Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::TaggedMap< Type, Union > Struct Template Reference

Map of SC::TaggedUnion, where the key is TaggedUnion enumeration value. More...

#include <TaggedMap.h>

Public Member Functions

template<Type enumType>
Union::template EnumToType< enumType >::type * getOrCreate ()
 
template<Type enumType>
bool set (const typename Union::template EnumToType< enumType >::type &obj)
 
template<Type enumType>
const Union::template EnumToType< enumType >::type * get () const
 
bool clear (Type enumType)
 
template<Type enumType, typename U >
bool hasValue (const U &obj) const
 

Public Attributes

VectorMap< Type, Union > flags
 

Detailed Description

template<typename Type, typename Union>
struct SC::TaggedMap< Type, Union >

Map of SC::TaggedUnion, where the key is TaggedUnion enumeration value.

Template Parameters
TypeEnumeration type used
Unionwith FieldTypes = TypeList<TaggedType<EnumType, EnumValue, Type>, ...>

Example:

namespace SC
{
// Create an arbitrary enumeration with some values
struct Compile
{
enum Type
{
libraryPath = 10,
enableRTTI = 110,
};
};
// Create the union definition containing a FieldTypes nested type
struct CompileFlags
{
// Helper to save some typing
template <Compile::Type E, typename T>
using Tag = TaggedType<Compile::Type, E, T>;
// FieldsTypes MUST be defined to be a TypeList of TaggedType(s)
using FieldsTypes = TypeTraits::TypeList< // List all associations between type and enumeration
Tag<Compile::libraryPath, String>, // Associate Compile::libraryPath with String
Tag<Compile::enableRTTI, bool>>; // Associate Compile::enableRTTI with bool type
using Union = TaggedUnion<CompileFlags>;
};
} // namespace SC
void SC::TaggedMapTest::basic()
{
TaggedMap<Compile::Type, CompileFlags::Union> taggedMap;
SC_TEST_EXPECT(taggedMap.get<Compile::libraryPath>() == nullptr);
*taggedMap.getOrCreate<Compile::libraryPath>() = "My String";
SC_TEST_EXPECT(*taggedMap.get<Compile::libraryPath>() == "My String");
SC_TEST_EXPECT(taggedMap.get<Compile::enableRTTI>() == nullptr);
*taggedMap.getOrCreate<Compile::enableRTTI>() = true;
SC_TEST_EXPECT(*taggedMap.get<Compile::enableRTTI>());
}
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:113

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