Assignments Assignments

cmdLineParser.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27*/
28
29#ifndef CMD_LINE_PARSER_INCLUDED
30#define CMD_LINE_PARSER_INCLUDED
31#include <stdarg.h>
32#include <cstring>
33#include <cstdlib>
34#include <string>
35#include <vector>
36
37 namespace Util
38{
40 class CmdLineReadable
41 {
42 public:
44 bool set;
45
47 std::string name;
48
50 CmdLineReadable( const std::string &name );
51
53 virtual ~CmdLineReadable( void );
54
57 virtual int read( char **argv , int argc );
58 };
59
61 template< class Type >
62 class CmdLineParameter : public CmdLineReadable
63 {
64 public:
66 Type value;
67
69 CmdLineParameter( const std::string &name );
70
72 CmdLineParameter( const std::string &name , Type v );
73
76 int read( char **argv , int argc );
77 };
78
80 template< class Type , int Dim >
81 class CmdLineParameterArray : public CmdLineReadable
82 {
83 public:
85 Type values[Dim];
86
88 CmdLineParameterArray( const std::string &name, const Type* v=NULL );
89
92 int read( char **argv , int argc );
93 };
94
96 template< class Type >
97 class CmdLineParameters : public CmdLineReadable
98 {
99 public:
101 int count;
102
104 Type *values;
105
107 CmdLineParameters( const std::string &name );
108
110 ~CmdLineParameters( void );
111
114 int read( char **argv , int argc );
115 };
116
117#if defined( _WIN32 ) || defined( _WIN64 )
118 static const char FileSeparator = '\\';
119#else // !_WIN32 && !_WIN64
120 static const char FileSeparator = '/';
121#endif // _WIN32 || _WIN64
122
125 void CmdLineParse( int argc , char **argv, CmdLineReadable **params );
126
128 std::string ToUpper( const std::string &str );
129
131 std::string ToLower( const std::string &str );
132
134 std::string GetFileExtension( const std::string &fileName );
135
137 std::vector< std::string > ReadWords( const std::string &fileName );
138
140 std::string GetLocalFileName( const std::string &fileName );
141
143 std::string GetFileDirectory( const std::string &fileName );
144
146 std::string GetFileName( const std::string &directory , const std::string &localFileName );
147}
148#include "cmdLineParser.inl"
149#endif // CMD_LINE_PARSER_INCLUDED
Util::CmdLineParameterArray::read
int read(char **argv, int argc)
Definition cmdLineParser.inl:77
Util::CmdLineParameterArray::values
Type values[Dim]
Definition cmdLineParser.h:85
Util::CmdLineParameterArray::CmdLineParameterArray
CmdLineParameterArray(const std::string &name, const Type *v=NULL)
Definition cmdLineParser.inl:70
Util::CmdLineParameter::value
Type value
Definition cmdLineParser.h:66
Util::CmdLineParameter::CmdLineParameter
CmdLineParameter(const std::string &name)
Definition cmdLineParser.inl:50
Util::CmdLineParameter::read
int read(char **argv, int argc)
Definition cmdLineParser.inl:55
Util::CmdLineParameters::count
int count
Definition cmdLineParser.h:101
Util::CmdLineParameters::~CmdLineParameters
~CmdLineParameters(void)
Definition cmdLineParser.inl:95
Util::CmdLineParameters::values
Type * values
Definition cmdLineParser.h:104
Util::CmdLineParameters::read
int read(char **argv, int argc)
Definition cmdLineParser.inl:103
Util::CmdLineParameters::CmdLineParameters
CmdLineParameters(const std::string &name)
Definition cmdLineParser.inl:92
Util::CmdLineReadable
Definition cmdLineParser.h:41
Util::CmdLineReadable::name
std::string name
Definition cmdLineParser.h:47
Util::CmdLineReadable::set
bool set
Definition cmdLineParser.h:44
Util::CmdLineReadable::read
virtual int read(char **argv, int argc)
Definition cmdLineParser.inl:45
Util::CmdLineReadable::~CmdLineReadable
virtual ~CmdLineReadable(void)
Definition cmdLineParser.inl:43
Util::CmdLineReadable::CmdLineReadable
CmdLineReadable(const std::string &name)
Definition cmdLineParser.inl:41
cmdLineParser.inl
params
CmdLineReadable * params[]
Definition main1.cpp:37
Util
Definition algebra.h:7
Util::GetFileDirectory
std::string GetFileDirectory(const std::string &fileName)
Definition cmdLineParser.inl:183
Util::CmdLineParse
void CmdLineParse(int argc, char **argv, CmdLineReadable **params)
Definition cmdLineParser.inl:125
Util::ToLower
std::string ToLower(const std::string &str)
Definition cmdLineParser.inl:158
Util::FileSeparator
static const char FileSeparator
Definition cmdLineParser.h:120
Util::GetLocalFileName
std::string GetLocalFileName(const std::string &fileName)
Definition cmdLineParser.inl:175
Util::ToUpper
std::string ToUpper(const std::string &str)
Definition cmdLineParser.inl:149
Util::GetFileName
std::string GetFileName(const std::string &directory, const std::string &localFileName)
Definition cmdLineParser.inl:191
Util::GetFileExtension
std::string GetFileExtension(const std::string &fileName)
Definition cmdLineParser.inl:167
Util::ReadWords
std::vector< std::string > ReadWords(const std::string &fileName)
Definition cmdLineParser.inl:199