Permalink
Browse files

Did some work to make it compile in C++11 and C++03

    The default is C++03    which means std::auto_ptr<> for owned pointers.
    When using     C++11    this means std::unique_ptr<> for owned pointers.

    You can specify C++11 by setting the CXXSTDVER flag for make.

    This will build all libs with either 11 or 03 extension so they
    can live together in the destination directory.
  • Loading branch information...
1 parent 38d41cd commit 35321dff77aa2d465bffc48c8ec3299d07f0c91c Martin York committed May 17, 2012
View
@@ -2,6 +2,7 @@
#ifndef THORSANVIL_JSON_JSON_DOM
#define THORSANVIL_JSON_JSON_DOM
+#include "portability.h"
#include "JsonException.h"
#include <boost/ptr_container/ptr_vector.hpp>
@@ -48,7 +49,7 @@ struct JsonObject
JsonArray* array;
} data;
};
-typedef std::pair<std::auto_ptr<std::string>,std::auto_ptr<JsonValue> > JsonMapValue;
+typedef std::pair<SMART_OWNED_PTR<std::string>,SMART_OWNED_PTR<JsonValue> > JsonMapValue;
/*
* Json only supports three types:
@@ -117,17 +118,17 @@ struct JsonValue
};
struct JsonStringItem: JsonValue
{
- std::auto_ptr<std::string> value;
- JsonStringItem(std::auto_ptr<std::string>& data): value(data) {}
+ SMART_OWNED_PTR<std::string> value;
+ JsonStringItem(SMART_OWNED_PTR<std::string>& data): value(SMART_OWNED_MOVE(data)) {}
virtual void print(std::ostream& stream) const { stream << '"' << *value << '"'; }
private:
virtual void setValue(std::string& dst) const {dst = *value;}
};
struct JsonNumberItem: JsonValue
{
- std::auto_ptr<std::string> value;
- JsonNumberItem(std::auto_ptr<std::string>& data): value(data) {}
+ SMART_OWNED_PTR<std::string> value;
+ JsonNumberItem(SMART_OWNED_PTR<std::string>& data): value(SMART_OWNED_MOVE(data)) {}
virtual void print(std::ostream& stream) const { stream << *value; }
private:
@@ -154,16 +155,16 @@ struct JsonNULLItem: JsonValue
};
struct JsonMapItem: JsonValue
{
- std::auto_ptr<JsonMap> value;
- JsonMapItem(std::auto_ptr<JsonMap>& data): value(data) {}
+ SMART_OWNED_PTR<JsonMap> value;
+ JsonMapItem(SMART_OWNED_PTR<JsonMap>& data): value(SMART_OWNED_MOVE(data)) {}
virtual void print(std::ostream& stream) const { stream << *value; }
private:
};
struct JsonArrayItem: JsonValue
{
- std::auto_ptr<JsonArray> value;
- JsonArrayItem(std::auto_ptr<JsonArray>& data): value(data) {}
+ SMART_OWNED_PTR<JsonArray> value;
+ JsonArrayItem(SMART_OWNED_PTR<JsonArray>& data): value(SMART_OWNED_MOVE(data)) {}
virtual void print(std::ostream& stream) const { stream << *value; }
private:
View
@@ -111,14 +111,14 @@ struct ParserCleanInterface: ParserInterface
virtual void mapClose() {}
virtual JsonMap* mapCreate() { return NULL;}
virtual JsonMap* mapCreate(JsonMapValue* val) { delete val; return NULL;}
- virtual JsonMap* mapAppend(JsonMap* map, JsonMapValue* val) { std::auto_ptr<JsonMapValue> aval(val); delete map; return NULL;}
- virtual JsonMapValue* mapCreateElement(std::string* k,JsonValue* val) { std::auto_ptr<JsonValue> aval(val); delete k; return NULL;}
+ virtual JsonMap* mapAppend(JsonMap* map, JsonMapValue* val) { SMART_OWNED_PTR<JsonMapValue> aval(val); delete map; return NULL;}
+ virtual JsonMapValue* mapCreateElement(std::string* k,JsonValue* val) { SMART_OWNED_PTR<JsonValue> aval(val); delete k; return NULL;}
virtual std::string* mapKeyNote(std::string* k) { delete k; return NULL;}
virtual void arrayOpen() {}
virtual void arrayClose() {}
virtual JsonArray* arrayCreate() { return NULL;}
virtual JsonArray* arrayCreate(JsonValue* val) { delete val; return NULL;}
- virtual JsonArray* arrayAppend(JsonArray* arr, JsonValue* val) { std::auto_ptr<JsonArray> aarr(arr); delete val; return NULL;}
+ virtual JsonArray* arrayAppend(JsonArray* arr, JsonValue* val) { SMART_OWNED_PTR<JsonArray> aarr(arr); delete val; return NULL;}
virtual JsonArray* arrayNote(JsonArray* arr) { delete arr; return NULL;}
virtual JsonValue* arrayCreateElement(JsonValue* val) { delete val; return NULL;}
virtual JsonValue* valueParseMap(JsonMap* map) { delete map; return NULL;}
@@ -134,23 +134,23 @@ struct ParserCleanInterface: ParserInterface
struct ParserDomInterface: ParserCleanInterface
{
virtual JsonMap* mapCreate() { return new JsonMap();}
- virtual JsonMap* mapCreate(JsonMapValue* val) { std::auto_ptr<JsonMapValue>aval(val);std::auto_ptr<JsonMap> amap(new JsonMap());amap->insert(*(aval->first), aval->second);return amap.release();}
- virtual JsonMap* mapAppend(JsonMap* map, JsonMapValue* val) { std::auto_ptr<JsonMapValue>aval(val);std::auto_ptr<JsonMap> amap(map); amap->insert(*(aval->first), aval->second);return amap.release();}
- virtual JsonMapValue* mapCreateElement(std::string* k,JsonValue* val) { std::auto_ptr<JsonValue> aval(val);std::auto_ptr<std::string> ak(k);
- std::auto_ptr<JsonMapValue> result(new JsonMapValue);result->first = ak;result->second = aval;
+ virtual JsonMap* mapCreate(JsonMapValue* val) { SMART_OWNED_PTR<JsonMapValue>aval(val);SMART_OWNED_PTR<JsonMap> amap(new JsonMap());amap->insert(*(aval->first), aval->second.release());return amap.release();}
+ virtual JsonMap* mapAppend(JsonMap* map, JsonMapValue* val) { SMART_OWNED_PTR<JsonMapValue>aval(val);SMART_OWNED_PTR<JsonMap> amap(map); amap->insert(*(aval->first), aval->second.release());return amap.release();}
+ virtual JsonMapValue* mapCreateElement(std::string* k,JsonValue* val) { SMART_OWNED_PTR<JsonValue> aval(val);SMART_OWNED_PTR<std::string> ak(k);
+ SMART_OWNED_PTR<JsonMapValue> result(new JsonMapValue);result->first = SMART_OWNED_MOVE(ak);result->second = SMART_OWNED_MOVE(aval);
return result.release();
}
virtual std::string* mapKeyNote(std::string* k) { return k;}
virtual JsonArray* arrayCreate() { return new JsonArray();}
- virtual JsonArray* arrayCreate(JsonValue* val) { std::auto_ptr<JsonValue> aval(val);std::auto_ptr<JsonArray> aarr(new JsonArray());aarr->push_back(aval); return aarr.release();}
- virtual JsonArray* arrayAppend(JsonArray* arr, JsonValue* val) { std::auto_ptr<JsonValue> aval(val);std::auto_ptr<JsonArray> aarr(arr); aarr->push_back(aval); return aarr.release();}
+ virtual JsonArray* arrayCreate(JsonValue* val) { SMART_OWNED_PTR<JsonValue> aval(val);SMART_OWNED_PTR<JsonArray> aarr(new JsonArray());aarr->push_back(aval.release()); return aarr.release();}
+ virtual JsonArray* arrayAppend(JsonArray* arr, JsonValue* val) { SMART_OWNED_PTR<JsonValue> aval(val);SMART_OWNED_PTR<JsonArray> aarr(arr); aarr->push_back(aval.release()); return aarr.release();}
virtual JsonArray* arrayNote(JsonArray* arr) { return arr;}
- virtual JsonValue* arrayCreateElement(JsonValue* val) { std::auto_ptr<JsonValue> aval(val); return aval.release();}
+ virtual JsonValue* arrayCreateElement(JsonValue* val) { SMART_OWNED_PTR<JsonValue> aval(val); return aval.release();}
- virtual JsonValue* valueParseMap(JsonMap* map) { std::auto_ptr<JsonMap> amap(map); return new JsonMapItem(amap);}
- virtual JsonValue* valueParseArray(JsonArray* arr) { std::auto_ptr<JsonArray> aarr(arr); return new JsonArrayItem(aarr);}
- virtual JsonValue* valueParseString(std::string* str) { std::auto_ptr<std::string> astr(str); return new JsonStringItem(astr);}
- virtual JsonValue* valueParseNumber(std::string* num) { std::auto_ptr<std::string> anum(num); return new JsonNumberItem(anum);}
+ virtual JsonValue* valueParseMap(JsonMap* map) { SMART_OWNED_PTR<JsonMap> amap(map); return new JsonMapItem(amap);}
+ virtual JsonValue* valueParseArray(JsonArray* arr) { SMART_OWNED_PTR<JsonArray> aarr(arr); return new JsonArrayItem(aarr);}
+ virtual JsonValue* valueParseString(std::string* str) { SMART_OWNED_PTR<std::string> astr(str); return new JsonStringItem(astr);}
+ virtual JsonValue* valueParseNumber(std::string* num) { SMART_OWNED_PTR<std::string> anum(num); return new JsonNumberItem(anum);}
virtual JsonValue* valueParseBool(bool value) { return new JsonBoolItem(value);}
virtual JsonValue* valueParseNULL() { return new JsonNULLItem();}
View
@@ -10,20 +10,20 @@ int ParserRecursive::error(int /*val*/, std::string const& msg)
throw ThorsAnvil::Json::ParsingError(msg);
}
-int ParserRecursive::JsonValueParse(int val, std::auto_ptr<JsonValue>& value)
+int ParserRecursive::JsonValueParse(int val, SMART_OWNED_PTR<JsonValue>& value)
{
switch(val)
{
case '{': {
- std::auto_ptr<JsonMap> map;
+ SMART_OWNED_PTR<JsonMap> map;
int result = JsonMapParse(yylex(), map);
if (result == 0)
{ value.reset(pi.valueParseMap(map.release()));
}
return result;
}
case '[': {
- std::auto_ptr<JsonArray> array;
+ SMART_OWNED_PTR<JsonArray> array;
int result = JsonArrayParse(yylex(), array);
if (result == 0)
{ value.reset(pi.valueParseArray(array.release()));
@@ -39,18 +39,18 @@ int ParserRecursive::JsonValueParse(int val, std::auto_ptr<JsonValue>& value)
}
return error(val, "syntax error");
}
-int ParserRecursive::JsonMapValueListParse(int val, std::auto_ptr<JsonMap>& map)
+int ParserRecursive::JsonMapValueListParse(int val, SMART_OWNED_PTR<JsonMap>& map)
{
if (val == yy::ParserShiftReduce::token::JSON_STRING)
{
- std::auto_ptr<std::string> key(pi.getStringLexer(lexer));
+ SMART_OWNED_PTR<std::string> key(pi.getStringLexer(lexer));
if ((val = yylex()) == ':')
{
key.reset(pi.mapKeyNote(key.release()));
- std::auto_ptr<JsonValue> value;
+ SMART_OWNED_PTR<JsonValue> value;
if ((val = JsonValueParse(yylex(), value)) == 0)
{
- std::auto_ptr<JsonMapValue> mapValue(pi.mapCreateElement(key.release(), value.release()));
+ SMART_OWNED_PTR<JsonMapValue> mapValue(pi.mapCreateElement(key.release(), value.release()));
if (map.get() == NULL)
{
map.reset(pi.mapCreate(mapValue.release()));
@@ -72,9 +72,9 @@ int ParserRecursive::JsonMapValueListParse(int val, std::auto_ptr<JsonMap>& map)
return error(val, "syntax error");
}
-int ParserRecursive::JsonArrayValueListParse(int val, std::auto_ptr<JsonArray>& array)
+int ParserRecursive::JsonArrayValueListParse(int val, SMART_OWNED_PTR<JsonArray>& array)
{
- std::auto_ptr<JsonValue> value;
+ SMART_OWNED_PTR<JsonValue> value;
if ((val = JsonValueParse(val, value)) == 0)
{
value.reset(pi.arrayCreateElement(value.release()));
@@ -96,7 +96,7 @@ int ParserRecursive::JsonArrayValueListParse(int val, std::auto_ptr<JsonArray>&
}
return error(val, "syntax error");
}
-int ParserRecursive::JsonMapParse(int val, std::auto_ptr<JsonMap>& map)
+int ParserRecursive::JsonMapParse(int val, SMART_OWNED_PTR<JsonMap>& map)
{
pi.mapOpen();
int result;
@@ -112,7 +112,7 @@ int ParserRecursive::JsonMapParse(int val, std::auto_ptr<JsonMap>& map)
pi.mapClose();
return result;
}
-int ParserRecursive::JsonArrayParse(int val, std::auto_ptr<JsonArray>& array)
+int ParserRecursive::JsonArrayParse(int val, SMART_OWNED_PTR<JsonArray>& array)
{
pi.arrayOpen();
int result;
@@ -130,9 +130,9 @@ int ParserRecursive::JsonArrayParse(int val, std::auto_ptr<JsonArray>& array)
}
int ParserRecursive::parseJosnObject(int val)
{
- int result;
- std::auto_ptr<JsonMap> map;
- std::auto_ptr<JsonArray> array;
+ int result;
+ SMART_OWNED_PTR<JsonMap> map;
+ SMART_OWNED_PTR<JsonArray> array;
switch(val)
{
case '{': result = JsonMapParse(yylex(), map); pi.doneMap(map.release()); return result;
View
@@ -18,11 +18,11 @@ class ParserRecursive
LexerJson& lexer;
ParserInterface& pi;
- int JsonValueParse(int val, std::auto_ptr<JsonValue>& value);
- int JsonMapValueListParse(int val, std::auto_ptr<JsonMap>& ma);
- int JsonArrayValueListParse(int val, std::auto_ptr<JsonArray>& array);
- int JsonMapParse(int val, std::auto_ptr<JsonMap>& map);
- int JsonArrayParse(int val, std::auto_ptr<JsonArray>& array);
+ int JsonValueParse(int val, SMART_OWNED_PTR<JsonValue>& value);
+ int JsonMapValueListParse(int val, SMART_OWNED_PTR<JsonMap>& ma);
+ int JsonArrayValueListParse(int val, SMART_OWNED_PTR<JsonArray>& array);
+ int JsonMapParse(int val, SMART_OWNED_PTR<JsonMap>& map);
+ int JsonArrayParse(int val, SMART_OWNED_PTR<JsonArray>& array);
int parseJosnObject(int val);
int yylex() { return lexer.yylex(pi);}
View
@@ -8,11 +8,11 @@ using namespace ThorsAnvil::Json;
class ScannerDomInterface: public ParserDomInterface
{
- JsonObjectType& objectTypeRef;
- std::auto_ptr<JsonMap>& mapRef;
- std::auto_ptr<JsonArray>& arrayRef;
+ JsonObjectType& objectTypeRef;
+ SMART_OWNED_PTR<JsonMap>& mapRef;
+ SMART_OWNED_PTR<JsonArray>& arrayRef;
public:
- ScannerDomInterface(JsonObjectType& objectType, std::auto_ptr<JsonMap>& map, std::auto_ptr<JsonArray>& array)
+ ScannerDomInterface(JsonObjectType& objectType, SMART_OWNED_PTR<JsonMap>& map, SMART_OWNED_PTR<JsonArray>& array)
: objectTypeRef(objectType)
, mapRef(map)
, arrayRef(array)
View
@@ -12,15 +12,15 @@ namespace ThorsAnvil
class ScannerDom
{
- std::auto_ptr<JsonMap> map;
- std::auto_ptr<JsonArray> array;
- JsonObjectType objectType;
+ SMART_OWNED_PTR<JsonMap> map;
+ SMART_OWNED_PTR<JsonArray> array;
+ JsonObjectType objectType;
public:
template<typename Parser>
JsonObjectType parse(std::istream& stream);
- std::auto_ptr<JsonMap>& getMap() { return map;}
- std::auto_ptr<JsonArray>& getArray() { return array;}
+ SMART_OWNED_PTR<JsonMap>& getMap() { return map;}
+ SMART_OWNED_PTR<JsonArray>& getArray() { return array;}
};
}
}
Oops, something went wrong.

0 comments on commit 35321df

Please sign in to comment.