Jamba  3.2.0
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>
28 
29 namespace pongasoft {
30 namespace VST {
31 namespace GUI {
32 
33 using namespace VSTGUI;
34 using namespace Params;
35 
88 class ViewCxMgr : private IViewListenerAdapter
89 {
90 public:
97  template<typename TView>
98  ViewGUIParamCxAware<TView> *registerConnectionFor(TView *iView, GUIState *iGUIState);
99 
103  void closeAll();
104 
105 private:
109  void viewWillDelete(CView *iView) override;
110 
111 private:
112  std::unordered_map<CView *, std::unique_ptr<GUIParamCxAware>> fViewConnections{};
113 };
114 
115 //------------------------------------------------------------------------
116 // ViewCxMgr::registerConnectionFor
117 //------------------------------------------------------------------------
118 template<typename TView>
120 {
121  if(iView == nullptr)
122  return nullptr;
123 
124  auto iter = fViewConnections.find(iView);
125 
126  if(iter == fViewConnections.end())
127  {
128  iView->registerViewListener(this);
129  fViewConnections[iView] = std::make_unique<ViewGUIParamCxAware<TView>>(iView);
130  fViewConnections[iView]->initState(iGUIState);
131  }
132 
133  return static_cast<ViewGUIParamCxAware<TView> *>(fViewConnections[iView].get());
134 }
135 
136 
137 }
138 }
139 }
Definition: GUIState.h:39
Definition: Clock.h:22
Definition: GUIParamCxAware.h:299
Definition: Types.h:29
Definition: ViewCxMgr.h:88
ViewGUIParamCxAware< TView > * registerConnectionFor(TView *iView, GUIState *iGUIState)
Definition: ViewCxMgr.h:119