config.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 #ifndef CONFIG_H
30 #define CONFIG_H
31 
32 #include <stdio.h>
33 
34 #include <string>
35 
36 #ifndef Q_MOC_RUN
37 #include <boost/shared_ptr.hpp>
38 #endif
39 
40 #include <QMap>
41 #include <QString>
42 #include <QVariant>
43 
44 namespace rviz
45 {
124 class Config
125 {
126 private:
127  class Node;
129 
130 public:
132  Config();
134  Config(const Config& source) = default;
136  Config(const QVariant& value);
137 
139  void copy(const Config& source);
140 
148  enum Type
149  {
155  };
156 
159  Type getType() const;
160 
171  void setType(Type new_type);
172 
175  bool isValid() const;
176 
189  void mapSetValue(const QString& key, const QVariant& value);
190 
194  Config mapMakeChild(const QString& key);
195 
197  void mapRemoveChild(const QString& key);
198 
203  Config mapGetChild(const QString& key) const;
204 
212  bool mapGetValue(const QString& key, QVariant* value_out) const;
213 
222  bool mapGetInt(const QString& key, int* value_out) const;
223 
232  bool mapGetFloat(const QString& key, float* value_out) const;
233 
242  bool mapGetBool(const QString& key, bool* value_out) const;
243 
252  bool mapGetString(const QString& key, QString* value_out) const;
253 
256  void setValue(const QVariant& value);
257 
260  QVariant getValue() const;
261 
264  int listLength() const;
265 
269  Config listChildAt(int i) const;
270 
275 
292  {
293  public:
295  void advance();
296 
300  bool isValid();
301 
303  void start();
304 
306  QString currentKey();
307 
310 
311  private:
314  MapIterator();
315 
317  QMap<QString, Config::NodePtr>::const_iterator iterator_;
319  friend class Config;
320  };
321 
329  MapIterator mapIterator() const;
330 
331 private:
332  Config(NodePtr node);
333  static Config invalidConfig();
334 
336  void makeValid();
337 
339 
340  friend class MapIterator;
341 };
342 
343 } // end namespace rviz
344 
345 #endif // CONFIG_H
rviz::Config::MapIterator::iterator_valid_
bool iterator_valid_
Definition: config.h:318
rviz::Config::isValid
bool isValid() const
Returns true if the internal Node reference is valid, false if not. Same as (getType() !...
Definition: config.cpp:307
boost::shared_ptr< Node >
rviz::Config::MapIterator::isValid
bool isValid()
Return true if the iterator currently points to a valid entry, false if not.
Definition: config.cpp:392
rviz::Config::MapIterator::node_
Config::NodePtr node_
Definition: config.h:316
rviz::Config::Empty
@ Empty
Definition: config.h:153
rviz::Config::Config
Config()
Default constructor. Creates an empty config object.
Definition: config.cpp:122
rviz::Config::MapIterator::start
void start()
Resets the iterator to the start of the map.
Definition: config.cpp:409
rviz::Config::listLength
int listLength() const
Returns the length of the List in this Node, or 0 if this Node does not have type List.
Definition: config.cpp:324
rviz::Config::MapIterator::MapIterator
MapIterator()
Private constructor enforces that MapIterators are only made by their friend the Config class.
Definition: config.cpp:370
rviz::Config::MapIterator::currentKey
QString currentKey()
Return the name of the current map entry.
Definition: config.cpp:420
rviz::Config::Node
Definition: config.cpp:42
rviz::Config::Type
Type
Possible types a Config Node can have are Map, List, Value, and Empty. Invalid means the Config objec...
Definition: config.h:148
rviz::Config::mapGetChild
Config mapGetChild(const QString &key) const
If the referenced Node is a Map and it has a child with the given key, return a reference to the chil...
Definition: config.cpp:207
rviz::Config::List
@ List
Definition: config.h:151
rviz::Config::makeValid
void makeValid()
If the node pointer is NULL, this sets it to a new empty node.
Definition: config.cpp:299
rviz
Definition: add_display_dialog.cpp:54
rviz::Config::mapMakeChild
Config mapMakeChild(const QString &key)
Create a child node stored with the given key, and return the child.
Definition: config.cpp:188
rviz::Config::mapGetValue
bool mapGetValue(const QString &key, QVariant *value_out) const
Convenience function for looking up a named value.
Definition: config.cpp:224
rviz::Config::listAppendNew
Config listAppendNew()
Ensure the referenced Node is of type List, append a new Empty Node to the end of the list,...
Definition: config.cpp:341
rviz::Config::Value
@ Value
Definition: config.h:152
rviz::Config::mapGetBool
bool mapGetBool(const QString &key, bool *value_out) const
Convenience function for looking up a named boolean.
Definition: config.cpp:277
rviz::Config::copy
void copy(const Config &source)
Make this a deep copy of source.
Definition: config.cpp:135
rviz::Config::node_
NodePtr node_
Definition: config.h:338
rviz::Config::getType
Type getType() const
Return the Type of the referenced Node, or Invalid if this Config does not refer to a Node at all.
Definition: config.cpp:172
rviz::Config::listChildAt
Config listChildAt(int i) const
Return the i'th child in the list, if the referenced Node has type List. Returns an Invalid Config if...
Definition: config.cpp:329
rviz::Config::MapIterator::iterator_
QMap< QString, Config::NodePtr >::const_iterator iterator_
Definition: config.h:317
rviz::Config::MapIterator::currentChild
Config currentChild()
Return a Config reference to the current map entry.
Definition: config.cpp:430
rviz::Config::setType
void setType(Type new_type)
Set the type of this Config Node.
Definition: config.cpp:177
rviz::Config::Invalid
@ Invalid
Definition: config.h:154
rviz::Config::mapGetString
bool mapGetString(const QString &key, QString *value_out) const
Convenience function for looking up a named string.
Definition: config.cpp:288
rviz::Config::NodePtr
boost::shared_ptr< Node > NodePtr
Definition: config.h:127
rviz::Config::Map
@ Map
Definition: config.h:150
rviz::Config::mapGetInt
bool mapGetInt(const QString &key, int *value_out) const
Convenience function for looking up a named integer.
Definition: config.cpp:235
rviz::Config::mapRemoveChild
void mapRemoveChild(const QString &key)
Remove child node with given key from the Map.
Definition: config.cpp:199
rviz::Config::MapIterator
Iterator class for looping over all entries in a Map type Config Node.
Definition: config.h:291
rviz::Config::mapGetFloat
bool mapGetFloat(const QString &key, float *value_out) const
Convenience function for looking up a named float.
Definition: config.cpp:251
rviz::Config::mapIterator
MapIterator mapIterator() const
Return a new iterator for looping over key/value pairs.
Definition: config.cpp:351
rviz::Config::MapIterator::advance
void advance()
Advance iterator to next entry.
Definition: config.cpp:374
rviz::Config::setValue
void setValue(const QVariant &value)
Ensures this is a valid Config object, sets the type to Value then sets the value.
Definition: config.cpp:312
rviz::Config
Configuration data storage class.
Definition: config.h:124
rviz::Config::mapSetValue
void mapSetValue(const QString &key, const QVariant &value)
Set a named child to the given value.
Definition: config.cpp:183
rviz::Config::invalidConfig
static Config invalidConfig()
Definition: config.cpp:167
rviz::Config::getValue
QVariant getValue() const
If this config object is valid and is a Value type, this returns its value. Otherwise it returns an i...
Definition: config.cpp:319


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02