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#include <string>
27#include <vector>
28
29namespace armarx::aron
30{
31 /**
32 * @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.
33 * Further, it can be used to navigate through a type or data object
34 */
35 class Path
36 {
37 public:
38 static const constexpr char* DEFAULT_ROOT_IDENTIFIER = "_ARON";
39 static const constexpr char* DEFAULT_DELIMETER = "->";
40
41 /// default constructor
42 Path();
43
44 /// default constructor, taking a list of strings (a path)
45 Path(const std::vector<std::string>&);
46
47 /// copy constructor
48 Path(const Path&);
49
50 /// append constructor
51 Path(const Path&, const std::vector<std::string>&);
52
53 /// copy operator
54 Path& operator=(const armarx::aron::Path&) = default;
55
56 std::vector<std::string> getPath() const;
57 std::string getFirstElement() const;
58 std::string getLastElement() const;
59 bool hasElement() const;
60 size_t size() const;
61
62 Path withIndex(int, bool escape = false) const;
63 Path withElement(const std::string&, bool escape = false) const;
64 Path withAcceptedType(bool escape = false) const;
65 Path withAcceptedTypeIndex(int, bool escape = false) const;
66
67 void setRootIdentifier(const std::string&);
68 std::string getRootIdentifier() const;
69
70 void setDelimeter(const std::string&);
71 std::string getDelimeter() const;
72
73 std::string toString() const;
74 static Path FromString(const std::string&,
75 const std::string& rootIdentifier = DEFAULT_ROOT_IDENTIFIER,
76 const std::string& delimeter = DEFAULT_DELIMETER);
77
80 Path getWithoutPrefix(const Path&) const;
81
82 bool hasPrefix(const Path&) const;
83 bool hasDirectPrefix(const Path&) const;
84
85 private:
86 void append(const std::string&);
87
88 private:
89 std::string rootIdentifier;
90 std::string delimeter;
91 std::vector<std::string> path;
92 };
93} // namespace armarx::aron
The Path class.
Definition Path.h:36
void setRootIdentifier(const std::string &)
Definition Path.cpp:57
Path withDetachedFirstElement() const
Definition Path.cpp:207
Path getWithoutPrefix(const Path &) const
Definition Path.cpp:218
static Path FromString(const std::string &, const std::string &rootIdentifier=DEFAULT_ROOT_IDENTIFIER, const std::string &delimeter=DEFAULT_DELIMETER)
Definition Path.cpp:139
bool hasDirectPrefix(const Path &) const
Definition Path.cpp:265
std::string toString() const
Definition Path.cpp:127
size_t size() const
Definition Path.cpp:121
bool hasPrefix(const Path &) const
Definition Path.cpp:242
bool hasElement() const
Definition Path.cpp:115
Path withIndex(int, bool escape=false) const
Definition Path.cpp:152
std::vector< std::string > getPath() const
Definition Path.cpp:87
std::string getLastElement() const
Definition Path.cpp:93
Path withElement(const std::string &, bool escape=false) const
Definition Path.cpp:163
Path withAcceptedType(bool escape=false) const
Definition Path.cpp:174
Path withAcceptedTypeIndex(int, bool escape=false) const
Definition Path.cpp:185
static const constexpr char * DEFAULT_ROOT_IDENTIFIER
Definition Path.h:38
Path()
default constructor
Definition Path.cpp:34
Path withDetachedLastElement() const
Definition Path.cpp:196
std::string getFirstElement() const
Definition Path.cpp:104
Path & operator=(const armarx::aron::Path &)=default
copy operator
std::string getDelimeter() const
Definition Path.cpp:75
void setDelimeter(const std::string &)
Definition Path.cpp:69
static const constexpr char * DEFAULT_DELIMETER
Definition Path.h:39
std::string getRootIdentifier() const
Definition Path.cpp:63