Jamba  3.0.2
ParamTable.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 
19 #pragma once
20 
24 
25 #include "ParamDisplay.h"
26 
27 #include <string>
28 
29 namespace pongasoft {
30 namespace VST {
31 namespace Debug {
32 
37 {
38 public:
39  explicit ParamTable(ParamDisplay iParamDisplay) : fParamDisplay{std::move(iParamDisplay)} {}
40 
41 public:
42  // builder pattern to initialize the table
43  ParamTable &precision(int32 iPrecision) { fParamDisplay.precision(iPrecision); return *this; }
44  ParamTable &keys(std::vector<ParamDisplay::Key> const &iKeys) { fParamDisplay.keys(iKeys); return *this; };
45  ParamTable &key(ParamDisplay::Key iKey) { fParamDisplay.key(iKey); return *this; }
46  ParamTable &ids(std::vector<ParamID> const &iParamIDs) { fParamDisplay.ids(iParamIDs); return *this; };
47  ParamTable &id(ParamID iParamID) { fParamDisplay.id(iParamID); return *this; };
48  ParamTable &header(bool iDisplayHeader = true) { fDisplayHeader = iDisplayHeader; return *this; };
49  ParamTable &showHeader() { return header(true); };
50  ParamTable &hideHeader() { return header(false); };
51  ParamTable &headerSeparation(bool iDisplayHeaderSeparation = true) { fDisplayHeaderSeparation = iDisplayHeaderSeparation; return *this; };
54  ParamTable &lineSeparation(bool iDisplayLineSeparation = true) { fDisplayLineSeparation = iDisplayLineSeparation; return *this; };
57  ParamTable &cellSeparation(bool iDisplayCellSeparation = true) { fDisplayCellSeparation = iDisplayCellSeparation; return *this; };
60 
63 
64  // returns the table as a vector of rows
65  std::vector<std::string> rows() const;
66 
67  // returns a tabular representation of the params
68  std::string toString() const;
69 
70  // print the table
71  void print(std::string const &iFirstLine = "") const;
72 
73  // returns the table as a vector of rows
74  std::vector<std::string> rows(NormalizedState const &iNormalizedState) const;
75 
76  // returns a tabular representation of the params
77  std::string toString(NormalizedState const &iNormalizedState) const;
78 
79  // print the table
80  void print(NormalizedState const &iNormalizedState, std::string const &iFirstLine = "") const;
81 
82 protected:
83  // computeSizes
84  std::string::size_type computeSizes(ParamDisplay::ValueMap const &iHeader,
85  ParamDisplay::ParamMap const &iParams,
86  std::map<ParamDisplay::Key, std::string::size_type> &oSizes) const;
87 
88  // computeHeader
90 
91  // returns the table as a vector of rows
92  std::vector<std::string> rows(ParamDisplay::ParamMap const &iParamMap) const;
93 
94 public:
98  static ParamTable from(Parameters const &iParams);
99 
103  static ParamTable from(RT::RTState const *iState, bool iSaveStateOnly = false);
104 
108  static ParamTable from(GUI::GUIState const *iState, bool iSaveStateOnly = false);
109 
110 private:
111  bool fDisplayHeader{true};
115 
117 };
118 
119 }
120 }
121 }
122 
ParamTable & precision(int32 iPrecision)
Definition: ParamTable.h:43
ParamTable & showHeader()
Definition: ParamTable.h:49
ParamTable & keys(std::vector< ParamDisplay::Key > const &iKeys)
Definition: ParamTable.h:44
ParamDisplay & precision(int32 iPrecision)
Definition: ParamDisplay.h:67
ParamTable & lineSeparation(bool iDisplayLineSeparation=true)
Definition: ParamTable.h:54
Definition: Parameters.h:39
std::string toString() const
Definition: ParamTable.cpp:40
static ParamTable from(Parameters const &iParams)
Definition: ParamTable.cpp:241
ParamTable & id(ParamID iParamID)
Definition: ParamTable.h:47
Definition: GUIState.h:39
ParamDisplay fParamDisplay
Definition: ParamTable.h:116
ParamTable & full()
Definition: ParamTable.h:62
Definition: ParamDisplay.h:33
ParamDisplay & ids(std::vector< ParamID > const &iParamIDs)
Definition: ParamDisplay.h:70
ParamDisplay & key(Key iKey)
Definition: ParamDisplay.h:69
Definition: Clock.h:22
ParamTable & headerSeparation(bool iDisplayHeaderSeparation=true)
Definition: ParamTable.h:51
ParamTable & header(bool iDisplayHeader=true)
Definition: ParamTable.h:48
Definition: RTState.h:43
Definition: NormalizedState.h:38
ParamTable & cellSeparation(bool iDisplayCellSeparation=true)
Definition: ParamTable.h:57
ParamTable & showLineSeparation()
Definition: ParamTable.h:55
Definition: ParamTable.h:36
ParamDisplay & keys(std::vector< Key > const &iKeys)
Definition: ParamDisplay.h:68
ParamTable & showHeaderSeparation()
Definition: ParamTable.h:52
bool fDisplayHeaderSeparation
Definition: ParamTable.h:112
std::string::size_type computeSizes(ParamDisplay::ValueMap const &iHeader, ParamDisplay::ParamMap const &iParams, std::map< ParamDisplay::Key, std::string::size_type > &oSizes) const
Definition: ParamTable.cpp:202
bool fDisplayCellSeparation
Definition: ParamTable.h:114
std::vector< std::string > rows() const
Definition: ParamTable.cpp:134
ParamTable & hideCellSeparation()
Definition: ParamTable.h:59
bool fDisplayLineSeparation
Definition: ParamTable.h:113
Key
Definition: ParamDisplay.h:36
ParamTable & showCellSeparation()
Definition: ParamTable.h:58
ParamTable & hideLineSeparation()
Definition: ParamTable.h:56
ParamTable(ParamDisplay iParamDisplay)
Definition: ParamTable.h:39
ParamTable & key(ParamDisplay::Key iKey)
Definition: ParamTable.h:45
std::map< Key, Value > ValueMap
Definition: ParamDisplay.h:58
ParamTable & compact()
Definition: ParamTable.h:61
ParamTable & hideHeader()
Definition: ParamTable.h:50
ParamTable & hideHeaderSeparation()
Definition: ParamTable.h:53
void print(std::string const &iFirstLine="") const
Definition: ParamTable.cpp:59
bool fDisplayHeader
Definition: ParamTable.h:111
std::map< ParamID, ValueMap > ParamMap
Definition: ParamDisplay.h:59
ParamDisplay & id(ParamID iParamID)
Definition: ParamDisplay.h:71
ParamTable & ids(std::vector< ParamID > const &iParamIDs)
Definition: ParamTable.h:46
ParamDisplay::ValueMap computeHeader() const
Definition: ParamTable.cpp:187