diff --git a/Foundation/Foundation_vs71.vcproj b/Foundation/Foundation_vs71.vcproj
index 4f6e601cf..6eb0ac20a 100644
--- a/Foundation/Foundation_vs71.vcproj
+++ b/Foundation/Foundation_vs71.vcproj
@@ -265,6 +265,9 @@
+
+
@@ -584,6 +587,9 @@
+
+
diff --git a/Foundation/Foundation_vs80.vcproj b/Foundation/Foundation_vs80.vcproj
index b9d2175c2..7d8fc2fa0 100644
--- a/Foundation/Foundation_vs80.vcproj
+++ b/Foundation/Foundation_vs80.vcproj
@@ -1,7 +1,7 @@
+
+
@@ -803,6 +807,10 @@
RelativePath=".\include\Poco\DynamicFactory.h"
>
+
+
diff --git a/Foundation/Makefile b/Foundation/Makefile
index de3795579..480846862 100644
--- a/Foundation/Makefile
+++ b/Foundation/Makefile
@@ -1,7 +1,7 @@
#
# Makefile
#
-# $Id: //poco/Main/Foundation/Makefile#44 $
+# $Id: //poco/Main/Foundation/Makefile#45 $
#
# Makefile for Poco Foundation
#
@@ -29,7 +29,7 @@ objects = ArchiveStrategy ASCIIEncoding AsyncChannel Base64Decoder Base64Encoder
ThreadPool ActiveDispatcher Timer Timespan Timestamp Timezone Token URI \
FileStreamFactory URIStreamFactory URIStreamOpener UTF16Encoding Windows1252Encoding \
UTF8Encoding UnicodeConverter UUID UUIDGenerator Void Format \
- Pipe PipeImpl PipeStream DynamicAny DynamicAnyHolder SharedMemory \
+ Pipe PipeImpl PipeStream DynamicAny DynamicAnyHolder DynamicStruct SharedMemory \
FileStream Unicode UTF8String \
AsyncIOCommand AsyncIOEvent AsyncIOChannel AsyncStreamChannel \
adler32 compress crc32 deflate gzio infback inffast inflate inftrees \
diff --git a/Foundation/include/Poco/Base64Decoder.h b/Foundation/include/Poco/Base64Decoder.h
index b7e11afbf..a1ec70d75 100644
--- a/Foundation/include/Poco/Base64Decoder.h
+++ b/Foundation/include/Poco/Base64Decoder.h
@@ -1,7 +1,7 @@
//
// Base64Decoder.h
//
-// $Id: //poco/Main/Foundation/include/Poco/Base64Decoder.h#2 $
+// $Id: //poco/Main/Foundation/include/Poco/Base64Decoder.h#3 $
//
// Library: Foundation
// Package: Streams
@@ -67,6 +67,10 @@ private:
static unsigned char IN_ENCODING[256];
static bool IN_ENCODING_INIT;
+
+private:
+ Base64DecoderBuf(const Base64DecoderBuf&);
+ Base64DecoderBuf& operator = (const Base64DecoderBuf&);
};
@@ -83,6 +87,10 @@ public:
protected:
Base64DecoderBuf _buf;
+
+private:
+ Base64DecoderIOS(const Base64DecoderIOS&);
+ Base64DecoderIOS& operator = (const Base64DecoderIOS&);
};
@@ -93,6 +101,10 @@ class Foundation_API Base64Decoder: public Base64DecoderIOS, public std::istream
public:
Base64Decoder(std::istream& istr);
~Base64Decoder();
+
+private:
+ Base64Decoder(const Base64Decoder&);
+ Base64Decoder& operator = (const Base64Decoder&);
};
diff --git a/Foundation/include/Poco/Base64Encoder.h b/Foundation/include/Poco/Base64Encoder.h
index 2d62d8e57..5cb4bfaae 100644
--- a/Foundation/include/Poco/Base64Encoder.h
+++ b/Foundation/include/Poco/Base64Encoder.h
@@ -1,7 +1,7 @@
//
// Base64Encoder.h
//
-// $Id: //poco/Main/Foundation/include/Poco/Base64Encoder.h#3 $
+// $Id: //poco/Main/Foundation/include/Poco/Base64Encoder.h#4 $
//
// Library: Foundation
// Package: Streams
@@ -83,6 +83,9 @@ private:
static const unsigned char OUT_ENCODING[64];
friend class Base64DecoderBuf;
+
+ Base64EncoderBuf(const Base64EncoderBuf&);
+ Base64EncoderBuf& operator = (const Base64EncoderBuf&);
};
@@ -100,6 +103,10 @@ public:
protected:
Base64EncoderBuf _buf;
+
+private:
+ Base64EncoderIOS(const Base64EncoderIOS&);
+ Base64EncoderIOS& operator = (const Base64EncoderIOS&);
};
@@ -114,6 +121,10 @@ class Foundation_API Base64Encoder: public Base64EncoderIOS, public std::ostream
public:
Base64Encoder(std::ostream& ostr);
~Base64Encoder();
+
+private:
+ Base64Encoder(const Base64Encoder&);
+ Base64Encoder& operator = (const Base64Encoder&);
};
diff --git a/Foundation/include/Poco/BufferedBidirectionalStreamBuf.h b/Foundation/include/Poco/BufferedBidirectionalStreamBuf.h
index 7af808fc6..c14aea0a3 100644
--- a/Foundation/include/Poco/BufferedBidirectionalStreamBuf.h
+++ b/Foundation/include/Poco/BufferedBidirectionalStreamBuf.h
@@ -1,7 +1,7 @@
//
// BufferedBidirectionalStreamBuf.h
//
-// $Id: //poco/Main/Foundation/include/Poco/BufferedBidirectionalStreamBuf.h#5 $
+// $Id: //poco/Main/Foundation/include/Poco/BufferedBidirectionalStreamBuf.h#6 $
//
// Library: Foundation
// Package: Streams
@@ -178,6 +178,9 @@ private:
char_type* _pReadBuffer;
char_type* _pWriteBuffer;
openmode _mode;
+
+ BasicBufferedBidirectionalStreamBuf(const BasicBufferedBidirectionalStreamBuf&);
+ BasicBufferedBidirectionalStreamBuf& operator = (const BasicBufferedBidirectionalStreamBuf&);
};
diff --git a/Foundation/include/Poco/BufferedStreamBuf.h b/Foundation/include/Poco/BufferedStreamBuf.h
index 14a6745b0..c9a307bee 100644
--- a/Foundation/include/Poco/BufferedStreamBuf.h
+++ b/Foundation/include/Poco/BufferedStreamBuf.h
@@ -1,7 +1,7 @@
//
// BufferedStreamBuf.h
//
-// $Id: //poco/Main/Foundation/include/Poco/BufferedStreamBuf.h#4 $
+// $Id: //poco/Main/Foundation/include/Poco/BufferedStreamBuf.h#5 $
//
// Library: Foundation
// Package: Streams
@@ -170,6 +170,9 @@ private:
std::streamsize _bufsize;
char_type* _pBuffer;
openmode _mode;
+
+ BasicBufferedStreamBuf(const BasicBufferedStreamBuf&);
+ BasicBufferedStreamBuf& operator = (const BasicBufferedStreamBuf&);
};
diff --git a/Foundation/include/Poco/Channel.h b/Foundation/include/Poco/Channel.h
index 6eeee1f4a..e2cf1239e 100644
--- a/Foundation/include/Poco/Channel.h
+++ b/Foundation/include/Poco/Channel.h
@@ -1,7 +1,7 @@
//
// Channel.h
//
-// $Id: //poco/Main/Foundation/include/Poco/Channel.h#2 $
+// $Id: //poco/Main/Foundation/include/Poco/Channel.h#3 $
//
// Library: Foundation
// Package: Logging
@@ -87,6 +87,10 @@ public:
protected:
virtual ~Channel();
+
+private:
+ Channel(const Channel&);
+ Channel& operator = (const Channel&);
};
diff --git a/Foundation/include/Poco/DynamicAny.h b/Foundation/include/Poco/DynamicAny.h
index c0a709e15..e79fc8e59 100644
--- a/Foundation/include/Poco/DynamicAny.h
+++ b/Foundation/include/Poco/DynamicAny.h
@@ -1,7 +1,7 @@
//
// DynamicAny.h
//
-// $Id: //poco/Main/Foundation/include/Poco/DynamicAny.h#9 $
+// $Id: //poco/Main/Foundation/include/Poco/DynamicAny.h#10 $
//
// Library: Foundation
// Package: Core
@@ -64,7 +64,7 @@ class Foundation_API DynamicAny
/// String truncation is allowed -- it is possible to convert between string and character when string length is
/// greater than 1. An empty string gets converted to the char '\0', a non-empty string is truncated to the first character.
///
- /// Bolean conversion are performed as follows:
+ /// Boolean conversion is performed as follows:
///
/// A string value "false" (not case sensitive) or "0" can be converted to a boolean value false, any other string
/// not being false by the above criteria evaluates to true (e.g: "hi" -> true).
@@ -180,7 +180,7 @@ public:
}
template
- bool operator == (const T& other)
+ bool operator == (const T& other) const
/// Equality operator
{
T value;
@@ -188,7 +188,7 @@ public:
return value == other;
}
- bool operator == (const char* other)
+ bool operator == (const char* other) const
/// Equality operator
{
std::string value;
@@ -197,7 +197,7 @@ public:
}
template
- bool operator != (const T& other)
+ bool operator != (const T& other) const
/// Inequality operator
{
T value;
@@ -205,7 +205,7 @@ public:
return value != other;
}
- bool operator != (const char* other)
+ bool operator != (const char* other) const
/// Inequality operator
{
std::string value;
@@ -213,14 +213,63 @@ public:
return value != other;
}
- const std::type_info& type() const;
+ bool isArray() const;
+ /// Returns true if DynamicAny represents a vector
+
+ bool isStruct() const;
+ /// Returns true if DynamicAny represents a struct
+
+ DynamicAny& operator[](std::vector::size_type n);
+ /// Index operator, only use on DynamicAnys where isArray
+ /// returns true! In all other cases a BadCastException is thrown!
+
+ const DynamicAny& operator[](std::vector::size_type n) const;
+ /// const Index operator, only use on DynamicAnys where isArray
+ /// returns true! In all other cases a BadCastException is thrown!
+
+ DynamicAny& operator[](const std::string& name);
+ /// Index operator by name, only use on DynamicAnys where isStruct
+ /// returns true! In all other cases a BadCastException is thrown!
+
+ const DynamicAny& operator[](const std::string& name) const;
+ /// Index operator by name, only use on DynamicAnys where isStruct
+ /// returns true! In all other cases a BadCastException is thrown!
+
+ const std::type_info& type() const;
/// Returns the type information of the stored content.
+
+ static DynamicAny parse(const std::string& val);
+ /// Parses the string which must be in JSON format
+
+ static std::string toString(const DynamicAny& any);
+ /// Converts the DynamicAny to a string in JSON format. Note that toString will return
+ /// a different result than any.convert()!
+private:
+ static DynamicAny parse(const std::string& val, std::string::size_type& offset);
+ /// Parses the string which must be in JSON format
+
+ static DynamicAny parseObject(const std::string& val, std::string::size_type& pos);
+ static DynamicAny parseArray(const std::string& val, std::string::size_type& pos);
+ static std::string parseString(const std::string& val, std::string::size_type& pos);
+ static void skipWhiteSpace(const std::string& val, std::string::size_type& pos);
private:
DynamicAnyHolder* _pHolder;
};
+inline bool DynamicAny::isArray() const
+{
+ return _pHolder->isArray();
+}
+
+
+inline bool DynamicAny::isStruct() const
+{
+ return _pHolder->isStruct();
+}
+
+
} // namespace Poco
diff --git a/Foundation/include/Poco/DynamicAnyHolder.h b/Foundation/include/Poco/DynamicAnyHolder.h
index bdad04f1d..76b0d56ac 100644
--- a/Foundation/include/Poco/DynamicAnyHolder.h
+++ b/Foundation/include/Poco/DynamicAnyHolder.h
@@ -1,7 +1,7 @@
//
// DynamicAnyHolder.h
//
-// $Id: //poco/Main/Foundation/include/Poco/DynamicAnyHolder.h#9 $
+// $Id: //poco/Main/Foundation/include/Poco/DynamicAnyHolder.h#11 $
//
// Library: Foundation
// Package: Core
@@ -43,8 +43,15 @@
#include "Poco/Foundation.h"
#include "Poco/NumberFormatter.h"
#include "Poco/NumberParser.h"
+#include "Poco/DateTime.h"
+#include "Poco/Timestamp.h"
+#include "Poco/LocalDateTime.h"
+#include "Poco/DateTimeFormat.h"
+#include "Poco/DateTimeFormatter.h"
+#include "Poco/DateTimeParser.h"
#include "Poco/String.h"
#include "Poco/Exception.h"
+#include
#include
#undef min
#undef max
@@ -54,11 +61,19 @@
namespace Poco {
+class DynamicAny;
+
+
+void Foundation_API appendJSONString(std::string& val, const DynamicAny& any);
+ /// Converts the any to a JSON value and adds it to val
+
+
class Foundation_API DynamicAnyHolder
/// Interface for a data holder used by the DynamicAny class.
/// Provides methods to convert between data types.
/// Only data types for which a convert method exists are supported, which are
- /// all C++ built-in types with addition of std::string.
+ /// all C++ built-in types with addition of std::string, DateTime, LocalDateTime, Timestamp,
+ /// std::vector and DynamicStruct.
{
public:
DynamicAnyHolder();
@@ -81,6 +96,11 @@ public:
virtual void convert(UInt16& val) const = 0;
virtual void convert(UInt32& val) const = 0;
virtual void convert(UInt64& val) const = 0;
+ virtual void convert(DateTime& val) const = 0;
+ virtual void convert(LocalDateTime& val) const = 0;
+ virtual void convert(Timestamp& val) const = 0;
+ virtual bool isArray() const = 0;
+ virtual bool isStruct() const = 0;
#ifndef POCO_LONG_IS_64_BIT
void convert(long& val) const;
@@ -271,22 +291,22 @@ public:
throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
}
- void convert(bool& val) const
+ void convert(bool&) const
{
throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
}
- void convert(float& val) const
+ void convert(float&) const
{
throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
}
- void convert(double& val) const
+ void convert(double&) const
{
throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
}
- void convert(char& val) const
+ void convert(char&) const
{
throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
}
@@ -296,10 +316,35 @@ public:
throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
}
+ void convert(DateTime&) const
+ {
+ throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
+ }
+
DynamicAnyHolder* clone() const
{
throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
}
+
+ bool isArray() const
+ {
+ throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
+ }
+
+ bool isStruct() const
+ {
+ throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name());
+ }
};
@@ -385,6 +430,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("Int8 -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("Int8 -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("Int8 -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -395,6 +455,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
Int8 _val;
};
@@ -484,6 +554,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("Int16 -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("Int16 -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("Int16 -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -494,6 +579,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
Int16 _val;
};
@@ -583,6 +678,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("Int32 -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("Int32 -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("Int32 -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -593,6 +703,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
Int32 _val;
};
@@ -682,6 +802,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime& dt) const
+ {
+ dt = Timestamp(_val);
+ }
+
+ void convert(LocalDateTime& ldt) const
+ {
+ ldt = Timestamp(_val);
+ }
+
+ void convert(Timestamp& val) const
+ {
+ val = Timestamp(_val);
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -692,6 +827,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
Int64 _val;
};
@@ -781,6 +926,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("UInt8 -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("Unt8 -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("UInt8 -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -791,6 +951,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
UInt8 _val;
};
@@ -880,6 +1050,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("UInt16 -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("UInt16 -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("UInt16 -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -890,6 +1075,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
UInt16 _val;
};
@@ -979,6 +1174,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("UInt32 -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("UInt32 -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("UInt32 -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -989,6 +1199,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
UInt32 _val;
};
@@ -1078,6 +1298,27 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime& dt) const
+ {
+ Int64 val;
+ convertUnsignedToSigned(_val, val);
+ dt = Timestamp(val);
+ }
+
+ void convert(LocalDateTime& ldt) const
+ {
+ Int64 val;
+ convertUnsignedToSigned(_val, val);
+ ldt = Timestamp(val);
+ }
+
+ void convert(Timestamp& val) const
+ {
+ Int64 tmp;
+ convertUnsignedToSigned(_val, tmp);
+ val = Timestamp(tmp);
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -1088,6 +1329,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
UInt64 _val;
};
@@ -1175,6 +1426,21 @@ public:
val = (_val ? "true" : "false");
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("bool -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("bool -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("bool -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -1185,6 +1451,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
bool _val;
};
@@ -1275,6 +1551,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("float -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("float -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("float -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -1285,6 +1576,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
float _val;
};
@@ -1381,6 +1682,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("double -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("double -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("double -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -1391,6 +1707,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
double _val;
};
@@ -1478,6 +1804,21 @@ public:
val = std::string(1, _val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("char -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("char -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("char -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -1488,6 +1829,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
char _val;
};
@@ -1593,6 +1944,33 @@ public:
val = _val;
}
+ void convert(DateTime& val) const
+ {
+ int tzd = 0;
+ if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, val, tzd))
+ throw BadCastException("string -> DateTime");
+ }
+
+ void convert(LocalDateTime& ldt) const
+ {
+ int tzd = 0;
+ DateTime tmp;
+ if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd))
+ throw BadCastException("string -> LocalDateTime");
+
+ ldt = LocalDateTime(tzd, tmp, false);
+ }
+
+ void convert(Timestamp& ts) const
+ {
+ int tzd = 0;
+ DateTime tmp;
+ if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd))
+ throw BadCastException("string -> Timestamp");
+
+ ts = tmp.timestamp();
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -1603,6 +1981,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
std::string _val;
};
@@ -1695,6 +2083,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("long -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("long -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("long -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -1705,6 +2108,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
long _val;
};
@@ -1794,6 +2207,21 @@ public:
val = NumberFormatter::format(_val);
}
+ void convert(DateTime&) const
+ {
+ throw BadCastException("unsigned long -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("unsigned long -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("unsigned long -> Timestamp");
+ }
+
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
@@ -1804,6 +2232,16 @@ public:
return _val;
}
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
private:
unsigned long _val;
};
@@ -1812,6 +2250,523 @@ private:
#endif // 64bit
+template
+class DynamicAnyHolderImpl >: public DynamicAnyHolder
+{
+public:
+ DynamicAnyHolderImpl(const std::vector& val): _val(val)
+ {
+ }
+
+ ~DynamicAnyHolderImpl()
+ {
+ }
+
+ const std::type_info& type() const
+ {
+ return typeid(std::vector);
+ }
+
+ void convert(Int8& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(Int16& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(Int32& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(Int64& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(UInt8& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(UInt16& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(UInt32& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(UInt64& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(bool& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(float& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(double& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(char& val) const
+ {
+ throw BadCastException("Cannot cast collection type to non-collection type");
+ }
+
+ void convert(std::string& val) const
+ {
+ // Serialize in JSON format: note: although this a vector, the code only
+ // supports vector. We can't make this a total specialization,
+ // because of an otherwise cyclic dependency between DynamicAny and DynamicAnyHolder
+
+ // JSON format definition: [ n times: elem ',' ], no ',' for last elem
+ val.append("[ ");
+ typename std::vector::const_iterator it = _val.begin();
+ typename std::vector::const_iterator itEnd = _val.end();
+ if (!_val.empty())
+ {
+ appendJSONString(val, *it);
+ ++it;
+ }
+ for (; it != itEnd; ++it)
+ {
+
+ val.append(", ");
+ appendJSONString(val, *it);
+ }
+ val.append(" ]");
+ }
+
+ void convert(DateTime&) const
+ {
+ throw BadCastException("vector -> DateTime");
+ }
+
+ void convert(LocalDateTime&) const
+ {
+ throw BadCastException("vector -> LocalDateTime");
+ }
+
+ void convert(Timestamp&) const
+ {
+ throw BadCastException("vector -> Timestamp");
+ }
+
+ DynamicAnyHolder* clone() const
+ {
+ return new DynamicAnyHolderImpl(_val);
+ }
+
+ const std::vector& value() const
+ {
+ return _val;
+ }
+
+ bool isArray() const
+ {
+ return true;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
+ T& operator[](typename std::vector::size_type n)
+ {
+ return _val.operator[](n);
+ }
+
+ const T& operator[](typename std::vector::size_type n) const
+ {
+ return _val.operator[](n);
+ }
+
+private:
+ std::vector _val;
+};
+
+
+template <>
+class DynamicAnyHolderImpl: public DynamicAnyHolder
+{
+public:
+ DynamicAnyHolderImpl(const DateTime& val): _val(val)
+ {
+ }
+
+ ~DynamicAnyHolderImpl()
+ {
+ }
+
+ const std::type_info& type() const
+ {
+ return typeid(DateTime);
+ }
+
+ void convert(Int8& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int16& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int32& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int64& val) const
+ {
+ val = _val.timestamp().epochMicroseconds();
+ }
+
+ void convert(UInt8& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt16& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt32& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt64& val) const
+ {
+ val = _val.timestamp().epochMicroseconds();
+ }
+
+ void convert(bool&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(float&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(double&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(char&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(std::string& val) const
+ {
+ val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT);
+ }
+
+ void convert(DateTime& val) const
+ {
+ val = _val;
+ }
+
+ void convert(LocalDateTime& ldt) const
+ {
+ ldt = _val.timestamp();
+ }
+
+ void convert(Timestamp& ts) const
+ {
+ ts = _val.timestamp();
+ }
+
+ DynamicAnyHolder* clone() const
+ {
+ return new DynamicAnyHolderImpl(_val);
+ }
+
+ const DateTime& value() const
+ {
+ return _val;
+ }
+
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
+private:
+ DateTime _val;
+};
+
+
+template <>
+class DynamicAnyHolderImpl: public DynamicAnyHolder
+{
+public:
+ DynamicAnyHolderImpl(const LocalDateTime& val): _val(val)
+ {
+ }
+
+ ~DynamicAnyHolderImpl()
+ {
+ }
+
+ const std::type_info& type() const
+ {
+ return typeid(LocalDateTime);
+ }
+
+ void convert(Int8& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int16& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int32& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int64& val) const
+ {
+ val = _val.timestamp().epochMicroseconds();
+ }
+
+ void convert(UInt8& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt16& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt32& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt64& val) const
+ {
+ val = _val.timestamp().epochMicroseconds();
+ }
+
+ void convert(bool&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(float&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(double&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(char&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(std::string& val) const
+ {
+ val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT);
+ }
+
+ void convert(DateTime& val) const
+ {
+ val = _val.timestamp();
+ }
+
+ void convert(LocalDateTime& ldt) const
+ {
+ ldt = _val;
+ }
+
+ void convert(Timestamp& ts) const
+ {
+ ts = _val.timestamp();
+ }
+
+ DynamicAnyHolder* clone() const
+ {
+ return new DynamicAnyHolderImpl(_val);
+ }
+
+ const LocalDateTime& value() const
+ {
+ return _val;
+ }
+
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
+private:
+ LocalDateTime _val;
+};
+
+
+template <>
+class DynamicAnyHolderImpl: public DynamicAnyHolder
+{
+public:
+ DynamicAnyHolderImpl(const Timestamp& val): _val(val)
+ {
+ }
+
+ ~DynamicAnyHolderImpl()
+ {
+ }
+
+ const std::type_info& type() const
+ {
+ return typeid(Timestamp);
+ }
+
+ void convert(Int8& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int16& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int32& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(Int64& val) const
+ {
+ val = _val.epochMicroseconds();
+ }
+
+ void convert(UInt8& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt16& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt32& val) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(UInt64& val) const
+ {
+ val = _val.epochMicroseconds();
+ }
+
+ void convert(bool&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(float&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(double&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(char&) const
+ {
+ throw BadCastException();
+ }
+
+ void convert(std::string& val) const
+ {
+ val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT);
+ }
+
+ void convert(DateTime& val) const
+ {
+ val = _val;
+ }
+
+ void convert(LocalDateTime& ldt) const
+ {
+ ldt = _val;
+ }
+
+ void convert(Timestamp& ts) const
+ {
+ ts = _val;
+ }
+
+ DynamicAnyHolder* clone() const
+ {
+ return new DynamicAnyHolderImpl(_val);
+ }
+
+ const Timestamp& value() const
+ {
+ return _val;
+ }
+
+ bool isArray() const
+ {
+ return false;
+ }
+
+ bool isStruct() const
+ {
+ return false;
+ }
+
+private:
+ Timestamp _val;
+};
+
+
} // namespace Poco
diff --git a/Foundation/include/Poco/DynamicStruct.h b/Foundation/include/Poco/DynamicStruct.h
new file mode 100644
index 000000000..e1f68d4ee
--- /dev/null
+++ b/Foundation/include/Poco/DynamicStruct.h
@@ -0,0 +1,378 @@
+//
+// DynamicStruct.h
+//
+// $Id: //poco/Main/Foundation/include/Poco/DynamicStruct.h#9 $
+//
+// Library: Foundation
+// Package: Core
+// Module: DynamicStruct
+//
+// Definition of the DynamicStruct class.
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef Foundation_DynamicStruct_INCLUDED
+#define Foundation_DynamicStruct_INCLUDED
+
+
+#include "Poco/Foundation.h"
+#include "Poco/DynamicAny.h"
+#include "Poco/DynamicAnyHolder.h"
+#include