[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Usata-commits] Changes to usata2/src/object.cpp
From: |
David Lau |
Subject: |
[Usata-commits] Changes to usata2/src/object.cpp |
Date: |
Mon, 10 Jan 2005 15:26:08 -0500 |
Index: usata2/src/object.cpp
diff -u usata2/src/object.cpp:1.3 usata2/src/object.cpp:1.4
--- usata2/src/object.cpp:1.3 Mon Jan 10 06:58:12 2005
+++ usata2/src/object.cpp Mon Jan 10 20:10:20 2005
@@ -4,13 +4,11 @@
#include <boost/bind.hpp>
#include <vector>
#include <string>
+#include <iostream>
#define USATA_NODE_PATH_SEPARATOR '/'
namespace usata
{
-
-namespace exceptions
-{
namespace
{
std::string valid_path_chars = "abcdefghijklmnopqrstuvwxyz"
@@ -18,10 +16,6 @@
"1234567890_";
}
-/*
-template <typename T>
-struct plus_equal : public binary_function(
-*/
std::string
node_path_check(const std::string& path)
{
@@ -37,15 +31,98 @@
// reassemble the path
- std::string r_path;
-/*
- std::for_each(strv.begin(), strv.end(),
- boost::bind(string::append, &r_path, _1));
-*/
+ std::string rpath;
+ vector<string>::iterator it(strv.begin());
+ rpath = *it;
+ ++it;
+ while (it != strv.end())
+ {
+ rpath += USATA_NODE_PATH_SEPARATOR;
+ rpath += *it;
+ ++it;
+ }
- return string("");
+ return rpath;
}
+
+void
+NodeInterface::add(const Object_sp& obj, const std::string& _path)
+ throw (exceptions::NodeException)
+{
+ using std::string;
+ using std::vector;
+ using namespace boost::algorithm;
+
+ typedef vector<string>::iterator Iter;
+
+ struct local
+ {
+ static string rebuild(Iter b, Iter&e)
+ { string retval=*b;
+ ++b;
+ while (b != e)
+ {
+ retval += USATA_NODE_PATH_SEPARATOR;
+ retval += *b;
+ ++b;
+ }
+ return retval;
+ }
+
+ };
+
+ string path = node_path_check(_path);
+
+ vector<string> decomposed;
+
+ split(decomposed, path, is_any_of("/"));
+ vector<string>::iterator decomp_it(decomposed.begin());
+
+ Object_sp current_obj = get_child(*decomp_it);
+ if (!current_obj.get())
+ {
+ throw std::runtime_error("w1");
+ }
+ decomp_it++;
+ NodeInterface * current_ni;
+ while (decomp_it != decomposed.end())
+ {
+ std::cout << *decomp_it << std::endl;
+ current_ni =
+ dynamic_cast<NodeInterface*>(current_obj.get());
+ if (!current_ni)
+ {
+ using namespace exceptions;
+
+ string badpath = local::rebuild(decomposed.begin(),
+ decomp_it);
+ // FIXME: gotta get a way to get the name of this
+ // here
+ throw NodePathNotNode(badpath, "");
+ }
+
+ current_obj = current_ni->get_child(*decomp_it);
+ if (!current_obj.get())
+ {
+ throw std::runtime_error("whoops");
+ }
+
+ ++decomp_it;
+ }
+
+ current_ni = dynamic_cast<NodeInterface*>(current_obj.get());
+
+ current_ni->add_child(obj);
+
+ return;
+}
+
+
+namespace exceptions
+{
+
+
NodeMissingChild::NodeMissingChild(const std::string& nn, const std::string&
cn)
: child_name(nn),
container_name(cn),
@@ -76,5 +153,19 @@
return retval;
}
+namespace exceptions
+{
+
+
+ NodePathNotNode::NodePathNotNode(const std::string &path,
+ const std::string& base_node)
+ : NodeException(
+ (boost::format("[%2%] %1% is not a node")%path%base_node).str())
+ {
+
+ };
+
+}
+
}