List.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 <memory>
28
29// Base class
31
32// ArmarX
36#include "Dict.h"
37
38namespace armarx::aron::data
39{
40 class List;
41 typedef std::shared_ptr<List> ListPtr;
42
43 class List : public detail::ContainerVariant<data::dto::List, List>
44 {
45 public:
46 // constructors
47 List(const Path& path = Path());
48 List(const data::dto::ListPtr&, const Path& path = Path());
49 List(const std::vector<VariantPtr>&, const Path& path = Path());
50
51 // operators
52 using detail::ContainerVariant<data::dto::List, List>::operator==;
53
54 bool operator==(const List&) const override;
55 bool operator==(const ListPtr&) const override;
56
57 // static methods
58 static PointerType FromAronListDTO(const data::dto::ListPtr& aron);
59 static data::dto::ListPtr ToAronListDTO(const PointerType& navigator);
60
61 // public member functions
62 DictPtr getAsDict() const;
63
64 data::dto::ListPtr toAronListDTO() const;
65
66 void addElement(const VariantPtr&);
67
68 /// Pre-allocate for `size` elements. Used by the writers, which know the element
69 /// count up front, to avoid the repeated growth of both backing vectors.
70 void reserve(std::size_t size);
71
72 void setElement(unsigned int, const VariantPtr&);
73 VariantPtr getElement(unsigned int) const;
74 bool hasElement(unsigned int) const;
75 std::vector<VariantPtr> getElements() const;
76
77 void removeElement(unsigned int);
78
79 void clear();
80
81 // virtual implementations
82 using detail::ContainerVariant<data::dto::List, List>::clone;
83 ListPtr clone(const Path& p) const override;
84
85 std::string getShortName() const override;
86 std::string getFullName() const override;
87 std::vector<VariantPtr> getChildren() const override;
88 size_t childrenSize() const override;
89
90 type::VariantPtr recalculateType() const override;
91 bool fullfillsType(const type::VariantPtr&) const override;
92
93 VariantPtr navigateAbsolute(const Path& path) const override;
94
95 private:
96 std::vector<VariantPtr> childrenNavigators;
97 };
98} // namespace armarx::aron::data
99
100namespace armarx::aron
101{
102 template <typename... _Args>
104 make_list(_Args&&... args)
105 {
106 return std::make_shared<aron::data::List>(args...);
107 }
108} // namespace armarx::aron
The Path class.
Definition Path.h:36
size_t childrenSize() const override
get the children size of a data variant
Definition List.cpp:361
std::string getShortName() const override
get a short str representation of this variant
Definition List.cpp:243
List(const Path &path=Path())
Definition List.cpp:39
VariantPtr getElement(unsigned int) const
Definition List.cpp:199
bool hasElement(unsigned int) const
Definition List.cpp:193
std::vector< VariantPtr > getElements() const
Definition List.cpp:214
void addElement(const VariantPtr &)
Definition List.cpp:142
type::VariantPtr recalculateType() const override
recalculate the type of a data variant. Please not tha the mapping ist NOT bijective,...
Definition List.cpp:256
std::string getFullName() const override
get the full str representation of this variant
Definition List.cpp:249
void removeElement(unsigned int)
Definition List.cpp:220
static PointerType FromAronListDTO(const data::dto::ListPtr &aron)
Definition List.cpp:116
void reserve(std::size_t size)
Pre-allocate for size elements.
Definition List.cpp:148
data::dto::ListPtr toAronListDTO() const
Definition List.cpp:236
bool operator==(const List &) const override
Definition List.cpp:67
void setElement(unsigned int, const VariantPtr &)
Definition List.cpp:155
VariantPtr navigateAbsolute(const Path &path) const override
naviate absolute
Definition List.cpp:367
bool fullfillsType(const type::VariantPtr &) const override
checks, if the current data variant fullfills the given type
Definition List.cpp:263
static data::dto::ListPtr ToAronListDTO(const PointerType &navigator)
Definition List.cpp:126
std::vector< VariantPtr > getChildren() const override
get the children of a data variant
Definition List.cpp:355
ListPtr clone(const Path &p) const override
Definition List.cpp:103
DictPtr getAsDict() const
Definition List.cpp:133
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< List > ListPtr
Definition List.h:41
std::shared_ptr< Variant > VariantPtr
std::shared_ptr< Variant > VariantPtr
aron::data::ListPtr make_list(_Args &&... args)
Definition List.h:104