SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // Classes representing a single program option (with different types) 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 #ifndef Option_h 00022 #define Option_h 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #include <string> 00035 #include <vector> 00036 #include <exception> 00037 #include <utils/common/UtilExceptions.h> 00038 00039 00040 // =========================================================================== 00041 // class definitions 00042 // =========================================================================== 00047 typedef std::vector<int> IntVector; 00048 00049 00050 /* ------------------------------------------------------------------------- 00051 * Option 00052 * ----------------------------------------------------------------------- */ 00078 class Option { 00079 public: 00081 virtual ~Option(); 00082 00083 00087 bool isSet() const; 00088 00089 00098 virtual SUMOReal getFloat() const; 00099 00100 00109 virtual int getInt() const; 00110 00111 00120 virtual std::string getString() const; 00121 00122 00131 virtual bool getBool() const; 00132 00133 00142 virtual const IntVector& getIntVector() const; 00143 00144 00164 virtual bool set(const std::string& v) = 0; 00165 00166 00173 virtual std::string getValueString() const = 0; 00174 00175 00182 virtual bool isBool() const; 00183 00184 00189 virtual bool isDefault() const; 00190 00191 00198 virtual bool isFileName() const; 00199 00200 00208 bool isWriteable() const; 00209 00210 00216 void resetWritable(); 00217 00218 00225 const std::string& getDescription() const; 00226 00227 00234 void setDescription(const std::string& desc); 00235 00236 00243 virtual const std::string& getTypeName() const; 00244 00245 00246 protected: 00253 bool markSet(); 00254 00255 00256 protected: 00264 Option(bool set = false); 00265 00266 00268 Option(const Option& s); 00269 00270 00272 virtual Option& operator=(const Option& s); 00273 00274 00275 protected: 00277 std::string myTypeName; 00278 00279 00280 private: 00282 bool myAmSet; 00283 00285 bool myHaveTheDefaultValue; 00286 00288 bool myAmWritable; 00289 00291 std::string myDescription; 00292 00293 }; 00294 00295 00296 /* ------------------------------------------------------------------------- 00297 * Option_Integer 00298 * ----------------------------------------------------------------------- */ 00303 class Option_Integer : public Option { 00304 public: 00309 Option_Integer(); 00310 00311 00318 Option_Integer(int value); 00319 00320 00322 Option_Integer(const Option_Integer& s); 00323 00324 00326 ~Option_Integer(); 00327 00328 00330 Option_Integer& operator=(const Option_Integer& s); 00331 00332 00337 int getInt() const; 00338 00339 00355 bool set(const std::string& v); 00356 00357 00365 std::string getValueString() const; 00366 00367 00368 private: 00370 int myValue; 00371 00372 }; 00373 00374 00375 /* ------------------------------------------------------------------------- 00376 * Option_String 00377 * ----------------------------------------------------------------------- */ 00378 class Option_String : public Option { 00379 public: 00384 Option_String(); 00385 00386 00393 Option_String(const std::string& value, std::string typeName = "STR"); 00394 00395 00397 Option_String(const Option_String& s); 00398 00399 00401 virtual ~Option_String(); 00402 00403 00405 Option_String& operator=(const Option_String& s); 00406 00407 00412 std::string getString() const; 00413 00414 00426 bool set(const std::string& v); 00427 00428 00436 std::string getValueString() const; 00437 00438 00439 protected: 00441 std::string myValue; 00442 00443 }; 00444 00445 00446 /* ------------------------------------------------------------------------- 00447 * Option_Float 00448 * ----------------------------------------------------------------------- */ 00449 class Option_Float : public Option { 00450 public: 00455 Option_Float(); 00456 00457 00464 Option_Float(SUMOReal value); 00465 00466 00468 Option_Float(const Option_Float& s); 00469 00470 00472 ~Option_Float(); 00473 00474 00476 Option_Float& operator=(const Option_Float& s); 00477 00478 00483 SUMOReal getFloat() const; 00484 00485 00501 bool set(const std::string& v); 00502 00503 00511 std::string getValueString() const; 00512 00513 00514 private: 00516 SUMOReal myValue; 00517 00518 }; 00519 00520 00521 /* ------------------------------------------------------------------------- 00522 * Option_Bool 00523 * ----------------------------------------------------------------------- */ 00524 class Option_Bool : public Option { 00525 public: 00530 Option_Bool(); 00531 00532 00539 Option_Bool(bool value); 00540 00541 00543 Option_Bool(const Option_Bool& s); 00544 00545 00547 ~Option_Bool(); 00548 00549 00551 Option_Bool& operator=(const Option_Bool& s); 00552 00553 00558 bool getBool() const; 00559 00561 bool set(const std::string& v); 00562 00563 00571 std::string getValueString() const; 00572 00573 00581 bool isBool() const; 00582 00583 00584 private: 00586 bool myValue; 00587 00588 }; 00589 00590 00591 /* ------------------------------------------------------------------------- 00592 * Option_FileName 00593 * ----------------------------------------------------------------------- */ 00594 class Option_FileName : public Option_String { 00595 public: 00598 Option_FileName(); 00599 00600 00605 Option_FileName(const std::string& value); 00606 00607 00609 Option_FileName(const Option_String& s); 00610 00611 00613 virtual ~Option_FileName(); 00614 00616 Option_FileName& operator=(const Option_FileName& s); 00617 00618 00625 bool isFileName() const; 00626 00627 }; 00628 00629 00630 /* ------------------------------------------------------------------------- 00631 * Option_IntVector 00632 * ----------------------------------------------------------------------- */ 00633 class Option_IntVector : public Option { 00634 public: 00637 Option_IntVector(); 00638 00639 00644 Option_IntVector(const IntVector& value); 00645 00646 00648 Option_IntVector(const Option_IntVector& s); 00649 00650 00652 virtual ~Option_IntVector(); 00653 00654 00656 Option_IntVector& operator=(const Option_IntVector& s); 00657 00658 00663 const IntVector& getIntVector() const; 00664 00665 00681 bool set(const std::string& v); 00682 00683 00691 std::string getValueString() const; 00692 00693 00694 private: 00696 IntVector myValue; 00697 }; 00698 00699 00700 #endif 00701 00702 /****************************************************************************/ 00703