Dict.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 <map>
28 #include <memory>
29 #include <utility>
30 
31 // Base class
32 #include "../detail/ContainerVariant.h"
33 
34 // ArmarX
35 #include "../../../type/variant/any/AnyObject.h"
36 #include "../../../type/variant/container/Dict.h"
37 #include "../../../type/variant/container/Object.h"
38 
39 namespace armarx::aron::data
40 {
41  class Dict;
42  typedef std::shared_ptr<Dict> DictPtr;
43 
44  class Dict : public detail::ContainerVariant<data::dto::Dict, Dict>
45  {
46  public:
47  // constructors
48  Dict(const Path& path = Path());
49  Dict(const data::dto::DictPtr&, const Path& path = Path());
50  Dict(const std::map<std::string, VariantPtr>&, const Path& path = Path());
51 
52  // operators
54 
55  bool operator==(const Dict&) const override;
56  bool operator==(const DictPtr&) const override;
57  VariantPtr operator[](const std::string&) const;
58  Dict& operator=(const Dict&);
59 
61  static data::dto::DictPtr ToAronDictDTO(const PointerType& navigator);
62 
63  // public member functions
65  std::vector<std::string> getAllKeys() const;
66  std::string getAllKeysAsString() const;
67 
68  void addElement(const std::string& key, const VariantPtr& = nullptr);
69  void addElementCopy(const std::string& key, const VariantPtr& = nullptr);
70  bool hasElement(const std::string&) const;
71  void setElement(const std::string&, const VariantPtr& = nullptr);
72  void setElementCopy(const std::string&, const VariantPtr& = nullptr);
73  VariantPtr getElement(const std::string&) const;
74  std::map<std::string, VariantPtr> getElements() const;
75 
76  void mergeAndReplace(const DictPtr& d);
77  void mergeAndReplaceCopy(const DictPtr& d);
78 
79  VariantPtr at(const std::string&) const;
80  void removeElement(const std::string& key);
81  void clear();
82 
83  // virtual implementations
84  using Base::clone;
85  DictPtr clone(const Path& p) const override;
86 
87  std::string getShortName() const override;
88  std::string getFullName() const override;
89  std::vector<VariantPtr> getChildren() const override;
90  size_t childrenSize() const override;
91 
92  type::VariantPtr recalculateType() const override;
93  bool fullfillsType(const type::VariantPtr&) const override;
94 
95  VariantPtr navigateAbsolute(const Path& path) const override;
96 
97  private:
98  // members
99  std::map<std::string, VariantPtr> childrenNavigators;
100  };
101 } // namespace armarx::aron::data
102 
103 namespace armarx::aron
104 {
105  template <typename... _Args>
107  make_dict(_Args&&... args)
108  {
109  return std::make_shared<aron::data::Dict>(args...);
110  }
111 } // namespace armarx::aron
armarx::aron::data::Dict::recalculateType
type::VariantPtr recalculateType() const override
recalculate the type of a data variant. Please not tha the mapping ist NOT bijective,...
Definition: Dict.cpp:329
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::data::Dict::removeElement
void removeElement(const std::string &key)
Definition: Dict.cpp:295
armarx::aron::make_dict
aron::data::DictPtr make_dict(_Args &&... args)
Definition: Dict.h:107
armarx::aron::data::Dict::addElementCopy
void addElementCopy(const std::string &key, const VariantPtr &=nullptr)
Definition: Dict.cpp:183
armarx::aron::data::Variant::PointerType
VariantPtr PointerType
Definition: Variant.h:63
armarx::aron::data::Dict::getElement
VariantPtr getElement(const std::string &) const
Definition: Dict.cpp:233
armarx::aron::data::Variant::path
const Path path
Definition: Variant.h:156
armarx::aron::data::Dict::operator=
Dict & operator=(const Dict &)
Definition: Dict.cpp:102
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::clone
virtual PointerType clone() const
Definition: SpecializedVariant.h:82
armarx::aron::data::Dict::mergeAndReplace
void mergeAndReplace(const DictPtr &d)
Definition: Dict.cpp:197
armarx::aron::data::Dict::FromAronDictDTO
static PointerType FromAronDictDTO(const data::dto::DictPtr &aron)
Definition: Dict.cpp:129
armarx::aron::data::Dict::getAllKeys
std::vector< std::string > getAllKeys() const
Definition: Dict.cpp:152
armarx::aron::data::Dict::navigateAbsolute
VariantPtr navigateAbsolute(const Path &path) const override
naviate absolute
Definition: Dict.cpp:433
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::data::Dict::operator==
bool operator==(const Dict &) const override
Definition: Dict.cpp:65
armarx::aron::data::Dict::fullfillsType
bool fullfillsType(const type::VariantPtr &) const override
checks, if the current data variant fullfills the given type
Definition: Dict.cpp:336
armarx::aron::data::Dict::addElement
void addElement(const std::string &key, const VariantPtr &=nullptr)
Definition: Dict.cpp:169
armarx::aron
Definition: DataDisplayVisitor.cpp:5
armarx::aron::data::Dict::clear
void clear()
Definition: Dict.cpp:302
armarx::aron::data::detail::ContainerVariant
Definition: ContainerVariant.h:37
armarx::aron::data::Dict::hasElement
bool hasElement(const std::string &) const
Definition: Dict.cpp:227
armarx::aron::data::Dict::Dict
Dict(const Path &path=Path())
Definition: Dict.cpp:38
armarx::aron::data::Dict::ToAronDictDTO
static data::dto::DictPtr ToAronDictDTO(const PointerType &navigator)
Definition: Dict.cpp:139
armarx::aron::data::Dict::at
VariantPtr at(const std::string &) const
Definition: Dict.cpp:309
armarx::aron::data
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:3
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::aron::data::Dict::operator[]
VariantPtr operator[](const std::string &) const
Definition: Dict.cpp:96
armarx::aron::data::Dict::getElements
std::map< std::string, VariantPtr > getElements() const
Definition: Dict.cpp:249
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::aron::data::Dict::mergeAndReplaceCopy
void mergeAndReplaceCopy(const DictPtr &d)
Definition: Dict.cpp:212
armarx::aron::data::Dict::setElementCopy
void setElementCopy(const std::string &, const VariantPtr &=nullptr)
Definition: Dict.cpp:281
armarx::aron::data::Dict::getChildren
std::vector< VariantPtr > getChildren() const override
get the children of a data variant
Definition: Dict.cpp:416
armarx::aron::data::Dict::childrenSize
size_t childrenSize() const override
get the children size of a data variant
Definition: Dict.cpp:427
armarx::aron::data::Dict::getAllKeysAsString
std::string getAllKeysAsString() const
Definition: Dict.cpp:163
armarx::aron::data::Dict::getFullName
std::string getFullName() const override
get the full str representation of this variant
Definition: Dict.cpp:322
armarx::aron::data::Dict::getShortName
std::string getShortName() const override
get a short str representation of this variant
Definition: Dict.cpp:316
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::aron
AronDataType::PointerType aron
Definition: SpecializedVariant.h:154
armarx::aron::data::Dict::setElement
void setElement(const std::string &, const VariantPtr &=nullptr)
Definition: Dict.cpp:255
armarx::aron::data::Dict
Definition: Dict.h:44
armarx::aron::data::Dict::toAronDictDTO
data::dto::DictPtr toAronDictDTO() const
Definition: Dict.cpp:145