remove Node.rawNode and just use the constructor instead

This commit is contained in:
Cameron Ross 2018-04-22 15:44:16 -03:00
parent f528351867
commit 9dd8bed9b6
No known key found for this signature in database
GPG key ID: 777897D98DC91C54
3 changed files with 21 additions and 36 deletions

View file

@ -291,13 +291,17 @@ final class Constructor
{
static if(is(U : ScalarStyle))
{
return Node.rawNode((*delegates!T)[tag](node), start, tag,
style, CollectionStyle.Invalid);
auto newNode = Node((*delegates!T)[tag](node), tag);
newNode.startMark_ = start;
newNode.scalarStyle = style;
return newNode;
}
else static if(is(U : CollectionStyle))
{
return Node.rawNode((*delegates!T)[tag](node), start, tag,
ScalarStyle.Invalid, style);
auto newNode = Node((*delegates!T)[tag](node), tag);
newNode.startMark_ = start;
newNode.collectionStyle = style;
return newNode;
}
else static assert(false);
}

View file

@ -193,7 +193,7 @@ struct Node
Value.allowed!T;
}
private:
package:
// Stored value.
Value value_;
// Start position of the node.
@ -1766,28 +1766,6 @@ struct Node
}
package:
// Construct a node from raw data.
//
// Params: value = Value of the node.
// startMark = Start position of the node in file.
// tag = Tag of the node.
// scalarStyle = Scalar style of the node.
// collectionStyle = Collection style of the node.
//
// Returns: Constructed node.
static Node rawNode(Value value, const Mark startMark, const string tag,
const ScalarStyle scalarStyle,
const CollectionStyle collectionStyle) @safe
{
Node node;
node.setValue(value);
node.startMark_ = startMark;
node.tag_ = tag;
node.scalarStyle = scalarStyle;
node.collectionStyle = collectionStyle;
return node;
}
// Construct Node.Value from user defined type.
static Value userValue(T)(T value) @trusted

View file

@ -238,11 +238,12 @@ final class Representer
* Returns: The represented node.
*/
Node representScalar(string tag, string scalar,
ScalarStyle style = ScalarStyle.Invalid) @trusted
ScalarStyle style = ScalarStyle.Invalid) @safe
{
if(style == ScalarStyle.Invalid){style = defaultScalarStyle_;}
return Node.rawNode(Node.Value(scalar), Mark(), tag, style,
CollectionStyle.Invalid);
auto newNode = Node(scalar, tag);
newNode.scalarStyle = style;
return newNode;
}
///
@safe unittest
@ -291,7 +292,7 @@ final class Representer
* Throws: $(D RepresenterException) if a child could not be represented.
*/
Node representSequence(string tag, Node[] sequence,
CollectionStyle style = CollectionStyle.Invalid) @trusted
CollectionStyle style = CollectionStyle.Invalid) @safe
{
Node[] value;
value.length = sequence.length;
@ -314,8 +315,9 @@ final class Representer
? defaultCollectionStyle_
: bestStyle;
}
return Node.rawNode(Node.Value(value), Mark(), tag,
ScalarStyle.Invalid, style);
auto newNode = Node(value, tag);
newNode.collectionStyle = style;
return newNode;
}
///
@safe unittest
@ -365,7 +367,7 @@ final class Representer
* Throws: $(D RepresenterException) if a child could not be represented.
*/
Node representMapping(string tag, Node.Pair[] pairs,
CollectionStyle style = CollectionStyle.Invalid) @trusted
CollectionStyle style = CollectionStyle.Invalid) @safe
{
Node.Pair[] value;
value.length = pairs.length;
@ -396,8 +398,9 @@ final class Representer
? defaultCollectionStyle_
: bestStyle;
}
return Node.rawNode(Node.Value(value), Mark(), tag,
ScalarStyle.Invalid, style);
auto newNode = Node(value, tag);
newNode.collectionStyle = style;
return newNode;
}
///
@safe unittest