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);
136  Config(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, QVariant value);
190 
194  Config mapMakeChild(const QString& key);
195 
200  Config mapGetChild(const QString& key) const;
201 
209  bool mapGetValue(const QString& key, QVariant* value_out) const;
210 
219  bool mapGetInt(const QString& key, int* value_out) const;
220 
229  bool mapGetFloat(const QString& key, float* value_out) const;
230 
239  bool mapGetBool(const QString& key, bool* value_out) const;
240 
249  bool mapGetString(const QString& key, QString* value_out) const;
250 
253  void setValue(const QVariant& value);
254 
257  QVariant getValue() const;
258 
261  int listLength() const;
262 
266  Config listChildAt(int i) const;
267 
272 
289  {
290  public:
292  void advance();
293 
297  bool isValid();
298 
300  void start();
301 
303  QString currentKey();
304 
307 
308  private:
311  MapIterator();
312 
314  QMap<QString, Config::NodePtr>::const_iterator iterator_;
316  friend class Config;
317  };
318 
326  MapIterator mapIterator() const;
327 
328 private:
329  Config(NodePtr node);
330  static Config invalidConfig();
331 
333  void makeValid();
334 
335  NodePtr node_;
336 
337  friend class MapIterator;
338 };
339 
340 } // end namespace rviz
341 
342 #endif // CONFIG_H
void setValue(const QVariant &value)
Ensures this is a valid Config object, sets the type to Value then sets the value.
Definition: config.cpp:317
Config::NodePtr node_
Definition: config.h:313
static Config invalidConfig()
Definition: config.cpp:173
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:324
Config()
Default constructor. Creates an empty config object.
Definition: config.cpp:118
MapIterator()
Private constructor enforces that MapIterators are only made by their friend the Config class...
Definition: config.cpp:375
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:329
bool isValid()
Return true if the iterator currently points to a valid entry, false if not.
Definition: config.cpp:397
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:212
bool mapGetString(const QString &key, QString *value_out) const
Convenience function for looking up a named string.
Definition: config.cpp:293
void makeValid()
If the node pointer is NULL, this sets it to a new empty node.
Definition: config.cpp:304
boost::shared_ptr< Node > NodePtr
Definition: config.h:127
void start()
Resets the iterator to the start of the map.
Definition: config.cpp:414
bool isValid() const
Returns true if the internal Node reference is valid, false if not. Same as (getType() != Invalid)...
Definition: config.cpp:312
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Definition: config.cpp:196
Configuration data storage class.
Definition: config.h:124
QString currentKey()
Return the name of the current map entry.
Definition: config.cpp:425
Type
Possible types a Config Node can have are Map, List, Value, and Empty. Invalid means the Config objec...
Definition: config.h:148
Config mapMakeChild(const QString &key)
Create a child node stored with the given key, and return the child.
Definition: config.cpp:201
Iterator class for looping over all entries in a Map type Config Node.
Definition: config.h:288
bool mapGetValue(const QString &key, QVariant *value_out) const
Convenience function for looking up a named value.
Definition: config.cpp:229
bool mapGetFloat(const QString &key, float *value_out) const
Convenience function for looking up a named float.
Definition: config.cpp:256
NodePtr node_
Definition: config.h:335
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:178
bool mapGetBool(const QString &key, bool *value_out) const
Convenience function for looking up a named boolean.
Definition: config.cpp:282
Config listAppendNew()
Ensure the referenced Node is of type List, append a new Empty Node to the end of the list...
Definition: config.cpp:346
Config listChildAt(int i) const
Return the i&#39;th child in the list, if the referenced Node has type List. Returns an Invalid Config if...
Definition: config.cpp:334
Config currentChild()
Return a Config reference to the current map entry.
Definition: config.cpp:435
MapIterator mapIterator() const
Return a new iterator for looping over key/value pairs.
Definition: config.cpp:356
QMap< QString, Config::NodePtr >::const_iterator iterator_
Definition: config.h:314
bool mapGetInt(const QString &key, int *value_out) const
Convenience function for looking up a named integer.
Definition: config.cpp:240
friend class Config
Definition: config.h:316
void copy(const Config &source)
Make this a deep copy of source.
Definition: config.cpp:135
void setType(Type new_type)
Set the type of this Config Node.
Definition: config.cpp:183
void advance()
Advance iterator to next entry.
Definition: config.cpp:379


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24