aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
utils_prm.cpp
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 #include <agrum/PRM/utils_prm.h>
23 
24 namespace gum {
25  namespace prm {
26 
27  // Decompose a string in a vector of strings using "." as separators.
28  void decomposePath(const std::string& path, std::vector< std::string >& v) {
29  size_t prev = 0;
30  size_t length = 0;
31  size_t idx_1 = path.find(".");
32  size_t idx_2 = path.find(PRMObject::LEFT_CAST());
33 
34  if (idx_2 == std::string::npos) {
35  // ignore safe names
36  size_t idx = idx_1;
37 
38  while (idx != std::string::npos) {
39  length = idx - prev;
40  v.push_back(path.substr(prev, length));
41  prev = idx + 1;
42  idx = path.find(".", prev);
43  }
44  } else {
45  size_t tmp = 0;
46 
47  while (idx_1 != std::string::npos) {
48  if (idx_1 < idx_2) {
49  length = idx_1 - prev;
50  v.push_back(path.substr(prev, length));
51  prev = idx_1 + 1;
52  idx_1 = path.find(".", prev);
53  } else if (idx_2 < idx_1) {
54  tmp = path.find(PRMObject::RIGHT_CAST(), idx_2);
55  idx_1 = path.find(".", tmp);
56  idx_2 = path.find(PRMObject::LEFT_CAST(), tmp);
57  }
58  }
59  }
60 
61  v.push_back(path.substr(prev, std::string::npos));
62  }
63 
65  static NodeId id = 0;
66  return ++id;
67  }
68 
69  } /* namespace prm */
70 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
NodeId nextNodeId()
Returns the next value of an unique counter for PRM&#39;s node id.
Definition: utils_prm.cpp:64
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:28