![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
00001 /* 00002 * The GURLS Package in C++ 00003 * 00004 * Copyright (C) 2011-1013, IIT@MIT Lab 00005 * All rights reserved. 00006 * 00007 * author: M. Santoro 00008 * email: msantoro@mit.edu 00009 * website: http://cbcl.mit.edu/IIT@MIT/IIT@MIT.html 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions 00013 * are met: 00014 * 00015 * * Redistributions of source code must retain the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer. 00018 * * Redistributions in binary form must reproduce the above 00019 * copyright notice, this list of conditions and the following 00020 * disclaimer in the documentation and/or other materials 00021 * provided with the distribution. 00022 * * Neither the name(s) of the copyright holders nor the names 00023 * of its contributors or of the Massacusetts Institute of 00024 * Technology or of the Italian Institute of Technology may be 00025 * used to endorse or promote products derived from this software 00026 * without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00029 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00030 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00031 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00032 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00033 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00034 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00035 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00036 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00037 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00038 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00039 * POSSIBILITY OF SUCH DAMAGE. 00040 */ 00041 00042 #ifndef _GURLS_OPTLIST_H_ 00043 #define _GURLS_OPTLIST_H_ 00044 00045 #include <iostream> 00046 #include <string> 00047 #include <map> 00048 #include <vector> 00049 #include <algorithm> 00050 #include <typeinfo> 00051 00052 #include "gurls++/exports.h" 00053 #include "gurls++/gmat2d.h" 00054 #include "gurls++/gvec.h" 00055 #include "gurls++/options.h" 00056 #include "gurls++/optarray.h" 00057 #include "gurls++/exceptions.h" 00058 00059 00060 namespace gurls { 00061 00062 00063 #ifdef _WIN32 00064 #pragma warning(push) 00065 #pragma warning(disable : 4251) 00066 #endif 00067 00073 class GURLS_EXPORT GurlsOptionsList: public GurlsOption 00074 { 00075 public: 00076 typedef std::map<std::string, GurlsOption* > ValueType; 00077 00084 GurlsOptionsList(std::string ExpName, bool usedefopt = false); 00085 00089 GurlsOptionsList(const GurlsOptionsList &other); 00090 00094 ~GurlsOptionsList(); 00095 00099 bool addOpt(std::string key, GurlsOption* value); 00100 00104 bool addOpt(std::string key, std::string value); 00105 00109 bool addOpt(std::string key, std::wstring value); 00110 00114 GurlsOption* getOpt(std::string key); 00115 00119 const GurlsOption* getOpt(std::string key) const; 00120 00124 template<class T> 00125 T* getOptAs(std::string key) 00126 { 00127 return T::dynacast(this->getOpt(key)); 00128 } 00129 00133 template<class T> 00134 const T* getOptAs(std::string key) const 00135 { 00136 return T::dynacast(this->getOpt(key)); 00137 } 00138 00142 template<class T> 00143 typename T::ValueType& getOptValue(std::string key) 00144 { 00145 return this->getOptAs<T>(key)->getValue(); 00146 } 00147 00151 template<class T> 00152 const typename T::ValueType& getOptValue(std::string key) const 00153 { 00154 return this->getOptAs<T>(key)->getValue(); 00155 } 00156 00160 std::string getOptAsString(std::string key) const; 00161 00165 std::string getName() const; 00166 00170 const ValueType& getValue() const; 00171 00175 void setName(std::string); 00176 00180 double getOptAsNumber(std::string key) const; 00181 00185 void printAll(); 00186 00190 bool hasOpt(std::string key) const; 00191 00198 void removeOpt(std::string key, bool deleteMembers = true); 00199 00203 virtual bool isA(OptTypes id) const; 00204 00208 static GurlsOptionsList* dynacast(GurlsOption* opt); 00209 00213 static const GurlsOptionsList* dynacast(const GurlsOption* opt); 00214 00218 int size() const; 00219 00223 GurlsOption* operator[] (int idx); 00224 00228 friend GURLS_EXPORT std::ostream& operator<<(std::ostream& os, const GurlsOptionsList& opt); 00229 00233 virtual std::ostream& operator<<(std::ostream& os) const; 00234 00238 std::string toString(); 00239 00243 void copyOpt(std::string key, const GurlsOptionsList &from); 00244 00248 void save(const std::string& fileName) const; 00249 00253 void load(const std::string& fileName); 00254 00255 protected: 00256 std::string name; 00257 ValueType* table; 00258 00259 }; 00260 00261 #ifdef _WIN32 00262 #pragma warning(pop) 00263 #endif 00264 00265 } 00266 00267 #endif // _GURLS_OPTLIST_H_