Bitstream Interpretation Library (BIL)
0.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
datagen
bitcorrelate
bitcorrelateArgs.cpp
Go to the documentation of this file.
1
6
#include <
datagen/bitcorrelate/bitcorrelateArgs.hpp
>
7
#include <
datagen/bitcorrelate/bitcorrelateMsgs.hpp
>
8
#include <
exception/CommandLineException.hpp
>
9
10
using namespace
bil;
11
12
std::string
xdlFileName
;
13
std::string
bitFileName
;
14
std::string
dbFileName
;
15
std::string
statsFileName
;
16
std::string
dataPathName
;
17
18
19
void
parseCommandLine
(
int
argc,
char
** argv)
20
{
21
// set program parameters to standard values
22
xdlFileName
.clear();
23
bitFileName
.clear();
24
dbFileName
.clear();
25
statsFileName
.clear();
26
dataPathName
.clear();
27
28
// examine all program parameters
29
std::string arg;
30
size_t
positionalOptIndex = 0;
31
size_t
argCount =
static_cast<
size_t
>
(argc);
32
for
(
size_t
i = 1; i < argCount; ++i)
33
{
34
// copy parameter
35
arg.assign(argv[i]);
36
// no switches allowed
37
if
(
'-'
== arg[0])
38
{
39
if
(
"-dp"
== arg)
40
{
41
if
((++i) >= argCount)
42
throw
CommandLineException
(
ERROR_NO_DATAPATH_MSG
);
43
dataPathName
.assign(argv[i]);
44
}
45
else
if
(
"-s"
== arg)
46
{
47
if
((++i) >= argCount)
48
throw
CommandLineException
(
ERROR_NO_STATSFILE_MSG
);
49
statsFileName
.assign(argv[i]);
50
}
51
else
52
{
53
std::string msg =
ERROR_UNKNOWN_OPTION_1_MSG
;
54
msg.append(arg);
55
msg.append(
ERROR_UNKNOWN_OPTION_2_MSG
);
56
throw
CommandLineException
(msg);
57
}
58
}
59
// process positional arguments
60
else
61
{
62
switch
(positionalOptIndex)
63
{
64
case
0:
xdlFileName
= arg;
break
;
65
case
1:
bitFileName
= arg;
break
;
66
case
2:
dbFileName
= arg;
break
;
67
default
:
throw
CommandLineException
(
ERROR_TOO_MANY_PARAMETERS_MSG
);
68
}
69
positionalOptIndex++;
70
}
71
}
72
73
// XDL name must not be empty
74
if
(
xdlFileName
.empty())
throw
CommandLineException
(
ERROR_NO_XDL_FILE_MSG
);
75
76
// bitfile name must not be empty
77
if
(
bitFileName
.empty())
throw
CommandLineException
(
ERROR_NO_BIT_FILE_MSG
);
78
79
// data base name must not be empty
80
if
(
dbFileName
.empty())
throw
CommandLineException
(
ERROR_NO_DB_FILE_MSG
);
81
82
// if data path set, enforce that it ends with path separator
83
if
(!
dataPathName
.empty())
84
{
85
char
lastChar =
dataPathName
[
dataPathName
.size()-1];
86
if
((
'/'
!= lastChar) && (
'\\'
!= lastChar))
dataPathName
.push_back(
'/'
);
87
}
88
}
Generated on Wed Aug 8 2012 21:57:40 for Bitstream Interpretation Library (BIL) by
1.8.1.1