Jamba C++ API  5.1.1
DiscreteTypeParamSerializer< T, Compare > Class Template Reference

This converters maps a list of values of type T to discrete values. More...

#include <ParamSerializers.h>

Inherits IParamSerializer< T >, and IDiscreteConverter< T >.

Public Types

using ConstructorType = std::initializer_list< std::pair< const T, std::string > > const &
 Defines the type for the constructor argument. More...
 
using ParamType = T
 
using TList = std::vector< T >
 Defines the mapping: discrete value [0, stepCount] to T. More...
 
using TMap = std::map< T, std::pair< std::string, int32 >, Compare >
 Maintains the map of possible values of T (defined in constructor) More...
 
- Public Types inherited from IParamSerializer< T >
using ParamType = T
 

Public Member Functions

tresult convertFromDiscreteValue (int32 iDiscreteValue, ParamType &oValue) const override
 
tresult convertToDiscreteValue (ParamType const &iValue, int32 &oDiscreteValue) const override
 
 DiscreteTypeParamSerializer (ConstructorType iInitList)
 
int32 getStepCount () const override
 
tresult readFromStream (IBStreamer &iStreamer, ParamType &oValue) const override
 This method should read from the stream and populate oValue accordingly (aka deserialization) More...
 
tresult writeToStream (const ParamType &iValue, IBStreamer &oStreamer) const override
 This method should write iValue to the stream (aka serialization) More...
 
void writeToStream (ParamType const &iValue, std::ostream &oStream) const override
 By default, this implementation simply writes the value to the stream IF it is possible (determined at compilation time). More...
 
- Public Member Functions inherited from IParamSerializer< T >
virtual std::string toString (ParamType const &iValue, int32 iPrecision) const
 

Private Attributes

TList fList {}
 
TMap fMap {}
 

Detailed Description

template<typename T, class Compare = std::less<T>>
class pongasoft::VST::DiscreteTypeParamSerializer< T, Compare >

This converters maps a list of values of type T to discrete values.

It can be used with any T that is comparable (note that you can optionally provide your own Compare). For example, T can be an enum, enum class, struct, class, etc...

Example:

enum class ETabs {
kTabAll = 100,
kTabToggleButtonView = 150
};
// ...
JmbParam<ETabs> fTab;
// ...
fTab =
vst<DiscreteTypeParamConverter<ETabs>>(EJambaTestPluginParamID::kTab,
STR16("Tab"),
{
{ETabs::kTabAll, STR16("All Controls")},
{ETabs::kTabToggleButtonView, STR16("ToggleButton")},
})
.add();

Member Typedef Documentation

◆ ConstructorType

using ConstructorType = std::initializer_list<std::pair<const T, std::string> > const &

Defines the type for the constructor argument.

Example: { { t, "abc" }, ... }

◆ ParamType

using ParamType = T

◆ TList

using TList = std::vector<T>

Defines the mapping: discrete value [0, stepCount] to T.

◆ TMap

using TMap = std::map<T, std::pair<std::string, int32>, Compare>

Maintains the map of possible values of T (defined in constructor)

Constructor & Destructor Documentation

◆ DiscreteTypeParamSerializer()

Member Function Documentation

◆ convertFromDiscreteValue()

tresult convertFromDiscreteValue ( int32  iDiscreteValue,
ParamType oValue 
) const
inlineoverridevirtual

◆ convertToDiscreteValue()

tresult convertToDiscreteValue ( ParamType const &  iValue,
int32 &  oDiscreteValue 
) const
inlineoverridevirtual

◆ getStepCount()

int32 getStepCount ( ) const
inlineoverridevirtual

◆ readFromStream()

tresult readFromStream ( IBStreamer &  iStreamer,
ParamType oValue 
) const
inlineoverridevirtual

This method should read from the stream and populate oValue accordingly (aka deserialization)

Returns
kResultOk if reading was successful, kResultFalse otherwise (or kNotImplemented if not supported)

Reimplemented from IParamSerializer< T >.

◆ writeToStream() [1/2]

tresult writeToStream ( const ParamType iValue,
IBStreamer &  oStreamer 
) const
inlineoverridevirtual

This method should write iValue to the stream (aka serialization)

Returns
kResultOk if writing was successful, kResultFalse otherwise (or kNotImplemented if not supported)

Reimplemented from IParamSerializer< T >.

◆ writeToStream() [2/2]

void writeToStream ( ParamType const &  iValue,
std::ostream &  oStream 
) const
inlineoverridevirtual

By default, this implementation simply writes the value to the stream IF it is possible (determined at compilation time).

Doesn't do anything if not. Subclasses can redefine this behavior.

Reimplemented from IParamSerializer< T >.

Member Data Documentation

◆ fList

TList fList {}
private

◆ fMap

TMap fMap {}
private

The documentation for this class was generated from the following file: