Keywords.h
Go to the documentation of this file.
00001 
00002 /*
00003  * Copyright (c) 2011, Thomas Ruehr <ruehr@cs.tum.edu>
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  *     * Redistributions of source code must retain the above copyright
00010  *       notice, this list of conditions and the following disclaimer.
00011  *     * Redistributions in binary form must reproduce the above copyright
00012  *       notice, this list of conditions and the following disclaimer in the
00013  *       documentation and/or other materials provided with the distribution.
00014  *     * Neither the name of Willow Garage, Inc. nor the names of its
00015  *       contributors may be used to endorse or promote products derived from
00016  *       this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028  * POSSIBILITY OF SUCH DAMAGE.
00029  */
00030 
00034 
00036 //void test_func(Keywords &kp)
00037 //{
00038 //    ROS_INFO("string %s",kp.lookup_s("blub").c_str());
00039 //    ROS_INFO("double %f",kp.lookup_d("blub"));
00040 //    ROS_INFO("vec %f %f %f",kp.lookup_v("blic").x(),kp.lookup_v("blic").y(),kp.lookup_v("blic").z());
00041 //}
00042 // ...
00043 // test_func(Keywords() ("bla",1) ("blub","blib") ("tic", 5) ("blub",7) ("blic",tf::Vector3(0,0,1)) );
00044 // or
00045 // test_func(Keywords("bla",1) ("blub","blib") ("tic", 5) ("blub",7) ("blic",tf::Vector3(0,0,1)) );
00046 
00047 #ifndef __KEYWORDS_H__
00048 #define __KEYWORDS_H__
00049 
00050 #include <tf/tf.h>
00051 #include <string>
00052 
00053 #include <map>
00054 
00055 typedef struct {
00056     std::string s;
00057     tf::Vector3 v;
00058     double d;
00059 
00060     operator std::string() {return s;}
00061     operator tf::Vector3() {return v;}
00062     operator double() {return d;}
00063 } KeyValPair;
00064 
00065 
00066 
00067 class Keywords
00068 {
00069 public:
00070 
00071     Keywords() {};
00072 
00073     Keywords(std::string name, double val);
00074 
00075     Keywords &operator()(std::string name, double val);
00076 
00077     Keywords(std::string name, std::string val);
00078 
00079     Keywords &operator()(std::string name, std::string val);
00080 
00081     Keywords(std::string name, tf::Vector3 val);
00082 
00083     Keywords &operator()(std::string name, tf::Vector3 val);
00084 
00085     Keywords &contains();
00086 
00087     //check if key is existing
00088     bool has_d(const std::string &key) const;
00089     bool has_s(const std::string &key) const;
00090     bool has_v(const std::string &key) const;
00091 
00092     //lookup, returns value when key is found else 0/0 vector/empty string
00093     double lookup_d(const std::string &key) const;
00094     std::string lookup_s(const std::string &key) const;
00095     tf::Vector3 lookup_v(const std::string &key) const;
00096 
00097     KeyValPair lookup(const std::string &key) const;
00098 
00099   // one map for each type, allow to have multiple entries with the same key but different value type
00100     std::map<std::string, double> parameters_d;
00101     std::map<std::string, std::string> parameters_s;
00102     std::map<std::string, tf::Vector3> parameters_v;
00103 
00104 };
00105 
00106 #endif


ias_drawer_executive
Author(s): Thomas Ruehr
autogenerated on Mon Oct 6 2014 08:59:22