diff --git a/Foundation/include/Poco/AccessExpirationDecorator.h b/Foundation/include/Poco/AccessExpirationDecorator.h index 552663c04..a1938875a 100644 --- a/Foundation/include/Poco/AccessExpirationDecorator.h +++ b/Foundation/include/Poco/AccessExpirationDecorator.h @@ -1,105 +1,105 @@ -// -// AccessExpirationDecorator.h -// -// $Id: //poco/svn/Foundation/include/Poco/AccessExpirationDecorator.h#2 $ -// -// Library: Foundation -// Package: Events -// Module: AccessExpirationDecorator -// -// Implementation of the AccessExpirationDecorator template. -// -// Copyright (c) 2006, 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_AccessExpirationDecorator_INCLUDED -#define Foundation_AccessExpirationDecorator_INCLUDED - - -#include "Poco/Timestamp.h" -#include "Poco/Timespan.h" - - -namespace Poco { - - -template -class AccessExpirationDecorator - /// AccessExpirationDecorator adds an expiration method to values so that they can be used - /// with the UniqueAccessExpireCache -{ -public: - AccessExpirationDecorator(): - _value(), - _span() - { - } - - AccessExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs): - /// Creates an element that will expire in diff milliseconds - _value(p), - _span(diffInMs*1000) - { - } - - AccessExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan): - /// Creates an element that will expire after the given timeSpan - _value(p), - _span(timeSpan) - { - } - - - ~AccessExpirationDecorator() - { - } - - const Poco::Timespan& getTimeout() const - { - return _span; - } - - const TArgs& value() const - { - return _value; - } - - TArgs& value() - { - return _value; - } - -private: - TArgs _value; - Timespan _span; -}; - - -} // namespace Poco - - -#endif +// +// AccessExpirationDecorator.h +// +// $Id: //poco/svn/Foundation/include/Poco/AccessExpirationDecorator.h#2 $ +// +// Library: Foundation +// Package: Events +// Module: AccessExpirationDecorator +// +// Implementation of the AccessExpirationDecorator template. +// +// Copyright (c) 2006, 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_AccessExpirationDecorator_INCLUDED +#define Foundation_AccessExpirationDecorator_INCLUDED + + +#include "Poco/Timestamp.h" +#include "Poco/Timespan.h" + + +namespace Poco { + + +template +class AccessExpirationDecorator + /// AccessExpirationDecorator adds an expiration method to values so that they can be used + /// with the UniqueAccessExpireCache +{ +public: + AccessExpirationDecorator(): + _value(), + _span() + { + } + + AccessExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs): + /// Creates an element that will expire in diff milliseconds + _value(p), + _span(diffInMs*1000) + { + } + + AccessExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan): + /// Creates an element that will expire after the given timeSpan + _value(p), + _span(timeSpan) + { + } + + + ~AccessExpirationDecorator() + { + } + + const Poco::Timespan& getTimeout() const + { + return _span; + } + + const TArgs& value() const + { + return _value; + } + + TArgs& value() + { + return _value; + } + +private: + TArgs _value; + Timespan _span; +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/AccessExpireCache.h b/Foundation/include/Poco/AccessExpireCache.h index 0034507ab..dee5bdf37 100644 --- a/Foundation/include/Poco/AccessExpireCache.h +++ b/Foundation/include/Poco/AccessExpireCache.h @@ -1,80 +1,80 @@ -// -// AccessExpireCache.h -// -// $Id: //poco/svn/Foundation/include/Poco/AccessExpireCache.h#2 $ -// -// Library: Foundation -// Package: Cache -// Module: AccessExpireCache -// -// Definition of the AccessExpireCache class. -// -// Copyright (c) 2006, 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_AccessExpireCache_INCLUDED -#define Foundation_AccessExpireCache_INCLUDED - - -#include "Poco/AbstractCache.h" -#include "Poco/AccessExpireStrategy.h" - - -namespace Poco { - - -template -class AccessExpireCache: public AbstractCache > - /// An AccessExpireCache caches entries for a fixed time period (per default 10 minutes). - /// Entries expire when they are not accessed with get() during this time period. Each access resets - /// the start time for expiration. - /// Be careful when using an AccessExpireCache. A cache is often used - /// like cache.has(x) followed by cache.get x). Note that it could happen - /// that the "has" call works, then the current execution thread gets descheduled, time passes, - /// the entry gets invalid, thus leading to an empty SharedPtr being returned - /// when "get" is invoked. -{ -public: - AccessExpireCache(Timestamp::TimeDiff expire = 600000): - AbstractCache >(AccessExpireStrategy(expire)) - { - } - - ~AccessExpireCache() - { - } - -private: - AccessExpireCache(const AccessExpireCache& aCache); - AccessExpireCache& operator = (const AccessExpireCache& aCache); -}; - - -} // namespace Poco - - -#endif +// +// AccessExpireCache.h +// +// $Id: //poco/svn/Foundation/include/Poco/AccessExpireCache.h#2 $ +// +// Library: Foundation +// Package: Cache +// Module: AccessExpireCache +// +// Definition of the AccessExpireCache class. +// +// Copyright (c) 2006, 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_AccessExpireCache_INCLUDED +#define Foundation_AccessExpireCache_INCLUDED + + +#include "Poco/AbstractCache.h" +#include "Poco/AccessExpireStrategy.h" + + +namespace Poco { + + +template +class AccessExpireCache: public AbstractCache > + /// An AccessExpireCache caches entries for a fixed time period (per default 10 minutes). + /// Entries expire when they are not accessed with get() during this time period. Each access resets + /// the start time for expiration. + /// Be careful when using an AccessExpireCache. A cache is often used + /// like cache.has(x) followed by cache.get x). Note that it could happen + /// that the "has" call works, then the current execution thread gets descheduled, time passes, + /// the entry gets invalid, thus leading to an empty SharedPtr being returned + /// when "get" is invoked. +{ +public: + AccessExpireCache(Timestamp::TimeDiff expire = 600000): + AbstractCache >(AccessExpireStrategy(expire)) + { + } + + ~AccessExpireCache() + { + } + +private: + AccessExpireCache(const AccessExpireCache& aCache); + AccessExpireCache& operator = (const AccessExpireCache& aCache); +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/AccessExpireLRUCache.h b/Foundation/include/Poco/AccessExpireLRUCache.h index 8da3698ce..39f138c54 100644 --- a/Foundation/include/Poco/AccessExpireLRUCache.h +++ b/Foundation/include/Poco/AccessExpireLRUCache.h @@ -1,82 +1,82 @@ -// -// AccessExpireLRUCache.h -// -// $Id: //poco/svn/Foundation/include/Poco/AccessExpireLRUCache.h#2 $ -// -// Library: Foundation -// Package: Cache -// Module: AccessExpireLRUCache -// -// Definition of the AccessExpireLRUCache class. -// -// Copyright (c) 2006, 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_AccessExpireLRUCache_INCLUDED -#define Foundation_AccessExpireLRUCache_INCLUDED - - -#include "Poco/AbstractCache.h" -#include "Poco/StrategyCollection.h" -#include "Poco/AccessExpireStrategy.h" -#include "Poco/LRUStrategy.h" - - -namespace Poco { - - -template < - class TKey, - class TValue -> -class AccessExpireLRUCache: public AbstractCache > - /// An AccessExpireLRUCache combines LRU caching and time based expire caching. - /// It cache entries for a fixed time period (per default 10 minutes) - /// but also limits the size of the cache (per default: 1024). -{ -public: - AccessExpireLRUCache(long cacheSize = 1024, Timestamp::TimeDiff expire = 600000): - AbstractCache >(StrategyCollection()) - { - this->_strategy.pushBack(new LRUStrategy(cacheSize)); - this->_strategy.pushBack(new AccessExpireStrategy(expire)); - } - - ~AccessExpireLRUCache() - { - } - -private: - AccessExpireLRUCache(const AccessExpireLRUCache& aCache); - AccessExpireLRUCache& operator = (const AccessExpireLRUCache& aCache); -}; - - -} // namespace Poco - - -#endif +// +// AccessExpireLRUCache.h +// +// $Id: //poco/svn/Foundation/include/Poco/AccessExpireLRUCache.h#2 $ +// +// Library: Foundation +// Package: Cache +// Module: AccessExpireLRUCache +// +// Definition of the AccessExpireLRUCache class. +// +// Copyright (c) 2006, 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_AccessExpireLRUCache_INCLUDED +#define Foundation_AccessExpireLRUCache_INCLUDED + + +#include "Poco/AbstractCache.h" +#include "Poco/StrategyCollection.h" +#include "Poco/AccessExpireStrategy.h" +#include "Poco/LRUStrategy.h" + + +namespace Poco { + + +template < + class TKey, + class TValue +> +class AccessExpireLRUCache: public AbstractCache > + /// An AccessExpireLRUCache combines LRU caching and time based expire caching. + /// It cache entries for a fixed time period (per default 10 minutes) + /// but also limits the size of the cache (per default: 1024). +{ +public: + AccessExpireLRUCache(long cacheSize = 1024, Timestamp::TimeDiff expire = 600000): + AbstractCache >(StrategyCollection()) + { + this->_strategy.pushBack(new LRUStrategy(cacheSize)); + this->_strategy.pushBack(new AccessExpireStrategy(expire)); + } + + ~AccessExpireLRUCache() + { + } + +private: + AccessExpireLRUCache(const AccessExpireLRUCache& aCache); + AccessExpireLRUCache& operator = (const AccessExpireLRUCache& aCache); +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/AccessExpireStrategy.h b/Foundation/include/Poco/AccessExpireStrategy.h index b362486e9..060e0e563 100644 --- a/Foundation/include/Poco/AccessExpireStrategy.h +++ b/Foundation/include/Poco/AccessExpireStrategy.h @@ -1,93 +1,93 @@ -// -// AccessExpireStrategy.h -// -// $Id: //poco/svn/Foundation/include/Poco/AccessExpireStrategy.h#2 $ -// -// Library: Foundation -// Package: Cache -// Module: AccessExpireStrategy -// -// Definition of the AccessExpireStrategy class. -// -// Copyright (c) 2006, 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_AccessExpireStrategy_INCLUDED -#define Foundation_AccessExpireStrategy_INCLUDED - - -#include "Poco/KeyValueArgs.h" -#include "Poco/ValidArgs.h" -#include "Poco/ExpireStrategy.h" -#include "Poco/Bugcheck.h" -#include "Poco/Timestamp.h" -#include "Poco/EventArgs.h" -#include -#include - - -namespace Poco { - - -template < - class TKey, - class TValue -> -class AccessExpireStrategy: public ExpireStrategy - /// An AccessExpireStrategy implements time and access based expiration of cache entries -{ -public: - AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy(expireTimeInMilliSec) - /// Create an expire strategy. Note that the smallest allowed caching time is 25ms. - /// Anything lower than that is not useful with current operating systems. - { - } - - ~AccessExpireStrategy() - { - } - - void onGet(const void*, const TKey& key) - { - // get triggers an update to the expiration time - typename ExpireStrategy::Iterator it = this->_keys.find(key); - if (it != this->_keys.end()) - { - this->_keyIndex.erase(it->second); - Timestamp now; - typename ExpireStrategy::IndexIterator itIdx = - this->_keyIndex.insert(typename ExpireStrategy::TimeIndex::value_type(now, key)); - it->second = itIdx; - } - } -}; - - -} // namespace Poco - - -#endif +// +// AccessExpireStrategy.h +// +// $Id: //poco/svn/Foundation/include/Poco/AccessExpireStrategy.h#2 $ +// +// Library: Foundation +// Package: Cache +// Module: AccessExpireStrategy +// +// Definition of the AccessExpireStrategy class. +// +// Copyright (c) 2006, 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_AccessExpireStrategy_INCLUDED +#define Foundation_AccessExpireStrategy_INCLUDED + + +#include "Poco/KeyValueArgs.h" +#include "Poco/ValidArgs.h" +#include "Poco/ExpireStrategy.h" +#include "Poco/Bugcheck.h" +#include "Poco/Timestamp.h" +#include "Poco/EventArgs.h" +#include +#include + + +namespace Poco { + + +template < + class TKey, + class TValue +> +class AccessExpireStrategy: public ExpireStrategy + /// An AccessExpireStrategy implements time and access based expiration of cache entries +{ +public: + AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy(expireTimeInMilliSec) + /// Create an expire strategy. Note that the smallest allowed caching time is 25ms. + /// Anything lower than that is not useful with current operating systems. + { + } + + ~AccessExpireStrategy() + { + } + + void onGet(const void*, const TKey& key) + { + // get triggers an update to the expiration time + typename ExpireStrategy::Iterator it = this->_keys.find(key); + if (it != this->_keys.end()) + { + this->_keyIndex.erase(it->second); + Timestamp now; + typename ExpireStrategy::IndexIterator itIdx = + this->_keyIndex.insert(typename ExpireStrategy::TimeIndex::value_type(now, key)); + it->second = itIdx; + } + } +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/AsyncIOChannel.h b/Foundation/include/Poco/AsyncIOChannel.h index 790535798..3d642235a 100644 --- a/Foundation/include/Poco/AsyncIOChannel.h +++ b/Foundation/include/Poco/AsyncIOChannel.h @@ -1,154 +1,154 @@ -// -// AsyncIOChannel.h -// -// $Id: //poco/svn/Foundation/include/Poco/AsyncIOChannel.h#2 $ -// -// Library: Foundation -// Package: AsyncIO -// Module: AsyncIOChannel -// -// Definition of the AsyncIOChannel 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_AsyncIOChannel_INCLUDED -#define Foundation_AsyncIOChannel_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/ActiveDispatcher.h" -#include "Poco/ActiveMethod.h" -#include "Poco/AsyncIOCommand.h" - - -namespace Poco { - - -class Foundation_API AsyncIOChannel: public ActiveDispatcher - /// AsyncIOChannel supports asynchronous I/O operations on - /// streams or other input/output facilities. - /// - /// This implementation of asynchronous I/O is based on - /// blocking I/O operations that are executed in a separate thread. - /// Some operating systems may provide special asynchronous - /// I/O operations at the operating system level. However, these - /// are not used by the current implementation. - /// - /// I/O operations (in the form of AsyncIOCommand subclass instances) - /// are queued for execution on an AsyncIOChannel. The AsyncIOChannel's - /// I/O thread executes all queued commands in FIFO order. - /// - /// Since AsyncIOChannel is based on ActiveDispatcher, the I/O thread is - /// taken from the default thread pool. It should be ensured that the - /// capacity of the default thread pool is sufficient before using - /// asynchronous I/O. For every AsyncIOChannel instance, one thread - /// from the default thread pool is needed. - /// - /// Subclasses of AsyncIOChannel implement asynchronous input/output - /// for streams and sockets. - /// - /// The enqueue() active member function is used to enqueue AsyncIOCommand - /// instances for execution. - /// - /// The cancel() member function (inherited from ActiveDispatcher) can be - /// used to cancel all pending requests. - /// - /// Both the AsyncIOCommand class, and the AsyncIOChannel class offer events - /// that notify an interested party about the successful or unsuccessful - /// completion of a command. - /// - /// There are also two ways to wait for the completion of a command and - /// obtain its result. The first one is by using the return value of - /// enqueue(), which is ActiveResult. See the ActiveResult class - /// template for more information. The second one is by using the functions - /// of AsyncIOCommand, such as wait(), succeeded() and result(). - /// - /// AsyncIOChannel supports the operations write, read and seek directly. However, - /// subclasses of AsyncIOChannel can define additional operations. -{ -public: - ActiveMethod > enqueue; - /// Actual signature: - /// int enqueueImpl(const AsyncIOCommand::Ptr& pCommand); - /// - /// Enqueue the given command for eventual execution. - /// Returns the number of bytes read or written if the operation - /// was successful. - - BasicEvent commandCompleted; - /// Fired when a command has successfully completed. - - BasicEvent commandFailed; - /// Fired when a command has failed. - - virtual int write(const void* buffer, int length); - /// Write length bytes from buffer. - /// - /// Must be overridden by subclasses. The default implementation - /// throws a NotImplementedException. - /// - /// Returns the number of bytes written. - - virtual int read(void* buffer, int length); - /// Read up to length bytes into buffer. - /// - /// Must be overridden by subclasses. The default implementation - /// throws a NotImplementedException. - /// - /// Returns the number of bytes read. - - virtual int seek(std::streamoff off, std::ios::seekdir dir); - /// Sets the current read/write position. - /// - /// Must be overridden by subclasses. The default implementation - /// throws a NotImplementedException. - /// - /// Always returns 0. - -protected: - AsyncIOChannel(); - /// Creates the AsyncIOChannel. - - ~AsyncIOChannel(); - /// Destroys the AsyncIOChannel. - - int enqueueImpl(const AsyncIOCommand::Ptr& pCommand); - /// Execute the given command by calling - /// pCommand->execute(this); - /// and return the result. - -private: - AsyncIOChannel(const AsyncIOChannel&); - AsyncIOChannel& operator = (const AsyncIOChannel&); -}; - - -} // namespace Poco - - -#endif // Foundation_AsyncIOChannel_INCLUDED +// +// AsyncIOChannel.h +// +// $Id: //poco/svn/Foundation/include/Poco/AsyncIOChannel.h#2 $ +// +// Library: Foundation +// Package: AsyncIO +// Module: AsyncIOChannel +// +// Definition of the AsyncIOChannel 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_AsyncIOChannel_INCLUDED +#define Foundation_AsyncIOChannel_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/ActiveDispatcher.h" +#include "Poco/ActiveMethod.h" +#include "Poco/AsyncIOCommand.h" + + +namespace Poco { + + +class Foundation_API AsyncIOChannel: public ActiveDispatcher + /// AsyncIOChannel supports asynchronous I/O operations on + /// streams or other input/output facilities. + /// + /// This implementation of asynchronous I/O is based on + /// blocking I/O operations that are executed in a separate thread. + /// Some operating systems may provide special asynchronous + /// I/O operations at the operating system level. However, these + /// are not used by the current implementation. + /// + /// I/O operations (in the form of AsyncIOCommand subclass instances) + /// are queued for execution on an AsyncIOChannel. The AsyncIOChannel's + /// I/O thread executes all queued commands in FIFO order. + /// + /// Since AsyncIOChannel is based on ActiveDispatcher, the I/O thread is + /// taken from the default thread pool. It should be ensured that the + /// capacity of the default thread pool is sufficient before using + /// asynchronous I/O. For every AsyncIOChannel instance, one thread + /// from the default thread pool is needed. + /// + /// Subclasses of AsyncIOChannel implement asynchronous input/output + /// for streams and sockets. + /// + /// The enqueue() active member function is used to enqueue AsyncIOCommand + /// instances for execution. + /// + /// The cancel() member function (inherited from ActiveDispatcher) can be + /// used to cancel all pending requests. + /// + /// Both the AsyncIOCommand class, and the AsyncIOChannel class offer events + /// that notify an interested party about the successful or unsuccessful + /// completion of a command. + /// + /// There are also two ways to wait for the completion of a command and + /// obtain its result. The first one is by using the return value of + /// enqueue(), which is ActiveResult. See the ActiveResult class + /// template for more information. The second one is by using the functions + /// of AsyncIOCommand, such as wait(), succeeded() and result(). + /// + /// AsyncIOChannel supports the operations write, read and seek directly. However, + /// subclasses of AsyncIOChannel can define additional operations. +{ +public: + ActiveMethod > enqueue; + /// Actual signature: + /// int enqueueImpl(const AsyncIOCommand::Ptr& pCommand); + /// + /// Enqueue the given command for eventual execution. + /// Returns the number of bytes read or written if the operation + /// was successful. + + BasicEvent commandCompleted; + /// Fired when a command has successfully completed. + + BasicEvent commandFailed; + /// Fired when a command has failed. + + virtual int write(const void* buffer, int length); + /// Write length bytes from buffer. + /// + /// Must be overridden by subclasses. The default implementation + /// throws a NotImplementedException. + /// + /// Returns the number of bytes written. + + virtual int read(void* buffer, int length); + /// Read up to length bytes into buffer. + /// + /// Must be overridden by subclasses. The default implementation + /// throws a NotImplementedException. + /// + /// Returns the number of bytes read. + + virtual int seek(std::streamoff off, std::ios::seekdir dir); + /// Sets the current read/write position. + /// + /// Must be overridden by subclasses. The default implementation + /// throws a NotImplementedException. + /// + /// Always returns 0. + +protected: + AsyncIOChannel(); + /// Creates the AsyncIOChannel. + + ~AsyncIOChannel(); + /// Destroys the AsyncIOChannel. + + int enqueueImpl(const AsyncIOCommand::Ptr& pCommand); + /// Execute the given command by calling + /// pCommand->execute(this); + /// and return the result. + +private: + AsyncIOChannel(const AsyncIOChannel&); + AsyncIOChannel& operator = (const AsyncIOChannel&); +}; + + +} // namespace Poco + + +#endif // Foundation_AsyncIOChannel_INCLUDED diff --git a/Foundation/include/Poco/AsyncIOCommand.h b/Foundation/include/Poco/AsyncIOCommand.h index da78eed86..28a5cbe43 100644 --- a/Foundation/include/Poco/AsyncIOCommand.h +++ b/Foundation/include/Poco/AsyncIOCommand.h @@ -1,319 +1,319 @@ -// -// AsyncIOCommand.h -// -// $Id: //poco/svn/Foundation/include/Poco/AsyncIOCommand.h#2 $ -// -// Library: Foundation -// Package: AsyncIO -// Module: AsyncIOCommand -// -// Definition of the AsyncIOCommand class and subclasses. -// -// 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_AsyncIOCommand_INCLUDED -#define Foundation_AsyncIOCommand_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/RefCountedObject.h" -#include "Poco/AutoPtr.h" -#include "Poco/Event.h" -#include "Poco/BasicEvent.h" -#include "Poco/AsyncIOEvent.h" -#include "Poco/Exception.h" -#include - - -namespace Poco { - - -class AsyncIOChannel; - - -class Foundation_API AsyncIOCommand: public RefCountedObject - /// AsyncIOCommand is the base class for all asynchronous input/output - /// commands used with AsyncIOChannel. - /// - /// See class AsyncIOChannel for more information about asynchronous input/output. -{ -public: - typedef AutoPtr Ptr; - - enum State - { - CMD_PENDING, /// Command is queued for execution. - CMD_IN_PROGRESS, /// Command is currently being executed. - CMD_COMPLETED, /// Command has completed successfully. - CMD_FAILED /// Command has failed. - }; - - BasicEvent commandCompleted; - /// Fired when the command has successfully completed. - - BasicEvent commandFailed; - /// Fired when the command has failed. - - State state() const; - /// Returns the current state of the command. - - void wait(); - /// Waits for the completion of the command. - - void wait(long milliseconds); - /// Waits at most the given timeout for the - /// completion of the command. Throws a - /// TimeoutException if the command does - /// not complete within the given timeout. - - bool tryWait(long milliseconds); - /// Waits at most the given timeout for the - /// completion of the command. - /// - /// Returns true if the command completes within - /// the given timeout, otherwise false. - - bool succeeded() const; - /// Returns true iff the command completed successfully. - - bool failed() const; - /// Returns true iff the command has completed with an error. - - const Exception* exception() const; - /// If the command failed with an exception, returns a - /// clone of the exception. Otherwise, returns a null pointer. - - int execute(AsyncIOChannel& channel); - /// Executes the command on the given AsyncIOChannel. - /// - /// Sets the state to CMD_IN_PROGRESS, calls - /// executeImpl(), and, according to its result, - /// sets the state to CMD_COMPLETED or CMD_FAILED - /// and signals the event. - /// - /// Returns the number of bytes processed by the - /// command. - - int result() const; - /// Returns the result of the command. - -protected: - AsyncIOCommand(); - /// Creates the AsyncIOCommand. - - ~AsyncIOCommand(); - /// Destroys the AsyncIOCommand. - - virtual int executeImpl(AsyncIOChannel& channel) = 0; - /// Executes the command on the given AsyncIOChannel. - /// Must be overridded by subclasses. - /// - /// Returns the number of bytes processed by the - /// command. - -private: - State _state; - Event _completed; - int _result; - Exception* _pException; -}; - - -class Foundation_API AsyncWriteCommand: public AsyncIOCommand - /// An asynchronous write command. -{ -public: - AsyncWriteCommand(const void* buffer, int length); - /// Create an AsyncWriteCommand for writing length bytes - /// from the given buffer. The given buffer must be - /// valid until the command completes. - - const void* buffer() const; - /// Returns the buffer's address. - - int length() const; - /// Returns the buffer's size. - -protected: - int executeImpl(AsyncIOChannel& channel); - ~AsyncWriteCommand(); - -private: - AsyncWriteCommand(); - - const void* _buffer; - int _length; -}; - - -class Foundation_API AsyncBufferedWriteCommand: public AsyncWriteCommand - /// An asynchronous write command. The difference to - /// AsyncWriteCommand is that AsyncBufferedWriteCommand - /// copies the data in the buffer into an internal buffer, thus - /// the given buffer can be deleted as soon as the constructor - /// returns. -{ -public: - AsyncBufferedWriteCommand(const void* buffer, int length); - /// Create an AsyncBufferedWriteCommand for writing length bytes - /// from the given buffer and copies the data from the - /// given buffer into an internal buffer. - /// - /// The internal buffer can be accessed via the buffer() - /// member function inherited from AsyncWriteCommand. - -protected: - ~AsyncBufferedWriteCommand(); -}; - - -class Foundation_API AsyncReadCommand: public AsyncIOCommand - /// An asynchronous read command. -{ -public: - AsyncReadCommand(void* buffer, int length); - /// Create an AsyncReadCommand for reading up to length - /// bytes into the given buffer. - - void* buffer() const; - /// Returns the buffer's address. - - int length() const; - /// Returns the buffer's size. - -protected: - int executeImpl(AsyncIOChannel& channel); - ~AsyncReadCommand(); - -private: - AsyncReadCommand(); - - void* _buffer; - int _length; -}; - - -class Foundation_API AsyncBufferedReadCommand: public AsyncReadCommand - /// An asynchronous read command. In contrast to - /// AsyncReadCommand, which requires an externally supplied - /// buffer that must be valid until the command completes, - /// AsyncBufferedReadCommand maintains an internal buffer. -{ -public: - AsyncBufferedReadCommand(int length); - /// Create an AsyncReadCommand for reading up to length - /// bytes into an internal buffer. - /// - /// The buffer can be accessed via the buffer() member - /// function inherited from AsyncReadCommand. - -protected: - ~AsyncBufferedReadCommand(); -}; - - -class Foundation_API AsyncSeekCommand: public AsyncIOCommand - /// An asynchronous seek command. -{ -public: - AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir = std::ios::beg); - /// Creates an AsyncSeekCommand for setting the current read/write position. - -protected: - int executeImpl(AsyncIOChannel& channel); - ~AsyncSeekCommand(); - -private: - AsyncSeekCommand(); - - std::streamoff _off; - std::ios::seekdir _dir; -}; - - -// -// inlines -// -inline AsyncIOCommand::State AsyncIOCommand::state() const -{ - return _state; -} - - -inline int AsyncIOCommand::result() const -{ - return _result; -} - - -inline const Exception* AsyncIOCommand::exception() const -{ - return _pException; -} - - -inline bool AsyncIOCommand::succeeded() const -{ - return _state == CMD_COMPLETED; -} - - -inline bool AsyncIOCommand::failed() const -{ - return _state == CMD_FAILED; -} - - -inline const void* AsyncWriteCommand::buffer() const -{ - return _buffer; -} - - -inline int AsyncWriteCommand::length() const -{ - return _length; -} - - -inline void* AsyncReadCommand::buffer() const -{ - return _buffer; -} - - -inline int AsyncReadCommand::length() const -{ - return _length; -} - - -} // namespace Poco - - -#endif // Foundation_AsyncIOCommand_INCLUDED +// +// AsyncIOCommand.h +// +// $Id: //poco/svn/Foundation/include/Poco/AsyncIOCommand.h#2 $ +// +// Library: Foundation +// Package: AsyncIO +// Module: AsyncIOCommand +// +// Definition of the AsyncIOCommand class and subclasses. +// +// 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_AsyncIOCommand_INCLUDED +#define Foundation_AsyncIOCommand_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/RefCountedObject.h" +#include "Poco/AutoPtr.h" +#include "Poco/Event.h" +#include "Poco/BasicEvent.h" +#include "Poco/AsyncIOEvent.h" +#include "Poco/Exception.h" +#include + + +namespace Poco { + + +class AsyncIOChannel; + + +class Foundation_API AsyncIOCommand: public RefCountedObject + /// AsyncIOCommand is the base class for all asynchronous input/output + /// commands used with AsyncIOChannel. + /// + /// See class AsyncIOChannel for more information about asynchronous input/output. +{ +public: + typedef AutoPtr Ptr; + + enum State + { + CMD_PENDING, /// Command is queued for execution. + CMD_IN_PROGRESS, /// Command is currently being executed. + CMD_COMPLETED, /// Command has completed successfully. + CMD_FAILED /// Command has failed. + }; + + BasicEvent commandCompleted; + /// Fired when the command has successfully completed. + + BasicEvent commandFailed; + /// Fired when the command has failed. + + State state() const; + /// Returns the current state of the command. + + void wait(); + /// Waits for the completion of the command. + + void wait(long milliseconds); + /// Waits at most the given timeout for the + /// completion of the command. Throws a + /// TimeoutException if the command does + /// not complete within the given timeout. + + bool tryWait(long milliseconds); + /// Waits at most the given timeout for the + /// completion of the command. + /// + /// Returns true if the command completes within + /// the given timeout, otherwise false. + + bool succeeded() const; + /// Returns true iff the command completed successfully. + + bool failed() const; + /// Returns true iff the command has completed with an error. + + const Exception* exception() const; + /// If the command failed with an exception, returns a + /// clone of the exception. Otherwise, returns a null pointer. + + int execute(AsyncIOChannel& channel); + /// Executes the command on the given AsyncIOChannel. + /// + /// Sets the state to CMD_IN_PROGRESS, calls + /// executeImpl(), and, according to its result, + /// sets the state to CMD_COMPLETED or CMD_FAILED + /// and signals the event. + /// + /// Returns the number of bytes processed by the + /// command. + + int result() const; + /// Returns the result of the command. + +protected: + AsyncIOCommand(); + /// Creates the AsyncIOCommand. + + ~AsyncIOCommand(); + /// Destroys the AsyncIOCommand. + + virtual int executeImpl(AsyncIOChannel& channel) = 0; + /// Executes the command on the given AsyncIOChannel. + /// Must be overridded by subclasses. + /// + /// Returns the number of bytes processed by the + /// command. + +private: + State _state; + Event _completed; + int _result; + Exception* _pException; +}; + + +class Foundation_API AsyncWriteCommand: public AsyncIOCommand + /// An asynchronous write command. +{ +public: + AsyncWriteCommand(const void* buffer, int length); + /// Create an AsyncWriteCommand for writing length bytes + /// from the given buffer. The given buffer must be + /// valid until the command completes. + + const void* buffer() const; + /// Returns the buffer's address. + + int length() const; + /// Returns the buffer's size. + +protected: + int executeImpl(AsyncIOChannel& channel); + ~AsyncWriteCommand(); + +private: + AsyncWriteCommand(); + + const void* _buffer; + int _length; +}; + + +class Foundation_API AsyncBufferedWriteCommand: public AsyncWriteCommand + /// An asynchronous write command. The difference to + /// AsyncWriteCommand is that AsyncBufferedWriteCommand + /// copies the data in the buffer into an internal buffer, thus + /// the given buffer can be deleted as soon as the constructor + /// returns. +{ +public: + AsyncBufferedWriteCommand(const void* buffer, int length); + /// Create an AsyncBufferedWriteCommand for writing length bytes + /// from the given buffer and copies the data from the + /// given buffer into an internal buffer. + /// + /// The internal buffer can be accessed via the buffer() + /// member function inherited from AsyncWriteCommand. + +protected: + ~AsyncBufferedWriteCommand(); +}; + + +class Foundation_API AsyncReadCommand: public AsyncIOCommand + /// An asynchronous read command. +{ +public: + AsyncReadCommand(void* buffer, int length); + /// Create an AsyncReadCommand for reading up to length + /// bytes into the given buffer. + + void* buffer() const; + /// Returns the buffer's address. + + int length() const; + /// Returns the buffer's size. + +protected: + int executeImpl(AsyncIOChannel& channel); + ~AsyncReadCommand(); + +private: + AsyncReadCommand(); + + void* _buffer; + int _length; +}; + + +class Foundation_API AsyncBufferedReadCommand: public AsyncReadCommand + /// An asynchronous read command. In contrast to + /// AsyncReadCommand, which requires an externally supplied + /// buffer that must be valid until the command completes, + /// AsyncBufferedReadCommand maintains an internal buffer. +{ +public: + AsyncBufferedReadCommand(int length); + /// Create an AsyncReadCommand for reading up to length + /// bytes into an internal buffer. + /// + /// The buffer can be accessed via the buffer() member + /// function inherited from AsyncReadCommand. + +protected: + ~AsyncBufferedReadCommand(); +}; + + +class Foundation_API AsyncSeekCommand: public AsyncIOCommand + /// An asynchronous seek command. +{ +public: + AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir = std::ios::beg); + /// Creates an AsyncSeekCommand for setting the current read/write position. + +protected: + int executeImpl(AsyncIOChannel& channel); + ~AsyncSeekCommand(); + +private: + AsyncSeekCommand(); + + std::streamoff _off; + std::ios::seekdir _dir; +}; + + +// +// inlines +// +inline AsyncIOCommand::State AsyncIOCommand::state() const +{ + return _state; +} + + +inline int AsyncIOCommand::result() const +{ + return _result; +} + + +inline const Exception* AsyncIOCommand::exception() const +{ + return _pException; +} + + +inline bool AsyncIOCommand::succeeded() const +{ + return _state == CMD_COMPLETED; +} + + +inline bool AsyncIOCommand::failed() const +{ + return _state == CMD_FAILED; +} + + +inline const void* AsyncWriteCommand::buffer() const +{ + return _buffer; +} + + +inline int AsyncWriteCommand::length() const +{ + return _length; +} + + +inline void* AsyncReadCommand::buffer() const +{ + return _buffer; +} + + +inline int AsyncReadCommand::length() const +{ + return _length; +} + + +} // namespace Poco + + +#endif // Foundation_AsyncIOCommand_INCLUDED diff --git a/Foundation/include/Poco/AsyncIOEvent.h b/Foundation/include/Poco/AsyncIOEvent.h index 4c5b01d5a..4c32a3867 100644 --- a/Foundation/include/Poco/AsyncIOEvent.h +++ b/Foundation/include/Poco/AsyncIOEvent.h @@ -1,121 +1,121 @@ -// -// AsyncIOEvent.h -// -// $Id: //poco/svn/Foundation/include/Poco/AsyncIOEvent.h#2 $ -// -// Library: Foundation -// Package: AsyncIO -// Module: AsyncIOEvent -// -// Definition of the AsyncIOEvent 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_AsyncIOEvent_INCLUDED -#define Foundation_AsyncIOEvent_INCLUDED - - -#include "Poco/Foundation.h" - - -namespace Poco { - - -class AsyncIOCommand; -class AsyncIOChannel; - - -class Foundation_API AsyncIOEvent - /// The AsyncIOEvent class holds information about an event - /// caused by asynchronous input or output operation. -{ -public: - enum EventKind - { - EV_COMMAND_COMPLETED, - EV_COMMAND_FAILED - }; - - AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what); - /// Creates the AsyncIOEvent. - - AsyncIOEvent(const AsyncIOEvent& event); - /// Creates a AsyncIOEvent from another one. - - ~AsyncIOEvent(); - /// Destroys the AsyncIOEvent. - - AsyncIOEvent& operator = (const AsyncIOEvent& event); - /// Assigns a AsyncIOEvent. - - void swap(AsyncIOEvent& event); - /// Swaps the event with another one. - - AsyncIOCommand& command() const; - /// Returns the command that caused the event. - - AsyncIOChannel& channel() const; - /// Returns the channel that caused the event. - - EventKind what() const; - /// Returns the reason of the event. - -private: - AsyncIOEvent(); - - AsyncIOCommand* _pCommand; - AsyncIOChannel* _pChannel; - EventKind _what; -}; - - -// -// inlines -// -inline AsyncIOCommand& AsyncIOEvent::command() const -{ - return *_pCommand; -} - - -inline AsyncIOChannel& AsyncIOEvent::channel() const -{ - return *_pChannel; -} - - -inline AsyncIOEvent::EventKind AsyncIOEvent::what() const -{ - return _what; -} - - -} // namespace Poco - - -#endif // Foundation_AsyncIOEvent_INCLUDED +// +// AsyncIOEvent.h +// +// $Id: //poco/svn/Foundation/include/Poco/AsyncIOEvent.h#2 $ +// +// Library: Foundation +// Package: AsyncIO +// Module: AsyncIOEvent +// +// Definition of the AsyncIOEvent 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_AsyncIOEvent_INCLUDED +#define Foundation_AsyncIOEvent_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +class AsyncIOCommand; +class AsyncIOChannel; + + +class Foundation_API AsyncIOEvent + /// The AsyncIOEvent class holds information about an event + /// caused by asynchronous input or output operation. +{ +public: + enum EventKind + { + EV_COMMAND_COMPLETED, + EV_COMMAND_FAILED + }; + + AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what); + /// Creates the AsyncIOEvent. + + AsyncIOEvent(const AsyncIOEvent& event); + /// Creates a AsyncIOEvent from another one. + + ~AsyncIOEvent(); + /// Destroys the AsyncIOEvent. + + AsyncIOEvent& operator = (const AsyncIOEvent& event); + /// Assigns a AsyncIOEvent. + + void swap(AsyncIOEvent& event); + /// Swaps the event with another one. + + AsyncIOCommand& command() const; + /// Returns the command that caused the event. + + AsyncIOChannel& channel() const; + /// Returns the channel that caused the event. + + EventKind what() const; + /// Returns the reason of the event. + +private: + AsyncIOEvent(); + + AsyncIOCommand* _pCommand; + AsyncIOChannel* _pChannel; + EventKind _what; +}; + + +// +// inlines +// +inline AsyncIOCommand& AsyncIOEvent::command() const +{ + return *_pCommand; +} + + +inline AsyncIOChannel& AsyncIOEvent::channel() const +{ + return *_pChannel; +} + + +inline AsyncIOEvent::EventKind AsyncIOEvent::what() const +{ + return _what; +} + + +} // namespace Poco + + +#endif // Foundation_AsyncIOEvent_INCLUDED diff --git a/Foundation/include/Poco/AsyncStreamChannel.h b/Foundation/include/Poco/AsyncStreamChannel.h index 7f6503f44..ddaacdc2f 100644 --- a/Foundation/include/Poco/AsyncStreamChannel.h +++ b/Foundation/include/Poco/AsyncStreamChannel.h @@ -1,96 +1,96 @@ -// -// AsyncStreamChannel.h -// -// $Id: //poco/svn/Foundation/include/Poco/AsyncStreamChannel.h#2 $ -// -// Library: Foundation -// Package: AsyncIO -// Module: AsyncStreamChannel -// -// Definition of the AsyncStreamChannel 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_AsyncStreamChannel_INCLUDED -#define Foundation_AsyncStreamChannel_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/AsyncIOChannel.h" -#include -#include -#include - - -namespace Poco { - - -class Foundation_API AsyncStreamChannel: public AsyncIOChannel - /// AsyncStreamChannel provides an AsyncIOChannel for I/O streams. - /// - /// Usage Example: - /// std::stringstream str; - /// AsyncStreamChannel channel(str); - /// channel.enqueue(new AsyncWriteCommand("Hello", 5)); - /// channel.enqueue(new AsyncWriteCommand(", ", 2)); - /// ActiveResult result = channel.enqueue(new AsyncWriteCommand("world!", 6)); - /// result.wait(); - /// std::string s(str.str()); -{ -public: - AsyncStreamChannel(std::istream& istr); - /// Creates an AsyncStreamChannel using the given input stream. - /// Only read and seek operations will be allowed. - - AsyncStreamChannel(std::ostream& ostr); - /// Creates an AsyncStreamChannel using the given output stream. - /// Only write and seek operations will be allowed. - - AsyncStreamChannel(std::iostream& iostr); - /// Creates an AsyncStreamChannel using the given input/output stream. - - ~AsyncStreamChannel(); - /// Destroys the AsyncStreamChannel. - - // AsyncIOChannel - int write(const void* buffer, int length); - int read(void* buffer, int length); - int seek(std::streamoff off, std::ios::seekdir dir); - -private: - AsyncStreamChannel(); - - std::istream* _pIstr; - std::ostream* _pOstr; -}; - - -} // namespace Poco - - -#endif // Foundation_AsyncStreamChannel_INCLUDED +// +// AsyncStreamChannel.h +// +// $Id: //poco/svn/Foundation/include/Poco/AsyncStreamChannel.h#2 $ +// +// Library: Foundation +// Package: AsyncIO +// Module: AsyncStreamChannel +// +// Definition of the AsyncStreamChannel 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_AsyncStreamChannel_INCLUDED +#define Foundation_AsyncStreamChannel_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/AsyncIOChannel.h" +#include +#include +#include + + +namespace Poco { + + +class Foundation_API AsyncStreamChannel: public AsyncIOChannel + /// AsyncStreamChannel provides an AsyncIOChannel for I/O streams. + /// + /// Usage Example: + /// std::stringstream str; + /// AsyncStreamChannel channel(str); + /// channel.enqueue(new AsyncWriteCommand("Hello", 5)); + /// channel.enqueue(new AsyncWriteCommand(", ", 2)); + /// ActiveResult result = channel.enqueue(new AsyncWriteCommand("world!", 6)); + /// result.wait(); + /// std::string s(str.str()); +{ +public: + AsyncStreamChannel(std::istream& istr); + /// Creates an AsyncStreamChannel using the given input stream. + /// Only read and seek operations will be allowed. + + AsyncStreamChannel(std::ostream& ostr); + /// Creates an AsyncStreamChannel using the given output stream. + /// Only write and seek operations will be allowed. + + AsyncStreamChannel(std::iostream& iostr); + /// Creates an AsyncStreamChannel using the given input/output stream. + + ~AsyncStreamChannel(); + /// Destroys the AsyncStreamChannel. + + // AsyncIOChannel + int write(const void* buffer, int length); + int read(void* buffer, int length); + int seek(std::streamoff off, std::ios::seekdir dir); + +private: + AsyncStreamChannel(); + + std::istream* _pIstr; + std::ostream* _pOstr; +}; + + +} // namespace Poco + + +#endif // Foundation_AsyncStreamChannel_INCLUDED diff --git a/Foundation/include/Poco/Checksum.h b/Foundation/include/Poco/Checksum.h index c49a28f3e..c3c6e2190 100644 --- a/Foundation/include/Poco/Checksum.h +++ b/Foundation/include/Poco/Checksum.h @@ -1,130 +1,130 @@ -// -// Checksum.h -// -// $Id: //poco/svn/Foundation/include/Poco/Checksum.h#2 $ -// -// Library: Foundation -// Package: Core -// Module: Checksum -// -// Definition of the Checksum 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_Checksum_INCLUDED -#define Foundation_Checksum_INCLUDED - - -#include "Poco/Foundation.h" - - -namespace Poco { - - -class Foundation_API Checksum - /// This class calculates CRC-32 or Adler-32 checksums - /// for arbitrary data. - /// - /// A cyclic redundancy check (CRC) is a type of hash function, which is used to produce a - /// small, fixed-size checksum of a larger block of data, such as a packet of network - /// traffic or a computer file. CRC-32 is one of the most commonly used CRC algorithms. - /// - /// Adler-32 is a checksum algorithm which was invented by Mark Adler. - /// It is almost as reliable as a 32-bit cyclic redundancy check for protecting against - /// accidental modification of data, such as distortions occurring during a transmission, - /// but is significantly faster to calculate in software. - -{ -public: - enum Type - { - TYPE_ADLER32 = 0, - TYPE_CRC32 - }; - - Checksum(); - /// Creates a CRC-32 checksum initialized to 0. - - Checksum(Type t); - /// Creates the Checksum, using the given type. - - ~Checksum(); - /// Destroys the Checksum. - - void update(const char* data, unsigned length); - /// Updates the checksum with the given data. - - void update(const std::string& data); - /// Updates the checksum with the given data. - - void update(char data); - /// Updates the checksum with the given data. - - Poco::UInt32 checksum() const; - /// Returns the calculated checksum. - - Type type() const; - /// Which type of checksum are we calulcating - -private: - Type _type; - Poco::UInt32 _value; -}; - - -// -// inlines -// -inline void Checksum::update(const std::string& data) -{ - update(data.c_str(), static_cast(data.size())); -} - - -inline void Checksum::update(char c) -{ - update(&c, 1); -} - - -inline Poco::UInt32 Checksum::checksum() const -{ - return _value; -} - - -inline Checksum::Type Checksum::type() const -{ - return _type; -} - - -} // namespace Poco - - -#endif // Foundation_Checksum_INCLUDED +// +// Checksum.h +// +// $Id: //poco/svn/Foundation/include/Poco/Checksum.h#2 $ +// +// Library: Foundation +// Package: Core +// Module: Checksum +// +// Definition of the Checksum 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_Checksum_INCLUDED +#define Foundation_Checksum_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +class Foundation_API Checksum + /// This class calculates CRC-32 or Adler-32 checksums + /// for arbitrary data. + /// + /// A cyclic redundancy check (CRC) is a type of hash function, which is used to produce a + /// small, fixed-size checksum of a larger block of data, such as a packet of network + /// traffic or a computer file. CRC-32 is one of the most commonly used CRC algorithms. + /// + /// Adler-32 is a checksum algorithm which was invented by Mark Adler. + /// It is almost as reliable as a 32-bit cyclic redundancy check for protecting against + /// accidental modification of data, such as distortions occurring during a transmission, + /// but is significantly faster to calculate in software. + +{ +public: + enum Type + { + TYPE_ADLER32 = 0, + TYPE_CRC32 + }; + + Checksum(); + /// Creates a CRC-32 checksum initialized to 0. + + Checksum(Type t); + /// Creates the Checksum, using the given type. + + ~Checksum(); + /// Destroys the Checksum. + + void update(const char* data, unsigned length); + /// Updates the checksum with the given data. + + void update(const std::string& data); + /// Updates the checksum with the given data. + + void update(char data); + /// Updates the checksum with the given data. + + Poco::UInt32 checksum() const; + /// Returns the calculated checksum. + + Type type() const; + /// Which type of checksum are we calulcating + +private: + Type _type; + Poco::UInt32 _value; +}; + + +// +// inlines +// +inline void Checksum::update(const std::string& data) +{ + update(data.c_str(), static_cast(data.size())); +} + + +inline void Checksum::update(char c) +{ + update(&c, 1); +} + + +inline Poco::UInt32 Checksum::checksum() const +{ + return _value; +} + + +inline Checksum::Type Checksum::type() const +{ + return _type; +} + + +} // namespace Poco + + +#endif // Foundation_Checksum_INCLUDED diff --git a/Foundation/include/Poco/Condition.h b/Foundation/include/Poco/Condition.h index 12a8c637a..3d5a47305 100644 --- a/Foundation/include/Poco/Condition.h +++ b/Foundation/include/Poco/Condition.h @@ -1,159 +1,159 @@ -// -// Condition.h -// -// $Id: //poco/svn/Foundation/include/Poco/Condition.h#2 $ -// -// Library: Foundation -// Package: Threading -// Module: Condition -// -// Definition of the Condition class template. -// -// 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_Condition_INCLUDED -#define Foundation_Condition_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/Mutex.h" -#include "Poco/ScopedUnlock.h" -#include "Poco/Event.h" -#include "Poco/Exception.h" -#include - - -namespace Poco { - - -class Foundation_API Condition - /// A Condition is a synchronization object used to block a thread - /// until a particular condition is met. - /// A Condition object is always used in conjunction with - /// a Mutex (or FastMutex) object. - /// - /// Condition objects are similar to POSIX condition variables, which the - /// difference that Condition is not subject to spurious wakeups. - /// - /// Threads waiting on a Condition are resumed in FIFO order. -{ -public: - Condition(); - /// Creates the Condition. - - ~Condition(); - /// Destroys the Condition. - - template - void wait(Mtx& mutex) - /// Unlocks the mutex (which must be locked upon calling - /// wait()) and waits until the Condition is signalled. - /// - /// The given mutex will be locked again upon - /// leaving the function, even in case of an exception. - { - ScopedUnlock unlock(mutex, false); - Event event; - { - FastMutex::ScopedLock lock(_mutex); - mutex.unlock(); - enqueue(event); - } - event.wait(); - } - - template - void wait(Mtx& mutex, long milliseconds) - /// Unlocks the mutex (which must be locked upon calling - /// wait()) and waits for the given time until the Condition is signalled. - /// - /// The given mutex will be locked again upon successfully leaving the - /// function, even in case of an exception. - /// - /// Throws a TimeoutException if the Condition is not signalled - /// within the given time interval. - { - if (!tryWait(mutex, milliseconds)) - throw TimeoutException(); - } - - template - bool tryWait(Mtx& mutex, long milliseconds) - /// Unlocks the mutex (which must be locked upon calling - /// tryWait()) and waits for the given time until the Condition is signalled. - /// - /// The given mutex will be locked again upon leaving the - /// function, even in case of an exception. - /// - /// Returns true if the Condition has been signalled - /// within the given time interval, otherwise false. - { - ScopedUnlock unlock(mutex, false); - Event event; - { - FastMutex::ScopedLock lock(_mutex); - mutex.unlock(); - enqueue(event); - } - if (!event.tryWait(milliseconds)) - { - FastMutex::ScopedLock lock(_mutex); - dequeue(event); - return false; - } - return true; - } - - void signal(); - /// Signals the Condition and allows one waiting thread - /// to continue execution. - - void broadcast(); - /// Signals the Condition and allows all waiting - /// threads to continue their execution. - -protected: - void enqueue(Event& event); - void dequeue(); - void dequeue(Event& event); - -private: - Condition(const Condition&); - Condition& operator = (const Condition&); - - typedef std::deque WaitQueue; - - FastMutex _mutex; - WaitQueue _waitQueue; -}; - - -} // namespace Poco - - -#endif // Foundation_Condition_INCLUDED +// +// Condition.h +// +// $Id: //poco/svn/Foundation/include/Poco/Condition.h#2 $ +// +// Library: Foundation +// Package: Threading +// Module: Condition +// +// Definition of the Condition class template. +// +// 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_Condition_INCLUDED +#define Foundation_Condition_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Mutex.h" +#include "Poco/ScopedUnlock.h" +#include "Poco/Event.h" +#include "Poco/Exception.h" +#include + + +namespace Poco { + + +class Foundation_API Condition + /// A Condition is a synchronization object used to block a thread + /// until a particular condition is met. + /// A Condition object is always used in conjunction with + /// a Mutex (or FastMutex) object. + /// + /// Condition objects are similar to POSIX condition variables, which the + /// difference that Condition is not subject to spurious wakeups. + /// + /// Threads waiting on a Condition are resumed in FIFO order. +{ +public: + Condition(); + /// Creates the Condition. + + ~Condition(); + /// Destroys the Condition. + + template + void wait(Mtx& mutex) + /// Unlocks the mutex (which must be locked upon calling + /// wait()) and waits until the Condition is signalled. + /// + /// The given mutex will be locked again upon + /// leaving the function, even in case of an exception. + { + ScopedUnlock unlock(mutex, false); + Event event; + { + FastMutex::ScopedLock lock(_mutex); + mutex.unlock(); + enqueue(event); + } + event.wait(); + } + + template + void wait(Mtx& mutex, long milliseconds) + /// Unlocks the mutex (which must be locked upon calling + /// wait()) and waits for the given time until the Condition is signalled. + /// + /// The given mutex will be locked again upon successfully leaving the + /// function, even in case of an exception. + /// + /// Throws a TimeoutException if the Condition is not signalled + /// within the given time interval. + { + if (!tryWait(mutex, milliseconds)) + throw TimeoutException(); + } + + template + bool tryWait(Mtx& mutex, long milliseconds) + /// Unlocks the mutex (which must be locked upon calling + /// tryWait()) and waits for the given time until the Condition is signalled. + /// + /// The given mutex will be locked again upon leaving the + /// function, even in case of an exception. + /// + /// Returns true if the Condition has been signalled + /// within the given time interval, otherwise false. + { + ScopedUnlock unlock(mutex, false); + Event event; + { + FastMutex::ScopedLock lock(_mutex); + mutex.unlock(); + enqueue(event); + } + if (!event.tryWait(milliseconds)) + { + FastMutex::ScopedLock lock(_mutex); + dequeue(event); + return false; + } + return true; + } + + void signal(); + /// Signals the Condition and allows one waiting thread + /// to continue execution. + + void broadcast(); + /// Signals the Condition and allows all waiting + /// threads to continue their execution. + +protected: + void enqueue(Event& event); + void dequeue(); + void dequeue(Event& event); + +private: + Condition(const Condition&); + Condition& operator = (const Condition&); + + typedef std::deque WaitQueue; + + FastMutex _mutex; + WaitQueue _waitQueue; +}; + + +} // namespace Poco + + +#endif // Foundation_Condition_INCLUDED diff --git a/Foundation/include/Poco/DynamicAny.h b/Foundation/include/Poco/DynamicAny.h index 1d576609a..e8fab2f34 100644 --- a/Foundation/include/Poco/DynamicAny.h +++ b/Foundation/include/Poco/DynamicAny.h @@ -1,1794 +1,1794 @@ -// -// DynamicAny.h -// -// $Id: //poco/svn/Foundation/include/Poco/DynamicAny.h#2 $ -// -// Library: Foundation -// Package: Core -// Module: DynamicAny -// -// Definition of the DynamicAny 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_DynamicAny_INCLUDED -#define Foundation_DynamicAny_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/DynamicAnyHolder.h" -#include - - -namespace Poco { - - -class Foundation_API DynamicAny - /// DynamicAny allows to store data of different types and to convert between these types transparently. - /// DynamicAny puts forth the best effort to provide intuitive and reasonable conversion semantics and prevent - /// unexpected data loss, particularly when performing narrowing or signedness conversions of numeric data types. - /// - /// Loss of signedness is not allowed for numeric values. This means that if an attempt is made to convert - /// the internal value which is a negative signed integer to an unsigned integer type storage, a RangeException is thrown. - /// Overflow is not allowed, so if the internal value is a larger number than the target numeric type size can accomodate, - /// a RangeException is thrown. - /// - /// Precision loss, such as in conversion from floating-point types to integers or from double to float on platforms - /// where they differ in size (provided internal actual value fits in float min/max range), is allowed. - /// - /// 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. - /// - /// 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). - /// Integer 0 values are false, everything else is true. - /// Floating point values equal to the minimal FP representation on a given platform are false, everything else is true. - /// - /// Arithmetic operations with POD types as well as between DynamicAny's are supported, subject to following - /// limitations: - /// - /// - for std::string and const char* values, only '+' and '+=' operations are supported - /// - /// - for integral and floating point numeric values, following operations are supported: - /// '+', '+=', '-', '-=', '*', '*=' , '/' and '/=' - /// - /// - for integral values, following operations are supported: - /// prefix and postfix increment (++) and decement (--) - /// - /// - for all other types, InvalidArgumentException is thrown upon attempt of an arithmetic operation - /// - /// A DynamicAny can be created from and converted to a value of any type for which a specialization of - /// DynamicAnyHolderImpl is available. For supported types, see DynamicAnyHolder documentation. -{ -public: - DynamicAny(); - /// Creates a DynamicAny holding an int with value 0. - - template - DynamicAny(const T &val): - _pHolder(new DynamicAnyHolderImpl(val)) - /// Creates the DynamicAny from the given value. - { - } - - DynamicAny(const char* pVal); - // Convenience constructor for const char* which gets mapped to a std::string internally, i.e. pVal is deep-copied. - - DynamicAny(const DynamicAny& other); - /// Copy constructor. - - ~DynamicAny(); - /// Destroys the DynamicAny. - - void swap(DynamicAny& other); - /// Swaps the content of the this DynamicAny with the other DynamicAny. - - template - void convert(T& val) const - /// Invoke this method to perform a safe conversion. - /// - /// Example usage: - /// DynamicAny any("42"); - /// int i; - /// any.convert(i); - /// - /// Throws a RangeException if the value does not fit - /// into the result variable. - /// Throws a NotImplementedException if conversion is - /// not available for the given type. - { - _pHolder->convert(val); - } - - template - T convert() const - /// Invoke this method to perform a safe conversion. - /// - /// Example usage: - /// DynamicAny any("42"); - /// int i = any.convert(); - /// - /// Throws a RangeException if the value does not fit - /// into the result variable. - /// Throws a NotImplementedException if conversion is - /// not available for the given type. - { - T result; - _pHolder->convert(result); - return result; - } - - template - operator T () const - /// Safe conversion operator for implicit type - /// conversions. - /// - /// Throws a RangeException if the value does not fit - /// into the result variable. - /// Throws a NotImplementedException if conversion is - /// not available for the given type. - { - T result; - _pHolder->convert(result); - return result; - } - - template - const T& extract() const - /// Returns a const reference to the actual value. - /// - /// Must be instantiated with the exact type of - /// the stored value, otherwise a BadCastException - /// is thrown. - { - DynamicAnyHolderImpl* pHolder = dynamic_cast*>(_pHolder); - if (pHolder) - return pHolder->value(); - else - throw BadCastException(); - } - - template - DynamicAny& operator = (const T& other) - /// Assignment operator for assigning POD to DynamicAny - { - DynamicAny tmp(other); - swap(tmp); - return *this; - } - - DynamicAny& operator = (const DynamicAny& other); - /// Assignment operator specialization for DynamicAny - - template - const DynamicAny operator + (const T& other) const - /// Addition operator for adding POD to DynamicAny - { - return convert() + other; - } - - const DynamicAny operator + (const DynamicAny& other) const; - /// Addition operator specialization for DynamicAny - - const DynamicAny operator + (const char* other) const; - /// Addition operator specialization for adding const char* to DynamicAny - - DynamicAny& operator ++ (); - /// Pre-increment operator - - DynamicAny operator ++ (int); - /// Post-increment operator - - DynamicAny& operator -- (); - /// Pre-decrement operator - - DynamicAny operator -- (int); - /// Post-decrement operator - - template - DynamicAny& operator += (const T& other) - /// Addition asignment operator for addition/assignment of POD to DynamicAny. - { - return *this = convert() + other; - } - - DynamicAny& operator += (const DynamicAny& other); - /// Addition asignment operator specialization for DynamicAny - - DynamicAny& operator += (const char* other); - /// Addition asignment operator specialization for const char* - - template - const DynamicAny operator - (const T& other) const - /// Subtraction operator for subtracting POD from DynamicAny - { - return convert() - other; - } - - const DynamicAny operator - (const DynamicAny& other) const; - /// Subtraction operator specialization for DynamicAny - - template - DynamicAny& operator -= (const T& other) - /// Subtraction asignment operator - { - return *this = convert() - other; - } - - DynamicAny& operator -= (const DynamicAny& other); - /// Subtraction asignment operator specialization for DynamicAny - - template - const DynamicAny operator * (const T& other) const - /// Multiplication operator for multiplying DynamicAny with POD - { - return convert() * other; - } - - const DynamicAny operator * (const DynamicAny& other) const; - /// Multiplication operator specialization for DynamicAny - - template - DynamicAny& operator *= (const T& other) - /// Multiplication asignment operator - { - return *this = convert() * other; - } - - DynamicAny& operator *= (const DynamicAny& other); - /// Multiplication asignment operator specialization for DynamicAny - - template - const DynamicAny operator / (const T& other) const - /// Division operator for dividing DynamicAny with POD - { - return convert() / other; - } - - const DynamicAny operator / (const DynamicAny& other) const; - /// Division operator specialization for DynamicAny - - template - DynamicAny& operator /= (const T& other) - /// Division asignment operator - { - return *this = convert() / other; - } - - DynamicAny& operator /= (const DynamicAny& other); - /// Division asignment operator specialization for DynamicAny - - template - bool operator == (const T& other) const - /// Equality operator - { - return convert() == other; - } - - bool operator == (const char* other) const; - /// Equality operator specialization for const char* - - bool operator == (const DynamicAny& other) const; - /// Equality operator specialization for DynamicAny - - template - bool operator != (const T& other) const - /// Inequality operator - { - return convert() != other; - } - - bool operator != (const DynamicAny& other) const; - /// Inequality operator specialization for DynamicAny - - bool operator != (const char* other) const; - /// Inequality operator specialization for const char* - - template - bool operator < (const T& other) const - /// Less than operator - { - return convert() < other; - } - - template - bool operator <= (const T& other) const - /// Less than or equal operator - { - return convert() <= other; - } - - template - bool operator > (const T& other) const - /// Greater than operator - { - return convert() > other; - } - - template - bool operator >= (const T& other) const - /// Greater than or equal operator - { - return convert() >= other; - } - - bool isArray() const; - /// Returns true if DynamicAny represents a vector - - bool isStruct() const; - /// Returns true if DynamicAny represents a struct - - template - DynamicAny& operator [] (T n) - /// Index operator, only use on DynamicAnys where isArray - /// returns true! In all other cases a BadCastException is thrown! - { - DynamicAnyHolderImpl >* pHolder = - dynamic_cast > *>(_pHolder); - if (pHolder) - return pHolder->operator[](n); - else - throw BadCastException(); - } - - template - const DynamicAny& operator [] (T n) const - /// const Index operator, only use on DynamicAnys where isArray - /// returns true! In all other cases a BadCastException is thrown! - { - const DynamicAnyHolderImpl >* pHolder = - dynamic_cast > *>(_pHolder); - if (pHolder) - return pHolder->operator[](n); - else - throw BadCastException(); - } - - 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! - - DynamicAny& operator [] (const char* 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 char* 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. - - bool isInteger() const; - /// Returns true if stored value is integer. - - bool isSigned() const; - /// Returns true if stored value is signed. - - bool isNumeric() const; - /// Returns true if stored value is numeric. - /// Returns false for numeric strings (e.g. "123" is string, not number) - - bool isString() const; - /// Returns true if stored value is std::string. - - 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); - - template - T add(const DynamicAny& other) const - { - return convert() + other.convert(); - } - - template - T subtract(const DynamicAny& other) const - { - return convert() - other.convert(); - } - - template - T multiply(const DynamicAny& other) const - { - return convert() * other.convert(); - } - - template - T divide(const DynamicAny& other) const - { - return convert() / other.convert(); - } - - DynamicAnyHolder* _pHolder; -}; - - -/// -/// inlines -/// - - -/// -/// DynamicAny members -/// - -inline void DynamicAny::swap(DynamicAny& ptr) -{ - std::swap(_pHolder, ptr._pHolder); -} - - -inline const std::type_info& DynamicAny::type() const -{ - return _pHolder->type(); -} - - -inline DynamicAny& DynamicAny::operator [] (const char* name) -{ - return operator [] (std::string(name)); -} - - -inline const DynamicAny& DynamicAny::operator [] (const char* name) const -{ - return operator [] (std::string(name)); -} - - -inline const DynamicAny DynamicAny::operator + (const char* other) const -{ - return convert() + other; -} - - -inline DynamicAny& DynamicAny::operator += (const char*other) -{ - return *this = convert() + other; -} - - -inline bool DynamicAny::operator == (const DynamicAny& other) const -{ - return convert() == other.convert(); -} - - -inline bool DynamicAny::operator == (const char* other) const -{ - return convert() == other; -} - - -inline bool DynamicAny::operator != (const DynamicAny& other) const -{ - return convert() != other.convert(); -} - - -inline bool DynamicAny::operator != (const char* other) const -{ - return convert() != other; -} - - -inline bool DynamicAny::isArray() const -{ - return _pHolder->isArray(); -} - - -inline bool DynamicAny::isStruct() const -{ - return _pHolder->isStruct(); -} - - -inline bool DynamicAny::isInteger() const -{ - return _pHolder->isInteger(); -} - - -inline bool DynamicAny::isSigned() const -{ - return _pHolder->isSigned(); -} - - -inline bool DynamicAny::isNumeric() const -{ - return _pHolder->isNumeric(); -} - - -inline bool DynamicAny::isString() const -{ - return _pHolder->isString(); -} - - -/// -/// DynamicAny non-member functions -/// - -inline const DynamicAny operator + (const char* other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to const char* -{ - std::string tmp = other; - return tmp + da.convert(); -} - - -inline const char operator + (const char& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to char -{ - return other + da.convert(); -} - - -inline const char operator - (const char& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from char -{ - return other - da.convert(); -} - - -inline const char operator * (const char& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with char -{ - return other * da.convert(); -} - - -inline const char operator / (const char& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with char -{ - return other / da.convert(); -} - - -inline char operator += (char& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to char -{ - return other += da.convert(); -} - - -inline char operator -= (char& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from char -{ - return other -= da.convert(); -} - - -inline char operator *= (char& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with char -{ - return other *= da.convert(); -} - - -inline char operator /= (char& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with char -{ - return other /= da.convert(); -} - - -inline const bool operator == (const char& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with char -{ - return other == da.convert(); -} - - -inline const bool operator != (const char& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with char -{ - return other != da.convert(); -} - - -inline const bool operator < (const char& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with char -{ - return other < da.convert(); -} - - -inline const bool operator <= (const char& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with char -{ - return other <= da.convert(); -} - - -inline const bool operator > (const char& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with char -{ - return other > da.convert(); -} - - -inline const bool operator >= (const char& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with char -{ - return other >= da.convert(); -} - - -inline const Poco::Int8 operator + (const Poco::Int8& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to Poco::Int8 -{ - return other + da.convert(); -} - - -inline const Poco::Int8 operator - (const Poco::Int8& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from Poco::Int8 -{ - return other - da.convert(); -} - - -inline const Poco::Int8 operator * (const Poco::Int8& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with Poco::Int8 -{ - return other * da.convert(); -} - - -inline const Poco::Int8 operator / (const Poco::Int8& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with Poco::Int8 -{ - return other / da.convert(); -} - - -inline Poco::Int8 operator += (Poco::Int8& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to Poco::Int8 -{ - return other += da.convert(); -} - - -inline Poco::Int8 operator -= (Poco::Int8& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from Poco::Int8 -{ - return other -= da.convert(); -} - - -inline Poco::Int8 operator *= (Poco::Int8& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with Poco::Int8 -{ - return other *= da.convert(); -} - - -inline Poco::Int8 operator /= (Poco::Int8& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with Poco::Int8 -{ - return other /= da.convert(); -} - - -inline const bool operator == (const Poco::Int8& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with Poco::Int8 -{ - return other == da.convert(); -} - - -inline const bool operator != (const Poco::Int8& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with Poco::Int8 -{ - return other != da.convert(); -} - - -inline const bool operator < (const Poco::Int8& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with Poco::Int8 -{ - return other < da.convert(); -} - - -inline const bool operator <= (const Poco::Int8& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with Poco::Int8 -{ - return other <= da.convert(); -} - - -inline const bool operator > (const Poco::Int8& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with Poco::Int8 -{ - return other > da.convert(); -} - - -inline const bool operator >= (const Poco::Int8& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with Poco::Int8 -{ - return other >= da.convert(); -} - - -inline const Poco::UInt8 operator + (const Poco::UInt8& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to Poco::UInt8 -{ - return other + da.convert(); -} - - -inline const Poco::UInt8 operator - (const Poco::UInt8& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from Poco::UInt8 -{ - return other - da.convert(); -} - - -inline const Poco::UInt8 operator * (const Poco::UInt8& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with Poco::UInt8 -{ - return other * da.convert(); -} - - -inline const Poco::UInt8 operator / (const Poco::UInt8& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with Poco::UInt8 -{ - return other / da.convert(); -} - - -inline Poco::UInt8 operator += (Poco::UInt8& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to Poco::UInt8 -{ - return other += da.convert(); -} - - -inline Poco::UInt8 operator -= (Poco::UInt8& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from Poco::UInt8 -{ - return other -= da.convert(); -} - - -inline Poco::UInt8 operator *= (Poco::UInt8& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with Poco::UInt8 -{ - return other *= da.convert(); -} - - -inline Poco::UInt8 operator /= (Poco::UInt8& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with Poco::UInt8 -{ - return other /= da.convert(); -} - - -inline const bool operator == (const Poco::UInt8& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with Poco::UInt8 -{ - return other == da.convert(); -} - - -inline const bool operator != (const Poco::UInt8& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with Poco::UInt8 -{ - return other != da.convert(); -} - - -inline const bool operator < (const Poco::UInt8& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with Poco::UInt8 -{ - return other < da.convert(); -} - - -inline const bool operator <= (const Poco::UInt8& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with Poco::UInt8 -{ - return other <= da.convert(); -} - - -inline const bool operator > (const Poco::UInt8& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with Poco::UInt8 -{ - return other > da.convert(); -} - - -inline const bool operator >= (const Poco::UInt8& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with Poco::UInt8 -{ - return other >= da.convert(); -} - - -inline const Poco::Int16 operator + (const Poco::Int16& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to Poco::Int16 -{ - return other + da.convert(); -} - - -inline const Poco::Int16 operator - (const Poco::Int16& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from Poco::Int16 -{ - return other - da.convert(); -} - - -inline const Poco::Int16 operator * (const Poco::Int16& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with Poco::Int16 -{ - return other * da.convert(); -} - - -inline const Poco::Int16 operator / (const Poco::Int16& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with Poco::Int16 -{ - return other / da.convert(); -} - - -inline Poco::Int16 operator += (Poco::Int16& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to Poco::Int16 -{ - return other += da.convert(); -} - - -inline Poco::Int16 operator -= (Poco::Int16& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from Poco::Int16 -{ - return other -= da.convert(); -} - - -inline Poco::Int16 operator *= (Poco::Int16& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with Poco::Int16 -{ - return other *= da.convert(); -} - - -inline Poco::Int16 operator /= (Poco::Int16& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with Poco::Int16 -{ - return other /= da.convert(); -} - - -inline const bool operator == (const Poco::Int16& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with Poco::Int16 -{ - return other == da.convert(); -} - - -inline const bool operator != (const Poco::Int16& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with Poco::Int16 -{ - return other != da.convert(); -} - - -inline const bool operator < (const Poco::Int16& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with Poco::Int16 -{ - return other < da.convert(); -} - - -inline const bool operator <= (const Poco::Int16& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with Poco::Int16 -{ - return other <= da.convert(); -} - - -inline const bool operator > (const Poco::Int16& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with Poco::Int16 -{ - return other > da.convert(); -} - - -inline const bool operator >= (const Poco::Int16& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with Poco::Int16 -{ - return other >= da.convert(); -} - - -inline const Poco::UInt16 operator + (const Poco::UInt16& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to Poco::UInt16 -{ - return other + da.convert(); -} - - -inline const Poco::UInt16 operator - (const Poco::UInt16& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from Poco::UInt16 -{ - return other - da.convert(); -} - - -inline const Poco::UInt16 operator * (const Poco::UInt16& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with Poco::UInt16 -{ - return other * da.convert(); -} - - -inline const Poco::UInt16 operator / (const Poco::UInt16& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with Poco::UInt16 -{ - return other / da.convert(); -} - - -inline Poco::UInt16 operator += (Poco::UInt16& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to Poco::UInt16 -{ - return other += da.convert(); -} - - -inline Poco::UInt16 operator -= (Poco::UInt16& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from Poco::UInt16 -{ - return other -= da.convert(); -} - - -inline Poco::UInt16 operator *= (Poco::UInt16& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with Poco::UInt16 -{ - return other *= da.convert(); -} - - -inline Poco::UInt16 operator /= (Poco::UInt16& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with Poco::UInt16 -{ - return other /= da.convert(); -} - - -inline const bool operator == (const Poco::UInt16& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with Poco::UInt16 -{ - return other == da.convert(); -} - - -inline const bool operator != (const Poco::UInt16& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with Poco::UInt16 -{ - return other != da.convert(); -} - - -inline const bool operator < (const Poco::UInt16& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with Poco::UInt16 -{ - return other < da.convert(); -} - - -inline const bool operator <= (const Poco::UInt16& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with Poco::UInt16 -{ - return other <= da.convert(); -} - - -inline const bool operator > (const Poco::UInt16& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with Poco::UInt16 -{ - return other > da.convert(); -} - - -inline const bool operator >= (const Poco::UInt16& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with Poco::UInt16 -{ - return other >= da.convert(); -} - - -inline const Poco::Int32 operator + (const Poco::Int32& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to Poco::Int32 -{ - return other + da.convert(); -} - - -inline const Poco::Int32 operator - (const Poco::Int32& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from Poco::Int32 -{ - return other - da.convert(); -} - - -inline const Poco::Int32 operator * (const Poco::Int32& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with Poco::Int32 -{ - return other * da.convert(); -} - - -inline const Poco::Int32 operator / (const Poco::Int32& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with Poco::Int32 -{ - return other / da.convert(); -} - - -inline Poco::Int32 operator += (Poco::Int32& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to Poco::Int32 -{ - return other += da.convert(); -} - - -inline Poco::Int32 operator -= (Poco::Int32& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from Poco::Int32 -{ - return other -= da.convert(); -} - - -inline Poco::Int32 operator *= (Poco::Int32& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with Poco::Int32 -{ - return other *= da.convert(); -} - - -inline Poco::Int32 operator /= (Poco::Int32& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with Poco::Int32 -{ - return other /= da.convert(); -} - - -inline const bool operator == (const Poco::Int32& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with Poco::Int32 -{ - return other == da.convert(); -} - - -inline const bool operator != (const Poco::Int32& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with Poco::Int32 -{ - return other != da.convert(); -} - - -inline const bool operator < (const Poco::Int32& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with Poco::Int32 -{ - return other < da.convert(); -} - - -inline const bool operator <= (const Poco::Int32& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with Poco::Int32 -{ - return other <= da.convert(); -} - - -inline const bool operator > (const Poco::Int32& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with Poco::Int32 -{ - return other > da.convert(); -} - - -inline const bool operator >= (const Poco::Int32& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with Poco::Int32 -{ - return other >= da.convert(); -} - - -inline const Poco::UInt32 operator + (const Poco::UInt32& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to Poco::UInt32 -{ - return other + da.convert(); -} - - -inline const Poco::UInt32 operator - (const Poco::UInt32& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from Poco::UInt32 -{ - return other - da.convert(); -} - - -inline const Poco::UInt32 operator * (const Poco::UInt32& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with Poco::UInt32 -{ - return other * da.convert(); -} - - -inline const Poco::UInt32 operator / (const Poco::UInt32& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with Poco::UInt32 -{ - return other / da.convert(); -} - - -inline Poco::UInt32 operator += (Poco::UInt32& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to Poco::UInt32 -{ - return other += da.convert(); -} - - -inline Poco::UInt32 operator -= (Poco::UInt32& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from Poco::UInt32 -{ - return other -= da.convert(); -} - - -inline Poco::UInt32 operator *= (Poco::UInt32& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with Poco::UInt32 -{ - return other *= da.convert(); -} - - -inline Poco::UInt32 operator /= (Poco::UInt32& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with Poco::UInt32 -{ - return other /= da.convert(); -} - - -inline const bool operator == (const Poco::UInt32& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with Poco::UInt32 -{ - return other == da.convert(); -} - - -inline const bool operator != (const Poco::UInt32& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with Poco::UInt32 -{ - return other != da.convert(); -} - - -inline const bool operator < (const Poco::UInt32& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with Poco::UInt32 -{ - return other < da.convert(); -} - - -inline const bool operator <= (const Poco::UInt32& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with Poco::UInt32 -{ - return other <= da.convert(); -} - - -inline const bool operator > (const Poco::UInt32& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with Poco::UInt32 -{ - return other > da.convert(); -} - - -inline const bool operator >= (const Poco::UInt32& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with Poco::UInt32 -{ - return other >= da.convert(); -} - - -inline const Poco::Int64 operator + (const Poco::Int64& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to Poco::Int64 -{ - return other + da.convert(); -} - - -inline const Poco::Int64 operator - (const Poco::Int64& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from Poco::Int64 -{ - return other - da.convert(); -} - - -inline const Poco::Int64 operator * (const Poco::Int64& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with Poco::Int64 -{ - return other * da.convert(); -} - - -inline const Poco::Int64 operator / (const Poco::Int64& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with Poco::Int64 -{ - return other / da.convert(); -} - - -inline Poco::Int64 operator += (Poco::Int64& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to Poco::Int64 -{ - return other += da.convert(); -} - - -inline Poco::Int64 operator -= (Poco::Int64& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from Poco::Int64 -{ - return other -= da.convert(); -} - - -inline Poco::Int64 operator *= (Poco::Int64& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with Poco::Int64 -{ - return other *= da.convert(); -} - - -inline Poco::Int64 operator /= (Poco::Int64& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with Poco::Int64 -{ - return other /= da.convert(); -} - - -inline const bool operator == (const Poco::Int64& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with Poco::Int64 -{ - return other == da.convert(); -} - - -inline const bool operator != (const Poco::Int64& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with Poco::Int64 -{ - return other != da.convert(); -} - - -inline const bool operator < (const Poco::Int64& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with Poco::Int64 -{ - return other < da.convert(); -} - - -inline const bool operator <= (const Poco::Int64& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with Poco::Int64 -{ - return other <= da.convert(); -} - - -inline const bool operator > (const Poco::Int64& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with Poco::Int64 -{ - return other > da.convert(); -} - - -inline const bool operator >= (const Poco::Int64& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with Poco::Int64 -{ - return other >= da.convert(); -} - - -inline const Poco::UInt64 operator + (const Poco::UInt64& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to Poco::UInt64 -{ - return other + da.convert(); -} - - -inline const Poco::UInt64 operator - (const Poco::UInt64& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from Poco::UInt64 -{ - return other - da.convert(); -} - - -inline const Poco::UInt64 operator * (const Poco::UInt64& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with Poco::UInt64 -{ - return other * da.convert(); -} - - -inline const Poco::UInt64 operator / (const Poco::UInt64& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with Poco::UInt64 -{ - return other / da.convert(); -} - - -inline Poco::UInt64 operator += (Poco::UInt64& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to Poco::UInt64 -{ - return other += da.convert(); -} - - -inline Poco::UInt64 operator -= (Poco::UInt64& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from Poco::UInt64 -{ - return other -= da.convert(); -} - - -inline Poco::UInt64 operator *= (Poco::UInt64& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with Poco::UInt64 -{ - return other *= da.convert(); -} - - -inline Poco::UInt64 operator /= (Poco::UInt64& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with Poco::UInt64 -{ - return other /= da.convert(); -} - - -inline const bool operator == (const Poco::UInt64& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with Poco::UInt64 -{ - return other == da.convert(); -} - - -inline const bool operator != (const Poco::UInt64& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with Poco::UInt64 -{ - return other != da.convert(); -} - - -inline const bool operator < (const Poco::UInt64& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with Poco::UInt64 -{ - return other < da.convert(); -} - - -inline const bool operator <= (const Poco::UInt64& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with Poco::UInt64 -{ - return other <= da.convert(); -} - - -inline const bool operator > (const Poco::UInt64& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with Poco::UInt64 -{ - return other > da.convert(); -} - - -inline const bool operator >= (const Poco::UInt64& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with Poco::UInt64 -{ - return other >= da.convert(); -} - - -inline const float operator + (const float& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to float -{ - return other + da.convert(); -} - - -inline const float operator - (const float& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from float -{ - return other - da.convert(); -} - - -inline const float operator * (const float& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with float -{ - return other * da.convert(); -} - - -inline const float operator / (const float& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with float -{ - return other / da.convert(); -} - - -inline float operator += (float& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to float -{ - return other += da.convert(); -} - - -inline float operator -= (float& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from float -{ - return other -= da.convert(); -} - - -inline float operator *= (float& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with float -{ - return other *= da.convert(); -} - - -inline float operator /= (float& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with float -{ - return other /= da.convert(); -} - - -inline const bool operator == (const float& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with float -{ - return other == da.convert(); -} - - -inline const bool operator != (const float& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with float -{ - return other != da.convert(); -} - - -inline const bool operator < (const float& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with float -{ - return other < da.convert(); -} - - -inline const bool operator <= (const float& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with float -{ - return other <= da.convert(); -} - - -inline const bool operator > (const float& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with float -{ - return other > da.convert(); -} - - -inline const bool operator >= (const float& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with float -{ - return other >= da.convert(); -} - - -inline const double operator + (const double& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to double -{ - return other + da.convert(); -} - - -inline const double operator - (const double& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from double -{ - return other - da.convert(); -} - - -inline const double operator * (const double& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with double -{ - return other * da.convert(); -} - - -inline const double operator / (const double& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with double -{ - return other / da.convert(); -} - - -inline double operator += (double& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to double -{ - return other += da.convert(); -} - - -inline double operator -= (double& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from double -{ - return other -= da.convert(); -} - - -inline double operator *= (double& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with double -{ - return other *= da.convert(); -} - - -inline double operator /= (double& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with double -{ - return other /= da.convert(); -} - - -inline const bool operator == (const double& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with double -{ - return other == da.convert(); -} - - -inline const bool operator != (const double& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with double -{ - return other != da.convert(); -} - - -inline const bool operator < (const double& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with double -{ - return other < da.convert(); -} - - -inline const bool operator <= (const double& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with double -{ - return other <= da.convert(); -} - - -inline const bool operator > (const double& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with double -{ - return other > da.convert(); -} - - -inline const bool operator >= (const double& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with double -{ - return other >= da.convert(); -} - - -inline const bool operator == (const bool& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with bool -{ - return other == da.convert(); -} - - -inline const bool operator != (const bool& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with bool -{ - return other != da.convert(); -} - - -inline const bool operator == (const std::string& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with std::string -{ - return other == da.convert(); -} - - -inline const bool operator != (const std::string& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with std::string -{ - return other != da.convert(); -} - - -inline const bool operator == (const char* other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with const char* -{ - return da.convert() == other; -} - - -inline const bool operator != (const char* other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with const char* -{ - return da.convert() != other; -} - - -#ifndef POCO_LONG_IS_64_BIT - - -inline const long operator + (const long& other, const DynamicAny& da) - /// Addition operator for adding DynamicAny to long -{ - return other + da.convert(); -} - - -inline const long operator - (const long& other, const DynamicAny& da) - /// Subtraction operator for subtracting DynamicAny from long -{ - return other - da.convert(); -} - - -inline const long operator * (const long& other, const DynamicAny& da) - /// Multiplication operator for multiplying DynamicAny with long -{ - return other * da.convert(); -} - - -inline const long operator / (const long& other, const DynamicAny& da) - /// Division operator for dividing DynamicAny with long -{ - return other / da.convert(); -} - - -inline long operator += (long& other, const DynamicAny& da) - /// Addition asignment operator for adding DynamicAny to long -{ - return other += da.convert(); -} - - -inline long operator -= (long& other, const DynamicAny& da) - /// Subtraction asignment operator for subtracting DynamicAny from long -{ - return other -= da.convert(); -} - - -inline long operator *= (long& other, const DynamicAny& da) - /// Multiplication asignment operator for multiplying DynamicAny with long -{ - return other *= da.convert(); -} - - -inline long operator /= (long& other, const DynamicAny& da) - /// Division asignment operator for dividing DynamicAny with long -{ - return other /= da.convert(); -} - - -inline const bool operator == (const long& other, const DynamicAny& da) - /// Equality operator for comparing DynamicAny with long -{ - return other == da.convert(); -} - - -inline const bool operator != (const long& other, const DynamicAny& da) - /// Inequality operator for comparing DynamicAny with long -{ - return other != da.convert(); -} - - -inline const bool operator < (const long& other, const DynamicAny& da) - /// Less than operator for comparing DynamicAny with long -{ - return other < da.convert(); -} - - -inline const bool operator <= (const long& other, const DynamicAny& da) - /// Less than or equal operator for comparing DynamicAny with long -{ - return other <= da.convert(); -} - - -inline const bool operator > (const long& other, const DynamicAny& da) - /// Greater than operator for comparing DynamicAny with long -{ - return other > da.convert(); -} - - -inline const bool operator >= (const long& other, const DynamicAny& da) - /// Greater than or equal operator for comparing DynamicAny with long -{ - return other >= da.convert(); -} - - -#endif // POCO_LONG_IS_64_BIT - - -} // namespace Poco - - -#endif // Foundation_DynamicAny_INCLUDED +// +// DynamicAny.h +// +// $Id: //poco/svn/Foundation/include/Poco/DynamicAny.h#2 $ +// +// Library: Foundation +// Package: Core +// Module: DynamicAny +// +// Definition of the DynamicAny 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_DynamicAny_INCLUDED +#define Foundation_DynamicAny_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/DynamicAnyHolder.h" +#include + + +namespace Poco { + + +class Foundation_API DynamicAny + /// DynamicAny allows to store data of different types and to convert between these types transparently. + /// DynamicAny puts forth the best effort to provide intuitive and reasonable conversion semantics and prevent + /// unexpected data loss, particularly when performing narrowing or signedness conversions of numeric data types. + /// + /// Loss of signedness is not allowed for numeric values. This means that if an attempt is made to convert + /// the internal value which is a negative signed integer to an unsigned integer type storage, a RangeException is thrown. + /// Overflow is not allowed, so if the internal value is a larger number than the target numeric type size can accomodate, + /// a RangeException is thrown. + /// + /// Precision loss, such as in conversion from floating-point types to integers or from double to float on platforms + /// where they differ in size (provided internal actual value fits in float min/max range), is allowed. + /// + /// 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. + /// + /// 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). + /// Integer 0 values are false, everything else is true. + /// Floating point values equal to the minimal FP representation on a given platform are false, everything else is true. + /// + /// Arithmetic operations with POD types as well as between DynamicAny's are supported, subject to following + /// limitations: + /// + /// - for std::string and const char* values, only '+' and '+=' operations are supported + /// + /// - for integral and floating point numeric values, following operations are supported: + /// '+', '+=', '-', '-=', '*', '*=' , '/' and '/=' + /// + /// - for integral values, following operations are supported: + /// prefix and postfix increment (++) and decement (--) + /// + /// - for all other types, InvalidArgumentException is thrown upon attempt of an arithmetic operation + /// + /// A DynamicAny can be created from and converted to a value of any type for which a specialization of + /// DynamicAnyHolderImpl is available. For supported types, see DynamicAnyHolder documentation. +{ +public: + DynamicAny(); + /// Creates a DynamicAny holding an int with value 0. + + template + DynamicAny(const T &val): + _pHolder(new DynamicAnyHolderImpl(val)) + /// Creates the DynamicAny from the given value. + { + } + + DynamicAny(const char* pVal); + // Convenience constructor for const char* which gets mapped to a std::string internally, i.e. pVal is deep-copied. + + DynamicAny(const DynamicAny& other); + /// Copy constructor. + + ~DynamicAny(); + /// Destroys the DynamicAny. + + void swap(DynamicAny& other); + /// Swaps the content of the this DynamicAny with the other DynamicAny. + + template + void convert(T& val) const + /// Invoke this method to perform a safe conversion. + /// + /// Example usage: + /// DynamicAny any("42"); + /// int i; + /// any.convert(i); + /// + /// Throws a RangeException if the value does not fit + /// into the result variable. + /// Throws a NotImplementedException if conversion is + /// not available for the given type. + { + _pHolder->convert(val); + } + + template + T convert() const + /// Invoke this method to perform a safe conversion. + /// + /// Example usage: + /// DynamicAny any("42"); + /// int i = any.convert(); + /// + /// Throws a RangeException if the value does not fit + /// into the result variable. + /// Throws a NotImplementedException if conversion is + /// not available for the given type. + { + T result; + _pHolder->convert(result); + return result; + } + + template + operator T () const + /// Safe conversion operator for implicit type + /// conversions. + /// + /// Throws a RangeException if the value does not fit + /// into the result variable. + /// Throws a NotImplementedException if conversion is + /// not available for the given type. + { + T result; + _pHolder->convert(result); + return result; + } + + template + const T& extract() const + /// Returns a const reference to the actual value. + /// + /// Must be instantiated with the exact type of + /// the stored value, otherwise a BadCastException + /// is thrown. + { + DynamicAnyHolderImpl* pHolder = dynamic_cast*>(_pHolder); + if (pHolder) + return pHolder->value(); + else + throw BadCastException(); + } + + template + DynamicAny& operator = (const T& other) + /// Assignment operator for assigning POD to DynamicAny + { + DynamicAny tmp(other); + swap(tmp); + return *this; + } + + DynamicAny& operator = (const DynamicAny& other); + /// Assignment operator specialization for DynamicAny + + template + const DynamicAny operator + (const T& other) const + /// Addition operator for adding POD to DynamicAny + { + return convert() + other; + } + + const DynamicAny operator + (const DynamicAny& other) const; + /// Addition operator specialization for DynamicAny + + const DynamicAny operator + (const char* other) const; + /// Addition operator specialization for adding const char* to DynamicAny + + DynamicAny& operator ++ (); + /// Pre-increment operator + + DynamicAny operator ++ (int); + /// Post-increment operator + + DynamicAny& operator -- (); + /// Pre-decrement operator + + DynamicAny operator -- (int); + /// Post-decrement operator + + template + DynamicAny& operator += (const T& other) + /// Addition asignment operator for addition/assignment of POD to DynamicAny. + { + return *this = convert() + other; + } + + DynamicAny& operator += (const DynamicAny& other); + /// Addition asignment operator specialization for DynamicAny + + DynamicAny& operator += (const char* other); + /// Addition asignment operator specialization for const char* + + template + const DynamicAny operator - (const T& other) const + /// Subtraction operator for subtracting POD from DynamicAny + { + return convert() - other; + } + + const DynamicAny operator - (const DynamicAny& other) const; + /// Subtraction operator specialization for DynamicAny + + template + DynamicAny& operator -= (const T& other) + /// Subtraction asignment operator + { + return *this = convert() - other; + } + + DynamicAny& operator -= (const DynamicAny& other); + /// Subtraction asignment operator specialization for DynamicAny + + template + const DynamicAny operator * (const T& other) const + /// Multiplication operator for multiplying DynamicAny with POD + { + return convert() * other; + } + + const DynamicAny operator * (const DynamicAny& other) const; + /// Multiplication operator specialization for DynamicAny + + template + DynamicAny& operator *= (const T& other) + /// Multiplication asignment operator + { + return *this = convert() * other; + } + + DynamicAny& operator *= (const DynamicAny& other); + /// Multiplication asignment operator specialization for DynamicAny + + template + const DynamicAny operator / (const T& other) const + /// Division operator for dividing DynamicAny with POD + { + return convert() / other; + } + + const DynamicAny operator / (const DynamicAny& other) const; + /// Division operator specialization for DynamicAny + + template + DynamicAny& operator /= (const T& other) + /// Division asignment operator + { + return *this = convert() / other; + } + + DynamicAny& operator /= (const DynamicAny& other); + /// Division asignment operator specialization for DynamicAny + + template + bool operator == (const T& other) const + /// Equality operator + { + return convert() == other; + } + + bool operator == (const char* other) const; + /// Equality operator specialization for const char* + + bool operator == (const DynamicAny& other) const; + /// Equality operator specialization for DynamicAny + + template + bool operator != (const T& other) const + /// Inequality operator + { + return convert() != other; + } + + bool operator != (const DynamicAny& other) const; + /// Inequality operator specialization for DynamicAny + + bool operator != (const char* other) const; + /// Inequality operator specialization for const char* + + template + bool operator < (const T& other) const + /// Less than operator + { + return convert() < other; + } + + template + bool operator <= (const T& other) const + /// Less than or equal operator + { + return convert() <= other; + } + + template + bool operator > (const T& other) const + /// Greater than operator + { + return convert() > other; + } + + template + bool operator >= (const T& other) const + /// Greater than or equal operator + { + return convert() >= other; + } + + bool isArray() const; + /// Returns true if DynamicAny represents a vector + + bool isStruct() const; + /// Returns true if DynamicAny represents a struct + + template + DynamicAny& operator [] (T n) + /// Index operator, only use on DynamicAnys where isArray + /// returns true! In all other cases a BadCastException is thrown! + { + DynamicAnyHolderImpl >* pHolder = + dynamic_cast > *>(_pHolder); + if (pHolder) + return pHolder->operator[](n); + else + throw BadCastException(); + } + + template + const DynamicAny& operator [] (T n) const + /// const Index operator, only use on DynamicAnys where isArray + /// returns true! In all other cases a BadCastException is thrown! + { + const DynamicAnyHolderImpl >* pHolder = + dynamic_cast > *>(_pHolder); + if (pHolder) + return pHolder->operator[](n); + else + throw BadCastException(); + } + + 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! + + DynamicAny& operator [] (const char* 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 char* 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. + + bool isInteger() const; + /// Returns true if stored value is integer. + + bool isSigned() const; + /// Returns true if stored value is signed. + + bool isNumeric() const; + /// Returns true if stored value is numeric. + /// Returns false for numeric strings (e.g. "123" is string, not number) + + bool isString() const; + /// Returns true if stored value is std::string. + + 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); + + template + T add(const DynamicAny& other) const + { + return convert() + other.convert(); + } + + template + T subtract(const DynamicAny& other) const + { + return convert() - other.convert(); + } + + template + T multiply(const DynamicAny& other) const + { + return convert() * other.convert(); + } + + template + T divide(const DynamicAny& other) const + { + return convert() / other.convert(); + } + + DynamicAnyHolder* _pHolder; +}; + + +/// +/// inlines +/// + + +/// +/// DynamicAny members +/// + +inline void DynamicAny::swap(DynamicAny& ptr) +{ + std::swap(_pHolder, ptr._pHolder); +} + + +inline const std::type_info& DynamicAny::type() const +{ + return _pHolder->type(); +} + + +inline DynamicAny& DynamicAny::operator [] (const char* name) +{ + return operator [] (std::string(name)); +} + + +inline const DynamicAny& DynamicAny::operator [] (const char* name) const +{ + return operator [] (std::string(name)); +} + + +inline const DynamicAny DynamicAny::operator + (const char* other) const +{ + return convert() + other; +} + + +inline DynamicAny& DynamicAny::operator += (const char*other) +{ + return *this = convert() + other; +} + + +inline bool DynamicAny::operator == (const DynamicAny& other) const +{ + return convert() == other.convert(); +} + + +inline bool DynamicAny::operator == (const char* other) const +{ + return convert() == other; +} + + +inline bool DynamicAny::operator != (const DynamicAny& other) const +{ + return convert() != other.convert(); +} + + +inline bool DynamicAny::operator != (const char* other) const +{ + return convert() != other; +} + + +inline bool DynamicAny::isArray() const +{ + return _pHolder->isArray(); +} + + +inline bool DynamicAny::isStruct() const +{ + return _pHolder->isStruct(); +} + + +inline bool DynamicAny::isInteger() const +{ + return _pHolder->isInteger(); +} + + +inline bool DynamicAny::isSigned() const +{ + return _pHolder->isSigned(); +} + + +inline bool DynamicAny::isNumeric() const +{ + return _pHolder->isNumeric(); +} + + +inline bool DynamicAny::isString() const +{ + return _pHolder->isString(); +} + + +/// +/// DynamicAny non-member functions +/// + +inline const DynamicAny operator + (const char* other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to const char* +{ + std::string tmp = other; + return tmp + da.convert(); +} + + +inline const char operator + (const char& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to char +{ + return other + da.convert(); +} + + +inline const char operator - (const char& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from char +{ + return other - da.convert(); +} + + +inline const char operator * (const char& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with char +{ + return other * da.convert(); +} + + +inline const char operator / (const char& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with char +{ + return other / da.convert(); +} + + +inline char operator += (char& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to char +{ + return other += da.convert(); +} + + +inline char operator -= (char& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from char +{ + return other -= da.convert(); +} + + +inline char operator *= (char& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with char +{ + return other *= da.convert(); +} + + +inline char operator /= (char& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with char +{ + return other /= da.convert(); +} + + +inline const bool operator == (const char& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with char +{ + return other == da.convert(); +} + + +inline const bool operator != (const char& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with char +{ + return other != da.convert(); +} + + +inline const bool operator < (const char& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with char +{ + return other < da.convert(); +} + + +inline const bool operator <= (const char& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with char +{ + return other <= da.convert(); +} + + +inline const bool operator > (const char& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with char +{ + return other > da.convert(); +} + + +inline const bool operator >= (const char& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with char +{ + return other >= da.convert(); +} + + +inline const Poco::Int8 operator + (const Poco::Int8& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to Poco::Int8 +{ + return other + da.convert(); +} + + +inline const Poco::Int8 operator - (const Poco::Int8& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from Poco::Int8 +{ + return other - da.convert(); +} + + +inline const Poco::Int8 operator * (const Poco::Int8& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with Poco::Int8 +{ + return other * da.convert(); +} + + +inline const Poco::Int8 operator / (const Poco::Int8& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with Poco::Int8 +{ + return other / da.convert(); +} + + +inline Poco::Int8 operator += (Poco::Int8& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to Poco::Int8 +{ + return other += da.convert(); +} + + +inline Poco::Int8 operator -= (Poco::Int8& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from Poco::Int8 +{ + return other -= da.convert(); +} + + +inline Poco::Int8 operator *= (Poco::Int8& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with Poco::Int8 +{ + return other *= da.convert(); +} + + +inline Poco::Int8 operator /= (Poco::Int8& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with Poco::Int8 +{ + return other /= da.convert(); +} + + +inline const bool operator == (const Poco::Int8& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with Poco::Int8 +{ + return other == da.convert(); +} + + +inline const bool operator != (const Poco::Int8& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with Poco::Int8 +{ + return other != da.convert(); +} + + +inline const bool operator < (const Poco::Int8& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with Poco::Int8 +{ + return other < da.convert(); +} + + +inline const bool operator <= (const Poco::Int8& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with Poco::Int8 +{ + return other <= da.convert(); +} + + +inline const bool operator > (const Poco::Int8& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with Poco::Int8 +{ + return other > da.convert(); +} + + +inline const bool operator >= (const Poco::Int8& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with Poco::Int8 +{ + return other >= da.convert(); +} + + +inline const Poco::UInt8 operator + (const Poco::UInt8& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to Poco::UInt8 +{ + return other + da.convert(); +} + + +inline const Poco::UInt8 operator - (const Poco::UInt8& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from Poco::UInt8 +{ + return other - da.convert(); +} + + +inline const Poco::UInt8 operator * (const Poco::UInt8& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with Poco::UInt8 +{ + return other * da.convert(); +} + + +inline const Poco::UInt8 operator / (const Poco::UInt8& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with Poco::UInt8 +{ + return other / da.convert(); +} + + +inline Poco::UInt8 operator += (Poco::UInt8& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to Poco::UInt8 +{ + return other += da.convert(); +} + + +inline Poco::UInt8 operator -= (Poco::UInt8& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from Poco::UInt8 +{ + return other -= da.convert(); +} + + +inline Poco::UInt8 operator *= (Poco::UInt8& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with Poco::UInt8 +{ + return other *= da.convert(); +} + + +inline Poco::UInt8 operator /= (Poco::UInt8& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with Poco::UInt8 +{ + return other /= da.convert(); +} + + +inline const bool operator == (const Poco::UInt8& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with Poco::UInt8 +{ + return other == da.convert(); +} + + +inline const bool operator != (const Poco::UInt8& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with Poco::UInt8 +{ + return other != da.convert(); +} + + +inline const bool operator < (const Poco::UInt8& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with Poco::UInt8 +{ + return other < da.convert(); +} + + +inline const bool operator <= (const Poco::UInt8& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with Poco::UInt8 +{ + return other <= da.convert(); +} + + +inline const bool operator > (const Poco::UInt8& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with Poco::UInt8 +{ + return other > da.convert(); +} + + +inline const bool operator >= (const Poco::UInt8& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with Poco::UInt8 +{ + return other >= da.convert(); +} + + +inline const Poco::Int16 operator + (const Poco::Int16& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to Poco::Int16 +{ + return other + da.convert(); +} + + +inline const Poco::Int16 operator - (const Poco::Int16& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from Poco::Int16 +{ + return other - da.convert(); +} + + +inline const Poco::Int16 operator * (const Poco::Int16& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with Poco::Int16 +{ + return other * da.convert(); +} + + +inline const Poco::Int16 operator / (const Poco::Int16& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with Poco::Int16 +{ + return other / da.convert(); +} + + +inline Poco::Int16 operator += (Poco::Int16& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to Poco::Int16 +{ + return other += da.convert(); +} + + +inline Poco::Int16 operator -= (Poco::Int16& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from Poco::Int16 +{ + return other -= da.convert(); +} + + +inline Poco::Int16 operator *= (Poco::Int16& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with Poco::Int16 +{ + return other *= da.convert(); +} + + +inline Poco::Int16 operator /= (Poco::Int16& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with Poco::Int16 +{ + return other /= da.convert(); +} + + +inline const bool operator == (const Poco::Int16& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with Poco::Int16 +{ + return other == da.convert(); +} + + +inline const bool operator != (const Poco::Int16& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with Poco::Int16 +{ + return other != da.convert(); +} + + +inline const bool operator < (const Poco::Int16& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with Poco::Int16 +{ + return other < da.convert(); +} + + +inline const bool operator <= (const Poco::Int16& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with Poco::Int16 +{ + return other <= da.convert(); +} + + +inline const bool operator > (const Poco::Int16& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with Poco::Int16 +{ + return other > da.convert(); +} + + +inline const bool operator >= (const Poco::Int16& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with Poco::Int16 +{ + return other >= da.convert(); +} + + +inline const Poco::UInt16 operator + (const Poco::UInt16& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to Poco::UInt16 +{ + return other + da.convert(); +} + + +inline const Poco::UInt16 operator - (const Poco::UInt16& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from Poco::UInt16 +{ + return other - da.convert(); +} + + +inline const Poco::UInt16 operator * (const Poco::UInt16& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with Poco::UInt16 +{ + return other * da.convert(); +} + + +inline const Poco::UInt16 operator / (const Poco::UInt16& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with Poco::UInt16 +{ + return other / da.convert(); +} + + +inline Poco::UInt16 operator += (Poco::UInt16& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to Poco::UInt16 +{ + return other += da.convert(); +} + + +inline Poco::UInt16 operator -= (Poco::UInt16& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from Poco::UInt16 +{ + return other -= da.convert(); +} + + +inline Poco::UInt16 operator *= (Poco::UInt16& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with Poco::UInt16 +{ + return other *= da.convert(); +} + + +inline Poco::UInt16 operator /= (Poco::UInt16& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with Poco::UInt16 +{ + return other /= da.convert(); +} + + +inline const bool operator == (const Poco::UInt16& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with Poco::UInt16 +{ + return other == da.convert(); +} + + +inline const bool operator != (const Poco::UInt16& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with Poco::UInt16 +{ + return other != da.convert(); +} + + +inline const bool operator < (const Poco::UInt16& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with Poco::UInt16 +{ + return other < da.convert(); +} + + +inline const bool operator <= (const Poco::UInt16& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with Poco::UInt16 +{ + return other <= da.convert(); +} + + +inline const bool operator > (const Poco::UInt16& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with Poco::UInt16 +{ + return other > da.convert(); +} + + +inline const bool operator >= (const Poco::UInt16& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with Poco::UInt16 +{ + return other >= da.convert(); +} + + +inline const Poco::Int32 operator + (const Poco::Int32& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to Poco::Int32 +{ + return other + da.convert(); +} + + +inline const Poco::Int32 operator - (const Poco::Int32& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from Poco::Int32 +{ + return other - da.convert(); +} + + +inline const Poco::Int32 operator * (const Poco::Int32& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with Poco::Int32 +{ + return other * da.convert(); +} + + +inline const Poco::Int32 operator / (const Poco::Int32& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with Poco::Int32 +{ + return other / da.convert(); +} + + +inline Poco::Int32 operator += (Poco::Int32& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to Poco::Int32 +{ + return other += da.convert(); +} + + +inline Poco::Int32 operator -= (Poco::Int32& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from Poco::Int32 +{ + return other -= da.convert(); +} + + +inline Poco::Int32 operator *= (Poco::Int32& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with Poco::Int32 +{ + return other *= da.convert(); +} + + +inline Poco::Int32 operator /= (Poco::Int32& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with Poco::Int32 +{ + return other /= da.convert(); +} + + +inline const bool operator == (const Poco::Int32& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with Poco::Int32 +{ + return other == da.convert(); +} + + +inline const bool operator != (const Poco::Int32& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with Poco::Int32 +{ + return other != da.convert(); +} + + +inline const bool operator < (const Poco::Int32& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with Poco::Int32 +{ + return other < da.convert(); +} + + +inline const bool operator <= (const Poco::Int32& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with Poco::Int32 +{ + return other <= da.convert(); +} + + +inline const bool operator > (const Poco::Int32& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with Poco::Int32 +{ + return other > da.convert(); +} + + +inline const bool operator >= (const Poco::Int32& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with Poco::Int32 +{ + return other >= da.convert(); +} + + +inline const Poco::UInt32 operator + (const Poco::UInt32& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to Poco::UInt32 +{ + return other + da.convert(); +} + + +inline const Poco::UInt32 operator - (const Poco::UInt32& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from Poco::UInt32 +{ + return other - da.convert(); +} + + +inline const Poco::UInt32 operator * (const Poco::UInt32& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with Poco::UInt32 +{ + return other * da.convert(); +} + + +inline const Poco::UInt32 operator / (const Poco::UInt32& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with Poco::UInt32 +{ + return other / da.convert(); +} + + +inline Poco::UInt32 operator += (Poco::UInt32& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to Poco::UInt32 +{ + return other += da.convert(); +} + + +inline Poco::UInt32 operator -= (Poco::UInt32& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from Poco::UInt32 +{ + return other -= da.convert(); +} + + +inline Poco::UInt32 operator *= (Poco::UInt32& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with Poco::UInt32 +{ + return other *= da.convert(); +} + + +inline Poco::UInt32 operator /= (Poco::UInt32& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with Poco::UInt32 +{ + return other /= da.convert(); +} + + +inline const bool operator == (const Poco::UInt32& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with Poco::UInt32 +{ + return other == da.convert(); +} + + +inline const bool operator != (const Poco::UInt32& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with Poco::UInt32 +{ + return other != da.convert(); +} + + +inline const bool operator < (const Poco::UInt32& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with Poco::UInt32 +{ + return other < da.convert(); +} + + +inline const bool operator <= (const Poco::UInt32& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with Poco::UInt32 +{ + return other <= da.convert(); +} + + +inline const bool operator > (const Poco::UInt32& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with Poco::UInt32 +{ + return other > da.convert(); +} + + +inline const bool operator >= (const Poco::UInt32& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with Poco::UInt32 +{ + return other >= da.convert(); +} + + +inline const Poco::Int64 operator + (const Poco::Int64& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to Poco::Int64 +{ + return other + da.convert(); +} + + +inline const Poco::Int64 operator - (const Poco::Int64& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from Poco::Int64 +{ + return other - da.convert(); +} + + +inline const Poco::Int64 operator * (const Poco::Int64& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with Poco::Int64 +{ + return other * da.convert(); +} + + +inline const Poco::Int64 operator / (const Poco::Int64& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with Poco::Int64 +{ + return other / da.convert(); +} + + +inline Poco::Int64 operator += (Poco::Int64& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to Poco::Int64 +{ + return other += da.convert(); +} + + +inline Poco::Int64 operator -= (Poco::Int64& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from Poco::Int64 +{ + return other -= da.convert(); +} + + +inline Poco::Int64 operator *= (Poco::Int64& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with Poco::Int64 +{ + return other *= da.convert(); +} + + +inline Poco::Int64 operator /= (Poco::Int64& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with Poco::Int64 +{ + return other /= da.convert(); +} + + +inline const bool operator == (const Poco::Int64& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with Poco::Int64 +{ + return other == da.convert(); +} + + +inline const bool operator != (const Poco::Int64& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with Poco::Int64 +{ + return other != da.convert(); +} + + +inline const bool operator < (const Poco::Int64& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with Poco::Int64 +{ + return other < da.convert(); +} + + +inline const bool operator <= (const Poco::Int64& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with Poco::Int64 +{ + return other <= da.convert(); +} + + +inline const bool operator > (const Poco::Int64& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with Poco::Int64 +{ + return other > da.convert(); +} + + +inline const bool operator >= (const Poco::Int64& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with Poco::Int64 +{ + return other >= da.convert(); +} + + +inline const Poco::UInt64 operator + (const Poco::UInt64& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to Poco::UInt64 +{ + return other + da.convert(); +} + + +inline const Poco::UInt64 operator - (const Poco::UInt64& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from Poco::UInt64 +{ + return other - da.convert(); +} + + +inline const Poco::UInt64 operator * (const Poco::UInt64& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with Poco::UInt64 +{ + return other * da.convert(); +} + + +inline const Poco::UInt64 operator / (const Poco::UInt64& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with Poco::UInt64 +{ + return other / da.convert(); +} + + +inline Poco::UInt64 operator += (Poco::UInt64& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to Poco::UInt64 +{ + return other += da.convert(); +} + + +inline Poco::UInt64 operator -= (Poco::UInt64& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from Poco::UInt64 +{ + return other -= da.convert(); +} + + +inline Poco::UInt64 operator *= (Poco::UInt64& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with Poco::UInt64 +{ + return other *= da.convert(); +} + + +inline Poco::UInt64 operator /= (Poco::UInt64& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with Poco::UInt64 +{ + return other /= da.convert(); +} + + +inline const bool operator == (const Poco::UInt64& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with Poco::UInt64 +{ + return other == da.convert(); +} + + +inline const bool operator != (const Poco::UInt64& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with Poco::UInt64 +{ + return other != da.convert(); +} + + +inline const bool operator < (const Poco::UInt64& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with Poco::UInt64 +{ + return other < da.convert(); +} + + +inline const bool operator <= (const Poco::UInt64& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with Poco::UInt64 +{ + return other <= da.convert(); +} + + +inline const bool operator > (const Poco::UInt64& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with Poco::UInt64 +{ + return other > da.convert(); +} + + +inline const bool operator >= (const Poco::UInt64& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with Poco::UInt64 +{ + return other >= da.convert(); +} + + +inline const float operator + (const float& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to float +{ + return other + da.convert(); +} + + +inline const float operator - (const float& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from float +{ + return other - da.convert(); +} + + +inline const float operator * (const float& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with float +{ + return other * da.convert(); +} + + +inline const float operator / (const float& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with float +{ + return other / da.convert(); +} + + +inline float operator += (float& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to float +{ + return other += da.convert(); +} + + +inline float operator -= (float& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from float +{ + return other -= da.convert(); +} + + +inline float operator *= (float& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with float +{ + return other *= da.convert(); +} + + +inline float operator /= (float& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with float +{ + return other /= da.convert(); +} + + +inline const bool operator == (const float& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with float +{ + return other == da.convert(); +} + + +inline const bool operator != (const float& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with float +{ + return other != da.convert(); +} + + +inline const bool operator < (const float& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with float +{ + return other < da.convert(); +} + + +inline const bool operator <= (const float& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with float +{ + return other <= da.convert(); +} + + +inline const bool operator > (const float& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with float +{ + return other > da.convert(); +} + + +inline const bool operator >= (const float& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with float +{ + return other >= da.convert(); +} + + +inline const double operator + (const double& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to double +{ + return other + da.convert(); +} + + +inline const double operator - (const double& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from double +{ + return other - da.convert(); +} + + +inline const double operator * (const double& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with double +{ + return other * da.convert(); +} + + +inline const double operator / (const double& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with double +{ + return other / da.convert(); +} + + +inline double operator += (double& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to double +{ + return other += da.convert(); +} + + +inline double operator -= (double& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from double +{ + return other -= da.convert(); +} + + +inline double operator *= (double& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with double +{ + return other *= da.convert(); +} + + +inline double operator /= (double& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with double +{ + return other /= da.convert(); +} + + +inline const bool operator == (const double& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with double +{ + return other == da.convert(); +} + + +inline const bool operator != (const double& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with double +{ + return other != da.convert(); +} + + +inline const bool operator < (const double& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with double +{ + return other < da.convert(); +} + + +inline const bool operator <= (const double& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with double +{ + return other <= da.convert(); +} + + +inline const bool operator > (const double& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with double +{ + return other > da.convert(); +} + + +inline const bool operator >= (const double& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with double +{ + return other >= da.convert(); +} + + +inline const bool operator == (const bool& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with bool +{ + return other == da.convert(); +} + + +inline const bool operator != (const bool& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with bool +{ + return other != da.convert(); +} + + +inline const bool operator == (const std::string& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with std::string +{ + return other == da.convert(); +} + + +inline const bool operator != (const std::string& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with std::string +{ + return other != da.convert(); +} + + +inline const bool operator == (const char* other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with const char* +{ + return da.convert() == other; +} + + +inline const bool operator != (const char* other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with const char* +{ + return da.convert() != other; +} + + +#ifndef POCO_LONG_IS_64_BIT + + +inline const long operator + (const long& other, const DynamicAny& da) + /// Addition operator for adding DynamicAny to long +{ + return other + da.convert(); +} + + +inline const long operator - (const long& other, const DynamicAny& da) + /// Subtraction operator for subtracting DynamicAny from long +{ + return other - da.convert(); +} + + +inline const long operator * (const long& other, const DynamicAny& da) + /// Multiplication operator for multiplying DynamicAny with long +{ + return other * da.convert(); +} + + +inline const long operator / (const long& other, const DynamicAny& da) + /// Division operator for dividing DynamicAny with long +{ + return other / da.convert(); +} + + +inline long operator += (long& other, const DynamicAny& da) + /// Addition asignment operator for adding DynamicAny to long +{ + return other += da.convert(); +} + + +inline long operator -= (long& other, const DynamicAny& da) + /// Subtraction asignment operator for subtracting DynamicAny from long +{ + return other -= da.convert(); +} + + +inline long operator *= (long& other, const DynamicAny& da) + /// Multiplication asignment operator for multiplying DynamicAny with long +{ + return other *= da.convert(); +} + + +inline long operator /= (long& other, const DynamicAny& da) + /// Division asignment operator for dividing DynamicAny with long +{ + return other /= da.convert(); +} + + +inline const bool operator == (const long& other, const DynamicAny& da) + /// Equality operator for comparing DynamicAny with long +{ + return other == da.convert(); +} + + +inline const bool operator != (const long& other, const DynamicAny& da) + /// Inequality operator for comparing DynamicAny with long +{ + return other != da.convert(); +} + + +inline const bool operator < (const long& other, const DynamicAny& da) + /// Less than operator for comparing DynamicAny with long +{ + return other < da.convert(); +} + + +inline const bool operator <= (const long& other, const DynamicAny& da) + /// Less than or equal operator for comparing DynamicAny with long +{ + return other <= da.convert(); +} + + +inline const bool operator > (const long& other, const DynamicAny& da) + /// Greater than operator for comparing DynamicAny with long +{ + return other > da.convert(); +} + + +inline const bool operator >= (const long& other, const DynamicAny& da) + /// Greater than or equal operator for comparing DynamicAny with long +{ + return other >= da.convert(); +} + + +#endif // POCO_LONG_IS_64_BIT + + +} // namespace Poco + + +#endif // Foundation_DynamicAny_INCLUDED diff --git a/Foundation/include/Poco/DynamicAnyHolder.h b/Foundation/include/Poco/DynamicAnyHolder.h index 6296c09fa..57c868351 100644 --- a/Foundation/include/Poco/DynamicAnyHolder.h +++ b/Foundation/include/Poco/DynamicAnyHolder.h @@ -1,3215 +1,3215 @@ -// -// DynamicAnyHolder.h -// -// $Id: //poco/svn/Foundation/include/Poco/DynamicAnyHolder.h#3 $ -// -// Library: Foundation -// Package: Core -// Module: DynamicAnyHolder -// -// Definition of the DynamicAnyHolder 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_DynamicAnyHolder_INCLUDED -#define Foundation_DynamicAnyHolder_INCLUDED - - -#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 -#include - - -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, DateTime, LocalDateTime, Timestamp, - /// std::vector and DynamicStruct. -{ -public: - DynamicAnyHolder(); - /// Creates the DynamicAnyHolder. - - virtual ~DynamicAnyHolder(); - /// Destroys the DynamicAnyHolder. - - virtual DynamicAnyHolder* clone() const = 0; - /// Deep-copies the DynamicAnyHolder. - - virtual const std::type_info& type() const = 0; - /// Returns the type information of the stored content. - - virtual void convert(Int8& val) const = 0; - virtual void convert(Int16& val) const = 0; - virtual void convert(Int32& val) const = 0; - virtual void convert(Int64& val) const = 0; - virtual void convert(UInt8& val) const = 0; - 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; - virtual bool isInteger() const = 0; - virtual bool isSigned() const = 0; - virtual bool isNumeric() const = 0; - virtual bool isString() const = 0; - -#ifndef POCO_LONG_IS_64_BIT - void convert(long& val) const; - void convert(unsigned long& val) const; -#endif - - virtual void convert(bool& val) const = 0; - virtual void convert(float& val) const = 0; - virtual void convert(double& val) const = 0; - virtual void convert(char& val) const = 0; - virtual void convert(std::string& val) const = 0; - -protected: - template - void convertToSmaller(const F& from, T& to) const - /// This function is meant to convert signed numeric values from - /// larger to smaller type. It checks the upper and lower bound and - /// if from value is within limits of type T (i.e. check calls do not throw), - /// it is converted. - { - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (std::numeric_limits::is_signed); - poco_static_assert (std::numeric_limits::is_signed); - - if (std::numeric_limits::is_integer) - checkUpperLimit(from, to); - else - checkUpperLimitFloat(from, to); - - checkLowerLimit(from, to); - to = static_cast(from); - } - - template - void convertToSmallerUnsigned(const F& from, T& to) const - /// This function is meant for converting unsigned integral data types, - /// from larger to smaller type. Since lower limit is always 0 for unigned types, - /// only the upper limit is checked, thus saving some cycles compared to the signed - /// version of the function. If the value to be converted is smaller than - /// the maximum value for the target type, the conversion is performed. - { - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (!std::numeric_limits::is_signed); - poco_static_assert (!std::numeric_limits::is_signed); - - checkUpperLimit(from, to); - to = static_cast(from); - } - - template - void convertSignedToUnsigned(const F& from, T& to) const - /// This function is meant for converting signed integral data types to - /// unsigned data types. Negative values can not be converted and if one is - /// encountered, RangeException is thrown. - /// If upper limit is within the target data type limits, the conversion is performed. - { - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (std::numeric_limits::is_signed); - poco_static_assert (!std::numeric_limits::is_signed); - - if (from < 0) - throw RangeException("Value too small."); - checkUpperLimit(from, to); - to = static_cast(from); - } - - template - void convertSignedFloatToUnsigned(const F& from, T& to) const - /// This function is meant for converting floating point data types to - /// unsigned integral data types. Negative values can not be converted and if one is - /// encountered, RangeException is thrown. - /// If uper limit is within the target data type limits, the conversion is performed. - { - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (!std::numeric_limits::is_integer); - poco_static_assert (std::numeric_limits::is_integer); - poco_static_assert (!std::numeric_limits::is_signed); - - if (from < 0) - throw RangeException("Value too small."); - checkUpperLimitFloat(from, to); - to = static_cast(from); - } - - template - void convertUnsignedToSigned(const F& from, T& to) const - /// This function is meant for converting unsigned integral data types to - /// unsigned data types. Negative values can not be converted and if one is - /// encountered, RangeException is thrown. - /// If upper limit is within the target data type limits, the converiosn is performed. - { - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (std::numeric_limits::is_specialized); - poco_static_assert (!std::numeric_limits::is_signed); - poco_static_assert (std::numeric_limits::is_signed); - - checkUpperLimit(from, to); - to = static_cast(from); - } - -private: - template - void checkUpperLimit(const F& from, T& to) const - { - if ((sizeof(T) < sizeof(F)) && - (from > static_cast(std::numeric_limits::max()))) - { - throw RangeException("Value too large."); - } - else - if (static_cast(from) > std::numeric_limits::max()) - { - throw RangeException("Value too large."); - } - } - - template - void checkUpperLimitFloat(const F& from, T& to) const - { - if (from > std::numeric_limits::max()) - throw RangeException("Value too large."); - } - - template - void checkLowerLimit(const F& from, T& to) const - { - if (from < std::numeric_limits::min()) - throw RangeException("Value too small."); - } -}; - - -// -// inlines -// -#ifndef POCO_LONG_IS_64_BIT -inline void DynamicAnyHolder::convert(long& val) const -{ - Int32 tmp; - convert(tmp); - val = tmp; -} - - -inline void DynamicAnyHolder::convert(unsigned long& val) const -{ - UInt32 tmp; - convert(tmp); - val = tmp; -} -#endif - - -template -class DynamicAnyHolderImpl: public DynamicAnyHolder - /// Template based implementation of a DynamicAnyHolder. - /// Conversion work happens in the template specializations of this class. - /// - /// DynamicAny can be used for any type for which a specialization for - /// DynamicAnyHolderImpl is available. - /// - /// DynamicAnyHolderImpl throws following exceptions: - /// NotImplementedException (if the specialization for a type does not exist) - /// RangeException (if an attempt is made to assign a numeric value outside of the target min/max limits - /// SyntaxException (if an attempt is made to convert a string containing non-numeric characters to number) - /// - /// All specializations must additionally implement a public member function: - /// const T& value() const - /// returning a const reference to the actual stored value. -{ -public: - DynamicAnyHolderImpl() - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(T); - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return type() == typeid(std::string); - } - - void convert(Int8&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(Int16&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(Int32&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(Int64&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(UInt8&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(UInt16&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(UInt32&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(UInt64&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(bool&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(float&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(double&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(char&) const - { - throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); - } - - void convert(std::string&) const - { - 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()); - } -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(Int8 val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Int8); - } - - void convert(Int8& val) const - { - val = _val; - } - - void convert(Int16& val) const - { - val = _val; - } - - void convert(Int32& val) const - { - val = _val; - } - - void convert(Int64& val) const - { - val = _val; - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - val = static_cast(_val); - } - - void convert(std::string& val) const - { - 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); - } - - const Int8& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - Int8 _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(Int16 val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Int16); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - val = _val; - } - - void convert(Int32& val) const - { - val = _val; - } - - void convert(Int64& val) const - { - val = _val; - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const Int16& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - Int16 _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(Int32 val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Int32); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - val = _val; - } - - void convert(Int64& val) const - { - val = _val; - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const Int32& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - Int32 _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(Int64 val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Int64); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int64& val) const - { - val = _val; - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const Int64& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - Int64 _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(UInt8 val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(UInt8); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - val = static_cast(_val); - } - - void convert(Int64& val) const - { - val = static_cast(_val); - } - - void convert(UInt8& val) const - { - val = _val; - } - - void convert(UInt16& val) const - { - val = _val; - } - - void convert(UInt32& val) const - { - val = _val; - } - - void convert(UInt64& val) const - { - val = _val; - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const UInt8& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - UInt8 _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(UInt16 val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(UInt16); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - val = static_cast(_val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - val = _val; - } - - void convert(UInt32& val) const - { - val = _val; - } - - void convert(UInt64& val) const - { - val = _val; - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const UInt16& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - UInt16 _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(UInt32 val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(UInt32); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - val = _val; - } - - void convert(UInt64& val) const - { - val = _val; - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const UInt32& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - UInt32 _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(UInt64 val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(UInt64); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - val = _val; - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const UInt64& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - UInt64 _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(bool val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(bool); - } - - void convert(Int8& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(Int16& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(Int32& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(Int64& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(UInt8& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(UInt16& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(UInt32& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(UInt64& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(bool& val) const - { - val = _val; - } - - void convert(float& val) const - { - val = (_val ? 1.0f : 0.0f); - } - - void convert(double& val) const - { - val = (_val ? 1.0 : 0.0); - } - - void convert(char& val) const - { - val = static_cast(_val ? 1 : 0); - } - - void convert(std::string& val) const - { - 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); - } - - const bool& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - bool _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(float val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(float); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int64& val) const - { - convertToSmaller(_val, val); - } - - void convert(UInt8& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = !(_val <= std::numeric_limits::min() && - _val >= -1 * std::numeric_limits::min()); - } - - void convert(float& val) const - { - val = _val; - } - - void convert(double& val) const - { - val = _val; - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const float& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - float _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(double val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(double); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int64& val) const - { - convertToSmaller(_val, val); - } - - void convert(UInt8& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = !(_val <= std::numeric_limits::min() && - _val >= -1 * std::numeric_limits::min()); - } - - void convert(float& val) const - { - double fMin = -1 * std::numeric_limits::max(); - double fMax = std::numeric_limits::max(); - - if (_val < fMin) throw RangeException("Value too small."); - if (_val > fMax) throw RangeException("Value too large."); - - val = static_cast(_val); - } - - void convert(double& val) const - { - val = _val; - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const double& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - double _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(char val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(char); - } - - void convert(Int8& val) const - { - val = static_cast(_val); - } - - void convert(Int16& val) const - { - val = static_cast(_val); - } - - void convert(Int32& val) const - { - val = static_cast(_val); - } - - void convert(Int64& val) const - { - val = static_cast(_val); - } - - void convert(UInt8& val) const - { - val = static_cast(_val); - } - - void convert(UInt16& val) const - { - val = static_cast(_val); - } - - void convert(UInt32& val) const - { - val = static_cast(_val); - } - - void convert(UInt64& val) const - { - val = static_cast(_val); - } - - void convert(bool& val) const - { - val = (_val != '\0'); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - val = _val; - } - - void convert(std::string& val) const - { - 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); - } - - const char& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - char _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(const char* pVal): _val(pVal) - { - } - - DynamicAnyHolderImpl(const std::string& val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(std::string); - } - - void convert(Int8& val) const - { - int v = NumberParser::parse(_val); - convertToSmaller(v, val); - } - - void convert(Int16& val) const - { - int v = NumberParser::parse(_val); - convertToSmaller(v, val); - } - - void convert(Int32& val) const - { - val = NumberParser::parse(_val); - } - - void convert(Int64& val) const - { - val = NumberParser::parse64(_val); - } - - void convert(UInt8& val) const - { - unsigned int v = NumberParser::parseUnsigned(_val); - convertToSmallerUnsigned(v, val); - } - - void convert(UInt16& val) const - { - unsigned int v = NumberParser::parseUnsigned(_val); - convertToSmallerUnsigned(v, val); - } - - void convert(UInt32& val) const - { - val = NumberParser::parseUnsigned(_val); - } - - void convert(UInt64& val) const - { - val = NumberParser::parseUnsigned64(_val); - } - - void convert(bool& val) const - { - static const std::string VAL_FALSE("false"); - static const std::string VAL_INTFALSE("0"); - - if (_val == VAL_INTFALSE || (icompare(_val, VAL_FALSE) == 0)) - val = false; - else - val = true; - } - - void convert(float& val) const - { - double v = NumberParser::parseFloat(_val); - convertToSmaller(v, val); - } - - void convert(double& val) const - { - val = NumberParser::parseFloat(_val); - } - - void convert(char& val) const - { - if (_val.empty()) - val = '\0'; - else - val = _val[0]; - } - - void convert(std::string& val) const - { - 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); - } - - const std::string& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() const - { - return true; - } - -private: - std::string _val; -}; - - -#ifndef POCO_LONG_IS_64_BIT - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(long val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(long); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - val = static_cast(_val); - } - - void convert(Int64& val) const - { - val = static_cast(_val); - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const long& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - long _val; -}; - - -template <> -class DynamicAnyHolderImpl: public DynamicAnyHolder -{ -public: - DynamicAnyHolderImpl(unsigned long val): _val(val) - { - } - - ~DynamicAnyHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(unsigned long); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - val = static_cast(_val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast(_val); - } - - void convert(double& val) const - { - val = static_cast(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast(tmp); - } - - void convert(std::string& val) const - { - 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); - } - - const unsigned long& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits::is_specialized; - } - - bool isString() const - { - return false; - } - -private: - unsigned long _val; -}; - - -#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 the 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; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() 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; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() 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; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() 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; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - Timestamp _val; -}; - - -} // namespace Poco - - -#endif // Foundation_DynamicAnyHolder_INCLUDED +// +// DynamicAnyHolder.h +// +// $Id: //poco/svn/Foundation/include/Poco/DynamicAnyHolder.h#3 $ +// +// Library: Foundation +// Package: Core +// Module: DynamicAnyHolder +// +// Definition of the DynamicAnyHolder 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_DynamicAnyHolder_INCLUDED +#define Foundation_DynamicAnyHolder_INCLUDED + + +#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 +#include + + +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, DateTime, LocalDateTime, Timestamp, + /// std::vector and DynamicStruct. +{ +public: + DynamicAnyHolder(); + /// Creates the DynamicAnyHolder. + + virtual ~DynamicAnyHolder(); + /// Destroys the DynamicAnyHolder. + + virtual DynamicAnyHolder* clone() const = 0; + /// Deep-copies the DynamicAnyHolder. + + virtual const std::type_info& type() const = 0; + /// Returns the type information of the stored content. + + virtual void convert(Int8& val) const = 0; + virtual void convert(Int16& val) const = 0; + virtual void convert(Int32& val) const = 0; + virtual void convert(Int64& val) const = 0; + virtual void convert(UInt8& val) const = 0; + 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; + virtual bool isInteger() const = 0; + virtual bool isSigned() const = 0; + virtual bool isNumeric() const = 0; + virtual bool isString() const = 0; + +#ifndef POCO_LONG_IS_64_BIT + void convert(long& val) const; + void convert(unsigned long& val) const; +#endif + + virtual void convert(bool& val) const = 0; + virtual void convert(float& val) const = 0; + virtual void convert(double& val) const = 0; + virtual void convert(char& val) const = 0; + virtual void convert(std::string& val) const = 0; + +protected: + template + void convertToSmaller(const F& from, T& to) const + /// This function is meant to convert signed numeric values from + /// larger to smaller type. It checks the upper and lower bound and + /// if from value is within limits of type T (i.e. check calls do not throw), + /// it is converted. + { + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (std::numeric_limits::is_signed); + poco_static_assert (std::numeric_limits::is_signed); + + if (std::numeric_limits::is_integer) + checkUpperLimit(from, to); + else + checkUpperLimitFloat(from, to); + + checkLowerLimit(from, to); + to = static_cast(from); + } + + template + void convertToSmallerUnsigned(const F& from, T& to) const + /// This function is meant for converting unsigned integral data types, + /// from larger to smaller type. Since lower limit is always 0 for unigned types, + /// only the upper limit is checked, thus saving some cycles compared to the signed + /// version of the function. If the value to be converted is smaller than + /// the maximum value for the target type, the conversion is performed. + { + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (!std::numeric_limits::is_signed); + poco_static_assert (!std::numeric_limits::is_signed); + + checkUpperLimit(from, to); + to = static_cast(from); + } + + template + void convertSignedToUnsigned(const F& from, T& to) const + /// This function is meant for converting signed integral data types to + /// unsigned data types. Negative values can not be converted and if one is + /// encountered, RangeException is thrown. + /// If upper limit is within the target data type limits, the conversion is performed. + { + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (std::numeric_limits::is_signed); + poco_static_assert (!std::numeric_limits::is_signed); + + if (from < 0) + throw RangeException("Value too small."); + checkUpperLimit(from, to); + to = static_cast(from); + } + + template + void convertSignedFloatToUnsigned(const F& from, T& to) const + /// This function is meant for converting floating point data types to + /// unsigned integral data types. Negative values can not be converted and if one is + /// encountered, RangeException is thrown. + /// If uper limit is within the target data type limits, the conversion is performed. + { + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (!std::numeric_limits::is_integer); + poco_static_assert (std::numeric_limits::is_integer); + poco_static_assert (!std::numeric_limits::is_signed); + + if (from < 0) + throw RangeException("Value too small."); + checkUpperLimitFloat(from, to); + to = static_cast(from); + } + + template + void convertUnsignedToSigned(const F& from, T& to) const + /// This function is meant for converting unsigned integral data types to + /// unsigned data types. Negative values can not be converted and if one is + /// encountered, RangeException is thrown. + /// If upper limit is within the target data type limits, the converiosn is performed. + { + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (std::numeric_limits::is_specialized); + poco_static_assert (!std::numeric_limits::is_signed); + poco_static_assert (std::numeric_limits::is_signed); + + checkUpperLimit(from, to); + to = static_cast(from); + } + +private: + template + void checkUpperLimit(const F& from, T& to) const + { + if ((sizeof(T) < sizeof(F)) && + (from > static_cast(std::numeric_limits::max()))) + { + throw RangeException("Value too large."); + } + else + if (static_cast(from) > std::numeric_limits::max()) + { + throw RangeException("Value too large."); + } + } + + template + void checkUpperLimitFloat(const F& from, T& to) const + { + if (from > std::numeric_limits::max()) + throw RangeException("Value too large."); + } + + template + void checkLowerLimit(const F& from, T& to) const + { + if (from < std::numeric_limits::min()) + throw RangeException("Value too small."); + } +}; + + +// +// inlines +// +#ifndef POCO_LONG_IS_64_BIT +inline void DynamicAnyHolder::convert(long& val) const +{ + Int32 tmp; + convert(tmp); + val = tmp; +} + + +inline void DynamicAnyHolder::convert(unsigned long& val) const +{ + UInt32 tmp; + convert(tmp); + val = tmp; +} +#endif + + +template +class DynamicAnyHolderImpl: public DynamicAnyHolder + /// Template based implementation of a DynamicAnyHolder. + /// Conversion work happens in the template specializations of this class. + /// + /// DynamicAny can be used for any type for which a specialization for + /// DynamicAnyHolderImpl is available. + /// + /// DynamicAnyHolderImpl throws following exceptions: + /// NotImplementedException (if the specialization for a type does not exist) + /// RangeException (if an attempt is made to assign a numeric value outside of the target min/max limits + /// SyntaxException (if an attempt is made to convert a string containing non-numeric characters to number) + /// + /// All specializations must additionally implement a public member function: + /// const T& value() const + /// returning a const reference to the actual stored value. +{ +public: + DynamicAnyHolderImpl() + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(T); + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return type() == typeid(std::string); + } + + void convert(Int8&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(Int16&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(Int32&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(Int64&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(UInt8&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(UInt16&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(UInt32&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(UInt64&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(bool&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(float&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(double&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(char&) const + { + throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); + } + + void convert(std::string&) const + { + 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()); + } +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(Int8 val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Int8); + } + + void convert(Int8& val) const + { + val = _val; + } + + void convert(Int16& val) const + { + val = _val; + } + + void convert(Int32& val) const + { + val = _val; + } + + void convert(Int64& val) const + { + val = _val; + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + val = static_cast(_val); + } + + void convert(std::string& val) const + { + 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); + } + + const Int8& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + Int8 _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(Int16 val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Int16); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + val = _val; + } + + void convert(Int32& val) const + { + val = _val; + } + + void convert(Int64& val) const + { + val = _val; + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const Int16& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + Int16 _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(Int32 val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Int32); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + val = _val; + } + + void convert(Int64& val) const + { + val = _val; + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const Int32& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + Int32 _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(Int64 val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Int64); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int64& val) const + { + val = _val; + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const Int64& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + Int64 _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(UInt8 val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(UInt8); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + val = static_cast(_val); + } + + void convert(Int64& val) const + { + val = static_cast(_val); + } + + void convert(UInt8& val) const + { + val = _val; + } + + void convert(UInt16& val) const + { + val = _val; + } + + void convert(UInt32& val) const + { + val = _val; + } + + void convert(UInt64& val) const + { + val = _val; + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const UInt8& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + UInt8 _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(UInt16 val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(UInt16); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + val = static_cast(_val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + val = _val; + } + + void convert(UInt32& val) const + { + val = _val; + } + + void convert(UInt64& val) const + { + val = _val; + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const UInt16& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + UInt16 _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(UInt32 val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(UInt32); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + val = _val; + } + + void convert(UInt64& val) const + { + val = _val; + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const UInt32& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + UInt32 _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(UInt64 val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(UInt64); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + val = _val; + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const UInt64& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + UInt64 _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(bool val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(bool); + } + + void convert(Int8& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(Int16& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(Int32& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(Int64& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(UInt8& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(UInt16& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(UInt32& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(UInt64& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(bool& val) const + { + val = _val; + } + + void convert(float& val) const + { + val = (_val ? 1.0f : 0.0f); + } + + void convert(double& val) const + { + val = (_val ? 1.0 : 0.0); + } + + void convert(char& val) const + { + val = static_cast(_val ? 1 : 0); + } + + void convert(std::string& val) const + { + 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); + } + + const bool& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + bool _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(float val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(float); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int64& val) const + { + convertToSmaller(_val, val); + } + + void convert(UInt8& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = !(_val <= std::numeric_limits::min() && + _val >= -1 * std::numeric_limits::min()); + } + + void convert(float& val) const + { + val = _val; + } + + void convert(double& val) const + { + val = _val; + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const float& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + float _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(double val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(double); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int64& val) const + { + convertToSmaller(_val, val); + } + + void convert(UInt8& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = !(_val <= std::numeric_limits::min() && + _val >= -1 * std::numeric_limits::min()); + } + + void convert(float& val) const + { + double fMin = -1 * std::numeric_limits::max(); + double fMax = std::numeric_limits::max(); + + if (_val < fMin) throw RangeException("Value too small."); + if (_val > fMax) throw RangeException("Value too large."); + + val = static_cast(_val); + } + + void convert(double& val) const + { + val = _val; + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const double& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + double _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(char val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(char); + } + + void convert(Int8& val) const + { + val = static_cast(_val); + } + + void convert(Int16& val) const + { + val = static_cast(_val); + } + + void convert(Int32& val) const + { + val = static_cast(_val); + } + + void convert(Int64& val) const + { + val = static_cast(_val); + } + + void convert(UInt8& val) const + { + val = static_cast(_val); + } + + void convert(UInt16& val) const + { + val = static_cast(_val); + } + + void convert(UInt32& val) const + { + val = static_cast(_val); + } + + void convert(UInt64& val) const + { + val = static_cast(_val); + } + + void convert(bool& val) const + { + val = (_val != '\0'); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + val = _val; + } + + void convert(std::string& val) const + { + 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); + } + + const char& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + char _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(const char* pVal): _val(pVal) + { + } + + DynamicAnyHolderImpl(const std::string& val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(std::string); + } + + void convert(Int8& val) const + { + int v = NumberParser::parse(_val); + convertToSmaller(v, val); + } + + void convert(Int16& val) const + { + int v = NumberParser::parse(_val); + convertToSmaller(v, val); + } + + void convert(Int32& val) const + { + val = NumberParser::parse(_val); + } + + void convert(Int64& val) const + { + val = NumberParser::parse64(_val); + } + + void convert(UInt8& val) const + { + unsigned int v = NumberParser::parseUnsigned(_val); + convertToSmallerUnsigned(v, val); + } + + void convert(UInt16& val) const + { + unsigned int v = NumberParser::parseUnsigned(_val); + convertToSmallerUnsigned(v, val); + } + + void convert(UInt32& val) const + { + val = NumberParser::parseUnsigned(_val); + } + + void convert(UInt64& val) const + { + val = NumberParser::parseUnsigned64(_val); + } + + void convert(bool& val) const + { + static const std::string VAL_FALSE("false"); + static const std::string VAL_INTFALSE("0"); + + if (_val == VAL_INTFALSE || (icompare(_val, VAL_FALSE) == 0)) + val = false; + else + val = true; + } + + void convert(float& val) const + { + double v = NumberParser::parseFloat(_val); + convertToSmaller(v, val); + } + + void convert(double& val) const + { + val = NumberParser::parseFloat(_val); + } + + void convert(char& val) const + { + if (_val.empty()) + val = '\0'; + else + val = _val[0]; + } + + void convert(std::string& val) const + { + 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); + } + + const std::string& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() const + { + return true; + } + +private: + std::string _val; +}; + + +#ifndef POCO_LONG_IS_64_BIT + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(long val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(long); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + val = static_cast(_val); + } + + void convert(Int64& val) const + { + val = static_cast(_val); + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const long& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + long _val; +}; + + +template <> +class DynamicAnyHolderImpl: public DynamicAnyHolder +{ +public: + DynamicAnyHolderImpl(unsigned long val): _val(val) + { + } + + ~DynamicAnyHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(unsigned long); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + val = static_cast(_val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast(_val); + } + + void convert(double& val) const + { + val = static_cast(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast(tmp); + } + + void convert(std::string& val) const + { + 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); + } + + const unsigned long& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits::is_specialized; + } + + bool isString() const + { + return false; + } + +private: + unsigned long _val; +}; + + +#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 the 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; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() 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; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() 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; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() 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; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + Timestamp _val; +}; + + +} // namespace Poco + + +#endif // Foundation_DynamicAnyHolder_INCLUDED diff --git a/Foundation/include/Poco/DynamicStruct.h b/Foundation/include/Poco/DynamicStruct.h index 664afcd8e..f181e2283 100644 --- a/Foundation/include/Poco/DynamicStruct.h +++ b/Foundation/include/Poco/DynamicStruct.h @@ -1,399 +1,399 @@ -// -// 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 DynamicAny objects. -{ -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; -}; - - -// -// inlines -// -inline DynamicAny& DynamicStruct::operator [] (const std::string& name) -{ - return _data[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; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() const - { - return false; - } - - DynamicAny& operator [] (const std::string& name) - { - return _val[name]; - } - - const DynamicAny& operator [] (const std::string& name) const - { - return _val[name]; - } - -private: - DynamicStruct _val; -}; - - -} // namespace Poco - - -#endif // Foundation_DynamicStruct_INCLUDED +// +// 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 DynamicAny objects. +{ +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; +}; + + +// +// inlines +// +inline DynamicAny& DynamicStruct::operator [] (const std::string& name) +{ + return _data[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; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() const + { + return false; + } + + DynamicAny& operator [] (const std::string& name) + { + return _val[name]; + } + + const DynamicAny& operator [] (const std::string& name) const + { + return _val[name]; + } + +private: + DynamicStruct _val; +}; + + +} // namespace Poco + + +#endif // Foundation_DynamicStruct_INCLUDED diff --git a/Foundation/include/Poco/ExpirationDecorator.h b/Foundation/include/Poco/ExpirationDecorator.h index 3a630f467..b2c78fe3f 100644 --- a/Foundation/include/Poco/ExpirationDecorator.h +++ b/Foundation/include/Poco/ExpirationDecorator.h @@ -1,114 +1,114 @@ -// -// ExpirationDecorator.h -// -// $Id: //poco/svn/Foundation/include/Poco/ExpirationDecorator.h#2 $ -// -// Library: Foundation -// Package: Events -// Module: ExpirationDecorator -// -// Implementation of the ExpirationDecorator template. -// -// Copyright (c) 2006, 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_ExpirationDecorator_INCLUDED -#define Foundation_ExpirationDecorator_INCLUDED - - -#include "Poco/Timestamp.h" -#include "Poco/Timespan.h" - - -namespace Poco { - - -template -class ExpirationDecorator - /// ExpirationDecorator adds an expiration method to values so that they can be used - /// with the UniqueExpireCache -{ -public: - ExpirationDecorator(): - _value(), - _expiresAt() - { - } - - ExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs): - /// Creates an element that will expire in diff milliseconds - _value(p), - _expiresAt() - { - _expiresAt += (diffInMs*1000); - } - - ExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan): - /// Creates an element that will expire after the given timeSpan - _value(p), - _expiresAt() - { - _expiresAt += timeSpan.totalMicroseconds(); - } - - ExpirationDecorator(const TArgs& p, const Poco::Timestamp& timeStamp): - /// Creates an element that will expire at the given time point - _value(p), - _expiresAt(timeStamp) - { - } - - - ~ExpirationDecorator() - { - } - - const Poco::Timestamp& getExpiration() const - { - return _expiresAt; - } - - const TArgs& value() const - { - return _value; - } - - TArgs& value() - { - return _value; - } - -private: - TArgs _value; - Timestamp _expiresAt; -}; - - -} // namespace Poco - - -#endif +// +// ExpirationDecorator.h +// +// $Id: //poco/svn/Foundation/include/Poco/ExpirationDecorator.h#2 $ +// +// Library: Foundation +// Package: Events +// Module: ExpirationDecorator +// +// Implementation of the ExpirationDecorator template. +// +// Copyright (c) 2006, 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_ExpirationDecorator_INCLUDED +#define Foundation_ExpirationDecorator_INCLUDED + + +#include "Poco/Timestamp.h" +#include "Poco/Timespan.h" + + +namespace Poco { + + +template +class ExpirationDecorator + /// ExpirationDecorator adds an expiration method to values so that they can be used + /// with the UniqueExpireCache +{ +public: + ExpirationDecorator(): + _value(), + _expiresAt() + { + } + + ExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs): + /// Creates an element that will expire in diff milliseconds + _value(p), + _expiresAt() + { + _expiresAt += (diffInMs*1000); + } + + ExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan): + /// Creates an element that will expire after the given timeSpan + _value(p), + _expiresAt() + { + _expiresAt += timeSpan.totalMicroseconds(); + } + + ExpirationDecorator(const TArgs& p, const Poco::Timestamp& timeStamp): + /// Creates an element that will expire at the given time point + _value(p), + _expiresAt(timeStamp) + { + } + + + ~ExpirationDecorator() + { + } + + const Poco::Timestamp& getExpiration() const + { + return _expiresAt; + } + + const TArgs& value() const + { + return _value; + } + + TArgs& value() + { + return _value; + } + +private: + TArgs _value; + Timestamp _expiresAt; +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/FileStream.h b/Foundation/include/Poco/FileStream.h index 1ab56d2bf..ddb3b3e6a 100644 --- a/Foundation/include/Poco/FileStream.h +++ b/Foundation/include/Poco/FileStream.h @@ -1,194 +1,194 @@ -// -// FileStream.h -// -// $Id: //poco/svn/Foundation/include/Poco/FileStream.h#2 $ -// -// Library: Foundation -// Package: Streams -// Module: FileStream -// -// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes. -// -// 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_FileStream_INCLUDED -#define Foundation_FileStream_INCLUDED - - -#include "Poco/Foundation.h" -#if defined(POCO_OS_FAMILY_WINDOWS) -#include "FileStream_WIN32.h" -#else -#include "FileStream_POSIX.h" -#endif -#include -#include - - -namespace Poco { - - -class Foundation_API FileIOS: public virtual std::ios - /// The base class for FileInputStream and FileOutputStream. - /// - /// This class is needed to ensure the correct initialization - /// order of the stream buffer and base classes. - /// - /// Files are always opened in binary mode, a text mode - /// with CR-LF translation is not supported. Thus, the - /// file is always opened as if the std::ios::binary flag - /// was specified. - /// Use an InputLineEndingConverter or OutputLineEndingConverter - /// if you require CR-LF translation. - /// - /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd, - /// UTF-8 encoded Unicode paths are correctly handled. -{ -public: - FileIOS(std::ios::openmode defaultMode); - /// Creates the basic stream. - - ~FileIOS(); - /// Destroys the stream. - - void open(const std::string& path, std::ios::openmode mode); - /// Opens the file specified by path, using the given mode. - /// - /// Throws a FileException (or a similar exception) if the file - /// does not exist or is not accessible for other reasons and - /// a new file cannot be created. - - void close(); - /// Closes the file stream. - - FileStreamBuf* rdbuf(); - /// Returns a pointer to the underlying streambuf. - -protected: - FileStreamBuf _buf; - std::ios::openmode _defaultMode; -}; - - -class Foundation_API FileInputStream: public FileIOS, public std::istream - /// An input stream for reading from a file. - /// - /// Files are always opened in binary mode, a text mode - /// with CR-LF translation is not supported. Thus, the - /// file is always opened as if the std::ios::binary flag - /// was specified. - /// Use an InputLineEndingConverter if you require CR-LF translation. - /// - /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd, - /// UTF-8 encoded Unicode paths are correctly handled. -{ -public: - FileInputStream(); - /// Creates an unopened FileInputStream. - - FileInputStream(const std::string& path, std::ios::openmode mode = std::ios::in); - /// Creates the FileInputStream for the file given by path, using - /// the given mode. - /// - /// The std::ios::in flag is always set, regardless of the actual - /// value specified for mode. - /// - /// Throws a FileNotFoundException (or a similar exception) if the file - /// does not exist or is not accessible for other reasons. - - ~FileInputStream(); - /// Destroys the stream. -}; - - -class Foundation_API FileOutputStream: public FileIOS, public std::ostream - /// An output stream for writing to a file. - /// - /// Files are always opened in binary mode, a text mode - /// with CR-LF translation is not supported. Thus, the - /// file is always opened as if the std::ios::binary flag - /// was specified. - /// Use an OutputLineEndingConverter if you require CR-LF translation. - /// - /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd, - /// UTF-8 encoded Unicode paths are correctly handled. -{ -public: - FileOutputStream(); - /// Creats an unopened FileOutputStream. - - FileOutputStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc); - /// Creates the FileOutputStream for the file given by path, using - /// the given mode. - /// - /// The std::ios::out is always set, regardless of the actual - /// value specified for mode. - /// - /// Throws a FileException (or a similar exception) if the file - /// does not exist or is not accessible for other reasons and - /// a new file cannot be created. - - ~FileOutputStream(); - /// Destroys the FileOutputStream. -}; - - -class Foundation_API FileStream: public FileIOS, public std::iostream - /// A stream for reading from and writing to a file. - /// - /// Files are always opened in binary mode, a text mode - /// with CR-LF translation is not supported. Thus, the - /// file is always opened as if the std::ios::binary flag - /// was specified. - /// Use an InputLineEndingConverter or OutputLineEndingConverter - /// if you require CR-LF translation. - /// - /// A seek (seekg() or seekp()) operation will always set the - /// read position and the write position simultaneously to the - /// same value. - /// - /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd, - /// UTF-8 encoded Unicode paths are correctly handled. -{ -public: - FileStream(); - /// Creats an unopened FileStream. - - FileStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::in); - /// Creates the FileStream for the file given by path, using - /// the given mode. - - ~FileStream(); - /// Destroys the FileOutputStream. -}; - - -} // namespace Poco - - -#endif // Foundation_FileStream_INCLUDED +// +// FileStream.h +// +// $Id: //poco/svn/Foundation/include/Poco/FileStream.h#2 $ +// +// Library: Foundation +// Package: Streams +// Module: FileStream +// +// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes. +// +// 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_FileStream_INCLUDED +#define Foundation_FileStream_INCLUDED + + +#include "Poco/Foundation.h" +#if defined(POCO_OS_FAMILY_WINDOWS) +#include "FileStream_WIN32.h" +#else +#include "FileStream_POSIX.h" +#endif +#include +#include + + +namespace Poco { + + +class Foundation_API FileIOS: public virtual std::ios + /// The base class for FileInputStream and FileOutputStream. + /// + /// This class is needed to ensure the correct initialization + /// order of the stream buffer and base classes. + /// + /// Files are always opened in binary mode, a text mode + /// with CR-LF translation is not supported. Thus, the + /// file is always opened as if the std::ios::binary flag + /// was specified. + /// Use an InputLineEndingConverter or OutputLineEndingConverter + /// if you require CR-LF translation. + /// + /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd, + /// UTF-8 encoded Unicode paths are correctly handled. +{ +public: + FileIOS(std::ios::openmode defaultMode); + /// Creates the basic stream. + + ~FileIOS(); + /// Destroys the stream. + + void open(const std::string& path, std::ios::openmode mode); + /// Opens the file specified by path, using the given mode. + /// + /// Throws a FileException (or a similar exception) if the file + /// does not exist or is not accessible for other reasons and + /// a new file cannot be created. + + void close(); + /// Closes the file stream. + + FileStreamBuf* rdbuf(); + /// Returns a pointer to the underlying streambuf. + +protected: + FileStreamBuf _buf; + std::ios::openmode _defaultMode; +}; + + +class Foundation_API FileInputStream: public FileIOS, public std::istream + /// An input stream for reading from a file. + /// + /// Files are always opened in binary mode, a text mode + /// with CR-LF translation is not supported. Thus, the + /// file is always opened as if the std::ios::binary flag + /// was specified. + /// Use an InputLineEndingConverter if you require CR-LF translation. + /// + /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd, + /// UTF-8 encoded Unicode paths are correctly handled. +{ +public: + FileInputStream(); + /// Creates an unopened FileInputStream. + + FileInputStream(const std::string& path, std::ios::openmode mode = std::ios::in); + /// Creates the FileInputStream for the file given by path, using + /// the given mode. + /// + /// The std::ios::in flag is always set, regardless of the actual + /// value specified for mode. + /// + /// Throws a FileNotFoundException (or a similar exception) if the file + /// does not exist or is not accessible for other reasons. + + ~FileInputStream(); + /// Destroys the stream. +}; + + +class Foundation_API FileOutputStream: public FileIOS, public std::ostream + /// An output stream for writing to a file. + /// + /// Files are always opened in binary mode, a text mode + /// with CR-LF translation is not supported. Thus, the + /// file is always opened as if the std::ios::binary flag + /// was specified. + /// Use an OutputLineEndingConverter if you require CR-LF translation. + /// + /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd, + /// UTF-8 encoded Unicode paths are correctly handled. +{ +public: + FileOutputStream(); + /// Creats an unopened FileOutputStream. + + FileOutputStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc); + /// Creates the FileOutputStream for the file given by path, using + /// the given mode. + /// + /// The std::ios::out is always set, regardless of the actual + /// value specified for mode. + /// + /// Throws a FileException (or a similar exception) if the file + /// does not exist or is not accessible for other reasons and + /// a new file cannot be created. + + ~FileOutputStream(); + /// Destroys the FileOutputStream. +}; + + +class Foundation_API FileStream: public FileIOS, public std::iostream + /// A stream for reading from and writing to a file. + /// + /// Files are always opened in binary mode, a text mode + /// with CR-LF translation is not supported. Thus, the + /// file is always opened as if the std::ios::binary flag + /// was specified. + /// Use an InputLineEndingConverter or OutputLineEndingConverter + /// if you require CR-LF translation. + /// + /// A seek (seekg() or seekp()) operation will always set the + /// read position and the write position simultaneously to the + /// same value. + /// + /// On Windows platforms, if POCO_WIN32_UTF8 is #define'd, + /// UTF-8 encoded Unicode paths are correctly handled. +{ +public: + FileStream(); + /// Creats an unopened FileStream. + + FileStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::in); + /// Creates the FileStream for the file given by path, using + /// the given mode. + + ~FileStream(); + /// Destroys the FileOutputStream. +}; + + +} // namespace Poco + + +#endif // Foundation_FileStream_INCLUDED diff --git a/Foundation/include/Poco/FileStream_POSIX.h b/Foundation/include/Poco/FileStream_POSIX.h index be8aab771..b93dbb693 100644 --- a/Foundation/include/Poco/FileStream_POSIX.h +++ b/Foundation/include/Poco/FileStream_POSIX.h @@ -1,93 +1,93 @@ -// -// FileStream_POSIX.h -// -// $Id: //poco/svn/Foundation/include/Poco/FileStream_POSIX.h#2 $ -// -// Library: Foundation -// Package: Streams -// Module: FileStream -// -// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes. -// -// 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_FileStream_POSIX_INCLUDED -#define Foundation_FileStream_POSIX_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/BufferedBidirectionalStreamBuf.h" -#include -#include - - -namespace Poco { - - -class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf - /// This stream buffer handles Fileio -{ -public: - FileStreamBuf(); - /// Creates a FileStreamBuf. - - ~FileStreamBuf(); - /// Destroys the FileStream. - - void open(const std::string& path, std::ios::openmode mode); - /// Opens the given file in the given mode. - - void close(); - /// Closes the File stream buffer. - - std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out); - /// Change position by offset, according to way and mode. - - std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out); - /// Change to specified position, according to mode. - -protected: - enum - { - BUFFER_SIZE = 4096 - }; - - int readFromDevice(char* buffer, std::streamsize length); - int writeToDevice(const char* buffer, std::streamsize length); - -private: - std::string _path; - int _fd; - std::streamoff _pos; -}; - - -} // namespace Poco - - -#endif // Foundation_FileStream_WIN32_INCLUDED +// +// FileStream_POSIX.h +// +// $Id: //poco/svn/Foundation/include/Poco/FileStream_POSIX.h#2 $ +// +// Library: Foundation +// Package: Streams +// Module: FileStream +// +// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes. +// +// 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_FileStream_POSIX_INCLUDED +#define Foundation_FileStream_POSIX_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/BufferedBidirectionalStreamBuf.h" +#include +#include + + +namespace Poco { + + +class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf + /// This stream buffer handles Fileio +{ +public: + FileStreamBuf(); + /// Creates a FileStreamBuf. + + ~FileStreamBuf(); + /// Destroys the FileStream. + + void open(const std::string& path, std::ios::openmode mode); + /// Opens the given file in the given mode. + + void close(); + /// Closes the File stream buffer. + + std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out); + /// Change position by offset, according to way and mode. + + std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out); + /// Change to specified position, according to mode. + +protected: + enum + { + BUFFER_SIZE = 4096 + }; + + int readFromDevice(char* buffer, std::streamsize length); + int writeToDevice(const char* buffer, std::streamsize length); + +private: + std::string _path; + int _fd; + std::streamoff _pos; +}; + + +} // namespace Poco + + +#endif // Foundation_FileStream_WIN32_INCLUDED diff --git a/Foundation/include/Poco/FileStream_WIN32.h b/Foundation/include/Poco/FileStream_WIN32.h index 9fc7cd701..1b53f3dbe 100644 --- a/Foundation/include/Poco/FileStream_WIN32.h +++ b/Foundation/include/Poco/FileStream_WIN32.h @@ -1,92 +1,92 @@ -// -// FileStream_WIN32.h -// -// $Id: //poco/svn/Foundation/include/Poco/FileStream_WIN32.h#2 $ -// -// Library: Foundation -// Package: Streams -// Module: FileStream -// -// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes. -// -// 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_FileStream_WIN32_INCLUDED -#define Foundation_FileStream_WIN32_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/BufferedBidirectionalStreamBuf.h" -#include "Poco/UnWindows.h" - - -namespace Poco { - - -class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf - /// This stream buffer handles Fileio -{ -public: - FileStreamBuf(); - /// Creates a FileStreamBuf. - - ~FileStreamBuf(); - /// Destroys the FileStream. - - void open(const std::string& path, std::ios::openmode mode); - /// Opens the given file in the given mode. - - void close(); - /// Closes the File stream buffer - - std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out); - /// change position by offset, according to way and mode - - std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out); - /// change to specified position, according to mode - -protected: - enum - { - BUFFER_SIZE = 4096 - }; - - int readFromDevice(char* buffer, std::streamsize length); - int writeToDevice(const char* buffer, std::streamsize length); - -private: - std::string _path; - HANDLE _handle; - UInt64 _pos; -}; - - -} // namespace Poco - - -#endif // Foundation_FileStream_WIN32_INCLUDED +// +// FileStream_WIN32.h +// +// $Id: //poco/svn/Foundation/include/Poco/FileStream_WIN32.h#2 $ +// +// Library: Foundation +// Package: Streams +// Module: FileStream +// +// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes. +// +// 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_FileStream_WIN32_INCLUDED +#define Foundation_FileStream_WIN32_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/BufferedBidirectionalStreamBuf.h" +#include "Poco/UnWindows.h" + + +namespace Poco { + + +class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf + /// This stream buffer handles Fileio +{ +public: + FileStreamBuf(); + /// Creates a FileStreamBuf. + + ~FileStreamBuf(); + /// Destroys the FileStream. + + void open(const std::string& path, std::ios::openmode mode); + /// Opens the given file in the given mode. + + void close(); + /// Closes the File stream buffer + + std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out); + /// change position by offset, according to way and mode + + std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out); + /// change to specified position, according to mode + +protected: + enum + { + BUFFER_SIZE = 4096 + }; + + int readFromDevice(char* buffer, std::streamsize length); + int writeToDevice(const char* buffer, std::streamsize length); + +private: + std::string _path; + HANDLE _handle; + UInt64 _pos; +}; + + +} // namespace Poco + + +#endif // Foundation_FileStream_WIN32_INCLUDED diff --git a/Foundation/include/Poco/FunctionDelegate.h b/Foundation/include/Poco/FunctionDelegate.h index 819205cea..8b989265c 100644 --- a/Foundation/include/Poco/FunctionDelegate.h +++ b/Foundation/include/Poco/FunctionDelegate.h @@ -1,208 +1,208 @@ -// -// FunctionDelegate.h -// -// $Id: //poco/svn/Foundation/include/Poco/FunctionDelegate.h#2 $ -// -// Library: Foundation -// Package: Events -// Module: FunctionDelegate -// -// Implementation of the FunctionDelegate template. -// -// Copyright (c) 2006, 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_FunctionDelegate_INCLUDED -#define Foundation_FunctionDelegate_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/AbstractDelegate.h" - - -namespace Poco { - - -template -class FunctionDelegate: public AbstractDelegate - /// Wraps a C style function (or a C++ static fucntion) to be used as - /// a delegate -{ -public: - typedef void (*NotifyMethod)(const void*, TArgs&); - - FunctionDelegate(NotifyMethod method): - AbstractDelegate(*reinterpret_cast(&method)), - _receiverMethod(method) - { - } - - FunctionDelegate(const FunctionDelegate& delegate): - AbstractDelegate(delegate), - _receiverMethod(delegate._receiverMethod) - { - } - - ~FunctionDelegate() - { - } - - FunctionDelegate& operator = (const FunctionDelegate& delegate) - { - if (&delegate != this) - { - this->_pTarget = delegate._pTarget; - this->_receiverMethod = delegate._receiverMethod; - } - return *this; - } - - bool notify(const void* sender, TArgs& arguments) - { - (*_receiverMethod)(sender, arguments); - return true; // a "standard" delegate never expires - } - - AbstractDelegate* clone() const - { - return new FunctionDelegate(*this); - } - -protected: - NotifyMethod _receiverMethod; - -private: - FunctionDelegate(); -}; - - -template -class FunctionDelegate: public AbstractDelegate -{ -public: - typedef void (*NotifyMethod)(void*, TArgs&); - - FunctionDelegate(NotifyMethod method): - AbstractDelegate(*reinterpret_cast(&method)), - _receiverMethod(method) - { - } - - FunctionDelegate(const FunctionDelegate& delegate): - AbstractDelegate(delegate), - _receiverMethod(delegate._receiverMethod) - { - } - - ~FunctionDelegate() - { - } - - FunctionDelegate& operator = (const FunctionDelegate& delegate) - { - if (&delegate != this) - { - this->_pTarget = delegate._pTarget; - this->_receiverMethod = delegate._receiverMethod; - } - return *this; - } - - bool notify(const void* sender, TArgs& arguments) - { - (*_receiverMethod)(const_cast(sender), arguments); - return true; // a "standard" delegate never expires - } - - AbstractDelegate* clone() const - { - return new FunctionDelegate(*this); - } - -protected: - NotifyMethod _receiverMethod; - -private: - FunctionDelegate(); -}; - - -template -class FunctionDelegate: public AbstractDelegate -{ -public: - typedef void (*NotifyMethod)(TArgs&); - - FunctionDelegate(NotifyMethod method): - AbstractDelegate(*reinterpret_cast(&method)), - _receiverMethod(method) - { - } - - FunctionDelegate(const FunctionDelegate& delegate): - AbstractDelegate(delegate), - _receiverMethod(delegate._receiverMethod) - { - } - - ~FunctionDelegate() - { - } - - FunctionDelegate& operator = (const FunctionDelegate& delegate) - { - if (&delegate != this) - { - this->_pTarget = delegate._pTarget; - this->_receiverMethod = delegate._receiverMethod; - } - return *this; - } - - bool notify(const void* sender, TArgs& arguments) - { - (*_receiverMethod)(arguments); - return true; // a "standard" delegate never expires - } - - AbstractDelegate* clone() const - { - return new FunctionDelegate(*this); - } - -protected: - NotifyMethod _receiverMethod; - -private: - FunctionDelegate(); -}; - - -} // namespace Poco - - -#endif +// +// FunctionDelegate.h +// +// $Id: //poco/svn/Foundation/include/Poco/FunctionDelegate.h#2 $ +// +// Library: Foundation +// Package: Events +// Module: FunctionDelegate +// +// Implementation of the FunctionDelegate template. +// +// Copyright (c) 2006, 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_FunctionDelegate_INCLUDED +#define Foundation_FunctionDelegate_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/AbstractDelegate.h" + + +namespace Poco { + + +template +class FunctionDelegate: public AbstractDelegate + /// Wraps a C style function (or a C++ static fucntion) to be used as + /// a delegate +{ +public: + typedef void (*NotifyMethod)(const void*, TArgs&); + + FunctionDelegate(NotifyMethod method): + AbstractDelegate(*reinterpret_cast(&method)), + _receiverMethod(method) + { + } + + FunctionDelegate(const FunctionDelegate& delegate): + AbstractDelegate(delegate), + _receiverMethod(delegate._receiverMethod) + { + } + + ~FunctionDelegate() + { + } + + FunctionDelegate& operator = (const FunctionDelegate& delegate) + { + if (&delegate != this) + { + this->_pTarget = delegate._pTarget; + this->_receiverMethod = delegate._receiverMethod; + } + return *this; + } + + bool notify(const void* sender, TArgs& arguments) + { + (*_receiverMethod)(sender, arguments); + return true; // a "standard" delegate never expires + } + + AbstractDelegate* clone() const + { + return new FunctionDelegate(*this); + } + +protected: + NotifyMethod _receiverMethod; + +private: + FunctionDelegate(); +}; + + +template +class FunctionDelegate: public AbstractDelegate +{ +public: + typedef void (*NotifyMethod)(void*, TArgs&); + + FunctionDelegate(NotifyMethod method): + AbstractDelegate(*reinterpret_cast(&method)), + _receiverMethod(method) + { + } + + FunctionDelegate(const FunctionDelegate& delegate): + AbstractDelegate(delegate), + _receiverMethod(delegate._receiverMethod) + { + } + + ~FunctionDelegate() + { + } + + FunctionDelegate& operator = (const FunctionDelegate& delegate) + { + if (&delegate != this) + { + this->_pTarget = delegate._pTarget; + this->_receiverMethod = delegate._receiverMethod; + } + return *this; + } + + bool notify(const void* sender, TArgs& arguments) + { + (*_receiverMethod)(const_cast(sender), arguments); + return true; // a "standard" delegate never expires + } + + AbstractDelegate* clone() const + { + return new FunctionDelegate(*this); + } + +protected: + NotifyMethod _receiverMethod; + +private: + FunctionDelegate(); +}; + + +template +class FunctionDelegate: public AbstractDelegate +{ +public: + typedef void (*NotifyMethod)(TArgs&); + + FunctionDelegate(NotifyMethod method): + AbstractDelegate(*reinterpret_cast(&method)), + _receiverMethod(method) + { + } + + FunctionDelegate(const FunctionDelegate& delegate): + AbstractDelegate(delegate), + _receiverMethod(delegate._receiverMethod) + { + } + + ~FunctionDelegate() + { + } + + FunctionDelegate& operator = (const FunctionDelegate& delegate) + { + if (&delegate != this) + { + this->_pTarget = delegate._pTarget; + this->_receiverMethod = delegate._receiverMethod; + } + return *this; + } + + bool notify(const void* sender, TArgs& arguments) + { + (*_receiverMethod)(arguments); + return true; // a "standard" delegate never expires + } + + AbstractDelegate* clone() const + { + return new FunctionDelegate(*this); + } + +protected: + NotifyMethod _receiverMethod; + +private: + FunctionDelegate(); +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/FunctionPriorityDelegate.h b/Foundation/include/Poco/FunctionPriorityDelegate.h index 248ea05f3..f567193d9 100644 --- a/Foundation/include/Poco/FunctionPriorityDelegate.h +++ b/Foundation/include/Poco/FunctionPriorityDelegate.h @@ -1,212 +1,212 @@ -// -// FunctionPriorityDelegate.h -// -// $Id: //poco/svn/Foundation/include/Poco/FunctionPriorityDelegate.h#2 $ -// -// Library: Foundation -// Package: Events -// Module: FunctionPriorityDelegate -// -// Implementation of the FunctionPriorityDelegate template. -// -// Copyright (c) 2006, 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_FunctionPriorityDelegate_INCLUDED -#define Foundation_FunctionPriorityDelegate_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/AbstractPriorityDelegate.h" - - -namespace Poco { - - -template -class FunctionPriorityDelegate: public AbstractPriorityDelegate - /// Wraps a C style function (or a C++ static fucntion) to be used as - /// a priority delegate -{ -public: - typedef void (*NotifyMethod)(const void*, TArgs&); - - FunctionPriorityDelegate(NotifyMethod method, int prio): - AbstractPriorityDelegate(*reinterpret_cast(&method), prio), - _receiverMethod(method) - { - } - - FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): - AbstractPriorityDelegate(delegate._pTarget, delegate._priority), - _receiverMethod(delegate._receiverMethod) - { - } - - FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) - { - if (&delegate != this) - { - this->_pTarget = delegate._pTarget; - this->_receiverMethod = delegate._receiverMethod; - this->_priority = delegate._priority; - } - return *this; - } - - ~FunctionPriorityDelegate() - { - } - - bool notify(const void* sender, TArgs& arguments) - { - (*_receiverMethod)(sender, arguments); - return true; // per default the delegate never expires - } - - AbstractPriorityDelegate* clone() const - { - return new FunctionPriorityDelegate(*this); - } - -protected: - NotifyMethod _receiverMethod; - -private: - FunctionPriorityDelegate(); -}; - - -template -class FunctionPriorityDelegate: public AbstractPriorityDelegate -{ -public: - typedef void (*NotifyMethod)(void*, TArgs&); - - FunctionPriorityDelegate(NotifyMethod method, int prio): - AbstractPriorityDelegate(*reinterpret_cast(&method), prio), - _receiverMethod(method) - { - } - - FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): - AbstractPriorityDelegate(delegate._pTarget, delegate._priority), - _receiverMethod(delegate._receiverMethod) - { - } - - FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) - { - if (&delegate != this) - { - this->_pTarget = delegate._pTarget; - this->_receiverMethod = delegate._receiverMethod; - this->_priority = delegate._priority; - } - return *this; - } - - ~FunctionPriorityDelegate() - { - } - - bool notify(const void* sender, TArgs& arguments) - { - (*_receiverMethod)(const_cast(sender), arguments); - return true; // per default the delegate never expires - } - - AbstractPriorityDelegate* clone() const - { - return new FunctionPriorityDelegate(*this); - } - -protected: - NotifyMethod _receiverMethod; - -private: - FunctionPriorityDelegate(); -}; - - - -template -class FunctionPriorityDelegate: public AbstractPriorityDelegate -{ -public: - typedef void (*NotifyMethod)(TArgs&); - - FunctionPriorityDelegate(NotifyMethod method, int prio): - AbstractPriorityDelegate(*reinterpret_cast(&method), prio), - _receiverMethod(method) - { - } - - FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): - AbstractPriorityDelegate(delegate._pTarget, delegate._priority), - _receiverMethod(delegate._receiverMethod) - { - } - - FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) - { - if (&delegate != this) - { - this->_pTarget = delegate._pTarget; - this->_receiverMethod = delegate._receiverMethod; - this->_priority = delegate._priority; - } - return *this; - } - - ~FunctionPriorityDelegate() - { - } - - bool notify(const void* sender, TArgs& arguments) - { - (*_receiverMethod)(arguments); - return true; // per default the delegate never expires - } - - AbstractPriorityDelegate* clone() const - { - return new FunctionPriorityDelegate(*this); - } - -protected: - NotifyMethod _receiverMethod; - -private: - FunctionPriorityDelegate(); -}; - - -} // namespace Poco - - -#endif +// +// FunctionPriorityDelegate.h +// +// $Id: //poco/svn/Foundation/include/Poco/FunctionPriorityDelegate.h#2 $ +// +// Library: Foundation +// Package: Events +// Module: FunctionPriorityDelegate +// +// Implementation of the FunctionPriorityDelegate template. +// +// Copyright (c) 2006, 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_FunctionPriorityDelegate_INCLUDED +#define Foundation_FunctionPriorityDelegate_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/AbstractPriorityDelegate.h" + + +namespace Poco { + + +template +class FunctionPriorityDelegate: public AbstractPriorityDelegate + /// Wraps a C style function (or a C++ static fucntion) to be used as + /// a priority delegate +{ +public: + typedef void (*NotifyMethod)(const void*, TArgs&); + + FunctionPriorityDelegate(NotifyMethod method, int prio): + AbstractPriorityDelegate(*reinterpret_cast(&method), prio), + _receiverMethod(method) + { + } + + FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): + AbstractPriorityDelegate(delegate._pTarget, delegate._priority), + _receiverMethod(delegate._receiverMethod) + { + } + + FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) + { + if (&delegate != this) + { + this->_pTarget = delegate._pTarget; + this->_receiverMethod = delegate._receiverMethod; + this->_priority = delegate._priority; + } + return *this; + } + + ~FunctionPriorityDelegate() + { + } + + bool notify(const void* sender, TArgs& arguments) + { + (*_receiverMethod)(sender, arguments); + return true; // per default the delegate never expires + } + + AbstractPriorityDelegate* clone() const + { + return new FunctionPriorityDelegate(*this); + } + +protected: + NotifyMethod _receiverMethod; + +private: + FunctionPriorityDelegate(); +}; + + +template +class FunctionPriorityDelegate: public AbstractPriorityDelegate +{ +public: + typedef void (*NotifyMethod)(void*, TArgs&); + + FunctionPriorityDelegate(NotifyMethod method, int prio): + AbstractPriorityDelegate(*reinterpret_cast(&method), prio), + _receiverMethod(method) + { + } + + FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): + AbstractPriorityDelegate(delegate._pTarget, delegate._priority), + _receiverMethod(delegate._receiverMethod) + { + } + + FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) + { + if (&delegate != this) + { + this->_pTarget = delegate._pTarget; + this->_receiverMethod = delegate._receiverMethod; + this->_priority = delegate._priority; + } + return *this; + } + + ~FunctionPriorityDelegate() + { + } + + bool notify(const void* sender, TArgs& arguments) + { + (*_receiverMethod)(const_cast(sender), arguments); + return true; // per default the delegate never expires + } + + AbstractPriorityDelegate* clone() const + { + return new FunctionPriorityDelegate(*this); + } + +protected: + NotifyMethod _receiverMethod; + +private: + FunctionPriorityDelegate(); +}; + + + +template +class FunctionPriorityDelegate: public AbstractPriorityDelegate +{ +public: + typedef void (*NotifyMethod)(TArgs&); + + FunctionPriorityDelegate(NotifyMethod method, int prio): + AbstractPriorityDelegate(*reinterpret_cast(&method), prio), + _receiverMethod(method) + { + } + + FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): + AbstractPriorityDelegate(delegate._pTarget, delegate._priority), + _receiverMethod(delegate._receiverMethod) + { + } + + FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) + { + if (&delegate != this) + { + this->_pTarget = delegate._pTarget; + this->_receiverMethod = delegate._receiverMethod; + this->_priority = delegate._priority; + } + return *this; + } + + ~FunctionPriorityDelegate() + { + } + + bool notify(const void* sender, TArgs& arguments) + { + (*_receiverMethod)(arguments); + return true; // per default the delegate never expires + } + + AbstractPriorityDelegate* clone() const + { + return new FunctionPriorityDelegate(*this); + } + +protected: + NotifyMethod _receiverMethod; + +private: + FunctionPriorityDelegate(); +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/Hash.h b/Foundation/include/Poco/Hash.h index 0f59f8849..099946c10 100644 --- a/Foundation/include/Poco/Hash.h +++ b/Foundation/include/Poco/Hash.h @@ -1,127 +1,127 @@ -// -// Hash.h -// -// $Id: //poco/svn/Foundation/include/Poco/Hash.h#2 $ -// -// Library: Foundation -// Package: Hashing -// Module: Hash -// -// Definition of the Hash class. -// -// Copyright (c) 2006, 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_Hash_INCLUDED -#define Foundation_Hash_INCLUDED - - -#include "Poco/Foundation.h" -#include - - -namespace Poco { - - -template -struct Hash - /// A generic hash function. -{ - std::size_t operator () (T value) const - /// Returns the hash for the given value. - { - return hash(value); - } -}; - - -std::size_t Foundation_API hash(Int8 n); -std::size_t Foundation_API hash(UInt8 n); -std::size_t Foundation_API hash(Int16 n); -std::size_t Foundation_API hash(UInt16 n); -std::size_t Foundation_API hash(Int32 n); -std::size_t Foundation_API hash(UInt32 n); -std::size_t Foundation_API hash(Int64 n); -std::size_t Foundation_API hash(UInt64 n); -std::size_t Foundation_API hash(const std::string& str); - - -// -// inlines -// -inline std::size_t hash(Int8 n) -{ - return static_cast(n)*2654435761U; -} - - -inline std::size_t hash(UInt8 n) -{ - return static_cast(n)*2654435761U; -} - - -inline std::size_t hash(Int16 n) -{ - return static_cast(n)*2654435761U; -} - - -inline std::size_t hash(UInt16 n) -{ - return static_cast(n)*2654435761U; -} - - -inline std::size_t hash(Int32 n) -{ - return static_cast(n)*2654435761U; -} - - -inline std::size_t hash(UInt32 n) -{ - return static_cast(n)*2654435761U; -} - - -inline std::size_t hash(Int64 n) -{ - return static_cast(n)*2654435761U; -} - - -inline std::size_t hash(UInt64 n) -{ - return static_cast(n)*2654435761U; -} - - -} // namespace Poco - - -#endif // Foundation_Hash_INCLUDED +// +// Hash.h +// +// $Id: //poco/svn/Foundation/include/Poco/Hash.h#2 $ +// +// Library: Foundation +// Package: Hashing +// Module: Hash +// +// Definition of the Hash class. +// +// Copyright (c) 2006, 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_Hash_INCLUDED +#define Foundation_Hash_INCLUDED + + +#include "Poco/Foundation.h" +#include + + +namespace Poco { + + +template +struct Hash + /// A generic hash function. +{ + std::size_t operator () (T value) const + /// Returns the hash for the given value. + { + return hash(value); + } +}; + + +std::size_t Foundation_API hash(Int8 n); +std::size_t Foundation_API hash(UInt8 n); +std::size_t Foundation_API hash(Int16 n); +std::size_t Foundation_API hash(UInt16 n); +std::size_t Foundation_API hash(Int32 n); +std::size_t Foundation_API hash(UInt32 n); +std::size_t Foundation_API hash(Int64 n); +std::size_t Foundation_API hash(UInt64 n); +std::size_t Foundation_API hash(const std::string& str); + + +// +// inlines +// +inline std::size_t hash(Int8 n) +{ + return static_cast(n)*2654435761U; +} + + +inline std::size_t hash(UInt8 n) +{ + return static_cast(n)*2654435761U; +} + + +inline std::size_t hash(Int16 n) +{ + return static_cast(n)*2654435761U; +} + + +inline std::size_t hash(UInt16 n) +{ + return static_cast(n)*2654435761U; +} + + +inline std::size_t hash(Int32 n) +{ + return static_cast(n)*2654435761U; +} + + +inline std::size_t hash(UInt32 n) +{ + return static_cast(n)*2654435761U; +} + + +inline std::size_t hash(Int64 n) +{ + return static_cast(n)*2654435761U; +} + + +inline std::size_t hash(UInt64 n) +{ + return static_cast(n)*2654435761U; +} + + +} // namespace Poco + + +#endif // Foundation_Hash_INCLUDED diff --git a/Foundation/include/Poco/HashMap.h b/Foundation/include/Poco/HashMap.h index 124a0b094..d72669038 100644 --- a/Foundation/include/Poco/HashMap.h +++ b/Foundation/include/Poco/HashMap.h @@ -1,244 +1,244 @@ -// -// HashMap.h -// -// $Id: //poco/svn/Foundation/include/Poco/HashMap.h#2 $ -// -// Library: Foundation -// Package: Hashing -// Module: HashMap -// -// Definition of the HashMap class. -// -// Copyright (c) 2006, 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_HashMap_INCLUDED -#define Foundation_HashMap_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/LinearHashTable.h" -#include "Poco/Exception.h" -#include - - -namespace Poco { - - -template -struct HashMapEntry - /// This class template is used internally by HashMap. -{ - Key first; - Value second; - - HashMapEntry(): - first(), - second() - { - } - - HashMapEntry(const Key& key): - first(key), - second() - { - } - - HashMapEntry(const Key& key, const Value& value): - first(key), - second(value) - { - } - - bool operator == (const HashMapEntry& entry) const - { - return first == entry.first; - } - - bool operator != (const HashMapEntry& entry) const - { - return first != entry.first; - } -}; - - -template -struct HashMapEntryHash - /// This class template is used internally by HashMap. -{ - std::size_t operator () (const HME& entry) const - { - return _func(entry.first); - } - -private: - KeyHashFunc _func; -}; - - -template > -class HashMap - /// This class implements a map using a LinearHashTable. - /// - /// A HashMap can be used just like a std::map. -{ -public: - typedef Key KeyType; - typedef Mapped MappedType; - typedef Mapped& Reference; - typedef const Mapped& ConstReference; - typedef Mapped* Pointer; - typedef const Mapped* ConstPointer; - - typedef HashMapEntry ValueType; - typedef std::pair PairType; - - typedef HashMapEntryHash HashType; - typedef LinearHashTable HashTable; - - typedef typename HashTable::Iterator Iterator; - typedef typename HashTable::ConstIterator ConstIterator; - - HashMap() - /// Creates an empty HashMap. - { - } - - HashMap(std::size_t initialReserve): - _table(initialReserve) - /// Creates the HashMap with room for initialReserve entries. - { - } - - HashMap& operator = (const HashMap& map) - /// Assigns another HashMap. - { - HashMap tmp(map); - swap(tmp); - return *this; - } - - void swap(HashMap& map) - /// Swaps the HashMap with another one. - { - _table.swap(map._table); - } - - ConstIterator begin() const - { - return _table.begin(); - } - - ConstIterator end() const - { - return _table.end(); - } - - Iterator begin() - { - return _table.begin(); - } - - Iterator end() - { - return _table.end(); - } - - ConstIterator find(const KeyType& key) const - { - ValueType value(key); - return _table.find(value); - } - - Iterator find(const KeyType& key) - { - ValueType value(key); - return _table.find(value); - } - - std::pair insert(const PairType& pair) - { - ValueType value(pair.first, pair.second); - return _table.insert(value); - } - - std::pair insert(const ValueType& value) - { - return _table.insert(value); - } - - void erase(Iterator it) - { - _table.erase(it); - } - - void erase(const KeyType& key) - { - Iterator it = find(key); - _table.erase(it); - } - - void clear() - { - _table.clear(); - } - - std::size_t size() const - { - return _table.size(); - } - - bool empty() const - { - return _table.empty(); - } - - ConstReference operator [] (const KeyType& key) const - { - ConstIterator it = _table.find(key); - if (it != _table.end()) - return it->second; - else - throw NotFoundException(); - } - - Reference operator [] (const KeyType& key) - { - ValueType value(key); - std::pair res = _table.insert(value); - return res.first->second; - } - -private: - HashTable _table; -}; - - -} // namespace Poco - - -#endif // Foundation_HashMap_INCLUDED +// +// HashMap.h +// +// $Id: //poco/svn/Foundation/include/Poco/HashMap.h#2 $ +// +// Library: Foundation +// Package: Hashing +// Module: HashMap +// +// Definition of the HashMap class. +// +// Copyright (c) 2006, 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_HashMap_INCLUDED +#define Foundation_HashMap_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/LinearHashTable.h" +#include "Poco/Exception.h" +#include + + +namespace Poco { + + +template +struct HashMapEntry + /// This class template is used internally by HashMap. +{ + Key first; + Value second; + + HashMapEntry(): + first(), + second() + { + } + + HashMapEntry(const Key& key): + first(key), + second() + { + } + + HashMapEntry(const Key& key, const Value& value): + first(key), + second(value) + { + } + + bool operator == (const HashMapEntry& entry) const + { + return first == entry.first; + } + + bool operator != (const HashMapEntry& entry) const + { + return first != entry.first; + } +}; + + +template +struct HashMapEntryHash + /// This class template is used internally by HashMap. +{ + std::size_t operator () (const HME& entry) const + { + return _func(entry.first); + } + +private: + KeyHashFunc _func; +}; + + +template > +class HashMap + /// This class implements a map using a LinearHashTable. + /// + /// A HashMap can be used just like a std::map. +{ +public: + typedef Key KeyType; + typedef Mapped MappedType; + typedef Mapped& Reference; + typedef const Mapped& ConstReference; + typedef Mapped* Pointer; + typedef const Mapped* ConstPointer; + + typedef HashMapEntry ValueType; + typedef std::pair PairType; + + typedef HashMapEntryHash HashType; + typedef LinearHashTable HashTable; + + typedef typename HashTable::Iterator Iterator; + typedef typename HashTable::ConstIterator ConstIterator; + + HashMap() + /// Creates an empty HashMap. + { + } + + HashMap(std::size_t initialReserve): + _table(initialReserve) + /// Creates the HashMap with room for initialReserve entries. + { + } + + HashMap& operator = (const HashMap& map) + /// Assigns another HashMap. + { + HashMap tmp(map); + swap(tmp); + return *this; + } + + void swap(HashMap& map) + /// Swaps the HashMap with another one. + { + _table.swap(map._table); + } + + ConstIterator begin() const + { + return _table.begin(); + } + + ConstIterator end() const + { + return _table.end(); + } + + Iterator begin() + { + return _table.begin(); + } + + Iterator end() + { + return _table.end(); + } + + ConstIterator find(const KeyType& key) const + { + ValueType value(key); + return _table.find(value); + } + + Iterator find(const KeyType& key) + { + ValueType value(key); + return _table.find(value); + } + + std::pair insert(const PairType& pair) + { + ValueType value(pair.first, pair.second); + return _table.insert(value); + } + + std::pair insert(const ValueType& value) + { + return _table.insert(value); + } + + void erase(Iterator it) + { + _table.erase(it); + } + + void erase(const KeyType& key) + { + Iterator it = find(key); + _table.erase(it); + } + + void clear() + { + _table.clear(); + } + + std::size_t size() const + { + return _table.size(); + } + + bool empty() const + { + return _table.empty(); + } + + ConstReference operator [] (const KeyType& key) const + { + ConstIterator it = _table.find(key); + if (it != _table.end()) + return it->second; + else + throw NotFoundException(); + } + + Reference operator [] (const KeyType& key) + { + ValueType value(key); + std::pair res = _table.insert(value); + return res.first->second; + } + +private: + HashTable _table; +}; + + +} // namespace Poco + + +#endif // Foundation_HashMap_INCLUDED diff --git a/Foundation/include/Poco/HashSet.h b/Foundation/include/Poco/HashSet.h index 5c627e7ea..d77f18523 100644 --- a/Foundation/include/Poco/HashSet.h +++ b/Foundation/include/Poco/HashSet.h @@ -1,199 +1,199 @@ -// -// HashSet.h -// -// $Id: //poco/svn/Foundation/include/Poco/HashSet.h#2 $ -// -// Library: Foundation -// Package: Hashing -// Module: HashSet -// -// Definition of the HashSet class. -// -// Copyright (c) 2006, 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_HashSet_INCLUDED -#define Foundation_HashSet_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/LinearHashTable.h" - - -namespace Poco { - - -template > -class HashSet - /// This class implements a set using a LinearHashTable. - /// - /// A HashSet can be used just like a std::set. -{ -public: - typedef Value ValueType; - typedef Value& Reference; - typedef const Value& ConstReference; - typedef Value* Pointer; - typedef const Value* ConstPointer; - typedef HashFunc Hash; - - typedef LinearHashTable HashTable; - - typedef typename HashTable::Iterator Iterator; - typedef typename HashTable::ConstIterator ConstIterator; - - HashSet() - /// Creates an empty HashSet. - { - } - - HashSet(std::size_t initialReserve): - _table(initialReserve) - /// Creates the HashSet, using the given initialReserve. - { - } - - HashSet(const HashSet& set): - _table(set._table) - /// Creates the HashSet by copying another one. - { - } - - ~HashSet() - /// Destroys the HashSet. - { - } - - HashSet& operator = (const HashSet& table) - /// Assigns another HashSet. - { - HashSet tmp(table); - swap(tmp); - return *this; - } - - void swap(HashSet& set) - /// Swaps the HashSet with another one. - { - _table.swap(set._table); - } - - ConstIterator begin() const - /// Returns an iterator pointing to the first entry, if one exists. - { - return _table.begin(); - } - - ConstIterator end() const - /// Returns an iterator pointing to the end of the table. - { - return _table.end(); - } - - Iterator begin() - /// Returns an iterator pointing to the first entry, if one exists. - { - return _table.begin(); - } - - Iterator end() - /// Returns an iterator pointing to the end of the table. - { - return _table.end(); - } - - ConstIterator find(const ValueType& value) const - /// Finds an entry in the table. - { - return _table.find(value); - } - - Iterator find(const ValueType& value) - /// Finds an entry in the table. - { - return _table.find(value); - } - - std::size_t count(const ValueType& value) const - /// Returns the number of elements with the given - /// value, with is either 1 or 0. - { - return _table.count(value); - } - - std::pair insert(const ValueType& value) - /// Inserts an element into the set. - /// - /// If the element already exists in the set, - /// a pair(iterator, false) with iterator pointing to the - /// existing element is returned. - /// Otherwise, the element is inserted an a - /// pair(iterator, true) with iterator - /// pointing to the new element is returned. - { - return _table.insert(value); - } - - void erase(Iterator it) - /// Erases the element pointed to by it. - { - _table.erase(it); - } - - void erase(const ValueType& value) - /// Erases the element with the given value, if it exists. - { - _table.erase(value); - } - - void clear() - /// Erases all elements. - { - _table.clear(); - } - - std::size_t size() const - /// Returns the number of elements in the table. - { - return _table.size(); - } - - bool empty() const - /// Returns true iff the table is empty. - { - return _table.empty(); - } - -private: - HashTable _table; -}; - - -} // namespace Poco - - -#endif // Foundation_HashSet_INCLUDED +// +// HashSet.h +// +// $Id: //poco/svn/Foundation/include/Poco/HashSet.h#2 $ +// +// Library: Foundation +// Package: Hashing +// Module: HashSet +// +// Definition of the HashSet class. +// +// Copyright (c) 2006, 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_HashSet_INCLUDED +#define Foundation_HashSet_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/LinearHashTable.h" + + +namespace Poco { + + +template > +class HashSet + /// This class implements a set using a LinearHashTable. + /// + /// A HashSet can be used just like a std::set. +{ +public: + typedef Value ValueType; + typedef Value& Reference; + typedef const Value& ConstReference; + typedef Value* Pointer; + typedef const Value* ConstPointer; + typedef HashFunc Hash; + + typedef LinearHashTable HashTable; + + typedef typename HashTable::Iterator Iterator; + typedef typename HashTable::ConstIterator ConstIterator; + + HashSet() + /// Creates an empty HashSet. + { + } + + HashSet(std::size_t initialReserve): + _table(initialReserve) + /// Creates the HashSet, using the given initialReserve. + { + } + + HashSet(const HashSet& set): + _table(set._table) + /// Creates the HashSet by copying another one. + { + } + + ~HashSet() + /// Destroys the HashSet. + { + } + + HashSet& operator = (const HashSet& table) + /// Assigns another HashSet. + { + HashSet tmp(table); + swap(tmp); + return *this; + } + + void swap(HashSet& set) + /// Swaps the HashSet with another one. + { + _table.swap(set._table); + } + + ConstIterator begin() const + /// Returns an iterator pointing to the first entry, if one exists. + { + return _table.begin(); + } + + ConstIterator end() const + /// Returns an iterator pointing to the end of the table. + { + return _table.end(); + } + + Iterator begin() + /// Returns an iterator pointing to the first entry, if one exists. + { + return _table.begin(); + } + + Iterator end() + /// Returns an iterator pointing to the end of the table. + { + return _table.end(); + } + + ConstIterator find(const ValueType& value) const + /// Finds an entry in the table. + { + return _table.find(value); + } + + Iterator find(const ValueType& value) + /// Finds an entry in the table. + { + return _table.find(value); + } + + std::size_t count(const ValueType& value) const + /// Returns the number of elements with the given + /// value, with is either 1 or 0. + { + return _table.count(value); + } + + std::pair insert(const ValueType& value) + /// Inserts an element into the set. + /// + /// If the element already exists in the set, + /// a pair(iterator, false) with iterator pointing to the + /// existing element is returned. + /// Otherwise, the element is inserted an a + /// pair(iterator, true) with iterator + /// pointing to the new element is returned. + { + return _table.insert(value); + } + + void erase(Iterator it) + /// Erases the element pointed to by it. + { + _table.erase(it); + } + + void erase(const ValueType& value) + /// Erases the element with the given value, if it exists. + { + _table.erase(value); + } + + void clear() + /// Erases all elements. + { + _table.clear(); + } + + std::size_t size() const + /// Returns the number of elements in the table. + { + return _table.size(); + } + + bool empty() const + /// Returns true iff the table is empty. + { + return _table.empty(); + } + +private: + HashTable _table; +}; + + +} // namespace Poco + + +#endif // Foundation_HashSet_INCLUDED diff --git a/Foundation/include/Poco/LinearHashTable.h b/Foundation/include/Poco/LinearHashTable.h index fa66b5908..859933401 100644 --- a/Foundation/include/Poco/LinearHashTable.h +++ b/Foundation/include/Poco/LinearHashTable.h @@ -1,492 +1,492 @@ -// -// LinearHashTable.h -// -// $Id: //poco/svn/Foundation/include/Poco/LinearHashTable.h#2 $ -// -// Library: Foundation -// Package: Hashing -// Module: LinearHashTable -// -// Definition of the LinearHashTable class. -// -// Copyright (c) 2006, 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_LinearHashTable_INCLUDED -#define Foundation_LinearHashTable_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/Hash.h" -#include -#include -#include -#include -#include - - -namespace Poco { - - -template > -class LinearHashTable - /// This class implements a linear hash table. - /// - /// In a linear hash table, the available address space - /// grows or shrinks dynamically. A linar hash table thus - /// supports any number of insertions or deletions without - /// lookup or insertion performance deterioration. - /// - /// Linear hashing was discovered by Witold Litwin in 1980 - /// and described in the paper LINEAR HASHING: A NEW TOOL FOR FILE AND TABLE ADDRESSING. - /// - /// For more information on linear hashing, see . - /// - /// The LinearHashTable is not thread safe. - /// - /// Value must support comparison for equality. - /// - /// Find, insert and delete operations are basically O(1) with regard - /// to the total number of elements in the table, and O(N) with regard - /// to the number of elements in the bucket where the element is stored. - /// On average, every bucket stores one element; the exact number depends - /// on the quality of the hash function. In most cases, the maximum number of - /// elements in a bucket should not exceed 3. -{ -public: - typedef Value ValueType; - typedef Value& Reference; - typedef const Value& ConstReference; - typedef Value* Pointer; - typedef const Value* ConstPointer; - typedef HashFunc Hash; - typedef std::vector Bucket; - typedef std::vector BucketVec; - typedef typename Bucket::iterator BucketIterator; - typedef typename BucketVec::iterator BucketVecIterator; - - class ConstIterator - { - public: - ConstIterator() - { - } - - ConstIterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt): - _vecIt(vecIt), - _endIt(endIt), - _buckIt(buckIt) - { - } - - ConstIterator(const ConstIterator& it): - _vecIt(it._vecIt), - _endIt(it._endIt), - _buckIt(it._buckIt) - { - } - - ConstIterator& operator = (const ConstIterator& it) - { - ConstIterator tmp(it); - swap(tmp); - return *this; - } - - void swap(ConstIterator& it) - { - using std::swap; - swap(_vecIt, it._vecIt); - swap(_endIt, it._endIt); - swap(_buckIt, it._buckIt); - } - - bool operator == (const ConstIterator& it) const - { - return _vecIt == it._vecIt && (_vecIt == _endIt || _buckIt == it._buckIt); - } - - bool operator != (const ConstIterator& 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; - } - - 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 *this->_buckIt; - } - - typename Bucket::value_type* operator -> () - { - return &*this->_buckIt; - } - - const typename Bucket::value_type* operator -> () const - { - return &*this->_buckIt; - } - - Iterator& operator ++ () // prefix - { - ConstIterator::operator ++ (); - return *this; - } - - Iterator operator ++ (int) // postfix - { - Iterator tmp(*this); - ++*this; - return tmp; - } - - friend class LinearHashTable; - }; - - LinearHashTable(std::size_t initialReserve = 64): - _split(0), - _front(1), - _size(0) - /// Creates the LinearHashTable, using the given initialReserve. - { - _buckets.reserve(calcSize(initialReserve)); - _buckets.push_back(Bucket()); - } - - LinearHashTable(const LinearHashTable& table): - _buckets(table._buckets), - _split(table._split), - _front(table._front), - _size(table._size) - /// Creates the LinearHashTable by copying another one. - { - } - - ~LinearHashTable() - /// Destroys the LinearHashTable. - { - } - - LinearHashTable& operator = (const LinearHashTable& table) - /// Assigns another LinearHashTable. - { - LinearHashTable tmp(table); - swap(tmp); - return *this; - } - - void swap(LinearHashTable& table) - /// Swaps the LinearHashTable with another one. - { - using std::swap; - swap(_buckets, table._buckets); - swap(_split, table._split); - swap(_front, table._front); - swap(_size, table._size); - } - - ConstIterator begin() const - /// Returns an iterator pointing to the first entry, if one exists. - { - BucketVecIterator it(_buckets.begin()); - BucketVecIterator end(_buckets.end()); - while (it != end && it->empty()) - { - ++it; - } - if (it == end) - return this->end(); - else - return ConstIterator(it, end, it->begin()); - } - - ConstIterator end() const - /// Returns an iterator pointing to the end of the table. - { - return ConstIterator(_buckets.end(), _buckets.end(), _buckets.front().end()); - } - - Iterator begin() - /// Returns an iterator pointing to the first entry, if one exists. - { - BucketVecIterator it(_buckets.begin()); - BucketVecIterator end(_buckets.end()); - while (it != end && it->empty()) - { - ++it; - } - if (it == end) - return this->end(); - else - return Iterator(it, end, it->begin()); - } - - Iterator end() - /// Returns an iterator pointing to the end of the table. - { - return Iterator(_buckets.end(), _buckets.end(), _buckets.front().end()); - } - - ConstIterator find(const Value& value) const - /// Finds an entry in the table. - { - std::size_t addr = bucketAddress(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 - return end(); - } - - Iterator find(const Value& value) - /// Finds an entry in the table. - { - std::size_t addr = bucketAddress(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 - return end(); - } - - std::size_t count(const Value& value) const - /// Returns the number of elements with the given - /// value, with is either 1 or 0. - { - return find(value) != end() ? 1 : 0; - } - - std::pair insert(const Value& value) - /// Inserts an element into the table. - /// - /// If the element already exists in the table, - /// a pair(iterator, false) with iterator pointing to the - /// existing element is returned. - /// Otherwise, the element is inserted an a - /// pair(iterator, true) with iterator - /// pointing to the new element is returned. - { - split(); - std::size_t addr = bucketAddress(value); - BucketVecIterator it(_buckets.begin() + addr); - BucketIterator buckIt(std::find(it->begin(), it->end(), value)); - if (buckIt == it->end()) - { - buckIt = it->insert(buckIt, value); - ++_size; - return std::make_pair(Iterator(it, _buckets.end(), buckIt), true); - } - else - { - return std::make_pair(Iterator(it, _buckets.end(), buckIt), false); - } - } - - void erase(Iterator it) - /// Erases the element pointed to by it. - { - if (it != end()) - { - it._vecIt->erase(it._buckIt); - --_size; - merge(); - } - } - - void erase(const Value& value) - /// Erases the element with the given value, if it exists. - { - Iterator it = find(value); - erase(it); - } - - void clear() - /// Erases all elements. - { - LinearHashTable empty; - swap(empty); - } - - std::size_t size() const - /// Returns the number of elements in the table. - { - return _size; - } - - bool empty() const - /// Returns true iff the table is empty. - { - return _size == 0; - } - -protected: - std::size_t bucketAddress(const Value& value) const - { - std::size_t n = _hash(value); - if (n % _front >= _split) - return n % _front; - else - return n % (2*_front); - } - - void split() - { - if (_split == _front) - { - _split = 0; - _front *= 2; - _buckets.reserve(_front*2); - } - Bucket tmp; - _buckets.push_back(tmp); - _buckets[_split].swap(tmp); - ++_split; - for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it) - { - using std::swap; - std::size_t addr = bucketAddress(*it); - _buckets[addr].push_back(Value()); - swap(*it, _buckets[addr].back()); - } - } - - void merge() - { - if (_split == 0) - { - _front /= 2; - _split = _front; - } - --_split; - Bucket tmp; - tmp.swap(_buckets.back()); - _buckets.pop_back(); - for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it) - { - using std::swap; - std::size_t addr = bucketAddress(*it); - _buckets[addr].push_back(Value()); - swap(*it, _buckets[addr].back()); - } - } - - static std::size_t calcSize(std::size_t initialSize) - { - std::size_t size = 32; - while (size < initialSize) size *= 2; - return size; - } - -private: - // 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; - HashFunc _hash; -}; - - -} // namespace Poco - - -#endif // Foundation_LinearHashTable_INCLUDED +// +// LinearHashTable.h +// +// $Id: //poco/svn/Foundation/include/Poco/LinearHashTable.h#2 $ +// +// Library: Foundation +// Package: Hashing +// Module: LinearHashTable +// +// Definition of the LinearHashTable class. +// +// Copyright (c) 2006, 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_LinearHashTable_INCLUDED +#define Foundation_LinearHashTable_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Hash.h" +#include +#include +#include +#include +#include + + +namespace Poco { + + +template > +class LinearHashTable + /// This class implements a linear hash table. + /// + /// In a linear hash table, the available address space + /// grows or shrinks dynamically. A linar hash table thus + /// supports any number of insertions or deletions without + /// lookup or insertion performance deterioration. + /// + /// Linear hashing was discovered by Witold Litwin in 1980 + /// and described in the paper LINEAR HASHING: A NEW TOOL FOR FILE AND TABLE ADDRESSING. + /// + /// For more information on linear hashing, see . + /// + /// The LinearHashTable is not thread safe. + /// + /// Value must support comparison for equality. + /// + /// Find, insert and delete operations are basically O(1) with regard + /// to the total number of elements in the table, and O(N) with regard + /// to the number of elements in the bucket where the element is stored. + /// On average, every bucket stores one element; the exact number depends + /// on the quality of the hash function. In most cases, the maximum number of + /// elements in a bucket should not exceed 3. +{ +public: + typedef Value ValueType; + typedef Value& Reference; + typedef const Value& ConstReference; + typedef Value* Pointer; + typedef const Value* ConstPointer; + typedef HashFunc Hash; + typedef std::vector Bucket; + typedef std::vector BucketVec; + typedef typename Bucket::iterator BucketIterator; + typedef typename BucketVec::iterator BucketVecIterator; + + class ConstIterator + { + public: + ConstIterator() + { + } + + ConstIterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt): + _vecIt(vecIt), + _endIt(endIt), + _buckIt(buckIt) + { + } + + ConstIterator(const ConstIterator& it): + _vecIt(it._vecIt), + _endIt(it._endIt), + _buckIt(it._buckIt) + { + } + + ConstIterator& operator = (const ConstIterator& it) + { + ConstIterator tmp(it); + swap(tmp); + return *this; + } + + void swap(ConstIterator& it) + { + using std::swap; + swap(_vecIt, it._vecIt); + swap(_endIt, it._endIt); + swap(_buckIt, it._buckIt); + } + + bool operator == (const ConstIterator& it) const + { + return _vecIt == it._vecIt && (_vecIt == _endIt || _buckIt == it._buckIt); + } + + bool operator != (const ConstIterator& 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; + } + + 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 *this->_buckIt; + } + + typename Bucket::value_type* operator -> () + { + return &*this->_buckIt; + } + + const typename Bucket::value_type* operator -> () const + { + return &*this->_buckIt; + } + + Iterator& operator ++ () // prefix + { + ConstIterator::operator ++ (); + return *this; + } + + Iterator operator ++ (int) // postfix + { + Iterator tmp(*this); + ++*this; + return tmp; + } + + friend class LinearHashTable; + }; + + LinearHashTable(std::size_t initialReserve = 64): + _split(0), + _front(1), + _size(0) + /// Creates the LinearHashTable, using the given initialReserve. + { + _buckets.reserve(calcSize(initialReserve)); + _buckets.push_back(Bucket()); + } + + LinearHashTable(const LinearHashTable& table): + _buckets(table._buckets), + _split(table._split), + _front(table._front), + _size(table._size) + /// Creates the LinearHashTable by copying another one. + { + } + + ~LinearHashTable() + /// Destroys the LinearHashTable. + { + } + + LinearHashTable& operator = (const LinearHashTable& table) + /// Assigns another LinearHashTable. + { + LinearHashTable tmp(table); + swap(tmp); + return *this; + } + + void swap(LinearHashTable& table) + /// Swaps the LinearHashTable with another one. + { + using std::swap; + swap(_buckets, table._buckets); + swap(_split, table._split); + swap(_front, table._front); + swap(_size, table._size); + } + + ConstIterator begin() const + /// Returns an iterator pointing to the first entry, if one exists. + { + BucketVecIterator it(_buckets.begin()); + BucketVecIterator end(_buckets.end()); + while (it != end && it->empty()) + { + ++it; + } + if (it == end) + return this->end(); + else + return ConstIterator(it, end, it->begin()); + } + + ConstIterator end() const + /// Returns an iterator pointing to the end of the table. + { + return ConstIterator(_buckets.end(), _buckets.end(), _buckets.front().end()); + } + + Iterator begin() + /// Returns an iterator pointing to the first entry, if one exists. + { + BucketVecIterator it(_buckets.begin()); + BucketVecIterator end(_buckets.end()); + while (it != end && it->empty()) + { + ++it; + } + if (it == end) + return this->end(); + else + return Iterator(it, end, it->begin()); + } + + Iterator end() + /// Returns an iterator pointing to the end of the table. + { + return Iterator(_buckets.end(), _buckets.end(), _buckets.front().end()); + } + + ConstIterator find(const Value& value) const + /// Finds an entry in the table. + { + std::size_t addr = bucketAddress(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 + return end(); + } + + Iterator find(const Value& value) + /// Finds an entry in the table. + { + std::size_t addr = bucketAddress(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 + return end(); + } + + std::size_t count(const Value& value) const + /// Returns the number of elements with the given + /// value, with is either 1 or 0. + { + return find(value) != end() ? 1 : 0; + } + + std::pair insert(const Value& value) + /// Inserts an element into the table. + /// + /// If the element already exists in the table, + /// a pair(iterator, false) with iterator pointing to the + /// existing element is returned. + /// Otherwise, the element is inserted an a + /// pair(iterator, true) with iterator + /// pointing to the new element is returned. + { + split(); + std::size_t addr = bucketAddress(value); + BucketVecIterator it(_buckets.begin() + addr); + BucketIterator buckIt(std::find(it->begin(), it->end(), value)); + if (buckIt == it->end()) + { + buckIt = it->insert(buckIt, value); + ++_size; + return std::make_pair(Iterator(it, _buckets.end(), buckIt), true); + } + else + { + return std::make_pair(Iterator(it, _buckets.end(), buckIt), false); + } + } + + void erase(Iterator it) + /// Erases the element pointed to by it. + { + if (it != end()) + { + it._vecIt->erase(it._buckIt); + --_size; + merge(); + } + } + + void erase(const Value& value) + /// Erases the element with the given value, if it exists. + { + Iterator it = find(value); + erase(it); + } + + void clear() + /// Erases all elements. + { + LinearHashTable empty; + swap(empty); + } + + std::size_t size() const + /// Returns the number of elements in the table. + { + return _size; + } + + bool empty() const + /// Returns true iff the table is empty. + { + return _size == 0; + } + +protected: + std::size_t bucketAddress(const Value& value) const + { + std::size_t n = _hash(value); + if (n % _front >= _split) + return n % _front; + else + return n % (2*_front); + } + + void split() + { + if (_split == _front) + { + _split = 0; + _front *= 2; + _buckets.reserve(_front*2); + } + Bucket tmp; + _buckets.push_back(tmp); + _buckets[_split].swap(tmp); + ++_split; + for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it) + { + using std::swap; + std::size_t addr = bucketAddress(*it); + _buckets[addr].push_back(Value()); + swap(*it, _buckets[addr].back()); + } + } + + void merge() + { + if (_split == 0) + { + _front /= 2; + _split = _front; + } + --_split; + Bucket tmp; + tmp.swap(_buckets.back()); + _buckets.pop_back(); + for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it) + { + using std::swap; + std::size_t addr = bucketAddress(*it); + _buckets[addr].push_back(Value()); + swap(*it, _buckets[addr].back()); + } + } + + static std::size_t calcSize(std::size_t initialSize) + { + std::size_t size = 32; + while (size < initialSize) size *= 2; + return size; + } + +private: + // 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; + HashFunc _hash; +}; + + +} // namespace Poco + + +#endif // Foundation_LinearHashTable_INCLUDED diff --git a/Foundation/include/Poco/MetaProgramming.h b/Foundation/include/Poco/MetaProgramming.h index ac19ed056..1a9a41ae0 100644 --- a/Foundation/include/Poco/MetaProgramming.h +++ b/Foundation/include/Poco/MetaProgramming.h @@ -1,157 +1,157 @@ -// -// TypeChecks.h -// -// $Id: //poco/svn/Foundation/include/Poco/MetaProgramming.h#2 $ -// -// Library: Foundation -// Package: Core -// Module: MetaProgramming -// -// Common definitions useful for Meta Template Programming -// -// Copyright (c) 2006, 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_TypeChecks_INCLUDED -#define Foundation_TypeChecks_INCLUDED - - -#include "Poco/Foundation.h" - - -namespace Poco { - - -template -struct IsReference - ///Use this struct to determine if a template type is a reference -{ - enum - { - VALUE = 0 - }; -}; - - -template -struct IsReference -{ - enum - { - VALUE = 1 - }; -}; - - -template -struct IsReference -{ - enum - { - VALUE = 1 - }; -}; - - - -template -struct IsConst - ///Use this struct to determine if a template type is a const type -{ - enum - { - VALUE = 0 - }; -}; - - -template -struct IsConst -{ - enum - { - VALUE = 1 - }; -}; - - -template -struct IsConst -{ - enum - { - VALUE = 1 - }; -}; - - -template -struct TypeWrapper - /// Use the type wrapper if you want to dedecouple constness and references from template types -{ - typedef T TYPE; - typedef const T CONSTTYPE; - typedef T& REFTYPE; - typedef const T& CONSTREFTYPE; -}; - - -template -struct TypeWrapper -{ - typedef T TYPE; - typedef const T CONSTTYPE; - typedef T& REFTYPE; - typedef const T& CONSTREFTYPE; -}; - - -template -struct TypeWrapper -{ - typedef T TYPE; - typedef const T CONSTTYPE; - typedef T& REFTYPE; - typedef const T& CONSTREFTYPE; -}; - - -template -struct TypeWrapper -{ - typedef T TYPE; - typedef const T CONSTTYPE; - typedef T& REFTYPE; - typedef const T& CONSTREFTYPE; -}; - - - -} // namespace Poco - - -#endif +// +// TypeChecks.h +// +// $Id: //poco/svn/Foundation/include/Poco/MetaProgramming.h#2 $ +// +// Library: Foundation +// Package: Core +// Module: MetaProgramming +// +// Common definitions useful for Meta Template Programming +// +// Copyright (c) 2006, 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_TypeChecks_INCLUDED +#define Foundation_TypeChecks_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +template +struct IsReference + ///Use this struct to determine if a template type is a reference +{ + enum + { + VALUE = 0 + }; +}; + + +template +struct IsReference +{ + enum + { + VALUE = 1 + }; +}; + + +template +struct IsReference +{ + enum + { + VALUE = 1 + }; +}; + + + +template +struct IsConst + ///Use this struct to determine if a template type is a const type +{ + enum + { + VALUE = 0 + }; +}; + + +template +struct IsConst +{ + enum + { + VALUE = 1 + }; +}; + + +template +struct IsConst +{ + enum + { + VALUE = 1 + }; +}; + + +template +struct TypeWrapper + /// Use the type wrapper if you want to dedecouple constness and references from template types +{ + typedef T TYPE; + typedef const T CONSTTYPE; + typedef T& REFTYPE; + typedef const T& CONSTREFTYPE; +}; + + +template +struct TypeWrapper +{ + typedef T TYPE; + typedef const T CONSTTYPE; + typedef T& REFTYPE; + typedef const T& CONSTREFTYPE; +}; + + +template +struct TypeWrapper +{ + typedef T TYPE; + typedef const T CONSTTYPE; + typedef T& REFTYPE; + typedef const T& CONSTREFTYPE; +}; + + +template +struct TypeWrapper +{ + typedef T TYPE; + typedef const T CONSTTYPE; + typedef T& REFTYPE; + typedef const T& CONSTREFTYPE; +}; + + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/NamedTuple.h b/Foundation/include/Poco/NamedTuple.h index 3bf5bee6f..9f53c8a6b 100644 --- a/Foundation/include/Poco/NamedTuple.h +++ b/Foundation/include/Poco/NamedTuple.h @@ -1,4484 +1,4484 @@ -// -// NamedTuple.h -// -// $Id: //poco/svn/Foundation/include/Poco/NamedTuple.h#2 $ -// -// Library: Foundation -// Package: Core -// Module: NamedTuple -// -// Definition of the NamedTuple 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_NamedTuple_INCLUDED -#define Foundation_NamedTuple_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/Tuple.h" -#include "Poco/TypeList.h" -#include "Poco/DynamicAny.h" -#include "Poco/SharedPtr.h" -#include "Poco/Format.h" - - -namespace Poco { - - -template -struct NamedTuple: public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), - typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), - typename TypeWrapper::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), - typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), - typename TypeWrapper::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - const std::string& n12 = "M", - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - const std::string& n13 = "N", - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - const std::string& n14 = "O", - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - const std::string& n15 = "P", - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - const std::string& n16 = "Q", - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - const std::string& n17 = "R", - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), - const std::string& n18 = "S", - typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), - const std::string& n19 = "T", - typename TypeWrapper::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - case 12: return TupleType::template get<12>(); - case 13: return TupleType::template get<13>(); - case 14: return TupleType::template get<14>(); - case 15: return TupleType::template get<15>(); - case 16: return TupleType::template get<16>(); - case 17: return TupleType::template get<17>(); - case 18: return TupleType::template get<18>(); - case 19: return TupleType::template get<19>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L", - const std::string& n12 = "M", - const std::string& n13 = "N", - const std::string& n14 = "O", - const std::string& n15 = "P", - const std::string& n16 = "Q", - const std::string& n17 = "R", - const std::string& n18 = "S", - const std::string& n19 = "T") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - _pNames->push_back(n12); - _pNames->push_back(n13); - _pNames->push_back(n14); - _pNames->push_back(n15); - _pNames->push_back(n16); - _pNames->push_back(n17); - _pNames->push_back(n18); - _pNames->push_back(n19); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), - typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), - typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - const std::string& n12 = "M", - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - const std::string& n13 = "N", - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - const std::string& n14 = "O", - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - const std::string& n15 = "P", - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - const std::string& n16 = "Q", - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - const std::string& n17 = "R", - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), - const std::string& n18 = "S", - typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - case 12: return TupleType::template get<12>(); - case 13: return TupleType::template get<13>(); - case 14: return TupleType::template get<14>(); - case 15: return TupleType::template get<15>(); - case 16: return TupleType::template get<16>(); - case 17: return TupleType::template get<17>(); - case 18: return TupleType::template get<18>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L", - const std::string& n12 = "M", - const std::string& n13 = "N", - const std::string& n14 = "O", - const std::string& n15 = "P", - const std::string& n16 = "Q", - const std::string& n17 = "R", - const std::string& n18 = "S") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - _pNames->push_back(n12); - _pNames->push_back(n13); - _pNames->push_back(n14); - _pNames->push_back(n15); - _pNames->push_back(n16); - _pNames->push_back(n17); - _pNames->push_back(n18); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - const std::string& n12 = "M", - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - const std::string& n13 = "N", - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - const std::string& n14 = "O", - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - const std::string& n15 = "P", - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - const std::string& n16 = "Q", - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - const std::string& n17 = "R", - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - case 12: return TupleType::template get<12>(); - case 13: return TupleType::template get<13>(); - case 14: return TupleType::template get<14>(); - case 15: return TupleType::template get<15>(); - case 16: return TupleType::template get<16>(); - case 17: return TupleType::template get<17>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L", - const std::string& n12 = "M", - const std::string& n13 = "N", - const std::string& n14 = "O", - const std::string& n15 = "P", - const std::string& n16 = "Q", - const std::string& n17 = "R") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - _pNames->push_back(n12); - _pNames->push_back(n13); - _pNames->push_back(n14); - _pNames->push_back(n15); - _pNames->push_back(n16); - _pNames->push_back(n17); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - const std::string& n12 = "M", - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - const std::string& n13 = "N", - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - const std::string& n14 = "O", - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - const std::string& n15 = "P", - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - const std::string& n16 = "Q", - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - case 12: return TupleType::template get<12>(); - case 13: return TupleType::template get<13>(); - case 14: return TupleType::template get<14>(); - case 15: return TupleType::template get<15>(); - case 16: return TupleType::template get<16>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L", - const std::string& n12 = "M", - const std::string& n13 = "N", - const std::string& n14 = "O", - const std::string& n15 = "P", - const std::string& n16 = "Q") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - _pNames->push_back(n12); - _pNames->push_back(n13); - _pNames->push_back(n14); - _pNames->push_back(n15); - _pNames->push_back(n16); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - const std::string& n12 = "M", - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - const std::string& n13 = "N", - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - const std::string& n14 = "O", - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - const std::string& n15 = "P", - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - case 12: return TupleType::template get<12>(); - case 13: return TupleType::template get<13>(); - case 14: return TupleType::template get<14>(); - case 15: return TupleType::template get<15>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L", - const std::string& n12 = "M", - const std::string& n13 = "N", - const std::string& n14 = "O", - const std::string& n15 = "P") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - _pNames->push_back(n12); - _pNames->push_back(n13); - _pNames->push_back(n14); - _pNames->push_back(n15); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - const std::string& n12 = "M", - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - const std::string& n13 = "N", - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - const std::string& n14 = "O", - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - case 12: return TupleType::template get<12>(); - case 13: return TupleType::template get<13>(); - case 14: return TupleType::template get<14>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L", - const std::string& n12 = "M", - const std::string& n13 = "N", - const std::string& n14 = "O") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - _pNames->push_back(n12); - _pNames->push_back(n13); - _pNames->push_back(n14); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - const std::string& n12 = "M", - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - const std::string& n13 = "N", - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - case 12: return TupleType::template get<12>(); - case 13: return TupleType::template get<13>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L", - const std::string& n12 = "M", - const std::string& n13 = "N") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - _pNames->push_back(n12); - _pNames->push_back(n13); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - const std::string& n12 = "M", - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12), _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - case 12: return TupleType::template get<12>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L", - const std::string& n12 = "M") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - _pNames->push_back(n12); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - const std::string& n11 = "L", - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - case 11: return TupleType::template get<11>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K", - const std::string& n11 = "L") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - _pNames->push_back(n11); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - const std::string& n10 = "K", - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10), _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - case 10: return TupleType::template get<10>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J", - const std::string& n10 = "K") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - _pNames->push_back(n10); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - const std::string& n9 = "J", - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - case 9: return TupleType::template get<9>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I", - const std::string& n9 = "J") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - _pNames->push_back(n9); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - const std::string& n8 = "I", - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7,n8); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - case 8: return TupleType::template get<8>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H", - const std::string& n8 = "I") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - _pNames->push_back(n8); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - const std::string& n7 = "H", - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): - TupleType(t0,t1,t2,t3,t4,t5,t6,t7), - _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6,n7); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - case 7: return TupleType::template get<7>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G", - const std::string& n7 = "H") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - _pNames->push_back(n7); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): - TupleType(t0,t1,t2,t3,t4,t5,t6), _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): - TupleType(t0,t1,t2,t3,t4,t5,t6) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - const std::string& n6 = "G", - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): - TupleType(t0,t1,t2,t3,t4,t5,t6), _pNames(0) - { - init(n0,n1,n2,n3,n4,n5,n6); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - case 6: return TupleType::template get<6>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F", - const std::string& n6 = "G") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - _pNames->push_back(n6); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): - TupleType(t0,t1,t2,t3,t4,t5), _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): - TupleType(t0,t1,t2,t3,t4,t5) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - const std::string& n5 = "F", - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): - TupleType(t0,t1,t2,t3,t4,t5), _pNames(0) - { - init(n0,n1,n2,n3,n4,n5); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - case 5: return TupleType::template get<5>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E", - const std::string& n5 = "F") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - _pNames->push_back(n5); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): - TupleType(t0,t1,t2,t3,t4), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): - TupleType(t0,t1,t2,t3,t4) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - const std::string& n4 = "E", - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): - TupleType(t0,t1,t2,t3,t4), - _pNames(0) - { - init(n0,n1,n2,n3,n4); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - case 4: return TupleType::template get<4>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D", - const std::string& n4 = "E") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - _pNames->push_back(n4); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): - TupleType(t0,t1,t2,t3), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): - TupleType(t0,t1,t2,t3) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - const std::string& n3 = "D", - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): - TupleType(t0,t1,t2,t3), _pNames(0) - { - init(n0,n1,n2,n3); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - case 3: return TupleType::template get<3>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C", - const std::string& n3 = "D") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - _pNames->push_back(n3); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): - TupleType(t0,t1,t2), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): - TupleType(t0,t1,t2) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - const std::string& n2 = "C", - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): - TupleType(t0,t1,t2), - _pNames(0) - { - init(n0,n1,n2); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - case 2: return TupleType::template get<2>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B", - const std::string& n2 = "C") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - _pNames->push_back(n2); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): - TupleType(t0,t1), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): - TupleType(t0,t1) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, - typename TypeWrapper::CONSTTYPE& t0, - const std::string& n1 = "B", - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): - TupleType(t0,t1), - _pNames(0) - { - init(n0,n1); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - case 1: return TupleType::template get<1>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A", - const std::string& n1 = "B") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - _pNames->push_back(n1); - } - } - - NameVecPtr _pNames; -}; - - -template -struct NamedTuple: - public Tuple -{ - typedef Tuple TupleType; - typedef typename Tuple::Type Type; - - typedef std::vector NameVec; - typedef SharedPtr NameVecPtr; - - NamedTuple(): _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(typename TypeWrapper::CONSTTYPE& t0): - TupleType(t0), - _pNames(0) - { - init(); - } - - NamedTuple(const NameVecPtr& rNames, - typename TypeWrapper::CONSTTYPE& t0): - TupleType(t0) - { - if (rNames->size() != TupleType::length) - throw InvalidArgumentException("Wrong names vector length."); - - _pNames = rNames; - } - - NamedTuple(const std::string& n0, typename TypeWrapper::CONSTTYPE& t0): - TupleType(t0), - _pNames(0) - { - init(n0); - } - - DynamicAny get(const std::string& name) const - { - NameVec::const_iterator it = _pNames->begin(); - NameVec::const_iterator itEnd = _pNames->end(); - - for(std::size_t counter = 0; it != itEnd; ++it, ++counter) - { - if (name == *it) - { - switch (counter) - { - case 0: return TupleType::template get<0>(); - default: throw RangeException(); - } - } - } - - throw NotFoundException("Name not found: " + name); - } - - DynamicAny operator [] (const std::string& name) const - { - return get(name); - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return TupleType::template get(); - } - - template - typename TypeGetter::HeadType& get() - { - return TupleType::template get(); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - return TupleType::template set(val); - } - - const NameVecPtr& names() - { - return _pNames; - } - - void setName(std::size_t index, const std::string& name) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - (*_pNames)[index] = name; - } - - const std::string& getName(std::size_t index) - { - if (index >= _pNames->size()) - throw InvalidArgumentException(format("Invalid index: %z", index)); - - return (*_pNames)[index]; - } - - bool operator == (const NamedTuple& other) const - { - return TupleType(*this) == TupleType(other) && _pNames == other._pNames; - } - - bool operator != (const NamedTuple& other) const - { - return !(*this == other); - } - - bool operator < (const NamedTuple& other) const - { - TupleType th(*this); - TupleType oth(other); - - return (th < oth && _pNames == other._pNames) || - (th == oth && _pNames < other._pNames) || - (th < oth && _pNames < other._pNames); - } - -private: - void init(const std::string& n0 = "A") - { - if (!_pNames) - { - _pNames = new NameVec; - _pNames->push_back(n0); - } - } - - NameVecPtr _pNames; -}; - - -} // namespace Poco - - -#endif // Foundation_Tuple_INCLUDED +// +// NamedTuple.h +// +// $Id: //poco/svn/Foundation/include/Poco/NamedTuple.h#2 $ +// +// Library: Foundation +// Package: Core +// Module: NamedTuple +// +// Definition of the NamedTuple 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_NamedTuple_INCLUDED +#define Foundation_NamedTuple_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Tuple.h" +#include "Poco/TypeList.h" +#include "Poco/DynamicAny.h" +#include "Poco/SharedPtr.h" +#include "Poco/Format.h" + + +namespace Poco { + + +template +struct NamedTuple: public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), + typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), + typename TypeWrapper::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), + typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), + typename TypeWrapper::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + const std::string& n12 = "M", + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + const std::string& n13 = "N", + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + const std::string& n14 = "O", + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + const std::string& n15 = "P", + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + const std::string& n16 = "Q", + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + const std::string& n17 = "R", + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), + const std::string& n18 = "S", + typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), + const std::string& n19 = "T", + typename TypeWrapper::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + case 12: return TupleType::template get<12>(); + case 13: return TupleType::template get<13>(); + case 14: return TupleType::template get<14>(); + case 15: return TupleType::template get<15>(); + case 16: return TupleType::template get<16>(); + case 17: return TupleType::template get<17>(); + case 18: return TupleType::template get<18>(); + case 19: return TupleType::template get<19>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L", + const std::string& n12 = "M", + const std::string& n13 = "N", + const std::string& n14 = "O", + const std::string& n15 = "P", + const std::string& n16 = "Q", + const std::string& n17 = "R", + const std::string& n18 = "S", + const std::string& n19 = "T") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + _pNames->push_back(n12); + _pNames->push_back(n13); + _pNames->push_back(n14); + _pNames->push_back(n15); + _pNames->push_back(n16); + _pNames->push_back(n17); + _pNames->push_back(n18); + _pNames->push_back(n19); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), + typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), + typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + const std::string& n12 = "M", + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + const std::string& n13 = "N", + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + const std::string& n14 = "O", + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + const std::string& n15 = "P", + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + const std::string& n16 = "Q", + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + const std::string& n17 = "R", + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), + const std::string& n18 = "S", + typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + case 12: return TupleType::template get<12>(); + case 13: return TupleType::template get<13>(); + case 14: return TupleType::template get<14>(); + case 15: return TupleType::template get<15>(); + case 16: return TupleType::template get<16>(); + case 17: return TupleType::template get<17>(); + case 18: return TupleType::template get<18>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L", + const std::string& n12 = "M", + const std::string& n13 = "N", + const std::string& n14 = "O", + const std::string& n15 = "P", + const std::string& n16 = "Q", + const std::string& n17 = "R", + const std::string& n18 = "S") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + _pNames->push_back(n12); + _pNames->push_back(n13); + _pNames->push_back(n14); + _pNames->push_back(n15); + _pNames->push_back(n16); + _pNames->push_back(n17); + _pNames->push_back(n18); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + const std::string& n12 = "M", + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + const std::string& n13 = "N", + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + const std::string& n14 = "O", + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + const std::string& n15 = "P", + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + const std::string& n16 = "Q", + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + const std::string& n17 = "R", + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + case 12: return TupleType::template get<12>(); + case 13: return TupleType::template get<13>(); + case 14: return TupleType::template get<14>(); + case 15: return TupleType::template get<15>(); + case 16: return TupleType::template get<16>(); + case 17: return TupleType::template get<17>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L", + const std::string& n12 = "M", + const std::string& n13 = "N", + const std::string& n14 = "O", + const std::string& n15 = "P", + const std::string& n16 = "Q", + const std::string& n17 = "R") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + _pNames->push_back(n12); + _pNames->push_back(n13); + _pNames->push_back(n14); + _pNames->push_back(n15); + _pNames->push_back(n16); + _pNames->push_back(n17); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + const std::string& n12 = "M", + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + const std::string& n13 = "N", + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + const std::string& n14 = "O", + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + const std::string& n15 = "P", + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + const std::string& n16 = "Q", + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + case 12: return TupleType::template get<12>(); + case 13: return TupleType::template get<13>(); + case 14: return TupleType::template get<14>(); + case 15: return TupleType::template get<15>(); + case 16: return TupleType::template get<16>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L", + const std::string& n12 = "M", + const std::string& n13 = "N", + const std::string& n14 = "O", + const std::string& n15 = "P", + const std::string& n16 = "Q") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + _pNames->push_back(n12); + _pNames->push_back(n13); + _pNames->push_back(n14); + _pNames->push_back(n15); + _pNames->push_back(n16); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + const std::string& n12 = "M", + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + const std::string& n13 = "N", + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + const std::string& n14 = "O", + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + const std::string& n15 = "P", + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + case 12: return TupleType::template get<12>(); + case 13: return TupleType::template get<13>(); + case 14: return TupleType::template get<14>(); + case 15: return TupleType::template get<15>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L", + const std::string& n12 = "M", + const std::string& n13 = "N", + const std::string& n14 = "O", + const std::string& n15 = "P") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + _pNames->push_back(n12); + _pNames->push_back(n13); + _pNames->push_back(n14); + _pNames->push_back(n15); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + const std::string& n12 = "M", + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + const std::string& n13 = "N", + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + const std::string& n14 = "O", + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + case 12: return TupleType::template get<12>(); + case 13: return TupleType::template get<13>(); + case 14: return TupleType::template get<14>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L", + const std::string& n12 = "M", + const std::string& n13 = "N", + const std::string& n14 = "O") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + _pNames->push_back(n12); + _pNames->push_back(n13); + _pNames->push_back(n14); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + const std::string& n12 = "M", + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + const std::string& n13 = "N", + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + case 12: return TupleType::template get<12>(); + case 13: return TupleType::template get<13>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L", + const std::string& n12 = "M", + const std::string& n13 = "N") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + _pNames->push_back(n12); + _pNames->push_back(n13); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + const std::string& n12 = "M", + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12), _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + case 12: return TupleType::template get<12>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L", + const std::string& n12 = "M") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + _pNames->push_back(n12); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + const std::string& n11 = "L", + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + case 11: return TupleType::template get<11>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K", + const std::string& n11 = "L") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + _pNames->push_back(n11); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + const std::string& n10 = "K", + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10), _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + case 10: return TupleType::template get<10>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J", + const std::string& n10 = "K") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + _pNames->push_back(n10); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + const std::string& n9 = "J", + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + case 9: return TupleType::template get<9>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I", + const std::string& n9 = "J") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + _pNames->push_back(n9); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + const std::string& n8 = "I", + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7,n8); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + case 8: return TupleType::template get<8>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H", + const std::string& n8 = "I") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + _pNames->push_back(n8); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + const std::string& n7 = "H", + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): + TupleType(t0,t1,t2,t3,t4,t5,t6,t7), + _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6,n7); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + case 7: return TupleType::template get<7>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G", + const std::string& n7 = "H") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + _pNames->push_back(n7); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): + TupleType(t0,t1,t2,t3,t4,t5,t6), _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): + TupleType(t0,t1,t2,t3,t4,t5,t6) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + const std::string& n6 = "G", + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): + TupleType(t0,t1,t2,t3,t4,t5,t6), _pNames(0) + { + init(n0,n1,n2,n3,n4,n5,n6); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + case 6: return TupleType::template get<6>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F", + const std::string& n6 = "G") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + _pNames->push_back(n6); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): + TupleType(t0,t1,t2,t3,t4,t5), _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): + TupleType(t0,t1,t2,t3,t4,t5) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + const std::string& n5 = "F", + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): + TupleType(t0,t1,t2,t3,t4,t5), _pNames(0) + { + init(n0,n1,n2,n3,n4,n5); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + case 5: return TupleType::template get<5>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E", + const std::string& n5 = "F") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + _pNames->push_back(n5); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): + TupleType(t0,t1,t2,t3,t4), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): + TupleType(t0,t1,t2,t3,t4) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + const std::string& n4 = "E", + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): + TupleType(t0,t1,t2,t3,t4), + _pNames(0) + { + init(n0,n1,n2,n3,n4); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + case 4: return TupleType::template get<4>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D", + const std::string& n4 = "E") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + _pNames->push_back(n4); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): + TupleType(t0,t1,t2,t3), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): + TupleType(t0,t1,t2,t3) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + const std::string& n3 = "D", + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): + TupleType(t0,t1,t2,t3), _pNames(0) + { + init(n0,n1,n2,n3); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + case 3: return TupleType::template get<3>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C", + const std::string& n3 = "D") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + _pNames->push_back(n3); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): + TupleType(t0,t1,t2), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): + TupleType(t0,t1,t2) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + const std::string& n2 = "C", + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): + TupleType(t0,t1,t2), + _pNames(0) + { + init(n0,n1,n2); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + case 2: return TupleType::template get<2>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B", + const std::string& n2 = "C") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + _pNames->push_back(n2); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): + TupleType(t0,t1), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): + TupleType(t0,t1) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, + typename TypeWrapper::CONSTTYPE& t0, + const std::string& n1 = "B", + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): + TupleType(t0,t1), + _pNames(0) + { + init(n0,n1); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + case 1: return TupleType::template get<1>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A", + const std::string& n1 = "B") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + _pNames->push_back(n1); + } + } + + NameVecPtr _pNames; +}; + + +template +struct NamedTuple: + public Tuple +{ + typedef Tuple TupleType; + typedef typename Tuple::Type Type; + + typedef std::vector NameVec; + typedef SharedPtr NameVecPtr; + + NamedTuple(): _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(typename TypeWrapper::CONSTTYPE& t0): + TupleType(t0), + _pNames(0) + { + init(); + } + + NamedTuple(const NameVecPtr& rNames, + typename TypeWrapper::CONSTTYPE& t0): + TupleType(t0) + { + if (rNames->size() != TupleType::length) + throw InvalidArgumentException("Wrong names vector length."); + + _pNames = rNames; + } + + NamedTuple(const std::string& n0, typename TypeWrapper::CONSTTYPE& t0): + TupleType(t0), + _pNames(0) + { + init(n0); + } + + DynamicAny get(const std::string& name) const + { + NameVec::const_iterator it = _pNames->begin(); + NameVec::const_iterator itEnd = _pNames->end(); + + for(std::size_t counter = 0; it != itEnd; ++it, ++counter) + { + if (name == *it) + { + switch (counter) + { + case 0: return TupleType::template get<0>(); + default: throw RangeException(); + } + } + } + + throw NotFoundException("Name not found: " + name); + } + + DynamicAny operator [] (const std::string& name) const + { + return get(name); + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return TupleType::template get(); + } + + template + typename TypeGetter::HeadType& get() + { + return TupleType::template get(); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + return TupleType::template set(val); + } + + const NameVecPtr& names() + { + return _pNames; + } + + void setName(std::size_t index, const std::string& name) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + (*_pNames)[index] = name; + } + + const std::string& getName(std::size_t index) + { + if (index >= _pNames->size()) + throw InvalidArgumentException(format("Invalid index: %z", index)); + + return (*_pNames)[index]; + } + + bool operator == (const NamedTuple& other) const + { + return TupleType(*this) == TupleType(other) && _pNames == other._pNames; + } + + bool operator != (const NamedTuple& other) const + { + return !(*this == other); + } + + bool operator < (const NamedTuple& other) const + { + TupleType th(*this); + TupleType oth(other); + + return (th < oth && _pNames == other._pNames) || + (th == oth && _pNames < other._pNames) || + (th < oth && _pNames < other._pNames); + } + +private: + void init(const std::string& n0 = "A") + { + if (!_pNames) + { + _pNames = new NameVec; + _pNames->push_back(n0); + } + } + + NameVecPtr _pNames; +}; + + +} // namespace Poco + + +#endif // Foundation_Tuple_INCLUDED diff --git a/Foundation/include/Poco/ScopedUnlock.h b/Foundation/include/Poco/ScopedUnlock.h index c7691bb90..d56676aa8 100644 --- a/Foundation/include/Poco/ScopedUnlock.h +++ b/Foundation/include/Poco/ScopedUnlock.h @@ -1,79 +1,79 @@ -// -// ScopedUnlock.h -// -// $Id: //poco/svn/Foundation/include/Poco/ScopedUnlock.h#2 $ -// -// Library: Foundation -// Package: Threading -// Module: Mutex -// -// Definition of the ScopedUnlock template 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_ScopedUnlock_INCLUDED -#define Foundation_ScopedUnlock_INCLUDED - - -#include "Poco/Foundation.h" - - -namespace Poco { - - -template -class ScopedUnlock - /// A class that simplifies thread synchronization - /// with a mutex. - /// The constructor accepts a Mutex and unlocks it. - /// The destructor unlocks the mutex. -{ -public: - inline ScopedUnlock(M& mutex, bool unlockNow = true): _mutex(mutex) - { - if (unlockNow) - _mutex.unlock(); - } - inline ~ScopedUnlock() - { - _mutex.lock(); - } - -private: - M& _mutex; - - ScopedUnlock(); - ScopedUnlock(const ScopedUnlock&); - ScopedUnlock& operator = (const ScopedUnlock&); -}; - - -} // namespace Poco - - -#endif // Foundation_ScopedUnlock_INCLUDED +// +// ScopedUnlock.h +// +// $Id: //poco/svn/Foundation/include/Poco/ScopedUnlock.h#2 $ +// +// Library: Foundation +// Package: Threading +// Module: Mutex +// +// Definition of the ScopedUnlock template 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_ScopedUnlock_INCLUDED +#define Foundation_ScopedUnlock_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +template +class ScopedUnlock + /// A class that simplifies thread synchronization + /// with a mutex. + /// The constructor accepts a Mutex and unlocks it. + /// The destructor unlocks the mutex. +{ +public: + inline ScopedUnlock(M& mutex, bool unlockNow = true): _mutex(mutex) + { + if (unlockNow) + _mutex.unlock(); + } + inline ~ScopedUnlock() + { + _mutex.lock(); + } + +private: + M& _mutex; + + ScopedUnlock(); + ScopedUnlock(const ScopedUnlock&); + ScopedUnlock& operator = (const ScopedUnlock&); +}; + + +} // namespace Poco + + +#endif // Foundation_ScopedUnlock_INCLUDED diff --git a/Foundation/include/Poco/SharedMemory.h b/Foundation/include/Poco/SharedMemory.h index f5b989315..3d77d5a7f 100644 --- a/Foundation/include/Poco/SharedMemory.h +++ b/Foundation/include/Poco/SharedMemory.h @@ -1,135 +1,135 @@ -// -// SharedMemory.h -// -// $Id: //poco/svn/Foundation/include/Poco/SharedMemory.h#2 $ -// -// Library: Foundation -// Package: Processes -// Module: SharedMemory -// -// Definition of the SharedMemory 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_SharedMemory_INCLUDED -#define Foundation_SharedMemory_INCLUDED - - -#include "Poco/Foundation.h" -#include -#include - - -namespace Poco { - - -class SharedMemoryImpl; -class File; - - -class Foundation_API SharedMemory - /// Create and manage a shared memory object. - /// - /// A SharedMemory object has value semantics, but - /// is implemented using a handle/implementation idiom. - /// Therefore, multiple SharedMemory objects can share - /// a single, reference counted SharedMemoryImpl object. -{ -public: - enum AccessMode - { - AM_READ = 0, - AM_WRITE - }; - - SharedMemory(); - /// 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, 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 - /// contain any slashes or backslashes. - /// - /// An address hint can be passed to the system, specifying the desired - /// 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. - /// - /// An address hint can be passed to the system, specifying the desired - /// 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. - - SharedMemory(const SharedMemory& other); - /// Creates a SharedMemory object by copying another one. - - ~SharedMemory(); - /// Destroys the SharedMemory. - - SharedMemory& operator = (const SharedMemory& other); - /// Assigns another SharedMemory object. - - void swap(SharedMemory& other); - /// Swaps the SharedMemory object with another one. - - char* begin() const; - /// Returns the start address of the shared memory segment. - /// Will be NULL for illegal segments. - - char* end() const; - /// Returns the one-past-end end address of the shared memory segment. - /// Will be NULL for illegal segments. - -private: - SharedMemoryImpl* _pImpl; -}; - - -// -// inlines -// -inline void SharedMemory::swap(SharedMemory& other) -{ - using std::swap; - swap(_pImpl, other._pImpl); -} - - -} // namespace Poco::Poco - - -#endif // Foundation_SharedMemory_INCLUDED +// +// SharedMemory.h +// +// $Id: //poco/svn/Foundation/include/Poco/SharedMemory.h#2 $ +// +// Library: Foundation +// Package: Processes +// Module: SharedMemory +// +// Definition of the SharedMemory 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_SharedMemory_INCLUDED +#define Foundation_SharedMemory_INCLUDED + + +#include "Poco/Foundation.h" +#include +#include + + +namespace Poco { + + +class SharedMemoryImpl; +class File; + + +class Foundation_API SharedMemory + /// Create and manage a shared memory object. + /// + /// A SharedMemory object has value semantics, but + /// is implemented using a handle/implementation idiom. + /// Therefore, multiple SharedMemory objects can share + /// a single, reference counted SharedMemoryImpl object. +{ +public: + enum AccessMode + { + AM_READ = 0, + AM_WRITE + }; + + SharedMemory(); + /// 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, 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 + /// contain any slashes or backslashes. + /// + /// An address hint can be passed to the system, specifying the desired + /// 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. + /// + /// An address hint can be passed to the system, specifying the desired + /// 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. + + SharedMemory(const SharedMemory& other); + /// Creates a SharedMemory object by copying another one. + + ~SharedMemory(); + /// Destroys the SharedMemory. + + SharedMemory& operator = (const SharedMemory& other); + /// Assigns another SharedMemory object. + + void swap(SharedMemory& other); + /// Swaps the SharedMemory object with another one. + + char* begin() const; + /// Returns the start address of the shared memory segment. + /// Will be NULL for illegal segments. + + char* end() const; + /// Returns the one-past-end end address of the shared memory segment. + /// Will be NULL for illegal segments. + +private: + SharedMemoryImpl* _pImpl; +}; + + +// +// inlines +// +inline void SharedMemory::swap(SharedMemory& other) +{ + using std::swap; + swap(_pImpl, other._pImpl); +} + + +} // namespace Poco::Poco + + +#endif // Foundation_SharedMemory_INCLUDED diff --git a/Foundation/include/Poco/SharedMemory_DUMMY.h b/Foundation/include/Poco/SharedMemory_DUMMY.h index 1190ed7ce..11fc09c46 100644 --- a/Foundation/include/Poco/SharedMemory_DUMMY.h +++ b/Foundation/include/Poco/SharedMemory_DUMMY.h @@ -1,110 +1,110 @@ -// -// SharedMemoryImpl.h -// -// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_DUMMY.h#2 $ -// -// Library: Foundation -// Package: Processes -// Module: SharedMemoryImpl -// -// Definition of the SharedMemoryImpl 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_SharedMemoryImpl_INCLUDED -#define Foundation_SharedMemoryImpl_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/SharedMemory.h" -#include "Poco/RefCountedObject.h" - - -namespace Poco { - - -class Foundation_API SharedMemoryImpl: public RefCountedObject - /// A dummy implementation of shared memory, for systems - /// that do not have shared memory support. -{ -public: - 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 - /// contain any slashes or backslashes. - /// - /// An address hint can be passed to the system, specifying the desired - /// 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. - - SharedMemoryImpl(const Poco::File& aFile, SharedMemory::AccessMode mode, const void* addr); - /// Maps the entire contents of file into a shared memory segment. - /// - /// An address hint can be passed to the system, specifying the desired - /// 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. - - char* begin() const; - /// Returns the start address of the shared memory segment. - - char* end() const; - /// Returns the one-past-end end address of the shared memory segment. - -protected: - ~SharedMemoryImpl(); - /// Destroys the SharedMemoryImpl. - -private: - SharedMemoryImpl(); - SharedMemoryImpl(const SharedMemoryImpl&); - SharedMemoryImpl& operator = (const SharedMemoryImpl&); -}; - - -// -// inlines -// -inline char* SharedMemoryImpl::begin() const -{ - return 0; -} - - -inline char* SharedMemoryImpl::end() const -{ - return 0; -} - - -} // namespace Poco - - -#endif // Foundation_SharedMemoryImpl_INCLUDED +// +// SharedMemoryImpl.h +// +// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_DUMMY.h#2 $ +// +// Library: Foundation +// Package: Processes +// Module: SharedMemoryImpl +// +// Definition of the SharedMemoryImpl 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_SharedMemoryImpl_INCLUDED +#define Foundation_SharedMemoryImpl_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/SharedMemory.h" +#include "Poco/RefCountedObject.h" + + +namespace Poco { + + +class Foundation_API SharedMemoryImpl: public RefCountedObject + /// A dummy implementation of shared memory, for systems + /// that do not have shared memory support. +{ +public: + 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 + /// contain any slashes or backslashes. + /// + /// An address hint can be passed to the system, specifying the desired + /// 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. + + SharedMemoryImpl(const Poco::File& aFile, SharedMemory::AccessMode mode, const void* addr); + /// Maps the entire contents of file into a shared memory segment. + /// + /// An address hint can be passed to the system, specifying the desired + /// 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. + + char* begin() const; + /// Returns the start address of the shared memory segment. + + char* end() const; + /// Returns the one-past-end end address of the shared memory segment. + +protected: + ~SharedMemoryImpl(); + /// Destroys the SharedMemoryImpl. + +private: + SharedMemoryImpl(); + SharedMemoryImpl(const SharedMemoryImpl&); + SharedMemoryImpl& operator = (const SharedMemoryImpl&); +}; + + +// +// inlines +// +inline char* SharedMemoryImpl::begin() const +{ + return 0; +} + + +inline char* SharedMemoryImpl::end() const +{ + return 0; +} + + +} // namespace Poco + + +#endif // Foundation_SharedMemoryImpl_INCLUDED diff --git a/Foundation/include/Poco/SharedMemory_POSIX.h b/Foundation/include/Poco/SharedMemory_POSIX.h index 0513e4180..ae4893a5d 100644 --- a/Foundation/include/Poco/SharedMemory_POSIX.h +++ b/Foundation/include/Poco/SharedMemory_POSIX.h @@ -1,129 +1,129 @@ -// -// SharedMemoryImpl.h -// -// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_POSIX.h#2 $ -// -// Library: Foundation -// Package: Processes -// Module: SharedMemoryImpl -// -// Definition of the SharedMemoryImpl 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_SharedMemoryImpl_INCLUDED -#define Foundation_SharedMemoryImpl_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/SharedMemory.h" -#include "Poco/RefCountedObject.h" - - -namespace Poco { - - -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, 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 - /// contain any slashes or backslashes. - /// - /// An address hint can be passed to the system, specifying the desired - /// 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. - /// - /// An address hint can be passed to the system, specifying the desired - /// 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. - - char* begin() const; - /// Returns the start address of the shared memory segment. - - char* end() const; - /// Returns the one-past-end end address of the shared memory segment. - -protected: - void map(const void* addrHint); - /// Maps the shared memory object. - - void unmap(); - /// Unmaps the shared memory object. - - void close(); - /// Releases the handle for the shared memory segment. - - ~SharedMemoryImpl(); - /// Destroys the SharedMemoryImpl. - -private: - SharedMemoryImpl(); - SharedMemoryImpl(const SharedMemoryImpl&); - SharedMemoryImpl& operator = (const SharedMemoryImpl&); - - std::size_t _size; - int _fd; - char* _address; - SharedMemory::AccessMode _access; - std::string _name; - bool _fileMapped; - bool _server; -}; - - -// -// inlines -// -inline char* SharedMemoryImpl::begin() const -{ - return _address; -} - - -inline char* SharedMemoryImpl::end() const -{ - return _address + _size; -} - - -} // namespace Poco - - -#endif // Foundation_SharedMemoryImpl_INCLUDED +// +// SharedMemoryImpl.h +// +// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_POSIX.h#2 $ +// +// Library: Foundation +// Package: Processes +// Module: SharedMemoryImpl +// +// Definition of the SharedMemoryImpl 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_SharedMemoryImpl_INCLUDED +#define Foundation_SharedMemoryImpl_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/SharedMemory.h" +#include "Poco/RefCountedObject.h" + + +namespace Poco { + + +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, 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 + /// contain any slashes or backslashes. + /// + /// An address hint can be passed to the system, specifying the desired + /// 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. + /// + /// An address hint can be passed to the system, specifying the desired + /// 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. + + char* begin() const; + /// Returns the start address of the shared memory segment. + + char* end() const; + /// Returns the one-past-end end address of the shared memory segment. + +protected: + void map(const void* addrHint); + /// Maps the shared memory object. + + void unmap(); + /// Unmaps the shared memory object. + + void close(); + /// Releases the handle for the shared memory segment. + + ~SharedMemoryImpl(); + /// Destroys the SharedMemoryImpl. + +private: + SharedMemoryImpl(); + SharedMemoryImpl(const SharedMemoryImpl&); + SharedMemoryImpl& operator = (const SharedMemoryImpl&); + + std::size_t _size; + int _fd; + char* _address; + SharedMemory::AccessMode _access; + std::string _name; + bool _fileMapped; + bool _server; +}; + + +// +// inlines +// +inline char* SharedMemoryImpl::begin() const +{ + return _address; +} + + +inline char* SharedMemoryImpl::end() const +{ + return _address + _size; +} + + +} // namespace Poco + + +#endif // Foundation_SharedMemoryImpl_INCLUDED diff --git a/Foundation/include/Poco/SharedMemory_WIN32.h b/Foundation/include/Poco/SharedMemory_WIN32.h index aa9fe1283..a0c426657 100644 --- a/Foundation/include/Poco/SharedMemory_WIN32.h +++ b/Foundation/include/Poco/SharedMemory_WIN32.h @@ -1,125 +1,125 @@ -// -// SharedMemoryImpl.h -// -// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_WIN32.h#2 $ -// -// Library: Foundation -// Package: Processes -// Module: SharedMemoryImpl -// -// Definition of the SharedMemoryImpl 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_SharedMemoryImpl_INCLUDED -#define Foundation_SharedMemoryImpl_INCLUDED - - -#include "Poco/Poco.h" -#include "Poco/SharedMemory.h" -#include "Poco/RefCountedObject.h" - - -namespace Poco { - - -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, 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 - /// contain any slashes or backslashes. - /// - /// An address hint can be passed to the system, specifying the desired - /// 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. - - SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint); - /// Maps the entire contents of file into a shared memory segment. - /// - /// An address hint can be passed to the system, specifying the desired - /// 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. - - char* begin() const; - /// Returns the beginn address of the SharedMemory segment. Will be null for illegal segments. - - char* end() const; - /// Points past the last byte of the end address of the SharedMemory segment. Will be null for illegal segments. - -protected: - void map(); - /// Maps the shared memory object. - - void unmap(); - /// Unmaps the shared memory object. - - void close(); - /// Releases the handle for the shared memory segment. - - ~SharedMemoryImpl(); - /// Destroys the SharedMemoryImpl. - -private: - SharedMemoryImpl(); - SharedMemoryImpl(const SharedMemoryImpl&); - SharedMemoryImpl& operator = (const SharedMemoryImpl&); - - std::string _name; - HANDLE _memHandle; - HANDLE _fileHandle; - DWORD _size; - DWORD _mode; - char* _address; -}; - - -// -// inlines -// -inline char* SharedMemoryImpl::begin() const -{ - return _address; -} - - -inline char* SharedMemoryImpl::end() const -{ - return _address + _size; -} - - -} // namespace Poco - - -#endif // Foundation_SharedMemoryImpl_INCLUDED +// +// SharedMemoryImpl.h +// +// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_WIN32.h#2 $ +// +// Library: Foundation +// Package: Processes +// Module: SharedMemoryImpl +// +// Definition of the SharedMemoryImpl 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_SharedMemoryImpl_INCLUDED +#define Foundation_SharedMemoryImpl_INCLUDED + + +#include "Poco/Poco.h" +#include "Poco/SharedMemory.h" +#include "Poco/RefCountedObject.h" + + +namespace Poco { + + +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, 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 + /// contain any slashes or backslashes. + /// + /// An address hint can be passed to the system, specifying the desired + /// 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. + + SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint); + /// Maps the entire contents of file into a shared memory segment. + /// + /// An address hint can be passed to the system, specifying the desired + /// 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. + + char* begin() const; + /// Returns the beginn address of the SharedMemory segment. Will be null for illegal segments. + + char* end() const; + /// Points past the last byte of the end address of the SharedMemory segment. Will be null for illegal segments. + +protected: + void map(); + /// Maps the shared memory object. + + void unmap(); + /// Unmaps the shared memory object. + + void close(); + /// Releases the handle for the shared memory segment. + + ~SharedMemoryImpl(); + /// Destroys the SharedMemoryImpl. + +private: + SharedMemoryImpl(); + SharedMemoryImpl(const SharedMemoryImpl&); + SharedMemoryImpl& operator = (const SharedMemoryImpl&); + + std::string _name; + HANDLE _memHandle; + HANDLE _fileHandle; + DWORD _size; + DWORD _mode; + char* _address; +}; + + +// +// inlines +// +inline char* SharedMemoryImpl::begin() const +{ + return _address; +} + + +inline char* SharedMemoryImpl::end() const +{ + return _address + _size; +} + + +} // namespace Poco + + +#endif // Foundation_SharedMemoryImpl_INCLUDED diff --git a/Foundation/include/Poco/Tuple.h b/Foundation/include/Poco/Tuple.h index 5db3b15d4..f0cef6fdf 100644 --- a/Foundation/include/Poco/Tuple.h +++ b/Foundation/include/Poco/Tuple.h @@ -1,1769 +1,1769 @@ -// -// Tuple.h -// -// $Id: //poco/svn/Foundation/include/Poco/Tuple.h#2 $ -// -// Library: Foundation -// Package: Core -// Module: Tuple -// -// Definition of the Tuple class. -// -// Copyright (c) 2004-2006, 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_Tuple_INCLUDED -#define Foundation_Tuple_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/TypeList.h" - - -namespace Poco { - - -#if defined(POCO_OS_FAMILY_WINDOWS) -#define POCO_TYPEWRAPPER_DEFAULTVALUE(T) TypeWrapper::TYPE() -#else -#define POCO_TYPEWRAPPER_DEFAULTVALUE(T) typename TypeWrapper::TYPE() -#endif - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), - typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), - typename TypeWrapper::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, typename TypeListType::HeadType - (t12, typename TypeListType::HeadType - (t13, typename TypeListType::HeadType - (t14, typename TypeListType::HeadType - (t15, typename TypeListType::HeadType - (t16, typename TypeListType::HeadType - (t17, typename TypeListType::HeadType - (t18, typename TypeListType::HeadType - (t19, NullTypeList())))))))))))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), - typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, typename TypeListType::HeadType - (t12, typename TypeListType::HeadType - (t13, typename TypeListType::HeadType - (t14, typename TypeListType::HeadType - (t15, typename TypeListType::HeadType - (t16, typename TypeListType::HeadType - (t17, typename TypeListType::HeadType - (t18, NullTypeList()))))))))))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), - typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, typename TypeListType::HeadType - (t12, typename TypeListType::HeadType - (t13, typename TypeListType::HeadType - (t14, typename TypeListType::HeadType - (t15, typename TypeListType::HeadType - (t16, typename TypeListType::HeadType - (t17, NullTypeList())))))))))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), - typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, typename TypeListType::HeadType - (t12, typename TypeListType::HeadType - (t13, typename TypeListType::HeadType - (t14, typename TypeListType::HeadType - (t15, typename TypeListType::HeadType - (t16, NullTypeList()))))))))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), - typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, typename TypeListType::HeadType - (t12, typename TypeListType::HeadType - (t13, typename TypeListType::HeadType - (t14, typename TypeListType::HeadType - (t15, NullTypeList())))))))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), - typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, typename TypeListType::HeadType - (t12, typename TypeListType::HeadType - (t13, typename TypeListType::HeadType - (t14, NullTypeList()))))))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), - typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, typename TypeListType::HeadType - (t12, typename TypeListType::HeadType - (t13, NullTypeList())))))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), - typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, typename TypeListType::HeadType - (t12, NullTypeList()))))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), - typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, typename TypeListType::HeadType - (t11, NullTypeList())))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), - typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, typename TypeListType::HeadType - (t10, NullTypeList()))))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), - typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, typename TypeListType::HeadType - (t9, NullTypeList())))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), - typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, typename TypeListType::HeadType - (t8, NullTypeList()))))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), - typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, typename TypeListType::HeadType - (t7, NullTypeList())))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), - typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, typename TypeListType::HeadType - (t6, NullTypeList()))))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), - typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, typename TypeListType::HeadType - (t5, NullTypeList())))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), - typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, typename TypeListType::HeadType - (t4, NullTypeList()))))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), - typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, typename TypeListType::HeadType - (t3, NullTypeList())))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), - typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): - _data(t0, typename TypeListType::HeadType - (t1, typename TypeListType::HeadType - (t2, NullTypeList()))) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef typename TypeListType::HeadType Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0, - typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): - _data(t0, typename TypeListType::HeadType(t1, NullTypeList())) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -template -struct Tuple -{ - typedef TypeList Type; - - enum TupleLengthType - { - length = Type::length - }; - - Tuple():_data() - { - } - - Tuple(typename TypeWrapper::CONSTTYPE& t0): - _data(t0, NullTypeList()) - { - } - - template - typename TypeGetter::ConstHeadType& get() const - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - typename TypeGetter::HeadType& get() - { - return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); - } - - template - void set(typename TypeGetter::ConstHeadType& val) - { - Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; - } - - bool operator == (const Tuple& other) const - { - return _data == other._data; - } - - bool operator != (const Tuple& other) const - { - return !(_data == other._data); - } - - bool operator < (const Tuple& other) const - { - return _data < other._data; - } - -private: - Type _data; -}; - - -} // namespace Poco - - -#endif // Foundation_Tuple_INCLUDED +// +// Tuple.h +// +// $Id: //poco/svn/Foundation/include/Poco/Tuple.h#2 $ +// +// Library: Foundation +// Package: Core +// Module: Tuple +// +// Definition of the Tuple class. +// +// Copyright (c) 2004-2006, 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_Tuple_INCLUDED +#define Foundation_Tuple_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/TypeList.h" + + +namespace Poco { + + +#if defined(POCO_OS_FAMILY_WINDOWS) +#define POCO_TYPEWRAPPER_DEFAULTVALUE(T) TypeWrapper::TYPE() +#else +#define POCO_TYPEWRAPPER_DEFAULTVALUE(T) typename TypeWrapper::TYPE() +#endif + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), + typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), + typename TypeWrapper::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, typename TypeListType::HeadType + (t12, typename TypeListType::HeadType + (t13, typename TypeListType::HeadType + (t14, typename TypeListType::HeadType + (t15, typename TypeListType::HeadType + (t16, typename TypeListType::HeadType + (t17, typename TypeListType::HeadType + (t18, typename TypeListType::HeadType + (t19, NullTypeList())))))))))))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), + typename TypeWrapper::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, typename TypeListType::HeadType + (t12, typename TypeListType::HeadType + (t13, typename TypeListType::HeadType + (t14, typename TypeListType::HeadType + (t15, typename TypeListType::HeadType + (t16, typename TypeListType::HeadType + (t17, typename TypeListType::HeadType + (t18, NullTypeList()))))))))))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), + typename TypeWrapper::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, typename TypeListType::HeadType + (t12, typename TypeListType::HeadType + (t13, typename TypeListType::HeadType + (t14, typename TypeListType::HeadType + (t15, typename TypeListType::HeadType + (t16, typename TypeListType::HeadType + (t17, NullTypeList())))))))))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), + typename TypeWrapper::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, typename TypeListType::HeadType + (t12, typename TypeListType::HeadType + (t13, typename TypeListType::HeadType + (t14, typename TypeListType::HeadType + (t15, typename TypeListType::HeadType + (t16, NullTypeList()))))))))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), + typename TypeWrapper::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, typename TypeListType::HeadType + (t12, typename TypeListType::HeadType + (t13, typename TypeListType::HeadType + (t14, typename TypeListType::HeadType + (t15, NullTypeList())))))))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), + typename TypeWrapper::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, typename TypeListType::HeadType + (t12, typename TypeListType::HeadType + (t13, typename TypeListType::HeadType + (t14, NullTypeList()))))))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), + typename TypeWrapper::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, typename TypeListType::HeadType + (t12, typename TypeListType::HeadType + (t13, NullTypeList())))))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), + typename TypeWrapper::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, typename TypeListType::HeadType + (t12, NullTypeList()))))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), + typename TypeWrapper::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, typename TypeListType::HeadType + (t11, NullTypeList())))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), + typename TypeWrapper::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, typename TypeListType::HeadType + (t10, NullTypeList()))))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), + typename TypeWrapper::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, typename TypeListType::HeadType + (t9, NullTypeList())))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), + typename TypeWrapper::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, typename TypeListType::HeadType + (t8, NullTypeList()))))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), + typename TypeWrapper::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, typename TypeListType::HeadType + (t7, NullTypeList())))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), + typename TypeWrapper::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, typename TypeListType::HeadType + (t6, NullTypeList()))))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), + typename TypeWrapper::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, typename TypeListType::HeadType + (t5, NullTypeList())))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), + typename TypeWrapper::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, typename TypeListType::HeadType + (t4, NullTypeList()))))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), + typename TypeWrapper::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, typename TypeListType::HeadType + (t3, NullTypeList())))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), + typename TypeWrapper::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): + _data(t0, typename TypeListType::HeadType + (t1, typename TypeListType::HeadType + (t2, NullTypeList()))) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef typename TypeListType::HeadType Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0, + typename TypeWrapper::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): + _data(t0, typename TypeListType::HeadType(t1, NullTypeList())) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +template +struct Tuple +{ + typedef TypeList Type; + + enum TupleLengthType + { + length = Type::length + }; + + Tuple():_data() + { + } + + Tuple(typename TypeWrapper::CONSTTYPE& t0): + _data(t0, NullTypeList()) + { + } + + template + typename TypeGetter::ConstHeadType& get() const + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + typename TypeGetter::HeadType& get() + { + return Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data); + } + + template + void set(typename TypeGetter::ConstHeadType& val) + { + Getter::template get::HeadType, typename Type::HeadType, typename Type::TailType>(_data) = val; + } + + bool operator == (const Tuple& other) const + { + return _data == other._data; + } + + bool operator != (const Tuple& other) const + { + return !(_data == other._data); + } + + bool operator < (const Tuple& other) const + { + return _data < other._data; + } + +private: + Type _data; +}; + + +} // namespace Poco + + +#endif // Foundation_Tuple_INCLUDED diff --git a/Foundation/include/Poco/TypeList.h b/Foundation/include/Poco/TypeList.h index 0900d445f..bc09fcc52 100644 --- a/Foundation/include/Poco/TypeList.h +++ b/Foundation/include/Poco/TypeList.h @@ -1,487 +1,487 @@ -// -// TypeList.h -// -// $Id: //poco/svn/Foundation/include/Poco/TypeList.h#3 $ -// -// Library: Foundation -// Package: Core -// Module: TypeList -// -// Implementation of the TypeList template. -// -// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// Portions extracted and adapted from -// The Loki Library -// Copyright (c) 2001 by Andrei Alexandrescu -// -// 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_TypeList_INCLUDED -#define Foundation_TypeList_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/MetaProgramming.h" - - -namespace Poco { - - -template -struct TypeList; - - -struct NullTypeList -{ - enum - { - length = 0 - }; - - bool operator == (const NullTypeList&) const - { - return true; - } - - bool operator != (const NullTypeList&) const - { - return false; - } - - bool operator < (const NullTypeList&) const - { - return false; - } -}; - - -template -struct TypeList - /// Compile Time List of Types -{ - typedef Head HeadType; - typedef Tail TailType; - typedef typename TypeWrapper::CONSTTYPE ConstHeadType; - typedef typename TypeWrapper::CONSTTYPE ConstTailType; - enum - { - length = TailType::length+1 - }; - - TypeList():head(), tail() - { - } - - TypeList(ConstHeadType& h, ConstTailType& t):head(h), tail(t) - { - } - - TypeList(const TypeList& tl): head(tl.head), tail(tl.tail) - { - } - - TypeList& operator = (const TypeList& tl) - { - if (this != &tl) - { - TypeList tmp(tl); - swap(tmp); - } - return *this; - } - - bool operator == (const TypeList& tl) const - { - return tl.head == head && tl.tail == tail; - } - - bool operator != (const TypeList& tl) const - { - return !(*this == tl); - } - - bool operator < (const TypeList& tl) const - { - if (head < tl.head) - return true; - else if (head == tl.head) - return tail < tl.tail; - return false; - } - - void swap(TypeList& tl) - { - std::swap(head, tl.head); - std::swap(tail, tl.tail); - } - - HeadType head; - TailType tail; -}; - - -template -struct TypeListType - /// TypeListType takes 1 - 20 typename arguments. - /// Usage: - /// - /// TypeListType::HeadType typeList; - /// - /// typeList is a TypeList of T0, T1, ... , Tn -{ -private: - typedef typename TypeListType::HeadType TailType; - -public: - typedef TypeList HeadType; -}; - - -template <> -struct TypeListType<> -{ - typedef NullTypeList HeadType; -}; - - -template -struct Getter -{ - template - inline static Ret& get(TypeList& val) - { - return Getter::template get(val.tail); - } - - template - inline static const Ret& get(const TypeList& val) - { - return Getter::template get(val.tail); - } -}; - - -template <> -struct Getter<0> -{ - template - inline static Ret& get(TypeList& val) - { - return val.head; - } - - template - inline static const Ret& get(const TypeList& val) - { - return val.head; - } -}; - - -template -struct TypeGetter; - - -template -struct TypeGetter > -{ - typedef typename TypeGetter::HeadType HeadType; - typedef typename TypeWrapper::CONSTTYPE ConstHeadType; -}; - - -template -struct TypeGetter<0, TypeList > -{ - typedef typename TypeList::HeadType HeadType; - typedef typename TypeWrapper::CONSTTYPE ConstHeadType; -}; - - -template -struct TypeLocator; - /// TypeLocator returns the first occurrence of the type T in Head - /// or -1 if the type is not found. - /// - /// Usage example: - /// - /// TypeLocator::HeadType TypeLoc; - /// - /// if (2 == TypeLoc.value) ... - /// - - -template -struct TypeLocator -{ - enum { value = -1 }; -}; - - -template -struct TypeLocator, T> -{ - enum { value = 0 }; -}; - - -template -struct TypeLocator, T> -{ -private: - enum { tmp = TypeLocator::value }; -public: - enum { value = tmp == -1 ? -1 : 1 + tmp }; -}; - - -template -struct TypeAppender; - /// TypeAppender appends T (type or a TypeList) to Head. - /// - /// Usage: - /// - /// typedef TypeListType::HeadType Type1; - /// typedef TypeAppender::HeadType Type2; - /// (Type2 is a TypeList of char,int) - /// - /// typedef TypeListType::HeadType Type3; - /// typedef TypeAppender::HeadType Type4; - /// (Type4 is a TypeList of char,int,float,double) - /// - - -template <> -struct TypeAppender -{ - typedef NullTypeList HeadType; -}; - - -template -struct TypeAppender -{ - typedef TypeList HeadType; -}; - - -template -struct TypeAppender > -{ - typedef TypeList HeadType; -}; - - -template -struct TypeAppender, T> -{ - typedef TypeList::HeadType> HeadType; -}; - - -template -struct TypeOneEraser; - /// TypeOneEraser erases the first occurence of the type T in Head. - /// Usage: - /// - /// typedef TypeListType::HeadType Type3; - /// typedef TypeOneEraser::HeadType Type2; - /// (Type2 is a TypeList of char,float) - /// - - -template -struct TypeOneEraser -{ - typedef NullTypeList HeadType; -}; - - -template -struct TypeOneEraser, T> -{ - typedef Tail HeadType; -}; - - -template -struct TypeOneEraser, T> -{ - typedef TypeList ::HeadType> HeadType; -}; - - -template -struct TypeAllEraser; - /// TypeAllEraser erases all the occurences of the type T in Head. - /// Usage: - /// - /// typedef TypeListType::HeadType Type4; - /// typedef TypeAllEraser::HeadType Type2; - /// (Type2 is a TypeList of char,float) - /// - - -template -struct TypeAllEraser -{ - typedef NullTypeList HeadType; -}; - - -template -struct TypeAllEraser, T> -{ - typedef typename TypeAllEraser::HeadType HeadType; -}; - - -template -struct TypeAllEraser, T> -{ - typedef TypeList ::HeadType> HeadType; -}; - - -template -struct TypeDuplicateEraser; - /// TypeDuplicateEraser erases all but the first occurence of the type T in Head. - /// Usage: - /// - /// typedef TypeListType::HeadType Type4; - /// typedef TypeDuplicateEraser::HeadType Type3; - /// (Type3 is a TypeList of char,int,float) - /// - - -template <> -struct TypeDuplicateEraser -{ - typedef NullTypeList HeadType; -}; - - -template -struct TypeDuplicateEraser > -{ -private: - typedef typename TypeDuplicateEraser::HeadType L1; - typedef typename TypeOneEraser::HeadType L2; -public: - typedef TypeList HeadType; -}; - - -template -struct TypeOneReplacer; - /// TypeOneReplacer replaces the first occurence - /// of the type T in Head with type R. - /// Usage: - /// - /// typedef TypeListType::HeadType Type4; - /// typedef TypeOneReplacer::HeadType TypeR; - /// (TypeR is a TypeList of char,double,float,int) - /// - - -template -struct TypeOneReplacer -{ - typedef NullTypeList HeadType; -}; - - -template -struct TypeOneReplacer, T, R> -{ - typedef TypeList HeadType; -}; - - -template -struct TypeOneReplacer, T, R> -{ - typedef TypeList::HeadType> HeadType; -}; - - -template -struct TypeAllReplacer; - /// TypeAllReplacer replaces all the occurences - /// of the type T in Head with type R. - /// Usage: - /// - /// typedef TypeListType::HeadType Type4; - /// typedef TypeAllReplacer::HeadType TypeR; - /// (TypeR is a TypeList of char,double,float,double) - /// - - -template -struct TypeAllReplacer -{ - typedef NullTypeList HeadType; -}; - - -template -struct TypeAllReplacer, T, R> -{ - typedef TypeList::HeadType> HeadType; -}; - - -template -struct TypeAllReplacer, T, R> -{ - typedef TypeList::HeadType> HeadType; -}; - - -} // namespace Poco - - -#endif +// +// TypeList.h +// +// $Id: //poco/svn/Foundation/include/Poco/TypeList.h#3 $ +// +// Library: Foundation +// Package: Core +// Module: TypeList +// +// Implementation of the TypeList template. +// +// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// Portions extracted and adapted from +// The Loki Library +// Copyright (c) 2001 by Andrei Alexandrescu +// +// 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_TypeList_INCLUDED +#define Foundation_TypeList_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/MetaProgramming.h" + + +namespace Poco { + + +template +struct TypeList; + + +struct NullTypeList +{ + enum + { + length = 0 + }; + + bool operator == (const NullTypeList&) const + { + return true; + } + + bool operator != (const NullTypeList&) const + { + return false; + } + + bool operator < (const NullTypeList&) const + { + return false; + } +}; + + +template +struct TypeList + /// Compile Time List of Types +{ + typedef Head HeadType; + typedef Tail TailType; + typedef typename TypeWrapper::CONSTTYPE ConstHeadType; + typedef typename TypeWrapper::CONSTTYPE ConstTailType; + enum + { + length = TailType::length+1 + }; + + TypeList():head(), tail() + { + } + + TypeList(ConstHeadType& h, ConstTailType& t):head(h), tail(t) + { + } + + TypeList(const TypeList& tl): head(tl.head), tail(tl.tail) + { + } + + TypeList& operator = (const TypeList& tl) + { + if (this != &tl) + { + TypeList tmp(tl); + swap(tmp); + } + return *this; + } + + bool operator == (const TypeList& tl) const + { + return tl.head == head && tl.tail == tail; + } + + bool operator != (const TypeList& tl) const + { + return !(*this == tl); + } + + bool operator < (const TypeList& tl) const + { + if (head < tl.head) + return true; + else if (head == tl.head) + return tail < tl.tail; + return false; + } + + void swap(TypeList& tl) + { + std::swap(head, tl.head); + std::swap(tail, tl.tail); + } + + HeadType head; + TailType tail; +}; + + +template +struct TypeListType + /// TypeListType takes 1 - 20 typename arguments. + /// Usage: + /// + /// TypeListType::HeadType typeList; + /// + /// typeList is a TypeList of T0, T1, ... , Tn +{ +private: + typedef typename TypeListType::HeadType TailType; + +public: + typedef TypeList HeadType; +}; + + +template <> +struct TypeListType<> +{ + typedef NullTypeList HeadType; +}; + + +template +struct Getter +{ + template + inline static Ret& get(TypeList& val) + { + return Getter::template get(val.tail); + } + + template + inline static const Ret& get(const TypeList& val) + { + return Getter::template get(val.tail); + } +}; + + +template <> +struct Getter<0> +{ + template + inline static Ret& get(TypeList& val) + { + return val.head; + } + + template + inline static const Ret& get(const TypeList& val) + { + return val.head; + } +}; + + +template +struct TypeGetter; + + +template +struct TypeGetter > +{ + typedef typename TypeGetter::HeadType HeadType; + typedef typename TypeWrapper::CONSTTYPE ConstHeadType; +}; + + +template +struct TypeGetter<0, TypeList > +{ + typedef typename TypeList::HeadType HeadType; + typedef typename TypeWrapper::CONSTTYPE ConstHeadType; +}; + + +template +struct TypeLocator; + /// TypeLocator returns the first occurrence of the type T in Head + /// or -1 if the type is not found. + /// + /// Usage example: + /// + /// TypeLocator::HeadType TypeLoc; + /// + /// if (2 == TypeLoc.value) ... + /// + + +template +struct TypeLocator +{ + enum { value = -1 }; +}; + + +template +struct TypeLocator, T> +{ + enum { value = 0 }; +}; + + +template +struct TypeLocator, T> +{ +private: + enum { tmp = TypeLocator::value }; +public: + enum { value = tmp == -1 ? -1 : 1 + tmp }; +}; + + +template +struct TypeAppender; + /// TypeAppender appends T (type or a TypeList) to Head. + /// + /// Usage: + /// + /// typedef TypeListType::HeadType Type1; + /// typedef TypeAppender::HeadType Type2; + /// (Type2 is a TypeList of char,int) + /// + /// typedef TypeListType::HeadType Type3; + /// typedef TypeAppender::HeadType Type4; + /// (Type4 is a TypeList of char,int,float,double) + /// + + +template <> +struct TypeAppender +{ + typedef NullTypeList HeadType; +}; + + +template +struct TypeAppender +{ + typedef TypeList HeadType; +}; + + +template +struct TypeAppender > +{ + typedef TypeList HeadType; +}; + + +template +struct TypeAppender, T> +{ + typedef TypeList::HeadType> HeadType; +}; + + +template +struct TypeOneEraser; + /// TypeOneEraser erases the first occurence of the type T in Head. + /// Usage: + /// + /// typedef TypeListType::HeadType Type3; + /// typedef TypeOneEraser::HeadType Type2; + /// (Type2 is a TypeList of char,float) + /// + + +template +struct TypeOneEraser +{ + typedef NullTypeList HeadType; +}; + + +template +struct TypeOneEraser, T> +{ + typedef Tail HeadType; +}; + + +template +struct TypeOneEraser, T> +{ + typedef TypeList ::HeadType> HeadType; +}; + + +template +struct TypeAllEraser; + /// TypeAllEraser erases all the occurences of the type T in Head. + /// Usage: + /// + /// typedef TypeListType::HeadType Type4; + /// typedef TypeAllEraser::HeadType Type2; + /// (Type2 is a TypeList of char,float) + /// + + +template +struct TypeAllEraser +{ + typedef NullTypeList HeadType; +}; + + +template +struct TypeAllEraser, T> +{ + typedef typename TypeAllEraser::HeadType HeadType; +}; + + +template +struct TypeAllEraser, T> +{ + typedef TypeList ::HeadType> HeadType; +}; + + +template +struct TypeDuplicateEraser; + /// TypeDuplicateEraser erases all but the first occurence of the type T in Head. + /// Usage: + /// + /// typedef TypeListType::HeadType Type4; + /// typedef TypeDuplicateEraser::HeadType Type3; + /// (Type3 is a TypeList of char,int,float) + /// + + +template <> +struct TypeDuplicateEraser +{ + typedef NullTypeList HeadType; +}; + + +template +struct TypeDuplicateEraser > +{ +private: + typedef typename TypeDuplicateEraser::HeadType L1; + typedef typename TypeOneEraser::HeadType L2; +public: + typedef TypeList HeadType; +}; + + +template +struct TypeOneReplacer; + /// TypeOneReplacer replaces the first occurence + /// of the type T in Head with type R. + /// Usage: + /// + /// typedef TypeListType::HeadType Type4; + /// typedef TypeOneReplacer::HeadType TypeR; + /// (TypeR is a TypeList of char,double,float,int) + /// + + +template +struct TypeOneReplacer +{ + typedef NullTypeList HeadType; +}; + + +template +struct TypeOneReplacer, T, R> +{ + typedef TypeList HeadType; +}; + + +template +struct TypeOneReplacer, T, R> +{ + typedef TypeList::HeadType> HeadType; +}; + + +template +struct TypeAllReplacer; + /// TypeAllReplacer replaces all the occurences + /// of the type T in Head with type R. + /// Usage: + /// + /// typedef TypeListType::HeadType Type4; + /// typedef TypeAllReplacer::HeadType TypeR; + /// (TypeR is a TypeList of char,double,float,double) + /// + + +template +struct TypeAllReplacer +{ + typedef NullTypeList HeadType; +}; + + +template +struct TypeAllReplacer, T, R> +{ + typedef TypeList::HeadType> HeadType; +}; + + +template +struct TypeAllReplacer, T, R> +{ + typedef TypeList::HeadType> HeadType; +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/UTF8String.h b/Foundation/include/Poco/UTF8String.h index 288ed13d5..3d1dad1ef 100644 --- a/Foundation/include/Poco/UTF8String.h +++ b/Foundation/include/Poco/UTF8String.h @@ -1,80 +1,80 @@ -// -// UTF8String.h -// -// $Id: //poco/svn/Foundation/include/Poco/UTF8String.h#2 $ -// -// Library: Foundation -// Package: Text -// Module: UTF8String -// -// Definition of the UTF8 string functions. -// -// 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_UTF8String_INCLUDED -#define Foundation_UTF8String_INCLUDED - - -#include "Poco/Foundation.h" - - -namespace Poco { - - -struct Foundation_API UTF8 - /// This class provides static methods that are UTF-8 capable variants - /// of the same functions in Poco/String.h. - /// - /// The various variants of icompare() provide case insensitive comparison - /// for UTF-8 encoded strings. - /// - /// toUpper(), toUpperInPlace(), toLower() and toLowerInPlace() provide - /// Unicode-based character case transformation for UTF-8 encoded strings. -{ - static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2); - static int icompare(const std::string& str1, const std::string& str2); - static int icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2); - static int icompare(const std::string& str1, std::string::size_type n, const std::string& str2); - static int icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2); - static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2); - static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2); - static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr); - static int icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr); - static int icompare(const std::string& str, const std::string::value_type* ptr); - - static std::string toUpper(const std::string& str); - static std::string& toUpperInPlace(std::string& str); - static std::string toLower(const std::string& str); - static std::string& toLowerInPlace(std::string& str); -}; - - -} // namespace Poco - - -#endif // Foundation_UTF8String_INCLUDED +// +// UTF8String.h +// +// $Id: //poco/svn/Foundation/include/Poco/UTF8String.h#2 $ +// +// Library: Foundation +// Package: Text +// Module: UTF8String +// +// Definition of the UTF8 string functions. +// +// 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_UTF8String_INCLUDED +#define Foundation_UTF8String_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +struct Foundation_API UTF8 + /// This class provides static methods that are UTF-8 capable variants + /// of the same functions in Poco/String.h. + /// + /// The various variants of icompare() provide case insensitive comparison + /// for UTF-8 encoded strings. + /// + /// toUpper(), toUpperInPlace(), toLower() and toLowerInPlace() provide + /// Unicode-based character case transformation for UTF-8 encoded strings. +{ + static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2); + static int icompare(const std::string& str1, const std::string& str2); + static int icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2); + static int icompare(const std::string& str1, std::string::size_type n, const std::string& str2); + static int icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2); + static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2); + static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2); + static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr); + static int icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr); + static int icompare(const std::string& str, const std::string::value_type* ptr); + + static std::string toUpper(const std::string& str); + static std::string& toUpperInPlace(std::string& str); + static std::string toLower(const std::string& str); + static std::string& toLowerInPlace(std::string& str); +}; + + +} // namespace Poco + + +#endif // Foundation_UTF8String_INCLUDED diff --git a/Foundation/include/Poco/UnWindows.h b/Foundation/include/Poco/UnWindows.h index 16c62000f..abc32bc64 100644 --- a/Foundation/include/Poco/UnWindows.h +++ b/Foundation/include/Poco/UnWindows.h @@ -1,110 +1,110 @@ -// -// UnWindows.h -// -// $Id: //poco/svn/Foundation/include/Poco/UnWindows.h#2 $ -// -// Library: Foundation -// Package: Core -// Module: UnWindows -// -// A wrapper around the "Poco/UnWindows.h" header file that #undef's some -// of the macros for function names defined by "Poco/UnWindows.h" that -// are a frequent source of conflicts (e.g., GetUserName). -// -// Remember, that most of the WIN32 API functions come in two variants, -// an Unicode variant (e.g., GetUserNameA) and an ASCII variant (GetUserNameW). -// There is also a macro (GetUserName) that's either defined to be the Unicode -// name or the ASCII name, depending on whether the UNICODE macro is #define'd -// or not. POCO always calls the Unicode or ASCII functions directly (depending -// on whether POCO_WIN32_UTF8 is #define'd or not), so the macros are not ignored. -// -// These macro definitions are a frequent case of problems and naming conflicts, -// especially for C++ programmers. Say, you define a class with a member function named -// GetUserName. Depending on whether "Poco/UnWindows.h" has been included by a particular -// translation unit or not, this might be changed to GetUserNameA/GetUserNameW, or not. -// While, due to naming conventions used, this is less of a problem in POCO, some -// of the users of POCO might use a different naming convention where this can become -// a problem. -// -// To disable the #undef's, compile POCO with the POCO_NO_UNWINDOWS macro #define'd. -// -// 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 - - -#if !defined(POCO_NO_UNWINDOWS) -// A list of annoying macros to #undef. -// Feel free to extend as required. -#undef GetBinaryType -#undef GetShortPathName -#undef GetLongPathName -#undef GetEnvironmentStrings -#undef SetEnvironmentStrings -#undef FreeEnvironmentStrings -#undef FormatMessage -#undef EncryptFile -#undef DecryptFile -#undef CreateMutex -#undef OpenMutex -#undef CreateEvent -#undef OpenEvent -#undef CreateSemaphore -#undef OpenSemaphore -#undef LoadLibrary -#undef GetModuleFileName -#undef CreateProcess -#undef GetCommandLine -#undef GetEnvironmentVariable -#undef SetEnvironmentVariable -#undef ExpandEnvironmentStrings -#undef OutputDebugString -#undef FindResource -#undef UpdateResource -#undef FindAtom -#undef AddAtom -#undef GetSystemDirector -#undef GetTempPath -#undef GetTempFileName -#undef SetCurrentDirectory -#undef GetCurrentDirectory -#undef CreateDirectory -#undef RemoveDirectory -#undef CreateFile -#undef DeleteFile -#undef SearchPath -#undef CopyFile -#undef MoveFile -#undef ReplaceFile -#undef GetComputerName -#undef SetComputerName -#undef GetUserName -#undef LogonUser -#undef GetVersion -#undef GetObject -#endif // POCO_NO_UNWINDOWS +// +// UnWindows.h +// +// $Id: //poco/svn/Foundation/include/Poco/UnWindows.h#2 $ +// +// Library: Foundation +// Package: Core +// Module: UnWindows +// +// A wrapper around the "Poco/UnWindows.h" header file that #undef's some +// of the macros for function names defined by "Poco/UnWindows.h" that +// are a frequent source of conflicts (e.g., GetUserName). +// +// Remember, that most of the WIN32 API functions come in two variants, +// an Unicode variant (e.g., GetUserNameA) and an ASCII variant (GetUserNameW). +// There is also a macro (GetUserName) that's either defined to be the Unicode +// name or the ASCII name, depending on whether the UNICODE macro is #define'd +// or not. POCO always calls the Unicode or ASCII functions directly (depending +// on whether POCO_WIN32_UTF8 is #define'd or not), so the macros are not ignored. +// +// These macro definitions are a frequent case of problems and naming conflicts, +// especially for C++ programmers. Say, you define a class with a member function named +// GetUserName. Depending on whether "Poco/UnWindows.h" has been included by a particular +// translation unit or not, this might be changed to GetUserNameA/GetUserNameW, or not. +// While, due to naming conventions used, this is less of a problem in POCO, some +// of the users of POCO might use a different naming convention where this can become +// a problem. +// +// To disable the #undef's, compile POCO with the POCO_NO_UNWINDOWS macro #define'd. +// +// 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 + + +#if !defined(POCO_NO_UNWINDOWS) +// A list of annoying macros to #undef. +// Feel free to extend as required. +#undef GetBinaryType +#undef GetShortPathName +#undef GetLongPathName +#undef GetEnvironmentStrings +#undef SetEnvironmentStrings +#undef FreeEnvironmentStrings +#undef FormatMessage +#undef EncryptFile +#undef DecryptFile +#undef CreateMutex +#undef OpenMutex +#undef CreateEvent +#undef OpenEvent +#undef CreateSemaphore +#undef OpenSemaphore +#undef LoadLibrary +#undef GetModuleFileName +#undef CreateProcess +#undef GetCommandLine +#undef GetEnvironmentVariable +#undef SetEnvironmentVariable +#undef ExpandEnvironmentStrings +#undef OutputDebugString +#undef FindResource +#undef UpdateResource +#undef FindAtom +#undef AddAtom +#undef GetSystemDirector +#undef GetTempPath +#undef GetTempFileName +#undef SetCurrentDirectory +#undef GetCurrentDirectory +#undef CreateDirectory +#undef RemoveDirectory +#undef CreateFile +#undef DeleteFile +#undef SearchPath +#undef CopyFile +#undef MoveFile +#undef ReplaceFile +#undef GetComputerName +#undef SetComputerName +#undef GetUserName +#undef LogonUser +#undef GetVersion +#undef GetObject +#endif // POCO_NO_UNWINDOWS diff --git a/Foundation/include/Poco/Unicode.h b/Foundation/include/Poco/Unicode.h index f7048435e..c5bb112fe 100644 --- a/Foundation/include/Poco/Unicode.h +++ b/Foundation/include/Poco/Unicode.h @@ -1,216 +1,216 @@ -// -// Unicode.h -// -// $Id: //poco/svn/Foundation/include/Poco/Unicode.h#2 $ -// -// Library: Foundation -// Package: Text -// Module: Unicode -// -// Definition of the Unicode 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_Unicode_INCLUDED -#define Foundation_Unicode_INCLUDED - - -#include "Poco/Foundation.h" - - -namespace Poco { - - -class Foundation_API Unicode - /// This class contains enumerations and static - /// utility functions for dealing with Unicode characters - /// and their properties. - /// - /// For more information on Unicode, see . - /// - /// The implementation is based on the Unicode support - /// functions in PCRE. -{ -public: - // Implementation note: the following definitions must be kept - // in sync with those from ucp.h (PCRE). - enum CharacterCategory - /// Unicode 5.0 character categories. - { - UCP_OTHER, - UCP_LETTER, - UCP_MARK, - UCP_NUMBER, - UCP_PUNCTUATION, - UCP_SYMBOL, - UCP_SEPARATOR - }; - - enum CharacterType - /// Unicode 5.0 character types. - { - UCP_CONTROL, - UCP_FORMAT, - UCP_UNASSIGNED, - UCP_PRIVATE_USE, - UCP_SURROGATE, - UCP_LOWER_CASE_LETTER, - UCP_MODIFIER_LETTER, - UCP_OTHER_LETTER, - UCP_TITLE_CASE_LETTER, - UCP_UPPER_CASE_LETTER, - UCP_SPACING_MARK, - UCP_ENCLOSING_MARK, - UCP_NON_SPACING_MARK, - UCP_DECIMAL_NUMBER, - UCP_LETTER_NUMBER, - UCP_OTHER_NUMBER, - UCP_CONNECTOR_PUNCTUATION, - UCP_DASH_PUNCTUATION, - UCP_CLOSE_PUNCTUATION, - UCP_FINAL_PUNCTUATION, - UCP_INITIAL_PUNCTUATION, - UCP_OTHER_PUNCTUATION, - UCP_OPEN_PUNCTUATION, - UCP_CURRENCY_SYMBOL, - UCP_MODIFIER_SYMBOL, - UCP_MATHEMATICAL_SYMBOL, - UCP_OTHER_SYMBOL, - UCP_LINE_SEPARATOR, - UCP_PARAGRAPH_SEPARATOR, - UCP_SPACE_SEPARATOR - }; - - enum Script - /// Unicode 5.0 scripts. - { - UCP_ARABIC, - UCP_ARMENIAN, - UCP_BENGALI, - UCP_BOPOMOFO, - UCP_BRAILLE, - UCP_BUGINESE, - UCP_BUHID, - UCP_CANADIAN_ABORIGINAL, - UCP_CHEROKEE, - UCP_COMMON, - UCP_COPTIC, - UCP_CYPRIOT, - UCP_CYRILLIC, - UCP_DESERET, - UCP_DEVANAGARI, - UCP_ETHIOPIC, - UCP_GEORGIAN, - UCP_GLAGOLITIC, - UCP_GOTHIC, - UCP_GREEK, - UCP_GUJARATI, - UCP_GURMUKHI, - UCP_HAN, - UCP_HANGUL, - UCP_HANUNOO, - UCP_HEBREW, - UCP_HIRAGANA, - UCP_INHERITED, - UCP_KANNADA, - UCP_KATAKANA, - UCP_KHAROSHTHI, - UCP_KHMER, - UCP_LAO, - UCP_LATIN, - UCP_LIMBU, - UCP_LINEAR_B, - UCP_MALAYALAM, - UCP_MONGOLIAN, - UCP_MYANMAR, - UCP_NEW_TAI_LUE, - UCP_OGHAM, - UCP_OLD_ITALIC, - UCP_OLD_PERSIAN, - UCP_ORIYA, - UCP_OSMANYA, - UCP_RUNIC, - UCP_SHAVIAN, - UCP_SINHALA, - UCP_SYLOTI_NAGRI, - UCP_SYRIAC, - UCP_TAGALOG, - UCP_TAGBANWA, - UCP_TAI_LE, - UCP_TAMIL, - UCP_TELUGU, - UCP_THAANA, - UCP_THAI, - UCP_TIBETAN, - UCP_TIFINAGH, - UCP_UGARITIC, - UCP_YI, - UCP_BALINESE, - UCP_CUNEIFORM, - UCP_NKO, - UCP_PHAGS_PA, - UCP_PHOENICIAN - }; - - struct CharacterProperties - /// This structure holds the character properties - /// of an Unicode character. - { - CharacterCategory category; - CharacterType type; - Script script; - }; - - static void properties(int ch, CharacterProperties& props); - /// Return the Unicode character properties for the - /// character with the given Unicode value. - - static bool isLower(int ch); - /// Returns true iff the given character is a lowercase - /// character. - - static bool isUpper(int ch); - /// Returns true iff the given character is an uppercase - /// character. - - static int toLower(int ch); - /// If the given character is an uppercase character, - /// return its lowercase counterpart, otherwise return - /// the character. - - static int toUpper(int ch); - /// If the given character is a lowercase character, - /// return its uppercase counterpart, otherwise return - /// the character. -}; - - -} // namespace Poco - - -#endif // Foundation_Unicode_INCLUDED +// +// Unicode.h +// +// $Id: //poco/svn/Foundation/include/Poco/Unicode.h#2 $ +// +// Library: Foundation +// Package: Text +// Module: Unicode +// +// Definition of the Unicode 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_Unicode_INCLUDED +#define Foundation_Unicode_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +class Foundation_API Unicode + /// This class contains enumerations and static + /// utility functions for dealing with Unicode characters + /// and their properties. + /// + /// For more information on Unicode, see . + /// + /// The implementation is based on the Unicode support + /// functions in PCRE. +{ +public: + // Implementation note: the following definitions must be kept + // in sync with those from ucp.h (PCRE). + enum CharacterCategory + /// Unicode 5.0 character categories. + { + UCP_OTHER, + UCP_LETTER, + UCP_MARK, + UCP_NUMBER, + UCP_PUNCTUATION, + UCP_SYMBOL, + UCP_SEPARATOR + }; + + enum CharacterType + /// Unicode 5.0 character types. + { + UCP_CONTROL, + UCP_FORMAT, + UCP_UNASSIGNED, + UCP_PRIVATE_USE, + UCP_SURROGATE, + UCP_LOWER_CASE_LETTER, + UCP_MODIFIER_LETTER, + UCP_OTHER_LETTER, + UCP_TITLE_CASE_LETTER, + UCP_UPPER_CASE_LETTER, + UCP_SPACING_MARK, + UCP_ENCLOSING_MARK, + UCP_NON_SPACING_MARK, + UCP_DECIMAL_NUMBER, + UCP_LETTER_NUMBER, + UCP_OTHER_NUMBER, + UCP_CONNECTOR_PUNCTUATION, + UCP_DASH_PUNCTUATION, + UCP_CLOSE_PUNCTUATION, + UCP_FINAL_PUNCTUATION, + UCP_INITIAL_PUNCTUATION, + UCP_OTHER_PUNCTUATION, + UCP_OPEN_PUNCTUATION, + UCP_CURRENCY_SYMBOL, + UCP_MODIFIER_SYMBOL, + UCP_MATHEMATICAL_SYMBOL, + UCP_OTHER_SYMBOL, + UCP_LINE_SEPARATOR, + UCP_PARAGRAPH_SEPARATOR, + UCP_SPACE_SEPARATOR + }; + + enum Script + /// Unicode 5.0 scripts. + { + UCP_ARABIC, + UCP_ARMENIAN, + UCP_BENGALI, + UCP_BOPOMOFO, + UCP_BRAILLE, + UCP_BUGINESE, + UCP_BUHID, + UCP_CANADIAN_ABORIGINAL, + UCP_CHEROKEE, + UCP_COMMON, + UCP_COPTIC, + UCP_CYPRIOT, + UCP_CYRILLIC, + UCP_DESERET, + UCP_DEVANAGARI, + UCP_ETHIOPIC, + UCP_GEORGIAN, + UCP_GLAGOLITIC, + UCP_GOTHIC, + UCP_GREEK, + UCP_GUJARATI, + UCP_GURMUKHI, + UCP_HAN, + UCP_HANGUL, + UCP_HANUNOO, + UCP_HEBREW, + UCP_HIRAGANA, + UCP_INHERITED, + UCP_KANNADA, + UCP_KATAKANA, + UCP_KHAROSHTHI, + UCP_KHMER, + UCP_LAO, + UCP_LATIN, + UCP_LIMBU, + UCP_LINEAR_B, + UCP_MALAYALAM, + UCP_MONGOLIAN, + UCP_MYANMAR, + UCP_NEW_TAI_LUE, + UCP_OGHAM, + UCP_OLD_ITALIC, + UCP_OLD_PERSIAN, + UCP_ORIYA, + UCP_OSMANYA, + UCP_RUNIC, + UCP_SHAVIAN, + UCP_SINHALA, + UCP_SYLOTI_NAGRI, + UCP_SYRIAC, + UCP_TAGALOG, + UCP_TAGBANWA, + UCP_TAI_LE, + UCP_TAMIL, + UCP_TELUGU, + UCP_THAANA, + UCP_THAI, + UCP_TIBETAN, + UCP_TIFINAGH, + UCP_UGARITIC, + UCP_YI, + UCP_BALINESE, + UCP_CUNEIFORM, + UCP_NKO, + UCP_PHAGS_PA, + UCP_PHOENICIAN + }; + + struct CharacterProperties + /// This structure holds the character properties + /// of an Unicode character. + { + CharacterCategory category; + CharacterType type; + Script script; + }; + + static void properties(int ch, CharacterProperties& props); + /// Return the Unicode character properties for the + /// character with the given Unicode value. + + static bool isLower(int ch); + /// Returns true iff the given character is a lowercase + /// character. + + static bool isUpper(int ch); + /// Returns true iff the given character is an uppercase + /// character. + + static int toLower(int ch); + /// If the given character is an uppercase character, + /// return its lowercase counterpart, otherwise return + /// the character. + + static int toUpper(int ch); + /// If the given character is a lowercase character, + /// return its uppercase counterpart, otherwise return + /// the character. +}; + + +} // namespace Poco + + +#endif // Foundation_Unicode_INCLUDED diff --git a/Foundation/include/Poco/UniqueAccessExpireCache.h b/Foundation/include/Poco/UniqueAccessExpireCache.h index f30ae9b97..2fe45a38b 100644 --- a/Foundation/include/Poco/UniqueAccessExpireCache.h +++ b/Foundation/include/Poco/UniqueAccessExpireCache.h @@ -1,89 +1,89 @@ -// -// UniqueAccessExpireCache.h -// -// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireCache.h#2 $ -// -// Library: Foundation -// Package: Cache -// Module: UniqueAccessExpireCache -// -// Definition of the UniqueAccessExpireCache class. -// -// Copyright (c) 2006, 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_UniqueAccessExpireCache_INCLUDED -#define Foundation_UniqueAccessExpireCache_INCLUDED - - -#include "Poco/AbstractCache.h" -#include "Poco/UniqueAccessExpireStrategy.h" - - -namespace Poco { - - -template -class UniqueAccessExpireCache: public AbstractCache > - /// An UniqueAccessExpireCache caches entries for a given time span. In contrast - /// to ExpireCache which only allows to set a per cache expiration value, it allows to define - /// expiration per CacheEntry. - /// Each TValue object must thus offer the following method: - /// - /// const Poco::Timespan& getTimeout() const; - /// - /// which returns the relative timespan for how long the entry should be valid without being accessed! - /// The absolute expire timepoint is calculated as now() + getTimeout(). - /// Accessing an object will update this absolute expire timepoint. - /// You can use the Poco::AccessExpirationDecorator to add the getExpiration - /// method to values that do not have a getExpiration function. - /// - /// Be careful when using an UniqueAccessExpireCache. A cache is often used - /// like cache.has(x) followed by cache.get x). Note that it could happen - /// that the "has" call works, then the current execution thread gets descheduled, time passes, - /// the entry gets invalid, thus leading to an empty SharedPtr being returned - /// when "get" is invoked. -{ -public: - UniqueAccessExpireCache(): - AbstractCache >(UniqueAccessExpireStrategy()) - { - } - - ~UniqueAccessExpireCache() - { - } - -private: - UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache); - UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache); -}; - - -} // namespace Poco - -#endif +// +// UniqueAccessExpireCache.h +// +// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireCache.h#2 $ +// +// Library: Foundation +// Package: Cache +// Module: UniqueAccessExpireCache +// +// Definition of the UniqueAccessExpireCache class. +// +// Copyright (c) 2006, 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_UniqueAccessExpireCache_INCLUDED +#define Foundation_UniqueAccessExpireCache_INCLUDED + + +#include "Poco/AbstractCache.h" +#include "Poco/UniqueAccessExpireStrategy.h" + + +namespace Poco { + + +template +class UniqueAccessExpireCache: public AbstractCache > + /// An UniqueAccessExpireCache caches entries for a given time span. In contrast + /// to ExpireCache which only allows to set a per cache expiration value, it allows to define + /// expiration per CacheEntry. + /// Each TValue object must thus offer the following method: + /// + /// const Poco::Timespan& getTimeout() const; + /// + /// which returns the relative timespan for how long the entry should be valid without being accessed! + /// The absolute expire timepoint is calculated as now() + getTimeout(). + /// Accessing an object will update this absolute expire timepoint. + /// You can use the Poco::AccessExpirationDecorator to add the getExpiration + /// method to values that do not have a getExpiration function. + /// + /// Be careful when using an UniqueAccessExpireCache. A cache is often used + /// like cache.has(x) followed by cache.get x). Note that it could happen + /// that the "has" call works, then the current execution thread gets descheduled, time passes, + /// the entry gets invalid, thus leading to an empty SharedPtr being returned + /// when "get" is invoked. +{ +public: + UniqueAccessExpireCache(): + AbstractCache >(UniqueAccessExpireStrategy()) + { + } + + ~UniqueAccessExpireCache() + { + } + +private: + UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache); + UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache); +}; + + +} // namespace Poco + +#endif diff --git a/Foundation/include/Poco/UniqueAccessExpireLRUCache.h b/Foundation/include/Poco/UniqueAccessExpireLRUCache.h index e75438f9c..fb298d226 100644 --- a/Foundation/include/Poco/UniqueAccessExpireLRUCache.h +++ b/Foundation/include/Poco/UniqueAccessExpireLRUCache.h @@ -1,91 +1,91 @@ -// -// UniqueAccessExpireLRUCache.h -// -// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireLRUCache.h#2 $ -// -// Library: Foundation -// Package: Cache -// Module: UniqueAccessExpireLRUCache -// -// Definition of the UniqueAccessExpireLRUCache class. -// -// Copyright (c) 2006, 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_UniqueAccessExpireLRUCache_INCLUDED -#define Foundation_UniqueAccessExpireLRUCache_INCLUDED - - -#include "Poco/AbstractCache.h" -#include "Poco/StrategyCollection.h" -#include "Poco/UniqueAccessExpireStrategy.h" -#include "Poco/LRUStrategy.h" - - -namespace Poco { - - -template < - class TKey, - class TValue -> -class UniqueAccessExpireLRUCache: public AbstractCache > - /// A UniqueAccessExpireLRUCache combines LRU caching and time based per entry expire caching. - /// One can define for each cache entry a seperate timepoint - /// but also limit the size of the cache (per default: 1024). - /// Each TValue object must thus offer the following method: - /// - /// const Poco::Timespan& getTimeout() const; - /// - /// which returns the relative timespan for how long the entry should be valid without being accessed! - /// The absolute expire timepoint is calculated as now() + getTimeout(). - /// Accessing an object will update this absolute expire timepoint. - /// You can use the Poco::AccessExpirationDecorator to add the getExpiration - /// method to values that do not have a getExpiration function. -{ -public: - UniqueAccessExpireLRUCache(long cacheSize = 1024): - AbstractCache >(StrategyCollection()) - { - this->_strategy.pushBack(new LRUStrategy(cacheSize)); - this->_strategy.pushBack(new UniqueAccessExpireStrategy()); - } - - ~UniqueAccessExpireLRUCache() - { - } - -private: - UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache); - UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache); -}; - - -} // namespace Poco - - -#endif +// +// UniqueAccessExpireLRUCache.h +// +// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireLRUCache.h#2 $ +// +// Library: Foundation +// Package: Cache +// Module: UniqueAccessExpireLRUCache +// +// Definition of the UniqueAccessExpireLRUCache class. +// +// Copyright (c) 2006, 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_UniqueAccessExpireLRUCache_INCLUDED +#define Foundation_UniqueAccessExpireLRUCache_INCLUDED + + +#include "Poco/AbstractCache.h" +#include "Poco/StrategyCollection.h" +#include "Poco/UniqueAccessExpireStrategy.h" +#include "Poco/LRUStrategy.h" + + +namespace Poco { + + +template < + class TKey, + class TValue +> +class UniqueAccessExpireLRUCache: public AbstractCache > + /// A UniqueAccessExpireLRUCache combines LRU caching and time based per entry expire caching. + /// One can define for each cache entry a seperate timepoint + /// but also limit the size of the cache (per default: 1024). + /// Each TValue object must thus offer the following method: + /// + /// const Poco::Timespan& getTimeout() const; + /// + /// which returns the relative timespan for how long the entry should be valid without being accessed! + /// The absolute expire timepoint is calculated as now() + getTimeout(). + /// Accessing an object will update this absolute expire timepoint. + /// You can use the Poco::AccessExpirationDecorator to add the getExpiration + /// method to values that do not have a getExpiration function. +{ +public: + UniqueAccessExpireLRUCache(long cacheSize = 1024): + AbstractCache >(StrategyCollection()) + { + this->_strategy.pushBack(new LRUStrategy(cacheSize)); + this->_strategy.pushBack(new UniqueAccessExpireStrategy()); + } + + ~UniqueAccessExpireLRUCache() + { + } + +private: + UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache); + UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache); +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/UniqueAccessExpireStrategy.h b/Foundation/include/Poco/UniqueAccessExpireStrategy.h index 67d423bb9..2acb53c61 100644 --- a/Foundation/include/Poco/UniqueAccessExpireStrategy.h +++ b/Foundation/include/Poco/UniqueAccessExpireStrategy.h @@ -1,178 +1,178 @@ -// -// UniqueAccessExpireStrategy.h -// -// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireStrategy.h#3 $ -// -// Library: Foundation -// Package: Cache -// Module: UniqueAccessExpireStrategy -// -// Definition of the UniqueAccessExpireStrategy class. -// -// Copyright (c) 2006, 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_UniqueAccessExpireStrategy_INCLUDED -#define Foundation_UniqueAccessExpireStrategy_INCLUDED - -#include "Poco/KeyValueArgs.h" -#include "Poco/ValidArgs.h" -#include "Poco/AbstractStrategy.h" -#include "Poco/Bugcheck.h" -#include "Poco/Timestamp.h" -#include "Poco/Timespan.h" -#include "Poco/EventArgs.h" -#include "Poco/UniqueExpireStrategy.h" -#include -#include -#include - - -namespace Poco { - - - -template < - class TKey, - class TValue -> -class UniqueAccessExpireStrategy: public AbstractStrategy - /// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast - /// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define - /// expiration per CacheEntry. - /// Each TValue object must thus offer the following method: - /// - /// const Poco::Timestamp& getTimeout() const; - /// - /// which returns the timespan for how long an object will be valid without being accessed. -{ -public: - typedef std::pair KeyExpire; - typedef std::multimap TimeIndex; - typedef typename TimeIndex::iterator IndexIterator; - typedef typename TimeIndex::const_iterator ConstIndexIterator; - typedef std::map Keys; - typedef typename Keys::iterator Iterator; - -public: - UniqueAccessExpireStrategy() - /// Create an unique expire strategy. - { - } - - ~UniqueAccessExpireStrategy() - { - } - - void onAdd(const void*, const KeyValueArgs & args) - { - // the expire value defines how many millisecs in the future the - // value will expire, even insert negative values! - Timestamp expire; - expire += args.value().getTimeout().totalMicroseconds(); - - IndexIterator it = _keyIndex.insert(std::make_pair(expire, std::make_pair(args.key(), args.value().getTimeout()))); - std::pair stat = _keys.insert(std::make_pair(args.key(), it)); - if (!stat.second) - { - _keyIndex.erase(stat.first->second); - stat.first->second = it; - } - } - - void onRemove(const void*, const TKey& key) - { - Iterator it = _keys.find(key); - if (it != _keys.end()) - { - _keyIndex.erase(it->second); - _keys.erase(it); - } - } - - void onGet(const void*, const TKey& key) - { - // get updates the expiration time stamp - Iterator it = _keys.find(key); - if (it != _keys.end()) - { - KeyExpire ke = it->second->second; - // gen new absolute expire value - Timestamp expire; - expire += ke.second.totalMicroseconds(); - // delete old index - _keyIndex.erase(it->second); - IndexIterator itt = _keyIndex.insert(std::make_pair(expire, ke)); - // update iterator - it->second = itt; - } - } - - void onClear(const void*, const EventArgs& args) - { - _keys.clear(); - _keyIndex.clear(); - } - - void onIsValid(const void*, ValidArgs& args) - { - Iterator it = _keys.find(args.key()); - if (it != _keys.end()) - { - Timestamp now; - if (it->second->first <= now) - { - args.invalidate(); - } - } - else //not found: probably removed by onReplace - args.invalidate(); - } - - void onReplace(const void*, std::set& elemsToRemove) - { - // Note: replace only informs the cache which elements - // it would like to remove! - // it does not remove them on its own! - IndexIterator it = _keyIndex.begin(); - Timestamp now; - while (it != _keyIndex.end() && it->first < now) - { - elemsToRemove.insert(it->second.first); - ++it; - } - } - -protected: - Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map - TimeIndex _keyIndex; /// Maps time to key value -}; - - -} // namespace Poco - -#endif +// +// UniqueAccessExpireStrategy.h +// +// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireStrategy.h#3 $ +// +// Library: Foundation +// Package: Cache +// Module: UniqueAccessExpireStrategy +// +// Definition of the UniqueAccessExpireStrategy class. +// +// Copyright (c) 2006, 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_UniqueAccessExpireStrategy_INCLUDED +#define Foundation_UniqueAccessExpireStrategy_INCLUDED + +#include "Poco/KeyValueArgs.h" +#include "Poco/ValidArgs.h" +#include "Poco/AbstractStrategy.h" +#include "Poco/Bugcheck.h" +#include "Poco/Timestamp.h" +#include "Poco/Timespan.h" +#include "Poco/EventArgs.h" +#include "Poco/UniqueExpireStrategy.h" +#include +#include +#include + + +namespace Poco { + + + +template < + class TKey, + class TValue +> +class UniqueAccessExpireStrategy: public AbstractStrategy + /// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast + /// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define + /// expiration per CacheEntry. + /// Each TValue object must thus offer the following method: + /// + /// const Poco::Timestamp& getTimeout() const; + /// + /// which returns the timespan for how long an object will be valid without being accessed. +{ +public: + typedef std::pair KeyExpire; + typedef std::multimap TimeIndex; + typedef typename TimeIndex::iterator IndexIterator; + typedef typename TimeIndex::const_iterator ConstIndexIterator; + typedef std::map Keys; + typedef typename Keys::iterator Iterator; + +public: + UniqueAccessExpireStrategy() + /// Create an unique expire strategy. + { + } + + ~UniqueAccessExpireStrategy() + { + } + + void onAdd(const void*, const KeyValueArgs & args) + { + // the expire value defines how many millisecs in the future the + // value will expire, even insert negative values! + Timestamp expire; + expire += args.value().getTimeout().totalMicroseconds(); + + IndexIterator it = _keyIndex.insert(std::make_pair(expire, std::make_pair(args.key(), args.value().getTimeout()))); + std::pair stat = _keys.insert(std::make_pair(args.key(), it)); + if (!stat.second) + { + _keyIndex.erase(stat.first->second); + stat.first->second = it; + } + } + + void onRemove(const void*, const TKey& key) + { + Iterator it = _keys.find(key); + if (it != _keys.end()) + { + _keyIndex.erase(it->second); + _keys.erase(it); + } + } + + void onGet(const void*, const TKey& key) + { + // get updates the expiration time stamp + Iterator it = _keys.find(key); + if (it != _keys.end()) + { + KeyExpire ke = it->second->second; + // gen new absolute expire value + Timestamp expire; + expire += ke.second.totalMicroseconds(); + // delete old index + _keyIndex.erase(it->second); + IndexIterator itt = _keyIndex.insert(std::make_pair(expire, ke)); + // update iterator + it->second = itt; + } + } + + void onClear(const void*, const EventArgs& args) + { + _keys.clear(); + _keyIndex.clear(); + } + + void onIsValid(const void*, ValidArgs& args) + { + Iterator it = _keys.find(args.key()); + if (it != _keys.end()) + { + Timestamp now; + if (it->second->first <= now) + { + args.invalidate(); + } + } + else //not found: probably removed by onReplace + args.invalidate(); + } + + void onReplace(const void*, std::set& elemsToRemove) + { + // Note: replace only informs the cache which elements + // it would like to remove! + // it does not remove them on its own! + IndexIterator it = _keyIndex.begin(); + Timestamp now; + while (it != _keyIndex.end() && it->first < now) + { + elemsToRemove.insert(it->second.first); + ++it; + } + } + +protected: + Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map + TimeIndex _keyIndex; /// Maps time to key value +}; + + +} // namespace Poco + +#endif diff --git a/Foundation/include/Poco/UniqueExpireCache.h b/Foundation/include/Poco/UniqueExpireCache.h index 366af7d40..15e86d1d0 100644 --- a/Foundation/include/Poco/UniqueExpireCache.h +++ b/Foundation/include/Poco/UniqueExpireCache.h @@ -1,89 +1,89 @@ -// -// UniqueExpireCache.h -// -// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireCache.h#2 $ -// -// Library: Foundation -// Package: Cache -// Module: UniqueExpireCache -// -// Definition of the UniqueExpireCache class. -// -// Copyright (c) 2006, 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_UniqueExpireCache_INCLUDED -#define Foundation_UniqueExpireCache_INCLUDED - - -#include "Poco/AbstractCache.h" -#include "Poco/UniqueExpireStrategy.h" - - -namespace Poco { - - -template -class UniqueExpireCache: public AbstractCache > - /// An UniqueExpireCache caches entries for a given time amount. In contrast - /// to ExpireCache which only allows to set a per cache expiration value, it allows to define - /// expiration per CacheEntry. - /// Each TValue object must thus offer the following method: - /// - /// const Poco::Timestamp& getExpiration() const; - /// - /// which returns the absolute timepoint when the entry will be invalidated. - /// Accessing an object will NOT update this absolute expire timepoint. - /// You can use the Poco::ExpirationDecorator to add the getExpiration - /// method to values that do not have a getExpiration function. - /// - /// Be careful when using an UniqueExpireCache. A cache is often used - /// like cache.has(x) followed by cache.get x). Note that it could happen - /// that the "has" call works, then the current execution thread gets descheduled, time passes, - /// the entry gets invalid, thus leading to an empty SharedPtr being returned - /// when "get" is invoked. -{ -public: - UniqueExpireCache(): - AbstractCache >(UniqueExpireStrategy()) - { - } - - ~UniqueExpireCache() - { - } - -private: - UniqueExpireCache(const UniqueExpireCache& aCache); - UniqueExpireCache& operator = (const UniqueExpireCache& aCache); -}; - - -} // namespace Poco - - -#endif +// +// UniqueExpireCache.h +// +// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireCache.h#2 $ +// +// Library: Foundation +// Package: Cache +// Module: UniqueExpireCache +// +// Definition of the UniqueExpireCache class. +// +// Copyright (c) 2006, 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_UniqueExpireCache_INCLUDED +#define Foundation_UniqueExpireCache_INCLUDED + + +#include "Poco/AbstractCache.h" +#include "Poco/UniqueExpireStrategy.h" + + +namespace Poco { + + +template +class UniqueExpireCache: public AbstractCache > + /// An UniqueExpireCache caches entries for a given time amount. In contrast + /// to ExpireCache which only allows to set a per cache expiration value, it allows to define + /// expiration per CacheEntry. + /// Each TValue object must thus offer the following method: + /// + /// const Poco::Timestamp& getExpiration() const; + /// + /// which returns the absolute timepoint when the entry will be invalidated. + /// Accessing an object will NOT update this absolute expire timepoint. + /// You can use the Poco::ExpirationDecorator to add the getExpiration + /// method to values that do not have a getExpiration function. + /// + /// Be careful when using an UniqueExpireCache. A cache is often used + /// like cache.has(x) followed by cache.get x). Note that it could happen + /// that the "has" call works, then the current execution thread gets descheduled, time passes, + /// the entry gets invalid, thus leading to an empty SharedPtr being returned + /// when "get" is invoked. +{ +public: + UniqueExpireCache(): + AbstractCache >(UniqueExpireStrategy()) + { + } + + ~UniqueExpireCache() + { + } + +private: + UniqueExpireCache(const UniqueExpireCache& aCache); + UniqueExpireCache& operator = (const UniqueExpireCache& aCache); +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/UniqueExpireLRUCache.h b/Foundation/include/Poco/UniqueExpireLRUCache.h index 63a328f90..01f2ce365 100644 --- a/Foundation/include/Poco/UniqueExpireLRUCache.h +++ b/Foundation/include/Poco/UniqueExpireLRUCache.h @@ -1,90 +1,90 @@ -// -// UniqueExpireLRUCache.h -// -// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireLRUCache.h#2 $ -// -// Library: Foundation -// Package: Cache -// Module: UniqueExpireLRUCache -// -// Definition of the UniqueExpireLRUCache class. -// -// Copyright (c) 2006, 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_UniqueExpireLRUCache_INCLUDED -#define Foundation_UniqueExpireLRUCache_INCLUDED - - -#include "Poco/AbstractCache.h" -#include "Poco/StrategyCollection.h" -#include "Poco/UniqueExpireStrategy.h" -#include "Poco/LRUStrategy.h" - - -namespace Poco { - - -template < - class TKey, - class TValue -> -class UniqueExpireLRUCache: public AbstractCache > - /// A UniqueExpireLRUCache combines LRU caching and time based per entry expire caching. - /// One can define for each cache entry a seperate timepoint - /// but also limit the size of the cache (per default: 1024). - /// Each TValue object must thus offer the following method: - /// - /// const Poco::Timestamp& getExpiration() const; - /// - /// which returns the absolute timepoint when the entry will be invalidated. - /// Accessing an object will NOT update this absolute expire timepoint. - /// You can use the Poco::ExpirationDecorator to add the getExpiration - /// method to values that do not have a getExpiration function. -{ -public: - UniqueExpireLRUCache(long cacheSize = 1024): - AbstractCache >(StrategyCollection()) - { - this->_strategy.pushBack(new LRUStrategy(cacheSize)); - this->_strategy.pushBack(new UniqueExpireStrategy()); - } - - ~UniqueExpireLRUCache() - { - } - -private: - UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache); - UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache); -}; - - -} // namespace Poco - - -#endif +// +// UniqueExpireLRUCache.h +// +// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireLRUCache.h#2 $ +// +// Library: Foundation +// Package: Cache +// Module: UniqueExpireLRUCache +// +// Definition of the UniqueExpireLRUCache class. +// +// Copyright (c) 2006, 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_UniqueExpireLRUCache_INCLUDED +#define Foundation_UniqueExpireLRUCache_INCLUDED + + +#include "Poco/AbstractCache.h" +#include "Poco/StrategyCollection.h" +#include "Poco/UniqueExpireStrategy.h" +#include "Poco/LRUStrategy.h" + + +namespace Poco { + + +template < + class TKey, + class TValue +> +class UniqueExpireLRUCache: public AbstractCache > + /// A UniqueExpireLRUCache combines LRU caching and time based per entry expire caching. + /// One can define for each cache entry a seperate timepoint + /// but also limit the size of the cache (per default: 1024). + /// Each TValue object must thus offer the following method: + /// + /// const Poco::Timestamp& getExpiration() const; + /// + /// which returns the absolute timepoint when the entry will be invalidated. + /// Accessing an object will NOT update this absolute expire timepoint. + /// You can use the Poco::ExpirationDecorator to add the getExpiration + /// method to values that do not have a getExpiration function. +{ +public: + UniqueExpireLRUCache(long cacheSize = 1024): + AbstractCache >(StrategyCollection()) + { + this->_strategy.pushBack(new LRUStrategy(cacheSize)); + this->_strategy.pushBack(new UniqueExpireStrategy()); + } + + ~UniqueExpireLRUCache() + { + } + +private: + UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache); + UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache); +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/UniqueExpireStrategy.h b/Foundation/include/Poco/UniqueExpireStrategy.h index b5017799d..137642c77 100644 --- a/Foundation/include/Poco/UniqueExpireStrategy.h +++ b/Foundation/include/Poco/UniqueExpireStrategy.h @@ -1,160 +1,160 @@ -// -// UniqueExpireStrategy.h -// -// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireStrategy.h#3 $ -// -// Library: Foundation -// Package: Cache -// Module: UniqueExpireStrategy -// -// Definition of the UniqueExpireStrategy class. -// -// Copyright (c) 2006, 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_UniqueExpireStrategy_INCLUDED -#define Foundation_UniqueExpireStrategy_INCLUDED - - -#include "Poco/KeyValueArgs.h" -#include "Poco/ValidArgs.h" -#include "Poco/AbstractStrategy.h" -#include "Poco/Bugcheck.h" -#include "Poco/Timestamp.h" -#include "Poco/EventArgs.h" -#include -#include - - -namespace Poco { - - -template < - class TKey, - class TValue -> -class UniqueExpireStrategy: public AbstractStrategy - /// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast - /// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define - /// expiration per CacheEntry. - /// Each TValue object must thus offer the following method: - /// - /// const Poco::Timestamp& getExpiration() const; - /// - /// which returns the absolute timepoint when the entry will be invalidated. -{ -public: - typedef std::multimap TimeIndex; - typedef typename TimeIndex::iterator IndexIterator; - typedef typename TimeIndex::const_iterator ConstIndexIterator; - typedef std::map Keys; - typedef typename Keys::iterator Iterator; - -public: - UniqueExpireStrategy() - /// Create an unique expire strategy. - { - } - - ~UniqueExpireStrategy() - { - } - - void onAdd(const void*, const KeyValueArgs & args) - { - // note: we have to insert even if the expire timepoint is in the past (for StrategyCollection classes to avoid inconsistency with LRU) - // no problem: will be removed with next get - const Timestamp& expire = args.value().getExpiration(); - IndexIterator it = _keyIndex.insert(std::make_pair(expire, args.key())); - std::pair stat = _keys.insert(std::make_pair(args.key(), it)); - if (!stat.second) - { - _keyIndex.erase(stat.first->second); - stat.first->second = it; - } - } - - void onRemove(const void*, const TKey& key) - { - Iterator it = _keys.find(key); - if (it != _keys.end()) - { - _keyIndex.erase(it->second); - _keys.erase(it); - } - } - - void onGet(const void*, const TKey& key) - { - // get triggers no changes in an expire - } - - void onClear(const void*, const EventArgs& args) - { - _keys.clear(); - _keyIndex.clear(); - } - - void onIsValid(const void*, ValidArgs& args) - { - Iterator it = _keys.find(args.key()); - if (it != _keys.end()) - { - Timestamp now; - if (it->second->first <= now) - { - args.invalidate(); - } - } - else //not found: probably removed by onReplace - args.invalidate(); - } - - void onReplace(const void*, std::set& elemsToRemove) - { - // Note: replace only informs the cache which elements - // it would like to remove! - // it does not remove them on its own! - IndexIterator it = _keyIndex.begin(); - Timestamp now; - while (it != _keyIndex.end() && it->first < now) - { - elemsToRemove.insert(it->second); - ++it; - } - } - -protected: - Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map - TimeIndex _keyIndex; /// Maps time to key value -}; - - -} // namespace Poco - - -#endif +// +// UniqueExpireStrategy.h +// +// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireStrategy.h#3 $ +// +// Library: Foundation +// Package: Cache +// Module: UniqueExpireStrategy +// +// Definition of the UniqueExpireStrategy class. +// +// Copyright (c) 2006, 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_UniqueExpireStrategy_INCLUDED +#define Foundation_UniqueExpireStrategy_INCLUDED + + +#include "Poco/KeyValueArgs.h" +#include "Poco/ValidArgs.h" +#include "Poco/AbstractStrategy.h" +#include "Poco/Bugcheck.h" +#include "Poco/Timestamp.h" +#include "Poco/EventArgs.h" +#include +#include + + +namespace Poco { + + +template < + class TKey, + class TValue +> +class UniqueExpireStrategy: public AbstractStrategy + /// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast + /// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define + /// expiration per CacheEntry. + /// Each TValue object must thus offer the following method: + /// + /// const Poco::Timestamp& getExpiration() const; + /// + /// which returns the absolute timepoint when the entry will be invalidated. +{ +public: + typedef std::multimap TimeIndex; + typedef typename TimeIndex::iterator IndexIterator; + typedef typename TimeIndex::const_iterator ConstIndexIterator; + typedef std::map Keys; + typedef typename Keys::iterator Iterator; + +public: + UniqueExpireStrategy() + /// Create an unique expire strategy. + { + } + + ~UniqueExpireStrategy() + { + } + + void onAdd(const void*, const KeyValueArgs & args) + { + // note: we have to insert even if the expire timepoint is in the past (for StrategyCollection classes to avoid inconsistency with LRU) + // no problem: will be removed with next get + const Timestamp& expire = args.value().getExpiration(); + IndexIterator it = _keyIndex.insert(std::make_pair(expire, args.key())); + std::pair stat = _keys.insert(std::make_pair(args.key(), it)); + if (!stat.second) + { + _keyIndex.erase(stat.first->second); + stat.first->second = it; + } + } + + void onRemove(const void*, const TKey& key) + { + Iterator it = _keys.find(key); + if (it != _keys.end()) + { + _keyIndex.erase(it->second); + _keys.erase(it); + } + } + + void onGet(const void*, const TKey& key) + { + // get triggers no changes in an expire + } + + void onClear(const void*, const EventArgs& args) + { + _keys.clear(); + _keyIndex.clear(); + } + + void onIsValid(const void*, ValidArgs& args) + { + Iterator it = _keys.find(args.key()); + if (it != _keys.end()) + { + Timestamp now; + if (it->second->first <= now) + { + args.invalidate(); + } + } + else //not found: probably removed by onReplace + args.invalidate(); + } + + void onReplace(const void*, std::set& elemsToRemove) + { + // Note: replace only informs the cache which elements + // it would like to remove! + // it does not remove them on its own! + IndexIterator it = _keyIndex.begin(); + Timestamp now; + while (it != _keyIndex.end() && it->first < now) + { + elemsToRemove.insert(it->second); + ++it; + } + } + +protected: + Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map + TimeIndex _keyIndex; /// Maps time to key value +}; + + +} // namespace Poco + + +#endif diff --git a/Foundation/include/Poco/WindowsConsoleChannel.h b/Foundation/include/Poco/WindowsConsoleChannel.h index 080ac9e52..83ff4254a 100644 --- a/Foundation/include/Poco/WindowsConsoleChannel.h +++ b/Foundation/include/Poco/WindowsConsoleChannel.h @@ -1,89 +1,89 @@ -// -// WindowsConsoleChannel.h -// -// $Id: //poco/svn/Foundation/include/Poco/WindowsConsoleChannel.h#2 $ -// -// Library: Foundation -// Package: Logging -// Module: WindowsConsoleChannel -// -// Definition of the WindowsConsoleChannel 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_WindowsConsoleChannel_INCLUDED -#define Foundation_WindowsConsoleChannel_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/Channel.h" -#include "Poco/Mutex.h" -#include "Poco/UnWindows.h" - - -namespace Poco { - - -class Foundation_API WindowsConsoleChannel: public Channel - /// A channel that writes to the Windows console. - /// - /// Only the message's text is written, followed - /// by a newline. - /// - /// If POCO has been compiled with POCO_WIN32_UTF8, - /// log messages are assumed to be UTF-8 encoded, and - /// are converted to UTF-16 prior to writing them to the - /// console. This is the main difference to the ConsoleChannel - /// class, which cannot handle UTF-8 encoded messages on Windows. - /// - /// Chain this channel to a FormattingChannel with an - /// appropriate Formatter to control what is contained - /// in the text. - /// - /// Only available on Windows platforms. -{ -public: - WindowsConsoleChannel(); - /// Creates the WindowsConsoleChannel. - - void log(const Message& msg); - /// Logs the given message to the channel's stream. - -protected: - ~WindowsConsoleChannel(); - -private: - HANDLE _hConsole; - bool _isFile; -}; - - -} // namespace Poco - - -#endif // Foundation_WindowsConsoleChannel_INCLUDED +// +// WindowsConsoleChannel.h +// +// $Id: //poco/svn/Foundation/include/Poco/WindowsConsoleChannel.h#2 $ +// +// Library: Foundation +// Package: Logging +// Module: WindowsConsoleChannel +// +// Definition of the WindowsConsoleChannel 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_WindowsConsoleChannel_INCLUDED +#define Foundation_WindowsConsoleChannel_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Channel.h" +#include "Poco/Mutex.h" +#include "Poco/UnWindows.h" + + +namespace Poco { + + +class Foundation_API WindowsConsoleChannel: public Channel + /// A channel that writes to the Windows console. + /// + /// Only the message's text is written, followed + /// by a newline. + /// + /// If POCO has been compiled with POCO_WIN32_UTF8, + /// log messages are assumed to be UTF-8 encoded, and + /// are converted to UTF-16 prior to writing them to the + /// console. This is the main difference to the ConsoleChannel + /// class, which cannot handle UTF-8 encoded messages on Windows. + /// + /// Chain this channel to a FormattingChannel with an + /// appropriate Formatter to control what is contained + /// in the text. + /// + /// Only available on Windows platforms. +{ +public: + WindowsConsoleChannel(); + /// Creates the WindowsConsoleChannel. + + void log(const Message& msg); + /// Logs the given message to the channel's stream. + +protected: + ~WindowsConsoleChannel(); + +private: + HANDLE _hConsole; + bool _isFile; +}; + + +} // namespace Poco + + +#endif // Foundation_WindowsConsoleChannel_INCLUDED diff --git a/Foundation/src/AsyncIOChannel.cpp b/Foundation/src/AsyncIOChannel.cpp index 4c9ea2194..e942622c7 100644 --- a/Foundation/src/AsyncIOChannel.cpp +++ b/Foundation/src/AsyncIOChannel.cpp @@ -1,79 +1,79 @@ -// -// AsyncIOChannel.cpp -// -// $Id: //poco/svn/Foundation/src/AsyncIOChannel.cpp#2 $ -// -// Library: Foundation -// Package: AsyncIO -// Module: AsyncIOChannel -// -// 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/AsyncIOChannel.h" - - -namespace Poco { - - -AsyncIOChannel::AsyncIOChannel(): - enqueue(this, &AsyncIOChannel::enqueueImpl) -{ -} - - -AsyncIOChannel::~AsyncIOChannel() -{ -} - - -int AsyncIOChannel::enqueueImpl(const AsyncIOCommand::Ptr& pCommand) -{ - AsyncIOCommand::Ptr ptr(pCommand); - return ptr->execute(*this); -} - - -int AsyncIOChannel::write(const void* buffer, int length) -{ - throw NotImplementedException("write()"); -} - - -int AsyncIOChannel::read(void* buffer, int length) -{ - throw NotImplementedException("read()"); -} - - -int AsyncIOChannel::seek(std::streamoff off, std::ios::seekdir dir) -{ - throw NotImplementedException("seek()"); -} - - -} // namespace Poco +// +// AsyncIOChannel.cpp +// +// $Id: //poco/svn/Foundation/src/AsyncIOChannel.cpp#2 $ +// +// Library: Foundation +// Package: AsyncIO +// Module: AsyncIOChannel +// +// 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/AsyncIOChannel.h" + + +namespace Poco { + + +AsyncIOChannel::AsyncIOChannel(): + enqueue(this, &AsyncIOChannel::enqueueImpl) +{ +} + + +AsyncIOChannel::~AsyncIOChannel() +{ +} + + +int AsyncIOChannel::enqueueImpl(const AsyncIOCommand::Ptr& pCommand) +{ + AsyncIOCommand::Ptr ptr(pCommand); + return ptr->execute(*this); +} + + +int AsyncIOChannel::write(const void* buffer, int length) +{ + throw NotImplementedException("write()"); +} + + +int AsyncIOChannel::read(void* buffer, int length) +{ + throw NotImplementedException("read()"); +} + + +int AsyncIOChannel::seek(std::streamoff off, std::ios::seekdir dir) +{ + throw NotImplementedException("seek()"); +} + + +} // namespace Poco diff --git a/Foundation/src/AsyncIOCommand.cpp b/Foundation/src/AsyncIOCommand.cpp index e097d4f21..c68b4464a 100644 --- a/Foundation/src/AsyncIOCommand.cpp +++ b/Foundation/src/AsyncIOCommand.cpp @@ -1,236 +1,236 @@ -// -// AsyncIOCommand.cpp -// -// $Id: //poco/svn/Foundation/src/AsyncIOCommand.cpp#2 $ -// -// Library: Foundation -// Package: AsyncIO -// Module: AsyncIOCommand -// -// 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/AsyncIOCommand.h" -#include "Poco/AsyncIOChannel.h" -#include "Poco/AsyncIOEvent.h" -#include - - -namespace Poco { - - -// -// AsyncIOCommand -// - - -AsyncIOCommand::AsyncIOCommand(): - _state(CMD_PENDING), - _result(0), - _pException(0) -{ -} - - -AsyncIOCommand::~AsyncIOCommand() -{ - delete _pException; -} - - -void AsyncIOCommand::wait() -{ - _completed.wait(); -} - - -void AsyncIOCommand::wait(long milliseconds) -{ - _completed.wait(milliseconds); -} - - -bool AsyncIOCommand::tryWait(long milliseconds) -{ - return _completed.tryWait(milliseconds); -} - - -int AsyncIOCommand::execute(AsyncIOChannel& channel) -{ - delete _pException; - _pException = 0; - - _state = CMD_IN_PROGRESS; - try - { - _result = executeImpl(channel); - _state = CMD_COMPLETED; - _completed.set(); - AsyncIOEvent completedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_COMPLETED); - commandCompleted(this, completedEvent); - channel.commandCompleted(this, completedEvent); - return _result; - } - catch (Exception& exc) - { - _pException = exc.clone(); - _state = CMD_FAILED; - _completed.set(); - AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED); - commandFailed(this, failedEvent); - channel.commandFailed(this, failedEvent); - throw; - } - catch (std::exception& exc) - { - _pException = new Exception(exc.what()); - _state = CMD_FAILED; - _completed.set(); - AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED); - commandFailed(this, failedEvent); - channel.commandFailed(this, failedEvent); - throw; - } - catch (...) - { - _pException = new Exception("Unknown exception"); - _state = CMD_FAILED; - _completed.set(); - AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED); - commandFailed(this, failedEvent); - channel.commandFailed(this, failedEvent); - throw; - } -} - - -// -// AsyncWriteCommand -// - - -AsyncWriteCommand::AsyncWriteCommand(const void* buffer, int length): - _buffer(buffer), - _length(length) -{ -} - - -AsyncWriteCommand::~AsyncWriteCommand() -{ -} - - -int AsyncWriteCommand::executeImpl(AsyncIOChannel& channel) -{ - return channel.write(_buffer, _length); -} - - -// -// AsyncBufferedWriteCommand -// - - -AsyncBufferedWriteCommand::AsyncBufferedWriteCommand(const void* buf, int length): - AsyncWriteCommand(new char[length], length) -{ - std::memcpy(const_cast(buffer()), buf, length); -} - - -AsyncBufferedWriteCommand::~AsyncBufferedWriteCommand() -{ - delete [] reinterpret_cast(buffer()); -} - - -// -// AsyncReadCommand -// - - -AsyncReadCommand::AsyncReadCommand(void* buffer, int length): - _buffer(buffer), - _length(length) -{ -} - - -AsyncReadCommand::~AsyncReadCommand() -{ -} - - -int AsyncReadCommand::executeImpl(AsyncIOChannel& channel) -{ - return channel.read(_buffer, _length); -} - - -// -// AsyncBufferedReadCommand -// - - -AsyncBufferedReadCommand::AsyncBufferedReadCommand(int length): - AsyncReadCommand(new char[length], length) -{ -} - - -AsyncBufferedReadCommand::~AsyncBufferedReadCommand() -{ - delete [] reinterpret_cast(buffer()); -} - - -// -// AsyncSeekCommand -// - - -AsyncSeekCommand::AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir): - _off(off), - _dir(dir) -{ -} - - -AsyncSeekCommand::~AsyncSeekCommand() -{ -} - - -int AsyncSeekCommand::executeImpl(AsyncIOChannel& channel) -{ - return channel.seek(_off, _dir); -} - - -} // namespace Poco +// +// AsyncIOCommand.cpp +// +// $Id: //poco/svn/Foundation/src/AsyncIOCommand.cpp#2 $ +// +// Library: Foundation +// Package: AsyncIO +// Module: AsyncIOCommand +// +// 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/AsyncIOCommand.h" +#include "Poco/AsyncIOChannel.h" +#include "Poco/AsyncIOEvent.h" +#include + + +namespace Poco { + + +// +// AsyncIOCommand +// + + +AsyncIOCommand::AsyncIOCommand(): + _state(CMD_PENDING), + _result(0), + _pException(0) +{ +} + + +AsyncIOCommand::~AsyncIOCommand() +{ + delete _pException; +} + + +void AsyncIOCommand::wait() +{ + _completed.wait(); +} + + +void AsyncIOCommand::wait(long milliseconds) +{ + _completed.wait(milliseconds); +} + + +bool AsyncIOCommand::tryWait(long milliseconds) +{ + return _completed.tryWait(milliseconds); +} + + +int AsyncIOCommand::execute(AsyncIOChannel& channel) +{ + delete _pException; + _pException = 0; + + _state = CMD_IN_PROGRESS; + try + { + _result = executeImpl(channel); + _state = CMD_COMPLETED; + _completed.set(); + AsyncIOEvent completedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_COMPLETED); + commandCompleted(this, completedEvent); + channel.commandCompleted(this, completedEvent); + return _result; + } + catch (Exception& exc) + { + _pException = exc.clone(); + _state = CMD_FAILED; + _completed.set(); + AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED); + commandFailed(this, failedEvent); + channel.commandFailed(this, failedEvent); + throw; + } + catch (std::exception& exc) + { + _pException = new Exception(exc.what()); + _state = CMD_FAILED; + _completed.set(); + AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED); + commandFailed(this, failedEvent); + channel.commandFailed(this, failedEvent); + throw; + } + catch (...) + { + _pException = new Exception("Unknown exception"); + _state = CMD_FAILED; + _completed.set(); + AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED); + commandFailed(this, failedEvent); + channel.commandFailed(this, failedEvent); + throw; + } +} + + +// +// AsyncWriteCommand +// + + +AsyncWriteCommand::AsyncWriteCommand(const void* buffer, int length): + _buffer(buffer), + _length(length) +{ +} + + +AsyncWriteCommand::~AsyncWriteCommand() +{ +} + + +int AsyncWriteCommand::executeImpl(AsyncIOChannel& channel) +{ + return channel.write(_buffer, _length); +} + + +// +// AsyncBufferedWriteCommand +// + + +AsyncBufferedWriteCommand::AsyncBufferedWriteCommand(const void* buf, int length): + AsyncWriteCommand(new char[length], length) +{ + std::memcpy(const_cast(buffer()), buf, length); +} + + +AsyncBufferedWriteCommand::~AsyncBufferedWriteCommand() +{ + delete [] reinterpret_cast(buffer()); +} + + +// +// AsyncReadCommand +// + + +AsyncReadCommand::AsyncReadCommand(void* buffer, int length): + _buffer(buffer), + _length(length) +{ +} + + +AsyncReadCommand::~AsyncReadCommand() +{ +} + + +int AsyncReadCommand::executeImpl(AsyncIOChannel& channel) +{ + return channel.read(_buffer, _length); +} + + +// +// AsyncBufferedReadCommand +// + + +AsyncBufferedReadCommand::AsyncBufferedReadCommand(int length): + AsyncReadCommand(new char[length], length) +{ +} + + +AsyncBufferedReadCommand::~AsyncBufferedReadCommand() +{ + delete [] reinterpret_cast(buffer()); +} + + +// +// AsyncSeekCommand +// + + +AsyncSeekCommand::AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir): + _off(off), + _dir(dir) +{ +} + + +AsyncSeekCommand::~AsyncSeekCommand() +{ +} + + +int AsyncSeekCommand::executeImpl(AsyncIOChannel& channel) +{ + return channel.seek(_off, _dir); +} + + +} // namespace Poco diff --git a/Foundation/src/AsyncIOEvent.cpp b/Foundation/src/AsyncIOEvent.cpp index 48a70dfd7..5299c237c 100644 --- a/Foundation/src/AsyncIOEvent.cpp +++ b/Foundation/src/AsyncIOEvent.cpp @@ -1,88 +1,88 @@ -// -// AsyncIOEvent.cpp -// -// $Id: //poco/svn/Foundation/src/AsyncIOEvent.cpp#2 $ -// -// Library: Foundation -// Package: AsyncIO -// Module: AsyncIOEvent -// -// 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/AsyncIOEvent.h" -#include "Poco/AsyncIOCommand.h" -#include - - -namespace Poco { - - -AsyncIOEvent::AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what): - _pCommand(pCommand), - _pChannel(pChannel), - _what(what) -{ - poco_check_ptr (pCommand); - poco_check_ptr (pChannel); - - _pCommand->duplicate(); -} - - -AsyncIOEvent::AsyncIOEvent(const AsyncIOEvent& event): - _pCommand(event._pCommand), - _pChannel(event._pChannel), - _what(event._what) -{ - _pCommand->duplicate(); -} - - -AsyncIOEvent::~AsyncIOEvent() -{ - _pCommand->release(); -} - - -AsyncIOEvent& AsyncIOEvent::operator = (const AsyncIOEvent& event) -{ - AsyncIOEvent tmp(event); - swap(tmp); - return *this; -} - - -void AsyncIOEvent::swap(AsyncIOEvent& event) -{ - std::swap(_pCommand, event._pCommand); - std::swap(_pChannel, event._pChannel); - std::swap(_what, event._what); -} - - -} // namespace Poco +// +// AsyncIOEvent.cpp +// +// $Id: //poco/svn/Foundation/src/AsyncIOEvent.cpp#2 $ +// +// Library: Foundation +// Package: AsyncIO +// Module: AsyncIOEvent +// +// 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/AsyncIOEvent.h" +#include "Poco/AsyncIOCommand.h" +#include + + +namespace Poco { + + +AsyncIOEvent::AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what): + _pCommand(pCommand), + _pChannel(pChannel), + _what(what) +{ + poco_check_ptr (pCommand); + poco_check_ptr (pChannel); + + _pCommand->duplicate(); +} + + +AsyncIOEvent::AsyncIOEvent(const AsyncIOEvent& event): + _pCommand(event._pCommand), + _pChannel(event._pChannel), + _what(event._what) +{ + _pCommand->duplicate(); +} + + +AsyncIOEvent::~AsyncIOEvent() +{ + _pCommand->release(); +} + + +AsyncIOEvent& AsyncIOEvent::operator = (const AsyncIOEvent& event) +{ + AsyncIOEvent tmp(event); + swap(tmp); + return *this; +} + + +void AsyncIOEvent::swap(AsyncIOEvent& event) +{ + std::swap(_pCommand, event._pCommand); + std::swap(_pChannel, event._pChannel); + std::swap(_what, event._what); +} + + +} // namespace Poco diff --git a/Foundation/src/AsyncStreamChannel.cpp b/Foundation/src/AsyncStreamChannel.cpp index 54f8ab620..d7bf42227 100644 --- a/Foundation/src/AsyncStreamChannel.cpp +++ b/Foundation/src/AsyncStreamChannel.cpp @@ -1,100 +1,100 @@ -// -// AsyncStreamChannel.cpp -// -// $Id: //poco/svn/Foundation/src/AsyncStreamChannel.cpp#2 $ -// -// Library: Foundation -// Package: AsyncIO -// Module: AsyncStreamChannel -// -// 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/AsyncStreamChannel.h" -#include "Poco/Exception.h" - - -namespace Poco { - - -AsyncStreamChannel::AsyncStreamChannel(std::istream& istr): - _pIstr(&istr), - _pOstr(0) -{ -} - - -AsyncStreamChannel::AsyncStreamChannel(std::ostream& ostr): - _pIstr(0), - _pOstr(&ostr) -{ -} - - -AsyncStreamChannel::AsyncStreamChannel(std::iostream& iostr): - _pIstr(&iostr), - _pOstr(&iostr) -{ -} - - -AsyncStreamChannel::~AsyncStreamChannel() -{ -} - - -int AsyncStreamChannel::write(const void* buffer, int length) -{ - if (_pOstr) - { - _pOstr->write(reinterpret_cast(buffer), length); - return length; - } - else throw IOException("Cannot write to an input stream"); -} - - -int AsyncStreamChannel::read(void* buffer, int length) -{ - if (_pIstr) - return static_cast(_pIstr->read(reinterpret_cast(buffer), length).gcount()); - else - throw IOException("Cannot read from an output stream"); -} - - -int AsyncStreamChannel::seek(std::streamoff off, std::ios::seekdir dir) -{ - if (_pIstr) - _pIstr->seekg(off, dir); - if (_pOstr) - _pOstr->seekp(off, dir); - return 0; -} - - -} // namespace Poco +// +// AsyncStreamChannel.cpp +// +// $Id: //poco/svn/Foundation/src/AsyncStreamChannel.cpp#2 $ +// +// Library: Foundation +// Package: AsyncIO +// Module: AsyncStreamChannel +// +// 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/AsyncStreamChannel.h" +#include "Poco/Exception.h" + + +namespace Poco { + + +AsyncStreamChannel::AsyncStreamChannel(std::istream& istr): + _pIstr(&istr), + _pOstr(0) +{ +} + + +AsyncStreamChannel::AsyncStreamChannel(std::ostream& ostr): + _pIstr(0), + _pOstr(&ostr) +{ +} + + +AsyncStreamChannel::AsyncStreamChannel(std::iostream& iostr): + _pIstr(&iostr), + _pOstr(&iostr) +{ +} + + +AsyncStreamChannel::~AsyncStreamChannel() +{ +} + + +int AsyncStreamChannel::write(const void* buffer, int length) +{ + if (_pOstr) + { + _pOstr->write(reinterpret_cast(buffer), length); + return length; + } + else throw IOException("Cannot write to an input stream"); +} + + +int AsyncStreamChannel::read(void* buffer, int length) +{ + if (_pIstr) + return static_cast(_pIstr->read(reinterpret_cast(buffer), length).gcount()); + else + throw IOException("Cannot read from an output stream"); +} + + +int AsyncStreamChannel::seek(std::streamoff off, std::ios::seekdir dir) +{ + if (_pIstr) + _pIstr->seekg(off, dir); + if (_pOstr) + _pOstr->seekp(off, dir); + return 0; +} + + +} // namespace Poco diff --git a/Foundation/src/Checksum.cpp b/Foundation/src/Checksum.cpp index 719a2d724..d4156a0e3 100644 --- a/Foundation/src/Checksum.cpp +++ b/Foundation/src/Checksum.cpp @@ -1,76 +1,76 @@ -// -// Checksum.cpp -// -// $Id: //poco/svn/Foundation/src/Checksum.cpp#2 $ -// -// Library: Foundation -// Package: Core -// Module: Checksum -// -// 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/Checksum.h" -#include "Poco/zlib.h" - - -namespace Poco { - - -Checksum::Checksum(): - _type(TYPE_CRC32), - _value(crc32(0L, Z_NULL, 0)) -{ -} - - -Checksum::Checksum(Type t): - _type(t), - _value(0) -{ - if (t == TYPE_CRC32) - _value = crc32(0L, Z_NULL, 0); - else - _value = adler32(0L, Z_NULL, 0); -} - - -Checksum::~Checksum() -{ -} - - -void Checksum::update(const char* data, unsigned length) -{ - if (_type == TYPE_ADLER32) - _value = adler32(_value, reinterpret_cast(data), length); - else - _value = crc32(_value, reinterpret_cast(data), length); -} - - -} // namespace Poco +// +// Checksum.cpp +// +// $Id: //poco/svn/Foundation/src/Checksum.cpp#2 $ +// +// Library: Foundation +// Package: Core +// Module: Checksum +// +// 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/Checksum.h" +#include "Poco/zlib.h" + + +namespace Poco { + + +Checksum::Checksum(): + _type(TYPE_CRC32), + _value(crc32(0L, Z_NULL, 0)) +{ +} + + +Checksum::Checksum(Type t): + _type(t), + _value(0) +{ + if (t == TYPE_CRC32) + _value = crc32(0L, Z_NULL, 0); + else + _value = adler32(0L, Z_NULL, 0); +} + + +Checksum::~Checksum() +{ +} + + +void Checksum::update(const char* data, unsigned length) +{ + if (_type == TYPE_ADLER32) + _value = adler32(_value, reinterpret_cast(data), length); + else + _value = crc32(_value, reinterpret_cast(data), length); +} + + +} // namespace Poco diff --git a/Foundation/src/Condition.cpp b/Foundation/src/Condition.cpp index 6702cd3ae..c653580ad 100644 --- a/Foundation/src/Condition.cpp +++ b/Foundation/src/Condition.cpp @@ -1,101 +1,101 @@ -// -// Condition.cpp -// -// $Id: //poco/svn/Foundation/src/Condition.cpp#2 $ -// -// Library: Foundation -// Package: Threading -// Module: Condition -// -// 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/Condition.h" - - -namespace Poco { - - -Condition::Condition() -{ -} - -Condition::~Condition() -{ -} - - -void Condition::signal() -{ - FastMutex::ScopedLock lock(_mutex); - - if (!_waitQueue.empty()) - { - _waitQueue.front()->set(); - dequeue(); - } -} - - -void Condition::broadcast() -{ - FastMutex::ScopedLock lock(_mutex); - - for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it) - { - (*it)->set(); - } - _waitQueue.clear(); -} - - -void Condition::enqueue(Event& event) -{ - _waitQueue.push_back(&event); -} - - -void Condition::dequeue() -{ - _waitQueue.pop_front(); -} - - -void Condition::dequeue(Event& event) -{ - for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it) - { - if (*it == &event) - { - _waitQueue.erase(it); - break; - } - } -} - - -} // namespace Poco +// +// Condition.cpp +// +// $Id: //poco/svn/Foundation/src/Condition.cpp#2 $ +// +// Library: Foundation +// Package: Threading +// Module: Condition +// +// 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/Condition.h" + + +namespace Poco { + + +Condition::Condition() +{ +} + +Condition::~Condition() +{ +} + + +void Condition::signal() +{ + FastMutex::ScopedLock lock(_mutex); + + if (!_waitQueue.empty()) + { + _waitQueue.front()->set(); + dequeue(); + } +} + + +void Condition::broadcast() +{ + FastMutex::ScopedLock lock(_mutex); + + for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it) + { + (*it)->set(); + } + _waitQueue.clear(); +} + + +void Condition::enqueue(Event& event) +{ + _waitQueue.push_back(&event); +} + + +void Condition::dequeue() +{ + _waitQueue.pop_front(); +} + + +void Condition::dequeue(Event& event) +{ + for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it) + { + if (*it == &event) + { + _waitQueue.erase(it); + break; + } + } +} + + +} // namespace Poco diff --git a/Foundation/src/DynamicAny.cpp b/Foundation/src/DynamicAny.cpp index d9fb10d89..104f91141 100644 --- a/Foundation/src/DynamicAny.cpp +++ b/Foundation/src/DynamicAny.cpp @@ -1,408 +1,408 @@ -// -// DynamicAny.cpp -// -// $Id: //poco/svn/Foundation/src/DynamicAny.cpp#3 $ -// -// Library: Foundation -// Package: Core -// Module: DynamicAny -// -// 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/DynamicAny.h" -#include "Poco/DynamicStruct.h" -#include -#include - - -namespace Poco { - - -DynamicAny::DynamicAny(): - _pHolder(new DynamicAnyHolderImpl(0)) -{ -} - - -DynamicAny::DynamicAny(const char* pVal): - _pHolder(new DynamicAnyHolderImpl(pVal)) -{ -} - - -DynamicAny::DynamicAny(const DynamicAny& other): - _pHolder(0) -{ - if (other._pHolder) - _pHolder = other._pHolder->clone(); -} - - -DynamicAny::~DynamicAny() -{ - delete _pHolder; -} - - -DynamicAny& DynamicAny::operator = (const DynamicAny& other) -{ - DynamicAny tmp(other); - swap(tmp); - return *this; -} - - -const DynamicAny DynamicAny::operator + (const DynamicAny& other) const -{ - if (isInteger()) - { - if(isSigned()) - return add(other); - else - return add(other); - } - else if (isNumeric()) - return add(other); - else if (isString()) - return add(other); - else - throw InvalidArgumentException("Invalid operation for this data type."); -} - - -DynamicAny& DynamicAny::operator += (const DynamicAny& other) -{ - if (isInteger()) - { - if(isSigned()) - return *this = add(other); - else - return *this = add(other); - } - else if (isNumeric()) - return *this = add(other); - else if (isString()) - return *this = add(other); - else - throw InvalidArgumentException("Invalid operation for this data type."); -} - - -const DynamicAny DynamicAny::operator - (const DynamicAny& other) const -{ - if (isInteger()) - { - if(isSigned()) - return subtract(other); - else - return subtract(other); - } - else if (isNumeric()) - return subtract(other); - else - throw InvalidArgumentException("Invalid operation for this data type."); -} - - -DynamicAny& DynamicAny::operator -= (const DynamicAny& other) -{ - if (isInteger()) - { - if(isSigned()) - return *this = subtract(other); - else - return *this = subtract(other); - } - else if (isNumeric()) - return *this = subtract(other); - else - throw InvalidArgumentException("Invalid operation for this data type."); -} - - -const DynamicAny DynamicAny::operator * (const DynamicAny& other) const -{ - if (isInteger()) - { - if(isSigned()) - return multiply(other); - else - return multiply(other); - } - else if (isNumeric()) - return multiply(other); - else - throw InvalidArgumentException("Invalid operation for this data type."); -} - - -DynamicAny& DynamicAny::operator *= (const DynamicAny& other) -{ - if (isInteger()) - { - if(isSigned()) - return *this = multiply(other); - else - return *this = multiply(other); - } - else if (isNumeric()) - return *this = multiply(other); - else - throw InvalidArgumentException("Invalid operation for this data type."); -} - - -const DynamicAny DynamicAny::operator / (const DynamicAny& other) const -{ - if (isInteger()) - { - if(isSigned()) - return divide(other); - else - return divide(other); - } - else if (isNumeric()) - return divide(other); - else - throw InvalidArgumentException("Invalid operation for this data type."); -} - - -DynamicAny& DynamicAny::operator /= (const DynamicAny& other) -{ - if (isInteger()) - { - if(isSigned()) - return *this = divide(other); - else - return *this = divide(other); - } - else if (isNumeric()) - return *this = divide(other); - else - throw InvalidArgumentException("Invalid operation for this data type."); -} - - -DynamicAny& DynamicAny::operator ++ () -{ - if (!isInteger()) - throw InvalidArgumentException("Invalid operation for this data type."); - - return *this = *this + 1; -} - -DynamicAny DynamicAny::operator ++ (int) -{ - if (!isInteger()) - throw InvalidArgumentException("Invalid operation for this data type."); - - DynamicAny tmp(*this); - *this += 1; - return tmp; -} - -DynamicAny& DynamicAny::operator -- () -{ - if (!isInteger()) - throw InvalidArgumentException("Invalid operation for this data type."); - - return *this = *this - 1; -} - -DynamicAny DynamicAny::operator -- (int) -{ - if (!isInteger()) - throw InvalidArgumentException("Invalid operation for this data type."); - - DynamicAny tmp(*this); - *this -= 1; - return tmp; -} - - -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; -} - - -} // namespace Poco::Poco +// +// DynamicAny.cpp +// +// $Id: //poco/svn/Foundation/src/DynamicAny.cpp#3 $ +// +// Library: Foundation +// Package: Core +// Module: DynamicAny +// +// 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/DynamicAny.h" +#include "Poco/DynamicStruct.h" +#include +#include + + +namespace Poco { + + +DynamicAny::DynamicAny(): + _pHolder(new DynamicAnyHolderImpl(0)) +{ +} + + +DynamicAny::DynamicAny(const char* pVal): + _pHolder(new DynamicAnyHolderImpl(pVal)) +{ +} + + +DynamicAny::DynamicAny(const DynamicAny& other): + _pHolder(0) +{ + if (other._pHolder) + _pHolder = other._pHolder->clone(); +} + + +DynamicAny::~DynamicAny() +{ + delete _pHolder; +} + + +DynamicAny& DynamicAny::operator = (const DynamicAny& other) +{ + DynamicAny tmp(other); + swap(tmp); + return *this; +} + + +const DynamicAny DynamicAny::operator + (const DynamicAny& other) const +{ + if (isInteger()) + { + if(isSigned()) + return add(other); + else + return add(other); + } + else if (isNumeric()) + return add(other); + else if (isString()) + return add(other); + else + throw InvalidArgumentException("Invalid operation for this data type."); +} + + +DynamicAny& DynamicAny::operator += (const DynamicAny& other) +{ + if (isInteger()) + { + if(isSigned()) + return *this = add(other); + else + return *this = add(other); + } + else if (isNumeric()) + return *this = add(other); + else if (isString()) + return *this = add(other); + else + throw InvalidArgumentException("Invalid operation for this data type."); +} + + +const DynamicAny DynamicAny::operator - (const DynamicAny& other) const +{ + if (isInteger()) + { + if(isSigned()) + return subtract(other); + else + return subtract(other); + } + else if (isNumeric()) + return subtract(other); + else + throw InvalidArgumentException("Invalid operation for this data type."); +} + + +DynamicAny& DynamicAny::operator -= (const DynamicAny& other) +{ + if (isInteger()) + { + if(isSigned()) + return *this = subtract(other); + else + return *this = subtract(other); + } + else if (isNumeric()) + return *this = subtract(other); + else + throw InvalidArgumentException("Invalid operation for this data type."); +} + + +const DynamicAny DynamicAny::operator * (const DynamicAny& other) const +{ + if (isInteger()) + { + if(isSigned()) + return multiply(other); + else + return multiply(other); + } + else if (isNumeric()) + return multiply(other); + else + throw InvalidArgumentException("Invalid operation for this data type."); +} + + +DynamicAny& DynamicAny::operator *= (const DynamicAny& other) +{ + if (isInteger()) + { + if(isSigned()) + return *this = multiply(other); + else + return *this = multiply(other); + } + else if (isNumeric()) + return *this = multiply(other); + else + throw InvalidArgumentException("Invalid operation for this data type."); +} + + +const DynamicAny DynamicAny::operator / (const DynamicAny& other) const +{ + if (isInteger()) + { + if(isSigned()) + return divide(other); + else + return divide(other); + } + else if (isNumeric()) + return divide(other); + else + throw InvalidArgumentException("Invalid operation for this data type."); +} + + +DynamicAny& DynamicAny::operator /= (const DynamicAny& other) +{ + if (isInteger()) + { + if(isSigned()) + return *this = divide(other); + else + return *this = divide(other); + } + else if (isNumeric()) + return *this = divide(other); + else + throw InvalidArgumentException("Invalid operation for this data type."); +} + + +DynamicAny& DynamicAny::operator ++ () +{ + if (!isInteger()) + throw InvalidArgumentException("Invalid operation for this data type."); + + return *this = *this + 1; +} + +DynamicAny DynamicAny::operator ++ (int) +{ + if (!isInteger()) + throw InvalidArgumentException("Invalid operation for this data type."); + + DynamicAny tmp(*this); + *this += 1; + return tmp; +} + +DynamicAny& DynamicAny::operator -- () +{ + if (!isInteger()) + throw InvalidArgumentException("Invalid operation for this data type."); + + return *this = *this - 1; +} + +DynamicAny DynamicAny::operator -- (int) +{ + if (!isInteger()) + throw InvalidArgumentException("Invalid operation for this data type."); + + DynamicAny tmp(*this); + *this -= 1; + return tmp; +} + + +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; +} + + +} // namespace Poco::Poco diff --git a/Foundation/src/DynamicAnyHolder.cpp b/Foundation/src/DynamicAnyHolder.cpp index 3274296c8..c63c6f927 100644 --- a/Foundation/src/DynamicAnyHolder.cpp +++ b/Foundation/src/DynamicAnyHolder.cpp @@ -1,69 +1,69 @@ -// -// DynamicAnyHolder.cpp -// -// $Id: //poco/svn/Foundation/src/DynamicAnyHolder.cpp#3 $ -// -// Library: Foundation -// Package: Core -// Module: DynamicAnyHolder -// -// 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/DynamicAnyHolder.h" -#include "Poco/DynamicAny.h" - - -namespace Poco { - - -DynamicAnyHolder::DynamicAnyHolder() -{ -} - - -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 +// +// DynamicAnyHolder.cpp +// +// $Id: //poco/svn/Foundation/src/DynamicAnyHolder.cpp#3 $ +// +// Library: Foundation +// Package: Core +// Module: DynamicAnyHolder +// +// 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/DynamicAnyHolder.h" +#include "Poco/DynamicAny.h" + + +namespace Poco { + + +DynamicAnyHolder::DynamicAnyHolder() +{ +} + + +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 index ee6abb90a..6fa982896 100644 --- a/Foundation/src/DynamicStruct.cpp +++ b/Foundation/src/DynamicStruct.cpp @@ -1,81 +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 +// +// 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/FileStream.cpp b/Foundation/src/FileStream.cpp index e45742f2c..03446ee96 100644 --- a/Foundation/src/FileStream.cpp +++ b/Foundation/src/FileStream.cpp @@ -1,140 +1,140 @@ -// -// FileStream.cpp -// -// $Id: //poco/svn/Foundation/src/FileStream.cpp#2 $ -// -// Library: Foundation -// Package: Streams -// Module: FileStream -// -// 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/FileStream.h" -#include "Poco/Exception.h" -#if defined(POCO_OS_FAMILY_WINDOWS) -#include "FileStream_WIN32.cpp" -#else -#include "FileStream_POSIX.cpp" -#endif - - -namespace Poco { - - -FileIOS::FileIOS(std::ios::openmode defaultMode): - _defaultMode(defaultMode) -{ - poco_ios_init(&_buf); -} - - -FileIOS::~FileIOS() -{ -} - - -void FileIOS::open(const std::string& path, std::ios::openmode mode) -{ - clear(); - _buf.open(path, mode | _defaultMode); -} - - -void FileIOS::close() -{ - _buf.close(); -} - - -FileStreamBuf* FileIOS::rdbuf() -{ - return &_buf; -} - - -FileInputStream::FileInputStream(): - FileIOS(std::ios::in), - std::istream(&_buf) -{ -} - - -FileInputStream::FileInputStream(const std::string& path, std::ios::openmode mode): - FileIOS(std::ios::in), - std::istream(&_buf) -{ - open(path, mode); -} - - -FileInputStream::~FileInputStream() -{ -} - - -FileOutputStream::FileOutputStream(): - FileIOS(std::ios::out), - std::ostream(&_buf) -{ -} - - -FileOutputStream::FileOutputStream(const std::string& path, std::ios::openmode mode): - FileIOS(std::ios::out), - std::ostream(&_buf) -{ - open(path, mode); -} - - -FileOutputStream::~FileOutputStream() -{ -} - - -FileStream::FileStream(): - FileIOS(std::ios::in | std::ios::out), - std::iostream(&_buf) -{ -} - - -FileStream::FileStream(const std::string& path, std::ios::openmode mode): - FileIOS(std::ios::in | std::ios::out), - std::iostream(&_buf) -{ - open(path, mode); -} - - -FileStream::~FileStream() -{ -} - - -} // namespace Poco +// +// FileStream.cpp +// +// $Id: //poco/svn/Foundation/src/FileStream.cpp#2 $ +// +// Library: Foundation +// Package: Streams +// Module: FileStream +// +// 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/FileStream.h" +#include "Poco/Exception.h" +#if defined(POCO_OS_FAMILY_WINDOWS) +#include "FileStream_WIN32.cpp" +#else +#include "FileStream_POSIX.cpp" +#endif + + +namespace Poco { + + +FileIOS::FileIOS(std::ios::openmode defaultMode): + _defaultMode(defaultMode) +{ + poco_ios_init(&_buf); +} + + +FileIOS::~FileIOS() +{ +} + + +void FileIOS::open(const std::string& path, std::ios::openmode mode) +{ + clear(); + _buf.open(path, mode | _defaultMode); +} + + +void FileIOS::close() +{ + _buf.close(); +} + + +FileStreamBuf* FileIOS::rdbuf() +{ + return &_buf; +} + + +FileInputStream::FileInputStream(): + FileIOS(std::ios::in), + std::istream(&_buf) +{ +} + + +FileInputStream::FileInputStream(const std::string& path, std::ios::openmode mode): + FileIOS(std::ios::in), + std::istream(&_buf) +{ + open(path, mode); +} + + +FileInputStream::~FileInputStream() +{ +} + + +FileOutputStream::FileOutputStream(): + FileIOS(std::ios::out), + std::ostream(&_buf) +{ +} + + +FileOutputStream::FileOutputStream(const std::string& path, std::ios::openmode mode): + FileIOS(std::ios::out), + std::ostream(&_buf) +{ + open(path, mode); +} + + +FileOutputStream::~FileOutputStream() +{ +} + + +FileStream::FileStream(): + FileIOS(std::ios::in | std::ios::out), + std::iostream(&_buf) +{ +} + + +FileStream::FileStream(const std::string& path, std::ios::openmode mode): + FileIOS(std::ios::in | std::ios::out), + std::iostream(&_buf) +{ + open(path, mode); +} + + +FileStream::~FileStream() +{ +} + + +} // namespace Poco diff --git a/Foundation/src/FileStream_POSIX.cpp b/Foundation/src/FileStream_POSIX.cpp index c78050427..4c388de70 100644 --- a/Foundation/src/FileStream_POSIX.cpp +++ b/Foundation/src/FileStream_POSIX.cpp @@ -1,183 +1,183 @@ -// -// FileStream_POSIX.cpp -// -// $Id: //poco/svn/Foundation/src/FileStream_POSIX.cpp#2 $ -// -// Library: Foundation -// Package: Streams -// Module: FileStream -// -// 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/FileStream.h" -#include "Poco/File.h" -#include "Poco/Exception.h" -#include -#include -#include -#include - - -namespace Poco { - - -FileStreamBuf::FileStreamBuf(): - BufferedBidirectionalStreamBuf(BUFFER_SIZE, std::ios::in | std::ios::out), - _fd(-1), - _pos(0) -{ -} - - -FileStreamBuf::~FileStreamBuf() -{ - try - { - close(); - } - catch (...) - { - } -} - - -void FileStreamBuf::open(const std::string& path, std::ios::openmode mode) -{ - poco_assert (_fd == -1); - - _path = path; - setMode(mode); - - int flags(0); - if (mode & std::ios::trunc) - flags |= O_TRUNC; - if (mode & std::ios::app) - flags |= O_APPEND; - if (mode & std::ios::out) - flags |= O_CREAT; - if ((mode & std::ios::in) && (mode & std::ios::out)) - flags |= O_RDWR; - else if (mode & std::ios::in) - flags |= O_RDONLY; - else - flags |= O_WRONLY; - - _fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP); - if (_fd == -1) - File::handleLastError(_path); - - if ((mode & std::ios::app) || (mode & std::ios::ate)) - seekoff(0, std::ios::end, mode); -} - - -int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length) -{ - if (_fd == -1) return -1; - - if (getMode() & std::ios::out) - sync(); - - int n = read(_fd, buffer, length); - if (n == -1) - File::handleLastError(_path); - _pos += n; - return n; -} - - -int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length) -{ - if (_fd == -1) return -1; - - int n = write(_fd, buffer, length); - if (n == -1) - File::handleLastError(_path); - _pos += n; - return n; -} - - -void FileStreamBuf::close() -{ - if (_fd != -1) - { - sync(); - ::close(_fd); - _fd = -1; - } -} - - -std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode) -{ - if (_fd == -1 || !(getMode() & mode)) - return -1; - - if (getMode() & std::ios::out) - sync(); - - std::streamoff adj; - if (mode & std::ios::in) - adj = static_cast(egptr() - gptr()); - else - adj = 0; - - resetBuffers(); - - int whence = SEEK_SET; - if (dir == std::ios::cur) - { - whence = SEEK_CUR; - off -= adj; - } - else if (dir == std::ios::end) - { - whence = SEEK_END; - } - _pos = lseek(_fd, off, whence); - return _pos; -} - - -std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode) -{ - if (_fd == -1 || !(getMode() & mode)) - return -1; - - if (getMode() & std::ios::out) - sync(); - - resetBuffers(); - - _pos = lseek(_fd, pos, SEEK_SET); - return _pos; -} - - -} // namespace Poco +// +// FileStream_POSIX.cpp +// +// $Id: //poco/svn/Foundation/src/FileStream_POSIX.cpp#2 $ +// +// Library: Foundation +// Package: Streams +// Module: FileStream +// +// 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/FileStream.h" +#include "Poco/File.h" +#include "Poco/Exception.h" +#include +#include +#include +#include + + +namespace Poco { + + +FileStreamBuf::FileStreamBuf(): + BufferedBidirectionalStreamBuf(BUFFER_SIZE, std::ios::in | std::ios::out), + _fd(-1), + _pos(0) +{ +} + + +FileStreamBuf::~FileStreamBuf() +{ + try + { + close(); + } + catch (...) + { + } +} + + +void FileStreamBuf::open(const std::string& path, std::ios::openmode mode) +{ + poco_assert (_fd == -1); + + _path = path; + setMode(mode); + + int flags(0); + if (mode & std::ios::trunc) + flags |= O_TRUNC; + if (mode & std::ios::app) + flags |= O_APPEND; + if (mode & std::ios::out) + flags |= O_CREAT; + if ((mode & std::ios::in) && (mode & std::ios::out)) + flags |= O_RDWR; + else if (mode & std::ios::in) + flags |= O_RDONLY; + else + flags |= O_WRONLY; + + _fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP); + if (_fd == -1) + File::handleLastError(_path); + + if ((mode & std::ios::app) || (mode & std::ios::ate)) + seekoff(0, std::ios::end, mode); +} + + +int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length) +{ + if (_fd == -1) return -1; + + if (getMode() & std::ios::out) + sync(); + + int n = read(_fd, buffer, length); + if (n == -1) + File::handleLastError(_path); + _pos += n; + return n; +} + + +int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length) +{ + if (_fd == -1) return -1; + + int n = write(_fd, buffer, length); + if (n == -1) + File::handleLastError(_path); + _pos += n; + return n; +} + + +void FileStreamBuf::close() +{ + if (_fd != -1) + { + sync(); + ::close(_fd); + _fd = -1; + } +} + + +std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode) +{ + if (_fd == -1 || !(getMode() & mode)) + return -1; + + if (getMode() & std::ios::out) + sync(); + + std::streamoff adj; + if (mode & std::ios::in) + adj = static_cast(egptr() - gptr()); + else + adj = 0; + + resetBuffers(); + + int whence = SEEK_SET; + if (dir == std::ios::cur) + { + whence = SEEK_CUR; + off -= adj; + } + else if (dir == std::ios::end) + { + whence = SEEK_END; + } + _pos = lseek(_fd, off, whence); + return _pos; +} + + +std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode) +{ + if (_fd == -1 || !(getMode() & mode)) + return -1; + + if (getMode() & std::ios::out) + sync(); + + resetBuffers(); + + _pos = lseek(_fd, pos, SEEK_SET); + return _pos; +} + + +} // namespace Poco diff --git a/Foundation/src/FileStream_WIN32.cpp b/Foundation/src/FileStream_WIN32.cpp index 5ce244162..c8ea1c3a4 100644 --- a/Foundation/src/FileStream_WIN32.cpp +++ b/Foundation/src/FileStream_WIN32.cpp @@ -1,223 +1,223 @@ -// -// FileStream.cpp -// -// $Id: //poco/svn/Foundation/src/FileStream_WIN32.cpp#2 $ -// -// Library: Foundation -// Package: Streams -// Module: FileStream -// -// 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/FileStream.h" -#include "Poco/File.h" -#include "Poco/Exception.h" -#if defined (POCO_WIN32_UTF8) -#include "Poco/UnicodeConverter.h" -#endif - - -namespace Poco { - - -FileStreamBuf::FileStreamBuf(): - BufferedBidirectionalStreamBuf(BUFFER_SIZE, 0), - _handle(INVALID_HANDLE_VALUE), - _pos(0) -{ -} - - -FileStreamBuf::~FileStreamBuf() -{ - try - { - close(); - } - catch (...) - { - } -} - - -void FileStreamBuf::open(const std::string& path, std::ios::openmode mode) -{ - poco_assert (_handle == INVALID_HANDLE_VALUE); - - _path = path; - setMode(mode); - - DWORD access = 0; - if (mode & std::ios::in) - access |= GENERIC_READ; - if (mode & std::ios::out) - access |= GENERIC_WRITE; - - DWORD shareMode = FILE_SHARE_READ; - DWORD creationDisp = OPEN_EXISTING; - if (mode & std::ios::trunc) - creationDisp = CREATE_ALWAYS; - else if (mode & std::ios::out) - creationDisp = OPEN_ALWAYS; - - DWORD flags = FILE_ATTRIBUTE_NORMAL; - -#if defined (POCO_WIN32_UTF8) - std::wstring utf16Path; - UnicodeConverter::toUTF16(path, utf16Path); - _handle = CreateFileW(utf16Path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL); -#else - _handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL); -#endif - - if (_handle == INVALID_HANDLE_VALUE) - File::handleLastError(_path); - - if ((mode & std::ios::ate) || (mode & std::ios::app)) - seekoff(0, std::ios::end, mode); -} - - -int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length) -{ - if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::in)) - return -1; - - if (getMode() & std::ios::out) - sync(); - - DWORD bytesRead(0); - BOOL rc = ReadFile(_handle, buffer, static_cast(length), &bytesRead, NULL); - if (rc == 0) - File::handleLastError(_path); - - _pos += bytesRead; - - return static_cast(bytesRead); -} - - -int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length) -{ - if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::out)) - return -1; - - if (getMode() & std::ios::app) - { - LARGE_INTEGER li; - li.QuadPart = 0; - li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_END); - if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) - File::handleLastError(_path); - _pos = li.QuadPart; - } - - DWORD bytesWritten(0); - BOOL rc = WriteFile(_handle, buffer, static_cast(length), &bytesWritten, NULL); - if (rc == 0) - File::handleLastError(_path); - - _pos += bytesWritten; - - return static_cast(bytesWritten); -} - - -void FileStreamBuf::close() -{ - if (_handle != INVALID_HANDLE_VALUE) - { - if (getMode() & std::ios::out) - sync(); - - CloseHandle(_handle); - _handle = INVALID_HANDLE_VALUE; - } -} - - -std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode) -{ - if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode)) - return -1; - - if (getMode() & std::ios::out) - sync(); - - std::streamoff adj; - if (mode & std::ios::in) - adj = static_cast(egptr() - gptr()); - else - adj = 0; - - resetBuffers(); - - DWORD offset = FILE_BEGIN; - if (dir == std::ios::cur) - { - offset = FILE_CURRENT; - off -= adj; - } - else if (dir == std::ios::end) - { - offset = FILE_END; - } - - LARGE_INTEGER li; - li.QuadPart = off; - li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, offset); - - if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) - File::handleLastError(_path); - _pos = li.QuadPart; - return std::streampos(static_cast(_pos)); -} - - -std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode) -{ - if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode)) - return -1; - - if (getMode() & std::ios::out) - sync(); - - resetBuffers(); - - LARGE_INTEGER li; - li.QuadPart = pos; - li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_BEGIN); - - if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) - File::handleLastError(_path); - _pos = li.QuadPart; - return std::streampos(static_cast(_pos)); -} - - -} // namespace Poco +// +// FileStream.cpp +// +// $Id: //poco/svn/Foundation/src/FileStream_WIN32.cpp#2 $ +// +// Library: Foundation +// Package: Streams +// Module: FileStream +// +// 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/FileStream.h" +#include "Poco/File.h" +#include "Poco/Exception.h" +#if defined (POCO_WIN32_UTF8) +#include "Poco/UnicodeConverter.h" +#endif + + +namespace Poco { + + +FileStreamBuf::FileStreamBuf(): + BufferedBidirectionalStreamBuf(BUFFER_SIZE, 0), + _handle(INVALID_HANDLE_VALUE), + _pos(0) +{ +} + + +FileStreamBuf::~FileStreamBuf() +{ + try + { + close(); + } + catch (...) + { + } +} + + +void FileStreamBuf::open(const std::string& path, std::ios::openmode mode) +{ + poco_assert (_handle == INVALID_HANDLE_VALUE); + + _path = path; + setMode(mode); + + DWORD access = 0; + if (mode & std::ios::in) + access |= GENERIC_READ; + if (mode & std::ios::out) + access |= GENERIC_WRITE; + + DWORD shareMode = FILE_SHARE_READ; + DWORD creationDisp = OPEN_EXISTING; + if (mode & std::ios::trunc) + creationDisp = CREATE_ALWAYS; + else if (mode & std::ios::out) + creationDisp = OPEN_ALWAYS; + + DWORD flags = FILE_ATTRIBUTE_NORMAL; + +#if defined (POCO_WIN32_UTF8) + std::wstring utf16Path; + UnicodeConverter::toUTF16(path, utf16Path); + _handle = CreateFileW(utf16Path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL); +#else + _handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL); +#endif + + if (_handle == INVALID_HANDLE_VALUE) + File::handleLastError(_path); + + if ((mode & std::ios::ate) || (mode & std::ios::app)) + seekoff(0, std::ios::end, mode); +} + + +int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length) +{ + if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::in)) + return -1; + + if (getMode() & std::ios::out) + sync(); + + DWORD bytesRead(0); + BOOL rc = ReadFile(_handle, buffer, static_cast(length), &bytesRead, NULL); + if (rc == 0) + File::handleLastError(_path); + + _pos += bytesRead; + + return static_cast(bytesRead); +} + + +int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length) +{ + if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::out)) + return -1; + + if (getMode() & std::ios::app) + { + LARGE_INTEGER li; + li.QuadPart = 0; + li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_END); + if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) + File::handleLastError(_path); + _pos = li.QuadPart; + } + + DWORD bytesWritten(0); + BOOL rc = WriteFile(_handle, buffer, static_cast(length), &bytesWritten, NULL); + if (rc == 0) + File::handleLastError(_path); + + _pos += bytesWritten; + + return static_cast(bytesWritten); +} + + +void FileStreamBuf::close() +{ + if (_handle != INVALID_HANDLE_VALUE) + { + if (getMode() & std::ios::out) + sync(); + + CloseHandle(_handle); + _handle = INVALID_HANDLE_VALUE; + } +} + + +std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode) +{ + if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode)) + return -1; + + if (getMode() & std::ios::out) + sync(); + + std::streamoff adj; + if (mode & std::ios::in) + adj = static_cast(egptr() - gptr()); + else + adj = 0; + + resetBuffers(); + + DWORD offset = FILE_BEGIN; + if (dir == std::ios::cur) + { + offset = FILE_CURRENT; + off -= adj; + } + else if (dir == std::ios::end) + { + offset = FILE_END; + } + + LARGE_INTEGER li; + li.QuadPart = off; + li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, offset); + + if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) + File::handleLastError(_path); + _pos = li.QuadPart; + return std::streampos(static_cast(_pos)); +} + + +std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode) +{ + if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode)) + return -1; + + if (getMode() & std::ios::out) + sync(); + + resetBuffers(); + + LARGE_INTEGER li; + li.QuadPart = pos; + li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_BEGIN); + + if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) + File::handleLastError(_path); + _pos = li.QuadPart; + return std::streampos(static_cast(_pos)); +} + + +} // namespace Poco diff --git a/Foundation/src/Hash.cpp b/Foundation/src/Hash.cpp index 4036aa9b7..f0b30ac2e 100644 --- a/Foundation/src/Hash.cpp +++ b/Foundation/src/Hash.cpp @@ -1,56 +1,56 @@ -// -// Hash.cpp -// -// $Id: //poco/svn/Foundation/src/Hash.cpp#2 $ -// -// Library: Foundation -// Package: Hashing -// Module: Hash -// -// Copyright (c) 2006, 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/Hash.h" - - -namespace Poco { - - -std::size_t hash(const std::string& str) -{ - std::size_t h = 0; - std::string::const_iterator it = str.begin(); - std::string::const_iterator end = str.end(); - while (it != end) - { - h = h * 0xf4243 ^ *it++; - } - return h; -} - - -} // namespace Poco +// +// Hash.cpp +// +// $Id: //poco/svn/Foundation/src/Hash.cpp#2 $ +// +// Library: Foundation +// Package: Hashing +// Module: Hash +// +// Copyright (c) 2006, 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/Hash.h" + + +namespace Poco { + + +std::size_t hash(const std::string& str) +{ + std::size_t h = 0; + std::string::const_iterator it = str.begin(); + std::string::const_iterator end = str.end(); + while (it != end) + { + h = h * 0xf4243 ^ *it++; + } + return h; +} + + +} // namespace Poco diff --git a/Foundation/src/SharedMemory.cpp b/Foundation/src/SharedMemory.cpp index 6458a05e0..03ce55f77 100644 --- a/Foundation/src/SharedMemory.cpp +++ b/Foundation/src/SharedMemory.cpp @@ -1,118 +1,118 @@ -// -// SharedMemory.cpp -// -// $Id: //poco/svn/Foundation/src/SharedMemory.cpp#3 $ -// -// Library: Foundation -// Package: Processes -// Module: SharedMemory -// -// 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. -// - - -#if POCO_OS == POCO_OS_SOLARIS -#undef _XOPEN_SOURCE -#define _XOPEN_SOURCE 500 -#endif - - -#include "Poco/SharedMemory.h" -#include "Poco/Exception.h" -#if defined(POCO_NO_SHAREDMEMORY) -#include "SharedMemory_DUMMY.cpp" -#elif defined(POCO_OS_FAMILY_WINDOWS) -#include "SharedMemory_WIN32.cpp" -#elif defined(POCO_OS_FAMILY_UNIX) -#include "SharedMemory_POSIX.cpp" -#else -#include "SharedMemory_DUMMY.cpp" -#endif - - -namespace Poco { - - -SharedMemory::SharedMemory(): - _pImpl(0) -{ -} - - -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)) -{ -} - - -SharedMemory::SharedMemory(const Poco::File& file, AccessMode mode, const void* addrHint): - _pImpl(new SharedMemoryImpl(file, mode, addrHint)) -{ -} - - -SharedMemory::SharedMemory(const SharedMemory& other): - _pImpl(other._pImpl) -{ - if (_pImpl) - _pImpl->duplicate(); -} - - -SharedMemory::~SharedMemory() -{ - if (_pImpl) - _pImpl->release(); -} - - -SharedMemory& SharedMemory::operator = (const SharedMemory& other) -{ - SharedMemory tmp(other); - swap(tmp); - return *this; -} - - -char* SharedMemory::begin() const -{ - if (_pImpl) - return _pImpl->begin(); - else - return 0; -} - - -char* SharedMemory::end() const -{ - if (_pImpl) - return _pImpl->end(); - else - return 0; -} - - -} // namespace Poco +// +// SharedMemory.cpp +// +// $Id: //poco/svn/Foundation/src/SharedMemory.cpp#3 $ +// +// Library: Foundation +// Package: Processes +// Module: SharedMemory +// +// 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. +// + + +#if POCO_OS == POCO_OS_SOLARIS +#undef _XOPEN_SOURCE +#define _XOPEN_SOURCE 500 +#endif + + +#include "Poco/SharedMemory.h" +#include "Poco/Exception.h" +#if defined(POCO_NO_SHAREDMEMORY) +#include "SharedMemory_DUMMY.cpp" +#elif defined(POCO_OS_FAMILY_WINDOWS) +#include "SharedMemory_WIN32.cpp" +#elif defined(POCO_OS_FAMILY_UNIX) +#include "SharedMemory_POSIX.cpp" +#else +#include "SharedMemory_DUMMY.cpp" +#endif + + +namespace Poco { + + +SharedMemory::SharedMemory(): + _pImpl(0) +{ +} + + +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)) +{ +} + + +SharedMemory::SharedMemory(const Poco::File& file, AccessMode mode, const void* addrHint): + _pImpl(new SharedMemoryImpl(file, mode, addrHint)) +{ +} + + +SharedMemory::SharedMemory(const SharedMemory& other): + _pImpl(other._pImpl) +{ + if (_pImpl) + _pImpl->duplicate(); +} + + +SharedMemory::~SharedMemory() +{ + if (_pImpl) + _pImpl->release(); +} + + +SharedMemory& SharedMemory::operator = (const SharedMemory& other) +{ + SharedMemory tmp(other); + swap(tmp); + return *this; +} + + +char* SharedMemory::begin() const +{ + if (_pImpl) + return _pImpl->begin(); + else + return 0; +} + + +char* SharedMemory::end() const +{ + if (_pImpl) + return _pImpl->end(); + else + return 0; +} + + +} // namespace Poco diff --git a/Foundation/src/SharedMemory_DUMMY.cpp b/Foundation/src/SharedMemory_DUMMY.cpp index 075637c6b..b210150c3 100644 --- a/Foundation/src/SharedMemory_DUMMY.cpp +++ b/Foundation/src/SharedMemory_DUMMY.cpp @@ -1,58 +1,58 @@ -// -// SharedMemoryImpl.cpp -// -// $Id: //poco/svn/Foundation/src/SharedMemory_DUMMY.cpp#2 $ -// -// Library: Foundation -// Package: Processes -// Module: SharedMemoryImpl -// -// 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/SharedMemory_DUMMY.h" - - -namespace Poco { - - -SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*, bool) -{ -} - - -SharedMemoryImpl::SharedMemoryImpl(const Poco::File&, SharedMemory::AccessMode, const void*) -{ -} - - -SharedMemoryImpl::~SharedMemoryImpl() -{ -} - - -} // namespace Poco +// +// SharedMemoryImpl.cpp +// +// $Id: //poco/svn/Foundation/src/SharedMemory_DUMMY.cpp#2 $ +// +// Library: Foundation +// Package: Processes +// Module: SharedMemoryImpl +// +// 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/SharedMemory_DUMMY.h" + + +namespace Poco { + + +SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*, bool) +{ +} + + +SharedMemoryImpl::SharedMemoryImpl(const Poco::File&, SharedMemory::AccessMode, const void*) +{ +} + + +SharedMemoryImpl::~SharedMemoryImpl() +{ +} + + +} // namespace Poco diff --git a/Foundation/src/SharedMemory_POSIX.cpp b/Foundation/src/SharedMemory_POSIX.cpp index c4931c50d..3edb1d69e 100644 --- a/Foundation/src/SharedMemory_POSIX.cpp +++ b/Foundation/src/SharedMemory_POSIX.cpp @@ -1,156 +1,156 @@ -// -// SharedMemoryImpl.cpp -// -// $Id: //poco/svn/Foundation/src/SharedMemory_POSIX.cpp#2 $ -// -// Library: Foundation -// Package: Processes -// Module: SharedMemoryImpl -// -// 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/SharedMemory_POSIX.h" -#include "Poco/Exception.h" -#include "Poco/File.h" -#include -#include -#include -#include -#include - - -namespace Poco { - - -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), - _server(server) -{ -#if POCO_OS == POCO_OS_HPUX - _name.append("tmp/"); -#endif - - _name.append(name); - - int flags = O_CREAT; - if (_access == SharedMemory::AM_WRITE) - flags |= O_RDWR; - else - flags |= O_RDONLY; - - // open the shared memory segment - _fd = ::shm_open(_name.c_str(), flags, S_IRUSR | S_IWUSR); - if (_fd == -1) - throw SystemException("Cannot create shared memory object", _name); - - // now set the correct size for the segment - if (-1 == ::ftruncate(_fd, size)) - { - ::close(_fd); - _fd = -1; - ::shm_unlink(_name.c_str()); - throw SystemException("Cannot resize shared memory object", _name); - } - map(addrHint); -} - - -SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint): - _size(0), - _fd(-1), - _address(0), - _access(mode), - _name(file.path()), - _fileMapped(true), - _server(false) -{ - if (!file.exists() || !file.isFile()) - throw FileNotFoundException(file.path()); - - _size = file.getSize(); - int flag = O_RDONLY; - if (mode == SharedMemory::AM_WRITE) - flag = O_RDWR; - _fd = ::open(_name.c_str(), flag); - if (-1 == _fd) - throw OpenFileException("Cannot open memory mapped file", _name); - - map(addrHint); -} - - -SharedMemoryImpl::~SharedMemoryImpl() -{ - unmap(); - close(); -} - - -void SharedMemoryImpl::map(const void* addrHint) -{ - int access = PROT_READ; - if (_access == SharedMemory::AM_WRITE) - access |= PROT_WRITE; - - void* addr = ::mmap(const_cast(addrHint), _size, access, MAP_SHARED, _fd, 0); - if (addr == MAP_FAILED) - throw SystemException("Cannot map file into shared memory", _name); - - _address = static_cast(addr); -} - - -void SharedMemoryImpl::unmap() -{ - if (_address) - { - ::munmap(_address, _size); - } -} - - -void SharedMemoryImpl::close() -{ - if (_fd != -1) - { - ::close(_fd); - _fd = -1; - } - if (!_fileMapped && _server) - { - ::shm_unlink(_name.c_str()); - } -} - - -} // namespace Poco +// +// SharedMemoryImpl.cpp +// +// $Id: //poco/svn/Foundation/src/SharedMemory_POSIX.cpp#2 $ +// +// Library: Foundation +// Package: Processes +// Module: SharedMemoryImpl +// +// 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/SharedMemory_POSIX.h" +#include "Poco/Exception.h" +#include "Poco/File.h" +#include +#include +#include +#include +#include + + +namespace Poco { + + +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), + _server(server) +{ +#if POCO_OS == POCO_OS_HPUX + _name.append("tmp/"); +#endif + + _name.append(name); + + int flags = O_CREAT; + if (_access == SharedMemory::AM_WRITE) + flags |= O_RDWR; + else + flags |= O_RDONLY; + + // open the shared memory segment + _fd = ::shm_open(_name.c_str(), flags, S_IRUSR | S_IWUSR); + if (_fd == -1) + throw SystemException("Cannot create shared memory object", _name); + + // now set the correct size for the segment + if (-1 == ::ftruncate(_fd, size)) + { + ::close(_fd); + _fd = -1; + ::shm_unlink(_name.c_str()); + throw SystemException("Cannot resize shared memory object", _name); + } + map(addrHint); +} + + +SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint): + _size(0), + _fd(-1), + _address(0), + _access(mode), + _name(file.path()), + _fileMapped(true), + _server(false) +{ + if (!file.exists() || !file.isFile()) + throw FileNotFoundException(file.path()); + + _size = file.getSize(); + int flag = O_RDONLY; + if (mode == SharedMemory::AM_WRITE) + flag = O_RDWR; + _fd = ::open(_name.c_str(), flag); + if (-1 == _fd) + throw OpenFileException("Cannot open memory mapped file", _name); + + map(addrHint); +} + + +SharedMemoryImpl::~SharedMemoryImpl() +{ + unmap(); + close(); +} + + +void SharedMemoryImpl::map(const void* addrHint) +{ + int access = PROT_READ; + if (_access == SharedMemory::AM_WRITE) + access |= PROT_WRITE; + + void* addr = ::mmap(const_cast(addrHint), _size, access, MAP_SHARED, _fd, 0); + if (addr == MAP_FAILED) + throw SystemException("Cannot map file into shared memory", _name); + + _address = static_cast(addr); +} + + +void SharedMemoryImpl::unmap() +{ + if (_address) + { + ::munmap(_address, _size); + } +} + + +void SharedMemoryImpl::close() +{ + if (_fd != -1) + { + ::close(_fd); + _fd = -1; + } + if (!_fileMapped && _server) + { + ::shm_unlink(_name.c_str()); + } +} + + +} // namespace Poco diff --git a/Foundation/src/SharedMemory_WIN32.cpp b/Foundation/src/SharedMemory_WIN32.cpp index 8bd6629ff..a949cd385 100644 --- a/Foundation/src/SharedMemory_WIN32.cpp +++ b/Foundation/src/SharedMemory_WIN32.cpp @@ -1,166 +1,166 @@ -// -// SharedMemoryImpl.cpp -// -// $Id: //poco/svn/Foundation/src/SharedMemory_WIN32.cpp#2 $ -// -// Library: Foundation -// Package: Processes -// Module: SharedMemoryImpl -// -// 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/SharedMemory_WIN32.h" -#include "Poco/Exception.h" -#include "Poco/File.h" -#if defined (POCO_WIN32_UTF8) -#include "Poco/UnicodeConverter.h" -#endif -#include "Poco/UnWindows.h" - - -namespace Poco { - - -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), - _size(static_cast(size)), - _mode(PAGE_READONLY), - _address(0) -{ - if (mode == SharedMemory::AM_WRITE) - _mode = PAGE_READWRITE; - -#if defined (POCO_WIN32_UTF8) - std::wstring utf16name; - UnicodeConverter::toUTF16(_name, utf16name); - _memHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, utf16name.c_str()); -#else - _memHandle = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, _name.c_str()); -#endif - - if (!_memHandle) - throw SystemException("Cannot create shared memory object", _name); - - map(); -} - - -SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void*): - _name(file.path()), - _memHandle(INVALID_HANDLE_VALUE), - _fileHandle(INVALID_HANDLE_VALUE), - _size(0), - _mode(PAGE_READONLY), - _address(0) -{ - if (!file.exists() || !file.isFile()) - throw FileNotFoundException(_name); - - _size = static_cast(file.getSize()); - - DWORD shareMode = FILE_SHARE_READ; - DWORD fileMode = GENERIC_READ; - - if (mode == SharedMemory::AM_WRITE) - { - _mode = PAGE_READWRITE; - fileMode |= GENERIC_WRITE; - } - -#if defined (POCO_WIN32_UTF8) - std::wstring utf16name; - UnicodeConverter::toUTF16(_name, utf16name); - _fileHandle = CreateFileW(utf16name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -#else - _fileHandle = CreateFileA(_name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -#endif - - if (_fileHandle == INVALID_HANDLE_VALUE) - throw OpenFileException("Cannot open memory mapped file", _name); - - _memHandle = CreateFileMapping(_fileHandle, NULL, _mode, 0, 0, NULL); - if (!_memHandle) - { - CloseHandle(_fileHandle); - _fileHandle = INVALID_HANDLE_VALUE; - throw SystemException("Cannot map file into shared memory", _name); - } - map(); -} - - -SharedMemoryImpl::~SharedMemoryImpl() -{ - unmap(); - close(); -} - - -void SharedMemoryImpl::map() -{ - DWORD access = FILE_MAP_READ; - if (_mode == PAGE_READWRITE) - access = FILE_MAP_WRITE; - LPVOID addr = MapViewOfFile(_memHandle, access, 0, 0, _size); - if (!addr) - throw SystemException("Cannot map shared memory object", _name); - - _address = static_cast(addr); -} - - -void SharedMemoryImpl::unmap() -{ - if (_address) - { - UnmapViewOfFile(_address); - _address = 0; - return; - } -} - - -void SharedMemoryImpl::close() -{ - if (_memHandle != INVALID_HANDLE_VALUE) - { - CloseHandle(_memHandle); - _memHandle = INVALID_HANDLE_VALUE; - } - - if (_fileHandle != INVALID_HANDLE_VALUE) - { - CloseHandle(_fileHandle); - _fileHandle = INVALID_HANDLE_VALUE; - } -} - - -} // namespace Poco +// +// SharedMemoryImpl.cpp +// +// $Id: //poco/svn/Foundation/src/SharedMemory_WIN32.cpp#2 $ +// +// Library: Foundation +// Package: Processes +// Module: SharedMemoryImpl +// +// 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/SharedMemory_WIN32.h" +#include "Poco/Exception.h" +#include "Poco/File.h" +#if defined (POCO_WIN32_UTF8) +#include "Poco/UnicodeConverter.h" +#endif +#include "Poco/UnWindows.h" + + +namespace Poco { + + +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), + _size(static_cast(size)), + _mode(PAGE_READONLY), + _address(0) +{ + if (mode == SharedMemory::AM_WRITE) + _mode = PAGE_READWRITE; + +#if defined (POCO_WIN32_UTF8) + std::wstring utf16name; + UnicodeConverter::toUTF16(_name, utf16name); + _memHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, utf16name.c_str()); +#else + _memHandle = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, _name.c_str()); +#endif + + if (!_memHandle) + throw SystemException("Cannot create shared memory object", _name); + + map(); +} + + +SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void*): + _name(file.path()), + _memHandle(INVALID_HANDLE_VALUE), + _fileHandle(INVALID_HANDLE_VALUE), + _size(0), + _mode(PAGE_READONLY), + _address(0) +{ + if (!file.exists() || !file.isFile()) + throw FileNotFoundException(_name); + + _size = static_cast(file.getSize()); + + DWORD shareMode = FILE_SHARE_READ; + DWORD fileMode = GENERIC_READ; + + if (mode == SharedMemory::AM_WRITE) + { + _mode = PAGE_READWRITE; + fileMode |= GENERIC_WRITE; + } + +#if defined (POCO_WIN32_UTF8) + std::wstring utf16name; + UnicodeConverter::toUTF16(_name, utf16name); + _fileHandle = CreateFileW(utf16name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); +#else + _fileHandle = CreateFileA(_name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); +#endif + + if (_fileHandle == INVALID_HANDLE_VALUE) + throw OpenFileException("Cannot open memory mapped file", _name); + + _memHandle = CreateFileMapping(_fileHandle, NULL, _mode, 0, 0, NULL); + if (!_memHandle) + { + CloseHandle(_fileHandle); + _fileHandle = INVALID_HANDLE_VALUE; + throw SystemException("Cannot map file into shared memory", _name); + } + map(); +} + + +SharedMemoryImpl::~SharedMemoryImpl() +{ + unmap(); + close(); +} + + +void SharedMemoryImpl::map() +{ + DWORD access = FILE_MAP_READ; + if (_mode == PAGE_READWRITE) + access = FILE_MAP_WRITE; + LPVOID addr = MapViewOfFile(_memHandle, access, 0, 0, _size); + if (!addr) + throw SystemException("Cannot map shared memory object", _name); + + _address = static_cast(addr); +} + + +void SharedMemoryImpl::unmap() +{ + if (_address) + { + UnmapViewOfFile(_address); + _address = 0; + return; + } +} + + +void SharedMemoryImpl::close() +{ + if (_memHandle != INVALID_HANDLE_VALUE) + { + CloseHandle(_memHandle); + _memHandle = INVALID_HANDLE_VALUE; + } + + if (_fileHandle != INVALID_HANDLE_VALUE) + { + CloseHandle(_fileHandle); + _fileHandle = INVALID_HANDLE_VALUE; + } +} + + +} // namespace Poco diff --git a/Foundation/src/UTF8String.cpp b/Foundation/src/UTF8String.cpp index d55c1c856..0afe84c7a 100644 --- a/Foundation/src/UTF8String.cpp +++ b/Foundation/src/UTF8String.cpp @@ -1,203 +1,203 @@ -// -// UTF8String.cpp -// -// $Id: //poco/svn/Foundation/src/UTF8String.cpp#2 $ -// -// Library: Foundation -// Package: Text -// Module: UTF8String -// -// 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/UTF8String.h" -#include "Poco/Unicode.h" -#include "Poco/TextIterator.h" -#include "Poco/TextConverter.h" -#include "Poco/UTF8Encoding.h" -#include - - -namespace Poco { - - -int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2) -{ - static UTF8Encoding utf8; - - std::string::size_type sz = str.size(); - if (pos > sz) pos = sz; - if (pos + n > sz) n = sz - pos; - TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8); - TextIterator uend1(str.begin() + pos + n); - TextIterator uit2(it2, end2, utf8); - TextIterator uend2(end2); - while (uit1 != uend1 && uit2 != uend2) - { - int c1 = Unicode::toLower(*uit1); - int c2 = Unicode::toLower(*uit2); - if (c1 < c2) - return -1; - else if (c1 > c2) - return 1; - ++uit1; ++uit2; - } - - if (uit1 == uend1) - return uit2 == uend2 ? 0 : -1; - else - return 1; -} - - -int UTF8::icompare(const std::string& str1, const std::string& str2) -{ - return icompare(str1, 0, str1.size(), str2.begin(), str2.end()); -} - - -int UTF8::icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2) -{ - if (n2 > str2.size()) n2 = str2.size(); - return icompare(str1, 0, n1, str2.begin(), str2.begin() + n2); -} - - -int UTF8::icompare(const std::string& str1, std::string::size_type n, const std::string& str2) -{ - if (n > str2.size()) n = str2.size(); - return icompare(str1, 0, n, str2.begin(), str2.begin() + n); -} - - -int UTF8::icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2) -{ - return icompare(str1, pos, n, str2.begin(), str2.end()); -} - - -int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2) -{ - std::string::size_type sz2 = str2.size(); - if (pos2 > sz2) pos2 = sz2; - if (pos2 + n2 > sz2) n2 = sz2 - pos2; - return icompare(str1, pos1, n1, str2.begin() + pos2, str2.begin() + pos2 + n2); -} - - -int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2) -{ - std::string::size_type sz2 = str2.size(); - if (pos2 > sz2) pos2 = sz2; - if (pos2 + n > sz2) n = sz2 - pos2; - return icompare(str1, pos1, n, str2.begin() + pos2, str2.begin() + pos2 + n); -} - - -int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr) -{ - static UTF8Encoding utf8; - - poco_check_ptr (ptr); - std::string::size_type sz = str.size(); - if (pos > sz) pos = sz; - if (pos + n > sz) n = sz - pos; - TextIterator uit(str.begin() + pos, str.begin() + pos + n, utf8); - TextIterator uend(str.begin() + pos + n); - while (uit != uend && *ptr) - { - int c1 = Unicode::toLower(*uit); - int c2 = Unicode::toLower(*ptr); - if (c1 < c2) - return -1; - else if (c1 > c2) - return 1; - ++uit; ++ptr; - } - - if (uit == uend) - return *ptr == 0 ? 0 : -1; - else - return 1; -} - - -int UTF8::icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr) -{ - return icompare(str, pos, str.size() - pos, ptr); -} - - -int UTF8::icompare(const std::string& str, const std::string::value_type* ptr) -{ - return icompare(str, 0, str.size(), ptr); -} - - -std::string UTF8::toUpper(const std::string& str) -{ - static UTF8Encoding utf8; - std::string result; - TextConverter converter(utf8, utf8); - converter.convert(str, result, Unicode::toUpper); - return result; -} - - -std::string& UTF8::toUpperInPlace(std::string& str) -{ - static UTF8Encoding utf8; - std::string result; - TextConverter converter(utf8, utf8); - converter.convert(str, result, Unicode::toUpper); - std::swap(str, result); - return str; -} - - -std::string UTF8::toLower(const std::string& str) -{ - static UTF8Encoding utf8; - std::string result; - TextConverter converter(utf8, utf8); - converter.convert(str, result, Unicode::toLower); - return result; -} - - -std::string& UTF8::toLowerInPlace(std::string& str) -{ - static UTF8Encoding utf8; - std::string result; - TextConverter converter(utf8, utf8); - converter.convert(str, result, Unicode::toLower); - std::swap(str, result); - return str; -} - - -} // namespace Poco +// +// UTF8String.cpp +// +// $Id: //poco/svn/Foundation/src/UTF8String.cpp#2 $ +// +// Library: Foundation +// Package: Text +// Module: UTF8String +// +// 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/UTF8String.h" +#include "Poco/Unicode.h" +#include "Poco/TextIterator.h" +#include "Poco/TextConverter.h" +#include "Poco/UTF8Encoding.h" +#include + + +namespace Poco { + + +int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2) +{ + static UTF8Encoding utf8; + + std::string::size_type sz = str.size(); + if (pos > sz) pos = sz; + if (pos + n > sz) n = sz - pos; + TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8); + TextIterator uend1(str.begin() + pos + n); + TextIterator uit2(it2, end2, utf8); + TextIterator uend2(end2); + while (uit1 != uend1 && uit2 != uend2) + { + int c1 = Unicode::toLower(*uit1); + int c2 = Unicode::toLower(*uit2); + if (c1 < c2) + return -1; + else if (c1 > c2) + return 1; + ++uit1; ++uit2; + } + + if (uit1 == uend1) + return uit2 == uend2 ? 0 : -1; + else + return 1; +} + + +int UTF8::icompare(const std::string& str1, const std::string& str2) +{ + return icompare(str1, 0, str1.size(), str2.begin(), str2.end()); +} + + +int UTF8::icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2) +{ + if (n2 > str2.size()) n2 = str2.size(); + return icompare(str1, 0, n1, str2.begin(), str2.begin() + n2); +} + + +int UTF8::icompare(const std::string& str1, std::string::size_type n, const std::string& str2) +{ + if (n > str2.size()) n = str2.size(); + return icompare(str1, 0, n, str2.begin(), str2.begin() + n); +} + + +int UTF8::icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2) +{ + return icompare(str1, pos, n, str2.begin(), str2.end()); +} + + +int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2) +{ + std::string::size_type sz2 = str2.size(); + if (pos2 > sz2) pos2 = sz2; + if (pos2 + n2 > sz2) n2 = sz2 - pos2; + return icompare(str1, pos1, n1, str2.begin() + pos2, str2.begin() + pos2 + n2); +} + + +int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2) +{ + std::string::size_type sz2 = str2.size(); + if (pos2 > sz2) pos2 = sz2; + if (pos2 + n > sz2) n = sz2 - pos2; + return icompare(str1, pos1, n, str2.begin() + pos2, str2.begin() + pos2 + n); +} + + +int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr) +{ + static UTF8Encoding utf8; + + poco_check_ptr (ptr); + std::string::size_type sz = str.size(); + if (pos > sz) pos = sz; + if (pos + n > sz) n = sz - pos; + TextIterator uit(str.begin() + pos, str.begin() + pos + n, utf8); + TextIterator uend(str.begin() + pos + n); + while (uit != uend && *ptr) + { + int c1 = Unicode::toLower(*uit); + int c2 = Unicode::toLower(*ptr); + if (c1 < c2) + return -1; + else if (c1 > c2) + return 1; + ++uit; ++ptr; + } + + if (uit == uend) + return *ptr == 0 ? 0 : -1; + else + return 1; +} + + +int UTF8::icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr) +{ + return icompare(str, pos, str.size() - pos, ptr); +} + + +int UTF8::icompare(const std::string& str, const std::string::value_type* ptr) +{ + return icompare(str, 0, str.size(), ptr); +} + + +std::string UTF8::toUpper(const std::string& str) +{ + static UTF8Encoding utf8; + std::string result; + TextConverter converter(utf8, utf8); + converter.convert(str, result, Unicode::toUpper); + return result; +} + + +std::string& UTF8::toUpperInPlace(std::string& str) +{ + static UTF8Encoding utf8; + std::string result; + TextConverter converter(utf8, utf8); + converter.convert(str, result, Unicode::toUpper); + std::swap(str, result); + return str; +} + + +std::string UTF8::toLower(const std::string& str) +{ + static UTF8Encoding utf8; + std::string result; + TextConverter converter(utf8, utf8); + converter.convert(str, result, Unicode::toLower); + return result; +} + + +std::string& UTF8::toLowerInPlace(std::string& str) +{ + static UTF8Encoding utf8; + std::string result; + TextConverter converter(utf8, utf8); + converter.convert(str, result, Unicode::toLower); + std::swap(str, result); + return str; +} + + +} // namespace Poco diff --git a/Foundation/src/Unicode.cpp b/Foundation/src/Unicode.cpp index 7e2ce940a..86413a4e4 100644 --- a/Foundation/src/Unicode.cpp +++ b/Foundation/src/Unicode.cpp @@ -1,94 +1,94 @@ -// -// Unicode.cpp -// -// $Id: //poco/svn/Foundation/src/Unicode.cpp#2 $ -// -// Library: Foundation -// Package: Text -// Module: Unicode -// -// 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/Unicode.h" - - -extern "C" -{ -#include "pcre_internal.h" -} - - -namespace Poco { - - -void Unicode::properties(int ch, CharacterProperties& props) -{ - int type; - int script; - int category = _pcre_ucp_findprop(static_cast(ch), &type, &script); - props.category = static_cast(category); - props.type = static_cast(type); - props.script = static_cast