23 #include "usThreads_p.h"
24 #include "usStaticInit_p.h"
36 std::string RemoveTrailingPathSeparator(
const std::string&
in)
38 #ifdef US_PLATFORM_WINDOWS
39 const char separator =
'\\';
41 const char separator =
'/';
43 if (in.empty())
return in;
44 std::string::const_iterator lastChar = --in.end();
45 while (lastChar != in.begin() && std::isspace(*lastChar)) lastChar--;
46 if (*lastChar != separator) lastChar++;
47 std::string::const_iterator firstChar = in.begin();
48 while (firstChar < lastChar && std::isspace(*firstChar)) firstChar++;
49 return std::string(firstChar, lastChar);
54 std::string ModuleSettings::CURRENT_MODULE_PATH()
56 static const std::string var =
"us_current_module_path";
60 struct ModuleSettingsPrivate :
public MultiThreaded<>
62 ModuleSettingsPrivate()
64 #ifdef US_ENABLE_AUTOLOADING_SUPPORT
65 , autoLoadingEnabled(true)
67 , autoLoadingEnabled(false)
69 , autoLoadingDisabled(false)
72 autoLoadPaths.insert(ModuleSettings::CURRENT_MODULE_PATH());
74 char* envPaths = getenv(
"US_AUTOLOAD_PATHS");
77 std::stringstream ss(envPaths);
79 #ifdef US_PLATFORM_WINDOWS
80 const char separator =
';';
82 const char separator =
':';
84 while (std::getline(ss, envPath, separator))
86 std::string normalizedEnvPath = RemoveTrailingPathSeparator(envPath);
87 if (!normalizedEnvPath.empty())
89 extraPaths.insert(normalizedEnvPath);
94 if (getenv(
"US_DISABLE_AUTOLOADING"))
96 autoLoadingDisabled =
true;
100 std::set<std::string> autoLoadPaths;
101 std::set<std::string> extraPaths;
102 bool autoLoadingEnabled;
103 bool autoLoadingDisabled;
104 std::string storagePath;
108 US_GLOBAL_STATIC(ModuleSettingsPrivate, moduleSettingsPrivate)
112 #ifdef US_ENABLE_THREADING_SUPPORT
119 bool ModuleSettings::IsAutoLoadingEnabled()
121 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
122 #ifdef US_ENABLE_AUTOLOADING_SUPPORT
123 return !moduleSettingsPrivate()->autoLoadingDisabled &&
124 moduleSettingsPrivate()->autoLoadingEnabled;
130 void ModuleSettings::SetAutoLoadingEnabled(
bool enable)
132 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
133 moduleSettingsPrivate()->autoLoadingEnabled = enable;
138 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
140 moduleSettingsPrivate()->autoLoadPaths.end());
141 paths.insert(paths.end(), moduleSettingsPrivate()->extraPaths.begin(),
142 moduleSettingsPrivate()->extraPaths.end());
143 std::sort(paths.begin(), paths.end());
144 paths.erase(std::unique(paths.begin(), paths.end()), paths.end());
148 void ModuleSettings::SetAutoLoadPaths(
const PathList& paths)
151 normalizedPaths.resize(paths.size());
152 std::transform(paths.begin(), paths.end(), normalizedPaths.begin(), RemoveTrailingPathSeparator);
154 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
155 moduleSettingsPrivate()->autoLoadPaths.clear();
156 moduleSettingsPrivate()->autoLoadPaths.insert(normalizedPaths.begin(), normalizedPaths.end());
159 void ModuleSettings::AddAutoLoadPath(
const std::string& path)
161 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
162 moduleSettingsPrivate()->autoLoadPaths.insert(RemoveTrailingPathSeparator(path));
165 void ModuleSettings::SetStoragePath(
const std::string &path)
167 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
168 moduleSettingsPrivate()->storagePath = RemoveTrailingPathSeparator(path);
171 std::string ModuleSettings::GetStoragePath()
173 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
174 return moduleSettingsPrivate()->storagePath;
177 void ModuleSettings::SetLogLevel(MsgType level)
179 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
180 moduleSettingsPrivate()->logLevel = level;
183 MsgType ModuleSettings::GetLogLevel()
185 US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
186 return moduleSettingsPrivate()->logLevel;
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
std::vector< std::string > PathList