本文整理汇总了C++中StringMap::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ StringMap::clear方法的具体用法?C++ StringMap::clear怎么用?C++ StringMap::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringMap
的用法示例。
在下文中一共展示了StringMap::clear方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cacheAllFontNames
int Font::cacheAllFontNames()
{
nameFileMap.clear();
fileNameMap.clear();
Array<String> fontFiles;
Array<String> fontNames;
enumFontFilesAndNames(Adder<Array<String>, String>(fontFiles), Adder<Array<String>, String>(fontNames));
int count = fontFiles.getCount();
BL_ASSERT(count == fontNames.getCount());
for (int i = 0; i < count; ++i)
{
BaseLib::Console::trace << fontNames[i] << ": " << fontFiles[i] << BaseLib::Streams::newLine;
nameFileMap[fontNames[i]] = fontFiles[i];
fileNameMap[fontFiles[i]] = fontNames[i];
}
return count;
}
示例2: getFileInfo
void Directory::getFileInfo(StringMap &map) const
{
// Note: fileInfo must not contain path
map.clear();
map["name"] = fileName();
map["time"] << fileTime();
if(fileIsDir()) map["type"] = "directory";
else {
map["type"] = "file";
map["size"] << fileSize();
}
}
示例3: findSubstringInChunk
void findSubstringInChunk(string S, int startPos, int wordLength, int wordNum, StringMap &Lmap, vector<int> &result) {
int start = startPos;
int strLength = (int)S.length();
StringMap candidate;
int wordCount = 0;
while (start + wordLength <= strLength) {
// we can safely try S[start...start + wordLength - 1]
string word = S.substr(start, wordLength);
// compare word with every element in L
auto findWord = Lmap.find(word);
if (findWord == Lmap.end()) {
candidate.clear();
wordCount = 0;
} else {
// insert this word into the candidate
auto it = candidate.find(word);
if (it == candidate.end()) {
candidate[word] = 1;
} else {
candidate[word]++;
}
wordCount++;
if (wordCount == wordNum) {
// test whether candidate is the same as Lmap
if (compareStringMap(candidate, Lmap)) {
// we have found one!
result.push_back(start - (wordNum - 1) * wordLength);
}
// remove the first word in the candidate
word = S.substr(start - (wordNum - 1) * wordLength, wordLength);
candidate[word]--;
if (candidate[word] == 0) {
// remove this item
candidate.erase(word);
}
wordCount--;
}
}
start += wordLength;
}
}
示例4: StringTable
StringTable()
{
m_map.clear();
m_vec.clear();
m_invalid = "invalid-string";
}
示例5: main
//.........这里部分代码省略.........
}
ScanFile(argv[i], ext, false, verbose);
}
/* Default output file is Makefile */
if (filename == NULL) filename = strdup("Makefile");
/* Default delimiter string */
if (delimiter == NULL) delimiter = strdup("# DO NOT DELETE");
char backup[PATH_MAX];
strcpy(backup, filename);
strcat(backup, ".bak");
char *content = NULL;
long size = 0;
/* Read in the current file; so we can overwrite everything from the
* end of non-depend data marker down till the end. */
FILE *src = fopen(filename, "rb");
if (src != NULL) {
fseek(src, 0, SEEK_END);
size = ftell(src);
rewind(src);
content = (char*)malloc(size * sizeof(*content));
if (fread(content, 1, size, src) != (size_t)size) {
fprintf(stderr, "Could not read %s\n", filename);
exit(-2);
}
fclose(src);
}
FILE *dst = fopen(filename, "w");
bool found_delimiter = false;
if (size != 0) {
src = fopen(backup, "wb");
if (fwrite(content, 1, size, src) != (size_t)size) {
fprintf(stderr, "Could not write %s\n", filename);
exit(-2);
}
fclose(src);
/* Then append it to the real file. */
src = fopen(backup, "rb");
while (fgets(content, size, src) != NULL) {
fputs(content, dst);
if (!strncmp(content, delimiter, strlen(delimiter))) found_delimiter = true;
if (!append && found_delimiter) break;
}
fclose(src);
}
if (!found_delimiter) fprintf(dst, "\n%s\n", delimiter);
for (StringMap::iterator it = _files.begin(); it != _files.end(); it++) {
for (StringSet::iterator h = it->second->begin(); h != it->second->end(); h++) {
fprintf(dst, "%s: %s\n", it->first, *h);
}
}
/* Clean up our mess. */
fclose(dst);
free(delimiter);
free(filename);
free(ext);
free(content);
for (StringMap::iterator it = _files.begin(); it != _files.end(); it++) {
for (StringSet::iterator h = it->second->begin(); h != it->second->end(); h++) {
free(*h);
}
it->second->clear();
delete it->second;
free(it->first);
}
_files.clear();
for (StringMap::iterator it = _headers.begin(); it != _headers.end(); it++) {
for (StringSet::iterator h = it->second->begin(); h != it->second->end(); h++) {
free(*h);
}
it->second->clear();
delete it->second;
free(it->first);
}
_headers.clear();
for (StringSet::iterator it = _defines.begin(); it != _defines.end(); it++) {
free(*it);
}
_defines.clear();
for (StringSet::iterator it = _include_dirs.begin(); it != _include_dirs.end(); it++) {
free(*it);
}
_include_dirs.clear();
return 0;
}
示例6: main
int main (int argc, char *argv[]) {
if(argc < 2) {
ERR("usage: \n" << argv[0] << " <file.osm/.osm.bz2/.osm.pbf> [<profile.lua>]");
}
/*** Setup Scripting Environment ***/
ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua"), argv[1]);
unsigned numberOfThreads = omp_get_num_procs();
if(testDataFile("extractor.ini")) {
ExtractorConfiguration extractorConfig("extractor.ini");
unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads"));
if( rawNumber != 0 && rawNumber <= numberOfThreads)
numberOfThreads = rawNumber;
}
omp_set_num_threads(numberOfThreads);
INFO("extracting data from input file " << argv[1]);
bool isPBF(false);
std::string outputFileName(argv[1]);
std::string restrictionsFileName(argv[1]);
std::string::size_type pos = outputFileName.find(".osm.bz2");
if(pos==std::string::npos) {
pos = outputFileName.find(".osm.pbf");
if(pos!=std::string::npos) {
isPBF = true;
}
}
if(pos!=string::npos) {
outputFileName.replace(pos, 8, ".osrm");
restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
} else {
pos=outputFileName.find(".osm");
if(pos!=string::npos) {
outputFileName.replace(pos, 5, ".osrm");
restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
} else {
outputFileName.append(".osrm");
restrictionsFileName.append(".osrm.restrictions");
}
}
unsigned amountOfRAM = 1;
unsigned installedRAM = GetPhysicalmemory();
if(installedRAM < 2048264) {
WARN("Machine has less than 2GB RAM.");
}
StringMap stringMap;
ExtractionContainers externalMemory;
stringMap[""] = 0;
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
BaseParser<ExtractorCallbacks, _Node, _RawRestrictionContainer, _Way> * parser;
if(isPBF) {
parser = new PBFParser(argv[1]);
} else {
parser = new XMLParser(argv[1]);
}
parser->RegisterCallbacks(extractCallBacks);
parser->RegisterScriptingEnvironment(scriptingEnvironment);
if(!parser->Init())
ERR("Parser not initialized!");
double time = get_timestamp();
parser->Parse();
INFO("parsing finished after " << get_timestamp() - time << " seconds");
externalMemory.PrepareData(outputFileName, restrictionsFileName, amountOfRAM, scriptingEnvironment.luaStateVector[0]);
stringMap.clear();
delete parser;
delete extractCallBacks;
INFO("finished");
std::cout << "\nRun:\n"
"./osrm-prepare " << outputFileName << " " << restrictionsFileName << std::endl;
return 0;
}
示例7: main
//.........这里部分代码省略.........
];
if(0 != luaL_dostring(
myLuaState,
"print('Initializing LUA engine')\n"
)) {
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
}
luabind::module(myLuaState) [
luabind::class_<HashTable<std::string, std::string> >("keyVals")
.def("Add", &HashTable<std::string, std::string>::Add)
.def("Find", &HashTable<std::string, std::string>::Find)
];
luabind::module(myLuaState) [
luabind::class_<ImportNode>("Node")
.def(luabind::constructor<>())
.def_readwrite("lat", &ImportNode::lat)
.def_readwrite("lon", &ImportNode::lon)
.def_readwrite("id", &ImportNode::id)
.def_readwrite("bollard", &ImportNode::bollard)
.def_readwrite("traffic_light", &ImportNode::trafficLight)
.def_readwrite("tags", &ImportNode::keyVals)
];
luabind::module(myLuaState) [
luabind::class_<_Way>("Way")
.def(luabind::constructor<>())
.def_readwrite("name", &_Way::name)
.def_readwrite("speed", &_Way::speed)
.def_readwrite("type", &_Way::type)
.def_readwrite("access", &_Way::access)
.def_readwrite("roundabout", &_Way::roundabout)
.def_readwrite("is_duration_set", &_Way::isDurationSet)
.def_readwrite("is_access_restricted", &_Way::isAccessRestricted)
.def_readwrite("ignore_in_grid", &_Way::ignoreInGrid)
.def_readwrite("tags", &_Way::keyVals)
.def_readwrite("direction", &_Way::direction)
.enum_("constants")
[
luabind::value("notSure", 0),
luabind::value("oneway", 1),
luabind::value("bidirectional", 2),
luabind::value("opposite", 3)
]
];
// Now call our function in a lua script
INFO("Parsing speedprofile from " << (argc > 2 ? argv[2] : "profile.lua") );
if(0 != luaL_dofile(myLuaState, (argc > 2 ? argv[2] : "profile.lua") )) {
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
}
//open utility libraries string library;
luaL_openlibs(myLuaState);
/*** End of Scripting Environment Setup; ***/
unsigned amountOfRAM = 1;
unsigned installedRAM = GetPhysicalmemory();
if(installedRAM < 2048264) {
WARN("Machine has less than 2GB RAM.");
}
/* if(testDataFile("extractor.ini")) {
ExtractorConfiguration extractorConfig("extractor.ini");
unsigned memoryAmountFromFile = atoi(extractorConfig.GetParameter("Memory").c_str());
if( memoryAmountFromFile != 0 && memoryAmountFromFile <= installedRAM/(1024*1024))
amountOfRAM = memoryAmountFromFile;
INFO("Using " << amountOfRAM << " GB of RAM for buffers");
}
*/
StringMap stringMap;
ExtractionContainers externalMemory;
stringMap[""] = 0;
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
BaseParser<_Node, _RawRestrictionContainer, _Way> * parser;
if(isPBF) {
parser = new PBFParser(argv[1]);
} else {
parser = new XMLParser(argv[1]);
}
parser->RegisterCallbacks(&nodeFunction, &restrictionFunction, &wayFunction);
parser->RegisterLUAState(myLuaState);
if(!parser->Init())
INFO("Parser not initialized!");
parser->Parse();
externalMemory.PrepareData(outputFileName, restrictionsFileName, amountOfRAM);
stringMap.clear();
delete parser;
delete extractCallBacks;
INFO("[extractor] finished.");
std::cout << "\nRun:\n"
"./osrm-prepare " << outputFileName << " " << restrictionsFileName << std::endl;
return 0;
}
示例8: deleteAll
void SymbolType::deleteAll(){
WriteLock l=WL(Types::tSymbol);
locations.clear();
strings.clear();
}