From 13ea5f0c24a106612ce96a9b96ffdaf771105ae2 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Sat, 22 Oct 2011 17:06:32 +0200 Subject: [PATCH] Added a shortcut alias called "as" for Node.get(), and replaced get() with as() all over the code, tutorials, examples and docs. Fixed a bug in YAML benchmark makefile. Fixed a bug in autoddoc configuration. --- autoddoc.cfg | 2 +- doc/doctrees/environment.pickle | Bin 12705 -> 12705 bytes doc/doctrees/tutorials/custom_types.doctree | Bin 47211 -> 46981 bytes .../tutorials/getting_started.doctree | Bin 35418 -> 35392 bytes doc/html/_sources/tutorials/custom_types.txt | 22 ++-- .../_sources/tutorials/getting_started.txt | 10 +- doc/html/api/dyaml.constructor.html | 6 +- doc/html/api/dyaml.dumper.html | 4 +- doc/html/api/dyaml.loader.html | 6 ++ doc/html/api/dyaml.node.html | 16 ++- doc/html/api/dyaml.representer.html | 12 +-- doc/html/articles/spec_differences.html | 2 +- doc/html/index.html | 2 +- doc/html/search.html | 2 +- doc/html/searchindex.js | 2 +- doc/html/tutorials/custom_types.html | 24 ++--- doc/html/tutorials/getting_started.html | 12 +-- doc/html/tutorials/yaml_syntax.html | 2 +- docsrc/tutorials/custom_types.rst | 22 ++-- docsrc/tutorials/getting_started.rst | 10 +- dyaml/constructor.d | 42 ++++---- dyaml/node.d | 95 +++++++++--------- dyaml/representer.d | 40 ++++---- dyaml/serializer.d | 6 +- examples/constructor/main.d | 16 +-- examples/getting_started/main.d | 2 +- examples/representer/main.d | 2 +- examples/resolver/main.d | 16 +-- examples/yaml_bench/Makefile | 2 +- examples/yaml_bench/yaml_bench.d | 14 +-- examples/yaml_gen/yaml_gen.d | 48 ++++----- test/src/constructor.d | 8 +- test/src/inputoutput.d | 4 +- 33 files changed, 236 insertions(+), 215 deletions(-) diff --git a/autoddoc.cfg b/autoddoc.cfg index e21ffe1..7498db8 100644 --- a/autoddoc.cfg +++ b/autoddoc.cfg @@ -29,7 +29,7 @@ links = ../index.html Documentation home # Source files or patterns to ignore. Supports regexp syntax. # E.g; To ignore main.d and all source files in the test/ directory, # you would use: "main.d test/*" -ignore = test/*, examples/*, docsrc/*, autoddoc/*, yaml.d, unittest.d, cdc.d, dyaml/composer.d, dyaml/event.d, dyaml/parser.d, dyaml/reader.d, dyaml/scanner.d, dyaml/token.d, dyaml/util.d, dyaml/anchor.d, dyaml/emitter.d, dyaml/flags.d, dyaml/serializer.d, dyaml/sharedobject.d, dyaml/tag.d, dyaml/tagdirectives.d +ignore = test/*, examples/*, docsrc/*, autoddoc/*, yaml.d, unittest.d, cdc.d, dyaml/composer.d, dyaml/event.d, dyaml/parser.d, dyaml/reader.d, dyaml/scanner.d, dyaml/token.d, dyaml/util.d, dyaml/anchor.d, dyaml/emitter.d, dyaml/flags.d, dyaml/serializer.d, dyaml/sharedobject.d, dyaml/tag.d, dyaml/tagdirectives.d, dyaml/queue.d [DDOC] # Command to use to generate the documentation. diff --git a/doc/doctrees/environment.pickle b/doc/doctrees/environment.pickle index adc89ed267d0966fe9809cbeb3c05d371d4a4d41..ecb58beed1a56d66ba151f19a3f3b1d6ec8e357a 100644 GIT binary patch delta 63 zcmZ3OyfAq~tG>~SZ5KG^7H25CJ6>L~?fkzxw=;CW%nK|ppJkXrm`sKrGVCA<{+~13 Jyj}klBLE=vA)5dI delta 63 zcmZ3OyfAq~tG?0l(yJm>4>OeA9WMi!+|3^|bRbN@<{KHN5GKF-)C@Zalc(v*=I#2g F7y-pa9!&rM diff --git a/doc/doctrees/tutorials/custom_types.doctree b/doc/doctrees/tutorials/custom_types.doctree index 056c1d896bb84b32a26a8c2bb72bf7e834d53998..98e74fb473f18793e3ccd1f5db4ce3324cce3fda 100644 GIT binary patch delta 3074 zcma)8Yj6}*7S4ppV-jWvnY@UEJRpEVfG9@s5u*aiMuI4<@e$je={xBjdb-Ec-H@nb zL`4kdJ--k}OZ}kU!{pr$YX66$|>vM~|u8E)8UPi-@ zx3^*UQppbA?||`=9Vhtaoo&8ietPGZrH<9$FxzR+V|4fLMrw@ZA~={01QxU58iBhOTd5cg6mG)`Vf+Ib%k2I{#4_aZ zC>uJ_+ymEoV+rkZgaPNm7?n>KWl!HxX? zBhzNB5fBO6xuUXe!chut7V}KScH<#c@l^+_7gk7qr$5Q!UcqDDZ$X?mqFY7SZMk8$ zdq+fsbVNOTZ2x5|?!Xxyku2bMX5ryD5lkFWrjRq$t_XA_i^lVhW;KoeQj>}}p^1sG zSZ-Lar-=wjlg7smELoxB3^m0Cd~FsUjuXMzG#LV&$f8k`nbA}~Cz~G&{X$Dp!0*b1 zgV0h&M5M*0zOB2JpE^*@&m5ew!a)PdabszO@-5n^aj(UgQm_HraaqLm8?qP`d(r}j z0X%?^E~!{oGdJl$oOk-AU~X;O@DN&iU?a9taJ-gfQSlG^^A_Q%kC3ZOH&q>2)RFO0 z_AgV{( z^z2zX(I=IWKpX8E(i^y2*hS_7l||fMc%CQH)xj6gGAPwqu9I{f-kPq7y-1isB8@um z5>0|O9*OBDW7Gv|Vp zvQD>k#{wAPeMhGI_VXu?%+d}ZVo;jI%yn>3fIY2Ao4G0qOBgUJ%w?=EY1vHHO{`>7 zF>E*_?B%p!+l@H7W3bFd4hzmw@7p5Nu|t|S9<99Xh_`~5K^aTOQgNej6wOkB>%>|v zhGR4?$%MLKz?g^$=_V$9BIG#10wScv#*Lof+m2RBCj~Zu7c7azsrSLF1fv30BJz4& zbu@SlEuFQ!w-i-DSQj(m{@VH z6Dc_@tdr?-L=;RG>3^F)a;(|+4&Q&QY010jkBd49(Vdqkg#Ly2^K}*eN`nvLijxF;oIFctph*@8l2_CfeNe{^g{ z_#foUlP1yk`=2;Y!AJbWm=yk4jL%?;KV0+af9(_Ac>KJEf1#xZ{*A3vNSVd3PX+Wd JY~9F$p8)nWsg?i$ delta 3187 zcma)8YgAlU6`tV@fq^iAGzeuNf$#_swo0{;K|H)^aWXxt4qHfeT%2UHx&nD`dsEe5AQ7U4rTs(Vs#F496R19M~?gE`?vCU z^kf%*pE>!YoIP>RdxyX2t&^8d{UeaJ&17Fm8)|K7Z3`rXV_15?u>y{;oq!n)WKNA8 z$nyqe#hH5xvRFBCraEir$QlfP?0T-plMWlZS`WjrJdbAxO0jJ*Dtik(9?v|vyf9uP zhaWBJ@uAP?>di+NPYdN}IC2;&IC6P5Qt==yaiznWQEvp1y{mTvhP;DDd1|b#11hsD zer8#bW%)l5^|E-pys(PV)v|tEdRNL@CaX%@gJ+F(Mvl=Df}7;4<3YJ|qDpRje7B#V zsA4a!v6iFi^5hLsRT;68wgc&iW5NFYM#B)?j65rM5}Zit>D$%20;P*VEs=@~d;O9S z2%sMq-@ufO*kamv@wKvSVv}!m*1d+^P4d2p_1-EuGSS%3j24=0Er+ZQDfw}6P{e~? zqd8ZIZ8@ZF1FR7SweioYmdN z%(uJDsBSZ*wV0+PeRs&7$*!6$I6{3}8NJO#`(w9}zU|xDzGI2K-izUHm3Sw+-!Abk z`R~aVSK=EB5_ck;CGKMK54hwg@ott#vy#N!n8NlJ5GfG0NIC)vA zjjBdj=75&8qZT9tz3JH7G)&S$1*I2rj|kvungiL86dAs zZ{B0$2xT~oPP=G-jN;!-#z968xM-9yDEFT4kRun07Ns0QKTG*E!#}eW{#lknJS1fZ zGg2%6c_Fapb7(<1!yGZ@WQa3?F92KeXIkMp!94E!yul*JpE%-LJL+}W;ElTCWd}>&W^y4Aux8Xao{PO#%j-$U@DTQbR zUA9ou5Qh_T$K{6Q-$jp7jE5v5C<(BnB&s}-^Vd&;zX+aUcec&1#=Wx zFym_-XMc&I#qmJXYXXmxH(x26mlfA+8&f+Wx6L$fJ&Qi2f@IlfH;^@sOM*!<=j$Sz z?t^noSRoQ&L7R05A3s9~2d3oM%o^W$LKYBp#DQsfZN`811vKGBSFWcMDb>A4Y`Dlo zWx5qHlTk|@q$>_CWx>7y4U)J^H~|PP0heWKrZzT1S)@qQHKl-my1Eup`vlp z_WS~`5J$dJfKPJN?1Nbxb}PIKSP}9k;_X)GwKjq^f#08)zm|X-CB(CKe#PDj&F7x9_*;!b)2P+5oPJa-zfUvbHkT=$`%G6G=L(RN03TVJoh>M?QP| z{DFczN-n+2f5iR}{7JrYRq_9s`+va}|6kY9|J7gRmbtdTYiJ3<>)0v8FM#J6c%7)N-UlnE*3YLNz@S`vN>Fgl@}xvuPnn-l$w|_d84}Y z=9$W7%sku-3=CR+`6;P-K7FQOM6zD9K1wC{9hz z&r4A#$yb1yB{{iTU5v2G%^TGhacdn08W;jJ1!k*;rWVZn%wmPo;#7pm_f5q`6cURS ziVIScGt)9bGL;3XdR&t?7&~w(wh3VE5rVSH>8S^$z6c%7)PEReF94Zz!nNidcNoaGZ7%MMWE=E}fOs`j$-aK8| zjG32*fq_BGFFz$!52W>`njQ}qPy{X@q^`qgI@w+wqAOlqAHmzaUVRa_;Ax=hkc?CX zgc*s(Vqh!eO~qw&6cTfC^2;;x(iKYbxrz%?lQYvQ6-p`#QuP!jdzm_La^gA+0pEOFaTDjgXI7K diff --git a/doc/html/_sources/tutorials/custom_types.txt b/doc/html/_sources/tutorials/custom_types.txt index 389abdc..35d48e0 100644 --- a/doc/html/_sources/tutorials/custom_types.txt +++ b/doc/html/_sources/tutorials/custom_types.txt @@ -54,7 +54,7 @@ of these functions: Color constructColorScalar(Mark start, Mark end, ref Node node) { - string value = node.get!string; + string value = node.as!string; if(value.length != 6) { @@ -93,9 +93,9 @@ of these functions: //Might throw if a value is missing is not an integer, or is out of range. try { - r = node["r"].get!ubyte; - g = node["g"].get!ubyte; - b = node["b"].get!ubyte; + r = node["r"].as!ubyte; + g = node["g"].as!ubyte; + b = node["b"].as!ubyte; } catch(NodeException e) { @@ -143,10 +143,10 @@ Finally, the code to put it all together: auto root = loader.load(); - if(root["scalar-red"].get!Color == red && - root["mapping-red"].get!Color == red && - root["scalar-orange"].get!Color == orange && - root["mapping-orange"].get!Color == orange) + if(root["scalar-red"].as!Color == red && + root["mapping-red"].as!Color == red && + root["scalar-orange"].as!Color == orange && + root["mapping-orange"].as!Color == orange) { writeln("SUCCESS"); return; @@ -162,8 +162,8 @@ Finally, the code to put it all together: First, we create a *Constructor* and pass functions to handle the ``!color`` and ``!color-mapping`` tag. We construct a *Loader* and pass the *Constructor* -to it. We then load the YAML document, and finally, read the colors using -*get()* method to test if they were loaded as expected. +to it. We then load the YAML document, and finally, read the colors to test if +they were loaded as expected. You can find the source code for what we've done so far in the ``examples/constructor`` directory in the D:YAML package. @@ -256,7 +256,7 @@ With the following code, we will add support for dumping the our Color type. Node representColor(ref Node node, Representer representer) { //The node is guaranteed to be Color as we add representer for Color. - Color color = node.get!Color; + Color color = node.as!Color; static immutable hex = "0123456789ABCDEF"; diff --git a/doc/html/_sources/tutorials/getting_started.txt b/doc/html/_sources/tutorials/getting_started.txt index 8e4c7cd..55c451b 100644 --- a/doc/html/_sources/tutorials/getting_started.txt +++ b/doc/html/_sources/tutorials/getting_started.txt @@ -90,7 +90,7 @@ into the file: { writeln(word); } - writeln("The answer is ", root["Answer"].get!int); + writeln("The answer is ", root["Answer"].as!int); //Dump the loaded document to output.yaml. Dumper("output.yaml").dump(root); @@ -115,7 +115,7 @@ possible. mapping (associative array) or a scalar (value). Here the root node is a mapping, and we use the index operator to get subnodes with keys "Hello World" and "Answer". We iterate over the first, as it is a sequence, and use the -*Node.get()* method on the second to get its value as an integer. +*Node.as()* method on the second to read its value as an integer. You can iterate over a mapping or sequence as if it was an associative or normal array. If you try to iterate over a scalar, it will throw a *YAMLException*. @@ -128,9 +128,9 @@ not possible to convert to iterated type, a *YAMLException* is thrown. For instance, if we specified *int* here, we would get an error, as "Hello" cannot be converted to an integer. -The *Node.get()* method is used to get value of a scalar node, allowing to -specify type. D:YAML will try to return the scalar as this type, converting if -needed, throwing *YAMLException* if not possible. +The *Node.as()* method is used to read value of a scalar node as specified type. +D:YAML will try to return the scalar as this type, converting if needed, +throwing *YAMLException* if not possible. Finally we dump the document we just read to ``output.yaml`` with the *Dumper.dump()* method. *Dumper* is a struct used to dump YAML documents. diff --git a/doc/html/api/dyaml.constructor.html b/doc/html/api/dyaml.constructor.html index 117a4b3..63d0eca 100644 --- a/doc/html/api/dyaml.constructor.html +++ b/doc/html/api/dyaml.constructor.html @@ -127,7 +127,7 @@ { //Guaranteed to be string as we construct from scalar. //!mystruct x:y:z - auto parts = node.get!string().split(":"); + auto parts = node.as!string().split(":"); try { return MyStruct(to!int(parts[0]), to!int(parts[1]), to!int(parts[2])); @@ -174,7 +174,7 @@ //!mystruct [x, y, z] try { - return MyStruct(node[0].get!int, node[1].get!int, node[2].get!int); + return MyStruct(node[0].as!int, node[1].as!int, node[2].as!int); } catch(NodeException e) { @@ -218,7 +218,7 @@ //!mystruct {"x": x, "y": y, "z": z} try { - return MyStruct(node["x"].get!int, node["y"].get!int, node["z"].get!int); + return MyStruct(node["x"].as!int, node["y"].as!int, node["z"].as!int); } catch(NodeException e) { diff --git a/doc/html/api/dyaml.dumper.html b/doc/html/api/dyaml.dumper.html index 403281d..2ccf744 100644 --- a/doc/html/api/dyaml.dumper.html +++ b/doc/html/api/dyaml.dumper.html @@ -189,9 +189,11 @@

Example:

 Dumper dumper = Dumper("file.yaml");
+ string[string] directives;
+ directives["!short!"] = "tag:long.org,2011:";
  //This will emit tags starting with "tag:long.org,2011"
  //with a "!short!" prefix instead.
- dumper.tags("short", "tag:long.org,2011:");
+ dumper.tagDirectives(directives);
  dumper.dump(Node("foo"));
 

diff --git a/doc/html/api/dyaml.loader.html b/doc/html/api/dyaml.loader.html index 89af805..1223a95 100644 --- a/doc/html/api/dyaml.loader.html +++ b/doc/html/api/dyaml.loader.html @@ -149,6 +149,12 @@
Node[] loadAll();

Load all YAML documents. +

+

This is just a shortcut that iterates over all documents and returns + them all at once. Calling loadAll after iterating over the node or + vice versa will not return any documents, as they have all been parsed + already. +

Returns:
Array of root nodes of all documents in the file/stream. diff --git a/doc/html/api/dyaml.node.html b/doc/html/api/dyaml.node.html index d90e293..825532d 100644 --- a/doc/html/api/dyaml.node.html +++ b/doc/html/api/dyaml.node.html @@ -246,6 +246,11 @@

Is this node a user defined type?

+
+
const @property string tag(); +
+

Return tag of the node.

+
bool opEquals(T)(ref T rhs);
@@ -271,6 +276,11 @@ Returns:
true if equal, false otherwise.
+ +
alias as; +
+

Shortcut for get().

+
T get(T)();
@@ -303,9 +313,9 @@ Examples:
Automatic type conversion:
 auto node = Node(42);
 
- assert(node.get!int == 42);
- assert(node.get!string == "42");
- assert(node.get!double == 42.0);
+ assert(node.as!int == 42);
+ assert(node.as!string == "42");
+ assert(node.as!double == 42.0);
 
diff --git a/doc/html/api/dyaml.representer.html b/doc/html/api/dyaml.representer.html index b1dfb6a..4326e3f 100644 --- a/doc/html/api/dyaml.representer.html +++ b/doc/html/api/dyaml.representer.html @@ -95,7 +95,7 @@ Node representMyStruct(ref Node node, Representer representer) { //The node is guaranteed to be MyStruct as we add representer for MyStruct. - auto value = node.get!MyStruct; + auto value = node.as!MyStruct; //Using custom scalar format, x:y:z. auto scalar = format(value.x, ":", value.y, ":", value.z); //Representing as a scalar, with custom tag to specify this data type. @@ -136,7 +136,7 @@ return x == t.x && y == t.y && z == t.z; } - ///Useful for Node.get!string . + ///Useful for Node.as!string . override string toString() { return format("MyClass("), x, ", ", y, ", ", z, ""); @@ -147,7 +147,7 @@ Node representMyClass(ref Node node, Representer representer) { //The node is guaranteed to be MyClass as we add representer for MyClass. - auto value = node.get!MyClass; + auto value = node.as!MyClass; //Using custom scalar format, x:y:z. auto scalar = format(value.x, ":", value.y, ":", value.z); //Representing as a scalar, with custom tag to specify this data type. @@ -189,7 +189,7 @@ Node representMyStruct(ref Node node, Representer representer) { - auto value = node.get!MyStruct; + auto value = node.as!MyStruct; auto scalar = format(value.x, ":", value.y, ":", value.z); return representer.representScalar("!mystruct.tag", scalar); } @@ -223,7 +223,7 @@ Node representMyStruct(ref Node node, Representer representer) { - auto value = node.get!MyStruct; + auto value = node.as!MyStruct; auto nodes = [Node(value.x), Node(value.y), Node(value.z)]; return representer.representSequence("!mystruct.tag", nodes); } @@ -257,7 +257,7 @@ Node representMyStruct(ref Node node, Representer representer) { - auto value = node.get!MyStruct; + auto value = node.as!MyStruct; auto pairs = [Node.Pair("x", value.x), Node.Pair("y", value.y), Node.Pair("z", value.z)]; diff --git a/doc/html/articles/spec_differences.html b/doc/html/articles/spec_differences.html index 5c6f923..549aac8 100644 --- a/doc/html/articles/spec_differences.html +++ b/doc/html/articles/spec_differences.html @@ -138,7 +138,7 @@ struct appears in Phobos.

diff --git a/doc/html/index.html b/doc/html/index.html index de8886f..55c97b9 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -104,7 +104,7 @@ diff --git a/doc/html/search.html b/doc/html/search.html index b29e1eb..71354f8 100644 --- a/doc/html/search.html +++ b/doc/html/search.html @@ -87,7 +87,7 @@ diff --git a/doc/html/searchindex.js b/doc/html/searchindex.js index f016544..37e3890 100644 --- a/doc/html/searchindex.js +++ b/doc/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({objects:{},terms:{represent:[2,3],all:[1,3,4],code:[0,1,3,4],representmap:3,scalar:[0,1,2,3,4],follow:[3,4],decid:3,depend:[0,3],show:[0,3],readabl:0,specif:[0,1,3,2],representsequ:3,program:4,digit:[3,4],sourc:[3,4],everi:3,string:[0,3,4],powervr:0,"void":[3,4],phobo:1,ident:3,failur:3,yamlexcept:[3,4],implicitli:[0,3],implement:[1,3],tri:1,gender:0,list:[0,1,2],iter:4,"try":[3,4],item:0,refer:[0,3],slower:0,past:4,fold:0,second:[0,4],design:0,pass:3,download:4,rrr:3,even:[1,4],index:[3,4],what:3,appear:1,compar:3,cast:3,preserv:[0,4],section:3,current:4,version:4,"new":3,method:[3,4],dyaml:[1,4],never:1,here:4,ggg:3,ldyaml:4,path:4,modifi:4,implicit:[0,3],valu:[0,1,3,4],convert:[0,3,4],male:0,loos:1,datetim:0,omap:0,chang:[0,1,3],commonli:4,modul:4,unix:4,subnod:4,instal:4,articl:[0,2],regex:3,from:3,would:[3,4],doubl:0,two:[0,1,3],next:[3,4],few:1,call:[3,4],msg:3,type:[0,1,2,3,4],tell:4,more:[0,4],phone:0,known:[1,2,4],hold:3,must:[3,4],addrepresent:3,word:4,alia:[0,1],work:1,itself:3,can:[0,1,3,4],learn:4,purpos:3,root:[3,4],overrid:3,want:3,stream:[0,1],give:4,process:3,templat:3,topic:3,tag:[0,1,3,2],tab:1,serial:[0,3],addconstructorxxx:3,cours:3,multipl:[0,1],newlin:0,quot:[0,1],getting_start:4,how:[3,4],foreach:[3,4],answer:[0,4],instead:0,simpl:[0,3,4],css:3,map:[0,1,2,3,4],mar:4,clone:0,variant:1,befor:3,ff0000:3,uint:3,mai:1,end:[0,1,3],data:[0,1,2,3,4],welcom:[2,4],ani:[0,3,4],stdio:4,explicit:[0,3],correspond:3,ambigu:1,caus:1,inform:[0,4],green:[0,3],allow:[0,1,4],first:[0,2,3,4],order:[1,4],over:4,move:4,orang:3,becaus:1,veri:1,hierarchi:0,still:[0,1],paramet:3,write:4,style:[0,4],precondit:3,yaml:[0,1,2,3,4],window:4,complex:[0,3],main:[3,4],might:[0,1,3,4],easier:0,them:[0,1,3,4],"float":[0,3],"return":[3,4],thei:[0,1,3,4],python:0,auto:3,now:[1,3,4],introduct:[0,4],name:[0,3],separ:0,each:[0,3],found:[3,4],went:3,complet:3,mean:[1,3],compil:[3,4],unequ:[1,3],idea:4,"static":3,expect:[3,4],our:[3,4],extract:4,out:[0,3],space:0,content:[1,3,4],rel:4,"0123456789abcdefabcdef":3,ref:3,red:[0,3],difficulti:1,advanc:0,"0123456789abcdef":3,base:[0,3],dictionari:0,put:[3,4],org:[1,3],"byte":1,thrown:4,pyyaml:[0,1],indent:[0,1],could:[3,4],keep:4,length:3,yamlcoloninflowcontext:1,confus:1,assign:0,radeon:0,oper:[0,3,4],rang:3,onc:[0,1],arrai:[0,1,3,4],restrict:1,unlik:0,alreadi:[3,4],done:3,stabl:4,miss:3,addconstructormap:3,size:0,differ:[1,2,3,4],dump:[3,4],script:4,associ:[0,1,4],addimplicitresolv:3,system:[0,4],construct:[0,3],gpu:0,white:3,conveni:0,"final":[3,4],store:[0,3],adher:1,consol:4,option:[0,4],especi:0,ishexdigit:3,specifi:[0,3,4],pars:[0,3,4],somewhat:0,exactli:4,than:1,serv:4,remov:0,structur:[0,1],charact:[0,1,3],project:[2,4],str:[0,3],were:3,posit:3,argument:3,packag:[3,4],have:[0,3,4],tabl:0,need:[0,1,3,4],"null":0,lib:4,alias:[0,1,2],constructcolormap:3,note:[3,4],also:[0,3,4],read:[0,3,4],take:3,which:[0,1,3],brace:0,channel:3,uppercas:3,blue:[0,3],begin:[0,1],normal:4,previou:3,most:[0,3,4],regular:3,pair:[0,3],"class":[1,3],opequ:3,don:[1,3,4],later:3,flow:[0,1],doe:[0,1,4],bracket:0,cortex:0,fact:0,ldc:4,cdc:4,alphanumer:1,syntax:[0,2],identifi:[0,3],find:[3,4],onli:[3,4],explicitli:[0,3],just:[3,4],explain:4,should:[1,3,4],meant:4,std:[3,4],get:[2,3,4],express:3,cannot:[1,4],report:3,requir:3,whether:3,common:0,contain:[0,1,3,4],where:[0,3,4],wiki:1,set:[0,2,3,4],seq:0,see:[0,1,3],rgb:3,result:3,fail:1,close:1,athlon:0,representscalar:3,wikipedia:0,written:4,between:[0,1,2],"import":4,altern:3,accord:1,kei:[0,1,4],both:3,last:0,howev:[0,3],equal:3,comment:[0,4],etc:3,tutori:[2,3,4],context:[0,1],load:[1,3,4],color:[0,3],hyphen:0,loader:[3,4],colon:0,suppli:3,respect:3,addconstructorscalar:3,bbb:3,empti:0,sinc:3,json:0,basic:4,xxx:[3,4],anywher:0,assert:3,togeth:3,input:[3,4],"catch":3,multi:0,therefor:[1,3],look:4,plain:[0,1,3],ffff00:3,defin:[0,3],ain:0,error:4,anchor:[0,1,2],readi:3,non:[0,3],archiv:4,tediou:3,ascii:[1,3],dumper:[3,4],disabl:3,clearli:1,same:[0,1,3,4],check:[3,4],member:3,binari:0,instanc:[1,3,4],timestamp:0,android:0,document:[0,1,2,3,4],difficult:0,http:1,nest:0,user:[0,3],nodeexcept:3,markup:0,well:3,constructorexcept:3,person:0,exampl:[3,4],command:4,thi:[0,1,3,4],everyth:3,left:0,explan:4,systim:0,newest:4,execut:4,less:1,paragraph:0,gdc:4,human:0,yet:4,languag:[0,4],struct:[1,3,4],libdyaml:4,interptet:1,except:4,constructcolorscalar:3,add:[3,4],other:[1,4],els:0,match:3,build:4,real:0,format:[0,3,4],handl:[1,3],know:3,world:4,recurs:[0,1],tolow:3,like:3,success:3,arbitrari:3,resolv:[0,2,3],integ:[0,3,4],arthur:0,api:[2,3,4],singl:[0,1],output:[3,4],unnecessari:1,right:1,often:3,linux:[0,4],some:[0,1,3,4],guarante:3,ubyt:[0,3],librari:4,representcolor:3,lead:1,though:4,unord:1,condit:3,either:[0,3,4],object:3,run:4,acronym:0,usag:4,immut:3,rrggbb:3,unicod:1,chapter:0,comparison:3,about:[1,4],rare:1,usedefaultrepresent:3,page:0,constructor:[2,3],fals:3,produc:4,block:0,subset:0,within:1,encod:1,automat:4,bsd:0,mark:[0,1,3],your:[2,3,4],wai:[1,3],support:[0,1,3],question:0,"long":0,custom:[0,2,3],writeln:[3,4],start:[0,2,3,4],"function":3,form:3,continu:0,link:4,line:0,conclus:4,"throw":[3,4],dmd:4,consist:0,possibl:[0,1,3,4],"default":[0,3],displai:4,until:0,directori:[3,4],problem:1,similar:[0,4],featur:[0,1],creat:[0,3,4],"int":[0,3,4],cover:4,dure:3,parser:[0,4],doesn:4,repres:[0,3,4],"char":3,exist:4,file:[1,3,4],yamlnul:0,isdigit:3,dent:0,simplest:4,probabl:0,hex:3,when:[3,4],detail:[0,1],invalid:3,valid:1,bool:0,futur:[0,1],test:3,you:[0,3,4],node:[0,3,4],resolut:[0,3],sequenc:[0,2,3,4],consid:[1,3],debian:0,reduc:0,longer:3,home:4,rule:1,hello:4,ignor:1,far:3,escap:0,cpu:0},objtypes:{},titles:["YAML syntax","Differences between D:YAML and the YAML specification","Welcome to D:YAML documentation!","Custom YAML data types","Getting started"],objnames:{},filenames:["tutorials/yaml_syntax","articles/spec_differences","index","tutorials/custom_types","tutorials/getting_started"]}) \ No newline at end of file +Search.setIndex({objects:{},terms:{represent:[2,3],all:[1,3,4],code:[0,1,3,4],representmap:3,scalar:[0,1,2,3,4],follow:[3,4],decid:3,depend:[0,3],show:[0,3],readabl:0,specif:[0,1,3,2],representsequ:3,program:4,digit:[3,4],sourc:[3,4],everi:3,string:[0,3,4],powervr:0,"void":[3,4],phobo:1,ident:3,failur:3,yamlexcept:[3,4],implicitli:[0,3],implement:[1,3],tri:1,gender:0,list:[0,1,2],iter:4,"try":[3,4],item:0,refer:[0,3],slower:0,past:4,fold:0,second:[0,4],design:0,pass:3,download:4,rrr:3,even:[1,4],index:[3,4],what:3,appear:1,compar:3,cast:3,preserv:[0,4],section:3,current:4,version:4,"new":3,method:[3,4],dyaml:[1,4],never:1,here:4,ggg:3,ldyaml:4,path:4,modifi:4,implicit:[0,3],valu:[0,1,3,4],convert:[0,3,4],male:0,loos:1,datetim:0,omap:0,chang:[0,1,3],commonli:4,modul:4,unix:4,subnod:4,instal:4,articl:[0,2],regex:3,from:3,would:[3,4],doubl:0,two:[0,1,3],next:[3,4],few:1,call:[3,4],msg:3,type:[0,1,2,3,4],tell:4,more:[0,4],phone:0,known:[1,2,4],hold:3,must:[3,4],addrepresent:3,word:4,alia:[0,1],work:1,itself:3,can:[0,1,3,4],learn:4,purpos:3,root:[3,4],overrid:3,want:3,stream:[0,1],give:4,process:3,templat:3,topic:3,tag:[0,1,3,2],tab:1,serial:[0,3],addconstructorxxx:3,cours:3,multipl:[0,1],newlin:0,quot:[0,1],getting_start:4,how:[3,4],foreach:[3,4],answer:[0,4],instead:0,simpl:[0,3,4],css:3,map:[0,1,2,3,4],mar:4,clone:0,variant:1,befor:3,ff0000:3,uint:3,mai:1,end:[0,1,3],data:[0,1,2,3,4],welcom:[2,4],ani:[0,3,4],stdio:4,explicit:[0,3],correspond:3,ambigu:1,caus:1,inform:[0,4],green:[0,3],allow:[0,1],first:[0,2,3,4],order:[1,4],over:4,move:4,orang:3,becaus:1,veri:1,hierarchi:0,still:[0,1],paramet:3,write:4,style:[0,4],precondit:3,yaml:[0,1,2,3,4],window:4,complex:[0,3],main:[3,4],might:[0,1,3,4],easier:0,them:[0,1,3,4],"float":[0,3],"return":[3,4],thei:[0,1,3,4],python:0,auto:3,now:[1,3,4],introduct:[0,4],name:[0,3],separ:0,each:[0,3],found:[3,4],went:3,complet:3,mean:[1,3],compil:[3,4],unequ:[1,3],idea:4,"static":3,expect:[3,4],our:[3,4],extract:4,out:[0,3],space:0,content:[1,3,4],rel:4,"0123456789abcdefabcdef":3,ref:3,red:[0,3],difficulti:1,advanc:0,"0123456789abcdef":3,base:[0,3],dictionari:0,put:[3,4],org:[1,3],"byte":1,thrown:4,pyyaml:[0,1],indent:[0,1],could:[3,4],keep:4,length:3,yamlcoloninflowcontext:1,confus:1,assign:0,radeon:0,oper:[0,3,4],rang:3,onc:[0,1],arrai:[0,1,3,4],restrict:1,unlik:0,alreadi:[3,4],done:3,stabl:4,miss:3,addconstructormap:3,size:0,differ:[1,2,3,4],dump:[3,4],script:4,associ:[0,1,4],addimplicitresolv:3,system:[0,4],construct:[0,3],gpu:0,white:3,conveni:0,"final":[3,4],store:[0,3],adher:1,consol:4,option:[0,4],especi:0,ishexdigit:3,specifi:[0,3,4],pars:[0,3,4],somewhat:0,exactli:4,than:1,serv:4,remov:0,structur:[0,1],charact:[0,1,3],project:[2,4],str:[0,3],were:3,posit:3,argument:3,packag:[3,4],have:[0,3,4],tabl:0,need:[0,1,3,4],"null":0,lib:4,alias:[0,1,2],constructcolormap:3,note:[3,4],also:[0,3,4],read:[0,3,4],take:3,which:[0,1,3],brace:0,channel:3,uppercas:3,blue:[0,3],begin:[0,1],normal:4,previou:3,most:[0,3,4],regular:3,pair:[0,3],"class":[1,3],opequ:3,don:[1,3,4],later:3,flow:[0,1],doe:[0,1,4],bracket:0,cortex:0,fact:0,ldc:4,cdc:4,alphanumer:1,syntax:[0,2],identifi:[0,3],find:[3,4],onli:[3,4],explicitli:[0,3],just:[3,4],explain:4,should:[1,3,4],meant:4,std:[3,4],get:[2,3,4],express:3,cannot:[1,4],report:3,requir:3,whether:3,common:0,contain:[0,1,3,4],where:[0,3,4],wiki:1,set:[0,2,3,4],seq:0,see:[0,1,3],rgb:3,result:3,fail:1,close:1,athlon:0,representscalar:3,wikipedia:0,written:4,between:[0,1,2],"import":4,altern:3,accord:1,kei:[0,1,4],both:3,last:0,howev:[0,3],equal:3,comment:[0,4],etc:3,tutori:[2,3,4],context:[0,1],load:[1,3,4],color:[0,3],hyphen:0,loader:[3,4],colon:0,suppli:3,respect:3,addconstructorscalar:3,bbb:3,empti:0,sinc:3,json:0,basic:4,xxx:[3,4],anywher:0,assert:3,togeth:3,input:[3,4],"catch":3,multi:0,therefor:[1,3],look:4,plain:[0,1,3],ffff00:3,defin:[0,3],ain:0,error:4,anchor:[0,1,2],readi:3,non:[0,3],archiv:4,tediou:3,ascii:[1,3],dumper:[3,4],disabl:3,clearli:1,same:[0,1,3,4],check:[3,4],member:3,binari:0,instanc:[1,3,4],timestamp:0,android:0,document:[0,1,2,3,4],difficult:0,http:1,nest:0,user:[0,3],nodeexcept:3,markup:0,well:3,constructorexcept:3,person:0,exampl:[3,4],command:4,thi:[0,1,3,4],everyth:3,left:0,explan:4,systim:0,newest:4,execut:4,less:1,paragraph:0,gdc:4,human:0,yet:4,languag:[0,4],struct:[1,3,4],libdyaml:4,interptet:1,except:4,constructcolorscalar:3,add:[3,4],other:[1,4],els:0,match:3,build:4,real:0,format:[0,3,4],handl:[1,3],know:3,world:4,recurs:[0,1],tolow:3,like:3,success:3,arbitrari:3,resolv:[0,2,3],integ:[0,3,4],arthur:0,api:[2,3,4],singl:[0,1],output:[3,4],unnecessari:1,right:1,often:3,linux:[0,4],some:[0,1,3,4],guarante:3,ubyt:[0,3],librari:4,representcolor:3,lead:1,though:4,unord:1,condit:3,either:[0,3,4],object:3,run:4,acronym:0,usag:4,immut:3,rrggbb:3,unicod:1,chapter:0,comparison:3,about:[1,4],rare:1,usedefaultrepresent:3,page:0,constructor:[2,3],fals:3,produc:4,block:0,subset:0,within:1,encod:1,automat:4,bsd:0,mark:[0,1,3],your:[2,3,4],wai:[1,3],support:[0,1,3],question:0,"long":0,custom:[0,2,3],writeln:[3,4],start:[0,2,3,4],"function":3,form:3,continu:0,link:4,line:0,conclus:4,"throw":[3,4],dmd:4,consist:0,possibl:[0,1,3,4],"default":[0,3],displai:4,until:0,directori:[3,4],problem:1,similar:[0,4],featur:[0,1],creat:[0,3,4],"int":[0,3,4],cover:4,dure:3,parser:[0,4],doesn:4,repres:[0,3,4],"char":3,exist:4,file:[1,3,4],yamlnul:0,isdigit:3,dent:0,simplest:4,probabl:0,hex:3,when:[3,4],detail:[0,1],invalid:3,valid:1,bool:0,futur:[0,1],test:3,you:[0,3,4],node:[0,3,4],resolut:[0,3],sequenc:[0,2,3,4],consid:[1,3],debian:0,reduc:0,longer:3,home:4,rule:1,hello:4,ignor:1,far:3,escap:0,cpu:0},objtypes:{},titles:["YAML syntax","Differences between D:YAML and the YAML specification","Welcome to D:YAML documentation!","Custom YAML data types","Getting started"],objnames:{},filenames:["tutorials/yaml_syntax","articles/spec_differences","index","tutorials/custom_types","tutorials/getting_started"]}) \ No newline at end of file diff --git a/doc/html/tutorials/custom_types.html b/doc/html/tutorials/custom_types.html index 9fe58cd..5e92567 100644 --- a/doc/html/tutorials/custom_types.html +++ b/doc/html/tutorials/custom_types.html @@ -87,7 +87,7 @@ from a mapping, where we use the following format: {r:RRR, g:GGG, b:BBB} . Code of these functions:

Color constructColorScalar(Mark start, Mark end, ref Node node)
 {
-    string value = node.get!string;
+    string value = node.as!string;
 
     if(value.length != 6)
     {
@@ -126,9 +126,9 @@ of these functions:

//Might throw if a value is missing is not an integer, or is out of range. try { - r = node["r"].get!ubyte; - g = node["g"].get!ubyte; - b = node["b"].get!ubyte; + r = node["r"].as!ubyte; + g = node["g"].as!ubyte; + b = node["b"].as!ubyte; } catch(NodeException e) { @@ -171,10 +171,10 @@ of these functions:

auto root = loader.load(); - if(root["scalar-red"].get!Color == red && - root["mapping-red"].get!Color == red && - root["scalar-orange"].get!Color == orange && - root["mapping-orange"].get!Color == orange) + if(root["scalar-red"].as!Color == red && + root["mapping-red"].as!Color == red && + root["scalar-orange"].as!Color == orange && + root["mapping-orange"].as!Color == orange) { writeln("SUCCESS"); return; @@ -191,8 +191,8 @@ of these functions:

First, we create a Constructor and pass functions to handle the !color and !color-mapping tag. We construct a Loader and pass the Constructor -to it. We then load the YAML document, and finally, read the colors using -get() method to test if they were loaded as expected.

+to it. We then load the YAML document, and finally, read the colors to test if +they were loaded as expected.

You can find the source code for what we’ve done so far in the examples/constructor directory in the D:YAML package.

@@ -263,7 +263,7 @@ loading the output.

Node representColor(ref Node node, Representer representer)
 {
     //The node is guaranteed to be Color as we add representer for Color.
-    Color color = node.get!Color;
+    Color color = node.as!Color;
 
     static immutable hex = "0123456789ABCDEF";
 
@@ -369,7 +369,7 @@ directory of the D:YAML package.

diff --git a/doc/html/tutorials/getting_started.html b/doc/html/tutorials/getting_started.html index 04ce92f..1646e53 100644 --- a/doc/html/tutorials/getting_started.html +++ b/doc/html/tutorials/getting_started.html @@ -116,7 +116,7 @@ into the file:

{ writeln(word); } - writeln("The answer is ", root["Answer"].get!int); + writeln("The answer is ", root["Answer"].as!int); //Dump the loaded document to output.yaml. Dumper("output.yaml").dump(root); @@ -137,7 +137,7 @@ possible.

mapping (associative array) or a scalar (value). Here the root node is a mapping, and we use the index operator to get subnodes with keys “Hello World” and “Answer”. We iterate over the first, as it is a sequence, and use the -Node.get() method on the second to get its value as an integer.

+Node.as() method on the second to read its value as an integer.

You can iterate over a mapping or sequence as if it was an associative or normal array. If you try to iterate over a scalar, it will throw a YAMLException.

You can iterate over subnodes using Node as the iterated type, or specify @@ -147,9 +147,9 @@ so we iterate over the “Hello World” sequence as an array of strings not possible to convert to iterated type, a YAMLException is thrown. For instance, if we specified int here, we would get an error, as “Hello” cannot be converted to an integer.

-

The Node.get() method is used to get value of a scalar node, allowing to -specify type. D:YAML will try to return the scalar as this type, converting if -needed, throwing YAMLException if not possible.

+

The Node.as() method is used to read value of a scalar node as specified type. +D:YAML will try to return the scalar as this type, converting if needed, +throwing YAMLException if not possible.

Finally we dump the document we just read to output.yaml with the Dumper.dump() method. Dumper is a struct used to dump YAML documents. The dump() method writes one or more documents to a file, throwing @@ -237,7 +237,7 @@ example in the example/getting_st

diff --git a/doc/html/tutorials/yaml_syntax.html b/doc/html/tutorials/yaml_syntax.html index fb01f92..54f8742 100644 --- a/doc/html/tutorials/yaml_syntax.html +++ b/doc/html/tutorials/yaml_syntax.html @@ -330,7 +330,7 @@ Some of these might change in the future (especially !!map and !!set).

diff --git a/docsrc/tutorials/custom_types.rst b/docsrc/tutorials/custom_types.rst index 389abdc..35d48e0 100644 --- a/docsrc/tutorials/custom_types.rst +++ b/docsrc/tutorials/custom_types.rst @@ -54,7 +54,7 @@ of these functions: Color constructColorScalar(Mark start, Mark end, ref Node node) { - string value = node.get!string; + string value = node.as!string; if(value.length != 6) { @@ -93,9 +93,9 @@ of these functions: //Might throw if a value is missing is not an integer, or is out of range. try { - r = node["r"].get!ubyte; - g = node["g"].get!ubyte; - b = node["b"].get!ubyte; + r = node["r"].as!ubyte; + g = node["g"].as!ubyte; + b = node["b"].as!ubyte; } catch(NodeException e) { @@ -143,10 +143,10 @@ Finally, the code to put it all together: auto root = loader.load(); - if(root["scalar-red"].get!Color == red && - root["mapping-red"].get!Color == red && - root["scalar-orange"].get!Color == orange && - root["mapping-orange"].get!Color == orange) + if(root["scalar-red"].as!Color == red && + root["mapping-red"].as!Color == red && + root["scalar-orange"].as!Color == orange && + root["mapping-orange"].as!Color == orange) { writeln("SUCCESS"); return; @@ -162,8 +162,8 @@ Finally, the code to put it all together: First, we create a *Constructor* and pass functions to handle the ``!color`` and ``!color-mapping`` tag. We construct a *Loader* and pass the *Constructor* -to it. We then load the YAML document, and finally, read the colors using -*get()* method to test if they were loaded as expected. +to it. We then load the YAML document, and finally, read the colors to test if +they were loaded as expected. You can find the source code for what we've done so far in the ``examples/constructor`` directory in the D:YAML package. @@ -256,7 +256,7 @@ With the following code, we will add support for dumping the our Color type. Node representColor(ref Node node, Representer representer) { //The node is guaranteed to be Color as we add representer for Color. - Color color = node.get!Color; + Color color = node.as!Color; static immutable hex = "0123456789ABCDEF"; diff --git a/docsrc/tutorials/getting_started.rst b/docsrc/tutorials/getting_started.rst index 8e4c7cd..55c451b 100644 --- a/docsrc/tutorials/getting_started.rst +++ b/docsrc/tutorials/getting_started.rst @@ -90,7 +90,7 @@ into the file: { writeln(word); } - writeln("The answer is ", root["Answer"].get!int); + writeln("The answer is ", root["Answer"].as!int); //Dump the loaded document to output.yaml. Dumper("output.yaml").dump(root); @@ -115,7 +115,7 @@ possible. mapping (associative array) or a scalar (value). Here the root node is a mapping, and we use the index operator to get subnodes with keys "Hello World" and "Answer". We iterate over the first, as it is a sequence, and use the -*Node.get()* method on the second to get its value as an integer. +*Node.as()* method on the second to read its value as an integer. You can iterate over a mapping or sequence as if it was an associative or normal array. If you try to iterate over a scalar, it will throw a *YAMLException*. @@ -128,9 +128,9 @@ not possible to convert to iterated type, a *YAMLException* is thrown. For instance, if we specified *int* here, we would get an error, as "Hello" cannot be converted to an integer. -The *Node.get()* method is used to get value of a scalar node, allowing to -specify type. D:YAML will try to return the scalar as this type, converting if -needed, throwing *YAMLException* if not possible. +The *Node.as()* method is used to read value of a scalar node as specified type. +D:YAML will try to return the scalar as this type, converting if needed, +throwing *YAMLException* if not possible. Finally we dump the document we just read to ``output.yaml`` with the *Dumper.dump()* method. *Dumper* is a struct used to dump YAML documents. diff --git a/dyaml/constructor.d b/dyaml/constructor.d index c7ebcf5..0c5f487 100644 --- a/dyaml/constructor.d +++ b/dyaml/constructor.d @@ -149,7 +149,7 @@ final class Constructor * { * //Guaranteed to be string as we construct from scalar. * //!mystruct x:y:z - * auto parts = node.get!string().split(":"); + * auto parts = node.as!string().split(":"); * try * { * return MyStruct(to!int(parts[0]), to!int(parts[1]), to!int(parts[2])); @@ -201,7 +201,7 @@ final class Constructor * //!mystruct [x, y, z] * try * { - * return MyStruct(node[0].get!int, node[1].get!int, node[2].get!int); + * return MyStruct(node[0].as!int, node[1].as!int, node[2].as!int); * } * catch(NodeException e) * { @@ -250,7 +250,7 @@ final class Constructor * //!mystruct {"x": x, "y": y, "z": z} * try * { - * return MyStruct(node["x"].get!int, node["y"].get!int, node["z"].get!int); + * return MyStruct(node["x"].as!int, node["y"].as!int, node["z"].as!int); * } * catch(NodeException e) * { @@ -344,7 +344,7 @@ YAMLMerge constructMerge(Mark start, Mark end, ref Node node) ///Construct a boolean node. bool constructBool(Mark start, Mark end, ref Node node) { - string value = node.get!string().toLower(); + string value = node.as!string().toLower(); if(["yes", "true", "on"].canFind(value)) {return true;} if(["no", "false", "off"].canFind(value)){return false;} throw new Error("Unable to parse boolean value: " ~ value, start, end); @@ -353,7 +353,7 @@ bool constructBool(Mark start, Mark end, ref Node node) ///Construct an integer (long) node. long constructLong(Mark start, Mark end, ref Node node) { - string value = node.get!string().replace("_", ""); + string value = node.as!string().replace("_", ""); const char c = value[0]; const long sign = c != '-' ? 1 : -1; if(c == '-' || c == '+') @@ -421,7 +421,7 @@ unittest ///Construct a floating point (real) node. real constructReal(Mark start, Mark end, ref Node node) { - string value = node.get!string().replace("_", "").toLower(); + string value = node.as!string().replace("_", "").toLower(); const char c = value[0]; const real sign = c != '-' ? 1.0 : -1.0; if(c == '-' || c == '+') @@ -491,7 +491,7 @@ unittest ///Construct a binary (base64) node. ubyte[] constructBinary(Mark start, Mark end, ref Node node) { - string value = node.get!string; + string value = node.as!string; //For an unknown reason, this must be nested to work (compiler bug?). try { @@ -520,7 +520,7 @@ unittest ///Construct a timestamp (SysTime) node. SysTime constructTimestamp(Mark start, Mark end, ref Node node) { - string value = node.get!string; + string value = node.as!string; immutable YMDRegexp = regex("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)"); immutable HMSRegexp = regex("^[Tt \t]+([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(\\.[0-9]*)?"); @@ -619,7 +619,7 @@ unittest ///Construct a string node. string constructString(Mark start, Mark end, ref Node node) { - return node.get!string; + return node.as!string; } ///Convert a sequence of single-element mappings into a sequence of pairs. @@ -633,7 +633,7 @@ Node.Pair[] getPairs(string type, Mark start, Mark end, Node[] nodes) new Error("While constructing " ~ type ~ ", expected a mapping with single element", start, end)); - pairs ~= node.get!(Node.Pair[]); + pairs ~= node.as!(Node.Pair[]); } return pairs; @@ -642,7 +642,7 @@ Node.Pair[] getPairs(string type, Mark start, Mark end, Node[] nodes) ///Construct an ordered map (ordered sequence of key:value pairs without duplicates) node. Node.Pair[] constructOrderedMap(Mark start, Mark end, ref Node node) { - auto pairs = getPairs("ordered map", start, end, node.get!(Node[])); + auto pairs = getPairs("ordered map", start, end, node.as!(Node[])); //TODO: the map here should be replaced with something with deterministic //memory allocation if possible. @@ -702,13 +702,13 @@ unittest ///Construct a pairs (ordered sequence of key: value pairs allowing duplicates) node. Node.Pair[] constructPairs(Mark start, Mark end, ref Node node) { - return getPairs("pairs", start, end, node.get!(Node[])); + return getPairs("pairs", start, end, node.as!(Node[])); } ///Construct a set node. Node[] constructSet(Mark start, Mark end, ref Node node) { - auto pairs = node.get!(Node.Pair[]); + auto pairs = node.as!(Node.Pair[]); //In future, the map here should be replaced with something with deterministic //memory allocation if possible. @@ -772,13 +772,13 @@ unittest ///Construct a sequence (array) node. Node[] constructSequence(Mark start, Mark end, ref Node node) { - return node.get!(Node[]); + return node.as!(Node[]); } ///Construct an unordered map (unordered set of key: value _pairs without duplicates) node. Node.Pair[] constructMap(Mark start, Mark end, ref Node node) { - auto pairs = node.get!(Node.Pair[]); + auto pairs = node.as!(Node.Pair[]); //TODO: the map here should be replaced with something with deterministic //memory allocation if possible. //Detect duplicates. @@ -808,7 +808,7 @@ struct MyStruct MyStruct constructMyStructScalar(Mark start, Mark end, ref Node node) { //Guaranteed to be string as we construct from scalar. - auto parts = node.get!string().split(":"); + auto parts = node.as!string().split(":"); try { return MyStruct(to!int(parts[0]), to!int(parts[1]), to!int(parts[2])); @@ -825,7 +825,7 @@ MyStruct constructMyStructSequence(Mark start, Mark end, ref Node node) //node is guaranteed to be sequence. try { - return MyStruct(node[0].get!int, node[1].get!int, node[2].get!int); + return MyStruct(node[0].as!int, node[1].as!int, node[2].as!int); } catch(NodeException e) { @@ -839,7 +839,7 @@ MyStruct constructMyStructMapping(Mark start, Mark end, ref Node node) //node is guaranteed to be mapping. try { - return MyStruct(node["x"].get!int, node["y"].get!int, node["z"].get!int); + return MyStruct(node["x"].as!int, node["y"].as!int, node["z"].as!int); } catch(NodeException e) { @@ -858,7 +858,7 @@ unittest loader.constructor = constructor; Node node = loader.load(); - assert(node.get!MyStruct == MyStruct(1, 2, 3)); + assert(node.as!MyStruct == MyStruct(1, 2, 3)); } unittest @@ -871,7 +871,7 @@ unittest loader.constructor = constructor; Node node = loader.load(); - assert(node.get!MyStruct == MyStruct(1, 2, 3)); + assert(node.as!MyStruct == MyStruct(1, 2, 3)); } unittest @@ -884,5 +884,5 @@ unittest loader.constructor = constructor; Node node = loader.load(); - assert(node.get!MyStruct == MyStruct(1, 2, 3)); + assert(node.as!MyStruct == MyStruct(1, 2, 3)); } diff --git a/dyaml/node.d b/dyaml/node.d index 0e3e92d..1e3042d 100644 --- a/dyaml/node.d +++ b/dyaml/node.d @@ -216,7 +216,7 @@ struct Node with(Node(42)) { assert(isScalar() && !isSequence && !isMapping && !isUserType); - assert(get!int == 42 && get!float == 42.0f && get!string == "42"); + assert(as!int == 42 && as!float == 42.0f && as!string == "42"); assert(!isUserType()); } with(Node(new class{int a = 5;})) @@ -278,7 +278,7 @@ struct Node { assert(!isScalar() && isSequence && !isMapping && !isUserType); assert(length == 3); - assert(opIndex(2).get!int == 3); + assert(opIndex(2).as!int == 3); } //Will be emitted as a sequence (default for arrays) @@ -332,7 +332,7 @@ struct Node { assert(!isScalar() && !isSequence && isMapping && !isUserType); assert(length == 2); - assert(opIndex("2").get!int == 2); + assert(opIndex("2").as!int == 2); } //Will be emitted as an unordered mapping (default for mappings) @@ -402,7 +402,7 @@ struct Node { assert(!isScalar() && !isSequence && isMapping && !isUserType); assert(length == 2); - assert(opIndex("2").get!int == 2); + assert(opIndex("2").as!int == 2); } //Will be emitted as an unordered mapping (default for mappings) @@ -457,6 +457,9 @@ struct Node return equals!(T, true)(rhs); } + ///Shortcut for get(). + alias get as; + /** * Get the value of the node as specified type. * @@ -486,9 +489,9 @@ struct Node * -------------------- * auto node = Node(42); * - * assert(node.get!int == 42); - * assert(node.get!string == "42"); - * assert(node.get!double == 42.0); + * assert(node.as!int == 42); + * assert(node.as!string == "42"); + * assert(node.as!double == 42.0); * -------------------- * * Returns: Value of the node as specified type. @@ -524,7 +527,7 @@ struct Node ///Must go before others, as even string/int/etc could be stored in a YAMLObject. if(isUserType) { - auto object = get!YAMLObject; + auto object = as!YAMLObject; if(object.type is typeid(T)) { target = (cast(YAMLContainer!T)object).value_; @@ -534,7 +537,7 @@ struct Node //If we're getting from a mapping and we're not getting Node.Pair[], //we're getting the default value. - if(isMapping){return this["="].get!T;} + if(isMapping){return this["="].as!T;} void throwUnexpectedType() { @@ -606,8 +609,8 @@ struct Node */ @property size_t length() { - if(isSequence) {return get!(Node[]).length;} - else if(isMapping){return get!(Pair[]).length;} + if(isSequence) {return as!(Node[]).length;} + else if(isMapping){return as!(Pair[]).length;} throw new Error("Trying to get length of a scalar node", startMark_); } @@ -640,7 +643,7 @@ struct Node else if(isMapping) { auto idx = findPair(index); - if(idx >= 0){return get!(Pair[])[idx].value;} + if(idx >= 0){return as!(Pair[])[idx].value;} string msg = "Mapping index not found" ~ (isSomeString!T ? ": " ~ to!string(index) : ""); throw new Error(msg, startMark_); @@ -669,10 +672,10 @@ struct Node Pair(k3, n3), Pair(k4, n4)])); - assert(narray[0].get!int == 11); + assert(narray[0].as!int == 11); assert(null !is collectException(narray[42])); - assert(nmap["11"].get!int == 11); - assert(nmap["14"].get!int == 14); + assert(nmap["11"].as!int == 11); + assert(nmap["14"].as!int == 14); assert(null !is collectException(nmap["42"])); } @@ -718,7 +721,7 @@ struct Node if(idx < 0){add(index, value);} else { - auto pairs = get!(Node.Pair[])(); + auto pairs = as!(Node.Pair[])(); static if(is(V == Node)){pairs[idx].value = value;} else {pairs[idx].value = Node(value);} value_ = Value(pairs); @@ -736,15 +739,15 @@ struct Node { opIndexAssign(42, 3); assert(length == 5); - assert(opIndex(3).get!int == 42); + assert(opIndex(3).as!int == 42); } with(Node(["1", "2", "3"], [4, 5, 6])) { opIndexAssign(42, "3"); opIndexAssign(123, 456); assert(length == 4); - assert(opIndex("3").get!int == 42); - assert(opIndex(456).get!int == 123); + assert(opIndex("3").as!int == 42); + assert(opIndex(456).as!int == 123); } } @@ -772,7 +775,7 @@ struct Node } else { - T temp = node.get!T; + T temp = node.as!T; result = dg(temp); } if(result){break;} @@ -799,7 +802,7 @@ struct Node } foreach(Node node; narray) { - array2 ~= node.get!int; + array2 ~= node.as!int; } assert(array == [11, 12, 13, 14]); assert(array2 == [11, 12, 13, 14]); @@ -829,18 +832,18 @@ struct Node } else static if(is(K == Node)) { - V tempValue = pair.value.get!V; + V tempValue = pair.value.as!V; result = dg(pair.key, tempValue); } else static if(is(V == Node)) { - K tempKey = pair.key.get!K; + K tempKey = pair.key.as!K; result = dg(tempKey, pair.value); } else { - K tempKey = pair.key.get!K; - V tempValue = pair.value.get!V; + K tempKey = pair.key.as!K; + V tempValue = pair.value.as!V; result = dg(tempKey, tempValue); } @@ -890,10 +893,10 @@ struct Node { switch(key) { - case "11": assert(value.get!int == 5 ); break; - case "12": assert(value.get!bool == true ); break; - case "13": assert(value.get!float == 1.0 ); break; - case "14": assert(value.get!string == "yarly"); break; + case "11": assert(value.as!int == 5 ); break; + case "12": assert(value.as!bool == true ); break; + case "13": assert(value.as!float == 1.0 ); break; + case "14": assert(value.as!string == "yarly"); break; default: assert(false); } } @@ -931,7 +934,7 @@ struct Node with(Node([1, 2, 3, 4])) { add(5.0f); - assert(opIndex(4).get!float == 5.0f); + assert(opIndex(4).as!float == 5.0f); } } @@ -967,7 +970,7 @@ struct Node with(Node([1, 2], [3, 4])) { add(5, "6"); - assert(opIndex(5).get!string == "6"); + assert(opIndex(5).as!string == "6"); } } @@ -991,7 +994,7 @@ struct Node { foreach(idx, ref elem; get!(Node[])) { - if(elem.convertsTo!T && elem.get!T == value) + if(elem.convertsTo!T && elem.as!T == value) { removeAt(idx); return; @@ -1004,7 +1007,7 @@ struct Node auto idx = findPair!(T, true)(value); if(idx >= 0) { - auto pairs = get!(Node.Pair[])(); + auto pairs = as!(Node.Pair[])(); moveAll(pairs[idx + 1 .. $], pairs[idx .. $ - 1]); pairs.length = pairs.length - 1; value_ = Value(pairs); @@ -1020,8 +1023,8 @@ struct Node { remove(3); assert(length == 4); - assert(opIndex(2).get!int == 4); - assert(opIndex(3).get!int == 3); + assert(opIndex(2).as!int == 4); + assert(opIndex(3).as!int == 3); } with(Node(["1", "2", "3"], [4, 5, 6])) { @@ -1070,7 +1073,7 @@ struct Node auto idx = findPair(index); if(idx >= 0) { - auto pairs = get!(Node.Pair[])(); + auto pairs = as!(Node.Pair[])(); moveAll(pairs[idx + 1 .. $], pairs[idx .. $ - 1]); pairs.length = pairs.length - 1; value_ = Value(pairs); @@ -1086,7 +1089,7 @@ struct Node { removeAt(3); assert(length == 4); - assert(opIndex(3).get!int == 3); + assert(opIndex(3).as!int == 3); } with(Node(["1", "2", "3"], [4, 5, 6])) { @@ -1136,8 +1139,8 @@ struct Node } if(isSequence) { - auto seq1 = get!(Node[]); - auto seq2 = rhs.get!(Node[]); + auto seq1 = as!(Node[]); + auto seq2 = rhs.as!(Node[]); if(seq1 is seq2){return true;} if(seq1.length != seq2.length){return false;} foreach(node; 0 .. seq1.length) @@ -1148,8 +1151,8 @@ struct Node } if(isMapping) { - auto map1 = get!(Node.Pair[]); - auto map2 = rhs.get!(Node.Pair[]); + auto map1 = as!(Node.Pair[]); + auto map2 = rhs.as!(Node.Pair[]); if(map1 is map2){return true;} if(map1.length != map2.length){return false;} foreach(pair; 0 .. map1.length) @@ -1163,7 +1166,7 @@ struct Node if(isUserType) { if(!rhs.isUserType){return false;} - return get!YAMLObject.equals(rhs.get!YAMLObject); + return get!YAMLObject.equals(rhs.as!YAMLObject); } if(isFloat) { @@ -1287,7 +1290,7 @@ struct Node //Get index of pair with key (or value, if value is true) matching index. long findPair(T, bool value = false)(const ref T index) { - auto pairs = get!(Node.Pair[])(); + auto pairs = as!(Node.Pair[])(); Node* node; foreach(idx, ref pair; pairs) { @@ -1301,8 +1304,8 @@ struct Node else static if(isFloatingPoint!T) { //Need to handle NaNs separately. - if((node.get!T == index) || - (isFloat && isNaN(index) && isNaN(node.get!real))) + if((node.as!T == index) || + (isFloat && isNaN(index) && isNaN(node.as!real))) { return idx; } @@ -1311,7 +1314,7 @@ struct Node { try { - if(node.get!T == index){return idx;} + if(node.as!T == index){return idx;} } catch(NodeException e) { diff --git a/dyaml/representer.d b/dyaml/representer.d index 9ca7e2a..6d9050a 100644 --- a/dyaml/representer.d +++ b/dyaml/representer.d @@ -99,7 +99,7 @@ final class Representer * Node representMyStruct(ref Node node, Representer representer) * { * //The node is guaranteed to be MyStruct as we add representer for MyStruct. - * auto value = node.get!MyStruct; + * auto value = node.as!MyStruct; * //Using custom scalar format, x:y:z. * auto scalar = format(value.x, ":", value.y, ":", value.z); * //Representing as a scalar, with custom tag to specify this data type. @@ -141,7 +141,7 @@ final class Representer * return x == t.x && y == t.y && z == t.z; * } * - * ///Useful for Node.get!string . + * ///Useful for Node.as!string . * override string toString() * { * return format("MyClass(", x, ", ", y, ", ", z, ")"); @@ -152,7 +152,7 @@ final class Representer * Node representMyClass(ref Node node, Representer representer) * { * //The node is guaranteed to be MyClass as we add representer for MyClass. - * auto value = node.get!MyClass; + * auto value = node.as!MyClass; * //Using custom scalar format, x:y:z. * auto scalar = format(value.x, ":", value.y, ":", value.z); * //Representing as a scalar, with custom tag to specify this data type. @@ -200,7 +200,7 @@ final class Representer * * Node representMyStruct(ref Node node, Representer representer) * { - * auto value = node.get!MyStruct; + * auto value = node.as!MyStruct; * auto scalar = format(value.x, ":", value.y, ":", value.z); * return representer.representScalar("!mystruct.tag", scalar); * } @@ -232,7 +232,7 @@ final class Representer * * Node representMyStruct(ref Node node, Representer representer) * { - * auto value = node.get!MyStruct; + * auto value = node.as!MyStruct; * auto nodes = [Node(value.x), Node(value.y), Node(value.z)]; * return representer.representSequence("!mystruct.tag", nodes); * } @@ -270,7 +270,7 @@ final class Representer * * Node representMyStruct(ref Node node, Representer representer) * { - * auto value = node.get!MyStruct; + * auto value = node.as!MyStruct; * auto pairs = [Node.Pair("x", value.x), * Node.Pair("y", value.y), * Node.Pair("z", value.z)]; @@ -294,7 +294,7 @@ final class Representer Node representData(ref Node data) { //User types are wrapped in YAMLObject. - auto type = data.isUserType ? data.get!YAMLObject.type : data.type; + auto type = data.isUserType ? data.as!YAMLObject.type : data.type; enforce((type in representers_) !is null, new RepresenterException("No representer function for type " @@ -322,7 +322,7 @@ Node representNull(ref Node node, Representer representer) ///Represent a string _node as a string scalar. Node representString(ref Node node, Representer representer) { - string value = node.get!string; + string value = node.as!string; return value is null ? representNull(node, representer) : representer.representScalar("tag:yaml.org,2002:str", value); } @@ -330,7 +330,7 @@ Node representString(ref Node node, Representer representer) ///Represent a bytes _node as a binary scalar. Node representBytes(ref Node node, Representer representer) { - const ubyte[] value = node.get!(ubyte[]); + const ubyte[] value = node.as!(ubyte[]); if(value is null){return representNull(node, representer);} return representer.representScalar("tag:yaml.org,2002:binary", cast(string)Base64.encode(value)); @@ -340,20 +340,20 @@ Node representBytes(ref Node node, Representer representer) Node representBool(ref Node node, Representer representer) { return representer.representScalar("tag:yaml.org,2002:bool", - node.get!bool ? "true" : "false"); + node.as!bool ? "true" : "false"); } ///Represent a long _node as an integer scalar. Node representLong(ref Node node, Representer representer) { return representer.representScalar("tag:yaml.org,2002:int", - to!string(node.get!long)); + to!string(node.as!long)); } ///Represent a real _node as a floating point scalar. Node representReal(ref Node node, Representer representer) { - real f = node.get!real; + real f = node.as!real; string value = isNaN(f) ? ".nan": f == real.infinity ? ".inf": f == -1.0 * real.infinity ? "-.inf": @@ -368,13 +368,13 @@ Node representReal(ref Node node, Representer representer) Node representSysTime(ref Node node, Representer representer) { return representer.representScalar("tag:yaml.org,2002:timestamp", - node.get!SysTime.toISOExtString()); + node.as!SysTime.toISOExtString()); } ///Represent a sequence _node as sequence/set. Node representNodes(ref Node node, Representer representer) { - auto nodes = node.get!(Node[]); + auto nodes = node.as!(Node[]); if(node.tag_ == Tag("tag:yaml.org,2002:set")) { ///YAML sets are mapping with null values. @@ -396,7 +396,7 @@ Node representNodes(ref Node node, Representer representer) ///Represent a mapping _node as map/ordered map/pairs. Node representPairs(ref Node node, Representer representer) { - auto pairs = node.get!(Node.Pair[]); + auto pairs = node.as!(Node.Pair[]); bool hasDuplicates(Node.Pair[] pairs) { @@ -456,7 +456,7 @@ struct MyStruct Node representMyStruct(ref Node node, Representer representer) { //The node is guaranteed to be MyStruct as we add representer for MyStruct. - auto value = node.get!MyStruct; + auto value = node.as!MyStruct; //Using custom scalar format, x:y:z. auto scalar = format(value.x, ":", value.y, ":", value.z); //Representing as a scalar, with custom tag to specify this data type. @@ -465,14 +465,14 @@ Node representMyStruct(ref Node node, Representer representer) Node representMyStructSeq(ref Node node, Representer representer) { - auto value = node.get!MyStruct; + auto value = node.as!MyStruct; auto nodes = [Node(value.x), Node(value.y), Node(value.z)]; return representer.representSequence("!mystruct.tag", nodes); } Node representMyStructMap(ref Node node, Representer representer) { - auto value = node.get!MyStruct; + auto value = node.as!MyStruct; auto pairs = [Node.Pair("x", value.x), Node.Pair("y", value.y), Node.Pair("z", value.z)]; @@ -498,7 +498,7 @@ class MyClass return x == t.x && y == t.y && z == t.z; } - ///Useful for Node.get!string . + ///Useful for Node.as!string . override string toString() { return format("MyClass(", x, ", ", y, ", ", z, ")"); @@ -509,7 +509,7 @@ class MyClass Node representMyClass(ref Node node, Representer representer) { //The node is guaranteed to be MyClass as we add representer for MyClass. - auto value = node.get!MyClass; + auto value = node.as!MyClass; //Using custom scalar format, x:y:z. auto scalar = format(value.x, ":", value.y, ":", value.z); //Representing as a scalar, with custom tag to specify this data type. diff --git a/dyaml/serializer.d b/dyaml/serializer.d index f318c36..14a163f 100644 --- a/dyaml/serializer.d +++ b/dyaml/serializer.d @@ -123,8 +123,8 @@ struct Serializer { if(node.isScalar) { - return node.isType!string ? node.get!string.length > 64 : - node.isType!(ubyte[]) ? node.get!(ubyte[]).length > 64: + return node.isType!string ? node.as!string.length > 64 : + node.isType!(ubyte[]) ? node.as!(ubyte[]).length > 64: false; } return node.length > 2; @@ -192,7 +192,7 @@ struct Serializer if(node.isScalar) { assert(node.isType!string, "Scalar node type must be string before serialized"); - auto value = node.get!string; + auto value = node.as!string; Tag detectedTag = resolver_.resolve(NodeID.Scalar, Tag(null), value, true); Tag defaultTag = resolver_.resolve(NodeID.Scalar, Tag(null), value, false); diff --git a/examples/constructor/main.d b/examples/constructor/main.d index c8fe62e..4c3d8ea 100644 --- a/examples/constructor/main.d +++ b/examples/constructor/main.d @@ -12,7 +12,7 @@ struct Color Color constructColorScalar(Mark start, Mark end, ref Node node) { - string value = node.get!string; + string value = node.as!string; if(value.length != 6) { @@ -51,9 +51,9 @@ Color constructColorMapping(Mark start, Mark end, ref Node node) //Might throw if a value is missing is not an integer, or is out of range. try { - r = node["r"].get!ubyte; - g = node["g"].get!ubyte; - b = node["b"].get!ubyte; + r = node["r"].as!ubyte; + g = node["g"].as!ubyte; + b = node["b"].as!ubyte; } catch(NodeException e) { @@ -80,10 +80,10 @@ void main() auto root = loader.load(); - if(root["scalar-red"].get!Color == red && - root["mapping-red"].get!Color == red && - root["scalar-orange"].get!Color == orange && - root["mapping-orange"].get!Color == orange) + if(root["scalar-red"].as!Color == red && + root["mapping-red"].as!Color == red && + root["scalar-orange"].as!Color == orange && + root["mapping-orange"].as!Color == orange) { writeln("SUCCESS"); return; diff --git a/examples/getting_started/main.d b/examples/getting_started/main.d index 26cd944..31508b6 100644 --- a/examples/getting_started/main.d +++ b/examples/getting_started/main.d @@ -11,7 +11,7 @@ void main() { writeln(word); } - writeln("The answer is ", root["Answer"].get!int); + writeln("The answer is ", root["Answer"].as!int); //Dump the loaded document to output.yaml. Dumper("output.yaml").dump(root); diff --git a/examples/representer/main.d b/examples/representer/main.d index 7c30007..92b00c6 100644 --- a/examples/representer/main.d +++ b/examples/representer/main.d @@ -11,7 +11,7 @@ struct Color Node representColor(ref Node node, Representer representer) { //The node is guaranteed to be Color as we add representer for Color. - Color color = node.get!Color; + Color color = node.as!Color; static immutable hex = "0123456789ABCDEF"; diff --git a/examples/resolver/main.d b/examples/resolver/main.d index 5cac6ab..efbd333 100644 --- a/examples/resolver/main.d +++ b/examples/resolver/main.d @@ -12,7 +12,7 @@ struct Color Color constructColorScalar(Mark start, Mark end, ref Node node) { - string value = node.get!string; + string value = node.as!string; if(value.length != 6) { @@ -51,9 +51,9 @@ Color constructColorMapping(Mark start, Mark end, ref Node node) //Might throw if a value is missing is not an integer, or is out of range. try { - r = node["r"].get!ubyte; - g = node["g"].get!ubyte; - b = node["b"].get!ubyte; + r = node["r"].as!ubyte; + g = node["g"].as!ubyte; + b = node["b"].as!ubyte; } catch(NodeException e) { @@ -85,10 +85,10 @@ void main() auto root = loader.load(); - if(root["scalar-red"].get!Color == red && - root["mapping-red"].get!Color == red && - root["scalar-orange"].get!Color == orange && - root["mapping-orange"].get!Color == orange) + if(root["scalar-red"].as!Color == red && + root["mapping-red"].as!Color == red && + root["scalar-orange"].as!Color == orange && + root["mapping-orange"].as!Color == orange) { writeln("SUCCESS"); return; diff --git a/examples/yaml_bench/Makefile b/examples/yaml_bench/Makefile index d16dffb..6fc6a4b 100644 --- a/examples/yaml_bench/Makefile +++ b/examples/yaml_bench/Makefile @@ -2,4 +2,4 @@ main: dmd -w -I../../ -L-L../../ -L-ldyaml yaml_bench.d clean: - rm yaml_stats yaml_bench.o + rm yaml_bench yaml_bench.o diff --git a/examples/yaml_bench/yaml_bench.d b/examples/yaml_bench/yaml_bench.d index 5bc3bda..6d05072 100644 --- a/examples/yaml_bench/yaml_bench.d +++ b/examples/yaml_bench/yaml_bench.d @@ -29,13 +29,13 @@ void extract(ref Node document) { if(root.isScalar) switch(root.tag) { - case "tag:yaml.org,2002:null": auto value = root.get!YAMLNull; break; - case "tag:yaml.org,2002:bool": auto value = root.get!bool; break; - case "tag:yaml.org,2002:int": auto value = root.get!long; break; - case "tag:yaml.org,2002:float": auto value = root.get!real; break; - case "tag:yaml.org,2002:binary": auto value = root.get!(ubyte[]); break; - case "tag:yaml.org,2002:timestamp": auto value = root.get!SysTime; break; - case "tag:yaml.org,2002:str": auto value = root.get!string; break; + case "tag:yaml.org,2002:null": auto value = root.as!YAMLNull; break; + case "tag:yaml.org,2002:bool": auto value = root.as!bool; break; + case "tag:yaml.org,2002:int": auto value = root.as!long; break; + case "tag:yaml.org,2002:float": auto value = root.as!real; break; + case "tag:yaml.org,2002:binary": auto value = root.as!(ubyte[]); break; + case "tag:yaml.org,2002:timestamp": auto value = root.as!SysTime; break; + case "tag:yaml.org,2002:str": auto value = root.as!string; break; default: writeln("Unrecognozed tag: ", root.tag); } else if(root.isSequence) foreach(ref Node node; root) diff --git a/examples/yaml_gen/yaml_gen.d b/examples/yaml_gen/yaml_gen.d index 40c2d91..9bc5630 100644 --- a/examples/yaml_gen/yaml_gen.d +++ b/examples/yaml_gen/yaml_gen.d @@ -75,7 +75,7 @@ string randomType(string[] types) auto probabilities = new uint[types.length]; foreach(index, type; types) { - probabilities[index] = config[type]["probability"].get!uint; + probabilities[index] = config[type]["probability"].as!uint; } return types[dice(probabilities)]; } @@ -84,8 +84,8 @@ Node genString(bool root = false) { auto range = config["string"]["range"]; - const chars = randomLong(range["min"].get!uint, range["max"].get!uint, - range["dist"].get!string); + const chars = randomLong(range["min"].as!uint, range["max"].as!uint, + range["dist"].as!string); char[] result = new char[chars]; result[0] = randomChar(alphabet); @@ -101,8 +101,8 @@ Node genInt(bool root = false) { auto range = config["int"]["range"]; - const result = randomLong(range["min"].get!int, range["max"].get!int, - range["dist"].get!string); + const result = randomLong(range["min"].as!int, range["max"].as!int, + range["dist"].as!string); return Node(result); } @@ -111,8 +111,8 @@ Node genFloat(bool root = false) { auto range = config["float"]["range"]; - const result = randomReal(range["min"].get!real, range["max"].get!real, - range["dist"].get!string); + const result = randomReal(range["min"].as!real, range["max"].as!real, + range["dist"].as!string); return Node(result); } @@ -126,10 +126,10 @@ Node genTimestamp(bool root = false) { auto range = config["timestamp"]["range"]; - auto hnsecs = randomLong(range["min"].get!ulong, range["max"].get!ulong, - range["dist"].get!string); + auto hnsecs = randomLong(range["min"].as!ulong, range["max"].as!ulong, + range["dist"].as!string); - if(randomNormalized() <= config["timestamp"]["round-chance"].get!real) + if(randomNormalized() <= config["timestamp"]["round-chance"].as!real) { hnsecs -= hnsecs % 10000000; } @@ -141,8 +141,8 @@ Node genBinary(bool root = false) { auto range = config["binary"]["range"]; - const bytes = randomLong(range["min"].get!uint, range["max"].get!uint, - range["dist"].get!string); + const bytes = randomLong(range["min"].as!uint, range["max"].as!uint, + range["dist"].as!string); ubyte[] result = new ubyte[bytes]; foreach(i; 0 .. bytes) @@ -167,8 +167,8 @@ Node nodes(in bool root, Node range, in string tag, in bool set = false) } else { - const elems = randomLong(range["min"].get!uint, range["max"].get!uint, - range["dist"].get!string); + const elems = randomLong(range["min"].as!uint, range["max"].as!uint, + range["dist"].as!string); nodes = new Node[elems]; foreach(i; 0 .. elems) @@ -204,8 +204,8 @@ Node pairs(bool root, bool complex, Node range, string tag) } else { - const pairs = randomLong(range["min"].get!uint, range["max"].get!uint, - range["dist"].get!string); + const pairs = randomLong(range["min"].as!uint, range["max"].as!uint, + range["dist"].as!string); keys = new Node[pairs]; values = new Node[pairs]; @@ -222,7 +222,7 @@ Node pairs(bool root, bool complex, Node range, string tag) Node genMap(bool root = false) { Node range = config["map"]["range"]; - const complex = config["complex-keys"].get!bool; + const complex = config["complex-keys"].as!bool; return pairs(root, complex, range, "tag:yaml.org,2002:map"); } @@ -230,7 +230,7 @@ Node genMap(bool root = false) Node genOmap(bool root = false) { Node range = config["omap"]["range"]; - const complex = config["complex-keys"].get!bool; + const complex = config["complex-keys"].as!bool; return pairs(root, complex, range, "tag:yaml.org,2002:omap"); } @@ -238,7 +238,7 @@ Node genOmap(bool root = false) Node genPairs(bool root = false) { Node range = config["pairs"]["range"]; - const complex = config["complex-keys"].get!bool; + const complex = config["complex-keys"].as!bool; return pairs(root, complex, range, "tag:yaml.org,2002:pairs"); } @@ -253,12 +253,12 @@ Node[] generate(in string configFileName) { config = Loader(configFileName).load(); - minNodesDocument = config["min-nodes-per-document"].get!long; + minNodesDocument = config["min-nodes-per-document"].as!long; Node[] result; - foreach(i; 0 .. config["documents"].get!uint) + foreach(i; 0 .. config["documents"].as!uint) { - result ~= generateNode(config["root-type"].get!string, true); + result ~= generateNode(config["root-type"].as!string, true); totalNodes = 0; } @@ -290,8 +290,8 @@ void main(string[] args) encoding == "utf-32" ? Encoding.UTF_32: Encoding.UTF_8; - dumper.indent = config["indent"].get!uint; - dumper.textWidth = config["text-width"].get!uint; + dumper.indent = config["indent"].as!uint; + dumper.textWidth = config["text-width"].as!uint; dumper.dump(generated); } catch(YAMLException e) diff --git a/test/src/constructor.d b/test/src/constructor.d index a8ba967..82c8b90 100644 --- a/test/src/constructor.d +++ b/test/src/constructor.d @@ -341,7 +341,7 @@ TestClass constructClass(Mark start, Mark end, ref Node node) { try { - return new TestClass(node["x"].get!int, node["y"].get!int, node["z"].get!int); + return new TestClass(node["x"].as!int, node["y"].as!int, node["z"].as!int); } catch(NodeException e) { @@ -352,7 +352,7 @@ TestClass constructClass(Mark start, Mark end, ref Node node) Node representClass(ref Node node, Representer representer) { - auto value = node.get!TestClass; + auto value = node.as!TestClass; auto pairs = [Node.Pair("x", value.x), Node.Pair("y", value.y), Node.Pair("z", value.z)]; @@ -364,14 +364,14 @@ Node representClass(ref Node node, Representer representer) ///Constructor function for TestStruct. TestStruct constructStruct(Mark start, Mark end, ref Node node) { - return TestStruct(to!int(node.get!string)); + return TestStruct(to!int(node.as!string)); } ///Representer function for TestStruct. Node representStruct(ref Node node, Representer representer) { string[] keys, values; - auto value = node.get!TestStruct; + auto value = node.as!TestStruct; return representer.representScalar("!tag2", to!string(value.value)); } diff --git a/test/src/inputoutput.d b/test/src/inputoutput.d index 1bce158..a549ebe 100644 --- a/test/src/inputoutput.d +++ b/test/src/inputoutput.d @@ -58,13 +58,13 @@ void testUnicodeInput(bool verbose, string unicodeFilename) string expected = data.split().join(" "); Node output = Loader(new MemoryStream(to!(char[])(data))).load(); - assert(output.get!string == expected); + assert(output.as!string == expected); foreach(stream; [new MemoryStream(cast(byte[])(bom16() ~ to!(wchar[])(data))), new MemoryStream(cast(byte[])(bom32() ~ to!(dchar[])(data)))]) { output = Loader(stream).load(); - assert(output.get!string == expected); + assert(output.as!string == expected); } }