NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Environment.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, FI MUNI CZ
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * Authors:
28  * Vilem Otte <vilem.otte@post.cz>
29  *
30  */
31 
32 #ifndef __ENVIRONMENT_H__
33 #define __ENVIRONMENT_H__
34 
35 #include <iostream>
36 #include <string>
37 #include <cmath>
38 #include <cstdlib>
39 #include <cstdio>
40 #include <fstream>
41 #include <string.h>
42 
43 using namespace std;
44 
49 enum OptionType {
50  optInt, // Integer env-var
51  optFloat, // Floating point env-var
52  optBool, // Boolean env-var
53  optString // String env-var
54 };
55 
60 class Option
61 {
62 public:
64 
66  OptionType type; //< Option type
67  char* name; //< Option name
68  char* value; //< Option value
69  char* abbrev; //< Option Abbreviation
70  char* defaultValue; //< Option default value
71 
72  char* description; //< Option description
73  void* pointer; //< TODO: Whats this for? (search in Minimax)
74 
76 
85  {
86  name = NULL;
87  value = NULL;
88  abbrev = NULL;
89  defaultValue = NULL;
90  description = NULL;
91  pointer = NULL;
92  }
93 
95 
103  virtual ~Option()
104  {
105  if(name) delete [] name;
106  if(value) delete [] value;
107  if(abbrev) delete [] abbrev;
108  if(defaultValue) delete [] defaultValue;
109  if(description) delete [] description;
110  }
111 
113 
122  friend ostream& operator<<(ostream& s, const Option& o)
123  {
124  // Ouptut name, abbrevation, value, default value and description
125  // Ideally resulting in string:
126  // > option_small_x opt_x 12.45 [1.0]
127  // > Small x option
128  s << o.name << "\t";
129 
130  if(o.abbrev)
131  s << o.abbrev;
132  else
133  s << "no abbrev";
134  s << "\t";
135 
136  if(o.value)
137  s << o.value;
138  else
139  s << "not set";
140  s << "\t";
141 
142  if(o.defaultValue)
143  s << "[" << o.defaultValue << "]";
144  else
145  s << "[not set]";
146  s << "\t";
147 
148  if(o.description)
149  s << endl << o.description;
150 
151  return s;
152  }
153 };
154 
161 {
162 private:
164 
166  int maxOptions; //< Maximal number of options
167  int numParams; //< Number of columns in parameter table
168  int paramRows; //< Number of rows in parameter table
169  char* optionalParams; //< String with prefixes with non-optional parameters
170  int curRow; //< Current row in parameter table
171  char*** params; //< Parameter table. 2D array of strings, first column are parameters, next are options
172  //< prefixed by char passed to function GetCmdlineParams paired with corresponding parameters.
173  int numOptions; //< Number of registered options
174  Option* options; //< Options table
175 
177 
186  bool CheckVariableType(const char* value, const OptionType type) const;
187 
197  char* ParseString(char* buffer, char* str) const;
198 
206  bool ParseBool(const char* valueString) const;
207 
215  int FindOption(const char* name, const bool isFatal = false) const;
216 
217 public:
224  static Environment* GetSingleton();
225 
232  static void SetSingleton(Environment* e);
233 
240  static void DeleteSingleton();
241 
248  virtual void PrintUsage(ostream &s) const;
249 
256  virtual void SetStaticOptions();
257 
268  void RegisterOption(const char *name, const OptionType type, const char *abbrev, const char *defValue = NULL);
269 
276  void SetInt(const char *name, const int value);
277 
284  void SetFloat(const char *name, const float value);
285 
292  void SetBool(const char *name, const bool value);
293 
300  void SetString(const char *name, const char *value);
301 
308  bool GetBool(const char *name, const bool isFatal = false) const;
309 
316  int GetInt(const char *name,const bool isFatal = false) const;
317 
324  float GetFloat(const char *name,const bool isFatal = false) const;
325 
332  double GetDouble(const char *name,const bool isFatal = false) const;
333 
341  bool GetIntValue(const char *name, int &value, const bool isFatal = false) const;
342 
350  bool GetDoubleValue(const char *name, double &value, const bool isFatal = false) const;
351 
359  bool GetFloatValue(const char *name, float &value, const bool isFatal = false) const;
360 
368  bool GetBoolValue(const char *name, bool &value, const bool isFatal = false) const;
369 
377  bool GetStringValue(const char *name, char *value, const bool isFatal = false) const;
378 
386  bool GetStringValue(const char *name, string &value, const bool isFatal = false) const;
387 
397  bool CheckForSwitch(const int argc, char **argv, const char swtch) const;
398 
412  void ReadCmdlineParams(const int argc, char **argv, const char *optParams);
413 
420  bool ReadEnvFile(const char *filename);
421 
430  void ParseCmdline(const int argc, char **argv, const int index);
431 
436  int GetParamNum() const { return paramRows; }
437 
450  bool GetParam(const char name, const int index, char *value) const;
451 
457  bool OptionPresent(const char *name) const;
458 
459  static Environment* mEnvironment; //< Singleton pointer to Environment instance
460 
461 public:
463 
471  Environment();
472 
474 
482  virtual ~Environment();
483 };
484 
485 
486  /*bool Parse(const int argc, char **argv, bool useExePath, char* overridePath = NULL, const char* overrideDefault = "default.env");
487 
488  void
489  CodeString(char *buff, int max);
490 
491  void
492  DecodeString(char *buff, int max);
493 
494  void
495  SaveCodedFile(char *filenameText,
496  char *filenameCoded);
497 
498 
499  virtual void RegisterOptions() = 0;*/
500 
501 #endif
friend ostream & operator<<(ostream &s, const Option &o)
Definition: Environment.h:122
#define NULL
Definition: Defs.hpp:39
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
Definition: DLLImports.inl:315
const char * name
Definition: DLLImports.cpp:42
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 GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean GLsizei const GLvoid pointer GLuint GLuint const GLchar name GLenum GLsizei GLenum GLsizei GLsizei height GLenum GLuint renderbuffer GLenum GLenum GLint * params
Definition: DLLImports.inl:373
int argc
Definition: Main.cpp:43
char * defaultValue
Definition: Environment.h:70
char * abbrev
Definition: Environment.h:69
int GetParamNum() const
Definition: Environment.h:436
char * name
Definition: Environment.h:67
Option()
Definition: Environment.h:84
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 GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean GLsizei const GLvoid * pointer
Definition: DLLImports.inl:365
OptionType type
Definition: Environment.h:66
virtual ~Option()
Definition: Environment.h:103
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
Definition: DLLImports.inl:363
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
Definition: DLLImports.inl:84
char ** argv
Definition: Main.cpp:44
void * pointer
Definition: Environment.h:73
char * value
Definition: Environment.h:68
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
Definition: DLLImports.inl:323
char * description
Definition: Environment.h:72
static Environment * mEnvironment
Definition: Environment.h:459
OptionType
Definition: Environment.h:49