fixed line endings

This commit is contained in:
Guenter Obiltschnig
2008-02-07 16:08:15 +00:00
parent a99f1aae4d
commit e4d9b3b40f
120 changed files with 32507 additions and 32507 deletions

View File

@@ -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 <typename TArgs>
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 <typename TArgs>
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

View File

@@ -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 TKey, class TValue>
class AccessExpireCache: public AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >
/// 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<TKey, TValue, AccessExpireStrategy<TKey, TValue> >(AccessExpireStrategy<TKey, TValue>(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 TKey, class TValue>
class AccessExpireCache: public AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >
/// 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<TKey, TValue, AccessExpireStrategy<TKey, TValue> >(AccessExpireStrategy<TKey, TValue>(expire))
{
}
~AccessExpireCache()
{
}
private:
AccessExpireCache(const AccessExpireCache& aCache);
AccessExpireCache& operator = (const AccessExpireCache& aCache);
};
} // namespace Poco
#endif

View File

@@ -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<TKey, TValue, StrategyCollection<TKey, TValue> >
/// 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<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
{
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
this->_strategy.pushBack(new AccessExpireStrategy<TKey, TValue>(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<TKey, TValue, StrategyCollection<TKey, TValue> >
/// 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<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
{
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
this->_strategy.pushBack(new AccessExpireStrategy<TKey, TValue>(expire));
}
~AccessExpireLRUCache()
{
}
private:
AccessExpireLRUCache(const AccessExpireLRUCache& aCache);
AccessExpireLRUCache& operator = (const AccessExpireLRUCache& aCache);
};
} // namespace Poco
#endif

View File

@@ -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 <set>
#include <map>
namespace Poco {
template <
class TKey,
class TValue
>
class AccessExpireStrategy: public ExpireStrategy<TKey, TValue>
/// An AccessExpireStrategy implements time and access based expiration of cache entries
{
public:
AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy<TKey, TValue>(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<TKey, TValue>::Iterator it = this->_keys.find(key);
if (it != this->_keys.end())
{
this->_keyIndex.erase(it->second);
Timestamp now;
typename ExpireStrategy<TKey, TValue>::IndexIterator itIdx =
this->_keyIndex.insert(typename ExpireStrategy<TKey, TValue>::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 <set>
#include <map>
namespace Poco {
template <
class TKey,
class TValue
>
class AccessExpireStrategy: public ExpireStrategy<TKey, TValue>
/// An AccessExpireStrategy implements time and access based expiration of cache entries
{
public:
AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy<TKey, TValue>(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<TKey, TValue>::Iterator it = this->_keys.find(key);
if (it != this->_keys.end())
{
this->_keyIndex.erase(it->second);
Timestamp now;
typename ExpireStrategy<TKey, TValue>::IndexIterator itIdx =
this->_keyIndex.insert(typename ExpireStrategy<TKey, TValue>::TimeIndex::value_type(now, key));
it->second = itIdx;
}
}
};
} // namespace Poco
#endif

View File

@@ -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<int>. 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<int, AsyncIOCommand::Ptr, AsyncIOChannel, ActiveStarter<ActiveDispatcher> > 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<AsyncIOEvent> commandCompleted;
/// Fired when a command has successfully completed.
BasicEvent<AsyncIOEvent> 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<int>. 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<int, AsyncIOCommand::Ptr, AsyncIOChannel, ActiveStarter<ActiveDispatcher> > 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<AsyncIOEvent> commandCompleted;
/// Fired when a command has successfully completed.
BasicEvent<AsyncIOEvent> 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

View File

@@ -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 <ios>
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<AsyncIOCommand> 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<AsyncIOEvent> commandCompleted;
/// Fired when the command has successfully completed.
BasicEvent<AsyncIOEvent> 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 <ios>
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<AsyncIOCommand> 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<AsyncIOEvent> commandCompleted;
/// Fired when the command has successfully completed.
BasicEvent<AsyncIOEvent> 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

View File

@@ -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

View File

@@ -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 <istream>
#include <ostream>
#include <iostream>
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<int> 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 <istream>
#include <ostream>
#include <iostream>
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<int> 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

View File

@@ -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<unsigned int>(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<unsigned int>(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

View File

@@ -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 <deque>
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 <class Mtx>
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<Mtx> unlock(mutex, false);
Event event;
{
FastMutex::ScopedLock lock(_mutex);
mutex.unlock();
enqueue(event);
}
event.wait();
}
template <class Mtx>
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 <class Mtx>
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<Mtx> 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<Event*> 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 <deque>
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 <class Mtx>
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<Mtx> unlock(mutex, false);
Event event;
{
FastMutex::ScopedLock lock(_mutex);
mutex.unlock();
enqueue(event);
}
event.wait();
}
template <class Mtx>
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 <class Mtx>
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<Mtx> 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<Event*> WaitQueue;
FastMutex _mutex;
WaitQueue _waitQueue;
};
} // namespace Poco
#endif // Foundation_Condition_INCLUDED

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -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 <map>
#include <set>
namespace Poco {
class Foundation_API DynamicStruct
/// DynamicStruct allows to define a named collection of DynamicAny objects.
{
public:
typedef std::map<std::string, DynamicAny> 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 <name,DynamicAny> 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 <name,DynamicAny> 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<DynamicStruct::Iterator, bool> insert(const std::string& key, const DynamicAny& value);
/// Inserts a <name, DynamicAny> 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<DynamicStruct::Iterator, bool> insert(const DynamicStruct::Data::value_type& aPair);
/// Inserts a <name, DynamicAny> 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<std::string> 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::Iterator, bool> DynamicStruct::insert(const std::string& key, const DynamicAny& value)
{
return insert(std::make_pair(key, value));
}
inline std::pair<DynamicStruct::Iterator, bool> 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<DynamicStruct>: 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 <map>
#include <set>
namespace Poco {
class Foundation_API DynamicStruct
/// DynamicStruct allows to define a named collection of DynamicAny objects.
{
public:
typedef std::map<std::string, DynamicAny> 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 <name,DynamicAny> 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 <name,DynamicAny> 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<DynamicStruct::Iterator, bool> insert(const std::string& key, const DynamicAny& value);
/// Inserts a <name, DynamicAny> 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<DynamicStruct::Iterator, bool> insert(const DynamicStruct::Data::value_type& aPair);
/// Inserts a <name, DynamicAny> 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<std::string> 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::Iterator, bool> DynamicStruct::insert(const std::string& key, const DynamicAny& value)
{
return insert(std::make_pair(key, value));
}
inline std::pair<DynamicStruct::Iterator, bool> 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<DynamicStruct>: 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

View File

@@ -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 <typename TArgs>
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 <typename TArgs>
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

View File

@@ -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 <istream>
#include <ostream>
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 <istream>
#include <ostream>
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

View File

@@ -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 <istream>
#include <ostream>
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 <istream>
#include <ostream>
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

View File

@@ -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

View File

@@ -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 TArgs, bool hasSender = true, bool senderIsConst = true>
class FunctionDelegate: public AbstractDelegate<TArgs>
/// 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<TArgs>(*reinterpret_cast<void**>(&method)),
_receiverMethod(method)
{
}
FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(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<TArgs>* clone() const
{
return new FunctionDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionDelegate();
};
template <class TArgs>
class FunctionDelegate<TArgs, true, false>: public AbstractDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(void*, TArgs&);
FunctionDelegate(NotifyMethod method):
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
_receiverMethod(method)
{
}
FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(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<void*>(sender), arguments);
return true; // a "standard" delegate never expires
}
AbstractDelegate<TArgs>* clone() const
{
return new FunctionDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionDelegate();
};
template <class TArgs, bool senderIsConst>
class FunctionDelegate<TArgs, false, senderIsConst>: public AbstractDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(TArgs&);
FunctionDelegate(NotifyMethod method):
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
_receiverMethod(method)
{
}
FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(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<TArgs>* 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 TArgs, bool hasSender = true, bool senderIsConst = true>
class FunctionDelegate: public AbstractDelegate<TArgs>
/// 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<TArgs>(*reinterpret_cast<void**>(&method)),
_receiverMethod(method)
{
}
FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(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<TArgs>* clone() const
{
return new FunctionDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionDelegate();
};
template <class TArgs>
class FunctionDelegate<TArgs, true, false>: public AbstractDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(void*, TArgs&);
FunctionDelegate(NotifyMethod method):
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
_receiverMethod(method)
{
}
FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(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<void*>(sender), arguments);
return true; // a "standard" delegate never expires
}
AbstractDelegate<TArgs>* clone() const
{
return new FunctionDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionDelegate();
};
template <class TArgs, bool senderIsConst>
class FunctionDelegate<TArgs, false, senderIsConst>: public AbstractDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(TArgs&);
FunctionDelegate(NotifyMethod method):
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
_receiverMethod(method)
{
}
FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(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<TArgs>* clone() const
{
return new FunctionDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionDelegate();
};
} // namespace Poco
#endif

View File

@@ -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 TArgs, bool useSender = true, bool senderIsConst = true>
class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
/// 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<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(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<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionPriorityDelegate();
};
template <class TArgs>
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(void*, TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(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<void*>(sender), arguments);
return true; // per default the delegate never expires
}
AbstractPriorityDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionPriorityDelegate();
};
template <class TArgs>
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(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<TArgs>* 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 TArgs, bool useSender = true, bool senderIsConst = true>
class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
/// 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<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(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<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionPriorityDelegate();
};
template <class TArgs>
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(void*, TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(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<void*>(sender), arguments);
return true; // per default the delegate never expires
}
AbstractPriorityDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionPriorityDelegate();
};
template <class TArgs>
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(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<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
protected:
NotifyMethod _receiverMethod;
private:
FunctionPriorityDelegate();
};
} // namespace Poco
#endif

View File

@@ -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 <cstddef>
namespace Poco {
template <class T>
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<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(UInt8 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(Int16 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(UInt16 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(Int32 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(UInt32 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(Int64 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(UInt64 n)
{
return static_cast<std::size_t>(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 <cstddef>
namespace Poco {
template <class T>
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<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(UInt8 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(Int16 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(UInt16 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(Int32 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(UInt32 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(Int64 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
inline std::size_t hash(UInt64 n)
{
return static_cast<std::size_t>(n)*2654435761U;
}
} // namespace Poco
#endif // Foundation_Hash_INCLUDED

View File

@@ -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 <utility>
namespace Poco {
template <class Key, class Value>
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 <class HME, class KeyHashFunc>
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 Key, class Mapped, class HashFunc = Hash<Key> >
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<Key, Mapped> ValueType;
typedef std::pair<KeyType, MappedType> PairType;
typedef HashMapEntryHash<ValueType, HashFunc> HashType;
typedef LinearHashTable<ValueType, HashType> 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<Iterator, bool> insert(const PairType& pair)
{
ValueType value(pair.first, pair.second);
return _table.insert(value);
}
std::pair<Iterator, bool> 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<Iterator, bool> 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 <utility>
namespace Poco {
template <class Key, class Value>
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 <class HME, class KeyHashFunc>
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 Key, class Mapped, class HashFunc = Hash<Key> >
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<Key, Mapped> ValueType;
typedef std::pair<KeyType, MappedType> PairType;
typedef HashMapEntryHash<ValueType, HashFunc> HashType;
typedef LinearHashTable<ValueType, HashType> 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<Iterator, bool> insert(const PairType& pair)
{
ValueType value(pair.first, pair.second);
return _table.insert(value);
}
std::pair<Iterator, bool> 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<Iterator, bool> res = _table.insert(value);
return res.first->second;
}
private:
HashTable _table;
};
} // namespace Poco
#endif // Foundation_HashMap_INCLUDED

View File

@@ -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 Value, class HashFunc = Hash<Value> >
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<ValueType, Hash> 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<Iterator, bool> 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 Value, class HashFunc = Hash<Value> >
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<ValueType, Hash> 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<Iterator, bool> 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

View File

@@ -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 <functional>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstddef>
namespace Poco {
template <class Value, class HashFunc = Hash<Value> >
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 <http://en.wikipedia.org/wiki/Linear_hash>.
///
/// 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<Value> Bucket;
typedef std::vector<Bucket> 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<Iterator, bool> 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 <functional>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstddef>
namespace Poco {
template <class Value, class HashFunc = Hash<Value> >
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 <http://en.wikipedia.org/wiki/Linear_hash>.
///
/// 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<Value> Bucket;
typedef std::vector<Bucket> 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<Iterator, bool> 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

View File

@@ -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 <typename T>
struct IsReference
///Use this struct to determine if a template type is a reference
{
enum
{
VALUE = 0
};
};
template <typename T>
struct IsReference<T&>
{
enum
{
VALUE = 1
};
};
template <typename T>
struct IsReference<const T&>
{
enum
{
VALUE = 1
};
};
template <typename T>
struct IsConst
///Use this struct to determine if a template type is a const type
{
enum
{
VALUE = 0
};
};
template <typename T>
struct IsConst<const T&>
{
enum
{
VALUE = 1
};
};
template <typename T>
struct IsConst<const T>
{
enum
{
VALUE = 1
};
};
template <typename T>
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 <typename T>
struct TypeWrapper<const T>
{
typedef T TYPE;
typedef const T CONSTTYPE;
typedef T& REFTYPE;
typedef const T& CONSTREFTYPE;
};
template <typename T>
struct TypeWrapper<const T&>
{
typedef T TYPE;
typedef const T CONSTTYPE;
typedef T& REFTYPE;
typedef const T& CONSTREFTYPE;
};
template <typename T>
struct TypeWrapper<T&>
{
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 <typename T>
struct IsReference
///Use this struct to determine if a template type is a reference
{
enum
{
VALUE = 0
};
};
template <typename T>
struct IsReference<T&>
{
enum
{
VALUE = 1
};
};
template <typename T>
struct IsReference<const T&>
{
enum
{
VALUE = 1
};
};
template <typename T>
struct IsConst
///Use this struct to determine if a template type is a const type
{
enum
{
VALUE = 0
};
};
template <typename T>
struct IsConst<const T&>
{
enum
{
VALUE = 1
};
};
template <typename T>
struct IsConst<const T>
{
enum
{
VALUE = 1
};
};
template <typename T>
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 <typename T>
struct TypeWrapper<const T>
{
typedef T TYPE;
typedef const T CONSTTYPE;
typedef T& REFTYPE;
typedef const T& CONSTREFTYPE;
};
template <typename T>
struct TypeWrapper<const T&>
{
typedef T TYPE;
typedef const T CONSTTYPE;
typedef T& REFTYPE;
typedef const T& CONSTREFTYPE;
};
template <typename T>
struct TypeWrapper<T&>
{
typedef T TYPE;
typedef const T CONSTTYPE;
typedef T& REFTYPE;
typedef const T& CONSTREFTYPE;
};
} // namespace Poco
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -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 M>
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 M>
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

View File

@@ -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 <algorithm>
#include <cstddef>
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 <algorithm>
#include <cstddef>
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

View File

@@ -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

View File

@@ -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

View File

@@ -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

File diff suppressed because it is too large Load Diff

View File

@@ -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 <class Head, class Tail>
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 <class Head, class Tail>
struct TypeList
/// Compile Time List of Types
{
typedef Head HeadType;
typedef Tail TailType;
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
typedef typename TypeWrapper<TailType>::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 <typename T0 = NullTypeList,
typename T1 = NullTypeList,
typename T2 = NullTypeList,
typename T3 = NullTypeList,
typename T4 = NullTypeList,
typename T5 = NullTypeList,
typename T6 = NullTypeList,
typename T7 = NullTypeList,
typename T8 = NullTypeList,
typename T9 = NullTypeList,
typename T10 = NullTypeList,
typename T11 = NullTypeList,
typename T12 = NullTypeList,
typename T13 = NullTypeList,
typename T14 = NullTypeList,
typename T15 = NullTypeList,
typename T16 = NullTypeList,
typename T17 = NullTypeList,
typename T18 = NullTypeList,
typename T19 = NullTypeList>
struct TypeListType
/// TypeListType takes 1 - 20 typename arguments.
/// Usage:
///
/// TypeListType<T0, T1, ... , Tn>::HeadType typeList;
///
/// typeList is a TypeList of T0, T1, ... , Tn
{
private:
typedef typename TypeListType<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>::HeadType TailType;
public:
typedef TypeList<T0, TailType> HeadType;
};
template <>
struct TypeListType<>
{
typedef NullTypeList HeadType;
};
template <int n>
struct Getter
{
template <class Ret, class Head, class Tail>
inline static Ret& get(TypeList<Head, Tail>& val)
{
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
}
template <class Ret, class Head, class Tail>
inline static const Ret& get(const TypeList<Head, Tail>& val)
{
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
}
};
template <>
struct Getter<0>
{
template <class Ret, class Head, class Tail>
inline static Ret& get(TypeList<Head, Tail>& val)
{
return val.head;
}
template <class Ret, class Head, class Tail>
inline static const Ret& get(const TypeList<Head, Tail>& val)
{
return val.head;
}
};
template <int N, class Head>
struct TypeGetter;
template <int N, class Head, class Tail>
struct TypeGetter<N, TypeList<Head, Tail> >
{
typedef typename TypeGetter<N-1, Tail>::HeadType HeadType;
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
};
template <class Head, class Tail>
struct TypeGetter<0, TypeList<Head, Tail> >
{
typedef typename TypeList<Head, Tail>::HeadType HeadType;
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
};
template <class Head, class T>
struct TypeLocator;
/// TypeLocator returns the first occurrence of the type T in Head
/// or -1 if the type is not found.
///
/// Usage example:
///
/// TypeLocator<Head, int>::HeadType TypeLoc;
///
/// if (2 == TypeLoc.value) ...
///
template <class T>
struct TypeLocator<NullTypeList, T>
{
enum { value = -1 };
};
template <class T, class Tail>
struct TypeLocator<TypeList<T, Tail>, T>
{
enum { value = 0 };
};
template <class Head, class Tail, class T>
struct TypeLocator<TypeList<Head, Tail>, T>
{
private:
enum { tmp = TypeLocator<Tail, T>::value };
public:
enum { value = tmp == -1 ? -1 : 1 + tmp };
};
template <class Head, class T>
struct TypeAppender;
/// TypeAppender appends T (type or a TypeList) to Head.
///
/// Usage:
///
/// typedef TypeListType<char>::HeadType Type1;
/// typedef TypeAppender<Type1, int>::HeadType Type2;
/// (Type2 is a TypeList of char,int)
///
/// typedef TypeListType<float, double>::HeadType Type3;
/// typedef TypeAppender<Type2, Type3>::HeadType Type4;
/// (Type4 is a TypeList of char,int,float,double)
///
template <>
struct TypeAppender<NullTypeList, NullTypeList>
{
typedef NullTypeList HeadType;
};
template <class T>
struct TypeAppender<NullTypeList, T>
{
typedef TypeList<T, NullTypeList> HeadType;
};
template <class Head, class Tail>
struct TypeAppender<NullTypeList, TypeList<Head, Tail> >
{
typedef TypeList<Head, Tail> HeadType;
};
template <class Head, class Tail, class T>
struct TypeAppender<TypeList<Head, Tail>, T>
{
typedef TypeList<Head, typename TypeAppender<Tail, T>::HeadType> HeadType;
};
template <class Head, class T>
struct TypeOneEraser;
/// TypeOneEraser erases the first occurence of the type T in Head.
/// Usage:
///
/// typedef TypeListType<char, int, float>::HeadType Type3;
/// typedef TypeOneEraser<Type3, int>::HeadType Type2;
/// (Type2 is a TypeList of char,float)
///
template <class T>
struct TypeOneEraser<NullTypeList, T>
{
typedef NullTypeList HeadType;
};
template <class T, class Tail>
struct TypeOneEraser<TypeList<T, Tail>, T>
{
typedef Tail HeadType;
};
template <class Head, class Tail, class T>
struct TypeOneEraser<TypeList<Head, Tail>, T>
{
typedef TypeList <Head, typename TypeOneEraser<Tail, T>::HeadType> HeadType;
};
template <class Head, class T>
struct TypeAllEraser;
/// TypeAllEraser erases all the occurences of the type T in Head.
/// Usage:
///
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
/// typedef TypeAllEraser<Type4, int>::HeadType Type2;
/// (Type2 is a TypeList of char,float)
///
template <class T>
struct TypeAllEraser<NullTypeList, T>
{
typedef NullTypeList HeadType;
};
template <class T, class Tail>
struct TypeAllEraser<TypeList<T, Tail>, T>
{
typedef typename TypeAllEraser<Tail, T>::HeadType HeadType;
};
template <class Head, class Tail, class T>
struct TypeAllEraser<TypeList<Head, Tail>, T>
{
typedef TypeList <Head, typename TypeAllEraser<Tail, T>::HeadType> HeadType;
};
template <class Head>
struct TypeDuplicateEraser;
/// TypeDuplicateEraser erases all but the first occurence of the type T in Head.
/// Usage:
///
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
/// typedef TypeDuplicateEraser<Type4, int>::HeadType Type3;
/// (Type3 is a TypeList of char,int,float)
///
template <>
struct TypeDuplicateEraser<NullTypeList>
{
typedef NullTypeList HeadType;
};
template <class Head, class Tail>
struct TypeDuplicateEraser<TypeList<Head, Tail> >
{
private:
typedef typename TypeDuplicateEraser<Tail>::HeadType L1;
typedef typename TypeOneEraser<L1, Head>::HeadType L2;
public:
typedef TypeList<Head, L2> HeadType;
};
template <class Head, class T, class R>
struct TypeOneReplacer;
/// TypeOneReplacer replaces the first occurence
/// of the type T in Head with type R.
/// Usage:
///
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
/// typedef TypeOneReplacer<Type4, int, double>::HeadType TypeR;
/// (TypeR is a TypeList of char,double,float,int)
///
template <class T, class R>
struct TypeOneReplacer<NullTypeList, T, R>
{
typedef NullTypeList HeadType;
};
template <class T, class Tail, class R>
struct TypeOneReplacer<TypeList<T, Tail>, T, R>
{
typedef TypeList<R, Tail> HeadType;
};
template <class Head, class Tail, class T, class R>
struct TypeOneReplacer<TypeList<Head, Tail>, T, R>
{
typedef TypeList<Head, typename TypeOneReplacer<Tail, T, R>::HeadType> HeadType;
};
template <class Head, class T, class R>
struct TypeAllReplacer;
/// TypeAllReplacer replaces all the occurences
/// of the type T in Head with type R.
/// Usage:
///
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
/// typedef TypeAllReplacer<Type4, int, double>::HeadType TypeR;
/// (TypeR is a TypeList of char,double,float,double)
///
template <class T, class R>
struct TypeAllReplacer<NullTypeList, T, R>
{
typedef NullTypeList HeadType;
};
template <class T, class Tail, class R>
struct TypeAllReplacer<TypeList<T, Tail>, T, R>
{
typedef TypeList<R, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
};
template <class Head, class Tail, class T, class R>
struct TypeAllReplacer<TypeList<Head, Tail>, T, R>
{
typedef TypeList<Head, typename TypeAllReplacer<Tail, T, R>::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 <class Head, class Tail>
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 <class Head, class Tail>
struct TypeList
/// Compile Time List of Types
{
typedef Head HeadType;
typedef Tail TailType;
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
typedef typename TypeWrapper<TailType>::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 <typename T0 = NullTypeList,
typename T1 = NullTypeList,
typename T2 = NullTypeList,
typename T3 = NullTypeList,
typename T4 = NullTypeList,
typename T5 = NullTypeList,
typename T6 = NullTypeList,
typename T7 = NullTypeList,
typename T8 = NullTypeList,
typename T9 = NullTypeList,
typename T10 = NullTypeList,
typename T11 = NullTypeList,
typename T12 = NullTypeList,
typename T13 = NullTypeList,
typename T14 = NullTypeList,
typename T15 = NullTypeList,
typename T16 = NullTypeList,
typename T17 = NullTypeList,
typename T18 = NullTypeList,
typename T19 = NullTypeList>
struct TypeListType
/// TypeListType takes 1 - 20 typename arguments.
/// Usage:
///
/// TypeListType<T0, T1, ... , Tn>::HeadType typeList;
///
/// typeList is a TypeList of T0, T1, ... , Tn
{
private:
typedef typename TypeListType<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>::HeadType TailType;
public:
typedef TypeList<T0, TailType> HeadType;
};
template <>
struct TypeListType<>
{
typedef NullTypeList HeadType;
};
template <int n>
struct Getter
{
template <class Ret, class Head, class Tail>
inline static Ret& get(TypeList<Head, Tail>& val)
{
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
}
template <class Ret, class Head, class Tail>
inline static const Ret& get(const TypeList<Head, Tail>& val)
{
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
}
};
template <>
struct Getter<0>
{
template <class Ret, class Head, class Tail>
inline static Ret& get(TypeList<Head, Tail>& val)
{
return val.head;
}
template <class Ret, class Head, class Tail>
inline static const Ret& get(const TypeList<Head, Tail>& val)
{
return val.head;
}
};
template <int N, class Head>
struct TypeGetter;
template <int N, class Head, class Tail>
struct TypeGetter<N, TypeList<Head, Tail> >
{
typedef typename TypeGetter<N-1, Tail>::HeadType HeadType;
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
};
template <class Head, class Tail>
struct TypeGetter<0, TypeList<Head, Tail> >
{
typedef typename TypeList<Head, Tail>::HeadType HeadType;
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
};
template <class Head, class T>
struct TypeLocator;
/// TypeLocator returns the first occurrence of the type T in Head
/// or -1 if the type is not found.
///
/// Usage example:
///
/// TypeLocator<Head, int>::HeadType TypeLoc;
///
/// if (2 == TypeLoc.value) ...
///
template <class T>
struct TypeLocator<NullTypeList, T>
{
enum { value = -1 };
};
template <class T, class Tail>
struct TypeLocator<TypeList<T, Tail>, T>
{
enum { value = 0 };
};
template <class Head, class Tail, class T>
struct TypeLocator<TypeList<Head, Tail>, T>
{
private:
enum { tmp = TypeLocator<Tail, T>::value };
public:
enum { value = tmp == -1 ? -1 : 1 + tmp };
};
template <class Head, class T>
struct TypeAppender;
/// TypeAppender appends T (type or a TypeList) to Head.
///
/// Usage:
///
/// typedef TypeListType<char>::HeadType Type1;
/// typedef TypeAppender<Type1, int>::HeadType Type2;
/// (Type2 is a TypeList of char,int)
///
/// typedef TypeListType<float, double>::HeadType Type3;
/// typedef TypeAppender<Type2, Type3>::HeadType Type4;
/// (Type4 is a TypeList of char,int,float,double)
///
template <>
struct TypeAppender<NullTypeList, NullTypeList>
{
typedef NullTypeList HeadType;
};
template <class T>
struct TypeAppender<NullTypeList, T>
{
typedef TypeList<T, NullTypeList> HeadType;
};
template <class Head, class Tail>
struct TypeAppender<NullTypeList, TypeList<Head, Tail> >
{
typedef TypeList<Head, Tail> HeadType;
};
template <class Head, class Tail, class T>
struct TypeAppender<TypeList<Head, Tail>, T>
{
typedef TypeList<Head, typename TypeAppender<Tail, T>::HeadType> HeadType;
};
template <class Head, class T>
struct TypeOneEraser;
/// TypeOneEraser erases the first occurence of the type T in Head.
/// Usage:
///
/// typedef TypeListType<char, int, float>::HeadType Type3;
/// typedef TypeOneEraser<Type3, int>::HeadType Type2;
/// (Type2 is a TypeList of char,float)
///
template <class T>
struct TypeOneEraser<NullTypeList, T>
{
typedef NullTypeList HeadType;
};
template <class T, class Tail>
struct TypeOneEraser<TypeList<T, Tail>, T>
{
typedef Tail HeadType;
};
template <class Head, class Tail, class T>
struct TypeOneEraser<TypeList<Head, Tail>, T>
{
typedef TypeList <Head, typename TypeOneEraser<Tail, T>::HeadType> HeadType;
};
template <class Head, class T>
struct TypeAllEraser;
/// TypeAllEraser erases all the occurences of the type T in Head.
/// Usage:
///
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
/// typedef TypeAllEraser<Type4, int>::HeadType Type2;
/// (Type2 is a TypeList of char,float)
///
template <class T>
struct TypeAllEraser<NullTypeList, T>
{
typedef NullTypeList HeadType;
};
template <class T, class Tail>
struct TypeAllEraser<TypeList<T, Tail>, T>
{
typedef typename TypeAllEraser<Tail, T>::HeadType HeadType;
};
template <class Head, class Tail, class T>
struct TypeAllEraser<TypeList<Head, Tail>, T>
{
typedef TypeList <Head, typename TypeAllEraser<Tail, T>::HeadType> HeadType;
};
template <class Head>
struct TypeDuplicateEraser;
/// TypeDuplicateEraser erases all but the first occurence of the type T in Head.
/// Usage:
///
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
/// typedef TypeDuplicateEraser<Type4, int>::HeadType Type3;
/// (Type3 is a TypeList of char,int,float)
///
template <>
struct TypeDuplicateEraser<NullTypeList>
{
typedef NullTypeList HeadType;
};
template <class Head, class Tail>
struct TypeDuplicateEraser<TypeList<Head, Tail> >
{
private:
typedef typename TypeDuplicateEraser<Tail>::HeadType L1;
typedef typename TypeOneEraser<L1, Head>::HeadType L2;
public:
typedef TypeList<Head, L2> HeadType;
};
template <class Head, class T, class R>
struct TypeOneReplacer;
/// TypeOneReplacer replaces the first occurence
/// of the type T in Head with type R.
/// Usage:
///
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
/// typedef TypeOneReplacer<Type4, int, double>::HeadType TypeR;
/// (TypeR is a TypeList of char,double,float,int)
///
template <class T, class R>
struct TypeOneReplacer<NullTypeList, T, R>
{
typedef NullTypeList HeadType;
};
template <class T, class Tail, class R>
struct TypeOneReplacer<TypeList<T, Tail>, T, R>
{
typedef TypeList<R, Tail> HeadType;
};
template <class Head, class Tail, class T, class R>
struct TypeOneReplacer<TypeList<Head, Tail>, T, R>
{
typedef TypeList<Head, typename TypeOneReplacer<Tail, T, R>::HeadType> HeadType;
};
template <class Head, class T, class R>
struct TypeAllReplacer;
/// TypeAllReplacer replaces all the occurences
/// of the type T in Head with type R.
/// Usage:
///
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
/// typedef TypeAllReplacer<Type4, int, double>::HeadType TypeR;
/// (TypeR is a TypeList of char,double,float,double)
///
template <class T, class R>
struct TypeAllReplacer<NullTypeList, T, R>
{
typedef NullTypeList HeadType;
};
template <class T, class Tail, class R>
struct TypeAllReplacer<TypeList<T, Tail>, T, R>
{
typedef TypeList<R, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
};
template <class Head, class Tail, class T, class R>
struct TypeAllReplacer<TypeList<Head, Tail>, T, R>
{
typedef TypeList<Head, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
};
} // namespace Poco
#endif

View File

@@ -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

View File

@@ -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 <windows.h>
#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 <windows.h>
#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

View File

@@ -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 <http://www.unicode.org>.
///
/// 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 <http://www.unicode.org>.
///
/// 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

View File

@@ -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 TKey, class TValue>
class UniqueAccessExpireCache: public AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >
/// 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<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >(UniqueAccessExpireStrategy<TKey, TValue>())
{
}
~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 TKey, class TValue>
class UniqueAccessExpireCache: public AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >
/// 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<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >(UniqueAccessExpireStrategy<TKey, TValue>())
{
}
~UniqueAccessExpireCache()
{
}
private:
UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache);
UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache);
};
} // namespace Poco
#endif

View File

@@ -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<TKey, TValue, StrategyCollection<TKey, TValue> >
/// 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<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
{
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
this->_strategy.pushBack(new UniqueAccessExpireStrategy<TKey, TValue>());
}
~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<TKey, TValue, StrategyCollection<TKey, TValue> >
/// 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<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
{
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
this->_strategy.pushBack(new UniqueAccessExpireStrategy<TKey, TValue>());
}
~UniqueAccessExpireLRUCache()
{
}
private:
UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache);
UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache);
};
} // namespace Poco
#endif

View File

@@ -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 <set>
#include <map>
#include <stdio.h>
namespace Poco {
template <
class TKey,
class TValue
>
class UniqueAccessExpireStrategy: public AbstractStrategy<TKey, TValue>
/// 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<TKey, Timespan> KeyExpire;
typedef std::multimap<Timestamp, KeyExpire> TimeIndex;
typedef typename TimeIndex::iterator IndexIterator;
typedef typename TimeIndex::const_iterator ConstIndexIterator;
typedef std::map<TKey, IndexIterator> Keys;
typedef typename Keys::iterator Iterator;
public:
UniqueAccessExpireStrategy()
/// Create an unique expire strategy.
{
}
~UniqueAccessExpireStrategy()
{
}
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& 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<Iterator, bool> 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<TKey>& 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<TKey>& 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 <set>
#include <map>
#include <stdio.h>
namespace Poco {
template <
class TKey,
class TValue
>
class UniqueAccessExpireStrategy: public AbstractStrategy<TKey, TValue>
/// 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<TKey, Timespan> KeyExpire;
typedef std::multimap<Timestamp, KeyExpire> TimeIndex;
typedef typename TimeIndex::iterator IndexIterator;
typedef typename TimeIndex::const_iterator ConstIndexIterator;
typedef std::map<TKey, IndexIterator> Keys;
typedef typename Keys::iterator Iterator;
public:
UniqueAccessExpireStrategy()
/// Create an unique expire strategy.
{
}
~UniqueAccessExpireStrategy()
{
}
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& 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<Iterator, bool> 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<TKey>& 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<TKey>& 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

View File

@@ -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 TKey, class TValue>
class UniqueExpireCache: public AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >
/// 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<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >(UniqueExpireStrategy<TKey, TValue>())
{
}
~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 TKey, class TValue>
class UniqueExpireCache: public AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >
/// 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<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >(UniqueExpireStrategy<TKey, TValue>())
{
}
~UniqueExpireCache()
{
}
private:
UniqueExpireCache(const UniqueExpireCache& aCache);
UniqueExpireCache& operator = (const UniqueExpireCache& aCache);
};
} // namespace Poco
#endif

View File

@@ -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<TKey, TValue, StrategyCollection<TKey, TValue> >
/// 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<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
{
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
this->_strategy.pushBack(new UniqueExpireStrategy<TKey, TValue>());
}
~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<TKey, TValue, StrategyCollection<TKey, TValue> >
/// 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<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
{
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
this->_strategy.pushBack(new UniqueExpireStrategy<TKey, TValue>());
}
~UniqueExpireLRUCache()
{
}
private:
UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache);
UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache);
};
} // namespace Poco
#endif

View File

@@ -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 <set>
#include <map>
namespace Poco {
template <
class TKey,
class TValue
>
class UniqueExpireStrategy: public AbstractStrategy<TKey, TValue>
/// 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<Timestamp, TKey> TimeIndex;
typedef typename TimeIndex::iterator IndexIterator;
typedef typename TimeIndex::const_iterator ConstIndexIterator;
typedef std::map<TKey, IndexIterator> Keys;
typedef typename Keys::iterator Iterator;
public:
UniqueExpireStrategy()
/// Create an unique expire strategy.
{
}
~UniqueExpireStrategy()
{
}
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& 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<Iterator, bool> 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<TKey>& 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<TKey>& 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 <set>
#include <map>
namespace Poco {
template <
class TKey,
class TValue
>
class UniqueExpireStrategy: public AbstractStrategy<TKey, TValue>
/// 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<Timestamp, TKey> TimeIndex;
typedef typename TimeIndex::iterator IndexIterator;
typedef typename TimeIndex::const_iterator ConstIndexIterator;
typedef std::map<TKey, IndexIterator> Keys;
typedef typename Keys::iterator Iterator;
public:
UniqueExpireStrategy()
/// Create an unique expire strategy.
{
}
~UniqueExpireStrategy()
{
}
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& 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<Iterator, bool> 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<TKey>& 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<TKey>& 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

View File

@@ -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