ISystemComponent* GraphicsComponentSerializer::DeSerialize( const std::string entityName, ticpp::Element* componentElement, const ISystemScene::SystemSceneMap& systemScenes ) { std::string system; componentElement->GetAttribute( System::Attributes::SystemType, &system ); ISystemScene::SystemSceneMap::const_iterator systemScene = systemScenes.find( System::SystemTypeMapper::StringToType( system ) ); std::string type; componentElement->GetAttribute( System::Attributes::ComponentType, &type ); ISystemComponent* systemComponent = ( *systemScene ).second->CreateComponent( entityName, type ); ticpp::Element* attributesElement = componentElement->FirstChildElement( "attributes" ); for( Iterator< Element > attribute = attributesElement->FirstChildElement( false ); attribute != attribute.end( ); attribute++ ) { std::string key; attribute->GetAttribute( "key", &key ); if ( key == System::Parameters::Model ) { std::string modelPath; attribute->GetAttribute( "v1", &modelPath ); systemComponent->SetAttribute( System::Parameters::Model, modelPath ); } } return systemComponent; }
ISystemComponent* AnimationComponentSerializer::DeSerialize( const std::string entityName, ticpp::Element* componentElement, const ISystemScene::SystemSceneMap& systemScenes ) { std::string system; componentElement->GetAttribute( System::Attributes::SystemType, &system ); ISystemScene::SystemSceneMap::const_iterator systemScene = systemScenes.find( System::SystemTypeMapper::StringToType( system ) ); std::string type; componentElement->GetAttribute( System::Attributes::ComponentType, &type ); ISystemComponent* systemComponent = ( *systemScene ).second->CreateComponent( entityName, type ); std::map< std::string, std::string > animations; ticpp::Element* attributesElement = componentElement->FirstChildElement( "attributes" ); for( Iterator< Element > attribute = attributesElement->FirstChildElement( false ); attribute != attribute.end( ); attribute++ ) { std::string key; attribute->GetAttribute( "key", &key ); if ( key == "animation" ) { std::string animationName; attribute->GetAttribute( "v1", &animationName ); std::string animationPath; attribute->GetAttribute( "v2", &animationPath ); animations.insert( std::make_pair( animationName, animationPath ) ); } if ( key == System::Attributes::Animation::BindPose ) { std::string animationPath; attribute->GetAttribute( "v1", &animationPath ); systemComponent->SetAttribute( System::Attributes::Animation::BindPose, animationPath ); } if ( key == System::Attributes::Animation::DefaultAnimation ) { std::string animationPath; attribute->GetAttribute( "v1", &animationPath ); systemComponent->SetAttribute( System::Attributes::Animation::DefaultAnimation, animationPath ); } } systemComponent->SetAttribute( System::Attributes::Animation::Animations , animations ); return systemComponent; }
void Bank::readParamData( Iterator< Element > it, ParamData* paramData ) { it->GetAttribute( "id", ¶mData->id_, false ); it->GetAttribute( "value", ¶mData->value_, false ); it->GetAttribute( "vsens", ¶mData->veloSens_, false ); it->GetAttribute( "ktrack", ¶mData->keyTrack_, false ); it->GetAttribute( "cc", ¶mData->controller_, false ); it->GetAttribute( "ccmin", ¶mData->controllerMin_, false ); it->GetAttribute( "ccmax", ¶mData->controllerMax_, false ); it->GetAttribute( "ccsoft", ¶mData->controllerSoft_, false ); it->GetAttribute( "style", (int*)¶mData->style_, false ); it->GetAttribute( "label", ¶mData->label_, false ); it->GetAttribute( "unit", ¶mData->unit_, false ); it->GetAttribute( "fmt", (int*)¶mData->format_, false ); it->GetAttribute( "dflt", ¶mData->defaultValue_, false ); it->GetAttribute( "min", ¶mData->min_, false ); it->GetAttribute( "max", ¶mData->max_, false ); it->GetAttribute( "log", ¶mData->logFactor_, false ); it->GetAttribute( "steps", ¶mData->numSteps_, false ); it->GetAttribute( "res", ¶mData->resolution_, false ); }
tsdb::RecordParser* record_parser_from_xml(const std::string parse_instruction_filename, tsdb::Timeseries* out_ts) { using namespace std; using namespace ticpp; Document doc = Document(parse_instruction_filename); doc.LoadFile(); cout << "Loaded '" << parse_instruction_filename << "'." << endl; cout << "Creating parser..." << endl; /* Create the RecordParser */ tsdb::RecordParser* recordparser = new tsdb::RecordParser(); recordparser->setRecordStructure(out_ts->structure().get()); Iterator<Element> child; string name; string value; auto_ptr<Node> delimparser; for(child = child.begin(doc.FirstChildElement()); child != child.end(); child++) { child->GetValue(&value); if(value == "delimparser") { delimparser = child->Clone(); break; } } string delim = delimparser->ToElement()->GetAttribute("field_delim"); if(delim == "") { delim = ","; } string escape = delimparser->ToElement()->GetAttribute("escape_chars"); if(escape == "") { escape="\\"; } string quote = delimparser->ToElement()->GetAttribute("quote_chars"); if(quote == "") { quote="\"'"; } string mode = delimparser->ToElement()->GetAttribute("parse_mode"); if(mode == "extended") { recordparser->setSimpleParse(false); recordparser->setDelimiter(delim); recordparser->setEscapeCharacter(escape); recordparser->setQuoteCharacter(quote); cout << " - field delimiter(s): '" << delim << "'" << endl; cout << " - quote character(s): '" << quote << "'" << endl; cout << " - escape character(s): '" << escape << "'" << endl; } else { recordparser->setSimpleParse(true); recordparser->setDelimiter(delim.substr(0,1)); cout << " - field delimiter: '" << delim.substr(0,1) << "'" << endl; } cout << " Processing parser elements:" << endl; /* Loop through the RecordParser and look for TokenFilters or FieldParsers */ typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer; string tokens,comparison,format_string,type,missing_token_replacement; bool missing_tokens_ok = false; vector<string> vec; vector<size_t> apply_to_tokens; size_t i; for(child = child.begin(delimparser.get()); child != child.end(); child++) { child->GetValue(&value); if(value == "tokenfilter") { tokens = child->GetAttribute("tokens"); comparison = child->GetAttribute("comparison"); value = child->GetAttribute("value"); Tokenizer tok(tokens); vec.assign(tok.begin(),tok.end()); apply_to_tokens.clear(); for(i=0;i<vec.size();i++) { apply_to_tokens.push_back(atoi(vec.at(i).c_str())); } /* Write out some information */ cout << " - TokenFilter:" << endl; cout << " apply to tokens: ("; for(i=0;i<apply_to_tokens.size();) { cout << apply_to_tokens.at(i); i++; if(i<apply_to_tokens.size()) { cout << ","; } } cout << ")" << endl; if(comparison == "NE") { recordparser->addTokenFilter(new tsdb::TokenFilter(apply_to_tokens, tsdb::TokenFilter::NOT_EQUAL_TO, value)); cout << " comparison: NOT_EQUAL_TO" << endl; } else if(comparison == "EQ") { recordparser->addTokenFilter(new tsdb::TokenFilter(apply_to_tokens, tsdb::TokenFilter::EQUAL_TO, value)); cout << " comparison: EQUAL_TO" << endl; } else { cout << " comparison not recognized!" << endl; throw(runtime_error("comparison operator in TokenFilter not recognized")); } cout << " value: '" << value << "'" << endl; } else if(value == "fieldparser") { tokens = child->GetAttribute("tokens"); missing_tokens_ok=false; Tokenizer tok(tokens); vec.assign(tok.begin(),tok.end()); apply_to_tokens.clear(); for(i=0;i<vec.size();i++) { apply_to_tokens.push_back(atoi(vec.at(i).c_str())); } /* Write out some information */ cout << " - FieldParser:" << endl; cout << " apply to tokens: ("; for(i=0;i<apply_to_tokens.size();) { cout << apply_to_tokens.at(i); i++; if(i<apply_to_tokens.size()) { cout << ","; } } cout << ")" << endl; name = child->GetAttribute("name"); format_string = child->GetAttribute("format_string"); type = child->GetAttribute("type"); if(child->HasAttribute("missing_token_replacement")) { missing_token_replacement = child->GetAttribute("missing_token_replacement"); missing_tokens_ok = true; } if(type == "timestamp") { recordparser->addFieldParser(new tsdb::TimestampFieldParser(apply_to_tokens, format_string, name)); cout << " type: Timestamp" << endl; cout << " format string: '" << format_string << "'" << endl; } else if(type == "string") { recordparser->addFieldParser(new tsdb::StringFieldParser(apply_to_tokens, name)); cout << " type: String" << endl; } else if(type == "int32") { recordparser->addFieldParser(new tsdb::Int32FieldParser(apply_to_tokens.at(0), name)); cout << " type: Int32" << endl; } else if(type == "int8") { recordparser->addFieldParser(new tsdb::Int8FieldParser(apply_to_tokens.at(0), name)); cout << " type: Int8" << endl; } else if(type == "double") { recordparser->addFieldParser(new tsdb::DoubleFieldParser(apply_to_tokens.at(0), name)); cout << " type: Double" << endl; } else if(type == "char") { recordparser->addFieldParser(new tsdb::CharFieldParser(apply_to_tokens.at(0), name)); cout << " type: Char" << endl; } else { cout << " type: not recognized!" << endl; throw(runtime_error("type in FieldParser not recognized")); } if(missing_tokens_ok) { recordparser->fieldParsers().back()->setMissingTokenReplacement(missing_token_replacement); cout << " missing_token_replacement: '" << missing_token_replacement << "'" << endl; } cout << " name: '" << name << "'" << endl; } } return recordparser; cout << " finished processing parser elements." << endl; }