NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Environment.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Vilem Otte
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 
28 #include "Environment.h"
29 
30 #define strcasecmp _stricmp
31 #define strncasecmp _strnicmp
32 #define MAX_STRING_LEN 65536
33 
35 
43 bool Environment::CheckVariableType(const char* value, const OptionType type) const
44 {
45  char *s, *t, *u;
46 
47  switch(type)
48  {
49  case optInt:
50  // From Minimax - TODO: Check whether works!
51  strtol(value, &t, 10);
52  if(value + strlen(value) != t)
53  return false;
54  else
55  return true;
56  break;
57 
58  case optFloat:
59  // From Minimax - TODO: Check whether works!
60  strtod(value, &t);
61  if(value + strlen(value) != t)
62  return false;
63  else
64  return true;
65  break;
66 
67  case optBool:
68  // If string contains either 'true' or 'false' it's valid
69  if( !strcasecmp(value, "true") ||
70  !strcasecmp(value, "false"))
71  return true;
72  else
73  return false;
74  break;
75 
76  case optString:
77  // String is always a string
78  return true;
79  break;
80  }
81 
82  return false;
83 }
84 
94 char* Environment::ParseString(char* buffer, char* str) const
95 {
96  char *s = buffer;
97  char *t = str + strlen(str);
98 
99  // Skip leading whitespaces
100  while (*s == ' ' || *s == '\t' || *s == '\n' || *s == 0x0d)
101  s++;
102 
103  if (*s == 0)
104  return NULL;
105 
106  while ( (*s >= 'a' && *s <= 'z') ||
107  (*s >= 'A' && *s <= 'Z') ||
108  (*s >= '0' && *s <= '9') ||
109  (*s == '_'))
110  *t++ = *s++;
111 
112  *t = 0;
113 
114  // Skip trailing whitespaces
115  while (*s == ' ' || *s == '\t' || *s == '\n' || *s == 0x0d)
116  s++;
117 
118  return s;
119 }
120 
128 bool Environment::ParseBool(const char* valueString) const
129 {
130  bool value = true;
131 
132  if (!strcasecmp(valueString, "false"))
133  value = false;
134 
135  return value;
136 }
137 
145 int Environment::FindOption(const char* name, const bool isFatal) const
146 {
147  int i;
148  bool found = false;
149 
150  // Is this option registered ?
151  for (i = 0; i < numOptions; i++)
152  {
153  if (!strcmp(options[i].name, name))
154  {
155  found = true;
156  break;
157  }
158  }
159 
160  if (!found)
161  {
162  // No registration found - TODO: Log it!!!
163  //Debug << "Internal error: Required option " << name << " not registered.\n" << flush;
164  exit(1);
165  }
166 
167  if (options[i].value == NULL && options[i].defaultValue == NULL)
168  {
169  // This option was not initialised to some value
170  // TODO: Do the logging
171  if (isFatal)
172  {
173  //Debug << "Error: Required option " << name << " not found.\n" << flush;
174  exit(1);
175  }
176  else
177  {
178  //Debug << "Error: Required option " << name << " not found.\n" << flush;
179  return -1;
180  }
181  }
182 
183  return i;
184 }
185 
193 {
194  mEnvironment = e;
195 }
196 
204 {
205  if (!mEnvironment)
206  {
207  cerr << "Environment not allocated!!";
208  exit(1);
209  }
210 
211  return mEnvironment;
212 }
213 
221 {
222  if(mEnvironment)
223  delete mEnvironment;
224 }
225 
232 void Environment::PrintUsage(ostream &s) const
233 {
234  s << "Registered options:\n";
235  for (int j = 0; j < numOptions; j++)
236  s << options[j] << "\n";
237  s << flush;
238 }
239 
247 {
248  // TODO
249  /*GetFloatValue("Limits.threshold", Limits::Threshold);
250  GetFloatValue("Limits.small", Limits::Small);
251  GetFloatValue("Limits.infinity", Limits::Infinity);*/
252 }
253 
264 void Environment::RegisterOption(const char *name, const OptionType type, const char *abbrev, const char *defValue)
265 {
266  int i;
267 
268  // Make sure this option was not yet registered
269  for (i = 0; i < numOptions; i++)
270  {
271  if (!strcmp(name, options[i].name))
272  {
273  //Debug << "Error: Option " << name << " registered twice.\n";
274  exit(1);
275  }
276  }
277 
278  // Make sure we have enough room in memory
279  if (numOptions >= maxOptions)
280  {
281  //Debug << "Error: Too many options. Try enlarge the maxOptions " << "definition.\n";
282  exit(1);
283  }
284 
285  // Make sure the abbreviation doesn't start with 'D'
286  if (abbrev != NULL && (abbrev[0] == 'D' ))
287  {
288  //Debug << "Internal error: reserved switch " << abbrev << " used as an abbreviation.\n";
289  exit(1);
290  }
291 
292  // new option
293  options[numOptions].type = type;
294  options[numOptions].name = strdup(name);
295 
296  // assign abbreviation, if requested
297  if (abbrev != NULL)
298  {
299  options[numOptions].abbrev = strdup(abbrev);
300  }
301 
302  // assign default value, if requested
303  if (defValue != NULL)
304  {
305  options[numOptions].defaultValue = strdup(defValue);
306  if (!CheckVariableType(defValue, type))
307  {
308  //Debug << "Internal error: Inconsistent type and default value in option " << name << ".\n";
309  exit(1);
310  }
311  }
312 
313  // new option registered
314  numOptions++;
315 }
316 
323 void Environment::SetInt(const char *name, const int value)
324 {
325  int i = FindOption(name);
326 
327  if (i<0)
328  return;
329 
330  if (options[i].type == optInt)
331  {
332  delete [] options[i].value;
333  options[i].value = new char[16];
334  sprintf(options[i].value, "%.15d", value);
335  }
336  else
337  {
338  //Debug << "Internal error: Trying to set non-integer option " << name << " to integral value.\n" << flush;
339  exit(1);
340  }
341 }
342 
349 void Environment::SetFloat(const char *name, const float value)
350 {
351  int i = FindOption(name);
352 
353  if (i<0)
354  return;
355 
356  if (options[i].type == optFloat)
357  {
358  delete [] options[i].value;
359  options[i].value = new char[25];
360  sprintf(options[i].value, "%.15e", value);
361  }
362  else
363  {
364  //Debug << "Internal error: Trying to set non-float option " << name << " to float value.\n" << flush;
365  exit(1);
366  }
367 }
368 
375 void Environment::SetBool(const char *name, const bool value)
376 {
377  int i = FindOption(name);
378 
379  if (i<0)
380  return;
381 
382  if (options[i].type == optBool)
383  {
384  delete [] options[i].value;
385 
386  options[i].value = new char[6];
387 
388  if (value)
389  sprintf(options[i].value, "true");
390  else
391  sprintf(options[i].value, "false");
392  }
393  else
394  {
395  //Debug << "Internal error: Trying to set non-bool option " << name << " to boolean value.\n" << flush;
396  exit(1);
397  }
398 }
399 
406 void Environment::SetString(const char *name, const char *value)
407 {
408  int i = FindOption(name);
409 
410  if (i<0)
411  return;
412 
413  if (options[i].type == optString)
414  {
415  delete [] options[i].value;
416  options[i].value = ::strdup(value);
417  }
418  else
419  {
420  //Debug << "Internal error: Trying to set non-string option " << name << " to string value.\n" << flush;
421  exit(1);
422  }
423 }
424 
431 bool Environment::GetBool(const char *name, const bool isFatal) const
432 {
433  bool ret;
434  if (GetBoolValue(name, ret, isFatal))
435  return ret;
436  else
437  return false;
438 }
439 
446 int Environment::GetInt(const char *name,const bool isFatal) const
447 {
448  int ret;
449  if (GetIntValue(name, ret, isFatal))
450  return ret;
451  else
452  {
453  cerr << "Error: GetInt value not found!";
454  exit(-1);
455  }
456 }
457 
464 float Environment::GetFloat(const char *name, const bool isFatal) const
465 {
466  float ret;
467  if (GetFloatValue(name, ret, isFatal))
468  return ret;
469  else
470  {
471  cerr << "Error: GetFloat value not found!";
472  exit(-1);
473  }
474 }
475 
482 double Environment::GetDouble(const char *name,const bool isFatal) const
483 {
484  double ret;
485  if (GetDoubleValue(name, ret, isFatal))
486  return ret;
487  else
488  {
489  cerr << "Error: GetDouble value not found!";
490  exit(-1);
491  }
492 }
493 
501 bool Environment::GetIntValue(const char *name, int &value, const bool isFatal) const
502 {
503  int i = FindOption(name, isFatal);
504 
505  if (i<0)
506  return false;
507 
508  if (options[i].value != NULL)
509  {
510  value = strtol(options[i].value, NULL, 10);
511  }
512  else
513  {
514  value = strtol(options[i].defaultValue, NULL, 10);
515  }
516 
517  return true;
518 }
519 
527 bool Environment::GetDoubleValue(const char *name, double &value, const bool isFatal) const
528 {
529  int i = FindOption(name, isFatal);
530 
531  if (i<0)
532  return false;
533 
534  if (options[i].value != NULL)
535  {
536  value = strtod(options[i].value, NULL);
537  }
538  else
539  {
540  value = strtod(options[i].defaultValue, NULL);
541  }
542 
543  return true;
544 }
545 
553 bool Environment::GetFloatValue(const char *name, float &value, const bool isFatal) const
554 {
555  int i = FindOption(name, isFatal);
556 
557  if (i<0)
558  return false;
559 
560  if (options[i].value != NULL)
561  {
562  value = (float)strtod(options[i].value, NULL);
563  }
564  else
565  {
566  value = (float)strtod(options[i].defaultValue, NULL);
567  }
568 
569  return true;
570 }
571 
579 bool Environment::GetBoolValue(const char *name, bool &value, const bool isFatal) const
580 {
581  int i = FindOption(name, isFatal);
582 
583  if (i < 0)
584  return false;
585 
586  if (options[i].value != NULL)
587  value = ParseBool(options[i].value);
588  else
589  value = ParseBool(options[i].defaultValue);
590 
591  return true;
592 }
593 
601 bool Environment::GetStringValue(const char *name, char *value, const bool isFatal) const
602 {
603  int i = FindOption(name, isFatal);
604 
605  if (i<0)
606  return false;
607 
608  if (options[i].value != NULL)
609  strcpy(value, options[i].value);
610  else
611  strcpy(value, options[i].defaultValue);
612 
613  return true;
614 }
615 
623 bool Environment::GetStringValue(const char *name, string &value, const bool isFatal) const
624 {
625  char buffer[MAX_STRING_LEN];
626  bool result = GetStringValue(name, buffer, isFatal);
627  if (result)
628  value = buffer;
629  return result;
630 }
631 
641 bool Environment::CheckForSwitch(const int argc, char **argv, const char swtch) const
642 {
643  for (int i = 1; i < argc; i++)
644  if ((argv[i][0] == '-') && (argv[i][1] == swtch))
645  return true;
646  return false;
647 }
648 
662 void Environment::ReadCmdlineParams(const int argc, char **argv, const char *optParams)
663 {
664  int i;
665 
666  // Make sure we are called for the first time
667  if (optionalParams != NULL)
668  return;
669 
670  numParams = (int)strlen(optParams) + 1;
671  optionalParams = new char[numParams];
672  strcpy(optionalParams, optParams);
673 
674  // First, count all non-optional parameters on the command line
675  for (i = 1; i < argc; i++)
676  if (argv[i][0] != '-')
677  paramRows++;
678 
679  // if there is no non-optional parameter add a default one...
680  if (paramRows == 0)
681  paramRows = 1;
682 
683  // allocate and initialize the table for parameters
684  params = new char **[numParams];
685  for (i = 0; i < numParams; i++)
686  {
687  params[i] = new char *[paramRows];
688  for (int j = 0; j < paramRows; j++)
689  params[i][j] = NULL;
690  }
691 
692  // Now read all non-optional and optional parameters into the table
693  curRow = -1;
694  for (i = 1; i < argc; i++)
695  {
696  if (argv[i][0] != '-')
697  {
698  // non-optional parameter encountered
699  curRow++;
700  params[0][curRow] = new char[strlen(argv[i]) + 1];
701  strcpy(params[0][curRow], argv[i]);
702  }
703  else
704  {
705  // option encountered
706  char *t = strchr(optionalParams, argv[i][1]);
707  if (t != NULL)
708  {
709  // this option is optional parameter
710  int index = t - optionalParams + 1;
711  if (curRow < 0)
712  {
713  // it's a global parameter
714  for (int j = 0; j < paramRows; j++)
715  {
716  params[index][j] = new char[strlen(argv[i] + 2) + 1];
717  strcpy(params[index][j], argv[i] + 2);
718  }
719  }
720  else
721  {
722  // it's a scene parameter
723  if (params[index][curRow] != NULL)
724  {
725  delete [] params[index][curRow];
726  }
727  params[index][curRow] = new char[strlen(argv[i] + 2) + 1];
728  strcpy(params[index][curRow], argv[i] + 2);
729  }
730  }
731  }
732  }
733 
734  curRow = 0;
735 }
736 
743 bool Environment::ReadEnvFile(const char *filename)
744 {
745  char buff[MAX_STRING_LEN], name[MAX_STRING_LEN];
746  char *s, *t;
747  int i, line = 0;
748  bool found;
749  // igzstream envStream(envFilename);
750  ifstream envStream(filename);
751 
752  // some error had occured
753  if (envStream.fail())
754  {
755  cerr << "Error: Can't open file " << filename << " for reading (err. " << envStream.rdstate() << ").\n";
756  return false;
757  }
758 
759  name[0] = '\0';
760 
761  // main loop
762  for (;;)
763  {
764  // read in one line
765  envStream.getline(buff, MAX_STRING_LEN-1);
766 
767  if (!envStream)
768  break;
769 
770  line++;
771  // get rid of comments
772  s = strchr(buff, '#');
773  if (s != NULL)
774  *s = '\0';
775 
776  // get one identifier
777  s = ParseString(buff, name);
778 
779  // parse line
780  while (s != NULL)
781  {
782  // it's a group name - make the full name
783  if (*s == '{')
784  {
785  strcat(name, ".");
786  s++;
787  s = ParseString(s, name);
788  continue;
789  }
790 
791  // end of group
792  if (*s == '}')
793  {
794  if (strlen(name) == 0)
795  {
796  cerr << "Error: unpaired } in " << filename << " (line " << line << ").\n";
797  envStream.close();
798  return false;
799  }
800 
801  name[strlen(name) - 1] = '\0';
802  t = strrchr(name, '.');
803 
804  if (t == NULL)
805  name[0] = '\0';
806  else
807  *(t + 1) = '\0';
808 
809  s++;
810  s = ParseString(s, name);
811 
812  continue;
813  }
814 
815  // find variable name in the table
816  found = false;
817  for (i = 0; i < numOptions; i++)
818  {
819  if (!strcmp(name, options[i].name))
820  {
821  found = true;
822  break;
823  }
824  }
825 
826  if (!found)
827  {
828  cerr << "Warning: unknown option " << name << " in environment file " << filename << " (line " << line << ").\n";
829  }
830  else
831  {
832  switch (options[i].type)
833  {
834  case optInt:
835  {
836  strtol(s, &t, 10);
837  if (t == s || (*t != ' ' && *t != '\t' && *t != '\0' && *t != '}'))
838  {
839  cerr << "Error: Mismatch in int variable " << name << " in " << "environment file " << filename << " (line " << line << ").\n";
840  envStream.close();
841  return false;
842  }
843 
844  if (options[i].value != NULL)
845  delete [] options[i].value;
846 
847  options[i].value = new char[t - s + 1];
848  strncpy(options[i].value, s, t - s);
849  options[i].value[t - s] = '\0';
850  s = t;
851  break;
852  }
853 
854  case optFloat:
855  {
856  strtod(s, &t);
857  if (t == s || (*t != ' ' && *t != '\t' && *t != '\0' && *t != '}'))
858  {
859  cerr << "Error: Mismatch in float variable " << name << " in " << "environment file " << filename << " (line " << line << ").\n";
860  envStream.close();
861  return false;
862  }
863 
864  if (options[i].value != NULL)
865  delete [] options[i].value;
866 
867  options[i].value = new char[t - s + 1];
868  strncpy(options[i].value, s, t - s);
869  options[i].value[t - s] = '\0';
870  s = t;
871  break;
872  }
873 
874  case optBool:
875  {
876  t = s;
877  while ( (*t >= 'a' && *t <= 'z') ||
878  (*t >= 'A' && *t <= 'Z') ||
879  *t == '+' || *t == '-')
880  t++;
881 
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 == '}'))
885  {
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';
891  s = t;
892  }
893  else
894  {
895  cerr << "Error: Mismatch in bool variable " << name << " in " << "environment file " << filename << " (line " << line << ").\n";
896  envStream.close();
897  return false;
898  }
899  break;
900  }
901 
902  case optString:
903  {
904  if (options[i].value != NULL)
905  delete [] options[i].value;
906 
907  options[i].value = new char[strlen(s) + 1];
908  strcpy(options[i].value, s);
909  s += strlen(s);
910  int last = strlen(options[i].value)-1;
911 
912  if (options[i].value[last] == 0x0a || options[i].value[last] == 0x0d)
913  options[i].value[last] = 0;
914 
915  break;
916  }
917 
918  default:
919  {
920  //Debug << "Internal error: Unknown type of option.\n" << flush;
921  exit(1);
922  }
923  }
924  }
925 
926  // prepare the variable name for next pass
927  t = strrchr(name, '.');
928 
929  if (t == NULL)
930  name[0] = '\0';
931  else
932  *(t + 1) = '\0';
933 
934  // get next identifier
935  s = ParseString(s, name);
936  }
937  }
938 
939  envStream.close();
940  return true;
941 }
942 
951 void Environment::ParseCmdline(const int argc, char **argv, const int index)
952 {
953  int curIndex = -1;
954 
955  for (int i = 1; i < argc; i++)
956  {
957  // if this parameter is non-optional, skip it and increment the counter
958  if (argv[i][0] != '-')
959  {
960  curIndex++;
961  continue;
962  }
963 
964  // make sure to skip all non-optional parameters
965  char *t = strchr(optionalParams, argv[i][1]);
966  if (t != NULL)
967  continue;
968 
969  // if we are in the scope of the current parameter, parse it
970  if (curIndex == -1 || curIndex == index)
971  {
972  if (argv[i][1] == 'D')
973  {
974  // it's a full name definition
975  bool found = false;
976  int j;
977 
978  char *t = strchr(argv[i] + 2, '=');
979  if (t == NULL)
980  {
981  //Debug << "Error: Missing '=' in option. "<< "Syntax is -D<name>=<value>.\n" << flush;
982  exit(1);
983  }
984 
985  for (j = 0; j < numOptions; j++)
986  {
987  if (!strncmp(options[j].name, argv[i] + 2, t - argv[i] - 2) && (unsigned)(t - argv[i] - 2) == strlen(options[j].name))
988  {
989  found = true;
990  break;
991  }
992  }
993 
994  if (!found)
995  {
996  //Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
997  // exit(1);
998  }
999 
1000  if (found)
1001  {
1002  if (!CheckVariableType(t + 1, options[j].type))
1003  {
1004  //Debug << "Error: invalid type of value " << t + 1 << " in option " << options[j].name << ".\n";
1005  exit(1);
1006  }
1007 
1008  if (options[j].value != NULL)
1009  delete [] options[j].value;
1010 
1011  options[j].value = strdup(t + 1);
1012  }
1013  }
1014  else
1015  {
1016  // it's an abbreviation
1017  bool found = false;
1018  int j;
1019 
1020  for (j = 0; j < numOptions; j++)
1021  {
1022  if (options[j].abbrev != NULL && !strncmp(options[j].abbrev, argv[i] + 1, strlen(options[j].abbrev)))
1023  {
1024  found = true;
1025  break;
1026  }
1027 
1028  if (!found)
1029  {
1030  //Debug << "Warning: Unregistered option " << argv[i] << ".\n" << flush;
1031  // exit(1);
1032  }
1033  if (found)
1034  {
1035  if (!CheckVariableType(argv[i] + 1 + strlen(options[j].abbrev), options[j].type))
1036  {
1037  //Debug << "Error: invalid type of value " << argv[i] + 1 + strlen(options[j].abbrev) << "in option " << options[j].name << ".\n";
1038  exit(1);
1039  }
1040 
1041  if (options[j].value != NULL)
1042  delete [] options[j].value;
1043 
1044  options[j].value = strdup(argv[i] + 1 + strlen(options[j].abbrev));
1045  }
1046  }
1047  }
1048  }
1049  }
1050 }
1051 
1064 bool Environment::GetParam(const char name, const int index, char *value) const
1065 {
1066  int column;
1067 
1068  if (index >= paramRows || index < 0)
1069  return false;
1070 
1071  if (name == ' ')
1072  column = 0;
1073  else
1074  {
1075  char *t = strchr(optionalParams, name);
1076 
1077  if (t == NULL)
1078  return false;
1079 
1080  column = t - optionalParams + 1;
1081  }
1082 
1083  if (params[column][index] == NULL)
1084  return false;
1085 
1086  strcpy(value, params[column][index]);
1087 
1088  return true;
1089 }
1090 
1096 bool Environment::OptionPresent(const char *name) const
1097 {
1098  bool found = false;
1099  int i;
1100 
1101  for (i = 0; i < numOptions; i++)
1102  {
1103  if (!strcmp(options[i].name, name))
1104  {
1105  found = true;
1106  break;
1107  }
1108  }
1109 
1110  if (!found)
1111  {
1112  //Debug << "Internal error: Option " << name << " not registered.\n" << flush;
1113  exit(1);
1114  }
1115 
1116  if (options[i].value != NULL || options[i].defaultValue != NULL)
1117  return true;
1118  else
1119  return false;
1120 }
1121 
1129 {
1130  optionalParams = NULL;
1131  paramRows = 0;
1132  numParams = 0;
1133  params = NULL;
1134  maxOptions = 500;
1135 
1136 
1137  // this is maximal nuber of options.
1138  numOptions = 0;
1139 
1140  options = new Option[maxOptions];
1141 
1142  if (options == NULL )
1143  {
1144  //Debug << "Error: Memory allocation failed.\n";
1145  exit(1);
1146  }
1147 
1148  return;
1149 }
1150 
1158 {
1159  int i, j;
1160 
1161  // delete the params structure
1162  for (i = 0; i < numParams; i++)
1163  {
1164  for (j = 0; j < paramRows; j++)
1165  {
1166  if (params[i][j] != NULL)
1167  delete[] params[i][j];
1168  }
1169 
1170  if (params[i] != NULL)
1171  delete[] params[i];
1172  }
1173 
1174  if (params != NULL)
1175  delete[] params;
1176 
1177  if (options != NULL)
1178  delete [] options;
1179 
1180  if (optionalParams != NULL)
1181  delete optionalParams;
1182 }
#define NULL
Definition: Defs.hpp:39
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
Definition: DLLImports.inl:315
const char * name
Definition: DLLImports.cpp:42
#define strcasecmp
Definition: Environment.cpp:30
int argc
Definition: Main.cpp:43
char * defaultValue
Definition: Environment.h:70
char * abbrev
Definition: Environment.h:69
static void DeleteSingleton()
void ReadCmdlineParams(const int argc, char **argv, const char *optParams)
void SetBool(const char *name, const bool value)
#define MAX_STRING_LEN
Definition: Environment.cpp:32
#define strncasecmp
Definition: Environment.cpp:31
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()
char * name
Definition: Environment.h:67
bool CheckForSwitch(const int argc, char **argv, const char swtch) const
OptionType type
Definition: Environment.h:66
void SetFloat(const char *name, const float value)
void SetString(const char *name, const char *value)
String sprintf(const char *fmt,...)
Definition: Defs.cpp:241
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
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
virtual ~Environment()
char * value
Definition: Environment.h:68
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
Definition: DLLImports.inl:323
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
Definition: Environment.h:459
OptionType
Definition: Environment.h:49