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