aGrUM  0.16.0
utils_prm.cpp
Go to the documentation of this file.
1 
23 #include <agrum/PRM/utils_prm.h>
24 
25 namespace gum {
26  namespace prm {
27 
28  // Decompose a string in a vector of strings using "." as separators.
29  void decomposePath(const std::string& path, std::vector< std::string >& v) {
30  size_t prev = 0;
31  size_t length = 0;
32  size_t idx_1 = path.find(".");
33  size_t idx_2 = path.find(PRMObject::LEFT_CAST());
34 
35  if (idx_2 == std::string::npos) {
36  // ignore safe names
37  size_t idx = idx_1;
38 
39  while (idx != std::string::npos) {
40  length = idx - prev;
41  v.push_back(path.substr(prev, length));
42  prev = idx + 1;
43  idx = path.find(".", prev);
44  }
45  } else {
46  size_t tmp = 0;
47 
48  while (idx_1 != std::string::npos) {
49  if (idx_1 < idx_2) {
50  length = idx_1 - prev;
51  v.push_back(path.substr(prev, length));
52  prev = idx_1 + 1;
53  idx_1 = path.find(".", prev);
54  } else if (idx_2 < idx_1) {
55  tmp = path.find(PRMObject::RIGHT_CAST(), idx_2);
56  idx_1 = path.find(".", tmp);
57  idx_2 = path.find(PRMObject::LEFT_CAST(), tmp);
58  }
59  }
60  }
61 
62  v.push_back(path.substr(prev, std::string::npos));
63  }
64 
66  static NodeId id = 0;
67  return ++id;
68  }
69 
70  } /* namespace prm */
71 } // namespace gum
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
NodeId nextNodeId()
Returns the next value of an unique counter for PRM&#39;s node id.
Definition: utils_prm.cpp:65
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:79
void decomposePath(const std::string &path, std::vector< std::string > &v)
Decompose a string in a vector of strings using "." as separators.
Definition: utils_prm.cpp:29
static std::string RIGHT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:80
Size NodeId
Type for node ids.
Definition: graphElements.h:98