Assignments
Assignments
cmdLineParser.h
Go to the documentation of this file.
1/*
2Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
8Redistributions of source code must retain the above copyright notice, this list of
9conditions and the following disclaimer. Redistributions in binary form must reproduce
10the above copyright notice, this list of conditions and the following disclaimer
11in the documentation and/or other materials provided with the distribution.
12
13Neither the name of the Johns Hopkins University nor the names of its contributors
14may be used to endorse or promote products derived from this software without specific
15prior written permission.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26DAMAGE.
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
37namespace Util
38{
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 >
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 >
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 >
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
Definition: cmdLineParser.h:82
int read(char **argv, int argc)
Definition: cmdLineParser.inl:77
Type values[Dim]
Definition: cmdLineParser.h:85
CmdLineParameterArray(const std::string &name, const Type *v=NULL)
Definition: cmdLineParser.inl:70
Definition: cmdLineParser.h:63
Type value
Definition: cmdLineParser.h:66
CmdLineParameter(const std::string &name)
Definition: cmdLineParser.inl:50
int read(char **argv, int argc)
Definition: cmdLineParser.inl:55
Definition: cmdLineParser.h:98
int count
Definition: cmdLineParser.h:101
~CmdLineParameters(void)
Definition: cmdLineParser.inl:95
Type * values
Definition: cmdLineParser.h:104
int read(char **argv, int argc)
Definition: cmdLineParser.inl:103
CmdLineParameters(const std::string &name)
Definition: cmdLineParser.inl:92
Definition: cmdLineParser.h:41
std::string name
Definition: cmdLineParser.h:47
bool set
Definition: cmdLineParser.h:44
virtual int read(char **argv, int argc)
Definition: cmdLineParser.inl:45
virtual ~CmdLineReadable(void)
Definition: cmdLineParser.inl:43
CmdLineReadable(const std::string &name)
Definition: cmdLineParser.inl:41
CmdLineReadable * params[]
Definition: main1.cpp:37
Definition: algebra.h:7
std::string GetFileDirectory(const std::string &fileName)
Definition: cmdLineParser.inl:183
void CmdLineParse(int argc, char **argv, CmdLineReadable **params)
Definition: cmdLineParser.inl:125
std::string ToLower(const std::string &str)
Definition: cmdLineParser.inl:158
static const char FileSeparator
Definition: cmdLineParser.h:120
std::string GetLocalFileName(const std::string &fileName)
Definition: cmdLineParser.inl:175
std::string ToUpper(const std::string &str)
Definition: cmdLineParser.inl:149
std::string GetFileName(const std::string &directory, const std::string &localFileName)
Definition: cmdLineParser.inl:191
std::string GetFileExtension(const std::string &fileName)
Definition: cmdLineParser.inl:167
std::vector< std::string > ReadWords(const std::string &fileName)
Definition: cmdLineParser.inl:199