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
33
34// ArmarX
38
39namespace 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
53 using detail::ContainerVariant<data::dto::Dict, Dict>::operator==;
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
103namespace 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
The Path class.
Definition Path.h:36
size_t childrenSize() const override
get the children size of a data variant
Definition Dict.cpp:429
void addElement(const std::string &key, const VariantPtr &=nullptr)
Definition Dict.cpp:170
void removeElement(const std::string &key)
Definition Dict.cpp:297
VariantPtr at(const std::string &) const
Definition Dict.cpp:311
std::string getShortName() const override
get a short str representation of this variant
Definition Dict.cpp:318
void setElement(const std::string &, const VariantPtr &=nullptr)
Definition Dict.cpp:256
data::dto::DictPtr toAronDictDTO() const
Definition Dict.cpp:146
VariantPtr operator[](const std::string &) const
Definition Dict.cpp:97
type::VariantPtr recalculateType() const override
recalculate the type of a data variant. Please not tha the mapping ist NOT bijective,...
Definition Dict.cpp:331
std::string getAllKeysAsString() const
Definition Dict.cpp:164
std::string getFullName() const override
get the full str representation of this variant
Definition Dict.cpp:324
void mergeAndReplace(const DictPtr &d)
Definition Dict.cpp:198
void mergeAndReplaceCopy(const DictPtr &d)
Definition Dict.cpp:213
static data::dto::DictPtr ToAronDictDTO(const PointerType &navigator)
Definition Dict.cpp:140
Dict & operator=(const Dict &)
Definition Dict.cpp:103
bool operator==(const Dict &) const override
Definition Dict.cpp:66
Dict(const Path &path=Path())
Definition Dict.cpp:39
void addElementCopy(const std::string &key, const VariantPtr &=nullptr)
Definition Dict.cpp:184
std::map< std::string, VariantPtr > getElements() const
Definition Dict.cpp:250
std::vector< std::string > getAllKeys() const
Definition Dict.cpp:153
void setElementCopy(const std::string &, const VariantPtr &=nullptr)
Definition Dict.cpp:283
VariantPtr navigateAbsolute(const Path &path) const override
naviate absolute
Definition Dict.cpp:435
static PointerType FromAronDictDTO(const data::dto::DictPtr &aron)
Definition Dict.cpp:130
bool fullfillsType(const type::VariantPtr &) const override
checks, if the current data variant fullfills the given type
Definition Dict.cpp:338
std::vector< VariantPtr > getChildren() const override
get the children of a data variant
Definition Dict.cpp:418
bool hasElement(const std::string &) const
Definition Dict.cpp:228
VariantPtr getElement(const std::string &) const
Definition Dict.cpp:234
::IceInternal::Handle< Dict > DictPtr
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< Variant > VariantPtr
std::shared_ptr< Variant > VariantPtr
aron::data::DictPtr make_dict(_Args &&... args)
Definition Dict.h:107