Shaka Player Embedded
Classes | Namespaces | Macros
enum.h File Reference
#include <string>
#include <type_traits>
#include <vector>
#include "src/mapping/convert_js.h"
#include "src/mapping/js_wrappers.h"
#include "src/mapping/names.h"

Go to the source code of this file.

Classes

class  shaka::impl::StringEnumConverter< Enum >
 
struct  shaka::impl::NumberEnumConverter< Enum >
 
class  shaka::impl::EnumConverter< T >
 

Namespaces

 shaka
 
 shaka::impl
 

Macros

#define CONVERT_ENUM_AS_NUMBER(ns, type)
 
#define DEFINE_ENUM_MAPPING(ns, type)
 

Macro Definition Documentation

§ CONVERT_ENUM_AS_NUMBER

#define CONVERT_ENUM_AS_NUMBER (   ns,
  type 
)
Value:
template <> \
struct ::shaka::TypeName<ns::type, void> { \
static std::string name() { \
return #type; \
} \
}; \
template <> \
struct ::shaka::impl::ConvertHelper<ns::type> \
const char * name
ExceptionCode type

This file defines how to convert C++ enums. There are two kinds of (conceptual) enums: numbers and strings. Many browser API standards define JavaScript enums as possible string choices. The macros below allow defining the mapping between JavaScript values and the C++ enum values. Note that all these macros must be placed at the global namespace.

To indicate an enum should just be treated as numbers, simply add the following:

CONVERT_ENUM_AS_NUMBER(shaka::foo, MyEnumType);

To define an enum as string choices, add the following. Note that the macro defines |Enum| as an alias of the enum type:

DEFINE_ENUM_MAPPING(shaka::foo, MyEnumType) {
AddMapping(Enum::ENUM, "string");
AddMapping(Enum::OTHER, "any-valid-string");
}

Definition at line 52 of file enum.h.

§ DEFINE_ENUM_MAPPING

#define DEFINE_ENUM_MAPPING (   ns,
  type 
)
Value:
template <> \
struct ::shaka::TypeName<ns::type, void> { \
static std::string name() { \
return #type; \
} \
}; \
template <> \
class ::shaka::impl::EnumConverter<ns::type> \
: public ::shaka::impl::StringEnumConverter<ns::type> { \
public: \
using Enum = ns::type; \
EnumConverter(); \
}; \
template <> \
struct ::shaka::impl::ConvertHelper<ns::type> { \
static bool FromJsValue(Handle<JsValue> source, ns::type* dest) { \
return conv.FromJsValue(source, dest); \
} \
static ReturnVal<JsValue> ToJsValue(ns::type source) { \
return conv.ToJsValue(source); \
} \
}; \
inline ::shaka::impl::EnumConverter<ns::type>::EnumConverter()
const char * dest
Definition: media_utils.cc:31
bool FromJsValue(Handle< JsValue > source, T *dest)
Definition: convert_js.h:370
const char * name
ReturnVal< JsValue > ToJsValue(T &&source)
Definition: convert_js.h:381
const char * source
Definition: media_utils.cc:30
ExceptionCode type

Definition at line 63 of file enum.h.