diff options
author | David Robillard <d@drobilla.net> | 2013-01-14 05:20:55 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-14 05:20:55 +0000 |
commit | fc5305aedf9896cf083646885dbccd3d706cb94f (patch) | |
tree | 3c069458099d230a118a20a05ea8d391ad969bbb /sord/sordmm.hpp | |
parent | 51996c2730424f07c1f8487c3e42d594a1053a1c (diff) | |
download | sord-fc5305aedf9896cf083646885dbccd3d706cb94f.tar.gz sord-fc5305aedf9896cf083646885dbccd3d706cb94f.tar.bz2 sord-fc5305aedf9896cf083646885dbccd3d706cb94f.zip |
Add convenient numeric constructors for decimal and integer literals.
git-svn-id: http://svn.drobilla.net/sord/trunk@276 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'sord/sordmm.hpp')
-rw-r--r-- | sord/sordmm.hpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/sord/sordmm.hpp b/sord/sordmm.hpp index 4f3b609..d839d1b 100644 --- a/sord/sordmm.hpp +++ b/sord/sordmm.hpp @@ -151,6 +151,7 @@ public: inline Node(World& world, Type t, const std::string& s); inline Node(World& world); inline Node(World& world, const SordNode* node); + inline Node(World& world, SordNode* node, bool copy=false); inline Node(const Node& other); inline ~Node(); @@ -240,6 +241,30 @@ class Literal : public Node { public: inline Literal(World& world, const std::string& s) : Node(world, Node::LITERAL, s) {} + + static inline Node decimal(World& world, double d, unsigned frac_digits) { + const SerdNode val = serd_node_new_decimal(d, 7); + const SerdNode type = serd_node_from_string( + SERD_URI, (const uint8_t*)SORD_NS_XSD "decimal"); + + return Node( + world, + sord_node_from_serd_node( + world.c_obj(), world.prefixes().c_obj(), &val, &type, NULL), + false); + } + + static inline Node integer(World& world, int64_t i) { + const SerdNode val = serd_node_new_integer(i); + const SerdNode type = serd_node_from_string( + SERD_URI, (const uint8_t*)SORD_NS_XSD "integer"); + + return Node( + world, + sord_node_from_serd_node( + world.c_obj(), world.prefixes().c_obj(), &val, &type, NULL), + false); + } }; inline @@ -278,7 +303,14 @@ inline Node::Node(World& world, const SordNode* node) : _world(&world) { - _c_obj = node ? sord_node_copy(node) : NULL; + _c_obj = sord_node_copy(node); +} + +inline +Node::Node(World& world, SordNode* node, bool copy) + : _world(&world) +{ + _c_obj = copy ? sord_node_copy(node) : node; } inline |