S
S
syxme2021-06-05 20:56:01
C++ / C#
syxme, 2021-06-05 20:56:01

Template class and method how to do?

I need to parse xml, create classes that will be described in xml and fill these classes with data from attributes.
How I see it:

template<typename SetMethod>
  struct XMLField{
    std::string field; // название поля xml атрибута
    SetMethod* method; // метод класса для установки значения из field;
    uint8_t type;	// тип данных, bool, string и тд.
  };

  template<typename ViewClass, typename method>
  struct ViewOptions{
    ViewClass* viewClass; // класс который будет создан при парсинге 
    std::vector<XMLField<method>> fields; // поля и методы этого класса 
  };

  static std::map<std::string ,ViewOptions<>> extendXml;

How can this be implemented?
Call methods if I will be something like this, through bind:
template<typename Method, typename... Args>
  void emit(Method&& method, Args&&... args){
    for (size_t i = 0; i < events.size(); i++){
      std::bind(method,events[i],std::forward<Args>(args)...)();
    }
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question