File tree Expand file tree Collapse file tree 1 file changed +19
-13
lines changed
include/behaviortree_cpp/utils Expand file tree Collapse file tree 1 file changed +19
-13
lines changed Original file line number Diff line number Diff line change 16
16
#include < charconv>
17
17
#endif
18
18
19
- #include < exception>
20
- #include < algorithm>
21
- #include < iostream>
22
- #include < chrono>
23
19
#include < string>
24
- #include < cstring>
25
20
#include < type_traits>
26
21
#include < typeindex>
27
22
@@ -129,17 +124,17 @@ class Any
129
124
130
125
Any& operator = (const Any& other);
131
126
132
- bool isNumber () const ;
127
+ [[nodiscard]] bool isNumber () const ;
133
128
134
- bool isIntegral () const ;
129
+ [[nodiscard]] bool isIntegral () const ;
135
130
136
- bool isString () const
131
+ [[nodiscard]] bool isString () const
137
132
{
138
133
return _any.type () == typeid (SafeAny::SimpleString);
139
134
}
140
135
141
136
template <typename T>
142
- bool isType () const
137
+ [[nodiscard]] bool isType () const
143
138
{
144
139
return _any.type () == typeid (T);
145
140
}
@@ -154,7 +149,7 @@ class Any
154
149
155
150
// same as tryCast, but throws if fails
156
151
template <typename T>
157
- T cast () const {
152
+ [[nodiscard]] T cast () const {
158
153
if (auto res = tryCast<T>() )
159
154
{
160
155
return res.value ();
@@ -164,17 +159,28 @@ class Any
164
159
}
165
160
}
166
161
167
- const std::type_index& type () const noexcept
162
+ // Method to access the value by pointer
163
+ template <typename T>
164
+ [[nodiscard]] T* castPtr () const {
165
+
166
+ if ( _any.empty () )
167
+ {
168
+ return nullptr ;
169
+ }
170
+ return linb::any_cast<T>(&_any);
171
+ }
172
+
173
+ [[nodiscard]] const std::type_index& type () const noexcept
168
174
{
169
175
return _original_type;
170
176
}
171
177
172
- const std::type_info& castedType () const noexcept
178
+ [[nodiscard]] const std::type_info& castedType () const noexcept
173
179
{
174
180
return _any.type ();
175
181
}
176
182
177
- bool empty () const noexcept
183
+ [[nodiscard]] bool empty () const noexcept
178
184
{
179
185
return _any.empty ();
180
186
}
You can’t perform that action at this time.
0 commit comments