Bool.cpp
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 #include "Bool.h"
25 
26 namespace armarx::aron::data
27 {
28  /* constructors */
29  Bool::Bool(const data::dto::AronBoolPtr& o, const Path& path) :
30  detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant(
31  o,
32  data::Descriptor::BOOL,
33  path)
34  {
35  }
36 
37  Bool::Bool(const Path& path) :
38  detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant(
39  data::Descriptor::BOOL,
40  path)
41  {
42  }
43 
44  Bool::Bool(const bool d, const Path& path) :
45  detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant(
46  d,
47  data::Descriptor::BOOL,
48  path)
49  {
50  }
51 
52  /* operators */
53  bool
54  Bool::operator==(const Bool& other) const
55  {
56  const auto& otherAron = other.toAronBoolDTO();
57  if (aron->value != otherAron->value)
58  {
59  return false;
60  }
61  return true;
62  }
63 
64  bool
65  Bool::operator==(const BoolPtr& other) const
66  {
67  if (!other)
68  {
69  return false;
70  }
71  return *this == *other;
72  }
73 
74  /* static methods */
75  BoolPtr
76  Bool::FromAronBoolDTO(const data::dto::AronBoolPtr& aron)
77  {
78  if (!aron)
79  {
80  return nullptr;
81  }
82  return std::make_shared<Bool>(aron);
83  }
84 
85  data::dto::AronBoolPtr
86  Bool::ToAronBoolDTO(const BoolPtr& navigator)
87  {
88  return navigator ? navigator->toAronBoolDTO() : nullptr;
89  }
90 
91  /* public member functions */
92  data::dto::AronBoolPtr
94  {
95  return aron;
96  }
97 
98  /* virtual implementations */
99  void
100  Bool::fromString(const std::string& setter)
101  {
102  if (setter == "true" || setter == "1" || setter == "yes")
103  {
104  setValue(true);
105  }
106  else if (setter == "false" || setter == "0" || setter == "no")
107  {
108  setValue(false);
109  }
110  else
111  {
112  ARMARX_TRACE;
113  throw error::AronException(__PRETTY_FUNCTION__,
114  "Could not set from string. Got: '" + setter + "'");
115  }
116  }
117 
118  std::string
120  {
121  return "Bool";
122  }
123 
124  std::string
126  {
127  return "armarx::aron::data::Bool";
128  }
129 
130  bool
132  {
133  if (!type)
134  return true;
135  return type->getDescriptor() == type::Descriptor::BOOL;
136  }
137 
140  {
141  ARMARX_TRACE;
142  throw error::NotImplementedYetException(__PRETTY_FUNCTION__);
143  //return std::make_shared<type::Bool>(getPath());
144  }
145 } // namespace armarx::aron::data
armarx::aron::data::Bool::toAronBoolDTO
data::dto::AronBoolPtr toAronBoolDTO() const
Definition: Bool.cpp:93
armarx::aron::error::AronException
A base class for aron exceptions.
Definition: Exception.h:42
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::data::Bool
Definition: Bool.h:41
armarx::aron::data::Bool::Bool
Bool(const Path &=Path())
Definition: Bool.cpp:37
detail
Definition: OpenCVUtil.cpp:127
armarx::aron::data::Descriptor
Descriptor
Definition: Descriptor.h:193
armarx::aron::error::NotImplementedYetException
The NotImplementedYetException class.
Definition: Exception.h:88
armarx::aron::data::Bool::fromString
void fromString(const std::string &setter) override
set a primitive from a std string
Definition: Bool.cpp:100
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::type::Descriptor::BOOL
@ BOOL
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
Bool.h
armarx::aron::data::Bool::recalculateType
type::VariantPtr recalculateType() const override
recalculate the type of a data variant. Please not tha the mapping ist NOT bijective,...
Definition: Bool.cpp:139
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::aron::data::Bool::getShortName
std::string getShortName() const override
get a short str representation of this variant
Definition: Bool.cpp:119
armarx::aron::data::Bool::fullfillsType
bool fullfillsType(const type::VariantPtr &) const override
checks, if the current data variant fullfills the given type
Definition: Bool.cpp:131
armarx::aron::data
A convenience header to include all aron files (full include, not forward declared)
Definition: aron_conversions.cpp:3
armarx::aron::data::Bool::ToAronBoolDTO
static data::dto::AronBoolPtr ToAronBoolDTO(const BoolPtr &navigator)
Definition: Bool.cpp:86
armarx::aron::data::Bool::FromAronBoolDTO
static BoolPtr FromAronBoolDTO(const data::dto::AronBoolPtr &aron)
Definition: Bool.cpp:76
armarx::aron::data::Bool::getFullName
std::string getFullName() const override
get the full str representation of this variant
Definition: Bool.cpp:125
armarx::aron::data::detail::SpecializedVariantBase< data::dto::AronBool, Bool >::aron
AronDataType::PointerType aron
Definition: SpecializedVariant.h:154
armarx::aron::data::detail::PrimitiveVariant< data::dto::AronBool, bool, Bool >::setValue
void setValue(const bool &x)
Definition: PrimitiveVariant.h:126
armarx::aron::data::Bool::operator==
bool operator==(const Bool &other) const override
Definition: Bool.cpp:54
armarx::aron::data::BoolPtr
std::shared_ptr< Bool > BoolPtr
Definition: forward_declarations.h:38