import std.exception; import std.math; import gfx.decl.sdlang.parser; auto root = parseSource(` foo 1 true 2 false `); auto foo = root.getTag("foo"); assert( foo.expectValue!int() == 1 ); assert( foo.expectValue!bool() == true ); // No strings or floats found // If you'd rather receive a default value than an exception, use `getValue` instead. assertThrown!ValueNotFoundException( foo.expectValue!string() ); assertThrown!ValueNotFoundException( foo.expectValue!float() );
Retrieve a value of type T from this tag. Throws if not found.
Useful if you only expect one value of type T from this tag. Only looks for values of this tag, it does not search child tags. If you wish to search for a value in a child tag (for example, if this current tag is a root tag), try expectTagValue.
If you want to get more than one value from this tag, use values instead.
If this tag has multiple values, the first value matching the requested type will be returned. Ie, Extra values in the tag are ignored.
An sdlang.exception.ValueNotFoundException will be thrown if no value of the requested type can be found. If you'd rather receive a default value, use getValue instead.