#ifdef _WIN32 #include #include "StackWalker.h" #endif #include "TypeParser.h" #include "ValueParser.h" #include "DataBoardRepository.h" #include "DataValueRepository.h" #include "RecordType.h" #include "Component.h" #include "RecordValue.h" #include "StringValue.h" #include "IntegerValue.h" #include "DoubleValue.h" #include "ArrayValue.h" #include "MapValue.h" #include "IntegerType.h" #include "StringType.h" #include "DataType.h" #include "NumberType.h" #include void testParser() { std::cout << "Output of dbt & dbv files:" << std::endl; Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input11.dbt"); if(typeRepo == NULL) { std::cerr << "type repository not found" << std::endl; return; } Databoard::Type::DataType* type = typeRepo->getDataBoard("PBEparticle"); if(type == NULL) { std::cerr << "type not found" << std::endl; return; } Databoard::Value::Value* value = Databoard::Value::parse("input12.dbv", type); if(value == NULL) { std::cerr << "value not found" << std::endl; return; } //Databoard::Type::RecordType* r = ((Databoard::Type::RecordType*)type); //std::cout << r->getComponentIndex("FractalIndex") << std::endl; //std::cout << r->getComponentIndex("Bondforce") << std::endl; //std::cout << r->getComponentIndex("Density") << std::endl; //std::cout << r->getComponentIndex("RefractiveIndex") << std::endl; //std::cout << r->getComponentIndex("UVabsorption") << std::endl; //std::cout << r->getComponentIndex("SurfacePotential") << std::endl; //std::cout << r->getComponentIndex("SurfaceCharge") << std::endl; //std::cout << r->getComponentIndex("RPermittivity") << std::endl; //std::cout << r->getComponentIndex("AvgRadius") << std::endl; //Databoard::Value::RecordValue* t = ((Databoard::Value::RecordValue*)value); //Databoard::Value::DoubleValue* f0 = (Databoard::Value::DoubleValue*)t->getField(0); //Databoard::Value::DoubleValue* f1 = (Databoard::Value::DoubleValue*)t->getField(1); //Databoard::Value::DoubleValue* f2 = (Databoard::Value::DoubleValue*)t->getField(2); //Databoard::Value::DoubleValue* f3 = (Databoard::Value::DoubleValue*)t->getField(3); //Databoard::Value::RecordValue* f4 = (Databoard::Value::RecordValue*)t->getField(4); //Databoard::Value::DoubleValue* f5 = (Databoard::Value::DoubleValue*)t->getField(5); //Databoard::Value::DoubleValue* f6 = (Databoard::Value::DoubleValue*)t->getField(6); //Databoard::Value::DoubleValue* f7 = (Databoard::Value::DoubleValue*)t->getField(7); //Databoard::Value::DoubleValue* f8 = (Databoard::Value::DoubleValue*)t->getField(8); //std::cout << f0->getValue() << std::endl; //std::cout << f1->getValue() << std::endl; //std::cout << f2->getValue() << std::endl; //std::cout << f3->getValue() << std::endl; //std::cout << ((Databoard::Value::DoubleValue*)f4->getField(0))->getValue() << std::endl; //std::cout << ((Databoard::Value::DoubleValue*)f4->getField(1))->getValue() << std::endl; //std::cout << f5->getValue() << std::endl; //std::cout << f6->getValue() << std::endl; //std::cout << f7->getValue() << std::endl; //std::cout << f8->getValue() << std::endl; std::cout << type->writeOut() << std::endl; std::cout << value->writeOut() << std::endl; delete value; delete typeRepo; std::cout << "..." << std::endl; } void testParser2() { std::cout << "Output of dbt & dbd(s) files:" << std::endl; Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input23.dbt"); if(typeRepo == NULL) { std::cerr << "type repository not found" << std::endl; return; } Databoard::Value::DataValueRepository* valueRepo = NULL; Databoard::Value::parse("input24_1.dbd", valueRepo, typeRepo); Databoard::Value::parse("input24_2.dbd", valueRepo, typeRepo); const Databoard::Value::strDataValueDefinition* v1 = valueRepo->getDataValue("a"); const Databoard::Value::strDataValueDefinition* v2 = valueRepo->getDataValue("b"); std::cout << "... printing types:" << std::endl; for(int i = 0; i < typeRepo->count(); ++i) { std::cout << "#" << i << ":" << std::endl; std::cout << typeRepo->getDataBoard(i).writeOut() << std::endl << std::endl; } if(v1 != NULL) { std::cout << "... printing value definition:" << std::endl; std::cout << v1->writeOut() << std::endl; std::string v = v1->value->isValid(); if(v.length() > 0) { std::cout << "type is invalid: " << v << std::endl; } else { std::cout << "type is valid" << std::endl; } } if(v2 != NULL) { std::cout << "... printing value definition:" << std::endl; std::cout << v2->writeOut() << std::endl; std::string v = v2->value->isValid(); if(v.length() > 0) { std::cout << "type is invalid: " << v << std::endl; } else { std::cout << "type is valid" << std::endl; } } Databoard::Value::free(valueRepo); Databoard::Type::free(typeRepo); std::cout << "..." << std::endl; } void testParser3() { std::cout << "Output of dbt file:" << std::endl; Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input17.dbt"); Databoard::Type::DataType* type = typeRepo->getDataBoard("Complex"); if(type == NULL) { std::cerr << "type not found" << std::endl; return; } std::cout << type->writeOut() << std::endl; Databoard::Value::MapValue* mapValue = new Databoard::Value::MapValue(type); Databoard::Type::IntegerType* integerType = new Databoard::Type::IntegerType(); Databoard::Type::StringType* stringType = new Databoard::Type::StringType(); Databoard::Value::IntegerValue* k0 = new Databoard::Value::IntegerValue(integerType); Databoard::Value::IntegerValue* k1 = new Databoard::Value::IntegerValue(integerType); Databoard::Value::IntegerValue* k2 = new Databoard::Value::IntegerValue(integerType); Databoard::Value::IntegerValue* k3 = new Databoard::Value::IntegerValue(integerType); Databoard::Value::StringValue* v0 = new Databoard::Value::StringValue(stringType); Databoard::Value::StringValue* v1 = new Databoard::Value::StringValue(stringType); Databoard::Value::StringValue* v2 = new Databoard::Value::StringValue(stringType); Databoard::Value::StringValue* v3 = new Databoard::Value::StringValue(stringType); k0->setValue(2); k1->setValue(4); k2->setValue(8); k3->setValue(5); v0->setValue("asd0"); v1->setValue("asd1"); v2->setValue("asd2"); v3->setValue("asd3"); std::cout << "mappi:" << std::endl << mapValue->writeOut() << std::endl; mapValue->put(k0, v0); std::cout << "mappi:" << std::endl << mapValue->writeOut() << std::endl; mapValue->put(k1, v1); std::cout << "mappi:" << std::endl << mapValue->writeOut() << std::endl; mapValue->put(k2, v2); std::cout << "mappi:" << std::endl << mapValue->writeOut() << std::endl; mapValue->put(k3, v3); mapValue->removeRange(k0, k1); //Databoard::Value::Value* old = mapValue->remove(k0); //delete k0; //delete old; delete mapValue; delete integerType; delete stringType; Databoard::Type::free(typeRepo); } void testParser4() { std::cout << "Output of dbt & dbv files:" << std::endl; Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input25.dbt"); if(typeRepo == NULL) { std::cerr << "type repository not found" << std::endl; return; } Databoard::Type::DataType* type = typeRepo->getDataBoard("AggreDist"); if(type == NULL) { std::cerr << "type not found" << std::endl; return; } Databoard::Value::DataValueRepository* valueRepo = NULL; Databoard::Value::parse("input26_3.dbd", valueRepo, typeRepo); Databoard::Value::Value* value1 = Databoard::Value::parse("input26_1.dbv", type); if(value1 == NULL) { std::cerr << "value not found" << std::endl; return; } Databoard::Value::Value* value2 = Databoard::Value::parse("input26_2.dbv", type); if(value2 == NULL) { std::cerr << "value not found" << std::endl; return; } if(value1 != NULL) { std::cout << "... printing value definition:" << std::endl; std::cout << value1->writeOut() << std::endl; std::string v = value1->isValid(); if(v.length() > 0) { std::cout << "type is invalid: " << v << std::endl; } else { std::cout << "type is valid" << std::endl; } delete value1; } if(value2 != NULL) { std::cout << "... printing value definition:" << std::endl; std::cout << value2->writeOut() << std::endl; std::string v = value2->isValid(); if(v.length() > 0) { std::cout << "type is invalid: " << v << std::endl; } else { std::cout << "type is valid" << std::endl; } delete value2; } delete valueRepo; delete typeRepo; std::cout << "..." << std::endl; } void testParser5() { std::cout << "Output of dbt & dbv files:" << std::endl; Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input27.dbt"); if(typeRepo == NULL) { std::cerr << "type repository not found" << std::endl; return; } Databoard::Type::DataType* type = typeRepo->getDataBoard("Complex"); if(type == NULL) { std::cerr << "type not found" << std::endl; return; } Databoard::Value::Value* value = Databoard::Value::parse("input28.dbv", type); if(value == NULL) { std::cerr << "value not found" << std::endl; return; } std::cout << type->writeOut() << std::endl; std::cout << value->writeOut() << std::endl; delete value; delete typeRepo; std::cout << "..." << std::endl; } void testParser6() { std::cout << "Output of dbt & dbv files:" << std::endl; Databoard::Type::DataBoardRepository* typeRepo = Databoard::Type::parse("input29.dbt"); if(typeRepo == NULL) { std::cerr << "type repository not found" << std::endl; return; } Databoard::Type::DataType* type = typeRepo->getDataBoard("T"); if(type == NULL) { std::cerr << "type not found" << std::endl; return; } Databoard::Value::Value* value1 = Databoard::Value::parse("input30.dbv", type); if(value1 == NULL) { std::cerr << "value not found" << std::endl; return; } Databoard::Value::RecordValue* recordValue = dynamic_cast(value1); if(recordValue != NULL) { for(int i = 0; i < recordValue->count(); ++i) { Databoard::Value::Value* value = recordValue->getField(i); Databoard::Value::ArrayValue* arrayValue = dynamic_cast(value); if(arrayValue != NULL) { //// one by one: //for(int j = 0; j < arrayValue->count(); ++j) //{ // Databoard::Value::Value* value = arrayValue->get(j); // std::cout << value->writeOut() << std::endl; //} // or to vector: std::vector valueVector = arrayValue->getAll(); std::cout << "Row count: " << (int)valueVector.size() << std::endl; for(int j = 0; j < (int)valueVector.size(); ++j) { Databoard::Value::RecordValue* recordValue = (Databoard::Value::RecordValue*)valueVector.at(j); std::cout << "Element count: " << recordValue->count() << std::endl; for(int k = 0; k < recordValue->count(); ++k) { Databoard::Value::DoubleValue* doubleValue = (Databoard::Value::DoubleValue*)recordValue->getField(k); std::cout << doubleValue->getValue() << std::endl; } } } } delete value1; } delete typeRepo; std::cout << "..." << std::endl; } int main() { #ifdef _WIN32 InitAllocCheck(); #endif //testParser(); //testParser2(); //testParser3(); //testParser4(); //testParser5(); testParser6(); #ifdef _WIN32 DeInitAllocCheck(); #endif }