/[usata]/usata2/src/object.cpp
ViewVC logotype

Diff of /usata2/src/object.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by skunix, Mon Jan 10 06:58:12 2005 UTC revision 1.4 by skunix, Mon Jan 10 20:10:20 2005 UTC
# Line 4  Line 4 
4  #include <boost/bind.hpp>  #include <boost/bind.hpp>
5  #include <vector>  #include <vector>
6  #include <string>  #include <string>
7    #include <iostream>
8  #define USATA_NODE_PATH_SEPARATOR '/'  #define USATA_NODE_PATH_SEPARATOR '/'
9    
10  namespace usata  namespace usata
11  {  {
   
 namespace exceptions  
 {  
12  namespace  namespace
13  {  {
14          std::string valid_path_chars =  "abcdefghijklmnopqrstuvwxyz"          std::string valid_path_chars =  "abcdefghijklmnopqrstuvwxyz"
# Line 18  namespace Line 16  namespace
16                                          "1234567890_";                                          "1234567890_";
17    
18  }  }
 /*  
 template <typename T>  
 struct plus_equal : public binary_function(  
 */  
19  std::string  std::string
20  node_path_check(const std::string& path)  node_path_check(const std::string& path)
21  {  {
# Line 37  node_path_check(const std::string& path) Line 31  node_path_check(const std::string& path)
31    
32          // reassemble the path          // reassemble the path
33    
34          std::string r_path;          std::string rpath;
35  /*          vector<string>::iterator it(strv.begin());
36          std::for_each(strv.begin(), strv.end(),          rpath = *it;
37                          boost::bind(string::append, &r_path, _1));          ++it;
38  */                while (it != strv.end())
39            {
40                    rpath += USATA_NODE_PATH_SEPARATOR;
41                    rpath += *it;
42                    ++it;
43            }
44    
45          return string("");          return rpath;
46  }  }
47    
48    
49    void
50    NodeInterface::add(const Object_sp& obj, const std::string& _path)
51            throw (exceptions::NodeException)
52    {
53            using std::string;
54            using std::vector;
55            using namespace boost::algorithm;
56    
57            typedef vector<string>::iterator Iter;
58    
59            struct local
60            {
61                    static string rebuild(Iter b, Iter&e)
62                    {       string retval=*b;
63                            ++b;                    
64                            while (b != e)
65                            {
66                                    retval += USATA_NODE_PATH_SEPARATOR;
67                                    retval += *b;
68                                    ++b;
69                            }
70                            return retval;
71                    }
72                    
73            };
74    
75            string path = node_path_check(_path);
76            
77            vector<string> decomposed;
78    
79            split(decomposed, path, is_any_of("/"));
80            vector<string>::iterator decomp_it(decomposed.begin());
81            
82            Object_sp current_obj = get_child(*decomp_it);
83            if (!current_obj.get())
84            {
85                    throw std::runtime_error("w1");
86            }
87            decomp_it++;
88            NodeInterface * current_ni;
89            while (decomp_it != decomposed.end())
90            {
91                    std::cout << *decomp_it << std::endl;
92                    current_ni =
93                            dynamic_cast<NodeInterface*>(current_obj.get());
94                    if (!current_ni)
95                    {      
96                            using namespace exceptions;
97                            
98                            string badpath = local::rebuild(decomposed.begin(),
99                                                            decomp_it);
100                            // FIXME: gotta get a way to get the name of this
101                            // here
102                            throw NodePathNotNode(badpath, "");
103                    }
104            
105                    current_obj = current_ni->get_child(*decomp_it);
106                    if (!current_obj.get())
107                    {
108                            throw std::runtime_error("whoops");
109                    }
110                    
111                    ++decomp_it;
112            }
113            
114            current_ni = dynamic_cast<NodeInterface*>(current_obj.get());
115            
116            current_ni->add_child(obj);
117    
118            return;
119    }
120    
121    
122    namespace exceptions
123    {
124    
125    
126  NodeMissingChild::NodeMissingChild(const std::string& nn, const std::string& cn)  NodeMissingChild::NodeMissingChild(const std::string& nn, const std::string& cn)
127  :       child_name(nn),  :       child_name(nn),
128          container_name(cn),          container_name(cn),
# Line 76  NodeInterface::NodePathPop(std::string&n Line 153  NodeInterface::NodePathPop(std::string&n
153          return retval;          return retval;
154  }  }
155    
156    namespace exceptions
157    {
158    
159    
160            NodePathNotNode::NodePathNotNode(const std::string &path,
161                                             const std::string& base_node)
162            : NodeException(
163                    (boost::format("[%2%] %1% is not a node")%path%base_node).str())
164            {
165            
166            };
167    
168    }
169    
170    
171  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26