Some YAMLObject simplification (#180)

* change YAMLObject to an interface

* move YAMLContainer constructor with other private member

* some YAMLContainer simplification
This commit is contained in:
Cameron Ross 2018-07-06 03:35:27 -03:00 committed by BBasile
parent 93cdaa90dc
commit 26eb0913f1

View file

@ -58,16 +58,16 @@ struct YAMLNull
// Merge YAML type, used to support "tag:yaml.org,2002:merge". // Merge YAML type, used to support "tag:yaml.org,2002:merge".
package struct YAMLMerge{} package struct YAMLMerge{}
// Base class for YAMLContainer - used for user defined YAML types. // Interface for YAMLContainer - used for user defined YAML types.
package abstract class YAMLObject package interface YAMLObject
{ {
public: public:
// Get type of the stored value. // Get type of the stored value.
@property TypeInfo type() const pure @safe nothrow {assert(false);} @property TypeInfo type() const pure @safe nothrow;
protected: protected:
// Compare with another YAMLObject. // Compare with another YAMLObject.
int cmp(const YAMLObject) const @system {assert(false);} int cmp(const YAMLObject) const @system;
} }
// Stores a user defined YAML data type. // Stores a user defined YAML data type.
@ -76,22 +76,23 @@ package class YAMLContainer(T) if (!Node.allowed!T): YAMLObject
private: private:
// Stored value. // Stored value.
T value_; T value_;
// Construct a YAMLContainer holding specified value.
this(T value) @safe
{
value_ = value;
}
public: public:
// Get type of the stored value. // Get type of the stored value.
@property override TypeInfo type() const pure @safe nothrow {return typeid(T);} @property override TypeInfo type() const pure @safe nothrow
{
return typeid(T);
}
// Get string representation of the container. // Get string representation of the container.
override string toString() @system override string toString() @system
{ {
static if(!hasMember!(T, "toString")) return format("YAMLContainer(%s)", value_);
{
return super.toString();
}
else
{
return format("YAMLContainer(%s)", value_.toString());
}
} }
protected: protected:
@ -107,9 +108,6 @@ package class YAMLContainer(T) if (!Node.allowed!T): YAMLObject
return (*v1).opCmp(*v2); return (*v1).opCmp(*v2);
} }
private:
// Construct a YAMLContainer holding specified value.
this(T value) @safe {value_ = value;}
} }