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 +#include + + +namespace Poco { + + +class Foundation_API DynamicStruct + /// DynamicStruct allows to define a named collection of DynamicAnys +{ +public: + typedef std::map Data; + typedef Data::iterator Iterator; + typedef Data::const_iterator ConstIterator; + + DynamicStruct(); + /// Creates an empty DynamicStruct + + DynamicStruct(const Data &val); + /// Creates the DynamicStruct from the given value. + + virtual ~DynamicStruct(); + /// Destroys the DynamicStruct. + + DynamicAny& operator[](const std::string& name); + /// Returns the DynamicAny with the given name, creates an entry if not found. + + const DynamicAny& operator[](const std::string& name) const; + /// Returns the DynamicAny with the given name, throws a + /// NotFoundException if the data member is not found. + + bool contains(const std::string& name) const; + /// Returns true if the DynamicStruct contains a member with the given + /// name + + Iterator find(const std::string& name); + /// Returns an iterator, pointing to the pair containing + /// the element, or it returns end() if the member was not found + + ConstIterator find(const std::string& name) const; + /// Returns a const iterator, pointing to the pair containing + /// the element, or it returns end() if the member was not found + + Iterator end(); + /// Returns the end iterator for the DynamicStruct + + ConstIterator end() const; + /// Returns the end const iterator for the DynamicStruct + + Iterator begin(); + /// Returns the begin iterator for the DynamicStruct + + ConstIterator begin() const; + /// Returns the begin const iterator for the DynamicStruct + + std::pair insert(const std::string& key, const DynamicAny& value); + /// Inserts a pair into the DynamicStruct, + /// returns a pair containing the iterator and a boolean which + /// indicates success or not (is true, when insert succeeded, false, + /// when already another element was present, in this case Iterator + /// points to that other element) + + std::pair insert(const DynamicStruct::Data::value_type& aPair); + /// Inserts a pair into the DynamicStruct, + /// returns a pair containing the iterator and a boolean which + /// indicates success or not (is true, when insert succeeded, false, + /// when already another element was present, in this case Iterator + /// points to that other element) + + DynamicStruct::Data::size_type erase(const std::string& key); + /// Erases the element if found, returns number of elements deleted + + void erase(DynamicStruct::Iterator it); + /// Erases the element at the given position + + bool empty() const; + /// Returns true if the DynamicStruct doesn't contain any members + + DynamicStruct::Data::size_type size() const; + /// Returns the number of members the DynamicStruct contains + + std::set members() const; + /// Returns a sorted collection containing all member names + +private: + Data _data; +}; + + +inline DynamicAny& DynamicStruct::operator[](const std::string& name) +{ + return _data.operator [](name); +} + + +inline bool DynamicStruct::contains(const std::string& name) const +{ + return find(name) != end(); +} + + +inline DynamicStruct::Iterator DynamicStruct::find(const std::string& name) +{ + return _data.find(name); +} + + +inline DynamicStruct::ConstIterator DynamicStruct::find(const std::string& name) const +{ + return _data.find(name); +} + + +inline DynamicStruct::Iterator DynamicStruct::end() +{ + return _data.end(); +} + + +inline DynamicStruct::ConstIterator DynamicStruct::end() const +{ + return _data.end(); +} + + +inline DynamicStruct::Iterator DynamicStruct::begin() +{ + return _data.begin(); +} + + +inline DynamicStruct::ConstIterator DynamicStruct::begin() const +{ + return _data.begin(); +} + + +inline std::pair DynamicStruct::insert(const std::string& key, const DynamicAny& value) +{ + return insert(std::make_pair(key, value)); +} + + +inline std::pair DynamicStruct::insert(const DynamicStruct::Data::value_type& aPair) +{ + return _data.insert(aPair); +} + + +inline DynamicStruct::Data::size_type DynamicStruct::erase(const std::string& key) +{ + return _data.erase(key); +} + + +inline void DynamicStruct::erase(DynamicStruct::Iterator it) +{ + _data.erase(it); +} + + +inline bool DynamicStruct::empty() const +{ + return _data.empty(); +} + + +inline DynamicStruct::Data::size_type DynamicStruct::size() const +{ + return _data.size(); +} + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(const DynamicStruct& val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(DynamicStruct); + } + + void convert(Int8& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to Int8"); + } + + void convert(Int16& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to Int16"); + } + + void convert(Int32& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to Int32"); + } + + void convert(Int64& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to Int64"); + } + + void convert(UInt8& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to UInt8"); + } + + void convert(UInt16& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to UInt16"); + } + + void convert(UInt32& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to UInt32"); + } + + void convert(UInt64& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to UInt64"); + } + + void convert(bool& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to bool"); + } + + void convert(float& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to float"); + } + + void convert(double& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to double"); + } + + void convert(char& val) const + { + throw BadCastException("Cannot cast DynamicStruct type to char"); + } + + void convert(std::string& val) const + { + // Serialize in JSON format: equals an object + + // JSON format definition: { string ':' value } string:value pair n-times, sep. by ',' + val.append("{ "); + DynamicStruct::ConstIterator it = _val.begin(); + DynamicStruct::ConstIterator itEnd = _val.end(); + if (!_val.empty()) + { + DynamicAny key(it->first); + appendJSONString(val, key); + val.append(" : "); + appendJSONString(val, it->second); + ++it; + } + for (; it != itEnd; ++it) + { + val.append(", "); + DynamicAny key(it->first); + appendJSONString(val, key); + val.append(" : "); + appendJSONString(val, it->second); + } + + val.append(" }"); + + } + + void convert(Poco::DateTime&) const + { + throw BadCastException("DynamicStruct -> Poco::DateTime"); + } + + void convert(Poco::LocalDateTime&) const + { + throw BadCastException("DynamicStruct -> Poco::LocalDateTime"); + } + + void convert(Poco::Timestamp&) const + { + throw BadCastException("DynamicStruct -> Poco::Timestamp"); + } + + DynamicAnyHolder* clone() const + { + return new DynamicAnyHolderImpl(_val); + } + + const DynamicStruct& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return true; + } + + DynamicAny& operator[](const std::string& name) + { + return _val.operator[](name); + } + + const DynamicAny& operator[](const std::string& name) const + { + return _val.operator[](name); + } + +private: + DynamicStruct _val; +}; + + +} // namespace Poco + + +#endif // Foundation_DynamicStruct_INCLUDED diff --git a/Foundation/include/Poco/Glob.h b/Foundation/include/Poco/Glob.h index 99c1ef36d..fed45108a 100644 --- a/Foundation/include/Poco/Glob.h +++ b/Foundation/include/Poco/Glob.h @@ -1,7 +1,7 @@ // // Glob.h // -// $Id: //poco/Main/Foundation/include/Poco/Glob.h#3 $ +// $Id: //poco/Main/Foundation/include/Poco/Glob.h#4 $ // // Library: Foundation // Package: Filesystem @@ -73,9 +73,10 @@ public: enum Options /// Flags that modify the matching behavior. { - GLOB_DEFAULT = 0x00, /// default behavior - GLOB_DOT_SPECIAL = 0x01, /// '*' and '?' do not match '.' at beginning of subject - GLOB_DIRS_ONLY = 0x80 /// only glob for directories (for internal use only) + GLOB_DEFAULT = 0x00, /// default behavior + GLOB_DOT_SPECIAL = 0x01, /// '*' and '?' do not match '.' at beginning of subject + GLOB_FOLLOW_SYMLINKS = 0x02, /// follow symbolic links + GLOB_DIRS_ONLY = 0x80 /// only glob for directories (for internal use only) }; Glob(const std::string& pattern, int options = 0); @@ -141,7 +142,8 @@ protected: bool matchAfterAsterisk(std::string::const_iterator itp, const std::string::const_iterator& endp, std::string::const_iterator its, const std::string::const_iterator& ends); bool matchSet(std::string::const_iterator& itp, const std::string::const_iterator& endp, char c); static void collect(const Path& pathPattern, const Path& base, const Path& current, const std::string& pattern, std::set& files, int options); - + static bool isDirectory(const Path& path, bool followSymlink); + private: std::string _pattern; int _options; diff --git a/Foundation/include/Poco/HMACEngine.h b/Foundation/include/Poco/HMACEngine.h index f9e043fd4..f3df580aa 100644 --- a/Foundation/include/Poco/HMACEngine.h +++ b/Foundation/include/Poco/HMACEngine.h @@ -1,7 +1,7 @@ // // HMACEngine.h // -// $Id: //poco/Main/Foundation/include/Poco/HMACEngine.h#3 $ +// $Id: //poco/Main/Foundation/include/Poco/HMACEngine.h#4 $ // // Library: Foundation // Package: Crypt @@ -153,6 +153,8 @@ protected: private: HMACEngine(); + HMACEngine(const HMACEngine&); + HMACEngine& operator = (const HMACEngine&); Engine _engine; char* _ipad; diff --git a/Foundation/include/Poco/LinearHashTable.h b/Foundation/include/Poco/LinearHashTable.h index 47c911e20..85dc932d2 100644 --- a/Foundation/include/Poco/LinearHashTable.h +++ b/Foundation/include/Poco/LinearHashTable.h @@ -1,7 +1,7 @@ // // LinearHashTable.h // -// $Id: //poco/Main/Foundation/include/Poco/LinearHashTable.h#11 $ +// $Id: //poco/Main/Foundation/include/Poco/LinearHashTable.h#13 $ // // Library: Foundation // Package: Hashing @@ -86,40 +86,38 @@ public: typedef HashFunc Hash; typedef std::vector Bucket; typedef std::vector BucketVec; - - template - class BasicConstIterator; - - template - class BasicIterator + typedef typename Bucket::iterator BucketIterator; + typedef typename BucketVec::iterator BucketVecIterator; + + class ConstIterator { public: - BasicIterator() + ConstIterator() { } - BasicIterator(const VecIt& vecIt, const VecIt& endIt, const BuckIt& buckIt): + ConstIterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt): _vecIt(vecIt), _endIt(endIt), _buckIt(buckIt) { } - BasicIterator(const BasicIterator& it): + ConstIterator(const ConstIterator& it): _vecIt(it._vecIt), _endIt(it._endIt), _buckIt(it._buckIt) { } - BasicIterator& operator = (const BasicIterator& it) + ConstIterator& operator = (const ConstIterator& it) { - BasicIterator tmp(it); + ConstIterator tmp(it); swap(tmp); return *this; } - void swap(BasicIterator& it) + void swap(ConstIterator& it) { using std::swap; swap(_vecIt, it._vecIt); @@ -127,169 +125,119 @@ public: swap(_buckIt, it._buckIt); } - bool operator == (const BasicIterator& it) const + bool operator == (const ConstIterator& it) const { return _vecIt == it._vecIt && (_vecIt == _endIt || _buckIt == it._buckIt); } - bool operator != (const BasicIterator& it) const + bool operator != (const ConstIterator& it) const { return _vecIt != it._vecIt || (_vecIt != _endIt && _buckIt != it._buckIt); } - typename Bucket::value_type& operator * () + const typename Bucket::value_type& operator * () const { return *_buckIt; } + const typename Bucket::value_type* operator -> () const + { + return &*_buckIt; + } + + ConstIterator& operator ++ () // prefix + { + if (_vecIt != _endIt) + { + ++_buckIt; + while (_vecIt != _endIt && _buckIt == _vecIt->end()) + { + ++_vecIt; + if (_vecIt != _endIt) _buckIt = _vecIt->begin(); + } + } + return *this; + } + + ConstIterator operator ++ (int) // postfix + { + ConstIterator tmp(*this); + ++*this; + return tmp; + } + + protected: + BucketVecIterator _vecIt; + BucketVecIterator _endIt; + BucketIterator _buckIt; + + friend class LinearHashTable; + }; + + class Iterator: public ConstIterator + { + public: + Iterator() + { + } + + Iterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt): + ConstIterator(vecIt, endIt, buckIt) + { + } + + Iterator(const Iterator& it): + ConstIterator(it) + { + } + + Iterator& operator = (const Iterator& it) + { + Iterator tmp(it); + swap(tmp); + return *this; + } + + void swap(Iterator& it) + { + ConstIterator::swap(it); + } + + typename Bucket::value_type& operator * () + { + return *this->_buckIt; + } + const typename Bucket::value_type& operator * () const { - return *_buckIt; + return *this->_buckIt; } typename Bucket::value_type* operator -> () { - return &*_buckIt; + return &*this->_buckIt; } const typename Bucket::value_type* operator -> () const { - return &*_buckIt; + return &*this->_buckIt; } - BasicIterator& operator ++ () // prefix + Iterator& operator ++ () // prefix { - if (_vecIt != _endIt) - { - ++_buckIt; - while (_vecIt != _endIt && _buckIt == _vecIt->end()) - { - ++_vecIt; - if (_vecIt != _endIt) _buckIt = _vecIt->begin(); - } - } + ConstIterator::operator ++ (); return *this; } - BasicIterator operator ++ (int) // postfix + Iterator operator ++ (int) // postfix { - BasicIterator tmp(*this); + Iterator tmp(*this); ++*this; return tmp; } - - private: - VecIt _vecIt; - VecIt _endIt; - BuckIt _buckIt; - - friend class LinearHashTable; - template friend class BasicConstIterator; - }; - typedef BasicIterator Iterator; - - template - class BasicConstIterator - { - public: - BasicConstIterator() - { - } - - BasicConstIterator(const VecIt& vecIt, const VecIt& endIt, const BuckIt& buckIt): - _vecIt(vecIt), - _endIt(endIt), - _buckIt(buckIt) - { - } - - BasicConstIterator(const BasicConstIterator& it): - _vecIt(it._vecIt), - _endIt(it._endIt), - _buckIt(it._buckIt) - { - } - - BasicConstIterator(const Iterator& it): - _vecIt(it._vecIt), - _endIt(it._endIt), - _buckIt(it._buckIt) - { - } - - BasicConstIterator& operator = (const BasicConstIterator& it) - { - BasicConstIterator tmp(it); - swap(tmp); - return *this; - } - - BasicConstIterator& operator = (const Iterator& it) - { - BasicConstIterator tmp(it); - swap(tmp); - return *this; - } - - void swap(BasicConstIterator& it) - { - using std::swap; - swap(_vecIt, it._vecIt); - swap(_endIt, it._endIt); - swap(_buckIt, it._buckIt); - } - - bool operator == (const BasicConstIterator& it) const - { - return _vecIt == it._vecIt && (_vecIt == _endIt || _buckIt == it._buckIt); - } - - bool operator != (const BasicConstIterator& it) const - { - return _vecIt != it._vecIt || (_vecIt != _endIt && _buckIt != it._buckIt); - } - - const typename Bucket::value_type& operator * () const - { - return *_buckIt; - } - - const typename Bucket::value_type* operator -> () const - { - return &*_buckIt; - } - - BasicConstIterator& operator ++ () // prefix - { - if (_vecIt != _endIt) - { - ++_buckIt; - while (_vecIt != _endIt && _buckIt == _vecIt->end()) - { - ++_vecIt; - if (_vecIt != _endIt) _buckIt = _vecIt->begin(); - } - } - return *this; - } - - BasicConstIterator operator ++ (int) // postfix - { - BasicConstIterator tmp(*this); - ++*this; - return tmp; - } - - private: - VecIt _vecIt; - VecIt _endIt; - BuckIt _buckIt; - friend class LinearHashTable; }; - - typedef BasicConstIterator ConstIterator; LinearHashTable(std::size_t initialReserve = 64): _split(0), @@ -336,8 +284,8 @@ public: ConstIterator begin() const /// Returns an iterator pointing to the first entry, if one exists. { - typename BucketVec::const_iterator it = _buckets.begin(); - typename BucketVec::const_iterator end = _buckets.end(); + BucketVecIterator it(_buckets.begin()); + BucketVecIterator end(_buckets.end()); while (it != end && it->empty()) { ++it; @@ -357,8 +305,8 @@ public: Iterator begin() /// Returns an iterator pointing to the first entry, if one exists. { - typename BucketVec::iterator it = _buckets.begin(); - typename BucketVec::iterator end = _buckets.end(); + BucketVecIterator it(_buckets.begin()); + BucketVecIterator end(_buckets.end()); while (it != end && it->empty()) { ++it; @@ -379,8 +327,8 @@ public: /// Finds an entry in the table. { std::size_t addr = bucketAddress(value); - typename BucketVec::const_iterator it = _buckets.begin() + addr; - typename Bucket::const_iterator buckIt = std::find(it->begin(), it->end(), value); + BucketVecIterator it(_buckets.begin() + addr); + BucketIterator buckIt(std::find(it->begin(), it->end(), value)); if (buckIt != it->end()) return ConstIterator(it, _buckets.end(), buckIt); else @@ -391,8 +339,8 @@ public: /// Finds an entry in the table. { std::size_t addr = bucketAddress(value); - typename BucketVec::iterator it = _buckets.begin() + addr; - typename Bucket::iterator buckIt = std::find(it->begin(), it->end(), value); + BucketVecIterator it(_buckets.begin() + addr); + BucketIterator buckIt(std::find(it->begin(), it->end(), value)); if (buckIt != it->end()) return Iterator(it, _buckets.end(), buckIt); else @@ -418,8 +366,8 @@ public: { split(); std::size_t addr = bucketAddress(value); - typename BucketVec::iterator it = _buckets.begin() + addr; - typename Bucket::iterator buckIt = std::find(it->begin(), it->end(), value); + BucketVecIterator it(_buckets.begin() + addr); + BucketIterator buckIt(std::find(it->begin(), it->end(), value)); if (buckIt == it->end()) { buckIt = it->insert(buckIt, value); @@ -491,7 +439,7 @@ protected: _buckets.push_back(tmp); _buckets[_split].swap(tmp); ++_split; - for (typename Bucket::iterator it = tmp.begin(); it != tmp.end(); ++it) + for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it) { using std::swap; std::size_t addr = bucketAddress(*it); @@ -511,7 +459,7 @@ protected: Bucket tmp; tmp.swap(_buckets.back()); _buckets.pop_back(); - for (typename Bucket::iterator it = tmp.begin(); it != tmp.end(); ++it) + for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it) { using std::swap; std::size_t addr = bucketAddress(*it); @@ -528,7 +476,9 @@ protected: } private: - BucketVec _buckets; + // Evil hack: _buckets must be mutable because both ConstIterator and Iterator hold + // ordinary iterator's (not const_iterator's). + mutable BucketVec _buckets; std::size_t _split; std::size_t _front; std::size_t _size; diff --git a/Foundation/include/Poco/MD2Engine.h b/Foundation/include/Poco/MD2Engine.h index 29134cc1a..9b10f0826 100644 --- a/Foundation/include/Poco/MD2Engine.h +++ b/Foundation/include/Poco/MD2Engine.h @@ -1,7 +1,7 @@ // // MD2Engine.h // -// $Id: //poco/Main/Foundation/include/Poco/MD2Engine.h#2 $ +// $Id: //poco/Main/Foundation/include/Poco/MD2Engine.h#3 $ // // Library: Foundation // Package: Crypt @@ -100,6 +100,9 @@ private: Context _context; DigestEngine::Digest _digest; + + MD2Engine(const MD2Engine&); + MD2Engine& operator = (const MD2Engine&); }; diff --git a/Foundation/include/Poco/MD4Engine.h b/Foundation/include/Poco/MD4Engine.h index 74eaf193d..d32aa328c 100644 --- a/Foundation/include/Poco/MD4Engine.h +++ b/Foundation/include/Poco/MD4Engine.h @@ -1,7 +1,7 @@ // // MD4Engine.h // -// $Id: //poco/Main/Foundation/include/Poco/MD4Engine.h#2 $ +// $Id: //poco/Main/Foundation/include/Poco/MD4Engine.h#3 $ // // Library: Foundation // Package: Crypt @@ -105,6 +105,9 @@ private: Context _context; DigestEngine::Digest _digest; + + MD4Engine(const MD4Engine&); + MD4Engine& operator = (const MD4Engine&); }; diff --git a/Foundation/include/Poco/MD5Engine.h b/Foundation/include/Poco/MD5Engine.h index 4bb5e8ae4..7bb2ff4a3 100644 --- a/Foundation/include/Poco/MD5Engine.h +++ b/Foundation/include/Poco/MD5Engine.h @@ -1,7 +1,7 @@ // // MD5Engine.h // -// $Id: //poco/Main/Foundation/include/Poco/MD5Engine.h#2 $ +// $Id: //poco/Main/Foundation/include/Poco/MD5Engine.h#3 $ // // Library: Foundation // Package: Crypt @@ -105,6 +105,9 @@ private: Context _context; DigestEngine::Digest _digest; + + MD5Engine(const MD5Engine&); + MD5Engine& operator = (const MD5Engine&); }; diff --git a/Foundation/include/Poco/Process_WIN32.h b/Foundation/include/Poco/Process_WIN32.h index a3e6f5808..3c9a2ea3c 100644 --- a/Foundation/include/Poco/Process_WIN32.h +++ b/Foundation/include/Poco/Process_WIN32.h @@ -1,7 +1,7 @@ // // Process_WIN32.h // -// $Id: //poco/Main/Foundation/include/Poco/Process_WIN32.h#3 $ +// $Id: //poco/Main/Foundation/include/Poco/Process_WIN32.h#4 $ // // Library: Foundation // Package: Processes @@ -64,6 +64,9 @@ public: private: HANDLE _hProcess; UInt32 _pid; + + ProcessHandleImpl(const ProcessHandleImpl&); + ProcessHandleImpl& operator = (const ProcessHandleImpl&); }; diff --git a/Foundation/include/Poco/Process_WIN32U.h b/Foundation/include/Poco/Process_WIN32U.h index f17d189cf..d5f5ab8b5 100644 --- a/Foundation/include/Poco/Process_WIN32U.h +++ b/Foundation/include/Poco/Process_WIN32U.h @@ -1,7 +1,7 @@ // // Process_WIN32U.h // -// $Id: //poco/Main/Foundation/include/Poco/Process_WIN32U.h#3 $ +// $Id: //poco/Main/Foundation/include/Poco/Process_WIN32U.h#4 $ // // Library: Foundation // Package: Processes @@ -64,6 +64,9 @@ public: private: HANDLE _hProcess; UInt32 _pid; + + ProcessHandleImpl(const ProcessHandleImpl&); + ProcessHandleImpl& operator = (const ProcessHandleImpl&); }; diff --git a/Foundation/include/Poco/SHA1Engine.h b/Foundation/include/Poco/SHA1Engine.h index ef7215d42..3d593aa55 100644 --- a/Foundation/include/Poco/SHA1Engine.h +++ b/Foundation/include/Poco/SHA1Engine.h @@ -1,7 +1,7 @@ // // SHA1Engine.h // -// $Id: //poco/Main/Foundation/include/Poco/SHA1Engine.h#2 $ +// $Id: //poco/Main/Foundation/include/Poco/SHA1Engine.h#3 $ // // Library: Foundation // Package: Crypt @@ -91,6 +91,9 @@ private: Context _context; DigestEngine::Digest _digest; + + SHA1Engine(const SHA1Engine&); + SHA1Engine& operator = (const SHA1Engine&); }; diff --git a/Foundation/include/Poco/SharedMemory.h b/Foundation/include/Poco/SharedMemory.h index 31bc7ea8b..6b67ac786 100644 --- a/Foundation/include/Poco/SharedMemory.h +++ b/Foundation/include/Poco/SharedMemory.h @@ -1,7 +1,7 @@ // // SharedMemory.h // -// $Id: //poco/Main/Foundation/include/Poco/SharedMemory.h#5 $ +// $Id: //poco/Main/Foundation/include/Poco/SharedMemory.h#6 $ // // Library: Foundation // Package: Processes @@ -71,7 +71,7 @@ public: /// Default constructor creates an unmapped SharedMemory object. /// No clients can connect to an unmapped SharedMemory object. - SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint = 0); + SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint = 0, bool server = true); /// Creates or connects to a shared memory object with the given name. /// /// For maximum portability, name should be a valid Unix filename and not @@ -81,6 +81,10 @@ public: /// start address of the shared memory area. Whether the hint /// is actually honored is, however, up to the system. Windows platform /// will generally ignore the hint. + /// + /// If server is set to false, the shared memory region will be unlinked + /// by calling shm_unlink (on POSIX platforms) when the SharedMemory object is destroyed. + /// The server parameter is ignored on Windows platforms. SharedMemory(const File& file, AccessMode mode, const void* addrHint = 0); /// Maps the entire contents of file into a shared memory segment. diff --git a/Foundation/include/Poco/SharedMemory_DUMMY.h b/Foundation/include/Poco/SharedMemory_DUMMY.h index 632563221..31dfac3b9 100644 --- a/Foundation/include/Poco/SharedMemory_DUMMY.h +++ b/Foundation/include/Poco/SharedMemory_DUMMY.h @@ -1,7 +1,7 @@ // // SharedMemoryImpl.h // -// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_DUMMY.h#4 $ +// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_DUMMY.h#5 $ // // Library: Foundation // Package: Processes @@ -53,7 +53,7 @@ class Foundation_API SharedMemoryImpl: public RefCountedObject /// that do not have shared memory support. { public: - SharedMemoryImpl(const std::string& id, std::size_t size, SharedMemory::AccessMode mode, const void* addr); + SharedMemoryImpl(const std::string& id, std::size_t size, SharedMemory::AccessMode mode, const void* addr, bool server); /// Creates or connects to a shared memory object with the given name. /// /// For maximum portability, name should be a valid Unix filename and not diff --git a/Foundation/include/Poco/SharedMemory_POSIX.h b/Foundation/include/Poco/SharedMemory_POSIX.h index 66610f83b..b9a95c776 100644 --- a/Foundation/include/Poco/SharedMemory_POSIX.h +++ b/Foundation/include/Poco/SharedMemory_POSIX.h @@ -1,7 +1,7 @@ // // SharedMemoryImpl.h // -// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_POSIX.h#5 $ +// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_POSIX.h#6 $ // // Library: Foundation // Package: Processes @@ -52,7 +52,7 @@ class Foundation_API SharedMemoryImpl: public RefCountedObject /// Shared memory implementation for POSIX platforms. { public: - SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint); + SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server); /// Creates or connects to a shared memory object with the given name. /// /// For maximum portability, name should be a valid Unix filename and not @@ -62,6 +62,9 @@ public: /// start address of the shared memory area. Whether the hint /// is actually honored is, however, up to the system. Windows platform /// will generally ignore the hint. + /// + /// If server is set to false, the shared memory region will be unlinked + /// by calling shm_unlink when the SharedMemory object is destroyed. SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint); /// Maps the entire contents of file into a shared memory segment. @@ -101,6 +104,7 @@ private: SharedMemory::AccessMode _access; std::string _name; bool _fileMapped; + bool _server; }; diff --git a/Foundation/include/Poco/SharedMemory_WIN32.h b/Foundation/include/Poco/SharedMemory_WIN32.h index 346da14e9..d4866c751 100644 --- a/Foundation/include/Poco/SharedMemory_WIN32.h +++ b/Foundation/include/Poco/SharedMemory_WIN32.h @@ -1,7 +1,7 @@ // // SharedMemoryImpl.h // -// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_WIN32.h#4 $ +// $Id: //poco/Main/Foundation/include/Poco/SharedMemory_WIN32.h#5 $ // // Library: Foundation // Package: Processes @@ -52,7 +52,7 @@ class Foundation_API SharedMemoryImpl: public RefCountedObject /// Shared memory implementation for Windows platforms. { public: - SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint); + SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server); /// Creates or connects to a shared memory object with the given name. /// /// For maximum portability, name should be a valid Unix filename and not diff --git a/Foundation/include/Poco/Stopwatch.h b/Foundation/include/Poco/Stopwatch.h index 0361f2998..de2a64d38 100644 --- a/Foundation/include/Poco/Stopwatch.h +++ b/Foundation/include/Poco/Stopwatch.h @@ -49,7 +49,7 @@ namespace Poco { class Foundation_API Stopwatch /// A simple facility to measure time intervals - /// with (theoretical) microsecond resolution. + /// with microsecond resolution. { public: Stopwatch(); diff --git a/Foundation/include/Poco/String.h b/Foundation/include/Poco/String.h index 53b130752..69d129a15 100644 --- a/Foundation/include/Poco/String.h +++ b/Foundation/include/Poco/String.h @@ -1,7 +1,7 @@ // // String.h // -// $Id: //poco/Main/Foundation/include/Poco/String.h#7 $ +// $Id: //poco/Main/Foundation/include/Poco/String.h#8 $ // // Library: Foundation // Package: Core @@ -202,8 +202,8 @@ int icompare( It end1 = str.begin() + pos + n; while (it1 != end1 && it2 != end2) { - typename S::value_type c1 = std::tolower(*it1); - typename S::value_type c2 = std::tolower(*it2); + typename S::value_type c1(std::tolower(*it1)); + typename S::value_type c2(std::tolower(*it2)); if (c1 < c2) return -1; else if (c1 > c2) @@ -294,8 +294,8 @@ int icompare( typename S::const_iterator end = str.begin() + pos + n; while (it != end && *ptr) { - typename S::value_type c1 = std::tolower(*it); - typename S::value_type c2 = std::tolower(*ptr); + typename S::value_type c1(std::tolower(*it)); + typename S::value_type c2(std::tolower(*ptr)); if (c1 < c2) return -1; else if (c1 > c2) diff --git a/Foundation/include/Poco/Thread_WIN32.h b/Foundation/include/Poco/Thread_WIN32.h index a46fa1c3f..5936dd6a4 100644 --- a/Foundation/include/Poco/Thread_WIN32.h +++ b/Foundation/include/Poco/Thread_WIN32.h @@ -1,7 +1,7 @@ // // Thread_WIN32.h // -// $Id: //poco/Main/Foundation/include/Poco/Thread_WIN32.h#4 $ +// $Id: //poco/Main/Foundation/include/Poco/Thread_WIN32.h#5 $ // // Library: Foundation // Package: Threading @@ -101,7 +101,7 @@ inline int ThreadImpl::getPriorityImpl() const inline void ThreadImpl::sleepImpl(long milliseconds) { - Sleep(milliseconds); + Sleep(DWORD(milliseconds)); } diff --git a/Foundation/include/Poco/Timer.h b/Foundation/include/Poco/Timer.h index 96b1880d1..eaf92726a 100644 --- a/Foundation/include/Poco/Timer.h +++ b/Foundation/include/Poco/Timer.h @@ -1,7 +1,7 @@ // // Timer.h // -// $Id: //poco/Main/Foundation/include/Poco/Timer.h#2 $ +// $Id: //poco/Main/Foundation/include/Poco/Timer.h#3 $ // // Library: Foundation // Package: Threading @@ -138,6 +138,9 @@ private: Event _done; AbstractTimerCallback* _pCallback; mutable FastMutex _mutex; + + Timer(const Timer&); + Timer& operator = (const Timer&); }; diff --git a/Foundation/include/Poco/UnbufferedStreamBuf.h b/Foundation/include/Poco/UnbufferedStreamBuf.h index 66d326399..76a5aca77 100644 --- a/Foundation/include/Poco/UnbufferedStreamBuf.h +++ b/Foundation/include/Poco/UnbufferedStreamBuf.h @@ -1,7 +1,7 @@ // // UnufferedStreamBuf.h // -// $Id: //poco/Main/Foundation/include/Poco/UnbufferedStreamBuf.h#3 $ +// $Id: //poco/Main/Foundation/include/Poco/UnbufferedStreamBuf.h#4 $ // // Library: Foundation // Package: Streams @@ -169,13 +169,16 @@ private: return char_traits::eof(); } - virtual int_type writeToDevice(char_type c) + virtual int_type writeToDevice(char_type) { return char_traits::eof(); } int_type _pb; bool _ispb; + + BasicUnbufferedStreamBuf(const BasicUnbufferedStreamBuf&); + BasicUnbufferedStreamBuf& operator = (const BasicUnbufferedStreamBuf&); }; diff --git a/Foundation/src/DynamicAny.cpp b/Foundation/src/DynamicAny.cpp index 507c209d3..cb696610d 100644 --- a/Foundation/src/DynamicAny.cpp +++ b/Foundation/src/DynamicAny.cpp @@ -1,7 +1,7 @@ // // DynamicAny.cpp // -// $Id: //poco/Main/Foundation/src/DynamicAny.cpp#4 $ +// $Id: //poco/Main/Foundation/src/DynamicAny.cpp#5 $ // // Library: Foundation // Package: Core @@ -35,7 +35,9 @@ #include "Poco/DynamicAny.h" +#include "Poco/DynamicStruct.h" #include +#include namespace Poco { @@ -75,7 +77,187 @@ void DynamicAny::swap(DynamicAny& ptr) const std::type_info& DynamicAny::type() const { - return _pHolder->type(); + return _pHolder->type(); +} + + +DynamicAny& DynamicAny::operator[](std::vector::size_type n) +{ + DynamicAnyHolderImpl >* pHolder = dynamic_cast > *>(_pHolder); + if (pHolder) + return pHolder->operator[](n); + else + throw BadCastException(); +} + + +const DynamicAny& DynamicAny::operator[](std::vector::size_type n) const +{ + const DynamicAnyHolderImpl >* pHolder = dynamic_cast > *>(_pHolder); + if (pHolder) + return pHolder->operator[](n); + else + throw BadCastException(); +} + + + +DynamicAny& DynamicAny::operator[](const std::string& name) +{ + DynamicAnyHolderImpl* pHolder = dynamic_cast *>(_pHolder); + if (pHolder) + return pHolder->operator[](name); + else + throw BadCastException(); +} + + +const DynamicAny& DynamicAny::operator[](const std::string& name) const +{ + const DynamicAnyHolderImpl* pHolder = dynamic_cast* >(_pHolder); + if (pHolder) + return pHolder->operator[](name); + else + throw BadCastException(); +} + + +DynamicAny DynamicAny::parse(const std::string& val) +{ + std::string::size_type t = 0; + return parse(val, t); +} + + +DynamicAny DynamicAny::parse(const std::string& val, std::string::size_type& pos) +{ + // { -> an Object==DynamicStruct + // [ -> an array + // '/" -> a string (strip '/") + // other: also treat as string + skipWhiteSpace(val, pos); + if (pos < val.size()) + { + switch(val[pos]) + { + case '{': + return parseObject(val, pos); + case '[': + return parseArray(val, pos); + default: + return parseString(val, pos); + } + } + std::string empty; + return empty; +} + + +DynamicAny DynamicAny::parseObject(const std::string& val, std::string::size_type& pos) +{ + poco_assert_dbg (val[pos] == '{'); + ++pos; + skipWhiteSpace(val, pos); + DynamicStruct aStruct; + while(val[pos] != '}' && pos < val.size()) + { + std::string key = parseString(val, pos); + skipWhiteSpace(val, pos); + if (val[pos] != ':') + throw DataFormatException("Incorrect object, must contain: key : value pairs"); + ++pos; // skip past : + DynamicAny value = parse(val, pos); + aStruct.insert(key, value); + skipWhiteSpace(val, pos); + if (val[pos] == ',') + { + ++pos; + skipWhiteSpace(val, pos); + } + } + if (val[pos] != '}') + throw DataFormatException("Unterminated object"); + ++pos; + return aStruct; +} + + +DynamicAny DynamicAny::parseArray(const std::string& val, std::string::size_type& pos) +{ + poco_assert_dbg (val[pos] == '['); + ++pos; + skipWhiteSpace(val, pos); + std::vector result; + while(val[pos] != ']' && pos < val.size()) + { + result.push_back(parse(val, pos)); + skipWhiteSpace(val, pos); + if (val[pos] == ',') + { + ++pos; + skipWhiteSpace(val, pos); + } + } + if (val[pos] != ']') + throw DataFormatException("Unterminated array"); + ++pos; + return result; +} + + +std::string DynamicAny::parseString(const std::string& val, std::string::size_type& pos) +{ + static const std::string STR_STOP("'\""); + static const std::string OTHER_STOP(" ,]}"); // we stop at space, ',', ']' or '}' + + bool inString = false; + //skip optional ' " + if (val[pos] == '\'' || val[pos] == '"') + { + inString = true; + ++pos; + } + + + std::string::size_type stop = std::string::npos; + if (inString) + { + stop = val.find_first_of(STR_STOP, pos); + if (stop == std::string::npos) + throw DataFormatException("Unterminated string"); + } + else + { + // we stop at space, ',', ']' or '}' or end of string + stop = val.find_first_of(OTHER_STOP, pos); + if (stop == std::string::npos) + stop = val.size(); + + std::string::size_type safeCheck = val.find_first_of(STR_STOP, pos); + if (safeCheck != std::string::npos && safeCheck < stop) + throw DataFormatException("Misplaced string termination char found"); + + } + + // stop now points to the last char to be not included + std::string result = val.substr(pos, stop - pos); + ++stop; // point past '/" + pos = stop; + return result; +} + +void DynamicAny::skipWhiteSpace(const std::string& val, std::string::size_type& pos) +{ + while (std::isspace(val[pos])) + ++pos; +} + + +std::string DynamicAny::toString(const DynamicAny& any) +{ + std::string res; + appendJSONString(res, any); + return res; } diff --git a/Foundation/src/DynamicAnyHolder.cpp b/Foundation/src/DynamicAnyHolder.cpp index 2c4980ec3..ef1c4742b 100644 --- a/Foundation/src/DynamicAnyHolder.cpp +++ b/Foundation/src/DynamicAnyHolder.cpp @@ -1,7 +1,7 @@ // // DynamicAnyHolder.cpp // -// $Id: //poco/Main/Foundation/src/DynamicAnyHolder.cpp#2 $ +// $Id: //poco/Main/Foundation/src/DynamicAnyHolder.cpp#3 $ // // Library: Foundation // Package: Core @@ -35,6 +35,7 @@ #include "Poco/DynamicAnyHolder.h" +#include "Poco/DynamicAny.h" namespace Poco { @@ -50,4 +51,18 @@ DynamicAnyHolder::~DynamicAnyHolder() } +void appendJSONString(std::string& val, const DynamicAny& any) +{ + bool isJsonString = (any.type() == typeid(std::string) || any.type() == typeid(char) || any.type() == typeid(Poco::DateTime) || any.type() == typeid(Poco::LocalDateTime)); + if (isJsonString) + { + val.append(1, '\''); + } + val.append(any.convert()); + if (isJsonString) + { + val.append(1, '\''); + } +} + } // namespace Poco diff --git a/Foundation/src/DynamicStruct.cpp b/Foundation/src/DynamicStruct.cpp new file mode 100644 index 000000000..ee6abb90a --- /dev/null +++ b/Foundation/src/DynamicStruct.cpp @@ -0,0 +1,81 @@ +// +// DynamicStruct.cpp +// +// $Id: //poco/Main/Foundation/src/DynamicStruct.cpp#4 $ +// +// Library: Foundation +// Package: Core +// Module: DynamicStruct +// +// 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. +// + + +#include "Poco/DynamicStruct.h" +#include "Poco/Exception.h" + + +namespace Poco { + + +DynamicStruct::DynamicStruct(): + _data() +{ +} + + +DynamicStruct::DynamicStruct(const Data& d): + _data(d) +{ +} + + +DynamicStruct::~DynamicStruct() +{ +} + + +const DynamicAny& DynamicStruct::operator[](const std::string& name) const +{ + ConstIterator it = find(name); + if (it == end()) + throw NotFoundException(name); + return it->second; +} + + +std::set DynamicStruct::members() const +{ + std::set keys; + ConstIterator it = begin(); + ConstIterator itEnd = end(); + for (; it != itEnd; ++it) + keys.insert(it->first); + return keys; +} + + +} // namespace Poco::Poco diff --git a/Foundation/src/Glob.cpp b/Foundation/src/Glob.cpp index 16dbb222c..d6ff362ab 100644 --- a/Foundation/src/Glob.cpp +++ b/Foundation/src/Glob.cpp @@ -1,7 +1,7 @@ // // Glob.cpp // -// $Id: //poco/Main/Foundation/src/Glob.cpp#6 $ +// $Id: //poco/Main/Foundation/src/Glob.cpp#7 $ // // Library: Foundation // Package: Filesystem @@ -219,7 +219,7 @@ void Glob::collect(const Path& pathPattern, const Path& base, const Path& curren else { p.setFileName(name); - if (File(p).isDirectory()) + if (isDirectory(p, (options & GLOB_FOLLOW_SYMLINKS) != 0)) { p.makeDirectory(); files.insert(p.toString()); @@ -239,4 +239,27 @@ void Glob::collect(const Path& pathPattern, const Path& base, const Path& curren } +bool Glob::isDirectory(const Path& path, bool followSymlink) +{ + File f(path); + if (f.isDirectory()) + { + return true; + } + else if (followSymlink && f.isLink()) + { + try + { + // Test if link resolves to a directory. + DirectoryIterator it(f); + return true; + } + catch (Exception&) + { + } + } + return false; +} + + } // namespace Poco diff --git a/Foundation/src/MSG00001.bin b/Foundation/src/MSG00001.bin index be19fe466..45ecf37e0 100644 Binary files a/Foundation/src/MSG00001.bin and b/Foundation/src/MSG00001.bin differ diff --git a/Foundation/src/MemoryPool.cpp b/Foundation/src/MemoryPool.cpp index a545c3439..853d2c58c 100644 --- a/Foundation/src/MemoryPool.cpp +++ b/Foundation/src/MemoryPool.cpp @@ -1,7 +1,7 @@ // // MemoryPool.cpp // -// $Id: //poco/Main/Foundation/src/MemoryPool.cpp#6 $ +// $Id: //poco/Main/Foundation/src/MemoryPool.cpp#7 $ // // Library: Foundation // Package: Core @@ -47,6 +47,7 @@ MemoryPool::MemoryPool(std::size_t blockSize, int preAlloc, int maxAlloc): _allocated(preAlloc) { poco_assert (maxAlloc == 0 || maxAlloc >= preAlloc); + poco_assert (preAlloc >= 0 && maxAlloc >= 0); int r = BLOCK_RESERVE; if (preAlloc > r) diff --git a/Foundation/src/SharedMemory.cpp b/Foundation/src/SharedMemory.cpp index 0abcbed9c..409d2566e 100644 --- a/Foundation/src/SharedMemory.cpp +++ b/Foundation/src/SharedMemory.cpp @@ -1,7 +1,7 @@ // // SharedMemory.cpp // -// $Id: //poco/Main/Foundation/src/SharedMemory.cpp#6 $ +// $Id: //poco/Main/Foundation/src/SharedMemory.cpp#7 $ // // Library: Foundation // Package: Processes @@ -60,8 +60,8 @@ SharedMemory::SharedMemory(): } -SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint): - _pImpl(new SharedMemoryImpl(name, size, mode, addrHint)) +SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint, bool server): + _pImpl(new SharedMemoryImpl(name, size, mode, addrHint, server)) { } diff --git a/Foundation/src/SharedMemory_DUMMY.cpp b/Foundation/src/SharedMemory_DUMMY.cpp index eba26714e..63897b800 100644 --- a/Foundation/src/SharedMemory_DUMMY.cpp +++ b/Foundation/src/SharedMemory_DUMMY.cpp @@ -1,7 +1,7 @@ // // SharedMemoryImpl.cpp // -// $Id: //poco/Main/Foundation/src/SharedMemory_DUMMY.cpp#3 $ +// $Id: //poco/Main/Foundation/src/SharedMemory_DUMMY.cpp#4 $ // // Library: Foundation // Package: Processes @@ -40,7 +40,7 @@ namespace Poco { -SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*) +SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*, bool) { } diff --git a/Foundation/src/SharedMemory_POSIX.cpp b/Foundation/src/SharedMemory_POSIX.cpp index fd68b6278..fe6c4e447 100644 --- a/Foundation/src/SharedMemory_POSIX.cpp +++ b/Foundation/src/SharedMemory_POSIX.cpp @@ -1,7 +1,7 @@ // // SharedMemoryImpl.cpp // -// $Id: //poco/Main/Foundation/src/SharedMemory_POSIX.cpp#9 $ +// $Id: //poco/Main/Foundation/src/SharedMemory_POSIX.cpp#10 $ // // Library: Foundation // Package: Processes @@ -47,13 +47,14 @@ namespace Poco { -SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint): +SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server): _size(size), _fd(-1), _address(0), _access(mode), _name("/"), - _fileMapped(false) + _fileMapped(false), + _server(server) { #if POCO_OS == POCO_OS_HPUX _name.append("tmp/"); @@ -90,7 +91,8 @@ SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessM _address(0), _access(mode), _name(file.path()), - _fileMapped(true) + _fileMapped(true), + _server(false) { if (!file.exists() || !file.isFile()) throw FileNotFoundException(file.path()); @@ -144,7 +146,7 @@ void SharedMemoryImpl::close() ::close(_fd); _fd = -1; } - if (!_fileMapped) + if (!_fileMapped && _server) { ::shm_unlink(_name.c_str()); } diff --git a/Foundation/src/SharedMemory_WIN32.cpp b/Foundation/src/SharedMemory_WIN32.cpp index 6e562c771..d29e29854 100644 --- a/Foundation/src/SharedMemory_WIN32.cpp +++ b/Foundation/src/SharedMemory_WIN32.cpp @@ -1,7 +1,7 @@ // // SharedMemoryImpl.cpp // -// $Id: //poco/Main/Foundation/src/SharedMemory_WIN32.cpp#6 $ +// $Id: //poco/Main/Foundation/src/SharedMemory_WIN32.cpp#7 $ // // Library: Foundation // Package: Processes @@ -46,7 +46,7 @@ namespace Poco { -SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void*): +SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void*, bool): _name(name), _memHandle(INVALID_HANDLE_VALUE), _fileHandle(INVALID_HANDLE_VALUE), diff --git a/Foundation/src/UUIDGenerator.cpp b/Foundation/src/UUIDGenerator.cpp index bf75c6992..99a35d863 100644 --- a/Foundation/src/UUIDGenerator.cpp +++ b/Foundation/src/UUIDGenerator.cpp @@ -1,7 +1,7 @@ // // UUIDGenerator.cpp // -// $Id: //poco/Main/Foundation/src/UUIDGenerator.cpp#18 $ +// $Id: //poco/Main/Foundation/src/UUIDGenerator.cpp#19 $ // // Library: Foundation // Package: UUID @@ -202,6 +202,7 @@ void UUIDGenerator::getNode() std::memcpy(_node, pAdapter->Address, pAdapter->AddressLength); found = true; } + pAdapter = pAdapter->Next; } } else throw SystemException("cannot get network adapter list"); diff --git a/Foundation/src/pocomsg.h b/Foundation/src/pocomsg.h index 3beca6676..4aefa5ca5 100644 --- a/Foundation/src/pocomsg.h +++ b/Foundation/src/pocomsg.h @@ -1,7 +1,7 @@ // // pocomsg.mc[.h] // -// $Id: //poco/Main/Foundation/src/pocomsg.h#26 $ +// $Id: //poco/Main/Foundation/src/pocomsg.mc#7 $ // // The Poco message source/header file. // diff --git a/Foundation/testsuite/src/DynamicAnyTest.cpp b/Foundation/testsuite/src/DynamicAnyTest.cpp index 87852b9cf..e0d2578bd 100644 --- a/Foundation/testsuite/src/DynamicAnyTest.cpp +++ b/Foundation/testsuite/src/DynamicAnyTest.cpp @@ -1,7 +1,7 @@ // // DynamicAnyTest.cpp // -// $Id: //poco/Main/Foundation/testsuite/src/DynamicAnyTest.cpp#9 $ +// $Id: //poco/Main/Foundation/testsuite/src/DynamicAnyTest.cpp#11 $ // // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // and Contributors. @@ -36,6 +36,7 @@ #include "Poco/Exception.h" #include "Poco/DynamicAny.h" #include "Poco/Bugcheck.h" +#include "Poco/DynamicStruct.h" using namespace Poco; @@ -1221,6 +1222,534 @@ void DynamicAnyTest::testCtor() } +void DynamicAnyTest::testIsStruct() +{ + std::string s1("string"); + Poco::Int8 s2(-23); + Poco::Int16 s3(-33); + Poco::Int32 s4(-388); + Poco::Int64 s5(-23823838); + Poco::UInt8 s6(32); + Poco::UInt16 s7(16000); + Poco::UInt32 s8(334234); + Poco::UInt64 s9(2328328382); + float s10(13.333f); + double s11(13.555); + bool s12(true); + char s13('c'); + long s14(232323); + unsigned long s15(21233232); + std::vector s16; + DynamicStruct s17; + + DynamicAny d1(s1); + DynamicAny d2(s2); + DynamicAny d3(s3); + DynamicAny d4(s4); + DynamicAny d5(s5); + DynamicAny d6(s6); + DynamicAny d7(s7); + DynamicAny d8(s8); + DynamicAny d9(s9); + DynamicAny d10(s10); + DynamicAny d11(s11); + DynamicAny d12(s12); + DynamicAny d13(s13); + DynamicAny d14(s14); + DynamicAny d15(s15); + DynamicAny d16(s16); + DynamicAny d17(s17); + + assert (!d1.isStruct()); + assert (!d2.isStruct()); + assert (!d3.isStruct()); + assert (!d4.isStruct()); + assert (!d5.isStruct()); + assert (!d6.isStruct()); + assert (!d7.isStruct()); + assert (!d8.isStruct()); + assert (!d9.isStruct()); + assert (!d10.isStruct()); + assert (!d11.isStruct()); + assert (!d12.isStruct()); + assert (!d13.isStruct()); + assert (!d14.isStruct()); + assert (!d15.isStruct()); + assert (!d16.isStruct()); + assert (d17.isStruct()); +} + + +void DynamicAnyTest::testIsArray() +{ + std::string s1("string"); + Poco::Int8 s2(-23); + Poco::Int16 s3(-33); + Poco::Int32 s4(-388); + Poco::Int64 s5(-23823838); + Poco::UInt8 s6(32); + Poco::UInt16 s7(16000); + Poco::UInt32 s8(334234); + Poco::UInt64 s9(2328328382); + float s10(13.333f); + double s11(13.555); + bool s12(true); + char s13('c'); + long s14(232323); + unsigned long s15(21233232); + std::vector s16; + DynamicStruct s17; + + DynamicAny d1(s1); + DynamicAny d2(s2); + DynamicAny d3(s3); + DynamicAny d4(s4); + DynamicAny d5(s5); + DynamicAny d6(s6); + DynamicAny d7(s7); + DynamicAny d8(s8); + DynamicAny d9(s9); + DynamicAny d10(s10); + DynamicAny d11(s11); + DynamicAny d12(s12); + DynamicAny d13(s13); + DynamicAny d14(s14); + DynamicAny d15(s15); + DynamicAny d16(s16); + DynamicAny d17(s17); + + assert (!d1.isArray()); + assert (!d2.isArray()); + assert (!d3.isArray()); + assert (!d4.isArray()); + assert (!d5.isArray()); + assert (!d6.isArray()); + assert (!d7.isArray()); + assert (!d8.isArray()); + assert (!d9.isArray()); + assert (!d10.isArray()); + assert (!d11.isArray()); + assert (!d12.isArray()); + assert (!d13.isArray()); + assert (!d14.isArray()); + assert (!d15.isArray()); + assert (d16.isArray()); + assert (!d17.isArray()); +} + + +void DynamicAnyTest::testArrayIdxOperator() +{ + std::string s1("string"); + Poco::Int8 s2(-23); + Poco::Int16 s3(-33); + Poco::Int32 s4(-388); + Poco::Int64 s5(-23823838); + Poco::UInt8 s6(32); + Poco::UInt16 s7(16000); + Poco::UInt32 s8(334234); + Poco::UInt64 s9(2328328382); + float s10(13.333f); + double s11(13.555); + bool s12(true); + char s13('c'); + long s14(232323); + unsigned long s15(21233232); + std::vector s16; + s16.push_back(s1); + s16.push_back(s2); + DynamicStruct s17; + + DynamicAny d1(s1); + DynamicAny d2(s2); + DynamicAny d3(s3); + DynamicAny d4(s4); + DynamicAny d5(s5); + DynamicAny d6(s6); + DynamicAny d7(s7); + DynamicAny d8(s8); + DynamicAny d9(s9); + DynamicAny d10(s10); + DynamicAny d11(s11); + DynamicAny d12(s12); + DynamicAny d13(s13); + DynamicAny d14(s14); + DynamicAny d15(s15); + DynamicAny d16(s16); + DynamicAny d17(s17); + + testGetIdxMustThrow(d1, 0); + testGetIdxMustThrow(d2, 0); + testGetIdxMustThrow(d3, 0); + testGetIdxMustThrow(d4, 0); + testGetIdxMustThrow(d5, 0); + testGetIdxMustThrow(d6, 0); + testGetIdxMustThrow(d7, 0); + testGetIdxMustThrow(d8, 0); + testGetIdxMustThrow(d9, 0); + testGetIdxMustThrow(d10, 0); + testGetIdxMustThrow(d11, 0); + testGetIdxMustThrow(d12, 0); + testGetIdxMustThrow(d13, 0); + testGetIdxMustThrow(d14, 0); + testGetIdxMustThrow(d15, 0); + testGetIdx(d16, 0, s1); + testGetIdx(d16, 1, s2); + testGetIdxMustThrow(d17, 0); +} + + +void DynamicAnyTest::testDynamicStructBasics() +{ + DynamicStruct aStruct; + assert (aStruct.empty()); + assert (aStruct.size() == 0); + assert (aStruct.members().empty()); + + aStruct.insert("First Name", "Little"); + assert (!aStruct.empty()); + assert (aStruct.size() == 1); + assert (*(aStruct.members().begin()) == "First Name"); + assert (aStruct["First Name"] == "Little"); + aStruct.insert("Last Name", "POCO"); + assert (aStruct.members().size() == 2); + aStruct.erase("First Name"); + assert (aStruct.size() == 1); + assert (*(aStruct.members().begin()) == "Last Name"); +} + + +void DynamicAnyTest::testDynamicStruct() +{ + DynamicStruct aStruct; + aStruct["First Name"] = "Junior"; + aStruct["Last Name"] = "POCO"; + DynamicAny a1(aStruct); + assert (a1["First Name"] == "Junior"); + assert (a1["Last Name"] == "POCO"); + a1["First Name"] = "Senior"; + assert (a1["First Name"] == "Senior"); + testGetIdxMustThrow(a1, 0); +} + + +void DynamicAnyTest::testArrayToString() +{ + std::string s1("string"); + Poco::Int8 s2(23); + std::vector s16; + s16.push_back(s1); + s16.push_back(s2); + DynamicAny a1(s16); + std::string res = a1.convert(); + std::string expected("[ 'string', 23 ]"); + assert (res == expected); +} + + +void DynamicAnyTest::testStructToString() +{ + DynamicStruct aStruct; + aStruct["First Name"] = "Junior"; + aStruct["Last Name"] = "POCO"; + aStruct["Age"] = 1; + DynamicAny a1(aStruct); + std::string res = a1.convert(); + std::string expected = "{ 'Age' : 1, 'First Name' : 'Junior', 'Last Name' : 'POCO' }"; +; + assert (res == expected); +} + + +void DynamicAnyTest::testArrayOfStructsToString() +{ + std::vector s16; + DynamicStruct aStruct; + aStruct["First Name"] = "Junior"; + aStruct["Last Name"] = "POCO"; + aStruct["Age"] = 1; + s16.push_back(aStruct); + aStruct["First Name"] = "Senior"; + aStruct["Last Name"] = "POCO"; + aStruct["Age"] = 100; + s16.push_back(aStruct); + std::vector s16Cpy = s16; + // recursive arrays! + s16Cpy.push_back(s16); + s16.push_back(s16Cpy); + DynamicAny a1(s16); + std::string res = a1.convert(); + std::string expected = "[ " + "{ 'Age' : 1, 'First Name' : 'Junior', 'Last Name' : 'POCO' }, " + "{ 'Age' : 100, 'First Name' : 'Senior', 'Last Name' : 'POCO' }, " + "[ " + "{ 'Age' : 1, 'First Name' : 'Junior', 'Last Name' : 'POCO' }, " + "{ 'Age' : 100, 'First Name' : 'Senior', 'Last Name' : 'POCO' }, " + "[ " + "{ 'Age' : 1, 'First Name' : 'Junior', 'Last Name' : 'POCO' }, " + "{ 'Age' : 100, 'First Name' : 'Senior', 'Last Name' : 'POCO' } " + "] ] ]"; + + assert (res == expected); +} + + +void DynamicAnyTest::testStructWithArraysToString() +{ + std::string s1("string"); + Poco::Int8 s2(23); + std::vector s16; + s16.push_back(s1); + s16.push_back(s2); + DynamicAny a1(s16); + DynamicStruct addr; + addr["Number"] = 4; + addr["Street"] = "Unknown"; + addr["Country"] = "Carinthia"; + DynamicStruct aStruct; + aStruct["First Name"] = "Junior"; + aStruct["Last Name"] = a1; + aStruct["Age"] = 1; + aStruct["Address"] = addr; + DynamicAny a2(aStruct); + std::string res = a2.convert(); + std::string expected = "{ 'Address' : { 'Country' : 'Carinthia', 'Number' : 4, 'Street' : 'Unknown' }, " + "'Age' : 1, 'First Name' : 'Junior', 'Last Name' : [ 'string', 23 ] }"; + + assert (res == expected); +} + + +void DynamicAnyTest::testJSONDeserializeString() +{ + DynamicAny a("test"); + std::string tst = DynamicAny::toString(a); + DynamicAny b = DynamicAny::parse(tst); + assert (b.convert() == "test"); + + DynamicAny c('c'); + std::string tst2 = DynamicAny::toString(c); + DynamicAny b2 = DynamicAny::parse(tst2); + char cc = b2.convert(); + assert (cc == 'c'); +} + + +void DynamicAnyTest::testJSONDeserializePrimitives() +{ + Poco::Int8 i8(-12); + Poco::UInt16 u16(2345); + Poco::Int32 i32(-24343); + Poco::UInt64 u64(1234567890); + u64 *= u64; + bool b = false; + float f = 3.1415f; + double d = 3.1415; + + std::string s8 = DynamicAny::toString(i8); + std::string s16 = DynamicAny::toString(u16); + std::string s32 = DynamicAny::toString(i32); + std::string s64 = DynamicAny::toString(u64); + std::string sb = DynamicAny::toString(b); + std::string sf = DynamicAny::toString(f); + std::string sd = DynamicAny::toString(d); + DynamicAny a8 = DynamicAny::parse(s8); + DynamicAny a16 = DynamicAny::parse(s16); + DynamicAny a32 = DynamicAny::parse(s32); + DynamicAny a64 = DynamicAny::parse(s64); + DynamicAny ab = DynamicAny::parse(sb); + DynamicAny af = DynamicAny::parse(sf); + DynamicAny ad = DynamicAny::parse(sd); + assert (a8 == i8); + assert (a16 == u16); + assert (a32 == i32); + assert (a64 == u64); + assert (ab == b); + assert (af == f); + assert (ad == d); +} + + +void DynamicAnyTest::testJSONDeserializeArray() +{ + Poco::Int8 i8(-12); + Poco::UInt16 u16(2345); + Poco::Int32 i32(-24343); + Poco::UInt64 u64(1234567890); + u64 *= u64; + bool b = false; + float f = 3.1415f; + double d = 3.1415; + std::string s("test string"); + char c('x'); + std::vector aVec; + aVec.push_back(i8); + aVec.push_back(u16); + aVec.push_back(i32); + aVec.push_back(u64); + aVec.push_back(b); + aVec.push_back(f); + aVec.push_back(d); + aVec.push_back(s); + aVec.push_back(c); + + std::string sVec = DynamicAny::toString(aVec); + DynamicAny a = DynamicAny::parse(sVec); + assert (a[0] == i8); + assert (a[1] == u16); + assert (a[2] == i32); + assert (a[3] == u64); + assert (a[4] == b); + assert (a[5] == f); + assert (a[6] == d); + assert (a[7] == s); + assert (a[8] == c); +} + + +void DynamicAnyTest::testJSONDeserializeComplex() +{ + Poco::Int8 i8(-12); + Poco::UInt16 u16(2345); + Poco::Int32 i32(-24343); + Poco::UInt64 u64(1234567890); + u64 *= u64; + bool b = false; + float f = 3.1415f; + double d = 3.1415; + std::string s("test string"); + char c('x'); + DynamicStruct aStr; + aStr["i8"] = i8; + aStr["u16"] = u16; + aStr["i32"] = i32; + aStr["u64"] = u64; + aStr["b"] = b; + aStr["f"] = f; + aStr["d"] = d; + aStr["s"] = s; + aStr["c"] = c; + std::vector aVec; + aVec.push_back(i8); + aVec.push_back(u16); + aVec.push_back(i32); + aVec.push_back(u64); + aVec.push_back(b); + aVec.push_back(f); + aVec.push_back(d); + aVec.push_back(s); + aVec.push_back(c); + aVec.push_back(aStr); + aStr["vec"] = aVec; + + std::string sStr = DynamicAny::toString(aStr); + DynamicAny a = DynamicAny::parse(sStr); + assert (a.isStruct()); + assert (aStr["i8"] == i8); + assert (aStr["u16"] == u16); + assert (aStr["i32"] == i32); + assert (aStr["u64"] == u64); + assert (aStr["b"] == b); + assert (aStr["f"] == f); + assert (aStr["d"] == d); + assert (aStr["s"] == s); + assert (aStr["c"] == c); + DynamicAny vecRet = a["vec"]; + assert (vecRet.isArray()); + assert (vecRet[0] == i8); + assert (vecRet[1] == u16); + assert (vecRet[2] == i32); + assert (vecRet[3] == u64); + assert (vecRet[4] == b); + assert (vecRet[5] == f); + assert (vecRet[6] == d); + assert (vecRet[7] == s); + assert (vecRet[8] == c); + DynamicAny strRet = vecRet[9]; + assert (strRet.isStruct()); +} + + +void DynamicAnyTest::testJSONDeserializeStruct() +{ + Poco::Int8 i8(-12); + Poco::UInt16 u16(2345); + Poco::Int32 i32(-24343); + Poco::UInt64 u64(1234567890); + u64 *= u64; + bool b = false; + float f = 3.1415f; + double d = 3.1415; + std::string s("test string"); + char c('x'); + DynamicStruct aStr; + aStr["i8"] = i8; + aStr["u16"] = u16; + aStr["i32"] = i32; + aStr["u64"] = u64; + aStr["b"] = b; + aStr["f"] = f; + aStr["d"] = d; + aStr["s"] = s; + aStr["c"] = c; + + std::string sStr = DynamicAny::toString(aStr); + DynamicAny a = DynamicAny::parse(sStr); + assert (aStr["i8"] == i8); + assert (aStr["u16"] == u16); + assert (aStr["i32"] == i32); + assert (aStr["u64"] == u64); + assert (aStr["b"] == b); + assert (aStr["f"] == f); + assert (aStr["d"] == d); + assert (aStr["s"] == s); + assert (aStr["c"] == c); +} + + +void DynamicAnyTest::testDate() +{ + Poco::DateTime dtNow(2007, 3, 13, 8, 12, 15); + + Poco::Timestamp tsNow = dtNow.timestamp(); + Poco::LocalDateTime ldtNow(dtNow.timestamp()); + DynamicAny dt(dtNow); + DynamicAny ts(tsNow); + DynamicAny ldt(ldtNow); + DynamicAny dtStr(dt.convert()); + DynamicAny tsStr(ts.convert()); + DynamicAny ldtStr(ldt.convert()); + DateTime dtRes = dtStr.convert(); + LocalDateTime ldtRes = ldtStr.convert(); + Timestamp tsRes = tsStr.convert(); + assert (dtNow == dtRes); + assert (ldtNow == ldtRes); + assert (tsNow == tsRes); +} + +void DynamicAnyTest::testGetIdxMustThrow(DynamicAny& a1, std::vector::size_type n) +{ + try + { + DynamicAny& val1 = a1[n]; + fail("bad cast - must throw"); + } + catch (Poco::BadCastException&) + { + } + + try + { + const DynamicAny& c1 = a1; + const DynamicAny& cval1 = c1[n]; + fail("bad const cast - must throw"); + } + catch (Poco::BadCastException&) + { + } +} + + void DynamicAnyTest::setUp() { } @@ -1254,6 +1783,21 @@ CppUnit::Test* DynamicAnyTest::suite() CppUnit_addTest(pSuite, DynamicAnyTest, testLimitsInt); CppUnit_addTest(pSuite, DynamicAnyTest, testLimitsFloat); CppUnit_addTest(pSuite, DynamicAnyTest, testCtor); + CppUnit_addTest(pSuite, DynamicAnyTest, testIsStruct); + CppUnit_addTest(pSuite, DynamicAnyTest, testIsArray); + CppUnit_addTest(pSuite, DynamicAnyTest, testArrayIdxOperator); + CppUnit_addTest(pSuite, DynamicAnyTest, testDynamicStructBasics); + CppUnit_addTest(pSuite, DynamicAnyTest, testDynamicStruct); + CppUnit_addTest(pSuite, DynamicAnyTest, testArrayToString); + CppUnit_addTest(pSuite, DynamicAnyTest, testStructToString); + CppUnit_addTest(pSuite, DynamicAnyTest, testArrayOfStructsToString); + CppUnit_addTest(pSuite, DynamicAnyTest, testStructWithArraysToString); + CppUnit_addTest(pSuite, DynamicAnyTest, testJSONDeserializeString); + CppUnit_addTest(pSuite, DynamicAnyTest, testJSONDeserializePrimitives); + CppUnit_addTest(pSuite, DynamicAnyTest, testJSONDeserializeArray); + CppUnit_addTest(pSuite, DynamicAnyTest, testJSONDeserializeStruct); + CppUnit_addTest(pSuite, DynamicAnyTest, testJSONDeserializeComplex); + CppUnit_addTest(pSuite, DynamicAnyTest, testDate); return pSuite; } diff --git a/Foundation/testsuite/src/DynamicAnyTest.h b/Foundation/testsuite/src/DynamicAnyTest.h index 795cddbde..a719cf6e2 100644 --- a/Foundation/testsuite/src/DynamicAnyTest.h +++ b/Foundation/testsuite/src/DynamicAnyTest.h @@ -1,7 +1,7 @@ // // DynamicAnyTest.h // -// $Id: //poco/Main/Foundation/testsuite/src/DynamicAnyTest.h#4 $ +// $Id: //poco/Main/Foundation/testsuite/src/DynamicAnyTest.h#5 $ // // Tests for Any types // @@ -66,12 +66,40 @@ public: void testLimitsInt(); void testLimitsFloat(); void testCtor(); + void testIsStruct(); + void testIsArray(); + void testArrayIdxOperator(); + void testDynamicStructBasics(); + void testDynamicStruct(); + void testArrayToString(); + void testStructToString(); + void testArrayOfStructsToString(); + void testStructWithArraysToString(); + void testJSONDeserializeString(); + void testJSONDeserializePrimitives(); + void testJSONDeserializeArray(); + void testJSONDeserializeStruct(); + void testJSONDeserializeComplex(); + void testDate(); void setUp(); void tearDown(); static CppUnit::Test* suite(); private: + void testGetIdxMustThrow(Poco::DynamicAny& a1, std::vector::size_type n); + template + void testGetIdx(Poco::DynamicAny& a1, std::vector::size_type n, const T& expectedResult) + { + Poco::DynamicAny& val1 = a1[n]; + assert (val1 == expectedResult); + + const Poco::DynamicAny& c1 = a1; + const Poco::DynamicAny& cval1 = a1[n]; + assert (cval1 == expectedResult); + } + + template void testLimitsSigned() { diff --git a/Net/include/Poco/Net/HTTPClientSession.h b/Net/include/Poco/Net/HTTPClientSession.h index e2e51efaa..036634bbc 100644 --- a/Net/include/Poco/Net/HTTPClientSession.h +++ b/Net/include/Poco/Net/HTTPClientSession.h @@ -1,7 +1,7 @@ // // HTTPClientSession.h // -// $Id: //poco/Main/Net/include/Poco/Net/HTTPClientSession.h#5 $ +// $Id: //poco/Main/Net/include/Poco/Net/HTTPClientSession.h#6 $ // // Library: Net // Package: HTTPClient @@ -214,6 +214,9 @@ private: bool _expectResponseBody; std::ostream* _pRequestStream; std::istream* _pResponseStream; + + HTTPClientSession(const HTTPClientSession&); + HTTPClientSession& operator = (const HTTPClientSession&); }; diff --git a/Net/include/Poco/Net/HTTPRequest.h b/Net/include/Poco/Net/HTTPRequest.h index 3b85eab83..6b4ec35ea 100644 --- a/Net/include/Poco/Net/HTTPRequest.h +++ b/Net/include/Poco/Net/HTTPRequest.h @@ -1,7 +1,7 @@ // // HTTPRequest.h // -// $Id: //poco/Main/Net/include/Poco/Net/HTTPRequest.h#2 $ +// $Id: //poco/Main/Net/include/Poco/Net/HTTPRequest.h#3 $ // // Library: Net // Package: HTTP @@ -152,6 +152,9 @@ private: std::string _method; std::string _uri; + + HTTPRequest(const HTTPRequest&); + HTTPRequest& operator = (const HTTPRequest&); }; diff --git a/Net/include/Poco/Net/HTTPResponse.h b/Net/include/Poco/Net/HTTPResponse.h index c092fefef..6db55d2b2 100644 --- a/Net/include/Poco/Net/HTTPResponse.h +++ b/Net/include/Poco/Net/HTTPResponse.h @@ -1,7 +1,7 @@ // // HTTPResponse.h // -// $Id: //poco/Main/Net/include/Poco/Net/HTTPResponse.h#2 $ +// $Id: //poco/Main/Net/include/Poco/Net/HTTPResponse.h#3 $ // // Library: Net // Package: HTTP @@ -244,6 +244,9 @@ private: HTTPStatus _status; std::string _reason; + + HTTPResponse(const HTTPResponse&); + HTTPResponse& operator = (const HTTPResponse&); }; diff --git a/Net/include/Poco/Net/StringPartSource.h b/Net/include/Poco/Net/StringPartSource.h index 4963a23ce..306e21c84 100644 --- a/Net/include/Poco/Net/StringPartSource.h +++ b/Net/include/Poco/Net/StringPartSource.h @@ -1,7 +1,7 @@ // // StringPartSource.h // -// $Id: //poco/Main/Net/include/Poco/Net/StringPartSource.h#2 $ +// $Id: //poco/Main/Net/include/Poco/Net/StringPartSource.h#3 $ // // Library: Net // Package: Messages @@ -78,6 +78,9 @@ public: private: std::istringstream _istr; std::string _filename; + + StringPartSource(const StringPartSource&); + StringPartSource& operator = (const StringPartSource&); }; diff --git a/Net/src/HTTPClientSession.cpp b/Net/src/HTTPClientSession.cpp index 8f70d328e..af27bb756 100644 --- a/Net/src/HTTPClientSession.cpp +++ b/Net/src/HTTPClientSession.cpp @@ -1,7 +1,7 @@ // // HTTPClientSession.cpp // -// $Id: //poco/Main/Net/src/HTTPClientSession.cpp#18 $ +// $Id: //poco/Main/Net/src/HTTPClientSession.cpp#19 $ // // Library: Net // Package: HTTPClient @@ -184,7 +184,8 @@ std::ostream& HTTPClientSession::sendRequest(HTTPRequest& request) reconnect(); if (!keepAlive) request.setKeepAlive(false); - request.setHost(_host, _port); + if (!request.has(HTTPRequest::HOST)) + request.setHost(_host, _port); if (!_proxyHost.empty()) request.setURI(getHostInfo() + request.getURI()); _reconnect = keepAlive; diff --git a/Net/src/HTTPServerRequestImpl.cpp b/Net/src/HTTPServerRequestImpl.cpp index 73db13616..485363f9c 100644 --- a/Net/src/HTTPServerRequestImpl.cpp +++ b/Net/src/HTTPServerRequestImpl.cpp @@ -1,7 +1,7 @@ // // HTTPServerRequestImpl.cpp // -// $Id: //poco/Main/Net/src/HTTPServerRequestImpl.cpp#2 $ +// $Id: //poco/Main/Net/src/HTTPServerRequestImpl.cpp#3 $ // // Library: Net // Package: HTTPServer @@ -54,9 +54,7 @@ namespace Net { HTTPServerRequestImpl::HTTPServerRequestImpl(HTTPServerResponse& response, HTTPServerSession& session, HTTPServerParams* pParams): _response(response), _pStream(0), - _pParams(pParams), - _clientAddress(session.clientAddress()), - _serverAddress(session.serverAddress()) + _pParams(pParams) { poco_check_ptr (_pParams); @@ -65,6 +63,10 @@ HTTPServerRequestImpl::HTTPServerRequestImpl(HTTPServerResponse& response, HTTPS HTTPHeaderInputStream hs(session); read(hs); + // Now that we know socket is still connected, obtain addresses + _clientAddress = session.clientAddress(); + _serverAddress = session.serverAddress(); + if (getChunkedTransferEncoding()) _pStream = new HTTPChunkedInputStream(session); else if (getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH) diff --git a/Net/src/NetworkInterface.cpp b/Net/src/NetworkInterface.cpp index 886c6b65e..ab360fc91 100644 --- a/Net/src/NetworkInterface.cpp +++ b/Net/src/NetworkInterface.cpp @@ -1,7 +1,7 @@ // // NetworkInterface.cpp // -// $Id: //poco/Main/Net/src/NetworkInterface.cpp#20 $ +// $Id: //poco/Main/Net/src/NetworkInterface.cpp#21 $ // // Library: Net // Package: Sockets @@ -394,7 +394,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list() #endif // Add IPv4 loopback interface (not returned by GetAdaptersInfo) - result.push_back(NetworkInterface("Loopback", IPAddress("127.0.0.1"), -1)); + result.push_back(NetworkInterface("Loopback", IPAddress("127.0.0.1"), IPAddress("255.0.0.0"), IPAddress(), -1)); // On Windows 2000 we use GetAdaptersInfo. PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pInfo = 0; @@ -420,10 +420,13 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list() while (pInfo) { IPAddress address(std::string(pInfo->IpAddressList.IpAddress.String)); - IPAddress subnetMask(std::string(pInfo->IpAddressList.IpMask.String)); - IPAddress broadcastAddress(address); - broadcastAddress.mask(subnetMask, IPAddress("255.255.255.255")); - result.push_back(NetworkInterface(std::string(pInfo->AdapterName), address, subnetMask, broadcastAddress)); + if (!address.isWildcard()) // only return interfaces that have an address assigned. + { + IPAddress subnetMask(std::string(pInfo->IpAddressList.IpMask.String)); + IPAddress broadcastAddress(address); + broadcastAddress.mask(subnetMask, IPAddress("255.255.255.255")); + result.push_back(NetworkInterface(std::string(pInfo->AdapterName), address, subnetMask, broadcastAddress)); + } pInfo = pInfo->Next; } } diff --git a/NetSSL_OpenSSL/include/Poco/Net/HTTPSClientSession.h b/NetSSL_OpenSSL/include/Poco/Net/HTTPSClientSession.h index ba53f0bb5..3ea6a4130 100644 --- a/NetSSL_OpenSSL/include/Poco/Net/HTTPSClientSession.h +++ b/NetSSL_OpenSSL/include/Poco/Net/HTTPSClientSession.h @@ -1,7 +1,7 @@ // // HTTPSClientSession.h // -// $Id: //poco/Main/NetSSL_OpenSSL/include/Poco/Net/HTTPSClientSession.h#7 $ +// $Id: //poco/Main/NetSSL_OpenSSL/include/Poco/Net/HTTPSClientSession.h#8 $ // // Library: NetSSL_OpenSSL // Package: HTTPSClient @@ -99,6 +99,10 @@ protected: std::string getHostInfo() const; /// Returns the target host and port number for proxy requests. + +private: + HTTPSClientSession(const HTTPSClientSession&); + HTTPSClientSession& operator = (const HTTPSClientSession&); }; diff --git a/NetSSL_OpenSSL/src/SecureSocketImpl.cpp b/NetSSL_OpenSSL/src/SecureSocketImpl.cpp index 099eaef85..ee8c5b743 100644 --- a/NetSSL_OpenSSL/src/SecureSocketImpl.cpp +++ b/NetSSL_OpenSSL/src/SecureSocketImpl.cpp @@ -1,7 +1,7 @@ // // SecureSocketImpl.cpp // -// $Id: //poco/Main/NetSSL_OpenSSL/src/SecureSocketImpl.cpp#21 $ +// $Id: //poco/Main/NetSSL_OpenSSL/src/SecureSocketImpl.cpp#23 $ // // Library: NetSSL_OpenSSL // Package: SSLSockets @@ -240,10 +240,6 @@ void SecureSocketImpl::connectNB(const SocketAddress& address) } else { - int tmpSocket=0; - BIO_get_fd(_pBIO,&tmpSocket); - poco_assert (-1 != tmpSocket); - setSockfd(tmpSocket); establishTunnel(); connectSSL(address); poco_check_ptr (_pSSL); @@ -317,6 +313,7 @@ int SecureSocketImpl::receiveBytes(void* buffer, int length, int flags) poco_check_ptr (_pSSL); int rc; + bool renegotiating = false; do { rc = SSL_read(_pSSL, buffer, length); @@ -331,6 +328,8 @@ int SecureSocketImpl::receiveBytes(void* buffer, int length, int flags) case SSL_ERROR_NONE: case SSL_ERROR_WANT_WRITE: //renegotiation case SSL_ERROR_WANT_READ: //renegotiation + renegotiating = true; + break; default: ; } @@ -339,7 +338,7 @@ int SecureSocketImpl::receiveBytes(void* buffer, int length, int flags) while (rc < 0 && _socket.lastError() == POCO_EINTR); if (rc < 0) { - if (_socket.lastError() == POCO_EAGAIN || _socket.lastError() == POCO_ETIMEDOUT) + if (renegotiating || _socket.lastError() == POCO_EAGAIN || _socket.lastError() == POCO_ETIMEDOUT) throw TimeoutException(); else SocketImpl::error("failed to read bytes"); diff --git a/Util/include/Poco/Util/Application.h b/Util/include/Poco/Util/Application.h index ccb4ced45..d0bf86131 100644 --- a/Util/include/Poco/Util/Application.h +++ b/Util/include/Poco/Util/Application.h @@ -1,7 +1,7 @@ // // Application.h // -// $Id: //poco/Main/Util/include/Poco/Util/Application.h#14 $ +// $Id: //poco/Main/Util/include/Poco/Util/Application.h#15 $ // // Library: Util // Package: Application @@ -371,6 +371,9 @@ private: static Application* _pInstance; friend class LoggingSubsystem; + + Application(const Application&); + Application& operator = (const Application&); }; diff --git a/Util/include/Poco/Util/Subsystem.h b/Util/include/Poco/Util/Subsystem.h index 3b23d5dbe..b0e067ea7 100644 --- a/Util/include/Poco/Util/Subsystem.h +++ b/Util/include/Poco/Util/Subsystem.h @@ -1,7 +1,7 @@ // // Subsystem.h // -// $Id: //poco/Main/Util/include/Poco/Util/Subsystem.h#3 $ +// $Id: //poco/Main/Util/include/Poco/Util/Subsystem.h#4 $ // // Library: Util // Package: Application @@ -107,6 +107,10 @@ protected: /// Destroys the Subsystem. friend class Application; + +private: + Subsystem(const Subsystem&); + Subsystem& operator = (const Subsystem&); }; diff --git a/XML/include/Poco/XML/expat.h b/XML/include/Poco/XML/expat.h index cf113eeaf..20a8278f7 100644 --- a/XML/include/Poco/XML/expat.h +++ b/XML/include/Poco/XML/expat.h @@ -983,7 +983,8 @@ enum XML_FeatureEnum { XML_FEATURE_MIN_SIZE, XML_FEATURE_SIZEOF_XML_CHAR, XML_FEATURE_SIZEOF_XML_LCHAR, - XML_FEATURE_NS + XML_FEATURE_NS, + XML_FEATURE_LARGE_SIZE /* Additional features must be added to the end of this enum. */ }; @@ -1004,7 +1005,7 @@ XML_GetFeatureList(void); */ #define XML_MAJOR_VERSION 2 #define XML_MINOR_VERSION 0 -#define XML_MICRO_VERSION 0 +#define XML_MICRO_VERSION 1 #ifdef __cplusplus } diff --git a/XML/include/Poco/XML/expat_external.h b/XML/include/Poco/XML/expat_external.h index 1807a8fd1..2c03284ea 100644 --- a/XML/include/Poco/XML/expat_external.h +++ b/XML/include/Poco/XML/expat_external.h @@ -34,9 +34,9 @@ system headers may assume the cdecl convention. */ #ifndef XMLCALL -#if defined(XML_USE_MSC_EXTENSIONS) +#if defined(_MSC_VER) #define XMLCALL __cdecl -#elif defined(__GNUC__) && defined(__i386) +#elif defined(__GNUC__) && defined(__i386) && !defined(__INTEL_COMPILER) #define XMLCALL __attribute__((cdecl)) #else /* For any platform which uses this definition and supports more than @@ -65,6 +65,7 @@ #endif #endif /* not defined XML_STATIC */ + /* If we didn't define it above, define it away: */ #ifndef XMLIMPORT #define XMLIMPORT diff --git a/XML/src/ascii.h b/XML/src/ascii.h index 337e5bb7e..d10530b09 100644 --- a/XML/src/ascii.h +++ b/XML/src/ascii.h @@ -83,3 +83,10 @@ #define ASCII_LSQB 0x5B #define ASCII_RSQB 0x5D #define ASCII_UNDERSCORE 0x5F +#define ASCII_LPAREN 0x28 +#define ASCII_RPAREN 0x29 +#define ASCII_FF 0x0C +#define ASCII_SLASH 0x2F +#define ASCII_HASH 0x23 +#define ASCII_PIPE 0x7C +#define ASCII_COMMA 0x2C diff --git a/XML/src/internal.h b/XML/src/internal.h index ff056c659..dd5454831 100644 --- a/XML/src/internal.h +++ b/XML/src/internal.h @@ -20,7 +20,7 @@ and therefore subject to change. */ -#if defined(__GNUC__) && defined(__i386__) +#if defined(__GNUC__) && defined(__i386__) && !defined(__MINGW32__) /* We'll use this version by default only where we know it helps. regparm() generates warnings on Solaris boxes. See SF bug #692878. diff --git a/XML/src/xmlparse.cpp b/XML/src/xmlparse.cpp index e89cbf27d..da100284b 100644 --- a/XML/src/xmlparse.cpp +++ b/XML/src/xmlparse.cpp @@ -14,10 +14,13 @@ #include "macconfig.h" #elif defined(__amigaos4__) #include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" #elif defined(HAVE_EXPAT_CONFIG_H) #include "expat_config.h" #endif /* ndef COMPILED_FROM_DSP */ +#include "ascii.h" #include "Poco/XML/expat.h" #ifdef XML_UNICODE @@ -26,7 +29,8 @@ #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding #define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS #define XmlEncode XmlUtf16Encode -#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1)) +/* Using pointer subtraction to convert to integer type. */ +#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1)) typedef unsigned short ICHAR; #else #define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX @@ -665,10 +669,12 @@ XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) } static const XML_Char implicitContext[] = { - 'x', 'm', 'l', '=', 'h', 't', 't', 'p', ':', '/', '/', - 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/', - 'X', 'M', 'L', '/', '1', '9', '9', '8', '/', - 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0' + ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, + ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, + ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, + ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, + ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, + ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' }; XML_Parser XMLCALL @@ -761,7 +767,7 @@ parserCreate(const XML_Char *encodingName, unknownEncodingHandler = NULL; unknownEncodingHandlerData = NULL; - namespaceSeparator = '!'; + namespaceSeparator = ASCII_EXCL; ns = XML_FALSE; ns_triplets = XML_FALSE; @@ -1948,6 +1954,9 @@ XML_GetFeatureList(void) #ifdef XML_NS {XML_FEATURE_NS, XML_L("XML_NS"), 0}, #endif +#ifdef XML_LARGE_SIZE + {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, +#endif {XML_FEATURE_END, NULL, 0} }; @@ -2541,27 +2550,30 @@ doContent(XML_Parser parser, } *nextPtr = end; return XML_ERROR_NONE; - case XML_TOK_DATA_CHARS: - if (characterDataHandler) { - if (MUST_CONVERT(enc, s)) { - for (;;) { - ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); - *eventEndPP = s; - characterDataHandler(handlerArg, dataBuf, - (int)(dataPtr - (ICHAR *)dataBuf)); - if (s == next) - break; - *eventPP = s; + case XML_TOK_DATA_CHARS: + { + XML_CharacterDataHandler charDataHandler = characterDataHandler; + if (charDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = s; + charDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + if (s == next) + break; + *eventPP = s; + } } + else + charDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); } - else - characterDataHandler(handlerArg, - (XML_Char *)s, - (int)((XML_Char *)next - (XML_Char *)s)); + else if (defaultHandler) + reportDefault(parser, enc, s, next); } - else if (defaultHandler) - reportDefault(parser, enc, s, next); break; case XML_TOK_PI: if (!reportProcessingInstruction(parser, enc, s, next)) @@ -2806,7 +2818,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc, return XML_ERROR_NO_MEMORY; uriHash = CHAR_HASH(uriHash, c); } - while (*s++ != XML_T(':')) + while (*s++ != XML_T(ASCII_COLON)) ; do { /* copies null terminator */ const XML_Char c = *s; @@ -2880,7 +2892,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc, if (!binding) return XML_ERROR_UNBOUND_PREFIX; localPart = tagNamePtr->str; - while (*localPart++ != XML_T(':')) + while (*localPart++ != XML_T(ASCII_COLON)) ; } else if (dtd->defaultPrefix.binding) { @@ -2935,17 +2947,21 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, const XML_Char *uri, BINDING **bindingsPtr) { static const XML_Char xmlNamespace[] = { - 'h', 't', 't', 'p', ':', '/', '/', - 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/', - 'X', 'M', 'L', '/', '1', '9', '9', '8', '/', - 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0' + ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, + ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, + ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, + ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH, + ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, + ASCII_e, '\0' }; static const int xmlLen = (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; static const XML_Char xmlnsNamespace[] = { - 'h', 't', 't', 'p', ':', '/', '/', - 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/', - '2', '0', '0', '0', '/', 'x', 'm', 'l', 'n', 's', '/', '\0' + ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, + ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, + ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0, + ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, + ASCII_SLASH, '\0' }; static const int xmlnsLen = (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; @@ -2962,13 +2978,13 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, return XML_ERROR_UNDECLARING_PREFIX; if (prefix->name - && prefix->name[0] == XML_T('x') - && prefix->name[1] == XML_T('m') - && prefix->name[2] == XML_T('l')) { + && prefix->name[0] == XML_T(ASCII_x) + && prefix->name[1] == XML_T(ASCII_m) + && prefix->name[2] == XML_T(ASCII_l)) { /* Not allowed to bind xmlns */ - if (prefix->name[3] == XML_T('n') - && prefix->name[4] == XML_T('s') + if (prefix->name[3] == XML_T(ASCII_n) + && prefix->name[4] == XML_T(ASCII_s) && prefix->name[5] == XML_T('\0')) return XML_ERROR_RESERVED_PREFIX_XMLNS; @@ -3122,26 +3138,29 @@ doCdataSection(XML_Parser parser, reportDefault(parser, enc, s, next); break; case XML_TOK_DATA_CHARS: - if (characterDataHandler) { - if (MUST_CONVERT(enc, s)) { - for (;;) { - ICHAR *dataPtr = (ICHAR *)dataBuf; - XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); - *eventEndPP = next; - characterDataHandler(handlerArg, dataBuf, - (int)(dataPtr - (ICHAR *)dataBuf)); - if (s == next) - break; - *eventPP = s; + { + XML_CharacterDataHandler charDataHandler = characterDataHandler; + if (charDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = next; + charDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + if (s == next) + break; + *eventPP = s; + } } + else + charDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); } - else - characterDataHandler(handlerArg, - (XML_Char *)s, - (int)((XML_Char *)next - (XML_Char *)s)); + else if (defaultHandler) + reportDefault(parser, enc, s, next); } - else if (defaultHandler) - reportDefault(parser, enc, s, next); break; case XML_TOK_INVALID: *eventPP = next; @@ -3628,23 +3647,27 @@ doProlog(XML_Parser parser, XML_Bool haveMore) { #ifdef XML_DTD - static const XML_Char externalSubsetName[] = { '#' , '\0' }; + static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' }; #endif /* XML_DTD */ - static const XML_Char atypeCDATA[] = { 'C', 'D', 'A', 'T', 'A', '\0' }; - static const XML_Char atypeID[] = { 'I', 'D', '\0' }; - static const XML_Char atypeIDREF[] = { 'I', 'D', 'R', 'E', 'F', '\0' }; - static const XML_Char atypeIDREFS[] = { 'I', 'D', 'R', 'E', 'F', 'S', '\0' }; - static const XML_Char atypeENTITY[] = { 'E', 'N', 'T', 'I', 'T', 'Y', '\0' }; - static const XML_Char atypeENTITIES[] = - { 'E', 'N', 'T', 'I', 'T', 'I', 'E', 'S', '\0' }; + static const XML_Char atypeCDATA[] = + { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; + static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' }; + static const XML_Char atypeIDREF[] = + { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; + static const XML_Char atypeIDREFS[] = + { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; + static const XML_Char atypeENTITY[] = + { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; + static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N, + ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' }; static const XML_Char atypeNMTOKEN[] = { - 'N', 'M', 'T', 'O', 'K', 'E', 'N', '\0' }; - static const XML_Char atypeNMTOKENS[] = { - 'N', 'M', 'T', 'O', 'K', 'E', 'N', 'S', '\0' }; - static const XML_Char notationPrefix[] = { - 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N', '(', '\0' }; - static const XML_Char enumValueSep[] = { '|', '\0' }; - static const XML_Char enumValueStart[] = { '(', '\0' }; + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; + static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, + ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' }; + static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T, + ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' }; + static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' }; + static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' }; /* save one level of indirection */ DTD * const dtd = _dtd; @@ -3950,11 +3973,11 @@ doProlog(XML_Parser parser, 0, parser)) return XML_ERROR_NO_MEMORY; if (attlistDeclHandler && declAttributeType) { - if (*declAttributeType == XML_T('(') - || (*declAttributeType == XML_T('N') - && declAttributeType[1] == XML_T('O'))) { + if (*declAttributeType == XML_T(ASCII_LPAREN) + || (*declAttributeType == XML_T(ASCII_N) + && declAttributeType[1] == XML_T(ASCII_O))) { /* Enumerated or Notation type */ - if (!poolAppendChar(&tempPool, XML_T(')')) + if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) || !poolAppendChar(&tempPool, XML_T('\0'))) return XML_ERROR_NO_MEMORY; declAttributeType = tempPool.start; @@ -3987,11 +4010,11 @@ doProlog(XML_Parser parser, declAttributeIsCdata, XML_FALSE, attVal, parser)) return XML_ERROR_NO_MEMORY; if (attlistDeclHandler && declAttributeType) { - if (*declAttributeType == XML_T('(') - || (*declAttributeType == XML_T('N') - && declAttributeType[1] == XML_T('O'))) { + if (*declAttributeType == XML_T(ASCII_LPAREN) + || (*declAttributeType == XML_T(ASCII_N) + && declAttributeType[1] == XML_T(ASCII_O))) { /* Enumerated or Notation type */ - if (!poolAppendChar(&tempPool, XML_T(')')) + if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN)) || !poolAppendChar(&tempPool, XML_T('\0'))) return XML_ERROR_NO_MEMORY; declAttributeType = tempPool.start; @@ -4318,14 +4341,14 @@ doProlog(XML_Parser parser, } break; case XML_ROLE_GROUP_SEQUENCE: - if (groupConnector[prologState.level] == '|') + if (groupConnector[prologState.level] == ASCII_PIPE) return XML_ERROR_SYNTAX; - groupConnector[prologState.level] = ','; + groupConnector[prologState.level] = ASCII_COMMA; if (dtd->in_eldecl && elementDeclHandler) handleDefault = XML_FALSE; break; case XML_ROLE_GROUP_CHOICE: - if (groupConnector[prologState.level] == ',') + if (groupConnector[prologState.level] == ASCII_COMMA) return XML_ERROR_SYNTAX; if (dtd->in_eldecl && !groupConnector[prologState.level] @@ -4337,7 +4360,7 @@ doProlog(XML_Parser parser, if (elementDeclHandler) handleDefault = XML_FALSE; } - groupConnector[prologState.level] = '|'; + groupConnector[prologState.level] = ASCII_PIPE; break; case XML_ROLE_PARAM_ENTITY_REF: #ifdef XML_DTD @@ -5267,7 +5290,7 @@ setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) DTD * const dtd = _dtd; /* save one level of indirection */ const XML_Char *name; for (name = elementType->name; *name; name++) { - if (*name == XML_T(':')) { + if (*name == XML_T(ASCII_COLON)) { PREFIX *prefix; const XML_Char *s; for (s = elementType->name; s != name; s++) { @@ -5314,12 +5337,12 @@ getAttributeId(XML_Parser parser, const ENCODING *enc, poolFinish(&dtd->pool); if (!ns) ; - else if (name[0] == XML_T('x') - && name[1] == XML_T('m') - && name[2] == XML_T('l') - && name[3] == XML_T('n') - && name[4] == XML_T('s') - && (name[5] == XML_T('\0') || name[5] == XML_T(':'))) { + else if (name[0] == XML_T(ASCII_x) + && name[1] == XML_T(ASCII_m) + && name[2] == XML_T(ASCII_l) + && name[3] == XML_T(ASCII_n) + && name[4] == XML_T(ASCII_s) + && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { if (name[5] == XML_T('\0')) id->prefix = &dtd->defaultPrefix; else @@ -5330,7 +5353,7 @@ getAttributeId(XML_Parser parser, const ENCODING *enc, int i; for (i = 0; name[i]; i++) { /* attributes without prefix are *not* in the default namespace */ - if (name[i] == XML_T(':')) { + if (name[i] == XML_T(ASCII_COLON)) { int j; for (j = 0; j < i; j++) { if (!poolAppendChar(&dtd->pool, name[j])) @@ -5352,7 +5375,7 @@ getAttributeId(XML_Parser parser, const ENCODING *enc, return id; } -#define CONTEXT_SEP XML_T('\f') +#define CONTEXT_SEP XML_T(ASCII_FF) static const XML_Char * getContext(XML_Parser parser) @@ -5364,7 +5387,7 @@ getContext(XML_Parser parser) if (dtd->defaultPrefix.binding) { int i; int len; - if (!poolAppendChar(&tempPool, XML_T('='))) + if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) return NULL; len = dtd->defaultPrefix.binding->uriLen; if (namespaceSeparator) @@ -5390,7 +5413,7 @@ getContext(XML_Parser parser) for (s = prefix->name; *s; s++) if (!poolAppendChar(&tempPool, *s)) return NULL; - if (!poolAppendChar(&tempPool, XML_T('='))) + if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS))) return NULL; len = prefix->binding->uriLen; if (namespaceSeparator) @@ -5442,7 +5465,7 @@ setContext(XML_Parser parser, const XML_Char *context) context = s; poolDiscard(&tempPool); } - else if (*s == XML_T('=')) { + else if (*s == XML_T(ASCII_EQUALS)) { PREFIX *prefix; if (poolLength(&tempPool) == 0) prefix = &dtd->defaultPrefix; diff --git a/XML/src/xmlrole.c b/XML/src/xmlrole.c index 264951188..f41ca8fce 100644 --- a/XML/src/xmlrole.c +++ b/XML/src/xmlrole.c @@ -10,6 +10,8 @@ #include "macconfig.h" #elif defined(__amigaos4__) #include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" #else #ifdef HAVE_EXPAT_CONFIG_H #include "expat_config.h" @@ -53,12 +55,16 @@ static const char KW_IDREF[] = { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; static const char KW_IDREFS[] = { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; +#ifdef XML_DTD static const char KW_IGNORE[] = { ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' }; +#endif static const char KW_IMPLIED[] = { ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' }; +#ifdef XML_DTD static const char KW_INCLUDE[] = { ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' }; +#endif static const char KW_NDATA[] = { ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; static const char KW_NMTOKEN[] = { diff --git a/XML/src/xmltok.c b/XML/src/xmltok.c index c2f0af73d..44d130903 100644 --- a/XML/src/xmltok.c +++ b/XML/src/xmltok.c @@ -10,6 +10,8 @@ #include "macconfig.h" #elif defined(__amigaos4__) #include "amigaconfig.h" +#elif defined(__WATCOMC__) +#include "watcomconfig.h" #else #ifdef HAVE_EXPAT_CONFIG_H #include "expat_config.h" @@ -295,7 +297,9 @@ sb_charMatches(const ENCODING *enc, const char *p, int c) #endif #define PREFIX(ident) normal_ ## ident +#define XML_TOK_IMPL_C #include "xmltok_impl.c" +#undef XML_TOK_IMPL_C #undef MINBPC #undef BYTE_TYPE @@ -692,7 +696,9 @@ little2_isNmstrtMin(const ENCODING *enc, const char *p) #define IS_NMSTRT_CHAR(enc, p, n) (0) #define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) +#define XML_TOK_IMPL_C #include "xmltok_impl.c" +#undef XML_TOK_IMPL_C #undef MINBPC #undef BYTE_TYPE @@ -831,7 +837,9 @@ big2_isNmstrtMin(const ENCODING *enc, const char *p) #define IS_NMSTRT_CHAR(enc, p, n) (0) #define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) +#define XML_TOK_IMPL_C #include "xmltok_impl.c" +#undef XML_TOK_IMPL_C #undef MINBPC #undef BYTE_TYPE @@ -1610,7 +1618,9 @@ initScan(const ENCODING * const *encodingTable, #define NS(x) x #define ns(x) x +#define XML_TOK_NS_C #include "xmltok_ns.c" +#undef XML_TOK_NS_C #undef NS #undef ns @@ -1619,7 +1629,9 @@ initScan(const ENCODING * const *encodingTable, #define NS(x) x ## NS #define ns(x) x ## _ns +#define XML_TOK_NS_C #include "xmltok_ns.c" +#undef XML_TOK_NS_C #undef NS #undef ns diff --git a/XML/src/xmltok_impl.c b/XML/src/xmltok_impl.c index 0ee57abb1..126881925 100644 --- a/XML/src/xmltok_impl.c +++ b/XML/src/xmltok_impl.c @@ -2,6 +2,9 @@ See the file COPYING for copying permission. */ +/* This file is included! */ +#ifdef XML_TOK_IMPL_C + #ifndef IS_INVALID_CHAR #define IS_INVALID_CHAR(enc, ptr, n) (0) #endif @@ -1777,3 +1780,4 @@ PREFIX(updatePosition)(const ENCODING *enc, #undef CHECK_NMSTRT_CASE #undef CHECK_NMSTRT_CASES +#endif /* XML_TOK_IMPL_C */ diff --git a/XML/src/xmltok_ns.c b/XML/src/xmltok_ns.c index d2f893836..c3b88fdf4 100644 --- a/XML/src/xmltok_ns.c +++ b/XML/src/xmltok_ns.c @@ -1,3 +1,10 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* This file is included! */ +#ifdef XML_TOK_NS_C + const ENCODING * NS(XmlGetUtf8InternalEncoding)(void) { @@ -104,3 +111,5 @@ NS(XmlParseXmlDecl)(int isGeneralTextEntity, encoding, standalone); } + +#endif /* XML_TOK_NS_C */