diff options
-rw-r--r-- | lib/element.cpp | 7 | ||||
-rw-r--r-- | lib/element_uid.cpp | 21 | ||||
-rw-r--r-- | tests/query_test.py | 6 |
3 files changed, 22 insertions, 12 deletions
diff --git a/lib/element.cpp b/lib/element.cpp index 04a638b..c06d96d 100644 --- a/lib/element.cpp +++ b/lib/element.cpp @@ -33,7 +33,7 @@ Element::Element(const std::string &name) catch(const std::invalid_argument &ex) { extra = str(boost::format("%04x") % short(h++)); - uid = name+"#"+extra; + uid = name+" "+extra; } } if (not extra.empty()) (*this)->repr = name; @@ -74,6 +74,11 @@ bool Element::equals(const Element &rhs) return this->get() == rhs.get(); } +std::string Element::to_string(void) const +{ + return (*this)->repr; +} + void Element::adopt_element(const std::string &name, const Element &child) { if (child->parent) throw std::invalid_argument(str(boost::format( diff --git a/lib/element_uid.cpp b/lib/element_uid.cpp index 89035b4..49daad9 100644 --- a/lib/element_uid.cpp +++ b/lib/element_uid.cpp @@ -15,32 +15,31 @@ static std::set<std::string> &get_uid_set(void) return uid_set; } -static void free_uid(void *p) +static void free_uid(std::string *s) { boost::mutex::scoped_lock l(uid_mutex); - std::string *uid = reinterpret_cast<std::string *>(p); - get_uid_set().erase(*uid); - delete uid; + get_uid_set().erase(*s); + delete s; } -void Element::set_uid(const std::string &uid) +static std::string *alloc_uid(const std::string &uid) { boost::mutex::scoped_lock l(uid_mutex); if (get_uid_set().count(uid) > 0) { throw std::invalid_argument("Element::set_uid - uid already in use: " + uid); } - (*this)->uid.reset(new std::string(uid), &free_uid); get_uid_set().insert(uid); + return new std::string(uid); } -std::string Element::get_uid(void) const +void Element::set_uid(const std::string &uid) { - boost::mutex::scoped_lock l(uid_mutex); - return *((*this)->uid); + (*this)->uid.reset(alloc_uid(uid), &free_uid); } -std::string Element::to_string(void) const +std::string Element::get_uid(void) const { - return (*this)->repr; + boost::mutex::scoped_lock l(uid_mutex); + return *((*this)->uid); } diff --git a/tests/query_test.py b/tests/query_test.py index ec8fade..3cbe648 100644 --- a/tests/query_test.py +++ b/tests/query_test.py @@ -65,12 +65,18 @@ class QueryTest(unittest.TestCase): vec_source = VectorSource(numpy.uint32, [0, 9, 8, 7, 6]) vec_sink = VectorSink(numpy.uint32) block = MyBlock() + block.set_uid("my_block_uid") self.tb.connect(vec_source, block, vec_sink) self.tb.run() #query the block list blocks_result = self.tb.query(dict(path="/blocks.json")) self.assertEqual(len(blocks_result['blocks']), 3) + self.assertTrue('my_block_uid' in blocks_result['blocks']) + + #set the property + + #get the property if __name__ == '__main__': unittest.main() |