Vector<PosBase*> PosLoadUtil::loadPosWithFile(const char* sFilePath, EnumPosType enPosType, Node* container, int iLevel, bool isDebug) { Vector<PosBase*> posList; ValueMap fileDataMap = FileUtils::getInstance()->getValueMapFromFile(sFilePath); //遍历Valuemap for (auto it = fileDataMap.begin(); it != fileDataMap.end();++it){ Value value = it->second; ValueMap data = value.asValueMap(); /* 创建坐标对象 */ PosBase* posBase = NULL; switch (enPosType) { case enTowerPos: posBase = TowerPos::create(Point(data["x"].asInt(), data["y"].asInt()), data["herotype"].asInt(), data["bullettype"].asInt(), isDebug); break; case enMonsterPos: posBase = MonsterPos::create(Point(data["x"].asInt(), data["y"].asInt()), isDebug); break; default: posBase = TowerPos::create(Point(data["x"].asInt(), data["y"].asInt()), data["herotype"].asInt(), data["bullettype"].asInt(), isDebug); break; } posList.pushBack(posBase); if (container != NULL) { container->addChild(posBase, iLevel); } } return posList; }
void PlayLayer::initPointsVector(float offX) { Node *runOfPoint = NULL; int count = 0; ValueMap point; //by char countBuf1[16] = ""; sprintf(countBuf1, "%d", count); auto moneyText = countBuf1; //point = objects->getObject(std::to_string(count)); point = objects->getObject(moneyText); while (point.begin()!= point.end()) { float x = point.at("x").asFloat(); float y = point.at("y").asFloat(); runOfPoint = Node::create(); runOfPoint->setPosition(Point(x - offX, y )); this->pointsVector.pushBack(runOfPoint); count++; //by char countBuf2[16] = ""; sprintf(countBuf2, "%d", count); auto moneyText = countBuf2; //point = objects->getObject( std::to_string(count)); point = objects->getObject( moneyText); } runOfPoint = NULL; }
double petabricks::Heuristic::eval (const ValueMap featureValues) { FormulaPtr evaluated = _formula->clone(); for(ValueMap::const_iterator i=featureValues.begin(), e=featureValues.end(); i!=e; ++i) { const std::string& featureName=i->first; const std::string featureValueStr = jalib::XToString(i->second); evaluated = MaximaWrapper::instance().subst(featureValueStr, featureName, evaluated); } evaluated = MaximaWrapper::instance().toFloat(evaluated); double value = evaluated->value(); //Keep the value within the limits if (value < _min) { return _min; } else if (value > _max) { return _max; } else { return value; } }
void Domain::Indices::Partition(const ValueMap& specified, const set<string>& dimensions, ValueMap& results) { ValueMap::const_iterator element; for(element = specified.begin(); element != specified.end(); element++) { if(dimensions.find(element->first) != dimensions.end()) { results[element->first] = element->second; } } }
void Histogram::insertZeroBoundaryValues(float xMin, float xMax) { if (_valueMap.empty()) { if (xMin<xMax) { _valueMap[xMin] = 0.0; _valueMap[xMax] = 0.0; } return; } float interval = 1.0f; float min_gap_for_single_insertion = interval*1.5; float min_gap_for_double_insertion = interval*2.5; if (xMin<_valueMap.begin()->first) { _valueMap[xMin] = 0.0; } if (xMax>_valueMap.rbegin()->first) { _valueMap[xMax] = 0.0; } ValueMap::iterator itr = _valueMap.begin(); float previous_x = itr->first; for(; itr != _valueMap.end(); ++itr) { float current_x = itr->first; float gap = current_x-previous_x; if (gap>min_gap_for_double_insertion) { _valueMap[previous_x+interval] = 0.0f; _valueMap[current_x-interval] = 0.0f; } else if (gap>min_gap_for_single_insertion) { _valueMap[(previous_x+current_x)*0.5]=0.0f; } previous_x = current_x; } }
bool SparseMatrix::optimiseSAMG (bool transposed) { if (!editable) return false; ValueMap trans; // only computed if needed ValueIter begin, end; if (transposed) { for (const auto& it : elem) trans[IJPair(it.first.second,it.first.first)] = it.second; begin = trans.begin(); end = trans.end(); std::swap(nrow,ncol); } else { begin = elem.begin(); end = elem.end(); } size_t nnz = this->size(); A.resize(nnz); JA.resize(nnz); IA.resize(nrow+1,nnz+1); IA[0] = 1; // first row start at index 1 size_t cur_row = 1, ix = 0; for (ValueIter it = begin; it != end; ++it, ix++) { A[ix] = it->second; // storing element value JA[ix] = it->first.second; while (it->first.first > cur_row) IA[cur_row++] = ix+1; } editable = false; elem.clear(); // Erase the editable matrix elements // convert to row storage format required by SAMG (diagonal term first) for (size_t r = 0; r < nrow; r++) { int rstart = IA[r]-1; int rend = IA[r+1]-1; // looking for diagonal element for (int diag_ix = rstart; diag_ix < rend; diag_ix++) if (JA[diag_ix] == (int)(1+r)) { // swapping (if necessary) with first element on this row if (diag_ix > rstart) { std::swap(A[rstart],A[diag_ix]); std::swap(JA[rstart],JA[diag_ix]); } break; } } return true; }
void createTXTRecord_( TXTRecordRef& record ) { TXTRecordCreate( &record, 0, 0 ); for( ValueMapCIter i = data_.begin(); i != data_.end(); ++i ) { const std::string& key = i->first; const std::string& value = i->second; const uint8_t valueSize = value.length() > 255 ? 255 : uint8_t( value.length( )); TXTRecordSetValue( &record, key.c_str(), valueSize, value.c_str( )); } }
void Predator::loadAnimationFromDataFile(const char* animationDataKey){ ValueMap framesData = DataManager::getInstance()->_staticData\ .at("character").asValueMap()\ .at("hamster").asValueMap()\ .at(Value(_id).asString().c_str()).asValueMap()\ .at("animations").asValueMap()\ .at(animationDataKey).asValueMap(); int animationId = _animationsId.size(); _animationsId[std::string(animationDataKey)] = animationId; int animationFrameNum = framesData.at("animation_frame_num").asInt(); bool isAnimationLooping = framesData.at("loop").asBool(); //判断framesData中是否存有"animation_frame_index_start"的信息 bool doesDataIncludeFrameIndexStart = false; for (auto it = framesData.begin(); it != framesData.end(); it++){ if (it->first == std::string("animation_frame_index_start")){ doesDataIncludeFrameIndexStart = true; } } int animationFrameIndexStart; if (doesDataIncludeFrameIndexStart){ animationFrameIndexStart = _animationsFrameIndexStart[std::string(framesData.at("animation_frame_index_start").asString())]; } else{ animationFrameIndexStart = _animationsFrameIndexStart[std::string(animationDataKey)]; } ValueMap animationFrameSequence = framesData.at("animation_frame_sequence").asValueMap(); ValueMap animationDurationSequence = framesData.at("animation_duration_sequence").asValueMap(); _animationFrameSequences[animationId] = new int[animationFrameNum + 1]; _animationDurationSequences[animationId] = new int[animationFrameNum]; for (int animationFrameIndex = 0; animationFrameIndex < animationFrameNum; animationFrameIndex++){ _animationFrameSequences[animationId][animationFrameIndex] = animationFrameSequence[Value(animationFrameIndex).asString().c_str()].asInt() + animationFrameIndexStart; _animationDurationSequences[animationId][animationFrameIndex] = animationDurationSequence[Value(animationFrameIndex).asString().c_str()].asInt(); } if (isAnimationLooping){ _animationFrameSequences[animationId][animationFrameNum] = -1;//循环动画序列结尾标志 } else{ _animationFrameSequences[animationId][animationFrameNum] = -2;//非循环动画序列结尾标志 } }
void Configure::SaveConfigGroup(ValueMap vals) { ofs_.open(conf_path_.c_str(), std::ios::app|std::ios::out); for (ValueMap::iterator it = vals.begin(); it != vals.end(); it++) { std::string title = it->first; if (title.empty()) continue; // title = title.substr(title.find_first_of(" ")+1); ofs_ << title << ": " << it->second << '\n'; } ofs_ << '\n'; ofs_.close(); }
void PlayLayer::initPointsVector(float offX) { Node *runOfPoint = NULL; int count = 0; ValueMap point; point = objects->getObject(std::to_string(count)); while (point.begin()!= point.end()) { float x = point.at("x").asFloat(); float y = point.at("y").asFloat(); runOfPoint = Node::create(); runOfPoint->setPosition(Point(x - offX , y )); this->pointsVector.pushBack(runOfPoint); count++; point = objects->getObject( std::to_string(count)); } runOfPoint = NULL; }
bool Session::snmpGetNext( Identifier &identifier, Value &value, ErrorInfo *error ) { ValueMap vars; IdentifierList ids; ids << identifier; if ( !snmpGetInternal( SNMP_MSG_GETNEXT, ids, vars, error ) ) return false; assert( vars.count() == 1 ); ValueMap::ConstIterator it = vars.begin(); identifier = it.key(); value = it.data(); return true; }
void StartScene::addWayPoint() { DataModel *m = DataModel::getModel(); auto objects = this->_tileMap->objectGroupNamed("Objects"); WayPoint *wp = NULL; std::string stringWithFormat = "Waypoint"; int wayPointCounter = 0; ValueMap wayPoint; wayPoint = objects->objectNamed(stringWithFormat + to_string(wayPointCounter)); while (wayPoint.begin() != wayPoint.end()) { int x = wayPoint.at("x").asInt(); int y = wayPoint.at("y").asInt(); wp = WayPoint::create(); wp->setPosition(ccp(x, y)); m->waypoints.pushBack(wp); wayPointCounter++; wayPoint = objects->objectNamed(stringWithFormat + to_string(wayPointCounter)); } wp =NULL; }
// ValueMap map<string, string> bool Domain::Indices::Lookup(const ValueMap& specified, Data::RIDList& results) { if(!this->meta->OpenReader()) { return false; } if(!this->meta->index->OpenReader()) { return false; } string name; ValueMap::const_iterator cell; map< string, set<string> > indices; for(cell = specified.begin(); cell != specified.end(); cell++) { if(this->meta->Index(cell->first, name)) { indices[name].insert(cell->first); } else { this->meta->Close(); return false; } } ValueMap partition; Data::RIDList records; map< string, set<string> >::iterator fragment; for(fragment = indices.begin(); fragment != indices.end(); fragment++) { partition.clear(); this->Partition(specified, fragment->second, partition); if(!this->meta->index->Lookup(partition, records)) { this->meta->index->Close(); return false; } else { if(records.size() == 0) { results.clear(); return true; } else { if(results.size() == 0) { results.assign(records.begin(), records.end()); } else { results = results & records; } } } } this->meta->index->Close(); this->meta->Close(); return true; }
void ShapeCache::addShapeWithFileToSprite(std::string plist, cocos2d::Sprite *s){ FileUtils *fu = FileUtils::getInstance(); ValueMap root = fu->getValueMapFromFile(plist); auto bodies = root["bodies"].asValueMap(); ValueMap fixtureDef; for (auto iter=bodies.begin(); iter!=bodies.end(); iter++) { fixtureDef = iter->second.asValueMap(); } ValueMap item = fixtureDef["fixtures"].asValueVector()[0].asValueMap(); s->setPhysicsBody(PhysicsBody::create()); for (auto iter=item.begin(); iter!=item.end(); iter++) { std::string key = iter->first; auto type = iter->second; if (key == "polygons") { auto value = type.asValueVector(); for (int i=0; i<value.size(); i++) { auto _item = value[i].asValueVector(); Vec2 *vec = new Vec2[_item.size()]; for (int j=0; j<_item.size(); j++) { Point p = PointFromString(_item[j].asString().c_str()); vec[j] = Vec2(p.x, p.y); } s->getPhysicsBody()->addShape(PhysicsShapePolygon::create(vec, _item.size())); } }else if (key == "mass"){ s->getPhysicsBody()->setMass(type.asInt()); }else if (key == "friction"){ auto shapes = s->getPhysicsBody()->getShapes(); for (int i=0; i<shapes.size(); i++) { shapes.at(i)->setFriction(type.asInt()); } } } }
void writeStream(std::ostream &stream, int tabCount) { for(ValueMap::iterator vi = values.begin(); vi != values.end(); ++vi) { writeTabs(stream, tabCount); stream << (*vi).first << " = " << (*vi).second.first << std::endl; } for(GroupMap::iterator gi = groups.begin(); gi != groups.end(); ++gi) { if((gi != groups.begin()) || (!values.empty())) stream << std::endl; writeTabs(stream, tabCount); stream << (*gi).first << std::endl; writeTabs(stream, tabCount); stream << "{" << std::endl; (*gi).second->writeStream(stream, tabCount + 1), writeTabs(stream, tabCount); stream << "}" << std::endl; } if(!lines.empty() && ((!groups.empty() || !values.empty()))) stream << std::endl; for(LineList::iterator li = lines.begin(); li != lines.end(); ++li) { writeTabs(stream, tabCount); std::string &f = (*li); stream << (*li) << std::endl; } }
int TransportRegistry::load_transport_configuration(const OPENDDS_STRING& file_name, ACE_Configuration_Heap& cf) { const ACE_Configuration_Section_Key &root = cf.root_section(); // Create a vector to hold configuration information so we can populate // them after the transports instances are created. typedef std::pair<TransportConfig_rch, OPENDDS_VECTOR(OPENDDS_STRING) > ConfigInfo; OPENDDS_VECTOR(ConfigInfo) configInfoVec; // Record the transport instances created, so we can place them // in the implicit transport configuration for this file. OPENDDS_LIST(TransportInst_rch) instances; ACE_TString sect_name; for (int index = 0; cf.enumerate_sections(root, index, sect_name) == 0; ++index) { if (ACE_OS::strcmp(sect_name.c_str(), TRANSPORT_SECTION_NAME) == 0) { // found the [transport/*] section, now iterate through subsections... ACE_Configuration_Section_Key sect; if (cf.open_section(root, sect_name.c_str(), 0, sect) != 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("failed to open section %s\n"), sect_name.c_str()), -1); } else { // Ensure there are no properties in this section ValueMap vm; if (pullValues(cf, sect, vm) > 0) { // There are values inside [transport] ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("transport sections must have a section name\n"), sect_name.c_str()), -1); } // Process the subsections of this section (the individual transport // impls). KeyList keys; if (processSections( cf, sect, keys ) != 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("too many nesting layers in [%s] section.\n"), sect_name.c_str()), -1); } for (KeyList::const_iterator it=keys.begin(); it != keys.end(); ++it) { OPENDDS_STRING transport_id = (*it).first; ACE_Configuration_Section_Key inst_sect = (*it).second; ValueMap values; if (pullValues( cf, (*it).second, values ) != 0) { // Get the factory_id for the transport. OPENDDS_STRING transport_type; ValueMap::const_iterator vm_it = values.find("transport_type"); if (vm_it != values.end()) { transport_type = (*vm_it).second; } else { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("missing transport_type in [transport/%C] section.\n"), transport_id.c_str()), -1); } // Create the TransportInst object and load the transport // configuration in ACE_Configuration_Heap to the TransportInst // object. TransportInst_rch inst = this->create_inst(transport_id, transport_type); if (inst == 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("Unable to create transport instance in [transport/%C] section.\n"), transport_id.c_str()), -1); } instances.push_back(inst); inst->load(cf, inst_sect); } else { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("missing transport_type in [transport/%C] section.\n"), transport_id.c_str()), -1); } } } } else if (ACE_OS::strcmp(sect_name.c_str(), CONFIG_SECTION_NAME) == 0) { // found the [config/*] section, now iterate through subsections... ACE_Configuration_Section_Key sect; if (cf.open_section(root, sect_name.c_str(), 0, sect) != 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("failed to open section [%s]\n"), sect_name.c_str()), -1); } else { // Ensure there are no properties in this section ValueMap vm; if (pullValues(cf, sect, vm) > 0) { // There are values inside [config] ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("config sections must have a section name\n"), sect_name.c_str()), -1); } // Process the subsections of this section (the individual config // impls). KeyList keys; if (processSections( cf, sect, keys ) != 0) { // Don't allow multiple layers of nesting ([config/x/y]). ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("too many nesting layers in [%s] section.\n"), sect_name.c_str()), -1); } for (KeyList::const_iterator it=keys.begin(); it != keys.end(); ++it) { OPENDDS_STRING config_id = (*it).first; // Create a TransportConfig object. TransportConfig_rch config = this->create_config(config_id); if (config == 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("Unable to create transport config in [config/%C] section.\n"), config_id.c_str()), -1); } ValueMap values; pullValues( cf, (*it).second, values ); ConfigInfo configInfo; configInfo.first = config; for (ValueMap::const_iterator it=values.begin(); it != values.end(); ++it) { OPENDDS_STRING name = (*it).first; if (name == "transports") { OPENDDS_STRING value = (*it).second; char delim = ','; size_t pos = 0; OPENDDS_STRING token; while ((pos = value.find(delim)) != OPENDDS_STRING::npos) { token = value.substr(0, pos); configInfo.second.push_back(token); value.erase(0, pos + 1); } configInfo.second.push_back(value); configInfoVec.push_back(configInfo); } else if (name == "swap_bytes") { OPENDDS_STRING value = (*it).second; if ((value == "1") || (value == "true")) { config->swap_bytes_ = true; } else if ((value != "0") && (value != "false")) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("Illegal value for swap_bytes (%C) in [config/%C] section.\n"), value.c_str(), config_id.c_str()), -1); } } else if (name == "passive_connect_duration") { OPENDDS_STRING value = (*it).second; if (!convertToInteger(value, config->passive_connect_duration_)) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("Illegal integer value for passive_connect_duration (%s) in [config/%C] section.\n"), value.c_str(), config_id.c_str()), -1); } } else { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("Unexpected entry (%C) in [config/%C] section.\n"), name.c_str(), config_id.c_str()), -1); } } if (configInfo.second.size() == 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("No transport instances listed in [config/%C] section.\n"), config_id.c_str()), -1); } } } } else if (ACE_OS::strncmp(sect_name.c_str(), OLD_TRANSPORT_PREFIX.c_str(), OLD_TRANSPORT_PREFIX.length()) == 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ") ACE_TEXT("Obsolete transport configuration found (%s).\n"), sect_name.c_str()), -1); } } // Populate the configurations with instances for (unsigned int i = 0; i < configInfoVec.size(); ++i) { TransportConfig_rch config = configInfoVec[i].first; OPENDDS_VECTOR(OPENDDS_STRING)& insts = configInfoVec[i].second; for (unsigned int j = 0; j < insts.size(); ++j) { TransportInst_rch inst = this->get_inst(insts[j]); if (inst == 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("The inst (%C) in [config/%C] section is undefined.\n"), insts[j].c_str(), config->name().c_str()), -1); } config->instances_.push_back(inst); } } // Create and populate the default configuration for this // file with all the instances from this file. if (!instances.empty()) { TransportConfig_rch config = this->create_config(file_name); if (config == 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) TransportRegistry::load_transport_configuration: ") ACE_TEXT("Unable to create default transport config.\n"), file_name.c_str()), -1); } instances.sort(predicate); for (OPENDDS_LIST(TransportInst_rch)::const_iterator it = instances.begin(); it != instances.end(); ++it) { config->instances_.push_back(*it); } } return 0; }
osg::Node* Histogram::createGraphicalRepresentation() { if (_valueMap.empty()) return 0; osg::ref_ptr<osg::MatrixTransform> transform = new osg::MatrixTransform; float xMin = _valueMap.begin()->first; float xMax = _valueMap.rbegin()->first; float depth = 0.0f; float yMax = 0.0f; // find yMax for(ValueMap::iterator itr = _valueMap.begin(); itr != _valueMap.end(); ++itr) { float y = itr->second; if (y>yMax) yMax = y; } float xScale = 1.0f/(xMax-xMin); float yScale = 1.0f/yMax; { osg::ref_ptr<osg::Geode> geode = new osg::Geode; transform->addChild(geode.get()); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geode->addDrawable(geometry.get()); geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; geometry->setVertexArray(vertices.get()); osg::ref_ptr<osg::Vec4Array> colours = new osg::Vec4Array; geometry->setColorArray(colours.get(), osg::Array::BIND_PER_PRIMITIVE_SET); colours->push_back(osg::Vec4(1.0,1.0,1.0,1.0)); colours->push_back(osg::Vec4(1.0,1.0,1.0,1.0)); colours->push_back(osg::Vec4(1.0,1.0,1.0,0.1)); unsigned numColumnsRequired = _valueMap.size(); vertices->reserve(numColumnsRequired*3); for(ValueMap::iterator itr = _valueMap.begin(); itr != _valueMap.end(); ++itr) { float x = itr->first; float y = itr->second; vertices->push_back(osg::Vec3(x*xScale, 0.0f, depth)); vertices->push_back(osg::Vec3(x*xScale, y*yScale, depth)); vertices->push_back(osg::Vec3(x*xScale, yMax*yScale, depth)); } osg::ref_ptr<osg::DrawElementsUShort> background_primitives = new osg::DrawElementsUShort(GL_TRIANGLE_STRIP); osg::ref_ptr<osg::DrawElementsUShort> historgram_primitives = new osg::DrawElementsUShort(GL_TRIANGLE_STRIP); osg::ref_ptr<osg::DrawElementsUShort> outline_primitives = new osg::DrawElementsUShort(GL_LINE_STRIP); for(unsigned int i=0; i<numColumnsRequired; ++i) { int iv = i*3; background_primitives->push_back(iv+2); background_primitives->push_back(iv+1); historgram_primitives->push_back(iv+1); historgram_primitives->push_back(iv+0); outline_primitives->push_back(iv+1); } geometry->addPrimitiveSet(outline_primitives.get()); geometry->addPrimitiveSet(historgram_primitives.get()); geometry->addPrimitiveSet(background_primitives.get()); } //transform->setMatrix(osg::Matrix::scale(xScale/(maxX-minY), yScale/(yMax), 1.0f)); transform->setMatrix(osg::Matrix::scale(2.0,1.0,1.0)*osg::Matrix::rotate(osg::DegreesToRadians(90.0), osg::Vec3d(1.0,0.0,0.0))); return transform.release(); }
int InfoRepoDiscovery::Config::discovery_config(ACE_Configuration_Heap& cf) { const ACE_Configuration_Section_Key& root = cf.root_section(); ACE_Configuration_Section_Key repo_sect; if (cf.open_section(root, REPO_SECTION_NAME, 0, repo_sect) != 0) { if (DCPS_debug_level > 0) { // This is not an error if the configuration file does not have // any repository (sub)section. The code default configuration will be used. ACE_DEBUG((LM_NOTICE, ACE_TEXT("(%P|%t) NOTICE: InfoRepoDiscovery::Config::discovery_config ") ACE_TEXT("failed to open [%s] section.\n"), REPO_SECTION_NAME)); } return 0; } else { // Ensure there are no properties in this section ValueMap vm; if (pullValues(cf, repo_sect, vm) > 0) { // There are values inside [repo] ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) InfoRepoDiscovery::Config::discovery_config ") ACE_TEXT("repo sections must have a subsection name\n")), -1); } // Process the subsections of this section (the individual repos) KeyList keys; if (processSections( cf, repo_sect, keys ) != 0) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) InfoRepoDiscovery::Config::discovery_config ") ACE_TEXT("too many nesting layers in the [repo] section.\n")), -1); } // Loop through the [repo/*] sections for (KeyList::const_iterator it=keys.begin(); it != keys.end(); ++it) { std::string repo_name = (*it).first; ValueMap values; pullValues( cf, (*it).second, values ); Discovery::RepoKey repoKey = Discovery::DEFAULT_REPO; bool repoKeySpecified = false, bitIpSpecified = false, bitPortSpecified = false; std::string repoIor; int bitPort = 0; std::string bitIp; for (ValueMap::const_iterator it=values.begin(); it != values.end(); ++it) { std::string name = (*it).first; if (name == "RepositoryKey") { repoKey = (*it).second; repoKeySpecified = true; if (DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) [repository/%C]: RepositoryKey == %C\n"), repo_name.c_str(), repoKey.c_str())); } } else if (name == "RepositoryIor") { repoIor = (*it).second; if (DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) [repository/%C]: RepositoryIor == %C\n"), repo_name.c_str(), repoIor.c_str())); } } else if (name == "DCPSBitTransportIPAddress") { bitIp = (*it).second; bitIpSpecified = true; if (DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) [repository/%C]: DCPSBitTransportIPAddress == %C\n"), repo_name.c_str(), bitIp.c_str())); } } else if (name == "DCPSBitTransportPort") { std::string value = (*it).second; bitPort = ACE_OS::atoi(value.c_str()); bitPortSpecified = true; if (convertToInteger(value, bitPort)) { } else { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) InfoRepoDiscovery::Config::discovery_config ") ACE_TEXT("Illegal integer value for DCPSBitTransportPort (%C) in [repository/%C] section.\n"), value.c_str(), repo_name.c_str()), -1); } if (DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) [repository/%C]: DCPSBitTransportPort == %d\n"), repo_name.c_str(), bitPort)); } } else { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) InfoRepoDiscovery::Config::discovery_config ") ACE_TEXT("Unexpected entry (%C) in [repository/%C] section.\n"), name.c_str(), repo_name.c_str()), -1); } } if (values.find("RepositoryIor") == values.end()) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) InfoRepoDiscovery::Config::discovery_config ") ACE_TEXT("Repository section [repository/%C] section is missing RepositoryIor value.\n"), repo_name.c_str()), -1); } if (!repoKeySpecified) { // If the RepositoryKey option was not specified, use the section // name as the repo key repoKey = repo_name; } InfoRepoDiscovery_rch discovery = new InfoRepoDiscovery(repoKey, repoIor.c_str()); if (bitPortSpecified) discovery->bit_transport_port(bitPort); if (bitIpSpecified) discovery->bit_transport_ip(bitIp); TheServiceParticipant->add_discovery( DCPS::static_rchandle_cast<Discovery>(discovery)); } } return 0; }
static jobject ValueMap2SFSObject(JNIEnv* env, const ValueMap& valueMap, jobject javaObj) { jclass cls = env->GetObjectClass(javaObj); if (!cls) return javaObj; for (auto it = valueMap.begin(); it != valueMap.end(); ++it) { jobject javaKey = env->NewStringUTF(it->first.c_str()); if (it->second.getType() == Value::Type::BYTE) { jmethodID mid = env->GetMethodID(cls, "putByte", "(Ljava/lang/String;B)V"); if (mid) env->CallVoidMethod(javaObj, mid, javaKey, it->second.asByte()); } else if (it->second.getType() == Value::Type::INTEGER) { jmethodID mid = env->GetMethodID(cls, "putInt", "(Ljava/lang/String;I)V"); if (mid) env->CallVoidMethod(javaObj, mid, javaKey, it->second.asInt()); } else if (it->second.getType() == Value::Type::FLOAT) { jmethodID mid = env->GetMethodID(cls, "putFloat", "(Ljava/lang/String;F)V"); if (mid) env->CallVoidMethod(javaObj, mid, javaKey, it->second.asFloat()); } else if (it->second.getType() == Value::Type::DOUBLE) { jmethodID mid = env->GetMethodID(cls, "putFloat", "(Ljava/lang/String;F)V"); if (mid) env->CallVoidMethod(javaObj, mid, javaKey, it->second.asDouble()); } else if (it->second.getType() == Value::Type::BOOLEAN) { jmethodID mid = env->GetMethodID(cls, "putBool", "(Ljava/lang/String;Z)V"); if (mid) env->CallVoidMethod(javaObj, mid, javaKey, it->second.asBool()); } else if (it->second.getType() == Value::Type::STRING) { jmethodID mid = env->GetMethodID(cls, "putUtfString", "(Ljava/lang/String;Ljava/lang/String;)V"); if (mid) { jobject javaValue = env->NewStringUTF(it->second.asString().c_str()); env->CallVoidMethod(javaObj, mid, javaKey, javaValue); env->DeleteLocalRef(javaValue); } } else if (it->second.getType() == Value::Type::VECTOR) { jmethodID mid = env->GetMethodID(cls, "putSFSArray", "(Ljava/lang/String;Lcom/smartfoxserver/v2/entities/data/ISFSArray;)V"); if (mid) { jobject javaSFSArray = getSFSArray(env); jobject javaValue = ValueVector2SFSArray(env, it->second.asValueVector(), javaSFSArray); env->CallVoidMethod(javaObj, mid, javaKey, javaValue); env->DeleteLocalRef(javaValue); } } else if (it->second.getType() == Value::Type::MAP) { jmethodID mid = env->GetMethodID(cls, "putSFSObject", "(Ljava/lang/String;Lcom/smartfoxserver/v2/entities/data/ISFSObject;)V"); if (mid) { jobject sub_obj = getSFSObject(env); jobject javaValue = ValueMap2SFSObject(env, it->second.asValueMap(), sub_obj); env->CallVoidMethod(javaObj, mid, javaKey, javaValue); env->DeleteLocalRef(javaValue); } } else if (it->second.getType() == Value::Type::INT_KEY_MAP) { } env->DeleteLocalRef(javaKey); } env->DeleteLocalRef(cls); return javaObj; }
/* * this method saves the attribute together with the host string that * defines the type of object that this attribute is associated to (like * position or document) and the hosts database id. */ void AttributeMap::save( dbID id ) { checkHost(); QSqlQuery attribQuery; attribQuery.prepare( "SELECT id, valueIsList FROM attributes WHERE hostObject=:host AND hostId=:hostId AND name=:name" ); attribQuery.bindValue( ":host", mHost ); attribQuery.bindValue( ":hostId", id.toString() ); Iterator it; for ( it = begin(); it != end(); ++it ) { Attribute att = it.value(); kDebug() << ">> oo- saving attribute with name " << it.key() << " for " << id.toString() << " att-name: " << att.name(); attribQuery.bindValue( ":name", att.name() ); attribQuery.exec(); QString attribId; if ( attribQuery.next() ) { // the attrib exists. Check the values attribId = attribQuery.value(0).toString(); // the id if ( att.value().isNull() || att.mDelete ) { // the value is empty. the existing entry needs to be dropped dbDeleteAttribute( attribId ); return; } } else { // the attrib does not yet exist. Create if att value is not null. if ( att.value().isNull() ) { kDebug() << "oo- skip writing of attribute, value is empty"; } else { kDebug() << "oo- writing of attribute name " << att.name(); QSqlQuery insQuery; insQuery.prepare( "INSERT INTO attributes (hostObject, hostId, name, valueIsList, relationTable, " "relationIDColumn, relationStringColumn) " "VALUES (:host, :hostId, :name, :valueIsList, :relTable, :relIDCol, :relStringCol )" ); insQuery.bindValue( ":host", mHost ); insQuery.bindValue( ":hostId", id.toString() ); insQuery.bindValue( ":name", att.name() ); insQuery.bindValue( ":valueIsList", att.listValue() ); // Write the relation table info. These remain empty for non related attributes. insQuery.bindValue( ":relTable", att.mTable ); insQuery.bindValue( ":relIDCol", att.mIdCol ); insQuery.bindValue( ":relStringCol", att.mStringCol ); insQuery.exec(); dbID attId = KraftDB::self()->getLastInsertID(); attribId = attId.toString(); } } // store the id to be able to drop not longer existent values kDebug() << "adding attribute id " << attribId << " for attribute " << att.name(); // now there is a valid entry in the attribute table. Check the values. QSqlQuery valueQuery( "SELECT id, value FROM attributeValues WHERE attributeId=" + attribId ); typedef QMap<QString, QString> ValueMap; ValueMap valueMap; while ( valueQuery.next() ) { QString idStr = valueQuery.value( 0 ).toString(); // id QString valStr = valueQuery.value( 1 ).toString(); // value valueMap[valStr] = idStr; } // create a stringlist with the current values of the attribute if ( att.listValue() ) { QStringList newValues; newValues = att.mValue.toStringList(); kDebug() << "new values are: " << newValues.join( ", " ); if ( newValues.empty() ) { // delete the entire attribute. dbDeleteValue( attribId ); // deletes all values dbDeleteAttribute( attribId ); valueMap.clear(); } else { // we really have new values QSqlQuery insValue; insValue.prepare( "INSERT INTO attributeValues (attributeId, value) VALUES (:attribId, :val)" ); insValue.bindValue( ":attribId", attribId ); // loop over all existing new values of the attribute. for ( QStringList::Iterator valIt = newValues.begin(); valIt != newValues.end(); ++valIt ) { QString curValue = *valIt; if ( valueMap.contains( curValue ) ) { // the valueMap is already saved. remove it from the valueMap string kDebug() << "Value " << curValue << " is already present with id " << valueMap[curValue]; valueMap.remove( curValue ); } else { // the value is not yet there, insert it. insValue.bindValue( ":val", curValue ); insValue.exec(); } } } } else { // only a single entry for the attribte, update if needed. QString newValue = att.mValue.toString(); // access the attribute object directly to get the numeric kDebug() << "NEW value String: " << newValue; // value in case the attribute is bound to a relation table if ( newValue.isEmpty() ) { // delete the entire attribute dbDeleteValue( attribId ); // deletes all values dbDeleteAttribute( attribId ); valueMap.clear(); } else { if ( valueMap.empty() ) { // there is no entry yet that could be updated. QSqlQuery insertQuery; insertQuery.prepare( "INSERT INTO attributeValues (attributeId, value ) VALUES (:id, :val)" ); insertQuery.bindValue( ":id", attribId ); insertQuery.bindValue( ":val", newValue ); insertQuery.exec(); kDebug() << "insert new attrib value for non list: " << newValue; } else { QString oldValue = valueMap.begin().key(); QString id = valueMap.begin().value(); if ( newValue != oldValue ) { kDebug() << "Updating " << id << " from " << oldValue << " to " << newValue; QSqlQuery updateQuery; updateQuery.prepare( "UPDATE attributeValues SET value=:val WHERE id=:id" ); updateQuery.bindValue( ":val", newValue ); updateQuery.bindValue( ":id", id ); kDebug() << "do the update!"; updateQuery.exec(); } valueMap.remove( oldValue ); } } } // remove all still existing entries in the valueMap because they point to values which are // in the db but were deleted from the attribute if ( ! valueMap.isEmpty() ) { ValueMap::Iterator mapIt; for ( mapIt = valueMap.begin(); mapIt != valueMap.end(); ++mapIt ) { QString valId = mapIt.value(); dbDeleteValue( attribId, valId ); } } } }