1 #pragma once
2 
3 #ifndef TPARAMCONTAINER_INCLUDED
4 #define TPARAMCONTAINER_INCLUDED
5 
6 #include <memory>
7 
8 #include "tparam.h"
9 //#include "tfx.h"
10 #include "tcommon.h"
11 
12 #undef DVAPI
13 #undef DVVAR
14 #ifdef TPARAM_EXPORTS
15 #define DVAPI DV_EXPORT_API
16 #define DVVAR DV_EXPORT_VAR
17 #else
18 #define DVAPI DV_IMPORT_API
19 #define DVVAR DV_IMPORT_VAR
20 #endif
21 
22 class TIStream;
23 class TOStream;
24 class TParamObserver;
25 class TParam;
26 
27 class DVAPI TParamVar {
28   std::string m_name;
29   bool m_isHidden;
30   // Flag for an obsolete parameter used for maintaining backward-compatiblity.
31   // - The obsolete parameter will call a special function
32   // (TFx::onObsoleteParameterLoaded) on loaded which enables to do some special
33   // action. (e.g. converting to a new parameter etc.)
34   // - The obsolete parameter will not be saved.
35   bool m_isObsolete;
36   TParamObserver *m_paramObserver;
37 
38 public:
39   TParamVar(std::string name, bool hidden = false, bool obsolete = false)
m_name(name)40       : m_name(name)
41       , m_isHidden(hidden)
42       , m_isObsolete(obsolete)
43       , m_paramObserver(0) {}
~TParamVar()44   virtual ~TParamVar() {}
45   virtual TParamVar *clone() const = 0;
getName()46   std::string getName() const { return m_name; }
isHidden()47   bool isHidden() const { return m_isHidden; }
setIsHidden(bool hidden)48   void setIsHidden(bool hidden) { m_isHidden = hidden; }
isObsolete()49   bool isObsolete() const { return m_isObsolete; }
50   virtual void setParam(TParam *param) = 0;
51   virtual TParam *getParam() const     = 0;
52   void setParamObserver(TParamObserver *obs);
53 };
54 
55 template <class T>
56 class TParamVarT final : public TParamVar {
57   // Very dirty fix for link fx, separating the variable between the plugin fx
58   // and the built-in fx.
59   // Note that for now link fx is available only with built-in fx, since m_var
60   // must be "pointer to pointer" of parameter to make the link fx to work
61   // properly.
62   T *m_var            = nullptr;
63   TParamP m_pluginVar = 0;
64 
65 public:
66   TParamVarT(std::string name, T *var = nullptr, TParamP pluginVar = 0,
67              bool hidden = false, bool obsolete = false)
TParamVar(name,hidden)68       : TParamVar(name, hidden), m_var(var), m_pluginVar(pluginVar) {}
69   TParamVarT() = delete;
setParam(TParam * param)70   void setParam(TParam *param) {
71     if (m_var)
72       *m_var = TParamP(param);
73     else
74       m_pluginVar = TParamP(param);
75   }
getParam()76   virtual TParam *getParam() const {
77     if (m_var)
78       return m_var->getPointer();
79     else
80       return m_pluginVar.getPointer();
81   }
clone()82   TParamVar *clone() const {
83     return new TParamVarT<T>(getName(), m_var, m_pluginVar, isHidden());
84   }
85 };
86 
87 class DVAPI TParamContainer {
88   class Imp;
89   std::unique_ptr<Imp> m_imp;
90 
91 public:
92   TParamContainer();
93   ~TParamContainer();
94 
95   void add(TParamVar *var);
96 
97   int getParamCount() const;
98 
99   bool isParamHidden(int index) const;
100 
101   TParam *getParam(int index) const;
102   std::string getParamName(int index) const;
103   TParam *getParam(std::string name) const;
104   TParamVar *getParamVar(std::string name) const;
105   const TParamVar *getParamVar(int index) const;
106 
107   void unlink();
108   void link(const TParamContainer *src);
109   void copy(const TParamContainer *src);
110 
111   void setParamObserver(TParamObserver *);
112   TParamObserver *getParamObserver() const;
113 
114 private:
115   TParamContainer(const TParamContainer &);
116   TParamContainer &operator=(const TParamContainer &);
117 };
118 
119 #endif
120