![]() |
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_OPT_H_ 00043 #define _GURLS_OPT_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++/exceptions.h" 00056 00057 00062 namespace gurls 00063 { 00064 00065 00070 enum OptTypes {GenericOption, StringOption, NumberOption, 00071 StringListOption, NumberListOption, FunctionOption, 00072 MatrixOption, VectorOption, 00073 OptListOption, TaskSequenceOption, TaskIDOption, OptArrayOption, ProcessOption}; 00074 00075 00076 00090 class GURLS_EXPORT GurlsOption 00091 { 00092 protected: 00093 OptTypes type; 00094 00095 public: 00096 00100 GurlsOption(OptTypes t); 00101 00105 OptTypes getType() const; 00106 00110 virtual ~GurlsOption(); 00111 00115 virtual bool isA(OptTypes id) const; 00116 00120 const virtual std::type_info& getDataID(); 00121 00125 friend GURLS_EXPORT std::ostream& operator<<(std::ostream& os, const GurlsOption& opt); 00126 00130 virtual std::ostream& operator<<(std::ostream& os) const = 0; 00131 }; 00132 00133 #ifdef _WIN32 00134 #pragma warning(push) 00135 #pragma warning(disable : 4251) 00136 #endif 00137 00142 class GURLS_EXPORT OptString: public GurlsOption 00143 { 00144 00145 protected: 00146 std::string value; 00147 00148 public: 00149 00150 typedef std::string ValueType; 00151 00155 OptString(); 00156 00160 // OptString(const char* str); 00161 00165 OptString(const std::string& str); 00166 00170 OptString(const std::wstring& str); 00171 00175 OptString& operator=(const OptString& other); 00176 00180 ~OptString(); 00181 00185 OptString& operator=(const std::string& other); 00186 00190 void setValue(const std::string& newvalue); 00191 00195 std::string& getValue(); 00196 00200 const std::string& getValue() const; 00201 00205 virtual bool isA(OptTypes id) const; 00206 00210 static OptString* dynacast(GurlsOption* opt); 00211 00215 static const OptString* dynacast(const GurlsOption* opt); 00216 00220 virtual std::ostream& operator<<(std::ostream& os) const; 00221 00222 }; 00223 00224 #ifdef _WIN32 00225 #pragma warning(pop) 00226 #endif 00227 00232 class GURLS_EXPORT OptStringList: public GurlsOption 00233 { 00234 protected: 00235 std::vector<std::string>* value; 00236 00237 public: 00238 00239 typedef std::vector<std::string> ValueType; 00240 00244 OptStringList(); 00245 00249 OptStringList(const std::vector<std::string>& vec); 00250 00254 OptStringList(std::string& str); 00255 00259 OptStringList& operator=(const OptStringList& other); 00260 00264 ~OptStringList(); 00265 00269 void setValue(const std::vector<std::string> newvalue); 00270 00274 void add(const std::string str); 00275 00279 const std::vector<std::string>& getValue() const; 00280 00284 virtual bool isA(OptTypes id) const; 00285 00289 static OptStringList* dynacast(GurlsOption* opt); 00290 00294 static const OptStringList* dynacast(const GurlsOption* opt); 00295 00299 virtual std::ostream& operator<<(std::ostream& os) const; 00300 00304 void clear(); 00305 00309 OptStringList& operator<<(std::string& str); 00310 00314 OptStringList& operator<<(const char* str); 00315 00316 }; 00317 00318 00324 class GURLS_EXPORT OptNumber: public GurlsOption 00325 { 00326 protected: 00327 double value; 00328 00329 public: 00330 00331 typedef double ValueType; 00332 00336 OptNumber(); 00337 00341 OptNumber(double v); 00342 00346 OptNumber& operator=(const OptNumber& other); 00347 00348 // ~OptNumber(){} 00349 00353 OptNumber& operator=(double other); 00354 00358 void setValue(double newvalue); 00359 00363 const double& getValue() const; 00364 00368 double& getValue(); 00369 00373 virtual bool isA(OptTypes id) const; 00374 00378 static OptNumber* dynacast(GurlsOption* opt); 00379 00383 static const OptNumber* dynacast(const GurlsOption* opt); 00384 00388 virtual std::ostream& operator<<(std::ostream& os) const; 00389 00390 }; 00391 00392 //#ifdef GURLS_DEPRECATED 00393 00399 class GURLS_EXPORT OptNumberList: public GurlsOption 00400 { 00401 private: 00402 std::vector<double>* value; 00403 00404 public: 00405 00406 typedef std::vector<double> ValueType; 00407 00411 OptNumberList(); 00412 00416 OptNumberList(const std::vector<double>& vec); 00417 00421 OptNumberList(double v); 00422 00426 OptNumberList(double *v, int n); 00427 00431 OptNumberList& operator=(const OptNumberList& other); 00432 00433 ~OptNumberList(); 00434 00438 void setValue(const std::vector<double> newvalue); 00439 00443 void add(const double d); 00444 00448 std::vector<double>& getValue(); 00449 00453 const std::vector<double>& getValue() const; 00454 00458 virtual bool isA(OptTypes id) const; 00459 00463 static OptNumberList* dynacast(GurlsOption* opt); 00464 00468 static const OptNumberList* dynacast(const GurlsOption* opt); 00469 00473 virtual std::ostream& operator<<(std::ostream& os) const; 00474 00478 void clear(); 00479 00483 OptNumberList& operator<<(double& d); 00484 } 00485 00486 //#ifdef __GNUC__ 00487 // __attribute__ ((deprecated)) 00488 //#endif 00489 ; 00490 00491 //#ifdef _WIN32 00492 //#pragma deprecated( OptNumberList ) 00493 //#endif 00494 00495 //#endif 00496 00497 00501 static const std::string TASKDESC_SEPARATOR(":"); 00502 00508 class GURLS_EXPORT OptTaskSequence: public OptStringList 00509 { 00510 protected: 00514 bool isValid(const std::string & str, std::string& type, std::string& name); 00515 00516 public: 00517 00518 typedef OptStringList::ValueType ValueType; 00519 00523 OptTaskSequence(); 00524 00528 OptTaskSequence(const char* str); 00529 00533 OptTaskSequence(std::string &str); 00534 00538 OptTaskSequence(const std::vector<std::string>& data); 00539 00543 OptTaskSequence& operator=(const OptTaskSequence& other); 00544 00548 void addTask(const std::string newtask); 00549 00553 virtual bool isA(OptTypes id) const; 00554 00558 static OptTaskSequence* dynacast(GurlsOption* opt); 00559 00563 static const OptTaskSequence* dynacast(const GurlsOption* opt); 00564 00568 void getTaskAt(int index, std::string& taskdesc, std::string& taskname); 00569 00573 unsigned long size(); 00574 00575 }; 00576 00582 class GURLS_EXPORT OptProcess: public GurlsOption 00583 { 00584 public: 00588 enum Action {ignore, compute, computeNsave, load, remove}; 00589 00590 typedef std::vector<Action> ValueType; 00591 00592 protected: 00593 00594 ValueType* value; 00595 00599 static std::vector<std::string>& actionNames(); 00600 00601 public: 00602 00606 OptProcess(); 00607 00611 OptProcess(const OptProcess& other); 00612 00616 ~OptProcess(); 00617 00621 void addAction(const Action action); 00622 00626 OptProcess& operator<<(const Action action); 00627 00631 const ValueType& getValue() const; 00632 00636 Action operator[](unsigned long index); 00637 00641 void clear(); 00642 00646 unsigned long size(); 00647 00651 virtual bool isA(OptTypes id) const; 00652 00656 static OptProcess* dynacast(GurlsOption* opt); 00657 00661 static const OptProcess* dynacast(const GurlsOption* opt); 00662 00666 virtual std::ostream& operator<<(std::ostream& os) const; 00667 00668 }; 00669 00670 } 00671 00672 #endif // _GURLS_OPT_H_