YARP
Yet Another Robot Platform
Property.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_PROPERTY_H
11 #define YARP_OS_PROPERTY_H
12 
13 #include <yarp/os/Bottle.h>
14 #include <yarp/os/Portable.h>
15 #include <yarp/os/Searchable.h>
16 
17 #include <string>
18 
19 namespace yarp {
20 namespace os {
21 
35  public Searchable,
36  public Portable
37 {
38 public:
39  using Searchable::check;
41 
50  Property(int hash_size = 0);
51 
55  Property(const char* str);
56 
57 
61  Property(const Property& rhs);
62 
67  Property(std::initializer_list<std::pair<std::string, yarp::os::Value>> values);
71  virtual ~Property();
72 
76  const Property& operator=(const Property& prop);
77 
78  // documented in Searchable
79  bool check(const std::string& key) const override;
80 
92  void put(const std::string& key, const std::string& value);
93 
105  void put(const std::string& key, const Value& value);
106 
118  void put(const std::string& key, Value* value);
119 
131  void put(const std::string& key, int value);
132 
144  void put(const std::string& key, double value);
145 
156  Property& addGroup(const std::string& key);
157 
166  void unput(const std::string& key);
167 
168  // documented in Searchable
169  Value& find(const std::string& key) const override;
170 
171  // documented in Searchable
172  Bottle& findGroup(const std::string& key) const override;
173 
180  void clear();
181 
203  void fromString(const std::string& txt, bool wipe = true);
204 
229  void fromCommand(int argc, char* argv[], bool skipFirst = true, bool wipe = true);
230 
255  void fromCommand(int argc, const char* argv[], bool skipFirst = true, bool wipe = true);
256 
278  void fromArguments(const char* arguments, bool wipe = true);
279 
356  bool fromConfigFile(const std::string& fname, bool wipe = true);
357 
371  bool fromConfigFile(const std::string& fname,
372  Searchable& env,
373  bool wipe = true);
374 
385  bool fromConfigDir(const std::string& dirname,
386  const std::string& section = std::string(),
387  bool wipe = true);
388 
396  void fromConfig(const char* txt, bool wipe = true);
397 
410  void fromConfig(const char* txt,
411  Searchable& env,
412  bool wipe = true);
413 
423  void fromQuery(const char* url,
424  bool wipe = true);
425 
426 
427  // documented in Searchable
428  std::string toString() const override;
429 
430  // documented in Portable
431  bool read(ConnectionReader& reader) override;
432 
433  // documented in Portable
434  bool write(ConnectionWriter& writer) const override;
435 
436 private:
437  int hash_size;
438 
439  void summon();
440  bool check() const;
441 
442 #ifndef DOXYGEN_SHOULD_SKIP_THIS
443 private:
444  class Private;
445  Private* mPriv;
446 #endif // DOXYGEN_SHOULD_SKIP_THIS
447 };
448 
449 } // namespace os
450 } // namespace yarp
451 
452 #endif // YARP_OS_PROPERTY_H
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:553
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:516
A class for storing options and configuration information.
Definition: Property.h:34
A base class for nested structures that can be searched.
Definition: Searchable.h:68
This is a base class for objects that can be both read from and be written to the YARP network...
Definition: Portable.h:28
#define YARP_OS_API
Definition: api.h:19
The main, catch-all namespace for YARP.
Definition: numeric.h:47
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
An interface for writing to a network connection.
A simple collection of objects that can be described and transmitted in a portable way...
Definition: Bottle.h:72
An interface for reading from a network connection.
A single value (typically within a Bottle).
Definition: Value.h:46
std::string toString(const T &value)
convert an arbitrary type to string.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.