2013-10-31 16:59:18 +00:00
|
|
|
#ifndef LAYERS_H
|
|
|
|
#define LAYERS_H
|
|
|
|
|
|
|
|
#include "definition_global.h"
|
2013-11-16 18:12:42 +00:00
|
|
|
|
2015-08-12 20:21:10 +00:00
|
|
|
#include "DefinitionNode.h"
|
2013-10-31 16:59:18 +00:00
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace definition {
|
|
|
|
|
2015-12-10 23:36:50 +00:00
|
|
|
typedef DefinitionNode *(*LayerConstructor)(Layers *parent, const string &name);
|
2013-10-31 16:59:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Layers of definitions, ideally all of the same type.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class DEFINITIONSHARED_EXPORT Layers : public DefinitionNode {
|
|
|
|
public:
|
2015-12-10 23:36:50 +00:00
|
|
|
Layers(DefinitionNode *parent, const string &name, LayerConstructor layer_constructor);
|
2013-10-31 16:59:18 +00:00
|
|
|
virtual ~Layers();
|
|
|
|
|
2015-08-13 17:49:16 +00:00
|
|
|
virtual void save(PackStream *stream) const override;
|
|
|
|
virtual void load(PackStream *stream) override;
|
2015-11-09 21:30:46 +00:00
|
|
|
virtual void copy(DefinitionNode *destination) const override;
|
2013-10-31 16:59:18 +00:00
|
|
|
|
2015-11-20 00:07:31 +00:00
|
|
|
virtual bool applyDiff(const DefinitionDiff *diff, bool backward = false) override;
|
2015-12-10 23:36:50 +00:00
|
|
|
virtual void generateInitDiffs(vector<const DefinitionDiff *> *diffs) const override;
|
2015-11-20 00:07:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximal layer count allowed.
|
|
|
|
*/
|
2013-10-31 16:59:18 +00:00
|
|
|
void setMaxLayerCount(int max_layer_count);
|
|
|
|
|
2015-11-20 00:07:31 +00:00
|
|
|
/**
|
|
|
|
* Get the current layer count.
|
|
|
|
*/
|
|
|
|
int getLayerCount() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a layer by its position.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
DefinitionNode *getLayer(int position) const;
|
2013-10-31 16:59:18 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-20 00:07:31 +00:00
|
|
|
* Retrieve a layer by its name.
|
|
|
|
*/
|
2015-12-10 23:36:50 +00:00
|
|
|
DefinitionNode *getLayer(const string &name) const;
|
2015-11-20 00:07:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new empty layer.
|
|
|
|
*/
|
2015-12-10 23:36:50 +00:00
|
|
|
void addLayer(const string &name);
|
2015-11-20 00:07:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new layer, copying another node into it.
|
|
|
|
*/
|
|
|
|
void addLayer(const DefinitionNode &tocopy);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a layer by its position.
|
2013-10-31 16:59:18 +00:00
|
|
|
*/
|
|
|
|
void removeLayer(int position);
|
|
|
|
|
2015-11-20 00:07:31 +00:00
|
|
|
/**
|
|
|
|
* Clear this node of all layers.
|
|
|
|
*/
|
|
|
|
void clear();
|
2015-08-13 21:46:50 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
public:
|
2013-11-16 18:12:42 +00:00
|
|
|
LayerConstructor layer_constructor;
|
2013-10-31 16:59:18 +00:00
|
|
|
int max_layer_count;
|
2015-12-10 23:36:50 +00:00
|
|
|
vector<DefinitionNode *> layers;
|
2015-11-09 21:30:46 +00:00
|
|
|
DefinitionNode *null_layer;
|
2013-10-31 16:59:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // LAYERS_H
|