-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwuParameter.cpp
More file actions
executable file
·104 lines (82 loc) · 2.98 KB
/
wuParameter.cpp
File metadata and controls
executable file
·104 lines (82 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
WorldOfWator
Copyright 2009 Ingo Berg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "wuParameter.h"
#include "suStringTokens.h"
#include "suUtility.h"
namespace wu
{
//---------------------------------------------------------------------------
// The statis instance
std::auto_ptr<Parameter> Parameter::m_pInst(0);
//---------------------------------------------------------------------------
Parameter& Parameter::GetInst()
{
if (!m_pInst.get())
m_pInst.reset(new Parameter());
return *m_pInst;
}
//---------------------------------------------------------------------------
Parameter* Parameter::GetInstPtr()
{
if (!m_pInst.get())
m_pInst.reset(new Parameter());
return m_pInst.get();
}
//---------------------------------------------------------------------------
Parameter::Parameter()
:m_sCmdLine()
,m_Param()
{
m_sCmdLine = GetCommandLine();
su::StringTokens<string_type> par(m_sCmdLine, _T("/"));
int iNum = par.Count();
su::StringTokens<string_type> subpar;
// don't split the path and dont add an additional argument
m_Param[par[0]] = _T("");
// store options in capital letters
for (int i=1; i<iNum; ++i)
{
subpar.Tokenize(par[i], _T(" :"));
m_Param[su::to_upper(subpar[0])] = (subpar.Count()>=2) ? subpar[1] : _T("");
}
}
//---------------------------------------------------------------------------
const Parameter::string_type& Parameter::GetCmdLine() const
{
return m_sCmdLine;
}
//---------------------------------------------------------------------------
unsigned Parameter::GetArgc() const
{
return (unsigned)m_Param.size();
}
//---------------------------------------------------------------------------
/** \brief Check whether a given Parameter was present in the command line.
*/
bool Parameter::IsOpt(const string_type &a_sArg) const
{
map_type::const_iterator item = m_Param.find(a_sArg);
return (item!=m_Param.end());
}
//---------------------------------------------------------------------------
const Parameter::string_type& Parameter::GetOpt(const string_type &a_sOpt) const
{
static const string_type sEmpty;
string_type sOpt = su::to_upper(a_sOpt);
map_type::const_iterator item = m_Param.find(sOpt);
return (item!=m_Param.end()) ? item->second : sEmpty;
}
}