libdrmconf  0.12.0
A library to program DMR radios.
configmergevisitor.hh
1 #ifndef CONFIGMERGEVISITOR_HH
2 #define CONFIGMERGEVISITOR_HH
3 
4 #include "visitor.hh"
5 
6 class ConfigObject;
7 class RadioID;
8 class Channel;
9 class Contact;
10 class PositioningSystem;
11 class RoamingChannel;
13 class RXGroupList;
14 class Zone;
15 class ScanList;
16 class RoamingZone;
17 
18 
24 {
25 public:
28  enum class ItemStrategy {
29  Ignore,
30  Override,
31  Duplicate
32  };
33 
36  enum class SetStrategy {
37  Ignore,
38  Override,
39  Duplicate,
40  Merge
41  };
42 
43 public:
49  ConfigMergeVisitor(Config *destination, QHash<ConfigObject *, ConfigObject *> &translation,
51  SetStrategy setStrategy=SetStrategy::Ignore);
52 
53 
54  bool processItem(ConfigItem *item, const ErrorStack &err=ErrorStack());
55 
56 protected:
58  bool processRadioID(RadioID *item, const ErrorStack &err = ErrorStack());
60  bool processChannel(Channel *item, const ErrorStack &err = ErrorStack());
62  bool processContact(Contact *item, const ErrorStack &err = ErrorStack());
66  bool processRoamingChannel(RoamingChannel *item, const ErrorStack &err = ErrorStack());
68  bool processGroupList(RXGroupList *item, const ErrorStack &err = ErrorStack());
70  bool processZone(Zone *item, const ErrorStack &err = ErrorStack());
72  bool processScanList(ScanList *item, const ErrorStack &err = ErrorStack());
74  bool processRoamingZone(RoamingZone *item, const ErrorStack &err = ErrorStack());
75 
78  bool addObject(AbstractConfigObjectList *list, ConfigObject *present, ConfigObject *merging, const ErrorStack &err = ErrorStack());
80  bool ignoreObject(AbstractConfigObjectList *list, ConfigObject *present, ConfigObject *merging, const ErrorStack &err = ErrorStack());
84  bool replaceObject(AbstractConfigObjectList *list, ConfigObject *present, ConfigObject *merging, const ErrorStack &err = ErrorStack());
86  bool duplicateObject(AbstractConfigObjectList *list, ConfigObject *present, ConfigObject *merging, const ErrorStack &err = ErrorStack());
88  bool mergeList(ConfigObjectRefList *present, ConfigObjectRefList *merging, const ErrorStack &err = ErrorStack());
89 
90 protected:
94  QHash<ConfigObject *, ConfigObject *> &_translation;
99 };
100 
101 
105 {
106 public:
109  static bool mergeInto(Config *destination, Config *source,
112  const ErrorStack &err = ErrorStack());
113 
117  static Config *merge(Config *destination, Config *source,
120  const ErrorStack &err = ErrorStack());
121 };
122 
123 #endif // CONFIGMERGEVISITOR_HH
Generic list class for config objects.
Definition: configobject.hh:258
The base class of all channels (analog and digital) of a codeplug configuration.
Definition: channel.hh:34
Base class for all configuration objects (channels, zones, contacts, etc).
Definition: configobject.hh:40
Implements a visitor to merge the visited config into a given config.
Definition: configmergevisitor.hh:24
bool processRadioID(RadioID *item, const ErrorStack &err=ErrorStack())
Handles a RadioID object of the source configuration.
Definition: configmergevisitor.cc:50
bool duplicateObject(AbstractConfigObjectList *list, ConfigObject *present, ConfigObject *merging, const ErrorStack &err=ErrorStack())
Adds a copy of the merging object to the given list.
Definition: configmergevisitor.cc:299
bool addObject(AbstractConfigObjectList *list, ConfigObject *present, ConfigObject *merging, const ErrorStack &err=ErrorStack())
Adds a copy of the merging object to the given list, containing the colliding present object.
Definition: configmergevisitor.cc:252
QHash< ConfigObject *, ConfigObject * > & _translation
Translation table for fixing references.
Definition: configmergevisitor.hh:94
ItemStrategy _itemStrategy
The item merge strategy.
Definition: configmergevisitor.hh:96
ConfigMergeVisitor(Config *destination, QHash< ConfigObject *, ConfigObject * > &translation, ItemStrategy itemStrategy=ItemStrategy::Ignore, SetStrategy setStrategy=SetStrategy::Ignore)
Constructor of the merge visitor.
Definition: configmergevisitor.cc:13
bool processRoamingChannel(RoamingChannel *item, const ErrorStack &err=ErrorStack())
Handles a RoamingChannel object of the source configuration.
Definition: configmergevisitor.cc:134
bool processZone(Zone *item, const ErrorStack &err=ErrorStack())
Handles a Zone object of the source configuration.
Definition: configmergevisitor.cc:179
bool processChannel(Channel *item, const ErrorStack &err=ErrorStack())
Handles a Channel object of the source configuration.
Definition: configmergevisitor.cc:71
bool processRoamingZone(RoamingZone *item, const ErrorStack &err=ErrorStack())
Handles a RoamingZone object of the source configuration.
Definition: configmergevisitor.cc:228
SetStrategy
Possible strategies to merge sets of references.
Definition: configmergevisitor.hh:36
@ Override
Override the destination item.
@ Duplicate
Add a new set with a modified name.
@ Ignore
Ignore the source set.
bool processItem(ConfigItem *item, const ErrorStack &err=ErrorStack())
Traverses the specified config item.
Definition: configmergevisitor.cc:23
bool processPositioningSystem(PositioningSystem *item, const ErrorStack &err=ErrorStack())
Handles a PositioningSystem object of the source configuration.
Definition: configmergevisitor.cc:113
bool mergeList(ConfigObjectRefList *present, ConfigObjectRefList *merging, const ErrorStack &err=ErrorStack())
Merges two reference lists.
Definition: configmergevisitor.cc:317
bool processScanList(ScanList *item, const ErrorStack &err=ErrorStack())
Handles a ScanList object of the source configuration.
Definition: configmergevisitor.cc:204
bool processContact(Contact *item, const ErrorStack &err=ErrorStack())
Handles a Contact object of the source configuration.
Definition: configmergevisitor.cc:92
SetStrategy _setStrategy
The set merge strategy.
Definition: configmergevisitor.hh:98
bool ignoreObject(AbstractConfigObjectList *list, ConfigObject *present, ConfigObject *merging, const ErrorStack &err=ErrorStack())
Does not add the merging object, but fixes the translation table to bend references to the merging ob...
Definition: configmergevisitor.cc:271
bool processGroupList(RXGroupList *item, const ErrorStack &err=ErrorStack())
Handles a RXGroupList object of the source configuration.
Definition: configmergevisitor.cc:155
bool replaceObject(AbstractConfigObjectList *list, ConfigObject *present, ConfigObject *merging, const ErrorStack &err=ErrorStack())
Replaces the present object in the given list by a copy of merging object.
Definition: configmergevisitor.cc:282
ItemStrategy
Possible strategies to merge atomic items.
Definition: configmergevisitor.hh:28
@ Override
Override the destination item.
@ Duplicate
Add a new item with a modified name.
@ Ignore
Ignore the source item.
Config * _destination
The destination configuration.
Definition: configmergevisitor.hh:92
Just a namespace to provide merging functions.
Definition: configmergevisitor.hh:105
static Config * merge(Config *destination, Config *source, ConfigMergeVisitor::ItemStrategy itemStrategy=ConfigMergeVisitor::ItemStrategy::Ignore, ConfigMergeVisitor::SetStrategy setStrategy=ConfigMergeVisitor::SetStrategy::Ignore, const ErrorStack &err=ErrorStack())
Merges the given source into a copy of the given destination, using the specified strategies to handl...
Definition: configmergevisitor.cc:359
static bool mergeInto(Config *destination, Config *source, ConfigMergeVisitor::ItemStrategy itemStrategy=ConfigMergeVisitor::ItemStrategy::Ignore, ConfigMergeVisitor::SetStrategy setStrategy=ConfigMergeVisitor::SetStrategy::Ignore, const ErrorStack &err=ErrorStack())
Merges the given source into the given destination using the specified strategies to handle conflicts...
Definition: configmergevisitor.cc:336
List class for config objects.
Definition: configobject.hh:390
Base class of all labeled and named objects.
Definition: configobject.hh:199
The config class, representing the codeplug configuration.
Definition: config.hh:70
Represents the base-class for all contact types, analog (DTMF) or digital (DMR, M17).
Definition: contact.hh:18
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
Base class of the positioning systems, that is APRS and DMR position reporting system.
Definition: gpssystem.hh:17
Generic representation of a RX group list.
Definition: rxgrouplist.hh:14
Abstract base class for all radio IDs.
Definition: radioid.hh:15
Represents a roaming channel.
Definition: roamingchannel.hh:16
Represents a RoamingZone within the abstract device configuration.
Definition: roamingzone.hh:15
Generic representation of a scan list.
Definition: scanlist.hh:15
Base visitor class for the config tree.
Definition: visitor.hh:20
Represents a zone within the generic configuration.
Definition: zone.hh:15