aGrUM  0.14.2
utils_prm.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it udnder the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
21 #include <agrum/PRM/utils_prm.h>
22 
23 namespace gum {
24  namespace prm {
25 
26  // Decompose a string in a vector of strings using "." as separators.
27  void decomposePath(const std::string& path, std::vector< std::string >& v) {
28  size_t prev = 0;
29  size_t length = 0;
30  size_t idx_1 = path.find(".");
31  size_t idx_2 = path.find(PRMObject::LEFT_CAST());
32 
33  if (idx_2 == std::string::npos) {
34  // ignore safe names
35  size_t idx = idx_1;
36 
37  while (idx != std::string::npos) {
38  length = idx - prev;
39  v.push_back(path.substr(prev, length));
40  prev = idx + 1;
41  idx = path.find(".", prev);
42  }
43  } else {
44  size_t tmp = 0;
45 
46  while (idx_1 != std::string::npos) {
47  if (idx_1 < idx_2) {
48  length = idx_1 - prev;
49  v.push_back(path.substr(prev, length));
50  prev = idx_1 + 1;
51  idx_1 = path.find(".", prev);
52  } else if (idx_2 < idx_1) {
53  tmp = path.find(PRMObject::RIGHT_CAST(), idx_2);
54  idx_1 = path.find(".", tmp);
55  idx_2 = path.find(PRMObject::LEFT_CAST(), tmp);
56  }
57  }
58  }
59 
60  v.push_back(path.substr(prev, std::string::npos));
61  }
62 
64  static NodeId id = 0;
65  return ++id;
66  }
67 
68  } /* namespace prm */
69 } // namespace gum
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
NodeId nextNodeId()
Returns the next value of an unique counter for PRM&#39;s node id.
Definition: utils_prm.cpp:63
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:76
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:27
static std::string RIGHT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:77
Size NodeId
Type for node ids.
Definition: graphElements.h:97