KSquare Utilities
KKLSC::Variables Class Reference

Variables that specify where we can locate Camera Application directories and files. More...

#include <Variables.h>

Public Member Functions

 Variables ()
 
 ~Variables ()
 

Static Public Member Functions

static KKStr ConfigurationDir ()
 
static KKStr HomeDir ()
 
static KKStr ScannerFilesDefaultDir ()
 
static void SetHomeDir (const KKStr &_homeDir)
 
static KKStr SubstituteInEnvironmentVariables (const KKStr &src)
 Expands the supplied string by substituting in Environment variable values. More...
 

Detailed Description

Variables that specify where we can locate Camera Application directories and files.

All methods and applications are to use these variables to locate files and directories that they need. This way all the knowledge or where to locate things is kept in this one class.

Definition at line 21 of file Variables.h.

Constructor & Destructor Documentation

Variables::Variables ( )

Definition at line 23 of file Variables.cpp.

24 {
25 }
Variables::~Variables ( )

Definition at line 29 of file Variables.cpp.

30 {
31 }

Member Function Documentation

KKStr Variables::ConfigurationDir ( )
static

Where application configuration files go; NOT training models.

Definition at line 71 of file Variables.cpp.

References KKB::KKStr::Concat(), HomeDir(), KKB::KKStr::operator+(), and KKB::osAddSlash().

72 {
73  KKStr configDir = osAddSlash (osAddSlash (HomeDir ()) + "Configurations");
74  return configDir;
75 }
static KKStr HomeDir()
Definition: Variables.cpp:44
KKB::KKStr osAddSlash(const KKStr &fileSpec)
KKStr Variables::HomeDir ( )
static

Home Directory. All other directories will be off this directory.

Definition at line 44 of file Variables.cpp.

References KKB::KKStr::Concat(), KKB::KKStr::Empty(), and KKB::osGetEnvVariable().

Referenced by ConfigurationDir(), ScannerFilesDefaultDir(), and SubstituteInEnvironmentVariables().

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 */
bool Empty() const
Definition: KKStr.h:241
KKStrPtr osGetEnvVariable(const KKStr &_varName)
Definition: OSservices.cpp:897
KKStr Variables::ScannerFilesDefaultDir ( )
static

Definition at line 80 of file Variables.cpp.

References KKB::KKStr::Concat(), HomeDir(), KKB::KKStr::operator+(), and KKB::osAddSlash().

81 {
82  KKStr scsFilesDefaultDir = osAddSlash (HomeDir ()) + "ScannerFiles";
83  return scsFilesDefaultDir;
84 }
static KKStr HomeDir()
Definition: Variables.cpp:44
KKB::KKStr osAddSlash(const KKStr &fileSpec)
void Variables::SetHomeDir ( const KKStr _homeDir)
static

Definition at line 37 of file Variables.cpp.

References KKB::KKStr::operator=().

38 {
39  homeDir = _homeDir;
40 }
KKStr Variables::SubstituteInEnvironmentVariables ( const KKStr src)
static

Expands the supplied string by substituting in Environment variable values.

Similar to the 'osSubstituteInEvironmentVariables' method defined in 'osServices' except that if 'HomeDir' is not defined then the string 'c:\Temp' will be used. If a environment variable other than "HomeDir" is not defined then the original string will be returned. ex: '\TrainingLibraries\Shrimp9G' will expand to: 'SCS\TrainingLibraries\Shrimp9G'

Parameters
[in]srcString that is to be search for environment variables and expanded.
Returns
returns the expanded string.

Definition at line 116 of file Variables.cpp.

References KKB::KKStr::Concat(), KKB::KKStr::EqualIgnoreCase(), HomeDir(), KKB::KKStr::KKStr(), KKB::KKStr::LocateCharacter(), KKB::KKStr::operator+(), KKB::KKStr::operator=(), KKB::KKStr::operator[](), KKB::osGetEnvVariable(), and KKB::KKStr::SubStrPart().

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 */
__int32 kkint32
Definition: KKBaseTypes.h:88
static KKStr HomeDir()
Definition: Variables.cpp:44
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
kkint32 LocateCharacter(char ch) const
Returns index of 1st occurrence of &#39;ch&#39; otherwise -1.
Definition: KKStr.cpp:2021
KKStrPtr osGetEnvVariable(const KKStr &_varName)
Definition: OSservices.cpp:897
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

The documentation for this class was generated from the following files: