|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Classes representing a single program option (with different types) 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef Option_h 00020 #define Option_h 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include <string> 00033 #include <vector> 00034 #include <exception> 00035 #include <utils/common/UtilExceptions.h> 00036 00037 00038 // =========================================================================== 00039 // class definitions 00040 // =========================================================================== 00045 typedef std::vector<int> IntVector; 00046 00047 00048 /* ------------------------------------------------------------------------- 00049 * Option 00050 * ----------------------------------------------------------------------- */ 00076 class Option { 00077 public: 00079 virtual ~Option(); 00080 00081 00085 bool isSet() const; 00086 00087 00096 virtual SUMOReal getFloat() const; 00097 00098 00107 virtual int getInt() const; 00108 00109 00118 virtual std::string getString() const; 00119 00120 00129 virtual bool getBool() const; 00130 00131 00140 virtual const IntVector& getIntVector() const; 00141 00142 00162 virtual bool set(const std::string& v) = 0; 00163 00164 00171 virtual std::string getValueString() const = 0; 00172 00173 00180 virtual bool isBool() const; 00181 00182 00187 virtual bool isDefault() const; 00188 00189 00196 virtual bool isFileName() const; 00197 00198 00206 bool isWriteable() const; 00207 00208 00214 void resetWritable(); 00215 00216 00223 const std::string& getDescription() const; 00224 00225 00232 void setDescription(const std::string& desc); 00233 00234 00241 virtual const std::string& getTypeName() const; 00242 00243 00244 protected: 00251 bool markSet(); 00252 00253 00254 protected: 00262 Option(bool set=false); 00263 00264 00266 Option(const Option& s); 00267 00268 00270 virtual Option& operator=(const Option& s); 00271 00272 00273 protected: 00275 std::string myTypeName; 00276 00277 00278 private: 00280 bool myAmSet; 00281 00283 bool myHaveTheDefaultValue; 00284 00286 bool myAmWritable; 00287 00289 std::string myDescription; 00290 00291 }; 00292 00293 00294 /* ------------------------------------------------------------------------- 00295 * Option_Integer 00296 * ----------------------------------------------------------------------- */ 00301 class Option_Integer : public Option { 00302 public: 00307 Option_Integer(); 00308 00309 00316 Option_Integer(int value); 00317 00318 00320 Option_Integer(const Option_Integer& s); 00321 00322 00324 ~Option_Integer(); 00325 00326 00328 Option_Integer& operator=(const Option_Integer& s); 00329 00330 00335 int getInt() const; 00336 00337 00353 bool set(const std::string& v); 00354 00355 00363 std::string getValueString() const; 00364 00365 00366 private: 00368 int myValue; 00369 00370 }; 00371 00372 00373 /* ------------------------------------------------------------------------- 00374 * Option_String 00375 * ----------------------------------------------------------------------- */ 00376 class Option_String : public Option { 00377 public: 00382 Option_String(); 00383 00384 00391 Option_String(const std::string& value, std::string typeName="STR"); 00392 00393 00395 Option_String(const Option_String& s); 00396 00397 00399 virtual ~Option_String(); 00400 00401 00403 Option_String& operator=(const Option_String& s); 00404 00405 00410 std::string getString() const; 00411 00412 00424 bool set(const std::string& v); 00425 00426 00434 std::string getValueString() const; 00435 00436 00437 protected: 00439 std::string myValue; 00440 00441 }; 00442 00443 00444 /* ------------------------------------------------------------------------- 00445 * Option_Float 00446 * ----------------------------------------------------------------------- */ 00447 class Option_Float : public Option { 00448 public: 00453 Option_Float(); 00454 00455 00462 Option_Float(SUMOReal value); 00463 00464 00466 Option_Float(const Option_Float& s); 00467 00468 00470 ~Option_Float(); 00471 00472 00474 Option_Float& operator=(const Option_Float& s); 00475 00476 00481 SUMOReal getFloat() const; 00482 00483 00499 bool set(const std::string& v); 00500 00501 00509 std::string getValueString() const; 00510 00511 00512 private: 00514 SUMOReal myValue; 00515 00516 }; 00517 00518 00519 /* ------------------------------------------------------------------------- 00520 * Option_Bool 00521 * ----------------------------------------------------------------------- */ 00522 class Option_Bool : public Option { 00523 public: 00528 Option_Bool(); 00529 00530 00537 Option_Bool(bool value); 00538 00539 00541 Option_Bool(const Option_Bool& s); 00542 00543 00545 ~Option_Bool(); 00546 00547 00549 Option_Bool& operator=(const Option_Bool& s); 00550 00551 00556 bool getBool() const; 00557 00559 bool set(const std::string& v); 00560 00561 00569 std::string getValueString() const; 00570 00571 00579 bool isBool() const; 00580 00581 00582 private: 00584 bool myValue; 00585 00586 }; 00587 00588 00589 /* ------------------------------------------------------------------------- 00590 * Option_FileName 00591 * ----------------------------------------------------------------------- */ 00592 class Option_FileName : public Option_String { 00593 public: 00596 Option_FileName(); 00597 00598 00603 Option_FileName(const std::string& value); 00604 00605 00607 Option_FileName(const Option_String& s); 00608 00609 00611 virtual ~Option_FileName(); 00612 00614 Option_FileName& operator=(const Option_FileName& s); 00615 00616 00623 bool isFileName() const; 00624 00625 }; 00626 00627 00628 /* ------------------------------------------------------------------------- 00629 * Option_IntVector 00630 * ----------------------------------------------------------------------- */ 00631 class Option_IntVector : public Option { 00632 public: 00635 Option_IntVector(); 00636 00637 00642 Option_IntVector(const IntVector& value); 00643 00644 00646 Option_IntVector(const Option_IntVector& s); 00647 00648 00650 virtual ~Option_IntVector(); 00651 00652 00654 Option_IntVector& operator=(const Option_IntVector& s); 00655 00656 00661 const IntVector& getIntVector() const; 00662 00663 00679 bool set(const std::string& v); 00680 00681 00689 std::string getValueString() const; 00690 00691 00692 private: 00694 IntVector myValue; 00695 }; 00696 00697 00698 #endif 00699 00700 /****************************************************************************/ 00701