Noise Modeler Library  0.1
Library for procedurally generating noise-based terrains and other content
 All Classes Files Functions Variables Enumerations Enumerator Groups Pages
graph.hpp
1 #ifndef NM_GRAPH_HPP
2 #define NM_GRAPH_HPP
3 
4 #include <nmlib/util.hpp>
5 #include <nmlib/util/signals.hpp>
6 
7 namespace nm {
8 
9 class Module;
10 class ModuleType;
11 
16 class Graph : public UserDataProvider, NonCopyable //TODO make copyable
17 {
18 public:
19  Graph():
20  m_modules{}
21  {}
22  ~Graph();
23  bool addModule(std::unique_ptr<Module> module);
24  Module* createModule(const ModuleType& type, std::string name);
25  Module* createModule(const ModuleType& type);
26  std::unique_ptr<Module> removeModule(Module& module);
27  void clearModules();
28  Module* getModule(const std::string &name);
29  const Module* getModule(const std::string &name) const;
30  Module *getModule(unsigned int index);
31  const Module *getModule(unsigned int index) const;
32  Module *findModule(std::function<bool(Module&)> predicative);
33  const Module *findModule(std::function<bool(const Module&)> predicative) const;
34  unsigned int numModules() const { return m_modules.size(); }
35  void traverseModulesTopological(std::function<void(const Module&)> callback) const;
36 
37  //signals
38  signal<void(Graph&)> destroying;
39  signal<void(Graph&, Module&, unsigned int)> moduleAdded;
40  signal<void(Graph&, Module&, unsigned int)> moduleRemoved;
41 
42 private:
43  std::vector<std::unique_ptr<Module>> m_modules;
44 
45 };
46 
47 } // namespace nm
48 
49 #endif // NM_GRAPH_HPP
Base class for stuff that needs to provide user data in form of a void* pointer.
Definition: userdataprovider.hpp:10
An instantiated ModuleType. A node in a function graph.
Definition: module.hpp:40
A graph of Modules.
Definition: graph.hpp:16
Describes a recipe for a module and its inputs and outputs.
Definition: moduletype.hpp:37
Utility headers.
A super-class for non-copyable classes.
Definition: noncopyable.hpp:10