Skip to content

Commit

Permalink
NOT_SET can serialize as "NOT SET" or "NOT_SET" (#412)
Browse files Browse the repository at this point in the history
* NOT_SET can be serialized as either "NOT SET" or "NET_SET"

* allow enum creation macros to be used elsewhere

* make it harder to get Enums wrong
  • Loading branch information
J. Daniel Smith authored Jan 30, 2021
1 parent d22cdb9 commit 1f671bb
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 243 deletions.
73 changes: 22 additions & 51 deletions six/modules/c++/cphd/include/cphd/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,18 @@ SIX_Enum_ENUM_3(DomainType,
*
* Enumeration used to represent PhaseSGNs
*/
struct PhaseSGN final : public six::details::Enum<PhaseSGN>
{
SIX_Enum_BEGIN_DEFINE(PhaseSGN)
//! The enumerations allowed
enum
{
SIX_Enum_BEGIN_enum
MINUS_1 = -1,
PLUS_1 = 1,
NOT_SET = six::NOT_SET_VALUE
};

static const map_t& string_to_int_()
{
static const map_t retval
{
{"-1", MINUS_1},
{"+1", PLUS_1},
SIX_Enum_map_entry_NOT_SET
};
return retval;
}

PhaseSGN() = default;
PhaseSGN(const std::string& s) : Enum(s) {}
PhaseSGN(int i) : Enum(i) {}
PhaseSGN& operator=(const int& o) { value = o; return *this; }
};
SIX_Enum_END_enum

SIX_Enum_BEGIN_string_to_int
{ "-1", MINUS_1 },
{ "+1", PLUS_1 },
SIX_Enum_END_string_to_int
SIX_Enum_END_DEFINE(PhaseSGN);

/*!
* \struct RefHeight
Expand Down Expand Up @@ -137,41 +122,27 @@ SIX_Enum_ENUM_4(SRPType,
*
* Enumeration used to represent PolarizationTypes
*/
struct PolarizationType final : public six::details::Enum<PolarizationType>
{
SIX_Enum_BEGIN_DEFINE(PolarizationType)
//! The enumerations allowed
enum
{
SIX_Enum_BEGIN_enum
X = 1,
Y = 2,
V = 3,
H = 4,
RHC = 5,
LHC = 6,
UNSPECIFIED = 7,
NOT_SET = six::NOT_SET_VALUE
};

static const map_t& string_to_int_()
{
static const map_t retval
{
SIX_Enum_map_entry_(X),
SIX_Enum_map_entry_(Y),
SIX_Enum_map_entry_(V),
SIX_Enum_map_entry_(H),
SIX_Enum_map_entry_(RHC),
SIX_Enum_map_entry_(LHC),
SIX_Enum_map_entry_(UNSPECIFIED),
SIX_Enum_map_entry_NOT_SET
};
return retval;
}

PolarizationType() = default;
PolarizationType(const std::string & s) : Enum(s) {}
PolarizationType(int i) : Enum(i) {}
PolarizationType& operator=(const int& o) { value = o; return *this; }
};
SIX_Enum_END_enum

SIX_Enum_BEGIN_string_to_int
SIX_Enum_map_entry_(X),
SIX_Enum_map_entry_(Y),
SIX_Enum_map_entry_(V),
SIX_Enum_map_entry_(H),
SIX_Enum_map_entry_(RHC),
SIX_Enum_map_entry_(LHC),
SIX_Enum_map_entry_(UNSPECIFIED),
SIX_Enum_END_string_to_int
SIX_Enum_END_DEFINE(PolarizationType);
}
#endif
131 changes: 30 additions & 101 deletions six/modules/c++/six.sidd/include/six/sidd/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,65 +33,36 @@ namespace sidd
*
* Enumeration used to represent ARPFlags
*/
struct ARPFlag final : public six::details::Enum<ARPFlag>
{
SIX_Enum_BEGIN_DEFINE(ARPFlag)
//! The enumerations allowed
enum
{
SIX_Enum_BEGIN_enum
REALTIME = 0,
PREDICTED = 1,
POST_PROCESSED = 2,
NOT_SET = six::NOT_SET_VALUE
};
SIX_Enum_END_enum

static const map_t& string_to_int_()
{
static const map_t retval
{
SIX_Enum_BEGIN_string_to_int
SIX_Enum_map_entry_(REALTIME),
SIX_Enum_map_entry_(PREDICTED),
{"POST PROCESSED", POST_PROCESSED },
SIX_Enum_map_entry_NOT_SET
};
return retval;
}

ARPFlag() = default;
ARPFlag(const std::string& s) : Enum(s) {}
ARPFlag(int i) : Enum(i) {}
ARPFlag& operator=(const int& o) { value = o; return *this; }
};
SIX_Enum_END_string_to_int
SIX_Enum_END_DEFINE(ARPFlag);

/*!
* \struct BandEqualizationAlgorithm
*
* Enumeration used to represent BandEqualizationAlgorithms
*/
struct BandEqualizationAlgorithm final : public six::details::Enum<BandEqualizationAlgorithm>
{
SIX_Enum_BEGIN_DEFINE(BandEqualizationAlgorithm)
//! The enumerations allowed
enum
{
SIX_Enum_BEGIN_enum
LUT_1D = 0,
NOT_SET = six::NOT_SET_VALUE
};
SIX_Enum_END_enum

static const map_t& string_to_int_()
{
static const map_t retval
{
SIX_Enum_BEGIN_string_to_int
{"LUT 1D", LUT_1D },
SIX_Enum_map_entry_NOT_SET
};
return retval;
}

BandEqualizationAlgorithm() = default;
BandEqualizationAlgorithm(const std::string& s) : Enum(s) {}
BandEqualizationAlgorithm(int i) : Enum(i) {}
BandEqualizationAlgorithm& operator=(const int& o) { value = o; return *this; }
};

SIX_Enum_END_string_to_int
SIX_Enum_END_DEFINE(BandEqualizationAlgorithm);

/*!
* \struct CoordinateSystemType
Expand Down Expand Up @@ -119,77 +90,49 @@ SIX_Enum_ENUM_3(DRAType,
*
* Enumeration used to represent DownsamplingMethods
*/
struct DownsamplingMethod final : public six::details::Enum<DownsamplingMethod>
{
SIX_Enum_BEGIN_DEFINE(DownsamplingMethod)
//! The enumerations allowed
enum
{
SIX_Enum_BEGIN_enum
DECIMATE = 0,
MAX_PIXEL = 1,
AVERAGE = 2,
NEAREST_NEIGHBOR = 3,
BILINEAR = 4,
LAGRANGE = 5,
NOT_SET = six::NOT_SET_VALUE
};
SIX_Enum_END_enum

static const map_t& string_to_int_()
{
static const map_t retval
{
SIX_Enum_BEGIN_string_to_int
SIX_Enum_map_entry_(DECIMATE),
{ "MAX PIXEL", MAX_PIXEL },
SIX_Enum_map_entry_(AVERAGE),
{ "NEAREST NEIGHBOR", NEAREST_NEIGHBOR },
SIX_Enum_map_entry_(BILINEAR),
SIX_Enum_map_entry_(LAGRANGE),
SIX_Enum_map_entry_NOT_SET
};
return retval;
}

DownsamplingMethod() = default;
DownsamplingMethod(const std::string & s) : Enum(s) {}
DownsamplingMethod(int i) : Enum(i) {}
DownsamplingMethod& operator=(const int& o) { value = o; return *this; }
};
SIX_Enum_END_string_to_int
SIX_Enum_END_DEFINE(DownsamplingMethod);


/*!
* \struct FilterDatabaseName
*
* Enumeration used to represent FilterDatabaseNames
*/
struct FilterDatabaseName final : public six::details::Enum<FilterDatabaseName>
{
SIX_Enum_BEGIN_DEFINE(FilterDatabaseName)
//! The enumerations allowed
enum
{
SIX_Enum_BEGIN_enum
BILINEAR = 0,
CUBIC = 1,
LAGRANGE = 2,
NEAREST_NEIGHBOR = 3,
NOT_SET = six::NOT_SET_VALUE
};
SIX_Enum_END_enum

static const map_t& string_to_int_()
{
static const map_t retval
{
SIX_Enum_BEGIN_string_to_int
SIX_Enum_map_entry_(BILINEAR),
SIX_Enum_map_entry_(CUBIC),
SIX_Enum_map_entry_(LAGRANGE),
{ "NEAREST NEIGHBOR", NEAREST_NEIGHBOR },
SIX_Enum_map_entry_NOT_SET
};
return retval;
}

FilterDatabaseName() = default;
FilterDatabaseName(const std::string& s) : Enum(s) {}
FilterDatabaseName(int i) : Enum(i) {}
FilterDatabaseName& operator=(const int& o) { value = o; return *this; }
};
SIX_Enum_END_string_to_int
SIX_Enum_END_DEFINE(FilterDatabaseName);

/*!
* \struct FilterOperation
Expand All @@ -206,36 +149,22 @@ SIX_Enum_ENUM_2(FilterOperation,
*
* Enumeration used to represent RenderingIntents
*/
struct RenderingIntent final : public six::details::Enum<RenderingIntent>
{
SIX_Enum_BEGIN_DEFINE(RenderingIntent)
//! The enumerations allowed
enum
{
SIX_Enum_BEGIN_enum
PERCEPTUAL = 0,
SATURATION = 1,
RELATIVE_INTENT = 2,
ABSOLUTE_INTENT = 3,
NOT_SET = six::NOT_SET_VALUE
};
SIX_Enum_END_enum

static const map_t& string_to_int_()
{
static const map_t retval
{
SIX_Enum_BEGIN_string_to_int
SIX_Enum_map_entry_(PERCEPTUAL),
SIX_Enum_map_entry_(SATURATION),
{ "RELATIVE INTENT", RELATIVE_INTENT },
{ "ABSOLUTE INTENT", ABSOLUTE_INTENT },
SIX_Enum_map_entry_NOT_SET
};
return retval;
}

RenderingIntent() = default;
RenderingIntent(const std::string& s) : Enum(s) {}
RenderingIntent(int i) : Enum(i) {}
RenderingIntent& operator=(const int& o) { value = o; return *this; }
};
SIX_Enum_END_string_to_int
SIX_Enum_END_DEFINE(RenderingIntent);

/*!
* \struct ShadowDirection
Expand Down
61 changes: 30 additions & 31 deletions six/modules/c++/six/include/six/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,40 +154,39 @@ namespace details


#define SIX_Enum_map_entry_(n) { #n, n }
#define SIX_Enum_map_entry_NOT_SET { "NOT SET", NOT_SET }
#define SIX_Enum_map_entry_NOT_SET SIX_Enum_map_entry_(NOT_SET), { "NOT SET", NOT_SET }

// Generate an enum class derived from details::Enum
// There are a few examples of expanded code below.
#define SIX_Enum_struct_1_(name) struct name final : public six::details::Enum<name> { \
name() = default; name(const std::string& s) : Enum(s) {} name(int i) : Enum(i) {} \
name& operator=(const int& o) { value = o; return *this; } enum {
#define SIX_Enum_struct_2_ NOT_SET = six::NOT_SET_VALUE }; \
static const map_t& string_to_int_() { \
static const map_t retval{
#define SIX_Enum_struct_3_ SIX_Enum_map_entry_NOT_SET }; return retval; } }


#define SIX_Enum_ENUM_STR_1(name, n, s, v) SIX_Enum_struct_1_(name) \
n = v, SIX_Enum_struct_2_ \
{s, n}, SIX_Enum_struct_3_
#define SIX_Enum_ENUM_1(name, n, v) SIX_Enum_ENUM_STR_1(name, n, #n, v)
#define SIX_Enum_ENUM_STR_2(name, n1, s1, v1, n2, s2, v2) SIX_Enum_struct_1_(name) \
n1 = v1, n2 = v2, SIX_Enum_struct_2_ \
{s1, n1}, {s2, n2}, SIX_Enum_struct_3_
#define SIX_Enum_ENUM_2(name, n1, v1, n2, v2) \
SIX_Enum_ENUM_STR_2(name, n1, #n1, v1, n2, #n2, v2)
#define SIX_Enum_ENUM_3(name, n1, v1, n2, v2, n3, v3) SIX_Enum_struct_1_(name) \
n1 = v1, n2 = v2, n3 = v3, SIX_Enum_struct_2_ \
SIX_Enum_map_entry_(n1), SIX_Enum_map_entry_(n2), SIX_Enum_map_entry_(n3), SIX_Enum_struct_3_
#define SIX_Enum_ENUM_STR_4(name, n1, s1, v1, n2, s2, v2, n3, s3, v3, n4, s4, v4) SIX_Enum_struct_1_(name) \
n1 = v1, n2 = v2, n3 = v3, n4 = v4, SIX_Enum_struct_2_ \
{s1, n1}, {s2, n2}, {s3, n3}, {s4, n4}, SIX_Enum_struct_3_
#define SIX_Enum_ENUM_4(name, n1, v1, n2, v2, n3, v3, n4, v4) \
SIX_Enum_ENUM_STR_4(name, n1, #n1, v1, n2, #n2, v2, n3, #n3, v3, n4, #n4, v4)
#define SIX_Enum_ENUM_5(name, n1, v1, n2, v2, n3, v3, n4, v4, n5, v5) SIX_Enum_struct_1_(name) \
n1 = v1, n2 = v2, n3 = v3, n4 = v4, n5 = v5, SIX_Enum_struct_2_ \
SIX_Enum_map_entry_(n1), SIX_Enum_map_entry_(n2), SIX_Enum_map_entry_(n3), SIX_Enum_map_entry_(n4), SIX_Enum_map_entry_(n5), \
SIX_Enum_struct_3_
#define SIX_Enum_constructors_(name) name() = default; name(const std::string& s) : Enum(s) {} name(int i) : Enum(i) {} \
name& operator=(const int& o) { value = o; return *this; }
#define SIX_Enum_BEGIN_enum enum {
#define SIX_Enum_BEGIN_DEFINE(name) struct name final : public six::details::Enum<name> {
#define SIX_Enum_END_DEFINE(name) SIX_Enum_constructors_(name); }
#define SIX_Enum_BEGIN_string_to_int static const map_t& string_to_int_() { static const map_t retval {
#define SIX_Enum_END_enum NOT_SET = six::NOT_SET_VALUE };
#define SIX_Enum_END_string_to_int SIX_Enum_map_entry_NOT_SET }; return retval; }

#define SIX_Enum_ENUM_begin_(name) SIX_Enum_BEGIN_DEFINE(name) SIX_Enum_constructors_(name); SIX_Enum_BEGIN_enum
#define SIX_Enum_ENUM_1_ SIX_Enum_END_enum SIX_Enum_BEGIN_string_to_int
#define SIX_Enum_ENUM_end_ SIX_Enum_END_string_to_int }

#define SIX_Enum_ENUM_1(name, n, v) SIX_Enum_ENUM_begin_(name) \
n = v, SIX_Enum_ENUM_1_ SIX_Enum_map_entry_(n), SIX_Enum_ENUM_end_
#define SIX_Enum_ENUM_2(name, n1, v1, n2, v2) SIX_Enum_ENUM_begin_(name) \
n1 = v1, n2 = v2, SIX_Enum_ENUM_1_ SIX_Enum_map_entry_(n1), \
SIX_Enum_map_entry_(n2), SIX_Enum_ENUM_end_
#define SIX_Enum_ENUM_3(name, n1, v1, n2, v2, n3, v3) SIX_Enum_ENUM_begin_(name) \
n1 = v1, n2 = v2, n3 = v3, SIX_Enum_ENUM_1_ SIX_Enum_map_entry_(n1), \
SIX_Enum_map_entry_(n2), SIX_Enum_map_entry_(n3), SIX_Enum_ENUM_end_
#define SIX_Enum_ENUM_4(name, n1, v1, n2, v2, n3, v3, n4, v4) SIX_Enum_ENUM_begin_(name) \
n1 = v1, n2 = v2, n3 = v3, n4 = v4, SIX_Enum_ENUM_1_ \
SIX_Enum_map_entry_(n1), SIX_Enum_map_entry_(n2), SIX_Enum_map_entry_(n3), \
SIX_Enum_map_entry_(n4), SIX_Enum_ENUM_end_
#define SIX_Enum_ENUM_5(name, n1, v1, n2, v2, n3, v3, n4, v4, n5, v5) SIX_Enum_ENUM_begin_(name) \
n1 = v1, n2 = v2, n3 = v3, n4 = v4, n5 = v5, SIX_Enum_ENUM_1_ \
SIX_Enum_map_entry_(n1), SIX_Enum_map_entry_(n2), SIX_Enum_map_entry_(n3), \
SIX_Enum_map_entry_(n4), SIX_Enum_map_entry_(n5), SIX_Enum_ENUM_end_
} // namespace details
}
#endif // SIX_SIX_Enum_h_INCLUDED_
Loading

0 comments on commit 1f671bb

Please sign in to comment.