YARP
Yet Another Robot Platform
Searchable.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_SEARCHABLE_H
8 #define YARP_OS_SEARCHABLE_H
9 
10 #include <yarp/os/api.h>
11 
12 #include <cstddef>
13 #include <string>
14 
15 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
16 #define YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE
17 # include <yarp/os/ConstString.h>
18 #undef YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE
19 #endif // YARP_NO_DEPRECATED
20 
21 
22 namespace yarp {
23 namespace os {
24 class Value;
25 class Bottle;
26 } // namespace os
27 } // namespace yarp
28 
29 namespace yarp {
30 namespace os {
31 
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 
34 class YARP_os_API SearchReport
35 {
36 public:
38  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) value;
39  bool isFound;
40  bool isGroup;
41  bool isComment;
42  bool isDefault;
43 
44  explicit SearchReport();
45 };
46 
47 class YARP_os_API SearchMonitor
48 {
49 public:
50  virtual ~SearchMonitor();
51  virtual void report(const SearchReport& report, const char* context) = 0;
52 };
53 
54 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
55 
56 
66 {
67 private:
68  SearchMonitor* monitor;
69  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) monitorContext;
70 
71 public:
75  explicit Searchable();
76 
80  Searchable(const Searchable& rhs) = default;
81 
85  Searchable(Searchable&& rhs) noexcept = default;
86 
90  virtual ~Searchable();
91 
95  Searchable& operator=(const Searchable& rhs) = default;
96 
100  Searchable& operator=(Searchable&& rhs) noexcept = default;
101 
108  virtual bool check(const std::string& key) const = 0;
109 
110 
118  virtual bool check(const std::string& key,
119  const std::string& comment) const;
120 
129  virtual Value& find(const std::string& key) const = 0;
130 
141  virtual Bottle& findGroup(const std::string& key) const = 0;
142 
154  Bottle& findGroup(const std::string& key, const std::string& comment) const;
155 
181  virtual bool check(const std::string& key,
182  Value*& result,
183  const std::string& comment = "") const;
184 
185 
195  virtual Value check(const std::string& key,
196  const Value& fallback,
197  const std::string& comment = "") const;
198 
203  virtual bool isNull() const;
204 
212  virtual std::string toString() const = 0;
213 
214 #ifndef DOXYGEN_SHOULD_SKIP_THIS
215  virtual void setMonitor(SearchMonitor* monitor, const char* context = "");
216  virtual SearchMonitor* getMonitor() const;
217  virtual std::string getMonitorContext() const;
218  virtual void reportToMonitor(const SearchReport& report) const;
219 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
220 };
221 
222 } // namespace os
223 } // namespace yarp
224 
225 #endif // YARP_OS_SEARCHABLE_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
A base class for nested structures that can be searched.
Definition: Searchable.h:66
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
Searchable(const Searchable &rhs)=default
Copy constructor.
Searchable(Searchable &&rhs) noexcept=default
Move constructor.
Searchable & operator=(const Searchable &rhs)=default
Copy assignment operator.
virtual ~Searchable()
Destructor.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
Searchable & operator=(Searchable &&rhs) noexcept=default
Move assignment operator.
A single value (typically within a Bottle).
Definition: Value.h:45
std::string findGroup(const robotinterface::ParamList &list, const std::string &name)
Definition: Types.cpp:47
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:336
#define YARP_os_API
Definition: api.h:18