-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParse.cpp
More file actions
100 lines (80 loc) · 2.22 KB
/
Parse.cpp
File metadata and controls
100 lines (80 loc) · 2.22 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
/*
* This file is part of ElasticFusion.
*
* Copyright (C) 2015 Imperial College London
*
* The use of the code within this file and all code within files that
* make up the software that is ElasticFusion is permitted for
* non-commercial purposes only. The full terms and conditions that
* apply to the code within this file are detailed within the LICENSE.txt
* file and at <http://www.imperial.ac.uk/dyson-robotics-lab/downloads/elastic-fusion/elastic-fusion-license/>
* unless explicitly stated. By downloading this file you agree to
* comply with these terms.
*
* If you wish to use any of this code for commercial purposes then
* please email researchcontracts.engineering@imperial.ac.uk.
*
*/
#include "Parse.h"
Parse::Parse()
{
}
const Parse & Parse::get()
{
static const Parse instance;
return instance;
}
int Parse::arg(int argc, char** argv, const char* str, std::string &val) const
{
int index = findArg(argc, argv, str) + 1;
if(index > 0 && index < argc)
{
val = argv[index];
}
return index - 1;
}
int Parse::arg(int argc, char** argv, const char* str, float &val) const
{
int index = findArg(argc, argv, str) + 1;
if(index > 0 && index < argc)
{
val = atof(argv[index]);
}
return index - 1;
}
int Parse::arg(int argc, char** argv, const char* str, int &val) const
{
int index = findArg(argc, argv, str) + 1;
if(index > 0 && index < argc)
{
val = atoi(argv[index]);
}
return index - 1;
}
std::string Parse::shaderDir() const
{
std::string currentVal = STR(SHADER_DIR);
assert(pangolin::FileExists(currentVal) && "Shader directory not found!");
return currentVal;
}
std::string Parse::baseDir() const
{
char buf[256];
int length = 0;//readlink("/proc/self/exe",buf,sizeof(buf));
std::string currentVal;
currentVal.append((char *)&buf, length);
currentVal = currentVal.substr(0, currentVal.rfind("/build/"));
return currentVal;
}
int Parse::findArg(int argc, char** argv, const char* argument_name) const
{
for(int i = 1; i < argc; ++i)
{
// Search for the string
if(strcmp(argv[i], argument_name) == 0)
{
return i;
}
}
return -1;
}