Ice 3.7 C++11 API Reference
Loading...
Searching...
No Matches
Options.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_UTIL_OPTIONS_H
6#define ICE_UTIL_OPTIONS_H
7
8#include <IceUtil/Config.h>
9#include <IceUtil/RecMutex.h>
10#include <IceUtil/Shared.h>
11#include <IceUtil/Handle.h>
12#include <IceUtil/Exception.h>
13#include <string>
14#include <vector>
15#include <map>
16
17namespace IceUtilInternal
18{
19
20class ICE_API APIException : public IceUtil::ExceptionHelper<APIException>
21{
22public:
23
24 APIException(const char*, int, const ::std::string&);
25#ifndef ICE_CPP11_COMPILER
26 virtual ~APIException() throw();
27#endif
28 virtual ::std::string ice_id() const;
29 virtual void ice_print(std::ostream&) const;
30#ifndef ICE_CPP11_MAPPING
31 virtual APIException* ice_clone() const;
32#endif
33
34 ::std::string reason;
35};
36
37ICE_API ::std::ostream& operator<<(::std::ostream&, const APIException&);
38
39class ICE_API BadOptException : public IceUtil::ExceptionHelper<BadOptException>
40{
41public:
42
43 BadOptException(const char*, int, const ::std::string&);
44#ifndef ICE_CPP11_COMPILER
45 virtual ~BadOptException() throw();
46#endif
47 virtual ::std::string ice_id() const;
48 virtual void ice_print(std::ostream&) const;
49
50#ifndef ICE_CPP11_MAPPING
51 virtual BadOptException* ice_clone() const;
52#endif
53
54 ::std::string reason;
55};
56
57ICE_API ::std::ostream& operator<<(::std::ostream&, const BadOptException&);
58
59class ICE_API Options
60{
61public:
62
63 enum LengthType { ShortOpt, LongOpt };
64 enum RepeatType { Repeat, NoRepeat };
65 enum ArgType { NeedArg, NoArg };
66
67 Options();
68 void addOpt(const ::std::string&, const ::std::string& = "",
69 ArgType = NoArg, ::std::string = "", RepeatType = NoRepeat);
70
71 typedef ::std::vector< ::std::string> StringVector;
72
73 static StringVector split(const ::std::string&);
74 StringVector parse(const StringVector&);
75 StringVector parse(int, const char* const []);
76 bool isSet(const ::std::string&) const;
77 ::std::string optArg(const ::std::string&) const;
78 StringVector argVec(const ::std::string&) const;
79
80private:
81
82 struct OptionDetails : public IceUtil::Shared
83 {
84 LengthType length;
85 ArgType arg;
86 RepeatType repeat;
87 bool hasDefault;
88 };
89 typedef IceUtil::Handle<OptionDetails> ODPtr;
90
91 struct OptionValue : public IceUtil::Shared
92 {
93 ::std::string val;
94 };
95 typedef IceUtil::Handle<OptionValue> OValPtr;
96
97 struct OptionValueVector : public IceUtil::Shared
98 {
99 ::std::vector< ::std::string> vals;
100 };
101 typedef IceUtil::Handle<OptionValueVector> OVecPtr;
102
103 typedef ::std::map< ::std::string, ODPtr> ValidOpts; // Valid options and their details.
104 typedef ::std::map< ::std::string, OValPtr> Opts; // Value of non-repeating options.
105 typedef ::std::map< ::std::string, OVecPtr> ROpts; // Value of repeating options.
106 typedef ::std::map< ::std::string, ::std::string> Synonyms; // Map from short to long option and vice versa.
107
108 void addValidOpt(const ::std::string&, const ::std::string&, ArgType, const ::std::string&, RepeatType);
109 ValidOpts::iterator checkOpt(const ::std::string&, LengthType);
110 void setOpt(const ::std::string&, const ::std::string&, const ::std::string&, RepeatType);
111 void setNonRepeatingOpt(const ::std::string&, const ::std::string&);
112 void setRepeatingOpt(const ::std::string&, const ::std::string&);
113 ValidOpts::const_iterator checkOptIsValid(const ::std::string&) const;
114 ValidOpts::const_iterator checkOptHasArg(const ::std::string&) const;
115 void updateSynonyms(const ::std::string&, const ::std::string&);
116 ::std::string getSynonym(const ::std::string&) const;
117
118 ValidOpts _validOpts;
119 Opts _opts;
120 ROpts _ropts;
121 Synonyms _synonyms;
122
123 bool parseCalled;
124
125 IceUtil::RecMutex _m;
126
127 Options(const Options&); // Not allowed.
128 void operator=(const Options&); // Not allowed.
129
130 static void checkArgs(const ::std::string&, const ::std::string&, bool, const ::std::string&);
131};
132
133}
134
135#endif
#define ICE_API
Definition Config.h:197