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 {
46 
125 class Config
126 {
127 private:
128  class Node;
130 
131 public:
133  Config();
135  Config( const Config& source );
137  Config( QVariant value );
138 
140  void copy( const Config& source );
141 
149  enum Type { Map, List, Value, Empty, Invalid };
150 
153  Type getType() const;
154 
165  void setType( Type new_type );
166 
169  bool isValid() const;
170 
183  void mapSetValue( const QString& key, QVariant value );
184 
188  Config mapMakeChild( const QString& key );
189 
194  Config mapGetChild( const QString& key ) const;
195 
203  bool mapGetValue( const QString& key, QVariant *value_out ) const;
204 
213  bool mapGetInt( const QString& key, int *value_out ) const;
214 
223  bool mapGetFloat( const QString& key, float *value_out ) const;
224 
233  bool mapGetBool( const QString& key, bool *value_out ) const;
234 
243  bool mapGetString( const QString& key, QString *value_out ) const;
244 
247  void setValue( const QVariant& value );
248 
251  QVariant getValue() const;
252 
255  int listLength() const;
256 
260  Config listChildAt( int i ) const;
261 
266 
283  {
284  public:
286  void advance();
287 
291  bool isValid();
292 
294  void start();
295 
297  QString currentKey();
298 
301 
302  private:
305  MapIterator();
306 
308  QMap<QString, Config::NodePtr>::const_iterator iterator_;
310  friend class Config;
311  };
312 
320  MapIterator mapIterator() const;
321 
322 private:
323  Config( NodePtr node );
324  static Config invalidConfig();
325 
327  void makeValid();
328 
329  NodePtr node_;
330 
331  friend class MapIterator;
332 };
333 
334 } // end namespace rviz
335 
336 #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:305
Config::NodePtr node_
Definition: config.h:307
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:167
static Config invalidConfig()
Definition: config.cpp:162
Config()
Default constructor. Creates an empty config object.
Definition: config.cpp:107
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:317
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:322
bool mapGetFloat(const QString &key, float *value_out) const
Convenience function for looking up a named float.
Definition: config.cpp:245
MapIterator()
Private constructor enforces that MapIterators are only made by their friend the Config class...
Definition: config.cpp:363
bool isValid()
Return true if the iterator currently points to a valid entry, false if not.
Definition: config.cpp:385
void makeValid()
If the node pointer is NULL, this sets it to a new empty node.
Definition: config.cpp:292
bool isValid() const
Returns true if the internal Node reference is valid, false if not. Same as (getType() != Invalid)...
Definition: config.cpp:300
boost::shared_ptr< Node > NodePtr
Definition: config.h:128
bool mapGetString(const QString &key, QString *value_out) const
Convenience function for looking up a named string.
Definition: config.cpp:281
void start()
Resets the iterator to the start of the map.
Definition: config.cpp:402
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Definition: config.cpp:185
Configuration data storage class.
Definition: config.h:125
QString currentKey()
Return the name of the current map entry.
Definition: config.cpp:413
Type
Possible types a Config Node can have are Map, List, Value, and Empty. Invalid means the Config objec...
Definition: config.h:149
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:312
Config mapMakeChild(const QString &key)
Create a child node stored with the given key, and return the child.
Definition: config.cpp:190
Iterator class for looping over all entries in a Map type Config Node.
Definition: config.h:282
bool mapGetBool(const QString &key, bool *value_out) const
Convenience function for looking up a named boolean.
Definition: config.cpp:270
NodePtr node_
Definition: config.h:329
bool mapGetInt(const QString &key, int *value_out) const
Convenience function for looking up a named integer.
Definition: config.cpp:229
MapIterator mapIterator() const
Return a new iterator for looping over key/value pairs.
Definition: config.cpp:344
Config listAppendNew()
Ensure the referenced Node is of type List, append a new Empty Node to the end of the list...
Definition: config.cpp:334
Config currentChild()
Return a Config reference to the current map entry.
Definition: config.cpp:423
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:201
QMap< QString, Config::NodePtr >::const_iterator iterator_
Definition: config.h:308
bool mapGetValue(const QString &key, QVariant *value_out) const
Convenience function for looking up a named value.
Definition: config.cpp:218
friend class Config
Definition: config.h:310
void copy(const Config &source)
Make this a deep copy of source.
Definition: config.cpp:125
void setType(Type new_type)
Set the type of this Config Node.
Definition: config.cpp:172
void advance()
Advance iterator to next entry.
Definition: config.cpp:367


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:50