18 #include "precompiled.h"
20 #include <boost/algorithm/string.hpp>
42 return &((*values)[0]);
57 for (
int search_ns = ns; search_ns >= 0; search_ns--)
59 TConfigMap::iterator it =
m_Map[search_ns].find(name);
60 if (it !=
m_Map[search_ns].end())
79 for (
int search_ns = ns; search_ns >= 0; search_ns--)
81 TConfigMap::iterator it =
m_Map[search_ns].find(name);
82 if (it !=
m_Map[search_ns].end())
91 std::map<CStr, CConfigValueSet> ret;
101 for (
int search_ns = 0; search_ns <= ns; search_ns++)
103 for (TConfigMap::iterator it =
m_Map[search_ns].begin(); it !=
m_Map[search_ns].end(); ++it)
105 if (boost::algorithm::starts_with(it->first, prefix))
106 ret[it->first] = it->second;
121 TConfigMap::iterator it =
m_Map[ns].find(name);
122 if (it !=
m_Map[ns].end())
123 return &(it->second[0]);
126 return &(it->second[0]);
151 parser.
InputTaskType(
"Assignment",
"_$ident_=<_[-$arg(_minus)]_$value_,>_[-$arg(_minus)]_$value[[;]$rest]");
155 shared_ptr<u8> buffer;
size_t buflen;
169 LOGERROR(L
"CConfigDB::Reload(): vfs_load for \"%ls\" failed: return was %lld",
m_ConfigFile[ns].
string().c_str(), (
long long)ret);
177 char *filebuf=(
char *)buffer.get();
178 char *filebufend=filebuf+buflen;
181 char *next=filebuf-1;
185 next=(
char *)memchr(pos,
'\n', filebufend-pos);
186 if (!next) next=filebufend;
189 if (lend > filebuf && *(lend-1) ==
'\r') lend--;
192 bool parseOk=parserLine.
ParseString(parser, std::string(pos, lend));
205 newMap[name].clear();
207 for(
size_t t = 0; t < argCount; t++ )
213 newMap[name].push_back( argument );
214 LOGMESSAGE(L
"Loaded config string \"%hs\" = \"%hs\"", name.c_str(), value.c_str());
218 while (next < filebufend);
220 m_Map[ns].swap(newMap);
246 char* pos = (
char*)buf.get();
248 for(TConfigMap::const_iterator it = map.begin(); it != map.end(); ++it)
250 pos += sprintf(pos,
"%s = \"%s\"\n", it->first.c_str(), it->second[0].m_String.c_str());
252 const size_t len = pos - (
char*)buf.get();
257 LOGERROR(L
"CConfigDB::WriteFile(): CreateFile \"%ls\" failed (error: %d)", path.
string().c_str(), (int)ret);
std::vector< CParserValue > CConfigValueSet
std::map< CStr, CConfigValueSet > GetValuesWithPrefix(EConfigNamespace ns, const CStr &prefix)
Retrieve a map of values corresponding to settings whose names begin with the given prefix; will sear...
static const uintptr_t maxSectorSize
static VfsPath m_ConfigFile[]
EConfigNamespace GetValueNamespace(EConfigNamespace ns, const CStr &name)
Returns the namespace that the value returned by GetValues was defined in, or CFG_LAST if it wasn't d...
bool Reload(EConfigNamespace)
Reload the config file associated with the specified config namespace (the last config file path set ...
const String & string() const
bool WriteFile(EConfigNamespace ns, const VfsPath &path)
Write the current state of the specified config namespace to the file specified by 'path'...
std::map< CStr, CConfigValueSet > TConfigMap
i64 Status
Error handling system.
bool ParseString(const CParser &parser, const std::string &line)
CConfigValueSet * GetValues(EConfigNamespace ns, const CStr &name)
Attempt to retrieve a vector of values corresponding to the given setting; will search CFG_COMMAND fi...
bool GetArgString(size_t arg, std::string &ret)
static Status AllocateAligned(shared_ptr< T > &p, size_t size, size_t alignment=cacheLineSize)
size_t GetArgCount() const
CConfigValue * GetValue(EConfigNamespace ns, const CStr &name)
Attempt to find a config variable with the given name; will search CFG_COMMAND first, and then all namespaces from the specified namespace down to system.
static std::map< CStr, CConfigValueSet > m_Map[]
bool InputTaskType(const std::string &strName, const std::string &strSyntax)
void SetConfigFile(EConfigNamespace ns, const VfsPath &path)
Set the path to the config file used to populate the specified namespace Note that this function does...
#define debug_warn(expr)
display the error dialog with the given text.
CConfigValue * CreateValue(EConfigNamespace ns, const CStr &name)
Create a new config value in the specified namespace.