Path.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 // STD/STL
27 #include <string>
28 #include <vector>
29 
30 namespace armarx::aron
31 {
32  /**
33  * @brief The Path class. It is used to keep track of the internal tree-like structure of a variant and can be converted into a string for debugging purposes and exception message generation.
34  * Further, it can be used to navigate through a type or data object
35  */
36  class Path
37  {
38  public:
39  static const constexpr char* DEFAULT_ROOT_IDENTIFIER = "_ARON";
40  static const constexpr char* DEFAULT_DELIMETER = "->";
41 
42  /// default constructor
43  Path();
44 
45  /// default constructor, taking a list of strings (a path)
46  Path(const std::vector<std::string>&);
47 
48  /// copy constructor
49  Path(const Path&);
50 
51  /// append constructor
52  Path(const Path&, const std::vector<std::string>&);
53 
54  /// copy operator
55  Path& operator=(const armarx::aron::Path&) = default;
56 
57  std::vector<std::string> getPath() const;
58  std::string getFirstElement() const;
59  std::string getLastElement() const;
60  bool hasElement() const;
61  size_t size() const;
62 
63  Path withIndex(int, bool escape = false) const;
64  Path withElement(const std::string&, bool escape = false) const;
65  Path withAcceptedType(bool escape = false) const;
66  Path withAcceptedTypeIndex(int, bool escape = false) const;
67 
68  void setRootIdentifier(const std::string&);
69  std::string getRootIdentifier() const;
70 
71  void setDelimeter(const std::string&);
72  std::string getDelimeter() const;
73 
74  std::string toString() const;
75  static Path FromString(const std::string&,
76  const std::string& rootIdentifier = DEFAULT_ROOT_IDENTIFIER,
77  const std::string& delimeter = DEFAULT_DELIMETER);
78 
81  Path getWithoutPrefix(const Path&) const;
82 
83  bool hasPrefix(const Path&) const;
84  bool hasDirectPrefix(const Path&) const;
85 
86  private:
87  void append(const std::string&);
88 
89  private:
90  std::string rootIdentifier;
91  std::string delimeter;
92  std::vector<std::string> path;
93  };
94 } // namespace armarx::aron
armarx::aron::Path::DEFAULT_DELIMETER
static const constexpr char * DEFAULT_DELIMETER
Definition: Path.h:40
armarx::aron::Path::withElement
Path withElement(const std::string &, bool escape=false) const
Definition: Path.cpp:161
armarx::aron::Path::getFirstElement
std::string getFirstElement() const
Definition: Path.cpp:102
armarx::aron::Path::hasElement
bool hasElement() const
Definition: Path.cpp:113
armarx::aron::Path::withAcceptedTypeIndex
Path withAcceptedTypeIndex(int, bool escape=false) const
Definition: Path.cpp:183
armarx::aron::Path::size
size_t size() const
Definition: Path.cpp:119
armarx::aron::Path::getDelimeter
std::string getDelimeter() const
Definition: Path.cpp:73
armarx::aron::Path::withIndex
Path withIndex(int, bool escape=false) const
Definition: Path.cpp:150
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::Path::DEFAULT_ROOT_IDENTIFIER
static const constexpr char * DEFAULT_ROOT_IDENTIFIER
Definition: Path.h:39
armarx::aron::Path::hasPrefix
bool hasPrefix(const Path &) const
Definition: Path.cpp:240
armarx::aron::Path::setRootIdentifier
void setRootIdentifier(const std::string &)
Definition: Path.cpp:55
armarx::aron::Path::setDelimeter
void setDelimeter(const std::string &)
Definition: Path.cpp:67
armarx::aron
Definition: DataDisplayVisitor.cpp:5
armarx::aron::Path::FromString
static Path FromString(const std::string &, const std::string &rootIdentifier=DEFAULT_ROOT_IDENTIFIER, const std::string &delimeter=DEFAULT_DELIMETER)
Definition: Path.cpp:137
armarx::aron::Path::Path
Path()
default constructor
Definition: Path.cpp:32
armarx::aron::Path::hasDirectPrefix
bool hasDirectPrefix(const Path &) const
Definition: Path.cpp:263
armarx::aron::Path::operator=
Path & operator=(const armarx::aron::Path &)=default
copy operator
armarx::aron::Path::getLastElement
std::string getLastElement() const
Definition: Path.cpp:91
armarx::aron::Path::withAcceptedType
Path withAcceptedType(bool escape=false) const
Definition: Path.cpp:172
armarx::aron::Path::withDetachedLastElement
Path withDetachedLastElement() const
Definition: Path.cpp:194
armarx::aron::Path::withDetachedFirstElement
Path withDetachedFirstElement() const
Definition: Path.cpp:205
armarx::aron::Path::getRootIdentifier
std::string getRootIdentifier() const
Definition: Path.cpp:61
armarx::aron::Path::getWithoutPrefix
Path getWithoutPrefix(const Path &) const
Definition: Path.cpp:216
armarx::aron::Path::getPath
std::vector< std::string > getPath() const
Definition: Path.cpp:85
armarx::aron::Path::toString
std::string toString() const
Definition: Path.cpp:125