Jamba  3.0.2
ViewCxMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 pongasoft
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 #pragma once
19 
20 #include <unordered_map>
21 #include <vector>
23 #include <vstgui4/vstgui/lib/iviewlistener.h>
27 
28 namespace pongasoft {
29 namespace VST {
30 namespace GUI {
31 
32 using namespace VSTGUI;
33 using namespace Params;
34 
87 class ViewCxMgr : private IViewListenerAdapter
88 {
89 public:
96  template<typename TView>
97  ViewGUIParamCxAware<TView> *registerConnectionFor(TView *iView, GUIState *iGUIState);
98 
102  void closeAll();
103 
104 private:
108  void viewWillDelete(CView *iView) override;
109 
110 private:
111  std::unordered_map<CView *, std::unique_ptr<GUIParamCxAware>> fViewConnections{};
112 };
113 
114 //------------------------------------------------------------------------
115 // ViewCxMgr::registerConnectionFor
116 //------------------------------------------------------------------------
117 template<typename TView>
119 {
120  if(iView == nullptr)
121  return nullptr;
122 
123  auto iter = fViewConnections.find(iView);
124 
125  if(iter == fViewConnections.end())
126  {
127  iView->registerViewListener(this);
128  fViewConnections[iView] = std::make_unique<ViewGUIParamCxAware<TView>>(iView);
129  fViewConnections[iView]->initState(iGUIState);
130  }
131 
132  return static_cast<ViewGUIParamCxAware<TView> *>(fViewConnections[iView].get());
133 }
134 
135 
136 }
137 }
138 }
Definition: GUIState.h:39
Definition: Clock.h:22
Definition: GUIParamCxAware.h:277
Definition: ViewCxMgr.h:87
ViewGUIParamCxAware< TView > * registerConnectionFor(TView *iView, GUIState *iGUIState)
Definition: ViewCxMgr.h:118