30 #define strcasecmp _stricmp
31 #define strncasecmp _strnicmp
32 #define MAX_STRING_LEN 65536
51 strtol(value, &t, 10);
52 if(value + strlen(value) != t)
61 if(value + strlen(value) != t)
94 char* Environment::ParseString(
char*
buffer,
char* str)
const
97 char *t = str + strlen(str);
100 while (*s ==
' ' || *s ==
'\t' || *s ==
'\n' || *s == 0x0d)
106 while ( (*s >=
'a' && *s <=
'z') ||
107 (*s >=
'A' && *s <=
'Z') ||
108 (*s >=
'0' && *s <=
'9') ||
115 while (*s ==
' ' || *s ==
'\t' || *s ==
'\n' || *s == 0x0d)
128 bool Environment::ParseBool(
const char* valueString)
const
145 int Environment::FindOption(
const char*
name,
const bool isFatal)
const
151 for (i = 0; i < numOptions; i++)
153 if (!strcmp(options[i].name, name))
167 if (options[i].value ==
NULL && options[i].defaultValue ==
NULL)
207 cerr <<
"Environment not allocated!!";
234 s <<
"Registered options:\n";
235 for (
int j = 0; j < numOptions; j++)
236 s << options[j] <<
"\n";
269 for (i = 0; i < numOptions; i++)
271 if (!strcmp(name, options[i].name))
279 if (numOptions >= maxOptions)
286 if (abbrev !=
NULL && (abbrev[0] ==
'D' ))
294 options[numOptions].
name = strdup(name);
299 options[numOptions].
abbrev = strdup(abbrev);
303 if (defValue !=
NULL)
306 if (!CheckVariableType(defValue, type))
325 int i = FindOption(name);
332 delete [] options[i].
value;
333 options[i].
value =
new char[16];
334 sprintf(options[i].value,
"%.15d", value);
351 int i = FindOption(name);
358 delete [] options[i].
value;
359 options[i].
value =
new char[25];
360 sprintf(options[i].value,
"%.15e", value);
377 int i = FindOption(name);
384 delete [] options[i].
value;
386 options[i].
value =
new char[6];
389 sprintf(options[i].value,
"true");
391 sprintf(options[i].value,
"false");
408 int i = FindOption(name);
415 delete [] options[i].
value;
416 options[i].
value = ::strdup(value);
453 cerr <<
"Error: GetInt value not found!";
471 cerr <<
"Error: GetFloat value not found!";
489 cerr <<
"Error: GetDouble value not found!";
503 int i = FindOption(name, isFatal);
508 if (options[i].value !=
NULL)
510 value = strtol(options[i].value,
NULL, 10);
514 value = strtol(options[i].defaultValue,
NULL, 10);
529 int i = FindOption(name, isFatal);
534 if (options[i].value !=
NULL)
536 value = strtod(options[i].value,
NULL);
540 value = strtod(options[i].defaultValue,
NULL);
555 int i = FindOption(name, isFatal);
560 if (options[i].value !=
NULL)
562 value = (float)strtod(options[i].value,
NULL);
566 value = (float)strtod(options[i].defaultValue,
NULL);
581 int i = FindOption(name, isFatal);
586 if (options[i].value !=
NULL)
587 value = ParseBool(options[i].value);
589 value = ParseBool(options[i].defaultValue);
603 int i = FindOption(name, isFatal);
608 if (options[i].value !=
NULL)
609 strcpy(value, options[i].value);
611 strcpy(value, options[i].defaultValue);
643 for (
int i = 1; i <
argc; i++)
644 if ((argv[i][0] ==
'-') && (argv[i][1] == swtch))
667 if (optionalParams !=
NULL)
670 numParams = (int)strlen(optParams) + 1;
671 optionalParams =
new char[numParams];
672 strcpy(optionalParams, optParams);
675 for (i = 1; i <
argc; i++)
676 if (argv[i][0] !=
'-')
684 params =
new char **[numParams];
685 for (i = 0; i < numParams; i++)
687 params[i] =
new char *[paramRows];
688 for (
int j = 0; j < paramRows; j++)
694 for (i = 1; i <
argc; i++)
696 if (argv[i][0] !=
'-')
700 params[0][curRow] =
new char[strlen(argv[i]) + 1];
701 strcpy(params[0][curRow], argv[i]);
706 char *t = strchr(optionalParams, argv[i][1]);
710 int index = t - optionalParams + 1;
714 for (
int j = 0; j < paramRows; j++)
716 params[
index][j] =
new char[strlen(argv[i] + 2) + 1];
717 strcpy(params[index][j], argv[i] + 2);
723 if (params[index][curRow] !=
NULL)
725 delete [] params[
index][curRow];
727 params[
index][curRow] =
new char[strlen(argv[i] + 2) + 1];
728 strcpy(params[index][curRow], argv[i] + 2);
750 ifstream envStream(filename);
753 if (envStream.fail())
755 cerr <<
"Error: Can't open file " << filename <<
" for reading (err. " << envStream.rdstate() <<
").\n";
772 s = strchr(buff,
'#');
777 s = ParseString(buff, name);
787 s = ParseString(s, name);
794 if (strlen(name) == 0)
796 cerr <<
"Error: unpaired } in " << filename <<
" (line " << line <<
").\n";
801 name[strlen(name) - 1] =
'\0';
802 t = strrchr(name,
'.');
810 s = ParseString(s, name);
817 for (i = 0; i < numOptions; i++)
819 if (!strcmp(name, options[i].name))
828 cerr <<
"Warning: unknown option " << name <<
" in environment file " << filename <<
" (line " << line <<
").\n";
832 switch (options[i].
type)
837 if (t == s || (*t !=
' ' && *t !=
'\t' && *t !=
'\0' && *t !=
'}'))
839 cerr <<
"Error: Mismatch in int variable " << name <<
" in " <<
"environment file " << filename <<
" (line " << line <<
").\n";
844 if (options[i].value !=
NULL)
845 delete [] options[i].
value;
847 options[i].
value =
new char[t - s + 1];
848 strncpy(options[i].value, s, t - s);
849 options[i].
value[t - s] =
'\0';
857 if (t == s || (*t !=
' ' && *t !=
'\t' && *t !=
'\0' && *t !=
'}'))
859 cerr <<
"Error: Mismatch in float variable " << name <<
" in " <<
"environment file " << filename <<
" (line " << line <<
").\n";
864 if (options[i].value !=
NULL)
865 delete [] options[i].
value;
867 options[i].
value =
new char[t - s + 1];
868 strncpy(options[i].value, s, t - s);
869 options[i].
value[t - s] =
'\0';
877 while ( (*t >=
'a' && *t <=
'z') ||
878 (*t >=
'A' && *t <=
'Z') ||
879 *t ==
'+' || *t ==
'-')
882 if (( (!
strncasecmp(s,
"true", t - s) && t - s == 4) ||
883 (!
strncasecmp(s,
"false", t - s) && t - s == 5)) &&
884 (*t ==
' ' || *t ==
'\t' || *t ==
'\0' || *t ==
'}'))
886 if (options[i].value !=
NULL)
887 delete [] options[i].
value;
888 options[i].
value =
new char[t - s + 1];
889 strncpy(options[i].value, s, t - s);
890 options[i].
value[t - s] =
'\0';
895 cerr <<
"Error: Mismatch in bool variable " << name <<
" in " <<
"environment file " << filename <<
" (line " << line <<
").\n";
904 if (options[i].value !=
NULL)
905 delete [] options[i].
value;
907 options[i].
value =
new char[strlen(s) + 1];
908 strcpy(options[i].value, s);
910 int last = strlen(options[i].value)-1;
912 if (options[i].value[last] == 0x0a || options[i].value[last] == 0x0d)
913 options[i].
value[last] = 0;
927 t = strrchr(name,
'.');
935 s = ParseString(s, name);
955 for (
int i = 1; i <
argc; i++)
958 if (argv[i][0] !=
'-')
965 char *t = strchr(optionalParams, argv[i][1]);
970 if (curIndex == -1 || curIndex == index)
972 if (argv[i][1] ==
'D')
978 char *t = strchr(argv[i] + 2,
'=');
985 for (j = 0; j < numOptions; j++)
987 if (!strncmp(options[j].name, argv[i] + 2, t - argv[i] - 2) && (
unsigned)(t - argv[i] - 2) == strlen(options[j].name))
1002 if (!CheckVariableType(t + 1, options[j].
type))
1008 if (options[j].value !=
NULL)
1009 delete [] options[j].
value;
1011 options[j].
value = strdup(t + 1);
1020 for (j = 0; j < numOptions; j++)
1022 if (options[j].abbrev !=
NULL && !strncmp(options[j].abbrev, argv[i] + 1, strlen(options[j].abbrev)))
1035 if (!CheckVariableType(argv[i] + 1 + strlen(options[j].abbrev), options[j].
type))
1041 if (options[j].value !=
NULL)
1042 delete [] options[j].
value;
1044 options[j].
value = strdup(argv[i] + 1 + strlen(options[j].abbrev));
1068 if (index >= paramRows || index < 0)
1075 char *t = strchr(optionalParams, name);
1080 column = t - optionalParams + 1;
1083 if (params[column][index] ==
NULL)
1086 strcpy(value, params[column][index]);
1101 for (i = 0; i < numOptions; i++)
1103 if (!strcmp(options[i].name, name))
1116 if (options[i].value !=
NULL || options[i].defaultValue !=
NULL)
1130 optionalParams =
NULL;
1140 options =
new Option[maxOptions];
1142 if (options ==
NULL )
1162 for (i = 0; i < numParams; i++)
1164 for (j = 0; j < paramRows; j++)
1166 if (params[i][j] !=
NULL)
1167 delete[] params[i][j];
1170 if (params[i] !=
NULL)
1177 if (options !=
NULL)
1180 if (optionalParams !=
NULL)
1181 delete optionalParams;
float GetFloat(const char *name, const bool isFatal=false) const
bool GetStringValue(const char *name, char *value, const bool isFatal=false) const
void RegisterOption(const char *name, const OptionType type, const char *abbrev, const char *defValue=NULL)
int GetInt(const char *name, const bool isFatal=false) const
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer
static void DeleteSingleton()
void ReadCmdlineParams(const int argc, char **argv, const char *optParams)
void SetBool(const char *name, const bool value)
void SetInt(const char *name, const int value)
double GetDouble(const char *name, const bool isFatal=false) const
void ParseCmdline(const int argc, char **argv, const int index)
bool GetDoubleValue(const char *name, double &value, const bool isFatal=false) const
static Environment * GetSingleton()
bool ReadEnvFile(const char *filename)
virtual void PrintUsage(ostream &s) const
bool OptionPresent(const char *name) const
virtual void SetStaticOptions()
bool CheckForSwitch(const int argc, char **argv, const char swtch) const
void SetFloat(const char *name, const float value)
void SetString(const char *name, const char *value)
String sprintf(const char *fmt,...)
bool GetFloatValue(const char *name, float &value, const bool isFatal=false) const
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint index
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value
bool GetIntValue(const char *name, int &value, const bool isFatal=false) const
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type
bool GetBoolValue(const char *name, bool &value, const bool isFatal=false) const
bool GetParam(const char name, const int index, char *value) const
bool GetBool(const char *name, const bool isFatal=false) const
static void SetSingleton(Environment *e)
static Environment * mEnvironment