bool LuaFeatureDefs::IsDefaultParam(const string& word) { if (paramMap.empty()) { InitParamMap(); } return (paramMap.find(word) != paramMap.end()); }
void TwqUser::RA_Prop::doIt(User& u) const { UserID uid = u.getID(); // 実際にTwitterAPIで問い合わせ ParamMap pm; pm.insert(TWAPIKWD::US_LOOKUP::UserId, QString("%1").arg(uid)); sgNet.restAPI(sgUser.GetCB<TwqUser::P_Prop>(uid), TWAPI::US_LOOKUP, pm, QString(), uid); }
// ############################################################## void ModelManager::saveConfig(const string& fname) const { LINFO("Saving configuration to '%s'", fname.c_str()); ParamMap pmap; this->writeParamsTo(pmap); pmap.format(fname); }
// ############################################################## void ModelManager::loadConfig(const string& fname) { LINFO("Loading configuration from '%s'", fname.c_str()); ParamMap pmap; pmap.load(fname.c_str()); this->readParamsFrom(pmap); }
static int FeatureDefNewIndex(lua_State* L) { // not a default value, set it if (!lua_isstring(L, 2)) { lua_rawset(L, 1); return 0; } const char* name = lua_tostring(L, 2); ParamMap::const_iterator it = paramMap.find(name); // not a default value, set it if (it == paramMap.end()) { lua_rawset(L, 1); return 0; } const void* userData = lua_touserdata(L, lua_upvalueindex(1)); const FeatureDef* fd = (const FeatureDef*)userData; // write-protected if (!gs->editDefsEnabled) { luaL_error(L, "Attempt to write FeatureDefs[%d].%s", fd->id, name); return 0; } // Definition editing const DataElement& elem = it->second; const char* p = ((const char*)fd) + elem.offset; switch (elem.type) { case FUNCTION_TYPE: case READONLY_TYPE: { luaL_error(L, "Can not write to %s", name); return 0; } case INT_TYPE: { *((int*)p) = lua_toint(L, -1); return 0; } case BOOL_TYPE: { *((bool*)p) = lua_toboolean(L, -1); return 0; } case FLOAT_TYPE: { *((float*)p) = lua_tofloat(L, -1); return 0; } case STRING_TYPE: { *((string*)p) = lua_tostring(L, -1); return 0; } case ERROR_TYPE:{ luaL_error(L, "ERROR_TYPE in FeatureDefs __newindex"); } } return 0; }
static int UnitDefIndex(lua_State* L) { // not a default value if (!lua_isstring(L, 2)) { lua_rawget(L, 1); return 1; } const char* name = lua_tostring(L, 2); ParamMap::const_iterator it = paramMap.find(name); // not a default value if (it == paramMap.end()) { lua_rawget(L, 1); return 1; } const void* userData = lua_touserdata(L, lua_upvalueindex(1)); const UnitDef* ud = static_cast<const UnitDef*>(userData); const DataElement& elem = it->second; const char* p = ((const char*)ud) + elem.offset; switch (elem.type) { case READONLY_TYPE: { lua_rawget(L, 1); return 1; } case INT_TYPE: { lua_pushnumber(L, *((int*)p)); return 1; } case BOOL_TYPE: { lua_pushboolean(L, *((bool*)p)); return 1; } case FLOAT_TYPE: { lua_pushnumber(L, *((float*)p)); return 1; } case STRING_TYPE: { lua_pushsstring(L, *((string*)p)); return 1; } case FUNCTION_TYPE: { return elem.func(L, p); } case ERROR_TYPE: { LOG_L(L_ERROR, "[%s] ERROR_TYPE for key \"%s\" in UnitDefs __index", __FUNCTION__, name); lua_pushnil(L); return 1; } } return 0; }
static int FeatureDefIndex(lua_State* L) { // not a default value if (!lua_isstring(L, 2)) { lua_rawget(L, 1); return 1; } const char* name = lua_tostring(L, 2); ParamMap::const_iterator it = paramMap.find(name); // not a default value if (it == paramMap.end()) { lua_rawget(L, 1); return 1; } const void* userData = lua_touserdata(L, lua_upvalueindex(1)); const FeatureDef* fd = (const FeatureDef*)userData; const DataElement& elem = it->second; const char* p = ((const char*)fd) + elem.offset; switch (elem.type) { case READONLY_TYPE: { lua_rawget(L, 1); return 1; } case INT_TYPE: { lua_pushnumber(L, *((int*)p)); return 1; } case BOOL_TYPE: { lua_pushboolean(L, *((bool*)p)); return 1; } case FLOAT_TYPE: { lua_pushnumber(L, *((float*)p)); return 1; } case STRING_TYPE: { lua_pushsstring(L, *((string*)p)); return 1; } case FUNCTION_TYPE: { return elem.func(L, p); } case ERROR_TYPE:{ luaL_error(L, "ERROR_TYPE in FeatureDefs __index"); } } return 0; }
void paramTest(){ const char* url = "http://show.mtty.com/v?p=VwsimgAO6MJ7jEpgW5IA8rszDyLuC4qNGtNxzw&a=0086-ffff-ffff&b=50&c=2546&d=9&e=288&r=3e581c094cf01851&s=9223372032561888060&x=6&tm=1460347546&l=http://click.bes.baidu.com/adx.php?c=cz00NGY1OWJmMDA0MGEzMzFmAHQ9MTQ2MDM0NzU0NgBzZT0xAGJ1PTE4NzA0OTA3AHR1PTkyMjMzNzIwMzI1NjE4ODgwNjAAYWQ9MTQ1ODExOTUyMDUyMDI1NDYAc2l0ZT1odHRwOi8vd3d3Ljh2djguY29tL25ld3MvNzdfMTQuaHRtbAB2PTEAaT05ZDFlOWFjMA&k=dz0zMzYAaD0yODAAY3NpZD0xMjAyNTkwODQzMjE2AHRtPTI2OTA0Njk4NQB0ZD0yMDc5NTQ4AHdpPTE4NzA0OTA3AGZuPTMwMDE0MDg4X2NwcgBmYW49AHVpZD0xODczNzA1NABjaD0wAG9zPTkAYnI9MTAAaXA9MTI0LjEyNi4yMDUuNzgAc3NwPTEAYXBwX2lkPQBhcHBfc2lkPQBzZGtfdmVyc2lvbj0AdHRwPTEAY29tcGxlPTAAc3R5cGU9MABjaG1kPTAAc2NobWQ9MAB4aXA9MTAwLjY1LjQxLjgwAGR0cD0xAGNtYXRjaD0yMDAAZmlyc3RfcmVnaW9uPTEAc2Vjb25kX3JlZ2lvbj0zODIAYWRjbGFzcz0w&url=http%253A%252F%252Fbdtg%2E9377a%2Ecom%252Fsousuotg%2Ephp%253Fid%253D11852%2526uid%253D%257Bmpid%257D_%257Bcid%257D"; //const char* url = "http://show.mtty.com/v?p=-tsCgWZqNjC6xpRl8VwJxQ==&of=3&a=0086-ffff-ffff&b=20000&c=12551&d=8&e=10000&r=g2iwjo7r6xpag&s=8863364436303842593&x=13&tm=1463538785&w=&gz=1"; ParamMap paramMap; getParamv2(paramMap,url); typedef typename ParamMap::iterator Iter; for(Iter iter = paramMap.begin();iter!=paramMap.end();iter++){ cout<<iter->first<<":"<<iter->second<<endl; } //DebugMessage("l:",paramMap["l"]); //char buffer[1024]; //std::string output; //urlDecode_f(paramMap["l"],output,buffer); //DebugMessage("after decoded,l:",output); }
void paramTest(){ const char* url = "v=1.0&d=9&k=1&y=7&t1=ererwrwer3&t2="; //const char* url = "http://show.mtty.com/v?p=-tsCgWZqNjC6xpRl8VwJxQ==&of=3&a=0086-ffff-ffff&b=20000&c=12551&d=8&e=10000&r=g2iwjo7r6xpag&s=8863364436303842593&x=13&tm=1463538785&w=&gz=1"; ParamMap paramMap; getParamv2(paramMap,url); typedef typename ParamMap::iterator Iter; for(Iter iter = paramMap.begin();iter!=paramMap.end();iter++){ cout<<iter->first<<":"<<iter->second<<endl; } //DebugMessage("l:",paramMap["l"]); //char buffer[1024]; //std::string output; //urlDecode_f(paramMap["l"],output,buffer); //DebugMessage("after decoded,l:",output); }
int LuaUtils::Next(const ParamMap& paramMap, lua_State* L) { luaL_checktype(L, 1, LUA_TTABLE); lua_settop(L, 2); // create a 2nd argument if there isn't one // internal parameters first if (lua_isnil(L, 2)) { const string& nextKey = paramMap.begin()->first; lua_pushsstring(L, nextKey); // push the key lua_pushvalue(L, 3); // copy the key lua_gettable(L, 1); // get the value return 2; } // all internal parameters use strings as keys if (lua_isstring(L, 2)) { const char* key = lua_tostring(L, 2); ParamMap::const_iterator it = paramMap.find(key); if ((it != paramMap.end()) && (it->second.type != READONLY_TYPE)) { // last key was an internal parameter ++it; while ((it != paramMap.end()) && (it->second.type == READONLY_TYPE)) { ++it; // skip read-only parameters } if ((it != paramMap.end()) && (it->second.type != READONLY_TYPE)) { // next key is an internal parameter const string& nextKey = it->first; lua_pushsstring(L, nextKey); // push the key lua_pushvalue(L, 3); // copy the key lua_gettable(L, 1); // get the value (proxied) return 2; } // start the user parameters, // remove the internal key and push a nil lua_settop(L, 1); lua_pushnil(L); } } // user parameter if (lua_next(L, 1)) { return 2; } // end of the line lua_pushnil(L); return 1; }
bool LuaFeatureDefs::PushEntries(lua_State* L) { if (paramMap.empty()) { InitParamMap(); } const map<string, const FeatureDef*>& featureDefs = featureHandler->GetFeatureDefs(); map<string, const FeatureDef*>::const_iterator fdIt; for (fdIt = featureDefs.begin(); fdIt != featureDefs.end(); ++fdIt) { const FeatureDef* fd = fdIt->second; if (fd == NULL) { continue; } lua_pushnumber(L, fd->id); lua_newtable(L); { // the proxy table lua_newtable(L); { // the metatable HSTR_PUSH(L, "__index"); lua_pushlightuserdata(L, (void*)fd); lua_pushcclosure(L, FeatureDefIndex, 1); lua_rawset(L, -3); // closure HSTR_PUSH(L, "__newindex"); lua_pushlightuserdata(L, (void*)fd); lua_pushcclosure(L, FeatureDefNewIndex, 1); lua_rawset(L, -3); HSTR_PUSH(L, "__metatable"); lua_pushlightuserdata(L, (void*)fd); lua_pushcclosure(L, FeatureDefMetatable, 1); lua_rawset(L, -3); } lua_setmetatable(L, -2); } HSTR_PUSH(L, "pairs"); lua_pushcfunction(L, Pairs); lua_rawset(L, -3); HSTR_PUSH(L, "next"); lua_pushcfunction(L, Next); lua_rawset(L, -3); lua_rawset(L, -3); // proxy table into FeatureDefs } return true; }
// ###################################################################### void IntegerComplexChannel::writeTo(ParamMap& pmap) const { GVX_TRACE(__PRETTY_FUNCTION__); IntegerChannel::writeTo(pmap); ChannelFacetMap::writeFacetsTo(pmap); for (uint i = 0; i < numChans(); ++i) { rutz::shared_ptr<ParamMap> submap(new ParamMap); subChan(i)->writeTo(*submap); submap->putDoubleParam("weight", rep->subchans[i].weight->getVal()); pmap.putSubpmap(subChan(i)->tagName(), submap); } }
// ###################################################################### void IntegerComplexChannel::readFrom(const ParamMap& pmap) { GVX_TRACE(__PRETTY_FUNCTION__); IntegerChannel::readFrom(pmap); ChannelFacetMap::readFacetsFrom(pmap); for (uint i = 0; i < numChans(); ++i) { const std::string tagname = subChan(i)->tagName(); if (pmap.hasParam(tagname)) { rutz::shared_ptr<ParamMap> submap = pmap.getSubpmap(tagname); subChan(i)->readFrom(*submap); double wt = rep->subchans[i].weight->getVal(); if (submap->queryDoubleParam("weight", wt) == ParamMap::MISSING) rep->subchans[i].weight->setVal(1.0); else rep->subchans[i].weight->setVal(wt); } } }
bool LuaWeaponDefs::PushEntries(lua_State* L) { if (paramMap.empty()) { InitParamMap(); } const map<string, int>& weaponMap = weaponDefHandler->weaponID; map<string, int>::const_iterator wit; for (wit = weaponMap.begin(); wit != weaponMap.end(); ++wit) { const WeaponDef* wd = &weaponDefHandler->weaponDefs[wit->second]; if (wd == NULL) { continue; } lua_pushnumber(L, wd->id); lua_newtable(L); { // the proxy table lua_newtable(L); { // the metatable HSTR_PUSH(L, "__index"); lua_pushlightuserdata(L, (void*)wd); lua_pushcclosure(L, WeaponDefIndex, 1); lua_rawset(L, -3); // closure HSTR_PUSH(L, "__newindex"); lua_pushlightuserdata(L, (void*)wd); lua_pushcclosure(L, WeaponDefNewIndex, 1); lua_rawset(L, -3); HSTR_PUSH(L, "__metatable"); lua_pushlightuserdata(L, (void*)wd); lua_pushcclosure(L, WeaponDefMetatable, 1); lua_rawset(L, -3); } lua_setmetatable(L, -2); } HSTR_PUSH(L, "pairs"); lua_pushcfunction(L, Pairs); lua_rawset(L, -3); HSTR_PUSH(L, "next"); lua_pushcfunction(L, Next); lua_rawset(L, -3); lua_rawset(L, -3); // proxy table into WeaponDefs } return true; }
bool LuaUnitDefs::PushEntries(lua_State* L) { if (paramMap.empty()) { InitParamMap(); } const map<string, int>& udMap = unitDefHandler->unitDefIDsByName; map<string, int>::const_iterator udIt; for (udIt = udMap.begin(); udIt != udMap.end(); ++udIt) { const UnitDef* ud = unitDefHandler->GetUnitDefByID(udIt->second); if (ud == NULL) { continue; } lua_pushnumber(L, ud->id); lua_newtable(L); { // the proxy table lua_newtable(L); { // the metatable HSTR_PUSH(L, "__index"); lua_pushlightuserdata(L, (void*)ud); lua_pushcclosure(L, UnitDefIndex, 1); lua_rawset(L, -3); // closure HSTR_PUSH(L, "__newindex"); lua_pushlightuserdata(L, (void*)ud); lua_pushcclosure(L, UnitDefNewIndex, 1); lua_rawset(L, -3); HSTR_PUSH(L, "__metatable"); lua_pushlightuserdata(L, (void*)ud); lua_pushcclosure(L, UnitDefMetatable, 1); lua_rawset(L, -3); } lua_setmetatable(L, -2); } HSTR_PUSH(L, "pairs"); lua_pushcfunction(L, Pairs); lua_rawset(L, -3); HSTR_PUSH(L, "next"); lua_pushcfunction(L, Next); lua_rawset(L, -3); lua_rawset(L, -3); // proxy table into UnitDefs } return true; }
bool LuaFeatureDefs::PushEntries(lua_State* L) { if (paramMap.empty()) { InitParamMap(); } lua_newtable(L); { // the metatable HSTR_PUSH_CFUNC(L, "__index", FeatureDefTableIndex); HSTR_PUSH_CFUNC(L, "__newindex", FeatureDefTableNewIndex); HSTR_PUSH_CFUNC(L, "__metatable", FeatureDefTableMetatable); } lua_setmetatable(L, -2); return true; }
// ############################################################## bool ModelManager::parseCommandLine(const int argc, const char** argv, const char* usage, const int minarg, const int maxarg) { ASSERT(rep != 0); // export options if that hasn't been done already if (this->hasBeenExported() == false) exportOptions(MC_RECURSE); // let's get our application name: if (argc <= 0) LFATAL("expected argc >= 1, got argc=%d", argc); string procname(argv[0]); uint ii = procname.rfind('/'); // skip the path; get just the filename: if (ii < procname.size()) procname = procname.substr(ii + 1); // if we wanted to automatically load a config from ~/.execname, // let's do that now: if (rep->autoLoadConfig && getenv("HOME")) { string fname = string(getenv("HOME")) + "/." + procname; FILE* tryit = fopen(fname.c_str(), "r"); if (tryit) { // config file exists; let's load it: fclose(tryit); LINFO("Autoloading configuration from '%s'", fname.c_str()); ParamMap pmap; pmap.load(fname.c_str()); readParamsFrom(pmap); } } return rep->com.parseCommandLine(argc, argv, usage, minarg, maxarg); }
/*! */ bool RCSSParamParser::parse( ParamMap & param_map ) { if ( M_str_pairs.empty() ) { return false; } int n_params = 0; for ( StrPairVec::iterator it = M_str_pairs.begin(); it != M_str_pairs.end(); ++it ) { // get parameter entry from map ParamPtr param_ptr = param_map.findLongName( it->first ); // analyze value string if ( param_ptr && param_ptr->analyze( it->second ) ) { ++n_params; } else { std::cerr << "***ERROR*** RCSSParamParser. " << "unknown parameter name or invalid value. name=[" << it->first << "] value=[" << it->second << "]" << std::endl; } } #ifdef DEBUG std::cerr << "RCSSParamParser. [" << M_param_name << "] read " << n_params << " params." << std::endl; #endif return true; }
//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void Var::saveIni( ParamMap &ini ) { if ( type == Var_Float ) { ini.setFloat(name, var_float() ); } if ( type == Var_Int ) { ini.setInt(name, var_int() ); } if ( type == Var_String ) { ini.setString(name, var_string() ); } }
//--------------------------------------------------------------------------- void Var::loadIni( ParamMap &ini ) { if ( type == Var_Float ) { var_float() = ini.getFloat(name, var_float() ); } if ( type == Var_Int ) { var_int() = ini.getInt(name, var_int() ); } if ( type == Var_String ) { var_string() = ini.getString(name, var_string() ); } }
static bool InitParamMap() { paramMap.clear(); paramMap["next"] = DataElement(READONLY_TYPE); paramMap["pairs"] = DataElement(READONLY_TYPE); // dummy FeatureDef for address lookups const FeatureDef fd; const char* start = ADDRESS(fd); ADD_FUNCTION("model", fd, ModelTable); ADD_FUNCTION("collisionVolume", fd.collisionVolume, ColVolTable); ADD_FUNCTION("modelname", fd, ModelName); ADD_FUNCTION("height", fd, ModelHeight); ADD_FUNCTION("radius", fd, ModelRadius); ADD_FUNCTION("drawTypeString", fd, ModelDrawType); ADD_FUNCTION("customParams", fd.customParams, CustomParamsTable); ADD_INT("id", fd.id); ADD_INT("deathFeatureID", fd.deathFeatureDefID); ADD_STRING("name", fd.name); ADD_STRING("tooltip", fd.description); ADD_FLOAT("metal", fd.metal); ADD_FLOAT("energy", fd.energy); ADD_FLOAT("maxHealth", fd.health); ADD_FLOAT("reclaimTime", fd.reclaimTime); ADD_FLOAT("mass", fd.mass); ADD_INT("xsize", fd.xsize); ADD_INT("zsize", fd.zsize); ADD_INT("drawType", fd.drawType); ADD_BOOL("upright", fd.upright); ADD_BOOL("destructable", fd.destructable); ADD_BOOL("reclaimable", fd.reclaimable); ADD_BOOL("autoreclaim", fd.autoreclaim); ADD_BOOL("blocking", fd.collidable); ADD_BOOL("burnable", fd.burnable); ADD_BOOL("floating", fd.floating); ADD_BOOL("geoThermal", fd.geoThermal); ADD_BOOL("noSelect", fd.selectable); ADD_INT("resurrectable", fd.resurrectable); ADD_INT("smokeTime", fd.smokeTime); ADD_DEPRECATED_LUADEF_KEY("minx"); ADD_DEPRECATED_LUADEF_KEY("miny"); ADD_DEPRECATED_LUADEF_KEY("minz"); ADD_DEPRECATED_LUADEF_KEY("midx"); ADD_DEPRECATED_LUADEF_KEY("midy"); ADD_DEPRECATED_LUADEF_KEY("midz"); ADD_DEPRECATED_LUADEF_KEY("maxx"); ADD_DEPRECATED_LUADEF_KEY("maxy"); ADD_DEPRECATED_LUADEF_KEY("maxz"); ADD_DEPRECATED_LUADEF_KEY("deathFeature"); return true; }
void TwqHomeTL::readNextPage() { ParamMap pm; pm.insert(TWAPIKWD::TW_SHOW::IncludeMyRetweet, "true"); _readNextPage(TWAPI::TL_HOME, pm); }
static int UnitDefNewIndex(lua_State* L) { // not a default value, set it if (!lua_isstring(L, 2)) { lua_rawset(L, 1); return 0; } const char* name = lua_tostring(L, 2); ParamMap::const_iterator it = paramMap.find(name); // not a default value, set it if (it == paramMap.end()) { lua_rawset(L, 1); return 0; } const void* userData = lua_touserdata(L, lua_upvalueindex(1)); const UnitDef* ud = static_cast<const UnitDef*>(userData); // write-protected if (!gs->editDefsEnabled) { luaL_error(L, "Attempt to write UnitDefs[%d].%s", ud->id, name); return 0; } // Definition editing const DataElement& elem = it->second; const char* p = ((const char*)ud) + elem.offset; switch (elem.type) { case FUNCTION_TYPE: case READONLY_TYPE: { luaL_error(L, "Can not write to %s", name); return 0; } case INT_TYPE: { *((int*)p) = lua_toint(L, -1); return 0; } case BOOL_TYPE: { *((bool*)p) = lua_toboolean(L, -1); return 0; } case FLOAT_TYPE: { *((float*)p) = lua_tofloat(L, -1); return 0; } case STRING_TYPE: { *((string*)p) = lua_tostring(L, -1); return 0; } case ERROR_TYPE: { LOG_L(L_ERROR, "[%s] ERROR_TYPE for key \"%s\" in UnitDefs __newindex", __FUNCTION__, name); lua_pushnil(L); return 1; } } return 0; }