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::os {
23 class Value;
24 class Bottle;
25 } // namespace yarp::os
26 
27 namespace yarp::os {
28 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
31 class YARP_os_API SearchReport
32 {
33 public:
35  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) value;
36  bool isFound;
37  bool isGroup;
38  bool isComment;
39  bool isDefault;
40 
41  explicit SearchReport();
42 };
43 
44 class YARP_os_API SearchMonitor
45 {
46 public:
47  virtual ~SearchMonitor();
48  virtual void report(const SearchReport& report, const char* context) = 0;
49 };
50 
51 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
52 
53 
63 {
64 private:
65  SearchMonitor* monitor;
66  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) monitorContext;
67 
68 public:
72  explicit Searchable();
73 
77  Searchable(const Searchable& rhs) = default;
78 
82  Searchable(Searchable&& rhs) noexcept = default;
83 
87  virtual ~Searchable();
88 
92  Searchable& operator=(const Searchable& rhs) = default;
93 
97  Searchable& operator=(Searchable&& rhs) noexcept = default;
98 
105  virtual bool check(const std::string& key) const = 0;
106 
107 
115  virtual bool check(const std::string& key,
116  const std::string& comment) const;
117 
126  virtual Value& find(const std::string& key) const = 0;
127 
138  virtual Bottle& findGroup(const std::string& key) const = 0;
139 
151  Bottle& findGroup(const std::string& key, const std::string& comment) const;
152 
178  virtual bool check(const std::string& key,
179  Value*& result,
180  const std::string& comment = "") const;
181 
182 
192  virtual Value check(const std::string& key,
193  const Value& fallback,
194  const std::string& comment = "") const;
195 
200  virtual bool isNull() const;
201 
209  virtual std::string toString() const = 0;
210 
211 #ifndef DOXYGEN_SHOULD_SKIP_THIS
212  virtual void setMonitor(SearchMonitor* monitor, const char* context = "");
213  virtual SearchMonitor* getMonitor() const;
214  virtual std::string getMonitorContext() const;
215  virtual void reportToMonitor(const SearchReport& report) const;
216 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
217 };
218 
219 } // namespace yarp::os
220 
221 #endif // YARP_OS_SEARCHABLE_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
A base class for nested structures that can be searched.
Definition: Searchable.h:63
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:43
An interface to the operating system, including Port based communication.
std::string findGroup(const robotinterface::ParamList &list, const std::string &name)
Definition: Types.cpp:47
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:338
#define YARP_os_API
Definition: api.h:18