mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
synced 2025-11-01 11:07:53 +00:00
fixed line endings
This commit is contained in:
@@ -1,105 +1,105 @@
|
|||||||
//
|
//
|
||||||
// AccessExpirationDecorator.h
|
// AccessExpirationDecorator.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpirationDecorator.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/AccessExpirationDecorator.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Events
|
// Package: Events
|
||||||
// Module: AccessExpirationDecorator
|
// Module: AccessExpirationDecorator
|
||||||
//
|
//
|
||||||
// Implementation of the AccessExpirationDecorator template.
|
// Implementation of the AccessExpirationDecorator template.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_AccessExpirationDecorator_INCLUDED
|
#ifndef Foundation_AccessExpirationDecorator_INCLUDED
|
||||||
#define Foundation_AccessExpirationDecorator_INCLUDED
|
#define Foundation_AccessExpirationDecorator_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Timestamp.h"
|
#include "Poco/Timestamp.h"
|
||||||
#include "Poco/Timespan.h"
|
#include "Poco/Timespan.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <typename TArgs>
|
template <typename TArgs>
|
||||||
class AccessExpirationDecorator
|
class AccessExpirationDecorator
|
||||||
/// AccessExpirationDecorator adds an expiration method to values so that they can be used
|
/// AccessExpirationDecorator adds an expiration method to values so that they can be used
|
||||||
/// with the UniqueAccessExpireCache
|
/// with the UniqueAccessExpireCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AccessExpirationDecorator():
|
AccessExpirationDecorator():
|
||||||
_value(),
|
_value(),
|
||||||
_span()
|
_span()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
|
AccessExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
|
||||||
/// Creates an element that will expire in diff milliseconds
|
/// Creates an element that will expire in diff milliseconds
|
||||||
_value(p),
|
_value(p),
|
||||||
_span(diffInMs*1000)
|
_span(diffInMs*1000)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
|
AccessExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
|
||||||
/// Creates an element that will expire after the given timeSpan
|
/// Creates an element that will expire after the given timeSpan
|
||||||
_value(p),
|
_value(p),
|
||||||
_span(timeSpan)
|
_span(timeSpan)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
~AccessExpirationDecorator()
|
~AccessExpirationDecorator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const Poco::Timespan& getTimeout() const
|
const Poco::Timespan& getTimeout() const
|
||||||
{
|
{
|
||||||
return _span;
|
return _span;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TArgs& value() const
|
const TArgs& value() const
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
TArgs& value()
|
TArgs& value()
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TArgs _value;
|
TArgs _value;
|
||||||
Timespan _span;
|
Timespan _span;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,80 +1,80 @@
|
|||||||
//
|
//
|
||||||
// AccessExpireCache.h
|
// AccessExpireCache.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireCache.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireCache.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: AccessExpireCache
|
// Module: AccessExpireCache
|
||||||
//
|
//
|
||||||
// Definition of the AccessExpireCache class.
|
// Definition of the AccessExpireCache class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_AccessExpireCache_INCLUDED
|
#ifndef Foundation_AccessExpireCache_INCLUDED
|
||||||
#define Foundation_AccessExpireCache_INCLUDED
|
#define Foundation_AccessExpireCache_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AbstractCache.h"
|
#include "Poco/AbstractCache.h"
|
||||||
#include "Poco/AccessExpireStrategy.h"
|
#include "Poco/AccessExpireStrategy.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class TKey, class TValue>
|
template <class TKey, class TValue>
|
||||||
class AccessExpireCache: public AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >
|
class AccessExpireCache: public AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >
|
||||||
/// An AccessExpireCache caches entries for a fixed time period (per default 10 minutes).
|
/// 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
|
/// Entries expire when they are not accessed with get() during this time period. Each access resets
|
||||||
/// the start time for expiration.
|
/// the start time for expiration.
|
||||||
/// Be careful when using an AccessExpireCache. A cache is often used
|
/// 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
|
/// 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,
|
/// 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
|
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||||
/// when "get" is invoked.
|
/// when "get" is invoked.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AccessExpireCache(Timestamp::TimeDiff expire = 600000):
|
AccessExpireCache(Timestamp::TimeDiff expire = 600000):
|
||||||
AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >(AccessExpireStrategy<TKey, TValue>(expire))
|
AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >(AccessExpireStrategy<TKey, TValue>(expire))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~AccessExpireCache()
|
~AccessExpireCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AccessExpireCache(const AccessExpireCache& aCache);
|
AccessExpireCache(const AccessExpireCache& aCache);
|
||||||
AccessExpireCache& operator = (const AccessExpireCache& aCache);
|
AccessExpireCache& operator = (const AccessExpireCache& aCache);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,82 +1,82 @@
|
|||||||
//
|
//
|
||||||
// AccessExpireLRUCache.h
|
// AccessExpireLRUCache.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireLRUCache.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireLRUCache.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: AccessExpireLRUCache
|
// Module: AccessExpireLRUCache
|
||||||
//
|
//
|
||||||
// Definition of the AccessExpireLRUCache class.
|
// Definition of the AccessExpireLRUCache class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_AccessExpireLRUCache_INCLUDED
|
#ifndef Foundation_AccessExpireLRUCache_INCLUDED
|
||||||
#define Foundation_AccessExpireLRUCache_INCLUDED
|
#define Foundation_AccessExpireLRUCache_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AbstractCache.h"
|
#include "Poco/AbstractCache.h"
|
||||||
#include "Poco/StrategyCollection.h"
|
#include "Poco/StrategyCollection.h"
|
||||||
#include "Poco/AccessExpireStrategy.h"
|
#include "Poco/AccessExpireStrategy.h"
|
||||||
#include "Poco/LRUStrategy.h"
|
#include "Poco/LRUStrategy.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class TKey,
|
class TKey,
|
||||||
class TValue
|
class TValue
|
||||||
>
|
>
|
||||||
class AccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
class AccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||||
/// An AccessExpireLRUCache combines LRU caching and time based expire caching.
|
/// An AccessExpireLRUCache combines LRU caching and time based expire caching.
|
||||||
/// It cache entries for a fixed time period (per default 10 minutes)
|
/// It cache entries for a fixed time period (per default 10 minutes)
|
||||||
/// but also limits the size of the cache (per default: 1024).
|
/// but also limits the size of the cache (per default: 1024).
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AccessExpireLRUCache(long cacheSize = 1024, Timestamp::TimeDiff expire = 600000):
|
AccessExpireLRUCache(long cacheSize = 1024, Timestamp::TimeDiff expire = 600000):
|
||||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||||
{
|
{
|
||||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||||
this->_strategy.pushBack(new AccessExpireStrategy<TKey, TValue>(expire));
|
this->_strategy.pushBack(new AccessExpireStrategy<TKey, TValue>(expire));
|
||||||
}
|
}
|
||||||
|
|
||||||
~AccessExpireLRUCache()
|
~AccessExpireLRUCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AccessExpireLRUCache(const AccessExpireLRUCache& aCache);
|
AccessExpireLRUCache(const AccessExpireLRUCache& aCache);
|
||||||
AccessExpireLRUCache& operator = (const AccessExpireLRUCache& aCache);
|
AccessExpireLRUCache& operator = (const AccessExpireLRUCache& aCache);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,93 +1,93 @@
|
|||||||
//
|
//
|
||||||
// AccessExpireStrategy.h
|
// AccessExpireStrategy.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireStrategy.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireStrategy.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: AccessExpireStrategy
|
// Module: AccessExpireStrategy
|
||||||
//
|
//
|
||||||
// Definition of the AccessExpireStrategy class.
|
// Definition of the AccessExpireStrategy class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_AccessExpireStrategy_INCLUDED
|
#ifndef Foundation_AccessExpireStrategy_INCLUDED
|
||||||
#define Foundation_AccessExpireStrategy_INCLUDED
|
#define Foundation_AccessExpireStrategy_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/KeyValueArgs.h"
|
#include "Poco/KeyValueArgs.h"
|
||||||
#include "Poco/ValidArgs.h"
|
#include "Poco/ValidArgs.h"
|
||||||
#include "Poco/ExpireStrategy.h"
|
#include "Poco/ExpireStrategy.h"
|
||||||
#include "Poco/Bugcheck.h"
|
#include "Poco/Bugcheck.h"
|
||||||
#include "Poco/Timestamp.h"
|
#include "Poco/Timestamp.h"
|
||||||
#include "Poco/EventArgs.h"
|
#include "Poco/EventArgs.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class TKey,
|
class TKey,
|
||||||
class TValue
|
class TValue
|
||||||
>
|
>
|
||||||
class AccessExpireStrategy: public ExpireStrategy<TKey, TValue>
|
class AccessExpireStrategy: public ExpireStrategy<TKey, TValue>
|
||||||
/// An AccessExpireStrategy implements time and access based expiration of cache entries
|
/// An AccessExpireStrategy implements time and access based expiration of cache entries
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy<TKey, TValue>(expireTimeInMilliSec)
|
AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy<TKey, TValue>(expireTimeInMilliSec)
|
||||||
/// Create an expire strategy. Note that the smallest allowed caching time is 25ms.
|
/// Create an expire strategy. Note that the smallest allowed caching time is 25ms.
|
||||||
/// Anything lower than that is not useful with current operating systems.
|
/// Anything lower than that is not useful with current operating systems.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~AccessExpireStrategy()
|
~AccessExpireStrategy()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void onGet(const void*, const TKey& key)
|
void onGet(const void*, const TKey& key)
|
||||||
{
|
{
|
||||||
// get triggers an update to the expiration time
|
// get triggers an update to the expiration time
|
||||||
typename ExpireStrategy<TKey, TValue>::Iterator it = this->_keys.find(key);
|
typename ExpireStrategy<TKey, TValue>::Iterator it = this->_keys.find(key);
|
||||||
if (it != this->_keys.end())
|
if (it != this->_keys.end())
|
||||||
{
|
{
|
||||||
this->_keyIndex.erase(it->second);
|
this->_keyIndex.erase(it->second);
|
||||||
Timestamp now;
|
Timestamp now;
|
||||||
typename ExpireStrategy<TKey, TValue>::IndexIterator itIdx =
|
typename ExpireStrategy<TKey, TValue>::IndexIterator itIdx =
|
||||||
this->_keyIndex.insert(typename ExpireStrategy<TKey, TValue>::TimeIndex::value_type(now, key));
|
this->_keyIndex.insert(typename ExpireStrategy<TKey, TValue>::TimeIndex::value_type(now, key));
|
||||||
it->second = itIdx;
|
it->second = itIdx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,154 +1,154 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOChannel.h
|
// AsyncIOChannel.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOChannel.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOChannel.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: AsyncIO
|
// Package: AsyncIO
|
||||||
// Module: AsyncIOChannel
|
// Module: AsyncIOChannel
|
||||||
//
|
//
|
||||||
// Definition of the AsyncIOChannel class.
|
// Definition of the AsyncIOChannel class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_AsyncIOChannel_INCLUDED
|
#ifndef Foundation_AsyncIOChannel_INCLUDED
|
||||||
#define Foundation_AsyncIOChannel_INCLUDED
|
#define Foundation_AsyncIOChannel_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/ActiveDispatcher.h"
|
#include "Poco/ActiveDispatcher.h"
|
||||||
#include "Poco/ActiveMethod.h"
|
#include "Poco/ActiveMethod.h"
|
||||||
#include "Poco/AsyncIOCommand.h"
|
#include "Poco/AsyncIOCommand.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncIOChannel: public ActiveDispatcher
|
class Foundation_API AsyncIOChannel: public ActiveDispatcher
|
||||||
/// AsyncIOChannel supports asynchronous I/O operations on
|
/// AsyncIOChannel supports asynchronous I/O operations on
|
||||||
/// streams or other input/output facilities.
|
/// streams or other input/output facilities.
|
||||||
///
|
///
|
||||||
/// This implementation of asynchronous I/O is based on
|
/// This implementation of asynchronous I/O is based on
|
||||||
/// blocking I/O operations that are executed in a separate thread.
|
/// blocking I/O operations that are executed in a separate thread.
|
||||||
/// Some operating systems may provide special asynchronous
|
/// Some operating systems may provide special asynchronous
|
||||||
/// I/O operations at the operating system level. However, these
|
/// I/O operations at the operating system level. However, these
|
||||||
/// are not used by the current implementation.
|
/// are not used by the current implementation.
|
||||||
///
|
///
|
||||||
/// I/O operations (in the form of AsyncIOCommand subclass instances)
|
/// I/O operations (in the form of AsyncIOCommand subclass instances)
|
||||||
/// are queued for execution on an AsyncIOChannel. The AsyncIOChannel's
|
/// are queued for execution on an AsyncIOChannel. The AsyncIOChannel's
|
||||||
/// I/O thread executes all queued commands in FIFO order.
|
/// I/O thread executes all queued commands in FIFO order.
|
||||||
///
|
///
|
||||||
/// Since AsyncIOChannel is based on ActiveDispatcher, the I/O thread is
|
/// Since AsyncIOChannel is based on ActiveDispatcher, the I/O thread is
|
||||||
/// taken from the default thread pool. It should be ensured that the
|
/// taken from the default thread pool. It should be ensured that the
|
||||||
/// capacity of the default thread pool is sufficient before using
|
/// capacity of the default thread pool is sufficient before using
|
||||||
/// asynchronous I/O. For every AsyncIOChannel instance, one thread
|
/// asynchronous I/O. For every AsyncIOChannel instance, one thread
|
||||||
/// from the default thread pool is needed.
|
/// from the default thread pool is needed.
|
||||||
///
|
///
|
||||||
/// Subclasses of AsyncIOChannel implement asynchronous input/output
|
/// Subclasses of AsyncIOChannel implement asynchronous input/output
|
||||||
/// for streams and sockets.
|
/// for streams and sockets.
|
||||||
///
|
///
|
||||||
/// The enqueue() active member function is used to enqueue AsyncIOCommand
|
/// The enqueue() active member function is used to enqueue AsyncIOCommand
|
||||||
/// instances for execution.
|
/// instances for execution.
|
||||||
///
|
///
|
||||||
/// The cancel() member function (inherited from ActiveDispatcher) can be
|
/// The cancel() member function (inherited from ActiveDispatcher) can be
|
||||||
/// used to cancel all pending requests.
|
/// used to cancel all pending requests.
|
||||||
///
|
///
|
||||||
/// Both the AsyncIOCommand class, and the AsyncIOChannel class offer events
|
/// Both the AsyncIOCommand class, and the AsyncIOChannel class offer events
|
||||||
/// that notify an interested party about the successful or unsuccessful
|
/// that notify an interested party about the successful or unsuccessful
|
||||||
/// completion of a command.
|
/// completion of a command.
|
||||||
///
|
///
|
||||||
/// There are also two ways to wait for the completion of a command and
|
/// 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
|
/// obtain its result. The first one is by using the return value of
|
||||||
/// enqueue(), which is ActiveResult<int>. See the ActiveResult class
|
/// enqueue(), which is ActiveResult<int>. See the ActiveResult class
|
||||||
/// template for more information. The second one is by using the functions
|
/// template for more information. The second one is by using the functions
|
||||||
/// of AsyncIOCommand, such as wait(), succeeded() and result().
|
/// of AsyncIOCommand, such as wait(), succeeded() and result().
|
||||||
///
|
///
|
||||||
/// AsyncIOChannel supports the operations write, read and seek directly. However,
|
/// AsyncIOChannel supports the operations write, read and seek directly. However,
|
||||||
/// subclasses of AsyncIOChannel can define additional operations.
|
/// subclasses of AsyncIOChannel can define additional operations.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ActiveMethod<int, AsyncIOCommand::Ptr, AsyncIOChannel, ActiveStarter<ActiveDispatcher> > enqueue;
|
ActiveMethod<int, AsyncIOCommand::Ptr, AsyncIOChannel, ActiveStarter<ActiveDispatcher> > enqueue;
|
||||||
/// Actual signature:
|
/// Actual signature:
|
||||||
/// int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
|
/// int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
|
||||||
///
|
///
|
||||||
/// Enqueue the given command for eventual execution.
|
/// Enqueue the given command for eventual execution.
|
||||||
/// Returns the number of bytes read or written if the operation
|
/// Returns the number of bytes read or written if the operation
|
||||||
/// was successful.
|
/// was successful.
|
||||||
|
|
||||||
BasicEvent<AsyncIOEvent> commandCompleted;
|
BasicEvent<AsyncIOEvent> commandCompleted;
|
||||||
/// Fired when a command has successfully completed.
|
/// Fired when a command has successfully completed.
|
||||||
|
|
||||||
BasicEvent<AsyncIOEvent> commandFailed;
|
BasicEvent<AsyncIOEvent> commandFailed;
|
||||||
/// Fired when a command has failed.
|
/// Fired when a command has failed.
|
||||||
|
|
||||||
virtual int write(const void* buffer, int length);
|
virtual int write(const void* buffer, int length);
|
||||||
/// Write length bytes from buffer.
|
/// Write length bytes from buffer.
|
||||||
///
|
///
|
||||||
/// Must be overridden by subclasses. The default implementation
|
/// Must be overridden by subclasses. The default implementation
|
||||||
/// throws a NotImplementedException.
|
/// throws a NotImplementedException.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes written.
|
/// Returns the number of bytes written.
|
||||||
|
|
||||||
virtual int read(void* buffer, int length);
|
virtual int read(void* buffer, int length);
|
||||||
/// Read up to length bytes into buffer.
|
/// Read up to length bytes into buffer.
|
||||||
///
|
///
|
||||||
/// Must be overridden by subclasses. The default implementation
|
/// Must be overridden by subclasses. The default implementation
|
||||||
/// throws a NotImplementedException.
|
/// throws a NotImplementedException.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes read.
|
/// Returns the number of bytes read.
|
||||||
|
|
||||||
virtual int seek(std::streamoff off, std::ios::seekdir dir);
|
virtual int seek(std::streamoff off, std::ios::seekdir dir);
|
||||||
/// Sets the current read/write position.
|
/// Sets the current read/write position.
|
||||||
///
|
///
|
||||||
/// Must be overridden by subclasses. The default implementation
|
/// Must be overridden by subclasses. The default implementation
|
||||||
/// throws a NotImplementedException.
|
/// throws a NotImplementedException.
|
||||||
///
|
///
|
||||||
/// Always returns 0.
|
/// Always returns 0.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AsyncIOChannel();
|
AsyncIOChannel();
|
||||||
/// Creates the AsyncIOChannel.
|
/// Creates the AsyncIOChannel.
|
||||||
|
|
||||||
~AsyncIOChannel();
|
~AsyncIOChannel();
|
||||||
/// Destroys the AsyncIOChannel.
|
/// Destroys the AsyncIOChannel.
|
||||||
|
|
||||||
int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
|
int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
|
||||||
/// Execute the given command by calling
|
/// Execute the given command by calling
|
||||||
/// pCommand->execute(this);
|
/// pCommand->execute(this);
|
||||||
/// and return the result.
|
/// and return the result.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsyncIOChannel(const AsyncIOChannel&);
|
AsyncIOChannel(const AsyncIOChannel&);
|
||||||
AsyncIOChannel& operator = (const AsyncIOChannel&);
|
AsyncIOChannel& operator = (const AsyncIOChannel&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_AsyncIOChannel_INCLUDED
|
#endif // Foundation_AsyncIOChannel_INCLUDED
|
||||||
|
|||||||
@@ -1,319 +1,319 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOCommand.h
|
// AsyncIOCommand.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOCommand.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOCommand.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: AsyncIO
|
// Package: AsyncIO
|
||||||
// Module: AsyncIOCommand
|
// Module: AsyncIOCommand
|
||||||
//
|
//
|
||||||
// Definition of the AsyncIOCommand class and subclasses.
|
// Definition of the AsyncIOCommand class and subclasses.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_AsyncIOCommand_INCLUDED
|
#ifndef Foundation_AsyncIOCommand_INCLUDED
|
||||||
#define Foundation_AsyncIOCommand_INCLUDED
|
#define Foundation_AsyncIOCommand_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/RefCountedObject.h"
|
#include "Poco/RefCountedObject.h"
|
||||||
#include "Poco/AutoPtr.h"
|
#include "Poco/AutoPtr.h"
|
||||||
#include "Poco/Event.h"
|
#include "Poco/Event.h"
|
||||||
#include "Poco/BasicEvent.h"
|
#include "Poco/BasicEvent.h"
|
||||||
#include "Poco/AsyncIOEvent.h"
|
#include "Poco/AsyncIOEvent.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <ios>
|
#include <ios>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class AsyncIOChannel;
|
class AsyncIOChannel;
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncIOCommand: public RefCountedObject
|
class Foundation_API AsyncIOCommand: public RefCountedObject
|
||||||
/// AsyncIOCommand is the base class for all asynchronous input/output
|
/// AsyncIOCommand is the base class for all asynchronous input/output
|
||||||
/// commands used with AsyncIOChannel.
|
/// commands used with AsyncIOChannel.
|
||||||
///
|
///
|
||||||
/// See class AsyncIOChannel for more information about asynchronous input/output.
|
/// See class AsyncIOChannel for more information about asynchronous input/output.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef AutoPtr<AsyncIOCommand> Ptr;
|
typedef AutoPtr<AsyncIOCommand> Ptr;
|
||||||
|
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
CMD_PENDING, /// Command is queued for execution.
|
CMD_PENDING, /// Command is queued for execution.
|
||||||
CMD_IN_PROGRESS, /// Command is currently being executed.
|
CMD_IN_PROGRESS, /// Command is currently being executed.
|
||||||
CMD_COMPLETED, /// Command has completed successfully.
|
CMD_COMPLETED, /// Command has completed successfully.
|
||||||
CMD_FAILED /// Command has failed.
|
CMD_FAILED /// Command has failed.
|
||||||
};
|
};
|
||||||
|
|
||||||
BasicEvent<AsyncIOEvent> commandCompleted;
|
BasicEvent<AsyncIOEvent> commandCompleted;
|
||||||
/// Fired when the command has successfully completed.
|
/// Fired when the command has successfully completed.
|
||||||
|
|
||||||
BasicEvent<AsyncIOEvent> commandFailed;
|
BasicEvent<AsyncIOEvent> commandFailed;
|
||||||
/// Fired when the command has failed.
|
/// Fired when the command has failed.
|
||||||
|
|
||||||
State state() const;
|
State state() const;
|
||||||
/// Returns the current state of the command.
|
/// Returns the current state of the command.
|
||||||
|
|
||||||
void wait();
|
void wait();
|
||||||
/// Waits for the completion of the command.
|
/// Waits for the completion of the command.
|
||||||
|
|
||||||
void wait(long milliseconds);
|
void wait(long milliseconds);
|
||||||
/// Waits at most the given timeout for the
|
/// Waits at most the given timeout for the
|
||||||
/// completion of the command. Throws a
|
/// completion of the command. Throws a
|
||||||
/// TimeoutException if the command does
|
/// TimeoutException if the command does
|
||||||
/// not complete within the given timeout.
|
/// not complete within the given timeout.
|
||||||
|
|
||||||
bool tryWait(long milliseconds);
|
bool tryWait(long milliseconds);
|
||||||
/// Waits at most the given timeout for the
|
/// Waits at most the given timeout for the
|
||||||
/// completion of the command.
|
/// completion of the command.
|
||||||
///
|
///
|
||||||
/// Returns true if the command completes within
|
/// Returns true if the command completes within
|
||||||
/// the given timeout, otherwise false.
|
/// the given timeout, otherwise false.
|
||||||
|
|
||||||
bool succeeded() const;
|
bool succeeded() const;
|
||||||
/// Returns true iff the command completed successfully.
|
/// Returns true iff the command completed successfully.
|
||||||
|
|
||||||
bool failed() const;
|
bool failed() const;
|
||||||
/// Returns true iff the command has completed with an error.
|
/// Returns true iff the command has completed with an error.
|
||||||
|
|
||||||
const Exception* exception() const;
|
const Exception* exception() const;
|
||||||
/// If the command failed with an exception, returns a
|
/// If the command failed with an exception, returns a
|
||||||
/// clone of the exception. Otherwise, returns a null pointer.
|
/// clone of the exception. Otherwise, returns a null pointer.
|
||||||
|
|
||||||
int execute(AsyncIOChannel& channel);
|
int execute(AsyncIOChannel& channel);
|
||||||
/// Executes the command on the given AsyncIOChannel.
|
/// Executes the command on the given AsyncIOChannel.
|
||||||
///
|
///
|
||||||
/// Sets the state to CMD_IN_PROGRESS, calls
|
/// Sets the state to CMD_IN_PROGRESS, calls
|
||||||
/// executeImpl(), and, according to its result,
|
/// executeImpl(), and, according to its result,
|
||||||
/// sets the state to CMD_COMPLETED or CMD_FAILED
|
/// sets the state to CMD_COMPLETED or CMD_FAILED
|
||||||
/// and signals the event.
|
/// and signals the event.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes processed by the
|
/// Returns the number of bytes processed by the
|
||||||
/// command.
|
/// command.
|
||||||
|
|
||||||
int result() const;
|
int result() const;
|
||||||
/// Returns the result of the command.
|
/// Returns the result of the command.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AsyncIOCommand();
|
AsyncIOCommand();
|
||||||
/// Creates the AsyncIOCommand.
|
/// Creates the AsyncIOCommand.
|
||||||
|
|
||||||
~AsyncIOCommand();
|
~AsyncIOCommand();
|
||||||
/// Destroys the AsyncIOCommand.
|
/// Destroys the AsyncIOCommand.
|
||||||
|
|
||||||
virtual int executeImpl(AsyncIOChannel& channel) = 0;
|
virtual int executeImpl(AsyncIOChannel& channel) = 0;
|
||||||
/// Executes the command on the given AsyncIOChannel.
|
/// Executes the command on the given AsyncIOChannel.
|
||||||
/// Must be overridded by subclasses.
|
/// Must be overridded by subclasses.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes processed by the
|
/// Returns the number of bytes processed by the
|
||||||
/// command.
|
/// command.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
State _state;
|
State _state;
|
||||||
Event _completed;
|
Event _completed;
|
||||||
int _result;
|
int _result;
|
||||||
Exception* _pException;
|
Exception* _pException;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncWriteCommand: public AsyncIOCommand
|
class Foundation_API AsyncWriteCommand: public AsyncIOCommand
|
||||||
/// An asynchronous write command.
|
/// An asynchronous write command.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncWriteCommand(const void* buffer, int length);
|
AsyncWriteCommand(const void* buffer, int length);
|
||||||
/// Create an AsyncWriteCommand for writing length bytes
|
/// Create an AsyncWriteCommand for writing length bytes
|
||||||
/// from the given buffer. The given buffer must be
|
/// from the given buffer. The given buffer must be
|
||||||
/// valid until the command completes.
|
/// valid until the command completes.
|
||||||
|
|
||||||
const void* buffer() const;
|
const void* buffer() const;
|
||||||
/// Returns the buffer's address.
|
/// Returns the buffer's address.
|
||||||
|
|
||||||
int length() const;
|
int length() const;
|
||||||
/// Returns the buffer's size.
|
/// Returns the buffer's size.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int executeImpl(AsyncIOChannel& channel);
|
int executeImpl(AsyncIOChannel& channel);
|
||||||
~AsyncWriteCommand();
|
~AsyncWriteCommand();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsyncWriteCommand();
|
AsyncWriteCommand();
|
||||||
|
|
||||||
const void* _buffer;
|
const void* _buffer;
|
||||||
int _length;
|
int _length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncBufferedWriteCommand: public AsyncWriteCommand
|
class Foundation_API AsyncBufferedWriteCommand: public AsyncWriteCommand
|
||||||
/// An asynchronous write command. The difference to
|
/// An asynchronous write command. The difference to
|
||||||
/// AsyncWriteCommand is that AsyncBufferedWriteCommand
|
/// AsyncWriteCommand is that AsyncBufferedWriteCommand
|
||||||
/// copies the data in the buffer into an internal buffer, thus
|
/// copies the data in the buffer into an internal buffer, thus
|
||||||
/// the given buffer can be deleted as soon as the constructor
|
/// the given buffer can be deleted as soon as the constructor
|
||||||
/// returns.
|
/// returns.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncBufferedWriteCommand(const void* buffer, int length);
|
AsyncBufferedWriteCommand(const void* buffer, int length);
|
||||||
/// Create an AsyncBufferedWriteCommand for writing length bytes
|
/// Create an AsyncBufferedWriteCommand for writing length bytes
|
||||||
/// from the given buffer and copies the data from the
|
/// from the given buffer and copies the data from the
|
||||||
/// given buffer into an internal buffer.
|
/// given buffer into an internal buffer.
|
||||||
///
|
///
|
||||||
/// The internal buffer can be accessed via the buffer()
|
/// The internal buffer can be accessed via the buffer()
|
||||||
/// member function inherited from AsyncWriteCommand.
|
/// member function inherited from AsyncWriteCommand.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~AsyncBufferedWriteCommand();
|
~AsyncBufferedWriteCommand();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncReadCommand: public AsyncIOCommand
|
class Foundation_API AsyncReadCommand: public AsyncIOCommand
|
||||||
/// An asynchronous read command.
|
/// An asynchronous read command.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncReadCommand(void* buffer, int length);
|
AsyncReadCommand(void* buffer, int length);
|
||||||
/// Create an AsyncReadCommand for reading up to length
|
/// Create an AsyncReadCommand for reading up to length
|
||||||
/// bytes into the given buffer.
|
/// bytes into the given buffer.
|
||||||
|
|
||||||
void* buffer() const;
|
void* buffer() const;
|
||||||
/// Returns the buffer's address.
|
/// Returns the buffer's address.
|
||||||
|
|
||||||
int length() const;
|
int length() const;
|
||||||
/// Returns the buffer's size.
|
/// Returns the buffer's size.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int executeImpl(AsyncIOChannel& channel);
|
int executeImpl(AsyncIOChannel& channel);
|
||||||
~AsyncReadCommand();
|
~AsyncReadCommand();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsyncReadCommand();
|
AsyncReadCommand();
|
||||||
|
|
||||||
void* _buffer;
|
void* _buffer;
|
||||||
int _length;
|
int _length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncBufferedReadCommand: public AsyncReadCommand
|
class Foundation_API AsyncBufferedReadCommand: public AsyncReadCommand
|
||||||
/// An asynchronous read command. In contrast to
|
/// An asynchronous read command. In contrast to
|
||||||
/// AsyncReadCommand, which requires an externally supplied
|
/// AsyncReadCommand, which requires an externally supplied
|
||||||
/// buffer that must be valid until the command completes,
|
/// buffer that must be valid until the command completes,
|
||||||
/// AsyncBufferedReadCommand maintains an internal buffer.
|
/// AsyncBufferedReadCommand maintains an internal buffer.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncBufferedReadCommand(int length);
|
AsyncBufferedReadCommand(int length);
|
||||||
/// Create an AsyncReadCommand for reading up to length
|
/// Create an AsyncReadCommand for reading up to length
|
||||||
/// bytes into an internal buffer.
|
/// bytes into an internal buffer.
|
||||||
///
|
///
|
||||||
/// The buffer can be accessed via the buffer() member
|
/// The buffer can be accessed via the buffer() member
|
||||||
/// function inherited from AsyncReadCommand.
|
/// function inherited from AsyncReadCommand.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~AsyncBufferedReadCommand();
|
~AsyncBufferedReadCommand();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncSeekCommand: public AsyncIOCommand
|
class Foundation_API AsyncSeekCommand: public AsyncIOCommand
|
||||||
/// An asynchronous seek command.
|
/// An asynchronous seek command.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir = std::ios::beg);
|
AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir = std::ios::beg);
|
||||||
/// Creates an AsyncSeekCommand for setting the current read/write position.
|
/// Creates an AsyncSeekCommand for setting the current read/write position.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int executeImpl(AsyncIOChannel& channel);
|
int executeImpl(AsyncIOChannel& channel);
|
||||||
~AsyncSeekCommand();
|
~AsyncSeekCommand();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsyncSeekCommand();
|
AsyncSeekCommand();
|
||||||
|
|
||||||
std::streamoff _off;
|
std::streamoff _off;
|
||||||
std::ios::seekdir _dir;
|
std::ios::seekdir _dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline AsyncIOCommand::State AsyncIOCommand::state() const
|
inline AsyncIOCommand::State AsyncIOCommand::state() const
|
||||||
{
|
{
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int AsyncIOCommand::result() const
|
inline int AsyncIOCommand::result() const
|
||||||
{
|
{
|
||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Exception* AsyncIOCommand::exception() const
|
inline const Exception* AsyncIOCommand::exception() const
|
||||||
{
|
{
|
||||||
return _pException;
|
return _pException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool AsyncIOCommand::succeeded() const
|
inline bool AsyncIOCommand::succeeded() const
|
||||||
{
|
{
|
||||||
return _state == CMD_COMPLETED;
|
return _state == CMD_COMPLETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool AsyncIOCommand::failed() const
|
inline bool AsyncIOCommand::failed() const
|
||||||
{
|
{
|
||||||
return _state == CMD_FAILED;
|
return _state == CMD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const void* AsyncWriteCommand::buffer() const
|
inline const void* AsyncWriteCommand::buffer() const
|
||||||
{
|
{
|
||||||
return _buffer;
|
return _buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int AsyncWriteCommand::length() const
|
inline int AsyncWriteCommand::length() const
|
||||||
{
|
{
|
||||||
return _length;
|
return _length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void* AsyncReadCommand::buffer() const
|
inline void* AsyncReadCommand::buffer() const
|
||||||
{
|
{
|
||||||
return _buffer;
|
return _buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int AsyncReadCommand::length() const
|
inline int AsyncReadCommand::length() const
|
||||||
{
|
{
|
||||||
return _length;
|
return _length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_AsyncIOCommand_INCLUDED
|
#endif // Foundation_AsyncIOCommand_INCLUDED
|
||||||
|
|||||||
@@ -1,121 +1,121 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOEvent.h
|
// AsyncIOEvent.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOEvent.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOEvent.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: AsyncIO
|
// Package: AsyncIO
|
||||||
// Module: AsyncIOEvent
|
// Module: AsyncIOEvent
|
||||||
//
|
//
|
||||||
// Definition of the AsyncIOEvent class.
|
// Definition of the AsyncIOEvent class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_AsyncIOEvent_INCLUDED
|
#ifndef Foundation_AsyncIOEvent_INCLUDED
|
||||||
#define Foundation_AsyncIOEvent_INCLUDED
|
#define Foundation_AsyncIOEvent_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class AsyncIOCommand;
|
class AsyncIOCommand;
|
||||||
class AsyncIOChannel;
|
class AsyncIOChannel;
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncIOEvent
|
class Foundation_API AsyncIOEvent
|
||||||
/// The AsyncIOEvent class holds information about an event
|
/// The AsyncIOEvent class holds information about an event
|
||||||
/// caused by asynchronous input or output operation.
|
/// caused by asynchronous input or output operation.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum EventKind
|
enum EventKind
|
||||||
{
|
{
|
||||||
EV_COMMAND_COMPLETED,
|
EV_COMMAND_COMPLETED,
|
||||||
EV_COMMAND_FAILED
|
EV_COMMAND_FAILED
|
||||||
};
|
};
|
||||||
|
|
||||||
AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what);
|
AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what);
|
||||||
/// Creates the AsyncIOEvent.
|
/// Creates the AsyncIOEvent.
|
||||||
|
|
||||||
AsyncIOEvent(const AsyncIOEvent& event);
|
AsyncIOEvent(const AsyncIOEvent& event);
|
||||||
/// Creates a AsyncIOEvent from another one.
|
/// Creates a AsyncIOEvent from another one.
|
||||||
|
|
||||||
~AsyncIOEvent();
|
~AsyncIOEvent();
|
||||||
/// Destroys the AsyncIOEvent.
|
/// Destroys the AsyncIOEvent.
|
||||||
|
|
||||||
AsyncIOEvent& operator = (const AsyncIOEvent& event);
|
AsyncIOEvent& operator = (const AsyncIOEvent& event);
|
||||||
/// Assigns a AsyncIOEvent.
|
/// Assigns a AsyncIOEvent.
|
||||||
|
|
||||||
void swap(AsyncIOEvent& event);
|
void swap(AsyncIOEvent& event);
|
||||||
/// Swaps the event with another one.
|
/// Swaps the event with another one.
|
||||||
|
|
||||||
AsyncIOCommand& command() const;
|
AsyncIOCommand& command() const;
|
||||||
/// Returns the command that caused the event.
|
/// Returns the command that caused the event.
|
||||||
|
|
||||||
AsyncIOChannel& channel() const;
|
AsyncIOChannel& channel() const;
|
||||||
/// Returns the channel that caused the event.
|
/// Returns the channel that caused the event.
|
||||||
|
|
||||||
EventKind what() const;
|
EventKind what() const;
|
||||||
/// Returns the reason of the event.
|
/// Returns the reason of the event.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsyncIOEvent();
|
AsyncIOEvent();
|
||||||
|
|
||||||
AsyncIOCommand* _pCommand;
|
AsyncIOCommand* _pCommand;
|
||||||
AsyncIOChannel* _pChannel;
|
AsyncIOChannel* _pChannel;
|
||||||
EventKind _what;
|
EventKind _what;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline AsyncIOCommand& AsyncIOEvent::command() const
|
inline AsyncIOCommand& AsyncIOEvent::command() const
|
||||||
{
|
{
|
||||||
return *_pCommand;
|
return *_pCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline AsyncIOChannel& AsyncIOEvent::channel() const
|
inline AsyncIOChannel& AsyncIOEvent::channel() const
|
||||||
{
|
{
|
||||||
return *_pChannel;
|
return *_pChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline AsyncIOEvent::EventKind AsyncIOEvent::what() const
|
inline AsyncIOEvent::EventKind AsyncIOEvent::what() const
|
||||||
{
|
{
|
||||||
return _what;
|
return _what;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_AsyncIOEvent_INCLUDED
|
#endif // Foundation_AsyncIOEvent_INCLUDED
|
||||||
|
|||||||
@@ -1,96 +1,96 @@
|
|||||||
//
|
//
|
||||||
// AsyncStreamChannel.h
|
// AsyncStreamChannel.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncStreamChannel.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/AsyncStreamChannel.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: AsyncIO
|
// Package: AsyncIO
|
||||||
// Module: AsyncStreamChannel
|
// Module: AsyncStreamChannel
|
||||||
//
|
//
|
||||||
// Definition of the AsyncStreamChannel class.
|
// Definition of the AsyncStreamChannel class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_AsyncStreamChannel_INCLUDED
|
#ifndef Foundation_AsyncStreamChannel_INCLUDED
|
||||||
#define Foundation_AsyncStreamChannel_INCLUDED
|
#define Foundation_AsyncStreamChannel_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/AsyncIOChannel.h"
|
#include "Poco/AsyncIOChannel.h"
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API AsyncStreamChannel: public AsyncIOChannel
|
class Foundation_API AsyncStreamChannel: public AsyncIOChannel
|
||||||
/// AsyncStreamChannel provides an AsyncIOChannel for I/O streams.
|
/// AsyncStreamChannel provides an AsyncIOChannel for I/O streams.
|
||||||
///
|
///
|
||||||
/// Usage Example:
|
/// Usage Example:
|
||||||
/// std::stringstream str;
|
/// std::stringstream str;
|
||||||
/// AsyncStreamChannel channel(str);
|
/// AsyncStreamChannel channel(str);
|
||||||
/// channel.enqueue(new AsyncWriteCommand("Hello", 5));
|
/// channel.enqueue(new AsyncWriteCommand("Hello", 5));
|
||||||
/// channel.enqueue(new AsyncWriteCommand(", ", 2));
|
/// channel.enqueue(new AsyncWriteCommand(", ", 2));
|
||||||
/// ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
|
/// ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
|
||||||
/// result.wait();
|
/// result.wait();
|
||||||
/// std::string s(str.str());
|
/// std::string s(str.str());
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncStreamChannel(std::istream& istr);
|
AsyncStreamChannel(std::istream& istr);
|
||||||
/// Creates an AsyncStreamChannel using the given input stream.
|
/// Creates an AsyncStreamChannel using the given input stream.
|
||||||
/// Only read and seek operations will be allowed.
|
/// Only read and seek operations will be allowed.
|
||||||
|
|
||||||
AsyncStreamChannel(std::ostream& ostr);
|
AsyncStreamChannel(std::ostream& ostr);
|
||||||
/// Creates an AsyncStreamChannel using the given output stream.
|
/// Creates an AsyncStreamChannel using the given output stream.
|
||||||
/// Only write and seek operations will be allowed.
|
/// Only write and seek operations will be allowed.
|
||||||
|
|
||||||
AsyncStreamChannel(std::iostream& iostr);
|
AsyncStreamChannel(std::iostream& iostr);
|
||||||
/// Creates an AsyncStreamChannel using the given input/output stream.
|
/// Creates an AsyncStreamChannel using the given input/output stream.
|
||||||
|
|
||||||
~AsyncStreamChannel();
|
~AsyncStreamChannel();
|
||||||
/// Destroys the AsyncStreamChannel.
|
/// Destroys the AsyncStreamChannel.
|
||||||
|
|
||||||
// AsyncIOChannel
|
// AsyncIOChannel
|
||||||
int write(const void* buffer, int length);
|
int write(const void* buffer, int length);
|
||||||
int read(void* buffer, int length);
|
int read(void* buffer, int length);
|
||||||
int seek(std::streamoff off, std::ios::seekdir dir);
|
int seek(std::streamoff off, std::ios::seekdir dir);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsyncStreamChannel();
|
AsyncStreamChannel();
|
||||||
|
|
||||||
std::istream* _pIstr;
|
std::istream* _pIstr;
|
||||||
std::ostream* _pOstr;
|
std::ostream* _pOstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_AsyncStreamChannel_INCLUDED
|
#endif // Foundation_AsyncStreamChannel_INCLUDED
|
||||||
|
|||||||
@@ -1,130 +1,130 @@
|
|||||||
//
|
//
|
||||||
// Checksum.h
|
// Checksum.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/Checksum.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/Checksum.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: Checksum
|
// Module: Checksum
|
||||||
//
|
//
|
||||||
// Definition of the Checksum class.
|
// Definition of the Checksum class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_Checksum_INCLUDED
|
#ifndef Foundation_Checksum_INCLUDED
|
||||||
#define Foundation_Checksum_INCLUDED
|
#define Foundation_Checksum_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API Checksum
|
class Foundation_API Checksum
|
||||||
/// This class calculates CRC-32 or Adler-32 checksums
|
/// This class calculates CRC-32 or Adler-32 checksums
|
||||||
/// for arbitrary data.
|
/// for arbitrary data.
|
||||||
///
|
///
|
||||||
/// A cyclic redundancy check (CRC) is a type of hash function, which is used to produce a
|
/// 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
|
/// 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.
|
/// 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.
|
/// 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
|
/// 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,
|
/// accidental modification of data, such as distortions occurring during a transmission,
|
||||||
/// but is significantly faster to calculate in software.
|
/// but is significantly faster to calculate in software.
|
||||||
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
TYPE_ADLER32 = 0,
|
TYPE_ADLER32 = 0,
|
||||||
TYPE_CRC32
|
TYPE_CRC32
|
||||||
};
|
};
|
||||||
|
|
||||||
Checksum();
|
Checksum();
|
||||||
/// Creates a CRC-32 checksum initialized to 0.
|
/// Creates a CRC-32 checksum initialized to 0.
|
||||||
|
|
||||||
Checksum(Type t);
|
Checksum(Type t);
|
||||||
/// Creates the Checksum, using the given type.
|
/// Creates the Checksum, using the given type.
|
||||||
|
|
||||||
~Checksum();
|
~Checksum();
|
||||||
/// Destroys the Checksum.
|
/// Destroys the Checksum.
|
||||||
|
|
||||||
void update(const char* data, unsigned length);
|
void update(const char* data, unsigned length);
|
||||||
/// Updates the checksum with the given data.
|
/// Updates the checksum with the given data.
|
||||||
|
|
||||||
void update(const std::string& data);
|
void update(const std::string& data);
|
||||||
/// Updates the checksum with the given data.
|
/// Updates the checksum with the given data.
|
||||||
|
|
||||||
void update(char data);
|
void update(char data);
|
||||||
/// Updates the checksum with the given data.
|
/// Updates the checksum with the given data.
|
||||||
|
|
||||||
Poco::UInt32 checksum() const;
|
Poco::UInt32 checksum() const;
|
||||||
/// Returns the calculated checksum.
|
/// Returns the calculated checksum.
|
||||||
|
|
||||||
Type type() const;
|
Type type() const;
|
||||||
/// Which type of checksum are we calulcating
|
/// Which type of checksum are we calulcating
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type _type;
|
Type _type;
|
||||||
Poco::UInt32 _value;
|
Poco::UInt32 _value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline void Checksum::update(const std::string& data)
|
inline void Checksum::update(const std::string& data)
|
||||||
{
|
{
|
||||||
update(data.c_str(), static_cast<unsigned int>(data.size()));
|
update(data.c_str(), static_cast<unsigned int>(data.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Checksum::update(char c)
|
inline void Checksum::update(char c)
|
||||||
{
|
{
|
||||||
update(&c, 1);
|
update(&c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Poco::UInt32 Checksum::checksum() const
|
inline Poco::UInt32 Checksum::checksum() const
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Checksum::Type Checksum::type() const
|
inline Checksum::Type Checksum::type() const
|
||||||
{
|
{
|
||||||
return _type;
|
return _type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_Checksum_INCLUDED
|
#endif // Foundation_Checksum_INCLUDED
|
||||||
|
|||||||
@@ -1,159 +1,159 @@
|
|||||||
//
|
//
|
||||||
// Condition.h
|
// Condition.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/Condition.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/Condition.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
// Module: Condition
|
// Module: Condition
|
||||||
//
|
//
|
||||||
// Definition of the Condition class template.
|
// Definition of the Condition class template.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_Condition_INCLUDED
|
#ifndef Foundation_Condition_INCLUDED
|
||||||
#define Foundation_Condition_INCLUDED
|
#define Foundation_Condition_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/Mutex.h"
|
#include "Poco/Mutex.h"
|
||||||
#include "Poco/ScopedUnlock.h"
|
#include "Poco/ScopedUnlock.h"
|
||||||
#include "Poco/Event.h"
|
#include "Poco/Event.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API Condition
|
class Foundation_API Condition
|
||||||
/// A Condition is a synchronization object used to block a thread
|
/// A Condition is a synchronization object used to block a thread
|
||||||
/// until a particular condition is met.
|
/// until a particular condition is met.
|
||||||
/// A Condition object is always used in conjunction with
|
/// A Condition object is always used in conjunction with
|
||||||
/// a Mutex (or FastMutex) object.
|
/// a Mutex (or FastMutex) object.
|
||||||
///
|
///
|
||||||
/// Condition objects are similar to POSIX condition variables, which the
|
/// Condition objects are similar to POSIX condition variables, which the
|
||||||
/// difference that Condition is not subject to spurious wakeups.
|
/// difference that Condition is not subject to spurious wakeups.
|
||||||
///
|
///
|
||||||
/// Threads waiting on a Condition are resumed in FIFO order.
|
/// Threads waiting on a Condition are resumed in FIFO order.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Condition();
|
Condition();
|
||||||
/// Creates the Condition.
|
/// Creates the Condition.
|
||||||
|
|
||||||
~Condition();
|
~Condition();
|
||||||
/// Destroys the Condition.
|
/// Destroys the Condition.
|
||||||
|
|
||||||
template <class Mtx>
|
template <class Mtx>
|
||||||
void wait(Mtx& mutex)
|
void wait(Mtx& mutex)
|
||||||
/// Unlocks the mutex (which must be locked upon calling
|
/// Unlocks the mutex (which must be locked upon calling
|
||||||
/// wait()) and waits until the Condition is signalled.
|
/// wait()) and waits until the Condition is signalled.
|
||||||
///
|
///
|
||||||
/// The given mutex will be locked again upon
|
/// The given mutex will be locked again upon
|
||||||
/// leaving the function, even in case of an exception.
|
/// leaving the function, even in case of an exception.
|
||||||
{
|
{
|
||||||
ScopedUnlock<Mtx> unlock(mutex, false);
|
ScopedUnlock<Mtx> unlock(mutex, false);
|
||||||
Event event;
|
Event event;
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
enqueue(event);
|
enqueue(event);
|
||||||
}
|
}
|
||||||
event.wait();
|
event.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Mtx>
|
template <class Mtx>
|
||||||
void wait(Mtx& mutex, long milliseconds)
|
void wait(Mtx& mutex, long milliseconds)
|
||||||
/// Unlocks the mutex (which must be locked upon calling
|
/// Unlocks the mutex (which must be locked upon calling
|
||||||
/// wait()) and waits for the given time until the Condition is signalled.
|
/// wait()) and waits for the given time until the Condition is signalled.
|
||||||
///
|
///
|
||||||
/// The given mutex will be locked again upon successfully leaving the
|
/// The given mutex will be locked again upon successfully leaving the
|
||||||
/// function, even in case of an exception.
|
/// function, even in case of an exception.
|
||||||
///
|
///
|
||||||
/// Throws a TimeoutException if the Condition is not signalled
|
/// Throws a TimeoutException if the Condition is not signalled
|
||||||
/// within the given time interval.
|
/// within the given time interval.
|
||||||
{
|
{
|
||||||
if (!tryWait(mutex, milliseconds))
|
if (!tryWait(mutex, milliseconds))
|
||||||
throw TimeoutException();
|
throw TimeoutException();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Mtx>
|
template <class Mtx>
|
||||||
bool tryWait(Mtx& mutex, long milliseconds)
|
bool tryWait(Mtx& mutex, long milliseconds)
|
||||||
/// Unlocks the mutex (which must be locked upon calling
|
/// Unlocks the mutex (which must be locked upon calling
|
||||||
/// tryWait()) and waits for the given time until the Condition is signalled.
|
/// tryWait()) and waits for the given time until the Condition is signalled.
|
||||||
///
|
///
|
||||||
/// The given mutex will be locked again upon leaving the
|
/// The given mutex will be locked again upon leaving the
|
||||||
/// function, even in case of an exception.
|
/// function, even in case of an exception.
|
||||||
///
|
///
|
||||||
/// Returns true if the Condition has been signalled
|
/// Returns true if the Condition has been signalled
|
||||||
/// within the given time interval, otherwise false.
|
/// within the given time interval, otherwise false.
|
||||||
{
|
{
|
||||||
ScopedUnlock<Mtx> unlock(mutex, false);
|
ScopedUnlock<Mtx> unlock(mutex, false);
|
||||||
Event event;
|
Event event;
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
enqueue(event);
|
enqueue(event);
|
||||||
}
|
}
|
||||||
if (!event.tryWait(milliseconds))
|
if (!event.tryWait(milliseconds))
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
dequeue(event);
|
dequeue(event);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal();
|
void signal();
|
||||||
/// Signals the Condition and allows one waiting thread
|
/// Signals the Condition and allows one waiting thread
|
||||||
/// to continue execution.
|
/// to continue execution.
|
||||||
|
|
||||||
void broadcast();
|
void broadcast();
|
||||||
/// Signals the Condition and allows all waiting
|
/// Signals the Condition and allows all waiting
|
||||||
/// threads to continue their execution.
|
/// threads to continue their execution.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void enqueue(Event& event);
|
void enqueue(Event& event);
|
||||||
void dequeue();
|
void dequeue();
|
||||||
void dequeue(Event& event);
|
void dequeue(Event& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Condition(const Condition&);
|
Condition(const Condition&);
|
||||||
Condition& operator = (const Condition&);
|
Condition& operator = (const Condition&);
|
||||||
|
|
||||||
typedef std::deque<Event*> WaitQueue;
|
typedef std::deque<Event*> WaitQueue;
|
||||||
|
|
||||||
FastMutex _mutex;
|
FastMutex _mutex;
|
||||||
WaitQueue _waitQueue;
|
WaitQueue _waitQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_Condition_INCLUDED
|
#endif // Foundation_Condition_INCLUDED
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,399 +1,399 @@
|
|||||||
//
|
//
|
||||||
// DynamicStruct.h
|
// DynamicStruct.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/include/Poco/DynamicStruct.h#9 $
|
// $Id: //poco/Main/Foundation/include/Poco/DynamicStruct.h#9 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: DynamicStruct
|
// Module: DynamicStruct
|
||||||
//
|
//
|
||||||
// Definition of the DynamicStruct class.
|
// Definition of the DynamicStruct class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_DynamicStruct_INCLUDED
|
#ifndef Foundation_DynamicStruct_INCLUDED
|
||||||
#define Foundation_DynamicStruct_INCLUDED
|
#define Foundation_DynamicStruct_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/DynamicAny.h"
|
#include "Poco/DynamicAny.h"
|
||||||
#include "Poco/DynamicAnyHolder.h"
|
#include "Poco/DynamicAnyHolder.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API DynamicStruct
|
class Foundation_API DynamicStruct
|
||||||
/// DynamicStruct allows to define a named collection of DynamicAny objects.
|
/// DynamicStruct allows to define a named collection of DynamicAny objects.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::map<std::string, DynamicAny> Data;
|
typedef std::map<std::string, DynamicAny> Data;
|
||||||
typedef Data::iterator Iterator;
|
typedef Data::iterator Iterator;
|
||||||
typedef Data::const_iterator ConstIterator;
|
typedef Data::const_iterator ConstIterator;
|
||||||
|
|
||||||
DynamicStruct();
|
DynamicStruct();
|
||||||
/// Creates an empty DynamicStruct
|
/// Creates an empty DynamicStruct
|
||||||
|
|
||||||
DynamicStruct(const Data &val);
|
DynamicStruct(const Data &val);
|
||||||
/// Creates the DynamicStruct from the given value.
|
/// Creates the DynamicStruct from the given value.
|
||||||
|
|
||||||
virtual ~DynamicStruct();
|
virtual ~DynamicStruct();
|
||||||
/// Destroys the DynamicStruct.
|
/// Destroys the DynamicStruct.
|
||||||
|
|
||||||
DynamicAny& operator [] (const std::string& name);
|
DynamicAny& operator [] (const std::string& name);
|
||||||
/// Returns the DynamicAny with the given name, creates an entry if not found.
|
/// Returns the DynamicAny with the given name, creates an entry if not found.
|
||||||
|
|
||||||
const DynamicAny& operator [] (const std::string& name) const;
|
const DynamicAny& operator [] (const std::string& name) const;
|
||||||
/// Returns the DynamicAny with the given name, throws a
|
/// Returns the DynamicAny with the given name, throws a
|
||||||
/// NotFoundException if the data member is not found.
|
/// NotFoundException if the data member is not found.
|
||||||
|
|
||||||
bool contains(const std::string& name) const;
|
bool contains(const std::string& name) const;
|
||||||
/// Returns true if the DynamicStruct contains a member with the given
|
/// Returns true if the DynamicStruct contains a member with the given
|
||||||
/// name
|
/// name
|
||||||
|
|
||||||
Iterator find(const std::string& name);
|
Iterator find(const std::string& name);
|
||||||
/// Returns an iterator, pointing to the <name,DynamicAny> pair containing
|
/// Returns an iterator, pointing to the <name,DynamicAny> pair containing
|
||||||
/// the element, or it returns end() if the member was not found
|
/// the element, or it returns end() if the member was not found
|
||||||
|
|
||||||
ConstIterator find(const std::string& name) const;
|
ConstIterator find(const std::string& name) const;
|
||||||
/// Returns a const iterator, pointing to the <name,DynamicAny> pair containing
|
/// Returns a const iterator, pointing to the <name,DynamicAny> pair containing
|
||||||
/// the element, or it returns end() if the member was not found
|
/// the element, or it returns end() if the member was not found
|
||||||
|
|
||||||
Iterator end();
|
Iterator end();
|
||||||
/// Returns the end iterator for the DynamicStruct
|
/// Returns the end iterator for the DynamicStruct
|
||||||
|
|
||||||
ConstIterator end() const;
|
ConstIterator end() const;
|
||||||
/// Returns the end const iterator for the DynamicStruct
|
/// Returns the end const iterator for the DynamicStruct
|
||||||
|
|
||||||
Iterator begin();
|
Iterator begin();
|
||||||
/// Returns the begin iterator for the DynamicStruct
|
/// Returns the begin iterator for the DynamicStruct
|
||||||
|
|
||||||
ConstIterator begin() const;
|
ConstIterator begin() const;
|
||||||
/// Returns the begin const iterator for the DynamicStruct
|
/// Returns the begin const iterator for the DynamicStruct
|
||||||
|
|
||||||
std::pair<DynamicStruct::Iterator, bool> insert(const std::string& key, const DynamicAny& value);
|
std::pair<DynamicStruct::Iterator, bool> insert(const std::string& key, const DynamicAny& value);
|
||||||
/// Inserts a <name, DynamicAny> pair into the DynamicStruct,
|
/// Inserts a <name, DynamicAny> pair into the DynamicStruct,
|
||||||
/// returns a pair containing the iterator and a boolean which
|
/// returns a pair containing the iterator and a boolean which
|
||||||
/// indicates success or not (is true, when insert succeeded, false,
|
/// indicates success or not (is true, when insert succeeded, false,
|
||||||
/// when already another element was present, in this case Iterator
|
/// when already another element was present, in this case Iterator
|
||||||
/// points to that other element)
|
/// points to that other element)
|
||||||
|
|
||||||
std::pair<DynamicStruct::Iterator, bool> insert(const DynamicStruct::Data::value_type& aPair);
|
std::pair<DynamicStruct::Iterator, bool> insert(const DynamicStruct::Data::value_type& aPair);
|
||||||
/// Inserts a <name, DynamicAny> pair into the DynamicStruct,
|
/// Inserts a <name, DynamicAny> pair into the DynamicStruct,
|
||||||
/// returns a pair containing the iterator and a boolean which
|
/// returns a pair containing the iterator and a boolean which
|
||||||
/// indicates success or not (is true, when insert succeeded, false,
|
/// indicates success or not (is true, when insert succeeded, false,
|
||||||
/// when already another element was present, in this case Iterator
|
/// when already another element was present, in this case Iterator
|
||||||
/// points to that other element)
|
/// points to that other element)
|
||||||
|
|
||||||
DynamicStruct::Data::size_type erase(const std::string& key);
|
DynamicStruct::Data::size_type erase(const std::string& key);
|
||||||
/// Erases the element if found, returns number of elements deleted
|
/// Erases the element if found, returns number of elements deleted
|
||||||
|
|
||||||
void erase(DynamicStruct::Iterator it);
|
void erase(DynamicStruct::Iterator it);
|
||||||
/// Erases the element at the given position
|
/// Erases the element at the given position
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
/// Returns true if the DynamicStruct doesn't contain any members
|
/// Returns true if the DynamicStruct doesn't contain any members
|
||||||
|
|
||||||
DynamicStruct::Data::size_type size() const;
|
DynamicStruct::Data::size_type size() const;
|
||||||
/// Returns the number of members the DynamicStruct contains
|
/// Returns the number of members the DynamicStruct contains
|
||||||
|
|
||||||
std::set<std::string> members() const;
|
std::set<std::string> members() const;
|
||||||
/// Returns a sorted collection containing all member names
|
/// Returns a sorted collection containing all member names
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Data _data;
|
Data _data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline DynamicAny& DynamicStruct::operator [] (const std::string& name)
|
inline DynamicAny& DynamicStruct::operator [] (const std::string& name)
|
||||||
{
|
{
|
||||||
return _data[name];
|
return _data[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool DynamicStruct::contains(const std::string& name) const
|
inline bool DynamicStruct::contains(const std::string& name) const
|
||||||
{
|
{
|
||||||
return find(name) != end();
|
return find(name) != end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline DynamicStruct::Iterator DynamicStruct::find(const std::string& name)
|
inline DynamicStruct::Iterator DynamicStruct::find(const std::string& name)
|
||||||
{
|
{
|
||||||
return _data.find(name);
|
return _data.find(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline DynamicStruct::ConstIterator DynamicStruct::find(const std::string& name) const
|
inline DynamicStruct::ConstIterator DynamicStruct::find(const std::string& name) const
|
||||||
{
|
{
|
||||||
return _data.find(name);
|
return _data.find(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline DynamicStruct::Iterator DynamicStruct::end()
|
inline DynamicStruct::Iterator DynamicStruct::end()
|
||||||
{
|
{
|
||||||
return _data.end();
|
return _data.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline DynamicStruct::ConstIterator DynamicStruct::end() const
|
inline DynamicStruct::ConstIterator DynamicStruct::end() const
|
||||||
{
|
{
|
||||||
return _data.end();
|
return _data.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline DynamicStruct::Iterator DynamicStruct::begin()
|
inline DynamicStruct::Iterator DynamicStruct::begin()
|
||||||
{
|
{
|
||||||
return _data.begin();
|
return _data.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline DynamicStruct::ConstIterator DynamicStruct::begin() const
|
inline DynamicStruct::ConstIterator DynamicStruct::begin() const
|
||||||
{
|
{
|
||||||
return _data.begin();
|
return _data.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::pair<DynamicStruct::Iterator, bool> DynamicStruct::insert(const std::string& key, const DynamicAny& value)
|
inline std::pair<DynamicStruct::Iterator, bool> DynamicStruct::insert(const std::string& key, const DynamicAny& value)
|
||||||
{
|
{
|
||||||
return insert(std::make_pair(key, value));
|
return insert(std::make_pair(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::pair<DynamicStruct::Iterator, bool> DynamicStruct::insert(const DynamicStruct::Data::value_type& aPair)
|
inline std::pair<DynamicStruct::Iterator, bool> DynamicStruct::insert(const DynamicStruct::Data::value_type& aPair)
|
||||||
{
|
{
|
||||||
return _data.insert(aPair);
|
return _data.insert(aPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline DynamicStruct::Data::size_type DynamicStruct::erase(const std::string& key)
|
inline DynamicStruct::Data::size_type DynamicStruct::erase(const std::string& key)
|
||||||
{
|
{
|
||||||
return _data.erase(key);
|
return _data.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void DynamicStruct::erase(DynamicStruct::Iterator it)
|
inline void DynamicStruct::erase(DynamicStruct::Iterator it)
|
||||||
{
|
{
|
||||||
_data.erase(it);
|
_data.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool DynamicStruct::empty() const
|
inline bool DynamicStruct::empty() const
|
||||||
{
|
{
|
||||||
return _data.empty();
|
return _data.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline DynamicStruct::Data::size_type DynamicStruct::size() const
|
inline DynamicStruct::Data::size_type DynamicStruct::size() const
|
||||||
{
|
{
|
||||||
return _data.size();
|
return _data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
class DynamicAnyHolderImpl<DynamicStruct>: public DynamicAnyHolder
|
class DynamicAnyHolderImpl<DynamicStruct>: public DynamicAnyHolder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DynamicAnyHolderImpl(const DynamicStruct& val): _val(val)
|
DynamicAnyHolderImpl(const DynamicStruct& val): _val(val)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~DynamicAnyHolderImpl()
|
~DynamicAnyHolderImpl()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::type_info& type() const
|
const std::type_info& type() const
|
||||||
{
|
{
|
||||||
return typeid(DynamicStruct);
|
return typeid(DynamicStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int8& val) const
|
void convert(Int8& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to Int8");
|
throw BadCastException("Cannot cast DynamicStruct type to Int8");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int16& val) const
|
void convert(Int16& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to Int16");
|
throw BadCastException("Cannot cast DynamicStruct type to Int16");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int32& val) const
|
void convert(Int32& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to Int32");
|
throw BadCastException("Cannot cast DynamicStruct type to Int32");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int64& val) const
|
void convert(Int64& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to Int64");
|
throw BadCastException("Cannot cast DynamicStruct type to Int64");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt8& val) const
|
void convert(UInt8& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to UInt8");
|
throw BadCastException("Cannot cast DynamicStruct type to UInt8");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt16& val) const
|
void convert(UInt16& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to UInt16");
|
throw BadCastException("Cannot cast DynamicStruct type to UInt16");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt32& val) const
|
void convert(UInt32& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to UInt32");
|
throw BadCastException("Cannot cast DynamicStruct type to UInt32");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt64& val) const
|
void convert(UInt64& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to UInt64");
|
throw BadCastException("Cannot cast DynamicStruct type to UInt64");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(bool& val) const
|
void convert(bool& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to bool");
|
throw BadCastException("Cannot cast DynamicStruct type to bool");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(float& val) const
|
void convert(float& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to float");
|
throw BadCastException("Cannot cast DynamicStruct type to float");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(double& val) const
|
void convert(double& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to double");
|
throw BadCastException("Cannot cast DynamicStruct type to double");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(char& val) const
|
void convert(char& val) const
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot cast DynamicStruct type to char");
|
throw BadCastException("Cannot cast DynamicStruct type to char");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(std::string& val) const
|
void convert(std::string& val) const
|
||||||
{
|
{
|
||||||
// Serialize in JSON format: equals an object
|
// Serialize in JSON format: equals an object
|
||||||
|
|
||||||
// JSON format definition: { string ':' value } string:value pair n-times, sep. by ','
|
// JSON format definition: { string ':' value } string:value pair n-times, sep. by ','
|
||||||
val.append("{ ");
|
val.append("{ ");
|
||||||
DynamicStruct::ConstIterator it = _val.begin();
|
DynamicStruct::ConstIterator it = _val.begin();
|
||||||
DynamicStruct::ConstIterator itEnd = _val.end();
|
DynamicStruct::ConstIterator itEnd = _val.end();
|
||||||
if (!_val.empty())
|
if (!_val.empty())
|
||||||
{
|
{
|
||||||
DynamicAny key(it->first);
|
DynamicAny key(it->first);
|
||||||
appendJSONString(val, key);
|
appendJSONString(val, key);
|
||||||
val.append(" : ");
|
val.append(" : ");
|
||||||
appendJSONString(val, it->second);
|
appendJSONString(val, it->second);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
for (; it != itEnd; ++it)
|
for (; it != itEnd; ++it)
|
||||||
{
|
{
|
||||||
val.append(", ");
|
val.append(", ");
|
||||||
DynamicAny key(it->first);
|
DynamicAny key(it->first);
|
||||||
appendJSONString(val, key);
|
appendJSONString(val, key);
|
||||||
val.append(" : ");
|
val.append(" : ");
|
||||||
appendJSONString(val, it->second);
|
appendJSONString(val, it->second);
|
||||||
}
|
}
|
||||||
val.append(" }");
|
val.append(" }");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Poco::DateTime&) const
|
void convert(Poco::DateTime&) const
|
||||||
{
|
{
|
||||||
throw BadCastException("DynamicStruct -> Poco::DateTime");
|
throw BadCastException("DynamicStruct -> Poco::DateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Poco::LocalDateTime&) const
|
void convert(Poco::LocalDateTime&) const
|
||||||
{
|
{
|
||||||
throw BadCastException("DynamicStruct -> Poco::LocalDateTime");
|
throw BadCastException("DynamicStruct -> Poco::LocalDateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Poco::Timestamp&) const
|
void convert(Poco::Timestamp&) const
|
||||||
{
|
{
|
||||||
throw BadCastException("DynamicStruct -> Poco::Timestamp");
|
throw BadCastException("DynamicStruct -> Poco::Timestamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicAnyHolder* clone() const
|
DynamicAnyHolder* clone() const
|
||||||
{
|
{
|
||||||
return new DynamicAnyHolderImpl(_val);
|
return new DynamicAnyHolderImpl(_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DynamicStruct& value() const
|
const DynamicStruct& value() const
|
||||||
{
|
{
|
||||||
return _val;
|
return _val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isArray() const
|
bool isArray() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isStruct() const
|
bool isStruct() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInteger() const
|
bool isInteger() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSigned() const
|
bool isSigned() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNumeric() const
|
bool isNumeric() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isString() const
|
bool isString() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicAny& operator [] (const std::string& name)
|
DynamicAny& operator [] (const std::string& name)
|
||||||
{
|
{
|
||||||
return _val[name];
|
return _val[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
const DynamicAny& operator [] (const std::string& name) const
|
const DynamicAny& operator [] (const std::string& name) const
|
||||||
{
|
{
|
||||||
return _val[name];
|
return _val[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DynamicStruct _val;
|
DynamicStruct _val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_DynamicStruct_INCLUDED
|
#endif // Foundation_DynamicStruct_INCLUDED
|
||||||
|
|||||||
@@ -1,114 +1,114 @@
|
|||||||
//
|
//
|
||||||
// ExpirationDecorator.h
|
// ExpirationDecorator.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/ExpirationDecorator.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/ExpirationDecorator.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Events
|
// Package: Events
|
||||||
// Module: ExpirationDecorator
|
// Module: ExpirationDecorator
|
||||||
//
|
//
|
||||||
// Implementation of the ExpirationDecorator template.
|
// Implementation of the ExpirationDecorator template.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_ExpirationDecorator_INCLUDED
|
#ifndef Foundation_ExpirationDecorator_INCLUDED
|
||||||
#define Foundation_ExpirationDecorator_INCLUDED
|
#define Foundation_ExpirationDecorator_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Timestamp.h"
|
#include "Poco/Timestamp.h"
|
||||||
#include "Poco/Timespan.h"
|
#include "Poco/Timespan.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <typename TArgs>
|
template <typename TArgs>
|
||||||
class ExpirationDecorator
|
class ExpirationDecorator
|
||||||
/// ExpirationDecorator adds an expiration method to values so that they can be used
|
/// ExpirationDecorator adds an expiration method to values so that they can be used
|
||||||
/// with the UniqueExpireCache
|
/// with the UniqueExpireCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExpirationDecorator():
|
ExpirationDecorator():
|
||||||
_value(),
|
_value(),
|
||||||
_expiresAt()
|
_expiresAt()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
|
ExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
|
||||||
/// Creates an element that will expire in diff milliseconds
|
/// Creates an element that will expire in diff milliseconds
|
||||||
_value(p),
|
_value(p),
|
||||||
_expiresAt()
|
_expiresAt()
|
||||||
{
|
{
|
||||||
_expiresAt += (diffInMs*1000);
|
_expiresAt += (diffInMs*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
|
ExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
|
||||||
/// Creates an element that will expire after the given timeSpan
|
/// Creates an element that will expire after the given timeSpan
|
||||||
_value(p),
|
_value(p),
|
||||||
_expiresAt()
|
_expiresAt()
|
||||||
{
|
{
|
||||||
_expiresAt += timeSpan.totalMicroseconds();
|
_expiresAt += timeSpan.totalMicroseconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpirationDecorator(const TArgs& p, const Poco::Timestamp& timeStamp):
|
ExpirationDecorator(const TArgs& p, const Poco::Timestamp& timeStamp):
|
||||||
/// Creates an element that will expire at the given time point
|
/// Creates an element that will expire at the given time point
|
||||||
_value(p),
|
_value(p),
|
||||||
_expiresAt(timeStamp)
|
_expiresAt(timeStamp)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
~ExpirationDecorator()
|
~ExpirationDecorator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const Poco::Timestamp& getExpiration() const
|
const Poco::Timestamp& getExpiration() const
|
||||||
{
|
{
|
||||||
return _expiresAt;
|
return _expiresAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TArgs& value() const
|
const TArgs& value() const
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
TArgs& value()
|
TArgs& value()
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TArgs _value;
|
TArgs _value;
|
||||||
Timestamp _expiresAt;
|
Timestamp _expiresAt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,194 +1,194 @@
|
|||||||
//
|
//
|
||||||
// FileStream.h
|
// FileStream.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/FileStream.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Streams
|
// Package: Streams
|
||||||
// Module: FileStream
|
// Module: FileStream
|
||||||
//
|
//
|
||||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_FileStream_INCLUDED
|
#ifndef Foundation_FileStream_INCLUDED
|
||||||
#define Foundation_FileStream_INCLUDED
|
#define Foundation_FileStream_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
#include "FileStream_WIN32.h"
|
#include "FileStream_WIN32.h"
|
||||||
#else
|
#else
|
||||||
#include "FileStream_POSIX.h"
|
#include "FileStream_POSIX.h"
|
||||||
#endif
|
#endif
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API FileIOS: public virtual std::ios
|
class Foundation_API FileIOS: public virtual std::ios
|
||||||
/// The base class for FileInputStream and FileOutputStream.
|
/// The base class for FileInputStream and FileOutputStream.
|
||||||
///
|
///
|
||||||
/// This class is needed to ensure the correct initialization
|
/// This class is needed to ensure the correct initialization
|
||||||
/// order of the stream buffer and base classes.
|
/// order of the stream buffer and base classes.
|
||||||
///
|
///
|
||||||
/// Files are always opened in binary mode, a text mode
|
/// Files are always opened in binary mode, a text mode
|
||||||
/// with CR-LF translation is not supported. Thus, the
|
/// with CR-LF translation is not supported. Thus, the
|
||||||
/// file is always opened as if the std::ios::binary flag
|
/// file is always opened as if the std::ios::binary flag
|
||||||
/// was specified.
|
/// was specified.
|
||||||
/// Use an InputLineEndingConverter or OutputLineEndingConverter
|
/// Use an InputLineEndingConverter or OutputLineEndingConverter
|
||||||
/// if you require CR-LF translation.
|
/// if you require CR-LF translation.
|
||||||
///
|
///
|
||||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileIOS(std::ios::openmode defaultMode);
|
FileIOS(std::ios::openmode defaultMode);
|
||||||
/// Creates the basic stream.
|
/// Creates the basic stream.
|
||||||
|
|
||||||
~FileIOS();
|
~FileIOS();
|
||||||
/// Destroys the stream.
|
/// Destroys the stream.
|
||||||
|
|
||||||
void open(const std::string& path, std::ios::openmode mode);
|
void open(const std::string& path, std::ios::openmode mode);
|
||||||
/// Opens the file specified by path, using the given mode.
|
/// Opens the file specified by path, using the given mode.
|
||||||
///
|
///
|
||||||
/// Throws a FileException (or a similar exception) if the file
|
/// Throws a FileException (or a similar exception) if the file
|
||||||
/// does not exist or is not accessible for other reasons and
|
/// does not exist or is not accessible for other reasons and
|
||||||
/// a new file cannot be created.
|
/// a new file cannot be created.
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
/// Closes the file stream.
|
/// Closes the file stream.
|
||||||
|
|
||||||
FileStreamBuf* rdbuf();
|
FileStreamBuf* rdbuf();
|
||||||
/// Returns a pointer to the underlying streambuf.
|
/// Returns a pointer to the underlying streambuf.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FileStreamBuf _buf;
|
FileStreamBuf _buf;
|
||||||
std::ios::openmode _defaultMode;
|
std::ios::openmode _defaultMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API FileInputStream: public FileIOS, public std::istream
|
class Foundation_API FileInputStream: public FileIOS, public std::istream
|
||||||
/// An input stream for reading from a file.
|
/// An input stream for reading from a file.
|
||||||
///
|
///
|
||||||
/// Files are always opened in binary mode, a text mode
|
/// Files are always opened in binary mode, a text mode
|
||||||
/// with CR-LF translation is not supported. Thus, the
|
/// with CR-LF translation is not supported. Thus, the
|
||||||
/// file is always opened as if the std::ios::binary flag
|
/// file is always opened as if the std::ios::binary flag
|
||||||
/// was specified.
|
/// was specified.
|
||||||
/// Use an InputLineEndingConverter if you require CR-LF translation.
|
/// Use an InputLineEndingConverter if you require CR-LF translation.
|
||||||
///
|
///
|
||||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileInputStream();
|
FileInputStream();
|
||||||
/// Creates an unopened FileInputStream.
|
/// Creates an unopened FileInputStream.
|
||||||
|
|
||||||
FileInputStream(const std::string& path, std::ios::openmode mode = std::ios::in);
|
FileInputStream(const std::string& path, std::ios::openmode mode = std::ios::in);
|
||||||
/// Creates the FileInputStream for the file given by path, using
|
/// Creates the FileInputStream for the file given by path, using
|
||||||
/// the given mode.
|
/// the given mode.
|
||||||
///
|
///
|
||||||
/// The std::ios::in flag is always set, regardless of the actual
|
/// The std::ios::in flag is always set, regardless of the actual
|
||||||
/// value specified for mode.
|
/// value specified for mode.
|
||||||
///
|
///
|
||||||
/// Throws a FileNotFoundException (or a similar exception) if the file
|
/// Throws a FileNotFoundException (or a similar exception) if the file
|
||||||
/// does not exist or is not accessible for other reasons.
|
/// does not exist or is not accessible for other reasons.
|
||||||
|
|
||||||
~FileInputStream();
|
~FileInputStream();
|
||||||
/// Destroys the stream.
|
/// Destroys the stream.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API FileOutputStream: public FileIOS, public std::ostream
|
class Foundation_API FileOutputStream: public FileIOS, public std::ostream
|
||||||
/// An output stream for writing to a file.
|
/// An output stream for writing to a file.
|
||||||
///
|
///
|
||||||
/// Files are always opened in binary mode, a text mode
|
/// Files are always opened in binary mode, a text mode
|
||||||
/// with CR-LF translation is not supported. Thus, the
|
/// with CR-LF translation is not supported. Thus, the
|
||||||
/// file is always opened as if the std::ios::binary flag
|
/// file is always opened as if the std::ios::binary flag
|
||||||
/// was specified.
|
/// was specified.
|
||||||
/// Use an OutputLineEndingConverter if you require CR-LF translation.
|
/// Use an OutputLineEndingConverter if you require CR-LF translation.
|
||||||
///
|
///
|
||||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileOutputStream();
|
FileOutputStream();
|
||||||
/// Creats an unopened FileOutputStream.
|
/// Creats an unopened FileOutputStream.
|
||||||
|
|
||||||
FileOutputStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc);
|
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
|
/// Creates the FileOutputStream for the file given by path, using
|
||||||
/// the given mode.
|
/// the given mode.
|
||||||
///
|
///
|
||||||
/// The std::ios::out is always set, regardless of the actual
|
/// The std::ios::out is always set, regardless of the actual
|
||||||
/// value specified for mode.
|
/// value specified for mode.
|
||||||
///
|
///
|
||||||
/// Throws a FileException (or a similar exception) if the file
|
/// Throws a FileException (or a similar exception) if the file
|
||||||
/// does not exist or is not accessible for other reasons and
|
/// does not exist or is not accessible for other reasons and
|
||||||
/// a new file cannot be created.
|
/// a new file cannot be created.
|
||||||
|
|
||||||
~FileOutputStream();
|
~FileOutputStream();
|
||||||
/// Destroys the FileOutputStream.
|
/// Destroys the FileOutputStream.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API FileStream: public FileIOS, public std::iostream
|
class Foundation_API FileStream: public FileIOS, public std::iostream
|
||||||
/// A stream for reading from and writing to a file.
|
/// A stream for reading from and writing to a file.
|
||||||
///
|
///
|
||||||
/// Files are always opened in binary mode, a text mode
|
/// Files are always opened in binary mode, a text mode
|
||||||
/// with CR-LF translation is not supported. Thus, the
|
/// with CR-LF translation is not supported. Thus, the
|
||||||
/// file is always opened as if the std::ios::binary flag
|
/// file is always opened as if the std::ios::binary flag
|
||||||
/// was specified.
|
/// was specified.
|
||||||
/// Use an InputLineEndingConverter or OutputLineEndingConverter
|
/// Use an InputLineEndingConverter or OutputLineEndingConverter
|
||||||
/// if you require CR-LF translation.
|
/// if you require CR-LF translation.
|
||||||
///
|
///
|
||||||
/// A seek (seekg() or seekp()) operation will always set the
|
/// A seek (seekg() or seekp()) operation will always set the
|
||||||
/// read position and the write position simultaneously to the
|
/// read position and the write position simultaneously to the
|
||||||
/// same value.
|
/// same value.
|
||||||
///
|
///
|
||||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileStream();
|
FileStream();
|
||||||
/// Creats an unopened FileStream.
|
/// Creats an unopened FileStream.
|
||||||
|
|
||||||
FileStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::in);
|
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
|
/// Creates the FileStream for the file given by path, using
|
||||||
/// the given mode.
|
/// the given mode.
|
||||||
|
|
||||||
~FileStream();
|
~FileStream();
|
||||||
/// Destroys the FileOutputStream.
|
/// Destroys the FileOutputStream.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_FileStream_INCLUDED
|
#endif // Foundation_FileStream_INCLUDED
|
||||||
|
|||||||
@@ -1,93 +1,93 @@
|
|||||||
//
|
//
|
||||||
// FileStream_POSIX.h
|
// FileStream_POSIX.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream_POSIX.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/FileStream_POSIX.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Streams
|
// Package: Streams
|
||||||
// Module: FileStream
|
// Module: FileStream
|
||||||
//
|
//
|
||||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_FileStream_POSIX_INCLUDED
|
#ifndef Foundation_FileStream_POSIX_INCLUDED
|
||||||
#define Foundation_FileStream_POSIX_INCLUDED
|
#define Foundation_FileStream_POSIX_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/BufferedBidirectionalStreamBuf.h"
|
#include "Poco/BufferedBidirectionalStreamBuf.h"
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
|
class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
|
||||||
/// This stream buffer handles Fileio
|
/// This stream buffer handles Fileio
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileStreamBuf();
|
FileStreamBuf();
|
||||||
/// Creates a FileStreamBuf.
|
/// Creates a FileStreamBuf.
|
||||||
|
|
||||||
~FileStreamBuf();
|
~FileStreamBuf();
|
||||||
/// Destroys the FileStream.
|
/// Destroys the FileStream.
|
||||||
|
|
||||||
void open(const std::string& path, std::ios::openmode mode);
|
void open(const std::string& path, std::ios::openmode mode);
|
||||||
/// Opens the given file in the given mode.
|
/// Opens the given file in the given mode.
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
/// Closes the File stream buffer.
|
/// 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);
|
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.
|
/// 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);
|
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||||
/// Change to specified position, according to mode.
|
/// Change to specified position, according to mode.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
BUFFER_SIZE = 4096
|
BUFFER_SIZE = 4096
|
||||||
};
|
};
|
||||||
|
|
||||||
int readFromDevice(char* buffer, std::streamsize length);
|
int readFromDevice(char* buffer, std::streamsize length);
|
||||||
int writeToDevice(const char* buffer, std::streamsize length);
|
int writeToDevice(const char* buffer, std::streamsize length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _path;
|
std::string _path;
|
||||||
int _fd;
|
int _fd;
|
||||||
std::streamoff _pos;
|
std::streamoff _pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_FileStream_WIN32_INCLUDED
|
#endif // Foundation_FileStream_WIN32_INCLUDED
|
||||||
|
|||||||
@@ -1,92 +1,92 @@
|
|||||||
//
|
//
|
||||||
// FileStream_WIN32.h
|
// FileStream_WIN32.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream_WIN32.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/FileStream_WIN32.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Streams
|
// Package: Streams
|
||||||
// Module: FileStream
|
// Module: FileStream
|
||||||
//
|
//
|
||||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_FileStream_WIN32_INCLUDED
|
#ifndef Foundation_FileStream_WIN32_INCLUDED
|
||||||
#define Foundation_FileStream_WIN32_INCLUDED
|
#define Foundation_FileStream_WIN32_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/BufferedBidirectionalStreamBuf.h"
|
#include "Poco/BufferedBidirectionalStreamBuf.h"
|
||||||
#include "Poco/UnWindows.h"
|
#include "Poco/UnWindows.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
|
class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
|
||||||
/// This stream buffer handles Fileio
|
/// This stream buffer handles Fileio
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileStreamBuf();
|
FileStreamBuf();
|
||||||
/// Creates a FileStreamBuf.
|
/// Creates a FileStreamBuf.
|
||||||
|
|
||||||
~FileStreamBuf();
|
~FileStreamBuf();
|
||||||
/// Destroys the FileStream.
|
/// Destroys the FileStream.
|
||||||
|
|
||||||
void open(const std::string& path, std::ios::openmode mode);
|
void open(const std::string& path, std::ios::openmode mode);
|
||||||
/// Opens the given file in the given mode.
|
/// Opens the given file in the given mode.
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
/// Closes the File stream buffer
|
/// 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);
|
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
|
/// 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);
|
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||||
/// change to specified position, according to mode
|
/// change to specified position, according to mode
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
BUFFER_SIZE = 4096
|
BUFFER_SIZE = 4096
|
||||||
};
|
};
|
||||||
|
|
||||||
int readFromDevice(char* buffer, std::streamsize length);
|
int readFromDevice(char* buffer, std::streamsize length);
|
||||||
int writeToDevice(const char* buffer, std::streamsize length);
|
int writeToDevice(const char* buffer, std::streamsize length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _path;
|
std::string _path;
|
||||||
HANDLE _handle;
|
HANDLE _handle;
|
||||||
UInt64 _pos;
|
UInt64 _pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_FileStream_WIN32_INCLUDED
|
#endif // Foundation_FileStream_WIN32_INCLUDED
|
||||||
|
|||||||
@@ -1,208 +1,208 @@
|
|||||||
//
|
//
|
||||||
// FunctionDelegate.h
|
// FunctionDelegate.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/FunctionDelegate.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/FunctionDelegate.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Events
|
// Package: Events
|
||||||
// Module: FunctionDelegate
|
// Module: FunctionDelegate
|
||||||
//
|
//
|
||||||
// Implementation of the FunctionDelegate template.
|
// Implementation of the FunctionDelegate template.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_FunctionDelegate_INCLUDED
|
#ifndef Foundation_FunctionDelegate_INCLUDED
|
||||||
#define Foundation_FunctionDelegate_INCLUDED
|
#define Foundation_FunctionDelegate_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/AbstractDelegate.h"
|
#include "Poco/AbstractDelegate.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class TArgs, bool hasSender = true, bool senderIsConst = true>
|
template <class TArgs, bool hasSender = true, bool senderIsConst = true>
|
||||||
class FunctionDelegate: public AbstractDelegate<TArgs>
|
class FunctionDelegate: public AbstractDelegate<TArgs>
|
||||||
/// Wraps a C style function (or a C++ static fucntion) to be used as
|
/// Wraps a C style function (or a C++ static fucntion) to be used as
|
||||||
/// a delegate
|
/// a delegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void (*NotifyMethod)(const void*, TArgs&);
|
typedef void (*NotifyMethod)(const void*, TArgs&);
|
||||||
|
|
||||||
FunctionDelegate(NotifyMethod method):
|
FunctionDelegate(NotifyMethod method):
|
||||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||||
_receiverMethod(method)
|
_receiverMethod(method)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDelegate(const FunctionDelegate& delegate):
|
FunctionDelegate(const FunctionDelegate& delegate):
|
||||||
AbstractDelegate<TArgs>(delegate),
|
AbstractDelegate<TArgs>(delegate),
|
||||||
_receiverMethod(delegate._receiverMethod)
|
_receiverMethod(delegate._receiverMethod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~FunctionDelegate()
|
~FunctionDelegate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||||
{
|
{
|
||||||
if (&delegate != this)
|
if (&delegate != this)
|
||||||
{
|
{
|
||||||
this->_pTarget = delegate._pTarget;
|
this->_pTarget = delegate._pTarget;
|
||||||
this->_receiverMethod = delegate._receiverMethod;
|
this->_receiverMethod = delegate._receiverMethod;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notify(const void* sender, TArgs& arguments)
|
bool notify(const void* sender, TArgs& arguments)
|
||||||
{
|
{
|
||||||
(*_receiverMethod)(sender, arguments);
|
(*_receiverMethod)(sender, arguments);
|
||||||
return true; // a "standard" delegate never expires
|
return true; // a "standard" delegate never expires
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractDelegate<TArgs>* clone() const
|
AbstractDelegate<TArgs>* clone() const
|
||||||
{
|
{
|
||||||
return new FunctionDelegate(*this);
|
return new FunctionDelegate(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NotifyMethod _receiverMethod;
|
NotifyMethod _receiverMethod;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunctionDelegate();
|
FunctionDelegate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class TArgs>
|
template <class TArgs>
|
||||||
class FunctionDelegate<TArgs, true, false>: public AbstractDelegate<TArgs>
|
class FunctionDelegate<TArgs, true, false>: public AbstractDelegate<TArgs>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void (*NotifyMethod)(void*, TArgs&);
|
typedef void (*NotifyMethod)(void*, TArgs&);
|
||||||
|
|
||||||
FunctionDelegate(NotifyMethod method):
|
FunctionDelegate(NotifyMethod method):
|
||||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||||
_receiverMethod(method)
|
_receiverMethod(method)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDelegate(const FunctionDelegate& delegate):
|
FunctionDelegate(const FunctionDelegate& delegate):
|
||||||
AbstractDelegate<TArgs>(delegate),
|
AbstractDelegate<TArgs>(delegate),
|
||||||
_receiverMethod(delegate._receiverMethod)
|
_receiverMethod(delegate._receiverMethod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~FunctionDelegate()
|
~FunctionDelegate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||||
{
|
{
|
||||||
if (&delegate != this)
|
if (&delegate != this)
|
||||||
{
|
{
|
||||||
this->_pTarget = delegate._pTarget;
|
this->_pTarget = delegate._pTarget;
|
||||||
this->_receiverMethod = delegate._receiverMethod;
|
this->_receiverMethod = delegate._receiverMethod;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notify(const void* sender, TArgs& arguments)
|
bool notify(const void* sender, TArgs& arguments)
|
||||||
{
|
{
|
||||||
(*_receiverMethod)(const_cast<void*>(sender), arguments);
|
(*_receiverMethod)(const_cast<void*>(sender), arguments);
|
||||||
return true; // a "standard" delegate never expires
|
return true; // a "standard" delegate never expires
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractDelegate<TArgs>* clone() const
|
AbstractDelegate<TArgs>* clone() const
|
||||||
{
|
{
|
||||||
return new FunctionDelegate(*this);
|
return new FunctionDelegate(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NotifyMethod _receiverMethod;
|
NotifyMethod _receiverMethod;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunctionDelegate();
|
FunctionDelegate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class TArgs, bool senderIsConst>
|
template <class TArgs, bool senderIsConst>
|
||||||
class FunctionDelegate<TArgs, false, senderIsConst>: public AbstractDelegate<TArgs>
|
class FunctionDelegate<TArgs, false, senderIsConst>: public AbstractDelegate<TArgs>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void (*NotifyMethod)(TArgs&);
|
typedef void (*NotifyMethod)(TArgs&);
|
||||||
|
|
||||||
FunctionDelegate(NotifyMethod method):
|
FunctionDelegate(NotifyMethod method):
|
||||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||||
_receiverMethod(method)
|
_receiverMethod(method)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDelegate(const FunctionDelegate& delegate):
|
FunctionDelegate(const FunctionDelegate& delegate):
|
||||||
AbstractDelegate<TArgs>(delegate),
|
AbstractDelegate<TArgs>(delegate),
|
||||||
_receiverMethod(delegate._receiverMethod)
|
_receiverMethod(delegate._receiverMethod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~FunctionDelegate()
|
~FunctionDelegate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||||
{
|
{
|
||||||
if (&delegate != this)
|
if (&delegate != this)
|
||||||
{
|
{
|
||||||
this->_pTarget = delegate._pTarget;
|
this->_pTarget = delegate._pTarget;
|
||||||
this->_receiverMethod = delegate._receiverMethod;
|
this->_receiverMethod = delegate._receiverMethod;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notify(const void* sender, TArgs& arguments)
|
bool notify(const void* sender, TArgs& arguments)
|
||||||
{
|
{
|
||||||
(*_receiverMethod)(arguments);
|
(*_receiverMethod)(arguments);
|
||||||
return true; // a "standard" delegate never expires
|
return true; // a "standard" delegate never expires
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractDelegate<TArgs>* clone() const
|
AbstractDelegate<TArgs>* clone() const
|
||||||
{
|
{
|
||||||
return new FunctionDelegate(*this);
|
return new FunctionDelegate(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NotifyMethod _receiverMethod;
|
NotifyMethod _receiverMethod;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunctionDelegate();
|
FunctionDelegate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,212 +1,212 @@
|
|||||||
//
|
//
|
||||||
// FunctionPriorityDelegate.h
|
// FunctionPriorityDelegate.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/FunctionPriorityDelegate.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/FunctionPriorityDelegate.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Events
|
// Package: Events
|
||||||
// Module: FunctionPriorityDelegate
|
// Module: FunctionPriorityDelegate
|
||||||
//
|
//
|
||||||
// Implementation of the FunctionPriorityDelegate template.
|
// Implementation of the FunctionPriorityDelegate template.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_FunctionPriorityDelegate_INCLUDED
|
#ifndef Foundation_FunctionPriorityDelegate_INCLUDED
|
||||||
#define Foundation_FunctionPriorityDelegate_INCLUDED
|
#define Foundation_FunctionPriorityDelegate_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/AbstractPriorityDelegate.h"
|
#include "Poco/AbstractPriorityDelegate.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class TArgs, bool useSender = true, bool senderIsConst = true>
|
template <class TArgs, bool useSender = true, bool senderIsConst = true>
|
||||||
class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
|
class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
|
||||||
/// Wraps a C style function (or a C++ static fucntion) to be used as
|
/// Wraps a C style function (or a C++ static fucntion) to be used as
|
||||||
/// a priority delegate
|
/// a priority delegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void (*NotifyMethod)(const void*, TArgs&);
|
typedef void (*NotifyMethod)(const void*, TArgs&);
|
||||||
|
|
||||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||||
_receiverMethod(method)
|
_receiverMethod(method)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||||
_receiverMethod(delegate._receiverMethod)
|
_receiverMethod(delegate._receiverMethod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||||
{
|
{
|
||||||
if (&delegate != this)
|
if (&delegate != this)
|
||||||
{
|
{
|
||||||
this->_pTarget = delegate._pTarget;
|
this->_pTarget = delegate._pTarget;
|
||||||
this->_receiverMethod = delegate._receiverMethod;
|
this->_receiverMethod = delegate._receiverMethod;
|
||||||
this->_priority = delegate._priority;
|
this->_priority = delegate._priority;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~FunctionPriorityDelegate()
|
~FunctionPriorityDelegate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notify(const void* sender, TArgs& arguments)
|
bool notify(const void* sender, TArgs& arguments)
|
||||||
{
|
{
|
||||||
(*_receiverMethod)(sender, arguments);
|
(*_receiverMethod)(sender, arguments);
|
||||||
return true; // per default the delegate never expires
|
return true; // per default the delegate never expires
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractPriorityDelegate<TArgs>* clone() const
|
AbstractPriorityDelegate<TArgs>* clone() const
|
||||||
{
|
{
|
||||||
return new FunctionPriorityDelegate(*this);
|
return new FunctionPriorityDelegate(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NotifyMethod _receiverMethod;
|
NotifyMethod _receiverMethod;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunctionPriorityDelegate();
|
FunctionPriorityDelegate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class TArgs>
|
template <class TArgs>
|
||||||
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
|
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void (*NotifyMethod)(void*, TArgs&);
|
typedef void (*NotifyMethod)(void*, TArgs&);
|
||||||
|
|
||||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||||
_receiverMethod(method)
|
_receiverMethod(method)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||||
_receiverMethod(delegate._receiverMethod)
|
_receiverMethod(delegate._receiverMethod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||||
{
|
{
|
||||||
if (&delegate != this)
|
if (&delegate != this)
|
||||||
{
|
{
|
||||||
this->_pTarget = delegate._pTarget;
|
this->_pTarget = delegate._pTarget;
|
||||||
this->_receiverMethod = delegate._receiverMethod;
|
this->_receiverMethod = delegate._receiverMethod;
|
||||||
this->_priority = delegate._priority;
|
this->_priority = delegate._priority;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~FunctionPriorityDelegate()
|
~FunctionPriorityDelegate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notify(const void* sender, TArgs& arguments)
|
bool notify(const void* sender, TArgs& arguments)
|
||||||
{
|
{
|
||||||
(*_receiverMethod)(const_cast<void*>(sender), arguments);
|
(*_receiverMethod)(const_cast<void*>(sender), arguments);
|
||||||
return true; // per default the delegate never expires
|
return true; // per default the delegate never expires
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractPriorityDelegate<TArgs>* clone() const
|
AbstractPriorityDelegate<TArgs>* clone() const
|
||||||
{
|
{
|
||||||
return new FunctionPriorityDelegate(*this);
|
return new FunctionPriorityDelegate(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NotifyMethod _receiverMethod;
|
NotifyMethod _receiverMethod;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunctionPriorityDelegate();
|
FunctionPriorityDelegate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <class TArgs>
|
template <class TArgs>
|
||||||
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
|
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void (*NotifyMethod)(TArgs&);
|
typedef void (*NotifyMethod)(TArgs&);
|
||||||
|
|
||||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||||
_receiverMethod(method)
|
_receiverMethod(method)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||||
_receiverMethod(delegate._receiverMethod)
|
_receiverMethod(delegate._receiverMethod)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||||
{
|
{
|
||||||
if (&delegate != this)
|
if (&delegate != this)
|
||||||
{
|
{
|
||||||
this->_pTarget = delegate._pTarget;
|
this->_pTarget = delegate._pTarget;
|
||||||
this->_receiverMethod = delegate._receiverMethod;
|
this->_receiverMethod = delegate._receiverMethod;
|
||||||
this->_priority = delegate._priority;
|
this->_priority = delegate._priority;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~FunctionPriorityDelegate()
|
~FunctionPriorityDelegate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notify(const void* sender, TArgs& arguments)
|
bool notify(const void* sender, TArgs& arguments)
|
||||||
{
|
{
|
||||||
(*_receiverMethod)(arguments);
|
(*_receiverMethod)(arguments);
|
||||||
return true; // per default the delegate never expires
|
return true; // per default the delegate never expires
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractPriorityDelegate<TArgs>* clone() const
|
AbstractPriorityDelegate<TArgs>* clone() const
|
||||||
{
|
{
|
||||||
return new FunctionPriorityDelegate(*this);
|
return new FunctionPriorityDelegate(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NotifyMethod _receiverMethod;
|
NotifyMethod _receiverMethod;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunctionPriorityDelegate();
|
FunctionPriorityDelegate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,127 +1,127 @@
|
|||||||
//
|
//
|
||||||
// Hash.h
|
// Hash.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/Hash.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/Hash.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Hashing
|
// Package: Hashing
|
||||||
// Module: Hash
|
// Module: Hash
|
||||||
//
|
//
|
||||||
// Definition of the Hash class.
|
// Definition of the Hash class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_Hash_INCLUDED
|
#ifndef Foundation_Hash_INCLUDED
|
||||||
#define Foundation_Hash_INCLUDED
|
#define Foundation_Hash_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct Hash
|
struct Hash
|
||||||
/// A generic hash function.
|
/// A generic hash function.
|
||||||
{
|
{
|
||||||
std::size_t operator () (T value) const
|
std::size_t operator () (T value) const
|
||||||
/// Returns the hash for the given value.
|
/// Returns the hash for the given value.
|
||||||
{
|
{
|
||||||
return hash(value);
|
return hash(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
std::size_t Foundation_API hash(Int8 n);
|
std::size_t Foundation_API hash(Int8 n);
|
||||||
std::size_t Foundation_API hash(UInt8 n);
|
std::size_t Foundation_API hash(UInt8 n);
|
||||||
std::size_t Foundation_API hash(Int16 n);
|
std::size_t Foundation_API hash(Int16 n);
|
||||||
std::size_t Foundation_API hash(UInt16 n);
|
std::size_t Foundation_API hash(UInt16 n);
|
||||||
std::size_t Foundation_API hash(Int32 n);
|
std::size_t Foundation_API hash(Int32 n);
|
||||||
std::size_t Foundation_API hash(UInt32 n);
|
std::size_t Foundation_API hash(UInt32 n);
|
||||||
std::size_t Foundation_API hash(Int64 n);
|
std::size_t Foundation_API hash(Int64 n);
|
||||||
std::size_t Foundation_API hash(UInt64 n);
|
std::size_t Foundation_API hash(UInt64 n);
|
||||||
std::size_t Foundation_API hash(const std::string& str);
|
std::size_t Foundation_API hash(const std::string& str);
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline std::size_t hash(Int8 n)
|
inline std::size_t hash(Int8 n)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(n)*2654435761U;
|
return static_cast<std::size_t>(n)*2654435761U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t hash(UInt8 n)
|
inline std::size_t hash(UInt8 n)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(n)*2654435761U;
|
return static_cast<std::size_t>(n)*2654435761U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t hash(Int16 n)
|
inline std::size_t hash(Int16 n)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(n)*2654435761U;
|
return static_cast<std::size_t>(n)*2654435761U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t hash(UInt16 n)
|
inline std::size_t hash(UInt16 n)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(n)*2654435761U;
|
return static_cast<std::size_t>(n)*2654435761U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t hash(Int32 n)
|
inline std::size_t hash(Int32 n)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(n)*2654435761U;
|
return static_cast<std::size_t>(n)*2654435761U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t hash(UInt32 n)
|
inline std::size_t hash(UInt32 n)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(n)*2654435761U;
|
return static_cast<std::size_t>(n)*2654435761U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t hash(Int64 n)
|
inline std::size_t hash(Int64 n)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(n)*2654435761U;
|
return static_cast<std::size_t>(n)*2654435761U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::size_t hash(UInt64 n)
|
inline std::size_t hash(UInt64 n)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(n)*2654435761U;
|
return static_cast<std::size_t>(n)*2654435761U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_Hash_INCLUDED
|
#endif // Foundation_Hash_INCLUDED
|
||||||
|
|||||||
@@ -1,244 +1,244 @@
|
|||||||
//
|
//
|
||||||
// HashMap.h
|
// HashMap.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/HashMap.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/HashMap.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Hashing
|
// Package: Hashing
|
||||||
// Module: HashMap
|
// Module: HashMap
|
||||||
//
|
//
|
||||||
// Definition of the HashMap class.
|
// Definition of the HashMap class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_HashMap_INCLUDED
|
#ifndef Foundation_HashMap_INCLUDED
|
||||||
#define Foundation_HashMap_INCLUDED
|
#define Foundation_HashMap_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/LinearHashTable.h"
|
#include "Poco/LinearHashTable.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class Key, class Value>
|
template <class Key, class Value>
|
||||||
struct HashMapEntry
|
struct HashMapEntry
|
||||||
/// This class template is used internally by HashMap.
|
/// This class template is used internally by HashMap.
|
||||||
{
|
{
|
||||||
Key first;
|
Key first;
|
||||||
Value second;
|
Value second;
|
||||||
|
|
||||||
HashMapEntry():
|
HashMapEntry():
|
||||||
first(),
|
first(),
|
||||||
second()
|
second()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMapEntry(const Key& key):
|
HashMapEntry(const Key& key):
|
||||||
first(key),
|
first(key),
|
||||||
second()
|
second()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMapEntry(const Key& key, const Value& value):
|
HashMapEntry(const Key& key, const Value& value):
|
||||||
first(key),
|
first(key),
|
||||||
second(value)
|
second(value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator == (const HashMapEntry& entry) const
|
bool operator == (const HashMapEntry& entry) const
|
||||||
{
|
{
|
||||||
return first == entry.first;
|
return first == entry.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator != (const HashMapEntry& entry) const
|
bool operator != (const HashMapEntry& entry) const
|
||||||
{
|
{
|
||||||
return first != entry.first;
|
return first != entry.first;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class HME, class KeyHashFunc>
|
template <class HME, class KeyHashFunc>
|
||||||
struct HashMapEntryHash
|
struct HashMapEntryHash
|
||||||
/// This class template is used internally by HashMap.
|
/// This class template is used internally by HashMap.
|
||||||
{
|
{
|
||||||
std::size_t operator () (const HME& entry) const
|
std::size_t operator () (const HME& entry) const
|
||||||
{
|
{
|
||||||
return _func(entry.first);
|
return _func(entry.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeyHashFunc _func;
|
KeyHashFunc _func;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Key, class Mapped, class HashFunc = Hash<Key> >
|
template <class Key, class Mapped, class HashFunc = Hash<Key> >
|
||||||
class HashMap
|
class HashMap
|
||||||
/// This class implements a map using a LinearHashTable.
|
/// This class implements a map using a LinearHashTable.
|
||||||
///
|
///
|
||||||
/// A HashMap can be used just like a std::map.
|
/// A HashMap can be used just like a std::map.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef Key KeyType;
|
typedef Key KeyType;
|
||||||
typedef Mapped MappedType;
|
typedef Mapped MappedType;
|
||||||
typedef Mapped& Reference;
|
typedef Mapped& Reference;
|
||||||
typedef const Mapped& ConstReference;
|
typedef const Mapped& ConstReference;
|
||||||
typedef Mapped* Pointer;
|
typedef Mapped* Pointer;
|
||||||
typedef const Mapped* ConstPointer;
|
typedef const Mapped* ConstPointer;
|
||||||
|
|
||||||
typedef HashMapEntry<Key, Mapped> ValueType;
|
typedef HashMapEntry<Key, Mapped> ValueType;
|
||||||
typedef std::pair<KeyType, MappedType> PairType;
|
typedef std::pair<KeyType, MappedType> PairType;
|
||||||
|
|
||||||
typedef HashMapEntryHash<ValueType, HashFunc> HashType;
|
typedef HashMapEntryHash<ValueType, HashFunc> HashType;
|
||||||
typedef LinearHashTable<ValueType, HashType> HashTable;
|
typedef LinearHashTable<ValueType, HashType> HashTable;
|
||||||
|
|
||||||
typedef typename HashTable::Iterator Iterator;
|
typedef typename HashTable::Iterator Iterator;
|
||||||
typedef typename HashTable::ConstIterator ConstIterator;
|
typedef typename HashTable::ConstIterator ConstIterator;
|
||||||
|
|
||||||
HashMap()
|
HashMap()
|
||||||
/// Creates an empty HashMap.
|
/// Creates an empty HashMap.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap(std::size_t initialReserve):
|
HashMap(std::size_t initialReserve):
|
||||||
_table(initialReserve)
|
_table(initialReserve)
|
||||||
/// Creates the HashMap with room for initialReserve entries.
|
/// Creates the HashMap with room for initialReserve entries.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap& operator = (const HashMap& map)
|
HashMap& operator = (const HashMap& map)
|
||||||
/// Assigns another HashMap.
|
/// Assigns another HashMap.
|
||||||
{
|
{
|
||||||
HashMap tmp(map);
|
HashMap tmp(map);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(HashMap& map)
|
void swap(HashMap& map)
|
||||||
/// Swaps the HashMap with another one.
|
/// Swaps the HashMap with another one.
|
||||||
{
|
{
|
||||||
_table.swap(map._table);
|
_table.swap(map._table);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator begin() const
|
ConstIterator begin() const
|
||||||
{
|
{
|
||||||
return _table.begin();
|
return _table.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator end() const
|
ConstIterator end() const
|
||||||
{
|
{
|
||||||
return _table.end();
|
return _table.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator begin()
|
Iterator begin()
|
||||||
{
|
{
|
||||||
return _table.begin();
|
return _table.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator end()
|
Iterator end()
|
||||||
{
|
{
|
||||||
return _table.end();
|
return _table.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator find(const KeyType& key) const
|
ConstIterator find(const KeyType& key) const
|
||||||
{
|
{
|
||||||
ValueType value(key);
|
ValueType value(key);
|
||||||
return _table.find(value);
|
return _table.find(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator find(const KeyType& key)
|
Iterator find(const KeyType& key)
|
||||||
{
|
{
|
||||||
ValueType value(key);
|
ValueType value(key);
|
||||||
return _table.find(value);
|
return _table.find(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Iterator, bool> insert(const PairType& pair)
|
std::pair<Iterator, bool> insert(const PairType& pair)
|
||||||
{
|
{
|
||||||
ValueType value(pair.first, pair.second);
|
ValueType value(pair.first, pair.second);
|
||||||
return _table.insert(value);
|
return _table.insert(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Iterator, bool> insert(const ValueType& value)
|
std::pair<Iterator, bool> insert(const ValueType& value)
|
||||||
{
|
{
|
||||||
return _table.insert(value);
|
return _table.insert(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(Iterator it)
|
void erase(Iterator it)
|
||||||
{
|
{
|
||||||
_table.erase(it);
|
_table.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(const KeyType& key)
|
void erase(const KeyType& key)
|
||||||
{
|
{
|
||||||
Iterator it = find(key);
|
Iterator it = find(key);
|
||||||
_table.erase(it);
|
_table.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
_table.clear();
|
_table.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t size() const
|
std::size_t size() const
|
||||||
{
|
{
|
||||||
return _table.size();
|
return _table.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
{
|
{
|
||||||
return _table.empty();
|
return _table.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstReference operator [] (const KeyType& key) const
|
ConstReference operator [] (const KeyType& key) const
|
||||||
{
|
{
|
||||||
ConstIterator it = _table.find(key);
|
ConstIterator it = _table.find(key);
|
||||||
if (it != _table.end())
|
if (it != _table.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
else
|
else
|
||||||
throw NotFoundException();
|
throw NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference operator [] (const KeyType& key)
|
Reference operator [] (const KeyType& key)
|
||||||
{
|
{
|
||||||
ValueType value(key);
|
ValueType value(key);
|
||||||
std::pair<Iterator, bool> res = _table.insert(value);
|
std::pair<Iterator, bool> res = _table.insert(value);
|
||||||
return res.first->second;
|
return res.first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HashTable _table;
|
HashTable _table;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_HashMap_INCLUDED
|
#endif // Foundation_HashMap_INCLUDED
|
||||||
|
|||||||
@@ -1,199 +1,199 @@
|
|||||||
//
|
//
|
||||||
// HashSet.h
|
// HashSet.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/HashSet.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/HashSet.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Hashing
|
// Package: Hashing
|
||||||
// Module: HashSet
|
// Module: HashSet
|
||||||
//
|
//
|
||||||
// Definition of the HashSet class.
|
// Definition of the HashSet class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_HashSet_INCLUDED
|
#ifndef Foundation_HashSet_INCLUDED
|
||||||
#define Foundation_HashSet_INCLUDED
|
#define Foundation_HashSet_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/LinearHashTable.h"
|
#include "Poco/LinearHashTable.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class Value, class HashFunc = Hash<Value> >
|
template <class Value, class HashFunc = Hash<Value> >
|
||||||
class HashSet
|
class HashSet
|
||||||
/// This class implements a set using a LinearHashTable.
|
/// This class implements a set using a LinearHashTable.
|
||||||
///
|
///
|
||||||
/// A HashSet can be used just like a std::set.
|
/// A HashSet can be used just like a std::set.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef Value ValueType;
|
typedef Value ValueType;
|
||||||
typedef Value& Reference;
|
typedef Value& Reference;
|
||||||
typedef const Value& ConstReference;
|
typedef const Value& ConstReference;
|
||||||
typedef Value* Pointer;
|
typedef Value* Pointer;
|
||||||
typedef const Value* ConstPointer;
|
typedef const Value* ConstPointer;
|
||||||
typedef HashFunc Hash;
|
typedef HashFunc Hash;
|
||||||
|
|
||||||
typedef LinearHashTable<ValueType, Hash> HashTable;
|
typedef LinearHashTable<ValueType, Hash> HashTable;
|
||||||
|
|
||||||
typedef typename HashTable::Iterator Iterator;
|
typedef typename HashTable::Iterator Iterator;
|
||||||
typedef typename HashTable::ConstIterator ConstIterator;
|
typedef typename HashTable::ConstIterator ConstIterator;
|
||||||
|
|
||||||
HashSet()
|
HashSet()
|
||||||
/// Creates an empty HashSet.
|
/// Creates an empty HashSet.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet(std::size_t initialReserve):
|
HashSet(std::size_t initialReserve):
|
||||||
_table(initialReserve)
|
_table(initialReserve)
|
||||||
/// Creates the HashSet, using the given initialReserve.
|
/// Creates the HashSet, using the given initialReserve.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet(const HashSet& set):
|
HashSet(const HashSet& set):
|
||||||
_table(set._table)
|
_table(set._table)
|
||||||
/// Creates the HashSet by copying another one.
|
/// Creates the HashSet by copying another one.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~HashSet()
|
~HashSet()
|
||||||
/// Destroys the HashSet.
|
/// Destroys the HashSet.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet& operator = (const HashSet& table)
|
HashSet& operator = (const HashSet& table)
|
||||||
/// Assigns another HashSet.
|
/// Assigns another HashSet.
|
||||||
{
|
{
|
||||||
HashSet tmp(table);
|
HashSet tmp(table);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(HashSet& set)
|
void swap(HashSet& set)
|
||||||
/// Swaps the HashSet with another one.
|
/// Swaps the HashSet with another one.
|
||||||
{
|
{
|
||||||
_table.swap(set._table);
|
_table.swap(set._table);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator begin() const
|
ConstIterator begin() const
|
||||||
/// Returns an iterator pointing to the first entry, if one exists.
|
/// Returns an iterator pointing to the first entry, if one exists.
|
||||||
{
|
{
|
||||||
return _table.begin();
|
return _table.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator end() const
|
ConstIterator end() const
|
||||||
/// Returns an iterator pointing to the end of the table.
|
/// Returns an iterator pointing to the end of the table.
|
||||||
{
|
{
|
||||||
return _table.end();
|
return _table.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator begin()
|
Iterator begin()
|
||||||
/// Returns an iterator pointing to the first entry, if one exists.
|
/// Returns an iterator pointing to the first entry, if one exists.
|
||||||
{
|
{
|
||||||
return _table.begin();
|
return _table.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator end()
|
Iterator end()
|
||||||
/// Returns an iterator pointing to the end of the table.
|
/// Returns an iterator pointing to the end of the table.
|
||||||
{
|
{
|
||||||
return _table.end();
|
return _table.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator find(const ValueType& value) const
|
ConstIterator find(const ValueType& value) const
|
||||||
/// Finds an entry in the table.
|
/// Finds an entry in the table.
|
||||||
{
|
{
|
||||||
return _table.find(value);
|
return _table.find(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator find(const ValueType& value)
|
Iterator find(const ValueType& value)
|
||||||
/// Finds an entry in the table.
|
/// Finds an entry in the table.
|
||||||
{
|
{
|
||||||
return _table.find(value);
|
return _table.find(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t count(const ValueType& value) const
|
std::size_t count(const ValueType& value) const
|
||||||
/// Returns the number of elements with the given
|
/// Returns the number of elements with the given
|
||||||
/// value, with is either 1 or 0.
|
/// value, with is either 1 or 0.
|
||||||
{
|
{
|
||||||
return _table.count(value);
|
return _table.count(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Iterator, bool> insert(const ValueType& value)
|
std::pair<Iterator, bool> insert(const ValueType& value)
|
||||||
/// Inserts an element into the set.
|
/// Inserts an element into the set.
|
||||||
///
|
///
|
||||||
/// If the element already exists in the set,
|
/// If the element already exists in the set,
|
||||||
/// a pair(iterator, false) with iterator pointing to the
|
/// a pair(iterator, false) with iterator pointing to the
|
||||||
/// existing element is returned.
|
/// existing element is returned.
|
||||||
/// Otherwise, the element is inserted an a
|
/// Otherwise, the element is inserted an a
|
||||||
/// pair(iterator, true) with iterator
|
/// pair(iterator, true) with iterator
|
||||||
/// pointing to the new element is returned.
|
/// pointing to the new element is returned.
|
||||||
{
|
{
|
||||||
return _table.insert(value);
|
return _table.insert(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(Iterator it)
|
void erase(Iterator it)
|
||||||
/// Erases the element pointed to by it.
|
/// Erases the element pointed to by it.
|
||||||
{
|
{
|
||||||
_table.erase(it);
|
_table.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(const ValueType& value)
|
void erase(const ValueType& value)
|
||||||
/// Erases the element with the given value, if it exists.
|
/// Erases the element with the given value, if it exists.
|
||||||
{
|
{
|
||||||
_table.erase(value);
|
_table.erase(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
/// Erases all elements.
|
/// Erases all elements.
|
||||||
{
|
{
|
||||||
_table.clear();
|
_table.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t size() const
|
std::size_t size() const
|
||||||
/// Returns the number of elements in the table.
|
/// Returns the number of elements in the table.
|
||||||
{
|
{
|
||||||
return _table.size();
|
return _table.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
/// Returns true iff the table is empty.
|
/// Returns true iff the table is empty.
|
||||||
{
|
{
|
||||||
return _table.empty();
|
return _table.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HashTable _table;
|
HashTable _table;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_HashSet_INCLUDED
|
#endif // Foundation_HashSet_INCLUDED
|
||||||
|
|||||||
@@ -1,492 +1,492 @@
|
|||||||
//
|
//
|
||||||
// LinearHashTable.h
|
// LinearHashTable.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/LinearHashTable.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/LinearHashTable.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Hashing
|
// Package: Hashing
|
||||||
// Module: LinearHashTable
|
// Module: LinearHashTable
|
||||||
//
|
//
|
||||||
// Definition of the LinearHashTable class.
|
// Definition of the LinearHashTable class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_LinearHashTable_INCLUDED
|
#ifndef Foundation_LinearHashTable_INCLUDED
|
||||||
#define Foundation_LinearHashTable_INCLUDED
|
#define Foundation_LinearHashTable_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/Hash.h"
|
#include "Poco/Hash.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class Value, class HashFunc = Hash<Value> >
|
template <class Value, class HashFunc = Hash<Value> >
|
||||||
class LinearHashTable
|
class LinearHashTable
|
||||||
/// This class implements a linear hash table.
|
/// This class implements a linear hash table.
|
||||||
///
|
///
|
||||||
/// In a linear hash table, the available address space
|
/// In a linear hash table, the available address space
|
||||||
/// grows or shrinks dynamically. A linar hash table thus
|
/// grows or shrinks dynamically. A linar hash table thus
|
||||||
/// supports any number of insertions or deletions without
|
/// supports any number of insertions or deletions without
|
||||||
/// lookup or insertion performance deterioration.
|
/// lookup or insertion performance deterioration.
|
||||||
///
|
///
|
||||||
/// Linear hashing was discovered by Witold Litwin in 1980
|
/// Linear hashing was discovered by Witold Litwin in 1980
|
||||||
/// and described in the paper LINEAR HASHING: A NEW TOOL FOR FILE AND TABLE ADDRESSING.
|
/// 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>.
|
/// For more information on linear hashing, see <http://en.wikipedia.org/wiki/Linear_hash>.
|
||||||
///
|
///
|
||||||
/// The LinearHashTable is not thread safe.
|
/// The LinearHashTable is not thread safe.
|
||||||
///
|
///
|
||||||
/// Value must support comparison for equality.
|
/// Value must support comparison for equality.
|
||||||
///
|
///
|
||||||
/// Find, insert and delete operations are basically O(1) with regard
|
/// 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 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.
|
/// 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 average, every bucket stores one element; the exact number depends
|
||||||
/// on the quality of the hash function. In most cases, the maximum number of
|
/// on the quality of the hash function. In most cases, the maximum number of
|
||||||
/// elements in a bucket should not exceed 3.
|
/// elements in a bucket should not exceed 3.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef Value ValueType;
|
typedef Value ValueType;
|
||||||
typedef Value& Reference;
|
typedef Value& Reference;
|
||||||
typedef const Value& ConstReference;
|
typedef const Value& ConstReference;
|
||||||
typedef Value* Pointer;
|
typedef Value* Pointer;
|
||||||
typedef const Value* ConstPointer;
|
typedef const Value* ConstPointer;
|
||||||
typedef HashFunc Hash;
|
typedef HashFunc Hash;
|
||||||
typedef std::vector<Value> Bucket;
|
typedef std::vector<Value> Bucket;
|
||||||
typedef std::vector<Bucket> BucketVec;
|
typedef std::vector<Bucket> BucketVec;
|
||||||
typedef typename Bucket::iterator BucketIterator;
|
typedef typename Bucket::iterator BucketIterator;
|
||||||
typedef typename BucketVec::iterator BucketVecIterator;
|
typedef typename BucketVec::iterator BucketVecIterator;
|
||||||
|
|
||||||
class ConstIterator
|
class ConstIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConstIterator()
|
ConstIterator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt):
|
ConstIterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt):
|
||||||
_vecIt(vecIt),
|
_vecIt(vecIt),
|
||||||
_endIt(endIt),
|
_endIt(endIt),
|
||||||
_buckIt(buckIt)
|
_buckIt(buckIt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator(const ConstIterator& it):
|
ConstIterator(const ConstIterator& it):
|
||||||
_vecIt(it._vecIt),
|
_vecIt(it._vecIt),
|
||||||
_endIt(it._endIt),
|
_endIt(it._endIt),
|
||||||
_buckIt(it._buckIt)
|
_buckIt(it._buckIt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator& operator = (const ConstIterator& it)
|
ConstIterator& operator = (const ConstIterator& it)
|
||||||
{
|
{
|
||||||
ConstIterator tmp(it);
|
ConstIterator tmp(it);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(ConstIterator& it)
|
void swap(ConstIterator& it)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(_vecIt, it._vecIt);
|
swap(_vecIt, it._vecIt);
|
||||||
swap(_endIt, it._endIt);
|
swap(_endIt, it._endIt);
|
||||||
swap(_buckIt, it._buckIt);
|
swap(_buckIt, it._buckIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator == (const ConstIterator& it) const
|
bool operator == (const ConstIterator& it) const
|
||||||
{
|
{
|
||||||
return _vecIt == it._vecIt && (_vecIt == _endIt || _buckIt == it._buckIt);
|
return _vecIt == it._vecIt && (_vecIt == _endIt || _buckIt == it._buckIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator != (const ConstIterator& it) const
|
bool operator != (const ConstIterator& it) const
|
||||||
{
|
{
|
||||||
return _vecIt != it._vecIt || (_vecIt != _endIt && _buckIt != it._buckIt);
|
return _vecIt != it._vecIt || (_vecIt != _endIt && _buckIt != it._buckIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
const typename Bucket::value_type& operator * () const
|
const typename Bucket::value_type& operator * () const
|
||||||
{
|
{
|
||||||
return *_buckIt;
|
return *_buckIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
const typename Bucket::value_type* operator -> () const
|
const typename Bucket::value_type* operator -> () const
|
||||||
{
|
{
|
||||||
return &*_buckIt;
|
return &*_buckIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator& operator ++ () // prefix
|
ConstIterator& operator ++ () // prefix
|
||||||
{
|
{
|
||||||
if (_vecIt != _endIt)
|
if (_vecIt != _endIt)
|
||||||
{
|
{
|
||||||
++_buckIt;
|
++_buckIt;
|
||||||
while (_vecIt != _endIt && _buckIt == _vecIt->end())
|
while (_vecIt != _endIt && _buckIt == _vecIt->end())
|
||||||
{
|
{
|
||||||
++_vecIt;
|
++_vecIt;
|
||||||
if (_vecIt != _endIt) _buckIt = _vecIt->begin();
|
if (_vecIt != _endIt) _buckIt = _vecIt->begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator operator ++ (int) // postfix
|
ConstIterator operator ++ (int) // postfix
|
||||||
{
|
{
|
||||||
ConstIterator tmp(*this);
|
ConstIterator tmp(*this);
|
||||||
++*this;
|
++*this;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BucketVecIterator _vecIt;
|
BucketVecIterator _vecIt;
|
||||||
BucketVecIterator _endIt;
|
BucketVecIterator _endIt;
|
||||||
BucketIterator _buckIt;
|
BucketIterator _buckIt;
|
||||||
|
|
||||||
friend class LinearHashTable;
|
friend class LinearHashTable;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Iterator: public ConstIterator
|
class Iterator: public ConstIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Iterator()
|
Iterator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt):
|
Iterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt):
|
||||||
ConstIterator(vecIt, endIt, buckIt)
|
ConstIterator(vecIt, endIt, buckIt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator(const Iterator& it):
|
Iterator(const Iterator& it):
|
||||||
ConstIterator(it)
|
ConstIterator(it)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator& operator = (const Iterator& it)
|
Iterator& operator = (const Iterator& it)
|
||||||
{
|
{
|
||||||
Iterator tmp(it);
|
Iterator tmp(it);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(Iterator& it)
|
void swap(Iterator& it)
|
||||||
{
|
{
|
||||||
ConstIterator::swap(it);
|
ConstIterator::swap(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
typename Bucket::value_type& operator * ()
|
typename Bucket::value_type& operator * ()
|
||||||
{
|
{
|
||||||
return *this->_buckIt;
|
return *this->_buckIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
const typename Bucket::value_type& operator * () const
|
const typename Bucket::value_type& operator * () const
|
||||||
{
|
{
|
||||||
return *this->_buckIt;
|
return *this->_buckIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
typename Bucket::value_type* operator -> ()
|
typename Bucket::value_type* operator -> ()
|
||||||
{
|
{
|
||||||
return &*this->_buckIt;
|
return &*this->_buckIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
const typename Bucket::value_type* operator -> () const
|
const typename Bucket::value_type* operator -> () const
|
||||||
{
|
{
|
||||||
return &*this->_buckIt;
|
return &*this->_buckIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator& operator ++ () // prefix
|
Iterator& operator ++ () // prefix
|
||||||
{
|
{
|
||||||
ConstIterator::operator ++ ();
|
ConstIterator::operator ++ ();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator operator ++ (int) // postfix
|
Iterator operator ++ (int) // postfix
|
||||||
{
|
{
|
||||||
Iterator tmp(*this);
|
Iterator tmp(*this);
|
||||||
++*this;
|
++*this;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend class LinearHashTable;
|
friend class LinearHashTable;
|
||||||
};
|
};
|
||||||
|
|
||||||
LinearHashTable(std::size_t initialReserve = 64):
|
LinearHashTable(std::size_t initialReserve = 64):
|
||||||
_split(0),
|
_split(0),
|
||||||
_front(1),
|
_front(1),
|
||||||
_size(0)
|
_size(0)
|
||||||
/// Creates the LinearHashTable, using the given initialReserve.
|
/// Creates the LinearHashTable, using the given initialReserve.
|
||||||
{
|
{
|
||||||
_buckets.reserve(calcSize(initialReserve));
|
_buckets.reserve(calcSize(initialReserve));
|
||||||
_buckets.push_back(Bucket());
|
_buckets.push_back(Bucket());
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearHashTable(const LinearHashTable& table):
|
LinearHashTable(const LinearHashTable& table):
|
||||||
_buckets(table._buckets),
|
_buckets(table._buckets),
|
||||||
_split(table._split),
|
_split(table._split),
|
||||||
_front(table._front),
|
_front(table._front),
|
||||||
_size(table._size)
|
_size(table._size)
|
||||||
/// Creates the LinearHashTable by copying another one.
|
/// Creates the LinearHashTable by copying another one.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~LinearHashTable()
|
~LinearHashTable()
|
||||||
/// Destroys the LinearHashTable.
|
/// Destroys the LinearHashTable.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearHashTable& operator = (const LinearHashTable& table)
|
LinearHashTable& operator = (const LinearHashTable& table)
|
||||||
/// Assigns another LinearHashTable.
|
/// Assigns another LinearHashTable.
|
||||||
{
|
{
|
||||||
LinearHashTable tmp(table);
|
LinearHashTable tmp(table);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(LinearHashTable& table)
|
void swap(LinearHashTable& table)
|
||||||
/// Swaps the LinearHashTable with another one.
|
/// Swaps the LinearHashTable with another one.
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(_buckets, table._buckets);
|
swap(_buckets, table._buckets);
|
||||||
swap(_split, table._split);
|
swap(_split, table._split);
|
||||||
swap(_front, table._front);
|
swap(_front, table._front);
|
||||||
swap(_size, table._size);
|
swap(_size, table._size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator begin() const
|
ConstIterator begin() const
|
||||||
/// Returns an iterator pointing to the first entry, if one exists.
|
/// Returns an iterator pointing to the first entry, if one exists.
|
||||||
{
|
{
|
||||||
BucketVecIterator it(_buckets.begin());
|
BucketVecIterator it(_buckets.begin());
|
||||||
BucketVecIterator end(_buckets.end());
|
BucketVecIterator end(_buckets.end());
|
||||||
while (it != end && it->empty())
|
while (it != end && it->empty())
|
||||||
{
|
{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
if (it == end)
|
if (it == end)
|
||||||
return this->end();
|
return this->end();
|
||||||
else
|
else
|
||||||
return ConstIterator(it, end, it->begin());
|
return ConstIterator(it, end, it->begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator end() const
|
ConstIterator end() const
|
||||||
/// Returns an iterator pointing to the end of the table.
|
/// Returns an iterator pointing to the end of the table.
|
||||||
{
|
{
|
||||||
return ConstIterator(_buckets.end(), _buckets.end(), _buckets.front().end());
|
return ConstIterator(_buckets.end(), _buckets.end(), _buckets.front().end());
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator begin()
|
Iterator begin()
|
||||||
/// Returns an iterator pointing to the first entry, if one exists.
|
/// Returns an iterator pointing to the first entry, if one exists.
|
||||||
{
|
{
|
||||||
BucketVecIterator it(_buckets.begin());
|
BucketVecIterator it(_buckets.begin());
|
||||||
BucketVecIterator end(_buckets.end());
|
BucketVecIterator end(_buckets.end());
|
||||||
while (it != end && it->empty())
|
while (it != end && it->empty())
|
||||||
{
|
{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
if (it == end)
|
if (it == end)
|
||||||
return this->end();
|
return this->end();
|
||||||
else
|
else
|
||||||
return Iterator(it, end, it->begin());
|
return Iterator(it, end, it->begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator end()
|
Iterator end()
|
||||||
/// Returns an iterator pointing to the end of the table.
|
/// Returns an iterator pointing to the end of the table.
|
||||||
{
|
{
|
||||||
return Iterator(_buckets.end(), _buckets.end(), _buckets.front().end());
|
return Iterator(_buckets.end(), _buckets.end(), _buckets.front().end());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator find(const Value& value) const
|
ConstIterator find(const Value& value) const
|
||||||
/// Finds an entry in the table.
|
/// Finds an entry in the table.
|
||||||
{
|
{
|
||||||
std::size_t addr = bucketAddress(value);
|
std::size_t addr = bucketAddress(value);
|
||||||
BucketVecIterator it(_buckets.begin() + addr);
|
BucketVecIterator it(_buckets.begin() + addr);
|
||||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||||
if (buckIt != it->end())
|
if (buckIt != it->end())
|
||||||
return ConstIterator(it, _buckets.end(), buckIt);
|
return ConstIterator(it, _buckets.end(), buckIt);
|
||||||
else
|
else
|
||||||
return end();
|
return end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator find(const Value& value)
|
Iterator find(const Value& value)
|
||||||
/// Finds an entry in the table.
|
/// Finds an entry in the table.
|
||||||
{
|
{
|
||||||
std::size_t addr = bucketAddress(value);
|
std::size_t addr = bucketAddress(value);
|
||||||
BucketVecIterator it(_buckets.begin() + addr);
|
BucketVecIterator it(_buckets.begin() + addr);
|
||||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||||
if (buckIt != it->end())
|
if (buckIt != it->end())
|
||||||
return Iterator(it, _buckets.end(), buckIt);
|
return Iterator(it, _buckets.end(), buckIt);
|
||||||
else
|
else
|
||||||
return end();
|
return end();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t count(const Value& value) const
|
std::size_t count(const Value& value) const
|
||||||
/// Returns the number of elements with the given
|
/// Returns the number of elements with the given
|
||||||
/// value, with is either 1 or 0.
|
/// value, with is either 1 or 0.
|
||||||
{
|
{
|
||||||
return find(value) != end() ? 1 : 0;
|
return find(value) != end() ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Iterator, bool> insert(const Value& value)
|
std::pair<Iterator, bool> insert(const Value& value)
|
||||||
/// Inserts an element into the table.
|
/// Inserts an element into the table.
|
||||||
///
|
///
|
||||||
/// If the element already exists in the table,
|
/// If the element already exists in the table,
|
||||||
/// a pair(iterator, false) with iterator pointing to the
|
/// a pair(iterator, false) with iterator pointing to the
|
||||||
/// existing element is returned.
|
/// existing element is returned.
|
||||||
/// Otherwise, the element is inserted an a
|
/// Otherwise, the element is inserted an a
|
||||||
/// pair(iterator, true) with iterator
|
/// pair(iterator, true) with iterator
|
||||||
/// pointing to the new element is returned.
|
/// pointing to the new element is returned.
|
||||||
{
|
{
|
||||||
split();
|
split();
|
||||||
std::size_t addr = bucketAddress(value);
|
std::size_t addr = bucketAddress(value);
|
||||||
BucketVecIterator it(_buckets.begin() + addr);
|
BucketVecIterator it(_buckets.begin() + addr);
|
||||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||||
if (buckIt == it->end())
|
if (buckIt == it->end())
|
||||||
{
|
{
|
||||||
buckIt = it->insert(buckIt, value);
|
buckIt = it->insert(buckIt, value);
|
||||||
++_size;
|
++_size;
|
||||||
return std::make_pair(Iterator(it, _buckets.end(), buckIt), true);
|
return std::make_pair(Iterator(it, _buckets.end(), buckIt), true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return std::make_pair(Iterator(it, _buckets.end(), buckIt), false);
|
return std::make_pair(Iterator(it, _buckets.end(), buckIt), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(Iterator it)
|
void erase(Iterator it)
|
||||||
/// Erases the element pointed to by it.
|
/// Erases the element pointed to by it.
|
||||||
{
|
{
|
||||||
if (it != end())
|
if (it != end())
|
||||||
{
|
{
|
||||||
it._vecIt->erase(it._buckIt);
|
it._vecIt->erase(it._buckIt);
|
||||||
--_size;
|
--_size;
|
||||||
merge();
|
merge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(const Value& value)
|
void erase(const Value& value)
|
||||||
/// Erases the element with the given value, if it exists.
|
/// Erases the element with the given value, if it exists.
|
||||||
{
|
{
|
||||||
Iterator it = find(value);
|
Iterator it = find(value);
|
||||||
erase(it);
|
erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
/// Erases all elements.
|
/// Erases all elements.
|
||||||
{
|
{
|
||||||
LinearHashTable empty;
|
LinearHashTable empty;
|
||||||
swap(empty);
|
swap(empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t size() const
|
std::size_t size() const
|
||||||
/// Returns the number of elements in the table.
|
/// Returns the number of elements in the table.
|
||||||
{
|
{
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
/// Returns true iff the table is empty.
|
/// Returns true iff the table is empty.
|
||||||
{
|
{
|
||||||
return _size == 0;
|
return _size == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::size_t bucketAddress(const Value& value) const
|
std::size_t bucketAddress(const Value& value) const
|
||||||
{
|
{
|
||||||
std::size_t n = _hash(value);
|
std::size_t n = _hash(value);
|
||||||
if (n % _front >= _split)
|
if (n % _front >= _split)
|
||||||
return n % _front;
|
return n % _front;
|
||||||
else
|
else
|
||||||
return n % (2*_front);
|
return n % (2*_front);
|
||||||
}
|
}
|
||||||
|
|
||||||
void split()
|
void split()
|
||||||
{
|
{
|
||||||
if (_split == _front)
|
if (_split == _front)
|
||||||
{
|
{
|
||||||
_split = 0;
|
_split = 0;
|
||||||
_front *= 2;
|
_front *= 2;
|
||||||
_buckets.reserve(_front*2);
|
_buckets.reserve(_front*2);
|
||||||
}
|
}
|
||||||
Bucket tmp;
|
Bucket tmp;
|
||||||
_buckets.push_back(tmp);
|
_buckets.push_back(tmp);
|
||||||
_buckets[_split].swap(tmp);
|
_buckets[_split].swap(tmp);
|
||||||
++_split;
|
++_split;
|
||||||
for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it)
|
for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
std::size_t addr = bucketAddress(*it);
|
std::size_t addr = bucketAddress(*it);
|
||||||
_buckets[addr].push_back(Value());
|
_buckets[addr].push_back(Value());
|
||||||
swap(*it, _buckets[addr].back());
|
swap(*it, _buckets[addr].back());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge()
|
void merge()
|
||||||
{
|
{
|
||||||
if (_split == 0)
|
if (_split == 0)
|
||||||
{
|
{
|
||||||
_front /= 2;
|
_front /= 2;
|
||||||
_split = _front;
|
_split = _front;
|
||||||
}
|
}
|
||||||
--_split;
|
--_split;
|
||||||
Bucket tmp;
|
Bucket tmp;
|
||||||
tmp.swap(_buckets.back());
|
tmp.swap(_buckets.back());
|
||||||
_buckets.pop_back();
|
_buckets.pop_back();
|
||||||
for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it)
|
for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
std::size_t addr = bucketAddress(*it);
|
std::size_t addr = bucketAddress(*it);
|
||||||
_buckets[addr].push_back(Value());
|
_buckets[addr].push_back(Value());
|
||||||
swap(*it, _buckets[addr].back());
|
swap(*it, _buckets[addr].back());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::size_t calcSize(std::size_t initialSize)
|
static std::size_t calcSize(std::size_t initialSize)
|
||||||
{
|
{
|
||||||
std::size_t size = 32;
|
std::size_t size = 32;
|
||||||
while (size < initialSize) size *= 2;
|
while (size < initialSize) size *= 2;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Evil hack: _buckets must be mutable because both ConstIterator and Iterator hold
|
// Evil hack: _buckets must be mutable because both ConstIterator and Iterator hold
|
||||||
// ordinary iterator's (not const_iterator's).
|
// ordinary iterator's (not const_iterator's).
|
||||||
mutable BucketVec _buckets;
|
mutable BucketVec _buckets;
|
||||||
std::size_t _split;
|
std::size_t _split;
|
||||||
std::size_t _front;
|
std::size_t _front;
|
||||||
std::size_t _size;
|
std::size_t _size;
|
||||||
HashFunc _hash;
|
HashFunc _hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_LinearHashTable_INCLUDED
|
#endif // Foundation_LinearHashTable_INCLUDED
|
||||||
|
|||||||
@@ -1,157 +1,157 @@
|
|||||||
//
|
//
|
||||||
// TypeChecks.h
|
// TypeChecks.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/MetaProgramming.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/MetaProgramming.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: MetaProgramming
|
// Module: MetaProgramming
|
||||||
//
|
//
|
||||||
// Common definitions useful for Meta Template Programming
|
// Common definitions useful for Meta Template Programming
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_TypeChecks_INCLUDED
|
#ifndef Foundation_TypeChecks_INCLUDED
|
||||||
#define Foundation_TypeChecks_INCLUDED
|
#define Foundation_TypeChecks_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsReference
|
struct IsReference
|
||||||
///Use this struct to determine if a template type is a reference
|
///Use this struct to determine if a template type is a reference
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
VALUE = 0
|
VALUE = 0
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsReference<T&>
|
struct IsReference<T&>
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
VALUE = 1
|
VALUE = 1
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsReference<const T&>
|
struct IsReference<const T&>
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
VALUE = 1
|
VALUE = 1
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsConst
|
struct IsConst
|
||||||
///Use this struct to determine if a template type is a const type
|
///Use this struct to determine if a template type is a const type
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
VALUE = 0
|
VALUE = 0
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsConst<const T&>
|
struct IsConst<const T&>
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
VALUE = 1
|
VALUE = 1
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsConst<const T>
|
struct IsConst<const T>
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
VALUE = 1
|
VALUE = 1
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TypeWrapper
|
struct TypeWrapper
|
||||||
/// Use the type wrapper if you want to dedecouple constness and references from template types
|
/// Use the type wrapper if you want to dedecouple constness and references from template types
|
||||||
{
|
{
|
||||||
typedef T TYPE;
|
typedef T TYPE;
|
||||||
typedef const T CONSTTYPE;
|
typedef const T CONSTTYPE;
|
||||||
typedef T& REFTYPE;
|
typedef T& REFTYPE;
|
||||||
typedef const T& CONSTREFTYPE;
|
typedef const T& CONSTREFTYPE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TypeWrapper<const T>
|
struct TypeWrapper<const T>
|
||||||
{
|
{
|
||||||
typedef T TYPE;
|
typedef T TYPE;
|
||||||
typedef const T CONSTTYPE;
|
typedef const T CONSTTYPE;
|
||||||
typedef T& REFTYPE;
|
typedef T& REFTYPE;
|
||||||
typedef const T& CONSTREFTYPE;
|
typedef const T& CONSTREFTYPE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TypeWrapper<const T&>
|
struct TypeWrapper<const T&>
|
||||||
{
|
{
|
||||||
typedef T TYPE;
|
typedef T TYPE;
|
||||||
typedef const T CONSTTYPE;
|
typedef const T CONSTTYPE;
|
||||||
typedef T& REFTYPE;
|
typedef T& REFTYPE;
|
||||||
typedef const T& CONSTREFTYPE;
|
typedef const T& CONSTREFTYPE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TypeWrapper<T&>
|
struct TypeWrapper<T&>
|
||||||
{
|
{
|
||||||
typedef T TYPE;
|
typedef T TYPE;
|
||||||
typedef const T CONSTTYPE;
|
typedef const T CONSTTYPE;
|
||||||
typedef T& REFTYPE;
|
typedef T& REFTYPE;
|
||||||
typedef const T& CONSTREFTYPE;
|
typedef const T& CONSTREFTYPE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,79 +1,79 @@
|
|||||||
//
|
//
|
||||||
// ScopedUnlock.h
|
// ScopedUnlock.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/ScopedUnlock.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/ScopedUnlock.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
// Module: Mutex
|
// Module: Mutex
|
||||||
//
|
//
|
||||||
// Definition of the ScopedUnlock template class.
|
// Definition of the ScopedUnlock template class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_ScopedUnlock_INCLUDED
|
#ifndef Foundation_ScopedUnlock_INCLUDED
|
||||||
#define Foundation_ScopedUnlock_INCLUDED
|
#define Foundation_ScopedUnlock_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class M>
|
template <class M>
|
||||||
class ScopedUnlock
|
class ScopedUnlock
|
||||||
/// A class that simplifies thread synchronization
|
/// A class that simplifies thread synchronization
|
||||||
/// with a mutex.
|
/// with a mutex.
|
||||||
/// The constructor accepts a Mutex and unlocks it.
|
/// The constructor accepts a Mutex and unlocks it.
|
||||||
/// The destructor unlocks the mutex.
|
/// The destructor unlocks the mutex.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline ScopedUnlock(M& mutex, bool unlockNow = true): _mutex(mutex)
|
inline ScopedUnlock(M& mutex, bool unlockNow = true): _mutex(mutex)
|
||||||
{
|
{
|
||||||
if (unlockNow)
|
if (unlockNow)
|
||||||
_mutex.unlock();
|
_mutex.unlock();
|
||||||
}
|
}
|
||||||
inline ~ScopedUnlock()
|
inline ~ScopedUnlock()
|
||||||
{
|
{
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
M& _mutex;
|
M& _mutex;
|
||||||
|
|
||||||
ScopedUnlock();
|
ScopedUnlock();
|
||||||
ScopedUnlock(const ScopedUnlock&);
|
ScopedUnlock(const ScopedUnlock&);
|
||||||
ScopedUnlock& operator = (const ScopedUnlock&);
|
ScopedUnlock& operator = (const ScopedUnlock&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_ScopedUnlock_INCLUDED
|
#endif // Foundation_ScopedUnlock_INCLUDED
|
||||||
|
|||||||
@@ -1,135 +1,135 @@
|
|||||||
//
|
//
|
||||||
// SharedMemory.h
|
// SharedMemory.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Processes
|
// Package: Processes
|
||||||
// Module: SharedMemory
|
// Module: SharedMemory
|
||||||
//
|
//
|
||||||
// Definition of the SharedMemory class.
|
// Definition of the SharedMemory class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_SharedMemory_INCLUDED
|
#ifndef Foundation_SharedMemory_INCLUDED
|
||||||
#define Foundation_SharedMemory_INCLUDED
|
#define Foundation_SharedMemory_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class SharedMemoryImpl;
|
class SharedMemoryImpl;
|
||||||
class File;
|
class File;
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API SharedMemory
|
class Foundation_API SharedMemory
|
||||||
/// Create and manage a shared memory object.
|
/// Create and manage a shared memory object.
|
||||||
///
|
///
|
||||||
/// A SharedMemory object has value semantics, but
|
/// A SharedMemory object has value semantics, but
|
||||||
/// is implemented using a handle/implementation idiom.
|
/// is implemented using a handle/implementation idiom.
|
||||||
/// Therefore, multiple SharedMemory objects can share
|
/// Therefore, multiple SharedMemory objects can share
|
||||||
/// a single, reference counted SharedMemoryImpl object.
|
/// a single, reference counted SharedMemoryImpl object.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum AccessMode
|
enum AccessMode
|
||||||
{
|
{
|
||||||
AM_READ = 0,
|
AM_READ = 0,
|
||||||
AM_WRITE
|
AM_WRITE
|
||||||
};
|
};
|
||||||
|
|
||||||
SharedMemory();
|
SharedMemory();
|
||||||
/// Default constructor creates an unmapped SharedMemory object.
|
/// Default constructor creates an unmapped SharedMemory object.
|
||||||
/// No clients can connect to 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);
|
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.
|
/// Creates or connects to a shared memory object with the given name.
|
||||||
///
|
///
|
||||||
/// For maximum portability, name should be a valid Unix filename and not
|
/// For maximum portability, name should be a valid Unix filename and not
|
||||||
/// contain any slashes or backslashes.
|
/// contain any slashes or backslashes.
|
||||||
///
|
///
|
||||||
/// An address hint can be passed to the system, specifying the desired
|
/// An address hint can be passed to the system, specifying the desired
|
||||||
/// start address of the shared memory area. Whether the hint
|
/// start address of the shared memory area. Whether the hint
|
||||||
/// is actually honored is, however, up to the system. Windows platform
|
/// is actually honored is, however, up to the system. Windows platform
|
||||||
/// will generally ignore the hint.
|
/// will generally ignore the hint.
|
||||||
///
|
///
|
||||||
/// If server is set to false, the shared memory region will be unlinked
|
/// 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.
|
/// by calling shm_unlink (on POSIX platforms) when the SharedMemory object is destroyed.
|
||||||
/// The server parameter is ignored on Windows platforms.
|
/// The server parameter is ignored on Windows platforms.
|
||||||
|
|
||||||
SharedMemory(const File& file, AccessMode mode, const void* addrHint = 0);
|
SharedMemory(const File& file, AccessMode mode, const void* addrHint = 0);
|
||||||
/// Maps the entire contents of file into a shared memory segment.
|
/// Maps the entire contents of file into a shared memory segment.
|
||||||
///
|
///
|
||||||
/// An address hint can be passed to the system, specifying the desired
|
/// An address hint can be passed to the system, specifying the desired
|
||||||
/// start address of the shared memory area. Whether the hint
|
/// start address of the shared memory area. Whether the hint
|
||||||
/// is actually honored is, however, up to the system. Windows platform
|
/// is actually honored is, however, up to the system. Windows platform
|
||||||
/// will generally ignore the hint.
|
/// will generally ignore the hint.
|
||||||
|
|
||||||
SharedMemory(const SharedMemory& other);
|
SharedMemory(const SharedMemory& other);
|
||||||
/// Creates a SharedMemory object by copying another one.
|
/// Creates a SharedMemory object by copying another one.
|
||||||
|
|
||||||
~SharedMemory();
|
~SharedMemory();
|
||||||
/// Destroys the SharedMemory.
|
/// Destroys the SharedMemory.
|
||||||
|
|
||||||
SharedMemory& operator = (const SharedMemory& other);
|
SharedMemory& operator = (const SharedMemory& other);
|
||||||
/// Assigns another SharedMemory object.
|
/// Assigns another SharedMemory object.
|
||||||
|
|
||||||
void swap(SharedMemory& other);
|
void swap(SharedMemory& other);
|
||||||
/// Swaps the SharedMemory object with another one.
|
/// Swaps the SharedMemory object with another one.
|
||||||
|
|
||||||
char* begin() const;
|
char* begin() const;
|
||||||
/// Returns the start address of the shared memory segment.
|
/// Returns the start address of the shared memory segment.
|
||||||
/// Will be NULL for illegal segments.
|
/// Will be NULL for illegal segments.
|
||||||
|
|
||||||
char* end() const;
|
char* end() const;
|
||||||
/// Returns the one-past-end end address of the shared memory segment.
|
/// Returns the one-past-end end address of the shared memory segment.
|
||||||
/// Will be NULL for illegal segments.
|
/// Will be NULL for illegal segments.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedMemoryImpl* _pImpl;
|
SharedMemoryImpl* _pImpl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline void SharedMemory::swap(SharedMemory& other)
|
inline void SharedMemory::swap(SharedMemory& other)
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(_pImpl, other._pImpl);
|
swap(_pImpl, other._pImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco::Poco
|
} // namespace Poco::Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_SharedMemory_INCLUDED
|
#endif // Foundation_SharedMemory_INCLUDED
|
||||||
|
|||||||
@@ -1,110 +1,110 @@
|
|||||||
//
|
//
|
||||||
// SharedMemoryImpl.h
|
// SharedMemoryImpl.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_DUMMY.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_DUMMY.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Processes
|
// Package: Processes
|
||||||
// Module: SharedMemoryImpl
|
// Module: SharedMemoryImpl
|
||||||
//
|
//
|
||||||
// Definition of the SharedMemoryImpl class.
|
// Definition of the SharedMemoryImpl class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/SharedMemory.h"
|
#include "Poco/SharedMemory.h"
|
||||||
#include "Poco/RefCountedObject.h"
|
#include "Poco/RefCountedObject.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||||
/// A dummy implementation of shared memory, for systems
|
/// A dummy implementation of shared memory, for systems
|
||||||
/// that do not have shared memory support.
|
/// that do not have shared memory support.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SharedMemoryImpl(const std::string& id, std::size_t size, SharedMemory::AccessMode mode, const void* addr, bool server);
|
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.
|
/// Creates or connects to a shared memory object with the given name.
|
||||||
///
|
///
|
||||||
/// For maximum portability, name should be a valid Unix filename and not
|
/// For maximum portability, name should be a valid Unix filename and not
|
||||||
/// contain any slashes or backslashes.
|
/// contain any slashes or backslashes.
|
||||||
///
|
///
|
||||||
/// An address hint can be passed to the system, specifying the desired
|
/// An address hint can be passed to the system, specifying the desired
|
||||||
/// start address of the shared memory area. Whether the hint
|
/// start address of the shared memory area. Whether the hint
|
||||||
/// is actually honored is, however, up to the system. Windows platform
|
/// is actually honored is, however, up to the system. Windows platform
|
||||||
/// will generally ignore the hint.
|
/// will generally ignore the hint.
|
||||||
|
|
||||||
SharedMemoryImpl(const Poco::File& aFile, SharedMemory::AccessMode mode, const void* addr);
|
SharedMemoryImpl(const Poco::File& aFile, SharedMemory::AccessMode mode, const void* addr);
|
||||||
/// Maps the entire contents of file into a shared memory segment.
|
/// Maps the entire contents of file into a shared memory segment.
|
||||||
///
|
///
|
||||||
/// An address hint can be passed to the system, specifying the desired
|
/// An address hint can be passed to the system, specifying the desired
|
||||||
/// start address of the shared memory area. Whether the hint
|
/// start address of the shared memory area. Whether the hint
|
||||||
/// is actually honored is, however, up to the system. Windows platform
|
/// is actually honored is, however, up to the system. Windows platform
|
||||||
/// will generally ignore the hint.
|
/// will generally ignore the hint.
|
||||||
|
|
||||||
char* begin() const;
|
char* begin() const;
|
||||||
/// Returns the start address of the shared memory segment.
|
/// Returns the start address of the shared memory segment.
|
||||||
|
|
||||||
char* end() const;
|
char* end() const;
|
||||||
/// Returns the one-past-end end address of the shared memory segment.
|
/// Returns the one-past-end end address of the shared memory segment.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~SharedMemoryImpl();
|
~SharedMemoryImpl();
|
||||||
/// Destroys the SharedMemoryImpl.
|
/// Destroys the SharedMemoryImpl.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedMemoryImpl();
|
SharedMemoryImpl();
|
||||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline char* SharedMemoryImpl::begin() const
|
inline char* SharedMemoryImpl::begin() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline char* SharedMemoryImpl::end() const
|
inline char* SharedMemoryImpl::end() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||||
|
|||||||
@@ -1,129 +1,129 @@
|
|||||||
//
|
//
|
||||||
// SharedMemoryImpl.h
|
// SharedMemoryImpl.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_POSIX.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_POSIX.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Processes
|
// Package: Processes
|
||||||
// Module: SharedMemoryImpl
|
// Module: SharedMemoryImpl
|
||||||
//
|
//
|
||||||
// Definition of the SharedMemoryImpl class.
|
// Definition of the SharedMemoryImpl class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/SharedMemory.h"
|
#include "Poco/SharedMemory.h"
|
||||||
#include "Poco/RefCountedObject.h"
|
#include "Poco/RefCountedObject.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||||
/// Shared memory implementation for POSIX platforms.
|
/// Shared memory implementation for POSIX platforms.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server);
|
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.
|
/// Creates or connects to a shared memory object with the given name.
|
||||||
///
|
///
|
||||||
/// For maximum portability, name should be a valid Unix filename and not
|
/// For maximum portability, name should be a valid Unix filename and not
|
||||||
/// contain any slashes or backslashes.
|
/// contain any slashes or backslashes.
|
||||||
///
|
///
|
||||||
/// An address hint can be passed to the system, specifying the desired
|
/// An address hint can be passed to the system, specifying the desired
|
||||||
/// start address of the shared memory area. Whether the hint
|
/// start address of the shared memory area. Whether the hint
|
||||||
/// is actually honored is, however, up to the system. Windows platform
|
/// is actually honored is, however, up to the system. Windows platform
|
||||||
/// will generally ignore the hint.
|
/// will generally ignore the hint.
|
||||||
///
|
///
|
||||||
/// If server is set to false, the shared memory region will be unlinked
|
/// If server is set to false, the shared memory region will be unlinked
|
||||||
/// by calling shm_unlink when the SharedMemory object is destroyed.
|
/// by calling shm_unlink when the SharedMemory object is destroyed.
|
||||||
|
|
||||||
SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint);
|
SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint);
|
||||||
/// Maps the entire contents of file into a shared memory segment.
|
/// Maps the entire contents of file into a shared memory segment.
|
||||||
///
|
///
|
||||||
/// An address hint can be passed to the system, specifying the desired
|
/// An address hint can be passed to the system, specifying the desired
|
||||||
/// start address of the shared memory area. Whether the hint
|
/// start address of the shared memory area. Whether the hint
|
||||||
/// is actually honored is, however, up to the system. Windows platform
|
/// is actually honored is, however, up to the system. Windows platform
|
||||||
/// will generally ignore the hint.
|
/// will generally ignore the hint.
|
||||||
|
|
||||||
char* begin() const;
|
char* begin() const;
|
||||||
/// Returns the start address of the shared memory segment.
|
/// Returns the start address of the shared memory segment.
|
||||||
|
|
||||||
char* end() const;
|
char* end() const;
|
||||||
/// Returns the one-past-end end address of the shared memory segment.
|
/// Returns the one-past-end end address of the shared memory segment.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void map(const void* addrHint);
|
void map(const void* addrHint);
|
||||||
/// Maps the shared memory object.
|
/// Maps the shared memory object.
|
||||||
|
|
||||||
void unmap();
|
void unmap();
|
||||||
/// Unmaps the shared memory object.
|
/// Unmaps the shared memory object.
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
/// Releases the handle for the shared memory segment.
|
/// Releases the handle for the shared memory segment.
|
||||||
|
|
||||||
~SharedMemoryImpl();
|
~SharedMemoryImpl();
|
||||||
/// Destroys the SharedMemoryImpl.
|
/// Destroys the SharedMemoryImpl.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedMemoryImpl();
|
SharedMemoryImpl();
|
||||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||||
|
|
||||||
std::size_t _size;
|
std::size_t _size;
|
||||||
int _fd;
|
int _fd;
|
||||||
char* _address;
|
char* _address;
|
||||||
SharedMemory::AccessMode _access;
|
SharedMemory::AccessMode _access;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
bool _fileMapped;
|
bool _fileMapped;
|
||||||
bool _server;
|
bool _server;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline char* SharedMemoryImpl::begin() const
|
inline char* SharedMemoryImpl::begin() const
|
||||||
{
|
{
|
||||||
return _address;
|
return _address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline char* SharedMemoryImpl::end() const
|
inline char* SharedMemoryImpl::end() const
|
||||||
{
|
{
|
||||||
return _address + _size;
|
return _address + _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||||
|
|||||||
@@ -1,125 +1,125 @@
|
|||||||
//
|
//
|
||||||
// SharedMemoryImpl.h
|
// SharedMemoryImpl.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_WIN32.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_WIN32.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Processes
|
// Package: Processes
|
||||||
// Module: SharedMemoryImpl
|
// Module: SharedMemoryImpl
|
||||||
//
|
//
|
||||||
// Definition of the SharedMemoryImpl class.
|
// Definition of the SharedMemoryImpl class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Poco.h"
|
#include "Poco/Poco.h"
|
||||||
#include "Poco/SharedMemory.h"
|
#include "Poco/SharedMemory.h"
|
||||||
#include "Poco/RefCountedObject.h"
|
#include "Poco/RefCountedObject.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||||
/// Shared memory implementation for Windows platforms.
|
/// Shared memory implementation for Windows platforms.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server);
|
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.
|
/// Creates or connects to a shared memory object with the given name.
|
||||||
///
|
///
|
||||||
/// For maximum portability, name should be a valid Unix filename and not
|
/// For maximum portability, name should be a valid Unix filename and not
|
||||||
/// contain any slashes or backslashes.
|
/// contain any slashes or backslashes.
|
||||||
///
|
///
|
||||||
/// An address hint can be passed to the system, specifying the desired
|
/// An address hint can be passed to the system, specifying the desired
|
||||||
/// start address of the shared memory area. Whether the hint
|
/// start address of the shared memory area. Whether the hint
|
||||||
/// is actually honored is, however, up to the system. Windows platform
|
/// is actually honored is, however, up to the system. Windows platform
|
||||||
/// will generally ignore the hint.
|
/// will generally ignore the hint.
|
||||||
|
|
||||||
SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint);
|
SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint);
|
||||||
/// Maps the entire contents of file into a shared memory segment.
|
/// Maps the entire contents of file into a shared memory segment.
|
||||||
///
|
///
|
||||||
/// An address hint can be passed to the system, specifying the desired
|
/// An address hint can be passed to the system, specifying the desired
|
||||||
/// start address of the shared memory area. Whether the hint
|
/// start address of the shared memory area. Whether the hint
|
||||||
/// is actually honored is, however, up to the system. Windows platform
|
/// is actually honored is, however, up to the system. Windows platform
|
||||||
/// will generally ignore the hint.
|
/// will generally ignore the hint.
|
||||||
|
|
||||||
char* begin() const;
|
char* begin() const;
|
||||||
/// Returns the beginn address of the SharedMemory segment. Will be null for illegal segments.
|
/// Returns the beginn address of the SharedMemory segment. Will be null for illegal segments.
|
||||||
|
|
||||||
char* end() const;
|
char* end() const;
|
||||||
/// Points past the last byte of the end address of the SharedMemory segment. Will be null for illegal segments.
|
/// Points past the last byte of the end address of the SharedMemory segment. Will be null for illegal segments.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void map();
|
void map();
|
||||||
/// Maps the shared memory object.
|
/// Maps the shared memory object.
|
||||||
|
|
||||||
void unmap();
|
void unmap();
|
||||||
/// Unmaps the shared memory object.
|
/// Unmaps the shared memory object.
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
/// Releases the handle for the shared memory segment.
|
/// Releases the handle for the shared memory segment.
|
||||||
|
|
||||||
~SharedMemoryImpl();
|
~SharedMemoryImpl();
|
||||||
/// Destroys the SharedMemoryImpl.
|
/// Destroys the SharedMemoryImpl.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedMemoryImpl();
|
SharedMemoryImpl();
|
||||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||||
|
|
||||||
std::string _name;
|
std::string _name;
|
||||||
HANDLE _memHandle;
|
HANDLE _memHandle;
|
||||||
HANDLE _fileHandle;
|
HANDLE _fileHandle;
|
||||||
DWORD _size;
|
DWORD _size;
|
||||||
DWORD _mode;
|
DWORD _mode;
|
||||||
char* _address;
|
char* _address;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// inlines
|
// inlines
|
||||||
//
|
//
|
||||||
inline char* SharedMemoryImpl::begin() const
|
inline char* SharedMemoryImpl::begin() const
|
||||||
{
|
{
|
||||||
return _address;
|
return _address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline char* SharedMemoryImpl::end() const
|
inline char* SharedMemoryImpl::end() const
|
||||||
{
|
{
|
||||||
return _address + _size;
|
return _address + _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,487 +1,487 @@
|
|||||||
//
|
//
|
||||||
// TypeList.h
|
// TypeList.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/TypeList.h#3 $
|
// $Id: //poco/svn/Foundation/include/Poco/TypeList.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: TypeList
|
// Module: TypeList
|
||||||
//
|
//
|
||||||
// Implementation of the TypeList template.
|
// Implementation of the TypeList template.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Portions extracted and adapted from
|
// Portions extracted and adapted from
|
||||||
// The Loki Library
|
// The Loki Library
|
||||||
// Copyright (c) 2001 by Andrei Alexandrescu
|
// Copyright (c) 2001 by Andrei Alexandrescu
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_TypeList_INCLUDED
|
#ifndef Foundation_TypeList_INCLUDED
|
||||||
#define Foundation_TypeList_INCLUDED
|
#define Foundation_TypeList_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/MetaProgramming.h"
|
#include "Poco/MetaProgramming.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail>
|
template <class Head, class Tail>
|
||||||
struct TypeList;
|
struct TypeList;
|
||||||
|
|
||||||
|
|
||||||
struct NullTypeList
|
struct NullTypeList
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
length = 0
|
length = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator == (const NullTypeList&) const
|
bool operator == (const NullTypeList&) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator != (const NullTypeList&) const
|
bool operator != (const NullTypeList&) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator < (const NullTypeList&) const
|
bool operator < (const NullTypeList&) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail>
|
template <class Head, class Tail>
|
||||||
struct TypeList
|
struct TypeList
|
||||||
/// Compile Time List of Types
|
/// Compile Time List of Types
|
||||||
{
|
{
|
||||||
typedef Head HeadType;
|
typedef Head HeadType;
|
||||||
typedef Tail TailType;
|
typedef Tail TailType;
|
||||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||||
typedef typename TypeWrapper<TailType>::CONSTTYPE ConstTailType;
|
typedef typename TypeWrapper<TailType>::CONSTTYPE ConstTailType;
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
length = TailType::length+1
|
length = TailType::length+1
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeList():head(), tail()
|
TypeList():head(), tail()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeList(ConstHeadType& h, ConstTailType& t):head(h), tail(t)
|
TypeList(ConstHeadType& h, ConstTailType& t):head(h), tail(t)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeList(const TypeList& tl): head(tl.head), tail(tl.tail)
|
TypeList(const TypeList& tl): head(tl.head), tail(tl.tail)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeList& operator = (const TypeList& tl)
|
TypeList& operator = (const TypeList& tl)
|
||||||
{
|
{
|
||||||
if (this != &tl)
|
if (this != &tl)
|
||||||
{
|
{
|
||||||
TypeList tmp(tl);
|
TypeList tmp(tl);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator == (const TypeList& tl) const
|
bool operator == (const TypeList& tl) const
|
||||||
{
|
{
|
||||||
return tl.head == head && tl.tail == tail;
|
return tl.head == head && tl.tail == tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator != (const TypeList& tl) const
|
bool operator != (const TypeList& tl) const
|
||||||
{
|
{
|
||||||
return !(*this == tl);
|
return !(*this == tl);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator < (const TypeList& tl) const
|
bool operator < (const TypeList& tl) const
|
||||||
{
|
{
|
||||||
if (head < tl.head)
|
if (head < tl.head)
|
||||||
return true;
|
return true;
|
||||||
else if (head == tl.head)
|
else if (head == tl.head)
|
||||||
return tail < tl.tail;
|
return tail < tl.tail;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(TypeList& tl)
|
void swap(TypeList& tl)
|
||||||
{
|
{
|
||||||
std::swap(head, tl.head);
|
std::swap(head, tl.head);
|
||||||
std::swap(tail, tl.tail);
|
std::swap(tail, tl.tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
HeadType head;
|
HeadType head;
|
||||||
TailType tail;
|
TailType tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T0 = NullTypeList,
|
template <typename T0 = NullTypeList,
|
||||||
typename T1 = NullTypeList,
|
typename T1 = NullTypeList,
|
||||||
typename T2 = NullTypeList,
|
typename T2 = NullTypeList,
|
||||||
typename T3 = NullTypeList,
|
typename T3 = NullTypeList,
|
||||||
typename T4 = NullTypeList,
|
typename T4 = NullTypeList,
|
||||||
typename T5 = NullTypeList,
|
typename T5 = NullTypeList,
|
||||||
typename T6 = NullTypeList,
|
typename T6 = NullTypeList,
|
||||||
typename T7 = NullTypeList,
|
typename T7 = NullTypeList,
|
||||||
typename T8 = NullTypeList,
|
typename T8 = NullTypeList,
|
||||||
typename T9 = NullTypeList,
|
typename T9 = NullTypeList,
|
||||||
typename T10 = NullTypeList,
|
typename T10 = NullTypeList,
|
||||||
typename T11 = NullTypeList,
|
typename T11 = NullTypeList,
|
||||||
typename T12 = NullTypeList,
|
typename T12 = NullTypeList,
|
||||||
typename T13 = NullTypeList,
|
typename T13 = NullTypeList,
|
||||||
typename T14 = NullTypeList,
|
typename T14 = NullTypeList,
|
||||||
typename T15 = NullTypeList,
|
typename T15 = NullTypeList,
|
||||||
typename T16 = NullTypeList,
|
typename T16 = NullTypeList,
|
||||||
typename T17 = NullTypeList,
|
typename T17 = NullTypeList,
|
||||||
typename T18 = NullTypeList,
|
typename T18 = NullTypeList,
|
||||||
typename T19 = NullTypeList>
|
typename T19 = NullTypeList>
|
||||||
struct TypeListType
|
struct TypeListType
|
||||||
/// TypeListType takes 1 - 20 typename arguments.
|
/// TypeListType takes 1 - 20 typename arguments.
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// TypeListType<T0, T1, ... , Tn>::HeadType typeList;
|
/// TypeListType<T0, T1, ... , Tn>::HeadType typeList;
|
||||||
///
|
///
|
||||||
/// typeList is a TypeList of T0, T1, ... , Tn
|
/// typeList is a TypeList of T0, T1, ... , Tn
|
||||||
{
|
{
|
||||||
private:
|
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;
|
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:
|
public:
|
||||||
typedef TypeList<T0, TailType> HeadType;
|
typedef TypeList<T0, TailType> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct TypeListType<>
|
struct TypeListType<>
|
||||||
{
|
{
|
||||||
typedef NullTypeList HeadType;
|
typedef NullTypeList HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <int n>
|
template <int n>
|
||||||
struct Getter
|
struct Getter
|
||||||
{
|
{
|
||||||
template <class Ret, class Head, class Tail>
|
template <class Ret, class Head, class Tail>
|
||||||
inline static Ret& get(TypeList<Head, Tail>& val)
|
inline static Ret& get(TypeList<Head, Tail>& val)
|
||||||
{
|
{
|
||||||
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
|
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Ret, class Head, class Tail>
|
template <class Ret, class Head, class Tail>
|
||||||
inline static const Ret& get(const TypeList<Head, Tail>& val)
|
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);
|
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Getter<0>
|
struct Getter<0>
|
||||||
{
|
{
|
||||||
template <class Ret, class Head, class Tail>
|
template <class Ret, class Head, class Tail>
|
||||||
inline static Ret& get(TypeList<Head, Tail>& val)
|
inline static Ret& get(TypeList<Head, Tail>& val)
|
||||||
{
|
{
|
||||||
return val.head;
|
return val.head;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Ret, class Head, class Tail>
|
template <class Ret, class Head, class Tail>
|
||||||
inline static const Ret& get(const TypeList<Head, Tail>& val)
|
inline static const Ret& get(const TypeList<Head, Tail>& val)
|
||||||
{
|
{
|
||||||
return val.head;
|
return val.head;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <int N, class Head>
|
template <int N, class Head>
|
||||||
struct TypeGetter;
|
struct TypeGetter;
|
||||||
|
|
||||||
|
|
||||||
template <int N, class Head, class Tail>
|
template <int N, class Head, class Tail>
|
||||||
struct TypeGetter<N, TypeList<Head, Tail> >
|
struct TypeGetter<N, TypeList<Head, Tail> >
|
||||||
{
|
{
|
||||||
typedef typename TypeGetter<N-1, Tail>::HeadType HeadType;
|
typedef typename TypeGetter<N-1, Tail>::HeadType HeadType;
|
||||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail>
|
template <class Head, class Tail>
|
||||||
struct TypeGetter<0, TypeList<Head, Tail> >
|
struct TypeGetter<0, TypeList<Head, Tail> >
|
||||||
{
|
{
|
||||||
typedef typename TypeList<Head, Tail>::HeadType HeadType;
|
typedef typename TypeList<Head, Tail>::HeadType HeadType;
|
||||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class T>
|
template <class Head, class T>
|
||||||
struct TypeLocator;
|
struct TypeLocator;
|
||||||
/// TypeLocator returns the first occurrence of the type T in Head
|
/// TypeLocator returns the first occurrence of the type T in Head
|
||||||
/// or -1 if the type is not found.
|
/// or -1 if the type is not found.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
///
|
///
|
||||||
/// TypeLocator<Head, int>::HeadType TypeLoc;
|
/// TypeLocator<Head, int>::HeadType TypeLoc;
|
||||||
///
|
///
|
||||||
/// if (2 == TypeLoc.value) ...
|
/// if (2 == TypeLoc.value) ...
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct TypeLocator<NullTypeList, T>
|
struct TypeLocator<NullTypeList, T>
|
||||||
{
|
{
|
||||||
enum { value = -1 };
|
enum { value = -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T, class Tail>
|
template <class T, class Tail>
|
||||||
struct TypeLocator<TypeList<T, Tail>, T>
|
struct TypeLocator<TypeList<T, Tail>, T>
|
||||||
{
|
{
|
||||||
enum { value = 0 };
|
enum { value = 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail, class T>
|
template <class Head, class Tail, class T>
|
||||||
struct TypeLocator<TypeList<Head, Tail>, T>
|
struct TypeLocator<TypeList<Head, Tail>, T>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
enum { tmp = TypeLocator<Tail, T>::value };
|
enum { tmp = TypeLocator<Tail, T>::value };
|
||||||
public:
|
public:
|
||||||
enum { value = tmp == -1 ? -1 : 1 + tmp };
|
enum { value = tmp == -1 ? -1 : 1 + tmp };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class T>
|
template <class Head, class T>
|
||||||
struct TypeAppender;
|
struct TypeAppender;
|
||||||
/// TypeAppender appends T (type or a TypeList) to Head.
|
/// TypeAppender appends T (type or a TypeList) to Head.
|
||||||
///
|
///
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// typedef TypeListType<char>::HeadType Type1;
|
/// typedef TypeListType<char>::HeadType Type1;
|
||||||
/// typedef TypeAppender<Type1, int>::HeadType Type2;
|
/// typedef TypeAppender<Type1, int>::HeadType Type2;
|
||||||
/// (Type2 is a TypeList of char,int)
|
/// (Type2 is a TypeList of char,int)
|
||||||
///
|
///
|
||||||
/// typedef TypeListType<float, double>::HeadType Type3;
|
/// typedef TypeListType<float, double>::HeadType Type3;
|
||||||
/// typedef TypeAppender<Type2, Type3>::HeadType Type4;
|
/// typedef TypeAppender<Type2, Type3>::HeadType Type4;
|
||||||
/// (Type4 is a TypeList of char,int,float,double)
|
/// (Type4 is a TypeList of char,int,float,double)
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct TypeAppender<NullTypeList, NullTypeList>
|
struct TypeAppender<NullTypeList, NullTypeList>
|
||||||
{
|
{
|
||||||
typedef NullTypeList HeadType;
|
typedef NullTypeList HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct TypeAppender<NullTypeList, T>
|
struct TypeAppender<NullTypeList, T>
|
||||||
{
|
{
|
||||||
typedef TypeList<T, NullTypeList> HeadType;
|
typedef TypeList<T, NullTypeList> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail>
|
template <class Head, class Tail>
|
||||||
struct TypeAppender<NullTypeList, TypeList<Head, Tail> >
|
struct TypeAppender<NullTypeList, TypeList<Head, Tail> >
|
||||||
{
|
{
|
||||||
typedef TypeList<Head, Tail> HeadType;
|
typedef TypeList<Head, Tail> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail, class T>
|
template <class Head, class Tail, class T>
|
||||||
struct TypeAppender<TypeList<Head, Tail>, T>
|
struct TypeAppender<TypeList<Head, Tail>, T>
|
||||||
{
|
{
|
||||||
typedef TypeList<Head, typename TypeAppender<Tail, T>::HeadType> HeadType;
|
typedef TypeList<Head, typename TypeAppender<Tail, T>::HeadType> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class T>
|
template <class Head, class T>
|
||||||
struct TypeOneEraser;
|
struct TypeOneEraser;
|
||||||
/// TypeOneEraser erases the first occurence of the type T in Head.
|
/// TypeOneEraser erases the first occurence of the type T in Head.
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// typedef TypeListType<char, int, float>::HeadType Type3;
|
/// typedef TypeListType<char, int, float>::HeadType Type3;
|
||||||
/// typedef TypeOneEraser<Type3, int>::HeadType Type2;
|
/// typedef TypeOneEraser<Type3, int>::HeadType Type2;
|
||||||
/// (Type2 is a TypeList of char,float)
|
/// (Type2 is a TypeList of char,float)
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct TypeOneEraser<NullTypeList, T>
|
struct TypeOneEraser<NullTypeList, T>
|
||||||
{
|
{
|
||||||
typedef NullTypeList HeadType;
|
typedef NullTypeList HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T, class Tail>
|
template <class T, class Tail>
|
||||||
struct TypeOneEraser<TypeList<T, Tail>, T>
|
struct TypeOneEraser<TypeList<T, Tail>, T>
|
||||||
{
|
{
|
||||||
typedef Tail HeadType;
|
typedef Tail HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail, class T>
|
template <class Head, class Tail, class T>
|
||||||
struct TypeOneEraser<TypeList<Head, Tail>, T>
|
struct TypeOneEraser<TypeList<Head, Tail>, T>
|
||||||
{
|
{
|
||||||
typedef TypeList <Head, typename TypeOneEraser<Tail, T>::HeadType> HeadType;
|
typedef TypeList <Head, typename TypeOneEraser<Tail, T>::HeadType> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class T>
|
template <class Head, class T>
|
||||||
struct TypeAllEraser;
|
struct TypeAllEraser;
|
||||||
/// TypeAllEraser erases all the occurences of the type T in Head.
|
/// TypeAllEraser erases all the occurences of the type T in Head.
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||||
/// typedef TypeAllEraser<Type4, int>::HeadType Type2;
|
/// typedef TypeAllEraser<Type4, int>::HeadType Type2;
|
||||||
/// (Type2 is a TypeList of char,float)
|
/// (Type2 is a TypeList of char,float)
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct TypeAllEraser<NullTypeList, T>
|
struct TypeAllEraser<NullTypeList, T>
|
||||||
{
|
{
|
||||||
typedef NullTypeList HeadType;
|
typedef NullTypeList HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T, class Tail>
|
template <class T, class Tail>
|
||||||
struct TypeAllEraser<TypeList<T, Tail>, T>
|
struct TypeAllEraser<TypeList<T, Tail>, T>
|
||||||
{
|
{
|
||||||
typedef typename TypeAllEraser<Tail, T>::HeadType HeadType;
|
typedef typename TypeAllEraser<Tail, T>::HeadType HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail, class T>
|
template <class Head, class Tail, class T>
|
||||||
struct TypeAllEraser<TypeList<Head, Tail>, T>
|
struct TypeAllEraser<TypeList<Head, Tail>, T>
|
||||||
{
|
{
|
||||||
typedef TypeList <Head, typename TypeAllEraser<Tail, T>::HeadType> HeadType;
|
typedef TypeList <Head, typename TypeAllEraser<Tail, T>::HeadType> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head>
|
template <class Head>
|
||||||
struct TypeDuplicateEraser;
|
struct TypeDuplicateEraser;
|
||||||
/// TypeDuplicateEraser erases all but the first occurence of the type T in Head.
|
/// TypeDuplicateEraser erases all but the first occurence of the type T in Head.
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||||
/// typedef TypeDuplicateEraser<Type4, int>::HeadType Type3;
|
/// typedef TypeDuplicateEraser<Type4, int>::HeadType Type3;
|
||||||
/// (Type3 is a TypeList of char,int,float)
|
/// (Type3 is a TypeList of char,int,float)
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct TypeDuplicateEraser<NullTypeList>
|
struct TypeDuplicateEraser<NullTypeList>
|
||||||
{
|
{
|
||||||
typedef NullTypeList HeadType;
|
typedef NullTypeList HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail>
|
template <class Head, class Tail>
|
||||||
struct TypeDuplicateEraser<TypeList<Head, Tail> >
|
struct TypeDuplicateEraser<TypeList<Head, Tail> >
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef typename TypeDuplicateEraser<Tail>::HeadType L1;
|
typedef typename TypeDuplicateEraser<Tail>::HeadType L1;
|
||||||
typedef typename TypeOneEraser<L1, Head>::HeadType L2;
|
typedef typename TypeOneEraser<L1, Head>::HeadType L2;
|
||||||
public:
|
public:
|
||||||
typedef TypeList<Head, L2> HeadType;
|
typedef TypeList<Head, L2> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class T, class R>
|
template <class Head, class T, class R>
|
||||||
struct TypeOneReplacer;
|
struct TypeOneReplacer;
|
||||||
/// TypeOneReplacer replaces the first occurence
|
/// TypeOneReplacer replaces the first occurence
|
||||||
/// of the type T in Head with type R.
|
/// of the type T in Head with type R.
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||||
/// typedef TypeOneReplacer<Type4, int, double>::HeadType TypeR;
|
/// typedef TypeOneReplacer<Type4, int, double>::HeadType TypeR;
|
||||||
/// (TypeR is a TypeList of char,double,float,int)
|
/// (TypeR is a TypeList of char,double,float,int)
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
template <class T, class R>
|
template <class T, class R>
|
||||||
struct TypeOneReplacer<NullTypeList, T, R>
|
struct TypeOneReplacer<NullTypeList, T, R>
|
||||||
{
|
{
|
||||||
typedef NullTypeList HeadType;
|
typedef NullTypeList HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T, class Tail, class R>
|
template <class T, class Tail, class R>
|
||||||
struct TypeOneReplacer<TypeList<T, Tail>, T, R>
|
struct TypeOneReplacer<TypeList<T, Tail>, T, R>
|
||||||
{
|
{
|
||||||
typedef TypeList<R, Tail> HeadType;
|
typedef TypeList<R, Tail> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail, class T, class R>
|
template <class Head, class Tail, class T, class R>
|
||||||
struct TypeOneReplacer<TypeList<Head, Tail>, T, R>
|
struct TypeOneReplacer<TypeList<Head, Tail>, T, R>
|
||||||
{
|
{
|
||||||
typedef TypeList<Head, typename TypeOneReplacer<Tail, T, R>::HeadType> HeadType;
|
typedef TypeList<Head, typename TypeOneReplacer<Tail, T, R>::HeadType> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class T, class R>
|
template <class Head, class T, class R>
|
||||||
struct TypeAllReplacer;
|
struct TypeAllReplacer;
|
||||||
/// TypeAllReplacer replaces all the occurences
|
/// TypeAllReplacer replaces all the occurences
|
||||||
/// of the type T in Head with type R.
|
/// of the type T in Head with type R.
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||||
/// typedef TypeAllReplacer<Type4, int, double>::HeadType TypeR;
|
/// typedef TypeAllReplacer<Type4, int, double>::HeadType TypeR;
|
||||||
/// (TypeR is a TypeList of char,double,float,double)
|
/// (TypeR is a TypeList of char,double,float,double)
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
template <class T, class R>
|
template <class T, class R>
|
||||||
struct TypeAllReplacer<NullTypeList, T, R>
|
struct TypeAllReplacer<NullTypeList, T, R>
|
||||||
{
|
{
|
||||||
typedef NullTypeList HeadType;
|
typedef NullTypeList HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T, class Tail, class R>
|
template <class T, class Tail, class R>
|
||||||
struct TypeAllReplacer<TypeList<T, Tail>, T, R>
|
struct TypeAllReplacer<TypeList<T, Tail>, T, R>
|
||||||
{
|
{
|
||||||
typedef TypeList<R, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
|
typedef TypeList<R, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Head, class Tail, class T, class R>
|
template <class Head, class Tail, class T, class R>
|
||||||
struct TypeAllReplacer<TypeList<Head, Tail>, T, R>
|
struct TypeAllReplacer<TypeList<Head, Tail>, T, R>
|
||||||
{
|
{
|
||||||
typedef TypeList<Head, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
|
typedef TypeList<Head, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,80 +1,80 @@
|
|||||||
//
|
//
|
||||||
// UTF8String.h
|
// UTF8String.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/UTF8String.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/UTF8String.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Text
|
// Package: Text
|
||||||
// Module: UTF8String
|
// Module: UTF8String
|
||||||
//
|
//
|
||||||
// Definition of the UTF8 string functions.
|
// Definition of the UTF8 string functions.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_UTF8String_INCLUDED
|
#ifndef Foundation_UTF8String_INCLUDED
|
||||||
#define Foundation_UTF8String_INCLUDED
|
#define Foundation_UTF8String_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
struct Foundation_API UTF8
|
struct Foundation_API UTF8
|
||||||
/// This class provides static methods that are UTF-8 capable variants
|
/// This class provides static methods that are UTF-8 capable variants
|
||||||
/// of the same functions in Poco/String.h.
|
/// of the same functions in Poco/String.h.
|
||||||
///
|
///
|
||||||
/// The various variants of icompare() provide case insensitive comparison
|
/// The various variants of icompare() provide case insensitive comparison
|
||||||
/// for UTF-8 encoded strings.
|
/// for UTF-8 encoded strings.
|
||||||
///
|
///
|
||||||
/// toUpper(), toUpperInPlace(), toLower() and toLowerInPlace() provide
|
/// toUpper(), toUpperInPlace(), toLower() and toLowerInPlace() provide
|
||||||
/// Unicode-based character case transformation for UTF-8 encoded strings.
|
/// 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& 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, 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 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 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 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 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& 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, 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, 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 int icompare(const std::string& str, const std::string::value_type* ptr);
|
||||||
|
|
||||||
static std::string toUpper(const std::string& str);
|
static std::string toUpper(const std::string& str);
|
||||||
static std::string& toUpperInPlace(std::string& str);
|
static std::string& toUpperInPlace(std::string& str);
|
||||||
static std::string toLower(const std::string& str);
|
static std::string toLower(const std::string& str);
|
||||||
static std::string& toLowerInPlace(std::string& str);
|
static std::string& toLowerInPlace(std::string& str);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_UTF8String_INCLUDED
|
#endif // Foundation_UTF8String_INCLUDED
|
||||||
|
|||||||
@@ -1,110 +1,110 @@
|
|||||||
//
|
//
|
||||||
// UnWindows.h
|
// UnWindows.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/UnWindows.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/UnWindows.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: UnWindows
|
// Module: UnWindows
|
||||||
//
|
//
|
||||||
// A wrapper around the "Poco/UnWindows.h" header file that #undef's some
|
// 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
|
// of the macros for function names defined by "Poco/UnWindows.h" that
|
||||||
// are a frequent source of conflicts (e.g., GetUserName).
|
// are a frequent source of conflicts (e.g., GetUserName).
|
||||||
//
|
//
|
||||||
// Remember, that most of the WIN32 API functions come in two variants,
|
// Remember, that most of the WIN32 API functions come in two variants,
|
||||||
// an Unicode variant (e.g., GetUserNameA) and an ASCII variant (GetUserNameW).
|
// 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
|
// 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
|
// 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
|
// 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.
|
// 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,
|
// 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
|
// 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
|
// 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.
|
// 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
|
// 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
|
// of the users of POCO might use a different naming convention where this can become
|
||||||
// a problem.
|
// a problem.
|
||||||
//
|
//
|
||||||
// To disable the #undef's, compile POCO with the POCO_NO_UNWINDOWS macro #define'd.
|
// To disable the #undef's, compile POCO with the POCO_NO_UNWINDOWS macro #define'd.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
|
||||||
#if !defined(POCO_NO_UNWINDOWS)
|
#if !defined(POCO_NO_UNWINDOWS)
|
||||||
// A list of annoying macros to #undef.
|
// A list of annoying macros to #undef.
|
||||||
// Feel free to extend as required.
|
// Feel free to extend as required.
|
||||||
#undef GetBinaryType
|
#undef GetBinaryType
|
||||||
#undef GetShortPathName
|
#undef GetShortPathName
|
||||||
#undef GetLongPathName
|
#undef GetLongPathName
|
||||||
#undef GetEnvironmentStrings
|
#undef GetEnvironmentStrings
|
||||||
#undef SetEnvironmentStrings
|
#undef SetEnvironmentStrings
|
||||||
#undef FreeEnvironmentStrings
|
#undef FreeEnvironmentStrings
|
||||||
#undef FormatMessage
|
#undef FormatMessage
|
||||||
#undef EncryptFile
|
#undef EncryptFile
|
||||||
#undef DecryptFile
|
#undef DecryptFile
|
||||||
#undef CreateMutex
|
#undef CreateMutex
|
||||||
#undef OpenMutex
|
#undef OpenMutex
|
||||||
#undef CreateEvent
|
#undef CreateEvent
|
||||||
#undef OpenEvent
|
#undef OpenEvent
|
||||||
#undef CreateSemaphore
|
#undef CreateSemaphore
|
||||||
#undef OpenSemaphore
|
#undef OpenSemaphore
|
||||||
#undef LoadLibrary
|
#undef LoadLibrary
|
||||||
#undef GetModuleFileName
|
#undef GetModuleFileName
|
||||||
#undef CreateProcess
|
#undef CreateProcess
|
||||||
#undef GetCommandLine
|
#undef GetCommandLine
|
||||||
#undef GetEnvironmentVariable
|
#undef GetEnvironmentVariable
|
||||||
#undef SetEnvironmentVariable
|
#undef SetEnvironmentVariable
|
||||||
#undef ExpandEnvironmentStrings
|
#undef ExpandEnvironmentStrings
|
||||||
#undef OutputDebugString
|
#undef OutputDebugString
|
||||||
#undef FindResource
|
#undef FindResource
|
||||||
#undef UpdateResource
|
#undef UpdateResource
|
||||||
#undef FindAtom
|
#undef FindAtom
|
||||||
#undef AddAtom
|
#undef AddAtom
|
||||||
#undef GetSystemDirector
|
#undef GetSystemDirector
|
||||||
#undef GetTempPath
|
#undef GetTempPath
|
||||||
#undef GetTempFileName
|
#undef GetTempFileName
|
||||||
#undef SetCurrentDirectory
|
#undef SetCurrentDirectory
|
||||||
#undef GetCurrentDirectory
|
#undef GetCurrentDirectory
|
||||||
#undef CreateDirectory
|
#undef CreateDirectory
|
||||||
#undef RemoveDirectory
|
#undef RemoveDirectory
|
||||||
#undef CreateFile
|
#undef CreateFile
|
||||||
#undef DeleteFile
|
#undef DeleteFile
|
||||||
#undef SearchPath
|
#undef SearchPath
|
||||||
#undef CopyFile
|
#undef CopyFile
|
||||||
#undef MoveFile
|
#undef MoveFile
|
||||||
#undef ReplaceFile
|
#undef ReplaceFile
|
||||||
#undef GetComputerName
|
#undef GetComputerName
|
||||||
#undef SetComputerName
|
#undef SetComputerName
|
||||||
#undef GetUserName
|
#undef GetUserName
|
||||||
#undef LogonUser
|
#undef LogonUser
|
||||||
#undef GetVersion
|
#undef GetVersion
|
||||||
#undef GetObject
|
#undef GetObject
|
||||||
#endif // POCO_NO_UNWINDOWS
|
#endif // POCO_NO_UNWINDOWS
|
||||||
|
|||||||
@@ -1,216 +1,216 @@
|
|||||||
//
|
//
|
||||||
// Unicode.h
|
// Unicode.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/Unicode.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/Unicode.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Text
|
// Package: Text
|
||||||
// Module: Unicode
|
// Module: Unicode
|
||||||
//
|
//
|
||||||
// Definition of the Unicode class.
|
// Definition of the Unicode class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_Unicode_INCLUDED
|
#ifndef Foundation_Unicode_INCLUDED
|
||||||
#define Foundation_Unicode_INCLUDED
|
#define Foundation_Unicode_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API Unicode
|
class Foundation_API Unicode
|
||||||
/// This class contains enumerations and static
|
/// This class contains enumerations and static
|
||||||
/// utility functions for dealing with Unicode characters
|
/// utility functions for dealing with Unicode characters
|
||||||
/// and their properties.
|
/// and their properties.
|
||||||
///
|
///
|
||||||
/// For more information on Unicode, see <http://www.unicode.org>.
|
/// For more information on Unicode, see <http://www.unicode.org>.
|
||||||
///
|
///
|
||||||
/// The implementation is based on the Unicode support
|
/// The implementation is based on the Unicode support
|
||||||
/// functions in PCRE.
|
/// functions in PCRE.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Implementation note: the following definitions must be kept
|
// Implementation note: the following definitions must be kept
|
||||||
// in sync with those from ucp.h (PCRE).
|
// in sync with those from ucp.h (PCRE).
|
||||||
enum CharacterCategory
|
enum CharacterCategory
|
||||||
/// Unicode 5.0 character categories.
|
/// Unicode 5.0 character categories.
|
||||||
{
|
{
|
||||||
UCP_OTHER,
|
UCP_OTHER,
|
||||||
UCP_LETTER,
|
UCP_LETTER,
|
||||||
UCP_MARK,
|
UCP_MARK,
|
||||||
UCP_NUMBER,
|
UCP_NUMBER,
|
||||||
UCP_PUNCTUATION,
|
UCP_PUNCTUATION,
|
||||||
UCP_SYMBOL,
|
UCP_SYMBOL,
|
||||||
UCP_SEPARATOR
|
UCP_SEPARATOR
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CharacterType
|
enum CharacterType
|
||||||
/// Unicode 5.0 character types.
|
/// Unicode 5.0 character types.
|
||||||
{
|
{
|
||||||
UCP_CONTROL,
|
UCP_CONTROL,
|
||||||
UCP_FORMAT,
|
UCP_FORMAT,
|
||||||
UCP_UNASSIGNED,
|
UCP_UNASSIGNED,
|
||||||
UCP_PRIVATE_USE,
|
UCP_PRIVATE_USE,
|
||||||
UCP_SURROGATE,
|
UCP_SURROGATE,
|
||||||
UCP_LOWER_CASE_LETTER,
|
UCP_LOWER_CASE_LETTER,
|
||||||
UCP_MODIFIER_LETTER,
|
UCP_MODIFIER_LETTER,
|
||||||
UCP_OTHER_LETTER,
|
UCP_OTHER_LETTER,
|
||||||
UCP_TITLE_CASE_LETTER,
|
UCP_TITLE_CASE_LETTER,
|
||||||
UCP_UPPER_CASE_LETTER,
|
UCP_UPPER_CASE_LETTER,
|
||||||
UCP_SPACING_MARK,
|
UCP_SPACING_MARK,
|
||||||
UCP_ENCLOSING_MARK,
|
UCP_ENCLOSING_MARK,
|
||||||
UCP_NON_SPACING_MARK,
|
UCP_NON_SPACING_MARK,
|
||||||
UCP_DECIMAL_NUMBER,
|
UCP_DECIMAL_NUMBER,
|
||||||
UCP_LETTER_NUMBER,
|
UCP_LETTER_NUMBER,
|
||||||
UCP_OTHER_NUMBER,
|
UCP_OTHER_NUMBER,
|
||||||
UCP_CONNECTOR_PUNCTUATION,
|
UCP_CONNECTOR_PUNCTUATION,
|
||||||
UCP_DASH_PUNCTUATION,
|
UCP_DASH_PUNCTUATION,
|
||||||
UCP_CLOSE_PUNCTUATION,
|
UCP_CLOSE_PUNCTUATION,
|
||||||
UCP_FINAL_PUNCTUATION,
|
UCP_FINAL_PUNCTUATION,
|
||||||
UCP_INITIAL_PUNCTUATION,
|
UCP_INITIAL_PUNCTUATION,
|
||||||
UCP_OTHER_PUNCTUATION,
|
UCP_OTHER_PUNCTUATION,
|
||||||
UCP_OPEN_PUNCTUATION,
|
UCP_OPEN_PUNCTUATION,
|
||||||
UCP_CURRENCY_SYMBOL,
|
UCP_CURRENCY_SYMBOL,
|
||||||
UCP_MODIFIER_SYMBOL,
|
UCP_MODIFIER_SYMBOL,
|
||||||
UCP_MATHEMATICAL_SYMBOL,
|
UCP_MATHEMATICAL_SYMBOL,
|
||||||
UCP_OTHER_SYMBOL,
|
UCP_OTHER_SYMBOL,
|
||||||
UCP_LINE_SEPARATOR,
|
UCP_LINE_SEPARATOR,
|
||||||
UCP_PARAGRAPH_SEPARATOR,
|
UCP_PARAGRAPH_SEPARATOR,
|
||||||
UCP_SPACE_SEPARATOR
|
UCP_SPACE_SEPARATOR
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Script
|
enum Script
|
||||||
/// Unicode 5.0 scripts.
|
/// Unicode 5.0 scripts.
|
||||||
{
|
{
|
||||||
UCP_ARABIC,
|
UCP_ARABIC,
|
||||||
UCP_ARMENIAN,
|
UCP_ARMENIAN,
|
||||||
UCP_BENGALI,
|
UCP_BENGALI,
|
||||||
UCP_BOPOMOFO,
|
UCP_BOPOMOFO,
|
||||||
UCP_BRAILLE,
|
UCP_BRAILLE,
|
||||||
UCP_BUGINESE,
|
UCP_BUGINESE,
|
||||||
UCP_BUHID,
|
UCP_BUHID,
|
||||||
UCP_CANADIAN_ABORIGINAL,
|
UCP_CANADIAN_ABORIGINAL,
|
||||||
UCP_CHEROKEE,
|
UCP_CHEROKEE,
|
||||||
UCP_COMMON,
|
UCP_COMMON,
|
||||||
UCP_COPTIC,
|
UCP_COPTIC,
|
||||||
UCP_CYPRIOT,
|
UCP_CYPRIOT,
|
||||||
UCP_CYRILLIC,
|
UCP_CYRILLIC,
|
||||||
UCP_DESERET,
|
UCP_DESERET,
|
||||||
UCP_DEVANAGARI,
|
UCP_DEVANAGARI,
|
||||||
UCP_ETHIOPIC,
|
UCP_ETHIOPIC,
|
||||||
UCP_GEORGIAN,
|
UCP_GEORGIAN,
|
||||||
UCP_GLAGOLITIC,
|
UCP_GLAGOLITIC,
|
||||||
UCP_GOTHIC,
|
UCP_GOTHIC,
|
||||||
UCP_GREEK,
|
UCP_GREEK,
|
||||||
UCP_GUJARATI,
|
UCP_GUJARATI,
|
||||||
UCP_GURMUKHI,
|
UCP_GURMUKHI,
|
||||||
UCP_HAN,
|
UCP_HAN,
|
||||||
UCP_HANGUL,
|
UCP_HANGUL,
|
||||||
UCP_HANUNOO,
|
UCP_HANUNOO,
|
||||||
UCP_HEBREW,
|
UCP_HEBREW,
|
||||||
UCP_HIRAGANA,
|
UCP_HIRAGANA,
|
||||||
UCP_INHERITED,
|
UCP_INHERITED,
|
||||||
UCP_KANNADA,
|
UCP_KANNADA,
|
||||||
UCP_KATAKANA,
|
UCP_KATAKANA,
|
||||||
UCP_KHAROSHTHI,
|
UCP_KHAROSHTHI,
|
||||||
UCP_KHMER,
|
UCP_KHMER,
|
||||||
UCP_LAO,
|
UCP_LAO,
|
||||||
UCP_LATIN,
|
UCP_LATIN,
|
||||||
UCP_LIMBU,
|
UCP_LIMBU,
|
||||||
UCP_LINEAR_B,
|
UCP_LINEAR_B,
|
||||||
UCP_MALAYALAM,
|
UCP_MALAYALAM,
|
||||||
UCP_MONGOLIAN,
|
UCP_MONGOLIAN,
|
||||||
UCP_MYANMAR,
|
UCP_MYANMAR,
|
||||||
UCP_NEW_TAI_LUE,
|
UCP_NEW_TAI_LUE,
|
||||||
UCP_OGHAM,
|
UCP_OGHAM,
|
||||||
UCP_OLD_ITALIC,
|
UCP_OLD_ITALIC,
|
||||||
UCP_OLD_PERSIAN,
|
UCP_OLD_PERSIAN,
|
||||||
UCP_ORIYA,
|
UCP_ORIYA,
|
||||||
UCP_OSMANYA,
|
UCP_OSMANYA,
|
||||||
UCP_RUNIC,
|
UCP_RUNIC,
|
||||||
UCP_SHAVIAN,
|
UCP_SHAVIAN,
|
||||||
UCP_SINHALA,
|
UCP_SINHALA,
|
||||||
UCP_SYLOTI_NAGRI,
|
UCP_SYLOTI_NAGRI,
|
||||||
UCP_SYRIAC,
|
UCP_SYRIAC,
|
||||||
UCP_TAGALOG,
|
UCP_TAGALOG,
|
||||||
UCP_TAGBANWA,
|
UCP_TAGBANWA,
|
||||||
UCP_TAI_LE,
|
UCP_TAI_LE,
|
||||||
UCP_TAMIL,
|
UCP_TAMIL,
|
||||||
UCP_TELUGU,
|
UCP_TELUGU,
|
||||||
UCP_THAANA,
|
UCP_THAANA,
|
||||||
UCP_THAI,
|
UCP_THAI,
|
||||||
UCP_TIBETAN,
|
UCP_TIBETAN,
|
||||||
UCP_TIFINAGH,
|
UCP_TIFINAGH,
|
||||||
UCP_UGARITIC,
|
UCP_UGARITIC,
|
||||||
UCP_YI,
|
UCP_YI,
|
||||||
UCP_BALINESE,
|
UCP_BALINESE,
|
||||||
UCP_CUNEIFORM,
|
UCP_CUNEIFORM,
|
||||||
UCP_NKO,
|
UCP_NKO,
|
||||||
UCP_PHAGS_PA,
|
UCP_PHAGS_PA,
|
||||||
UCP_PHOENICIAN
|
UCP_PHOENICIAN
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CharacterProperties
|
struct CharacterProperties
|
||||||
/// This structure holds the character properties
|
/// This structure holds the character properties
|
||||||
/// of an Unicode character.
|
/// of an Unicode character.
|
||||||
{
|
{
|
||||||
CharacterCategory category;
|
CharacterCategory category;
|
||||||
CharacterType type;
|
CharacterType type;
|
||||||
Script script;
|
Script script;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void properties(int ch, CharacterProperties& props);
|
static void properties(int ch, CharacterProperties& props);
|
||||||
/// Return the Unicode character properties for the
|
/// Return the Unicode character properties for the
|
||||||
/// character with the given Unicode value.
|
/// character with the given Unicode value.
|
||||||
|
|
||||||
static bool isLower(int ch);
|
static bool isLower(int ch);
|
||||||
/// Returns true iff the given character is a lowercase
|
/// Returns true iff the given character is a lowercase
|
||||||
/// character.
|
/// character.
|
||||||
|
|
||||||
static bool isUpper(int ch);
|
static bool isUpper(int ch);
|
||||||
/// Returns true iff the given character is an uppercase
|
/// Returns true iff the given character is an uppercase
|
||||||
/// character.
|
/// character.
|
||||||
|
|
||||||
static int toLower(int ch);
|
static int toLower(int ch);
|
||||||
/// If the given character is an uppercase character,
|
/// If the given character is an uppercase character,
|
||||||
/// return its lowercase counterpart, otherwise return
|
/// return its lowercase counterpart, otherwise return
|
||||||
/// the character.
|
/// the character.
|
||||||
|
|
||||||
static int toUpper(int ch);
|
static int toUpper(int ch);
|
||||||
/// If the given character is a lowercase character,
|
/// If the given character is a lowercase character,
|
||||||
/// return its uppercase counterpart, otherwise return
|
/// return its uppercase counterpart, otherwise return
|
||||||
/// the character.
|
/// the character.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_Unicode_INCLUDED
|
#endif // Foundation_Unicode_INCLUDED
|
||||||
|
|||||||
@@ -1,89 +1,89 @@
|
|||||||
//
|
//
|
||||||
// UniqueAccessExpireCache.h
|
// UniqueAccessExpireCache.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireCache.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireCache.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: UniqueAccessExpireCache
|
// Module: UniqueAccessExpireCache
|
||||||
//
|
//
|
||||||
// Definition of the UniqueAccessExpireCache class.
|
// Definition of the UniqueAccessExpireCache class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_UniqueAccessExpireCache_INCLUDED
|
#ifndef Foundation_UniqueAccessExpireCache_INCLUDED
|
||||||
#define Foundation_UniqueAccessExpireCache_INCLUDED
|
#define Foundation_UniqueAccessExpireCache_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AbstractCache.h"
|
#include "Poco/AbstractCache.h"
|
||||||
#include "Poco/UniqueAccessExpireStrategy.h"
|
#include "Poco/UniqueAccessExpireStrategy.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class TKey, class TValue>
|
template <class TKey, class TValue>
|
||||||
class UniqueAccessExpireCache: public AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >
|
class UniqueAccessExpireCache: public AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >
|
||||||
/// An UniqueAccessExpireCache caches entries for a given time span. In contrast
|
/// 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
|
/// to ExpireCache which only allows to set a per cache expiration value, it allows to define
|
||||||
/// expiration per CacheEntry.
|
/// expiration per CacheEntry.
|
||||||
/// Each TValue object must thus offer the following method:
|
/// Each TValue object must thus offer the following method:
|
||||||
///
|
///
|
||||||
/// const Poco::Timespan& getTimeout() const;
|
/// const Poco::Timespan& getTimeout() const;
|
||||||
///
|
///
|
||||||
/// which returns the relative timespan for how long the entry should be valid without being accessed!
|
/// 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().
|
/// The absolute expire timepoint is calculated as now() + getTimeout().
|
||||||
/// Accessing an object will update this absolute expire timepoint.
|
/// Accessing an object will update this absolute expire timepoint.
|
||||||
/// You can use the Poco::AccessExpirationDecorator to add the getExpiration
|
/// You can use the Poco::AccessExpirationDecorator to add the getExpiration
|
||||||
/// method to values that do not have a getExpiration function.
|
/// method to values that do not have a getExpiration function.
|
||||||
///
|
///
|
||||||
/// Be careful when using an UniqueAccessExpireCache. A cache is often used
|
/// 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
|
/// 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,
|
/// 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
|
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||||
/// when "get" is invoked.
|
/// when "get" is invoked.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniqueAccessExpireCache():
|
UniqueAccessExpireCache():
|
||||||
AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >(UniqueAccessExpireStrategy<TKey, TValue>())
|
AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >(UniqueAccessExpireStrategy<TKey, TValue>())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~UniqueAccessExpireCache()
|
~UniqueAccessExpireCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache);
|
UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache);
|
||||||
UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache);
|
UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,91 +1,91 @@
|
|||||||
//
|
//
|
||||||
// UniqueAccessExpireLRUCache.h
|
// UniqueAccessExpireLRUCache.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireLRUCache.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireLRUCache.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: UniqueAccessExpireLRUCache
|
// Module: UniqueAccessExpireLRUCache
|
||||||
//
|
//
|
||||||
// Definition of the UniqueAccessExpireLRUCache class.
|
// Definition of the UniqueAccessExpireLRUCache class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_UniqueAccessExpireLRUCache_INCLUDED
|
#ifndef Foundation_UniqueAccessExpireLRUCache_INCLUDED
|
||||||
#define Foundation_UniqueAccessExpireLRUCache_INCLUDED
|
#define Foundation_UniqueAccessExpireLRUCache_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AbstractCache.h"
|
#include "Poco/AbstractCache.h"
|
||||||
#include "Poco/StrategyCollection.h"
|
#include "Poco/StrategyCollection.h"
|
||||||
#include "Poco/UniqueAccessExpireStrategy.h"
|
#include "Poco/UniqueAccessExpireStrategy.h"
|
||||||
#include "Poco/LRUStrategy.h"
|
#include "Poco/LRUStrategy.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class TKey,
|
class TKey,
|
||||||
class TValue
|
class TValue
|
||||||
>
|
>
|
||||||
class UniqueAccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
class UniqueAccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||||
/// A UniqueAccessExpireLRUCache combines LRU caching and time based per entry expire caching.
|
/// A UniqueAccessExpireLRUCache combines LRU caching and time based per entry expire caching.
|
||||||
/// One can define for each cache entry a seperate timepoint
|
/// One can define for each cache entry a seperate timepoint
|
||||||
/// but also limit the size of the cache (per default: 1024).
|
/// but also limit the size of the cache (per default: 1024).
|
||||||
/// Each TValue object must thus offer the following method:
|
/// Each TValue object must thus offer the following method:
|
||||||
///
|
///
|
||||||
/// const Poco::Timespan& getTimeout() const;
|
/// const Poco::Timespan& getTimeout() const;
|
||||||
///
|
///
|
||||||
/// which returns the relative timespan for how long the entry should be valid without being accessed!
|
/// 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().
|
/// The absolute expire timepoint is calculated as now() + getTimeout().
|
||||||
/// Accessing an object will update this absolute expire timepoint.
|
/// Accessing an object will update this absolute expire timepoint.
|
||||||
/// You can use the Poco::AccessExpirationDecorator to add the getExpiration
|
/// You can use the Poco::AccessExpirationDecorator to add the getExpiration
|
||||||
/// method to values that do not have a getExpiration function.
|
/// method to values that do not have a getExpiration function.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniqueAccessExpireLRUCache(long cacheSize = 1024):
|
UniqueAccessExpireLRUCache(long cacheSize = 1024):
|
||||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||||
{
|
{
|
||||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||||
this->_strategy.pushBack(new UniqueAccessExpireStrategy<TKey, TValue>());
|
this->_strategy.pushBack(new UniqueAccessExpireStrategy<TKey, TValue>());
|
||||||
}
|
}
|
||||||
|
|
||||||
~UniqueAccessExpireLRUCache()
|
~UniqueAccessExpireLRUCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache);
|
UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache);
|
||||||
UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache);
|
UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,178 +1,178 @@
|
|||||||
//
|
//
|
||||||
// UniqueAccessExpireStrategy.h
|
// UniqueAccessExpireStrategy.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireStrategy.h#3 $
|
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireStrategy.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: UniqueAccessExpireStrategy
|
// Module: UniqueAccessExpireStrategy
|
||||||
//
|
//
|
||||||
// Definition of the UniqueAccessExpireStrategy class.
|
// Definition of the UniqueAccessExpireStrategy class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_UniqueAccessExpireStrategy_INCLUDED
|
#ifndef Foundation_UniqueAccessExpireStrategy_INCLUDED
|
||||||
#define Foundation_UniqueAccessExpireStrategy_INCLUDED
|
#define Foundation_UniqueAccessExpireStrategy_INCLUDED
|
||||||
|
|
||||||
#include "Poco/KeyValueArgs.h"
|
#include "Poco/KeyValueArgs.h"
|
||||||
#include "Poco/ValidArgs.h"
|
#include "Poco/ValidArgs.h"
|
||||||
#include "Poco/AbstractStrategy.h"
|
#include "Poco/AbstractStrategy.h"
|
||||||
#include "Poco/Bugcheck.h"
|
#include "Poco/Bugcheck.h"
|
||||||
#include "Poco/Timestamp.h"
|
#include "Poco/Timestamp.h"
|
||||||
#include "Poco/Timespan.h"
|
#include "Poco/Timespan.h"
|
||||||
#include "Poco/EventArgs.h"
|
#include "Poco/EventArgs.h"
|
||||||
#include "Poco/UniqueExpireStrategy.h"
|
#include "Poco/UniqueExpireStrategy.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class TKey,
|
class TKey,
|
||||||
class TValue
|
class TValue
|
||||||
>
|
>
|
||||||
class UniqueAccessExpireStrategy: public AbstractStrategy<TKey, TValue>
|
class UniqueAccessExpireStrategy: public AbstractStrategy<TKey, TValue>
|
||||||
/// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast
|
/// 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
|
/// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define
|
||||||
/// expiration per CacheEntry.
|
/// expiration per CacheEntry.
|
||||||
/// Each TValue object must thus offer the following method:
|
/// Each TValue object must thus offer the following method:
|
||||||
///
|
///
|
||||||
/// const Poco::Timestamp& getTimeout() const;
|
/// const Poco::Timestamp& getTimeout() const;
|
||||||
///
|
///
|
||||||
/// which returns the timespan for how long an object will be valid without being accessed.
|
/// which returns the timespan for how long an object will be valid without being accessed.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::pair<TKey, Timespan> KeyExpire;
|
typedef std::pair<TKey, Timespan> KeyExpire;
|
||||||
typedef std::multimap<Timestamp, KeyExpire> TimeIndex;
|
typedef std::multimap<Timestamp, KeyExpire> TimeIndex;
|
||||||
typedef typename TimeIndex::iterator IndexIterator;
|
typedef typename TimeIndex::iterator IndexIterator;
|
||||||
typedef typename TimeIndex::const_iterator ConstIndexIterator;
|
typedef typename TimeIndex::const_iterator ConstIndexIterator;
|
||||||
typedef std::map<TKey, IndexIterator> Keys;
|
typedef std::map<TKey, IndexIterator> Keys;
|
||||||
typedef typename Keys::iterator Iterator;
|
typedef typename Keys::iterator Iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UniqueAccessExpireStrategy()
|
UniqueAccessExpireStrategy()
|
||||||
/// Create an unique expire strategy.
|
/// Create an unique expire strategy.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~UniqueAccessExpireStrategy()
|
~UniqueAccessExpireStrategy()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& args)
|
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& args)
|
||||||
{
|
{
|
||||||
// the expire value defines how many millisecs in the future the
|
// the expire value defines how many millisecs in the future the
|
||||||
// value will expire, even insert negative values!
|
// value will expire, even insert negative values!
|
||||||
Timestamp expire;
|
Timestamp expire;
|
||||||
expire += args.value().getTimeout().totalMicroseconds();
|
expire += args.value().getTimeout().totalMicroseconds();
|
||||||
|
|
||||||
IndexIterator it = _keyIndex.insert(std::make_pair(expire, std::make_pair(args.key(), args.value().getTimeout())));
|
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));
|
std::pair<Iterator, bool> stat = _keys.insert(std::make_pair(args.key(), it));
|
||||||
if (!stat.second)
|
if (!stat.second)
|
||||||
{
|
{
|
||||||
_keyIndex.erase(stat.first->second);
|
_keyIndex.erase(stat.first->second);
|
||||||
stat.first->second = it;
|
stat.first->second = it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRemove(const void*, const TKey& key)
|
void onRemove(const void*, const TKey& key)
|
||||||
{
|
{
|
||||||
Iterator it = _keys.find(key);
|
Iterator it = _keys.find(key);
|
||||||
if (it != _keys.end())
|
if (it != _keys.end())
|
||||||
{
|
{
|
||||||
_keyIndex.erase(it->second);
|
_keyIndex.erase(it->second);
|
||||||
_keys.erase(it);
|
_keys.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onGet(const void*, const TKey& key)
|
void onGet(const void*, const TKey& key)
|
||||||
{
|
{
|
||||||
// get updates the expiration time stamp
|
// get updates the expiration time stamp
|
||||||
Iterator it = _keys.find(key);
|
Iterator it = _keys.find(key);
|
||||||
if (it != _keys.end())
|
if (it != _keys.end())
|
||||||
{
|
{
|
||||||
KeyExpire ke = it->second->second;
|
KeyExpire ke = it->second->second;
|
||||||
// gen new absolute expire value
|
// gen new absolute expire value
|
||||||
Timestamp expire;
|
Timestamp expire;
|
||||||
expire += ke.second.totalMicroseconds();
|
expire += ke.second.totalMicroseconds();
|
||||||
// delete old index
|
// delete old index
|
||||||
_keyIndex.erase(it->second);
|
_keyIndex.erase(it->second);
|
||||||
IndexIterator itt = _keyIndex.insert(std::make_pair(expire, ke));
|
IndexIterator itt = _keyIndex.insert(std::make_pair(expire, ke));
|
||||||
// update iterator
|
// update iterator
|
||||||
it->second = itt;
|
it->second = itt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onClear(const void*, const EventArgs& args)
|
void onClear(const void*, const EventArgs& args)
|
||||||
{
|
{
|
||||||
_keys.clear();
|
_keys.clear();
|
||||||
_keyIndex.clear();
|
_keyIndex.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onIsValid(const void*, ValidArgs<TKey>& args)
|
void onIsValid(const void*, ValidArgs<TKey>& args)
|
||||||
{
|
{
|
||||||
Iterator it = _keys.find(args.key());
|
Iterator it = _keys.find(args.key());
|
||||||
if (it != _keys.end())
|
if (it != _keys.end())
|
||||||
{
|
{
|
||||||
Timestamp now;
|
Timestamp now;
|
||||||
if (it->second->first <= now)
|
if (it->second->first <= now)
|
||||||
{
|
{
|
||||||
args.invalidate();
|
args.invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //not found: probably removed by onReplace
|
else //not found: probably removed by onReplace
|
||||||
args.invalidate();
|
args.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||||
{
|
{
|
||||||
// Note: replace only informs the cache which elements
|
// Note: replace only informs the cache which elements
|
||||||
// it would like to remove!
|
// it would like to remove!
|
||||||
// it does not remove them on its own!
|
// it does not remove them on its own!
|
||||||
IndexIterator it = _keyIndex.begin();
|
IndexIterator it = _keyIndex.begin();
|
||||||
Timestamp now;
|
Timestamp now;
|
||||||
while (it != _keyIndex.end() && it->first < now)
|
while (it != _keyIndex.end() && it->first < now)
|
||||||
{
|
{
|
||||||
elemsToRemove.insert(it->second.first);
|
elemsToRemove.insert(it->second.first);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map
|
Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map
|
||||||
TimeIndex _keyIndex; /// Maps time to key value
|
TimeIndex _keyIndex; /// Maps time to key value
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,89 +1,89 @@
|
|||||||
//
|
//
|
||||||
// UniqueExpireCache.h
|
// UniqueExpireCache.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireCache.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireCache.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: UniqueExpireCache
|
// Module: UniqueExpireCache
|
||||||
//
|
//
|
||||||
// Definition of the UniqueExpireCache class.
|
// Definition of the UniqueExpireCache class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_UniqueExpireCache_INCLUDED
|
#ifndef Foundation_UniqueExpireCache_INCLUDED
|
||||||
#define Foundation_UniqueExpireCache_INCLUDED
|
#define Foundation_UniqueExpireCache_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AbstractCache.h"
|
#include "Poco/AbstractCache.h"
|
||||||
#include "Poco/UniqueExpireStrategy.h"
|
#include "Poco/UniqueExpireStrategy.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <class TKey, class TValue>
|
template <class TKey, class TValue>
|
||||||
class UniqueExpireCache: public AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >
|
class UniqueExpireCache: public AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >
|
||||||
/// An UniqueExpireCache caches entries for a given time amount. In contrast
|
/// 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
|
/// to ExpireCache which only allows to set a per cache expiration value, it allows to define
|
||||||
/// expiration per CacheEntry.
|
/// expiration per CacheEntry.
|
||||||
/// Each TValue object must thus offer the following method:
|
/// Each TValue object must thus offer the following method:
|
||||||
///
|
///
|
||||||
/// const Poco::Timestamp& getExpiration() const;
|
/// const Poco::Timestamp& getExpiration() const;
|
||||||
///
|
///
|
||||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||||
/// Accessing an object will NOT update this absolute expire timepoint.
|
/// Accessing an object will NOT update this absolute expire timepoint.
|
||||||
/// You can use the Poco::ExpirationDecorator to add the getExpiration
|
/// You can use the Poco::ExpirationDecorator to add the getExpiration
|
||||||
/// method to values that do not have a getExpiration function.
|
/// method to values that do not have a getExpiration function.
|
||||||
///
|
///
|
||||||
/// Be careful when using an UniqueExpireCache. A cache is often used
|
/// 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
|
/// 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,
|
/// 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
|
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||||
/// when "get" is invoked.
|
/// when "get" is invoked.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniqueExpireCache():
|
UniqueExpireCache():
|
||||||
AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >(UniqueExpireStrategy<TKey, TValue>())
|
AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >(UniqueExpireStrategy<TKey, TValue>())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~UniqueExpireCache()
|
~UniqueExpireCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UniqueExpireCache(const UniqueExpireCache& aCache);
|
UniqueExpireCache(const UniqueExpireCache& aCache);
|
||||||
UniqueExpireCache& operator = (const UniqueExpireCache& aCache);
|
UniqueExpireCache& operator = (const UniqueExpireCache& aCache);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,90 +1,90 @@
|
|||||||
//
|
//
|
||||||
// UniqueExpireLRUCache.h
|
// UniqueExpireLRUCache.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireLRUCache.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireLRUCache.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: UniqueExpireLRUCache
|
// Module: UniqueExpireLRUCache
|
||||||
//
|
//
|
||||||
// Definition of the UniqueExpireLRUCache class.
|
// Definition of the UniqueExpireLRUCache class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_UniqueExpireLRUCache_INCLUDED
|
#ifndef Foundation_UniqueExpireLRUCache_INCLUDED
|
||||||
#define Foundation_UniqueExpireLRUCache_INCLUDED
|
#define Foundation_UniqueExpireLRUCache_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AbstractCache.h"
|
#include "Poco/AbstractCache.h"
|
||||||
#include "Poco/StrategyCollection.h"
|
#include "Poco/StrategyCollection.h"
|
||||||
#include "Poco/UniqueExpireStrategy.h"
|
#include "Poco/UniqueExpireStrategy.h"
|
||||||
#include "Poco/LRUStrategy.h"
|
#include "Poco/LRUStrategy.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class TKey,
|
class TKey,
|
||||||
class TValue
|
class TValue
|
||||||
>
|
>
|
||||||
class UniqueExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
class UniqueExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||||
/// A UniqueExpireLRUCache combines LRU caching and time based per entry expire caching.
|
/// A UniqueExpireLRUCache combines LRU caching and time based per entry expire caching.
|
||||||
/// One can define for each cache entry a seperate timepoint
|
/// One can define for each cache entry a seperate timepoint
|
||||||
/// but also limit the size of the cache (per default: 1024).
|
/// but also limit the size of the cache (per default: 1024).
|
||||||
/// Each TValue object must thus offer the following method:
|
/// Each TValue object must thus offer the following method:
|
||||||
///
|
///
|
||||||
/// const Poco::Timestamp& getExpiration() const;
|
/// const Poco::Timestamp& getExpiration() const;
|
||||||
///
|
///
|
||||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||||
/// Accessing an object will NOT update this absolute expire timepoint.
|
/// Accessing an object will NOT update this absolute expire timepoint.
|
||||||
/// You can use the Poco::ExpirationDecorator to add the getExpiration
|
/// You can use the Poco::ExpirationDecorator to add the getExpiration
|
||||||
/// method to values that do not have a getExpiration function.
|
/// method to values that do not have a getExpiration function.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniqueExpireLRUCache(long cacheSize = 1024):
|
UniqueExpireLRUCache(long cacheSize = 1024):
|
||||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||||
{
|
{
|
||||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||||
this->_strategy.pushBack(new UniqueExpireStrategy<TKey, TValue>());
|
this->_strategy.pushBack(new UniqueExpireStrategy<TKey, TValue>());
|
||||||
}
|
}
|
||||||
|
|
||||||
~UniqueExpireLRUCache()
|
~UniqueExpireLRUCache()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache);
|
UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache);
|
||||||
UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache);
|
UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,160 +1,160 @@
|
|||||||
//
|
//
|
||||||
// UniqueExpireStrategy.h
|
// UniqueExpireStrategy.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireStrategy.h#3 $
|
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireStrategy.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Cache
|
// Package: Cache
|
||||||
// Module: UniqueExpireStrategy
|
// Module: UniqueExpireStrategy
|
||||||
//
|
//
|
||||||
// Definition of the UniqueExpireStrategy class.
|
// Definition of the UniqueExpireStrategy class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_UniqueExpireStrategy_INCLUDED
|
#ifndef Foundation_UniqueExpireStrategy_INCLUDED
|
||||||
#define Foundation_UniqueExpireStrategy_INCLUDED
|
#define Foundation_UniqueExpireStrategy_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/KeyValueArgs.h"
|
#include "Poco/KeyValueArgs.h"
|
||||||
#include "Poco/ValidArgs.h"
|
#include "Poco/ValidArgs.h"
|
||||||
#include "Poco/AbstractStrategy.h"
|
#include "Poco/AbstractStrategy.h"
|
||||||
#include "Poco/Bugcheck.h"
|
#include "Poco/Bugcheck.h"
|
||||||
#include "Poco/Timestamp.h"
|
#include "Poco/Timestamp.h"
|
||||||
#include "Poco/EventArgs.h"
|
#include "Poco/EventArgs.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class TKey,
|
class TKey,
|
||||||
class TValue
|
class TValue
|
||||||
>
|
>
|
||||||
class UniqueExpireStrategy: public AbstractStrategy<TKey, TValue>
|
class UniqueExpireStrategy: public AbstractStrategy<TKey, TValue>
|
||||||
/// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast
|
/// 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
|
/// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define
|
||||||
/// expiration per CacheEntry.
|
/// expiration per CacheEntry.
|
||||||
/// Each TValue object must thus offer the following method:
|
/// Each TValue object must thus offer the following method:
|
||||||
///
|
///
|
||||||
/// const Poco::Timestamp& getExpiration() const;
|
/// const Poco::Timestamp& getExpiration() const;
|
||||||
///
|
///
|
||||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::multimap<Timestamp, TKey> TimeIndex;
|
typedef std::multimap<Timestamp, TKey> TimeIndex;
|
||||||
typedef typename TimeIndex::iterator IndexIterator;
|
typedef typename TimeIndex::iterator IndexIterator;
|
||||||
typedef typename TimeIndex::const_iterator ConstIndexIterator;
|
typedef typename TimeIndex::const_iterator ConstIndexIterator;
|
||||||
typedef std::map<TKey, IndexIterator> Keys;
|
typedef std::map<TKey, IndexIterator> Keys;
|
||||||
typedef typename Keys::iterator Iterator;
|
typedef typename Keys::iterator Iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UniqueExpireStrategy()
|
UniqueExpireStrategy()
|
||||||
/// Create an unique expire strategy.
|
/// Create an unique expire strategy.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~UniqueExpireStrategy()
|
~UniqueExpireStrategy()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& args)
|
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)
|
// 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
|
// no problem: will be removed with next get
|
||||||
const Timestamp& expire = args.value().getExpiration();
|
const Timestamp& expire = args.value().getExpiration();
|
||||||
IndexIterator it = _keyIndex.insert(std::make_pair(expire, args.key()));
|
IndexIterator it = _keyIndex.insert(std::make_pair(expire, args.key()));
|
||||||
std::pair<Iterator, bool> stat = _keys.insert(std::make_pair(args.key(), it));
|
std::pair<Iterator, bool> stat = _keys.insert(std::make_pair(args.key(), it));
|
||||||
if (!stat.second)
|
if (!stat.second)
|
||||||
{
|
{
|
||||||
_keyIndex.erase(stat.first->second);
|
_keyIndex.erase(stat.first->second);
|
||||||
stat.first->second = it;
|
stat.first->second = it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRemove(const void*, const TKey& key)
|
void onRemove(const void*, const TKey& key)
|
||||||
{
|
{
|
||||||
Iterator it = _keys.find(key);
|
Iterator it = _keys.find(key);
|
||||||
if (it != _keys.end())
|
if (it != _keys.end())
|
||||||
{
|
{
|
||||||
_keyIndex.erase(it->second);
|
_keyIndex.erase(it->second);
|
||||||
_keys.erase(it);
|
_keys.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onGet(const void*, const TKey& key)
|
void onGet(const void*, const TKey& key)
|
||||||
{
|
{
|
||||||
// get triggers no changes in an expire
|
// get triggers no changes in an expire
|
||||||
}
|
}
|
||||||
|
|
||||||
void onClear(const void*, const EventArgs& args)
|
void onClear(const void*, const EventArgs& args)
|
||||||
{
|
{
|
||||||
_keys.clear();
|
_keys.clear();
|
||||||
_keyIndex.clear();
|
_keyIndex.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onIsValid(const void*, ValidArgs<TKey>& args)
|
void onIsValid(const void*, ValidArgs<TKey>& args)
|
||||||
{
|
{
|
||||||
Iterator it = _keys.find(args.key());
|
Iterator it = _keys.find(args.key());
|
||||||
if (it != _keys.end())
|
if (it != _keys.end())
|
||||||
{
|
{
|
||||||
Timestamp now;
|
Timestamp now;
|
||||||
if (it->second->first <= now)
|
if (it->second->first <= now)
|
||||||
{
|
{
|
||||||
args.invalidate();
|
args.invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //not found: probably removed by onReplace
|
else //not found: probably removed by onReplace
|
||||||
args.invalidate();
|
args.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||||
{
|
{
|
||||||
// Note: replace only informs the cache which elements
|
// Note: replace only informs the cache which elements
|
||||||
// it would like to remove!
|
// it would like to remove!
|
||||||
// it does not remove them on its own!
|
// it does not remove them on its own!
|
||||||
IndexIterator it = _keyIndex.begin();
|
IndexIterator it = _keyIndex.begin();
|
||||||
Timestamp now;
|
Timestamp now;
|
||||||
while (it != _keyIndex.end() && it->first < now)
|
while (it != _keyIndex.end() && it->first < now)
|
||||||
{
|
{
|
||||||
elemsToRemove.insert(it->second);
|
elemsToRemove.insert(it->second);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map
|
Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map
|
||||||
TimeIndex _keyIndex; /// Maps time to key value
|
TimeIndex _keyIndex; /// Maps time to key value
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,89 +1,89 @@
|
|||||||
//
|
//
|
||||||
// WindowsConsoleChannel.h
|
// WindowsConsoleChannel.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/WindowsConsoleChannel.h#2 $
|
// $Id: //poco/svn/Foundation/include/Poco/WindowsConsoleChannel.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Logging
|
// Package: Logging
|
||||||
// Module: WindowsConsoleChannel
|
// Module: WindowsConsoleChannel
|
||||||
//
|
//
|
||||||
// Definition of the WindowsConsoleChannel class.
|
// Definition of the WindowsConsoleChannel class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef Foundation_WindowsConsoleChannel_INCLUDED
|
#ifndef Foundation_WindowsConsoleChannel_INCLUDED
|
||||||
#define Foundation_WindowsConsoleChannel_INCLUDED
|
#define Foundation_WindowsConsoleChannel_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/Channel.h"
|
#include "Poco/Channel.h"
|
||||||
#include "Poco/Mutex.h"
|
#include "Poco/Mutex.h"
|
||||||
#include "Poco/UnWindows.h"
|
#include "Poco/UnWindows.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
class Foundation_API WindowsConsoleChannel: public Channel
|
class Foundation_API WindowsConsoleChannel: public Channel
|
||||||
/// A channel that writes to the Windows console.
|
/// A channel that writes to the Windows console.
|
||||||
///
|
///
|
||||||
/// Only the message's text is written, followed
|
/// Only the message's text is written, followed
|
||||||
/// by a newline.
|
/// by a newline.
|
||||||
///
|
///
|
||||||
/// If POCO has been compiled with POCO_WIN32_UTF8,
|
/// If POCO has been compiled with POCO_WIN32_UTF8,
|
||||||
/// log messages are assumed to be UTF-8 encoded, and
|
/// log messages are assumed to be UTF-8 encoded, and
|
||||||
/// are converted to UTF-16 prior to writing them to the
|
/// are converted to UTF-16 prior to writing them to the
|
||||||
/// console. This is the main difference to the ConsoleChannel
|
/// console. This is the main difference to the ConsoleChannel
|
||||||
/// class, which cannot handle UTF-8 encoded messages on Windows.
|
/// class, which cannot handle UTF-8 encoded messages on Windows.
|
||||||
///
|
///
|
||||||
/// Chain this channel to a FormattingChannel with an
|
/// Chain this channel to a FormattingChannel with an
|
||||||
/// appropriate Formatter to control what is contained
|
/// appropriate Formatter to control what is contained
|
||||||
/// in the text.
|
/// in the text.
|
||||||
///
|
///
|
||||||
/// Only available on Windows platforms.
|
/// Only available on Windows platforms.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowsConsoleChannel();
|
WindowsConsoleChannel();
|
||||||
/// Creates the WindowsConsoleChannel.
|
/// Creates the WindowsConsoleChannel.
|
||||||
|
|
||||||
void log(const Message& msg);
|
void log(const Message& msg);
|
||||||
/// Logs the given message to the channel's stream.
|
/// Logs the given message to the channel's stream.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~WindowsConsoleChannel();
|
~WindowsConsoleChannel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HANDLE _hConsole;
|
HANDLE _hConsole;
|
||||||
bool _isFile;
|
bool _isFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#endif // Foundation_WindowsConsoleChannel_INCLUDED
|
#endif // Foundation_WindowsConsoleChannel_INCLUDED
|
||||||
|
|||||||
@@ -1,79 +1,79 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOChannel.cpp
|
// AsyncIOChannel.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/AsyncIOChannel.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/AsyncIOChannel.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: AsyncIO
|
// Package: AsyncIO
|
||||||
// Module: AsyncIOChannel
|
// Module: AsyncIOChannel
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AsyncIOChannel.h"
|
#include "Poco/AsyncIOChannel.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
AsyncIOChannel::AsyncIOChannel():
|
AsyncIOChannel::AsyncIOChannel():
|
||||||
enqueue(this, &AsyncIOChannel::enqueueImpl)
|
enqueue(this, &AsyncIOChannel::enqueueImpl)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncIOChannel::~AsyncIOChannel()
|
AsyncIOChannel::~AsyncIOChannel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncIOChannel::enqueueImpl(const AsyncIOCommand::Ptr& pCommand)
|
int AsyncIOChannel::enqueueImpl(const AsyncIOCommand::Ptr& pCommand)
|
||||||
{
|
{
|
||||||
AsyncIOCommand::Ptr ptr(pCommand);
|
AsyncIOCommand::Ptr ptr(pCommand);
|
||||||
return ptr->execute(*this);
|
return ptr->execute(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncIOChannel::write(const void* buffer, int length)
|
int AsyncIOChannel::write(const void* buffer, int length)
|
||||||
{
|
{
|
||||||
throw NotImplementedException("write()");
|
throw NotImplementedException("write()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncIOChannel::read(void* buffer, int length)
|
int AsyncIOChannel::read(void* buffer, int length)
|
||||||
{
|
{
|
||||||
throw NotImplementedException("read()");
|
throw NotImplementedException("read()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncIOChannel::seek(std::streamoff off, std::ios::seekdir dir)
|
int AsyncIOChannel::seek(std::streamoff off, std::ios::seekdir dir)
|
||||||
{
|
{
|
||||||
throw NotImplementedException("seek()");
|
throw NotImplementedException("seek()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,236 +1,236 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOCommand.cpp
|
// AsyncIOCommand.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/AsyncIOCommand.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/AsyncIOCommand.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: AsyncIO
|
// Package: AsyncIO
|
||||||
// Module: AsyncIOCommand
|
// Module: AsyncIOCommand
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AsyncIOCommand.h"
|
#include "Poco/AsyncIOCommand.h"
|
||||||
#include "Poco/AsyncIOChannel.h"
|
#include "Poco/AsyncIOChannel.h"
|
||||||
#include "Poco/AsyncIOEvent.h"
|
#include "Poco/AsyncIOEvent.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// AsyncIOCommand
|
// AsyncIOCommand
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
AsyncIOCommand::AsyncIOCommand():
|
AsyncIOCommand::AsyncIOCommand():
|
||||||
_state(CMD_PENDING),
|
_state(CMD_PENDING),
|
||||||
_result(0),
|
_result(0),
|
||||||
_pException(0)
|
_pException(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncIOCommand::~AsyncIOCommand()
|
AsyncIOCommand::~AsyncIOCommand()
|
||||||
{
|
{
|
||||||
delete _pException;
|
delete _pException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOCommand::wait()
|
void AsyncIOCommand::wait()
|
||||||
{
|
{
|
||||||
_completed.wait();
|
_completed.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOCommand::wait(long milliseconds)
|
void AsyncIOCommand::wait(long milliseconds)
|
||||||
{
|
{
|
||||||
_completed.wait(milliseconds);
|
_completed.wait(milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AsyncIOCommand::tryWait(long milliseconds)
|
bool AsyncIOCommand::tryWait(long milliseconds)
|
||||||
{
|
{
|
||||||
return _completed.tryWait(milliseconds);
|
return _completed.tryWait(milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncIOCommand::execute(AsyncIOChannel& channel)
|
int AsyncIOCommand::execute(AsyncIOChannel& channel)
|
||||||
{
|
{
|
||||||
delete _pException;
|
delete _pException;
|
||||||
_pException = 0;
|
_pException = 0;
|
||||||
|
|
||||||
_state = CMD_IN_PROGRESS;
|
_state = CMD_IN_PROGRESS;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_result = executeImpl(channel);
|
_result = executeImpl(channel);
|
||||||
_state = CMD_COMPLETED;
|
_state = CMD_COMPLETED;
|
||||||
_completed.set();
|
_completed.set();
|
||||||
AsyncIOEvent completedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_COMPLETED);
|
AsyncIOEvent completedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_COMPLETED);
|
||||||
commandCompleted(this, completedEvent);
|
commandCompleted(this, completedEvent);
|
||||||
channel.commandCompleted(this, completedEvent);
|
channel.commandCompleted(this, completedEvent);
|
||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
catch (Exception& exc)
|
catch (Exception& exc)
|
||||||
{
|
{
|
||||||
_pException = exc.clone();
|
_pException = exc.clone();
|
||||||
_state = CMD_FAILED;
|
_state = CMD_FAILED;
|
||||||
_completed.set();
|
_completed.set();
|
||||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||||
commandFailed(this, failedEvent);
|
commandFailed(this, failedEvent);
|
||||||
channel.commandFailed(this, failedEvent);
|
channel.commandFailed(this, failedEvent);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (std::exception& exc)
|
catch (std::exception& exc)
|
||||||
{
|
{
|
||||||
_pException = new Exception(exc.what());
|
_pException = new Exception(exc.what());
|
||||||
_state = CMD_FAILED;
|
_state = CMD_FAILED;
|
||||||
_completed.set();
|
_completed.set();
|
||||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||||
commandFailed(this, failedEvent);
|
commandFailed(this, failedEvent);
|
||||||
channel.commandFailed(this, failedEvent);
|
channel.commandFailed(this, failedEvent);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
_pException = new Exception("Unknown exception");
|
_pException = new Exception("Unknown exception");
|
||||||
_state = CMD_FAILED;
|
_state = CMD_FAILED;
|
||||||
_completed.set();
|
_completed.set();
|
||||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||||
commandFailed(this, failedEvent);
|
commandFailed(this, failedEvent);
|
||||||
channel.commandFailed(this, failedEvent);
|
channel.commandFailed(this, failedEvent);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// AsyncWriteCommand
|
// AsyncWriteCommand
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
AsyncWriteCommand::AsyncWriteCommand(const void* buffer, int length):
|
AsyncWriteCommand::AsyncWriteCommand(const void* buffer, int length):
|
||||||
_buffer(buffer),
|
_buffer(buffer),
|
||||||
_length(length)
|
_length(length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncWriteCommand::~AsyncWriteCommand()
|
AsyncWriteCommand::~AsyncWriteCommand()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncWriteCommand::executeImpl(AsyncIOChannel& channel)
|
int AsyncWriteCommand::executeImpl(AsyncIOChannel& channel)
|
||||||
{
|
{
|
||||||
return channel.write(_buffer, _length);
|
return channel.write(_buffer, _length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// AsyncBufferedWriteCommand
|
// AsyncBufferedWriteCommand
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
AsyncBufferedWriteCommand::AsyncBufferedWriteCommand(const void* buf, int length):
|
AsyncBufferedWriteCommand::AsyncBufferedWriteCommand(const void* buf, int length):
|
||||||
AsyncWriteCommand(new char[length], length)
|
AsyncWriteCommand(new char[length], length)
|
||||||
{
|
{
|
||||||
std::memcpy(const_cast<void*>(buffer()), buf, length);
|
std::memcpy(const_cast<void*>(buffer()), buf, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncBufferedWriteCommand::~AsyncBufferedWriteCommand()
|
AsyncBufferedWriteCommand::~AsyncBufferedWriteCommand()
|
||||||
{
|
{
|
||||||
delete [] reinterpret_cast<const char*>(buffer());
|
delete [] reinterpret_cast<const char*>(buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// AsyncReadCommand
|
// AsyncReadCommand
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
AsyncReadCommand::AsyncReadCommand(void* buffer, int length):
|
AsyncReadCommand::AsyncReadCommand(void* buffer, int length):
|
||||||
_buffer(buffer),
|
_buffer(buffer),
|
||||||
_length(length)
|
_length(length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncReadCommand::~AsyncReadCommand()
|
AsyncReadCommand::~AsyncReadCommand()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncReadCommand::executeImpl(AsyncIOChannel& channel)
|
int AsyncReadCommand::executeImpl(AsyncIOChannel& channel)
|
||||||
{
|
{
|
||||||
return channel.read(_buffer, _length);
|
return channel.read(_buffer, _length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// AsyncBufferedReadCommand
|
// AsyncBufferedReadCommand
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
AsyncBufferedReadCommand::AsyncBufferedReadCommand(int length):
|
AsyncBufferedReadCommand::AsyncBufferedReadCommand(int length):
|
||||||
AsyncReadCommand(new char[length], length)
|
AsyncReadCommand(new char[length], length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncBufferedReadCommand::~AsyncBufferedReadCommand()
|
AsyncBufferedReadCommand::~AsyncBufferedReadCommand()
|
||||||
{
|
{
|
||||||
delete [] reinterpret_cast<char*>(buffer());
|
delete [] reinterpret_cast<char*>(buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// AsyncSeekCommand
|
// AsyncSeekCommand
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
AsyncSeekCommand::AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir):
|
AsyncSeekCommand::AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir):
|
||||||
_off(off),
|
_off(off),
|
||||||
_dir(dir)
|
_dir(dir)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncSeekCommand::~AsyncSeekCommand()
|
AsyncSeekCommand::~AsyncSeekCommand()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncSeekCommand::executeImpl(AsyncIOChannel& channel)
|
int AsyncSeekCommand::executeImpl(AsyncIOChannel& channel)
|
||||||
{
|
{
|
||||||
return channel.seek(_off, _dir);
|
return channel.seek(_off, _dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,88 +1,88 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOEvent.cpp
|
// AsyncIOEvent.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/AsyncIOEvent.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/AsyncIOEvent.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: AsyncIO
|
// Package: AsyncIO
|
||||||
// Module: AsyncIOEvent
|
// Module: AsyncIOEvent
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AsyncIOEvent.h"
|
#include "Poco/AsyncIOEvent.h"
|
||||||
#include "Poco/AsyncIOCommand.h"
|
#include "Poco/AsyncIOCommand.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
AsyncIOEvent::AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what):
|
AsyncIOEvent::AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what):
|
||||||
_pCommand(pCommand),
|
_pCommand(pCommand),
|
||||||
_pChannel(pChannel),
|
_pChannel(pChannel),
|
||||||
_what(what)
|
_what(what)
|
||||||
{
|
{
|
||||||
poco_check_ptr (pCommand);
|
poco_check_ptr (pCommand);
|
||||||
poco_check_ptr (pChannel);
|
poco_check_ptr (pChannel);
|
||||||
|
|
||||||
_pCommand->duplicate();
|
_pCommand->duplicate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncIOEvent::AsyncIOEvent(const AsyncIOEvent& event):
|
AsyncIOEvent::AsyncIOEvent(const AsyncIOEvent& event):
|
||||||
_pCommand(event._pCommand),
|
_pCommand(event._pCommand),
|
||||||
_pChannel(event._pChannel),
|
_pChannel(event._pChannel),
|
||||||
_what(event._what)
|
_what(event._what)
|
||||||
{
|
{
|
||||||
_pCommand->duplicate();
|
_pCommand->duplicate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncIOEvent::~AsyncIOEvent()
|
AsyncIOEvent::~AsyncIOEvent()
|
||||||
{
|
{
|
||||||
_pCommand->release();
|
_pCommand->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncIOEvent& AsyncIOEvent::operator = (const AsyncIOEvent& event)
|
AsyncIOEvent& AsyncIOEvent::operator = (const AsyncIOEvent& event)
|
||||||
{
|
{
|
||||||
AsyncIOEvent tmp(event);
|
AsyncIOEvent tmp(event);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOEvent::swap(AsyncIOEvent& event)
|
void AsyncIOEvent::swap(AsyncIOEvent& event)
|
||||||
{
|
{
|
||||||
std::swap(_pCommand, event._pCommand);
|
std::swap(_pCommand, event._pCommand);
|
||||||
std::swap(_pChannel, event._pChannel);
|
std::swap(_pChannel, event._pChannel);
|
||||||
std::swap(_what, event._what);
|
std::swap(_what, event._what);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,100 +1,100 @@
|
|||||||
//
|
//
|
||||||
// AsyncStreamChannel.cpp
|
// AsyncStreamChannel.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/AsyncStreamChannel.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/AsyncStreamChannel.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: AsyncIO
|
// Package: AsyncIO
|
||||||
// Module: AsyncStreamChannel
|
// Module: AsyncStreamChannel
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/AsyncStreamChannel.h"
|
#include "Poco/AsyncStreamChannel.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
AsyncStreamChannel::AsyncStreamChannel(std::istream& istr):
|
AsyncStreamChannel::AsyncStreamChannel(std::istream& istr):
|
||||||
_pIstr(&istr),
|
_pIstr(&istr),
|
||||||
_pOstr(0)
|
_pOstr(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncStreamChannel::AsyncStreamChannel(std::ostream& ostr):
|
AsyncStreamChannel::AsyncStreamChannel(std::ostream& ostr):
|
||||||
_pIstr(0),
|
_pIstr(0),
|
||||||
_pOstr(&ostr)
|
_pOstr(&ostr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncStreamChannel::AsyncStreamChannel(std::iostream& iostr):
|
AsyncStreamChannel::AsyncStreamChannel(std::iostream& iostr):
|
||||||
_pIstr(&iostr),
|
_pIstr(&iostr),
|
||||||
_pOstr(&iostr)
|
_pOstr(&iostr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncStreamChannel::~AsyncStreamChannel()
|
AsyncStreamChannel::~AsyncStreamChannel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncStreamChannel::write(const void* buffer, int length)
|
int AsyncStreamChannel::write(const void* buffer, int length)
|
||||||
{
|
{
|
||||||
if (_pOstr)
|
if (_pOstr)
|
||||||
{
|
{
|
||||||
_pOstr->write(reinterpret_cast<const char*>(buffer), length);
|
_pOstr->write(reinterpret_cast<const char*>(buffer), length);
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
else throw IOException("Cannot write to an input stream");
|
else throw IOException("Cannot write to an input stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncStreamChannel::read(void* buffer, int length)
|
int AsyncStreamChannel::read(void* buffer, int length)
|
||||||
{
|
{
|
||||||
if (_pIstr)
|
if (_pIstr)
|
||||||
return static_cast<int>(_pIstr->read(reinterpret_cast<char*>(buffer), length).gcount());
|
return static_cast<int>(_pIstr->read(reinterpret_cast<char*>(buffer), length).gcount());
|
||||||
else
|
else
|
||||||
throw IOException("Cannot read from an output stream");
|
throw IOException("Cannot read from an output stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int AsyncStreamChannel::seek(std::streamoff off, std::ios::seekdir dir)
|
int AsyncStreamChannel::seek(std::streamoff off, std::ios::seekdir dir)
|
||||||
{
|
{
|
||||||
if (_pIstr)
|
if (_pIstr)
|
||||||
_pIstr->seekg(off, dir);
|
_pIstr->seekg(off, dir);
|
||||||
if (_pOstr)
|
if (_pOstr)
|
||||||
_pOstr->seekp(off, dir);
|
_pOstr->seekp(off, dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,76 +1,76 @@
|
|||||||
//
|
//
|
||||||
// Checksum.cpp
|
// Checksum.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/Checksum.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/Checksum.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: Checksum
|
// Module: Checksum
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Checksum.h"
|
#include "Poco/Checksum.h"
|
||||||
#include "Poco/zlib.h"
|
#include "Poco/zlib.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
Checksum::Checksum():
|
Checksum::Checksum():
|
||||||
_type(TYPE_CRC32),
|
_type(TYPE_CRC32),
|
||||||
_value(crc32(0L, Z_NULL, 0))
|
_value(crc32(0L, Z_NULL, 0))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Checksum::Checksum(Type t):
|
Checksum::Checksum(Type t):
|
||||||
_type(t),
|
_type(t),
|
||||||
_value(0)
|
_value(0)
|
||||||
{
|
{
|
||||||
if (t == TYPE_CRC32)
|
if (t == TYPE_CRC32)
|
||||||
_value = crc32(0L, Z_NULL, 0);
|
_value = crc32(0L, Z_NULL, 0);
|
||||||
else
|
else
|
||||||
_value = adler32(0L, Z_NULL, 0);
|
_value = adler32(0L, Z_NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Checksum::~Checksum()
|
Checksum::~Checksum()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Checksum::update(const char* data, unsigned length)
|
void Checksum::update(const char* data, unsigned length)
|
||||||
{
|
{
|
||||||
if (_type == TYPE_ADLER32)
|
if (_type == TYPE_ADLER32)
|
||||||
_value = adler32(_value, reinterpret_cast<const Bytef*>(data), length);
|
_value = adler32(_value, reinterpret_cast<const Bytef*>(data), length);
|
||||||
else
|
else
|
||||||
_value = crc32(_value, reinterpret_cast<const Bytef*>(data), length);
|
_value = crc32(_value, reinterpret_cast<const Bytef*>(data), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,101 +1,101 @@
|
|||||||
//
|
//
|
||||||
// Condition.cpp
|
// Condition.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/Condition.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/Condition.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
// Module: Condition
|
// Module: Condition
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Condition.h"
|
#include "Poco/Condition.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
Condition::Condition()
|
Condition::Condition()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Condition::~Condition()
|
Condition::~Condition()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Condition::signal()
|
void Condition::signal()
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
|
|
||||||
if (!_waitQueue.empty())
|
if (!_waitQueue.empty())
|
||||||
{
|
{
|
||||||
_waitQueue.front()->set();
|
_waitQueue.front()->set();
|
||||||
dequeue();
|
dequeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Condition::broadcast()
|
void Condition::broadcast()
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
|
|
||||||
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
||||||
{
|
{
|
||||||
(*it)->set();
|
(*it)->set();
|
||||||
}
|
}
|
||||||
_waitQueue.clear();
|
_waitQueue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Condition::enqueue(Event& event)
|
void Condition::enqueue(Event& event)
|
||||||
{
|
{
|
||||||
_waitQueue.push_back(&event);
|
_waitQueue.push_back(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Condition::dequeue()
|
void Condition::dequeue()
|
||||||
{
|
{
|
||||||
_waitQueue.pop_front();
|
_waitQueue.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Condition::dequeue(Event& event)
|
void Condition::dequeue(Event& event)
|
||||||
{
|
{
|
||||||
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
||||||
{
|
{
|
||||||
if (*it == &event)
|
if (*it == &event)
|
||||||
{
|
{
|
||||||
_waitQueue.erase(it);
|
_waitQueue.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,408 +1,408 @@
|
|||||||
//
|
//
|
||||||
// DynamicAny.cpp
|
// DynamicAny.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/DynamicAny.cpp#3 $
|
// $Id: //poco/svn/Foundation/src/DynamicAny.cpp#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: DynamicAny
|
// Module: DynamicAny
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/DynamicAny.h"
|
#include "Poco/DynamicAny.h"
|
||||||
#include "Poco/DynamicStruct.h"
|
#include "Poco/DynamicStruct.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
DynamicAny::DynamicAny():
|
DynamicAny::DynamicAny():
|
||||||
_pHolder(new DynamicAnyHolderImpl<int>(0))
|
_pHolder(new DynamicAnyHolderImpl<int>(0))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny::DynamicAny(const char* pVal):
|
DynamicAny::DynamicAny(const char* pVal):
|
||||||
_pHolder(new DynamicAnyHolderImpl<std::string>(pVal))
|
_pHolder(new DynamicAnyHolderImpl<std::string>(pVal))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny::DynamicAny(const DynamicAny& other):
|
DynamicAny::DynamicAny(const DynamicAny& other):
|
||||||
_pHolder(0)
|
_pHolder(0)
|
||||||
{
|
{
|
||||||
if (other._pHolder)
|
if (other._pHolder)
|
||||||
_pHolder = other._pHolder->clone();
|
_pHolder = other._pHolder->clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny::~DynamicAny()
|
DynamicAny::~DynamicAny()
|
||||||
{
|
{
|
||||||
delete _pHolder;
|
delete _pHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny& DynamicAny::operator = (const DynamicAny& other)
|
DynamicAny& DynamicAny::operator = (const DynamicAny& other)
|
||||||
{
|
{
|
||||||
DynamicAny tmp(other);
|
DynamicAny tmp(other);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const DynamicAny DynamicAny::operator + (const DynamicAny& other) const
|
const DynamicAny DynamicAny::operator + (const DynamicAny& other) const
|
||||||
{
|
{
|
||||||
if (isInteger())
|
if (isInteger())
|
||||||
{
|
{
|
||||||
if(isSigned())
|
if(isSigned())
|
||||||
return add<Poco::Int64>(other);
|
return add<Poco::Int64>(other);
|
||||||
else
|
else
|
||||||
return add<Poco::UInt64>(other);
|
return add<Poco::UInt64>(other);
|
||||||
}
|
}
|
||||||
else if (isNumeric())
|
else if (isNumeric())
|
||||||
return add<double>(other);
|
return add<double>(other);
|
||||||
else if (isString())
|
else if (isString())
|
||||||
return add<std::string>(other);
|
return add<std::string>(other);
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny& DynamicAny::operator += (const DynamicAny& other)
|
DynamicAny& DynamicAny::operator += (const DynamicAny& other)
|
||||||
{
|
{
|
||||||
if (isInteger())
|
if (isInteger())
|
||||||
{
|
{
|
||||||
if(isSigned())
|
if(isSigned())
|
||||||
return *this = add<Poco::Int64>(other);
|
return *this = add<Poco::Int64>(other);
|
||||||
else
|
else
|
||||||
return *this = add<Poco::UInt64>(other);
|
return *this = add<Poco::UInt64>(other);
|
||||||
}
|
}
|
||||||
else if (isNumeric())
|
else if (isNumeric())
|
||||||
return *this = add<double>(other);
|
return *this = add<double>(other);
|
||||||
else if (isString())
|
else if (isString())
|
||||||
return *this = add<std::string>(other);
|
return *this = add<std::string>(other);
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const DynamicAny DynamicAny::operator - (const DynamicAny& other) const
|
const DynamicAny DynamicAny::operator - (const DynamicAny& other) const
|
||||||
{
|
{
|
||||||
if (isInteger())
|
if (isInteger())
|
||||||
{
|
{
|
||||||
if(isSigned())
|
if(isSigned())
|
||||||
return subtract<Poco::Int64>(other);
|
return subtract<Poco::Int64>(other);
|
||||||
else
|
else
|
||||||
return subtract<Poco::UInt64>(other);
|
return subtract<Poco::UInt64>(other);
|
||||||
}
|
}
|
||||||
else if (isNumeric())
|
else if (isNumeric())
|
||||||
return subtract<double>(other);
|
return subtract<double>(other);
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny& DynamicAny::operator -= (const DynamicAny& other)
|
DynamicAny& DynamicAny::operator -= (const DynamicAny& other)
|
||||||
{
|
{
|
||||||
if (isInteger())
|
if (isInteger())
|
||||||
{
|
{
|
||||||
if(isSigned())
|
if(isSigned())
|
||||||
return *this = subtract<Poco::Int64>(other);
|
return *this = subtract<Poco::Int64>(other);
|
||||||
else
|
else
|
||||||
return *this = subtract<Poco::UInt64>(other);
|
return *this = subtract<Poco::UInt64>(other);
|
||||||
}
|
}
|
||||||
else if (isNumeric())
|
else if (isNumeric())
|
||||||
return *this = subtract<double>(other);
|
return *this = subtract<double>(other);
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const DynamicAny DynamicAny::operator * (const DynamicAny& other) const
|
const DynamicAny DynamicAny::operator * (const DynamicAny& other) const
|
||||||
{
|
{
|
||||||
if (isInteger())
|
if (isInteger())
|
||||||
{
|
{
|
||||||
if(isSigned())
|
if(isSigned())
|
||||||
return multiply<Poco::Int64>(other);
|
return multiply<Poco::Int64>(other);
|
||||||
else
|
else
|
||||||
return multiply<Poco::UInt64>(other);
|
return multiply<Poco::UInt64>(other);
|
||||||
}
|
}
|
||||||
else if (isNumeric())
|
else if (isNumeric())
|
||||||
return multiply<double>(other);
|
return multiply<double>(other);
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny& DynamicAny::operator *= (const DynamicAny& other)
|
DynamicAny& DynamicAny::operator *= (const DynamicAny& other)
|
||||||
{
|
{
|
||||||
if (isInteger())
|
if (isInteger())
|
||||||
{
|
{
|
||||||
if(isSigned())
|
if(isSigned())
|
||||||
return *this = multiply<Poco::Int64>(other);
|
return *this = multiply<Poco::Int64>(other);
|
||||||
else
|
else
|
||||||
return *this = multiply<Poco::UInt64>(other);
|
return *this = multiply<Poco::UInt64>(other);
|
||||||
}
|
}
|
||||||
else if (isNumeric())
|
else if (isNumeric())
|
||||||
return *this = multiply<double>(other);
|
return *this = multiply<double>(other);
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const DynamicAny DynamicAny::operator / (const DynamicAny& other) const
|
const DynamicAny DynamicAny::operator / (const DynamicAny& other) const
|
||||||
{
|
{
|
||||||
if (isInteger())
|
if (isInteger())
|
||||||
{
|
{
|
||||||
if(isSigned())
|
if(isSigned())
|
||||||
return divide<Poco::Int64>(other);
|
return divide<Poco::Int64>(other);
|
||||||
else
|
else
|
||||||
return divide<Poco::UInt64>(other);
|
return divide<Poco::UInt64>(other);
|
||||||
}
|
}
|
||||||
else if (isNumeric())
|
else if (isNumeric())
|
||||||
return divide<double>(other);
|
return divide<double>(other);
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny& DynamicAny::operator /= (const DynamicAny& other)
|
DynamicAny& DynamicAny::operator /= (const DynamicAny& other)
|
||||||
{
|
{
|
||||||
if (isInteger())
|
if (isInteger())
|
||||||
{
|
{
|
||||||
if(isSigned())
|
if(isSigned())
|
||||||
return *this = divide<Poco::Int64>(other);
|
return *this = divide<Poco::Int64>(other);
|
||||||
else
|
else
|
||||||
return *this = divide<Poco::UInt64>(other);
|
return *this = divide<Poco::UInt64>(other);
|
||||||
}
|
}
|
||||||
else if (isNumeric())
|
else if (isNumeric())
|
||||||
return *this = divide<double>(other);
|
return *this = divide<double>(other);
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny& DynamicAny::operator ++ ()
|
DynamicAny& DynamicAny::operator ++ ()
|
||||||
{
|
{
|
||||||
if (!isInteger())
|
if (!isInteger())
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
|
|
||||||
return *this = *this + 1;
|
return *this = *this + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicAny DynamicAny::operator ++ (int)
|
DynamicAny DynamicAny::operator ++ (int)
|
||||||
{
|
{
|
||||||
if (!isInteger())
|
if (!isInteger())
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
|
|
||||||
DynamicAny tmp(*this);
|
DynamicAny tmp(*this);
|
||||||
*this += 1;
|
*this += 1;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicAny& DynamicAny::operator -- ()
|
DynamicAny& DynamicAny::operator -- ()
|
||||||
{
|
{
|
||||||
if (!isInteger())
|
if (!isInteger())
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
|
|
||||||
return *this = *this - 1;
|
return *this = *this - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicAny DynamicAny::operator -- (int)
|
DynamicAny DynamicAny::operator -- (int)
|
||||||
{
|
{
|
||||||
if (!isInteger())
|
if (!isInteger())
|
||||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||||
|
|
||||||
DynamicAny tmp(*this);
|
DynamicAny tmp(*this);
|
||||||
*this -= 1;
|
*this -= 1;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny& DynamicAny::operator [] (const std::string& name)
|
DynamicAny& DynamicAny::operator [] (const std::string& name)
|
||||||
{
|
{
|
||||||
DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<DynamicAnyHolderImpl<DynamicStruct> *>(_pHolder);
|
DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<DynamicAnyHolderImpl<DynamicStruct> *>(_pHolder);
|
||||||
if (pHolder)
|
if (pHolder)
|
||||||
return pHolder->operator[](name);
|
return pHolder->operator[](name);
|
||||||
else
|
else
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const DynamicAny& DynamicAny::operator [] (const std::string& name) const
|
const DynamicAny& DynamicAny::operator [] (const std::string& name) const
|
||||||
{
|
{
|
||||||
const DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<const DynamicAnyHolderImpl<DynamicStruct>* >(_pHolder);
|
const DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<const DynamicAnyHolderImpl<DynamicStruct>* >(_pHolder);
|
||||||
if (pHolder)
|
if (pHolder)
|
||||||
return pHolder->operator[](name);
|
return pHolder->operator[](name);
|
||||||
else
|
else
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny DynamicAny::parse(const std::string& val)
|
DynamicAny DynamicAny::parse(const std::string& val)
|
||||||
{
|
{
|
||||||
std::string::size_type t = 0;
|
std::string::size_type t = 0;
|
||||||
return parse(val, t);
|
return parse(val, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny DynamicAny::parse(const std::string& val, std::string::size_type& pos)
|
DynamicAny DynamicAny::parse(const std::string& val, std::string::size_type& pos)
|
||||||
{
|
{
|
||||||
// { -> an Object==DynamicStruct
|
// { -> an Object==DynamicStruct
|
||||||
// [ -> an array
|
// [ -> an array
|
||||||
// '/" -> a string (strip '/")
|
// '/" -> a string (strip '/")
|
||||||
// other: also treat as string
|
// other: also treat as string
|
||||||
skipWhiteSpace(val, pos);
|
skipWhiteSpace(val, pos);
|
||||||
if (pos < val.size())
|
if (pos < val.size())
|
||||||
{
|
{
|
||||||
switch (val[pos])
|
switch (val[pos])
|
||||||
{
|
{
|
||||||
case '{':
|
case '{':
|
||||||
return parseObject(val, pos);
|
return parseObject(val, pos);
|
||||||
case '[':
|
case '[':
|
||||||
return parseArray(val, pos);
|
return parseArray(val, pos);
|
||||||
default:
|
default:
|
||||||
return parseString(val, pos);
|
return parseString(val, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string empty;
|
std::string empty;
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny DynamicAny::parseObject(const std::string& val, std::string::size_type& pos)
|
DynamicAny DynamicAny::parseObject(const std::string& val, std::string::size_type& pos)
|
||||||
{
|
{
|
||||||
poco_assert_dbg (val[pos] == '{');
|
poco_assert_dbg (val[pos] == '{');
|
||||||
++pos;
|
++pos;
|
||||||
skipWhiteSpace(val, pos);
|
skipWhiteSpace(val, pos);
|
||||||
DynamicStruct aStruct;
|
DynamicStruct aStruct;
|
||||||
while (val[pos] != '}' && pos < val.size())
|
while (val[pos] != '}' && pos < val.size())
|
||||||
{
|
{
|
||||||
std::string key = parseString(val, pos);
|
std::string key = parseString(val, pos);
|
||||||
skipWhiteSpace(val, pos);
|
skipWhiteSpace(val, pos);
|
||||||
if (val[pos] != ':')
|
if (val[pos] != ':')
|
||||||
throw DataFormatException("Incorrect object, must contain: key : value pairs");
|
throw DataFormatException("Incorrect object, must contain: key : value pairs");
|
||||||
++pos; // skip past :
|
++pos; // skip past :
|
||||||
DynamicAny value = parse(val, pos);
|
DynamicAny value = parse(val, pos);
|
||||||
aStruct.insert(key, value);
|
aStruct.insert(key, value);
|
||||||
skipWhiteSpace(val, pos);
|
skipWhiteSpace(val, pos);
|
||||||
if (val[pos] == ',')
|
if (val[pos] == ',')
|
||||||
{
|
{
|
||||||
++pos;
|
++pos;
|
||||||
skipWhiteSpace(val, pos);
|
skipWhiteSpace(val, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val[pos] != '}')
|
if (val[pos] != '}')
|
||||||
throw DataFormatException("Unterminated object");
|
throw DataFormatException("Unterminated object");
|
||||||
++pos;
|
++pos;
|
||||||
return aStruct;
|
return aStruct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAny DynamicAny::parseArray(const std::string& val, std::string::size_type& pos)
|
DynamicAny DynamicAny::parseArray(const std::string& val, std::string::size_type& pos)
|
||||||
{
|
{
|
||||||
poco_assert_dbg (val[pos] == '[');
|
poco_assert_dbg (val[pos] == '[');
|
||||||
++pos;
|
++pos;
|
||||||
skipWhiteSpace(val, pos);
|
skipWhiteSpace(val, pos);
|
||||||
std::vector<DynamicAny> result;
|
std::vector<DynamicAny> result;
|
||||||
while (val[pos] != ']' && pos < val.size())
|
while (val[pos] != ']' && pos < val.size())
|
||||||
{
|
{
|
||||||
result.push_back(parse(val, pos));
|
result.push_back(parse(val, pos));
|
||||||
skipWhiteSpace(val, pos);
|
skipWhiteSpace(val, pos);
|
||||||
if (val[pos] == ',')
|
if (val[pos] == ',')
|
||||||
{
|
{
|
||||||
++pos;
|
++pos;
|
||||||
skipWhiteSpace(val, pos);
|
skipWhiteSpace(val, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val[pos] != ']')
|
if (val[pos] != ']')
|
||||||
throw DataFormatException("Unterminated array");
|
throw DataFormatException("Unterminated array");
|
||||||
++pos;
|
++pos;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string DynamicAny::parseString(const std::string& val, std::string::size_type& pos)
|
std::string DynamicAny::parseString(const std::string& val, std::string::size_type& pos)
|
||||||
{
|
{
|
||||||
static const std::string STR_STOP("'\"");
|
static const std::string STR_STOP("'\"");
|
||||||
static const std::string OTHER_STOP(" ,]}"); // we stop at space, ',', ']' or '}'
|
static const std::string OTHER_STOP(" ,]}"); // we stop at space, ',', ']' or '}'
|
||||||
|
|
||||||
bool inString = false;
|
bool inString = false;
|
||||||
//skip optional ' "
|
//skip optional ' "
|
||||||
if (val[pos] == '\'' || val[pos] == '"')
|
if (val[pos] == '\'' || val[pos] == '"')
|
||||||
{
|
{
|
||||||
inString = true;
|
inString = true;
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::size_type stop = std::string::npos;
|
std::string::size_type stop = std::string::npos;
|
||||||
if (inString)
|
if (inString)
|
||||||
{
|
{
|
||||||
stop = val.find_first_of(STR_STOP, pos);
|
stop = val.find_first_of(STR_STOP, pos);
|
||||||
if (stop == std::string::npos)
|
if (stop == std::string::npos)
|
||||||
throw DataFormatException("Unterminated string");
|
throw DataFormatException("Unterminated string");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we stop at space, ',', ']' or '}' or end of string
|
// we stop at space, ',', ']' or '}' or end of string
|
||||||
stop = val.find_first_of(OTHER_STOP, pos);
|
stop = val.find_first_of(OTHER_STOP, pos);
|
||||||
if (stop == std::string::npos)
|
if (stop == std::string::npos)
|
||||||
stop = val.size();
|
stop = val.size();
|
||||||
|
|
||||||
std::string::size_type safeCheck = val.find_first_of(STR_STOP, pos);
|
std::string::size_type safeCheck = val.find_first_of(STR_STOP, pos);
|
||||||
if (safeCheck != std::string::npos && safeCheck < stop)
|
if (safeCheck != std::string::npos && safeCheck < stop)
|
||||||
throw DataFormatException("Misplaced string termination char found");
|
throw DataFormatException("Misplaced string termination char found");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop now points to the last char to be not included
|
// stop now points to the last char to be not included
|
||||||
std::string result = val.substr(pos, stop - pos);
|
std::string result = val.substr(pos, stop - pos);
|
||||||
++stop; // point past '/"
|
++stop; // point past '/"
|
||||||
pos = stop;
|
pos = stop;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DynamicAny::skipWhiteSpace(const std::string& val, std::string::size_type& pos)
|
void DynamicAny::skipWhiteSpace(const std::string& val, std::string::size_type& pos)
|
||||||
{
|
{
|
||||||
while (std::isspace(val[pos]))
|
while (std::isspace(val[pos]))
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string DynamicAny::toString(const DynamicAny& any)
|
std::string DynamicAny::toString(const DynamicAny& any)
|
||||||
{
|
{
|
||||||
std::string res;
|
std::string res;
|
||||||
appendJSONString(res, any);
|
appendJSONString(res, any);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco::Poco
|
} // namespace Poco::Poco
|
||||||
|
|||||||
@@ -1,69 +1,69 @@
|
|||||||
//
|
//
|
||||||
// DynamicAnyHolder.cpp
|
// DynamicAnyHolder.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/DynamicAnyHolder.cpp#3 $
|
// $Id: //poco/svn/Foundation/src/DynamicAnyHolder.cpp#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: DynamicAnyHolder
|
// Module: DynamicAnyHolder
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/DynamicAnyHolder.h"
|
#include "Poco/DynamicAnyHolder.h"
|
||||||
#include "Poco/DynamicAny.h"
|
#include "Poco/DynamicAny.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
DynamicAnyHolder::DynamicAnyHolder()
|
DynamicAnyHolder::DynamicAnyHolder()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicAnyHolder::~DynamicAnyHolder()
|
DynamicAnyHolder::~DynamicAnyHolder()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void appendJSONString(std::string& val, const DynamicAny& any)
|
void appendJSONString(std::string& val, const DynamicAny& any)
|
||||||
{
|
{
|
||||||
bool isJsonString = (any.type() == typeid(std::string) || any.type() == typeid(char) || any.type() == typeid(Poco::DateTime) || any.type() == typeid(Poco::LocalDateTime));
|
bool isJsonString = (any.type() == typeid(std::string) || any.type() == typeid(char) || any.type() == typeid(Poco::DateTime) || any.type() == typeid(Poco::LocalDateTime));
|
||||||
if (isJsonString)
|
if (isJsonString)
|
||||||
{
|
{
|
||||||
val.append(1, '\'');
|
val.append(1, '\'');
|
||||||
}
|
}
|
||||||
val.append(any.convert<std::string>());
|
val.append(any.convert<std::string>());
|
||||||
if (isJsonString)
|
if (isJsonString)
|
||||||
{
|
{
|
||||||
val.append(1, '\'');
|
val.append(1, '\'');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,81 +1,81 @@
|
|||||||
//
|
//
|
||||||
// DynamicStruct.cpp
|
// DynamicStruct.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/src/DynamicStruct.cpp#4 $
|
// $Id: //poco/Main/Foundation/src/DynamicStruct.cpp#4 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
// Module: DynamicStruct
|
// Module: DynamicStruct
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/DynamicStruct.h"
|
#include "Poco/DynamicStruct.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
DynamicStruct::DynamicStruct():
|
DynamicStruct::DynamicStruct():
|
||||||
_data()
|
_data()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicStruct::DynamicStruct(const Data& d):
|
DynamicStruct::DynamicStruct(const Data& d):
|
||||||
_data(d)
|
_data(d)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicStruct::~DynamicStruct()
|
DynamicStruct::~DynamicStruct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const DynamicAny& DynamicStruct::operator[](const std::string& name) const
|
const DynamicAny& DynamicStruct::operator[](const std::string& name) const
|
||||||
{
|
{
|
||||||
ConstIterator it = find(name);
|
ConstIterator it = find(name);
|
||||||
if (it == end())
|
if (it == end())
|
||||||
throw NotFoundException(name);
|
throw NotFoundException(name);
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::set<std::string> DynamicStruct::members() const
|
std::set<std::string> DynamicStruct::members() const
|
||||||
{
|
{
|
||||||
std::set<std::string> keys;
|
std::set<std::string> keys;
|
||||||
ConstIterator it = begin();
|
ConstIterator it = begin();
|
||||||
ConstIterator itEnd = end();
|
ConstIterator itEnd = end();
|
||||||
for (; it != itEnd; ++it)
|
for (; it != itEnd; ++it)
|
||||||
keys.insert(it->first);
|
keys.insert(it->first);
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco::Poco
|
} // namespace Poco::Poco
|
||||||
|
|||||||
@@ -1,140 +1,140 @@
|
|||||||
//
|
//
|
||||||
// FileStream.cpp
|
// FileStream.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/FileStream.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/FileStream.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Streams
|
// Package: Streams
|
||||||
// Module: FileStream
|
// Module: FileStream
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/FileStream.h"
|
#include "Poco/FileStream.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
#include "FileStream_WIN32.cpp"
|
#include "FileStream_WIN32.cpp"
|
||||||
#else
|
#else
|
||||||
#include "FileStream_POSIX.cpp"
|
#include "FileStream_POSIX.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
FileIOS::FileIOS(std::ios::openmode defaultMode):
|
FileIOS::FileIOS(std::ios::openmode defaultMode):
|
||||||
_defaultMode(defaultMode)
|
_defaultMode(defaultMode)
|
||||||
{
|
{
|
||||||
poco_ios_init(&_buf);
|
poco_ios_init(&_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileIOS::~FileIOS()
|
FileIOS::~FileIOS()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileIOS::open(const std::string& path, std::ios::openmode mode)
|
void FileIOS::open(const std::string& path, std::ios::openmode mode)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
_buf.open(path, mode | _defaultMode);
|
_buf.open(path, mode | _defaultMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileIOS::close()
|
void FileIOS::close()
|
||||||
{
|
{
|
||||||
_buf.close();
|
_buf.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileStreamBuf* FileIOS::rdbuf()
|
FileStreamBuf* FileIOS::rdbuf()
|
||||||
{
|
{
|
||||||
return &_buf;
|
return &_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileInputStream::FileInputStream():
|
FileInputStream::FileInputStream():
|
||||||
FileIOS(std::ios::in),
|
FileIOS(std::ios::in),
|
||||||
std::istream(&_buf)
|
std::istream(&_buf)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileInputStream::FileInputStream(const std::string& path, std::ios::openmode mode):
|
FileInputStream::FileInputStream(const std::string& path, std::ios::openmode mode):
|
||||||
FileIOS(std::ios::in),
|
FileIOS(std::ios::in),
|
||||||
std::istream(&_buf)
|
std::istream(&_buf)
|
||||||
{
|
{
|
||||||
open(path, mode);
|
open(path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileInputStream::~FileInputStream()
|
FileInputStream::~FileInputStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileOutputStream::FileOutputStream():
|
FileOutputStream::FileOutputStream():
|
||||||
FileIOS(std::ios::out),
|
FileIOS(std::ios::out),
|
||||||
std::ostream(&_buf)
|
std::ostream(&_buf)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileOutputStream::FileOutputStream(const std::string& path, std::ios::openmode mode):
|
FileOutputStream::FileOutputStream(const std::string& path, std::ios::openmode mode):
|
||||||
FileIOS(std::ios::out),
|
FileIOS(std::ios::out),
|
||||||
std::ostream(&_buf)
|
std::ostream(&_buf)
|
||||||
{
|
{
|
||||||
open(path, mode);
|
open(path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileOutputStream::~FileOutputStream()
|
FileOutputStream::~FileOutputStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileStream::FileStream():
|
FileStream::FileStream():
|
||||||
FileIOS(std::ios::in | std::ios::out),
|
FileIOS(std::ios::in | std::ios::out),
|
||||||
std::iostream(&_buf)
|
std::iostream(&_buf)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileStream::FileStream(const std::string& path, std::ios::openmode mode):
|
FileStream::FileStream(const std::string& path, std::ios::openmode mode):
|
||||||
FileIOS(std::ios::in | std::ios::out),
|
FileIOS(std::ios::in | std::ios::out),
|
||||||
std::iostream(&_buf)
|
std::iostream(&_buf)
|
||||||
{
|
{
|
||||||
open(path, mode);
|
open(path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileStream::~FileStream()
|
FileStream::~FileStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,183 +1,183 @@
|
|||||||
//
|
//
|
||||||
// FileStream_POSIX.cpp
|
// FileStream_POSIX.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/FileStream_POSIX.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/FileStream_POSIX.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Streams
|
// Package: Streams
|
||||||
// Module: FileStream
|
// Module: FileStream
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/FileStream.h"
|
#include "Poco/FileStream.h"
|
||||||
#include "Poco/File.h"
|
#include "Poco/File.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
FileStreamBuf::FileStreamBuf():
|
FileStreamBuf::FileStreamBuf():
|
||||||
BufferedBidirectionalStreamBuf(BUFFER_SIZE, std::ios::in | std::ios::out),
|
BufferedBidirectionalStreamBuf(BUFFER_SIZE, std::ios::in | std::ios::out),
|
||||||
_fd(-1),
|
_fd(-1),
|
||||||
_pos(0)
|
_pos(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileStreamBuf::~FileStreamBuf()
|
FileStreamBuf::~FileStreamBuf()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
||||||
{
|
{
|
||||||
poco_assert (_fd == -1);
|
poco_assert (_fd == -1);
|
||||||
|
|
||||||
_path = path;
|
_path = path;
|
||||||
setMode(mode);
|
setMode(mode);
|
||||||
|
|
||||||
int flags(0);
|
int flags(0);
|
||||||
if (mode & std::ios::trunc)
|
if (mode & std::ios::trunc)
|
||||||
flags |= O_TRUNC;
|
flags |= O_TRUNC;
|
||||||
if (mode & std::ios::app)
|
if (mode & std::ios::app)
|
||||||
flags |= O_APPEND;
|
flags |= O_APPEND;
|
||||||
if (mode & std::ios::out)
|
if (mode & std::ios::out)
|
||||||
flags |= O_CREAT;
|
flags |= O_CREAT;
|
||||||
if ((mode & std::ios::in) && (mode & std::ios::out))
|
if ((mode & std::ios::in) && (mode & std::ios::out))
|
||||||
flags |= O_RDWR;
|
flags |= O_RDWR;
|
||||||
else if (mode & std::ios::in)
|
else if (mode & std::ios::in)
|
||||||
flags |= O_RDONLY;
|
flags |= O_RDONLY;
|
||||||
else
|
else
|
||||||
flags |= O_WRONLY;
|
flags |= O_WRONLY;
|
||||||
|
|
||||||
_fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP);
|
_fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP);
|
||||||
if (_fd == -1)
|
if (_fd == -1)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
|
|
||||||
if ((mode & std::ios::app) || (mode & std::ios::ate))
|
if ((mode & std::ios::app) || (mode & std::ios::ate))
|
||||||
seekoff(0, std::ios::end, mode);
|
seekoff(0, std::ios::end, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||||
{
|
{
|
||||||
if (_fd == -1) return -1;
|
if (_fd == -1) return -1;
|
||||||
|
|
||||||
if (getMode() & std::ios::out)
|
if (getMode() & std::ios::out)
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
int n = read(_fd, buffer, length);
|
int n = read(_fd, buffer, length);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
_pos += n;
|
_pos += n;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||||
{
|
{
|
||||||
if (_fd == -1) return -1;
|
if (_fd == -1) return -1;
|
||||||
|
|
||||||
int n = write(_fd, buffer, length);
|
int n = write(_fd, buffer, length);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
_pos += n;
|
_pos += n;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamBuf::close()
|
void FileStreamBuf::close()
|
||||||
{
|
{
|
||||||
if (_fd != -1)
|
if (_fd != -1)
|
||||||
{
|
{
|
||||||
sync();
|
sync();
|
||||||
::close(_fd);
|
::close(_fd);
|
||||||
_fd = -1;
|
_fd = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
||||||
{
|
{
|
||||||
if (_fd == -1 || !(getMode() & mode))
|
if (_fd == -1 || !(getMode() & mode))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getMode() & std::ios::out)
|
if (getMode() & std::ios::out)
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
std::streamoff adj;
|
std::streamoff adj;
|
||||||
if (mode & std::ios::in)
|
if (mode & std::ios::in)
|
||||||
adj = static_cast<std::streamoff>(egptr() - gptr());
|
adj = static_cast<std::streamoff>(egptr() - gptr());
|
||||||
else
|
else
|
||||||
adj = 0;
|
adj = 0;
|
||||||
|
|
||||||
resetBuffers();
|
resetBuffers();
|
||||||
|
|
||||||
int whence = SEEK_SET;
|
int whence = SEEK_SET;
|
||||||
if (dir == std::ios::cur)
|
if (dir == std::ios::cur)
|
||||||
{
|
{
|
||||||
whence = SEEK_CUR;
|
whence = SEEK_CUR;
|
||||||
off -= adj;
|
off -= adj;
|
||||||
}
|
}
|
||||||
else if (dir == std::ios::end)
|
else if (dir == std::ios::end)
|
||||||
{
|
{
|
||||||
whence = SEEK_END;
|
whence = SEEK_END;
|
||||||
}
|
}
|
||||||
_pos = lseek(_fd, off, whence);
|
_pos = lseek(_fd, off, whence);
|
||||||
return _pos;
|
return _pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
||||||
{
|
{
|
||||||
if (_fd == -1 || !(getMode() & mode))
|
if (_fd == -1 || !(getMode() & mode))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getMode() & std::ios::out)
|
if (getMode() & std::ios::out)
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
resetBuffers();
|
resetBuffers();
|
||||||
|
|
||||||
_pos = lseek(_fd, pos, SEEK_SET);
|
_pos = lseek(_fd, pos, SEEK_SET);
|
||||||
return _pos;
|
return _pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,223 +1,223 @@
|
|||||||
//
|
//
|
||||||
// FileStream.cpp
|
// FileStream.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/FileStream_WIN32.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/FileStream_WIN32.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Streams
|
// Package: Streams
|
||||||
// Module: FileStream
|
// Module: FileStream
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/FileStream.h"
|
#include "Poco/FileStream.h"
|
||||||
#include "Poco/File.h"
|
#include "Poco/File.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#if defined (POCO_WIN32_UTF8)
|
#if defined (POCO_WIN32_UTF8)
|
||||||
#include "Poco/UnicodeConverter.h"
|
#include "Poco/UnicodeConverter.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
FileStreamBuf::FileStreamBuf():
|
FileStreamBuf::FileStreamBuf():
|
||||||
BufferedBidirectionalStreamBuf(BUFFER_SIZE, 0),
|
BufferedBidirectionalStreamBuf(BUFFER_SIZE, 0),
|
||||||
_handle(INVALID_HANDLE_VALUE),
|
_handle(INVALID_HANDLE_VALUE),
|
||||||
_pos(0)
|
_pos(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileStreamBuf::~FileStreamBuf()
|
FileStreamBuf::~FileStreamBuf()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
||||||
{
|
{
|
||||||
poco_assert (_handle == INVALID_HANDLE_VALUE);
|
poco_assert (_handle == INVALID_HANDLE_VALUE);
|
||||||
|
|
||||||
_path = path;
|
_path = path;
|
||||||
setMode(mode);
|
setMode(mode);
|
||||||
|
|
||||||
DWORD access = 0;
|
DWORD access = 0;
|
||||||
if (mode & std::ios::in)
|
if (mode & std::ios::in)
|
||||||
access |= GENERIC_READ;
|
access |= GENERIC_READ;
|
||||||
if (mode & std::ios::out)
|
if (mode & std::ios::out)
|
||||||
access |= GENERIC_WRITE;
|
access |= GENERIC_WRITE;
|
||||||
|
|
||||||
DWORD shareMode = FILE_SHARE_READ;
|
DWORD shareMode = FILE_SHARE_READ;
|
||||||
DWORD creationDisp = OPEN_EXISTING;
|
DWORD creationDisp = OPEN_EXISTING;
|
||||||
if (mode & std::ios::trunc)
|
if (mode & std::ios::trunc)
|
||||||
creationDisp = CREATE_ALWAYS;
|
creationDisp = CREATE_ALWAYS;
|
||||||
else if (mode & std::ios::out)
|
else if (mode & std::ios::out)
|
||||||
creationDisp = OPEN_ALWAYS;
|
creationDisp = OPEN_ALWAYS;
|
||||||
|
|
||||||
DWORD flags = FILE_ATTRIBUTE_NORMAL;
|
DWORD flags = FILE_ATTRIBUTE_NORMAL;
|
||||||
|
|
||||||
#if defined (POCO_WIN32_UTF8)
|
#if defined (POCO_WIN32_UTF8)
|
||||||
std::wstring utf16Path;
|
std::wstring utf16Path;
|
||||||
UnicodeConverter::toUTF16(path, utf16Path);
|
UnicodeConverter::toUTF16(path, utf16Path);
|
||||||
_handle = CreateFileW(utf16Path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
_handle = CreateFileW(utf16Path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
||||||
#else
|
#else
|
||||||
_handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
_handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (_handle == INVALID_HANDLE_VALUE)
|
if (_handle == INVALID_HANDLE_VALUE)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
|
|
||||||
if ((mode & std::ios::ate) || (mode & std::ios::app))
|
if ((mode & std::ios::ate) || (mode & std::ios::app))
|
||||||
seekoff(0, std::ios::end, mode);
|
seekoff(0, std::ios::end, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||||
{
|
{
|
||||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::in))
|
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::in))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getMode() & std::ios::out)
|
if (getMode() & std::ios::out)
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
DWORD bytesRead(0);
|
DWORD bytesRead(0);
|
||||||
BOOL rc = ReadFile(_handle, buffer, static_cast<DWORD>(length), &bytesRead, NULL);
|
BOOL rc = ReadFile(_handle, buffer, static_cast<DWORD>(length), &bytesRead, NULL);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
|
|
||||||
_pos += bytesRead;
|
_pos += bytesRead;
|
||||||
|
|
||||||
return static_cast<int>(bytesRead);
|
return static_cast<int>(bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||||
{
|
{
|
||||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::out))
|
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::out))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getMode() & std::ios::app)
|
if (getMode() & std::ios::app)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
li.QuadPart = 0;
|
li.QuadPart = 0;
|
||||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_END);
|
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_END);
|
||||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
_pos = li.QuadPart;
|
_pos = li.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD bytesWritten(0);
|
DWORD bytesWritten(0);
|
||||||
BOOL rc = WriteFile(_handle, buffer, static_cast<DWORD>(length), &bytesWritten, NULL);
|
BOOL rc = WriteFile(_handle, buffer, static_cast<DWORD>(length), &bytesWritten, NULL);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
|
|
||||||
_pos += bytesWritten;
|
_pos += bytesWritten;
|
||||||
|
|
||||||
return static_cast<int>(bytesWritten);
|
return static_cast<int>(bytesWritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamBuf::close()
|
void FileStreamBuf::close()
|
||||||
{
|
{
|
||||||
if (_handle != INVALID_HANDLE_VALUE)
|
if (_handle != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
if (getMode() & std::ios::out)
|
if (getMode() & std::ios::out)
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
CloseHandle(_handle);
|
CloseHandle(_handle);
|
||||||
_handle = INVALID_HANDLE_VALUE;
|
_handle = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
||||||
{
|
{
|
||||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getMode() & std::ios::out)
|
if (getMode() & std::ios::out)
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
std::streamoff adj;
|
std::streamoff adj;
|
||||||
if (mode & std::ios::in)
|
if (mode & std::ios::in)
|
||||||
adj = static_cast<std::streamoff>(egptr() - gptr());
|
adj = static_cast<std::streamoff>(egptr() - gptr());
|
||||||
else
|
else
|
||||||
adj = 0;
|
adj = 0;
|
||||||
|
|
||||||
resetBuffers();
|
resetBuffers();
|
||||||
|
|
||||||
DWORD offset = FILE_BEGIN;
|
DWORD offset = FILE_BEGIN;
|
||||||
if (dir == std::ios::cur)
|
if (dir == std::ios::cur)
|
||||||
{
|
{
|
||||||
offset = FILE_CURRENT;
|
offset = FILE_CURRENT;
|
||||||
off -= adj;
|
off -= adj;
|
||||||
}
|
}
|
||||||
else if (dir == std::ios::end)
|
else if (dir == std::ios::end)
|
||||||
{
|
{
|
||||||
offset = FILE_END;
|
offset = FILE_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
li.QuadPart = off;
|
li.QuadPart = off;
|
||||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, offset);
|
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, offset);
|
||||||
|
|
||||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
_pos = li.QuadPart;
|
_pos = li.QuadPart;
|
||||||
return std::streampos(static_cast<std::streamoff>(_pos));
|
return std::streampos(static_cast<std::streamoff>(_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
||||||
{
|
{
|
||||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (getMode() & std::ios::out)
|
if (getMode() & std::ios::out)
|
||||||
sync();
|
sync();
|
||||||
|
|
||||||
resetBuffers();
|
resetBuffers();
|
||||||
|
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
li.QuadPart = pos;
|
li.QuadPart = pos;
|
||||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_BEGIN);
|
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_BEGIN);
|
||||||
|
|
||||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||||
File::handleLastError(_path);
|
File::handleLastError(_path);
|
||||||
_pos = li.QuadPart;
|
_pos = li.QuadPart;
|
||||||
return std::streampos(static_cast<std::streamoff>(_pos));
|
return std::streampos(static_cast<std::streamoff>(_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,56 +1,56 @@
|
|||||||
//
|
//
|
||||||
// Hash.cpp
|
// Hash.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/Hash.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/Hash.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Hashing
|
// Package: Hashing
|
||||||
// Module: Hash
|
// Module: Hash
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Hash.h"
|
#include "Poco/Hash.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
std::size_t hash(const std::string& str)
|
std::size_t hash(const std::string& str)
|
||||||
{
|
{
|
||||||
std::size_t h = 0;
|
std::size_t h = 0;
|
||||||
std::string::const_iterator it = str.begin();
|
std::string::const_iterator it = str.begin();
|
||||||
std::string::const_iterator end = str.end();
|
std::string::const_iterator end = str.end();
|
||||||
while (it != end)
|
while (it != end)
|
||||||
{
|
{
|
||||||
h = h * 0xf4243 ^ *it++;
|
h = h * 0xf4243 ^ *it++;
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,118 +1,118 @@
|
|||||||
//
|
//
|
||||||
// SharedMemory.cpp
|
// SharedMemory.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/SharedMemory.cpp#3 $
|
// $Id: //poco/svn/Foundation/src/SharedMemory.cpp#3 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Processes
|
// Package: Processes
|
||||||
// Module: SharedMemory
|
// Module: SharedMemory
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#if POCO_OS == POCO_OS_SOLARIS
|
#if POCO_OS == POCO_OS_SOLARIS
|
||||||
#undef _XOPEN_SOURCE
|
#undef _XOPEN_SOURCE
|
||||||
#define _XOPEN_SOURCE 500
|
#define _XOPEN_SOURCE 500
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/SharedMemory.h"
|
#include "Poco/SharedMemory.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#if defined(POCO_NO_SHAREDMEMORY)
|
#if defined(POCO_NO_SHAREDMEMORY)
|
||||||
#include "SharedMemory_DUMMY.cpp"
|
#include "SharedMemory_DUMMY.cpp"
|
||||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
#include "SharedMemory_WIN32.cpp"
|
#include "SharedMemory_WIN32.cpp"
|
||||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||||
#include "SharedMemory_POSIX.cpp"
|
#include "SharedMemory_POSIX.cpp"
|
||||||
#else
|
#else
|
||||||
#include "SharedMemory_DUMMY.cpp"
|
#include "SharedMemory_DUMMY.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
SharedMemory::SharedMemory():
|
SharedMemory::SharedMemory():
|
||||||
_pImpl(0)
|
_pImpl(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint, bool server):
|
SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint, bool server):
|
||||||
_pImpl(new SharedMemoryImpl(name, size, mode, addrHint, server))
|
_pImpl(new SharedMemoryImpl(name, size, mode, addrHint, server))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemory::SharedMemory(const Poco::File& file, AccessMode mode, const void* addrHint):
|
SharedMemory::SharedMemory(const Poco::File& file, AccessMode mode, const void* addrHint):
|
||||||
_pImpl(new SharedMemoryImpl(file, mode, addrHint))
|
_pImpl(new SharedMemoryImpl(file, mode, addrHint))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemory::SharedMemory(const SharedMemory& other):
|
SharedMemory::SharedMemory(const SharedMemory& other):
|
||||||
_pImpl(other._pImpl)
|
_pImpl(other._pImpl)
|
||||||
{
|
{
|
||||||
if (_pImpl)
|
if (_pImpl)
|
||||||
_pImpl->duplicate();
|
_pImpl->duplicate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemory::~SharedMemory()
|
SharedMemory::~SharedMemory()
|
||||||
{
|
{
|
||||||
if (_pImpl)
|
if (_pImpl)
|
||||||
_pImpl->release();
|
_pImpl->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemory& SharedMemory::operator = (const SharedMemory& other)
|
SharedMemory& SharedMemory::operator = (const SharedMemory& other)
|
||||||
{
|
{
|
||||||
SharedMemory tmp(other);
|
SharedMemory tmp(other);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char* SharedMemory::begin() const
|
char* SharedMemory::begin() const
|
||||||
{
|
{
|
||||||
if (_pImpl)
|
if (_pImpl)
|
||||||
return _pImpl->begin();
|
return _pImpl->begin();
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char* SharedMemory::end() const
|
char* SharedMemory::end() const
|
||||||
{
|
{
|
||||||
if (_pImpl)
|
if (_pImpl)
|
||||||
return _pImpl->end();
|
return _pImpl->end();
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,58 +1,58 @@
|
|||||||
//
|
//
|
||||||
// SharedMemoryImpl.cpp
|
// SharedMemoryImpl.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/SharedMemory_DUMMY.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/SharedMemory_DUMMY.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Processes
|
// Package: Processes
|
||||||
// Module: SharedMemoryImpl
|
// Module: SharedMemoryImpl
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/SharedMemory_DUMMY.h"
|
#include "Poco/SharedMemory_DUMMY.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*, bool)
|
SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*, bool)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File&, SharedMemory::AccessMode, const void*)
|
SharedMemoryImpl::SharedMemoryImpl(const Poco::File&, SharedMemory::AccessMode, const void*)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::~SharedMemoryImpl()
|
SharedMemoryImpl::~SharedMemoryImpl()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,156 +1,156 @@
|
|||||||
//
|
//
|
||||||
// SharedMemoryImpl.cpp
|
// SharedMemoryImpl.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/SharedMemory_POSIX.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/SharedMemory_POSIX.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Processes
|
// Package: Processes
|
||||||
// Module: SharedMemoryImpl
|
// Module: SharedMemoryImpl
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/SharedMemory_POSIX.h"
|
#include "Poco/SharedMemory_POSIX.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/File.h"
|
#include "Poco/File.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server):
|
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server):
|
||||||
_size(size),
|
_size(size),
|
||||||
_fd(-1),
|
_fd(-1),
|
||||||
_address(0),
|
_address(0),
|
||||||
_access(mode),
|
_access(mode),
|
||||||
_name("/"),
|
_name("/"),
|
||||||
_fileMapped(false),
|
_fileMapped(false),
|
||||||
_server(server)
|
_server(server)
|
||||||
{
|
{
|
||||||
#if POCO_OS == POCO_OS_HPUX
|
#if POCO_OS == POCO_OS_HPUX
|
||||||
_name.append("tmp/");
|
_name.append("tmp/");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_name.append(name);
|
_name.append(name);
|
||||||
|
|
||||||
int flags = O_CREAT;
|
int flags = O_CREAT;
|
||||||
if (_access == SharedMemory::AM_WRITE)
|
if (_access == SharedMemory::AM_WRITE)
|
||||||
flags |= O_RDWR;
|
flags |= O_RDWR;
|
||||||
else
|
else
|
||||||
flags |= O_RDONLY;
|
flags |= O_RDONLY;
|
||||||
|
|
||||||
// open the shared memory segment
|
// open the shared memory segment
|
||||||
_fd = ::shm_open(_name.c_str(), flags, S_IRUSR | S_IWUSR);
|
_fd = ::shm_open(_name.c_str(), flags, S_IRUSR | S_IWUSR);
|
||||||
if (_fd == -1)
|
if (_fd == -1)
|
||||||
throw SystemException("Cannot create shared memory object", _name);
|
throw SystemException("Cannot create shared memory object", _name);
|
||||||
|
|
||||||
// now set the correct size for the segment
|
// now set the correct size for the segment
|
||||||
if (-1 == ::ftruncate(_fd, size))
|
if (-1 == ::ftruncate(_fd, size))
|
||||||
{
|
{
|
||||||
::close(_fd);
|
::close(_fd);
|
||||||
_fd = -1;
|
_fd = -1;
|
||||||
::shm_unlink(_name.c_str());
|
::shm_unlink(_name.c_str());
|
||||||
throw SystemException("Cannot resize shared memory object", _name);
|
throw SystemException("Cannot resize shared memory object", _name);
|
||||||
}
|
}
|
||||||
map(addrHint);
|
map(addrHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint):
|
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint):
|
||||||
_size(0),
|
_size(0),
|
||||||
_fd(-1),
|
_fd(-1),
|
||||||
_address(0),
|
_address(0),
|
||||||
_access(mode),
|
_access(mode),
|
||||||
_name(file.path()),
|
_name(file.path()),
|
||||||
_fileMapped(true),
|
_fileMapped(true),
|
||||||
_server(false)
|
_server(false)
|
||||||
{
|
{
|
||||||
if (!file.exists() || !file.isFile())
|
if (!file.exists() || !file.isFile())
|
||||||
throw FileNotFoundException(file.path());
|
throw FileNotFoundException(file.path());
|
||||||
|
|
||||||
_size = file.getSize();
|
_size = file.getSize();
|
||||||
int flag = O_RDONLY;
|
int flag = O_RDONLY;
|
||||||
if (mode == SharedMemory::AM_WRITE)
|
if (mode == SharedMemory::AM_WRITE)
|
||||||
flag = O_RDWR;
|
flag = O_RDWR;
|
||||||
_fd = ::open(_name.c_str(), flag);
|
_fd = ::open(_name.c_str(), flag);
|
||||||
if (-1 == _fd)
|
if (-1 == _fd)
|
||||||
throw OpenFileException("Cannot open memory mapped file", _name);
|
throw OpenFileException("Cannot open memory mapped file", _name);
|
||||||
|
|
||||||
map(addrHint);
|
map(addrHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::~SharedMemoryImpl()
|
SharedMemoryImpl::~SharedMemoryImpl()
|
||||||
{
|
{
|
||||||
unmap();
|
unmap();
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryImpl::map(const void* addrHint)
|
void SharedMemoryImpl::map(const void* addrHint)
|
||||||
{
|
{
|
||||||
int access = PROT_READ;
|
int access = PROT_READ;
|
||||||
if (_access == SharedMemory::AM_WRITE)
|
if (_access == SharedMemory::AM_WRITE)
|
||||||
access |= PROT_WRITE;
|
access |= PROT_WRITE;
|
||||||
|
|
||||||
void* addr = ::mmap(const_cast<void*>(addrHint), _size, access, MAP_SHARED, _fd, 0);
|
void* addr = ::mmap(const_cast<void*>(addrHint), _size, access, MAP_SHARED, _fd, 0);
|
||||||
if (addr == MAP_FAILED)
|
if (addr == MAP_FAILED)
|
||||||
throw SystemException("Cannot map file into shared memory", _name);
|
throw SystemException("Cannot map file into shared memory", _name);
|
||||||
|
|
||||||
_address = static_cast<char*>(addr);
|
_address = static_cast<char*>(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryImpl::unmap()
|
void SharedMemoryImpl::unmap()
|
||||||
{
|
{
|
||||||
if (_address)
|
if (_address)
|
||||||
{
|
{
|
||||||
::munmap(_address, _size);
|
::munmap(_address, _size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryImpl::close()
|
void SharedMemoryImpl::close()
|
||||||
{
|
{
|
||||||
if (_fd != -1)
|
if (_fd != -1)
|
||||||
{
|
{
|
||||||
::close(_fd);
|
::close(_fd);
|
||||||
_fd = -1;
|
_fd = -1;
|
||||||
}
|
}
|
||||||
if (!_fileMapped && _server)
|
if (!_fileMapped && _server)
|
||||||
{
|
{
|
||||||
::shm_unlink(_name.c_str());
|
::shm_unlink(_name.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,166 +1,166 @@
|
|||||||
//
|
//
|
||||||
// SharedMemoryImpl.cpp
|
// SharedMemoryImpl.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/SharedMemory_WIN32.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/SharedMemory_WIN32.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Processes
|
// Package: Processes
|
||||||
// Module: SharedMemoryImpl
|
// Module: SharedMemoryImpl
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/SharedMemory_WIN32.h"
|
#include "Poco/SharedMemory_WIN32.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/File.h"
|
#include "Poco/File.h"
|
||||||
#if defined (POCO_WIN32_UTF8)
|
#if defined (POCO_WIN32_UTF8)
|
||||||
#include "Poco/UnicodeConverter.h"
|
#include "Poco/UnicodeConverter.h"
|
||||||
#endif
|
#endif
|
||||||
#include "Poco/UnWindows.h"
|
#include "Poco/UnWindows.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void*, bool):
|
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void*, bool):
|
||||||
_name(name),
|
_name(name),
|
||||||
_memHandle(INVALID_HANDLE_VALUE),
|
_memHandle(INVALID_HANDLE_VALUE),
|
||||||
_fileHandle(INVALID_HANDLE_VALUE),
|
_fileHandle(INVALID_HANDLE_VALUE),
|
||||||
_size(static_cast<DWORD>(size)),
|
_size(static_cast<DWORD>(size)),
|
||||||
_mode(PAGE_READONLY),
|
_mode(PAGE_READONLY),
|
||||||
_address(0)
|
_address(0)
|
||||||
{
|
{
|
||||||
if (mode == SharedMemory::AM_WRITE)
|
if (mode == SharedMemory::AM_WRITE)
|
||||||
_mode = PAGE_READWRITE;
|
_mode = PAGE_READWRITE;
|
||||||
|
|
||||||
#if defined (POCO_WIN32_UTF8)
|
#if defined (POCO_WIN32_UTF8)
|
||||||
std::wstring utf16name;
|
std::wstring utf16name;
|
||||||
UnicodeConverter::toUTF16(_name, utf16name);
|
UnicodeConverter::toUTF16(_name, utf16name);
|
||||||
_memHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, utf16name.c_str());
|
_memHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, utf16name.c_str());
|
||||||
#else
|
#else
|
||||||
_memHandle = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, _name.c_str());
|
_memHandle = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, _name.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!_memHandle)
|
if (!_memHandle)
|
||||||
throw SystemException("Cannot create shared memory object", _name);
|
throw SystemException("Cannot create shared memory object", _name);
|
||||||
|
|
||||||
map();
|
map();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void*):
|
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void*):
|
||||||
_name(file.path()),
|
_name(file.path()),
|
||||||
_memHandle(INVALID_HANDLE_VALUE),
|
_memHandle(INVALID_HANDLE_VALUE),
|
||||||
_fileHandle(INVALID_HANDLE_VALUE),
|
_fileHandle(INVALID_HANDLE_VALUE),
|
||||||
_size(0),
|
_size(0),
|
||||||
_mode(PAGE_READONLY),
|
_mode(PAGE_READONLY),
|
||||||
_address(0)
|
_address(0)
|
||||||
{
|
{
|
||||||
if (!file.exists() || !file.isFile())
|
if (!file.exists() || !file.isFile())
|
||||||
throw FileNotFoundException(_name);
|
throw FileNotFoundException(_name);
|
||||||
|
|
||||||
_size = static_cast<DWORD>(file.getSize());
|
_size = static_cast<DWORD>(file.getSize());
|
||||||
|
|
||||||
DWORD shareMode = FILE_SHARE_READ;
|
DWORD shareMode = FILE_SHARE_READ;
|
||||||
DWORD fileMode = GENERIC_READ;
|
DWORD fileMode = GENERIC_READ;
|
||||||
|
|
||||||
if (mode == SharedMemory::AM_WRITE)
|
if (mode == SharedMemory::AM_WRITE)
|
||||||
{
|
{
|
||||||
_mode = PAGE_READWRITE;
|
_mode = PAGE_READWRITE;
|
||||||
fileMode |= GENERIC_WRITE;
|
fileMode |= GENERIC_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined (POCO_WIN32_UTF8)
|
#if defined (POCO_WIN32_UTF8)
|
||||||
std::wstring utf16name;
|
std::wstring utf16name;
|
||||||
UnicodeConverter::toUTF16(_name, utf16name);
|
UnicodeConverter::toUTF16(_name, utf16name);
|
||||||
_fileHandle = CreateFileW(utf16name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
_fileHandle = CreateFileW(utf16name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
#else
|
#else
|
||||||
_fileHandle = CreateFileA(_name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
_fileHandle = CreateFileA(_name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (_fileHandle == INVALID_HANDLE_VALUE)
|
if (_fileHandle == INVALID_HANDLE_VALUE)
|
||||||
throw OpenFileException("Cannot open memory mapped file", _name);
|
throw OpenFileException("Cannot open memory mapped file", _name);
|
||||||
|
|
||||||
_memHandle = CreateFileMapping(_fileHandle, NULL, _mode, 0, 0, NULL);
|
_memHandle = CreateFileMapping(_fileHandle, NULL, _mode, 0, 0, NULL);
|
||||||
if (!_memHandle)
|
if (!_memHandle)
|
||||||
{
|
{
|
||||||
CloseHandle(_fileHandle);
|
CloseHandle(_fileHandle);
|
||||||
_fileHandle = INVALID_HANDLE_VALUE;
|
_fileHandle = INVALID_HANDLE_VALUE;
|
||||||
throw SystemException("Cannot map file into shared memory", _name);
|
throw SystemException("Cannot map file into shared memory", _name);
|
||||||
}
|
}
|
||||||
map();
|
map();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryImpl::~SharedMemoryImpl()
|
SharedMemoryImpl::~SharedMemoryImpl()
|
||||||
{
|
{
|
||||||
unmap();
|
unmap();
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryImpl::map()
|
void SharedMemoryImpl::map()
|
||||||
{
|
{
|
||||||
DWORD access = FILE_MAP_READ;
|
DWORD access = FILE_MAP_READ;
|
||||||
if (_mode == PAGE_READWRITE)
|
if (_mode == PAGE_READWRITE)
|
||||||
access = FILE_MAP_WRITE;
|
access = FILE_MAP_WRITE;
|
||||||
LPVOID addr = MapViewOfFile(_memHandle, access, 0, 0, _size);
|
LPVOID addr = MapViewOfFile(_memHandle, access, 0, 0, _size);
|
||||||
if (!addr)
|
if (!addr)
|
||||||
throw SystemException("Cannot map shared memory object", _name);
|
throw SystemException("Cannot map shared memory object", _name);
|
||||||
|
|
||||||
_address = static_cast<char*>(addr);
|
_address = static_cast<char*>(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryImpl::unmap()
|
void SharedMemoryImpl::unmap()
|
||||||
{
|
{
|
||||||
if (_address)
|
if (_address)
|
||||||
{
|
{
|
||||||
UnmapViewOfFile(_address);
|
UnmapViewOfFile(_address);
|
||||||
_address = 0;
|
_address = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryImpl::close()
|
void SharedMemoryImpl::close()
|
||||||
{
|
{
|
||||||
if (_memHandle != INVALID_HANDLE_VALUE)
|
if (_memHandle != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
CloseHandle(_memHandle);
|
CloseHandle(_memHandle);
|
||||||
_memHandle = INVALID_HANDLE_VALUE;
|
_memHandle = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_fileHandle != INVALID_HANDLE_VALUE)
|
if (_fileHandle != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
CloseHandle(_fileHandle);
|
CloseHandle(_fileHandle);
|
||||||
_fileHandle = INVALID_HANDLE_VALUE;
|
_fileHandle = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,203 +1,203 @@
|
|||||||
//
|
//
|
||||||
// UTF8String.cpp
|
// UTF8String.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/UTF8String.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/UTF8String.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Text
|
// Package: Text
|
||||||
// Module: UTF8String
|
// Module: UTF8String
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/UTF8String.h"
|
#include "Poco/UTF8String.h"
|
||||||
#include "Poco/Unicode.h"
|
#include "Poco/Unicode.h"
|
||||||
#include "Poco/TextIterator.h"
|
#include "Poco/TextIterator.h"
|
||||||
#include "Poco/TextConverter.h"
|
#include "Poco/TextConverter.h"
|
||||||
#include "Poco/UTF8Encoding.h"
|
#include "Poco/UTF8Encoding.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2)
|
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2)
|
||||||
{
|
{
|
||||||
static UTF8Encoding utf8;
|
static UTF8Encoding utf8;
|
||||||
|
|
||||||
std::string::size_type sz = str.size();
|
std::string::size_type sz = str.size();
|
||||||
if (pos > sz) pos = sz;
|
if (pos > sz) pos = sz;
|
||||||
if (pos + n > sz) n = sz - pos;
|
if (pos + n > sz) n = sz - pos;
|
||||||
TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8);
|
TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8);
|
||||||
TextIterator uend1(str.begin() + pos + n);
|
TextIterator uend1(str.begin() + pos + n);
|
||||||
TextIterator uit2(it2, end2, utf8);
|
TextIterator uit2(it2, end2, utf8);
|
||||||
TextIterator uend2(end2);
|
TextIterator uend2(end2);
|
||||||
while (uit1 != uend1 && uit2 != uend2)
|
while (uit1 != uend1 && uit2 != uend2)
|
||||||
{
|
{
|
||||||
int c1 = Unicode::toLower(*uit1);
|
int c1 = Unicode::toLower(*uit1);
|
||||||
int c2 = Unicode::toLower(*uit2);
|
int c2 = Unicode::toLower(*uit2);
|
||||||
if (c1 < c2)
|
if (c1 < c2)
|
||||||
return -1;
|
return -1;
|
||||||
else if (c1 > c2)
|
else if (c1 > c2)
|
||||||
return 1;
|
return 1;
|
||||||
++uit1; ++uit2;
|
++uit1; ++uit2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uit1 == uend1)
|
if (uit1 == uend1)
|
||||||
return uit2 == uend2 ? 0 : -1;
|
return uit2 == uend2 ? 0 : -1;
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str1, const std::string& str2)
|
int UTF8::icompare(const std::string& str1, const std::string& str2)
|
||||||
{
|
{
|
||||||
return icompare(str1, 0, str1.size(), str2.begin(), str2.end());
|
return icompare(str1, 0, str1.size(), str2.begin(), str2.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2)
|
int UTF8::icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2)
|
||||||
{
|
{
|
||||||
if (n2 > str2.size()) n2 = str2.size();
|
if (n2 > str2.size()) n2 = str2.size();
|
||||||
return icompare(str1, 0, n1, str2.begin(), str2.begin() + n2);
|
return icompare(str1, 0, n1, str2.begin(), str2.begin() + n2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str1, std::string::size_type n, const std::string& str2)
|
int UTF8::icompare(const std::string& str1, std::string::size_type n, const std::string& str2)
|
||||||
{
|
{
|
||||||
if (n > str2.size()) n = str2.size();
|
if (n > str2.size()) n = str2.size();
|
||||||
return icompare(str1, 0, n, str2.begin(), str2.begin() + n);
|
return icompare(str1, 0, n, str2.begin(), str2.begin() + n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2)
|
int UTF8::icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2)
|
||||||
{
|
{
|
||||||
return icompare(str1, pos, n, str2.begin(), str2.end());
|
return icompare(str1, pos, n, str2.begin(), str2.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2)
|
int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2)
|
||||||
{
|
{
|
||||||
std::string::size_type sz2 = str2.size();
|
std::string::size_type sz2 = str2.size();
|
||||||
if (pos2 > sz2) pos2 = sz2;
|
if (pos2 > sz2) pos2 = sz2;
|
||||||
if (pos2 + n2 > sz2) n2 = sz2 - pos2;
|
if (pos2 + n2 > sz2) n2 = sz2 - pos2;
|
||||||
return icompare(str1, pos1, n1, str2.begin() + pos2, str2.begin() + pos2 + n2);
|
return icompare(str1, pos1, n1, str2.begin() + pos2, str2.begin() + pos2 + n2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2)
|
int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2)
|
||||||
{
|
{
|
||||||
std::string::size_type sz2 = str2.size();
|
std::string::size_type sz2 = str2.size();
|
||||||
if (pos2 > sz2) pos2 = sz2;
|
if (pos2 > sz2) pos2 = sz2;
|
||||||
if (pos2 + n > sz2) n = sz2 - pos2;
|
if (pos2 + n > sz2) n = sz2 - pos2;
|
||||||
return icompare(str1, pos1, n, str2.begin() + pos2, str2.begin() + pos2 + n);
|
return icompare(str1, pos1, n, str2.begin() + pos2, str2.begin() + pos2 + n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr)
|
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr)
|
||||||
{
|
{
|
||||||
static UTF8Encoding utf8;
|
static UTF8Encoding utf8;
|
||||||
|
|
||||||
poco_check_ptr (ptr);
|
poco_check_ptr (ptr);
|
||||||
std::string::size_type sz = str.size();
|
std::string::size_type sz = str.size();
|
||||||
if (pos > sz) pos = sz;
|
if (pos > sz) pos = sz;
|
||||||
if (pos + n > sz) n = sz - pos;
|
if (pos + n > sz) n = sz - pos;
|
||||||
TextIterator uit(str.begin() + pos, str.begin() + pos + n, utf8);
|
TextIterator uit(str.begin() + pos, str.begin() + pos + n, utf8);
|
||||||
TextIterator uend(str.begin() + pos + n);
|
TextIterator uend(str.begin() + pos + n);
|
||||||
while (uit != uend && *ptr)
|
while (uit != uend && *ptr)
|
||||||
{
|
{
|
||||||
int c1 = Unicode::toLower(*uit);
|
int c1 = Unicode::toLower(*uit);
|
||||||
int c2 = Unicode::toLower(*ptr);
|
int c2 = Unicode::toLower(*ptr);
|
||||||
if (c1 < c2)
|
if (c1 < c2)
|
||||||
return -1;
|
return -1;
|
||||||
else if (c1 > c2)
|
else if (c1 > c2)
|
||||||
return 1;
|
return 1;
|
||||||
++uit; ++ptr;
|
++uit; ++ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uit == uend)
|
if (uit == uend)
|
||||||
return *ptr == 0 ? 0 : -1;
|
return *ptr == 0 ? 0 : -1;
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr)
|
int UTF8::icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr)
|
||||||
{
|
{
|
||||||
return icompare(str, pos, str.size() - pos, ptr);
|
return icompare(str, pos, str.size() - pos, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UTF8::icompare(const std::string& str, const std::string::value_type* ptr)
|
int UTF8::icompare(const std::string& str, const std::string::value_type* ptr)
|
||||||
{
|
{
|
||||||
return icompare(str, 0, str.size(), ptr);
|
return icompare(str, 0, str.size(), ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string UTF8::toUpper(const std::string& str)
|
std::string UTF8::toUpper(const std::string& str)
|
||||||
{
|
{
|
||||||
static UTF8Encoding utf8;
|
static UTF8Encoding utf8;
|
||||||
std::string result;
|
std::string result;
|
||||||
TextConverter converter(utf8, utf8);
|
TextConverter converter(utf8, utf8);
|
||||||
converter.convert(str, result, Unicode::toUpper);
|
converter.convert(str, result, Unicode::toUpper);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string& UTF8::toUpperInPlace(std::string& str)
|
std::string& UTF8::toUpperInPlace(std::string& str)
|
||||||
{
|
{
|
||||||
static UTF8Encoding utf8;
|
static UTF8Encoding utf8;
|
||||||
std::string result;
|
std::string result;
|
||||||
TextConverter converter(utf8, utf8);
|
TextConverter converter(utf8, utf8);
|
||||||
converter.convert(str, result, Unicode::toUpper);
|
converter.convert(str, result, Unicode::toUpper);
|
||||||
std::swap(str, result);
|
std::swap(str, result);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string UTF8::toLower(const std::string& str)
|
std::string UTF8::toLower(const std::string& str)
|
||||||
{
|
{
|
||||||
static UTF8Encoding utf8;
|
static UTF8Encoding utf8;
|
||||||
std::string result;
|
std::string result;
|
||||||
TextConverter converter(utf8, utf8);
|
TextConverter converter(utf8, utf8);
|
||||||
converter.convert(str, result, Unicode::toLower);
|
converter.convert(str, result, Unicode::toLower);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string& UTF8::toLowerInPlace(std::string& str)
|
std::string& UTF8::toLowerInPlace(std::string& str)
|
||||||
{
|
{
|
||||||
static UTF8Encoding utf8;
|
static UTF8Encoding utf8;
|
||||||
std::string result;
|
std::string result;
|
||||||
TextConverter converter(utf8, utf8);
|
TextConverter converter(utf8, utf8);
|
||||||
converter.convert(str, result, Unicode::toLower);
|
converter.convert(str, result, Unicode::toLower);
|
||||||
std::swap(str, result);
|
std::swap(str, result);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,94 +1,94 @@
|
|||||||
//
|
//
|
||||||
// Unicode.cpp
|
// Unicode.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/Unicode.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/Unicode.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Text
|
// Package: Text
|
||||||
// Module: Unicode
|
// Module: Unicode
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Unicode.h"
|
#include "Poco/Unicode.h"
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "pcre_internal.h"
|
#include "pcre_internal.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
void Unicode::properties(int ch, CharacterProperties& props)
|
void Unicode::properties(int ch, CharacterProperties& props)
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
int script;
|
int script;
|
||||||
int category = _pcre_ucp_findprop(static_cast<unsigned>(ch), &type, &script);
|
int category = _pcre_ucp_findprop(static_cast<unsigned>(ch), &type, &script);
|
||||||
props.category = static_cast<CharacterCategory>(category);
|
props.category = static_cast<CharacterCategory>(category);
|
||||||
props.type = static_cast<CharacterType>(type);
|
props.type = static_cast<CharacterType>(type);
|
||||||
props.script = static_cast<Script>(script);
|
props.script = static_cast<Script>(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Unicode::isLower(int ch)
|
bool Unicode::isLower(int ch)
|
||||||
{
|
{
|
||||||
CharacterProperties props;
|
CharacterProperties props;
|
||||||
properties(ch, props);
|
properties(ch, props);
|
||||||
return props.category == UCP_LETTER && props.type == UCP_LOWER_CASE_LETTER;
|
return props.category == UCP_LETTER && props.type == UCP_LOWER_CASE_LETTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Unicode::isUpper(int ch)
|
bool Unicode::isUpper(int ch)
|
||||||
{
|
{
|
||||||
CharacterProperties props;
|
CharacterProperties props;
|
||||||
properties(ch, props);
|
properties(ch, props);
|
||||||
return props.category == UCP_LETTER && props.type == UCP_UPPER_CASE_LETTER;
|
return props.category == UCP_LETTER && props.type == UCP_UPPER_CASE_LETTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Unicode::toLower(int ch)
|
int Unicode::toLower(int ch)
|
||||||
{
|
{
|
||||||
if (isUpper(ch))
|
if (isUpper(ch))
|
||||||
return static_cast<int>(_pcre_ucp_othercase(static_cast<unsigned>(ch)));
|
return static_cast<int>(_pcre_ucp_othercase(static_cast<unsigned>(ch)));
|
||||||
else
|
else
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Unicode::toUpper(int ch)
|
int Unicode::toUpper(int ch)
|
||||||
{
|
{
|
||||||
if (isLower(ch))
|
if (isLower(ch))
|
||||||
return static_cast<int>(_pcre_ucp_othercase(static_cast<unsigned>(ch)));
|
return static_cast<int>(_pcre_ucp_othercase(static_cast<unsigned>(ch)));
|
||||||
else
|
else
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,88 +1,88 @@
|
|||||||
//
|
//
|
||||||
// WindowsConsoleChannel.cpp
|
// WindowsConsoleChannel.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/WindowsConsoleChannel.cpp#2 $
|
// $Id: //poco/svn/Foundation/src/WindowsConsoleChannel.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Logging
|
// Package: Logging
|
||||||
// Module: WindowsConsoleChannel
|
// Module: WindowsConsoleChannel
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/WindowsConsoleChannel.h"
|
#include "Poco/WindowsConsoleChannel.h"
|
||||||
#include "Poco/Message.h"
|
#include "Poco/Message.h"
|
||||||
#if defined(POCO_WIN32_UTF8)
|
#if defined(POCO_WIN32_UTF8)
|
||||||
#include "Poco/UnicodeConverter.h"
|
#include "Poco/UnicodeConverter.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
WindowsConsoleChannel::WindowsConsoleChannel():
|
WindowsConsoleChannel::WindowsConsoleChannel():
|
||||||
_isFile(false),
|
_isFile(false),
|
||||||
_hConsole(INVALID_HANDLE_VALUE)
|
_hConsole(INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
// check whether the console has been redirected
|
// check whether the console has been redirected
|
||||||
DWORD mode;
|
DWORD mode;
|
||||||
_isFile = (GetConsoleMode(_hConsole, &mode) == 0);
|
_isFile = (GetConsoleMode(_hConsole, &mode) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WindowsConsoleChannel::~WindowsConsoleChannel()
|
WindowsConsoleChannel::~WindowsConsoleChannel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WindowsConsoleChannel::log(const Message& msg)
|
void WindowsConsoleChannel::log(const Message& msg)
|
||||||
{
|
{
|
||||||
std::string text = msg.getText();
|
std::string text = msg.getText();
|
||||||
text += "\r\n";
|
text += "\r\n";
|
||||||
|
|
||||||
#if defined(POCO_WIN32_UTF8)
|
#if defined(POCO_WIN32_UTF8)
|
||||||
if (_isFile)
|
if (_isFile)
|
||||||
{
|
{
|
||||||
DWORD written;
|
DWORD written;
|
||||||
WriteFile(_hConsole, text.data(), text.size(), &written, NULL);
|
WriteFile(_hConsole, text.data(), text.size(), &written, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::wstring utext;
|
std::wstring utext;
|
||||||
UnicodeConverter::toUTF16(text, utext);
|
UnicodeConverter::toUTF16(text, utext);
|
||||||
DWORD written;
|
DWORD written;
|
||||||
WriteConsoleW(_hConsole, utext.data(), utext.size(), &written, NULL);
|
WriteConsoleW(_hConsole, utext.data(), utext.size(), &written, NULL);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
DWORD written;
|
DWORD written;
|
||||||
WriteFile(_hConsole, text.data(), text.size(), &written, NULL);
|
WriteFile(_hConsole, text.data(), text.size(), &written, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
@@ -1,183 +1,183 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOChannelTest.cpp
|
// AsyncIOChannelTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "AsyncIOChannelTest.h"
|
#include "AsyncIOChannelTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/AsyncStreamChannel.h"
|
#include "Poco/AsyncStreamChannel.h"
|
||||||
#include "Poco/AsyncIOCommand.h"
|
#include "Poco/AsyncIOCommand.h"
|
||||||
#include "Poco/AsyncIOEvent.h"
|
#include "Poco/AsyncIOEvent.h"
|
||||||
#include "Poco/Delegate.h"
|
#include "Poco/Delegate.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
using Poco::AsyncStreamChannel;
|
using Poco::AsyncStreamChannel;
|
||||||
using Poco::AsyncIOCommand;
|
using Poco::AsyncIOCommand;
|
||||||
using Poco::AsyncReadCommand;
|
using Poco::AsyncReadCommand;
|
||||||
using Poco::AsyncWriteCommand;
|
using Poco::AsyncWriteCommand;
|
||||||
using Poco::AsyncSeekCommand;
|
using Poco::AsyncSeekCommand;
|
||||||
using Poco::AsyncIOEvent;
|
using Poco::AsyncIOEvent;
|
||||||
using Poco::ActiveResult;
|
using Poco::ActiveResult;
|
||||||
using Poco::delegate;
|
using Poco::delegate;
|
||||||
|
|
||||||
|
|
||||||
AsyncIOChannelTest::AsyncIOChannelTest(const std::string& name):
|
AsyncIOChannelTest::AsyncIOChannelTest(const std::string& name):
|
||||||
CppUnit::TestCase(name),
|
CppUnit::TestCase(name),
|
||||||
_completed(0),
|
_completed(0),
|
||||||
_failed(0)
|
_failed(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncIOChannelTest::~AsyncIOChannelTest()
|
AsyncIOChannelTest::~AsyncIOChannelTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::testWrite()
|
void AsyncIOChannelTest::testWrite()
|
||||||
{
|
{
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
AsyncStreamChannel channel(str);
|
AsyncStreamChannel channel(str);
|
||||||
channel.enqueue(new AsyncWriteCommand("Hello", 5));
|
channel.enqueue(new AsyncWriteCommand("Hello", 5));
|
||||||
channel.enqueue(new AsyncWriteCommand(", ", 2));
|
channel.enqueue(new AsyncWriteCommand(", ", 2));
|
||||||
ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
|
ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
|
||||||
result.wait();
|
result.wait();
|
||||||
std::string s(str.str());
|
std::string s(str.str());
|
||||||
assert (s == "Hello, world!");
|
assert (s == "Hello, world!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::testRead()
|
void AsyncIOChannelTest::testRead()
|
||||||
{
|
{
|
||||||
std::istringstream istr("Hello, world!");
|
std::istringstream istr("Hello, world!");
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
AsyncStreamChannel channel(istr);
|
AsyncStreamChannel channel(istr);
|
||||||
ActiveResult<int> result = channel.enqueue(new AsyncReadCommand(buffer, sizeof(buffer)));
|
ActiveResult<int> result = channel.enqueue(new AsyncReadCommand(buffer, sizeof(buffer)));
|
||||||
result.wait();
|
result.wait();
|
||||||
std::string s(buffer, result.data());
|
std::string s(buffer, result.data());
|
||||||
assert (s == "Hello, world!");
|
assert (s == "Hello, world!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::testSeek()
|
void AsyncIOChannelTest::testSeek()
|
||||||
{
|
{
|
||||||
std::istringstream istr("Hello, world!");
|
std::istringstream istr("Hello, world!");
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
AsyncStreamChannel channel(istr);
|
AsyncStreamChannel channel(istr);
|
||||||
channel.enqueue(new AsyncSeekCommand(7, std::ios::beg));
|
channel.enqueue(new AsyncSeekCommand(7, std::ios::beg));
|
||||||
ActiveResult<int> result = channel.enqueue(new AsyncReadCommand(buffer, 5));
|
ActiveResult<int> result = channel.enqueue(new AsyncReadCommand(buffer, 5));
|
||||||
result.wait();
|
result.wait();
|
||||||
std::string s(buffer, result.data());
|
std::string s(buffer, result.data());
|
||||||
assert (s == "world");
|
assert (s == "world");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::testEvents()
|
void AsyncIOChannelTest::testEvents()
|
||||||
{
|
{
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
AsyncStreamChannel channel(str);
|
AsyncStreamChannel channel(str);
|
||||||
AsyncIOCommand::Ptr pWrite(new AsyncWriteCommand("Hello, world!", 13));
|
AsyncIOCommand::Ptr pWrite(new AsyncWriteCommand("Hello, world!", 13));
|
||||||
pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||||
channel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
channel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||||
assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
|
assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
|
||||||
ActiveResult<int> result = channel.enqueue(pWrite);
|
ActiveResult<int> result = channel.enqueue(pWrite);
|
||||||
pWrite->wait();
|
pWrite->wait();
|
||||||
result.wait();
|
result.wait();
|
||||||
assert (pWrite->succeeded());
|
assert (pWrite->succeeded());
|
||||||
assert (!pWrite->failed());
|
assert (!pWrite->failed());
|
||||||
assert (pWrite->state() == AsyncIOCommand::CMD_COMPLETED);
|
assert (pWrite->state() == AsyncIOCommand::CMD_COMPLETED);
|
||||||
assert (pWrite->result() == 13);
|
assert (pWrite->result() == 13);
|
||||||
assert (pWrite->exception() == 0);
|
assert (pWrite->exception() == 0);
|
||||||
assert (_completed == 2);
|
assert (_completed == 2);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
std::istringstream istr;
|
std::istringstream istr;
|
||||||
AsyncStreamChannel ichannel(istr);
|
AsyncStreamChannel ichannel(istr);
|
||||||
pWrite = new AsyncWriteCommand("Hello, world!", 13);
|
pWrite = new AsyncWriteCommand("Hello, world!", 13);
|
||||||
pWrite->commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
|
pWrite->commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
|
||||||
ichannel.commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
|
ichannel.commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
|
||||||
pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||||
ichannel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
ichannel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||||
assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
|
assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
|
||||||
result = ichannel.enqueue(pWrite);
|
result = ichannel.enqueue(pWrite);
|
||||||
pWrite->wait();
|
pWrite->wait();
|
||||||
result.wait();
|
result.wait();
|
||||||
assert (!pWrite->succeeded());
|
assert (!pWrite->succeeded());
|
||||||
assert (pWrite->failed());
|
assert (pWrite->failed());
|
||||||
assert (pWrite->exception() != 0);
|
assert (pWrite->exception() != 0);
|
||||||
assert (_completed == 0);
|
assert (_completed == 0);
|
||||||
assert (_failed == 2);
|
assert (_failed == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::setUp()
|
void AsyncIOChannelTest::setUp()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::tearDown()
|
void AsyncIOChannelTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::reset()
|
void AsyncIOChannelTest::reset()
|
||||||
{
|
{
|
||||||
_completed = 0;
|
_completed = 0;
|
||||||
_failed = 0;
|
_failed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::onCompleted(const void* sender, Poco::AsyncIOEvent& event)
|
void AsyncIOChannelTest::onCompleted(const void* sender, Poco::AsyncIOEvent& event)
|
||||||
{
|
{
|
||||||
++_completed;
|
++_completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AsyncIOChannelTest::onFailed(const void* sender, Poco::AsyncIOEvent& event)
|
void AsyncIOChannelTest::onFailed(const void* sender, Poco::AsyncIOEvent& event)
|
||||||
{
|
{
|
||||||
++_failed;
|
++_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* AsyncIOChannelTest::suite()
|
CppUnit::Test* AsyncIOChannelTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOChannelTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOChannelTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testWrite);
|
CppUnit_addTest(pSuite, AsyncIOChannelTest, testWrite);
|
||||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testRead);
|
CppUnit_addTest(pSuite, AsyncIOChannelTest, testRead);
|
||||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testSeek);
|
CppUnit_addTest(pSuite, AsyncIOChannelTest, testSeek);
|
||||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testEvents);
|
CppUnit_addTest(pSuite, AsyncIOChannelTest, testEvents);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,71 +1,71 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOChannelTest.h
|
// AsyncIOChannelTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the AsyncIOChannelTest class.
|
// Definition of the AsyncIOChannelTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef AsyncIOChannelTest_INCLUDED
|
#ifndef AsyncIOChannelTest_INCLUDED
|
||||||
#define AsyncIOChannelTest_INCLUDED
|
#define AsyncIOChannelTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
#include "Poco/AsyncIOEvent.h"
|
#include "Poco/AsyncIOEvent.h"
|
||||||
|
|
||||||
|
|
||||||
class AsyncIOChannelTest: public CppUnit::TestCase
|
class AsyncIOChannelTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsyncIOChannelTest(const std::string& name);
|
AsyncIOChannelTest(const std::string& name);
|
||||||
~AsyncIOChannelTest();
|
~AsyncIOChannelTest();
|
||||||
|
|
||||||
void testWrite();
|
void testWrite();
|
||||||
void testRead();
|
void testRead();
|
||||||
void testSeek();
|
void testSeek();
|
||||||
void testEvents();
|
void testEvents();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void reset();
|
void reset();
|
||||||
void onCompleted(const void* sender, Poco::AsyncIOEvent& event);
|
void onCompleted(const void* sender, Poco::AsyncIOEvent& event);
|
||||||
void onFailed(const void* sender, Poco::AsyncIOEvent& event);
|
void onFailed(const void* sender, Poco::AsyncIOEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _completed;
|
int _completed;
|
||||||
int _failed;
|
int _failed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // AsyncIOChannelTest_INCLUDED
|
#endif // AsyncIOChannelTest_INCLUDED
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOTestSuite.cpp
|
// AsyncIOTestSuite.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "AsyncIOTestSuite.h"
|
#include "AsyncIOTestSuite.h"
|
||||||
#include "AsyncIOChannelTest.h"
|
#include "AsyncIOChannelTest.h"
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* AsyncIOTestSuite::suite()
|
CppUnit::Test* AsyncIOTestSuite::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOTestSuite");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOTestSuite");
|
||||||
|
|
||||||
pSuite->addTest(AsyncIOChannelTest::suite());
|
pSuite->addTest(AsyncIOChannelTest::suite());
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,49 @@
|
|||||||
//
|
//
|
||||||
// AsyncIOTestSuite.h
|
// AsyncIOTestSuite.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the AsyncIOTestSuite class.
|
// Definition of the AsyncIOTestSuite class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef AsyncIOTestSuite_INCLUDED
|
#ifndef AsyncIOTestSuite_INCLUDED
|
||||||
#define AsyncIOTestSuite_INCLUDED
|
#define AsyncIOTestSuite_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
|
|
||||||
|
|
||||||
class AsyncIOTestSuite
|
class AsyncIOTestSuite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // AsyncIOTestSuite_INCLUDED
|
#endif // AsyncIOTestSuite_INCLUDED
|
||||||
|
|||||||
@@ -1,214 +1,214 @@
|
|||||||
//
|
//
|
||||||
// ConditionTest.cpp
|
// ConditionTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/ConditionTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/ConditionTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "ConditionTest.h"
|
#include "ConditionTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
#include "Poco/Runnable.h"
|
#include "Poco/Runnable.h"
|
||||||
#include "Poco/Condition.h"
|
#include "Poco/Condition.h"
|
||||||
#include "Poco/Mutex.h"
|
#include "Poco/Mutex.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
using Poco::Thread;
|
using Poco::Thread;
|
||||||
using Poco::Runnable;
|
using Poco::Runnable;
|
||||||
using Poco::Condition;
|
using Poco::Condition;
|
||||||
using Poco::Mutex;
|
using Poco::Mutex;
|
||||||
using Poco::TimeoutException;
|
using Poco::TimeoutException;
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class WaitRunnable: public Runnable
|
class WaitRunnable: public Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WaitRunnable(Condition& cond, Mutex& mutex):
|
WaitRunnable(Condition& cond, Mutex& mutex):
|
||||||
_ran(false),
|
_ran(false),
|
||||||
_cond(cond),
|
_cond(cond),
|
||||||
_mutex(mutex)
|
_mutex(mutex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
_cond.wait(_mutex);
|
_cond.wait(_mutex);
|
||||||
_mutex.unlock();
|
_mutex.unlock();
|
||||||
_ran = true;
|
_ran = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ran() const
|
bool ran() const
|
||||||
{
|
{
|
||||||
return _ran;
|
return _ran;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _ran;
|
bool _ran;
|
||||||
Condition& _cond;
|
Condition& _cond;
|
||||||
Mutex& _mutex;
|
Mutex& _mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TryWaitRunnable: public Runnable
|
class TryWaitRunnable: public Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TryWaitRunnable(Condition& cond, Mutex& mutex):
|
TryWaitRunnable(Condition& cond, Mutex& mutex):
|
||||||
_ran(false),
|
_ran(false),
|
||||||
_cond(cond),
|
_cond(cond),
|
||||||
_mutex(mutex)
|
_mutex(mutex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
if (_cond.tryWait(_mutex, 10000))
|
if (_cond.tryWait(_mutex, 10000))
|
||||||
{
|
{
|
||||||
_ran = true;
|
_ran = true;
|
||||||
}
|
}
|
||||||
_mutex.unlock();
|
_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ran() const
|
bool ran() const
|
||||||
{
|
{
|
||||||
return _ran;
|
return _ran;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _ran;
|
bool _ran;
|
||||||
Condition& _cond;
|
Condition& _cond;
|
||||||
Mutex& _mutex;
|
Mutex& _mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConditionTest::ConditionTest(const std::string& name): CppUnit::TestCase(name)
|
ConditionTest::ConditionTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConditionTest::~ConditionTest()
|
ConditionTest::~ConditionTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConditionTest::testSignal()
|
void ConditionTest::testSignal()
|
||||||
{
|
{
|
||||||
Condition cond;
|
Condition cond;
|
||||||
Mutex mtx;
|
Mutex mtx;
|
||||||
WaitRunnable r1(cond, mtx);
|
WaitRunnable r1(cond, mtx);
|
||||||
WaitRunnable r2(cond, mtx);
|
WaitRunnable r2(cond, mtx);
|
||||||
|
|
||||||
Thread t1;
|
Thread t1;
|
||||||
Thread t2;
|
Thread t2;
|
||||||
|
|
||||||
t1.start(r1);
|
t1.start(r1);
|
||||||
Thread::sleep(200);
|
Thread::sleep(200);
|
||||||
t2.start(r2);
|
t2.start(r2);
|
||||||
|
|
||||||
assert (!r1.ran());
|
assert (!r1.ran());
|
||||||
assert (!r2.ran());
|
assert (!r2.ran());
|
||||||
|
|
||||||
cond.signal();
|
cond.signal();
|
||||||
|
|
||||||
t1.join();
|
t1.join();
|
||||||
assert (r1.ran());
|
assert (r1.ran());
|
||||||
|
|
||||||
assert (!t2.tryJoin(200));
|
assert (!t2.tryJoin(200));
|
||||||
|
|
||||||
cond.signal();
|
cond.signal();
|
||||||
|
|
||||||
t2.join();
|
t2.join();
|
||||||
|
|
||||||
assert (r2.ran());
|
assert (r2.ran());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConditionTest::testBroadcast()
|
void ConditionTest::testBroadcast()
|
||||||
{
|
{
|
||||||
Condition cond;
|
Condition cond;
|
||||||
Mutex mtx;
|
Mutex mtx;
|
||||||
WaitRunnable r1(cond, mtx);
|
WaitRunnable r1(cond, mtx);
|
||||||
WaitRunnable r2(cond, mtx);
|
WaitRunnable r2(cond, mtx);
|
||||||
TryWaitRunnable r3(cond, mtx);
|
TryWaitRunnable r3(cond, mtx);
|
||||||
|
|
||||||
Thread t1;
|
Thread t1;
|
||||||
Thread t2;
|
Thread t2;
|
||||||
Thread t3;
|
Thread t3;
|
||||||
|
|
||||||
t1.start(r1);
|
t1.start(r1);
|
||||||
Thread::sleep(200);
|
Thread::sleep(200);
|
||||||
t2.start(r2);
|
t2.start(r2);
|
||||||
Thread::sleep(200);
|
Thread::sleep(200);
|
||||||
t3.start(r3);
|
t3.start(r3);
|
||||||
|
|
||||||
assert (!r1.ran());
|
assert (!r1.ran());
|
||||||
assert (!r2.ran());
|
assert (!r2.ran());
|
||||||
assert (!r3.ran());
|
assert (!r3.ran());
|
||||||
|
|
||||||
cond.signal();
|
cond.signal();
|
||||||
t1.join();
|
t1.join();
|
||||||
|
|
||||||
assert (r1.ran());
|
assert (r1.ran());
|
||||||
assert (!t2.tryJoin(500));
|
assert (!t2.tryJoin(500));
|
||||||
assert (!t3.tryJoin(500));
|
assert (!t3.tryJoin(500));
|
||||||
|
|
||||||
cond.broadcast();
|
cond.broadcast();
|
||||||
|
|
||||||
t2.join();
|
t2.join();
|
||||||
t3.join();
|
t3.join();
|
||||||
|
|
||||||
assert (r2.ran());
|
assert (r2.ran());
|
||||||
assert (r3.ran());
|
assert (r3.ran());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConditionTest::setUp()
|
void ConditionTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConditionTest::tearDown()
|
void ConditionTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* ConditionTest::suite()
|
CppUnit::Test* ConditionTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConditionTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConditionTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, ConditionTest, testSignal);
|
CppUnit_addTest(pSuite, ConditionTest, testSignal);
|
||||||
CppUnit_addTest(pSuite, ConditionTest, testBroadcast);
|
CppUnit_addTest(pSuite, ConditionTest, testBroadcast);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +1,61 @@
|
|||||||
//
|
//
|
||||||
// ConditionTest.h
|
// ConditionTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/ConditionTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/ConditionTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the ConditionTest class.
|
// Definition of the ConditionTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef ConditionTest_INCLUDED
|
#ifndef ConditionTest_INCLUDED
|
||||||
#define ConditionTest_INCLUDED
|
#define ConditionTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class ConditionTest: public CppUnit::TestCase
|
class ConditionTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConditionTest(const std::string& name);
|
ConditionTest(const std::string& name);
|
||||||
~ConditionTest();
|
~ConditionTest();
|
||||||
|
|
||||||
void testSignal();
|
void testSignal();
|
||||||
void testBroadcast();
|
void testBroadcast();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // ConditionTest_INCLUDED
|
#endif // ConditionTest_INCLUDED
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,162 +1,162 @@
|
|||||||
//
|
//
|
||||||
// DynamicAnyTest.h
|
// DynamicAnyTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/DynamicAnyTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/DynamicAnyTest.h#2 $
|
||||||
//
|
//
|
||||||
// Tests for Any types
|
// Tests for Any types
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef DynamicAnyTest_INCLUDED
|
#ifndef DynamicAnyTest_INCLUDED
|
||||||
#define DynamicAnyTest_INCLUDED
|
#define DynamicAnyTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/DynamicAny.h"
|
#include "Poco/DynamicAny.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class DynamicAnyTest: public CppUnit::TestCase
|
class DynamicAnyTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DynamicAnyTest(const std::string& name);
|
DynamicAnyTest(const std::string& name);
|
||||||
~DynamicAnyTest();
|
~DynamicAnyTest();
|
||||||
|
|
||||||
void testInt8();
|
void testInt8();
|
||||||
void testInt16();
|
void testInt16();
|
||||||
void testInt32();
|
void testInt32();
|
||||||
void testInt64();
|
void testInt64();
|
||||||
void testUInt8();
|
void testUInt8();
|
||||||
void testUInt16();
|
void testUInt16();
|
||||||
void testUInt32();
|
void testUInt32();
|
||||||
void testUInt64();
|
void testUInt64();
|
||||||
void testBool();
|
void testBool();
|
||||||
void testChar();
|
void testChar();
|
||||||
void testFloat();
|
void testFloat();
|
||||||
void testDouble();
|
void testDouble();
|
||||||
void testLong();
|
void testLong();
|
||||||
void testULong();
|
void testULong();
|
||||||
void testString();
|
void testString();
|
||||||
void testConversionOperator();
|
void testConversionOperator();
|
||||||
void testComparisonOperators();
|
void testComparisonOperators();
|
||||||
void testArithmeticOperators();
|
void testArithmeticOperators();
|
||||||
void testLimitsInt();
|
void testLimitsInt();
|
||||||
void testLimitsFloat();
|
void testLimitsFloat();
|
||||||
void testCtor();
|
void testCtor();
|
||||||
void testIsStruct();
|
void testIsStruct();
|
||||||
void testIsArray();
|
void testIsArray();
|
||||||
void testArrayIdxOperator();
|
void testArrayIdxOperator();
|
||||||
void testDynamicStructBasics();
|
void testDynamicStructBasics();
|
||||||
void testDynamicStruct();
|
void testDynamicStruct();
|
||||||
void testArrayToString();
|
void testArrayToString();
|
||||||
void testStructToString();
|
void testStructToString();
|
||||||
void testArrayOfStructsToString();
|
void testArrayOfStructsToString();
|
||||||
void testStructWithArraysToString();
|
void testStructWithArraysToString();
|
||||||
void testJSONDeserializeString();
|
void testJSONDeserializeString();
|
||||||
void testJSONDeserializePrimitives();
|
void testJSONDeserializePrimitives();
|
||||||
void testJSONDeserializeArray();
|
void testJSONDeserializeArray();
|
||||||
void testJSONDeserializeStruct();
|
void testJSONDeserializeStruct();
|
||||||
void testJSONDeserializeComplex();
|
void testJSONDeserializeComplex();
|
||||||
void testDate();
|
void testDate();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void testGetIdxMustThrow(Poco::DynamicAny& a1, std::vector<Poco::DynamicAny>::size_type n);
|
void testGetIdxMustThrow(Poco::DynamicAny& a1, std::vector<Poco::DynamicAny>::size_type n);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void testGetIdx(Poco::DynamicAny& a1, std::vector<Poco::DynamicAny>::size_type n, const T& expectedResult)
|
void testGetIdx(Poco::DynamicAny& a1, std::vector<Poco::DynamicAny>::size_type n, const T& expectedResult)
|
||||||
{
|
{
|
||||||
Poco::DynamicAny& val1 = a1[n];
|
Poco::DynamicAny& val1 = a1[n];
|
||||||
assert (val1 == expectedResult);
|
assert (val1 == expectedResult);
|
||||||
|
|
||||||
const Poco::DynamicAny& c1 = a1;
|
const Poco::DynamicAny& c1 = a1;
|
||||||
assert (a1 == c1); // silence the compiler
|
assert (a1 == c1); // silence the compiler
|
||||||
const Poco::DynamicAny& cval1 = a1[n];
|
const Poco::DynamicAny& cval1 = a1[n];
|
||||||
assert (cval1 == expectedResult);
|
assert (cval1 == expectedResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename TL, typename TS>
|
template<typename TL, typename TS>
|
||||||
void testLimitsSigned()
|
void testLimitsSigned()
|
||||||
{
|
{
|
||||||
TL iMin = std::numeric_limits<TS>::min();
|
TL iMin = std::numeric_limits<TS>::min();
|
||||||
Poco::DynamicAny da = iMin - 1;
|
Poco::DynamicAny da = iMin - 1;
|
||||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||||
catch (Poco::RangeException&) {}
|
catch (Poco::RangeException&) {}
|
||||||
|
|
||||||
TL iMax = std::numeric_limits<TS>::max();
|
TL iMax = std::numeric_limits<TS>::max();
|
||||||
da = iMax + 1;
|
da = iMax + 1;
|
||||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||||
catch (Poco::RangeException&) {}
|
catch (Poco::RangeException&) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TL, typename TS>
|
template<typename TL, typename TS>
|
||||||
void testLimitsFloatToInt()
|
void testLimitsFloatToInt()
|
||||||
{
|
{
|
||||||
Poco::DynamicAny da;
|
Poco::DynamicAny da;
|
||||||
|
|
||||||
if (std::numeric_limits<TS>::is_signed)
|
if (std::numeric_limits<TS>::is_signed)
|
||||||
{
|
{
|
||||||
TL iMin = static_cast<TL>(std::numeric_limits<TS>::min());
|
TL iMin = static_cast<TL>(std::numeric_limits<TS>::min());
|
||||||
da = iMin * 10;
|
da = iMin * 10;
|
||||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||||
catch (Poco::RangeException&) {}
|
catch (Poco::RangeException&) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
TL iMax = static_cast<TL>(std::numeric_limits<TS>::max());
|
TL iMax = static_cast<TL>(std::numeric_limits<TS>::max());
|
||||||
da = iMax * 10;
|
da = iMax * 10;
|
||||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||||
catch (Poco::RangeException&) {}
|
catch (Poco::RangeException&) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TS, typename TU>
|
template<typename TS, typename TU>
|
||||||
void testLimitsSignedUnsigned()
|
void testLimitsSignedUnsigned()
|
||||||
{
|
{
|
||||||
assert (std::numeric_limits<TS>::is_signed);
|
assert (std::numeric_limits<TS>::is_signed);
|
||||||
assert (!std::numeric_limits<TU>::is_signed);
|
assert (!std::numeric_limits<TU>::is_signed);
|
||||||
|
|
||||||
TS iMin = std::numeric_limits<TS>::min();
|
TS iMin = std::numeric_limits<TS>::min();
|
||||||
Poco::DynamicAny da = iMin;
|
Poco::DynamicAny da = iMin;
|
||||||
try { TU i; i = da.convert<TU>(); fail("must fail"); }
|
try { TU i; i = da.convert<TU>(); fail("must fail"); }
|
||||||
catch (Poco::RangeException&) {}
|
catch (Poco::RangeException&) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TL, typename TS>
|
template<typename TL, typename TS>
|
||||||
void testLimitsUnsigned()
|
void testLimitsUnsigned()
|
||||||
{
|
{
|
||||||
TL iMax = std::numeric_limits<TS>::max();
|
TL iMax = std::numeric_limits<TS>::max();
|
||||||
Poco::DynamicAny da = iMax + 1;
|
Poco::DynamicAny da = iMax + 1;
|
||||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||||
catch (Poco::RangeException&) {}
|
catch (Poco::RangeException&) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // DynamicAnyTest_INCLUDED
|
#endif // DynamicAnyTest_INCLUDED
|
||||||
|
|||||||
@@ -1,333 +1,333 @@
|
|||||||
//
|
//
|
||||||
// FileStreamTest.cpp
|
// FileStreamTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/FileStreamTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/FileStreamTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "FileStreamTest.h"
|
#include "FileStreamTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/FileStream.h"
|
#include "Poco/FileStream.h"
|
||||||
#include "Poco/File.h"
|
#include "Poco/File.h"
|
||||||
#include "Poco/TemporaryFile.h"
|
#include "Poco/TemporaryFile.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
FileStreamTest::FileStreamTest(const std::string& name): CppUnit::TestCase(name)
|
FileStreamTest::FileStreamTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileStreamTest::~FileStreamTest()
|
FileStreamTest::~FileStreamTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testRead()
|
void FileStreamTest::testRead()
|
||||||
{
|
{
|
||||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||||
char tmp[]={'\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
char tmp[]={'\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||||
std::string file(tmp);
|
std::string file(tmp);
|
||||||
file.append(".txt");
|
file.append(".txt");
|
||||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
char tmp[]={'\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
char tmp[]={'\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||||
std::string file(tmp);
|
std::string file(tmp);
|
||||||
file.append(".txt");
|
file.append(".txt");
|
||||||
#else
|
#else
|
||||||
std::string file("testfile.txt");
|
std::string file("testfile.txt");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Poco::TemporaryFile::registerForDeletion(file);
|
Poco::TemporaryFile::registerForDeletion(file);
|
||||||
|
|
||||||
Poco::FileOutputStream fos(file, std::ios::binary);
|
Poco::FileOutputStream fos(file, std::ios::binary);
|
||||||
fos << "sometestdata";
|
fos << "sometestdata";
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
Poco::FileInputStream fis(file);
|
Poco::FileInputStream fis(file);
|
||||||
assert (fis.good());
|
assert (fis.good());
|
||||||
std::string read;
|
std::string read;
|
||||||
fis >> read;
|
fis >> read;
|
||||||
assert (!read.empty());
|
assert (!read.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testWrite()
|
void FileStreamTest::testWrite()
|
||||||
{
|
{
|
||||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||||
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||||
std::string file(tmp);
|
std::string file(tmp);
|
||||||
file = "dummy_" + file + (".txt");
|
file = "dummy_" + file + (".txt");
|
||||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||||
std::string file(tmp);
|
std::string file(tmp);
|
||||||
file = "dummy_" + file + ".txt";
|
file = "dummy_" + file + ".txt";
|
||||||
#else
|
#else
|
||||||
std::string file("dummy_file.txt");
|
std::string file("dummy_file.txt");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Poco::TemporaryFile::registerForDeletion(file);
|
Poco::TemporaryFile::registerForDeletion(file);
|
||||||
|
|
||||||
Poco::FileOutputStream fos(file);
|
Poco::FileOutputStream fos(file);
|
||||||
assert (fos.good());
|
assert (fos.good());
|
||||||
fos << "hiho";
|
fos << "hiho";
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
Poco::FileInputStream fis(file);
|
Poco::FileInputStream fis(file);
|
||||||
assert (fis.good());
|
assert (fis.good());
|
||||||
std::string read;
|
std::string read;
|
||||||
fis >> read;
|
fis >> read;
|
||||||
assert (read == "hiho");
|
assert (read == "hiho");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testReadWrite()
|
void FileStreamTest::testReadWrite()
|
||||||
{
|
{
|
||||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||||
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||||
std::string file(tmp);
|
std::string file(tmp);
|
||||||
file = "dummy_" + file + (".txt");
|
file = "dummy_" + file + (".txt");
|
||||||
#else
|
#else
|
||||||
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||||
std::string file(tmp);
|
std::string file(tmp);
|
||||||
file = "dummy_" + file + ".txt";
|
file = "dummy_" + file + ".txt";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Poco::TemporaryFile::registerForDeletion(file);
|
Poco::TemporaryFile::registerForDeletion(file);
|
||||||
|
|
||||||
Poco::FileStream fos(file);
|
Poco::FileStream fos(file);
|
||||||
assert (fos.good());
|
assert (fos.good());
|
||||||
fos << "hiho";
|
fos << "hiho";
|
||||||
fos.seekg(0, std::ios::beg);
|
fos.seekg(0, std::ios::beg);
|
||||||
std::string read;
|
std::string read;
|
||||||
fos >> read;
|
fos >> read;
|
||||||
assert (read == "hiho");
|
assert (read == "hiho");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testOpen()
|
void FileStreamTest::testOpen()
|
||||||
{
|
{
|
||||||
Poco::FileOutputStream ostr;
|
Poco::FileOutputStream ostr;
|
||||||
ostr.open("test.txt", std::ios::out);
|
ostr.open("test.txt", std::ios::out);
|
||||||
assert (ostr.good());
|
assert (ostr.good());
|
||||||
ostr.close();
|
ostr.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testOpenModeIn()
|
void FileStreamTest::testOpenModeIn()
|
||||||
{
|
{
|
||||||
Poco::File f("nonexistent.txt");
|
Poco::File f("nonexistent.txt");
|
||||||
if (f.exists())
|
if (f.exists())
|
||||||
f.remove();
|
f.remove();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Poco::FileInputStream istr("nonexistent.txt");
|
Poco::FileInputStream istr("nonexistent.txt");
|
||||||
fail("nonexistent file - must throw");
|
fail("nonexistent file - must throw");
|
||||||
}
|
}
|
||||||
catch (Poco::Exception&)
|
catch (Poco::Exception&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
f.createFile();
|
f.createFile();
|
||||||
Poco::FileInputStream istr("nonexistent.txt");
|
Poco::FileInputStream istr("nonexistent.txt");
|
||||||
assert (istr.good());
|
assert (istr.good());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testOpenModeOut()
|
void FileStreamTest::testOpenModeOut()
|
||||||
{
|
{
|
||||||
Poco::File f("test.txt");
|
Poco::File f("test.txt");
|
||||||
if (f.exists())
|
if (f.exists())
|
||||||
f.remove();
|
f.remove();
|
||||||
|
|
||||||
Poco::FileOutputStream ostr1("test.txt");
|
Poco::FileOutputStream ostr1("test.txt");
|
||||||
ostr1 << "Hello, world!";
|
ostr1 << "Hello, world!";
|
||||||
ostr1.close();
|
ostr1.close();
|
||||||
|
|
||||||
assert (f.exists());
|
assert (f.exists());
|
||||||
assert (f.getSize() != 0);
|
assert (f.getSize() != 0);
|
||||||
|
|
||||||
Poco::FileStream str1("test.txt");
|
Poco::FileStream str1("test.txt");
|
||||||
str1.close();
|
str1.close();
|
||||||
|
|
||||||
assert (f.exists());
|
assert (f.exists());
|
||||||
assert (f.getSize() != 0);
|
assert (f.getSize() != 0);
|
||||||
|
|
||||||
Poco::FileOutputStream ostr2("test.txt");
|
Poco::FileOutputStream ostr2("test.txt");
|
||||||
ostr2.close();
|
ostr2.close();
|
||||||
|
|
||||||
assert (f.exists());
|
assert (f.exists());
|
||||||
assert (f.getSize() == 0);
|
assert (f.getSize() == 0);
|
||||||
|
|
||||||
f.remove();
|
f.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testOpenModeTrunc()
|
void FileStreamTest::testOpenModeTrunc()
|
||||||
{
|
{
|
||||||
Poco::File f("test.txt");
|
Poco::File f("test.txt");
|
||||||
if (f.exists())
|
if (f.exists())
|
||||||
f.remove();
|
f.remove();
|
||||||
|
|
||||||
Poco::FileOutputStream ostr1("test.txt");
|
Poco::FileOutputStream ostr1("test.txt");
|
||||||
ostr1 << "Hello, world!";
|
ostr1 << "Hello, world!";
|
||||||
ostr1.close();
|
ostr1.close();
|
||||||
|
|
||||||
assert (f.exists());
|
assert (f.exists());
|
||||||
assert (f.getSize() != 0);
|
assert (f.getSize() != 0);
|
||||||
|
|
||||||
Poco::FileStream str1("test.txt", std::ios::trunc);
|
Poco::FileStream str1("test.txt", std::ios::trunc);
|
||||||
str1.close();
|
str1.close();
|
||||||
|
|
||||||
assert (f.exists());
|
assert (f.exists());
|
||||||
assert (f.getSize() == 0);
|
assert (f.getSize() == 0);
|
||||||
|
|
||||||
f.remove();
|
f.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testOpenModeAte()
|
void FileStreamTest::testOpenModeAte()
|
||||||
{
|
{
|
||||||
Poco::FileOutputStream ostr("test.txt");
|
Poco::FileOutputStream ostr("test.txt");
|
||||||
ostr << "0123456789";
|
ostr << "0123456789";
|
||||||
ostr.close();
|
ostr.close();
|
||||||
|
|
||||||
Poco::FileStream str1("test.txt", std::ios::ate);
|
Poco::FileStream str1("test.txt", std::ios::ate);
|
||||||
int c = str1.get();
|
int c = str1.get();
|
||||||
assert (str1.eof());
|
assert (str1.eof());
|
||||||
|
|
||||||
str1.clear();
|
str1.clear();
|
||||||
str1.seekg(0);
|
str1.seekg(0);
|
||||||
c = str1.get();
|
c = str1.get();
|
||||||
assert (c == '0');
|
assert (c == '0');
|
||||||
|
|
||||||
str1.close();
|
str1.close();
|
||||||
|
|
||||||
Poco::FileStream str2("test.txt", std::ios::ate);
|
Poco::FileStream str2("test.txt", std::ios::ate);
|
||||||
str2 << "abcdef";
|
str2 << "abcdef";
|
||||||
str2.seekg(0);
|
str2.seekg(0);
|
||||||
std::string s;
|
std::string s;
|
||||||
str2 >> s;
|
str2 >> s;
|
||||||
assert (s == "0123456789abcdef");
|
assert (s == "0123456789abcdef");
|
||||||
str2.close();
|
str2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testOpenModeApp()
|
void FileStreamTest::testOpenModeApp()
|
||||||
{
|
{
|
||||||
Poco::FileOutputStream ostr("test.txt");
|
Poco::FileOutputStream ostr("test.txt");
|
||||||
ostr << "0123456789";
|
ostr << "0123456789";
|
||||||
ostr.close();
|
ostr.close();
|
||||||
|
|
||||||
Poco::FileStream str1("test.txt", std::ios::app);
|
Poco::FileStream str1("test.txt", std::ios::app);
|
||||||
|
|
||||||
str1 << "abc";
|
str1 << "abc";
|
||||||
|
|
||||||
str1.seekp(0);
|
str1.seekp(0);
|
||||||
|
|
||||||
str1 << "def";
|
str1 << "def";
|
||||||
|
|
||||||
str1.close();
|
str1.close();
|
||||||
|
|
||||||
Poco::FileInputStream istr("test.txt");
|
Poco::FileInputStream istr("test.txt");
|
||||||
std::string s;
|
std::string s;
|
||||||
istr >> s;
|
istr >> s;
|
||||||
assert (s == "0123456789abcdef");
|
assert (s == "0123456789abcdef");
|
||||||
istr.close();
|
istr.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::testSeek()
|
void FileStreamTest::testSeek()
|
||||||
{
|
{
|
||||||
Poco::FileStream str("test.txt", std::ios::trunc);
|
Poco::FileStream str("test.txt", std::ios::trunc);
|
||||||
str << "0123456789abcdef";
|
str << "0123456789abcdef";
|
||||||
|
|
||||||
str.seekg(0);
|
str.seekg(0);
|
||||||
int c = str.get();
|
int c = str.get();
|
||||||
assert (c == '0');
|
assert (c == '0');
|
||||||
|
|
||||||
str.seekg(10);
|
str.seekg(10);
|
||||||
assert (str.tellg() == std::streampos(10));
|
assert (str.tellg() == std::streampos(10));
|
||||||
c = str.get();
|
c = str.get();
|
||||||
assert (c == 'a');
|
assert (c == 'a');
|
||||||
assert (str.tellg() == std::streampos(11));
|
assert (str.tellg() == std::streampos(11));
|
||||||
|
|
||||||
str.seekg(-1, std::ios::end);
|
str.seekg(-1, std::ios::end);
|
||||||
assert (str.tellg() == std::streampos(15));
|
assert (str.tellg() == std::streampos(15));
|
||||||
c = str.get();
|
c = str.get();
|
||||||
assert (c == 'f');
|
assert (c == 'f');
|
||||||
assert (str.tellg() == std::streampos(16));
|
assert (str.tellg() == std::streampos(16));
|
||||||
|
|
||||||
str.seekg(-1, std::ios::cur);
|
str.seekg(-1, std::ios::cur);
|
||||||
assert (str.tellg() == std::streampos(15));
|
assert (str.tellg() == std::streampos(15));
|
||||||
c = str.get();
|
c = str.get();
|
||||||
assert (c == 'f');
|
assert (c == 'f');
|
||||||
assert (str.tellg() == std::streampos(16));
|
assert (str.tellg() == std::streampos(16));
|
||||||
|
|
||||||
str.seekg(-4, std::ios::cur);
|
str.seekg(-4, std::ios::cur);
|
||||||
assert (str.tellg() == std::streampos(12));
|
assert (str.tellg() == std::streampos(12));
|
||||||
c = str.get();
|
c = str.get();
|
||||||
assert (c == 'c');
|
assert (c == 'c');
|
||||||
assert (str.tellg() == std::streampos(13));
|
assert (str.tellg() == std::streampos(13));
|
||||||
|
|
||||||
str.seekg(1, std::ios::cur);
|
str.seekg(1, std::ios::cur);
|
||||||
assert (str.tellg() == std::streampos(14));
|
assert (str.tellg() == std::streampos(14));
|
||||||
c = str.get();
|
c = str.get();
|
||||||
assert (c == 'e');
|
assert (c == 'e');
|
||||||
assert (str.tellg() == std::streampos(15));
|
assert (str.tellg() == std::streampos(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::setUp()
|
void FileStreamTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileStreamTest::tearDown()
|
void FileStreamTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* FileStreamTest::suite()
|
CppUnit::Test* FileStreamTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FileStreamTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FileStreamTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testRead);
|
CppUnit_addTest(pSuite, FileStreamTest, testRead);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testWrite);
|
CppUnit_addTest(pSuite, FileStreamTest, testWrite);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testReadWrite);
|
CppUnit_addTest(pSuite, FileStreamTest, testReadWrite);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testOpen);
|
CppUnit_addTest(pSuite, FileStreamTest, testOpen);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeIn);
|
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeIn);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeOut);
|
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeOut);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeTrunc);
|
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeTrunc);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeAte);
|
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeAte);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeApp);
|
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeApp);
|
||||||
CppUnit_addTest(pSuite, FileStreamTest, testSeek);
|
CppUnit_addTest(pSuite, FileStreamTest, testSeek);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +1,69 @@
|
|||||||
//
|
//
|
||||||
// FileStreamTest.h
|
// FileStreamTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/FileStreamTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/FileStreamTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the FileStreamTest class.
|
// Definition of the FileStreamTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef FileStreamTest_INCLUDED
|
#ifndef FileStreamTest_INCLUDED
|
||||||
#define FileStreamTest_INCLUDED
|
#define FileStreamTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class FileStreamTest: public CppUnit::TestCase
|
class FileStreamTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileStreamTest(const std::string& name);
|
FileStreamTest(const std::string& name);
|
||||||
~FileStreamTest();
|
~FileStreamTest();
|
||||||
|
|
||||||
void testRead();
|
void testRead();
|
||||||
void testWrite();
|
void testWrite();
|
||||||
void testReadWrite();
|
void testReadWrite();
|
||||||
void testOpen();
|
void testOpen();
|
||||||
void testOpenModeIn();
|
void testOpenModeIn();
|
||||||
void testOpenModeOut();
|
void testOpenModeOut();
|
||||||
void testOpenModeTrunc();
|
void testOpenModeTrunc();
|
||||||
void testOpenModeAte();
|
void testOpenModeAte();
|
||||||
void testOpenModeApp();
|
void testOpenModeApp();
|
||||||
void testSeek();
|
void testSeek();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // FileStreamTest_INCLUDED
|
#endif // FileStreamTest_INCLUDED
|
||||||
|
|||||||
@@ -1,242 +1,242 @@
|
|||||||
//
|
//
|
||||||
// HashMapTest.cpp
|
// HashMapTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/HashMapTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/HashMapTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "HashMapTest.h"
|
#include "HashMapTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/HashMap.h"
|
#include "Poco/HashMap.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
using Poco::HashMap;
|
using Poco::HashMap;
|
||||||
|
|
||||||
|
|
||||||
HashMapTest::HashMapTest(const std::string& name): CppUnit::TestCase(name)
|
HashMapTest::HashMapTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HashMapTest::~HashMapTest()
|
HashMapTest::~HashMapTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashMapTest::testInsert()
|
void HashMapTest::testInsert()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
typedef HashMap<int, int> IntMap;
|
typedef HashMap<int, int> IntMap;
|
||||||
IntMap hm;
|
IntMap hm;
|
||||||
|
|
||||||
assert (hm.empty());
|
assert (hm.empty());
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, i*2));
|
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, i*2));
|
||||||
assert (res.first->first == i);
|
assert (res.first->first == i);
|
||||||
assert (res.first->second == i*2);
|
assert (res.first->second == i*2);
|
||||||
assert (res.second);
|
assert (res.second);
|
||||||
IntMap::Iterator it = hm.find(i);
|
IntMap::Iterator it = hm.find(i);
|
||||||
assert (it != hm.end());
|
assert (it != hm.end());
|
||||||
assert (it->first == i);
|
assert (it->first == i);
|
||||||
assert (it->second == i*2);
|
assert (it->second == i*2);
|
||||||
assert (hm.size() == i + 1);
|
assert (hm.size() == i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (!hm.empty());
|
assert (!hm.empty());
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
IntMap::Iterator it = hm.find(i);
|
IntMap::Iterator it = hm.find(i);
|
||||||
assert (it != hm.end());
|
assert (it != hm.end());
|
||||||
assert (it->first == i);
|
assert (it->first == i);
|
||||||
assert (it->second == i*2);
|
assert (it->second == i*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, 0));
|
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, 0));
|
||||||
assert (res.first->first == i);
|
assert (res.first->first == i);
|
||||||
assert (res.first->second == i*2);
|
assert (res.first->second == i*2);
|
||||||
assert (!res.second);
|
assert (!res.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashMapTest::testErase()
|
void HashMapTest::testErase()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
typedef HashMap<int, int> IntMap;
|
typedef HashMap<int, int> IntMap;
|
||||||
IntMap hm;
|
IntMap hm;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
hm.insert(IntMap::ValueType(i, i*2));
|
hm.insert(IntMap::ValueType(i, i*2));
|
||||||
}
|
}
|
||||||
assert (hm.size() == N);
|
assert (hm.size() == N);
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
hm.erase(i);
|
hm.erase(i);
|
||||||
IntMap::Iterator it = hm.find(i);
|
IntMap::Iterator it = hm.find(i);
|
||||||
assert (it == hm.end());
|
assert (it == hm.end());
|
||||||
}
|
}
|
||||||
assert (hm.size() == N/2);
|
assert (hm.size() == N/2);
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
IntMap::Iterator it = hm.find(i);
|
IntMap::Iterator it = hm.find(i);
|
||||||
assert (it == hm.end());
|
assert (it == hm.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < N; i += 2)
|
for (int i = 1; i < N; i += 2)
|
||||||
{
|
{
|
||||||
IntMap::Iterator it = hm.find(i);
|
IntMap::Iterator it = hm.find(i);
|
||||||
assert (it != hm.end());
|
assert (it != hm.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
hm.insert(IntMap::ValueType(i, i*2));
|
hm.insert(IntMap::ValueType(i, i*2));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
IntMap::Iterator it = hm.find(i);
|
IntMap::Iterator it = hm.find(i);
|
||||||
assert (it != hm.end());
|
assert (it != hm.end());
|
||||||
assert (it->first == i);
|
assert (it->first == i);
|
||||||
assert (it->second == i*2);
|
assert (it->second == i*2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashMapTest::testIterator()
|
void HashMapTest::testIterator()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
typedef HashMap<int, int> IntMap;
|
typedef HashMap<int, int> IntMap;
|
||||||
IntMap hm;
|
IntMap hm;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
hm.insert(IntMap::ValueType(i, i*2));
|
hm.insert(IntMap::ValueType(i, i*2));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, int> values;
|
std::map<int, int> values;
|
||||||
IntMap::Iterator it = hm.begin();
|
IntMap::Iterator it = hm.begin();
|
||||||
while (it != hm.end())
|
while (it != hm.end())
|
||||||
{
|
{
|
||||||
assert (values.find(it->first) == values.end());
|
assert (values.find(it->first) == values.end());
|
||||||
values[it->first] = it->second;
|
values[it->first] = it->second;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (values.size() == N);
|
assert (values.size() == N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashMapTest::testConstIterator()
|
void HashMapTest::testConstIterator()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
typedef HashMap<int, int> IntMap;
|
typedef HashMap<int, int> IntMap;
|
||||||
IntMap hm;
|
IntMap hm;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
hm.insert(IntMap::ValueType(i, i*2));
|
hm.insert(IntMap::ValueType(i, i*2));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, int> values;
|
std::map<int, int> values;
|
||||||
IntMap::ConstIterator it = hm.begin();
|
IntMap::ConstIterator it = hm.begin();
|
||||||
while (it != hm.end())
|
while (it != hm.end())
|
||||||
{
|
{
|
||||||
assert (values.find(it->first) == values.end());
|
assert (values.find(it->first) == values.end());
|
||||||
values[it->first] = it->second;
|
values[it->first] = it->second;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (values.size() == N);
|
assert (values.size() == N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashMapTest::testIndex()
|
void HashMapTest::testIndex()
|
||||||
{
|
{
|
||||||
typedef HashMap<int, int> IntMap;
|
typedef HashMap<int, int> IntMap;
|
||||||
IntMap hm;
|
IntMap hm;
|
||||||
|
|
||||||
hm[1] = 2;
|
hm[1] = 2;
|
||||||
hm[2] = 4;
|
hm[2] = 4;
|
||||||
hm[3] = 6;
|
hm[3] = 6;
|
||||||
|
|
||||||
assert (hm.size() == 3);
|
assert (hm.size() == 3);
|
||||||
assert (hm[1] == 2);
|
assert (hm[1] == 2);
|
||||||
assert (hm[2] == 4);
|
assert (hm[2] == 4);
|
||||||
assert (hm[3] == 6);
|
assert (hm[3] == 6);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const IntMap& im = hm;
|
const IntMap& im = hm;
|
||||||
int x = im[4];
|
int x = im[4];
|
||||||
fail("no such key - must throw");
|
fail("no such key - must throw");
|
||||||
}
|
}
|
||||||
catch (Poco::NotFoundException&)
|
catch (Poco::NotFoundException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashMapTest::setUp()
|
void HashMapTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashMapTest::tearDown()
|
void HashMapTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* HashMapTest::suite()
|
CppUnit::Test* HashMapTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashMapTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashMapTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, HashMapTest, testInsert);
|
CppUnit_addTest(pSuite, HashMapTest, testInsert);
|
||||||
CppUnit_addTest(pSuite, HashMapTest, testErase);
|
CppUnit_addTest(pSuite, HashMapTest, testErase);
|
||||||
CppUnit_addTest(pSuite, HashMapTest, testIterator);
|
CppUnit_addTest(pSuite, HashMapTest, testIterator);
|
||||||
CppUnit_addTest(pSuite, HashMapTest, testConstIterator);
|
CppUnit_addTest(pSuite, HashMapTest, testConstIterator);
|
||||||
CppUnit_addTest(pSuite, HashMapTest, testIndex);
|
CppUnit_addTest(pSuite, HashMapTest, testIndex);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +1,64 @@
|
|||||||
//
|
//
|
||||||
// HashMapTest.h
|
// HashMapTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/HashMapTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/HashMapTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the HashMapTest class.
|
// Definition of the HashMapTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef HashMapTest_INCLUDED
|
#ifndef HashMapTest_INCLUDED
|
||||||
#define HashMapTest_INCLUDED
|
#define HashMapTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class HashMapTest: public CppUnit::TestCase
|
class HashMapTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HashMapTest(const std::string& name);
|
HashMapTest(const std::string& name);
|
||||||
~HashMapTest();
|
~HashMapTest();
|
||||||
|
|
||||||
void testInsert();
|
void testInsert();
|
||||||
void testErase();
|
void testErase();
|
||||||
void testIterator();
|
void testIterator();
|
||||||
void testConstIterator();
|
void testConstIterator();
|
||||||
void testIndex();
|
void testIndex();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // HashMapTest_INCLUDED
|
#endif // HashMapTest_INCLUDED
|
||||||
|
|||||||
@@ -1,205 +1,205 @@
|
|||||||
//
|
//
|
||||||
// HashSetTest.cpp
|
// HashSetTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "HashSetTest.h"
|
#include "HashSetTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/HashSet.h"
|
#include "Poco/HashSet.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
using Poco::HashSet;
|
using Poco::HashSet;
|
||||||
|
|
||||||
|
|
||||||
HashSetTest::HashSetTest(const std::string& name): CppUnit::TestCase(name)
|
HashSetTest::HashSetTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HashSetTest::~HashSetTest()
|
HashSetTest::~HashSetTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashSetTest::testInsert()
|
void HashSetTest::testInsert()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
HashSet<int> hs;
|
HashSet<int> hs;
|
||||||
|
|
||||||
assert (hs.empty());
|
assert (hs.empty());
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i);
|
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i);
|
||||||
assert (*res.first == i);
|
assert (*res.first == i);
|
||||||
assert (res.second);
|
assert (res.second);
|
||||||
HashSet<int>::Iterator it = hs.find(i);
|
HashSet<int>::Iterator it = hs.find(i);
|
||||||
assert (it != hs.end());
|
assert (it != hs.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
assert (hs.size() == i + 1);
|
assert (hs.size() == i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (!hs.empty());
|
assert (!hs.empty());
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
HashSet<int>::Iterator it = hs.find(i);
|
HashSet<int>::Iterator it = hs.find(i);
|
||||||
assert (it != hs.end());
|
assert (it != hs.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i);
|
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i);
|
||||||
assert (*res.first == i);
|
assert (*res.first == i);
|
||||||
assert (!res.second);
|
assert (!res.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashSetTest::testErase()
|
void HashSetTest::testErase()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
HashSet<int> hs;
|
HashSet<int> hs;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
hs.insert(i);
|
hs.insert(i);
|
||||||
}
|
}
|
||||||
assert (hs.size() == N);
|
assert (hs.size() == N);
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
hs.erase(i);
|
hs.erase(i);
|
||||||
HashSet<int>::Iterator it = hs.find(i);
|
HashSet<int>::Iterator it = hs.find(i);
|
||||||
assert (it == hs.end());
|
assert (it == hs.end());
|
||||||
}
|
}
|
||||||
assert (hs.size() == N/2);
|
assert (hs.size() == N/2);
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
HashSet<int>::Iterator it = hs.find(i);
|
HashSet<int>::Iterator it = hs.find(i);
|
||||||
assert (it == hs.end());
|
assert (it == hs.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < N; i += 2)
|
for (int i = 1; i < N; i += 2)
|
||||||
{
|
{
|
||||||
HashSet<int>::Iterator it = hs.find(i);
|
HashSet<int>::Iterator it = hs.find(i);
|
||||||
assert (it != hs.end());
|
assert (it != hs.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
hs.insert(i);
|
hs.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
HashSet<int>::Iterator it = hs.find(i);
|
HashSet<int>::Iterator it = hs.find(i);
|
||||||
assert (it != hs.end());
|
assert (it != hs.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashSetTest::testIterator()
|
void HashSetTest::testIterator()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
HashSet<int> hs;
|
HashSet<int> hs;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
hs.insert(i);
|
hs.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<int> values;
|
std::set<int> values;
|
||||||
HashSet<int>::Iterator it = hs.begin();
|
HashSet<int>::Iterator it = hs.begin();
|
||||||
while (it != hs.end())
|
while (it != hs.end())
|
||||||
{
|
{
|
||||||
assert (values.find(*it) == values.end());
|
assert (values.find(*it) == values.end());
|
||||||
values.insert(*it);
|
values.insert(*it);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (values.size() == N);
|
assert (values.size() == N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashSetTest::testConstIterator()
|
void HashSetTest::testConstIterator()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
HashSet<int> hs;
|
HashSet<int> hs;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
hs.insert(i);
|
hs.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<int> values;
|
std::set<int> values;
|
||||||
HashSet<int>::ConstIterator it = hs.begin();
|
HashSet<int>::ConstIterator it = hs.begin();
|
||||||
while (it != hs.end())
|
while (it != hs.end())
|
||||||
{
|
{
|
||||||
assert (values.find(*it) == values.end());
|
assert (values.find(*it) == values.end());
|
||||||
values.insert(*it);
|
values.insert(*it);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (values.size() == N);
|
assert (values.size() == N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashSetTest::setUp()
|
void HashSetTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashSetTest::tearDown()
|
void HashSetTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* HashSetTest::suite()
|
CppUnit::Test* HashSetTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashSetTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashSetTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, HashSetTest, testInsert);
|
CppUnit_addTest(pSuite, HashSetTest, testInsert);
|
||||||
CppUnit_addTest(pSuite, HashSetTest, testErase);
|
CppUnit_addTest(pSuite, HashSetTest, testErase);
|
||||||
CppUnit_addTest(pSuite, HashSetTest, testIterator);
|
CppUnit_addTest(pSuite, HashSetTest, testIterator);
|
||||||
CppUnit_addTest(pSuite, HashSetTest, testConstIterator);
|
CppUnit_addTest(pSuite, HashSetTest, testConstIterator);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +1,63 @@
|
|||||||
//
|
//
|
||||||
// HashSetTest.h
|
// HashSetTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the HashSetTest class.
|
// Definition of the HashSetTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef HashSetTest_INCLUDED
|
#ifndef HashSetTest_INCLUDED
|
||||||
#define HashSetTest_INCLUDED
|
#define HashSetTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class HashSetTest: public CppUnit::TestCase
|
class HashSetTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HashSetTest(const std::string& name);
|
HashSetTest(const std::string& name);
|
||||||
~HashSetTest();
|
~HashSetTest();
|
||||||
|
|
||||||
void testInsert();
|
void testInsert();
|
||||||
void testErase();
|
void testErase();
|
||||||
void testIterator();
|
void testIterator();
|
||||||
void testConstIterator();
|
void testConstIterator();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // HashSetTest_INCLUDED
|
#endif // HashSetTest_INCLUDED
|
||||||
|
|||||||
@@ -1,224 +1,224 @@
|
|||||||
//
|
//
|
||||||
// HashTableTest.cpp
|
// HashTableTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/HashTableTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/HashTableTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "HashTableTest.h"
|
#include "HashTableTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/HashTable.h"
|
#include "Poco/HashTable.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
|
|
||||||
|
|
||||||
HashTableTest::HashTableTest(const std::string& name): CppUnit::TestCase(name)
|
HashTableTest::HashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HashTableTest::~HashTableTest()
|
HashTableTest::~HashTableTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTableTest::testInsert()
|
void HashTableTest::testInsert()
|
||||||
{
|
{
|
||||||
std::string s1("str1");
|
std::string s1("str1");
|
||||||
std::string s2("str2");
|
std::string s2("str2");
|
||||||
HashTable<std::string, int> hashTable;
|
HashTable<std::string, int> hashTable;
|
||||||
assert (!hashTable.exists(s1));
|
assert (!hashTable.exists(s1));
|
||||||
hashTable.insert(s1, 13);
|
hashTable.insert(s1, 13);
|
||||||
assert (hashTable.exists(s1));
|
assert (hashTable.exists(s1));
|
||||||
assert (hashTable.get(s1) == 13);
|
assert (hashTable.get(s1) == 13);
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
|
|
||||||
assert (hashTable.get(s1, retVal));
|
assert (hashTable.get(s1, retVal));
|
||||||
assert (retVal == 13);
|
assert (retVal == 13);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hashTable.insert(s1, 22);
|
hashTable.insert(s1, 22);
|
||||||
failmsg ("duplicate insert must fail");
|
failmsg ("duplicate insert must fail");
|
||||||
}
|
}
|
||||||
catch (Exception&){}
|
catch (Exception&){}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hashTable.get(s2);
|
hashTable.get(s2);
|
||||||
failmsg ("getting a non inserted item must fail");
|
failmsg ("getting a non inserted item must fail");
|
||||||
}
|
}
|
||||||
catch (Exception&){}
|
catch (Exception&){}
|
||||||
|
|
||||||
assert (!hashTable.exists(s2));
|
assert (!hashTable.exists(s2));
|
||||||
hashTable.insert(s2, 13);
|
hashTable.insert(s2, 13);
|
||||||
assert (hashTable.exists(s2));
|
assert (hashTable.exists(s2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTableTest::testUpdate()
|
void HashTableTest::testUpdate()
|
||||||
{
|
{
|
||||||
// add code for second test here
|
// add code for second test here
|
||||||
std::string s1("str1");
|
std::string s1("str1");
|
||||||
std::string s2("str2");
|
std::string s2("str2");
|
||||||
HashTable<std::string, int> hashTable;
|
HashTable<std::string, int> hashTable;
|
||||||
hashTable.insert(s1, 13);
|
hashTable.insert(s1, 13);
|
||||||
hashTable.update(s1, 14);
|
hashTable.update(s1, 14);
|
||||||
assert (hashTable.exists(s1));
|
assert (hashTable.exists(s1));
|
||||||
assert (hashTable.get(s1) == 14);
|
assert (hashTable.get(s1) == 14);
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
|
|
||||||
assert (hashTable.get(s1, retVal));
|
assert (hashTable.get(s1, retVal));
|
||||||
assert (retVal == 14);
|
assert (retVal == 14);
|
||||||
|
|
||||||
// updating a non existing item must work too
|
// updating a non existing item must work too
|
||||||
hashTable.update(s2, 15);
|
hashTable.update(s2, 15);
|
||||||
assert (hashTable.get(s2) == 15);
|
assert (hashTable.get(s2) == 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTableTest::testOverflow()
|
void HashTableTest::testOverflow()
|
||||||
{
|
{
|
||||||
HashTable<std::string, int> hashTable(13);
|
HashTable<std::string, int> hashTable(13);
|
||||||
for (int i = 0; i < 1024; ++i)
|
for (int i = 0; i < 1024; ++i)
|
||||||
{
|
{
|
||||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 1024; ++i)
|
for (int i = 0; i < 1024; ++i)
|
||||||
{
|
{
|
||||||
std::string tmp = Poco::NumberFormatter::format(i);
|
std::string tmp = Poco::NumberFormatter::format(i);
|
||||||
assert (hashTable.exists(tmp));
|
assert (hashTable.exists(tmp));
|
||||||
assert (hashTable.get(tmp) == i*i);
|
assert (hashTable.get(tmp) == i*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTableTest::testSize()
|
void HashTableTest::testSize()
|
||||||
{
|
{
|
||||||
HashTable<std::string, int> hashTable(13);
|
HashTable<std::string, int> hashTable(13);
|
||||||
assert (hashTable.size() == 0);
|
assert (hashTable.size() == 0);
|
||||||
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
||||||
assert (hashTable.size() == 1);
|
assert (hashTable.size() == 1);
|
||||||
Poco::UInt32 h2 = hashTable.update("2", 2);
|
Poco::UInt32 h2 = hashTable.update("2", 2);
|
||||||
assert (hashTable.size() == 2);
|
assert (hashTable.size() == 2);
|
||||||
hashTable.remove("1");
|
hashTable.remove("1");
|
||||||
assert (hashTable.size() == 1);
|
assert (hashTable.size() == 1);
|
||||||
hashTable.remove("3");
|
hashTable.remove("3");
|
||||||
assert (hashTable.size() == 1);
|
assert (hashTable.size() == 1);
|
||||||
hashTable.removeRaw("2", h2);
|
hashTable.removeRaw("2", h2);
|
||||||
assert (hashTable.size() == 0);
|
assert (hashTable.size() == 0);
|
||||||
hashTable.insert("1", 1);
|
hashTable.insert("1", 1);
|
||||||
hashTable.insert("2", 2);
|
hashTable.insert("2", 2);
|
||||||
assert (hashTable.size() == 2);
|
assert (hashTable.size() == 2);
|
||||||
hashTable.clear();
|
hashTable.clear();
|
||||||
assert (hashTable.size() == 0);
|
assert (hashTable.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTableTest::testResize()
|
void HashTableTest::testResize()
|
||||||
{
|
{
|
||||||
HashTable<std::string, int> hashTable(13);
|
HashTable<std::string, int> hashTable(13);
|
||||||
assert (hashTable.size() == 0);
|
assert (hashTable.size() == 0);
|
||||||
hashTable.resize(19);
|
hashTable.resize(19);
|
||||||
for (int i = 0; i < 1024; ++i)
|
for (int i = 0; i < 1024; ++i)
|
||||||
{
|
{
|
||||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||||
}
|
}
|
||||||
hashTable.resize(1009);
|
hashTable.resize(1009);
|
||||||
|
|
||||||
for (int i = 0; i < 1024; ++i)
|
for (int i = 0; i < 1024; ++i)
|
||||||
{
|
{
|
||||||
std::string tmp = Poco::NumberFormatter::format(i);
|
std::string tmp = Poco::NumberFormatter::format(i);
|
||||||
assert (hashTable.exists(tmp));
|
assert (hashTable.exists(tmp));
|
||||||
assert (hashTable.get(tmp) == i*i);
|
assert (hashTable.get(tmp) == i*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTableTest::testStatistic()
|
void HashTableTest::testStatistic()
|
||||||
{
|
{
|
||||||
double relax = 0.001;
|
double relax = 0.001;
|
||||||
HashTable<std::string, int> hashTable(13);
|
HashTable<std::string, int> hashTable(13);
|
||||||
assert (hashTable.size() == 0);
|
assert (hashTable.size() == 0);
|
||||||
HashStatistic stat1(hashTable.currentState());
|
HashStatistic stat1(hashTable.currentState());
|
||||||
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
||||||
assert (stat1.maxPositionsOfTable() == 13);
|
assert (stat1.maxPositionsOfTable() == 13);
|
||||||
assert (stat1.maxEntriesPerHash() == 0);
|
assert (stat1.maxEntriesPerHash() == 0);
|
||||||
|
|
||||||
hashTable.resize(19);
|
hashTable.resize(19);
|
||||||
stat1 = hashTable.currentState(true);
|
stat1 = hashTable.currentState(true);
|
||||||
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
||||||
assert (stat1.maxPositionsOfTable() == 19);
|
assert (stat1.maxPositionsOfTable() == 19);
|
||||||
assert (stat1.maxEntriesPerHash() == 0);
|
assert (stat1.maxEntriesPerHash() == 0);
|
||||||
assert (stat1.detailedEntriesPerHash().size() == 19);
|
assert (stat1.detailedEntriesPerHash().size() == 19);
|
||||||
|
|
||||||
for (int i = 0; i < 1024; ++i)
|
for (int i = 0; i < 1024; ++i)
|
||||||
{
|
{
|
||||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||||
}
|
}
|
||||||
stat1 = hashTable.currentState(true);
|
stat1 = hashTable.currentState(true);
|
||||||
double expAvg = 1024.0/ 19;
|
double expAvg = 1024.0/ 19;
|
||||||
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
||||||
assert (stat1.maxPositionsOfTable() == 19);
|
assert (stat1.maxPositionsOfTable() == 19);
|
||||||
assert (stat1.maxEntriesPerHash() > expAvg);
|
assert (stat1.maxEntriesPerHash() > expAvg);
|
||||||
hashTable.resize(1009);
|
hashTable.resize(1009);
|
||||||
stat1 = hashTable.currentState(true);
|
stat1 = hashTable.currentState(true);
|
||||||
|
|
||||||
expAvg = 1024.0/ 1009;
|
expAvg = 1024.0/ 1009;
|
||||||
|
|
||||||
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
||||||
assert (stat1.maxPositionsOfTable() == 1009);
|
assert (stat1.maxPositionsOfTable() == 1009);
|
||||||
assert (stat1.maxEntriesPerHash() > expAvg);
|
assert (stat1.maxEntriesPerHash() > expAvg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTableTest::setUp()
|
void HashTableTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HashTableTest::tearDown()
|
void HashTableTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* HashTableTest::suite()
|
CppUnit::Test* HashTableTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashTableTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashTableTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, HashTableTest, testInsert);
|
CppUnit_addTest(pSuite, HashTableTest, testInsert);
|
||||||
CppUnit_addTest(pSuite, HashTableTest, testUpdate);
|
CppUnit_addTest(pSuite, HashTableTest, testUpdate);
|
||||||
CppUnit_addTest(pSuite, HashTableTest, testOverflow);
|
CppUnit_addTest(pSuite, HashTableTest, testOverflow);
|
||||||
CppUnit_addTest(pSuite, HashTableTest, testSize);
|
CppUnit_addTest(pSuite, HashTableTest, testSize);
|
||||||
CppUnit_addTest(pSuite, HashTableTest, testResize);
|
CppUnit_addTest(pSuite, HashTableTest, testResize);
|
||||||
CppUnit_addTest(pSuite, HashTableTest, testStatistic);
|
CppUnit_addTest(pSuite, HashTableTest, testStatistic);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +1,65 @@
|
|||||||
//
|
//
|
||||||
// HashTableTest.h
|
// HashTableTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/HashTableTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/HashTableTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the HashTableTest class.
|
// Definition of the HashTableTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef HashTableTest_INCLUDED
|
#ifndef HashTableTest_INCLUDED
|
||||||
#define HashTableTest_INCLUDED
|
#define HashTableTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class HashTableTest: public CppUnit::TestCase
|
class HashTableTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HashTableTest(const std::string& name);
|
HashTableTest(const std::string& name);
|
||||||
~HashTableTest();
|
~HashTableTest();
|
||||||
|
|
||||||
void testInsert();
|
void testInsert();
|
||||||
void testOverflow();
|
void testOverflow();
|
||||||
void testUpdate();
|
void testUpdate();
|
||||||
void testSize();
|
void testSize();
|
||||||
void testResize();
|
void testResize();
|
||||||
void testStatistic();
|
void testStatistic();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // HashTableTest_INCLUDED
|
#endif // HashTableTest_INCLUDED
|
||||||
|
|||||||
@@ -1,52 +1,52 @@
|
|||||||
//
|
//
|
||||||
// HashingTestSuite.cpp
|
// HashingTestSuite.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/HashingTestSuite.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/HashingTestSuite.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "HashingTestSuite.h"
|
#include "HashingTestSuite.h"
|
||||||
#include "HashTableTest.h"
|
#include "HashTableTest.h"
|
||||||
#include "SimpleHashTableTest.h"
|
#include "SimpleHashTableTest.h"
|
||||||
#include "LinearHashTableTest.h"
|
#include "LinearHashTableTest.h"
|
||||||
#include "HashSetTest.h"
|
#include "HashSetTest.h"
|
||||||
#include "HashMapTest.h"
|
#include "HashMapTest.h"
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* HashingTestSuite::suite()
|
CppUnit::Test* HashingTestSuite::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashingTestSuite");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashingTestSuite");
|
||||||
|
|
||||||
pSuite->addTest(HashTableTest::suite());
|
pSuite->addTest(HashTableTest::suite());
|
||||||
pSuite->addTest(SimpleHashTableTest::suite());
|
pSuite->addTest(SimpleHashTableTest::suite());
|
||||||
pSuite->addTest(LinearHashTableTest::suite());
|
pSuite->addTest(LinearHashTableTest::suite());
|
||||||
pSuite->addTest(HashSetTest::suite());
|
pSuite->addTest(HashSetTest::suite());
|
||||||
pSuite->addTest(HashMapTest::suite());
|
pSuite->addTest(HashMapTest::suite());
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,49 @@
|
|||||||
//
|
//
|
||||||
// HashingTestSuite.h
|
// HashingTestSuite.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/HashingTestSuite.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/HashingTestSuite.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the HashingTestSuite class.
|
// Definition of the HashingTestSuite class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef HashingTestSuite_INCLUDED
|
#ifndef HashingTestSuite_INCLUDED
|
||||||
#define HashingTestSuite_INCLUDED
|
#define HashingTestSuite_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
|
|
||||||
|
|
||||||
class HashingTestSuite
|
class HashingTestSuite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // HashingTestSuite_INCLUDED
|
#endif // HashingTestSuite_INCLUDED
|
||||||
|
|||||||
@@ -1,374 +1,374 @@
|
|||||||
//
|
//
|
||||||
// LinearHashTableTest.cpp
|
// LinearHashTableTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "LinearHashTableTest.h"
|
#include "LinearHashTableTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/LinearHashTable.h"
|
#include "Poco/LinearHashTable.h"
|
||||||
#include "Poco/HashTable.h"
|
#include "Poco/HashTable.h"
|
||||||
#include "Poco/Stopwatch.h"
|
#include "Poco/Stopwatch.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
using Poco::LinearHashTable;
|
using Poco::LinearHashTable;
|
||||||
using Poco::HashTable;
|
using Poco::HashTable;
|
||||||
using Poco::Stopwatch;
|
using Poco::Stopwatch;
|
||||||
using Poco::NumberFormatter;
|
using Poco::NumberFormatter;
|
||||||
|
|
||||||
|
|
||||||
LinearHashTableTest::LinearHashTableTest(const std::string& name): CppUnit::TestCase(name)
|
LinearHashTableTest::LinearHashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LinearHashTableTest::~LinearHashTableTest()
|
LinearHashTableTest::~LinearHashTableTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LinearHashTableTest::testInsert()
|
void LinearHashTableTest::testInsert()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
LinearHashTable<int> ht;
|
LinearHashTable<int> ht;
|
||||||
|
|
||||||
assert (ht.empty());
|
assert (ht.empty());
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i);
|
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i);
|
||||||
assert (*res.first == i);
|
assert (*res.first == i);
|
||||||
assert (res.second);
|
assert (res.second);
|
||||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||||
assert (it != ht.end());
|
assert (it != ht.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
assert (ht.size() == i + 1);
|
assert (ht.size() == i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (!ht.empty());
|
assert (!ht.empty());
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||||
assert (it != ht.end());
|
assert (it != ht.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i);
|
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i);
|
||||||
assert (*res.first == i);
|
assert (*res.first == i);
|
||||||
assert (!res.second);
|
assert (!res.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LinearHashTableTest::testErase()
|
void LinearHashTableTest::testErase()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
LinearHashTable<int> ht;
|
LinearHashTable<int> ht;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
ht.insert(i);
|
ht.insert(i);
|
||||||
}
|
}
|
||||||
assert (ht.size() == N);
|
assert (ht.size() == N);
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
ht.erase(i);
|
ht.erase(i);
|
||||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||||
assert (it == ht.end());
|
assert (it == ht.end());
|
||||||
}
|
}
|
||||||
assert (ht.size() == N/2);
|
assert (ht.size() == N/2);
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||||
assert (it == ht.end());
|
assert (it == ht.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < N; i += 2)
|
for (int i = 1; i < N; i += 2)
|
||||||
{
|
{
|
||||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||||
assert (it != ht.end());
|
assert (it != ht.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; i += 2)
|
for (int i = 0; i < N; i += 2)
|
||||||
{
|
{
|
||||||
ht.insert(i);
|
ht.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||||
assert (it != ht.end());
|
assert (it != ht.end());
|
||||||
assert (*it == i);
|
assert (*it == i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LinearHashTableTest::testIterator()
|
void LinearHashTableTest::testIterator()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
LinearHashTable<int> ht;
|
LinearHashTable<int> ht;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
ht.insert(i);
|
ht.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<int> values;
|
std::set<int> values;
|
||||||
LinearHashTable<int>::Iterator it = ht.begin();
|
LinearHashTable<int>::Iterator it = ht.begin();
|
||||||
while (it != ht.end())
|
while (it != ht.end())
|
||||||
{
|
{
|
||||||
assert (values.find(*it) == values.end());
|
assert (values.find(*it) == values.end());
|
||||||
values.insert(*it);
|
values.insert(*it);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (values.size() == N);
|
assert (values.size() == N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LinearHashTableTest::testConstIterator()
|
void LinearHashTableTest::testConstIterator()
|
||||||
{
|
{
|
||||||
const int N = 1000;
|
const int N = 1000;
|
||||||
|
|
||||||
LinearHashTable<int> ht;
|
LinearHashTable<int> ht;
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
ht.insert(i);
|
ht.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<int> values;
|
std::set<int> values;
|
||||||
LinearHashTable<int>::ConstIterator it = ht.begin();
|
LinearHashTable<int>::ConstIterator it = ht.begin();
|
||||||
while (it != ht.end())
|
while (it != ht.end())
|
||||||
{
|
{
|
||||||
assert (values.find(*it) == values.end());
|
assert (values.find(*it) == values.end());
|
||||||
values.insert(*it);
|
values.insert(*it);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (values.size() == N);
|
assert (values.size() == N);
|
||||||
|
|
||||||
values.clear();
|
values.clear();
|
||||||
const LinearHashTable<int> cht(ht);
|
const LinearHashTable<int> cht(ht);
|
||||||
|
|
||||||
LinearHashTable<int>::ConstIterator cit = cht.begin();
|
LinearHashTable<int>::ConstIterator cit = cht.begin();
|
||||||
while (cit != cht.end())
|
while (cit != cht.end())
|
||||||
{
|
{
|
||||||
assert (values.find(*cit) == values.end());
|
assert (values.find(*cit) == values.end());
|
||||||
values.insert(*cit);
|
values.insert(*cit);
|
||||||
++cit;
|
++cit;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (values.size() == N);
|
assert (values.size() == N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LinearHashTableTest::testPerformanceInt()
|
void LinearHashTableTest::testPerformanceInt()
|
||||||
{
|
{
|
||||||
const int N = 5000000;
|
const int N = 5000000;
|
||||||
Stopwatch sw;
|
Stopwatch sw;
|
||||||
|
|
||||||
{
|
{
|
||||||
LinearHashTable<int> lht(N);
|
LinearHashTable<int> lht(N);
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
lht.insert(i);
|
lht.insert(i);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
lht.find(i);
|
lht.find(i);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Find LHT: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Find LHT: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
HashTable<int, int> ht;
|
HashTable<int, int> ht;
|
||||||
|
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
ht.insert(i, i);
|
ht.insert(i, i);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
ht.exists(i);
|
ht.exists(i);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::set<int> s;
|
std::set<int> s;
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
s.insert(i);
|
s.insert(i);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
s.find(i);
|
s.find(i);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LinearHashTableTest::testPerformanceStr()
|
void LinearHashTableTest::testPerformanceStr()
|
||||||
{
|
{
|
||||||
const int N = 5000000;
|
const int N = 5000000;
|
||||||
Stopwatch sw;
|
Stopwatch sw;
|
||||||
|
|
||||||
std::vector<std::string> values;
|
std::vector<std::string> values;
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
values.push_back(NumberFormatter::format0(i, 8));
|
values.push_back(NumberFormatter::format0(i, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
LinearHashTable<std::string> lht(N);
|
LinearHashTable<std::string> lht(N);
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
lht.insert(values[i]);
|
lht.insert(values[i]);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
lht.find(values[i]);
|
lht.find(values[i]);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Find LHT: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Find LHT: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
HashTable<std::string, int> ht;
|
HashTable<std::string, int> ht;
|
||||||
|
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
ht.insert(values[i], i);
|
ht.insert(values[i], i);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
ht.exists(values[i]);
|
ht.exists(values[i]);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::set<std::string> s;
|
std::set<std::string> s;
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
s.insert(values[i]);
|
s.insert(values[i]);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
|
|
||||||
sw.start();
|
sw.start();
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
{
|
{
|
||||||
s.find(values[i]);
|
s.find(values[i]);
|
||||||
}
|
}
|
||||||
sw.stop();
|
sw.stop();
|
||||||
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
||||||
sw.reset();
|
sw.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LinearHashTableTest::setUp()
|
void LinearHashTableTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LinearHashTableTest::tearDown()
|
void LinearHashTableTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* LinearHashTableTest::suite()
|
CppUnit::Test* LinearHashTableTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("LinearHashTableTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("LinearHashTableTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, LinearHashTableTest, testInsert);
|
CppUnit_addTest(pSuite, LinearHashTableTest, testInsert);
|
||||||
CppUnit_addTest(pSuite, LinearHashTableTest, testErase);
|
CppUnit_addTest(pSuite, LinearHashTableTest, testErase);
|
||||||
CppUnit_addTest(pSuite, LinearHashTableTest, testIterator);
|
CppUnit_addTest(pSuite, LinearHashTableTest, testIterator);
|
||||||
CppUnit_addTest(pSuite, LinearHashTableTest, testConstIterator);
|
CppUnit_addTest(pSuite, LinearHashTableTest, testConstIterator);
|
||||||
//CppUnit_addTest(pSuite, LinearHashTableTest, testPerformanceInt);
|
//CppUnit_addTest(pSuite, LinearHashTableTest, testPerformanceInt);
|
||||||
//CppUnit_addTest(pSuite, LinearHashTableTest, testPerformanceStr);
|
//CppUnit_addTest(pSuite, LinearHashTableTest, testPerformanceStr);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +1,65 @@
|
|||||||
//
|
//
|
||||||
// LinearHashTableTest.h
|
// LinearHashTableTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the LinearHashTableTest class.
|
// Definition of the LinearHashTableTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef LinearHashTableTest_INCLUDED
|
#ifndef LinearHashTableTest_INCLUDED
|
||||||
#define LinearHashTableTest_INCLUDED
|
#define LinearHashTableTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class LinearHashTableTest: public CppUnit::TestCase
|
class LinearHashTableTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LinearHashTableTest(const std::string& name);
|
LinearHashTableTest(const std::string& name);
|
||||||
~LinearHashTableTest();
|
~LinearHashTableTest();
|
||||||
|
|
||||||
void testInsert();
|
void testInsert();
|
||||||
void testErase();
|
void testErase();
|
||||||
void testIterator();
|
void testIterator();
|
||||||
void testConstIterator();
|
void testConstIterator();
|
||||||
void testPerformanceInt();
|
void testPerformanceInt();
|
||||||
void testPerformanceStr();
|
void testPerformanceStr();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // LinearHashTableTest_INCLUDED
|
#endif // LinearHashTableTest_INCLUDED
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,79 +1,79 @@
|
|||||||
//
|
//
|
||||||
// NamedTuplesTest.h
|
// NamedTuplesTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/NamedTuplesTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/NamedTuplesTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the NamedTuplesTest class.
|
// Definition of the NamedTuplesTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef NamedTuplesTest_INCLUDED
|
#ifndef NamedTuplesTest_INCLUDED
|
||||||
#define NamedTuplesTest_INCLUDED
|
#define NamedTuplesTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class NamedTuplesTest: public CppUnit::TestCase
|
class NamedTuplesTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NamedTuplesTest(const std::string& name);
|
NamedTuplesTest(const std::string& name);
|
||||||
~NamedTuplesTest();
|
~NamedTuplesTest();
|
||||||
|
|
||||||
void testNamedTuple1();
|
void testNamedTuple1();
|
||||||
void testNamedTuple2();
|
void testNamedTuple2();
|
||||||
void testNamedTuple3();
|
void testNamedTuple3();
|
||||||
void testNamedTuple4();
|
void testNamedTuple4();
|
||||||
void testNamedTuple5();
|
void testNamedTuple5();
|
||||||
void testNamedTuple6();
|
void testNamedTuple6();
|
||||||
void testNamedTuple7();
|
void testNamedTuple7();
|
||||||
void testNamedTuple8();
|
void testNamedTuple8();
|
||||||
void testNamedTuple9();
|
void testNamedTuple9();
|
||||||
void testNamedTuple10();
|
void testNamedTuple10();
|
||||||
void testNamedTuple11();
|
void testNamedTuple11();
|
||||||
void testNamedTuple12();
|
void testNamedTuple12();
|
||||||
void testNamedTuple13();
|
void testNamedTuple13();
|
||||||
void testNamedTuple14();
|
void testNamedTuple14();
|
||||||
void testNamedTuple15();
|
void testNamedTuple15();
|
||||||
void testNamedTuple16();
|
void testNamedTuple16();
|
||||||
void testNamedTuple17();
|
void testNamedTuple17();
|
||||||
void testNamedTuple18();
|
void testNamedTuple18();
|
||||||
void testNamedTuple19();
|
void testNamedTuple19();
|
||||||
void testNamedTuple20();
|
void testNamedTuple20();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // NamedTuplesTest_INCLUDED
|
#endif // NamedTuplesTest_INCLUDED
|
||||||
|
|||||||
@@ -1,116 +1,116 @@
|
|||||||
//
|
//
|
||||||
// SharedMemoryTest.cpp
|
// SharedMemoryTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/SharedMemoryTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/SharedMemoryTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "SharedMemoryTest.h"
|
#include "SharedMemoryTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/SharedMemory.h"
|
#include "Poco/SharedMemory.h"
|
||||||
#include "Poco/Path.h"
|
#include "Poco/Path.h"
|
||||||
#include "Poco/File.h"
|
#include "Poco/File.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
using Poco::SharedMemory;
|
using Poco::SharedMemory;
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryTest::SharedMemoryTest(const std::string& name): CppUnit::TestCase(name)
|
SharedMemoryTest::SharedMemoryTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SharedMemoryTest::~SharedMemoryTest()
|
SharedMemoryTest::~SharedMemoryTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryTest::testCreate()
|
void SharedMemoryTest::testCreate()
|
||||||
{
|
{
|
||||||
SharedMemory mem("hi", 4096, SharedMemory::AM_WRITE);
|
SharedMemory mem("hi", 4096, SharedMemory::AM_WRITE);
|
||||||
assert (mem.end()-mem.begin() == 4096);
|
assert (mem.end()-mem.begin() == 4096);
|
||||||
mem.begin()[0] = 'A';
|
mem.begin()[0] = 'A';
|
||||||
mem.end()[-1] = 'Z';
|
mem.end()[-1] = 'Z';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryTest::testCreateFromFile()
|
void SharedMemoryTest::testCreateFromFile()
|
||||||
{
|
{
|
||||||
Poco::Path p = findDataFile("testdata.txt");
|
Poco::Path p = findDataFile("testdata.txt");
|
||||||
Poco::File f(p);
|
Poco::File f(p);
|
||||||
assert (f.exists() && f.isFile());
|
assert (f.exists() && f.isFile());
|
||||||
SharedMemory mem(f, SharedMemory::AM_READ);
|
SharedMemory mem(f, SharedMemory::AM_READ);
|
||||||
assert (mem.end() > mem.begin()); // valid?
|
assert (mem.end() > mem.begin()); // valid?
|
||||||
assert (mem.end() - mem.begin() == f.getSize());
|
assert (mem.end() - mem.begin() == f.getSize());
|
||||||
assert (mem.begin()[0] == 'A');
|
assert (mem.begin()[0] == 'A');
|
||||||
assert (mem.end()[-5] == 'Z');
|
assert (mem.end()[-5] == 'Z');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Poco::Path SharedMemoryTest::findDataFile(const std::string& afile)
|
Poco::Path SharedMemoryTest::findDataFile(const std::string& afile)
|
||||||
{
|
{
|
||||||
Poco::Path root;
|
Poco::Path root;
|
||||||
root.makeAbsolute();
|
root.makeAbsolute();
|
||||||
Poco::Path result;
|
Poco::Path result;
|
||||||
while (!Poco::Path::find(root.toString(), "data", result))
|
while (!Poco::Path::find(root.toString(), "data", result))
|
||||||
{
|
{
|
||||||
root.makeParent();
|
root.makeParent();
|
||||||
if (root.toString().empty() || root.toString() == "/")
|
if (root.toString().empty() || root.toString() == "/")
|
||||||
throw Poco::FileNotFoundException("Didn't find data subdir");
|
throw Poco::FileNotFoundException("Didn't find data subdir");
|
||||||
}
|
}
|
||||||
result.makeDirectory();
|
result.makeDirectory();
|
||||||
result.setFileName(afile);
|
result.setFileName(afile);
|
||||||
Poco::File aFile(result.toString());
|
Poco::File aFile(result.toString());
|
||||||
if (!aFile.exists() || (aFile.exists() && !aFile.isFile()))
|
if (!aFile.exists() || (aFile.exists() && !aFile.isFile()))
|
||||||
throw Poco::FileNotFoundException("Didn't find file " + afile);
|
throw Poco::FileNotFoundException("Didn't find file " + afile);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryTest::setUp()
|
void SharedMemoryTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SharedMemoryTest::tearDown()
|
void SharedMemoryTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* SharedMemoryTest::suite()
|
CppUnit::Test* SharedMemoryTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SharedMemoryTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SharedMemoryTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, SharedMemoryTest, testCreate);
|
CppUnit_addTest(pSuite, SharedMemoryTest, testCreate);
|
||||||
CppUnit_addTest(pSuite, SharedMemoryTest, testCreateFromFile);
|
CppUnit_addTest(pSuite, SharedMemoryTest, testCreateFromFile);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +1,64 @@
|
|||||||
//
|
//
|
||||||
// SharedMemoryTest.h
|
// SharedMemoryTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/template/test.h#7 $
|
// $Id: //poco/Main/template/test.h#7 $
|
||||||
//
|
//
|
||||||
// Definition of the SharedMemoryTest class.
|
// Definition of the SharedMemoryTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef SharedMemoryTest_INCLUDED
|
#ifndef SharedMemoryTest_INCLUDED
|
||||||
#define SharedMemoryTest_INCLUDED
|
#define SharedMemoryTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/Path.h"
|
#include "Poco/Path.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class SharedMemoryTest: public CppUnit::TestCase
|
class SharedMemoryTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SharedMemoryTest(const std::string& name);
|
SharedMemoryTest(const std::string& name);
|
||||||
~SharedMemoryTest();
|
~SharedMemoryTest();
|
||||||
|
|
||||||
void testCreate();
|
void testCreate();
|
||||||
void testCreateFromFile();
|
void testCreateFromFile();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
static Poco::Path findDataFile(const std::string& afile);
|
static Poco::Path findDataFile(const std::string& afile);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SharedMemoryTest_INCLUDED
|
#endif // SharedMemoryTest_INCLUDED
|
||||||
|
|||||||
@@ -1,177 +1,177 @@
|
|||||||
//
|
//
|
||||||
// SimpleHashTableTest.cpp
|
// SimpleHashTableTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/SimpleHashTableTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/SimpleHashTableTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "SimpleHashTableTest.h"
|
#include "SimpleHashTableTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/SimpleHashTable.h"
|
#include "Poco/SimpleHashTable.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
|
|
||||||
|
|
||||||
SimpleHashTableTest::SimpleHashTableTest(const std::string& name): CppUnit::TestCase(name)
|
SimpleHashTableTest::SimpleHashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SimpleHashTableTest::~SimpleHashTableTest()
|
SimpleHashTableTest::~SimpleHashTableTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimpleHashTableTest::testInsert()
|
void SimpleHashTableTest::testInsert()
|
||||||
{
|
{
|
||||||
std::string s1("str1");
|
std::string s1("str1");
|
||||||
std::string s2("str2");
|
std::string s2("str2");
|
||||||
SimpleHashTable<std::string, int> hashTable;
|
SimpleHashTable<std::string, int> hashTable;
|
||||||
assert (!hashTable.exists(s1));
|
assert (!hashTable.exists(s1));
|
||||||
hashTable.insert(s1, 13);
|
hashTable.insert(s1, 13);
|
||||||
assert (hashTable.exists(s1));
|
assert (hashTable.exists(s1));
|
||||||
assert (hashTable.get(s1) == 13);
|
assert (hashTable.get(s1) == 13);
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
|
|
||||||
assert (hashTable.get(s1, retVal));
|
assert (hashTable.get(s1, retVal));
|
||||||
assert (retVal == 13);
|
assert (retVal == 13);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hashTable.insert(s1, 22);
|
hashTable.insert(s1, 22);
|
||||||
failmsg ("duplicate insert must fail");
|
failmsg ("duplicate insert must fail");
|
||||||
}
|
}
|
||||||
catch (Exception&){}
|
catch (Exception&){}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hashTable.get(s2);
|
hashTable.get(s2);
|
||||||
failmsg ("getting a non inserted item must fail");
|
failmsg ("getting a non inserted item must fail");
|
||||||
}
|
}
|
||||||
catch (Exception&){}
|
catch (Exception&){}
|
||||||
|
|
||||||
assert (!hashTable.exists(s2));
|
assert (!hashTable.exists(s2));
|
||||||
hashTable.insert(s2, 13);
|
hashTable.insert(s2, 13);
|
||||||
assert (hashTable.exists(s2));
|
assert (hashTable.exists(s2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimpleHashTableTest::testUpdate()
|
void SimpleHashTableTest::testUpdate()
|
||||||
{
|
{
|
||||||
// add code for second test here
|
// add code for second test here
|
||||||
std::string s1("str1");
|
std::string s1("str1");
|
||||||
std::string s2("str2");
|
std::string s2("str2");
|
||||||
SimpleHashTable<std::string, int> hashTable;
|
SimpleHashTable<std::string, int> hashTable;
|
||||||
hashTable.insert(s1, 13);
|
hashTable.insert(s1, 13);
|
||||||
hashTable.update(s1, 14);
|
hashTable.update(s1, 14);
|
||||||
assert (hashTable.exists(s1));
|
assert (hashTable.exists(s1));
|
||||||
assert (hashTable.get(s1) == 14);
|
assert (hashTable.get(s1) == 14);
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
|
|
||||||
assert (hashTable.get(s1, retVal));
|
assert (hashTable.get(s1, retVal));
|
||||||
assert (retVal == 14);
|
assert (retVal == 14);
|
||||||
|
|
||||||
// updating a non existing item must work too
|
// updating a non existing item must work too
|
||||||
hashTable.update(s2, 15);
|
hashTable.update(s2, 15);
|
||||||
assert (hashTable.get(s2) == 15);
|
assert (hashTable.get(s2) == 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimpleHashTableTest::testOverflow()
|
void SimpleHashTableTest::testOverflow()
|
||||||
{
|
{
|
||||||
SimpleHashTable<std::string, int> hashTable(31);
|
SimpleHashTable<std::string, int> hashTable(31);
|
||||||
for (int i = 0; i < 31; ++i)
|
for (int i = 0; i < 31; ++i)
|
||||||
{
|
{
|
||||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 31; ++i)
|
for (int i = 0; i < 31; ++i)
|
||||||
{
|
{
|
||||||
std::string tmp = Poco::NumberFormatter::format(i);
|
std::string tmp = Poco::NumberFormatter::format(i);
|
||||||
assert (hashTable.exists(tmp));
|
assert (hashTable.exists(tmp));
|
||||||
assert (hashTable.get(tmp) == i*i);
|
assert (hashTable.get(tmp) == i*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimpleHashTableTest::testSize()
|
void SimpleHashTableTest::testSize()
|
||||||
{
|
{
|
||||||
SimpleHashTable<std::string, int> hashTable(13);
|
SimpleHashTable<std::string, int> hashTable(13);
|
||||||
assert (hashTable.size() == 0);
|
assert (hashTable.size() == 0);
|
||||||
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
||||||
assert (hashTable.size() == 1);
|
assert (hashTable.size() == 1);
|
||||||
Poco::UInt32 h2 = hashTable.update("2", 2);
|
Poco::UInt32 h2 = hashTable.update("2", 2);
|
||||||
assert (hashTable.size() == 2);
|
assert (hashTable.size() == 2);
|
||||||
hashTable.clear();
|
hashTable.clear();
|
||||||
assert (hashTable.size() == 0);
|
assert (hashTable.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimpleHashTableTest::testResize()
|
void SimpleHashTableTest::testResize()
|
||||||
{
|
{
|
||||||
SimpleHashTable<std::string, int> hashTable(13);
|
SimpleHashTable<std::string, int> hashTable(13);
|
||||||
assert (hashTable.size() == 0);
|
assert (hashTable.size() == 0);
|
||||||
hashTable.resize(2467);
|
hashTable.resize(2467);
|
||||||
for (int i = 0; i < 1024; ++i)
|
for (int i = 0; i < 1024; ++i)
|
||||||
{
|
{
|
||||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||||
}
|
}
|
||||||
hashTable.resize(3037);
|
hashTable.resize(3037);
|
||||||
|
|
||||||
for (int i = 0; i < 1024; ++i)
|
for (int i = 0; i < 1024; ++i)
|
||||||
{
|
{
|
||||||
std::string tmp = Poco::NumberFormatter::format(i);
|
std::string tmp = Poco::NumberFormatter::format(i);
|
||||||
assert (hashTable.exists(tmp));
|
assert (hashTable.exists(tmp));
|
||||||
assert (hashTable.get(tmp) == i*i);
|
assert (hashTable.get(tmp) == i*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimpleHashTableTest::setUp()
|
void SimpleHashTableTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimpleHashTableTest::tearDown()
|
void SimpleHashTableTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* SimpleHashTableTest::suite()
|
CppUnit::Test* SimpleHashTableTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SimpleHashTableTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SimpleHashTableTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testInsert);
|
CppUnit_addTest(pSuite, SimpleHashTableTest, testInsert);
|
||||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testUpdate);
|
CppUnit_addTest(pSuite, SimpleHashTableTest, testUpdate);
|
||||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testOverflow);
|
CppUnit_addTest(pSuite, SimpleHashTableTest, testOverflow);
|
||||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testSize);
|
CppUnit_addTest(pSuite, SimpleHashTableTest, testSize);
|
||||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testResize);
|
CppUnit_addTest(pSuite, SimpleHashTableTest, testResize);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +1,65 @@
|
|||||||
//
|
//
|
||||||
// SimpleHashTableTest.h
|
// SimpleHashTableTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/SimpleHashTableTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/SimpleHashTableTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the SimpleHashTableTest class.
|
// Definition of the SimpleHashTableTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef SimpleHashTableTest_INCLUDED
|
#ifndef SimpleHashTableTest_INCLUDED
|
||||||
#define SimpleHashTableTest_INCLUDED
|
#define SimpleHashTableTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class SimpleHashTableTest: public CppUnit::TestCase
|
class SimpleHashTableTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SimpleHashTableTest(const std::string& name);
|
SimpleHashTableTest(const std::string& name);
|
||||||
~SimpleHashTableTest();
|
~SimpleHashTableTest();
|
||||||
|
|
||||||
void testInsert();
|
void testInsert();
|
||||||
void testOverflow();
|
void testOverflow();
|
||||||
void testUpdate();
|
void testUpdate();
|
||||||
void testSize();
|
void testSize();
|
||||||
void testResize();
|
void testResize();
|
||||||
void testStatistic();
|
void testStatistic();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SimpleHashTableTest_INCLUDED
|
#endif // SimpleHashTableTest_INCLUDED
|
||||||
|
|||||||
@@ -1,89 +1,89 @@
|
|||||||
//
|
//
|
||||||
// TextEncodingTest.cpp
|
// TextEncodingTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/TextEncodingTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/TextEncodingTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "TextEncodingTest.h"
|
#include "TextEncodingTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/TextEncoding.h"
|
#include "Poco/TextEncoding.h"
|
||||||
#include "Poco/Latin1Encoding.h"
|
#include "Poco/Latin1Encoding.h"
|
||||||
|
|
||||||
|
|
||||||
using Poco::TextEncoding;
|
using Poco::TextEncoding;
|
||||||
using Poco::Latin1Encoding;
|
using Poco::Latin1Encoding;
|
||||||
|
|
||||||
|
|
||||||
TextEncodingTest::TextEncodingTest(const std::string& name): CppUnit::TestCase(name)
|
TextEncodingTest::TextEncodingTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TextEncodingTest::~TextEncodingTest()
|
TextEncodingTest::~TextEncodingTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextEncodingTest::testTextEncoding()
|
void TextEncodingTest::testTextEncoding()
|
||||||
{
|
{
|
||||||
TextEncoding& utf8 = TextEncoding::byName("utf8");
|
TextEncoding& utf8 = TextEncoding::byName("utf8");
|
||||||
assert (std::string("UTF-8") == utf8.canonicalName());
|
assert (std::string("UTF-8") == utf8.canonicalName());
|
||||||
|
|
||||||
TextEncoding& latin1 = TextEncoding::byName("latin1");
|
TextEncoding& latin1 = TextEncoding::byName("latin1");
|
||||||
assert (std::string("ISO-8859-1") == latin1.canonicalName());
|
assert (std::string("ISO-8859-1") == latin1.canonicalName());
|
||||||
|
|
||||||
TextEncoding& glob = TextEncoding::global();
|
TextEncoding& glob = TextEncoding::global();
|
||||||
assert (std::string("UTF-8") == glob.canonicalName());
|
assert (std::string("UTF-8") == glob.canonicalName());
|
||||||
|
|
||||||
TextEncoding::global(new Latin1Encoding);
|
TextEncoding::global(new Latin1Encoding);
|
||||||
|
|
||||||
TextEncoding& glob2 = TextEncoding::global();
|
TextEncoding& glob2 = TextEncoding::global();
|
||||||
assert (std::string("ISO-8859-1") == glob2.canonicalName());
|
assert (std::string("ISO-8859-1") == glob2.canonicalName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextEncodingTest::setUp()
|
void TextEncodingTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TextEncodingTest::tearDown()
|
void TextEncodingTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* TextEncodingTest::suite()
|
CppUnit::Test* TextEncodingTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextEncodingTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextEncodingTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, TextEncodingTest, testTextEncoding);
|
CppUnit_addTest(pSuite, TextEncodingTest, testTextEncoding);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +1,60 @@
|
|||||||
//
|
//
|
||||||
// TextEncodingTest.h
|
// TextEncodingTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/TextEncodingTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/TextEncodingTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the TextEncodingTest class.
|
// Definition of the TextEncodingTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef TextEncodingTest_INCLUDED
|
#ifndef TextEncodingTest_INCLUDED
|
||||||
#define TextEncodingTest_INCLUDED
|
#define TextEncodingTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class TextEncodingTest: public CppUnit::TestCase
|
class TextEncodingTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextEncodingTest(const std::string& name);
|
TextEncodingTest(const std::string& name);
|
||||||
~TextEncodingTest();
|
~TextEncodingTest();
|
||||||
|
|
||||||
void testTextEncoding();
|
void testTextEncoding();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // TextEncodingTest_INCLUDED
|
#endif // TextEncodingTest_INCLUDED
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,88 +1,88 @@
|
|||||||
//
|
//
|
||||||
// TuplesTest.h
|
// TuplesTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/TuplesTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/TuplesTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the TuplesTest class.
|
// Definition of the TuplesTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef TuplesTest_INCLUDED
|
#ifndef TuplesTest_INCLUDED
|
||||||
#define TuplesTest_INCLUDED
|
#define TuplesTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class TuplesTest: public CppUnit::TestCase
|
class TuplesTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TuplesTest(const std::string& name);
|
TuplesTest(const std::string& name);
|
||||||
~TuplesTest();
|
~TuplesTest();
|
||||||
|
|
||||||
void testTuple1();
|
void testTuple1();
|
||||||
void testTuple2();
|
void testTuple2();
|
||||||
void testTuple3();
|
void testTuple3();
|
||||||
void testTuple4();
|
void testTuple4();
|
||||||
void testTuple5();
|
void testTuple5();
|
||||||
void testTuple6();
|
void testTuple6();
|
||||||
void testTuple7();
|
void testTuple7();
|
||||||
void testTuple8();
|
void testTuple8();
|
||||||
void testTuple9();
|
void testTuple9();
|
||||||
void testTuple10();
|
void testTuple10();
|
||||||
void testTuple11();
|
void testTuple11();
|
||||||
void testTuple12();
|
void testTuple12();
|
||||||
void testTuple13();
|
void testTuple13();
|
||||||
void testTuple14();
|
void testTuple14();
|
||||||
void testTuple15();
|
void testTuple15();
|
||||||
void testTuple16();
|
void testTuple16();
|
||||||
void testTuple17();
|
void testTuple17();
|
||||||
void testTuple18();
|
void testTuple18();
|
||||||
void testTuple19();
|
void testTuple19();
|
||||||
void testTuple20();
|
void testTuple20();
|
||||||
void testTupleOrder();
|
void testTupleOrder();
|
||||||
void testMemOverhead();
|
void testMemOverhead();
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void testTupleStrictWeak(const T& t1, const T& t2, const T& t3)
|
void testTupleStrictWeak(const T& t1, const T& t2, const T& t3)
|
||||||
{
|
{
|
||||||
assert (t1 < t2 && !(t2 < t1)); // antisymmetric
|
assert (t1 < t2 && !(t2 < t1)); // antisymmetric
|
||||||
assert (t1 < t2 && t2 < t3 && t1 < t3); // transitive
|
assert (t1 < t2 && t2 < t3 && t1 < t3); // transitive
|
||||||
assert (!(t1 < t1)); // irreflexive
|
assert (!(t1 < t1)); // irreflexive
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // TuplesTest_INCLUDED
|
#endif // TuplesTest_INCLUDED
|
||||||
|
|||||||
@@ -1,323 +1,323 @@
|
|||||||
//
|
//
|
||||||
// TypeListTest.cpp
|
// TypeListTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/TypeListTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/TypeListTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "TypeListTest.h"
|
#include "TypeListTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/Tuple.h"
|
#include "Poco/Tuple.h"
|
||||||
#include "Poco/TypeList.h"
|
#include "Poco/TypeList.h"
|
||||||
#include "Poco/Void.h"
|
#include "Poco/Void.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# pragma warning(disable:4800) // forcing value to bool 'true' or 'false' on MSVC 71
|
# pragma warning(disable:4800) // forcing value to bool 'true' or 'false' on MSVC 71
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using Poco::TypeList;
|
using Poco::TypeList;
|
||||||
using Poco::Tuple;
|
using Poco::Tuple;
|
||||||
using Poco::NullTypeList;
|
using Poco::NullTypeList;
|
||||||
using Poco::TypeListType;
|
using Poco::TypeListType;
|
||||||
using Poco::TypeGetter;
|
using Poco::TypeGetter;
|
||||||
using Poco::TypeLocator;
|
using Poco::TypeLocator;
|
||||||
using Poco::TypeAppender;
|
using Poco::TypeAppender;
|
||||||
using Poco::TypeOneEraser;
|
using Poco::TypeOneEraser;
|
||||||
using Poco::TypeAllEraser;
|
using Poco::TypeAllEraser;
|
||||||
using Poco::TypeDuplicateEraser;
|
using Poco::TypeDuplicateEraser;
|
||||||
using Poco::TypeOneReplacer;
|
using Poco::TypeOneReplacer;
|
||||||
using Poco::TypeAllReplacer;
|
using Poco::TypeAllReplacer;
|
||||||
using Poco::Int8;
|
using Poco::Int8;
|
||||||
using Poco::UInt8;
|
using Poco::UInt8;
|
||||||
using Poco::Int16;
|
using Poco::Int16;
|
||||||
using Poco::UInt16;
|
using Poco::UInt16;
|
||||||
using Poco::Int32;
|
using Poco::Int32;
|
||||||
using Poco::UInt32;
|
using Poco::UInt32;
|
||||||
using Poco::Int8;
|
using Poco::Int8;
|
||||||
using Poco::UInt8;
|
using Poco::UInt8;
|
||||||
using Poco::Int16;
|
using Poco::Int16;
|
||||||
using Poco::UInt16;
|
using Poco::UInt16;
|
||||||
using Poco::Int32;
|
using Poco::Int32;
|
||||||
using Poco::UInt32;
|
using Poco::UInt32;
|
||||||
using Poco::Void;
|
using Poco::Void;
|
||||||
|
|
||||||
|
|
||||||
TypeListTest::TypeListTest(const std::string& name): CppUnit::TestCase(name)
|
TypeListTest::TypeListTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TypeListTest::~TypeListTest()
|
TypeListTest::~TypeListTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TypeListTest::testTypeList()
|
void TypeListTest::testTypeList()
|
||||||
{
|
{
|
||||||
typedef TypeListType<Int8,
|
typedef TypeListType<Int8,
|
||||||
UInt8,
|
UInt8,
|
||||||
Int16,
|
Int16,
|
||||||
UInt16,
|
UInt16,
|
||||||
Int32,
|
Int32,
|
||||||
UInt32,
|
UInt32,
|
||||||
float,
|
float,
|
||||||
double,
|
double,
|
||||||
Int8,
|
Int8,
|
||||||
UInt8,
|
UInt8,
|
||||||
Int16,
|
Int16,
|
||||||
UInt16,
|
UInt16,
|
||||||
Int32,
|
Int32,
|
||||||
UInt32,
|
UInt32,
|
||||||
float>::HeadType Type15;
|
float>::HeadType Type15;
|
||||||
|
|
||||||
Tuple<TypeGetter<0, Type15>::HeadType,
|
Tuple<TypeGetter<0, Type15>::HeadType,
|
||||||
TypeGetter<1, Type15>::HeadType,
|
TypeGetter<1, Type15>::HeadType,
|
||||||
TypeGetter<2, Type15>::HeadType,
|
TypeGetter<2, Type15>::HeadType,
|
||||||
TypeGetter<3, Type15>::HeadType,
|
TypeGetter<3, Type15>::HeadType,
|
||||||
TypeGetter<4, Type15>::HeadType,
|
TypeGetter<4, Type15>::HeadType,
|
||||||
TypeGetter<5, Type15>::HeadType,
|
TypeGetter<5, Type15>::HeadType,
|
||||||
TypeGetter<6, Type15>::HeadType,
|
TypeGetter<6, Type15>::HeadType,
|
||||||
TypeGetter<7, Type15>::HeadType,
|
TypeGetter<7, Type15>::HeadType,
|
||||||
TypeGetter<8, Type15>::HeadType,
|
TypeGetter<8, Type15>::HeadType,
|
||||||
TypeGetter<9, Type15>::HeadType> tuple;
|
TypeGetter<9, Type15>::HeadType> tuple;
|
||||||
|
|
||||||
static TypeLocator<Type15, Int8> pos0;
|
static TypeLocator<Type15, Int8> pos0;
|
||||||
static TypeLocator<Type15, UInt8> pos1;
|
static TypeLocator<Type15, UInt8> pos1;
|
||||||
static TypeLocator<Type15, Int16> pos2;
|
static TypeLocator<Type15, Int16> pos2;
|
||||||
static TypeLocator<Type15, UInt16> pos3;
|
static TypeLocator<Type15, UInt16> pos3;
|
||||||
static TypeLocator<Type15, Int32> pos4;
|
static TypeLocator<Type15, Int32> pos4;
|
||||||
static TypeLocator<Type15, UInt32> pos5;
|
static TypeLocator<Type15, UInt32> pos5;
|
||||||
static TypeLocator<Type15, float> pos6;
|
static TypeLocator<Type15, float> pos6;
|
||||||
static TypeLocator<Type15, double> pos7;
|
static TypeLocator<Type15, double> pos7;
|
||||||
static TypeLocator<Type15, Int8> pos8;
|
static TypeLocator<Type15, Int8> pos8;
|
||||||
static TypeLocator<Type15, std::string> posUnknown;
|
static TypeLocator<Type15, std::string> posUnknown;
|
||||||
|
|
||||||
assert (pos0.value == 0);
|
assert (pos0.value == 0);
|
||||||
assert (pos1.value == 1);
|
assert (pos1.value == 1);
|
||||||
assert (pos2.value == 2);
|
assert (pos2.value == 2);
|
||||||
assert (pos3.value == 3);
|
assert (pos3.value == 3);
|
||||||
assert (pos4.value == 4);
|
assert (pos4.value == 4);
|
||||||
assert (pos5.value == 5);
|
assert (pos5.value == 5);
|
||||||
assert (pos6.value == 6);
|
assert (pos6.value == 6);
|
||||||
assert (pos7.value == 7);
|
assert (pos7.value == 7);
|
||||||
assert (pos8.value == 0);
|
assert (pos8.value == 0);
|
||||||
assert (posUnknown.value == -1);
|
assert (posUnknown.value == -1);
|
||||||
|
|
||||||
tuple.set<TypeLocator<Type15, Int32>::value >(-123);
|
tuple.set<TypeLocator<Type15, Int32>::value >(-123);
|
||||||
assert (-123 == tuple.get<4>());
|
assert (-123 == tuple.get<4>());
|
||||||
|
|
||||||
assert (typeid(TypeGetter<0, Type15>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, Type15>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<0, Type15>::ConstHeadType) == typeid(const Int8));
|
assert (typeid(TypeGetter<0, Type15>::ConstHeadType) == typeid(const Int8));
|
||||||
assert (typeid(TypeGetter<1, Type15>::HeadType) == typeid(UInt8));
|
assert (typeid(TypeGetter<1, Type15>::HeadType) == typeid(UInt8));
|
||||||
assert (typeid(TypeGetter<1, Type15>::ConstHeadType) == typeid(const UInt8));
|
assert (typeid(TypeGetter<1, Type15>::ConstHeadType) == typeid(const UInt8));
|
||||||
assert (typeid(TypeGetter<2, Type15>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<2, Type15>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<2, Type15>::ConstHeadType) == typeid(const Int16));
|
assert (typeid(TypeGetter<2, Type15>::ConstHeadType) == typeid(const Int16));
|
||||||
assert (typeid(TypeGetter<3, Type15>::HeadType) == typeid(UInt16));
|
assert (typeid(TypeGetter<3, Type15>::HeadType) == typeid(UInt16));
|
||||||
assert (typeid(TypeGetter<3, Type15>::ConstHeadType) == typeid(const UInt16));
|
assert (typeid(TypeGetter<3, Type15>::ConstHeadType) == typeid(const UInt16));
|
||||||
assert (typeid(TypeGetter<4, Type15>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<4, Type15>::HeadType) == typeid(Int32));
|
||||||
assert (typeid(TypeGetter<4, Type15>::ConstHeadType) == typeid(const Int32));
|
assert (typeid(TypeGetter<4, Type15>::ConstHeadType) == typeid(const Int32));
|
||||||
assert (typeid(TypeGetter<5, Type15>::HeadType) == typeid(UInt32));
|
assert (typeid(TypeGetter<5, Type15>::HeadType) == typeid(UInt32));
|
||||||
assert (typeid(TypeGetter<5, Type15>::ConstHeadType) == typeid(const UInt32));
|
assert (typeid(TypeGetter<5, Type15>::ConstHeadType) == typeid(const UInt32));
|
||||||
assert (typeid(TypeGetter<6, Type15>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<6, Type15>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<6, Type15>::ConstHeadType) == typeid(const float));
|
assert (typeid(TypeGetter<6, Type15>::ConstHeadType) == typeid(const float));
|
||||||
assert (typeid(TypeGetter<7, Type15>::HeadType) == typeid(double));
|
assert (typeid(TypeGetter<7, Type15>::HeadType) == typeid(double));
|
||||||
assert (typeid(TypeGetter<7, Type15>::ConstHeadType) == typeid(const double));
|
assert (typeid(TypeGetter<7, Type15>::ConstHeadType) == typeid(const double));
|
||||||
assert (typeid(TypeGetter<8, Type15>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<8, Type15>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<8, Type15>::ConstHeadType) == typeid(const Int8));
|
assert (typeid(TypeGetter<8, Type15>::ConstHeadType) == typeid(const Int8));
|
||||||
assert (typeid(TypeGetter<9, Type15>::HeadType) == typeid(UInt8));
|
assert (typeid(TypeGetter<9, Type15>::HeadType) == typeid(UInt8));
|
||||||
assert (typeid(TypeGetter<9, Type15>::ConstHeadType) == typeid(const UInt8));
|
assert (typeid(TypeGetter<9, Type15>::ConstHeadType) == typeid(const UInt8));
|
||||||
assert (typeid(TypeGetter<10, Type15>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<10, Type15>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<10, Type15>::ConstHeadType) == typeid(const Int16));
|
assert (typeid(TypeGetter<10, Type15>::ConstHeadType) == typeid(const Int16));
|
||||||
assert (typeid(TypeGetter<11, Type15>::HeadType) == typeid(UInt16));
|
assert (typeid(TypeGetter<11, Type15>::HeadType) == typeid(UInt16));
|
||||||
assert (typeid(TypeGetter<11, Type15>::ConstHeadType) == typeid(const UInt16));
|
assert (typeid(TypeGetter<11, Type15>::ConstHeadType) == typeid(const UInt16));
|
||||||
assert (typeid(TypeGetter<12, Type15>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<12, Type15>::HeadType) == typeid(Int32));
|
||||||
assert (typeid(TypeGetter<12, Type15>::ConstHeadType) == typeid(const Int32));
|
assert (typeid(TypeGetter<12, Type15>::ConstHeadType) == typeid(const Int32));
|
||||||
assert (typeid(TypeGetter<13, Type15>::HeadType) == typeid(UInt32));
|
assert (typeid(TypeGetter<13, Type15>::HeadType) == typeid(UInt32));
|
||||||
assert (typeid(TypeGetter<13, Type15>::ConstHeadType) == typeid(const UInt32));
|
assert (typeid(TypeGetter<13, Type15>::ConstHeadType) == typeid(const UInt32));
|
||||||
assert (typeid(TypeGetter<14, Type15>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<14, Type15>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<14, Type15>::ConstHeadType) == typeid(const float));
|
assert (typeid(TypeGetter<14, Type15>::ConstHeadType) == typeid(const float));
|
||||||
|
|
||||||
typedef TypeListType<Int8>::HeadType Type1;
|
typedef TypeListType<Int8>::HeadType Type1;
|
||||||
assert (1 == Type1::length);
|
assert (1 == Type1::length);
|
||||||
typedef TypeListType<Int16, Int32>::HeadType Type2;
|
typedef TypeListType<Int16, Int32>::HeadType Type2;
|
||||||
assert (2 == Type2::length);
|
assert (2 == Type2::length);
|
||||||
typedef TypeAppender<Type1, Type2>::HeadType Type3;
|
typedef TypeAppender<Type1, Type2>::HeadType Type3;
|
||||||
assert (3 == Type3::length);
|
assert (3 == Type3::length);
|
||||||
|
|
||||||
assert (typeid(TypeGetter<0, Type3>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, Type3>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<1, Type3>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, Type3>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<2, Type3>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<2, Type3>::HeadType) == typeid(Int32));
|
||||||
|
|
||||||
static TypeLocator<Type3, Int8> posNo1;
|
static TypeLocator<Type3, Int8> posNo1;
|
||||||
static TypeLocator<Type3, Int16> posNo2;
|
static TypeLocator<Type3, Int16> posNo2;
|
||||||
static TypeLocator<Type3, Int32> posNo3;
|
static TypeLocator<Type3, Int32> posNo3;
|
||||||
|
|
||||||
assert (posNo1.value == 0);
|
assert (posNo1.value == 0);
|
||||||
assert (posNo2.value == 1);
|
assert (posNo2.value == 1);
|
||||||
assert (posNo3.value == 2);
|
assert (posNo3.value == 2);
|
||||||
|
|
||||||
typedef TypeOneEraser<Type3, Int8>::HeadType TypeEraser1;
|
typedef TypeOneEraser<Type3, Int8>::HeadType TypeEraser1;
|
||||||
assert (2 == TypeEraser1::length);
|
assert (2 == TypeEraser1::length);
|
||||||
assert (typeid(TypeGetter<0, TypeEraser1>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<0, TypeEraser1>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<1, TypeEraser1>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<1, TypeEraser1>::HeadType) == typeid(Int32));
|
||||||
|
|
||||||
typedef TypeOneEraser<Type3, Int16>::HeadType TypeEraser2;
|
typedef TypeOneEraser<Type3, Int16>::HeadType TypeEraser2;
|
||||||
assert (2 == TypeEraser2::length);
|
assert (2 == TypeEraser2::length);
|
||||||
assert (typeid(TypeGetter<0, TypeEraser2>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, TypeEraser2>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<1, TypeEraser2>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<1, TypeEraser2>::HeadType) == typeid(Int32));
|
||||||
|
|
||||||
typedef TypeOneEraser<Type3, Int32>::HeadType TypeEraser3;
|
typedef TypeOneEraser<Type3, Int32>::HeadType TypeEraser3;
|
||||||
assert (2 == TypeEraser3::length);
|
assert (2 == TypeEraser3::length);
|
||||||
assert (typeid(TypeGetter<0, TypeEraser3>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, TypeEraser3>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<1, TypeEraser3>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, TypeEraser3>::HeadType) == typeid(Int16));
|
||||||
|
|
||||||
typedef TypeListType<Int8,Int16,Int8,Int16,Int8>::HeadType Type5;
|
typedef TypeListType<Int8,Int16,Int8,Int16,Int8>::HeadType Type5;
|
||||||
typedef TypeAllEraser<Type5, Int8>::HeadType TypeAllEraser3;
|
typedef TypeAllEraser<Type5, Int8>::HeadType TypeAllEraser3;
|
||||||
assert (2 == TypeAllEraser3::length);
|
assert (2 == TypeAllEraser3::length);
|
||||||
assert (typeid(TypeGetter<0, TypeAllEraser3>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<0, TypeAllEraser3>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<1, TypeAllEraser3>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, TypeAllEraser3>::HeadType) == typeid(Int16));
|
||||||
|
|
||||||
typedef TypeDuplicateEraser<Type5>::HeadType TypeDuplicateEraser1;
|
typedef TypeDuplicateEraser<Type5>::HeadType TypeDuplicateEraser1;
|
||||||
assert (2 == TypeDuplicateEraser1::length);
|
assert (2 == TypeDuplicateEraser1::length);
|
||||||
assert (typeid(TypeGetter<0, TypeDuplicateEraser1>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, TypeDuplicateEraser1>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<1, TypeDuplicateEraser1>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, TypeDuplicateEraser1>::HeadType) == typeid(Int16));
|
||||||
|
|
||||||
typedef TypeOneReplacer<Type5, Int8, Int32>::HeadType TypeOneReplacer1;
|
typedef TypeOneReplacer<Type5, Int8, Int32>::HeadType TypeOneReplacer1;
|
||||||
assert (5 == TypeOneReplacer1::length);
|
assert (5 == TypeOneReplacer1::length);
|
||||||
assert (typeid(TypeGetter<0, TypeOneReplacer1>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<0, TypeOneReplacer1>::HeadType) == typeid(Int32));
|
||||||
assert (typeid(TypeGetter<1, TypeOneReplacer1>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, TypeOneReplacer1>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<2, TypeOneReplacer1>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<2, TypeOneReplacer1>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<3, TypeOneReplacer1>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<3, TypeOneReplacer1>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<4, TypeOneReplacer1>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<4, TypeOneReplacer1>::HeadType) == typeid(Int8));
|
||||||
|
|
||||||
typedef TypeAllReplacer<Type5, Int8, Int32>::HeadType TypeAllReplacer1;
|
typedef TypeAllReplacer<Type5, Int8, Int32>::HeadType TypeAllReplacer1;
|
||||||
assert (5 == TypeAllReplacer1::length);
|
assert (5 == TypeAllReplacer1::length);
|
||||||
assert (typeid(TypeGetter<0, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<0, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
||||||
assert (typeid(TypeGetter<1, TypeAllReplacer1>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, TypeAllReplacer1>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<2, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<2, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
||||||
assert (typeid(TypeGetter<3, TypeAllReplacer1>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<3, TypeAllReplacer1>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<4, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<4, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
||||||
|
|
||||||
typedef TypeListType<Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void>::HeadType TypeVoid;
|
typedef TypeListType<Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void,Void>::HeadType TypeVoid;
|
||||||
assert (typeid(TypeGetter<0, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<0, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<1, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<1, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<2, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<2, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<3, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<3, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<4, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<4, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<5, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<5, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<6, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<6, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<7, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<7, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<8, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<8, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<9, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<9, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<10, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<10, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<11, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<11, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<12, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<12, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<13, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<13, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<14, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<14, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<15, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<15, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<16, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<16, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<17, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<17, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<18, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<18, TypeVoid>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<19, TypeVoid>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<19, TypeVoid>::HeadType) == typeid(Void));
|
||||||
|
|
||||||
|
|
||||||
typedef TypeOneReplacer<TypeVoid, Void, Int8>::HeadType TypeFirstReplacer;
|
typedef TypeOneReplacer<TypeVoid, Void, Int8>::HeadType TypeFirstReplacer;
|
||||||
assert (typeid(TypeGetter<0, TypeFirstReplacer>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, TypeFirstReplacer>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<1, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<1, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<2, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<2, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<3, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<3, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<4, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<4, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<5, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<5, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<6, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<6, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<7, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<7, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<8, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<8, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<9, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<9, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<10, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<10, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<11, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<11, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<12, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<12, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<13, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<13, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<14, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<14, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<15, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<15, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<16, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<16, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<17, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<17, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<18, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<18, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
assert (typeid(TypeGetter<19, TypeFirstReplacer>::HeadType) == typeid(Void));
|
assert (typeid(TypeGetter<19, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||||
|
|
||||||
typedef TypeOneReplacer<TypeFirstReplacer, Void, Int16>::HeadType TypeSecondReplacer;
|
typedef TypeOneReplacer<TypeFirstReplacer, Void, Int16>::HeadType TypeSecondReplacer;
|
||||||
assert (typeid(TypeGetter<0, TypeSecondReplacer>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, TypeSecondReplacer>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<1, TypeSecondReplacer>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, TypeSecondReplacer>::HeadType) == typeid(Int16));
|
||||||
|
|
||||||
typedef TypeOneReplacer<TypeSecondReplacer, Void, Int32>::HeadType TypeThirdReplacer;
|
typedef TypeOneReplacer<TypeSecondReplacer, Void, Int32>::HeadType TypeThirdReplacer;
|
||||||
assert (typeid(TypeGetter<0, TypeThirdReplacer>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, TypeThirdReplacer>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<1, TypeThirdReplacer>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, TypeThirdReplacer>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<2, TypeThirdReplacer>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<2, TypeThirdReplacer>::HeadType) == typeid(Int32));
|
||||||
|
|
||||||
|
|
||||||
typedef TypeAllReplacer<TypeThirdReplacer, Void, float>::HeadType TypeFourthReplacer;
|
typedef TypeAllReplacer<TypeThirdReplacer, Void, float>::HeadType TypeFourthReplacer;
|
||||||
assert (typeid(TypeGetter<0, TypeFourthReplacer>::HeadType) == typeid(Int8));
|
assert (typeid(TypeGetter<0, TypeFourthReplacer>::HeadType) == typeid(Int8));
|
||||||
assert (typeid(TypeGetter<1, TypeFourthReplacer>::HeadType) == typeid(Int16));
|
assert (typeid(TypeGetter<1, TypeFourthReplacer>::HeadType) == typeid(Int16));
|
||||||
assert (typeid(TypeGetter<2, TypeFourthReplacer>::HeadType) == typeid(Int32));
|
assert (typeid(TypeGetter<2, TypeFourthReplacer>::HeadType) == typeid(Int32));
|
||||||
assert (typeid(TypeGetter<3, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<3, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<4, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<4, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<5, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<5, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<6, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<6, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<7, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<7, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<8, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<8, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<9, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<9, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<10, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<10, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<11, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<11, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<12, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<12, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<13, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<13, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<14, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<14, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<15, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<15, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<16, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<16, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<17, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<17, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<18, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<18, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
assert (typeid(TypeGetter<19, TypeFourthReplacer>::HeadType) == typeid(float));
|
assert (typeid(TypeGetter<19, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TypeListTest::setUp()
|
void TypeListTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TypeListTest::tearDown()
|
void TypeListTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* TypeListTest::suite()
|
CppUnit::Test* TypeListTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TypeListTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TypeListTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, TypeListTest, testTypeList);
|
CppUnit_addTest(pSuite, TypeListTest, testTypeList);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +1,59 @@
|
|||||||
//
|
//
|
||||||
// TypeListTest.h
|
// TypeListTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/TypeListTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/TypeListTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the TypeListTest class.
|
// Definition of the TypeListTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef TypeListTest_INCLUDED
|
#ifndef TypeListTest_INCLUDED
|
||||||
#define TypeListTest_INCLUDED
|
#define TypeListTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class TypeListTest: public CppUnit::TestCase
|
class TypeListTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TypeListTest(const std::string& name);
|
TypeListTest(const std::string& name);
|
||||||
~TypeListTest();
|
~TypeListTest();
|
||||||
|
|
||||||
void testTypeList();
|
void testTypeList();
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // TypeListTest_INCLUDED
|
#endif // TypeListTest_INCLUDED
|
||||||
|
|||||||
@@ -1,122 +1,122 @@
|
|||||||
//
|
//
|
||||||
// UTF8StringTest.cpp
|
// UTF8StringTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/UTF8StringTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/UTF8StringTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "UTF8StringTest.h"
|
#include "UTF8StringTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/UTF8String.h"
|
#include "Poco/UTF8String.h"
|
||||||
|
|
||||||
|
|
||||||
using Poco::UTF8;
|
using Poco::UTF8;
|
||||||
|
|
||||||
|
|
||||||
UTF8StringTest::UTF8StringTest(const std::string& name): CppUnit::TestCase(name)
|
UTF8StringTest::UTF8StringTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UTF8StringTest::~UTF8StringTest()
|
UTF8StringTest::~UTF8StringTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UTF8StringTest::testCompare()
|
void UTF8StringTest::testCompare()
|
||||||
{
|
{
|
||||||
std::string a1("aaaaa");
|
std::string a1("aaaaa");
|
||||||
std::string b1("bbbbb");
|
std::string b1("bbbbb");
|
||||||
|
|
||||||
assert (UTF8::icompare(a1, b1) < 0);
|
assert (UTF8::icompare(a1, b1) < 0);
|
||||||
|
|
||||||
std::string a2("aaaaa");
|
std::string a2("aaaaa");
|
||||||
std::string b2("BBBBB");
|
std::string b2("BBBBB");
|
||||||
|
|
||||||
assert (UTF8::icompare(a2, b2) < 0);
|
assert (UTF8::icompare(a2, b2) < 0);
|
||||||
|
|
||||||
std::string a3("AAAAA");
|
std::string a3("AAAAA");
|
||||||
std::string b3("bbbbb");
|
std::string b3("bbbbb");
|
||||||
|
|
||||||
assert (UTF8::icompare(a3, b3) < 0);
|
assert (UTF8::icompare(a3, b3) < 0);
|
||||||
|
|
||||||
std::string a4("aaaaa");
|
std::string a4("aaaaa");
|
||||||
std::string b4("AAAAA");
|
std::string b4("AAAAA");
|
||||||
|
|
||||||
assert (UTF8::icompare(a4, b4) == 0);
|
assert (UTF8::icompare(a4, b4) == 0);
|
||||||
|
|
||||||
std::string a5("AAAAA");
|
std::string a5("AAAAA");
|
||||||
std::string b5("bbbbb");
|
std::string b5("bbbbb");
|
||||||
|
|
||||||
assert (UTF8::icompare(a5, b5) < 0);
|
assert (UTF8::icompare(a5, b5) < 0);
|
||||||
|
|
||||||
std::string a6("\303\274\303\266\303\244"); // "u"a"o
|
std::string a6("\303\274\303\266\303\244"); // "u"a"o
|
||||||
std::string b6("\303\234\303\226\303\204"); // "U"A"O
|
std::string b6("\303\234\303\226\303\204"); // "U"A"O
|
||||||
|
|
||||||
assert (UTF8::icompare(a6, b6) == 0);
|
assert (UTF8::icompare(a6, b6) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UTF8StringTest::testTransform()
|
void UTF8StringTest::testTransform()
|
||||||
{
|
{
|
||||||
std::string s1("abcde");
|
std::string s1("abcde");
|
||||||
UTF8::toUpperInPlace(s1);
|
UTF8::toUpperInPlace(s1);
|
||||||
assert (s1 == "ABCDE");
|
assert (s1 == "ABCDE");
|
||||||
|
|
||||||
std::string s2("aBcDe123");
|
std::string s2("aBcDe123");
|
||||||
UTF8::toUpperInPlace(s2);
|
UTF8::toUpperInPlace(s2);
|
||||||
assert (s2 == "ABCDE123");
|
assert (s2 == "ABCDE123");
|
||||||
|
|
||||||
std::string s3("\303\274\303\266\303\244"); // "u"a"o
|
std::string s3("\303\274\303\266\303\244"); // "u"a"o
|
||||||
UTF8::toUpperInPlace(s3);
|
UTF8::toUpperInPlace(s3);
|
||||||
assert (s3 == "\303\234\303\226\303\204"); // "U"A"O
|
assert (s3 == "\303\234\303\226\303\204"); // "U"A"O
|
||||||
UTF8::toLowerInPlace(s3);
|
UTF8::toLowerInPlace(s3);
|
||||||
assert (s3 == "\303\274\303\266\303\244"); // "U"A"O
|
assert (s3 == "\303\274\303\266\303\244"); // "U"A"O
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UTF8StringTest::setUp()
|
void UTF8StringTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UTF8StringTest::tearDown()
|
void UTF8StringTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* UTF8StringTest::suite()
|
CppUnit::Test* UTF8StringTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UTF8StringTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UTF8StringTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, UTF8StringTest, testCompare);
|
CppUnit_addTest(pSuite, UTF8StringTest, testCompare);
|
||||||
CppUnit_addTest(pSuite, UTF8StringTest, testTransform);
|
CppUnit_addTest(pSuite, UTF8StringTest, testTransform);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +1,61 @@
|
|||||||
//
|
//
|
||||||
// UTF8StringTest.h
|
// UTF8StringTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/UTF8StringTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/UTF8StringTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the UTF8StringTest class.
|
// Definition of the UTF8StringTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef UTF8StringTest_INCLUDED
|
#ifndef UTF8StringTest_INCLUDED
|
||||||
#define UTF8StringTest_INCLUDED
|
#define UTF8StringTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class UTF8StringTest: public CppUnit::TestCase
|
class UTF8StringTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UTF8StringTest(const std::string& name);
|
UTF8StringTest(const std::string& name);
|
||||||
~UTF8StringTest();
|
~UTF8StringTest();
|
||||||
|
|
||||||
void testCompare();
|
void testCompare();
|
||||||
void testTransform();
|
void testTransform();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // UTF8StringTest_INCLUDED
|
#endif // UTF8StringTest_INCLUDED
|
||||||
|
|||||||
@@ -1,276 +1,276 @@
|
|||||||
//
|
//
|
||||||
// UniqueExpireCacheTest.cpp
|
// UniqueExpireCacheTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireCacheTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireCacheTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "UniqueExpireCacheTest.h"
|
#include "UniqueExpireCacheTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/UniqueExpireCache.h"
|
#include "Poco/UniqueExpireCache.h"
|
||||||
#include "Poco/UniqueAccessExpireCache.h"
|
#include "Poco/UniqueAccessExpireCache.h"
|
||||||
#include "Poco/ExpirationDecorator.h"
|
#include "Poco/ExpirationDecorator.h"
|
||||||
#include "Poco/AccessExpirationDecorator.h"
|
#include "Poco/AccessExpirationDecorator.h"
|
||||||
#include "Poco/Bugcheck.h"
|
#include "Poco/Bugcheck.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
|
|
||||||
|
|
||||||
struct IntVal
|
struct IntVal
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
Poco::Timestamp validUntil;
|
Poco::Timestamp validUntil;
|
||||||
IntVal(int val, Poco::Timestamp::TimeDiff v):value(val), validUntil()
|
IntVal(int val, Poco::Timestamp::TimeDiff v):value(val), validUntil()
|
||||||
{
|
{
|
||||||
validUntil += (v*1000);
|
validUntil += (v*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Poco::Timestamp& getExpiration() const
|
const Poco::Timestamp& getExpiration() const
|
||||||
{
|
{
|
||||||
return validUntil;
|
return validUntil;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef AccessExpirationDecorator<int> DIntVal;
|
typedef AccessExpirationDecorator<int> DIntVal;
|
||||||
|
|
||||||
#define DURSLEEP 250
|
#define DURSLEEP 250
|
||||||
#define DURHALFSLEEP DURSLEEP / 2
|
#define DURHALFSLEEP DURSLEEP / 2
|
||||||
#define DURWAIT 300
|
#define DURWAIT 300
|
||||||
|
|
||||||
|
|
||||||
UniqueExpireCacheTest::UniqueExpireCacheTest(const std::string& name): CppUnit::TestCase(name)
|
UniqueExpireCacheTest::UniqueExpireCacheTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UniqueExpireCacheTest::~UniqueExpireCacheTest()
|
UniqueExpireCacheTest::~UniqueExpireCacheTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testClear()
|
void UniqueExpireCacheTest::testClear()
|
||||||
{
|
{
|
||||||
UniqueExpireCache<int, IntVal> aCache;
|
UniqueExpireCache<int, IntVal> aCache;
|
||||||
aCache.add(1, IntVal(2, DURSLEEP));
|
aCache.add(1, IntVal(2, DURSLEEP));
|
||||||
aCache.add(3, IntVal(4, DURSLEEP));
|
aCache.add(3, IntVal(4, DURSLEEP));
|
||||||
aCache.add(5, IntVal(6, DURSLEEP));
|
aCache.add(5, IntVal(6, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(1)->value == 2);
|
assert (aCache.get(1)->value == 2);
|
||||||
assert (aCache.get(3)->value == 4);
|
assert (aCache.get(3)->value == 4);
|
||||||
assert (aCache.get(5)->value == 6);
|
assert (aCache.get(5)->value == 6);
|
||||||
aCache.clear();
|
aCache.clear();
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testAccessClear()
|
void UniqueExpireCacheTest::testAccessClear()
|
||||||
{
|
{
|
||||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(1)->value() == 2);
|
assert (aCache.get(1)->value() == 2);
|
||||||
assert (aCache.get(3)->value() == 4);
|
assert (aCache.get(3)->value() == 4);
|
||||||
assert (aCache.get(5)->value() == 6);
|
assert (aCache.get(5)->value() == 6);
|
||||||
aCache.clear();
|
aCache.clear();
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testAccessUpdate()
|
void UniqueExpireCacheTest::testAccessUpdate()
|
||||||
{
|
{
|
||||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(1)->value() == 2);
|
assert (aCache.get(1)->value() == 2);
|
||||||
Thread::sleep(DURSLEEP/2);
|
Thread::sleep(DURSLEEP/2);
|
||||||
assert (aCache.get(1)->value() == 2);
|
assert (aCache.get(1)->value() == 2);
|
||||||
Thread::sleep(DURSLEEP/2);
|
Thread::sleep(DURSLEEP/2);
|
||||||
assert (aCache.get(1)->value() == 2);
|
assert (aCache.get(1)->value() == 2);
|
||||||
Thread::sleep(DURSLEEP/2);
|
Thread::sleep(DURSLEEP/2);
|
||||||
assert (aCache.get(1)->value() == 2);
|
assert (aCache.get(1)->value() == 2);
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
Thread::sleep(DURSLEEP*2);
|
Thread::sleep(DURSLEEP*2);
|
||||||
|
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
aCache.remove(666); //must work too
|
aCache.remove(666); //must work too
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testExpire0()
|
void UniqueExpireCacheTest::testExpire0()
|
||||||
{
|
{
|
||||||
UniqueExpireCache<int, IntVal> aCache;
|
UniqueExpireCache<int, IntVal> aCache;
|
||||||
aCache.add(1, IntVal(2, 0));
|
aCache.add(1, IntVal(2, 0));
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testAccessExpire0()
|
void UniqueExpireCacheTest::testAccessExpire0()
|
||||||
{
|
{
|
||||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||||
aCache.add(1, DIntVal(2, Timespan(0, 0)));
|
aCache.add(1, DIntVal(2, Timespan(0, 0)));
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testExpireN()
|
void UniqueExpireCacheTest::testExpireN()
|
||||||
{
|
{
|
||||||
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
||||||
// 3-1|5 -> 5 gets removed
|
// 3-1|5 -> 5 gets removed
|
||||||
UniqueExpireCache<int, IntVal> aCache;
|
UniqueExpireCache<int, IntVal> aCache;
|
||||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
SharedPtr<IntVal> tmp = aCache.get(1);
|
SharedPtr<IntVal> tmp = aCache.get(1);
|
||||||
assert (!tmp.isNull());
|
assert (!tmp.isNull());
|
||||||
assert (tmp->value == 2);
|
assert (tmp->value == 2);
|
||||||
Thread::sleep(DURWAIT);
|
Thread::sleep(DURWAIT);
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
|
|
||||||
// tmp must still be valid, access it
|
// tmp must still be valid, access it
|
||||||
assert (tmp->value == 2);
|
assert (tmp->value == 2);
|
||||||
tmp = aCache.get(1);
|
tmp = aCache.get(1);
|
||||||
assert (tmp.isNull());
|
assert (tmp.isNull());
|
||||||
|
|
||||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||||
Thread::sleep(DURHALFSLEEP);
|
Thread::sleep(DURHALFSLEEP);
|
||||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
tmp = aCache.get(1);
|
tmp = aCache.get(1);
|
||||||
SharedPtr<IntVal> tmp2 = aCache.get(3);
|
SharedPtr<IntVal> tmp2 = aCache.get(3);
|
||||||
assert (tmp->value == 2);
|
assert (tmp->value == 2);
|
||||||
assert (tmp2->value == 4);
|
assert (tmp2->value == 4);
|
||||||
|
|
||||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (tmp->value == 2); // 1-3
|
assert (tmp->value == 2); // 1-3
|
||||||
assert (tmp2->value == 4); // 3-1
|
assert (tmp2->value == 4); // 3-1
|
||||||
tmp2 = aCache.get(3);
|
tmp2 = aCache.get(3);
|
||||||
assert (tmp2->value == 4);
|
assert (tmp2->value == 4);
|
||||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (tmp2->value == 4);
|
assert (tmp2->value == 4);
|
||||||
tmp = aCache.get(1);
|
tmp = aCache.get(1);
|
||||||
tmp2 = aCache.get(3);
|
tmp2 = aCache.get(3);
|
||||||
assert (!tmp);
|
assert (!tmp);
|
||||||
assert (!tmp2);
|
assert (!tmp2);
|
||||||
|
|
||||||
// removing illegal entries should work too
|
// removing illegal entries should work too
|
||||||
aCache.remove(666);
|
aCache.remove(666);
|
||||||
|
|
||||||
aCache.clear();
|
aCache.clear();
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testDuplicateAdd()
|
void UniqueExpireCacheTest::testDuplicateAdd()
|
||||||
{
|
{
|
||||||
UniqueExpireCache<int, IntVal> aCache;
|
UniqueExpireCache<int, IntVal> aCache;
|
||||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value == 2);
|
assert (aCache.get(1)->value == 2);
|
||||||
aCache.add(1, IntVal(3, DURSLEEP));
|
aCache.add(1, IntVal(3, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value == 3);
|
assert (aCache.get(1)->value == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testAccessDuplicateAdd()
|
void UniqueExpireCacheTest::testAccessDuplicateAdd()
|
||||||
{
|
{
|
||||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||||
aCache.add(1, DIntVal(2, DURSLEEP)); // 1
|
aCache.add(1, DIntVal(2, DURSLEEP)); // 1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value() == 2);
|
assert (aCache.get(1)->value() == 2);
|
||||||
aCache.add(1, DIntVal(3, DURSLEEP));
|
aCache.add(1, DIntVal(3, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value() == 3);
|
assert (aCache.get(1)->value() == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::testExpirationDecorator()
|
void UniqueExpireCacheTest::testExpirationDecorator()
|
||||||
{
|
{
|
||||||
typedef ExpirationDecorator<int> ExpireInt;
|
typedef ExpirationDecorator<int> ExpireInt;
|
||||||
UniqueExpireCache<int, ExpireInt> aCache;
|
UniqueExpireCache<int, ExpireInt> aCache;
|
||||||
aCache.add(1, ExpireInt(2, DURSLEEP)); // 1
|
aCache.add(1, ExpireInt(2, DURSLEEP)); // 1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value() == 2);
|
assert (aCache.get(1)->value() == 2);
|
||||||
aCache.add(1, ExpireInt(3, DURSLEEP));
|
aCache.add(1, ExpireInt(3, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value() == 3);
|
assert (aCache.get(1)->value() == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::setUp()
|
void UniqueExpireCacheTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireCacheTest::tearDown()
|
void UniqueExpireCacheTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* UniqueExpireCacheTest::suite()
|
CppUnit::Test* UniqueExpireCacheTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UniqueExpireCacheTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UniqueExpireCacheTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testClear);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testClear);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessClear);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessClear);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessUpdate);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessUpdate);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpire0);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpire0);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessExpire0);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessExpire0);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpireN);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpireN);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testDuplicateAdd);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testDuplicateAdd);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessDuplicateAdd);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessDuplicateAdd);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpirationDecorator);
|
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpirationDecorator);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +1,64 @@
|
|||||||
//
|
//
|
||||||
// UniqueExpireCacheTest.h
|
// UniqueExpireCacheTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireCacheTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireCacheTest.h#2 $
|
||||||
//
|
//
|
||||||
// Tests for ExpireCache
|
// Tests for ExpireCache
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef UniqueExpireCacheTest_INCLUDED
|
#ifndef UniqueExpireCacheTest_INCLUDED
|
||||||
#define UniqueExpireCacheTest_INCLUDED
|
#define UniqueExpireCacheTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class UniqueExpireCacheTest: public CppUnit::TestCase
|
class UniqueExpireCacheTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniqueExpireCacheTest(const std::string& name);
|
UniqueExpireCacheTest(const std::string& name);
|
||||||
~UniqueExpireCacheTest();
|
~UniqueExpireCacheTest();
|
||||||
|
|
||||||
void testClear();
|
void testClear();
|
||||||
void testAccessClear();
|
void testAccessClear();
|
||||||
void testDuplicateAdd();
|
void testDuplicateAdd();
|
||||||
void testAccessDuplicateAdd();
|
void testAccessDuplicateAdd();
|
||||||
void testExpire0();
|
void testExpire0();
|
||||||
void testAccessExpire0();
|
void testAccessExpire0();
|
||||||
void testExpireN();
|
void testExpireN();
|
||||||
void testExpirationDecorator();
|
void testExpirationDecorator();
|
||||||
void testAccessUpdate();
|
void testAccessUpdate();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // UniqueExpireCacheTest_INCLUDED
|
#endif // UniqueExpireCacheTest_INCLUDED
|
||||||
|
|||||||
@@ -1,347 +1,347 @@
|
|||||||
//
|
//
|
||||||
// UniqueExpireLRUCacheTest.cpp
|
// UniqueExpireLRUCacheTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireLRUCacheTest.cpp#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireLRUCacheTest.cpp#2 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "UniqueExpireLRUCacheTest.h"
|
#include "UniqueExpireLRUCacheTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/UniqueExpireLRUCache.h"
|
#include "Poco/UniqueExpireLRUCache.h"
|
||||||
#include "Poco/UniqueAccessExpireLRUCache.h"
|
#include "Poco/UniqueAccessExpireLRUCache.h"
|
||||||
#include "Poco/AccessExpirationDecorator.h"
|
#include "Poco/AccessExpirationDecorator.h"
|
||||||
#include "Poco/Bugcheck.h"
|
#include "Poco/Bugcheck.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
|
|
||||||
|
|
||||||
struct IntVal
|
struct IntVal
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
Poco::Timestamp validUntil;
|
Poco::Timestamp validUntil;
|
||||||
IntVal(int val, Poco::Timestamp::TimeDiff v):value(val), validUntil()
|
IntVal(int val, Poco::Timestamp::TimeDiff v):value(val), validUntil()
|
||||||
{
|
{
|
||||||
validUntil += (v*1000);
|
validUntil += (v*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Poco::Timestamp& getExpiration() const
|
const Poco::Timestamp& getExpiration() const
|
||||||
{
|
{
|
||||||
return validUntil;
|
return validUntil;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef AccessExpirationDecorator<int> DIntVal;
|
typedef AccessExpirationDecorator<int> DIntVal;
|
||||||
|
|
||||||
|
|
||||||
#define DURSLEEP 250
|
#define DURSLEEP 250
|
||||||
#define DURHALFSLEEP DURSLEEP / 2
|
#define DURHALFSLEEP DURSLEEP / 2
|
||||||
#define DURWAIT 300
|
#define DURWAIT 300
|
||||||
|
|
||||||
|
|
||||||
UniqueExpireLRUCacheTest::UniqueExpireLRUCacheTest(const std::string& name): CppUnit::TestCase(name)
|
UniqueExpireLRUCacheTest::UniqueExpireLRUCacheTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UniqueExpireLRUCacheTest::~UniqueExpireLRUCacheTest()
|
UniqueExpireLRUCacheTest::~UniqueExpireLRUCacheTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testClear()
|
void UniqueExpireLRUCacheTest::testClear()
|
||||||
{
|
{
|
||||||
UniqueExpireLRUCache<int, IntVal> aCache;
|
UniqueExpireLRUCache<int, IntVal> aCache;
|
||||||
aCache.add(1, IntVal(2, DURSLEEP));
|
aCache.add(1, IntVal(2, DURSLEEP));
|
||||||
aCache.add(3, IntVal(4, DURSLEEP));
|
aCache.add(3, IntVal(4, DURSLEEP));
|
||||||
aCache.add(5, IntVal(6, DURSLEEP));
|
aCache.add(5, IntVal(6, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(1)->value == 2);
|
assert (aCache.get(1)->value == 2);
|
||||||
assert (aCache.get(3)->value == 4);
|
assert (aCache.get(3)->value == 4);
|
||||||
assert (aCache.get(5)->value == 6);
|
assert (aCache.get(5)->value == 6);
|
||||||
aCache.clear();
|
aCache.clear();
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testAccessClear()
|
void UniqueExpireLRUCacheTest::testAccessClear()
|
||||||
{
|
{
|
||||||
UniqueAccessExpireLRUCache<int, DIntVal> aCache;
|
UniqueAccessExpireLRUCache<int, DIntVal> aCache;
|
||||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(1)->value() == 2);
|
assert (aCache.get(1)->value() == 2);
|
||||||
assert (aCache.get(3)->value() == 4);
|
assert (aCache.get(3)->value() == 4);
|
||||||
assert (aCache.get(5)->value() == 6);
|
assert (aCache.get(5)->value() == 6);
|
||||||
aCache.clear();
|
aCache.clear();
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testExpire0()
|
void UniqueExpireLRUCacheTest::testExpire0()
|
||||||
{
|
{
|
||||||
UniqueExpireLRUCache<int, IntVal> aCache;
|
UniqueExpireLRUCache<int, IntVal> aCache;
|
||||||
aCache.add(1, IntVal(2, 0));
|
aCache.add(1, IntVal(2, 0));
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testExpireN()
|
void UniqueExpireLRUCacheTest::testExpireN()
|
||||||
{
|
{
|
||||||
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
||||||
// 3-1|5 -> 5 gets removed
|
// 3-1|5 -> 5 gets removed
|
||||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
SharedPtr<IntVal> tmp = aCache.get(1);
|
SharedPtr<IntVal> tmp = aCache.get(1);
|
||||||
assert (!tmp.isNull());
|
assert (!tmp.isNull());
|
||||||
assert (tmp->value == 2);
|
assert (tmp->value == 2);
|
||||||
Thread::sleep(DURWAIT);
|
Thread::sleep(DURWAIT);
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
|
|
||||||
// tmp must still be valid, access it
|
// tmp must still be valid, access it
|
||||||
assert (tmp->value == 2);
|
assert (tmp->value == 2);
|
||||||
tmp = aCache.get(1);
|
tmp = aCache.get(1);
|
||||||
assert (!tmp);
|
assert (!tmp);
|
||||||
|
|
||||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||||
Thread::sleep(DURHALFSLEEP);
|
Thread::sleep(DURHALFSLEEP);
|
||||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
tmp = aCache.get(1);
|
tmp = aCache.get(1);
|
||||||
SharedPtr<IntVal> tmp2 = aCache.get(3);
|
SharedPtr<IntVal> tmp2 = aCache.get(3);
|
||||||
assert (tmp->value == 2);
|
assert (tmp->value == 2);
|
||||||
assert (tmp2->value == 4);
|
assert (tmp2->value == 4);
|
||||||
|
|
||||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (tmp->value == 2); // 1-3
|
assert (tmp->value == 2); // 1-3
|
||||||
assert (tmp2->value == 4); // 3-1
|
assert (tmp2->value == 4); // 3-1
|
||||||
tmp2 = aCache.get(3);
|
tmp2 = aCache.get(3);
|
||||||
assert (tmp2->value == 4);
|
assert (tmp2->value == 4);
|
||||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (tmp2->value == 4);
|
assert (tmp2->value == 4);
|
||||||
tmp = aCache.get(1);
|
tmp = aCache.get(1);
|
||||||
tmp2 = aCache.get(3);
|
tmp2 = aCache.get(3);
|
||||||
assert (!tmp);
|
assert (!tmp);
|
||||||
assert (!tmp2);
|
assert (!tmp2);
|
||||||
|
|
||||||
// removing illegal entries should work too
|
// removing illegal entries should work too
|
||||||
aCache.remove(666);
|
aCache.remove(666);
|
||||||
|
|
||||||
aCache.clear();
|
aCache.clear();
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testCacheSize0()
|
void UniqueExpireLRUCacheTest::testCacheSize0()
|
||||||
{
|
{
|
||||||
// cache size 0 is illegal
|
// cache size 0 is illegal
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
UniqueExpireLRUCache<int, IntVal> aCache(0);
|
UniqueExpireLRUCache<int, IntVal> aCache(0);
|
||||||
failmsg ("cache size of 0 is illegal, test should fail");
|
failmsg ("cache size of 0 is illegal, test should fail");
|
||||||
}
|
}
|
||||||
catch (Poco::InvalidArgumentException&)
|
catch (Poco::InvalidArgumentException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testCacheSize1()
|
void UniqueExpireLRUCacheTest::testCacheSize1()
|
||||||
{
|
{
|
||||||
UniqueExpireLRUCache<int, IntVal> aCache(1);
|
UniqueExpireLRUCache<int, IntVal> aCache(1);
|
||||||
aCache.add(1, IntVal(2, DURSLEEP));
|
aCache.add(1, IntVal(2, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value == 2);
|
assert (aCache.get(1)->value == 2);
|
||||||
|
|
||||||
aCache.add(3, IntVal(4, DURSLEEP)); // replaces 1
|
aCache.add(3, IntVal(4, DURSLEEP)); // replaces 1
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.get(3)->value == 4);
|
assert (aCache.get(3)->value == 4);
|
||||||
|
|
||||||
aCache.add(5, IntVal(6, DURSLEEP));
|
aCache.add(5, IntVal(6, DURSLEEP));
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(5)->value == 6);
|
assert (aCache.get(5)->value == 6);
|
||||||
|
|
||||||
aCache.remove(5);
|
aCache.remove(5);
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
|
|
||||||
// removing illegal entries should work too
|
// removing illegal entries should work too
|
||||||
aCache.remove(666);
|
aCache.remove(666);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testCacheSize2()
|
void UniqueExpireLRUCacheTest::testCacheSize2()
|
||||||
{
|
{
|
||||||
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
||||||
// 3-1|5 -> 5 gets removed
|
// 3-1|5 -> 5 gets removed
|
||||||
UniqueExpireLRUCache<int, IntVal> aCache(2);
|
UniqueExpireLRUCache<int, IntVal> aCache(2);
|
||||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value == 2);
|
assert (aCache.get(1)->value == 2);
|
||||||
|
|
||||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.get(1)->value == 2); // 1-3
|
assert (aCache.get(1)->value == 2); // 1-3
|
||||||
assert (aCache.get(3)->value == 4); // 3-1
|
assert (aCache.get(3)->value == 4); // 3-1
|
||||||
|
|
||||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3|1
|
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3|1
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(5)->value == 6); // 5-3
|
assert (aCache.get(5)->value == 6); // 5-3
|
||||||
assert (aCache.get(3)->value == 4); // 3-5
|
assert (aCache.get(3)->value == 4); // 3-5
|
||||||
|
|
||||||
// test remove from the end and the beginning of the list
|
// test remove from the end and the beginning of the list
|
||||||
aCache.remove(5); // 3
|
aCache.remove(5); // 3
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
assert (aCache.get(3)->value == 4); // 3
|
assert (aCache.get(3)->value == 4); // 3
|
||||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3
|
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3
|
||||||
assert (aCache.get(3)->value == 4); // 3-5
|
assert (aCache.get(3)->value == 4); // 3-5
|
||||||
aCache.remove(3); // 5
|
aCache.remove(3); // 5
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
assert (aCache.get(5)->value == 6); // 5
|
assert (aCache.get(5)->value == 6); // 5
|
||||||
|
|
||||||
// removing illegal entries should work too
|
// removing illegal entries should work too
|
||||||
aCache.remove(666);
|
aCache.remove(666);
|
||||||
|
|
||||||
aCache.clear();
|
aCache.clear();
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testCacheSizeN()
|
void UniqueExpireLRUCacheTest::testCacheSizeN()
|
||||||
{
|
{
|
||||||
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
||||||
// 3-1|5 -> 5 gets removed
|
// 3-1|5 -> 5 gets removed
|
||||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value == 2);
|
assert (aCache.get(1)->value == 2);
|
||||||
|
|
||||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.get(1)->value == 2); // 1-3
|
assert (aCache.get(1)->value == 2); // 1-3
|
||||||
assert (aCache.get(3)->value == 4); // 3-1
|
assert (aCache.get(3)->value == 4); // 3-1
|
||||||
|
|
||||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3-1
|
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3-1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(5)->value == 6); // 5-3-1
|
assert (aCache.get(5)->value == 6); // 5-3-1
|
||||||
assert (aCache.get(3)->value == 4); // 3-5-1
|
assert (aCache.get(3)->value == 4); // 3-5-1
|
||||||
|
|
||||||
aCache.add(7, IntVal(8, DURSLEEP)); // 7-5-3|1
|
aCache.add(7, IntVal(8, DURSLEEP)); // 7-5-3|1
|
||||||
assert (!aCache.has(1));
|
assert (!aCache.has(1));
|
||||||
assert (aCache.has(7));
|
assert (aCache.has(7));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.has(5));
|
assert (aCache.has(5));
|
||||||
assert (aCache.get(5)->value == 6); // 5-7-3
|
assert (aCache.get(5)->value == 6); // 5-7-3
|
||||||
assert (aCache.get(3)->value == 4); // 3-5-7
|
assert (aCache.get(3)->value == 4); // 3-5-7
|
||||||
assert (aCache.get(7)->value == 8); // 7-3-5
|
assert (aCache.get(7)->value == 8); // 7-3-5
|
||||||
|
|
||||||
// test remove from the end and the beginning of the list
|
// test remove from the end and the beginning of the list
|
||||||
aCache.remove(5); // 7-3
|
aCache.remove(5); // 7-3
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
assert (aCache.get(3)->value == 4); // 3-7
|
assert (aCache.get(3)->value == 4); // 3-7
|
||||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3-7
|
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3-7
|
||||||
assert (aCache.get(7)->value == 8); // 7-5-3
|
assert (aCache.get(7)->value == 8); // 7-5-3
|
||||||
aCache.remove(7); // 5-3
|
aCache.remove(7); // 5-3
|
||||||
assert (!aCache.has(7));
|
assert (!aCache.has(7));
|
||||||
assert (aCache.has(3));
|
assert (aCache.has(3));
|
||||||
assert (aCache.get(5)->value == 6); // 5-3
|
assert (aCache.get(5)->value == 6); // 5-3
|
||||||
|
|
||||||
// removing illegal entries should work too
|
// removing illegal entries should work too
|
||||||
aCache.remove(666);
|
aCache.remove(666);
|
||||||
|
|
||||||
aCache.clear();
|
aCache.clear();
|
||||||
assert (!aCache.has(5));
|
assert (!aCache.has(5));
|
||||||
assert (!aCache.has(3));
|
assert (!aCache.has(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::testDuplicateAdd()
|
void UniqueExpireLRUCacheTest::testDuplicateAdd()
|
||||||
{
|
{
|
||||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value == 2);
|
assert (aCache.get(1)->value == 2);
|
||||||
aCache.add(1, IntVal(3, DURSLEEP));
|
aCache.add(1, IntVal(3, DURSLEEP));
|
||||||
assert (aCache.has(1));
|
assert (aCache.has(1));
|
||||||
assert (aCache.get(1)->value == 3);
|
assert (aCache.get(1)->value == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::setUp()
|
void UniqueExpireLRUCacheTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UniqueExpireLRUCacheTest::tearDown()
|
void UniqueExpireLRUCacheTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* UniqueExpireLRUCacheTest::suite()
|
CppUnit::Test* UniqueExpireLRUCacheTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UniqueExpireLRUCacheTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UniqueExpireLRUCacheTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testClear);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testClear);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testAccessClear);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testAccessClear);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testExpire0);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testExpire0);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testExpireN);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testExpireN);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize0);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize0);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize1);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize1);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize2);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize2);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSizeN);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSizeN);
|
||||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testDuplicateAdd);
|
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testDuplicateAdd);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +1,64 @@
|
|||||||
//
|
//
|
||||||
// UniqueExpireLRUCacheTest.h
|
// UniqueExpireLRUCacheTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireLRUCacheTest.h#2 $
|
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireLRUCacheTest.h#2 $
|
||||||
//
|
//
|
||||||
// Tests for UniqueExpireLRUCache
|
// Tests for UniqueExpireLRUCache
|
||||||
//
|
//
|
||||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef UniqueExpireLRUCacheTest_INCLUDED
|
#ifndef UniqueExpireLRUCacheTest_INCLUDED
|
||||||
#define UniqueExpireLRUCacheTest_INCLUDED
|
#define UniqueExpireLRUCacheTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class UniqueExpireLRUCacheTest: public CppUnit::TestCase
|
class UniqueExpireLRUCacheTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UniqueExpireLRUCacheTest(const std::string& name);
|
UniqueExpireLRUCacheTest(const std::string& name);
|
||||||
~UniqueExpireLRUCacheTest();
|
~UniqueExpireLRUCacheTest();
|
||||||
|
|
||||||
void testClear();
|
void testClear();
|
||||||
void testAccessClear();
|
void testAccessClear();
|
||||||
void testExpire0();
|
void testExpire0();
|
||||||
void testExpireN();
|
void testExpireN();
|
||||||
void testCacheSize0();
|
void testCacheSize0();
|
||||||
void testCacheSize1();
|
void testCacheSize1();
|
||||||
void testCacheSize2();
|
void testCacheSize2();
|
||||||
void testCacheSizeN();
|
void testCacheSizeN();
|
||||||
void testDuplicateAdd();
|
void testDuplicateAdd();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // UniqueExpireLRUCacheTest_INCLUDED
|
#endif // UniqueExpireLRUCacheTest_INCLUDED
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user