Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change in how it works.

         All the macros now assume that the type they are working with is called `LocalType`
         This design changes is to minimise repetitive code.
         As this is a breaking change I am rolling the major version number.
         The previos version will be in a branch

         This means that code that looked like this:

            class MyClass
            {
                int          member1;
                double       member2;
                std::string  member3;

                friend class JsonSerializeTraits<MyClass>;
            };

            namespace ThorsAnvil { namespace Serialize { namespace Json {

            template<>
            class JsonSerializeTraits<MyClass>
            {
                static ThorsAnvil::Serialize::Json::JsonSerializeType const  type    = Map;

                THORSANVIL_SERIALIZE_JsonAttribute(MyClass, member1);
                THORSANVIL_SERIALIZE_JsonAttribute(MyClass, member2);
                THORSANVIL_SERIALIZE_JsonAttribute(MyClass, member3);
                typedef boost::mps::vector<member1, member2, member3>   SerializeInfo;
            };

            }}}
         Now needs to look like this:

            class MyClass
            {
                int          member1;
                double       member2;
                std::string  member3;

                friend class JsonSerializeTraits<MyClass>;
            };

            namespace ThorsAnvil { namespace Serialize { namespace Json {

            template<>
            class JsonSerializeTraits<MyClass>
            {
                // IMPORTANT:
                // Added a typedef here
                //
                typedef MyClass LocalType;
                static ThorsAnvil::Serialize::Json::JsonSerializeType const  type    = Map;

                // Now each of these items just needs to mention the members.
                // Thus making the macros easier to use.
                THORSANVIL_SERIALIZE_JsonAttribute(member1);
                THORSANVIL_SERIALIZE_JsonAttribute(member2);
                THORSANVIL_SERIALIZE_JsonAttribute(member3);
                typedef boost::mps::vector<member1, member2, member3>   SerializeInfo;
            };

            }}}
  • Loading branch information...
commit 925486d3ac4f9d284c5e6489f3beb2943b5a45d2 1 parent 7ac88fe
@martin-seomoz martin-seomoz authored
View
45 Serialize/JsonSerializer.h
@@ -21,7 +21,7 @@
* a member of the compound type.
*
* Boilerplate code to create the appropriate types for SerializeInfo.
- * #define THORSANVIL_SERIALIZE_JsonAttribute(className, member)
+ * #define THORSANVIL_SERIALIZE_JsonAttribute(member)
*
* Example:
* class MyClass
@@ -38,11 +38,12 @@
* template<>
* class JsonSerializeTraits<MyClass>
* {
+ * typedef LocalType;
* static ThorsAnvil::Serialize::Json::JsonSerializeType const type = Map;
*
- * THORSANVIL_SERIALIZE_JsonAttribute(MyClass, member1);
- * THORSANVIL_SERIALIZE_JsonAttribute(MyClass, member2);
- * THORSANVIL_SERIALIZE_JsonAttribute(MyClass, member3);
+ * THORSANVIL_SERIALIZE_JsonAttribute(member1);
+ * THORSANVIL_SERIALIZE_JsonAttribute(member2);
+ * THORSANVIL_SERIALIZE_JsonAttribute(member3);
* typedef boost::mps::vector<member1, member2, member3> SerializeInfo;
* };
* }}}
@@ -92,38 +93,38 @@
*THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess: A generic accessor used by for arrays rather than maps (std::vector)
* But otherwise identical to THORSANVIL_SERIALIZE_JsonGenericMapAttributeAccess
*/
-#define THORSANVIL_SERIALIZE_JsonAttribute(className, member) \
- typedef BOOST_TYPEOF(((className*)01)->member) JsonAttribute ## member ## Type; \
- THORSANVIL_SERIALIZE_JsonAttribute_1(className, member, JsonSerializeTraits<JsonAttribute ## member ## Type>)
-
-#define THORSANVIL_SERIALIZE_JsonAttribute_1(className, member, SerTraits) \
- typedef BOOST_TYPEOF(&className::member) JsonAttribute ## member ## TypePtr; \
- typedef JsonSerialElementAccessor<className, JsonAttribute ## member ## TypePtr, SerTraits> JsonAttribute ## member ## Accessor; \
- struct member: JsonSerializeItem<className, JsonAttribute ## member ## Accessor, std::string> \
+#define THORSANVIL_SERIALIZE_JsonAttribute(member) \
+ typedef BOOST_TYPEOF(((LocalType*)01)->member) JsonAttribute ## member ## Type; \
+ THORSANVIL_SERIALIZE_JsonAttribute_1(member, JsonSerializeTraits<JsonAttribute ## member ## Type>)
+
+#define THORSANVIL_SERIALIZE_JsonAttribute_1(member, SerTraits) \
+ typedef BOOST_TYPEOF(&LocalType::member) JsonAttribute ## member ## TypePtr; \
+ typedef JsonSerialElementAccessor<LocalType, JsonAttribute ## member ## TypePtr, SerTraits> JsonAttribute ## member ## Accessor; \
+ struct member: JsonSerializeItem<LocalType, JsonAttribute ## member ## Accessor, std::string> \
{ \
member() \
- : JsonSerializeItem<className, JsonAttribute ## member ## Accessor, std::string>(#member, &className::member) \
+ : JsonSerializeItem<LocalType, JsonAttribute ## member ## Accessor, std::string>(#member, &LocalType::member) \
{} \
}
-#define THORSANVIL_SERIALIZE_JsonAttributeAccess(className, member, accessor) \
- struct member: JsonSerializeItem<className, accessor, std::string> \
+#define THORSANVIL_SERIALIZE_JsonAttributeAccess(member, accessor) \
+ struct member: JsonSerializeItem<LocalType, accessor, std::string> \
{ \
member() \
- : JsonSerializeItem<className, accessor, std::string>(#member, accessor()) \
+ : JsonSerializeItem<LocalType, accessor, std::string>(#member, accessor()) \
{} \
}
-#define THORSANVIL_SERIALIZE_JsonGenericMapAttributeAccess(className, accessor) \
- struct genericAccessor: JsonSerializeItem<className, accessor, std::string> \
+#define THORSANVIL_SERIALIZE_JsonGenericMapAttributeAccess(accessor) \
+ struct genericAccessor: JsonSerializeItem<LocalType, accessor, std::string> \
{ \
genericAccessor() \
- : JsonSerializeItem<className, accessor, std::string>("\xFF", accessor()) \
+ : JsonSerializeItem<LocalType, accessor, std::string>("\xFF", accessor()) \
{} \
}
-#define THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(className, accessor) \
- struct genericAccessor: JsonSerializeItem<className, accessor, int> \
+#define THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(accessor) \
+ struct genericAccessor: JsonSerializeItem<LocalType, accessor, int> \
{ \
genericAccessor() \
- : JsonSerializeItem<className, accessor, int>(-1 , accessor()) \
+ : JsonSerializeItem<LocalType, accessor, int>(-1 , accessor()) \
{} \
}
View
2  Serialize/JsonSerializerDeQue.h
@@ -28,7 +28,7 @@ struct JsonSerializeTraits<std::deque<T> >
typedef std::deque<T> LocalType;
typedef JsonContainerAttributeAccessor<LocalType> Accessor;
- THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(LocalType, Accessor);
+ THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(Accessor);
typedef boost::mpl::vector<genericAccessor> SerializeInfo;
};
View
2  Serialize/JsonSerializerList.h
@@ -28,7 +28,7 @@ struct JsonSerializeTraits<std::list<T> >
typedef std::list<T> LocalType;
typedef JsonContainerAttributeAccessor<LocalType> Accessor;
- THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(LocalType, Accessor);
+ THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(Accessor);
typedef boost::mpl::vector<genericAccessor> SerializeInfo;
};
View
6 Serialize/JsonSerializerMap.h
@@ -37,11 +37,11 @@ struct ContainerTraits<std::map<K,V> >
template<typename K, typename V>
struct JsonSerializeTraits<std::map<K, V> >
{
+ typedef std::map<K, V> LocalType;
static JsonSerializeType const type = Array;
- typedef std::map<K, V> LocalType;
typedef JsonContainerAttributeAccessor<LocalType> Accessor;
- THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(LocalType, Accessor);
+ THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(Accessor);
typedef boost::mpl::vector<genericAccessor> SerializeInfo;
};
@@ -122,7 +122,7 @@ struct JsonSerializeTraits<std::map<std::string, V> >
typedef std::map<std::string, V> LocalType;
typedef JsonContainerAttributeAccessor<LocalType> Accessor;
- THORSANVIL_SERIALIZE_JsonGenericMapAttributeAccess(LocalType, Accessor);
+ THORSANVIL_SERIALIZE_JsonGenericMapAttributeAccess(Accessor);
typedef boost::mpl::vector<genericAccessor> SerializeInfo;
};
View
4 Serialize/JsonSerializerMemory.h
@@ -18,8 +18,8 @@ struct JsonSerializeTraits<std::pair<K,V> >
{
static JsonSerializeType const type = Map;
typedef std::pair<K, V> LocalType;
- THORSANVIL_SERIALIZE_JsonAttribute(LocalType, first);
- THORSANVIL_SERIALIZE_JsonAttribute(LocalType, second);
+ THORSANVIL_SERIALIZE_JsonAttribute(first);
+ THORSANVIL_SERIALIZE_JsonAttribute(second);
typedef boost::mpl::vector<first,second> SerializeInfo;
};
View
2  Serialize/JsonSerializerSet.h
@@ -27,7 +27,7 @@ struct JsonSerializeTraits<std::set<T> >
static JsonSerializeType const type = Array;
typedef std::set<T> LocalType;
typedef JsonContainerAttributeAccessor<LocalType> Accessor;
- THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(LocalType, Accessor);
+ THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(Accessor);
typedef boost::mpl::vector<genericAccessor> SerializeInfo;
};
View
2  Serialize/JsonSerializerVector.h
@@ -28,7 +28,7 @@ struct JsonSerializeTraits<std::vector<T> >
typedef std::vector<T> LocalType;
typedef JsonContainerAttributeAccessor<LocalType> Accessor;
- THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(LocalType, Accessor);
+ THORSANVIL_SERIALIZE_JsonGenericArrAttributeAccess(Accessor);
typedef boost::mpl::vector<genericAccessor> SerializeInfo;
};
View
45 Serialize/test/JsonSerilizeTest.cpp
@@ -156,8 +156,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<OneMemberJsonClass>
{
+ typedef OneMemberJsonClass LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(OneMemberJsonClass, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -178,8 +179,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<NestedJsonTest>
{
+ typedef NestedJsonTest LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(NestedJsonTest, nested);
+ THORSANVIL_SERIALIZE_JsonAttribute(nested);
typedef boost::mpl::vector<nested> SerializeInfo;
};
}}}
@@ -202,8 +204,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestFloat>
{
+ typedef TestFloat LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestFloat, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -226,8 +229,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestDouble>
{
+ typedef TestDouble LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestDouble, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -251,8 +255,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestShort>
{
+ typedef TestShort LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestShort, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -275,8 +280,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestInt>
{
+ typedef TestInt LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestInt, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -299,8 +305,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestLong>
{
+ typedef TestLong LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestLong, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -324,8 +331,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestLongLong>
{
+ typedef TestLongLong LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestLongLong, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -349,8 +357,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestUnsignedShort>
{
+ typedef TestUnsignedShort LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestUnsignedShort, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -373,8 +382,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestUnsignedInt>
{
+ typedef TestUnsignedInt LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestUnsignedInt, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -397,8 +407,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestUnsignedLong>
{
+ typedef TestUnsignedLong LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestUnsignedLong, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -422,8 +433,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestUnsignedLongLong>
{
+ typedef TestUnsignedLongLong LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestUnsignedLongLong, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -448,8 +460,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestBool>
{
+ typedef TestBool LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestBool, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -479,8 +492,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestString>
{
+ typedef TestString LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestString, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
@@ -503,8 +517,9 @@ namespace ThorsAnvil { namespace Serialize { namespace Json {
template<>
struct JsonSerializeTraits<TestPointer>
{
+ typedef TestPointer LocalType;
static JsonSerializeType const type = Map;
- THORSANVIL_SERIALIZE_JsonAttribute(TestPointer, value);
+ THORSANVIL_SERIALIZE_JsonAttribute(value);
typedef boost::mpl::vector<value> SerializeInfo;
};
}}}
Please sign in to comment.
Something went wrong with that request. Please try again.