KSquare Utilities
Variables.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 
3 #include <stdio.h>
4 #include <string>
5 #include <iostream>
6 #include <fstream>
7 #include <vector>
8 
9 
10 #include "MemoryDebug.h"
11 #include "KKBaseTypes.h"
12 
13 using namespace std;
14 
15 
16 #include "OSservices.h"
17 using namespace KKB;
18 
19 #include "Variables.h"
20 using namespace KKLSC;
21 
22 
24 {
25 }
26 
27 
28 
30 {
31 }
32 
33 
34 KKStr Variables::homeDir = "";
35 
36 
37 void Variables::SetHomeDir (const KKStr& _homeDir)
38 {
39  homeDir = _homeDir;
40 }
41 
42 
43 
45 {
46  if (!homeDir.Empty ())
47  return homeDir;
48 
49  KKStrPtr homeDirEnvVar = osGetEnvVariable ("HomeDir");
50  if (!homeDirEnvVar)
51  {
52  #ifdef WIN32
53  return "C:\\Scs";
54  #else
55  return "~/Scs";
56  #endif
57  }
58  else
59  {
60  KKStr tempHomeDir = *homeDirEnvVar;
61  delete homeDirEnvVar;
62  homeDirEnvVar = NULL;
63  return tempHomeDir;
64  }
65 
66  return homeDir;
67 } /* HomeDir */
68 
69 
70 
72 {
73  KKStr configDir = osAddSlash (osAddSlash (HomeDir ()) + "Configurations");
74  return configDir;
75 }
76 
77 
78 
79 
81 {
82  KKStr scsFilesDefaultDir = osAddSlash (HomeDir ()) + "ScannerFiles";
83  return scsFilesDefaultDir;
84 }
85 
86 
87 
88 kkint32 Variables::LocateEnvStrStart (const KKStr& str)
89 {
90  kkint32 x = 0;
91  kkint32 y = 1;
92  kkint32 len = str.Len ();
93  const char* s = str.Str ();
94 
95  while (y < len)
96  {
97  if (s[y] == 0)
98  return -1;
99 
100  if (s[x] == '$')
101  {
102  if ((s[y] == '(') || (s[y] == '{') || (s[y] == '['))
103  return x;
104  }
105 
106  x++;
107  y++;
108  }
109 
110  return -1;
111 } /* LocateEnvStrStart */
112 
113 
114 
115 
117 {
118  kkint32 x = LocateEnvStrStart (src);
119  if (x < 0)
120  return src;
121 
122  char startChar = src[x + 1];
123  char endChar = ')';
124  if (startChar == '(')
125  endChar = ')';
126 
127  else if (startChar == '{')
128  endChar = '}';
129 
130  else if (startChar == '[')
131  endChar = ']';
132 
133  KKStr str (src);
134 
135  while (x >= 0)
136  {
137  KKStr beforeEnvStr = str.SubStrPart (0, x - 1);
138  str = str.SubStrPart (x + 2);
139  x = str.LocateCharacter (endChar);
140  if (x < 0)
141  return src;
142 
143  KKStr envStrName = str.SubStrPart (0, x - 1);
144  KKStr afterStrName = str.SubStrPart (x + 1);
145 
146  KKStrPtr envStrValue = osGetEnvVariable (envStrName);
147  if (envStrValue == NULL)
148  {
149  if (envStrName.EqualIgnoreCase ("HomeDir"))
150  envStrValue = new KKStr (Variables::HomeDir ());
151  }
152 
153  if (envStrValue == NULL)
154  return src;
155 
156  str = beforeEnvStr + (*envStrValue) + afterStrName;
157  delete envStrValue;
158  x = LocateEnvStrStart (str);
159  }
160 
161  return str;
162 } /* SubstituteInEnvironmentVariables */
Variables that specify where we can locate Camera Application directories and files.
Definition: Variables.h:21
bool EqualIgnoreCase(const char *s2) const
Definition: KKStr.cpp:1257
__int32 kkint32
Definition: KKBaseTypes.h:88
static KKStr HomeDir()
Definition: Variables.cpp:44
static KKStr SubstituteInEnvironmentVariables(const KKStr &src)
Expands the supplied string by substituting in Environment variable values.
Definition: Variables.cpp:116
KKStr operator+(const char *right) const
Definition: KKStr.cpp:3986
KKStr & operator=(KKStr &&src)
Definition: KKStr.cpp:1369
static KKStr ScannerFilesDefaultDir()
Definition: Variables.cpp:80
KKB::KKStr osAddSlash(const KKStr &fileSpec)
kkuint32 Len() const
Returns the number of characters in the string.
Definition: KKStr.h:366
static KKStr ConfigurationDir()
Definition: Variables.cpp:71
KKTHread * KKTHreadPtr
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
bool Empty() const
Definition: KKStr.h:241
KKStr SubStrPart(kkint32 firstChar, kkint32 lastChar) const
returns a SubString consisting of all characters starting at index &#39;firstChar&#39; and ending at &#39;lastInd...
Definition: KKStr.cpp:2802
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
kkint32 LocateCharacter(char ch) const
Returns index of 1st occurrence of &#39;ch&#39; otherwise -1.
Definition: KKStr.cpp:2021
Contains Classes that are specific to Cameras physical characteristics.
static void SetHomeDir(const KKStr &_homeDir)
Definition: Variables.cpp:37
KKStrPtr osGetEnvVariable(const KKStr &_varName)
Definition: OSservices.cpp:897
KKStr operator+(const KKStr &right) const
Definition: KKStr.cpp:3998
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
char operator[](kkint32 i) const
Definition: KKStr.cpp:3413
KKStr & operator=(const KKStr &src)
Definition: KKStr.cpp:1390
KKStr SubStrPart(kkint32 firstChar) const
returns a SubString consisting of all characters starting at index &#39;firstChar&#39; until the end of the s...
Definition: KKStr.cpp:2780