There is a base class "model of a device", it includes classes describing the configuration of this device.

Class Conf1 { public: Conf1(): Name("C1"){} private: string Name; int mvalue; } Class Conf2 и Conf3 по подобию. Class Model { public: Model(): Name("M1"){} private: string Name; Conf1 c1; Conf2 c2; Conf3 c3; } 

It is necessary to somehow establish the affinity of configurations by the name of the model.

All CONFIGS have "Name" and "parameter", MODEL only "name". It is necessary in some way to assign these configurations to the corresponding model and to produce the output of configurations in this way.

 <person> <firstName>Иван</firstName> <lastName>Иванов</lastName> <phoneNumbers> <phoneNumber>812 123-1234</phoneNumber> <phoneNumber>916 123-4567</phoneNumber> </phoneNumbers> </person> 

I can display, I can not organize a hierarchy of nesting classes.

  • one
    "affiliation of configurations" is that, I hesitate to ask? - DreamChild
  • That is, such a set of configurations refers to the M1 model. Something must be organized: <person> <firstName> Ivan </ firstName> <lastName> Ivanov </ lastName> <phoneNumbers> <phoneNumber> 812 123-1234 </ phoneNumber> <phoneNumber> 916 123-4567 </ phoneNumber> </ phoneNumbers> </ person> Nesting as in nesting doll - NewSheriff
  • not very clear, to be honest. Well, make a Model class method that will return its configuration (s) - DreamChild
  • No, you didn't understand me a bit. Trying to reformulate the question ... - NewSheriff
  • need more details. - Abyx

1 answer 1

It is not very clear what you really need, so I will try to suggest ...

If you plan to add the "configuration" classes that describe a certain device to the "model" class, but you are going to do it dynamically, and at the stage of creating the "model" class, you are not yet sure which "configurations" classes will be included there, - create a base class for “configurations”, and in the “model” class use the list in which you will place instances of “configuration” classes suitable for describing this “model”.

 class BaseConfig {...} class Config1 : public BaseConfig {...} class Config2 : public BaseConfig {...} class Model { Model(): Name("M1"){} ... private: list<BaseConfig> my_conf; } 

Running through the list, it will be possible to display the parameters of the “configurations” classes, unless of course you remember to override the output operator for them.

configuration children by model name

Indeed, it is not clear what you meant. If you want to determine if there is a “configuration” class in some “model”, then you can implement a method of returning the name (or, perhaps, type names) of “configuration” in the “configuration” class, and go over the list in model ", compare the value returned by this method with the one that interests.

  • It is difficult to formulate the task. It consists in the formation of a container that contains all configuration objects. This container is inherited from the class implementing the composite data model. The composite model class is inherited from the Class providing an interface to the data model. With this interface, this container can be returned as we want. As I understand it, this is described in the Yang RFC 6020 protocol. Your sample solution is close, thanks anyway. - NewSheriff