本文整理汇总了C++中ConfigVar类的典型用法代码示例。如果您正苦于以下问题:C++ ConfigVar类的具体用法?C++ ConfigVar怎么用?C++ ConfigVar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigVar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memset
// read the entire file into a ConfigVar instance and then use that to decode
// into mapped variables.
bool ConfigReader::load(const char *fileName) {
struct stat stbuf;
memset(&stbuf, 0, sizeof(struct stat));
if (lstat(fileName, &stbuf) != 0) return false;
int size = stbuf.st_size;
int fd = open(fileName, O_RDONLY);
if (fd < 0) return false;
char *buf = new char[size];
int res = ::read(fd, buf, size);
close(fd);
if (res != size) {
RLOG(WARNING) << "Partial read of config file, expecting " << size
<< " bytes, got " << res;
delete[] buf;
return false;
}
ConfigVar in;
in.write((unsigned char *)buf, size);
delete[] buf;
return loadFromVar(in);
}
示例2: memset
// read the entire file into a ConfigVar instance and then use that to decode
// into mapped variables.
bool ConfigReader::load(const char *fileName) {
struct stat_st stbuf;
memset(&stbuf, 0, sizeof(struct stat_st));
if (unix::lstat(fileName, &stbuf) != 0) return false;
int size = stbuf.st_size;
int fd = unix::open(fileName, O_RDONLY);
if (fd < 0) return false;
char *buf = new char[size];
int res = ::_read(fd, buf, size);
close(fd);
if (res != size) {
rWarning("Partial read of config file, expecting %i bytes, got %i", size,
res);
delete[] buf;
return false;
}
ConfigVar in;
in.write((unsigned char *)buf, size);
delete[] buf;
return loadFromVar(in);
}
示例3: fopen
bool Config::Init(const char* filename_)
{
FILE* fp;
char buffer[1024];
char token[1024];
char name[1024];
char* p;
int nline;
ConfigVar* var;
filename = filename_;
fp = fopen(filename, "r");
if (!fp)
return false;
nline = 0;
while (fgets(buffer, sizeof(buffer) - 1, fp))
{
buffer[sizeof(buffer) - 1] = '\0';
nline++;
p = ParseToken(buffer, token, sizeof(token));
if (!p)
{
// empty or commented line
continue;
}
strncpy(name, token, strlen(token));
name[strlen(token)] = '\0';
p = ParseToken(p, token, sizeof(token));
if (!p || token[0] != '=')
{
// syntax error
Log_Message("syntax error at %s, line %d", filename, nline);
fclose(fp);
return false;
}
var = new ConfigVar(name);
vars.Enqueue(var);
while (true)
{
p = ParseToken(p, token, sizeof(token));
if (!p)
break;
if (token[0] == ',')
continue;
var->Append(token);
}
}
fclose(fp);
return true;
}
示例4: GetListValue
const char* Config::GetListValue(const char* name, int num, const char* defval)
{
ConfigVar* var;
var = GetVar(name);
if (!var)
return defval;
return var->GetListValue(num, defval);
}
示例5: GetVar
int64_t Config::GetInt64Value(const char* name, int64_t defval)
{
ConfigVar* var;
var = GetVar(name);
if (!var)
return defval;
return var->GetInt64Value(defval);
}
示例6: GetBoolValue
bool Config::GetBoolValue(const char* name, bool defval)
{
ConfigVar* var;
var = GetVar(name);
if (!var)
return defval;
return var->GetBoolValue(defval);
}
示例7: GetListNum
int Config::GetListNum(const char* name)
{
ConfigVar* var;
var = GetVar(name);
if (!var)
return 0;
return var->GetListNum();
}
示例8: dm_plugin_load
// take in a DM plugin configuration file, find the DMPlugin descendent matching the value of plugname, and store its class factory funcs for later use
DMPlugin* dm_plugin_load(const char *pluginConfigPath)
{
ConfigVar cv;
if (cv.readVar(pluginConfigPath, "=") > 0) {
if (!is_daemonised) {
std::cerr << "Unable to load plugin config: " << pluginConfigPath << std::endl;
}
syslog(LOG_ERR, "Unable to load plugin config %s", pluginConfigPath);
return NULL;
}
String plugname(cv["plugname"]);
if (plugname.length() < 1) {
if (!is_daemonised) {
std::cerr << "Unable read plugin config plugname variable: " << pluginConfigPath << std::endl;
}
syslog(LOG_ERR, "Unable read plugin config plugname variable %s", pluginConfigPath);
return NULL;
}
if (plugname == "default") {
#ifdef DGDEBUG
std::cout << "Enabling default DM plugin" << std::endl;
#endif
return defaultdmcreate(cv);
}
#ifdef ENABLE_FANCYDM
if (plugname == "fancy") {
#ifdef DGDEBUG
std::cout << "Enabling fancy DM plugin" << std::endl;
#endif
return fancydmcreate(cv);
}
#endif
#ifdef ENABLE_TRICKLEDM
if (plugname == "trickle") {
#ifdef DGDEBUG
std::cout << "Enabling trickle DM plugin" << std::endl;
#endif
return trickledmcreate(cv);
}
#endif
if (!is_daemonised) {
std::cerr << "Unable to load plugin: " << plugname << std::endl;
}
syslog(LOG_ERR, "Unable to load plugin %s", plugname.toCharArray());
return NULL;
}
示例9: prefs_set_config_val_real
void prefs_set_config_val_real (char *key, char *value, gboolean callback)
{
ConfigVar *entry = prefs_config_vars;
while (entry->key)
{
if (strcasecmp (entry->key, key) == 0)
{
// NOTE: here the old value should not be freed because it is static
entry->cur_val = g_strdup (value);
if (callback && entry->callback)
entry->callback (key, value);
return;
}
entry++;
}
fprintf (stderr, "Warning: invalid key %s in config file\n", key);
}
示例10: toVar
bool ConfigReader::save(const char *fileName) const {
// write everything to a ConfigVar, then output to disk
ConfigVar out = toVar();
int fd = unix::open(fileName, O_RDWR | O_CREAT, 0640);
if (fd >= 0) {
int retVal = ::write(fd, out.buffer(), out.size());
close(fd);
if (retVal != out.size()) {
rError("Error writing to config file %s", fileName);
return false;
}
} else {
rError("Unable to open or create file %s", fileName);
return false;
}
return true;
}
示例11: rError
bool ConfigReader::loadFromVar(ConfigVar &in) {
in.resetOffset();
// parse.
int numEntries = in.readInt();
for (int i = 0; i < numEntries; ++i) {
string key, value;
in >> key >> value;
if (key.length() == 0) {
rError("Invalid key encoding in buffer");
return false;
}
ConfigVar newVar(value);
vars.insert(make_pair(key, newVar));
}
return true;
}
示例12: Save
bool Config::Save()
{
FILE* fp;
ConfigVar* var;
fp = fopen(filename, "w");
if (!fp)
return false;
fprintf(fp, "# Automatically generated configuration file. DO NOT EDIT!\n\n");
for (var = vars.First(); var != NULL; var = var->next)
{
fprintf(fp, "%s = \"%s", var->name.GetBuffer(), var->GetListValue(0, ""));
for (int i = 1; i < var->numelem; i++)
fprintf(fp, "\",\"%s", var->GetListValue(i, ""));
fprintf(fp, "\"\n");
}
fclose(fp);
return true;
}
示例13:
//------------------------------------------------------------------------------
void
Background2D::renderQueueEnded( Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation )
{
if( cv_show_background2d.GetB() == false )
{
return;
}
if( queueGroupId == Ogre::RENDER_QUEUE_MAIN )
{
m_RenderSystem->_setWorldMatrix( Ogre::Matrix4::IDENTITY );
m_RenderSystem->_setProjectionMatrix( Ogre::Matrix4::IDENTITY );
Ogre::Viewport *viewport( CameraManager::getSingleton().getViewport() );
float width = viewport->getActualWidth();
float height = viewport->getActualHeight();
Ogre::Matrix4 view;
view.makeTrans( Ogre::Vector3( m_PositionReal.x * 2 / width, -m_PositionReal.y * 2 / height, 0 ) );
m_RenderSystem->_setViewMatrix( view );
if( m_AlphaRenderOp.vertexData->vertexCount != 0 )
{
m_SceneManager->_setPass( m_AlphaMaterial->getTechnique( 0 )->getPass( 0 ), true, false );
m_RenderSystem->_render( m_AlphaRenderOp );
}
if( m_AddRenderOp.vertexData->vertexCount != 0 )
{
m_SceneManager->_setPass( m_AddMaterial->getTechnique( 0 )->getPass( 0 ), true, false );
m_RenderSystem->_render( m_AddRenderOp );
}
}
}
示例14: test
static bool
runTest(TestListener *listener, const std::string &suite,
const std::string &testName, TestDg test)
{
if (listener)
listener->testStarted(suite, testName);
bool protect = !isDebuggerAttached();
protect = protect || g_protect->val();
if (protect) {
try {
test();
if (listener)
listener->testComplete(suite, testName);
} catch (const Assertion &assertion) {
if (listener)
listener->testAsserted(suite, testName, assertion);
return false;
} catch (...) {
if (listener)
listener->testException(suite, testName);
return false;
}
} else {
test();
if (listener)
listener->testComplete(suite, testName);
}
return true;
}
示例15: if
//------------------------------------------------------------------------------
void
Background2D::InputDebug( const Event& event )
{
if( cv_background2d_manual.GetB() == true )
{
if( event.type == ET_KEY_IMPULSE && event.param1 == OIS::KC_W )
{
m_PositionReal.y += 2;
}
else if( event.type == ET_KEY_IMPULSE && event.param1 == OIS::KC_A )
{
m_PositionReal.x += 2;
}
else if( event.type == ET_KEY_IMPULSE && event.param1 == OIS::KC_S )
{
m_PositionReal.y -= 2;
}
else if( event.type == ET_KEY_IMPULSE && event.param1 == OIS::KC_D )
{
m_PositionReal.x -= 2;
}
CameraManager::getSingleton().Set2DScroll( m_PositionReal );
}
}