index.html: add new file
[vss2svn.git] / ssphys / SSPhys / Options.h
blobe1e605eb180c3a5db63c35ede1a172236398a901
1 // Options.h: interface for the COptions class.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #if !defined(AFX_OPTIONS_H__8B59AD68_C12F_44E7_9236_3C800593E961__INCLUDED_)
6 #define AFX_OPTIONS_H__8B59AD68_C12F_44E7_9236_3C800593E961__INCLUDED_
8 #if _MSC_VER > 1000
9 #pragma once
10 #endif // _MSC_VER > 1000
12 #include <list>
15 //---------------------------------------------------------------------------
16 enum tristate { cleared, undefined, set };
18 inline void operator &= (bool& _bool, tristate _tristate)
20 _bool = _tristate == undefined ? _bool : _tristate == cleared ? false : true;
24 //---------------------------------------------------------------------------
25 struct CValue
27 CValue ()
28 : m_Type (typeUndefined)
29 { }
30 CValue (tristate val)
31 : m_Type (typeTristate), pTristateValue (val)
32 { }
33 CValue (const char* pVal)
34 : m_Type (typeString), m_pStringValue (pVal)
35 { }
36 CValue (const bool val)
37 : m_Type (typeBool), pBoolValue(val)
38 { }
40 enum { typeUndefined, typeTristate, typeBool, typeString} m_Type;
41 union {
42 tristate pTristateValue;
43 bool pBoolValue;
44 const char* m_pStringValue;
47 operator const char* () const
49 assert (m_Type == typeString);
50 return m_pStringValue;
53 operator tristate () const
55 assert (m_Type == typeTristate);
56 return pTristateValue;
61 struct COption
63 int id;
64 CValue value;
67 typedef std::list<COption> COptionsList;
69 struct COptionInfo
71 public:
72 enum eArgType { noArgument, requiredArgument, optionalArgument, tristateArgument };
74 COptionInfo (int id, char shortOption, std::string longOption, std::string descr, eArgType needArg);
76 int m_Id;
77 char m_shortOption;
78 std::string m_longOption;
79 std::string m_Description;
80 eArgType m_needArg;
83 std::ostream& operator<<(std::ostream& os, const COptionInfo& info);
85 typedef std::list<COptionInfo> COptionInfoList;
88 class COptions
90 public:
91 virtual ~COptions () {};
93 virtual COptionInfoList GetOptionsInfo () const
95 return COptionInfoList ();
97 void SetOptions (const COptionsList& options)
99 COptionsList::const_iterator itor = options.begin ();
100 while (itor != options.end())
102 // if (!SetOption (*itor))
103 // throw SSException ("unknown option");
104 SetOption (*itor);
105 ++itor;
108 virtual bool SetOption (const COption& option) = 0;
110 virtual void PrintUsage () const;
114 #endif // !defined(AFX_OPTIONS_H__8B59AD68_C12F_44E7_9236_3C800593E961__INCLUDED_)