本文整理汇总了C++中CConfigFile::getVarPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ CConfigFile::getVarPtr方法的具体用法?C++ CConfigFile::getVarPtr怎么用?C++ CConfigFile::getVarPtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CConfigFile
的用法示例。
在下文中一共展示了CConfigFile::getVarPtr方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Bool version
bool getVarFromConfigFile(CConfigFile &cf, const string &name, bool &variable, bool defaultValue = false)
{
CConfigFile::CVar *ptr = cf.getVarPtr(name);
bool success;
variable = ((success = (ptr != NULL)) ? (ptr->asInt() != 0) : defaultValue);
return success;
}
示例2: string
// String version
bool getVarFromConfigFile(CConfigFile &cf, const string &name, string &variable, const string &defaultValue = string(""))
{
CConfigFile::CVar *ptr = cf.getVarPtr(name);
bool success;
variable = ((success = (ptr != NULL)) ? ptr->asString() : defaultValue);
return success;
}
示例3: generateSpellList
/** Generate list of spell
*/
static void generateSpellList(CConfigFile &cf, const std::string &sheetName)
{
CConfigFile::CVar *spellList = cf.getVarPtr("spell_list");
if (!spellList)
{
nlwarning("Can't read spell list");
return;
}
COFile f;
if (!f.open(sheetName, false, true))
{
nlwarning("Can't write %s", sheetName.c_str());
return;
}
try
{
COXml xmlStreamOut;
xmlStreamOut.init(&f);
xmlStreamOut.xmlPush("FORM");
IStream &xmlStream = xmlStreamOut;
xmlStream.xmlPush("STRUCT");
xmlStream.xmlPushBegin("ARRAY");
xmlStream.xmlSetAttrib("Name");
std::string name = "List";
xmlStream.serial(name);
xmlStream.xmlPushEnd();
for(uint k = 0; k < (uint) spellList->size(); ++k)
{
std::vector<std::string> result;
NLMISC::splitString(spellList->asString(k), "|", result);
if (result.size() < 2)
{
nlwarning("Should provide at list spell name and id");
}
xmlStream.xmlPush("STRUCT");
writeAtom(xmlStream, "ID", result[1]);
writeAtom(xmlStream, "SheetBaseName", result[0]);
xmlStream.xmlPop();
}
xmlStream.xmlPop(); // STRUCT
xmlStream.xmlPop(); // FORM
}
catch(const EStream &)
{
nlwarning("Cant write %s", sheetName.c_str());
}
}
示例4: main
//****************************************************************************************************************************
int main(int argc, char* argv[])
{
if (argc < 2)
{
nlwarning("Usage : %s config_file_name.cfg", argv[0]);
return -1;
}
CConfigFile cf;
try
{
cf.load(argv[1]);
}
catch(const NLMISC::EConfigFile &)
{
nlwarning("Error in config file %s", argv[1]);
return -1;
}
catch(...)
{
nlwarning("Can't read config file %s", argv[1]);
return -1;
}
// output for sheets
std::string outputPath;
CConfigFile::CVar *outputPathVar = cf.getVarPtr("output_path");
if (outputPathVar)
{
outputPath = outputPathVar->asString() + "/";
}
// output for 'levels' parents
std::string levelParentsPath;
CConfigFile::CVar *levelParentsPathVar = cf.getVarPtr("level_parents");
if (levelParentsPathVar)
{
levelParentsPath = levelParentsPathVar->asString() + "/";
}
// output for projectile parents
std::string projectileParentsPath;
CConfigFile::CVar *projectileParentsPathVar = cf.getVarPtr("projectile_base");
if (projectileParentsPathVar)
{
projectileParentsPath= projectileParentsPathVar->asString() + "/";
}
// output for 'projectile by level and mode' parents
std::string projectileByLevelAndModeParentsPath;
CConfigFile::CVar *projectileByLevelAndModeParentsPathVar = cf.getVarPtr("projectile_by_level_and_mode_parents");
if (projectileByLevelAndModeParentsPathVar)
{
projectileByLevelAndModeParentsPath = projectileByLevelAndModeParentsPathVar->asString() + "/";
}
// output for 'base spells' parents
std::string baseSpellPath;
CConfigFile::CVar *baseSpellPathVar = cf.getVarPtr("spell_base");
if (baseSpellPathVar)
{
baseSpellPath = baseSpellPathVar->asString() + "/";
}
// output for 'spell by levels' parents
std::string spellByLevelParentsPath;
CConfigFile::CVar *spellByLevelParentsPathVar = cf.getVarPtr("spell_by_level_parents");
if (spellByLevelParentsPathVar)
{
spellByLevelParentsPath = spellByLevelParentsPathVar->asString() + "/";
}
// output for 'final spell'
std::string finalSpellPath;
CConfigFile::CVar *finalSpellPathVar = cf.getVarPtr("final_spells");
if (finalSpellPathVar)
{
finalSpellPath = finalSpellPathVar->asString() + "/";
}
// read number of levels
CConfigFile::CVar *numLevelVar = cf.getVarPtr("num_levels");
if (!numLevelVar)
{
nlwarning("Can't read number of spell levels");
return -1;
}
uint numSpellLevels = numLevelVar->asInt();
std::vector<CUserParams> userParams(numSpellLevels);
// read user params set for each level
for(uint level = 0; level < numSpellLevels; ++level)
{
std::string varName = toString("user_params_level%d", (int) (level + 1));
CConfigFile::CVar *up = cf.getVarPtr(varName);
if (!up)
{
nlwarning("Can't read var %s", varName.c_str());
}
else
{
for(uint k = 0; k < CUserParams::NumUserParams; ++k)
{
userParams[level].UserParam[k] = up->asString(k);
//.........这里部分代码省略.........
示例5: init
/* Load the config file and the related words files. Return false in case of failure.
* Config file variables:
* - WordsPath: where to find <filter>_words_<languageCode>.txt
* - LanguageCode: language code (ex: en for English)
* - Utf8: results are in UTF8, otherwise in ANSI string
* - Filter: "*" for all files (default) or a name (ex: "item").
* - AdditionalFiles/AdditionalFileColumnTitles
*/
bool CWordsDictionary::init( const string& configFileName )
{
// Read config file
bool cfFound = false;
CConfigFile cf;
try
{
cf.load( configFileName );
cfFound = true;
}
catch ( EConfigFile& e )
{
nlwarning( "WD: %s", e.what() );
}
string wordsPath, languageCode, filter = "*";
vector<string> additionalFiles, additionalFileColumnTitles;
bool filterAll = true, utf8 = false;
if ( cfFound )
{
CConfigFile::CVar *v = cf.getVarPtr( "WordsPath" );
if ( v )
{
wordsPath = v->asString();
/*if ( (!wordsPath.empty()) && (wordsPath[wordsPath.size()-1]!='/') )
wordsPath += '/';*/
}
v = cf.getVarPtr( "LanguageCode" );
if ( v )
languageCode = v->asString();
v = cf.getVarPtr( "Utf8" );
if ( v )
utf8 = (v->asInt() == 1);
v = cf.getVarPtr( "Filter" );
if ( v )
{
filter = v->asString();
filterAll = (filter == "*");
}
v = cf.getVarPtr( "AdditionalFiles" );
if ( v )
{
for ( uint i=0; i!=v->size(); ++i )
additionalFiles.push_back( v->asString( i ) );
v = cf.getVarPtr( "AdditionalFileColumnTitles" );
if ( v->size() != additionalFiles.size() )
{
nlwarning( "AdditionalFiles and AdditionalFileColumnTitles have different size, ignoring second one" );
additionalFileColumnTitles.resize( v->size(), DefaultColTitle );
}
else
{
for ( uint i=0; i!=v->size(); ++i )
additionalFileColumnTitles.push_back( v->asString( i ) );
}
}
}
if ( languageCode.empty() )
languageCode = "en";
// Load all found words files
const string ext = ".txt";
vector<string> fileList;
CPath::getPathContent( wordsPath, false, false, true, fileList );
for ( vector<string>::const_iterator ifl=fileList.begin(); ifl!=fileList.end(); ++ifl )
{
const string& filename = (*ifl);
string::size_type p = string::npos;
bool isAdditionalFile = false;
// Test if filename is in additional file list
uint iAdditionalFile;
for ( iAdditionalFile=0; iAdditionalFile!=additionalFiles.size(); ++iAdditionalFile )
{
if ( (p = filename.find( additionalFiles[iAdditionalFile] )) != string::npos )
{
isAdditionalFile = true;
break;
}
}
// Or test if filename is a words_*.txt file
string pattern = string("_words_") + languageCode + ext;
if ( isAdditionalFile ||
((p = filename.find( pattern )) != string::npos) )
{
// Skip if a filter is specified and does not match the current file
if ( (!filterAll) && (filename.find( filter+pattern ) == string::npos) )
continue;
// Load file
nldebug( "WD: Loading %s", filename.c_str() );
//.........这里部分代码省略.........
示例6: if
/*
* CSV -> Georges
*/
void convertCsvFile( const string &file, bool generate, const string& sheetType )
{
const uint BUFFER_SIZE = 16*1024;
char lineBuffer[BUFFER_SIZE];
FILE *s;
vector<string> fields;
vector<string> args;
if ((s = fopen(file.c_str(), "r")) == NULL)
{
fprintf(stderr, "Can't find file %s to convert\n", file.c_str());
return;
}
loadSheetPath();
UFormLoader *formLoader = UFormLoader::createLoader ();
NLMISC::CSmartPtr<CForm> form;
NLMISC::CSmartPtr<UFormDfn> formDfn;
fgets(lineBuffer, BUFFER_SIZE, s);
explode(std::string(lineBuffer), std::string(SEPARATOR), fields);
vector<bool> activeFields( fields.size(), true );
// Load DFN (generation only)
set<CDfnField> dfnFields;
if ( generate )
{
formDfn = formLoader->loadFormDfn( (sheetType + ".dfn").c_str() );
if ( ! formDfn )
nlerror( "Can't find DFN for %s", sheetType.c_str() );
fillFromDFN( formLoader, dfnFields, formDfn, "", sheetType );
// Display missing fields and check fields against DFN
uint i;
for ( i=1; i!=fields.size(); ++i )
{
eraseCarriageReturnsAndMakeBlankNonAsciiChars( fields[i] );
if ( fields[i].empty() )
{
nlinfo( "Skipping field #%u (empty)", i );
activeFields[i] = false;
}
else if ( nlstricmp( fields[i], "parent" ) == 0 )
{
strlwr( fields[i] ); // non-const version
}
else
{
set<CDfnField>::iterator ist = dfnFields.find( CDfnField(fields[i]) );
if ( ist == dfnFields.end() )
{
nlinfo( "Skipping field #%u (%s, not found in %s DFN)", i, fields[i].c_str(), sheetType.c_str() );
activeFields[i] = false;
}
}
}
for ( i=1; i!=fields.size(); ++i )
{
if ( activeFields[i] )
nlinfo( "Selected field: %s", fields[i].c_str() );
}
}
string addExtension = "." + sheetType;
uint dirmapLetterIndex = ~0;
bool dirmapLetterBackward = false;
vector<string> dirmapDirs;
string dirmapSheetCode;
bool WriteEmptyProperties = false, WriteSheetsToDisk = true;
bool ForceInsertParents = false;
if ( generate )
{
// Get the directory mapping
try
{
CConfigFile dirmapcfg;
dirmapcfg.load( sheetType + "_dirmap.cfg" );
if ( OutputPath.empty() )
{
CConfigFile::CVar *path = dirmapcfg.getVarPtr( "OutputPath" );
if ( path )
OutputPath = path->asString();
if ( ! OutputPath.empty() )
{
if ( OutputPath[OutputPath.size()-1] != '/' )
OutputPath += '/';
else if ( ! CFile::isDirectory( OutputPath ) )
nlwarning( "Output path does not exist" );
}
}
//.........这里部分代码省略.........