Option.h

Go to the documentation of this file.
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 2001-2010 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() throw();
00080 
00081 
00085     bool isSet() const throw();
00086 
00087 
00096     virtual SUMOReal getFloat() const throw(InvalidArgument);
00097 
00098 
00107     virtual int getInt() const throw(InvalidArgument);
00108 
00109 
00118     virtual std::string getString() const throw(InvalidArgument);
00119 
00120 
00129     virtual bool getBool() const throw(InvalidArgument);
00130 
00131 
00140     virtual const IntVector &getIntVector() const throw(InvalidArgument);
00141 
00142 
00162     virtual bool set(const std::string &v) throw(InvalidArgument);
00163 
00164 
00169     virtual bool set(bool v) throw(InvalidArgument);
00170 
00171 
00178     virtual std::string getValueString() const throw(InvalidArgument);
00179 
00180 
00187     virtual bool isBool() const throw();
00188 
00189 
00194     virtual bool isDefault() const throw();
00195 
00196 
00203     virtual bool isFileName() const throw();
00204 
00205 
00213     bool isWriteable() const throw();
00214 
00215 
00217     friend class OptionsCont;
00218 
00219 
00226     const std::string &getDescription() const throw();
00227 
00228 
00235     virtual const std::string &getTypeName() const throw();
00236 
00237 
00238 protected:
00245     bool markSet() throw();
00246 
00247 
00248 protected:
00256     Option(bool set=false) throw();
00257 
00258 
00260     Option(const Option &s) throw();
00261 
00262 
00264     virtual Option &operator=(const Option &s) throw();
00265 
00266 
00267 protected:
00269     std::string myTypeName;
00270 
00271 
00272 private:
00274     bool myAmSet;
00275 
00277     bool myHaveTheDefaultValue;
00278 
00280     bool myAmWritable;
00281 
00283     std::string myDescription;
00284 
00285 };
00286 
00287 
00288 /* -------------------------------------------------------------------------
00289  * Option_Integer
00290  * ----------------------------------------------------------------------- */
00295 class Option_Integer : public Option {
00296 public:
00301     Option_Integer() throw();
00302 
00303 
00310     Option_Integer(int value) throw();
00311 
00312 
00314     Option_Integer(const Option_Integer &s) throw();
00315 
00316 
00318     ~Option_Integer() throw();
00319 
00320 
00322     Option_Integer &operator=(const Option_Integer &s) throw();
00323 
00324 
00329     int getInt() const throw(InvalidArgument);
00330 
00331 
00347     bool set(const std::string &v) throw(InvalidArgument);
00348 
00349 
00357     std::string getValueString() const throw(InvalidArgument);
00358 
00359 
00360 private:
00362     int      myValue;
00363 
00364 };
00365 
00366 
00367 /* -------------------------------------------------------------------------
00368  * Option_String
00369  * ----------------------------------------------------------------------- */
00370 class Option_String : public Option {
00371 public:
00376     Option_String() throw();
00377 
00378 
00385     Option_String(const std::string &value, std::string typeName="STR") throw();
00386 
00387 
00389     Option_String(const Option_String &s) throw();
00390 
00391 
00393     virtual ~Option_String() throw();
00394 
00395 
00397     Option_String &operator=(const Option_String &s) throw();
00398 
00399 
00404     std::string getString() const throw(InvalidArgument);
00405 
00406 
00418     bool set(const std::string &v) throw(InvalidArgument);
00419 
00420 
00428     std::string getValueString() const throw(InvalidArgument);
00429 
00430 
00431 protected:
00433     std::string      myValue;
00434 
00435 };
00436 
00437 
00438 /* -------------------------------------------------------------------------
00439  * Option_Float
00440  * ----------------------------------------------------------------------- */
00441 class Option_Float : public Option {
00442 public:
00447     Option_Float() throw();
00448 
00449 
00456     Option_Float(SUMOReal value) throw();
00457 
00458 
00460     Option_Float(const Option_Float &s) throw();
00461 
00462 
00464     ~Option_Float() throw();
00465 
00466 
00468     Option_Float &operator=(const Option_Float &s) throw();
00469 
00470 
00475     SUMOReal getFloat() const throw(InvalidArgument);
00476 
00477 
00493     bool set(const std::string &v) throw(InvalidArgument);
00494 
00495 
00503     std::string getValueString() const throw(InvalidArgument);
00504 
00505 
00506 private:
00508     SUMOReal       myValue;
00509 
00510 };
00511 
00512 
00513 /* -------------------------------------------------------------------------
00514  * Option_Bool
00515  * ----------------------------------------------------------------------- */
00516 class Option_Bool : public Option {
00517 public:
00522     Option_Bool() throw();
00523 
00524 
00531     Option_Bool(bool value) throw();
00532 
00533 
00535     Option_Bool(const Option_Bool &s) throw();
00536 
00537 
00539     ~Option_Bool() throw();
00540 
00541 
00543     Option_Bool &operator=(const Option_Bool &s) throw();
00544 
00545 
00550     bool getBool() const throw(InvalidArgument);
00551 
00553     bool set(bool v) throw(InvalidArgument);
00554 
00555 
00563     std::string getValueString() const throw(InvalidArgument);
00564 
00565 
00573     bool isBool() const throw();
00574 
00575 
00576 private:
00578     bool        myValue;
00579 
00580 };
00581 
00582 
00583 /* -------------------------------------------------------------------------
00584  * Option_FileName
00585  * ----------------------------------------------------------------------- */
00586 class Option_FileName : public Option_String {
00587 public:
00590     Option_FileName() throw();
00591 
00592 
00597     Option_FileName(const std::string &value) throw();
00598 
00599 
00601     Option_FileName(const Option_String &s) throw();
00602 
00603 
00605     virtual ~Option_FileName() throw();
00606 
00608     Option_FileName &operator=(const Option_FileName &s) throw();
00609 
00610 
00617     bool isFileName() const throw();
00618 
00619 };
00620 
00621 
00622 /* -------------------------------------------------------------------------
00623  * Option_IntVector
00624  * ----------------------------------------------------------------------- */
00625 class Option_IntVector : public Option {
00626 public:
00629     Option_IntVector() throw();
00630 
00631 
00636     Option_IntVector(const IntVector &value) throw();
00637 
00638 
00640     Option_IntVector(const Option_IntVector &s) throw();
00641 
00642 
00644     virtual ~Option_IntVector() throw();
00645 
00646 
00648     Option_IntVector &operator=(const Option_IntVector &s) throw();
00649 
00650 
00655     const IntVector &getIntVector() const throw(InvalidArgument);
00656 
00657 
00673     bool set(const std::string &v) throw(InvalidArgument);
00674 
00675 
00683     std::string getValueString() const throw(InvalidArgument);
00684 
00685 
00686 private:
00688     IntVector myValue;
00689 };
00690 
00691 
00692 #endif
00693 
00694 /****************************************************************************/
00695 

Generated on Wed May 5 00:06:35 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6