Пример #1
0
void WorldYamlSource::loadPropertySystems() {

	// iterate through each section (each section is a system)
	std::vector<YAML::Node> nodes = YAML::LoadAllFromFile(dir + "PropertySystems.yaml");
	for (size_t i = 0; i < nodes.size(); i++) {
		YamlWrapper yaml(nodes[i]);

		// parse which system this section is for
		String typeName = yaml.read<String>("Which", "NONE", "Invalid property system.");
		ThingType type = ThingType::fromString(typeName);

		// create the system
		propertySystems[type].reset(new PropertySystem());
		PropertySystem& system = *propertySystems[type];

		// parse the properties of the system
		YAML::Node propertiesNode = yaml["Properties"].getNode();
		for (auto iter = propertiesNode.begin(); iter != propertiesNode.end(); ++iter) {
			YamlWrapper propertyYaml(*iter);
			String name  = propertyYaml.read<String>("Name", "", "Property name not given.");
			Type type    = Type::fromString(propertyYaml.read<String>("Type"));
			Variant def  = readVariant(propertyYaml["Default"].getNode(), type);
			bool mainKey = propertyYaml.read<bool>("MainKey", false);
			system.add(name, type, def, mainKey);
		}
	}
}
Пример #2
0
void WorldYamlSource::loadItems() {
	if (!propertySystems[ThingType::ITEM]) return;
	PropertySystem& itemSys = *propertySystems[ThingType::ITEM];

	std::vector<YAML::Node> nodes = YAML::LoadAllFromFile(dir + "Items.yaml");
	for (size_t i = 0; i < nodes.size(); i++) {
		YamlWrapper yaml(nodes[i]);

		// read base
		String baseName = yaml.read<String>("Base", "", "Item lacks a base.");
		if (baseName == "") continue;
		auto iter = itemBaseNameMap.find(baseName);
		if (iter == itemBaseNameMap.end()) {
			LOG(ERROR) << "'" << baseName << "' is not an existing item base.";
			continue;
		}
		BaseThing& base = *iter->second;

		items.emplace_back(new Item(base, items.size() + 1));
		Item& item = *items.back();

		// read location
		if (yaml["Location"]->IsSequence()) {
			item.moveTo(yaml.read<Coord>("Location", Coord()));
		}

		// read properties
		YAML::Node propertiesNode = yaml["Properties"].getNode();
		for (auto iter = propertiesNode.begin(); iter != propertiesNode.end(); ++iter) {
			const Property& property = itemSys[iter->first.as<String>()];
			item.setValue(property, readVariant(iter->second, property.type));
		}
	}
}
void ServerConfigurationDialog::on_loadButton_clicked(bool)
{
   QString filePath(QDir::homePath()); 
   filePath = QFileDialog::getOpenFileName(this, tr("Open Server Configuration"),
      filePath, tr("Configuration Files (*.cfg)"));

   if (filePath.isEmpty()) return;

   try {
      Parser::ParseFile parser(filePath);
      parser.start();
      parser.wait();

      QStringList errors(parser.errors());
      if (!errors.isEmpty()) {
         QMsgBox::warning(this, "IQmol", errors.join("\n"));
      }

      Data::Bank& bank(parser.data());
      QList<Data::YamlNode*> yaml(bank.findData<Data::YamlNode>());
      if (yaml.first()) {
         yaml.first()->dump();
         m_currentConfiguration = ServerConfiguration(*(yaml.first()));
         blockUpdate(true);
         copyFrom(m_currentConfiguration);
         blockUpdate(false);
      }

   } catch (YAML::Exception& err) {
      QString msg(QString::fromStdString(err.what()));
      QMsgBox::warning(this, "IQmol", msg);
   }
}
Пример #4
0
int main( int argc, char *argv[] )
 {
  std::cout << __FUNCTION__ << std::endl;
  // Some typedefs
  typedef ::reflection::operation::transfer::observe_class<std::ostream> observe_type;
  typedef ::reflection::operation::transfer::xml::print_struct<std::ostream> xml_type;
  typedef ::reflection::operation::transfer::json::print_struct<std::ostream> json_type;
  typedef ::reflection::operation::transfer::cpp::print_struct<std::ostream> cpp_type;
  typedef ::reflection::operation::transfer::yaml::print_struct<std::ostream> yaml_type;
  typedef ::reflection::operation::transfer::protobuf::print_struct<std::ostream> protobuf_type;
  typedef ::reflection::operation::transfer::ini::print_struct<std::ostream> ini_type;

  MyClassReflection   r;  //!< Reflection of Original, with pointing to some instance

  observe_type observe; //!< Algorithm for observation AKA serialization

  { cpp_type cpp( observe ); //!< Fill observator how to serialize.
                    observe.register_class<MyBaseClass, MyBaseClasssReflectionView>( );
  }
  observe.view( std::cout, r ); // CPPize for example

  observe.clear();
  { xml_type xml( observe );//!< Fill observator how to serialize.
                  observe.register_class<MyBaseClass, MyBaseClasssReflectionView>( );
  }
  observe.view( std::cout, r ); // XMLize

  observe.clear();
  { json_type json( observe );//!< Fill observator how to serialize.
                    observe.register_class<MyBaseClass, MyBaseClasssReflectionView>( );
  }
  observe.view( std::cout, r ); // JSONize

  observe.clear();
  { yaml_type yaml( observe );//!< Fill observator how to serialize.
                    observe.register_class<MyBaseClass, MyBaseClasssReflectionView>( );
  }
  observe.view( std::cout, r ); // YAMLize

  observe.clear();
  { protobuf_type protobuf( observe );//!< Fill observator how to serialize.
                            observe.register_class<MyBaseClass, MyBaseClasssReflectionView>( );
  }
  observe.view( std::cout, r ); // Protobufferize

  observe.clear();
  { ini_type ini( observe );//!< Fill observator how to serialize.
                  observe.register_class<MyBaseClass, MyBaseClasssReflectionView>( );
  }
  observe.view( std::cout, r );  // INIrize

  return EXIT_SUCCESS;
 }
Пример #5
0
int main(int argc, char** argv) {
    qRegisterMetaType<ComponentA>("ComponentA");
    qRegisterMetaType<ComponentB>("ComponentB");

    Node base;
    base.AddChild(new Node)->AddComponent(new ComponentA);
    base.AddChild(new Node)->AddChild(new Node);
    Node* n = base.AddChild(new Node);
    n->AddComponent(new ComponentA);
    n->AddComponent(new ComponentB);

    //base.Display();
    //

    // yaml test
    YAML::Emitter out;
    out << YAML::BeginMap;
    out << YAML::Key << "metadata" << YAML::Value;
        out << YAML::BeginMap;
        out << YAML::Key << "author" << YAML::Value << "opatut";
        out << YAML::Key << "date" << YAML::Value << "2011-10-23";
        out << YAML::EndMap;


    out << YAML::Key << "rootnode" << YAML::Value;
    base.Serialize(out);

    std::string yaml(out.c_str());

    std::cout << "Output YAML:" << std::endl << "========" << std::endl;
    std::cout << yaml << std::endl;

    std::cout << "Base:" << std::endl << "========" << std::endl;
    base.Display();
    
    std::istringstream stream;
    stream.str(yaml);

    YAML::Parser parser(stream);
    YAML::Node doc;
    parser.GetNextDocument(doc);
    Node* read = Node::Deserialize(doc["rootnode"]);
    std::cout << "Read:" << std::endl << "========" << std::endl;
    read->Display();



    return 0;
}