Variant.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 <string>
30 #include <vector>
31 
32 // Simox
33 // #include <SimoxUtility/algorithm/string.h>
34 
35 // ArmarX
36 #include <RobotAPI/interface/aron.h>
40 
41 namespace armarx::aron::type
42 {
44  typedef std::unique_ptr<VariantFactory> VariantFactoryPtr;
45 
46  class Variant;
47  typedef std::shared_ptr<Variant> VariantPtr;
48 
49  /**
50  * @brief The Variant class. This is the parent class of all type variant objects. It provides basic methods to get the children of a type, to get the descriptor, etc.
51  * Usually, you get a VariantPtr as input to your code. You can use the descriptor to find out, which specific type is behind a variant. It is type safe.
52  * For casting, every variant implementation provides the DynamicCast method, which casts a pointer to the static used type.
53  *
54  * This implementation wraps around the underlying ice object (armarx::aron::type::dto::XXX). All data is stored in the ice handle.
55  * However, for simplicity, container types also contain pointers to their children variants
56  *
57  * Each ice type object has a special member 'maybeType' which holds an enum containing the information of if this type is a pointer, an optional or something else.
58  */
59  class Variant
60  {
61  public:
63 
64  public:
65  // constructors
68  {
69  }
70 
71  virtual ~Variant() = default;
72 
73  // operators
74  virtual bool operator==(const Variant& other) const = 0;
75 
76  bool
77  operator==(const VariantPtr& other) const
78  {
79  if (!other)
80  {
81  return false;
82  }
83 
84  return *this == *other;
85  }
86 
87  // static methods
88  /// create a variant object from an dto object
89  static VariantPtr FromAronDTO(const type::dto::GenericType&, const Path& = Path());
90 
91  // public methods
93  getDescriptor() const
94  {
95  return descriptor;
96  }
97 
98  Path
99  getPath() const
100  {
101  return path;
102  }
103 
104  std::string
105  pathToString() const
106  {
107  return path.toString();
108  }
109 
110  // virtual methods
111  /// naviate absolute
112  virtual VariantPtr navigateAbsolute(const Path& path) const = 0;
113 
114  /// navigate relative
115  virtual VariantPtr navigateRelative(const Path& path) const = 0;
116 
117  /// get a short name of this specific type
118  virtual std::string getShortName() const = 0;
119 
120  /// get the full name of this specific type
121  virtual std::string getFullName() const = 0;
122 
123  /// get all child elements
124  virtual std::vector<VariantPtr> getChildren() const = 0;
125  virtual size_t childrenSize() const = 0;
126 
127  /// set the maybetype of this type
128  virtual void setMaybe(const type::Maybe m) = 0;
129 
130  /// get the maybe type
131  virtual type::Maybe getMaybe() const = 0;
132 
133  /// convert this variant to a dto object.
134  /// In most cases you have to use the specific conversion methods of each type implementation (e.g. to toIntDTO() to get an aron::type::dto::Int object)
135  virtual type::dto::GenericTypePtr toAronDTO() const = 0;
136 
137  protected:
139  const Path path;
140 
141  private:
142  static const VariantFactoryPtr FACTORY;
143  };
144 
145  template <class T>
147 } // namespace armarx::aron::type
armarx::aron::type::Variant::getShortName
virtual std::string getShortName() const =0
get a short name of this specific type
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::type::Variant::childrenSize
virtual size_t childrenSize() const =0
armarx::aron::type::Variant::operator==
bool operator==(const VariantPtr &other) const
Definition: Variant.h:77
Descriptor.h
armarx::aron::type::Variant::getFullName
virtual std::string getFullName() const =0
get the full name of this specific type
armarx::aron::type::Variant::FromAronDTO
static VariantPtr FromAronDTO(const type::dto::GenericType &, const Path &=Path())
create a variant object from an dto object
Definition: Variant.cpp:39
Path.h
armarx::aron::type::Variant::navigateAbsolute
virtual VariantPtr navigateAbsolute(const Path &path) const =0
naviate absolute
armarx::aron::type::Variant::getChildren
virtual std::vector< VariantPtr > getChildren() const =0
get all child elements
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::type::Variant
The Variant class.
Definition: Variant.h:59
armarx::aron::type::Variant::getMaybe
virtual type::Maybe getMaybe() const =0
get the maybe type
armarx::aron::type::Variant::navigateRelative
virtual VariantPtr navigateRelative(const Path &path) const =0
navigate relative
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::aron::type::Variant::pathToString
std::string pathToString() const
Definition: Variant.h:105
armarx::aron::type::VariantFactoryPtr
std::unique_ptr< VariantFactory > VariantFactoryPtr
Definition: Variant.h:43
armarx::aron::type::Variant::getDescriptor
type::Descriptor getDescriptor() const
Definition: Variant.h:93
armarx::aron::type::isVariant
concept isVariant
Definition: Variant.h:146
armarx::aron::type::Variant::~Variant
virtual ~Variant()=default
armarx::aron::type::Variant::setMaybe
virtual void setMaybe(const type::Maybe m)=0
set the maybetype of this type
armarx::aron::type
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:9
Exception.h
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::aron::type::Variant::operator==
virtual bool operator==(const Variant &other) const =0
armarx::aron::type::Variant::Variant
Variant(const type::Descriptor &descriptor, const Path &path=Path())
Definition: Variant.h:66
armarx::aron::type::Variant::path
const Path path
Definition: Variant.h:139
armarx::aron::type::Variant::PointerType
VariantPtr PointerType
Definition: Variant.h:62
armarx::aron::type::Variant::toAronDTO
virtual type::dto::GenericTypePtr toAronDTO() const =0
convert this variant to a dto object.
armarx::aron::type::Descriptor
Descriptor
Definition: Descriptor.h:76
armarx::aron::Path::toString
std::string toString() const
Definition: Path.cpp:125
armarx::aron::type::Variant::descriptor
const type::Descriptor descriptor
Definition: Variant.h:138
armarx::aron::type::VariantFactory
The VariantFactory class.
Definition: Factory.h:39
armarx::aron::type::Variant::getPath
Path getPath() const
Definition: Variant.h:99