fixed line endings
This commit is contained in:
Родитель
a99f1aae4d
Коммит
e4d9b3b40f
|
@ -1,105 +1,105 @@
|
|||
//
|
||||
// AccessExpirationDecorator.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpirationDecorator.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: AccessExpirationDecorator
|
||||
//
|
||||
// Implementation of the AccessExpirationDecorator template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AccessExpirationDecorator_INCLUDED
|
||||
#define Foundation_AccessExpirationDecorator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Timespan.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <typename TArgs>
|
||||
class AccessExpirationDecorator
|
||||
/// AccessExpirationDecorator adds an expiration method to values so that they can be used
|
||||
/// with the UniqueAccessExpireCache
|
||||
{
|
||||
public:
|
||||
AccessExpirationDecorator():
|
||||
_value(),
|
||||
_span()
|
||||
{
|
||||
}
|
||||
|
||||
AccessExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
|
||||
/// Creates an element that will expire in diff milliseconds
|
||||
_value(p),
|
||||
_span(diffInMs*1000)
|
||||
{
|
||||
}
|
||||
|
||||
AccessExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
|
||||
/// Creates an element that will expire after the given timeSpan
|
||||
_value(p),
|
||||
_span(timeSpan)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~AccessExpirationDecorator()
|
||||
{
|
||||
}
|
||||
|
||||
const Poco::Timespan& getTimeout() const
|
||||
{
|
||||
return _span;
|
||||
}
|
||||
|
||||
const TArgs& value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
TArgs& value()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
private:
|
||||
TArgs _value;
|
||||
Timespan _span;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// AccessExpirationDecorator.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpirationDecorator.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: AccessExpirationDecorator
|
||||
//
|
||||
// Implementation of the AccessExpirationDecorator template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AccessExpirationDecorator_INCLUDED
|
||||
#define Foundation_AccessExpirationDecorator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Timespan.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <typename TArgs>
|
||||
class AccessExpirationDecorator
|
||||
/// AccessExpirationDecorator adds an expiration method to values so that they can be used
|
||||
/// with the UniqueAccessExpireCache
|
||||
{
|
||||
public:
|
||||
AccessExpirationDecorator():
|
||||
_value(),
|
||||
_span()
|
||||
{
|
||||
}
|
||||
|
||||
AccessExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
|
||||
/// Creates an element that will expire in diff milliseconds
|
||||
_value(p),
|
||||
_span(diffInMs*1000)
|
||||
{
|
||||
}
|
||||
|
||||
AccessExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
|
||||
/// Creates an element that will expire after the given timeSpan
|
||||
_value(p),
|
||||
_span(timeSpan)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~AccessExpirationDecorator()
|
||||
{
|
||||
}
|
||||
|
||||
const Poco::Timespan& getTimeout() const
|
||||
{
|
||||
return _span;
|
||||
}
|
||||
|
||||
const TArgs& value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
TArgs& value()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
private:
|
||||
TArgs _value;
|
||||
Timespan _span;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,80 +1,80 @@
|
|||
//
|
||||
// AccessExpireCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: AccessExpireCache
|
||||
//
|
||||
// Definition of the AccessExpireCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AccessExpireCache_INCLUDED
|
||||
#define Foundation_AccessExpireCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/AccessExpireStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TKey, class TValue>
|
||||
class AccessExpireCache: public AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >
|
||||
/// An AccessExpireCache caches entries for a fixed time period (per default 10 minutes).
|
||||
/// Entries expire when they are not accessed with get() during this time period. Each access resets
|
||||
/// the start time for expiration.
|
||||
/// Be careful when using an AccessExpireCache. A cache is often used
|
||||
/// like cache.has(x) followed by cache.get x). Note that it could happen
|
||||
/// that the "has" call works, then the current execution thread gets descheduled, time passes,
|
||||
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||
/// when "get" is invoked.
|
||||
{
|
||||
public:
|
||||
AccessExpireCache(Timestamp::TimeDiff expire = 600000):
|
||||
AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >(AccessExpireStrategy<TKey, TValue>(expire))
|
||||
{
|
||||
}
|
||||
|
||||
~AccessExpireCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
AccessExpireCache(const AccessExpireCache& aCache);
|
||||
AccessExpireCache& operator = (const AccessExpireCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// AccessExpireCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: AccessExpireCache
|
||||
//
|
||||
// Definition of the AccessExpireCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AccessExpireCache_INCLUDED
|
||||
#define Foundation_AccessExpireCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/AccessExpireStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TKey, class TValue>
|
||||
class AccessExpireCache: public AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >
|
||||
/// An AccessExpireCache caches entries for a fixed time period (per default 10 minutes).
|
||||
/// Entries expire when they are not accessed with get() during this time period. Each access resets
|
||||
/// the start time for expiration.
|
||||
/// Be careful when using an AccessExpireCache. A cache is often used
|
||||
/// like cache.has(x) followed by cache.get x). Note that it could happen
|
||||
/// that the "has" call works, then the current execution thread gets descheduled, time passes,
|
||||
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||
/// when "get" is invoked.
|
||||
{
|
||||
public:
|
||||
AccessExpireCache(Timestamp::TimeDiff expire = 600000):
|
||||
AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue> >(AccessExpireStrategy<TKey, TValue>(expire))
|
||||
{
|
||||
}
|
||||
|
||||
~AccessExpireCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
AccessExpireCache(const AccessExpireCache& aCache);
|
||||
AccessExpireCache& operator = (const AccessExpireCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,82 +1,82 @@
|
|||
//
|
||||
// AccessExpireLRUCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireLRUCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: AccessExpireLRUCache
|
||||
//
|
||||
// Definition of the AccessExpireLRUCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AccessExpireLRUCache_INCLUDED
|
||||
#define Foundation_AccessExpireLRUCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/StrategyCollection.h"
|
||||
#include "Poco/AccessExpireStrategy.h"
|
||||
#include "Poco/LRUStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class AccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||
/// An AccessExpireLRUCache combines LRU caching and time based expire caching.
|
||||
/// It cache entries for a fixed time period (per default 10 minutes)
|
||||
/// but also limits the size of the cache (per default: 1024).
|
||||
{
|
||||
public:
|
||||
AccessExpireLRUCache(long cacheSize = 1024, Timestamp::TimeDiff expire = 600000):
|
||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||
{
|
||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||
this->_strategy.pushBack(new AccessExpireStrategy<TKey, TValue>(expire));
|
||||
}
|
||||
|
||||
~AccessExpireLRUCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
AccessExpireLRUCache(const AccessExpireLRUCache& aCache);
|
||||
AccessExpireLRUCache& operator = (const AccessExpireLRUCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// AccessExpireLRUCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireLRUCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: AccessExpireLRUCache
|
||||
//
|
||||
// Definition of the AccessExpireLRUCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AccessExpireLRUCache_INCLUDED
|
||||
#define Foundation_AccessExpireLRUCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/StrategyCollection.h"
|
||||
#include "Poco/AccessExpireStrategy.h"
|
||||
#include "Poco/LRUStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class AccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||
/// An AccessExpireLRUCache combines LRU caching and time based expire caching.
|
||||
/// It cache entries for a fixed time period (per default 10 minutes)
|
||||
/// but also limits the size of the cache (per default: 1024).
|
||||
{
|
||||
public:
|
||||
AccessExpireLRUCache(long cacheSize = 1024, Timestamp::TimeDiff expire = 600000):
|
||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||
{
|
||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||
this->_strategy.pushBack(new AccessExpireStrategy<TKey, TValue>(expire));
|
||||
}
|
||||
|
||||
~AccessExpireLRUCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
AccessExpireLRUCache(const AccessExpireLRUCache& aCache);
|
||||
AccessExpireLRUCache& operator = (const AccessExpireLRUCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,93 +1,93 @@
|
|||
//
|
||||
// AccessExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireStrategy.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: AccessExpireStrategy
|
||||
//
|
||||
// Definition of the AccessExpireStrategy class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AccessExpireStrategy_INCLUDED
|
||||
#define Foundation_AccessExpireStrategy_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/KeyValueArgs.h"
|
||||
#include "Poco/ValidArgs.h"
|
||||
#include "Poco/ExpireStrategy.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/EventArgs.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class AccessExpireStrategy: public ExpireStrategy<TKey, TValue>
|
||||
/// An AccessExpireStrategy implements time and access based expiration of cache entries
|
||||
{
|
||||
public:
|
||||
AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy<TKey, TValue>(expireTimeInMilliSec)
|
||||
/// Create an expire strategy. Note that the smallest allowed caching time is 25ms.
|
||||
/// Anything lower than that is not useful with current operating systems.
|
||||
{
|
||||
}
|
||||
|
||||
~AccessExpireStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
void onGet(const void*, const TKey& key)
|
||||
{
|
||||
// get triggers an update to the expiration time
|
||||
typename ExpireStrategy<TKey, TValue>::Iterator it = this->_keys.find(key);
|
||||
if (it != this->_keys.end())
|
||||
{
|
||||
this->_keyIndex.erase(it->second);
|
||||
Timestamp now;
|
||||
typename ExpireStrategy<TKey, TValue>::IndexIterator itIdx =
|
||||
this->_keyIndex.insert(typename ExpireStrategy<TKey, TValue>::TimeIndex::value_type(now, key));
|
||||
it->second = itIdx;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// AccessExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AccessExpireStrategy.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: AccessExpireStrategy
|
||||
//
|
||||
// Definition of the AccessExpireStrategy class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AccessExpireStrategy_INCLUDED
|
||||
#define Foundation_AccessExpireStrategy_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/KeyValueArgs.h"
|
||||
#include "Poco/ValidArgs.h"
|
||||
#include "Poco/ExpireStrategy.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/EventArgs.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class AccessExpireStrategy: public ExpireStrategy<TKey, TValue>
|
||||
/// An AccessExpireStrategy implements time and access based expiration of cache entries
|
||||
{
|
||||
public:
|
||||
AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy<TKey, TValue>(expireTimeInMilliSec)
|
||||
/// Create an expire strategy. Note that the smallest allowed caching time is 25ms.
|
||||
/// Anything lower than that is not useful with current operating systems.
|
||||
{
|
||||
}
|
||||
|
||||
~AccessExpireStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
void onGet(const void*, const TKey& key)
|
||||
{
|
||||
// get triggers an update to the expiration time
|
||||
typename ExpireStrategy<TKey, TValue>::Iterator it = this->_keys.find(key);
|
||||
if (it != this->_keys.end())
|
||||
{
|
||||
this->_keyIndex.erase(it->second);
|
||||
Timestamp now;
|
||||
typename ExpireStrategy<TKey, TValue>::IndexIterator itIdx =
|
||||
this->_keyIndex.insert(typename ExpireStrategy<TKey, TValue>::TimeIndex::value_type(now, key));
|
||||
it->second = itIdx;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,154 +1,154 @@
|
|||
//
|
||||
// AsyncIOChannel.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOChannel.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOChannel
|
||||
//
|
||||
// Definition of the AsyncIOChannel class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AsyncIOChannel_INCLUDED
|
||||
#define Foundation_AsyncIOChannel_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/ActiveDispatcher.h"
|
||||
#include "Poco/ActiveMethod.h"
|
||||
#include "Poco/AsyncIOCommand.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API AsyncIOChannel: public ActiveDispatcher
|
||||
/// AsyncIOChannel supports asynchronous I/O operations on
|
||||
/// streams or other input/output facilities.
|
||||
///
|
||||
/// This implementation of asynchronous I/O is based on
|
||||
/// blocking I/O operations that are executed in a separate thread.
|
||||
/// Some operating systems may provide special asynchronous
|
||||
/// I/O operations at the operating system level. However, these
|
||||
/// are not used by the current implementation.
|
||||
///
|
||||
/// I/O operations (in the form of AsyncIOCommand subclass instances)
|
||||
/// are queued for execution on an AsyncIOChannel. The AsyncIOChannel's
|
||||
/// I/O thread executes all queued commands in FIFO order.
|
||||
///
|
||||
/// Since AsyncIOChannel is based on ActiveDispatcher, the I/O thread is
|
||||
/// taken from the default thread pool. It should be ensured that the
|
||||
/// capacity of the default thread pool is sufficient before using
|
||||
/// asynchronous I/O. For every AsyncIOChannel instance, one thread
|
||||
/// from the default thread pool is needed.
|
||||
///
|
||||
/// Subclasses of AsyncIOChannel implement asynchronous input/output
|
||||
/// for streams and sockets.
|
||||
///
|
||||
/// The enqueue() active member function is used to enqueue AsyncIOCommand
|
||||
/// instances for execution.
|
||||
///
|
||||
/// The cancel() member function (inherited from ActiveDispatcher) can be
|
||||
/// used to cancel all pending requests.
|
||||
///
|
||||
/// Both the AsyncIOCommand class, and the AsyncIOChannel class offer events
|
||||
/// that notify an interested party about the successful or unsuccessful
|
||||
/// completion of a command.
|
||||
///
|
||||
/// There are also two ways to wait for the completion of a command and
|
||||
/// obtain its result. The first one is by using the return value of
|
||||
/// enqueue(), which is ActiveResult<int>. See the ActiveResult class
|
||||
/// template for more information. The second one is by using the functions
|
||||
/// of AsyncIOCommand, such as wait(), succeeded() and result().
|
||||
///
|
||||
/// AsyncIOChannel supports the operations write, read and seek directly. However,
|
||||
/// subclasses of AsyncIOChannel can define additional operations.
|
||||
{
|
||||
public:
|
||||
ActiveMethod<int, AsyncIOCommand::Ptr, AsyncIOChannel, ActiveStarter<ActiveDispatcher> > enqueue;
|
||||
/// Actual signature:
|
||||
/// int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
|
||||
///
|
||||
/// Enqueue the given command for eventual execution.
|
||||
/// Returns the number of bytes read or written if the operation
|
||||
/// was successful.
|
||||
|
||||
BasicEvent<AsyncIOEvent> commandCompleted;
|
||||
/// Fired when a command has successfully completed.
|
||||
|
||||
BasicEvent<AsyncIOEvent> commandFailed;
|
||||
/// Fired when a command has failed.
|
||||
|
||||
virtual int write(const void* buffer, int length);
|
||||
/// Write length bytes from buffer.
|
||||
///
|
||||
/// Must be overridden by subclasses. The default implementation
|
||||
/// throws a NotImplementedException.
|
||||
///
|
||||
/// Returns the number of bytes written.
|
||||
|
||||
virtual int read(void* buffer, int length);
|
||||
/// Read up to length bytes into buffer.
|
||||
///
|
||||
/// Must be overridden by subclasses. The default implementation
|
||||
/// throws a NotImplementedException.
|
||||
///
|
||||
/// Returns the number of bytes read.
|
||||
|
||||
virtual int seek(std::streamoff off, std::ios::seekdir dir);
|
||||
/// Sets the current read/write position.
|
||||
///
|
||||
/// Must be overridden by subclasses. The default implementation
|
||||
/// throws a NotImplementedException.
|
||||
///
|
||||
/// Always returns 0.
|
||||
|
||||
protected:
|
||||
AsyncIOChannel();
|
||||
/// Creates the AsyncIOChannel.
|
||||
|
||||
~AsyncIOChannel();
|
||||
/// Destroys the AsyncIOChannel.
|
||||
|
||||
int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
|
||||
/// Execute the given command by calling
|
||||
/// pCommand->execute(this);
|
||||
/// and return the result.
|
||||
|
||||
private:
|
||||
AsyncIOChannel(const AsyncIOChannel&);
|
||||
AsyncIOChannel& operator = (const AsyncIOChannel&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_AsyncIOChannel_INCLUDED
|
||||
//
|
||||
// AsyncIOChannel.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOChannel.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOChannel
|
||||
//
|
||||
// Definition of the AsyncIOChannel class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AsyncIOChannel_INCLUDED
|
||||
#define Foundation_AsyncIOChannel_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/ActiveDispatcher.h"
|
||||
#include "Poco/ActiveMethod.h"
|
||||
#include "Poco/AsyncIOCommand.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API AsyncIOChannel: public ActiveDispatcher
|
||||
/// AsyncIOChannel supports asynchronous I/O operations on
|
||||
/// streams or other input/output facilities.
|
||||
///
|
||||
/// This implementation of asynchronous I/O is based on
|
||||
/// blocking I/O operations that are executed in a separate thread.
|
||||
/// Some operating systems may provide special asynchronous
|
||||
/// I/O operations at the operating system level. However, these
|
||||
/// are not used by the current implementation.
|
||||
///
|
||||
/// I/O operations (in the form of AsyncIOCommand subclass instances)
|
||||
/// are queued for execution on an AsyncIOChannel. The AsyncIOChannel's
|
||||
/// I/O thread executes all queued commands in FIFO order.
|
||||
///
|
||||
/// Since AsyncIOChannel is based on ActiveDispatcher, the I/O thread is
|
||||
/// taken from the default thread pool. It should be ensured that the
|
||||
/// capacity of the default thread pool is sufficient before using
|
||||
/// asynchronous I/O. For every AsyncIOChannel instance, one thread
|
||||
/// from the default thread pool is needed.
|
||||
///
|
||||
/// Subclasses of AsyncIOChannel implement asynchronous input/output
|
||||
/// for streams and sockets.
|
||||
///
|
||||
/// The enqueue() active member function is used to enqueue AsyncIOCommand
|
||||
/// instances for execution.
|
||||
///
|
||||
/// The cancel() member function (inherited from ActiveDispatcher) can be
|
||||
/// used to cancel all pending requests.
|
||||
///
|
||||
/// Both the AsyncIOCommand class, and the AsyncIOChannel class offer events
|
||||
/// that notify an interested party about the successful or unsuccessful
|
||||
/// completion of a command.
|
||||
///
|
||||
/// There are also two ways to wait for the completion of a command and
|
||||
/// obtain its result. The first one is by using the return value of
|
||||
/// enqueue(), which is ActiveResult<int>. See the ActiveResult class
|
||||
/// template for more information. The second one is by using the functions
|
||||
/// of AsyncIOCommand, such as wait(), succeeded() and result().
|
||||
///
|
||||
/// AsyncIOChannel supports the operations write, read and seek directly. However,
|
||||
/// subclasses of AsyncIOChannel can define additional operations.
|
||||
{
|
||||
public:
|
||||
ActiveMethod<int, AsyncIOCommand::Ptr, AsyncIOChannel, ActiveStarter<ActiveDispatcher> > enqueue;
|
||||
/// Actual signature:
|
||||
/// int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
|
||||
///
|
||||
/// Enqueue the given command for eventual execution.
|
||||
/// Returns the number of bytes read or written if the operation
|
||||
/// was successful.
|
||||
|
||||
BasicEvent<AsyncIOEvent> commandCompleted;
|
||||
/// Fired when a command has successfully completed.
|
||||
|
||||
BasicEvent<AsyncIOEvent> commandFailed;
|
||||
/// Fired when a command has failed.
|
||||
|
||||
virtual int write(const void* buffer, int length);
|
||||
/// Write length bytes from buffer.
|
||||
///
|
||||
/// Must be overridden by subclasses. The default implementation
|
||||
/// throws a NotImplementedException.
|
||||
///
|
||||
/// Returns the number of bytes written.
|
||||
|
||||
virtual int read(void* buffer, int length);
|
||||
/// Read up to length bytes into buffer.
|
||||
///
|
||||
/// Must be overridden by subclasses. The default implementation
|
||||
/// throws a NotImplementedException.
|
||||
///
|
||||
/// Returns the number of bytes read.
|
||||
|
||||
virtual int seek(std::streamoff off, std::ios::seekdir dir);
|
||||
/// Sets the current read/write position.
|
||||
///
|
||||
/// Must be overridden by subclasses. The default implementation
|
||||
/// throws a NotImplementedException.
|
||||
///
|
||||
/// Always returns 0.
|
||||
|
||||
protected:
|
||||
AsyncIOChannel();
|
||||
/// Creates the AsyncIOChannel.
|
||||
|
||||
~AsyncIOChannel();
|
||||
/// Destroys the AsyncIOChannel.
|
||||
|
||||
int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
|
||||
/// Execute the given command by calling
|
||||
/// pCommand->execute(this);
|
||||
/// and return the result.
|
||||
|
||||
private:
|
||||
AsyncIOChannel(const AsyncIOChannel&);
|
||||
AsyncIOChannel& operator = (const AsyncIOChannel&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_AsyncIOChannel_INCLUDED
|
||||
|
|
|
@ -1,319 +1,319 @@
|
|||
//
|
||||
// AsyncIOCommand.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOCommand.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOCommand
|
||||
//
|
||||
// Definition of the AsyncIOCommand class and subclasses.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AsyncIOCommand_INCLUDED
|
||||
#define Foundation_AsyncIOCommand_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Event.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <ios>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class AsyncIOChannel;
|
||||
|
||||
|
||||
class Foundation_API AsyncIOCommand: public RefCountedObject
|
||||
/// AsyncIOCommand is the base class for all asynchronous input/output
|
||||
/// commands used with AsyncIOChannel.
|
||||
///
|
||||
/// See class AsyncIOChannel for more information about asynchronous input/output.
|
||||
{
|
||||
public:
|
||||
typedef AutoPtr<AsyncIOCommand> Ptr;
|
||||
|
||||
enum State
|
||||
{
|
||||
CMD_PENDING, /// Command is queued for execution.
|
||||
CMD_IN_PROGRESS, /// Command is currently being executed.
|
||||
CMD_COMPLETED, /// Command has completed successfully.
|
||||
CMD_FAILED /// Command has failed.
|
||||
};
|
||||
|
||||
BasicEvent<AsyncIOEvent> commandCompleted;
|
||||
/// Fired when the command has successfully completed.
|
||||
|
||||
BasicEvent<AsyncIOEvent> commandFailed;
|
||||
/// Fired when the command has failed.
|
||||
|
||||
State state() const;
|
||||
/// Returns the current state of the command.
|
||||
|
||||
void wait();
|
||||
/// Waits for the completion of the command.
|
||||
|
||||
void wait(long milliseconds);
|
||||
/// Waits at most the given timeout for the
|
||||
/// completion of the command. Throws a
|
||||
/// TimeoutException if the command does
|
||||
/// not complete within the given timeout.
|
||||
|
||||
bool tryWait(long milliseconds);
|
||||
/// Waits at most the given timeout for the
|
||||
/// completion of the command.
|
||||
///
|
||||
/// Returns true if the command completes within
|
||||
/// the given timeout, otherwise false.
|
||||
|
||||
bool succeeded() const;
|
||||
/// Returns true iff the command completed successfully.
|
||||
|
||||
bool failed() const;
|
||||
/// Returns true iff the command has completed with an error.
|
||||
|
||||
const Exception* exception() const;
|
||||
/// If the command failed with an exception, returns a
|
||||
/// clone of the exception. Otherwise, returns a null pointer.
|
||||
|
||||
int execute(AsyncIOChannel& channel);
|
||||
/// Executes the command on the given AsyncIOChannel.
|
||||
///
|
||||
/// Sets the state to CMD_IN_PROGRESS, calls
|
||||
/// executeImpl(), and, according to its result,
|
||||
/// sets the state to CMD_COMPLETED or CMD_FAILED
|
||||
/// and signals the event.
|
||||
///
|
||||
/// Returns the number of bytes processed by the
|
||||
/// command.
|
||||
|
||||
int result() const;
|
||||
/// Returns the result of the command.
|
||||
|
||||
protected:
|
||||
AsyncIOCommand();
|
||||
/// Creates the AsyncIOCommand.
|
||||
|
||||
~AsyncIOCommand();
|
||||
/// Destroys the AsyncIOCommand.
|
||||
|
||||
virtual int executeImpl(AsyncIOChannel& channel) = 0;
|
||||
/// Executes the command on the given AsyncIOChannel.
|
||||
/// Must be overridded by subclasses.
|
||||
///
|
||||
/// Returns the number of bytes processed by the
|
||||
/// command.
|
||||
|
||||
private:
|
||||
State _state;
|
||||
Event _completed;
|
||||
int _result;
|
||||
Exception* _pException;
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncWriteCommand: public AsyncIOCommand
|
||||
/// An asynchronous write command.
|
||||
{
|
||||
public:
|
||||
AsyncWriteCommand(const void* buffer, int length);
|
||||
/// Create an AsyncWriteCommand for writing length bytes
|
||||
/// from the given buffer. The given buffer must be
|
||||
/// valid until the command completes.
|
||||
|
||||
const void* buffer() const;
|
||||
/// Returns the buffer's address.
|
||||
|
||||
int length() const;
|
||||
/// Returns the buffer's size.
|
||||
|
||||
protected:
|
||||
int executeImpl(AsyncIOChannel& channel);
|
||||
~AsyncWriteCommand();
|
||||
|
||||
private:
|
||||
AsyncWriteCommand();
|
||||
|
||||
const void* _buffer;
|
||||
int _length;
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncBufferedWriteCommand: public AsyncWriteCommand
|
||||
/// An asynchronous write command. The difference to
|
||||
/// AsyncWriteCommand is that AsyncBufferedWriteCommand
|
||||
/// copies the data in the buffer into an internal buffer, thus
|
||||
/// the given buffer can be deleted as soon as the constructor
|
||||
/// returns.
|
||||
{
|
||||
public:
|
||||
AsyncBufferedWriteCommand(const void* buffer, int length);
|
||||
/// Create an AsyncBufferedWriteCommand for writing length bytes
|
||||
/// from the given buffer and copies the data from the
|
||||
/// given buffer into an internal buffer.
|
||||
///
|
||||
/// The internal buffer can be accessed via the buffer()
|
||||
/// member function inherited from AsyncWriteCommand.
|
||||
|
||||
protected:
|
||||
~AsyncBufferedWriteCommand();
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncReadCommand: public AsyncIOCommand
|
||||
/// An asynchronous read command.
|
||||
{
|
||||
public:
|
||||
AsyncReadCommand(void* buffer, int length);
|
||||
/// Create an AsyncReadCommand for reading up to length
|
||||
/// bytes into the given buffer.
|
||||
|
||||
void* buffer() const;
|
||||
/// Returns the buffer's address.
|
||||
|
||||
int length() const;
|
||||
/// Returns the buffer's size.
|
||||
|
||||
protected:
|
||||
int executeImpl(AsyncIOChannel& channel);
|
||||
~AsyncReadCommand();
|
||||
|
||||
private:
|
||||
AsyncReadCommand();
|
||||
|
||||
void* _buffer;
|
||||
int _length;
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncBufferedReadCommand: public AsyncReadCommand
|
||||
/// An asynchronous read command. In contrast to
|
||||
/// AsyncReadCommand, which requires an externally supplied
|
||||
/// buffer that must be valid until the command completes,
|
||||
/// AsyncBufferedReadCommand maintains an internal buffer.
|
||||
{
|
||||
public:
|
||||
AsyncBufferedReadCommand(int length);
|
||||
/// Create an AsyncReadCommand for reading up to length
|
||||
/// bytes into an internal buffer.
|
||||
///
|
||||
/// The buffer can be accessed via the buffer() member
|
||||
/// function inherited from AsyncReadCommand.
|
||||
|
||||
protected:
|
||||
~AsyncBufferedReadCommand();
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncSeekCommand: public AsyncIOCommand
|
||||
/// An asynchronous seek command.
|
||||
{
|
||||
public:
|
||||
AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir = std::ios::beg);
|
||||
/// Creates an AsyncSeekCommand for setting the current read/write position.
|
||||
|
||||
protected:
|
||||
int executeImpl(AsyncIOChannel& channel);
|
||||
~AsyncSeekCommand();
|
||||
|
||||
private:
|
||||
AsyncSeekCommand();
|
||||
|
||||
std::streamoff _off;
|
||||
std::ios::seekdir _dir;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AsyncIOCommand::State AsyncIOCommand::state() const
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
|
||||
|
||||
inline int AsyncIOCommand::result() const
|
||||
{
|
||||
return _result;
|
||||
}
|
||||
|
||||
|
||||
inline const Exception* AsyncIOCommand::exception() const
|
||||
{
|
||||
return _pException;
|
||||
}
|
||||
|
||||
|
||||
inline bool AsyncIOCommand::succeeded() const
|
||||
{
|
||||
return _state == CMD_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
inline bool AsyncIOCommand::failed() const
|
||||
{
|
||||
return _state == CMD_FAILED;
|
||||
}
|
||||
|
||||
|
||||
inline const void* AsyncWriteCommand::buffer() const
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
|
||||
inline int AsyncWriteCommand::length() const
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
|
||||
inline void* AsyncReadCommand::buffer() const
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
|
||||
inline int AsyncReadCommand::length() const
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_AsyncIOCommand_INCLUDED
|
||||
//
|
||||
// AsyncIOCommand.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOCommand.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOCommand
|
||||
//
|
||||
// Definition of the AsyncIOCommand class and subclasses.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AsyncIOCommand_INCLUDED
|
||||
#define Foundation_AsyncIOCommand_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Event.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <ios>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class AsyncIOChannel;
|
||||
|
||||
|
||||
class Foundation_API AsyncIOCommand: public RefCountedObject
|
||||
/// AsyncIOCommand is the base class for all asynchronous input/output
|
||||
/// commands used with AsyncIOChannel.
|
||||
///
|
||||
/// See class AsyncIOChannel for more information about asynchronous input/output.
|
||||
{
|
||||
public:
|
||||
typedef AutoPtr<AsyncIOCommand> Ptr;
|
||||
|
||||
enum State
|
||||
{
|
||||
CMD_PENDING, /// Command is queued for execution.
|
||||
CMD_IN_PROGRESS, /// Command is currently being executed.
|
||||
CMD_COMPLETED, /// Command has completed successfully.
|
||||
CMD_FAILED /// Command has failed.
|
||||
};
|
||||
|
||||
BasicEvent<AsyncIOEvent> commandCompleted;
|
||||
/// Fired when the command has successfully completed.
|
||||
|
||||
BasicEvent<AsyncIOEvent> commandFailed;
|
||||
/// Fired when the command has failed.
|
||||
|
||||
State state() const;
|
||||
/// Returns the current state of the command.
|
||||
|
||||
void wait();
|
||||
/// Waits for the completion of the command.
|
||||
|
||||
void wait(long milliseconds);
|
||||
/// Waits at most the given timeout for the
|
||||
/// completion of the command. Throws a
|
||||
/// TimeoutException if the command does
|
||||
/// not complete within the given timeout.
|
||||
|
||||
bool tryWait(long milliseconds);
|
||||
/// Waits at most the given timeout for the
|
||||
/// completion of the command.
|
||||
///
|
||||
/// Returns true if the command completes within
|
||||
/// the given timeout, otherwise false.
|
||||
|
||||
bool succeeded() const;
|
||||
/// Returns true iff the command completed successfully.
|
||||
|
||||
bool failed() const;
|
||||
/// Returns true iff the command has completed with an error.
|
||||
|
||||
const Exception* exception() const;
|
||||
/// If the command failed with an exception, returns a
|
||||
/// clone of the exception. Otherwise, returns a null pointer.
|
||||
|
||||
int execute(AsyncIOChannel& channel);
|
||||
/// Executes the command on the given AsyncIOChannel.
|
||||
///
|
||||
/// Sets the state to CMD_IN_PROGRESS, calls
|
||||
/// executeImpl(), and, according to its result,
|
||||
/// sets the state to CMD_COMPLETED or CMD_FAILED
|
||||
/// and signals the event.
|
||||
///
|
||||
/// Returns the number of bytes processed by the
|
||||
/// command.
|
||||
|
||||
int result() const;
|
||||
/// Returns the result of the command.
|
||||
|
||||
protected:
|
||||
AsyncIOCommand();
|
||||
/// Creates the AsyncIOCommand.
|
||||
|
||||
~AsyncIOCommand();
|
||||
/// Destroys the AsyncIOCommand.
|
||||
|
||||
virtual int executeImpl(AsyncIOChannel& channel) = 0;
|
||||
/// Executes the command on the given AsyncIOChannel.
|
||||
/// Must be overridded by subclasses.
|
||||
///
|
||||
/// Returns the number of bytes processed by the
|
||||
/// command.
|
||||
|
||||
private:
|
||||
State _state;
|
||||
Event _completed;
|
||||
int _result;
|
||||
Exception* _pException;
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncWriteCommand: public AsyncIOCommand
|
||||
/// An asynchronous write command.
|
||||
{
|
||||
public:
|
||||
AsyncWriteCommand(const void* buffer, int length);
|
||||
/// Create an AsyncWriteCommand for writing length bytes
|
||||
/// from the given buffer. The given buffer must be
|
||||
/// valid until the command completes.
|
||||
|
||||
const void* buffer() const;
|
||||
/// Returns the buffer's address.
|
||||
|
||||
int length() const;
|
||||
/// Returns the buffer's size.
|
||||
|
||||
protected:
|
||||
int executeImpl(AsyncIOChannel& channel);
|
||||
~AsyncWriteCommand();
|
||||
|
||||
private:
|
||||
AsyncWriteCommand();
|
||||
|
||||
const void* _buffer;
|
||||
int _length;
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncBufferedWriteCommand: public AsyncWriteCommand
|
||||
/// An asynchronous write command. The difference to
|
||||
/// AsyncWriteCommand is that AsyncBufferedWriteCommand
|
||||
/// copies the data in the buffer into an internal buffer, thus
|
||||
/// the given buffer can be deleted as soon as the constructor
|
||||
/// returns.
|
||||
{
|
||||
public:
|
||||
AsyncBufferedWriteCommand(const void* buffer, int length);
|
||||
/// Create an AsyncBufferedWriteCommand for writing length bytes
|
||||
/// from the given buffer and copies the data from the
|
||||
/// given buffer into an internal buffer.
|
||||
///
|
||||
/// The internal buffer can be accessed via the buffer()
|
||||
/// member function inherited from AsyncWriteCommand.
|
||||
|
||||
protected:
|
||||
~AsyncBufferedWriteCommand();
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncReadCommand: public AsyncIOCommand
|
||||
/// An asynchronous read command.
|
||||
{
|
||||
public:
|
||||
AsyncReadCommand(void* buffer, int length);
|
||||
/// Create an AsyncReadCommand for reading up to length
|
||||
/// bytes into the given buffer.
|
||||
|
||||
void* buffer() const;
|
||||
/// Returns the buffer's address.
|
||||
|
||||
int length() const;
|
||||
/// Returns the buffer's size.
|
||||
|
||||
protected:
|
||||
int executeImpl(AsyncIOChannel& channel);
|
||||
~AsyncReadCommand();
|
||||
|
||||
private:
|
||||
AsyncReadCommand();
|
||||
|
||||
void* _buffer;
|
||||
int _length;
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncBufferedReadCommand: public AsyncReadCommand
|
||||
/// An asynchronous read command. In contrast to
|
||||
/// AsyncReadCommand, which requires an externally supplied
|
||||
/// buffer that must be valid until the command completes,
|
||||
/// AsyncBufferedReadCommand maintains an internal buffer.
|
||||
{
|
||||
public:
|
||||
AsyncBufferedReadCommand(int length);
|
||||
/// Create an AsyncReadCommand for reading up to length
|
||||
/// bytes into an internal buffer.
|
||||
///
|
||||
/// The buffer can be accessed via the buffer() member
|
||||
/// function inherited from AsyncReadCommand.
|
||||
|
||||
protected:
|
||||
~AsyncBufferedReadCommand();
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API AsyncSeekCommand: public AsyncIOCommand
|
||||
/// An asynchronous seek command.
|
||||
{
|
||||
public:
|
||||
AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir = std::ios::beg);
|
||||
/// Creates an AsyncSeekCommand for setting the current read/write position.
|
||||
|
||||
protected:
|
||||
int executeImpl(AsyncIOChannel& channel);
|
||||
~AsyncSeekCommand();
|
||||
|
||||
private:
|
||||
AsyncSeekCommand();
|
||||
|
||||
std::streamoff _off;
|
||||
std::ios::seekdir _dir;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AsyncIOCommand::State AsyncIOCommand::state() const
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
|
||||
|
||||
inline int AsyncIOCommand::result() const
|
||||
{
|
||||
return _result;
|
||||
}
|
||||
|
||||
|
||||
inline const Exception* AsyncIOCommand::exception() const
|
||||
{
|
||||
return _pException;
|
||||
}
|
||||
|
||||
|
||||
inline bool AsyncIOCommand::succeeded() const
|
||||
{
|
||||
return _state == CMD_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
inline bool AsyncIOCommand::failed() const
|
||||
{
|
||||
return _state == CMD_FAILED;
|
||||
}
|
||||
|
||||
|
||||
inline const void* AsyncWriteCommand::buffer() const
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
|
||||
inline int AsyncWriteCommand::length() const
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
|
||||
inline void* AsyncReadCommand::buffer() const
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
|
||||
inline int AsyncReadCommand::length() const
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_AsyncIOCommand_INCLUDED
|
||||
|
|
|
@ -1,121 +1,121 @@
|
|||
//
|
||||
// AsyncIOEvent.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOEvent.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOEvent
|
||||
//
|
||||
// Definition of the AsyncIOEvent class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AsyncIOEvent_INCLUDED
|
||||
#define Foundation_AsyncIOEvent_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class AsyncIOCommand;
|
||||
class AsyncIOChannel;
|
||||
|
||||
|
||||
class Foundation_API AsyncIOEvent
|
||||
/// The AsyncIOEvent class holds information about an event
|
||||
/// caused by asynchronous input or output operation.
|
||||
{
|
||||
public:
|
||||
enum EventKind
|
||||
{
|
||||
EV_COMMAND_COMPLETED,
|
||||
EV_COMMAND_FAILED
|
||||
};
|
||||
|
||||
AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what);
|
||||
/// Creates the AsyncIOEvent.
|
||||
|
||||
AsyncIOEvent(const AsyncIOEvent& event);
|
||||
/// Creates a AsyncIOEvent from another one.
|
||||
|
||||
~AsyncIOEvent();
|
||||
/// Destroys the AsyncIOEvent.
|
||||
|
||||
AsyncIOEvent& operator = (const AsyncIOEvent& event);
|
||||
/// Assigns a AsyncIOEvent.
|
||||
|
||||
void swap(AsyncIOEvent& event);
|
||||
/// Swaps the event with another one.
|
||||
|
||||
AsyncIOCommand& command() const;
|
||||
/// Returns the command that caused the event.
|
||||
|
||||
AsyncIOChannel& channel() const;
|
||||
/// Returns the channel that caused the event.
|
||||
|
||||
EventKind what() const;
|
||||
/// Returns the reason of the event.
|
||||
|
||||
private:
|
||||
AsyncIOEvent();
|
||||
|
||||
AsyncIOCommand* _pCommand;
|
||||
AsyncIOChannel* _pChannel;
|
||||
EventKind _what;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AsyncIOCommand& AsyncIOEvent::command() const
|
||||
{
|
||||
return *_pCommand;
|
||||
}
|
||||
|
||||
|
||||
inline AsyncIOChannel& AsyncIOEvent::channel() const
|
||||
{
|
||||
return *_pChannel;
|
||||
}
|
||||
|
||||
|
||||
inline AsyncIOEvent::EventKind AsyncIOEvent::what() const
|
||||
{
|
||||
return _what;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_AsyncIOEvent_INCLUDED
|
||||
//
|
||||
// AsyncIOEvent.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOEvent.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOEvent
|
||||
//
|
||||
// Definition of the AsyncIOEvent class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AsyncIOEvent_INCLUDED
|
||||
#define Foundation_AsyncIOEvent_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class AsyncIOCommand;
|
||||
class AsyncIOChannel;
|
||||
|
||||
|
||||
class Foundation_API AsyncIOEvent
|
||||
/// The AsyncIOEvent class holds information about an event
|
||||
/// caused by asynchronous input or output operation.
|
||||
{
|
||||
public:
|
||||
enum EventKind
|
||||
{
|
||||
EV_COMMAND_COMPLETED,
|
||||
EV_COMMAND_FAILED
|
||||
};
|
||||
|
||||
AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what);
|
||||
/// Creates the AsyncIOEvent.
|
||||
|
||||
AsyncIOEvent(const AsyncIOEvent& event);
|
||||
/// Creates a AsyncIOEvent from another one.
|
||||
|
||||
~AsyncIOEvent();
|
||||
/// Destroys the AsyncIOEvent.
|
||||
|
||||
AsyncIOEvent& operator = (const AsyncIOEvent& event);
|
||||
/// Assigns a AsyncIOEvent.
|
||||
|
||||
void swap(AsyncIOEvent& event);
|
||||
/// Swaps the event with another one.
|
||||
|
||||
AsyncIOCommand& command() const;
|
||||
/// Returns the command that caused the event.
|
||||
|
||||
AsyncIOChannel& channel() const;
|
||||
/// Returns the channel that caused the event.
|
||||
|
||||
EventKind what() const;
|
||||
/// Returns the reason of the event.
|
||||
|
||||
private:
|
||||
AsyncIOEvent();
|
||||
|
||||
AsyncIOCommand* _pCommand;
|
||||
AsyncIOChannel* _pChannel;
|
||||
EventKind _what;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AsyncIOCommand& AsyncIOEvent::command() const
|
||||
{
|
||||
return *_pCommand;
|
||||
}
|
||||
|
||||
|
||||
inline AsyncIOChannel& AsyncIOEvent::channel() const
|
||||
{
|
||||
return *_pChannel;
|
||||
}
|
||||
|
||||
|
||||
inline AsyncIOEvent::EventKind AsyncIOEvent::what() const
|
||||
{
|
||||
return _what;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_AsyncIOEvent_INCLUDED
|
||||
|
|
|
@ -1,96 +1,96 @@
|
|||
//
|
||||
// AsyncStreamChannel.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncStreamChannel.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncStreamChannel
|
||||
//
|
||||
// Definition of the AsyncStreamChannel class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AsyncStreamChannel_INCLUDED
|
||||
#define Foundation_AsyncStreamChannel_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/AsyncIOChannel.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API AsyncStreamChannel: public AsyncIOChannel
|
||||
/// AsyncStreamChannel provides an AsyncIOChannel for I/O streams.
|
||||
///
|
||||
/// Usage Example:
|
||||
/// std::stringstream str;
|
||||
/// AsyncStreamChannel channel(str);
|
||||
/// channel.enqueue(new AsyncWriteCommand("Hello", 5));
|
||||
/// channel.enqueue(new AsyncWriteCommand(", ", 2));
|
||||
/// ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
|
||||
/// result.wait();
|
||||
/// std::string s(str.str());
|
||||
{
|
||||
public:
|
||||
AsyncStreamChannel(std::istream& istr);
|
||||
/// Creates an AsyncStreamChannel using the given input stream.
|
||||
/// Only read and seek operations will be allowed.
|
||||
|
||||
AsyncStreamChannel(std::ostream& ostr);
|
||||
/// Creates an AsyncStreamChannel using the given output stream.
|
||||
/// Only write and seek operations will be allowed.
|
||||
|
||||
AsyncStreamChannel(std::iostream& iostr);
|
||||
/// Creates an AsyncStreamChannel using the given input/output stream.
|
||||
|
||||
~AsyncStreamChannel();
|
||||
/// Destroys the AsyncStreamChannel.
|
||||
|
||||
// AsyncIOChannel
|
||||
int write(const void* buffer, int length);
|
||||
int read(void* buffer, int length);
|
||||
int seek(std::streamoff off, std::ios::seekdir dir);
|
||||
|
||||
private:
|
||||
AsyncStreamChannel();
|
||||
|
||||
std::istream* _pIstr;
|
||||
std::ostream* _pOstr;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_AsyncStreamChannel_INCLUDED
|
||||
//
|
||||
// AsyncStreamChannel.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AsyncStreamChannel.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncStreamChannel
|
||||
//
|
||||
// Definition of the AsyncStreamChannel class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_AsyncStreamChannel_INCLUDED
|
||||
#define Foundation_AsyncStreamChannel_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/AsyncIOChannel.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API AsyncStreamChannel: public AsyncIOChannel
|
||||
/// AsyncStreamChannel provides an AsyncIOChannel for I/O streams.
|
||||
///
|
||||
/// Usage Example:
|
||||
/// std::stringstream str;
|
||||
/// AsyncStreamChannel channel(str);
|
||||
/// channel.enqueue(new AsyncWriteCommand("Hello", 5));
|
||||
/// channel.enqueue(new AsyncWriteCommand(", ", 2));
|
||||
/// ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
|
||||
/// result.wait();
|
||||
/// std::string s(str.str());
|
||||
{
|
||||
public:
|
||||
AsyncStreamChannel(std::istream& istr);
|
||||
/// Creates an AsyncStreamChannel using the given input stream.
|
||||
/// Only read and seek operations will be allowed.
|
||||
|
||||
AsyncStreamChannel(std::ostream& ostr);
|
||||
/// Creates an AsyncStreamChannel using the given output stream.
|
||||
/// Only write and seek operations will be allowed.
|
||||
|
||||
AsyncStreamChannel(std::iostream& iostr);
|
||||
/// Creates an AsyncStreamChannel using the given input/output stream.
|
||||
|
||||
~AsyncStreamChannel();
|
||||
/// Destroys the AsyncStreamChannel.
|
||||
|
||||
// AsyncIOChannel
|
||||
int write(const void* buffer, int length);
|
||||
int read(void* buffer, int length);
|
||||
int seek(std::streamoff off, std::ios::seekdir dir);
|
||||
|
||||
private:
|
||||
AsyncStreamChannel();
|
||||
|
||||
std::istream* _pIstr;
|
||||
std::ostream* _pOstr;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_AsyncStreamChannel_INCLUDED
|
||||
|
|
|
@ -1,130 +1,130 @@
|
|||
//
|
||||
// Checksum.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Checksum.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Checksum
|
||||
//
|
||||
// Definition of the Checksum class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Checksum_INCLUDED
|
||||
#define Foundation_Checksum_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API Checksum
|
||||
/// This class calculates CRC-32 or Adler-32 checksums
|
||||
/// for arbitrary data.
|
||||
///
|
||||
/// A cyclic redundancy check (CRC) is a type of hash function, which is used to produce a
|
||||
/// small, fixed-size checksum of a larger block of data, such as a packet of network
|
||||
/// traffic or a computer file. CRC-32 is one of the most commonly used CRC algorithms.
|
||||
///
|
||||
/// Adler-32 is a checksum algorithm which was invented by Mark Adler.
|
||||
/// It is almost as reliable as a 32-bit cyclic redundancy check for protecting against
|
||||
/// accidental modification of data, such as distortions occurring during a transmission,
|
||||
/// but is significantly faster to calculate in software.
|
||||
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
TYPE_ADLER32 = 0,
|
||||
TYPE_CRC32
|
||||
};
|
||||
|
||||
Checksum();
|
||||
/// Creates a CRC-32 checksum initialized to 0.
|
||||
|
||||
Checksum(Type t);
|
||||
/// Creates the Checksum, using the given type.
|
||||
|
||||
~Checksum();
|
||||
/// Destroys the Checksum.
|
||||
|
||||
void update(const char* data, unsigned length);
|
||||
/// Updates the checksum with the given data.
|
||||
|
||||
void update(const std::string& data);
|
||||
/// Updates the checksum with the given data.
|
||||
|
||||
void update(char data);
|
||||
/// Updates the checksum with the given data.
|
||||
|
||||
Poco::UInt32 checksum() const;
|
||||
/// Returns the calculated checksum.
|
||||
|
||||
Type type() const;
|
||||
/// Which type of checksum are we calulcating
|
||||
|
||||
private:
|
||||
Type _type;
|
||||
Poco::UInt32 _value;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void Checksum::update(const std::string& data)
|
||||
{
|
||||
update(data.c_str(), static_cast<unsigned int>(data.size()));
|
||||
}
|
||||
|
||||
|
||||
inline void Checksum::update(char c)
|
||||
{
|
||||
update(&c, 1);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 Checksum::checksum() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
inline Checksum::Type Checksum::type() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Checksum_INCLUDED
|
||||
//
|
||||
// Checksum.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Checksum.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Checksum
|
||||
//
|
||||
// Definition of the Checksum class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Checksum_INCLUDED
|
||||
#define Foundation_Checksum_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API Checksum
|
||||
/// This class calculates CRC-32 or Adler-32 checksums
|
||||
/// for arbitrary data.
|
||||
///
|
||||
/// A cyclic redundancy check (CRC) is a type of hash function, which is used to produce a
|
||||
/// small, fixed-size checksum of a larger block of data, such as a packet of network
|
||||
/// traffic or a computer file. CRC-32 is one of the most commonly used CRC algorithms.
|
||||
///
|
||||
/// Adler-32 is a checksum algorithm which was invented by Mark Adler.
|
||||
/// It is almost as reliable as a 32-bit cyclic redundancy check for protecting against
|
||||
/// accidental modification of data, such as distortions occurring during a transmission,
|
||||
/// but is significantly faster to calculate in software.
|
||||
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
TYPE_ADLER32 = 0,
|
||||
TYPE_CRC32
|
||||
};
|
||||
|
||||
Checksum();
|
||||
/// Creates a CRC-32 checksum initialized to 0.
|
||||
|
||||
Checksum(Type t);
|
||||
/// Creates the Checksum, using the given type.
|
||||
|
||||
~Checksum();
|
||||
/// Destroys the Checksum.
|
||||
|
||||
void update(const char* data, unsigned length);
|
||||
/// Updates the checksum with the given data.
|
||||
|
||||
void update(const std::string& data);
|
||||
/// Updates the checksum with the given data.
|
||||
|
||||
void update(char data);
|
||||
/// Updates the checksum with the given data.
|
||||
|
||||
Poco::UInt32 checksum() const;
|
||||
/// Returns the calculated checksum.
|
||||
|
||||
Type type() const;
|
||||
/// Which type of checksum are we calulcating
|
||||
|
||||
private:
|
||||
Type _type;
|
||||
Poco::UInt32 _value;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void Checksum::update(const std::string& data)
|
||||
{
|
||||
update(data.c_str(), static_cast<unsigned int>(data.size()));
|
||||
}
|
||||
|
||||
|
||||
inline void Checksum::update(char c)
|
||||
{
|
||||
update(&c, 1);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 Checksum::checksum() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
inline Checksum::Type Checksum::type() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Checksum_INCLUDED
|
||||
|
|
|
@ -1,159 +1,159 @@
|
|||
//
|
||||
// Condition.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Condition.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Condition
|
||||
//
|
||||
// Definition of the Condition class template.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Condition_INCLUDED
|
||||
#define Foundation_Condition_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/ScopedUnlock.h"
|
||||
#include "Poco/Event.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <deque>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API Condition
|
||||
/// A Condition is a synchronization object used to block a thread
|
||||
/// until a particular condition is met.
|
||||
/// A Condition object is always used in conjunction with
|
||||
/// a Mutex (or FastMutex) object.
|
||||
///
|
||||
/// Condition objects are similar to POSIX condition variables, which the
|
||||
/// difference that Condition is not subject to spurious wakeups.
|
||||
///
|
||||
/// Threads waiting on a Condition are resumed in FIFO order.
|
||||
{
|
||||
public:
|
||||
Condition();
|
||||
/// Creates the Condition.
|
||||
|
||||
~Condition();
|
||||
/// Destroys the Condition.
|
||||
|
||||
template <class Mtx>
|
||||
void wait(Mtx& mutex)
|
||||
/// Unlocks the mutex (which must be locked upon calling
|
||||
/// wait()) and waits until the Condition is signalled.
|
||||
///
|
||||
/// The given mutex will be locked again upon
|
||||
/// leaving the function, even in case of an exception.
|
||||
{
|
||||
ScopedUnlock<Mtx> unlock(mutex, false);
|
||||
Event event;
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
mutex.unlock();
|
||||
enqueue(event);
|
||||
}
|
||||
event.wait();
|
||||
}
|
||||
|
||||
template <class Mtx>
|
||||
void wait(Mtx& mutex, long milliseconds)
|
||||
/// Unlocks the mutex (which must be locked upon calling
|
||||
/// wait()) and waits for the given time until the Condition is signalled.
|
||||
///
|
||||
/// The given mutex will be locked again upon successfully leaving the
|
||||
/// function, even in case of an exception.
|
||||
///
|
||||
/// Throws a TimeoutException if the Condition is not signalled
|
||||
/// within the given time interval.
|
||||
{
|
||||
if (!tryWait(mutex, milliseconds))
|
||||
throw TimeoutException();
|
||||
}
|
||||
|
||||
template <class Mtx>
|
||||
bool tryWait(Mtx& mutex, long milliseconds)
|
||||
/// Unlocks the mutex (which must be locked upon calling
|
||||
/// tryWait()) and waits for the given time until the Condition is signalled.
|
||||
///
|
||||
/// The given mutex will be locked again upon leaving the
|
||||
/// function, even in case of an exception.
|
||||
///
|
||||
/// Returns true if the Condition has been signalled
|
||||
/// within the given time interval, otherwise false.
|
||||
{
|
||||
ScopedUnlock<Mtx> unlock(mutex, false);
|
||||
Event event;
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
mutex.unlock();
|
||||
enqueue(event);
|
||||
}
|
||||
if (!event.tryWait(milliseconds))
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
dequeue(event);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void signal();
|
||||
/// Signals the Condition and allows one waiting thread
|
||||
/// to continue execution.
|
||||
|
||||
void broadcast();
|
||||
/// Signals the Condition and allows all waiting
|
||||
/// threads to continue their execution.
|
||||
|
||||
protected:
|
||||
void enqueue(Event& event);
|
||||
void dequeue();
|
||||
void dequeue(Event& event);
|
||||
|
||||
private:
|
||||
Condition(const Condition&);
|
||||
Condition& operator = (const Condition&);
|
||||
|
||||
typedef std::deque<Event*> WaitQueue;
|
||||
|
||||
FastMutex _mutex;
|
||||
WaitQueue _waitQueue;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Condition_INCLUDED
|
||||
//
|
||||
// Condition.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Condition.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Condition
|
||||
//
|
||||
// Definition of the Condition class template.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Condition_INCLUDED
|
||||
#define Foundation_Condition_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/ScopedUnlock.h"
|
||||
#include "Poco/Event.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <deque>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API Condition
|
||||
/// A Condition is a synchronization object used to block a thread
|
||||
/// until a particular condition is met.
|
||||
/// A Condition object is always used in conjunction with
|
||||
/// a Mutex (or FastMutex) object.
|
||||
///
|
||||
/// Condition objects are similar to POSIX condition variables, which the
|
||||
/// difference that Condition is not subject to spurious wakeups.
|
||||
///
|
||||
/// Threads waiting on a Condition are resumed in FIFO order.
|
||||
{
|
||||
public:
|
||||
Condition();
|
||||
/// Creates the Condition.
|
||||
|
||||
~Condition();
|
||||
/// Destroys the Condition.
|
||||
|
||||
template <class Mtx>
|
||||
void wait(Mtx& mutex)
|
||||
/// Unlocks the mutex (which must be locked upon calling
|
||||
/// wait()) and waits until the Condition is signalled.
|
||||
///
|
||||
/// The given mutex will be locked again upon
|
||||
/// leaving the function, even in case of an exception.
|
||||
{
|
||||
ScopedUnlock<Mtx> unlock(mutex, false);
|
||||
Event event;
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
mutex.unlock();
|
||||
enqueue(event);
|
||||
}
|
||||
event.wait();
|
||||
}
|
||||
|
||||
template <class Mtx>
|
||||
void wait(Mtx& mutex, long milliseconds)
|
||||
/// Unlocks the mutex (which must be locked upon calling
|
||||
/// wait()) and waits for the given time until the Condition is signalled.
|
||||
///
|
||||
/// The given mutex will be locked again upon successfully leaving the
|
||||
/// function, even in case of an exception.
|
||||
///
|
||||
/// Throws a TimeoutException if the Condition is not signalled
|
||||
/// within the given time interval.
|
||||
{
|
||||
if (!tryWait(mutex, milliseconds))
|
||||
throw TimeoutException();
|
||||
}
|
||||
|
||||
template <class Mtx>
|
||||
bool tryWait(Mtx& mutex, long milliseconds)
|
||||
/// Unlocks the mutex (which must be locked upon calling
|
||||
/// tryWait()) and waits for the given time until the Condition is signalled.
|
||||
///
|
||||
/// The given mutex will be locked again upon leaving the
|
||||
/// function, even in case of an exception.
|
||||
///
|
||||
/// Returns true if the Condition has been signalled
|
||||
/// within the given time interval, otherwise false.
|
||||
{
|
||||
ScopedUnlock<Mtx> unlock(mutex, false);
|
||||
Event event;
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
mutex.unlock();
|
||||
enqueue(event);
|
||||
}
|
||||
if (!event.tryWait(milliseconds))
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
dequeue(event);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void signal();
|
||||
/// Signals the Condition and allows one waiting thread
|
||||
/// to continue execution.
|
||||
|
||||
void broadcast();
|
||||
/// Signals the Condition and allows all waiting
|
||||
/// threads to continue their execution.
|
||||
|
||||
protected:
|
||||
void enqueue(Event& event);
|
||||
void dequeue();
|
||||
void dequeue(Event& event);
|
||||
|
||||
private:
|
||||
Condition(const Condition&);
|
||||
Condition& operator = (const Condition&);
|
||||
|
||||
typedef std::deque<Event*> WaitQueue;
|
||||
|
||||
FastMutex _mutex;
|
||||
WaitQueue _waitQueue;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Condition_INCLUDED
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,399 +1,399 @@
|
|||
//
|
||||
// DynamicStruct.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/DynamicStruct.h#9 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicStruct
|
||||
//
|
||||
// Definition of the DynamicStruct class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_DynamicStruct_INCLUDED
|
||||
#define Foundation_DynamicStruct_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/DynamicAnyHolder.h"
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API DynamicStruct
|
||||
/// DynamicStruct allows to define a named collection of DynamicAny objects.
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, DynamicAny> Data;
|
||||
typedef Data::iterator Iterator;
|
||||
typedef Data::const_iterator ConstIterator;
|
||||
|
||||
DynamicStruct();
|
||||
/// Creates an empty DynamicStruct
|
||||
|
||||
DynamicStruct(const Data &val);
|
||||
/// Creates the DynamicStruct from the given value.
|
||||
|
||||
virtual ~DynamicStruct();
|
||||
/// Destroys the DynamicStruct.
|
||||
|
||||
DynamicAny& operator [] (const std::string& name);
|
||||
/// Returns the DynamicAny with the given name, creates an entry if not found.
|
||||
|
||||
const DynamicAny& operator [] (const std::string& name) const;
|
||||
/// Returns the DynamicAny with the given name, throws a
|
||||
/// NotFoundException if the data member is not found.
|
||||
|
||||
bool contains(const std::string& name) const;
|
||||
/// Returns true if the DynamicStruct contains a member with the given
|
||||
/// name
|
||||
|
||||
Iterator find(const std::string& name);
|
||||
/// Returns an iterator, pointing to the <name,DynamicAny> pair containing
|
||||
/// the element, or it returns end() if the member was not found
|
||||
|
||||
ConstIterator find(const std::string& name) const;
|
||||
/// Returns a const iterator, pointing to the <name,DynamicAny> pair containing
|
||||
/// the element, or it returns end() if the member was not found
|
||||
|
||||
Iterator end();
|
||||
/// Returns the end iterator for the DynamicStruct
|
||||
|
||||
ConstIterator end() const;
|
||||
/// Returns the end const iterator for the DynamicStruct
|
||||
|
||||
Iterator begin();
|
||||
/// Returns the begin iterator for the DynamicStruct
|
||||
|
||||
ConstIterator begin() const;
|
||||
/// Returns the begin const iterator for the DynamicStruct
|
||||
|
||||
std::pair<DynamicStruct::Iterator, bool> insert(const std::string& key, const DynamicAny& value);
|
||||
/// Inserts a <name, DynamicAny> pair into the DynamicStruct,
|
||||
/// returns a pair containing the iterator and a boolean which
|
||||
/// indicates success or not (is true, when insert succeeded, false,
|
||||
/// when already another element was present, in this case Iterator
|
||||
/// points to that other element)
|
||||
|
||||
std::pair<DynamicStruct::Iterator, bool> insert(const DynamicStruct::Data::value_type& aPair);
|
||||
/// Inserts a <name, DynamicAny> pair into the DynamicStruct,
|
||||
/// returns a pair containing the iterator and a boolean which
|
||||
/// indicates success or not (is true, when insert succeeded, false,
|
||||
/// when already another element was present, in this case Iterator
|
||||
/// points to that other element)
|
||||
|
||||
DynamicStruct::Data::size_type erase(const std::string& key);
|
||||
/// Erases the element if found, returns number of elements deleted
|
||||
|
||||
void erase(DynamicStruct::Iterator it);
|
||||
/// Erases the element at the given position
|
||||
|
||||
bool empty() const;
|
||||
/// Returns true if the DynamicStruct doesn't contain any members
|
||||
|
||||
DynamicStruct::Data::size_type size() const;
|
||||
/// Returns the number of members the DynamicStruct contains
|
||||
|
||||
std::set<std::string> members() const;
|
||||
/// Returns a sorted collection containing all member names
|
||||
|
||||
private:
|
||||
Data _data;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline DynamicAny& DynamicStruct::operator [] (const std::string& name)
|
||||
{
|
||||
return _data[name];
|
||||
}
|
||||
|
||||
|
||||
inline bool DynamicStruct::contains(const std::string& name) const
|
||||
{
|
||||
return find(name) != end();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Iterator DynamicStruct::find(const std::string& name)
|
||||
{
|
||||
return _data.find(name);
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::ConstIterator DynamicStruct::find(const std::string& name) const
|
||||
{
|
||||
return _data.find(name);
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Iterator DynamicStruct::end()
|
||||
{
|
||||
return _data.end();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::ConstIterator DynamicStruct::end() const
|
||||
{
|
||||
return _data.end();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Iterator DynamicStruct::begin()
|
||||
{
|
||||
return _data.begin();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::ConstIterator DynamicStruct::begin() const
|
||||
{
|
||||
return _data.begin();
|
||||
}
|
||||
|
||||
|
||||
inline std::pair<DynamicStruct::Iterator, bool> DynamicStruct::insert(const std::string& key, const DynamicAny& value)
|
||||
{
|
||||
return insert(std::make_pair(key, value));
|
||||
}
|
||||
|
||||
|
||||
inline std::pair<DynamicStruct::Iterator, bool> DynamicStruct::insert(const DynamicStruct::Data::value_type& aPair)
|
||||
{
|
||||
return _data.insert(aPair);
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Data::size_type DynamicStruct::erase(const std::string& key)
|
||||
{
|
||||
return _data.erase(key);
|
||||
}
|
||||
|
||||
|
||||
inline void DynamicStruct::erase(DynamicStruct::Iterator it)
|
||||
{
|
||||
_data.erase(it);
|
||||
}
|
||||
|
||||
|
||||
inline bool DynamicStruct::empty() const
|
||||
{
|
||||
return _data.empty();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Data::size_type DynamicStruct::size() const
|
||||
{
|
||||
return _data.size();
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
class DynamicAnyHolderImpl<DynamicStruct>: public DynamicAnyHolder
|
||||
{
|
||||
public:
|
||||
DynamicAnyHolderImpl(const DynamicStruct& val): _val(val)
|
||||
{
|
||||
}
|
||||
|
||||
~DynamicAnyHolderImpl()
|
||||
{
|
||||
}
|
||||
|
||||
const std::type_info& type() const
|
||||
{
|
||||
return typeid(DynamicStruct);
|
||||
}
|
||||
|
||||
void convert(Int8& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to Int8");
|
||||
}
|
||||
|
||||
void convert(Int16& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to Int16");
|
||||
}
|
||||
|
||||
void convert(Int32& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to Int32");
|
||||
}
|
||||
|
||||
void convert(Int64& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to Int64");
|
||||
}
|
||||
|
||||
void convert(UInt8& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to UInt8");
|
||||
}
|
||||
|
||||
void convert(UInt16& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to UInt16");
|
||||
}
|
||||
|
||||
void convert(UInt32& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to UInt32");
|
||||
}
|
||||
|
||||
void convert(UInt64& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to UInt64");
|
||||
}
|
||||
|
||||
void convert(bool& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to bool");
|
||||
}
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to float");
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to double");
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to char");
|
||||
}
|
||||
|
||||
void convert(std::string& val) const
|
||||
{
|
||||
// Serialize in JSON format: equals an object
|
||||
|
||||
// JSON format definition: { string ':' value } string:value pair n-times, sep. by ','
|
||||
val.append("{ ");
|
||||
DynamicStruct::ConstIterator it = _val.begin();
|
||||
DynamicStruct::ConstIterator itEnd = _val.end();
|
||||
if (!_val.empty())
|
||||
{
|
||||
DynamicAny key(it->first);
|
||||
appendJSONString(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, it->second);
|
||||
++it;
|
||||
}
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
val.append(", ");
|
||||
DynamicAny key(it->first);
|
||||
appendJSONString(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, it->second);
|
||||
}
|
||||
val.append(" }");
|
||||
}
|
||||
|
||||
void convert(Poco::DateTime&) const
|
||||
{
|
||||
throw BadCastException("DynamicStruct -> Poco::DateTime");
|
||||
}
|
||||
|
||||
void convert(Poco::LocalDateTime&) const
|
||||
{
|
||||
throw BadCastException("DynamicStruct -> Poco::LocalDateTime");
|
||||
}
|
||||
|
||||
void convert(Poco::Timestamp&) const
|
||||
{
|
||||
throw BadCastException("DynamicStruct -> Poco::Timestamp");
|
||||
}
|
||||
|
||||
DynamicAnyHolder* clone() const
|
||||
{
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const DynamicStruct& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
bool isArray() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isStruct() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isInteger() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSigned() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isNumeric() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isString() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DynamicAny& operator [] (const std::string& name)
|
||||
{
|
||||
return _val[name];
|
||||
}
|
||||
|
||||
const DynamicAny& operator [] (const std::string& name) const
|
||||
{
|
||||
return _val[name];
|
||||
}
|
||||
|
||||
private:
|
||||
DynamicStruct _val;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_DynamicStruct_INCLUDED
|
||||
//
|
||||
// DynamicStruct.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/DynamicStruct.h#9 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicStruct
|
||||
//
|
||||
// Definition of the DynamicStruct class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_DynamicStruct_INCLUDED
|
||||
#define Foundation_DynamicStruct_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/DynamicAnyHolder.h"
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API DynamicStruct
|
||||
/// DynamicStruct allows to define a named collection of DynamicAny objects.
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, DynamicAny> Data;
|
||||
typedef Data::iterator Iterator;
|
||||
typedef Data::const_iterator ConstIterator;
|
||||
|
||||
DynamicStruct();
|
||||
/// Creates an empty DynamicStruct
|
||||
|
||||
DynamicStruct(const Data &val);
|
||||
/// Creates the DynamicStruct from the given value.
|
||||
|
||||
virtual ~DynamicStruct();
|
||||
/// Destroys the DynamicStruct.
|
||||
|
||||
DynamicAny& operator [] (const std::string& name);
|
||||
/// Returns the DynamicAny with the given name, creates an entry if not found.
|
||||
|
||||
const DynamicAny& operator [] (const std::string& name) const;
|
||||
/// Returns the DynamicAny with the given name, throws a
|
||||
/// NotFoundException if the data member is not found.
|
||||
|
||||
bool contains(const std::string& name) const;
|
||||
/// Returns true if the DynamicStruct contains a member with the given
|
||||
/// name
|
||||
|
||||
Iterator find(const std::string& name);
|
||||
/// Returns an iterator, pointing to the <name,DynamicAny> pair containing
|
||||
/// the element, or it returns end() if the member was not found
|
||||
|
||||
ConstIterator find(const std::string& name) const;
|
||||
/// Returns a const iterator, pointing to the <name,DynamicAny> pair containing
|
||||
/// the element, or it returns end() if the member was not found
|
||||
|
||||
Iterator end();
|
||||
/// Returns the end iterator for the DynamicStruct
|
||||
|
||||
ConstIterator end() const;
|
||||
/// Returns the end const iterator for the DynamicStruct
|
||||
|
||||
Iterator begin();
|
||||
/// Returns the begin iterator for the DynamicStruct
|
||||
|
||||
ConstIterator begin() const;
|
||||
/// Returns the begin const iterator for the DynamicStruct
|
||||
|
||||
std::pair<DynamicStruct::Iterator, bool> insert(const std::string& key, const DynamicAny& value);
|
||||
/// Inserts a <name, DynamicAny> pair into the DynamicStruct,
|
||||
/// returns a pair containing the iterator and a boolean which
|
||||
/// indicates success or not (is true, when insert succeeded, false,
|
||||
/// when already another element was present, in this case Iterator
|
||||
/// points to that other element)
|
||||
|
||||
std::pair<DynamicStruct::Iterator, bool> insert(const DynamicStruct::Data::value_type& aPair);
|
||||
/// Inserts a <name, DynamicAny> pair into the DynamicStruct,
|
||||
/// returns a pair containing the iterator and a boolean which
|
||||
/// indicates success or not (is true, when insert succeeded, false,
|
||||
/// when already another element was present, in this case Iterator
|
||||
/// points to that other element)
|
||||
|
||||
DynamicStruct::Data::size_type erase(const std::string& key);
|
||||
/// Erases the element if found, returns number of elements deleted
|
||||
|
||||
void erase(DynamicStruct::Iterator it);
|
||||
/// Erases the element at the given position
|
||||
|
||||
bool empty() const;
|
||||
/// Returns true if the DynamicStruct doesn't contain any members
|
||||
|
||||
DynamicStruct::Data::size_type size() const;
|
||||
/// Returns the number of members the DynamicStruct contains
|
||||
|
||||
std::set<std::string> members() const;
|
||||
/// Returns a sorted collection containing all member names
|
||||
|
||||
private:
|
||||
Data _data;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline DynamicAny& DynamicStruct::operator [] (const std::string& name)
|
||||
{
|
||||
return _data[name];
|
||||
}
|
||||
|
||||
|
||||
inline bool DynamicStruct::contains(const std::string& name) const
|
||||
{
|
||||
return find(name) != end();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Iterator DynamicStruct::find(const std::string& name)
|
||||
{
|
||||
return _data.find(name);
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::ConstIterator DynamicStruct::find(const std::string& name) const
|
||||
{
|
||||
return _data.find(name);
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Iterator DynamicStruct::end()
|
||||
{
|
||||
return _data.end();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::ConstIterator DynamicStruct::end() const
|
||||
{
|
||||
return _data.end();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Iterator DynamicStruct::begin()
|
||||
{
|
||||
return _data.begin();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::ConstIterator DynamicStruct::begin() const
|
||||
{
|
||||
return _data.begin();
|
||||
}
|
||||
|
||||
|
||||
inline std::pair<DynamicStruct::Iterator, bool> DynamicStruct::insert(const std::string& key, const DynamicAny& value)
|
||||
{
|
||||
return insert(std::make_pair(key, value));
|
||||
}
|
||||
|
||||
|
||||
inline std::pair<DynamicStruct::Iterator, bool> DynamicStruct::insert(const DynamicStruct::Data::value_type& aPair)
|
||||
{
|
||||
return _data.insert(aPair);
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Data::size_type DynamicStruct::erase(const std::string& key)
|
||||
{
|
||||
return _data.erase(key);
|
||||
}
|
||||
|
||||
|
||||
inline void DynamicStruct::erase(DynamicStruct::Iterator it)
|
||||
{
|
||||
_data.erase(it);
|
||||
}
|
||||
|
||||
|
||||
inline bool DynamicStruct::empty() const
|
||||
{
|
||||
return _data.empty();
|
||||
}
|
||||
|
||||
|
||||
inline DynamicStruct::Data::size_type DynamicStruct::size() const
|
||||
{
|
||||
return _data.size();
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
class DynamicAnyHolderImpl<DynamicStruct>: public DynamicAnyHolder
|
||||
{
|
||||
public:
|
||||
DynamicAnyHolderImpl(const DynamicStruct& val): _val(val)
|
||||
{
|
||||
}
|
||||
|
||||
~DynamicAnyHolderImpl()
|
||||
{
|
||||
}
|
||||
|
||||
const std::type_info& type() const
|
||||
{
|
||||
return typeid(DynamicStruct);
|
||||
}
|
||||
|
||||
void convert(Int8& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to Int8");
|
||||
}
|
||||
|
||||
void convert(Int16& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to Int16");
|
||||
}
|
||||
|
||||
void convert(Int32& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to Int32");
|
||||
}
|
||||
|
||||
void convert(Int64& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to Int64");
|
||||
}
|
||||
|
||||
void convert(UInt8& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to UInt8");
|
||||
}
|
||||
|
||||
void convert(UInt16& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to UInt16");
|
||||
}
|
||||
|
||||
void convert(UInt32& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to UInt32");
|
||||
}
|
||||
|
||||
void convert(UInt64& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to UInt64");
|
||||
}
|
||||
|
||||
void convert(bool& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to bool");
|
||||
}
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to float");
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to double");
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
{
|
||||
throw BadCastException("Cannot cast DynamicStruct type to char");
|
||||
}
|
||||
|
||||
void convert(std::string& val) const
|
||||
{
|
||||
// Serialize in JSON format: equals an object
|
||||
|
||||
// JSON format definition: { string ':' value } string:value pair n-times, sep. by ','
|
||||
val.append("{ ");
|
||||
DynamicStruct::ConstIterator it = _val.begin();
|
||||
DynamicStruct::ConstIterator itEnd = _val.end();
|
||||
if (!_val.empty())
|
||||
{
|
||||
DynamicAny key(it->first);
|
||||
appendJSONString(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, it->second);
|
||||
++it;
|
||||
}
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
val.append(", ");
|
||||
DynamicAny key(it->first);
|
||||
appendJSONString(val, key);
|
||||
val.append(" : ");
|
||||
appendJSONString(val, it->second);
|
||||
}
|
||||
val.append(" }");
|
||||
}
|
||||
|
||||
void convert(Poco::DateTime&) const
|
||||
{
|
||||
throw BadCastException("DynamicStruct -> Poco::DateTime");
|
||||
}
|
||||
|
||||
void convert(Poco::LocalDateTime&) const
|
||||
{
|
||||
throw BadCastException("DynamicStruct -> Poco::LocalDateTime");
|
||||
}
|
||||
|
||||
void convert(Poco::Timestamp&) const
|
||||
{
|
||||
throw BadCastException("DynamicStruct -> Poco::Timestamp");
|
||||
}
|
||||
|
||||
DynamicAnyHolder* clone() const
|
||||
{
|
||||
return new DynamicAnyHolderImpl(_val);
|
||||
}
|
||||
|
||||
const DynamicStruct& value() const
|
||||
{
|
||||
return _val;
|
||||
}
|
||||
|
||||
bool isArray() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isStruct() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isInteger() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSigned() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isNumeric() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isString() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DynamicAny& operator [] (const std::string& name)
|
||||
{
|
||||
return _val[name];
|
||||
}
|
||||
|
||||
const DynamicAny& operator [] (const std::string& name) const
|
||||
{
|
||||
return _val[name];
|
||||
}
|
||||
|
||||
private:
|
||||
DynamicStruct _val;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_DynamicStruct_INCLUDED
|
||||
|
|
|
@ -1,114 +1,114 @@
|
|||
//
|
||||
// ExpirationDecorator.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ExpirationDecorator.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: ExpirationDecorator
|
||||
//
|
||||
// Implementation of the ExpirationDecorator template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_ExpirationDecorator_INCLUDED
|
||||
#define Foundation_ExpirationDecorator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Timespan.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <typename TArgs>
|
||||
class ExpirationDecorator
|
||||
/// ExpirationDecorator adds an expiration method to values so that they can be used
|
||||
/// with the UniqueExpireCache
|
||||
{
|
||||
public:
|
||||
ExpirationDecorator():
|
||||
_value(),
|
||||
_expiresAt()
|
||||
{
|
||||
}
|
||||
|
||||
ExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
|
||||
/// Creates an element that will expire in diff milliseconds
|
||||
_value(p),
|
||||
_expiresAt()
|
||||
{
|
||||
_expiresAt += (diffInMs*1000);
|
||||
}
|
||||
|
||||
ExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
|
||||
/// Creates an element that will expire after the given timeSpan
|
||||
_value(p),
|
||||
_expiresAt()
|
||||
{
|
||||
_expiresAt += timeSpan.totalMicroseconds();
|
||||
}
|
||||
|
||||
ExpirationDecorator(const TArgs& p, const Poco::Timestamp& timeStamp):
|
||||
/// Creates an element that will expire at the given time point
|
||||
_value(p),
|
||||
_expiresAt(timeStamp)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~ExpirationDecorator()
|
||||
{
|
||||
}
|
||||
|
||||
const Poco::Timestamp& getExpiration() const
|
||||
{
|
||||
return _expiresAt;
|
||||
}
|
||||
|
||||
const TArgs& value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
TArgs& value()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
private:
|
||||
TArgs _value;
|
||||
Timestamp _expiresAt;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// ExpirationDecorator.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ExpirationDecorator.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: ExpirationDecorator
|
||||
//
|
||||
// Implementation of the ExpirationDecorator template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_ExpirationDecorator_INCLUDED
|
||||
#define Foundation_ExpirationDecorator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Timespan.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <typename TArgs>
|
||||
class ExpirationDecorator
|
||||
/// ExpirationDecorator adds an expiration method to values so that they can be used
|
||||
/// with the UniqueExpireCache
|
||||
{
|
||||
public:
|
||||
ExpirationDecorator():
|
||||
_value(),
|
||||
_expiresAt()
|
||||
{
|
||||
}
|
||||
|
||||
ExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
|
||||
/// Creates an element that will expire in diff milliseconds
|
||||
_value(p),
|
||||
_expiresAt()
|
||||
{
|
||||
_expiresAt += (diffInMs*1000);
|
||||
}
|
||||
|
||||
ExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
|
||||
/// Creates an element that will expire after the given timeSpan
|
||||
_value(p),
|
||||
_expiresAt()
|
||||
{
|
||||
_expiresAt += timeSpan.totalMicroseconds();
|
||||
}
|
||||
|
||||
ExpirationDecorator(const TArgs& p, const Poco::Timestamp& timeStamp):
|
||||
/// Creates an element that will expire at the given time point
|
||||
_value(p),
|
||||
_expiresAt(timeStamp)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~ExpirationDecorator()
|
||||
{
|
||||
}
|
||||
|
||||
const Poco::Timestamp& getExpiration() const
|
||||
{
|
||||
return _expiresAt;
|
||||
}
|
||||
|
||||
const TArgs& value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
TArgs& value()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
private:
|
||||
TArgs _value;
|
||||
Timestamp _expiresAt;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,194 +1,194 @@
|
|||
//
|
||||
// FileStream.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FileStream_INCLUDED
|
||||
#define Foundation_FileStream_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "FileStream_WIN32.h"
|
||||
#else
|
||||
#include "FileStream_POSIX.h"
|
||||
#endif
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API FileIOS: public virtual std::ios
|
||||
/// The base class for FileInputStream and FileOutputStream.
|
||||
///
|
||||
/// This class is needed to ensure the correct initialization
|
||||
/// order of the stream buffer and base classes.
|
||||
///
|
||||
/// Files are always opened in binary mode, a text mode
|
||||
/// with CR-LF translation is not supported. Thus, the
|
||||
/// file is always opened as if the std::ios::binary flag
|
||||
/// was specified.
|
||||
/// Use an InputLineEndingConverter or OutputLineEndingConverter
|
||||
/// if you require CR-LF translation.
|
||||
///
|
||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||
{
|
||||
public:
|
||||
FileIOS(std::ios::openmode defaultMode);
|
||||
/// Creates the basic stream.
|
||||
|
||||
~FileIOS();
|
||||
/// Destroys the stream.
|
||||
|
||||
void open(const std::string& path, std::ios::openmode mode);
|
||||
/// Opens the file specified by path, using the given mode.
|
||||
///
|
||||
/// Throws a FileException (or a similar exception) if the file
|
||||
/// does not exist or is not accessible for other reasons and
|
||||
/// a new file cannot be created.
|
||||
|
||||
void close();
|
||||
/// Closes the file stream.
|
||||
|
||||
FileStreamBuf* rdbuf();
|
||||
/// Returns a pointer to the underlying streambuf.
|
||||
|
||||
protected:
|
||||
FileStreamBuf _buf;
|
||||
std::ios::openmode _defaultMode;
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API FileInputStream: public FileIOS, public std::istream
|
||||
/// An input stream for reading from a file.
|
||||
///
|
||||
/// Files are always opened in binary mode, a text mode
|
||||
/// with CR-LF translation is not supported. Thus, the
|
||||
/// file is always opened as if the std::ios::binary flag
|
||||
/// was specified.
|
||||
/// Use an InputLineEndingConverter if you require CR-LF translation.
|
||||
///
|
||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||
{
|
||||
public:
|
||||
FileInputStream();
|
||||
/// Creates an unopened FileInputStream.
|
||||
|
||||
FileInputStream(const std::string& path, std::ios::openmode mode = std::ios::in);
|
||||
/// Creates the FileInputStream for the file given by path, using
|
||||
/// the given mode.
|
||||
///
|
||||
/// The std::ios::in flag is always set, regardless of the actual
|
||||
/// value specified for mode.
|
||||
///
|
||||
/// Throws a FileNotFoundException (or a similar exception) if the file
|
||||
/// does not exist or is not accessible for other reasons.
|
||||
|
||||
~FileInputStream();
|
||||
/// Destroys the stream.
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API FileOutputStream: public FileIOS, public std::ostream
|
||||
/// An output stream for writing to a file.
|
||||
///
|
||||
/// Files are always opened in binary mode, a text mode
|
||||
/// with CR-LF translation is not supported. Thus, the
|
||||
/// file is always opened as if the std::ios::binary flag
|
||||
/// was specified.
|
||||
/// Use an OutputLineEndingConverter if you require CR-LF translation.
|
||||
///
|
||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||
{
|
||||
public:
|
||||
FileOutputStream();
|
||||
/// Creats an unopened FileOutputStream.
|
||||
|
||||
FileOutputStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc);
|
||||
/// Creates the FileOutputStream for the file given by path, using
|
||||
/// the given mode.
|
||||
///
|
||||
/// The std::ios::out is always set, regardless of the actual
|
||||
/// value specified for mode.
|
||||
///
|
||||
/// Throws a FileException (or a similar exception) if the file
|
||||
/// does not exist or is not accessible for other reasons and
|
||||
/// a new file cannot be created.
|
||||
|
||||
~FileOutputStream();
|
||||
/// Destroys the FileOutputStream.
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API FileStream: public FileIOS, public std::iostream
|
||||
/// A stream for reading from and writing to a file.
|
||||
///
|
||||
/// Files are always opened in binary mode, a text mode
|
||||
/// with CR-LF translation is not supported. Thus, the
|
||||
/// file is always opened as if the std::ios::binary flag
|
||||
/// was specified.
|
||||
/// Use an InputLineEndingConverter or OutputLineEndingConverter
|
||||
/// if you require CR-LF translation.
|
||||
///
|
||||
/// A seek (seekg() or seekp()) operation will always set the
|
||||
/// read position and the write position simultaneously to the
|
||||
/// same value.
|
||||
///
|
||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||
{
|
||||
public:
|
||||
FileStream();
|
||||
/// Creats an unopened FileStream.
|
||||
|
||||
FileStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::in);
|
||||
/// Creates the FileStream for the file given by path, using
|
||||
/// the given mode.
|
||||
|
||||
~FileStream();
|
||||
/// Destroys the FileOutputStream.
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_FileStream_INCLUDED
|
||||
//
|
||||
// FileStream.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FileStream_INCLUDED
|
||||
#define Foundation_FileStream_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "FileStream_WIN32.h"
|
||||
#else
|
||||
#include "FileStream_POSIX.h"
|
||||
#endif
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API FileIOS: public virtual std::ios
|
||||
/// The base class for FileInputStream and FileOutputStream.
|
||||
///
|
||||
/// This class is needed to ensure the correct initialization
|
||||
/// order of the stream buffer and base classes.
|
||||
///
|
||||
/// Files are always opened in binary mode, a text mode
|
||||
/// with CR-LF translation is not supported. Thus, the
|
||||
/// file is always opened as if the std::ios::binary flag
|
||||
/// was specified.
|
||||
/// Use an InputLineEndingConverter or OutputLineEndingConverter
|
||||
/// if you require CR-LF translation.
|
||||
///
|
||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||
{
|
||||
public:
|
||||
FileIOS(std::ios::openmode defaultMode);
|
||||
/// Creates the basic stream.
|
||||
|
||||
~FileIOS();
|
||||
/// Destroys the stream.
|
||||
|
||||
void open(const std::string& path, std::ios::openmode mode);
|
||||
/// Opens the file specified by path, using the given mode.
|
||||
///
|
||||
/// Throws a FileException (or a similar exception) if the file
|
||||
/// does not exist or is not accessible for other reasons and
|
||||
/// a new file cannot be created.
|
||||
|
||||
void close();
|
||||
/// Closes the file stream.
|
||||
|
||||
FileStreamBuf* rdbuf();
|
||||
/// Returns a pointer to the underlying streambuf.
|
||||
|
||||
protected:
|
||||
FileStreamBuf _buf;
|
||||
std::ios::openmode _defaultMode;
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API FileInputStream: public FileIOS, public std::istream
|
||||
/// An input stream for reading from a file.
|
||||
///
|
||||
/// Files are always opened in binary mode, a text mode
|
||||
/// with CR-LF translation is not supported. Thus, the
|
||||
/// file is always opened as if the std::ios::binary flag
|
||||
/// was specified.
|
||||
/// Use an InputLineEndingConverter if you require CR-LF translation.
|
||||
///
|
||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||
{
|
||||
public:
|
||||
FileInputStream();
|
||||
/// Creates an unopened FileInputStream.
|
||||
|
||||
FileInputStream(const std::string& path, std::ios::openmode mode = std::ios::in);
|
||||
/// Creates the FileInputStream for the file given by path, using
|
||||
/// the given mode.
|
||||
///
|
||||
/// The std::ios::in flag is always set, regardless of the actual
|
||||
/// value specified for mode.
|
||||
///
|
||||
/// Throws a FileNotFoundException (or a similar exception) if the file
|
||||
/// does not exist or is not accessible for other reasons.
|
||||
|
||||
~FileInputStream();
|
||||
/// Destroys the stream.
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API FileOutputStream: public FileIOS, public std::ostream
|
||||
/// An output stream for writing to a file.
|
||||
///
|
||||
/// Files are always opened in binary mode, a text mode
|
||||
/// with CR-LF translation is not supported. Thus, the
|
||||
/// file is always opened as if the std::ios::binary flag
|
||||
/// was specified.
|
||||
/// Use an OutputLineEndingConverter if you require CR-LF translation.
|
||||
///
|
||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||
{
|
||||
public:
|
||||
FileOutputStream();
|
||||
/// Creats an unopened FileOutputStream.
|
||||
|
||||
FileOutputStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc);
|
||||
/// Creates the FileOutputStream for the file given by path, using
|
||||
/// the given mode.
|
||||
///
|
||||
/// The std::ios::out is always set, regardless of the actual
|
||||
/// value specified for mode.
|
||||
///
|
||||
/// Throws a FileException (or a similar exception) if the file
|
||||
/// does not exist or is not accessible for other reasons and
|
||||
/// a new file cannot be created.
|
||||
|
||||
~FileOutputStream();
|
||||
/// Destroys the FileOutputStream.
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API FileStream: public FileIOS, public std::iostream
|
||||
/// A stream for reading from and writing to a file.
|
||||
///
|
||||
/// Files are always opened in binary mode, a text mode
|
||||
/// with CR-LF translation is not supported. Thus, the
|
||||
/// file is always opened as if the std::ios::binary flag
|
||||
/// was specified.
|
||||
/// Use an InputLineEndingConverter or OutputLineEndingConverter
|
||||
/// if you require CR-LF translation.
|
||||
///
|
||||
/// A seek (seekg() or seekp()) operation will always set the
|
||||
/// read position and the write position simultaneously to the
|
||||
/// same value.
|
||||
///
|
||||
/// On Windows platforms, if POCO_WIN32_UTF8 is #define'd,
|
||||
/// UTF-8 encoded Unicode paths are correctly handled.
|
||||
{
|
||||
public:
|
||||
FileStream();
|
||||
/// Creats an unopened FileStream.
|
||||
|
||||
FileStream(const std::string& path, std::ios::openmode mode = std::ios::out | std::ios::in);
|
||||
/// Creates the FileStream for the file given by path, using
|
||||
/// the given mode.
|
||||
|
||||
~FileStream();
|
||||
/// Destroys the FileOutputStream.
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_FileStream_INCLUDED
|
||||
|
|
|
@ -1,93 +1,93 @@
|
|||
//
|
||||
// FileStream_POSIX.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream_POSIX.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FileStream_POSIX_INCLUDED
|
||||
#define Foundation_FileStream_POSIX_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/BufferedBidirectionalStreamBuf.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
|
||||
/// This stream buffer handles Fileio
|
||||
{
|
||||
public:
|
||||
FileStreamBuf();
|
||||
/// Creates a FileStreamBuf.
|
||||
|
||||
~FileStreamBuf();
|
||||
/// Destroys the FileStream.
|
||||
|
||||
void open(const std::string& path, std::ios::openmode mode);
|
||||
/// Opens the given file in the given mode.
|
||||
|
||||
void close();
|
||||
/// Closes the File stream buffer.
|
||||
|
||||
std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||
/// Change position by offset, according to way and mode.
|
||||
|
||||
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||
/// Change to specified position, according to mode.
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
BUFFER_SIZE = 4096
|
||||
};
|
||||
|
||||
int readFromDevice(char* buffer, std::streamsize length);
|
||||
int writeToDevice(const char* buffer, std::streamsize length);
|
||||
|
||||
private:
|
||||
std::string _path;
|
||||
int _fd;
|
||||
std::streamoff _pos;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_FileStream_WIN32_INCLUDED
|
||||
//
|
||||
// FileStream_POSIX.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream_POSIX.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FileStream_POSIX_INCLUDED
|
||||
#define Foundation_FileStream_POSIX_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/BufferedBidirectionalStreamBuf.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
|
||||
/// This stream buffer handles Fileio
|
||||
{
|
||||
public:
|
||||
FileStreamBuf();
|
||||
/// Creates a FileStreamBuf.
|
||||
|
||||
~FileStreamBuf();
|
||||
/// Destroys the FileStream.
|
||||
|
||||
void open(const std::string& path, std::ios::openmode mode);
|
||||
/// Opens the given file in the given mode.
|
||||
|
||||
void close();
|
||||
/// Closes the File stream buffer.
|
||||
|
||||
std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||
/// Change position by offset, according to way and mode.
|
||||
|
||||
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||
/// Change to specified position, according to mode.
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
BUFFER_SIZE = 4096
|
||||
};
|
||||
|
||||
int readFromDevice(char* buffer, std::streamsize length);
|
||||
int writeToDevice(const char* buffer, std::streamsize length);
|
||||
|
||||
private:
|
||||
std::string _path;
|
||||
int _fd;
|
||||
std::streamoff _pos;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_FileStream_WIN32_INCLUDED
|
||||
|
|
|
@ -1,92 +1,92 @@
|
|||
//
|
||||
// FileStream_WIN32.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream_WIN32.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FileStream_WIN32_INCLUDED
|
||||
#define Foundation_FileStream_WIN32_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/BufferedBidirectionalStreamBuf.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
|
||||
/// This stream buffer handles Fileio
|
||||
{
|
||||
public:
|
||||
FileStreamBuf();
|
||||
/// Creates a FileStreamBuf.
|
||||
|
||||
~FileStreamBuf();
|
||||
/// Destroys the FileStream.
|
||||
|
||||
void open(const std::string& path, std::ios::openmode mode);
|
||||
/// Opens the given file in the given mode.
|
||||
|
||||
void close();
|
||||
/// Closes the File stream buffer
|
||||
|
||||
std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||
/// change position by offset, according to way and mode
|
||||
|
||||
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||
/// change to specified position, according to mode
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
BUFFER_SIZE = 4096
|
||||
};
|
||||
|
||||
int readFromDevice(char* buffer, std::streamsize length);
|
||||
int writeToDevice(const char* buffer, std::streamsize length);
|
||||
|
||||
private:
|
||||
std::string _path;
|
||||
HANDLE _handle;
|
||||
UInt64 _pos;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_FileStream_WIN32_INCLUDED
|
||||
//
|
||||
// FileStream_WIN32.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FileStream_WIN32.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FileStream_WIN32_INCLUDED
|
||||
#define Foundation_FileStream_WIN32_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/BufferedBidirectionalStreamBuf.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
|
||||
/// This stream buffer handles Fileio
|
||||
{
|
||||
public:
|
||||
FileStreamBuf();
|
||||
/// Creates a FileStreamBuf.
|
||||
|
||||
~FileStreamBuf();
|
||||
/// Destroys the FileStream.
|
||||
|
||||
void open(const std::string& path, std::ios::openmode mode);
|
||||
/// Opens the given file in the given mode.
|
||||
|
||||
void close();
|
||||
/// Closes the File stream buffer
|
||||
|
||||
std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||
/// change position by offset, according to way and mode
|
||||
|
||||
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
|
||||
/// change to specified position, according to mode
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
BUFFER_SIZE = 4096
|
||||
};
|
||||
|
||||
int readFromDevice(char* buffer, std::streamsize length);
|
||||
int writeToDevice(const char* buffer, std::streamsize length);
|
||||
|
||||
private:
|
||||
std::string _path;
|
||||
HANDLE _handle;
|
||||
UInt64 _pos;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_FileStream_WIN32_INCLUDED
|
||||
|
|
|
@ -1,208 +1,208 @@
|
|||
//
|
||||
// FunctionDelegate.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FunctionDelegate.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: FunctionDelegate
|
||||
//
|
||||
// Implementation of the FunctionDelegate template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FunctionDelegate_INCLUDED
|
||||
#define Foundation_FunctionDelegate_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/AbstractDelegate.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TArgs, bool hasSender = true, bool senderIsConst = true>
|
||||
class FunctionDelegate: public AbstractDelegate<TArgs>
|
||||
/// Wraps a C style function (or a C++ static fucntion) to be used as
|
||||
/// a delegate
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(const void*, TArgs&);
|
||||
|
||||
FunctionDelegate(NotifyMethod method):
|
||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate(const FunctionDelegate& delegate):
|
||||
AbstractDelegate<TArgs>(delegate),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
~FunctionDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(sender, arguments);
|
||||
return true; // a "standard" delegate never expires
|
||||
}
|
||||
|
||||
AbstractDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionDelegate();
|
||||
};
|
||||
|
||||
|
||||
template <class TArgs>
|
||||
class FunctionDelegate<TArgs, true, false>: public AbstractDelegate<TArgs>
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(void*, TArgs&);
|
||||
|
||||
FunctionDelegate(NotifyMethod method):
|
||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate(const FunctionDelegate& delegate):
|
||||
AbstractDelegate<TArgs>(delegate),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
~FunctionDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(const_cast<void*>(sender), arguments);
|
||||
return true; // a "standard" delegate never expires
|
||||
}
|
||||
|
||||
AbstractDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionDelegate();
|
||||
};
|
||||
|
||||
|
||||
template <class TArgs, bool senderIsConst>
|
||||
class FunctionDelegate<TArgs, false, senderIsConst>: public AbstractDelegate<TArgs>
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(TArgs&);
|
||||
|
||||
FunctionDelegate(NotifyMethod method):
|
||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate(const FunctionDelegate& delegate):
|
||||
AbstractDelegate<TArgs>(delegate),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
~FunctionDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(arguments);
|
||||
return true; // a "standard" delegate never expires
|
||||
}
|
||||
|
||||
AbstractDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionDelegate();
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// FunctionDelegate.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FunctionDelegate.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: FunctionDelegate
|
||||
//
|
||||
// Implementation of the FunctionDelegate template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FunctionDelegate_INCLUDED
|
||||
#define Foundation_FunctionDelegate_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/AbstractDelegate.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TArgs, bool hasSender = true, bool senderIsConst = true>
|
||||
class FunctionDelegate: public AbstractDelegate<TArgs>
|
||||
/// Wraps a C style function (or a C++ static fucntion) to be used as
|
||||
/// a delegate
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(const void*, TArgs&);
|
||||
|
||||
FunctionDelegate(NotifyMethod method):
|
||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate(const FunctionDelegate& delegate):
|
||||
AbstractDelegate<TArgs>(delegate),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
~FunctionDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(sender, arguments);
|
||||
return true; // a "standard" delegate never expires
|
||||
}
|
||||
|
||||
AbstractDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionDelegate();
|
||||
};
|
||||
|
||||
|
||||
template <class TArgs>
|
||||
class FunctionDelegate<TArgs, true, false>: public AbstractDelegate<TArgs>
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(void*, TArgs&);
|
||||
|
||||
FunctionDelegate(NotifyMethod method):
|
||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate(const FunctionDelegate& delegate):
|
||||
AbstractDelegate<TArgs>(delegate),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
~FunctionDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(const_cast<void*>(sender), arguments);
|
||||
return true; // a "standard" delegate never expires
|
||||
}
|
||||
|
||||
AbstractDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionDelegate();
|
||||
};
|
||||
|
||||
|
||||
template <class TArgs, bool senderIsConst>
|
||||
class FunctionDelegate<TArgs, false, senderIsConst>: public AbstractDelegate<TArgs>
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(TArgs&);
|
||||
|
||||
FunctionDelegate(NotifyMethod method):
|
||||
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate(const FunctionDelegate& delegate):
|
||||
AbstractDelegate<TArgs>(delegate),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
~FunctionDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
FunctionDelegate& operator = (const FunctionDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(arguments);
|
||||
return true; // a "standard" delegate never expires
|
||||
}
|
||||
|
||||
AbstractDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionDelegate();
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,212 +1,212 @@
|
|||
//
|
||||
// FunctionPriorityDelegate.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FunctionPriorityDelegate.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: FunctionPriorityDelegate
|
||||
//
|
||||
// Implementation of the FunctionPriorityDelegate template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FunctionPriorityDelegate_INCLUDED
|
||||
#define Foundation_FunctionPriorityDelegate_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/AbstractPriorityDelegate.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TArgs, bool useSender = true, bool senderIsConst = true>
|
||||
class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
|
||||
/// Wraps a C style function (or a C++ static fucntion) to be used as
|
||||
/// a priority delegate
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(const void*, TArgs&);
|
||||
|
||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
this->_priority = delegate._priority;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~FunctionPriorityDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(sender, arguments);
|
||||
return true; // per default the delegate never expires
|
||||
}
|
||||
|
||||
AbstractPriorityDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionPriorityDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionPriorityDelegate();
|
||||
};
|
||||
|
||||
|
||||
template <class TArgs>
|
||||
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(void*, TArgs&);
|
||||
|
||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
this->_priority = delegate._priority;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~FunctionPriorityDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(const_cast<void*>(sender), arguments);
|
||||
return true; // per default the delegate never expires
|
||||
}
|
||||
|
||||
AbstractPriorityDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionPriorityDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionPriorityDelegate();
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class TArgs>
|
||||
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(TArgs&);
|
||||
|
||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
this->_priority = delegate._priority;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~FunctionPriorityDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(arguments);
|
||||
return true; // per default the delegate never expires
|
||||
}
|
||||
|
||||
AbstractPriorityDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionPriorityDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionPriorityDelegate();
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// FunctionPriorityDelegate.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/FunctionPriorityDelegate.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: FunctionPriorityDelegate
|
||||
//
|
||||
// Implementation of the FunctionPriorityDelegate template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_FunctionPriorityDelegate_INCLUDED
|
||||
#define Foundation_FunctionPriorityDelegate_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/AbstractPriorityDelegate.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TArgs, bool useSender = true, bool senderIsConst = true>
|
||||
class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
|
||||
/// Wraps a C style function (or a C++ static fucntion) to be used as
|
||||
/// a priority delegate
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(const void*, TArgs&);
|
||||
|
||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
this->_priority = delegate._priority;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~FunctionPriorityDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(sender, arguments);
|
||||
return true; // per default the delegate never expires
|
||||
}
|
||||
|
||||
AbstractPriorityDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionPriorityDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionPriorityDelegate();
|
||||
};
|
||||
|
||||
|
||||
template <class TArgs>
|
||||
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(void*, TArgs&);
|
||||
|
||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
this->_priority = delegate._priority;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~FunctionPriorityDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(const_cast<void*>(sender), arguments);
|
||||
return true; // per default the delegate never expires
|
||||
}
|
||||
|
||||
AbstractPriorityDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionPriorityDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionPriorityDelegate();
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class TArgs>
|
||||
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
|
||||
{
|
||||
public:
|
||||
typedef void (*NotifyMethod)(TArgs&);
|
||||
|
||||
FunctionPriorityDelegate(NotifyMethod method, int prio):
|
||||
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
|
||||
_receiverMethod(method)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
|
||||
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
|
||||
_receiverMethod(delegate._receiverMethod)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
|
||||
{
|
||||
if (&delegate != this)
|
||||
{
|
||||
this->_pTarget = delegate._pTarget;
|
||||
this->_receiverMethod = delegate._receiverMethod;
|
||||
this->_priority = delegate._priority;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~FunctionPriorityDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool notify(const void* sender, TArgs& arguments)
|
||||
{
|
||||
(*_receiverMethod)(arguments);
|
||||
return true; // per default the delegate never expires
|
||||
}
|
||||
|
||||
AbstractPriorityDelegate<TArgs>* clone() const
|
||||
{
|
||||
return new FunctionPriorityDelegate(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
NotifyMethod _receiverMethod;
|
||||
|
||||
private:
|
||||
FunctionPriorityDelegate();
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,127 +1,127 @@
|
|||
//
|
||||
// Hash.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Hash.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: Hash
|
||||
//
|
||||
// Definition of the Hash class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Hash_INCLUDED
|
||||
#define Foundation_Hash_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class T>
|
||||
struct Hash
|
||||
/// A generic hash function.
|
||||
{
|
||||
std::size_t operator () (T value) const
|
||||
/// Returns the hash for the given value.
|
||||
{
|
||||
return hash(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
std::size_t Foundation_API hash(Int8 n);
|
||||
std::size_t Foundation_API hash(UInt8 n);
|
||||
std::size_t Foundation_API hash(Int16 n);
|
||||
std::size_t Foundation_API hash(UInt16 n);
|
||||
std::size_t Foundation_API hash(Int32 n);
|
||||
std::size_t Foundation_API hash(UInt32 n);
|
||||
std::size_t Foundation_API hash(Int64 n);
|
||||
std::size_t Foundation_API hash(UInt64 n);
|
||||
std::size_t Foundation_API hash(const std::string& str);
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline std::size_t hash(Int8 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(UInt8 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(Int16 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(UInt16 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(Int32 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(UInt32 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(Int64 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(UInt64 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Hash_INCLUDED
|
||||
//
|
||||
// Hash.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Hash.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: Hash
|
||||
//
|
||||
// Definition of the Hash class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Hash_INCLUDED
|
||||
#define Foundation_Hash_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class T>
|
||||
struct Hash
|
||||
/// A generic hash function.
|
||||
{
|
||||
std::size_t operator () (T value) const
|
||||
/// Returns the hash for the given value.
|
||||
{
|
||||
return hash(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
std::size_t Foundation_API hash(Int8 n);
|
||||
std::size_t Foundation_API hash(UInt8 n);
|
||||
std::size_t Foundation_API hash(Int16 n);
|
||||
std::size_t Foundation_API hash(UInt16 n);
|
||||
std::size_t Foundation_API hash(Int32 n);
|
||||
std::size_t Foundation_API hash(UInt32 n);
|
||||
std::size_t Foundation_API hash(Int64 n);
|
||||
std::size_t Foundation_API hash(UInt64 n);
|
||||
std::size_t Foundation_API hash(const std::string& str);
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline std::size_t hash(Int8 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(UInt8 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(Int16 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(UInt16 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(Int32 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(UInt32 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(Int64 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t hash(UInt64 n)
|
||||
{
|
||||
return static_cast<std::size_t>(n)*2654435761U;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Hash_INCLUDED
|
||||
|
|
|
@ -1,244 +1,244 @@
|
|||
//
|
||||
// HashMap.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/HashMap.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: HashMap
|
||||
//
|
||||
// Definition of the HashMap class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_HashMap_INCLUDED
|
||||
#define Foundation_HashMap_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/LinearHashTable.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Key, class Value>
|
||||
struct HashMapEntry
|
||||
/// This class template is used internally by HashMap.
|
||||
{
|
||||
Key first;
|
||||
Value second;
|
||||
|
||||
HashMapEntry():
|
||||
first(),
|
||||
second()
|
||||
{
|
||||
}
|
||||
|
||||
HashMapEntry(const Key& key):
|
||||
first(key),
|
||||
second()
|
||||
{
|
||||
}
|
||||
|
||||
HashMapEntry(const Key& key, const Value& value):
|
||||
first(key),
|
||||
second(value)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator == (const HashMapEntry& entry) const
|
||||
{
|
||||
return first == entry.first;
|
||||
}
|
||||
|
||||
bool operator != (const HashMapEntry& entry) const
|
||||
{
|
||||
return first != entry.first;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class HME, class KeyHashFunc>
|
||||
struct HashMapEntryHash
|
||||
/// This class template is used internally by HashMap.
|
||||
{
|
||||
std::size_t operator () (const HME& entry) const
|
||||
{
|
||||
return _func(entry.first);
|
||||
}
|
||||
|
||||
private:
|
||||
KeyHashFunc _func;
|
||||
};
|
||||
|
||||
|
||||
template <class Key, class Mapped, class HashFunc = Hash<Key> >
|
||||
class HashMap
|
||||
/// This class implements a map using a LinearHashTable.
|
||||
///
|
||||
/// A HashMap can be used just like a std::map.
|
||||
{
|
||||
public:
|
||||
typedef Key KeyType;
|
||||
typedef Mapped MappedType;
|
||||
typedef Mapped& Reference;
|
||||
typedef const Mapped& ConstReference;
|
||||
typedef Mapped* Pointer;
|
||||
typedef const Mapped* ConstPointer;
|
||||
|
||||
typedef HashMapEntry<Key, Mapped> ValueType;
|
||||
typedef std::pair<KeyType, MappedType> PairType;
|
||||
|
||||
typedef HashMapEntryHash<ValueType, HashFunc> HashType;
|
||||
typedef LinearHashTable<ValueType, HashType> HashTable;
|
||||
|
||||
typedef typename HashTable::Iterator Iterator;
|
||||
typedef typename HashTable::ConstIterator ConstIterator;
|
||||
|
||||
HashMap()
|
||||
/// Creates an empty HashMap.
|
||||
{
|
||||
}
|
||||
|
||||
HashMap(std::size_t initialReserve):
|
||||
_table(initialReserve)
|
||||
/// Creates the HashMap with room for initialReserve entries.
|
||||
{
|
||||
}
|
||||
|
||||
HashMap& operator = (const HashMap& map)
|
||||
/// Assigns another HashMap.
|
||||
{
|
||||
HashMap tmp(map);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(HashMap& map)
|
||||
/// Swaps the HashMap with another one.
|
||||
{
|
||||
_table.swap(map._table);
|
||||
}
|
||||
|
||||
ConstIterator begin() const
|
||||
{
|
||||
return _table.begin();
|
||||
}
|
||||
|
||||
ConstIterator end() const
|
||||
{
|
||||
return _table.end();
|
||||
}
|
||||
|
||||
Iterator begin()
|
||||
{
|
||||
return _table.begin();
|
||||
}
|
||||
|
||||
Iterator end()
|
||||
{
|
||||
return _table.end();
|
||||
}
|
||||
|
||||
ConstIterator find(const KeyType& key) const
|
||||
{
|
||||
ValueType value(key);
|
||||
return _table.find(value);
|
||||
}
|
||||
|
||||
Iterator find(const KeyType& key)
|
||||
{
|
||||
ValueType value(key);
|
||||
return _table.find(value);
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const PairType& pair)
|
||||
{
|
||||
ValueType value(pair.first, pair.second);
|
||||
return _table.insert(value);
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const ValueType& value)
|
||||
{
|
||||
return _table.insert(value);
|
||||
}
|
||||
|
||||
void erase(Iterator it)
|
||||
{
|
||||
_table.erase(it);
|
||||
}
|
||||
|
||||
void erase(const KeyType& key)
|
||||
{
|
||||
Iterator it = find(key);
|
||||
_table.erase(it);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
_table.clear();
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
{
|
||||
return _table.size();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return _table.empty();
|
||||
}
|
||||
|
||||
ConstReference operator [] (const KeyType& key) const
|
||||
{
|
||||
ConstIterator it = _table.find(key);
|
||||
if (it != _table.end())
|
||||
return it->second;
|
||||
else
|
||||
throw NotFoundException();
|
||||
}
|
||||
|
||||
Reference operator [] (const KeyType& key)
|
||||
{
|
||||
ValueType value(key);
|
||||
std::pair<Iterator, bool> res = _table.insert(value);
|
||||
return res.first->second;
|
||||
}
|
||||
|
||||
private:
|
||||
HashTable _table;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_HashMap_INCLUDED
|
||||
//
|
||||
// HashMap.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/HashMap.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: HashMap
|
||||
//
|
||||
// Definition of the HashMap class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_HashMap_INCLUDED
|
||||
#define Foundation_HashMap_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/LinearHashTable.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Key, class Value>
|
||||
struct HashMapEntry
|
||||
/// This class template is used internally by HashMap.
|
||||
{
|
||||
Key first;
|
||||
Value second;
|
||||
|
||||
HashMapEntry():
|
||||
first(),
|
||||
second()
|
||||
{
|
||||
}
|
||||
|
||||
HashMapEntry(const Key& key):
|
||||
first(key),
|
||||
second()
|
||||
{
|
||||
}
|
||||
|
||||
HashMapEntry(const Key& key, const Value& value):
|
||||
first(key),
|
||||
second(value)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator == (const HashMapEntry& entry) const
|
||||
{
|
||||
return first == entry.first;
|
||||
}
|
||||
|
||||
bool operator != (const HashMapEntry& entry) const
|
||||
{
|
||||
return first != entry.first;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class HME, class KeyHashFunc>
|
||||
struct HashMapEntryHash
|
||||
/// This class template is used internally by HashMap.
|
||||
{
|
||||
std::size_t operator () (const HME& entry) const
|
||||
{
|
||||
return _func(entry.first);
|
||||
}
|
||||
|
||||
private:
|
||||
KeyHashFunc _func;
|
||||
};
|
||||
|
||||
|
||||
template <class Key, class Mapped, class HashFunc = Hash<Key> >
|
||||
class HashMap
|
||||
/// This class implements a map using a LinearHashTable.
|
||||
///
|
||||
/// A HashMap can be used just like a std::map.
|
||||
{
|
||||
public:
|
||||
typedef Key KeyType;
|
||||
typedef Mapped MappedType;
|
||||
typedef Mapped& Reference;
|
||||
typedef const Mapped& ConstReference;
|
||||
typedef Mapped* Pointer;
|
||||
typedef const Mapped* ConstPointer;
|
||||
|
||||
typedef HashMapEntry<Key, Mapped> ValueType;
|
||||
typedef std::pair<KeyType, MappedType> PairType;
|
||||
|
||||
typedef HashMapEntryHash<ValueType, HashFunc> HashType;
|
||||
typedef LinearHashTable<ValueType, HashType> HashTable;
|
||||
|
||||
typedef typename HashTable::Iterator Iterator;
|
||||
typedef typename HashTable::ConstIterator ConstIterator;
|
||||
|
||||
HashMap()
|
||||
/// Creates an empty HashMap.
|
||||
{
|
||||
}
|
||||
|
||||
HashMap(std::size_t initialReserve):
|
||||
_table(initialReserve)
|
||||
/// Creates the HashMap with room for initialReserve entries.
|
||||
{
|
||||
}
|
||||
|
||||
HashMap& operator = (const HashMap& map)
|
||||
/// Assigns another HashMap.
|
||||
{
|
||||
HashMap tmp(map);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(HashMap& map)
|
||||
/// Swaps the HashMap with another one.
|
||||
{
|
||||
_table.swap(map._table);
|
||||
}
|
||||
|
||||
ConstIterator begin() const
|
||||
{
|
||||
return _table.begin();
|
||||
}
|
||||
|
||||
ConstIterator end() const
|
||||
{
|
||||
return _table.end();
|
||||
}
|
||||
|
||||
Iterator begin()
|
||||
{
|
||||
return _table.begin();
|
||||
}
|
||||
|
||||
Iterator end()
|
||||
{
|
||||
return _table.end();
|
||||
}
|
||||
|
||||
ConstIterator find(const KeyType& key) const
|
||||
{
|
||||
ValueType value(key);
|
||||
return _table.find(value);
|
||||
}
|
||||
|
||||
Iterator find(const KeyType& key)
|
||||
{
|
||||
ValueType value(key);
|
||||
return _table.find(value);
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const PairType& pair)
|
||||
{
|
||||
ValueType value(pair.first, pair.second);
|
||||
return _table.insert(value);
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const ValueType& value)
|
||||
{
|
||||
return _table.insert(value);
|
||||
}
|
||||
|
||||
void erase(Iterator it)
|
||||
{
|
||||
_table.erase(it);
|
||||
}
|
||||
|
||||
void erase(const KeyType& key)
|
||||
{
|
||||
Iterator it = find(key);
|
||||
_table.erase(it);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
_table.clear();
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
{
|
||||
return _table.size();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return _table.empty();
|
||||
}
|
||||
|
||||
ConstReference operator [] (const KeyType& key) const
|
||||
{
|
||||
ConstIterator it = _table.find(key);
|
||||
if (it != _table.end())
|
||||
return it->second;
|
||||
else
|
||||
throw NotFoundException();
|
||||
}
|
||||
|
||||
Reference operator [] (const KeyType& key)
|
||||
{
|
||||
ValueType value(key);
|
||||
std::pair<Iterator, bool> res = _table.insert(value);
|
||||
return res.first->second;
|
||||
}
|
||||
|
||||
private:
|
||||
HashTable _table;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_HashMap_INCLUDED
|
||||
|
|
|
@ -1,199 +1,199 @@
|
|||
//
|
||||
// HashSet.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/HashSet.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: HashSet
|
||||
//
|
||||
// Definition of the HashSet class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_HashSet_INCLUDED
|
||||
#define Foundation_HashSet_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/LinearHashTable.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Value, class HashFunc = Hash<Value> >
|
||||
class HashSet
|
||||
/// This class implements a set using a LinearHashTable.
|
||||
///
|
||||
/// A HashSet can be used just like a std::set.
|
||||
{
|
||||
public:
|
||||
typedef Value ValueType;
|
||||
typedef Value& Reference;
|
||||
typedef const Value& ConstReference;
|
||||
typedef Value* Pointer;
|
||||
typedef const Value* ConstPointer;
|
||||
typedef HashFunc Hash;
|
||||
|
||||
typedef LinearHashTable<ValueType, Hash> HashTable;
|
||||
|
||||
typedef typename HashTable::Iterator Iterator;
|
||||
typedef typename HashTable::ConstIterator ConstIterator;
|
||||
|
||||
HashSet()
|
||||
/// Creates an empty HashSet.
|
||||
{
|
||||
}
|
||||
|
||||
HashSet(std::size_t initialReserve):
|
||||
_table(initialReserve)
|
||||
/// Creates the HashSet, using the given initialReserve.
|
||||
{
|
||||
}
|
||||
|
||||
HashSet(const HashSet& set):
|
||||
_table(set._table)
|
||||
/// Creates the HashSet by copying another one.
|
||||
{
|
||||
}
|
||||
|
||||
~HashSet()
|
||||
/// Destroys the HashSet.
|
||||
{
|
||||
}
|
||||
|
||||
HashSet& operator = (const HashSet& table)
|
||||
/// Assigns another HashSet.
|
||||
{
|
||||
HashSet tmp(table);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(HashSet& set)
|
||||
/// Swaps the HashSet with another one.
|
||||
{
|
||||
_table.swap(set._table);
|
||||
}
|
||||
|
||||
ConstIterator begin() const
|
||||
/// Returns an iterator pointing to the first entry, if one exists.
|
||||
{
|
||||
return _table.begin();
|
||||
}
|
||||
|
||||
ConstIterator end() const
|
||||
/// Returns an iterator pointing to the end of the table.
|
||||
{
|
||||
return _table.end();
|
||||
}
|
||||
|
||||
Iterator begin()
|
||||
/// Returns an iterator pointing to the first entry, if one exists.
|
||||
{
|
||||
return _table.begin();
|
||||
}
|
||||
|
||||
Iterator end()
|
||||
/// Returns an iterator pointing to the end of the table.
|
||||
{
|
||||
return _table.end();
|
||||
}
|
||||
|
||||
ConstIterator find(const ValueType& value) const
|
||||
/// Finds an entry in the table.
|
||||
{
|
||||
return _table.find(value);
|
||||
}
|
||||
|
||||
Iterator find(const ValueType& value)
|
||||
/// Finds an entry in the table.
|
||||
{
|
||||
return _table.find(value);
|
||||
}
|
||||
|
||||
std::size_t count(const ValueType& value) const
|
||||
/// Returns the number of elements with the given
|
||||
/// value, with is either 1 or 0.
|
||||
{
|
||||
return _table.count(value);
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const ValueType& value)
|
||||
/// Inserts an element into the set.
|
||||
///
|
||||
/// If the element already exists in the set,
|
||||
/// a pair(iterator, false) with iterator pointing to the
|
||||
/// existing element is returned.
|
||||
/// Otherwise, the element is inserted an a
|
||||
/// pair(iterator, true) with iterator
|
||||
/// pointing to the new element is returned.
|
||||
{
|
||||
return _table.insert(value);
|
||||
}
|
||||
|
||||
void erase(Iterator it)
|
||||
/// Erases the element pointed to by it.
|
||||
{
|
||||
_table.erase(it);
|
||||
}
|
||||
|
||||
void erase(const ValueType& value)
|
||||
/// Erases the element with the given value, if it exists.
|
||||
{
|
||||
_table.erase(value);
|
||||
}
|
||||
|
||||
void clear()
|
||||
/// Erases all elements.
|
||||
{
|
||||
_table.clear();
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
/// Returns the number of elements in the table.
|
||||
{
|
||||
return _table.size();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
/// Returns true iff the table is empty.
|
||||
{
|
||||
return _table.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
HashTable _table;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_HashSet_INCLUDED
|
||||
//
|
||||
// HashSet.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/HashSet.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: HashSet
|
||||
//
|
||||
// Definition of the HashSet class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_HashSet_INCLUDED
|
||||
#define Foundation_HashSet_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/LinearHashTable.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Value, class HashFunc = Hash<Value> >
|
||||
class HashSet
|
||||
/// This class implements a set using a LinearHashTable.
|
||||
///
|
||||
/// A HashSet can be used just like a std::set.
|
||||
{
|
||||
public:
|
||||
typedef Value ValueType;
|
||||
typedef Value& Reference;
|
||||
typedef const Value& ConstReference;
|
||||
typedef Value* Pointer;
|
||||
typedef const Value* ConstPointer;
|
||||
typedef HashFunc Hash;
|
||||
|
||||
typedef LinearHashTable<ValueType, Hash> HashTable;
|
||||
|
||||
typedef typename HashTable::Iterator Iterator;
|
||||
typedef typename HashTable::ConstIterator ConstIterator;
|
||||
|
||||
HashSet()
|
||||
/// Creates an empty HashSet.
|
||||
{
|
||||
}
|
||||
|
||||
HashSet(std::size_t initialReserve):
|
||||
_table(initialReserve)
|
||||
/// Creates the HashSet, using the given initialReserve.
|
||||
{
|
||||
}
|
||||
|
||||
HashSet(const HashSet& set):
|
||||
_table(set._table)
|
||||
/// Creates the HashSet by copying another one.
|
||||
{
|
||||
}
|
||||
|
||||
~HashSet()
|
||||
/// Destroys the HashSet.
|
||||
{
|
||||
}
|
||||
|
||||
HashSet& operator = (const HashSet& table)
|
||||
/// Assigns another HashSet.
|
||||
{
|
||||
HashSet tmp(table);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(HashSet& set)
|
||||
/// Swaps the HashSet with another one.
|
||||
{
|
||||
_table.swap(set._table);
|
||||
}
|
||||
|
||||
ConstIterator begin() const
|
||||
/// Returns an iterator pointing to the first entry, if one exists.
|
||||
{
|
||||
return _table.begin();
|
||||
}
|
||||
|
||||
ConstIterator end() const
|
||||
/// Returns an iterator pointing to the end of the table.
|
||||
{
|
||||
return _table.end();
|
||||
}
|
||||
|
||||
Iterator begin()
|
||||
/// Returns an iterator pointing to the first entry, if one exists.
|
||||
{
|
||||
return _table.begin();
|
||||
}
|
||||
|
||||
Iterator end()
|
||||
/// Returns an iterator pointing to the end of the table.
|
||||
{
|
||||
return _table.end();
|
||||
}
|
||||
|
||||
ConstIterator find(const ValueType& value) const
|
||||
/// Finds an entry in the table.
|
||||
{
|
||||
return _table.find(value);
|
||||
}
|
||||
|
||||
Iterator find(const ValueType& value)
|
||||
/// Finds an entry in the table.
|
||||
{
|
||||
return _table.find(value);
|
||||
}
|
||||
|
||||
std::size_t count(const ValueType& value) const
|
||||
/// Returns the number of elements with the given
|
||||
/// value, with is either 1 or 0.
|
||||
{
|
||||
return _table.count(value);
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const ValueType& value)
|
||||
/// Inserts an element into the set.
|
||||
///
|
||||
/// If the element already exists in the set,
|
||||
/// a pair(iterator, false) with iterator pointing to the
|
||||
/// existing element is returned.
|
||||
/// Otherwise, the element is inserted an a
|
||||
/// pair(iterator, true) with iterator
|
||||
/// pointing to the new element is returned.
|
||||
{
|
||||
return _table.insert(value);
|
||||
}
|
||||
|
||||
void erase(Iterator it)
|
||||
/// Erases the element pointed to by it.
|
||||
{
|
||||
_table.erase(it);
|
||||
}
|
||||
|
||||
void erase(const ValueType& value)
|
||||
/// Erases the element with the given value, if it exists.
|
||||
{
|
||||
_table.erase(value);
|
||||
}
|
||||
|
||||
void clear()
|
||||
/// Erases all elements.
|
||||
{
|
||||
_table.clear();
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
/// Returns the number of elements in the table.
|
||||
{
|
||||
return _table.size();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
/// Returns true iff the table is empty.
|
||||
{
|
||||
return _table.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
HashTable _table;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_HashSet_INCLUDED
|
||||
|
|
|
@ -1,492 +1,492 @@
|
|||
//
|
||||
// LinearHashTable.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/LinearHashTable.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: LinearHashTable
|
||||
//
|
||||
// Definition of the LinearHashTable class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_LinearHashTable_INCLUDED
|
||||
#define Foundation_LinearHashTable_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Hash.h"
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Value, class HashFunc = Hash<Value> >
|
||||
class LinearHashTable
|
||||
/// This class implements a linear hash table.
|
||||
///
|
||||
/// In a linear hash table, the available address space
|
||||
/// grows or shrinks dynamically. A linar hash table thus
|
||||
/// supports any number of insertions or deletions without
|
||||
/// lookup or insertion performance deterioration.
|
||||
///
|
||||
/// Linear hashing was discovered by Witold Litwin in 1980
|
||||
/// and described in the paper LINEAR HASHING: A NEW TOOL FOR FILE AND TABLE ADDRESSING.
|
||||
///
|
||||
/// For more information on linear hashing, see <http://en.wikipedia.org/wiki/Linear_hash>.
|
||||
///
|
||||
/// The LinearHashTable is not thread safe.
|
||||
///
|
||||
/// Value must support comparison for equality.
|
||||
///
|
||||
/// Find, insert and delete operations are basically O(1) with regard
|
||||
/// to the total number of elements in the table, and O(N) with regard
|
||||
/// to the number of elements in the bucket where the element is stored.
|
||||
/// On average, every bucket stores one element; the exact number depends
|
||||
/// on the quality of the hash function. In most cases, the maximum number of
|
||||
/// elements in a bucket should not exceed 3.
|
||||
{
|
||||
public:
|
||||
typedef Value ValueType;
|
||||
typedef Value& Reference;
|
||||
typedef const Value& ConstReference;
|
||||
typedef Value* Pointer;
|
||||
typedef const Value* ConstPointer;
|
||||
typedef HashFunc Hash;
|
||||
typedef std::vector<Value> Bucket;
|
||||
typedef std::vector<Bucket> BucketVec;
|
||||
typedef typename Bucket::iterator BucketIterator;
|
||||
typedef typename BucketVec::iterator BucketVecIterator;
|
||||
|
||||
class ConstIterator
|
||||
{
|
||||
public:
|
||||
ConstIterator()
|
||||
{
|
||||
}
|
||||
|
||||
ConstIterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt):
|
||||
_vecIt(vecIt),
|
||||
_endIt(endIt),
|
||||
_buckIt(buckIt)
|
||||
{
|
||||
}
|
||||
|
||||
ConstIterator(const ConstIterator& it):
|
||||
_vecIt(it._vecIt),
|
||||
_endIt(it._endIt),
|
||||
_buckIt(it._buckIt)
|
||||
{
|
||||
}
|
||||
|
||||
ConstIterator& operator = (const ConstIterator& it)
|
||||
{
|
||||
ConstIterator tmp(it);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(ConstIterator& it)
|
||||
{
|
||||
using std::swap;
|
||||
swap(_vecIt, it._vecIt);
|
||||
swap(_endIt, it._endIt);
|
||||
swap(_buckIt, it._buckIt);
|
||||
}
|
||||
|
||||
bool operator == (const ConstIterator& it) const
|
||||
{
|
||||
return _vecIt == it._vecIt && (_vecIt == _endIt || _buckIt == it._buckIt);
|
||||
}
|
||||
|
||||
bool operator != (const ConstIterator& it) const
|
||||
{
|
||||
return _vecIt != it._vecIt || (_vecIt != _endIt && _buckIt != it._buckIt);
|
||||
}
|
||||
|
||||
const typename Bucket::value_type& operator * () const
|
||||
{
|
||||
return *_buckIt;
|
||||
}
|
||||
|
||||
const typename Bucket::value_type* operator -> () const
|
||||
{
|
||||
return &*_buckIt;
|
||||
}
|
||||
|
||||
ConstIterator& operator ++ () // prefix
|
||||
{
|
||||
if (_vecIt != _endIt)
|
||||
{
|
||||
++_buckIt;
|
||||
while (_vecIt != _endIt && _buckIt == _vecIt->end())
|
||||
{
|
||||
++_vecIt;
|
||||
if (_vecIt != _endIt) _buckIt = _vecIt->begin();
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ConstIterator operator ++ (int) // postfix
|
||||
{
|
||||
ConstIterator tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
protected:
|
||||
BucketVecIterator _vecIt;
|
||||
BucketVecIterator _endIt;
|
||||
BucketIterator _buckIt;
|
||||
|
||||
friend class LinearHashTable;
|
||||
};
|
||||
|
||||
class Iterator: public ConstIterator
|
||||
{
|
||||
public:
|
||||
Iterator()
|
||||
{
|
||||
}
|
||||
|
||||
Iterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt):
|
||||
ConstIterator(vecIt, endIt, buckIt)
|
||||
{
|
||||
}
|
||||
|
||||
Iterator(const Iterator& it):
|
||||
ConstIterator(it)
|
||||
{
|
||||
}
|
||||
|
||||
Iterator& operator = (const Iterator& it)
|
||||
{
|
||||
Iterator tmp(it);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(Iterator& it)
|
||||
{
|
||||
ConstIterator::swap(it);
|
||||
}
|
||||
|
||||
typename Bucket::value_type& operator * ()
|
||||
{
|
||||
return *this->_buckIt;
|
||||
}
|
||||
|
||||
const typename Bucket::value_type& operator * () const
|
||||
{
|
||||
return *this->_buckIt;
|
||||
}
|
||||
|
||||
typename Bucket::value_type* operator -> ()
|
||||
{
|
||||
return &*this->_buckIt;
|
||||
}
|
||||
|
||||
const typename Bucket::value_type* operator -> () const
|
||||
{
|
||||
return &*this->_buckIt;
|
||||
}
|
||||
|
||||
Iterator& operator ++ () // prefix
|
||||
{
|
||||
ConstIterator::operator ++ ();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator ++ (int) // postfix
|
||||
{
|
||||
Iterator tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
friend class LinearHashTable;
|
||||
};
|
||||
|
||||
LinearHashTable(std::size_t initialReserve = 64):
|
||||
_split(0),
|
||||
_front(1),
|
||||
_size(0)
|
||||
/// Creates the LinearHashTable, using the given initialReserve.
|
||||
{
|
||||
_buckets.reserve(calcSize(initialReserve));
|
||||
_buckets.push_back(Bucket());
|
||||
}
|
||||
|
||||
LinearHashTable(const LinearHashTable& table):
|
||||
_buckets(table._buckets),
|
||||
_split(table._split),
|
||||
_front(table._front),
|
||||
_size(table._size)
|
||||
/// Creates the LinearHashTable by copying another one.
|
||||
{
|
||||
}
|
||||
|
||||
~LinearHashTable()
|
||||
/// Destroys the LinearHashTable.
|
||||
{
|
||||
}
|
||||
|
||||
LinearHashTable& operator = (const LinearHashTable& table)
|
||||
/// Assigns another LinearHashTable.
|
||||
{
|
||||
LinearHashTable tmp(table);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(LinearHashTable& table)
|
||||
/// Swaps the LinearHashTable with another one.
|
||||
{
|
||||
using std::swap;
|
||||
swap(_buckets, table._buckets);
|
||||
swap(_split, table._split);
|
||||
swap(_front, table._front);
|
||||
swap(_size, table._size);
|
||||
}
|
||||
|
||||
ConstIterator begin() const
|
||||
/// Returns an iterator pointing to the first entry, if one exists.
|
||||
{
|
||||
BucketVecIterator it(_buckets.begin());
|
||||
BucketVecIterator end(_buckets.end());
|
||||
while (it != end && it->empty())
|
||||
{
|
||||
++it;
|
||||
}
|
||||
if (it == end)
|
||||
return this->end();
|
||||
else
|
||||
return ConstIterator(it, end, it->begin());
|
||||
}
|
||||
|
||||
ConstIterator end() const
|
||||
/// Returns an iterator pointing to the end of the table.
|
||||
{
|
||||
return ConstIterator(_buckets.end(), _buckets.end(), _buckets.front().end());
|
||||
}
|
||||
|
||||
Iterator begin()
|
||||
/// Returns an iterator pointing to the first entry, if one exists.
|
||||
{
|
||||
BucketVecIterator it(_buckets.begin());
|
||||
BucketVecIterator end(_buckets.end());
|
||||
while (it != end && it->empty())
|
||||
{
|
||||
++it;
|
||||
}
|
||||
if (it == end)
|
||||
return this->end();
|
||||
else
|
||||
return Iterator(it, end, it->begin());
|
||||
}
|
||||
|
||||
Iterator end()
|
||||
/// Returns an iterator pointing to the end of the table.
|
||||
{
|
||||
return Iterator(_buckets.end(), _buckets.end(), _buckets.front().end());
|
||||
}
|
||||
|
||||
ConstIterator find(const Value& value) const
|
||||
/// Finds an entry in the table.
|
||||
{
|
||||
std::size_t addr = bucketAddress(value);
|
||||
BucketVecIterator it(_buckets.begin() + addr);
|
||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||
if (buckIt != it->end())
|
||||
return ConstIterator(it, _buckets.end(), buckIt);
|
||||
else
|
||||
return end();
|
||||
}
|
||||
|
||||
Iterator find(const Value& value)
|
||||
/// Finds an entry in the table.
|
||||
{
|
||||
std::size_t addr = bucketAddress(value);
|
||||
BucketVecIterator it(_buckets.begin() + addr);
|
||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||
if (buckIt != it->end())
|
||||
return Iterator(it, _buckets.end(), buckIt);
|
||||
else
|
||||
return end();
|
||||
}
|
||||
|
||||
std::size_t count(const Value& value) const
|
||||
/// Returns the number of elements with the given
|
||||
/// value, with is either 1 or 0.
|
||||
{
|
||||
return find(value) != end() ? 1 : 0;
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const Value& value)
|
||||
/// Inserts an element into the table.
|
||||
///
|
||||
/// If the element already exists in the table,
|
||||
/// a pair(iterator, false) with iterator pointing to the
|
||||
/// existing element is returned.
|
||||
/// Otherwise, the element is inserted an a
|
||||
/// pair(iterator, true) with iterator
|
||||
/// pointing to the new element is returned.
|
||||
{
|
||||
split();
|
||||
std::size_t addr = bucketAddress(value);
|
||||
BucketVecIterator it(_buckets.begin() + addr);
|
||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||
if (buckIt == it->end())
|
||||
{
|
||||
buckIt = it->insert(buckIt, value);
|
||||
++_size;
|
||||
return std::make_pair(Iterator(it, _buckets.end(), buckIt), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::make_pair(Iterator(it, _buckets.end(), buckIt), false);
|
||||
}
|
||||
}
|
||||
|
||||
void erase(Iterator it)
|
||||
/// Erases the element pointed to by it.
|
||||
{
|
||||
if (it != end())
|
||||
{
|
||||
it._vecIt->erase(it._buckIt);
|
||||
--_size;
|
||||
merge();
|
||||
}
|
||||
}
|
||||
|
||||
void erase(const Value& value)
|
||||
/// Erases the element with the given value, if it exists.
|
||||
{
|
||||
Iterator it = find(value);
|
||||
erase(it);
|
||||
}
|
||||
|
||||
void clear()
|
||||
/// Erases all elements.
|
||||
{
|
||||
LinearHashTable empty;
|
||||
swap(empty);
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
/// Returns the number of elements in the table.
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
/// Returns true iff the table is empty.
|
||||
{
|
||||
return _size == 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::size_t bucketAddress(const Value& value) const
|
||||
{
|
||||
std::size_t n = _hash(value);
|
||||
if (n % _front >= _split)
|
||||
return n % _front;
|
||||
else
|
||||
return n % (2*_front);
|
||||
}
|
||||
|
||||
void split()
|
||||
{
|
||||
if (_split == _front)
|
||||
{
|
||||
_split = 0;
|
||||
_front *= 2;
|
||||
_buckets.reserve(_front*2);
|
||||
}
|
||||
Bucket tmp;
|
||||
_buckets.push_back(tmp);
|
||||
_buckets[_split].swap(tmp);
|
||||
++_split;
|
||||
for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it)
|
||||
{
|
||||
using std::swap;
|
||||
std::size_t addr = bucketAddress(*it);
|
||||
_buckets[addr].push_back(Value());
|
||||
swap(*it, _buckets[addr].back());
|
||||
}
|
||||
}
|
||||
|
||||
void merge()
|
||||
{
|
||||
if (_split == 0)
|
||||
{
|
||||
_front /= 2;
|
||||
_split = _front;
|
||||
}
|
||||
--_split;
|
||||
Bucket tmp;
|
||||
tmp.swap(_buckets.back());
|
||||
_buckets.pop_back();
|
||||
for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it)
|
||||
{
|
||||
using std::swap;
|
||||
std::size_t addr = bucketAddress(*it);
|
||||
_buckets[addr].push_back(Value());
|
||||
swap(*it, _buckets[addr].back());
|
||||
}
|
||||
}
|
||||
|
||||
static std::size_t calcSize(std::size_t initialSize)
|
||||
{
|
||||
std::size_t size = 32;
|
||||
while (size < initialSize) size *= 2;
|
||||
return size;
|
||||
}
|
||||
|
||||
private:
|
||||
// Evil hack: _buckets must be mutable because both ConstIterator and Iterator hold
|
||||
// ordinary iterator's (not const_iterator's).
|
||||
mutable BucketVec _buckets;
|
||||
std::size_t _split;
|
||||
std::size_t _front;
|
||||
std::size_t _size;
|
||||
HashFunc _hash;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_LinearHashTable_INCLUDED
|
||||
//
|
||||
// LinearHashTable.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/LinearHashTable.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: LinearHashTable
|
||||
//
|
||||
// Definition of the LinearHashTable class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_LinearHashTable_INCLUDED
|
||||
#define Foundation_LinearHashTable_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Hash.h"
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Value, class HashFunc = Hash<Value> >
|
||||
class LinearHashTable
|
||||
/// This class implements a linear hash table.
|
||||
///
|
||||
/// In a linear hash table, the available address space
|
||||
/// grows or shrinks dynamically. A linar hash table thus
|
||||
/// supports any number of insertions or deletions without
|
||||
/// lookup or insertion performance deterioration.
|
||||
///
|
||||
/// Linear hashing was discovered by Witold Litwin in 1980
|
||||
/// and described in the paper LINEAR HASHING: A NEW TOOL FOR FILE AND TABLE ADDRESSING.
|
||||
///
|
||||
/// For more information on linear hashing, see <http://en.wikipedia.org/wiki/Linear_hash>.
|
||||
///
|
||||
/// The LinearHashTable is not thread safe.
|
||||
///
|
||||
/// Value must support comparison for equality.
|
||||
///
|
||||
/// Find, insert and delete operations are basically O(1) with regard
|
||||
/// to the total number of elements in the table, and O(N) with regard
|
||||
/// to the number of elements in the bucket where the element is stored.
|
||||
/// On average, every bucket stores one element; the exact number depends
|
||||
/// on the quality of the hash function. In most cases, the maximum number of
|
||||
/// elements in a bucket should not exceed 3.
|
||||
{
|
||||
public:
|
||||
typedef Value ValueType;
|
||||
typedef Value& Reference;
|
||||
typedef const Value& ConstReference;
|
||||
typedef Value* Pointer;
|
||||
typedef const Value* ConstPointer;
|
||||
typedef HashFunc Hash;
|
||||
typedef std::vector<Value> Bucket;
|
||||
typedef std::vector<Bucket> BucketVec;
|
||||
typedef typename Bucket::iterator BucketIterator;
|
||||
typedef typename BucketVec::iterator BucketVecIterator;
|
||||
|
||||
class ConstIterator
|
||||
{
|
||||
public:
|
||||
ConstIterator()
|
||||
{
|
||||
}
|
||||
|
||||
ConstIterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt):
|
||||
_vecIt(vecIt),
|
||||
_endIt(endIt),
|
||||
_buckIt(buckIt)
|
||||
{
|
||||
}
|
||||
|
||||
ConstIterator(const ConstIterator& it):
|
||||
_vecIt(it._vecIt),
|
||||
_endIt(it._endIt),
|
||||
_buckIt(it._buckIt)
|
||||
{
|
||||
}
|
||||
|
||||
ConstIterator& operator = (const ConstIterator& it)
|
||||
{
|
||||
ConstIterator tmp(it);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(ConstIterator& it)
|
||||
{
|
||||
using std::swap;
|
||||
swap(_vecIt, it._vecIt);
|
||||
swap(_endIt, it._endIt);
|
||||
swap(_buckIt, it._buckIt);
|
||||
}
|
||||
|
||||
bool operator == (const ConstIterator& it) const
|
||||
{
|
||||
return _vecIt == it._vecIt && (_vecIt == _endIt || _buckIt == it._buckIt);
|
||||
}
|
||||
|
||||
bool operator != (const ConstIterator& it) const
|
||||
{
|
||||
return _vecIt != it._vecIt || (_vecIt != _endIt && _buckIt != it._buckIt);
|
||||
}
|
||||
|
||||
const typename Bucket::value_type& operator * () const
|
||||
{
|
||||
return *_buckIt;
|
||||
}
|
||||
|
||||
const typename Bucket::value_type* operator -> () const
|
||||
{
|
||||
return &*_buckIt;
|
||||
}
|
||||
|
||||
ConstIterator& operator ++ () // prefix
|
||||
{
|
||||
if (_vecIt != _endIt)
|
||||
{
|
||||
++_buckIt;
|
||||
while (_vecIt != _endIt && _buckIt == _vecIt->end())
|
||||
{
|
||||
++_vecIt;
|
||||
if (_vecIt != _endIt) _buckIt = _vecIt->begin();
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ConstIterator operator ++ (int) // postfix
|
||||
{
|
||||
ConstIterator tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
protected:
|
||||
BucketVecIterator _vecIt;
|
||||
BucketVecIterator _endIt;
|
||||
BucketIterator _buckIt;
|
||||
|
||||
friend class LinearHashTable;
|
||||
};
|
||||
|
||||
class Iterator: public ConstIterator
|
||||
{
|
||||
public:
|
||||
Iterator()
|
||||
{
|
||||
}
|
||||
|
||||
Iterator(const BucketVecIterator& vecIt, const BucketVecIterator& endIt, const BucketIterator& buckIt):
|
||||
ConstIterator(vecIt, endIt, buckIt)
|
||||
{
|
||||
}
|
||||
|
||||
Iterator(const Iterator& it):
|
||||
ConstIterator(it)
|
||||
{
|
||||
}
|
||||
|
||||
Iterator& operator = (const Iterator& it)
|
||||
{
|
||||
Iterator tmp(it);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(Iterator& it)
|
||||
{
|
||||
ConstIterator::swap(it);
|
||||
}
|
||||
|
||||
typename Bucket::value_type& operator * ()
|
||||
{
|
||||
return *this->_buckIt;
|
||||
}
|
||||
|
||||
const typename Bucket::value_type& operator * () const
|
||||
{
|
||||
return *this->_buckIt;
|
||||
}
|
||||
|
||||
typename Bucket::value_type* operator -> ()
|
||||
{
|
||||
return &*this->_buckIt;
|
||||
}
|
||||
|
||||
const typename Bucket::value_type* operator -> () const
|
||||
{
|
||||
return &*this->_buckIt;
|
||||
}
|
||||
|
||||
Iterator& operator ++ () // prefix
|
||||
{
|
||||
ConstIterator::operator ++ ();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator ++ (int) // postfix
|
||||
{
|
||||
Iterator tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
friend class LinearHashTable;
|
||||
};
|
||||
|
||||
LinearHashTable(std::size_t initialReserve = 64):
|
||||
_split(0),
|
||||
_front(1),
|
||||
_size(0)
|
||||
/// Creates the LinearHashTable, using the given initialReserve.
|
||||
{
|
||||
_buckets.reserve(calcSize(initialReserve));
|
||||
_buckets.push_back(Bucket());
|
||||
}
|
||||
|
||||
LinearHashTable(const LinearHashTable& table):
|
||||
_buckets(table._buckets),
|
||||
_split(table._split),
|
||||
_front(table._front),
|
||||
_size(table._size)
|
||||
/// Creates the LinearHashTable by copying another one.
|
||||
{
|
||||
}
|
||||
|
||||
~LinearHashTable()
|
||||
/// Destroys the LinearHashTable.
|
||||
{
|
||||
}
|
||||
|
||||
LinearHashTable& operator = (const LinearHashTable& table)
|
||||
/// Assigns another LinearHashTable.
|
||||
{
|
||||
LinearHashTable tmp(table);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(LinearHashTable& table)
|
||||
/// Swaps the LinearHashTable with another one.
|
||||
{
|
||||
using std::swap;
|
||||
swap(_buckets, table._buckets);
|
||||
swap(_split, table._split);
|
||||
swap(_front, table._front);
|
||||
swap(_size, table._size);
|
||||
}
|
||||
|
||||
ConstIterator begin() const
|
||||
/// Returns an iterator pointing to the first entry, if one exists.
|
||||
{
|
||||
BucketVecIterator it(_buckets.begin());
|
||||
BucketVecIterator end(_buckets.end());
|
||||
while (it != end && it->empty())
|
||||
{
|
||||
++it;
|
||||
}
|
||||
if (it == end)
|
||||
return this->end();
|
||||
else
|
||||
return ConstIterator(it, end, it->begin());
|
||||
}
|
||||
|
||||
ConstIterator end() const
|
||||
/// Returns an iterator pointing to the end of the table.
|
||||
{
|
||||
return ConstIterator(_buckets.end(), _buckets.end(), _buckets.front().end());
|
||||
}
|
||||
|
||||
Iterator begin()
|
||||
/// Returns an iterator pointing to the first entry, if one exists.
|
||||
{
|
||||
BucketVecIterator it(_buckets.begin());
|
||||
BucketVecIterator end(_buckets.end());
|
||||
while (it != end && it->empty())
|
||||
{
|
||||
++it;
|
||||
}
|
||||
if (it == end)
|
||||
return this->end();
|
||||
else
|
||||
return Iterator(it, end, it->begin());
|
||||
}
|
||||
|
||||
Iterator end()
|
||||
/// Returns an iterator pointing to the end of the table.
|
||||
{
|
||||
return Iterator(_buckets.end(), _buckets.end(), _buckets.front().end());
|
||||
}
|
||||
|
||||
ConstIterator find(const Value& value) const
|
||||
/// Finds an entry in the table.
|
||||
{
|
||||
std::size_t addr = bucketAddress(value);
|
||||
BucketVecIterator it(_buckets.begin() + addr);
|
||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||
if (buckIt != it->end())
|
||||
return ConstIterator(it, _buckets.end(), buckIt);
|
||||
else
|
||||
return end();
|
||||
}
|
||||
|
||||
Iterator find(const Value& value)
|
||||
/// Finds an entry in the table.
|
||||
{
|
||||
std::size_t addr = bucketAddress(value);
|
||||
BucketVecIterator it(_buckets.begin() + addr);
|
||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||
if (buckIt != it->end())
|
||||
return Iterator(it, _buckets.end(), buckIt);
|
||||
else
|
||||
return end();
|
||||
}
|
||||
|
||||
std::size_t count(const Value& value) const
|
||||
/// Returns the number of elements with the given
|
||||
/// value, with is either 1 or 0.
|
||||
{
|
||||
return find(value) != end() ? 1 : 0;
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const Value& value)
|
||||
/// Inserts an element into the table.
|
||||
///
|
||||
/// If the element already exists in the table,
|
||||
/// a pair(iterator, false) with iterator pointing to the
|
||||
/// existing element is returned.
|
||||
/// Otherwise, the element is inserted an a
|
||||
/// pair(iterator, true) with iterator
|
||||
/// pointing to the new element is returned.
|
||||
{
|
||||
split();
|
||||
std::size_t addr = bucketAddress(value);
|
||||
BucketVecIterator it(_buckets.begin() + addr);
|
||||
BucketIterator buckIt(std::find(it->begin(), it->end(), value));
|
||||
if (buckIt == it->end())
|
||||
{
|
||||
buckIt = it->insert(buckIt, value);
|
||||
++_size;
|
||||
return std::make_pair(Iterator(it, _buckets.end(), buckIt), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::make_pair(Iterator(it, _buckets.end(), buckIt), false);
|
||||
}
|
||||
}
|
||||
|
||||
void erase(Iterator it)
|
||||
/// Erases the element pointed to by it.
|
||||
{
|
||||
if (it != end())
|
||||
{
|
||||
it._vecIt->erase(it._buckIt);
|
||||
--_size;
|
||||
merge();
|
||||
}
|
||||
}
|
||||
|
||||
void erase(const Value& value)
|
||||
/// Erases the element with the given value, if it exists.
|
||||
{
|
||||
Iterator it = find(value);
|
||||
erase(it);
|
||||
}
|
||||
|
||||
void clear()
|
||||
/// Erases all elements.
|
||||
{
|
||||
LinearHashTable empty;
|
||||
swap(empty);
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
/// Returns the number of elements in the table.
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
/// Returns true iff the table is empty.
|
||||
{
|
||||
return _size == 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::size_t bucketAddress(const Value& value) const
|
||||
{
|
||||
std::size_t n = _hash(value);
|
||||
if (n % _front >= _split)
|
||||
return n % _front;
|
||||
else
|
||||
return n % (2*_front);
|
||||
}
|
||||
|
||||
void split()
|
||||
{
|
||||
if (_split == _front)
|
||||
{
|
||||
_split = 0;
|
||||
_front *= 2;
|
||||
_buckets.reserve(_front*2);
|
||||
}
|
||||
Bucket tmp;
|
||||
_buckets.push_back(tmp);
|
||||
_buckets[_split].swap(tmp);
|
||||
++_split;
|
||||
for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it)
|
||||
{
|
||||
using std::swap;
|
||||
std::size_t addr = bucketAddress(*it);
|
||||
_buckets[addr].push_back(Value());
|
||||
swap(*it, _buckets[addr].back());
|
||||
}
|
||||
}
|
||||
|
||||
void merge()
|
||||
{
|
||||
if (_split == 0)
|
||||
{
|
||||
_front /= 2;
|
||||
_split = _front;
|
||||
}
|
||||
--_split;
|
||||
Bucket tmp;
|
||||
tmp.swap(_buckets.back());
|
||||
_buckets.pop_back();
|
||||
for (BucketIterator it = tmp.begin(); it != tmp.end(); ++it)
|
||||
{
|
||||
using std::swap;
|
||||
std::size_t addr = bucketAddress(*it);
|
||||
_buckets[addr].push_back(Value());
|
||||
swap(*it, _buckets[addr].back());
|
||||
}
|
||||
}
|
||||
|
||||
static std::size_t calcSize(std::size_t initialSize)
|
||||
{
|
||||
std::size_t size = 32;
|
||||
while (size < initialSize) size *= 2;
|
||||
return size;
|
||||
}
|
||||
|
||||
private:
|
||||
// Evil hack: _buckets must be mutable because both ConstIterator and Iterator hold
|
||||
// ordinary iterator's (not const_iterator's).
|
||||
mutable BucketVec _buckets;
|
||||
std::size_t _split;
|
||||
std::size_t _front;
|
||||
std::size_t _size;
|
||||
HashFunc _hash;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_LinearHashTable_INCLUDED
|
||||
|
|
|
@ -1,157 +1,157 @@
|
|||
//
|
||||
// TypeChecks.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/MetaProgramming.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: MetaProgramming
|
||||
//
|
||||
// Common definitions useful for Meta Template Programming
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_TypeChecks_INCLUDED
|
||||
#define Foundation_TypeChecks_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsReference
|
||||
///Use this struct to determine if a template type is a reference
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 0
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsReference<T&>
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsReference<const T&>
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsConst
|
||||
///Use this struct to determine if a template type is a const type
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 0
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsConst<const T&>
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsConst<const T>
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeWrapper
|
||||
/// Use the type wrapper if you want to dedecouple constness and references from template types
|
||||
{
|
||||
typedef T TYPE;
|
||||
typedef const T CONSTTYPE;
|
||||
typedef T& REFTYPE;
|
||||
typedef const T& CONSTREFTYPE;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeWrapper<const T>
|
||||
{
|
||||
typedef T TYPE;
|
||||
typedef const T CONSTTYPE;
|
||||
typedef T& REFTYPE;
|
||||
typedef const T& CONSTREFTYPE;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeWrapper<const T&>
|
||||
{
|
||||
typedef T TYPE;
|
||||
typedef const T CONSTTYPE;
|
||||
typedef T& REFTYPE;
|
||||
typedef const T& CONSTREFTYPE;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeWrapper<T&>
|
||||
{
|
||||
typedef T TYPE;
|
||||
typedef const T CONSTTYPE;
|
||||
typedef T& REFTYPE;
|
||||
typedef const T& CONSTREFTYPE;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// TypeChecks.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/MetaProgramming.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: MetaProgramming
|
||||
//
|
||||
// Common definitions useful for Meta Template Programming
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_TypeChecks_INCLUDED
|
||||
#define Foundation_TypeChecks_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsReference
|
||||
///Use this struct to determine if a template type is a reference
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 0
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsReference<T&>
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsReference<const T&>
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsConst
|
||||
///Use this struct to determine if a template type is a const type
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 0
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsConst<const T&>
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsConst<const T>
|
||||
{
|
||||
enum
|
||||
{
|
||||
VALUE = 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeWrapper
|
||||
/// Use the type wrapper if you want to dedecouple constness and references from template types
|
||||
{
|
||||
typedef T TYPE;
|
||||
typedef const T CONSTTYPE;
|
||||
typedef T& REFTYPE;
|
||||
typedef const T& CONSTREFTYPE;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeWrapper<const T>
|
||||
{
|
||||
typedef T TYPE;
|
||||
typedef const T CONSTTYPE;
|
||||
typedef T& REFTYPE;
|
||||
typedef const T& CONSTREFTYPE;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeWrapper<const T&>
|
||||
{
|
||||
typedef T TYPE;
|
||||
typedef const T CONSTTYPE;
|
||||
typedef T& REFTYPE;
|
||||
typedef const T& CONSTREFTYPE;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeWrapper<T&>
|
||||
{
|
||||
typedef T TYPE;
|
||||
typedef const T CONSTTYPE;
|
||||
typedef T& REFTYPE;
|
||||
typedef const T& CONSTREFTYPE;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,79 +1,79 @@
|
|||
//
|
||||
// ScopedUnlock.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ScopedUnlock.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Mutex
|
||||
//
|
||||
// Definition of the ScopedUnlock template class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_ScopedUnlock_INCLUDED
|
||||
#define Foundation_ScopedUnlock_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class M>
|
||||
class ScopedUnlock
|
||||
/// A class that simplifies thread synchronization
|
||||
/// with a mutex.
|
||||
/// The constructor accepts a Mutex and unlocks it.
|
||||
/// The destructor unlocks the mutex.
|
||||
{
|
||||
public:
|
||||
inline ScopedUnlock(M& mutex, bool unlockNow = true): _mutex(mutex)
|
||||
{
|
||||
if (unlockNow)
|
||||
_mutex.unlock();
|
||||
}
|
||||
inline ~ScopedUnlock()
|
||||
{
|
||||
_mutex.lock();
|
||||
}
|
||||
|
||||
private:
|
||||
M& _mutex;
|
||||
|
||||
ScopedUnlock();
|
||||
ScopedUnlock(const ScopedUnlock&);
|
||||
ScopedUnlock& operator = (const ScopedUnlock&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_ScopedUnlock_INCLUDED
|
||||
//
|
||||
// ScopedUnlock.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ScopedUnlock.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Mutex
|
||||
//
|
||||
// Definition of the ScopedUnlock template class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_ScopedUnlock_INCLUDED
|
||||
#define Foundation_ScopedUnlock_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class M>
|
||||
class ScopedUnlock
|
||||
/// A class that simplifies thread synchronization
|
||||
/// with a mutex.
|
||||
/// The constructor accepts a Mutex and unlocks it.
|
||||
/// The destructor unlocks the mutex.
|
||||
{
|
||||
public:
|
||||
inline ScopedUnlock(M& mutex, bool unlockNow = true): _mutex(mutex)
|
||||
{
|
||||
if (unlockNow)
|
||||
_mutex.unlock();
|
||||
}
|
||||
inline ~ScopedUnlock()
|
||||
{
|
||||
_mutex.lock();
|
||||
}
|
||||
|
||||
private:
|
||||
M& _mutex;
|
||||
|
||||
ScopedUnlock();
|
||||
ScopedUnlock(const ScopedUnlock&);
|
||||
ScopedUnlock& operator = (const ScopedUnlock&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_ScopedUnlock_INCLUDED
|
||||
|
|
|
@ -1,135 +1,135 @@
|
|||
//
|
||||
// SharedMemory.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemory
|
||||
//
|
||||
// Definition of the SharedMemory class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_SharedMemory_INCLUDED
|
||||
#define Foundation_SharedMemory_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class SharedMemoryImpl;
|
||||
class File;
|
||||
|
||||
|
||||
class Foundation_API SharedMemory
|
||||
/// Create and manage a shared memory object.
|
||||
///
|
||||
/// A SharedMemory object has value semantics, but
|
||||
/// is implemented using a handle/implementation idiom.
|
||||
/// Therefore, multiple SharedMemory objects can share
|
||||
/// a single, reference counted SharedMemoryImpl object.
|
||||
{
|
||||
public:
|
||||
enum AccessMode
|
||||
{
|
||||
AM_READ = 0,
|
||||
AM_WRITE
|
||||
};
|
||||
|
||||
SharedMemory();
|
||||
/// Default constructor creates an unmapped SharedMemory object.
|
||||
/// No clients can connect to an unmapped SharedMemory object.
|
||||
|
||||
SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint = 0, bool server = true);
|
||||
/// Creates or connects to a shared memory object with the given name.
|
||||
///
|
||||
/// For maximum portability, name should be a valid Unix filename and not
|
||||
/// contain any slashes or backslashes.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
///
|
||||
/// If server is set to false, the shared memory region will be unlinked
|
||||
/// by calling shm_unlink (on POSIX platforms) when the SharedMemory object is destroyed.
|
||||
/// The server parameter is ignored on Windows platforms.
|
||||
|
||||
SharedMemory(const File& file, AccessMode mode, const void* addrHint = 0);
|
||||
/// Maps the entire contents of file into a shared memory segment.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
SharedMemory(const SharedMemory& other);
|
||||
/// Creates a SharedMemory object by copying another one.
|
||||
|
||||
~SharedMemory();
|
||||
/// Destroys the SharedMemory.
|
||||
|
||||
SharedMemory& operator = (const SharedMemory& other);
|
||||
/// Assigns another SharedMemory object.
|
||||
|
||||
void swap(SharedMemory& other);
|
||||
/// Swaps the SharedMemory object with another one.
|
||||
|
||||
char* begin() const;
|
||||
/// Returns the start address of the shared memory segment.
|
||||
/// Will be NULL for illegal segments.
|
||||
|
||||
char* end() const;
|
||||
/// Returns the one-past-end end address of the shared memory segment.
|
||||
/// Will be NULL for illegal segments.
|
||||
|
||||
private:
|
||||
SharedMemoryImpl* _pImpl;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void SharedMemory::swap(SharedMemory& other)
|
||||
{
|
||||
using std::swap;
|
||||
swap(_pImpl, other._pImpl);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco::Poco
|
||||
|
||||
|
||||
#endif // Foundation_SharedMemory_INCLUDED
|
||||
//
|
||||
// SharedMemory.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemory
|
||||
//
|
||||
// Definition of the SharedMemory class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_SharedMemory_INCLUDED
|
||||
#define Foundation_SharedMemory_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class SharedMemoryImpl;
|
||||
class File;
|
||||
|
||||
|
||||
class Foundation_API SharedMemory
|
||||
/// Create and manage a shared memory object.
|
||||
///
|
||||
/// A SharedMemory object has value semantics, but
|
||||
/// is implemented using a handle/implementation idiom.
|
||||
/// Therefore, multiple SharedMemory objects can share
|
||||
/// a single, reference counted SharedMemoryImpl object.
|
||||
{
|
||||
public:
|
||||
enum AccessMode
|
||||
{
|
||||
AM_READ = 0,
|
||||
AM_WRITE
|
||||
};
|
||||
|
||||
SharedMemory();
|
||||
/// Default constructor creates an unmapped SharedMemory object.
|
||||
/// No clients can connect to an unmapped SharedMemory object.
|
||||
|
||||
SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint = 0, bool server = true);
|
||||
/// Creates or connects to a shared memory object with the given name.
|
||||
///
|
||||
/// For maximum portability, name should be a valid Unix filename and not
|
||||
/// contain any slashes or backslashes.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
///
|
||||
/// If server is set to false, the shared memory region will be unlinked
|
||||
/// by calling shm_unlink (on POSIX platforms) when the SharedMemory object is destroyed.
|
||||
/// The server parameter is ignored on Windows platforms.
|
||||
|
||||
SharedMemory(const File& file, AccessMode mode, const void* addrHint = 0);
|
||||
/// Maps the entire contents of file into a shared memory segment.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
SharedMemory(const SharedMemory& other);
|
||||
/// Creates a SharedMemory object by copying another one.
|
||||
|
||||
~SharedMemory();
|
||||
/// Destroys the SharedMemory.
|
||||
|
||||
SharedMemory& operator = (const SharedMemory& other);
|
||||
/// Assigns another SharedMemory object.
|
||||
|
||||
void swap(SharedMemory& other);
|
||||
/// Swaps the SharedMemory object with another one.
|
||||
|
||||
char* begin() const;
|
||||
/// Returns the start address of the shared memory segment.
|
||||
/// Will be NULL for illegal segments.
|
||||
|
||||
char* end() const;
|
||||
/// Returns the one-past-end end address of the shared memory segment.
|
||||
/// Will be NULL for illegal segments.
|
||||
|
||||
private:
|
||||
SharedMemoryImpl* _pImpl;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void SharedMemory::swap(SharedMemory& other)
|
||||
{
|
||||
using std::swap;
|
||||
swap(_pImpl, other._pImpl);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco::Poco
|
||||
|
||||
|
||||
#endif // Foundation_SharedMemory_INCLUDED
|
||||
|
|
|
@ -1,110 +1,110 @@
|
|||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_DUMMY.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Definition of the SharedMemoryImpl class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||
/// A dummy implementation of shared memory, for systems
|
||||
/// that do not have shared memory support.
|
||||
{
|
||||
public:
|
||||
SharedMemoryImpl(const std::string& id, std::size_t size, SharedMemory::AccessMode mode, const void* addr, bool server);
|
||||
/// Creates or connects to a shared memory object with the given name.
|
||||
///
|
||||
/// For maximum portability, name should be a valid Unix filename and not
|
||||
/// contain any slashes or backslashes.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
SharedMemoryImpl(const Poco::File& aFile, SharedMemory::AccessMode mode, const void* addr);
|
||||
/// Maps the entire contents of file into a shared memory segment.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
char* begin() const;
|
||||
/// Returns the start address of the shared memory segment.
|
||||
|
||||
char* end() const;
|
||||
/// Returns the one-past-end end address of the shared memory segment.
|
||||
|
||||
protected:
|
||||
~SharedMemoryImpl();
|
||||
/// Destroys the SharedMemoryImpl.
|
||||
|
||||
private:
|
||||
SharedMemoryImpl();
|
||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline char* SharedMemoryImpl::begin() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline char* SharedMemoryImpl::end() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_DUMMY.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Definition of the SharedMemoryImpl class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||
/// A dummy implementation of shared memory, for systems
|
||||
/// that do not have shared memory support.
|
||||
{
|
||||
public:
|
||||
SharedMemoryImpl(const std::string& id, std::size_t size, SharedMemory::AccessMode mode, const void* addr, bool server);
|
||||
/// Creates or connects to a shared memory object with the given name.
|
||||
///
|
||||
/// For maximum portability, name should be a valid Unix filename and not
|
||||
/// contain any slashes or backslashes.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
SharedMemoryImpl(const Poco::File& aFile, SharedMemory::AccessMode mode, const void* addr);
|
||||
/// Maps the entire contents of file into a shared memory segment.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
char* begin() const;
|
||||
/// Returns the start address of the shared memory segment.
|
||||
|
||||
char* end() const;
|
||||
/// Returns the one-past-end end address of the shared memory segment.
|
||||
|
||||
protected:
|
||||
~SharedMemoryImpl();
|
||||
/// Destroys the SharedMemoryImpl.
|
||||
|
||||
private:
|
||||
SharedMemoryImpl();
|
||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline char* SharedMemoryImpl::begin() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline char* SharedMemoryImpl::end() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
|
|
@ -1,129 +1,129 @@
|
|||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_POSIX.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Definition of the SharedMemoryImpl class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||
/// Shared memory implementation for POSIX platforms.
|
||||
{
|
||||
public:
|
||||
SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server);
|
||||
/// Creates or connects to a shared memory object with the given name.
|
||||
///
|
||||
/// For maximum portability, name should be a valid Unix filename and not
|
||||
/// contain any slashes or backslashes.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
///
|
||||
/// If server is set to false, the shared memory region will be unlinked
|
||||
/// by calling shm_unlink when the SharedMemory object is destroyed.
|
||||
|
||||
SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint);
|
||||
/// Maps the entire contents of file into a shared memory segment.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
char* begin() const;
|
||||
/// Returns the start address of the shared memory segment.
|
||||
|
||||
char* end() const;
|
||||
/// Returns the one-past-end end address of the shared memory segment.
|
||||
|
||||
protected:
|
||||
void map(const void* addrHint);
|
||||
/// Maps the shared memory object.
|
||||
|
||||
void unmap();
|
||||
/// Unmaps the shared memory object.
|
||||
|
||||
void close();
|
||||
/// Releases the handle for the shared memory segment.
|
||||
|
||||
~SharedMemoryImpl();
|
||||
/// Destroys the SharedMemoryImpl.
|
||||
|
||||
private:
|
||||
SharedMemoryImpl();
|
||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||
|
||||
std::size_t _size;
|
||||
int _fd;
|
||||
char* _address;
|
||||
SharedMemory::AccessMode _access;
|
||||
std::string _name;
|
||||
bool _fileMapped;
|
||||
bool _server;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline char* SharedMemoryImpl::begin() const
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
|
||||
|
||||
inline char* SharedMemoryImpl::end() const
|
||||
{
|
||||
return _address + _size;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_POSIX.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Definition of the SharedMemoryImpl class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||
/// Shared memory implementation for POSIX platforms.
|
||||
{
|
||||
public:
|
||||
SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server);
|
||||
/// Creates or connects to a shared memory object with the given name.
|
||||
///
|
||||
/// For maximum portability, name should be a valid Unix filename and not
|
||||
/// contain any slashes or backslashes.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
///
|
||||
/// If server is set to false, the shared memory region will be unlinked
|
||||
/// by calling shm_unlink when the SharedMemory object is destroyed.
|
||||
|
||||
SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint);
|
||||
/// Maps the entire contents of file into a shared memory segment.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
char* begin() const;
|
||||
/// Returns the start address of the shared memory segment.
|
||||
|
||||
char* end() const;
|
||||
/// Returns the one-past-end end address of the shared memory segment.
|
||||
|
||||
protected:
|
||||
void map(const void* addrHint);
|
||||
/// Maps the shared memory object.
|
||||
|
||||
void unmap();
|
||||
/// Unmaps the shared memory object.
|
||||
|
||||
void close();
|
||||
/// Releases the handle for the shared memory segment.
|
||||
|
||||
~SharedMemoryImpl();
|
||||
/// Destroys the SharedMemoryImpl.
|
||||
|
||||
private:
|
||||
SharedMemoryImpl();
|
||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||
|
||||
std::size_t _size;
|
||||
int _fd;
|
||||
char* _address;
|
||||
SharedMemory::AccessMode _access;
|
||||
std::string _name;
|
||||
bool _fileMapped;
|
||||
bool _server;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline char* SharedMemoryImpl::begin() const
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
|
||||
|
||||
inline char* SharedMemoryImpl::end() const
|
||||
{
|
||||
return _address + _size;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
|
|
@ -1,125 +1,125 @@
|
|||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_WIN32.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Definition of the SharedMemoryImpl class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||
/// Shared memory implementation for Windows platforms.
|
||||
{
|
||||
public:
|
||||
SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server);
|
||||
/// Creates or connects to a shared memory object with the given name.
|
||||
///
|
||||
/// For maximum portability, name should be a valid Unix filename and not
|
||||
/// contain any slashes or backslashes.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint);
|
||||
/// Maps the entire contents of file into a shared memory segment.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
char* begin() const;
|
||||
/// Returns the beginn address of the SharedMemory segment. Will be null for illegal segments.
|
||||
|
||||
char* end() const;
|
||||
/// Points past the last byte of the end address of the SharedMemory segment. Will be null for illegal segments.
|
||||
|
||||
protected:
|
||||
void map();
|
||||
/// Maps the shared memory object.
|
||||
|
||||
void unmap();
|
||||
/// Unmaps the shared memory object.
|
||||
|
||||
void close();
|
||||
/// Releases the handle for the shared memory segment.
|
||||
|
||||
~SharedMemoryImpl();
|
||||
/// Destroys the SharedMemoryImpl.
|
||||
|
||||
private:
|
||||
SharedMemoryImpl();
|
||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||
|
||||
std::string _name;
|
||||
HANDLE _memHandle;
|
||||
HANDLE _fileHandle;
|
||||
DWORD _size;
|
||||
DWORD _mode;
|
||||
char* _address;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline char* SharedMemoryImpl::begin() const
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
|
||||
|
||||
inline char* SharedMemoryImpl::end() const
|
||||
{
|
||||
return _address + _size;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
//
|
||||
// SharedMemoryImpl.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/SharedMemory_WIN32.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Definition of the SharedMemoryImpl class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_SharedMemoryImpl_INCLUDED
|
||||
#define Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Poco.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API SharedMemoryImpl: public RefCountedObject
|
||||
/// Shared memory implementation for Windows platforms.
|
||||
{
|
||||
public:
|
||||
SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server);
|
||||
/// Creates or connects to a shared memory object with the given name.
|
||||
///
|
||||
/// For maximum portability, name should be a valid Unix filename and not
|
||||
/// contain any slashes or backslashes.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint);
|
||||
/// Maps the entire contents of file into a shared memory segment.
|
||||
///
|
||||
/// An address hint can be passed to the system, specifying the desired
|
||||
/// start address of the shared memory area. Whether the hint
|
||||
/// is actually honored is, however, up to the system. Windows platform
|
||||
/// will generally ignore the hint.
|
||||
|
||||
char* begin() const;
|
||||
/// Returns the beginn address of the SharedMemory segment. Will be null for illegal segments.
|
||||
|
||||
char* end() const;
|
||||
/// Points past the last byte of the end address of the SharedMemory segment. Will be null for illegal segments.
|
||||
|
||||
protected:
|
||||
void map();
|
||||
/// Maps the shared memory object.
|
||||
|
||||
void unmap();
|
||||
/// Unmaps the shared memory object.
|
||||
|
||||
void close();
|
||||
/// Releases the handle for the shared memory segment.
|
||||
|
||||
~SharedMemoryImpl();
|
||||
/// Destroys the SharedMemoryImpl.
|
||||
|
||||
private:
|
||||
SharedMemoryImpl();
|
||||
SharedMemoryImpl(const SharedMemoryImpl&);
|
||||
SharedMemoryImpl& operator = (const SharedMemoryImpl&);
|
||||
|
||||
std::string _name;
|
||||
HANDLE _memHandle;
|
||||
HANDLE _fileHandle;
|
||||
DWORD _size;
|
||||
DWORD _mode;
|
||||
char* _address;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline char* SharedMemoryImpl::begin() const
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
|
||||
|
||||
inline char* SharedMemoryImpl::end() const
|
||||
{
|
||||
return _address + _size;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_SharedMemoryImpl_INCLUDED
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,487 +1,487 @@
|
|||
//
|
||||
// TypeList.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/TypeList.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: TypeList
|
||||
//
|
||||
// Implementation of the TypeList template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Portions extracted and adapted from
|
||||
// The Loki Library
|
||||
// Copyright (c) 2001 by Andrei Alexandrescu
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_TypeList_INCLUDED
|
||||
#define Foundation_TypeList_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/MetaProgramming.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeList;
|
||||
|
||||
|
||||
struct NullTypeList
|
||||
{
|
||||
enum
|
||||
{
|
||||
length = 0
|
||||
};
|
||||
|
||||
bool operator == (const NullTypeList&) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator != (const NullTypeList&) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator < (const NullTypeList&) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeList
|
||||
/// Compile Time List of Types
|
||||
{
|
||||
typedef Head HeadType;
|
||||
typedef Tail TailType;
|
||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||
typedef typename TypeWrapper<TailType>::CONSTTYPE ConstTailType;
|
||||
enum
|
||||
{
|
||||
length = TailType::length+1
|
||||
};
|
||||
|
||||
TypeList():head(), tail()
|
||||
{
|
||||
}
|
||||
|
||||
TypeList(ConstHeadType& h, ConstTailType& t):head(h), tail(t)
|
||||
{
|
||||
}
|
||||
|
||||
TypeList(const TypeList& tl): head(tl.head), tail(tl.tail)
|
||||
{
|
||||
}
|
||||
|
||||
TypeList& operator = (const TypeList& tl)
|
||||
{
|
||||
if (this != &tl)
|
||||
{
|
||||
TypeList tmp(tl);
|
||||
swap(tmp);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator == (const TypeList& tl) const
|
||||
{
|
||||
return tl.head == head && tl.tail == tail;
|
||||
}
|
||||
|
||||
bool operator != (const TypeList& tl) const
|
||||
{
|
||||
return !(*this == tl);
|
||||
}
|
||||
|
||||
bool operator < (const TypeList& tl) const
|
||||
{
|
||||
if (head < tl.head)
|
||||
return true;
|
||||
else if (head == tl.head)
|
||||
return tail < tl.tail;
|
||||
return false;
|
||||
}
|
||||
|
||||
void swap(TypeList& tl)
|
||||
{
|
||||
std::swap(head, tl.head);
|
||||
std::swap(tail, tl.tail);
|
||||
}
|
||||
|
||||
HeadType head;
|
||||
TailType tail;
|
||||
};
|
||||
|
||||
|
||||
template <typename T0 = NullTypeList,
|
||||
typename T1 = NullTypeList,
|
||||
typename T2 = NullTypeList,
|
||||
typename T3 = NullTypeList,
|
||||
typename T4 = NullTypeList,
|
||||
typename T5 = NullTypeList,
|
||||
typename T6 = NullTypeList,
|
||||
typename T7 = NullTypeList,
|
||||
typename T8 = NullTypeList,
|
||||
typename T9 = NullTypeList,
|
||||
typename T10 = NullTypeList,
|
||||
typename T11 = NullTypeList,
|
||||
typename T12 = NullTypeList,
|
||||
typename T13 = NullTypeList,
|
||||
typename T14 = NullTypeList,
|
||||
typename T15 = NullTypeList,
|
||||
typename T16 = NullTypeList,
|
||||
typename T17 = NullTypeList,
|
||||
typename T18 = NullTypeList,
|
||||
typename T19 = NullTypeList>
|
||||
struct TypeListType
|
||||
/// TypeListType takes 1 - 20 typename arguments.
|
||||
/// Usage:
|
||||
///
|
||||
/// TypeListType<T0, T1, ... , Tn>::HeadType typeList;
|
||||
///
|
||||
/// typeList is a TypeList of T0, T1, ... , Tn
|
||||
{
|
||||
private:
|
||||
typedef typename TypeListType<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>::HeadType TailType;
|
||||
|
||||
public:
|
||||
typedef TypeList<T0, TailType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct TypeListType<>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <int n>
|
||||
struct Getter
|
||||
{
|
||||
template <class Ret, class Head, class Tail>
|
||||
inline static Ret& get(TypeList<Head, Tail>& val)
|
||||
{
|
||||
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
|
||||
}
|
||||
|
||||
template <class Ret, class Head, class Tail>
|
||||
inline static const Ret& get(const TypeList<Head, Tail>& val)
|
||||
{
|
||||
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct Getter<0>
|
||||
{
|
||||
template <class Ret, class Head, class Tail>
|
||||
inline static Ret& get(TypeList<Head, Tail>& val)
|
||||
{
|
||||
return val.head;
|
||||
}
|
||||
|
||||
template <class Ret, class Head, class Tail>
|
||||
inline static const Ret& get(const TypeList<Head, Tail>& val)
|
||||
{
|
||||
return val.head;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <int N, class Head>
|
||||
struct TypeGetter;
|
||||
|
||||
|
||||
template <int N, class Head, class Tail>
|
||||
struct TypeGetter<N, TypeList<Head, Tail> >
|
||||
{
|
||||
typedef typename TypeGetter<N-1, Tail>::HeadType HeadType;
|
||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeGetter<0, TypeList<Head, Tail> >
|
||||
{
|
||||
typedef typename TypeList<Head, Tail>::HeadType HeadType;
|
||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T>
|
||||
struct TypeLocator;
|
||||
/// TypeLocator returns the first occurrence of the type T in Head
|
||||
/// or -1 if the type is not found.
|
||||
///
|
||||
/// Usage example:
|
||||
///
|
||||
/// TypeLocator<Head, int>::HeadType TypeLoc;
|
||||
///
|
||||
/// if (2 == TypeLoc.value) ...
|
||||
///
|
||||
|
||||
|
||||
template <class T>
|
||||
struct TypeLocator<NullTypeList, T>
|
||||
{
|
||||
enum { value = -1 };
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail>
|
||||
struct TypeLocator<TypeList<T, Tail>, T>
|
||||
{
|
||||
enum { value = 0 };
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct TypeLocator<TypeList<Head, Tail>, T>
|
||||
{
|
||||
private:
|
||||
enum { tmp = TypeLocator<Tail, T>::value };
|
||||
public:
|
||||
enum { value = tmp == -1 ? -1 : 1 + tmp };
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T>
|
||||
struct TypeAppender;
|
||||
/// TypeAppender appends T (type or a TypeList) to Head.
|
||||
///
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char>::HeadType Type1;
|
||||
/// typedef TypeAppender<Type1, int>::HeadType Type2;
|
||||
/// (Type2 is a TypeList of char,int)
|
||||
///
|
||||
/// typedef TypeListType<float, double>::HeadType Type3;
|
||||
/// typedef TypeAppender<Type2, Type3>::HeadType Type4;
|
||||
/// (Type4 is a TypeList of char,int,float,double)
|
||||
///
|
||||
|
||||
|
||||
template <>
|
||||
struct TypeAppender<NullTypeList, NullTypeList>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct TypeAppender<NullTypeList, T>
|
||||
{
|
||||
typedef TypeList<T, NullTypeList> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeAppender<NullTypeList, TypeList<Head, Tail> >
|
||||
{
|
||||
typedef TypeList<Head, Tail> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct TypeAppender<TypeList<Head, Tail>, T>
|
||||
{
|
||||
typedef TypeList<Head, typename TypeAppender<Tail, T>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T>
|
||||
struct TypeOneEraser;
|
||||
/// TypeOneEraser erases the first occurence of the type T in Head.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float>::HeadType Type3;
|
||||
/// typedef TypeOneEraser<Type3, int>::HeadType Type2;
|
||||
/// (Type2 is a TypeList of char,float)
|
||||
///
|
||||
|
||||
|
||||
template <class T>
|
||||
struct TypeOneEraser<NullTypeList, T>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail>
|
||||
struct TypeOneEraser<TypeList<T, Tail>, T>
|
||||
{
|
||||
typedef Tail HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct TypeOneEraser<TypeList<Head, Tail>, T>
|
||||
{
|
||||
typedef TypeList <Head, typename TypeOneEraser<Tail, T>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T>
|
||||
struct TypeAllEraser;
|
||||
/// TypeAllEraser erases all the occurences of the type T in Head.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||
/// typedef TypeAllEraser<Type4, int>::HeadType Type2;
|
||||
/// (Type2 is a TypeList of char,float)
|
||||
///
|
||||
|
||||
|
||||
template <class T>
|
||||
struct TypeAllEraser<NullTypeList, T>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail>
|
||||
struct TypeAllEraser<TypeList<T, Tail>, T>
|
||||
{
|
||||
typedef typename TypeAllEraser<Tail, T>::HeadType HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct TypeAllEraser<TypeList<Head, Tail>, T>
|
||||
{
|
||||
typedef TypeList <Head, typename TypeAllEraser<Tail, T>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head>
|
||||
struct TypeDuplicateEraser;
|
||||
/// TypeDuplicateEraser erases all but the first occurence of the type T in Head.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||
/// typedef TypeDuplicateEraser<Type4, int>::HeadType Type3;
|
||||
/// (Type3 is a TypeList of char,int,float)
|
||||
///
|
||||
|
||||
|
||||
template <>
|
||||
struct TypeDuplicateEraser<NullTypeList>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeDuplicateEraser<TypeList<Head, Tail> >
|
||||
{
|
||||
private:
|
||||
typedef typename TypeDuplicateEraser<Tail>::HeadType L1;
|
||||
typedef typename TypeOneEraser<L1, Head>::HeadType L2;
|
||||
public:
|
||||
typedef TypeList<Head, L2> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T, class R>
|
||||
struct TypeOneReplacer;
|
||||
/// TypeOneReplacer replaces the first occurence
|
||||
/// of the type T in Head with type R.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||
/// typedef TypeOneReplacer<Type4, int, double>::HeadType TypeR;
|
||||
/// (TypeR is a TypeList of char,double,float,int)
|
||||
///
|
||||
|
||||
|
||||
template <class T, class R>
|
||||
struct TypeOneReplacer<NullTypeList, T, R>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail, class R>
|
||||
struct TypeOneReplacer<TypeList<T, Tail>, T, R>
|
||||
{
|
||||
typedef TypeList<R, Tail> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T, class R>
|
||||
struct TypeOneReplacer<TypeList<Head, Tail>, T, R>
|
||||
{
|
||||
typedef TypeList<Head, typename TypeOneReplacer<Tail, T, R>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T, class R>
|
||||
struct TypeAllReplacer;
|
||||
/// TypeAllReplacer replaces all the occurences
|
||||
/// of the type T in Head with type R.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||
/// typedef TypeAllReplacer<Type4, int, double>::HeadType TypeR;
|
||||
/// (TypeR is a TypeList of char,double,float,double)
|
||||
///
|
||||
|
||||
|
||||
template <class T, class R>
|
||||
struct TypeAllReplacer<NullTypeList, T, R>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail, class R>
|
||||
struct TypeAllReplacer<TypeList<T, Tail>, T, R>
|
||||
{
|
||||
typedef TypeList<R, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T, class R>
|
||||
struct TypeAllReplacer<TypeList<Head, Tail>, T, R>
|
||||
{
|
||||
typedef TypeList<Head, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// TypeList.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/TypeList.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: TypeList
|
||||
//
|
||||
// Implementation of the TypeList template.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Portions extracted and adapted from
|
||||
// The Loki Library
|
||||
// Copyright (c) 2001 by Andrei Alexandrescu
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_TypeList_INCLUDED
|
||||
#define Foundation_TypeList_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/MetaProgramming.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeList;
|
||||
|
||||
|
||||
struct NullTypeList
|
||||
{
|
||||
enum
|
||||
{
|
||||
length = 0
|
||||
};
|
||||
|
||||
bool operator == (const NullTypeList&) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator != (const NullTypeList&) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator < (const NullTypeList&) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeList
|
||||
/// Compile Time List of Types
|
||||
{
|
||||
typedef Head HeadType;
|
||||
typedef Tail TailType;
|
||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||
typedef typename TypeWrapper<TailType>::CONSTTYPE ConstTailType;
|
||||
enum
|
||||
{
|
||||
length = TailType::length+1
|
||||
};
|
||||
|
||||
TypeList():head(), tail()
|
||||
{
|
||||
}
|
||||
|
||||
TypeList(ConstHeadType& h, ConstTailType& t):head(h), tail(t)
|
||||
{
|
||||
}
|
||||
|
||||
TypeList(const TypeList& tl): head(tl.head), tail(tl.tail)
|
||||
{
|
||||
}
|
||||
|
||||
TypeList& operator = (const TypeList& tl)
|
||||
{
|
||||
if (this != &tl)
|
||||
{
|
||||
TypeList tmp(tl);
|
||||
swap(tmp);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator == (const TypeList& tl) const
|
||||
{
|
||||
return tl.head == head && tl.tail == tail;
|
||||
}
|
||||
|
||||
bool operator != (const TypeList& tl) const
|
||||
{
|
||||
return !(*this == tl);
|
||||
}
|
||||
|
||||
bool operator < (const TypeList& tl) const
|
||||
{
|
||||
if (head < tl.head)
|
||||
return true;
|
||||
else if (head == tl.head)
|
||||
return tail < tl.tail;
|
||||
return false;
|
||||
}
|
||||
|
||||
void swap(TypeList& tl)
|
||||
{
|
||||
std::swap(head, tl.head);
|
||||
std::swap(tail, tl.tail);
|
||||
}
|
||||
|
||||
HeadType head;
|
||||
TailType tail;
|
||||
};
|
||||
|
||||
|
||||
template <typename T0 = NullTypeList,
|
||||
typename T1 = NullTypeList,
|
||||
typename T2 = NullTypeList,
|
||||
typename T3 = NullTypeList,
|
||||
typename T4 = NullTypeList,
|
||||
typename T5 = NullTypeList,
|
||||
typename T6 = NullTypeList,
|
||||
typename T7 = NullTypeList,
|
||||
typename T8 = NullTypeList,
|
||||
typename T9 = NullTypeList,
|
||||
typename T10 = NullTypeList,
|
||||
typename T11 = NullTypeList,
|
||||
typename T12 = NullTypeList,
|
||||
typename T13 = NullTypeList,
|
||||
typename T14 = NullTypeList,
|
||||
typename T15 = NullTypeList,
|
||||
typename T16 = NullTypeList,
|
||||
typename T17 = NullTypeList,
|
||||
typename T18 = NullTypeList,
|
||||
typename T19 = NullTypeList>
|
||||
struct TypeListType
|
||||
/// TypeListType takes 1 - 20 typename arguments.
|
||||
/// Usage:
|
||||
///
|
||||
/// TypeListType<T0, T1, ... , Tn>::HeadType typeList;
|
||||
///
|
||||
/// typeList is a TypeList of T0, T1, ... , Tn
|
||||
{
|
||||
private:
|
||||
typedef typename TypeListType<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>::HeadType TailType;
|
||||
|
||||
public:
|
||||
typedef TypeList<T0, TailType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct TypeListType<>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <int n>
|
||||
struct Getter
|
||||
{
|
||||
template <class Ret, class Head, class Tail>
|
||||
inline static Ret& get(TypeList<Head, Tail>& val)
|
||||
{
|
||||
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
|
||||
}
|
||||
|
||||
template <class Ret, class Head, class Tail>
|
||||
inline static const Ret& get(const TypeList<Head, Tail>& val)
|
||||
{
|
||||
return Getter<n-1>::template get<Ret, typename Tail::HeadType, typename Tail::TailType>(val.tail);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct Getter<0>
|
||||
{
|
||||
template <class Ret, class Head, class Tail>
|
||||
inline static Ret& get(TypeList<Head, Tail>& val)
|
||||
{
|
||||
return val.head;
|
||||
}
|
||||
|
||||
template <class Ret, class Head, class Tail>
|
||||
inline static const Ret& get(const TypeList<Head, Tail>& val)
|
||||
{
|
||||
return val.head;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <int N, class Head>
|
||||
struct TypeGetter;
|
||||
|
||||
|
||||
template <int N, class Head, class Tail>
|
||||
struct TypeGetter<N, TypeList<Head, Tail> >
|
||||
{
|
||||
typedef typename TypeGetter<N-1, Tail>::HeadType HeadType;
|
||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeGetter<0, TypeList<Head, Tail> >
|
||||
{
|
||||
typedef typename TypeList<Head, Tail>::HeadType HeadType;
|
||||
typedef typename TypeWrapper<HeadType>::CONSTTYPE ConstHeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T>
|
||||
struct TypeLocator;
|
||||
/// TypeLocator returns the first occurrence of the type T in Head
|
||||
/// or -1 if the type is not found.
|
||||
///
|
||||
/// Usage example:
|
||||
///
|
||||
/// TypeLocator<Head, int>::HeadType TypeLoc;
|
||||
///
|
||||
/// if (2 == TypeLoc.value) ...
|
||||
///
|
||||
|
||||
|
||||
template <class T>
|
||||
struct TypeLocator<NullTypeList, T>
|
||||
{
|
||||
enum { value = -1 };
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail>
|
||||
struct TypeLocator<TypeList<T, Tail>, T>
|
||||
{
|
||||
enum { value = 0 };
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct TypeLocator<TypeList<Head, Tail>, T>
|
||||
{
|
||||
private:
|
||||
enum { tmp = TypeLocator<Tail, T>::value };
|
||||
public:
|
||||
enum { value = tmp == -1 ? -1 : 1 + tmp };
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T>
|
||||
struct TypeAppender;
|
||||
/// TypeAppender appends T (type or a TypeList) to Head.
|
||||
///
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char>::HeadType Type1;
|
||||
/// typedef TypeAppender<Type1, int>::HeadType Type2;
|
||||
/// (Type2 is a TypeList of char,int)
|
||||
///
|
||||
/// typedef TypeListType<float, double>::HeadType Type3;
|
||||
/// typedef TypeAppender<Type2, Type3>::HeadType Type4;
|
||||
/// (Type4 is a TypeList of char,int,float,double)
|
||||
///
|
||||
|
||||
|
||||
template <>
|
||||
struct TypeAppender<NullTypeList, NullTypeList>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct TypeAppender<NullTypeList, T>
|
||||
{
|
||||
typedef TypeList<T, NullTypeList> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeAppender<NullTypeList, TypeList<Head, Tail> >
|
||||
{
|
||||
typedef TypeList<Head, Tail> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct TypeAppender<TypeList<Head, Tail>, T>
|
||||
{
|
||||
typedef TypeList<Head, typename TypeAppender<Tail, T>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T>
|
||||
struct TypeOneEraser;
|
||||
/// TypeOneEraser erases the first occurence of the type T in Head.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float>::HeadType Type3;
|
||||
/// typedef TypeOneEraser<Type3, int>::HeadType Type2;
|
||||
/// (Type2 is a TypeList of char,float)
|
||||
///
|
||||
|
||||
|
||||
template <class T>
|
||||
struct TypeOneEraser<NullTypeList, T>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail>
|
||||
struct TypeOneEraser<TypeList<T, Tail>, T>
|
||||
{
|
||||
typedef Tail HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct TypeOneEraser<TypeList<Head, Tail>, T>
|
||||
{
|
||||
typedef TypeList <Head, typename TypeOneEraser<Tail, T>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T>
|
||||
struct TypeAllEraser;
|
||||
/// TypeAllEraser erases all the occurences of the type T in Head.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||
/// typedef TypeAllEraser<Type4, int>::HeadType Type2;
|
||||
/// (Type2 is a TypeList of char,float)
|
||||
///
|
||||
|
||||
|
||||
template <class T>
|
||||
struct TypeAllEraser<NullTypeList, T>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail>
|
||||
struct TypeAllEraser<TypeList<T, Tail>, T>
|
||||
{
|
||||
typedef typename TypeAllEraser<Tail, T>::HeadType HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct TypeAllEraser<TypeList<Head, Tail>, T>
|
||||
{
|
||||
typedef TypeList <Head, typename TypeAllEraser<Tail, T>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head>
|
||||
struct TypeDuplicateEraser;
|
||||
/// TypeDuplicateEraser erases all but the first occurence of the type T in Head.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||
/// typedef TypeDuplicateEraser<Type4, int>::HeadType Type3;
|
||||
/// (Type3 is a TypeList of char,int,float)
|
||||
///
|
||||
|
||||
|
||||
template <>
|
||||
struct TypeDuplicateEraser<NullTypeList>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeDuplicateEraser<TypeList<Head, Tail> >
|
||||
{
|
||||
private:
|
||||
typedef typename TypeDuplicateEraser<Tail>::HeadType L1;
|
||||
typedef typename TypeOneEraser<L1, Head>::HeadType L2;
|
||||
public:
|
||||
typedef TypeList<Head, L2> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T, class R>
|
||||
struct TypeOneReplacer;
|
||||
/// TypeOneReplacer replaces the first occurence
|
||||
/// of the type T in Head with type R.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||
/// typedef TypeOneReplacer<Type4, int, double>::HeadType TypeR;
|
||||
/// (TypeR is a TypeList of char,double,float,int)
|
||||
///
|
||||
|
||||
|
||||
template <class T, class R>
|
||||
struct TypeOneReplacer<NullTypeList, T, R>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail, class R>
|
||||
struct TypeOneReplacer<TypeList<T, Tail>, T, R>
|
||||
{
|
||||
typedef TypeList<R, Tail> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T, class R>
|
||||
struct TypeOneReplacer<TypeList<Head, Tail>, T, R>
|
||||
{
|
||||
typedef TypeList<Head, typename TypeOneReplacer<Tail, T, R>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class T, class R>
|
||||
struct TypeAllReplacer;
|
||||
/// TypeAllReplacer replaces all the occurences
|
||||
/// of the type T in Head with type R.
|
||||
/// Usage:
|
||||
///
|
||||
/// typedef TypeListType<char, int, float, int>::HeadType Type4;
|
||||
/// typedef TypeAllReplacer<Type4, int, double>::HeadType TypeR;
|
||||
/// (TypeR is a TypeList of char,double,float,double)
|
||||
///
|
||||
|
||||
|
||||
template <class T, class R>
|
||||
struct TypeAllReplacer<NullTypeList, T, R>
|
||||
{
|
||||
typedef NullTypeList HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class Tail, class R>
|
||||
struct TypeAllReplacer<TypeList<T, Tail>, T, R>
|
||||
{
|
||||
typedef TypeList<R, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
template <class Head, class Tail, class T, class R>
|
||||
struct TypeAllReplacer<TypeList<Head, Tail>, T, R>
|
||||
{
|
||||
typedef TypeList<Head, typename TypeAllReplacer<Tail, T, R>::HeadType> HeadType;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,80 +1,80 @@
|
|||
//
|
||||
// UTF8String.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UTF8String.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: UTF8String
|
||||
//
|
||||
// Definition of the UTF8 string functions.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UTF8String_INCLUDED
|
||||
#define Foundation_UTF8String_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
struct Foundation_API UTF8
|
||||
/// This class provides static methods that are UTF-8 capable variants
|
||||
/// of the same functions in Poco/String.h.
|
||||
///
|
||||
/// The various variants of icompare() provide case insensitive comparison
|
||||
/// for UTF-8 encoded strings.
|
||||
///
|
||||
/// toUpper(), toUpperInPlace(), toLower() and toLowerInPlace() provide
|
||||
/// Unicode-based character case transformation for UTF-8 encoded strings.
|
||||
{
|
||||
static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2);
|
||||
static int icompare(const std::string& str1, const std::string& str2);
|
||||
static int icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2);
|
||||
static int icompare(const std::string& str1, std::string::size_type n, const std::string& str2);
|
||||
static int icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2);
|
||||
static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2);
|
||||
static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2);
|
||||
static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr);
|
||||
static int icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr);
|
||||
static int icompare(const std::string& str, const std::string::value_type* ptr);
|
||||
|
||||
static std::string toUpper(const std::string& str);
|
||||
static std::string& toUpperInPlace(std::string& str);
|
||||
static std::string toLower(const std::string& str);
|
||||
static std::string& toLowerInPlace(std::string& str);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_UTF8String_INCLUDED
|
||||
//
|
||||
// UTF8String.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UTF8String.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: UTF8String
|
||||
//
|
||||
// Definition of the UTF8 string functions.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UTF8String_INCLUDED
|
||||
#define Foundation_UTF8String_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
struct Foundation_API UTF8
|
||||
/// This class provides static methods that are UTF-8 capable variants
|
||||
/// of the same functions in Poco/String.h.
|
||||
///
|
||||
/// The various variants of icompare() provide case insensitive comparison
|
||||
/// for UTF-8 encoded strings.
|
||||
///
|
||||
/// toUpper(), toUpperInPlace(), toLower() and toLowerInPlace() provide
|
||||
/// Unicode-based character case transformation for UTF-8 encoded strings.
|
||||
{
|
||||
static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2);
|
||||
static int icompare(const std::string& str1, const std::string& str2);
|
||||
static int icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2);
|
||||
static int icompare(const std::string& str1, std::string::size_type n, const std::string& str2);
|
||||
static int icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2);
|
||||
static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2);
|
||||
static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2);
|
||||
static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr);
|
||||
static int icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr);
|
||||
static int icompare(const std::string& str, const std::string::value_type* ptr);
|
||||
|
||||
static std::string toUpper(const std::string& str);
|
||||
static std::string& toUpperInPlace(std::string& str);
|
||||
static std::string toLower(const std::string& str);
|
||||
static std::string& toLowerInPlace(std::string& str);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_UTF8String_INCLUDED
|
||||
|
|
|
@ -1,110 +1,110 @@
|
|||
//
|
||||
// UnWindows.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UnWindows.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: UnWindows
|
||||
//
|
||||
// A wrapper around the "Poco/UnWindows.h" header file that #undef's some
|
||||
// of the macros for function names defined by "Poco/UnWindows.h" that
|
||||
// are a frequent source of conflicts (e.g., GetUserName).
|
||||
//
|
||||
// Remember, that most of the WIN32 API functions come in two variants,
|
||||
// an Unicode variant (e.g., GetUserNameA) and an ASCII variant (GetUserNameW).
|
||||
// There is also a macro (GetUserName) that's either defined to be the Unicode
|
||||
// name or the ASCII name, depending on whether the UNICODE macro is #define'd
|
||||
// or not. POCO always calls the Unicode or ASCII functions directly (depending
|
||||
// on whether POCO_WIN32_UTF8 is #define'd or not), so the macros are not ignored.
|
||||
//
|
||||
// These macro definitions are a frequent case of problems and naming conflicts,
|
||||
// especially for C++ programmers. Say, you define a class with a member function named
|
||||
// GetUserName. Depending on whether "Poco/UnWindows.h" has been included by a particular
|
||||
// translation unit or not, this might be changed to GetUserNameA/GetUserNameW, or not.
|
||||
// While, due to naming conventions used, this is less of a problem in POCO, some
|
||||
// of the users of POCO might use a different naming convention where this can become
|
||||
// a problem.
|
||||
//
|
||||
// To disable the #undef's, compile POCO with the POCO_NO_UNWINDOWS macro #define'd.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#if !defined(POCO_NO_UNWINDOWS)
|
||||
// A list of annoying macros to #undef.
|
||||
// Feel free to extend as required.
|
||||
#undef GetBinaryType
|
||||
#undef GetShortPathName
|
||||
#undef GetLongPathName
|
||||
#undef GetEnvironmentStrings
|
||||
#undef SetEnvironmentStrings
|
||||
#undef FreeEnvironmentStrings
|
||||
#undef FormatMessage
|
||||
#undef EncryptFile
|
||||
#undef DecryptFile
|
||||
#undef CreateMutex
|
||||
#undef OpenMutex
|
||||
#undef CreateEvent
|
||||
#undef OpenEvent
|
||||
#undef CreateSemaphore
|
||||
#undef OpenSemaphore
|
||||
#undef LoadLibrary
|
||||
#undef GetModuleFileName
|
||||
#undef CreateProcess
|
||||
#undef GetCommandLine
|
||||
#undef GetEnvironmentVariable
|
||||
#undef SetEnvironmentVariable
|
||||
#undef ExpandEnvironmentStrings
|
||||
#undef OutputDebugString
|
||||
#undef FindResource
|
||||
#undef UpdateResource
|
||||
#undef FindAtom
|
||||
#undef AddAtom
|
||||
#undef GetSystemDirector
|
||||
#undef GetTempPath
|
||||
#undef GetTempFileName
|
||||
#undef SetCurrentDirectory
|
||||
#undef GetCurrentDirectory
|
||||
#undef CreateDirectory
|
||||
#undef RemoveDirectory
|
||||
#undef CreateFile
|
||||
#undef DeleteFile
|
||||
#undef SearchPath
|
||||
#undef CopyFile
|
||||
#undef MoveFile
|
||||
#undef ReplaceFile
|
||||
#undef GetComputerName
|
||||
#undef SetComputerName
|
||||
#undef GetUserName
|
||||
#undef LogonUser
|
||||
#undef GetVersion
|
||||
#undef GetObject
|
||||
#endif // POCO_NO_UNWINDOWS
|
||||
//
|
||||
// UnWindows.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UnWindows.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: UnWindows
|
||||
//
|
||||
// A wrapper around the "Poco/UnWindows.h" header file that #undef's some
|
||||
// of the macros for function names defined by "Poco/UnWindows.h" that
|
||||
// are a frequent source of conflicts (e.g., GetUserName).
|
||||
//
|
||||
// Remember, that most of the WIN32 API functions come in two variants,
|
||||
// an Unicode variant (e.g., GetUserNameA) and an ASCII variant (GetUserNameW).
|
||||
// There is also a macro (GetUserName) that's either defined to be the Unicode
|
||||
// name or the ASCII name, depending on whether the UNICODE macro is #define'd
|
||||
// or not. POCO always calls the Unicode or ASCII functions directly (depending
|
||||
// on whether POCO_WIN32_UTF8 is #define'd or not), so the macros are not ignored.
|
||||
//
|
||||
// These macro definitions are a frequent case of problems and naming conflicts,
|
||||
// especially for C++ programmers. Say, you define a class with a member function named
|
||||
// GetUserName. Depending on whether "Poco/UnWindows.h" has been included by a particular
|
||||
// translation unit or not, this might be changed to GetUserNameA/GetUserNameW, or not.
|
||||
// While, due to naming conventions used, this is less of a problem in POCO, some
|
||||
// of the users of POCO might use a different naming convention where this can become
|
||||
// a problem.
|
||||
//
|
||||
// To disable the #undef's, compile POCO with the POCO_NO_UNWINDOWS macro #define'd.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#if !defined(POCO_NO_UNWINDOWS)
|
||||
// A list of annoying macros to #undef.
|
||||
// Feel free to extend as required.
|
||||
#undef GetBinaryType
|
||||
#undef GetShortPathName
|
||||
#undef GetLongPathName
|
||||
#undef GetEnvironmentStrings
|
||||
#undef SetEnvironmentStrings
|
||||
#undef FreeEnvironmentStrings
|
||||
#undef FormatMessage
|
||||
#undef EncryptFile
|
||||
#undef DecryptFile
|
||||
#undef CreateMutex
|
||||
#undef OpenMutex
|
||||
#undef CreateEvent
|
||||
#undef OpenEvent
|
||||
#undef CreateSemaphore
|
||||
#undef OpenSemaphore
|
||||
#undef LoadLibrary
|
||||
#undef GetModuleFileName
|
||||
#undef CreateProcess
|
||||
#undef GetCommandLine
|
||||
#undef GetEnvironmentVariable
|
||||
#undef SetEnvironmentVariable
|
||||
#undef ExpandEnvironmentStrings
|
||||
#undef OutputDebugString
|
||||
#undef FindResource
|
||||
#undef UpdateResource
|
||||
#undef FindAtom
|
||||
#undef AddAtom
|
||||
#undef GetSystemDirector
|
||||
#undef GetTempPath
|
||||
#undef GetTempFileName
|
||||
#undef SetCurrentDirectory
|
||||
#undef GetCurrentDirectory
|
||||
#undef CreateDirectory
|
||||
#undef RemoveDirectory
|
||||
#undef CreateFile
|
||||
#undef DeleteFile
|
||||
#undef SearchPath
|
||||
#undef CopyFile
|
||||
#undef MoveFile
|
||||
#undef ReplaceFile
|
||||
#undef GetComputerName
|
||||
#undef SetComputerName
|
||||
#undef GetUserName
|
||||
#undef LogonUser
|
||||
#undef GetVersion
|
||||
#undef GetObject
|
||||
#endif // POCO_NO_UNWINDOWS
|
||||
|
|
|
@ -1,216 +1,216 @@
|
|||
//
|
||||
// Unicode.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Unicode.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: Unicode
|
||||
//
|
||||
// Definition of the Unicode class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Unicode_INCLUDED
|
||||
#define Foundation_Unicode_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API Unicode
|
||||
/// This class contains enumerations and static
|
||||
/// utility functions for dealing with Unicode characters
|
||||
/// and their properties.
|
||||
///
|
||||
/// For more information on Unicode, see <http://www.unicode.org>.
|
||||
///
|
||||
/// The implementation is based on the Unicode support
|
||||
/// functions in PCRE.
|
||||
{
|
||||
public:
|
||||
// Implementation note: the following definitions must be kept
|
||||
// in sync with those from ucp.h (PCRE).
|
||||
enum CharacterCategory
|
||||
/// Unicode 5.0 character categories.
|
||||
{
|
||||
UCP_OTHER,
|
||||
UCP_LETTER,
|
||||
UCP_MARK,
|
||||
UCP_NUMBER,
|
||||
UCP_PUNCTUATION,
|
||||
UCP_SYMBOL,
|
||||
UCP_SEPARATOR
|
||||
};
|
||||
|
||||
enum CharacterType
|
||||
/// Unicode 5.0 character types.
|
||||
{
|
||||
UCP_CONTROL,
|
||||
UCP_FORMAT,
|
||||
UCP_UNASSIGNED,
|
||||
UCP_PRIVATE_USE,
|
||||
UCP_SURROGATE,
|
||||
UCP_LOWER_CASE_LETTER,
|
||||
UCP_MODIFIER_LETTER,
|
||||
UCP_OTHER_LETTER,
|
||||
UCP_TITLE_CASE_LETTER,
|
||||
UCP_UPPER_CASE_LETTER,
|
||||
UCP_SPACING_MARK,
|
||||
UCP_ENCLOSING_MARK,
|
||||
UCP_NON_SPACING_MARK,
|
||||
UCP_DECIMAL_NUMBER,
|
||||
UCP_LETTER_NUMBER,
|
||||
UCP_OTHER_NUMBER,
|
||||
UCP_CONNECTOR_PUNCTUATION,
|
||||
UCP_DASH_PUNCTUATION,
|
||||
UCP_CLOSE_PUNCTUATION,
|
||||
UCP_FINAL_PUNCTUATION,
|
||||
UCP_INITIAL_PUNCTUATION,
|
||||
UCP_OTHER_PUNCTUATION,
|
||||
UCP_OPEN_PUNCTUATION,
|
||||
UCP_CURRENCY_SYMBOL,
|
||||
UCP_MODIFIER_SYMBOL,
|
||||
UCP_MATHEMATICAL_SYMBOL,
|
||||
UCP_OTHER_SYMBOL,
|
||||
UCP_LINE_SEPARATOR,
|
||||
UCP_PARAGRAPH_SEPARATOR,
|
||||
UCP_SPACE_SEPARATOR
|
||||
};
|
||||
|
||||
enum Script
|
||||
/// Unicode 5.0 scripts.
|
||||
{
|
||||
UCP_ARABIC,
|
||||
UCP_ARMENIAN,
|
||||
UCP_BENGALI,
|
||||
UCP_BOPOMOFO,
|
||||
UCP_BRAILLE,
|
||||
UCP_BUGINESE,
|
||||
UCP_BUHID,
|
||||
UCP_CANADIAN_ABORIGINAL,
|
||||
UCP_CHEROKEE,
|
||||
UCP_COMMON,
|
||||
UCP_COPTIC,
|
||||
UCP_CYPRIOT,
|
||||
UCP_CYRILLIC,
|
||||
UCP_DESERET,
|
||||
UCP_DEVANAGARI,
|
||||
UCP_ETHIOPIC,
|
||||
UCP_GEORGIAN,
|
||||
UCP_GLAGOLITIC,
|
||||
UCP_GOTHIC,
|
||||
UCP_GREEK,
|
||||
UCP_GUJARATI,
|
||||
UCP_GURMUKHI,
|
||||
UCP_HAN,
|
||||
UCP_HANGUL,
|
||||
UCP_HANUNOO,
|
||||
UCP_HEBREW,
|
||||
UCP_HIRAGANA,
|
||||
UCP_INHERITED,
|
||||
UCP_KANNADA,
|
||||
UCP_KATAKANA,
|
||||
UCP_KHAROSHTHI,
|
||||
UCP_KHMER,
|
||||
UCP_LAO,
|
||||
UCP_LATIN,
|
||||
UCP_LIMBU,
|
||||
UCP_LINEAR_B,
|
||||
UCP_MALAYALAM,
|
||||
UCP_MONGOLIAN,
|
||||
UCP_MYANMAR,
|
||||
UCP_NEW_TAI_LUE,
|
||||
UCP_OGHAM,
|
||||
UCP_OLD_ITALIC,
|
||||
UCP_OLD_PERSIAN,
|
||||
UCP_ORIYA,
|
||||
UCP_OSMANYA,
|
||||
UCP_RUNIC,
|
||||
UCP_SHAVIAN,
|
||||
UCP_SINHALA,
|
||||
UCP_SYLOTI_NAGRI,
|
||||
UCP_SYRIAC,
|
||||
UCP_TAGALOG,
|
||||
UCP_TAGBANWA,
|
||||
UCP_TAI_LE,
|
||||
UCP_TAMIL,
|
||||
UCP_TELUGU,
|
||||
UCP_THAANA,
|
||||
UCP_THAI,
|
||||
UCP_TIBETAN,
|
||||
UCP_TIFINAGH,
|
||||
UCP_UGARITIC,
|
||||
UCP_YI,
|
||||
UCP_BALINESE,
|
||||
UCP_CUNEIFORM,
|
||||
UCP_NKO,
|
||||
UCP_PHAGS_PA,
|
||||
UCP_PHOENICIAN
|
||||
};
|
||||
|
||||
struct CharacterProperties
|
||||
/// This structure holds the character properties
|
||||
/// of an Unicode character.
|
||||
{
|
||||
CharacterCategory category;
|
||||
CharacterType type;
|
||||
Script script;
|
||||
};
|
||||
|
||||
static void properties(int ch, CharacterProperties& props);
|
||||
/// Return the Unicode character properties for the
|
||||
/// character with the given Unicode value.
|
||||
|
||||
static bool isLower(int ch);
|
||||
/// Returns true iff the given character is a lowercase
|
||||
/// character.
|
||||
|
||||
static bool isUpper(int ch);
|
||||
/// Returns true iff the given character is an uppercase
|
||||
/// character.
|
||||
|
||||
static int toLower(int ch);
|
||||
/// If the given character is an uppercase character,
|
||||
/// return its lowercase counterpart, otherwise return
|
||||
/// the character.
|
||||
|
||||
static int toUpper(int ch);
|
||||
/// If the given character is a lowercase character,
|
||||
/// return its uppercase counterpart, otherwise return
|
||||
/// the character.
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Unicode_INCLUDED
|
||||
//
|
||||
// Unicode.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Unicode.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: Unicode
|
||||
//
|
||||
// Definition of the Unicode class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Unicode_INCLUDED
|
||||
#define Foundation_Unicode_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API Unicode
|
||||
/// This class contains enumerations and static
|
||||
/// utility functions for dealing with Unicode characters
|
||||
/// and their properties.
|
||||
///
|
||||
/// For more information on Unicode, see <http://www.unicode.org>.
|
||||
///
|
||||
/// The implementation is based on the Unicode support
|
||||
/// functions in PCRE.
|
||||
{
|
||||
public:
|
||||
// Implementation note: the following definitions must be kept
|
||||
// in sync with those from ucp.h (PCRE).
|
||||
enum CharacterCategory
|
||||
/// Unicode 5.0 character categories.
|
||||
{
|
||||
UCP_OTHER,
|
||||
UCP_LETTER,
|
||||
UCP_MARK,
|
||||
UCP_NUMBER,
|
||||
UCP_PUNCTUATION,
|
||||
UCP_SYMBOL,
|
||||
UCP_SEPARATOR
|
||||
};
|
||||
|
||||
enum CharacterType
|
||||
/// Unicode 5.0 character types.
|
||||
{
|
||||
UCP_CONTROL,
|
||||
UCP_FORMAT,
|
||||
UCP_UNASSIGNED,
|
||||
UCP_PRIVATE_USE,
|
||||
UCP_SURROGATE,
|
||||
UCP_LOWER_CASE_LETTER,
|
||||
UCP_MODIFIER_LETTER,
|
||||
UCP_OTHER_LETTER,
|
||||
UCP_TITLE_CASE_LETTER,
|
||||
UCP_UPPER_CASE_LETTER,
|
||||
UCP_SPACING_MARK,
|
||||
UCP_ENCLOSING_MARK,
|
||||
UCP_NON_SPACING_MARK,
|
||||
UCP_DECIMAL_NUMBER,
|
||||
UCP_LETTER_NUMBER,
|
||||
UCP_OTHER_NUMBER,
|
||||
UCP_CONNECTOR_PUNCTUATION,
|
||||
UCP_DASH_PUNCTUATION,
|
||||
UCP_CLOSE_PUNCTUATION,
|
||||
UCP_FINAL_PUNCTUATION,
|
||||
UCP_INITIAL_PUNCTUATION,
|
||||
UCP_OTHER_PUNCTUATION,
|
||||
UCP_OPEN_PUNCTUATION,
|
||||
UCP_CURRENCY_SYMBOL,
|
||||
UCP_MODIFIER_SYMBOL,
|
||||
UCP_MATHEMATICAL_SYMBOL,
|
||||
UCP_OTHER_SYMBOL,
|
||||
UCP_LINE_SEPARATOR,
|
||||
UCP_PARAGRAPH_SEPARATOR,
|
||||
UCP_SPACE_SEPARATOR
|
||||
};
|
||||
|
||||
enum Script
|
||||
/// Unicode 5.0 scripts.
|
||||
{
|
||||
UCP_ARABIC,
|
||||
UCP_ARMENIAN,
|
||||
UCP_BENGALI,
|
||||
UCP_BOPOMOFO,
|
||||
UCP_BRAILLE,
|
||||
UCP_BUGINESE,
|
||||
UCP_BUHID,
|
||||
UCP_CANADIAN_ABORIGINAL,
|
||||
UCP_CHEROKEE,
|
||||
UCP_COMMON,
|
||||
UCP_COPTIC,
|
||||
UCP_CYPRIOT,
|
||||
UCP_CYRILLIC,
|
||||
UCP_DESERET,
|
||||
UCP_DEVANAGARI,
|
||||
UCP_ETHIOPIC,
|
||||
UCP_GEORGIAN,
|
||||
UCP_GLAGOLITIC,
|
||||
UCP_GOTHIC,
|
||||
UCP_GREEK,
|
||||
UCP_GUJARATI,
|
||||
UCP_GURMUKHI,
|
||||
UCP_HAN,
|
||||
UCP_HANGUL,
|
||||
UCP_HANUNOO,
|
||||
UCP_HEBREW,
|
||||
UCP_HIRAGANA,
|
||||
UCP_INHERITED,
|
||||
UCP_KANNADA,
|
||||
UCP_KATAKANA,
|
||||
UCP_KHAROSHTHI,
|
||||
UCP_KHMER,
|
||||
UCP_LAO,
|
||||
UCP_LATIN,
|
||||
UCP_LIMBU,
|
||||
UCP_LINEAR_B,
|
||||
UCP_MALAYALAM,
|
||||
UCP_MONGOLIAN,
|
||||
UCP_MYANMAR,
|
||||
UCP_NEW_TAI_LUE,
|
||||
UCP_OGHAM,
|
||||
UCP_OLD_ITALIC,
|
||||
UCP_OLD_PERSIAN,
|
||||
UCP_ORIYA,
|
||||
UCP_OSMANYA,
|
||||
UCP_RUNIC,
|
||||
UCP_SHAVIAN,
|
||||
UCP_SINHALA,
|
||||
UCP_SYLOTI_NAGRI,
|
||||
UCP_SYRIAC,
|
||||
UCP_TAGALOG,
|
||||
UCP_TAGBANWA,
|
||||
UCP_TAI_LE,
|
||||
UCP_TAMIL,
|
||||
UCP_TELUGU,
|
||||
UCP_THAANA,
|
||||
UCP_THAI,
|
||||
UCP_TIBETAN,
|
||||
UCP_TIFINAGH,
|
||||
UCP_UGARITIC,
|
||||
UCP_YI,
|
||||
UCP_BALINESE,
|
||||
UCP_CUNEIFORM,
|
||||
UCP_NKO,
|
||||
UCP_PHAGS_PA,
|
||||
UCP_PHOENICIAN
|
||||
};
|
||||
|
||||
struct CharacterProperties
|
||||
/// This structure holds the character properties
|
||||
/// of an Unicode character.
|
||||
{
|
||||
CharacterCategory category;
|
||||
CharacterType type;
|
||||
Script script;
|
||||
};
|
||||
|
||||
static void properties(int ch, CharacterProperties& props);
|
||||
/// Return the Unicode character properties for the
|
||||
/// character with the given Unicode value.
|
||||
|
||||
static bool isLower(int ch);
|
||||
/// Returns true iff the given character is a lowercase
|
||||
/// character.
|
||||
|
||||
static bool isUpper(int ch);
|
||||
/// Returns true iff the given character is an uppercase
|
||||
/// character.
|
||||
|
||||
static int toLower(int ch);
|
||||
/// If the given character is an uppercase character,
|
||||
/// return its lowercase counterpart, otherwise return
|
||||
/// the character.
|
||||
|
||||
static int toUpper(int ch);
|
||||
/// If the given character is a lowercase character,
|
||||
/// return its uppercase counterpart, otherwise return
|
||||
/// the character.
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Unicode_INCLUDED
|
||||
|
|
|
@ -1,89 +1,89 @@
|
|||
//
|
||||
// UniqueAccessExpireCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueAccessExpireCache
|
||||
//
|
||||
// Definition of the UniqueAccessExpireCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueAccessExpireCache_INCLUDED
|
||||
#define Foundation_UniqueAccessExpireCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/UniqueAccessExpireStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TKey, class TValue>
|
||||
class UniqueAccessExpireCache: public AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >
|
||||
/// An UniqueAccessExpireCache caches entries for a given time span. In contrast
|
||||
/// to ExpireCache which only allows to set a per cache expiration value, it allows to define
|
||||
/// expiration per CacheEntry.
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timespan& getTimeout() const;
|
||||
///
|
||||
/// which returns the relative timespan for how long the entry should be valid without being accessed!
|
||||
/// The absolute expire timepoint is calculated as now() + getTimeout().
|
||||
/// Accessing an object will update this absolute expire timepoint.
|
||||
/// You can use the Poco::AccessExpirationDecorator to add the getExpiration
|
||||
/// method to values that do not have a getExpiration function.
|
||||
///
|
||||
/// Be careful when using an UniqueAccessExpireCache. A cache is often used
|
||||
/// like cache.has(x) followed by cache.get x). Note that it could happen
|
||||
/// that the "has" call works, then the current execution thread gets descheduled, time passes,
|
||||
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||
/// when "get" is invoked.
|
||||
{
|
||||
public:
|
||||
UniqueAccessExpireCache():
|
||||
AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >(UniqueAccessExpireStrategy<TKey, TValue>())
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueAccessExpireCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache);
|
||||
UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
#endif
|
||||
//
|
||||
// UniqueAccessExpireCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueAccessExpireCache
|
||||
//
|
||||
// Definition of the UniqueAccessExpireCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueAccessExpireCache_INCLUDED
|
||||
#define Foundation_UniqueAccessExpireCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/UniqueAccessExpireStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TKey, class TValue>
|
||||
class UniqueAccessExpireCache: public AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >
|
||||
/// An UniqueAccessExpireCache caches entries for a given time span. In contrast
|
||||
/// to ExpireCache which only allows to set a per cache expiration value, it allows to define
|
||||
/// expiration per CacheEntry.
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timespan& getTimeout() const;
|
||||
///
|
||||
/// which returns the relative timespan for how long the entry should be valid without being accessed!
|
||||
/// The absolute expire timepoint is calculated as now() + getTimeout().
|
||||
/// Accessing an object will update this absolute expire timepoint.
|
||||
/// You can use the Poco::AccessExpirationDecorator to add the getExpiration
|
||||
/// method to values that do not have a getExpiration function.
|
||||
///
|
||||
/// Be careful when using an UniqueAccessExpireCache. A cache is often used
|
||||
/// like cache.has(x) followed by cache.get x). Note that it could happen
|
||||
/// that the "has" call works, then the current execution thread gets descheduled, time passes,
|
||||
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||
/// when "get" is invoked.
|
||||
{
|
||||
public:
|
||||
UniqueAccessExpireCache():
|
||||
AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue> >(UniqueAccessExpireStrategy<TKey, TValue>())
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueAccessExpireCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache);
|
||||
UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,91 +1,91 @@
|
|||
//
|
||||
// UniqueAccessExpireLRUCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireLRUCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueAccessExpireLRUCache
|
||||
//
|
||||
// Definition of the UniqueAccessExpireLRUCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueAccessExpireLRUCache_INCLUDED
|
||||
#define Foundation_UniqueAccessExpireLRUCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/StrategyCollection.h"
|
||||
#include "Poco/UniqueAccessExpireStrategy.h"
|
||||
#include "Poco/LRUStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class UniqueAccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||
/// A UniqueAccessExpireLRUCache combines LRU caching and time based per entry expire caching.
|
||||
/// One can define for each cache entry a seperate timepoint
|
||||
/// but also limit the size of the cache (per default: 1024).
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timespan& getTimeout() const;
|
||||
///
|
||||
/// which returns the relative timespan for how long the entry should be valid without being accessed!
|
||||
/// The absolute expire timepoint is calculated as now() + getTimeout().
|
||||
/// Accessing an object will update this absolute expire timepoint.
|
||||
/// You can use the Poco::AccessExpirationDecorator to add the getExpiration
|
||||
/// method to values that do not have a getExpiration function.
|
||||
{
|
||||
public:
|
||||
UniqueAccessExpireLRUCache(long cacheSize = 1024):
|
||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||
{
|
||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||
this->_strategy.pushBack(new UniqueAccessExpireStrategy<TKey, TValue>());
|
||||
}
|
||||
|
||||
~UniqueAccessExpireLRUCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache);
|
||||
UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// UniqueAccessExpireLRUCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireLRUCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueAccessExpireLRUCache
|
||||
//
|
||||
// Definition of the UniqueAccessExpireLRUCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueAccessExpireLRUCache_INCLUDED
|
||||
#define Foundation_UniqueAccessExpireLRUCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/StrategyCollection.h"
|
||||
#include "Poco/UniqueAccessExpireStrategy.h"
|
||||
#include "Poco/LRUStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class UniqueAccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||
/// A UniqueAccessExpireLRUCache combines LRU caching and time based per entry expire caching.
|
||||
/// One can define for each cache entry a seperate timepoint
|
||||
/// but also limit the size of the cache (per default: 1024).
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timespan& getTimeout() const;
|
||||
///
|
||||
/// which returns the relative timespan for how long the entry should be valid without being accessed!
|
||||
/// The absolute expire timepoint is calculated as now() + getTimeout().
|
||||
/// Accessing an object will update this absolute expire timepoint.
|
||||
/// You can use the Poco::AccessExpirationDecorator to add the getExpiration
|
||||
/// method to values that do not have a getExpiration function.
|
||||
{
|
||||
public:
|
||||
UniqueAccessExpireLRUCache(long cacheSize = 1024):
|
||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||
{
|
||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||
this->_strategy.pushBack(new UniqueAccessExpireStrategy<TKey, TValue>());
|
||||
}
|
||||
|
||||
~UniqueAccessExpireLRUCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache);
|
||||
UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,178 +1,178 @@
|
|||
//
|
||||
// UniqueAccessExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireStrategy.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueAccessExpireStrategy
|
||||
//
|
||||
// Definition of the UniqueAccessExpireStrategy class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueAccessExpireStrategy_INCLUDED
|
||||
#define Foundation_UniqueAccessExpireStrategy_INCLUDED
|
||||
|
||||
#include "Poco/KeyValueArgs.h"
|
||||
#include "Poco/ValidArgs.h"
|
||||
#include "Poco/AbstractStrategy.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/EventArgs.h"
|
||||
#include "Poco/UniqueExpireStrategy.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class UniqueAccessExpireStrategy: public AbstractStrategy<TKey, TValue>
|
||||
/// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast
|
||||
/// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define
|
||||
/// expiration per CacheEntry.
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timestamp& getTimeout() const;
|
||||
///
|
||||
/// which returns the timespan for how long an object will be valid without being accessed.
|
||||
{
|
||||
public:
|
||||
typedef std::pair<TKey, Timespan> KeyExpire;
|
||||
typedef std::multimap<Timestamp, KeyExpire> TimeIndex;
|
||||
typedef typename TimeIndex::iterator IndexIterator;
|
||||
typedef typename TimeIndex::const_iterator ConstIndexIterator;
|
||||
typedef std::map<TKey, IndexIterator> Keys;
|
||||
typedef typename Keys::iterator Iterator;
|
||||
|
||||
public:
|
||||
UniqueAccessExpireStrategy()
|
||||
/// Create an unique expire strategy.
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueAccessExpireStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& args)
|
||||
{
|
||||
// the expire value defines how many millisecs in the future the
|
||||
// value will expire, even insert negative values!
|
||||
Timestamp expire;
|
||||
expire += args.value().getTimeout().totalMicroseconds();
|
||||
|
||||
IndexIterator it = _keyIndex.insert(std::make_pair(expire, std::make_pair(args.key(), args.value().getTimeout())));
|
||||
std::pair<Iterator, bool> stat = _keys.insert(std::make_pair(args.key(), it));
|
||||
if (!stat.second)
|
||||
{
|
||||
_keyIndex.erase(stat.first->second);
|
||||
stat.first->second = it;
|
||||
}
|
||||
}
|
||||
|
||||
void onRemove(const void*, const TKey& key)
|
||||
{
|
||||
Iterator it = _keys.find(key);
|
||||
if (it != _keys.end())
|
||||
{
|
||||
_keyIndex.erase(it->second);
|
||||
_keys.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void onGet(const void*, const TKey& key)
|
||||
{
|
||||
// get updates the expiration time stamp
|
||||
Iterator it = _keys.find(key);
|
||||
if (it != _keys.end())
|
||||
{
|
||||
KeyExpire ke = it->second->second;
|
||||
// gen new absolute expire value
|
||||
Timestamp expire;
|
||||
expire += ke.second.totalMicroseconds();
|
||||
// delete old index
|
||||
_keyIndex.erase(it->second);
|
||||
IndexIterator itt = _keyIndex.insert(std::make_pair(expire, ke));
|
||||
// update iterator
|
||||
it->second = itt;
|
||||
}
|
||||
}
|
||||
|
||||
void onClear(const void*, const EventArgs& args)
|
||||
{
|
||||
_keys.clear();
|
||||
_keyIndex.clear();
|
||||
}
|
||||
|
||||
void onIsValid(const void*, ValidArgs<TKey>& args)
|
||||
{
|
||||
Iterator it = _keys.find(args.key());
|
||||
if (it != _keys.end())
|
||||
{
|
||||
Timestamp now;
|
||||
if (it->second->first <= now)
|
||||
{
|
||||
args.invalidate();
|
||||
}
|
||||
}
|
||||
else //not found: probably removed by onReplace
|
||||
args.invalidate();
|
||||
}
|
||||
|
||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||
{
|
||||
// Note: replace only informs the cache which elements
|
||||
// it would like to remove!
|
||||
// it does not remove them on its own!
|
||||
IndexIterator it = _keyIndex.begin();
|
||||
Timestamp now;
|
||||
while (it != _keyIndex.end() && it->first < now)
|
||||
{
|
||||
elemsToRemove.insert(it->second.first);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map
|
||||
TimeIndex _keyIndex; /// Maps time to key value
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
#endif
|
||||
//
|
||||
// UniqueAccessExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireStrategy.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueAccessExpireStrategy
|
||||
//
|
||||
// Definition of the UniqueAccessExpireStrategy class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueAccessExpireStrategy_INCLUDED
|
||||
#define Foundation_UniqueAccessExpireStrategy_INCLUDED
|
||||
|
||||
#include "Poco/KeyValueArgs.h"
|
||||
#include "Poco/ValidArgs.h"
|
||||
#include "Poco/AbstractStrategy.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/EventArgs.h"
|
||||
#include "Poco/UniqueExpireStrategy.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class UniqueAccessExpireStrategy: public AbstractStrategy<TKey, TValue>
|
||||
/// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast
|
||||
/// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define
|
||||
/// expiration per CacheEntry.
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timestamp& getTimeout() const;
|
||||
///
|
||||
/// which returns the timespan for how long an object will be valid without being accessed.
|
||||
{
|
||||
public:
|
||||
typedef std::pair<TKey, Timespan> KeyExpire;
|
||||
typedef std::multimap<Timestamp, KeyExpire> TimeIndex;
|
||||
typedef typename TimeIndex::iterator IndexIterator;
|
||||
typedef typename TimeIndex::const_iterator ConstIndexIterator;
|
||||
typedef std::map<TKey, IndexIterator> Keys;
|
||||
typedef typename Keys::iterator Iterator;
|
||||
|
||||
public:
|
||||
UniqueAccessExpireStrategy()
|
||||
/// Create an unique expire strategy.
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueAccessExpireStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& args)
|
||||
{
|
||||
// the expire value defines how many millisecs in the future the
|
||||
// value will expire, even insert negative values!
|
||||
Timestamp expire;
|
||||
expire += args.value().getTimeout().totalMicroseconds();
|
||||
|
||||
IndexIterator it = _keyIndex.insert(std::make_pair(expire, std::make_pair(args.key(), args.value().getTimeout())));
|
||||
std::pair<Iterator, bool> stat = _keys.insert(std::make_pair(args.key(), it));
|
||||
if (!stat.second)
|
||||
{
|
||||
_keyIndex.erase(stat.first->second);
|
||||
stat.first->second = it;
|
||||
}
|
||||
}
|
||||
|
||||
void onRemove(const void*, const TKey& key)
|
||||
{
|
||||
Iterator it = _keys.find(key);
|
||||
if (it != _keys.end())
|
||||
{
|
||||
_keyIndex.erase(it->second);
|
||||
_keys.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void onGet(const void*, const TKey& key)
|
||||
{
|
||||
// get updates the expiration time stamp
|
||||
Iterator it = _keys.find(key);
|
||||
if (it != _keys.end())
|
||||
{
|
||||
KeyExpire ke = it->second->second;
|
||||
// gen new absolute expire value
|
||||
Timestamp expire;
|
||||
expire += ke.second.totalMicroseconds();
|
||||
// delete old index
|
||||
_keyIndex.erase(it->second);
|
||||
IndexIterator itt = _keyIndex.insert(std::make_pair(expire, ke));
|
||||
// update iterator
|
||||
it->second = itt;
|
||||
}
|
||||
}
|
||||
|
||||
void onClear(const void*, const EventArgs& args)
|
||||
{
|
||||
_keys.clear();
|
||||
_keyIndex.clear();
|
||||
}
|
||||
|
||||
void onIsValid(const void*, ValidArgs<TKey>& args)
|
||||
{
|
||||
Iterator it = _keys.find(args.key());
|
||||
if (it != _keys.end())
|
||||
{
|
||||
Timestamp now;
|
||||
if (it->second->first <= now)
|
||||
{
|
||||
args.invalidate();
|
||||
}
|
||||
}
|
||||
else //not found: probably removed by onReplace
|
||||
args.invalidate();
|
||||
}
|
||||
|
||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||
{
|
||||
// Note: replace only informs the cache which elements
|
||||
// it would like to remove!
|
||||
// it does not remove them on its own!
|
||||
IndexIterator it = _keyIndex.begin();
|
||||
Timestamp now;
|
||||
while (it != _keyIndex.end() && it->first < now)
|
||||
{
|
||||
elemsToRemove.insert(it->second.first);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map
|
||||
TimeIndex _keyIndex; /// Maps time to key value
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,89 +1,89 @@
|
|||
//
|
||||
// UniqueExpireCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueExpireCache
|
||||
//
|
||||
// Definition of the UniqueExpireCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueExpireCache_INCLUDED
|
||||
#define Foundation_UniqueExpireCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/UniqueExpireStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TKey, class TValue>
|
||||
class UniqueExpireCache: public AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >
|
||||
/// An UniqueExpireCache caches entries for a given time amount. In contrast
|
||||
/// to ExpireCache which only allows to set a per cache expiration value, it allows to define
|
||||
/// expiration per CacheEntry.
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timestamp& getExpiration() const;
|
||||
///
|
||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||
/// Accessing an object will NOT update this absolute expire timepoint.
|
||||
/// You can use the Poco::ExpirationDecorator to add the getExpiration
|
||||
/// method to values that do not have a getExpiration function.
|
||||
///
|
||||
/// Be careful when using an UniqueExpireCache. A cache is often used
|
||||
/// like cache.has(x) followed by cache.get x). Note that it could happen
|
||||
/// that the "has" call works, then the current execution thread gets descheduled, time passes,
|
||||
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||
/// when "get" is invoked.
|
||||
{
|
||||
public:
|
||||
UniqueExpireCache():
|
||||
AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >(UniqueExpireStrategy<TKey, TValue>())
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueExpireCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
UniqueExpireCache(const UniqueExpireCache& aCache);
|
||||
UniqueExpireCache& operator = (const UniqueExpireCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// UniqueExpireCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueExpireCache
|
||||
//
|
||||
// Definition of the UniqueExpireCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueExpireCache_INCLUDED
|
||||
#define Foundation_UniqueExpireCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/UniqueExpireStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TKey, class TValue>
|
||||
class UniqueExpireCache: public AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >
|
||||
/// An UniqueExpireCache caches entries for a given time amount. In contrast
|
||||
/// to ExpireCache which only allows to set a per cache expiration value, it allows to define
|
||||
/// expiration per CacheEntry.
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timestamp& getExpiration() const;
|
||||
///
|
||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||
/// Accessing an object will NOT update this absolute expire timepoint.
|
||||
/// You can use the Poco::ExpirationDecorator to add the getExpiration
|
||||
/// method to values that do not have a getExpiration function.
|
||||
///
|
||||
/// Be careful when using an UniqueExpireCache. A cache is often used
|
||||
/// like cache.has(x) followed by cache.get x). Note that it could happen
|
||||
/// that the "has" call works, then the current execution thread gets descheduled, time passes,
|
||||
/// the entry gets invalid, thus leading to an empty SharedPtr being returned
|
||||
/// when "get" is invoked.
|
||||
{
|
||||
public:
|
||||
UniqueExpireCache():
|
||||
AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue> >(UniqueExpireStrategy<TKey, TValue>())
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueExpireCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
UniqueExpireCache(const UniqueExpireCache& aCache);
|
||||
UniqueExpireCache& operator = (const UniqueExpireCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,90 +1,90 @@
|
|||
//
|
||||
// UniqueExpireLRUCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireLRUCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueExpireLRUCache
|
||||
//
|
||||
// Definition of the UniqueExpireLRUCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueExpireLRUCache_INCLUDED
|
||||
#define Foundation_UniqueExpireLRUCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/StrategyCollection.h"
|
||||
#include "Poco/UniqueExpireStrategy.h"
|
||||
#include "Poco/LRUStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class UniqueExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||
/// A UniqueExpireLRUCache combines LRU caching and time based per entry expire caching.
|
||||
/// One can define for each cache entry a seperate timepoint
|
||||
/// but also limit the size of the cache (per default: 1024).
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timestamp& getExpiration() const;
|
||||
///
|
||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||
/// Accessing an object will NOT update this absolute expire timepoint.
|
||||
/// You can use the Poco::ExpirationDecorator to add the getExpiration
|
||||
/// method to values that do not have a getExpiration function.
|
||||
{
|
||||
public:
|
||||
UniqueExpireLRUCache(long cacheSize = 1024):
|
||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||
{
|
||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||
this->_strategy.pushBack(new UniqueExpireStrategy<TKey, TValue>());
|
||||
}
|
||||
|
||||
~UniqueExpireLRUCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache);
|
||||
UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// UniqueExpireLRUCache.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireLRUCache.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueExpireLRUCache
|
||||
//
|
||||
// Definition of the UniqueExpireLRUCache class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueExpireLRUCache_INCLUDED
|
||||
#define Foundation_UniqueExpireLRUCache_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/AbstractCache.h"
|
||||
#include "Poco/StrategyCollection.h"
|
||||
#include "Poco/UniqueExpireStrategy.h"
|
||||
#include "Poco/LRUStrategy.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class UniqueExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >
|
||||
/// A UniqueExpireLRUCache combines LRU caching and time based per entry expire caching.
|
||||
/// One can define for each cache entry a seperate timepoint
|
||||
/// but also limit the size of the cache (per default: 1024).
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timestamp& getExpiration() const;
|
||||
///
|
||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||
/// Accessing an object will NOT update this absolute expire timepoint.
|
||||
/// You can use the Poco::ExpirationDecorator to add the getExpiration
|
||||
/// method to values that do not have a getExpiration function.
|
||||
{
|
||||
public:
|
||||
UniqueExpireLRUCache(long cacheSize = 1024):
|
||||
AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue> >(StrategyCollection<TKey, TValue>())
|
||||
{
|
||||
this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
|
||||
this->_strategy.pushBack(new UniqueExpireStrategy<TKey, TValue>());
|
||||
}
|
||||
|
||||
~UniqueExpireLRUCache()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache);
|
||||
UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,160 +1,160 @@
|
|||
//
|
||||
// UniqueExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireStrategy.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueExpireStrategy
|
||||
//
|
||||
// Definition of the UniqueExpireStrategy class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueExpireStrategy_INCLUDED
|
||||
#define Foundation_UniqueExpireStrategy_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/KeyValueArgs.h"
|
||||
#include "Poco/ValidArgs.h"
|
||||
#include "Poco/AbstractStrategy.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/EventArgs.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class UniqueExpireStrategy: public AbstractStrategy<TKey, TValue>
|
||||
/// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast
|
||||
/// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define
|
||||
/// expiration per CacheEntry.
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timestamp& getExpiration() const;
|
||||
///
|
||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||
{
|
||||
public:
|
||||
typedef std::multimap<Timestamp, TKey> TimeIndex;
|
||||
typedef typename TimeIndex::iterator IndexIterator;
|
||||
typedef typename TimeIndex::const_iterator ConstIndexIterator;
|
||||
typedef std::map<TKey, IndexIterator> Keys;
|
||||
typedef typename Keys::iterator Iterator;
|
||||
|
||||
public:
|
||||
UniqueExpireStrategy()
|
||||
/// Create an unique expire strategy.
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueExpireStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& args)
|
||||
{
|
||||
// note: we have to insert even if the expire timepoint is in the past (for StrategyCollection classes to avoid inconsistency with LRU)
|
||||
// no problem: will be removed with next get
|
||||
const Timestamp& expire = args.value().getExpiration();
|
||||
IndexIterator it = _keyIndex.insert(std::make_pair(expire, args.key()));
|
||||
std::pair<Iterator, bool> stat = _keys.insert(std::make_pair(args.key(), it));
|
||||
if (!stat.second)
|
||||
{
|
||||
_keyIndex.erase(stat.first->second);
|
||||
stat.first->second = it;
|
||||
}
|
||||
}
|
||||
|
||||
void onRemove(const void*, const TKey& key)
|
||||
{
|
||||
Iterator it = _keys.find(key);
|
||||
if (it != _keys.end())
|
||||
{
|
||||
_keyIndex.erase(it->second);
|
||||
_keys.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void onGet(const void*, const TKey& key)
|
||||
{
|
||||
// get triggers no changes in an expire
|
||||
}
|
||||
|
||||
void onClear(const void*, const EventArgs& args)
|
||||
{
|
||||
_keys.clear();
|
||||
_keyIndex.clear();
|
||||
}
|
||||
|
||||
void onIsValid(const void*, ValidArgs<TKey>& args)
|
||||
{
|
||||
Iterator it = _keys.find(args.key());
|
||||
if (it != _keys.end())
|
||||
{
|
||||
Timestamp now;
|
||||
if (it->second->first <= now)
|
||||
{
|
||||
args.invalidate();
|
||||
}
|
||||
}
|
||||
else //not found: probably removed by onReplace
|
||||
args.invalidate();
|
||||
}
|
||||
|
||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||
{
|
||||
// Note: replace only informs the cache which elements
|
||||
// it would like to remove!
|
||||
// it does not remove them on its own!
|
||||
IndexIterator it = _keyIndex.begin();
|
||||
Timestamp now;
|
||||
while (it != _keyIndex.end() && it->first < now)
|
||||
{
|
||||
elemsToRemove.insert(it->second);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map
|
||||
TimeIndex _keyIndex; /// Maps time to key value
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
// UniqueExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireStrategy.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
// Module: UniqueExpireStrategy
|
||||
//
|
||||
// Definition of the UniqueExpireStrategy class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_UniqueExpireStrategy_INCLUDED
|
||||
#define Foundation_UniqueExpireStrategy_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/KeyValueArgs.h"
|
||||
#include "Poco/ValidArgs.h"
|
||||
#include "Poco/AbstractStrategy.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/EventArgs.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <
|
||||
class TKey,
|
||||
class TValue
|
||||
>
|
||||
class UniqueExpireStrategy: public AbstractStrategy<TKey, TValue>
|
||||
/// An UniqueExpireStrategy implements time based expiration of cache entries. In contrast
|
||||
/// to ExpireStrategy which only allows to set a per cache expiration value, it allows to define
|
||||
/// expiration per CacheEntry.
|
||||
/// Each TValue object must thus offer the following method:
|
||||
///
|
||||
/// const Poco::Timestamp& getExpiration() const;
|
||||
///
|
||||
/// which returns the absolute timepoint when the entry will be invalidated.
|
||||
{
|
||||
public:
|
||||
typedef std::multimap<Timestamp, TKey> TimeIndex;
|
||||
typedef typename TimeIndex::iterator IndexIterator;
|
||||
typedef typename TimeIndex::const_iterator ConstIndexIterator;
|
||||
typedef std::map<TKey, IndexIterator> Keys;
|
||||
typedef typename Keys::iterator Iterator;
|
||||
|
||||
public:
|
||||
UniqueExpireStrategy()
|
||||
/// Create an unique expire strategy.
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueExpireStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
void onAdd(const void*, const KeyValueArgs <TKey, TValue>& args)
|
||||
{
|
||||
// note: we have to insert even if the expire timepoint is in the past (for StrategyCollection classes to avoid inconsistency with LRU)
|
||||
// no problem: will be removed with next get
|
||||
const Timestamp& expire = args.value().getExpiration();
|
||||
IndexIterator it = _keyIndex.insert(std::make_pair(expire, args.key()));
|
||||
std::pair<Iterator, bool> stat = _keys.insert(std::make_pair(args.key(), it));
|
||||
if (!stat.second)
|
||||
{
|
||||
_keyIndex.erase(stat.first->second);
|
||||
stat.first->second = it;
|
||||
}
|
||||
}
|
||||
|
||||
void onRemove(const void*, const TKey& key)
|
||||
{
|
||||
Iterator it = _keys.find(key);
|
||||
if (it != _keys.end())
|
||||
{
|
||||
_keyIndex.erase(it->second);
|
||||
_keys.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void onGet(const void*, const TKey& key)
|
||||
{
|
||||
// get triggers no changes in an expire
|
||||
}
|
||||
|
||||
void onClear(const void*, const EventArgs& args)
|
||||
{
|
||||
_keys.clear();
|
||||
_keyIndex.clear();
|
||||
}
|
||||
|
||||
void onIsValid(const void*, ValidArgs<TKey>& args)
|
||||
{
|
||||
Iterator it = _keys.find(args.key());
|
||||
if (it != _keys.end())
|
||||
{
|
||||
Timestamp now;
|
||||
if (it->second->first <= now)
|
||||
{
|
||||
args.invalidate();
|
||||
}
|
||||
}
|
||||
else //not found: probably removed by onReplace
|
||||
args.invalidate();
|
||||
}
|
||||
|
||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||
{
|
||||
// Note: replace only informs the cache which elements
|
||||
// it would like to remove!
|
||||
// it does not remove them on its own!
|
||||
IndexIterator it = _keyIndex.begin();
|
||||
Timestamp now;
|
||||
while (it != _keyIndex.end() && it->first < now)
|
||||
{
|
||||
elemsToRemove.insert(it->second);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Keys _keys; /// For faster replacement of keys, the iterator points to the _keyIndex map
|
||||
TimeIndex _keyIndex; /// Maps time to key value
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,89 +1,89 @@
|
|||
//
|
||||
// WindowsConsoleChannel.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/WindowsConsoleChannel.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: WindowsConsoleChannel
|
||||
//
|
||||
// Definition of the WindowsConsoleChannel class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_WindowsConsoleChannel_INCLUDED
|
||||
#define Foundation_WindowsConsoleChannel_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Channel.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API WindowsConsoleChannel: public Channel
|
||||
/// A channel that writes to the Windows console.
|
||||
///
|
||||
/// Only the message's text is written, followed
|
||||
/// by a newline.
|
||||
///
|
||||
/// If POCO has been compiled with POCO_WIN32_UTF8,
|
||||
/// log messages are assumed to be UTF-8 encoded, and
|
||||
/// are converted to UTF-16 prior to writing them to the
|
||||
/// console. This is the main difference to the ConsoleChannel
|
||||
/// class, which cannot handle UTF-8 encoded messages on Windows.
|
||||
///
|
||||
/// Chain this channel to a FormattingChannel with an
|
||||
/// appropriate Formatter to control what is contained
|
||||
/// in the text.
|
||||
///
|
||||
/// Only available on Windows platforms.
|
||||
{
|
||||
public:
|
||||
WindowsConsoleChannel();
|
||||
/// Creates the WindowsConsoleChannel.
|
||||
|
||||
void log(const Message& msg);
|
||||
/// Logs the given message to the channel's stream.
|
||||
|
||||
protected:
|
||||
~WindowsConsoleChannel();
|
||||
|
||||
private:
|
||||
HANDLE _hConsole;
|
||||
bool _isFile;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_WindowsConsoleChannel_INCLUDED
|
||||
//
|
||||
// WindowsConsoleChannel.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/WindowsConsoleChannel.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: WindowsConsoleChannel
|
||||
//
|
||||
// Definition of the WindowsConsoleChannel class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_WindowsConsoleChannel_INCLUDED
|
||||
#define Foundation_WindowsConsoleChannel_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Channel.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API WindowsConsoleChannel: public Channel
|
||||
/// A channel that writes to the Windows console.
|
||||
///
|
||||
/// Only the message's text is written, followed
|
||||
/// by a newline.
|
||||
///
|
||||
/// If POCO has been compiled with POCO_WIN32_UTF8,
|
||||
/// log messages are assumed to be UTF-8 encoded, and
|
||||
/// are converted to UTF-16 prior to writing them to the
|
||||
/// console. This is the main difference to the ConsoleChannel
|
||||
/// class, which cannot handle UTF-8 encoded messages on Windows.
|
||||
///
|
||||
/// Chain this channel to a FormattingChannel with an
|
||||
/// appropriate Formatter to control what is contained
|
||||
/// in the text.
|
||||
///
|
||||
/// Only available on Windows platforms.
|
||||
{
|
||||
public:
|
||||
WindowsConsoleChannel();
|
||||
/// Creates the WindowsConsoleChannel.
|
||||
|
||||
void log(const Message& msg);
|
||||
/// Logs the given message to the channel's stream.
|
||||
|
||||
protected:
|
||||
~WindowsConsoleChannel();
|
||||
|
||||
private:
|
||||
HANDLE _hConsole;
|
||||
bool _isFile;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_WindowsConsoleChannel_INCLUDED
|
||||
|
|
|
@ -1,79 +1,79 @@
|
|||
//
|
||||
// AsyncIOChannel.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/AsyncIOChannel.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOChannel
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncIOChannel.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
AsyncIOChannel::AsyncIOChannel():
|
||||
enqueue(this, &AsyncIOChannel::enqueueImpl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncIOChannel::~AsyncIOChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOChannel::enqueueImpl(const AsyncIOCommand::Ptr& pCommand)
|
||||
{
|
||||
AsyncIOCommand::Ptr ptr(pCommand);
|
||||
return ptr->execute(*this);
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOChannel::write(const void* buffer, int length)
|
||||
{
|
||||
throw NotImplementedException("write()");
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOChannel::read(void* buffer, int length)
|
||||
{
|
||||
throw NotImplementedException("read()");
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOChannel::seek(std::streamoff off, std::ios::seekdir dir)
|
||||
{
|
||||
throw NotImplementedException("seek()");
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// AsyncIOChannel.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/AsyncIOChannel.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOChannel
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncIOChannel.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
AsyncIOChannel::AsyncIOChannel():
|
||||
enqueue(this, &AsyncIOChannel::enqueueImpl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncIOChannel::~AsyncIOChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOChannel::enqueueImpl(const AsyncIOCommand::Ptr& pCommand)
|
||||
{
|
||||
AsyncIOCommand::Ptr ptr(pCommand);
|
||||
return ptr->execute(*this);
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOChannel::write(const void* buffer, int length)
|
||||
{
|
||||
throw NotImplementedException("write()");
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOChannel::read(void* buffer, int length)
|
||||
{
|
||||
throw NotImplementedException("read()");
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOChannel::seek(std::streamoff off, std::ios::seekdir dir)
|
||||
{
|
||||
throw NotImplementedException("seek()");
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,236 +1,236 @@
|
|||
//
|
||||
// AsyncIOCommand.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/AsyncIOCommand.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOCommand
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncIOCommand.h"
|
||||
#include "Poco/AsyncIOChannel.h"
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
//
|
||||
// AsyncIOCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncIOCommand::AsyncIOCommand():
|
||||
_state(CMD_PENDING),
|
||||
_result(0),
|
||||
_pException(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncIOCommand::~AsyncIOCommand()
|
||||
{
|
||||
delete _pException;
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOCommand::wait()
|
||||
{
|
||||
_completed.wait();
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOCommand::wait(long milliseconds)
|
||||
{
|
||||
_completed.wait(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
bool AsyncIOCommand::tryWait(long milliseconds)
|
||||
{
|
||||
return _completed.tryWait(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOCommand::execute(AsyncIOChannel& channel)
|
||||
{
|
||||
delete _pException;
|
||||
_pException = 0;
|
||||
|
||||
_state = CMD_IN_PROGRESS;
|
||||
try
|
||||
{
|
||||
_result = executeImpl(channel);
|
||||
_state = CMD_COMPLETED;
|
||||
_completed.set();
|
||||
AsyncIOEvent completedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_COMPLETED);
|
||||
commandCompleted(this, completedEvent);
|
||||
channel.commandCompleted(this, completedEvent);
|
||||
return _result;
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
_pException = exc.clone();
|
||||
_state = CMD_FAILED;
|
||||
_completed.set();
|
||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||
commandFailed(this, failedEvent);
|
||||
channel.commandFailed(this, failedEvent);
|
||||
throw;
|
||||
}
|
||||
catch (std::exception& exc)
|
||||
{
|
||||
_pException = new Exception(exc.what());
|
||||
_state = CMD_FAILED;
|
||||
_completed.set();
|
||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||
commandFailed(this, failedEvent);
|
||||
channel.commandFailed(this, failedEvent);
|
||||
throw;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
_pException = new Exception("Unknown exception");
|
||||
_state = CMD_FAILED;
|
||||
_completed.set();
|
||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||
commandFailed(this, failedEvent);
|
||||
channel.commandFailed(this, failedEvent);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncWriteCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncWriteCommand::AsyncWriteCommand(const void* buffer, int length):
|
||||
_buffer(buffer),
|
||||
_length(length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncWriteCommand::~AsyncWriteCommand()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncWriteCommand::executeImpl(AsyncIOChannel& channel)
|
||||
{
|
||||
return channel.write(_buffer, _length);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncBufferedWriteCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncBufferedWriteCommand::AsyncBufferedWriteCommand(const void* buf, int length):
|
||||
AsyncWriteCommand(new char[length], length)
|
||||
{
|
||||
std::memcpy(const_cast<void*>(buffer()), buf, length);
|
||||
}
|
||||
|
||||
|
||||
AsyncBufferedWriteCommand::~AsyncBufferedWriteCommand()
|
||||
{
|
||||
delete [] reinterpret_cast<const char*>(buffer());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncReadCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncReadCommand::AsyncReadCommand(void* buffer, int length):
|
||||
_buffer(buffer),
|
||||
_length(length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncReadCommand::~AsyncReadCommand()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncReadCommand::executeImpl(AsyncIOChannel& channel)
|
||||
{
|
||||
return channel.read(_buffer, _length);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncBufferedReadCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncBufferedReadCommand::AsyncBufferedReadCommand(int length):
|
||||
AsyncReadCommand(new char[length], length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncBufferedReadCommand::~AsyncBufferedReadCommand()
|
||||
{
|
||||
delete [] reinterpret_cast<char*>(buffer());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncSeekCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncSeekCommand::AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir):
|
||||
_off(off),
|
||||
_dir(dir)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncSeekCommand::~AsyncSeekCommand()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncSeekCommand::executeImpl(AsyncIOChannel& channel)
|
||||
{
|
||||
return channel.seek(_off, _dir);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// AsyncIOCommand.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/AsyncIOCommand.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOCommand
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncIOCommand.h"
|
||||
#include "Poco/AsyncIOChannel.h"
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
//
|
||||
// AsyncIOCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncIOCommand::AsyncIOCommand():
|
||||
_state(CMD_PENDING),
|
||||
_result(0),
|
||||
_pException(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncIOCommand::~AsyncIOCommand()
|
||||
{
|
||||
delete _pException;
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOCommand::wait()
|
||||
{
|
||||
_completed.wait();
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOCommand::wait(long milliseconds)
|
||||
{
|
||||
_completed.wait(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
bool AsyncIOCommand::tryWait(long milliseconds)
|
||||
{
|
||||
return _completed.tryWait(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
int AsyncIOCommand::execute(AsyncIOChannel& channel)
|
||||
{
|
||||
delete _pException;
|
||||
_pException = 0;
|
||||
|
||||
_state = CMD_IN_PROGRESS;
|
||||
try
|
||||
{
|
||||
_result = executeImpl(channel);
|
||||
_state = CMD_COMPLETED;
|
||||
_completed.set();
|
||||
AsyncIOEvent completedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_COMPLETED);
|
||||
commandCompleted(this, completedEvent);
|
||||
channel.commandCompleted(this, completedEvent);
|
||||
return _result;
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
_pException = exc.clone();
|
||||
_state = CMD_FAILED;
|
||||
_completed.set();
|
||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||
commandFailed(this, failedEvent);
|
||||
channel.commandFailed(this, failedEvent);
|
||||
throw;
|
||||
}
|
||||
catch (std::exception& exc)
|
||||
{
|
||||
_pException = new Exception(exc.what());
|
||||
_state = CMD_FAILED;
|
||||
_completed.set();
|
||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||
commandFailed(this, failedEvent);
|
||||
channel.commandFailed(this, failedEvent);
|
||||
throw;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
_pException = new Exception("Unknown exception");
|
||||
_state = CMD_FAILED;
|
||||
_completed.set();
|
||||
AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
|
||||
commandFailed(this, failedEvent);
|
||||
channel.commandFailed(this, failedEvent);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncWriteCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncWriteCommand::AsyncWriteCommand(const void* buffer, int length):
|
||||
_buffer(buffer),
|
||||
_length(length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncWriteCommand::~AsyncWriteCommand()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncWriteCommand::executeImpl(AsyncIOChannel& channel)
|
||||
{
|
||||
return channel.write(_buffer, _length);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncBufferedWriteCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncBufferedWriteCommand::AsyncBufferedWriteCommand(const void* buf, int length):
|
||||
AsyncWriteCommand(new char[length], length)
|
||||
{
|
||||
std::memcpy(const_cast<void*>(buffer()), buf, length);
|
||||
}
|
||||
|
||||
|
||||
AsyncBufferedWriteCommand::~AsyncBufferedWriteCommand()
|
||||
{
|
||||
delete [] reinterpret_cast<const char*>(buffer());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncReadCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncReadCommand::AsyncReadCommand(void* buffer, int length):
|
||||
_buffer(buffer),
|
||||
_length(length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncReadCommand::~AsyncReadCommand()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncReadCommand::executeImpl(AsyncIOChannel& channel)
|
||||
{
|
||||
return channel.read(_buffer, _length);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncBufferedReadCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncBufferedReadCommand::AsyncBufferedReadCommand(int length):
|
||||
AsyncReadCommand(new char[length], length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncBufferedReadCommand::~AsyncBufferedReadCommand()
|
||||
{
|
||||
delete [] reinterpret_cast<char*>(buffer());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// AsyncSeekCommand
|
||||
//
|
||||
|
||||
|
||||
AsyncSeekCommand::AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir):
|
||||
_off(off),
|
||||
_dir(dir)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncSeekCommand::~AsyncSeekCommand()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncSeekCommand::executeImpl(AsyncIOChannel& channel)
|
||||
{
|
||||
return channel.seek(_off, _dir);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,88 +1,88 @@
|
|||
//
|
||||
// AsyncIOEvent.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/AsyncIOEvent.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOEvent
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
#include "Poco/AsyncIOCommand.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
AsyncIOEvent::AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what):
|
||||
_pCommand(pCommand),
|
||||
_pChannel(pChannel),
|
||||
_what(what)
|
||||
{
|
||||
poco_check_ptr (pCommand);
|
||||
poco_check_ptr (pChannel);
|
||||
|
||||
_pCommand->duplicate();
|
||||
}
|
||||
|
||||
|
||||
AsyncIOEvent::AsyncIOEvent(const AsyncIOEvent& event):
|
||||
_pCommand(event._pCommand),
|
||||
_pChannel(event._pChannel),
|
||||
_what(event._what)
|
||||
{
|
||||
_pCommand->duplicate();
|
||||
}
|
||||
|
||||
|
||||
AsyncIOEvent::~AsyncIOEvent()
|
||||
{
|
||||
_pCommand->release();
|
||||
}
|
||||
|
||||
|
||||
AsyncIOEvent& AsyncIOEvent::operator = (const AsyncIOEvent& event)
|
||||
{
|
||||
AsyncIOEvent tmp(event);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOEvent::swap(AsyncIOEvent& event)
|
||||
{
|
||||
std::swap(_pCommand, event._pCommand);
|
||||
std::swap(_pChannel, event._pChannel);
|
||||
std::swap(_what, event._what);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// AsyncIOEvent.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/AsyncIOEvent.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncIOEvent
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
#include "Poco/AsyncIOCommand.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
AsyncIOEvent::AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what):
|
||||
_pCommand(pCommand),
|
||||
_pChannel(pChannel),
|
||||
_what(what)
|
||||
{
|
||||
poco_check_ptr (pCommand);
|
||||
poco_check_ptr (pChannel);
|
||||
|
||||
_pCommand->duplicate();
|
||||
}
|
||||
|
||||
|
||||
AsyncIOEvent::AsyncIOEvent(const AsyncIOEvent& event):
|
||||
_pCommand(event._pCommand),
|
||||
_pChannel(event._pChannel),
|
||||
_what(event._what)
|
||||
{
|
||||
_pCommand->duplicate();
|
||||
}
|
||||
|
||||
|
||||
AsyncIOEvent::~AsyncIOEvent()
|
||||
{
|
||||
_pCommand->release();
|
||||
}
|
||||
|
||||
|
||||
AsyncIOEvent& AsyncIOEvent::operator = (const AsyncIOEvent& event)
|
||||
{
|
||||
AsyncIOEvent tmp(event);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOEvent::swap(AsyncIOEvent& event)
|
||||
{
|
||||
std::swap(_pCommand, event._pCommand);
|
||||
std::swap(_pChannel, event._pChannel);
|
||||
std::swap(_what, event._what);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,100 +1,100 @@
|
|||
//
|
||||
// AsyncStreamChannel.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/AsyncStreamChannel.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncStreamChannel
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncStreamChannel.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
AsyncStreamChannel::AsyncStreamChannel(std::istream& istr):
|
||||
_pIstr(&istr),
|
||||
_pOstr(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncStreamChannel::AsyncStreamChannel(std::ostream& ostr):
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncStreamChannel::AsyncStreamChannel(std::iostream& iostr):
|
||||
_pIstr(&iostr),
|
||||
_pOstr(&iostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncStreamChannel::~AsyncStreamChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncStreamChannel::write(const void* buffer, int length)
|
||||
{
|
||||
if (_pOstr)
|
||||
{
|
||||
_pOstr->write(reinterpret_cast<const char*>(buffer), length);
|
||||
return length;
|
||||
}
|
||||
else throw IOException("Cannot write to an input stream");
|
||||
}
|
||||
|
||||
|
||||
int AsyncStreamChannel::read(void* buffer, int length)
|
||||
{
|
||||
if (_pIstr)
|
||||
return static_cast<int>(_pIstr->read(reinterpret_cast<char*>(buffer), length).gcount());
|
||||
else
|
||||
throw IOException("Cannot read from an output stream");
|
||||
}
|
||||
|
||||
|
||||
int AsyncStreamChannel::seek(std::streamoff off, std::ios::seekdir dir)
|
||||
{
|
||||
if (_pIstr)
|
||||
_pIstr->seekg(off, dir);
|
||||
if (_pOstr)
|
||||
_pOstr->seekp(off, dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// AsyncStreamChannel.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/AsyncStreamChannel.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: AsyncIO
|
||||
// Module: AsyncStreamChannel
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncStreamChannel.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
AsyncStreamChannel::AsyncStreamChannel(std::istream& istr):
|
||||
_pIstr(&istr),
|
||||
_pOstr(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncStreamChannel::AsyncStreamChannel(std::ostream& ostr):
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncStreamChannel::AsyncStreamChannel(std::iostream& iostr):
|
||||
_pIstr(&iostr),
|
||||
_pOstr(&iostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncStreamChannel::~AsyncStreamChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int AsyncStreamChannel::write(const void* buffer, int length)
|
||||
{
|
||||
if (_pOstr)
|
||||
{
|
||||
_pOstr->write(reinterpret_cast<const char*>(buffer), length);
|
||||
return length;
|
||||
}
|
||||
else throw IOException("Cannot write to an input stream");
|
||||
}
|
||||
|
||||
|
||||
int AsyncStreamChannel::read(void* buffer, int length)
|
||||
{
|
||||
if (_pIstr)
|
||||
return static_cast<int>(_pIstr->read(reinterpret_cast<char*>(buffer), length).gcount());
|
||||
else
|
||||
throw IOException("Cannot read from an output stream");
|
||||
}
|
||||
|
||||
|
||||
int AsyncStreamChannel::seek(std::streamoff off, std::ios::seekdir dir)
|
||||
{
|
||||
if (_pIstr)
|
||||
_pIstr->seekg(off, dir);
|
||||
if (_pOstr)
|
||||
_pOstr->seekp(off, dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,76 +1,76 @@
|
|||
//
|
||||
// Checksum.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Checksum.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Checksum
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Checksum.h"
|
||||
#include "Poco/zlib.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Checksum::Checksum():
|
||||
_type(TYPE_CRC32),
|
||||
_value(crc32(0L, Z_NULL, 0))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Checksum::Checksum(Type t):
|
||||
_type(t),
|
||||
_value(0)
|
||||
{
|
||||
if (t == TYPE_CRC32)
|
||||
_value = crc32(0L, Z_NULL, 0);
|
||||
else
|
||||
_value = adler32(0L, Z_NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
Checksum::~Checksum()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Checksum::update(const char* data, unsigned length)
|
||||
{
|
||||
if (_type == TYPE_ADLER32)
|
||||
_value = adler32(_value, reinterpret_cast<const Bytef*>(data), length);
|
||||
else
|
||||
_value = crc32(_value, reinterpret_cast<const Bytef*>(data), length);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// Checksum.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Checksum.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Checksum
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Checksum.h"
|
||||
#include "Poco/zlib.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Checksum::Checksum():
|
||||
_type(TYPE_CRC32),
|
||||
_value(crc32(0L, Z_NULL, 0))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Checksum::Checksum(Type t):
|
||||
_type(t),
|
||||
_value(0)
|
||||
{
|
||||
if (t == TYPE_CRC32)
|
||||
_value = crc32(0L, Z_NULL, 0);
|
||||
else
|
||||
_value = adler32(0L, Z_NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
Checksum::~Checksum()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Checksum::update(const char* data, unsigned length)
|
||||
{
|
||||
if (_type == TYPE_ADLER32)
|
||||
_value = adler32(_value, reinterpret_cast<const Bytef*>(data), length);
|
||||
else
|
||||
_value = crc32(_value, reinterpret_cast<const Bytef*>(data), length);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,101 +1,101 @@
|
|||
//
|
||||
// Condition.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Condition.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Condition
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Condition.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Condition::Condition()
|
||||
{
|
||||
}
|
||||
|
||||
Condition::~Condition()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Condition::signal()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (!_waitQueue.empty())
|
||||
{
|
||||
_waitQueue.front()->set();
|
||||
dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Condition::broadcast()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
||||
{
|
||||
(*it)->set();
|
||||
}
|
||||
_waitQueue.clear();
|
||||
}
|
||||
|
||||
|
||||
void Condition::enqueue(Event& event)
|
||||
{
|
||||
_waitQueue.push_back(&event);
|
||||
}
|
||||
|
||||
|
||||
void Condition::dequeue()
|
||||
{
|
||||
_waitQueue.pop_front();
|
||||
}
|
||||
|
||||
|
||||
void Condition::dequeue(Event& event)
|
||||
{
|
||||
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
||||
{
|
||||
if (*it == &event)
|
||||
{
|
||||
_waitQueue.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// Condition.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Condition.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Condition
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Condition.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Condition::Condition()
|
||||
{
|
||||
}
|
||||
|
||||
Condition::~Condition()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Condition::signal()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (!_waitQueue.empty())
|
||||
{
|
||||
_waitQueue.front()->set();
|
||||
dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Condition::broadcast()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
||||
{
|
||||
(*it)->set();
|
||||
}
|
||||
_waitQueue.clear();
|
||||
}
|
||||
|
||||
|
||||
void Condition::enqueue(Event& event)
|
||||
{
|
||||
_waitQueue.push_back(&event);
|
||||
}
|
||||
|
||||
|
||||
void Condition::dequeue()
|
||||
{
|
||||
_waitQueue.pop_front();
|
||||
}
|
||||
|
||||
|
||||
void Condition::dequeue(Event& event)
|
||||
{
|
||||
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
||||
{
|
||||
if (*it == &event)
|
||||
{
|
||||
_waitQueue.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,408 +1,408 @@
|
|||
//
|
||||
// DynamicAny.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/DynamicAny.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicAny
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/DynamicStruct.h"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DynamicAny::DynamicAny():
|
||||
_pHolder(new DynamicAnyHolderImpl<int>(0))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicAny::DynamicAny(const char* pVal):
|
||||
_pHolder(new DynamicAnyHolderImpl<std::string>(pVal))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicAny::DynamicAny(const DynamicAny& other):
|
||||
_pHolder(0)
|
||||
{
|
||||
if (other._pHolder)
|
||||
_pHolder = other._pHolder->clone();
|
||||
}
|
||||
|
||||
|
||||
DynamicAny::~DynamicAny()
|
||||
{
|
||||
delete _pHolder;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator = (const DynamicAny& other)
|
||||
{
|
||||
DynamicAny tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny DynamicAny::operator + (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return add<Poco::Int64>(other);
|
||||
else
|
||||
return add<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return add<double>(other);
|
||||
else if (isString())
|
||||
return add<std::string>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator += (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = add<Poco::Int64>(other);
|
||||
else
|
||||
return *this = add<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = add<double>(other);
|
||||
else if (isString())
|
||||
return *this = add<std::string>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny DynamicAny::operator - (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return subtract<Poco::Int64>(other);
|
||||
else
|
||||
return subtract<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return subtract<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator -= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = subtract<Poco::Int64>(other);
|
||||
else
|
||||
return *this = subtract<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = subtract<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny DynamicAny::operator * (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return multiply<Poco::Int64>(other);
|
||||
else
|
||||
return multiply<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return multiply<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator *= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = multiply<Poco::Int64>(other);
|
||||
else
|
||||
return *this = multiply<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = multiply<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny DynamicAny::operator / (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return divide<Poco::Int64>(other);
|
||||
else
|
||||
return divide<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return divide<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator /= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = divide<Poco::Int64>(other);
|
||||
else
|
||||
return *this = divide<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = divide<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator ++ ()
|
||||
{
|
||||
if (!isInteger())
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
|
||||
return *this = *this + 1;
|
||||
}
|
||||
|
||||
DynamicAny DynamicAny::operator ++ (int)
|
||||
{
|
||||
if (!isInteger())
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
|
||||
DynamicAny tmp(*this);
|
||||
*this += 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
DynamicAny& DynamicAny::operator -- ()
|
||||
{
|
||||
if (!isInteger())
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
|
||||
return *this = *this - 1;
|
||||
}
|
||||
|
||||
DynamicAny DynamicAny::operator -- (int)
|
||||
{
|
||||
if (!isInteger())
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
|
||||
DynamicAny tmp(*this);
|
||||
*this -= 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator [] (const std::string& name)
|
||||
{
|
||||
DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<DynamicAnyHolderImpl<DynamicStruct> *>(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->operator[](name);
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicAny::operator [] (const std::string& name) const
|
||||
{
|
||||
const DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<const DynamicAnyHolderImpl<DynamicStruct>* >(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->operator[](name);
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parse(const std::string& val)
|
||||
{
|
||||
std::string::size_type t = 0;
|
||||
return parse(val, t);
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parse(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
// { -> an Object==DynamicStruct
|
||||
// [ -> an array
|
||||
// '/" -> a string (strip '/")
|
||||
// other: also treat as string
|
||||
skipWhiteSpace(val, pos);
|
||||
if (pos < val.size())
|
||||
{
|
||||
switch (val[pos])
|
||||
{
|
||||
case '{':
|
||||
return parseObject(val, pos);
|
||||
case '[':
|
||||
return parseArray(val, pos);
|
||||
default:
|
||||
return parseString(val, pos);
|
||||
}
|
||||
}
|
||||
std::string empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parseObject(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
poco_assert_dbg (val[pos] == '{');
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
DynamicStruct aStruct;
|
||||
while (val[pos] != '}' && pos < val.size())
|
||||
{
|
||||
std::string key = parseString(val, pos);
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] != ':')
|
||||
throw DataFormatException("Incorrect object, must contain: key : value pairs");
|
||||
++pos; // skip past :
|
||||
DynamicAny value = parse(val, pos);
|
||||
aStruct.insert(key, value);
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] == ',')
|
||||
{
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
}
|
||||
}
|
||||
if (val[pos] != '}')
|
||||
throw DataFormatException("Unterminated object");
|
||||
++pos;
|
||||
return aStruct;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parseArray(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
poco_assert_dbg (val[pos] == '[');
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
std::vector<DynamicAny> result;
|
||||
while (val[pos] != ']' && pos < val.size())
|
||||
{
|
||||
result.push_back(parse(val, pos));
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] == ',')
|
||||
{
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
}
|
||||
}
|
||||
if (val[pos] != ']')
|
||||
throw DataFormatException("Unterminated array");
|
||||
++pos;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string DynamicAny::parseString(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
static const std::string STR_STOP("'\"");
|
||||
static const std::string OTHER_STOP(" ,]}"); // we stop at space, ',', ']' or '}'
|
||||
|
||||
bool inString = false;
|
||||
//skip optional ' "
|
||||
if (val[pos] == '\'' || val[pos] == '"')
|
||||
{
|
||||
inString = true;
|
||||
++pos;
|
||||
}
|
||||
|
||||
std::string::size_type stop = std::string::npos;
|
||||
if (inString)
|
||||
{
|
||||
stop = val.find_first_of(STR_STOP, pos);
|
||||
if (stop == std::string::npos)
|
||||
throw DataFormatException("Unterminated string");
|
||||
}
|
||||
else
|
||||
{
|
||||
// we stop at space, ',', ']' or '}' or end of string
|
||||
stop = val.find_first_of(OTHER_STOP, pos);
|
||||
if (stop == std::string::npos)
|
||||
stop = val.size();
|
||||
|
||||
std::string::size_type safeCheck = val.find_first_of(STR_STOP, pos);
|
||||
if (safeCheck != std::string::npos && safeCheck < stop)
|
||||
throw DataFormatException("Misplaced string termination char found");
|
||||
|
||||
}
|
||||
|
||||
// stop now points to the last char to be not included
|
||||
std::string result = val.substr(pos, stop - pos);
|
||||
++stop; // point past '/"
|
||||
pos = stop;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void DynamicAny::skipWhiteSpace(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
while (std::isspace(val[pos]))
|
||||
++pos;
|
||||
}
|
||||
|
||||
|
||||
std::string DynamicAny::toString(const DynamicAny& any)
|
||||
{
|
||||
std::string res;
|
||||
appendJSONString(res, any);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco::Poco
|
||||
//
|
||||
// DynamicAny.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/DynamicAny.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicAny
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/DynamicStruct.h"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DynamicAny::DynamicAny():
|
||||
_pHolder(new DynamicAnyHolderImpl<int>(0))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicAny::DynamicAny(const char* pVal):
|
||||
_pHolder(new DynamicAnyHolderImpl<std::string>(pVal))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicAny::DynamicAny(const DynamicAny& other):
|
||||
_pHolder(0)
|
||||
{
|
||||
if (other._pHolder)
|
||||
_pHolder = other._pHolder->clone();
|
||||
}
|
||||
|
||||
|
||||
DynamicAny::~DynamicAny()
|
||||
{
|
||||
delete _pHolder;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator = (const DynamicAny& other)
|
||||
{
|
||||
DynamicAny tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny DynamicAny::operator + (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return add<Poco::Int64>(other);
|
||||
else
|
||||
return add<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return add<double>(other);
|
||||
else if (isString())
|
||||
return add<std::string>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator += (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = add<Poco::Int64>(other);
|
||||
else
|
||||
return *this = add<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = add<double>(other);
|
||||
else if (isString())
|
||||
return *this = add<std::string>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny DynamicAny::operator - (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return subtract<Poco::Int64>(other);
|
||||
else
|
||||
return subtract<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return subtract<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator -= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = subtract<Poco::Int64>(other);
|
||||
else
|
||||
return *this = subtract<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = subtract<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny DynamicAny::operator * (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return multiply<Poco::Int64>(other);
|
||||
else
|
||||
return multiply<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return multiply<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator *= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = multiply<Poco::Int64>(other);
|
||||
else
|
||||
return *this = multiply<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = multiply<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny DynamicAny::operator / (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return divide<Poco::Int64>(other);
|
||||
else
|
||||
return divide<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return divide<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator /= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = divide<Poco::Int64>(other);
|
||||
else
|
||||
return *this = divide<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = divide<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator ++ ()
|
||||
{
|
||||
if (!isInteger())
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
|
||||
return *this = *this + 1;
|
||||
}
|
||||
|
||||
DynamicAny DynamicAny::operator ++ (int)
|
||||
{
|
||||
if (!isInteger())
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
|
||||
DynamicAny tmp(*this);
|
||||
*this += 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
DynamicAny& DynamicAny::operator -- ()
|
||||
{
|
||||
if (!isInteger())
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
|
||||
return *this = *this - 1;
|
||||
}
|
||||
|
||||
DynamicAny DynamicAny::operator -- (int)
|
||||
{
|
||||
if (!isInteger())
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
|
||||
DynamicAny tmp(*this);
|
||||
*this -= 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator [] (const std::string& name)
|
||||
{
|
||||
DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<DynamicAnyHolderImpl<DynamicStruct> *>(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->operator[](name);
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicAny::operator [] (const std::string& name) const
|
||||
{
|
||||
const DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<const DynamicAnyHolderImpl<DynamicStruct>* >(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->operator[](name);
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parse(const std::string& val)
|
||||
{
|
||||
std::string::size_type t = 0;
|
||||
return parse(val, t);
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parse(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
// { -> an Object==DynamicStruct
|
||||
// [ -> an array
|
||||
// '/" -> a string (strip '/")
|
||||
// other: also treat as string
|
||||
skipWhiteSpace(val, pos);
|
||||
if (pos < val.size())
|
||||
{
|
||||
switch (val[pos])
|
||||
{
|
||||
case '{':
|
||||
return parseObject(val, pos);
|
||||
case '[':
|
||||
return parseArray(val, pos);
|
||||
default:
|
||||
return parseString(val, pos);
|
||||
}
|
||||
}
|
||||
std::string empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parseObject(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
poco_assert_dbg (val[pos] == '{');
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
DynamicStruct aStruct;
|
||||
while (val[pos] != '}' && pos < val.size())
|
||||
{
|
||||
std::string key = parseString(val, pos);
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] != ':')
|
||||
throw DataFormatException("Incorrect object, must contain: key : value pairs");
|
||||
++pos; // skip past :
|
||||
DynamicAny value = parse(val, pos);
|
||||
aStruct.insert(key, value);
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] == ',')
|
||||
{
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
}
|
||||
}
|
||||
if (val[pos] != '}')
|
||||
throw DataFormatException("Unterminated object");
|
||||
++pos;
|
||||
return aStruct;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parseArray(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
poco_assert_dbg (val[pos] == '[');
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
std::vector<DynamicAny> result;
|
||||
while (val[pos] != ']' && pos < val.size())
|
||||
{
|
||||
result.push_back(parse(val, pos));
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] == ',')
|
||||
{
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
}
|
||||
}
|
||||
if (val[pos] != ']')
|
||||
throw DataFormatException("Unterminated array");
|
||||
++pos;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string DynamicAny::parseString(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
static const std::string STR_STOP("'\"");
|
||||
static const std::string OTHER_STOP(" ,]}"); // we stop at space, ',', ']' or '}'
|
||||
|
||||
bool inString = false;
|
||||
//skip optional ' "
|
||||
if (val[pos] == '\'' || val[pos] == '"')
|
||||
{
|
||||
inString = true;
|
||||
++pos;
|
||||
}
|
||||
|
||||
std::string::size_type stop = std::string::npos;
|
||||
if (inString)
|
||||
{
|
||||
stop = val.find_first_of(STR_STOP, pos);
|
||||
if (stop == std::string::npos)
|
||||
throw DataFormatException("Unterminated string");
|
||||
}
|
||||
else
|
||||
{
|
||||
// we stop at space, ',', ']' or '}' or end of string
|
||||
stop = val.find_first_of(OTHER_STOP, pos);
|
||||
if (stop == std::string::npos)
|
||||
stop = val.size();
|
||||
|
||||
std::string::size_type safeCheck = val.find_first_of(STR_STOP, pos);
|
||||
if (safeCheck != std::string::npos && safeCheck < stop)
|
||||
throw DataFormatException("Misplaced string termination char found");
|
||||
|
||||
}
|
||||
|
||||
// stop now points to the last char to be not included
|
||||
std::string result = val.substr(pos, stop - pos);
|
||||
++stop; // point past '/"
|
||||
pos = stop;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void DynamicAny::skipWhiteSpace(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
while (std::isspace(val[pos]))
|
||||
++pos;
|
||||
}
|
||||
|
||||
|
||||
std::string DynamicAny::toString(const DynamicAny& any)
|
||||
{
|
||||
std::string res;
|
||||
appendJSONString(res, any);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco::Poco
|
||||
|
|
|
@ -1,69 +1,69 @@
|
|||
//
|
||||
// DynamicAnyHolder.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/DynamicAnyHolder.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicAnyHolder
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DynamicAnyHolder.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DynamicAnyHolder::DynamicAnyHolder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicAnyHolder::~DynamicAnyHolder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void appendJSONString(std::string& val, const DynamicAny& any)
|
||||
{
|
||||
bool isJsonString = (any.type() == typeid(std::string) || any.type() == typeid(char) || any.type() == typeid(Poco::DateTime) || any.type() == typeid(Poco::LocalDateTime));
|
||||
if (isJsonString)
|
||||
{
|
||||
val.append(1, '\'');
|
||||
}
|
||||
val.append(any.convert<std::string>());
|
||||
if (isJsonString)
|
||||
{
|
||||
val.append(1, '\'');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// DynamicAnyHolder.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/DynamicAnyHolder.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicAnyHolder
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DynamicAnyHolder.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DynamicAnyHolder::DynamicAnyHolder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicAnyHolder::~DynamicAnyHolder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void appendJSONString(std::string& val, const DynamicAny& any)
|
||||
{
|
||||
bool isJsonString = (any.type() == typeid(std::string) || any.type() == typeid(char) || any.type() == typeid(Poco::DateTime) || any.type() == typeid(Poco::LocalDateTime));
|
||||
if (isJsonString)
|
||||
{
|
||||
val.append(1, '\'');
|
||||
}
|
||||
val.append(any.convert<std::string>());
|
||||
if (isJsonString)
|
||||
{
|
||||
val.append(1, '\'');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,81 +1,81 @@
|
|||
//
|
||||
// DynamicStruct.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/DynamicStruct.cpp#4 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicStruct
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DynamicStruct.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DynamicStruct::DynamicStruct():
|
||||
_data()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicStruct::DynamicStruct(const Data& d):
|
||||
_data(d)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicStruct::~DynamicStruct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicStruct::operator[](const std::string& name) const
|
||||
{
|
||||
ConstIterator it = find(name);
|
||||
if (it == end())
|
||||
throw NotFoundException(name);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
std::set<std::string> DynamicStruct::members() const
|
||||
{
|
||||
std::set<std::string> keys;
|
||||
ConstIterator it = begin();
|
||||
ConstIterator itEnd = end();
|
||||
for (; it != itEnd; ++it)
|
||||
keys.insert(it->first);
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco::Poco
|
||||
//
|
||||
// DynamicStruct.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/DynamicStruct.cpp#4 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicStruct
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DynamicStruct.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DynamicStruct::DynamicStruct():
|
||||
_data()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicStruct::DynamicStruct(const Data& d):
|
||||
_data(d)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicStruct::~DynamicStruct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicStruct::operator[](const std::string& name) const
|
||||
{
|
||||
ConstIterator it = find(name);
|
||||
if (it == end())
|
||||
throw NotFoundException(name);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
std::set<std::string> DynamicStruct::members() const
|
||||
{
|
||||
std::set<std::string> keys;
|
||||
ConstIterator it = begin();
|
||||
ConstIterator itEnd = end();
|
||||
for (; it != itEnd; ++it)
|
||||
keys.insert(it->first);
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco::Poco
|
||||
|
|
|
@ -1,140 +1,140 @@
|
|||
//
|
||||
// FileStream.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/FileStream.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "FileStream_WIN32.cpp"
|
||||
#else
|
||||
#include "FileStream_POSIX.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileIOS::FileIOS(std::ios::openmode defaultMode):
|
||||
_defaultMode(defaultMode)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
FileIOS::~FileIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileIOS::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
clear();
|
||||
_buf.open(path, mode | _defaultMode);
|
||||
}
|
||||
|
||||
|
||||
void FileIOS::close()
|
||||
{
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf* FileIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::FileInputStream():
|
||||
FileIOS(std::ios::in),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::FileInputStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::in),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::~FileInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::FileOutputStream():
|
||||
FileIOS(std::ios::out),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::FileOutputStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::out),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::~FileOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStream::FileStream():
|
||||
FileIOS(std::ios::in | std::ios::out),
|
||||
std::iostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStream::FileStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::in | std::ios::out),
|
||||
std::iostream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileStream::~FileStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// FileStream.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/FileStream.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "FileStream_WIN32.cpp"
|
||||
#else
|
||||
#include "FileStream_POSIX.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileIOS::FileIOS(std::ios::openmode defaultMode):
|
||||
_defaultMode(defaultMode)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
FileIOS::~FileIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileIOS::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
clear();
|
||||
_buf.open(path, mode | _defaultMode);
|
||||
}
|
||||
|
||||
|
||||
void FileIOS::close()
|
||||
{
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf* FileIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::FileInputStream():
|
||||
FileIOS(std::ios::in),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::FileInputStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::in),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::~FileInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::FileOutputStream():
|
||||
FileIOS(std::ios::out),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::FileOutputStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::out),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::~FileOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStream::FileStream():
|
||||
FileIOS(std::ios::in | std::ios::out),
|
||||
std::iostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStream::FileStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::in | std::ios::out),
|
||||
std::iostream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileStream::~FileStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,183 +1,183 @@
|
|||
//
|
||||
// FileStream_POSIX.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/FileStream_POSIX.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileStreamBuf::FileStreamBuf():
|
||||
BufferedBidirectionalStreamBuf(BUFFER_SIZE, std::ios::in | std::ios::out),
|
||||
_fd(-1),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf::~FileStreamBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
poco_assert (_fd == -1);
|
||||
|
||||
_path = path;
|
||||
setMode(mode);
|
||||
|
||||
int flags(0);
|
||||
if (mode & std::ios::trunc)
|
||||
flags |= O_TRUNC;
|
||||
if (mode & std::ios::app)
|
||||
flags |= O_APPEND;
|
||||
if (mode & std::ios::out)
|
||||
flags |= O_CREAT;
|
||||
if ((mode & std::ios::in) && (mode & std::ios::out))
|
||||
flags |= O_RDWR;
|
||||
else if (mode & std::ios::in)
|
||||
flags |= O_RDONLY;
|
||||
else
|
||||
flags |= O_WRONLY;
|
||||
|
||||
_fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP);
|
||||
if (_fd == -1)
|
||||
File::handleLastError(_path);
|
||||
|
||||
if ((mode & std::ios::app) || (mode & std::ios::ate))
|
||||
seekoff(0, std::ios::end, mode);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (_fd == -1) return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
int n = read(_fd, buffer, length);
|
||||
if (n == -1)
|
||||
File::handleLastError(_path);
|
||||
_pos += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (_fd == -1) return -1;
|
||||
|
||||
int n = write(_fd, buffer, length);
|
||||
if (n == -1)
|
||||
File::handleLastError(_path);
|
||||
_pos += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::close()
|
||||
{
|
||||
if (_fd != -1)
|
||||
{
|
||||
sync();
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
||||
{
|
||||
if (_fd == -1 || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
std::streamoff adj;
|
||||
if (mode & std::ios::in)
|
||||
adj = static_cast<std::streamoff>(egptr() - gptr());
|
||||
else
|
||||
adj = 0;
|
||||
|
||||
resetBuffers();
|
||||
|
||||
int whence = SEEK_SET;
|
||||
if (dir == std::ios::cur)
|
||||
{
|
||||
whence = SEEK_CUR;
|
||||
off -= adj;
|
||||
}
|
||||
else if (dir == std::ios::end)
|
||||
{
|
||||
whence = SEEK_END;
|
||||
}
|
||||
_pos = lseek(_fd, off, whence);
|
||||
return _pos;
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
||||
{
|
||||
if (_fd == -1 || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
resetBuffers();
|
||||
|
||||
_pos = lseek(_fd, pos, SEEK_SET);
|
||||
return _pos;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// FileStream_POSIX.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/FileStream_POSIX.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileStreamBuf::FileStreamBuf():
|
||||
BufferedBidirectionalStreamBuf(BUFFER_SIZE, std::ios::in | std::ios::out),
|
||||
_fd(-1),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf::~FileStreamBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
poco_assert (_fd == -1);
|
||||
|
||||
_path = path;
|
||||
setMode(mode);
|
||||
|
||||
int flags(0);
|
||||
if (mode & std::ios::trunc)
|
||||
flags |= O_TRUNC;
|
||||
if (mode & std::ios::app)
|
||||
flags |= O_APPEND;
|
||||
if (mode & std::ios::out)
|
||||
flags |= O_CREAT;
|
||||
if ((mode & std::ios::in) && (mode & std::ios::out))
|
||||
flags |= O_RDWR;
|
||||
else if (mode & std::ios::in)
|
||||
flags |= O_RDONLY;
|
||||
else
|
||||
flags |= O_WRONLY;
|
||||
|
||||
_fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP);
|
||||
if (_fd == -1)
|
||||
File::handleLastError(_path);
|
||||
|
||||
if ((mode & std::ios::app) || (mode & std::ios::ate))
|
||||
seekoff(0, std::ios::end, mode);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (_fd == -1) return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
int n = read(_fd, buffer, length);
|
||||
if (n == -1)
|
||||
File::handleLastError(_path);
|
||||
_pos += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (_fd == -1) return -1;
|
||||
|
||||
int n = write(_fd, buffer, length);
|
||||
if (n == -1)
|
||||
File::handleLastError(_path);
|
||||
_pos += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::close()
|
||||
{
|
||||
if (_fd != -1)
|
||||
{
|
||||
sync();
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
||||
{
|
||||
if (_fd == -1 || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
std::streamoff adj;
|
||||
if (mode & std::ios::in)
|
||||
adj = static_cast<std::streamoff>(egptr() - gptr());
|
||||
else
|
||||
adj = 0;
|
||||
|
||||
resetBuffers();
|
||||
|
||||
int whence = SEEK_SET;
|
||||
if (dir == std::ios::cur)
|
||||
{
|
||||
whence = SEEK_CUR;
|
||||
off -= adj;
|
||||
}
|
||||
else if (dir == std::ios::end)
|
||||
{
|
||||
whence = SEEK_END;
|
||||
}
|
||||
_pos = lseek(_fd, off, whence);
|
||||
return _pos;
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
||||
{
|
||||
if (_fd == -1 || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
resetBuffers();
|
||||
|
||||
_pos = lseek(_fd, pos, SEEK_SET);
|
||||
return _pos;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,223 +1,223 @@
|
|||
//
|
||||
// FileStream.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/FileStream_WIN32.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileStreamBuf::FileStreamBuf():
|
||||
BufferedBidirectionalStreamBuf(BUFFER_SIZE, 0),
|
||||
_handle(INVALID_HANDLE_VALUE),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf::~FileStreamBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
poco_assert (_handle == INVALID_HANDLE_VALUE);
|
||||
|
||||
_path = path;
|
||||
setMode(mode);
|
||||
|
||||
DWORD access = 0;
|
||||
if (mode & std::ios::in)
|
||||
access |= GENERIC_READ;
|
||||
if (mode & std::ios::out)
|
||||
access |= GENERIC_WRITE;
|
||||
|
||||
DWORD shareMode = FILE_SHARE_READ;
|
||||
DWORD creationDisp = OPEN_EXISTING;
|
||||
if (mode & std::ios::trunc)
|
||||
creationDisp = CREATE_ALWAYS;
|
||||
else if (mode & std::ios::out)
|
||||
creationDisp = OPEN_ALWAYS;
|
||||
|
||||
DWORD flags = FILE_ATTRIBUTE_NORMAL;
|
||||
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
std::wstring utf16Path;
|
||||
UnicodeConverter::toUTF16(path, utf16Path);
|
||||
_handle = CreateFileW(utf16Path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
||||
#else
|
||||
_handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
||||
#endif
|
||||
|
||||
if (_handle == INVALID_HANDLE_VALUE)
|
||||
File::handleLastError(_path);
|
||||
|
||||
if ((mode & std::ios::ate) || (mode & std::ios::app))
|
||||
seekoff(0, std::ios::end, mode);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::in))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
DWORD bytesRead(0);
|
||||
BOOL rc = ReadFile(_handle, buffer, static_cast<DWORD>(length), &bytesRead, NULL);
|
||||
if (rc == 0)
|
||||
File::handleLastError(_path);
|
||||
|
||||
_pos += bytesRead;
|
||||
|
||||
return static_cast<int>(bytesRead);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::out))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::app)
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = 0;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_END);
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
}
|
||||
|
||||
DWORD bytesWritten(0);
|
||||
BOOL rc = WriteFile(_handle, buffer, static_cast<DWORD>(length), &bytesWritten, NULL);
|
||||
if (rc == 0)
|
||||
File::handleLastError(_path);
|
||||
|
||||
_pos += bytesWritten;
|
||||
|
||||
return static_cast<int>(bytesWritten);
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::close()
|
||||
{
|
||||
if (_handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
CloseHandle(_handle);
|
||||
_handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
std::streamoff adj;
|
||||
if (mode & std::ios::in)
|
||||
adj = static_cast<std::streamoff>(egptr() - gptr());
|
||||
else
|
||||
adj = 0;
|
||||
|
||||
resetBuffers();
|
||||
|
||||
DWORD offset = FILE_BEGIN;
|
||||
if (dir == std::ios::cur)
|
||||
{
|
||||
offset = FILE_CURRENT;
|
||||
off -= adj;
|
||||
}
|
||||
else if (dir == std::ios::end)
|
||||
{
|
||||
offset = FILE_END;
|
||||
}
|
||||
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = off;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, offset);
|
||||
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
return std::streampos(static_cast<std::streamoff>(_pos));
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
resetBuffers();
|
||||
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = pos;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_BEGIN);
|
||||
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
return std::streampos(static_cast<std::streamoff>(_pos));
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// FileStream.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/FileStream_WIN32.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileStreamBuf::FileStreamBuf():
|
||||
BufferedBidirectionalStreamBuf(BUFFER_SIZE, 0),
|
||||
_handle(INVALID_HANDLE_VALUE),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf::~FileStreamBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
poco_assert (_handle == INVALID_HANDLE_VALUE);
|
||||
|
||||
_path = path;
|
||||
setMode(mode);
|
||||
|
||||
DWORD access = 0;
|
||||
if (mode & std::ios::in)
|
||||
access |= GENERIC_READ;
|
||||
if (mode & std::ios::out)
|
||||
access |= GENERIC_WRITE;
|
||||
|
||||
DWORD shareMode = FILE_SHARE_READ;
|
||||
DWORD creationDisp = OPEN_EXISTING;
|
||||
if (mode & std::ios::trunc)
|
||||
creationDisp = CREATE_ALWAYS;
|
||||
else if (mode & std::ios::out)
|
||||
creationDisp = OPEN_ALWAYS;
|
||||
|
||||
DWORD flags = FILE_ATTRIBUTE_NORMAL;
|
||||
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
std::wstring utf16Path;
|
||||
UnicodeConverter::toUTF16(path, utf16Path);
|
||||
_handle = CreateFileW(utf16Path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
||||
#else
|
||||
_handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
||||
#endif
|
||||
|
||||
if (_handle == INVALID_HANDLE_VALUE)
|
||||
File::handleLastError(_path);
|
||||
|
||||
if ((mode & std::ios::ate) || (mode & std::ios::app))
|
||||
seekoff(0, std::ios::end, mode);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::in))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
DWORD bytesRead(0);
|
||||
BOOL rc = ReadFile(_handle, buffer, static_cast<DWORD>(length), &bytesRead, NULL);
|
||||
if (rc == 0)
|
||||
File::handleLastError(_path);
|
||||
|
||||
_pos += bytesRead;
|
||||
|
||||
return static_cast<int>(bytesRead);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::out))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::app)
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = 0;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_END);
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
}
|
||||
|
||||
DWORD bytesWritten(0);
|
||||
BOOL rc = WriteFile(_handle, buffer, static_cast<DWORD>(length), &bytesWritten, NULL);
|
||||
if (rc == 0)
|
||||
File::handleLastError(_path);
|
||||
|
||||
_pos += bytesWritten;
|
||||
|
||||
return static_cast<int>(bytesWritten);
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::close()
|
||||
{
|
||||
if (_handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
CloseHandle(_handle);
|
||||
_handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
std::streamoff adj;
|
||||
if (mode & std::ios::in)
|
||||
adj = static_cast<std::streamoff>(egptr() - gptr());
|
||||
else
|
||||
adj = 0;
|
||||
|
||||
resetBuffers();
|
||||
|
||||
DWORD offset = FILE_BEGIN;
|
||||
if (dir == std::ios::cur)
|
||||
{
|
||||
offset = FILE_CURRENT;
|
||||
off -= adj;
|
||||
}
|
||||
else if (dir == std::ios::end)
|
||||
{
|
||||
offset = FILE_END;
|
||||
}
|
||||
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = off;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, offset);
|
||||
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
return std::streampos(static_cast<std::streamoff>(_pos));
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
resetBuffers();
|
||||
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = pos;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_BEGIN);
|
||||
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
return std::streampos(static_cast<std::streamoff>(_pos));
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,56 +1,56 @@
|
|||
//
|
||||
// Hash.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Hash.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: Hash
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Hash.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
std::size_t hash(const std::string& str)
|
||||
{
|
||||
std::size_t h = 0;
|
||||
std::string::const_iterator it = str.begin();
|
||||
std::string::const_iterator end = str.end();
|
||||
while (it != end)
|
||||
{
|
||||
h = h * 0xf4243 ^ *it++;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// Hash.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Hash.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: Hash
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Hash.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
std::size_t hash(const std::string& str)
|
||||
{
|
||||
std::size_t h = 0;
|
||||
std::string::const_iterator it = str.begin();
|
||||
std::string::const_iterator end = str.end();
|
||||
while (it != end)
|
||||
{
|
||||
h = h * 0xf4243 ^ *it++;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,118 +1,118 @@
|
|||
//
|
||||
// SharedMemory.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemory
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#if POCO_OS == POCO_OS_SOLARIS
|
||||
#undef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 500
|
||||
#endif
|
||||
|
||||
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_NO_SHAREDMEMORY)
|
||||
#include "SharedMemory_DUMMY.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "SharedMemory_WIN32.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "SharedMemory_POSIX.cpp"
|
||||
#else
|
||||
#include "SharedMemory_DUMMY.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemory::SharedMemory():
|
||||
_pImpl(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint, bool server):
|
||||
_pImpl(new SharedMemoryImpl(name, size, mode, addrHint, server))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::SharedMemory(const Poco::File& file, AccessMode mode, const void* addrHint):
|
||||
_pImpl(new SharedMemoryImpl(file, mode, addrHint))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::SharedMemory(const SharedMemory& other):
|
||||
_pImpl(other._pImpl)
|
||||
{
|
||||
if (_pImpl)
|
||||
_pImpl->duplicate();
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::~SharedMemory()
|
||||
{
|
||||
if (_pImpl)
|
||||
_pImpl->release();
|
||||
}
|
||||
|
||||
|
||||
SharedMemory& SharedMemory::operator = (const SharedMemory& other)
|
||||
{
|
||||
SharedMemory tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
char* SharedMemory::begin() const
|
||||
{
|
||||
if (_pImpl)
|
||||
return _pImpl->begin();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char* SharedMemory::end() const
|
||||
{
|
||||
if (_pImpl)
|
||||
return _pImpl->end();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// SharedMemory.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemory
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#if POCO_OS == POCO_OS_SOLARIS
|
||||
#undef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 500
|
||||
#endif
|
||||
|
||||
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_NO_SHAREDMEMORY)
|
||||
#include "SharedMemory_DUMMY.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "SharedMemory_WIN32.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "SharedMemory_POSIX.cpp"
|
||||
#else
|
||||
#include "SharedMemory_DUMMY.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemory::SharedMemory():
|
||||
_pImpl(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint, bool server):
|
||||
_pImpl(new SharedMemoryImpl(name, size, mode, addrHint, server))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::SharedMemory(const Poco::File& file, AccessMode mode, const void* addrHint):
|
||||
_pImpl(new SharedMemoryImpl(file, mode, addrHint))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::SharedMemory(const SharedMemory& other):
|
||||
_pImpl(other._pImpl)
|
||||
{
|
||||
if (_pImpl)
|
||||
_pImpl->duplicate();
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::~SharedMemory()
|
||||
{
|
||||
if (_pImpl)
|
||||
_pImpl->release();
|
||||
}
|
||||
|
||||
|
||||
SharedMemory& SharedMemory::operator = (const SharedMemory& other)
|
||||
{
|
||||
SharedMemory tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
char* SharedMemory::begin() const
|
||||
{
|
||||
if (_pImpl)
|
||||
return _pImpl->begin();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char* SharedMemory::end() const
|
||||
{
|
||||
if (_pImpl)
|
||||
return _pImpl->end();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,58 +1,58 @@
|
|||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory_DUMMY.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/SharedMemory_DUMMY.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*, bool)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File&, SharedMemory::AccessMode, const void*)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::~SharedMemoryImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory_DUMMY.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/SharedMemory_DUMMY.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*, bool)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File&, SharedMemory::AccessMode, const void*)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::~SharedMemoryImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,156 +1,156 @@
|
|||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory_POSIX.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/SharedMemory_POSIX.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/File.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server):
|
||||
_size(size),
|
||||
_fd(-1),
|
||||
_address(0),
|
||||
_access(mode),
|
||||
_name("/"),
|
||||
_fileMapped(false),
|
||||
_server(server)
|
||||
{
|
||||
#if POCO_OS == POCO_OS_HPUX
|
||||
_name.append("tmp/");
|
||||
#endif
|
||||
|
||||
_name.append(name);
|
||||
|
||||
int flags = O_CREAT;
|
||||
if (_access == SharedMemory::AM_WRITE)
|
||||
flags |= O_RDWR;
|
||||
else
|
||||
flags |= O_RDONLY;
|
||||
|
||||
// open the shared memory segment
|
||||
_fd = ::shm_open(_name.c_str(), flags, S_IRUSR | S_IWUSR);
|
||||
if (_fd == -1)
|
||||
throw SystemException("Cannot create shared memory object", _name);
|
||||
|
||||
// now set the correct size for the segment
|
||||
if (-1 == ::ftruncate(_fd, size))
|
||||
{
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
::shm_unlink(_name.c_str());
|
||||
throw SystemException("Cannot resize shared memory object", _name);
|
||||
}
|
||||
map(addrHint);
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint):
|
||||
_size(0),
|
||||
_fd(-1),
|
||||
_address(0),
|
||||
_access(mode),
|
||||
_name(file.path()),
|
||||
_fileMapped(true),
|
||||
_server(false)
|
||||
{
|
||||
if (!file.exists() || !file.isFile())
|
||||
throw FileNotFoundException(file.path());
|
||||
|
||||
_size = file.getSize();
|
||||
int flag = O_RDONLY;
|
||||
if (mode == SharedMemory::AM_WRITE)
|
||||
flag = O_RDWR;
|
||||
_fd = ::open(_name.c_str(), flag);
|
||||
if (-1 == _fd)
|
||||
throw OpenFileException("Cannot open memory mapped file", _name);
|
||||
|
||||
map(addrHint);
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::~SharedMemoryImpl()
|
||||
{
|
||||
unmap();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::map(const void* addrHint)
|
||||
{
|
||||
int access = PROT_READ;
|
||||
if (_access == SharedMemory::AM_WRITE)
|
||||
access |= PROT_WRITE;
|
||||
|
||||
void* addr = ::mmap(const_cast<void*>(addrHint), _size, access, MAP_SHARED, _fd, 0);
|
||||
if (addr == MAP_FAILED)
|
||||
throw SystemException("Cannot map file into shared memory", _name);
|
||||
|
||||
_address = static_cast<char*>(addr);
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::unmap()
|
||||
{
|
||||
if (_address)
|
||||
{
|
||||
::munmap(_address, _size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::close()
|
||||
{
|
||||
if (_fd != -1)
|
||||
{
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
}
|
||||
if (!_fileMapped && _server)
|
||||
{
|
||||
::shm_unlink(_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory_POSIX.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/SharedMemory_POSIX.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/File.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server):
|
||||
_size(size),
|
||||
_fd(-1),
|
||||
_address(0),
|
||||
_access(mode),
|
||||
_name("/"),
|
||||
_fileMapped(false),
|
||||
_server(server)
|
||||
{
|
||||
#if POCO_OS == POCO_OS_HPUX
|
||||
_name.append("tmp/");
|
||||
#endif
|
||||
|
||||
_name.append(name);
|
||||
|
||||
int flags = O_CREAT;
|
||||
if (_access == SharedMemory::AM_WRITE)
|
||||
flags |= O_RDWR;
|
||||
else
|
||||
flags |= O_RDONLY;
|
||||
|
||||
// open the shared memory segment
|
||||
_fd = ::shm_open(_name.c_str(), flags, S_IRUSR | S_IWUSR);
|
||||
if (_fd == -1)
|
||||
throw SystemException("Cannot create shared memory object", _name);
|
||||
|
||||
// now set the correct size for the segment
|
||||
if (-1 == ::ftruncate(_fd, size))
|
||||
{
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
::shm_unlink(_name.c_str());
|
||||
throw SystemException("Cannot resize shared memory object", _name);
|
||||
}
|
||||
map(addrHint);
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void* addrHint):
|
||||
_size(0),
|
||||
_fd(-1),
|
||||
_address(0),
|
||||
_access(mode),
|
||||
_name(file.path()),
|
||||
_fileMapped(true),
|
||||
_server(false)
|
||||
{
|
||||
if (!file.exists() || !file.isFile())
|
||||
throw FileNotFoundException(file.path());
|
||||
|
||||
_size = file.getSize();
|
||||
int flag = O_RDONLY;
|
||||
if (mode == SharedMemory::AM_WRITE)
|
||||
flag = O_RDWR;
|
||||
_fd = ::open(_name.c_str(), flag);
|
||||
if (-1 == _fd)
|
||||
throw OpenFileException("Cannot open memory mapped file", _name);
|
||||
|
||||
map(addrHint);
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::~SharedMemoryImpl()
|
||||
{
|
||||
unmap();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::map(const void* addrHint)
|
||||
{
|
||||
int access = PROT_READ;
|
||||
if (_access == SharedMemory::AM_WRITE)
|
||||
access |= PROT_WRITE;
|
||||
|
||||
void* addr = ::mmap(const_cast<void*>(addrHint), _size, access, MAP_SHARED, _fd, 0);
|
||||
if (addr == MAP_FAILED)
|
||||
throw SystemException("Cannot map file into shared memory", _name);
|
||||
|
||||
_address = static_cast<char*>(addr);
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::unmap()
|
||||
{
|
||||
if (_address)
|
||||
{
|
||||
::munmap(_address, _size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::close()
|
||||
{
|
||||
if (_fd != -1)
|
||||
{
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
}
|
||||
if (!_fileMapped && _server)
|
||||
{
|
||||
::shm_unlink(_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,166 +1,166 @@
|
|||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory_WIN32.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/SharedMemory_WIN32.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/File.h"
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void*, bool):
|
||||
_name(name),
|
||||
_memHandle(INVALID_HANDLE_VALUE),
|
||||
_fileHandle(INVALID_HANDLE_VALUE),
|
||||
_size(static_cast<DWORD>(size)),
|
||||
_mode(PAGE_READONLY),
|
||||
_address(0)
|
||||
{
|
||||
if (mode == SharedMemory::AM_WRITE)
|
||||
_mode = PAGE_READWRITE;
|
||||
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
std::wstring utf16name;
|
||||
UnicodeConverter::toUTF16(_name, utf16name);
|
||||
_memHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, utf16name.c_str());
|
||||
#else
|
||||
_memHandle = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, _name.c_str());
|
||||
#endif
|
||||
|
||||
if (!_memHandle)
|
||||
throw SystemException("Cannot create shared memory object", _name);
|
||||
|
||||
map();
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void*):
|
||||
_name(file.path()),
|
||||
_memHandle(INVALID_HANDLE_VALUE),
|
||||
_fileHandle(INVALID_HANDLE_VALUE),
|
||||
_size(0),
|
||||
_mode(PAGE_READONLY),
|
||||
_address(0)
|
||||
{
|
||||
if (!file.exists() || !file.isFile())
|
||||
throw FileNotFoundException(_name);
|
||||
|
||||
_size = static_cast<DWORD>(file.getSize());
|
||||
|
||||
DWORD shareMode = FILE_SHARE_READ;
|
||||
DWORD fileMode = GENERIC_READ;
|
||||
|
||||
if (mode == SharedMemory::AM_WRITE)
|
||||
{
|
||||
_mode = PAGE_READWRITE;
|
||||
fileMode |= GENERIC_WRITE;
|
||||
}
|
||||
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
std::wstring utf16name;
|
||||
UnicodeConverter::toUTF16(_name, utf16name);
|
||||
_fileHandle = CreateFileW(utf16name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#else
|
||||
_fileHandle = CreateFileA(_name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#endif
|
||||
|
||||
if (_fileHandle == INVALID_HANDLE_VALUE)
|
||||
throw OpenFileException("Cannot open memory mapped file", _name);
|
||||
|
||||
_memHandle = CreateFileMapping(_fileHandle, NULL, _mode, 0, 0, NULL);
|
||||
if (!_memHandle)
|
||||
{
|
||||
CloseHandle(_fileHandle);
|
||||
_fileHandle = INVALID_HANDLE_VALUE;
|
||||
throw SystemException("Cannot map file into shared memory", _name);
|
||||
}
|
||||
map();
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::~SharedMemoryImpl()
|
||||
{
|
||||
unmap();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::map()
|
||||
{
|
||||
DWORD access = FILE_MAP_READ;
|
||||
if (_mode == PAGE_READWRITE)
|
||||
access = FILE_MAP_WRITE;
|
||||
LPVOID addr = MapViewOfFile(_memHandle, access, 0, 0, _size);
|
||||
if (!addr)
|
||||
throw SystemException("Cannot map shared memory object", _name);
|
||||
|
||||
_address = static_cast<char*>(addr);
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::unmap()
|
||||
{
|
||||
if (_address)
|
||||
{
|
||||
UnmapViewOfFile(_address);
|
||||
_address = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::close()
|
||||
{
|
||||
if (_memHandle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(_memHandle);
|
||||
_memHandle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
if (_fileHandle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(_fileHandle);
|
||||
_fileHandle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory_WIN32.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
// Module: SharedMemoryImpl
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/SharedMemory_WIN32.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/File.h"
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void*, bool):
|
||||
_name(name),
|
||||
_memHandle(INVALID_HANDLE_VALUE),
|
||||
_fileHandle(INVALID_HANDLE_VALUE),
|
||||
_size(static_cast<DWORD>(size)),
|
||||
_mode(PAGE_READONLY),
|
||||
_address(0)
|
||||
{
|
||||
if (mode == SharedMemory::AM_WRITE)
|
||||
_mode = PAGE_READWRITE;
|
||||
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
std::wstring utf16name;
|
||||
UnicodeConverter::toUTF16(_name, utf16name);
|
||||
_memHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, utf16name.c_str());
|
||||
#else
|
||||
_memHandle = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, _mode, 0, _size, _name.c_str());
|
||||
#endif
|
||||
|
||||
if (!_memHandle)
|
||||
throw SystemException("Cannot create shared memory object", _name);
|
||||
|
||||
map();
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessMode mode, const void*):
|
||||
_name(file.path()),
|
||||
_memHandle(INVALID_HANDLE_VALUE),
|
||||
_fileHandle(INVALID_HANDLE_VALUE),
|
||||
_size(0),
|
||||
_mode(PAGE_READONLY),
|
||||
_address(0)
|
||||
{
|
||||
if (!file.exists() || !file.isFile())
|
||||
throw FileNotFoundException(_name);
|
||||
|
||||
_size = static_cast<DWORD>(file.getSize());
|
||||
|
||||
DWORD shareMode = FILE_SHARE_READ;
|
||||
DWORD fileMode = GENERIC_READ;
|
||||
|
||||
if (mode == SharedMemory::AM_WRITE)
|
||||
{
|
||||
_mode = PAGE_READWRITE;
|
||||
fileMode |= GENERIC_WRITE;
|
||||
}
|
||||
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
std::wstring utf16name;
|
||||
UnicodeConverter::toUTF16(_name, utf16name);
|
||||
_fileHandle = CreateFileW(utf16name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#else
|
||||
_fileHandle = CreateFileA(_name.c_str(), fileMode, shareMode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#endif
|
||||
|
||||
if (_fileHandle == INVALID_HANDLE_VALUE)
|
||||
throw OpenFileException("Cannot open memory mapped file", _name);
|
||||
|
||||
_memHandle = CreateFileMapping(_fileHandle, NULL, _mode, 0, 0, NULL);
|
||||
if (!_memHandle)
|
||||
{
|
||||
CloseHandle(_fileHandle);
|
||||
_fileHandle = INVALID_HANDLE_VALUE;
|
||||
throw SystemException("Cannot map file into shared memory", _name);
|
||||
}
|
||||
map();
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryImpl::~SharedMemoryImpl()
|
||||
{
|
||||
unmap();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::map()
|
||||
{
|
||||
DWORD access = FILE_MAP_READ;
|
||||
if (_mode == PAGE_READWRITE)
|
||||
access = FILE_MAP_WRITE;
|
||||
LPVOID addr = MapViewOfFile(_memHandle, access, 0, 0, _size);
|
||||
if (!addr)
|
||||
throw SystemException("Cannot map shared memory object", _name);
|
||||
|
||||
_address = static_cast<char*>(addr);
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::unmap()
|
||||
{
|
||||
if (_address)
|
||||
{
|
||||
UnmapViewOfFile(_address);
|
||||
_address = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryImpl::close()
|
||||
{
|
||||
if (_memHandle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(_memHandle);
|
||||
_memHandle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
if (_fileHandle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(_fileHandle);
|
||||
_fileHandle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,203 +1,203 @@
|
|||
//
|
||||
// UTF8String.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/UTF8String.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: UTF8String
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/UTF8String.h"
|
||||
#include "Poco/Unicode.h"
|
||||
#include "Poco/TextIterator.h"
|
||||
#include "Poco/TextConverter.h"
|
||||
#include "Poco/UTF8Encoding.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
|
||||
std::string::size_type sz = str.size();
|
||||
if (pos > sz) pos = sz;
|
||||
if (pos + n > sz) n = sz - pos;
|
||||
TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8);
|
||||
TextIterator uend1(str.begin() + pos + n);
|
||||
TextIterator uit2(it2, end2, utf8);
|
||||
TextIterator uend2(end2);
|
||||
while (uit1 != uend1 && uit2 != uend2)
|
||||
{
|
||||
int c1 = Unicode::toLower(*uit1);
|
||||
int c2 = Unicode::toLower(*uit2);
|
||||
if (c1 < c2)
|
||||
return -1;
|
||||
else if (c1 > c2)
|
||||
return 1;
|
||||
++uit1; ++uit2;
|
||||
}
|
||||
|
||||
if (uit1 == uend1)
|
||||
return uit2 == uend2 ? 0 : -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, const std::string& str2)
|
||||
{
|
||||
return icompare(str1, 0, str1.size(), str2.begin(), str2.end());
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2)
|
||||
{
|
||||
if (n2 > str2.size()) n2 = str2.size();
|
||||
return icompare(str1, 0, n1, str2.begin(), str2.begin() + n2);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type n, const std::string& str2)
|
||||
{
|
||||
if (n > str2.size()) n = str2.size();
|
||||
return icompare(str1, 0, n, str2.begin(), str2.begin() + n);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2)
|
||||
{
|
||||
return icompare(str1, pos, n, str2.begin(), str2.end());
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2)
|
||||
{
|
||||
std::string::size_type sz2 = str2.size();
|
||||
if (pos2 > sz2) pos2 = sz2;
|
||||
if (pos2 + n2 > sz2) n2 = sz2 - pos2;
|
||||
return icompare(str1, pos1, n1, str2.begin() + pos2, str2.begin() + pos2 + n2);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2)
|
||||
{
|
||||
std::string::size_type sz2 = str2.size();
|
||||
if (pos2 > sz2) pos2 = sz2;
|
||||
if (pos2 + n > sz2) n = sz2 - pos2;
|
||||
return icompare(str1, pos1, n, str2.begin() + pos2, str2.begin() + pos2 + n);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
|
||||
poco_check_ptr (ptr);
|
||||
std::string::size_type sz = str.size();
|
||||
if (pos > sz) pos = sz;
|
||||
if (pos + n > sz) n = sz - pos;
|
||||
TextIterator uit(str.begin() + pos, str.begin() + pos + n, utf8);
|
||||
TextIterator uend(str.begin() + pos + n);
|
||||
while (uit != uend && *ptr)
|
||||
{
|
||||
int c1 = Unicode::toLower(*uit);
|
||||
int c2 = Unicode::toLower(*ptr);
|
||||
if (c1 < c2)
|
||||
return -1;
|
||||
else if (c1 > c2)
|
||||
return 1;
|
||||
++uit; ++ptr;
|
||||
}
|
||||
|
||||
if (uit == uend)
|
||||
return *ptr == 0 ? 0 : -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr)
|
||||
{
|
||||
return icompare(str, pos, str.size() - pos, ptr);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str, const std::string::value_type* ptr)
|
||||
{
|
||||
return icompare(str, 0, str.size(), ptr);
|
||||
}
|
||||
|
||||
|
||||
std::string UTF8::toUpper(const std::string& str)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
std::string result;
|
||||
TextConverter converter(utf8, utf8);
|
||||
converter.convert(str, result, Unicode::toUpper);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string& UTF8::toUpperInPlace(std::string& str)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
std::string result;
|
||||
TextConverter converter(utf8, utf8);
|
||||
converter.convert(str, result, Unicode::toUpper);
|
||||
std::swap(str, result);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
std::string UTF8::toLower(const std::string& str)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
std::string result;
|
||||
TextConverter converter(utf8, utf8);
|
||||
converter.convert(str, result, Unicode::toLower);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string& UTF8::toLowerInPlace(std::string& str)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
std::string result;
|
||||
TextConverter converter(utf8, utf8);
|
||||
converter.convert(str, result, Unicode::toLower);
|
||||
std::swap(str, result);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// UTF8String.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/UTF8String.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: UTF8String
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/UTF8String.h"
|
||||
#include "Poco/Unicode.h"
|
||||
#include "Poco/TextIterator.h"
|
||||
#include "Poco/TextConverter.h"
|
||||
#include "Poco/UTF8Encoding.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
|
||||
std::string::size_type sz = str.size();
|
||||
if (pos > sz) pos = sz;
|
||||
if (pos + n > sz) n = sz - pos;
|
||||
TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8);
|
||||
TextIterator uend1(str.begin() + pos + n);
|
||||
TextIterator uit2(it2, end2, utf8);
|
||||
TextIterator uend2(end2);
|
||||
while (uit1 != uend1 && uit2 != uend2)
|
||||
{
|
||||
int c1 = Unicode::toLower(*uit1);
|
||||
int c2 = Unicode::toLower(*uit2);
|
||||
if (c1 < c2)
|
||||
return -1;
|
||||
else if (c1 > c2)
|
||||
return 1;
|
||||
++uit1; ++uit2;
|
||||
}
|
||||
|
||||
if (uit1 == uend1)
|
||||
return uit2 == uend2 ? 0 : -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, const std::string& str2)
|
||||
{
|
||||
return icompare(str1, 0, str1.size(), str2.begin(), str2.end());
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2)
|
||||
{
|
||||
if (n2 > str2.size()) n2 = str2.size();
|
||||
return icompare(str1, 0, n1, str2.begin(), str2.begin() + n2);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type n, const std::string& str2)
|
||||
{
|
||||
if (n > str2.size()) n = str2.size();
|
||||
return icompare(str1, 0, n, str2.begin(), str2.begin() + n);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2)
|
||||
{
|
||||
return icompare(str1, pos, n, str2.begin(), str2.end());
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2)
|
||||
{
|
||||
std::string::size_type sz2 = str2.size();
|
||||
if (pos2 > sz2) pos2 = sz2;
|
||||
if (pos2 + n2 > sz2) n2 = sz2 - pos2;
|
||||
return icompare(str1, pos1, n1, str2.begin() + pos2, str2.begin() + pos2 + n2);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2)
|
||||
{
|
||||
std::string::size_type sz2 = str2.size();
|
||||
if (pos2 > sz2) pos2 = sz2;
|
||||
if (pos2 + n > sz2) n = sz2 - pos2;
|
||||
return icompare(str1, pos1, n, str2.begin() + pos2, str2.begin() + pos2 + n);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
|
||||
poco_check_ptr (ptr);
|
||||
std::string::size_type sz = str.size();
|
||||
if (pos > sz) pos = sz;
|
||||
if (pos + n > sz) n = sz - pos;
|
||||
TextIterator uit(str.begin() + pos, str.begin() + pos + n, utf8);
|
||||
TextIterator uend(str.begin() + pos + n);
|
||||
while (uit != uend && *ptr)
|
||||
{
|
||||
int c1 = Unicode::toLower(*uit);
|
||||
int c2 = Unicode::toLower(*ptr);
|
||||
if (c1 < c2)
|
||||
return -1;
|
||||
else if (c1 > c2)
|
||||
return 1;
|
||||
++uit; ++ptr;
|
||||
}
|
||||
|
||||
if (uit == uend)
|
||||
return *ptr == 0 ? 0 : -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr)
|
||||
{
|
||||
return icompare(str, pos, str.size() - pos, ptr);
|
||||
}
|
||||
|
||||
|
||||
int UTF8::icompare(const std::string& str, const std::string::value_type* ptr)
|
||||
{
|
||||
return icompare(str, 0, str.size(), ptr);
|
||||
}
|
||||
|
||||
|
||||
std::string UTF8::toUpper(const std::string& str)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
std::string result;
|
||||
TextConverter converter(utf8, utf8);
|
||||
converter.convert(str, result, Unicode::toUpper);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string& UTF8::toUpperInPlace(std::string& str)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
std::string result;
|
||||
TextConverter converter(utf8, utf8);
|
||||
converter.convert(str, result, Unicode::toUpper);
|
||||
std::swap(str, result);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
std::string UTF8::toLower(const std::string& str)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
std::string result;
|
||||
TextConverter converter(utf8, utf8);
|
||||
converter.convert(str, result, Unicode::toLower);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string& UTF8::toLowerInPlace(std::string& str)
|
||||
{
|
||||
static UTF8Encoding utf8;
|
||||
std::string result;
|
||||
TextConverter converter(utf8, utf8);
|
||||
converter.convert(str, result, Unicode::toLower);
|
||||
std::swap(str, result);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,94 +1,94 @@
|
|||
//
|
||||
// Unicode.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Unicode.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: Unicode
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Unicode.h"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "pcre_internal.h"
|
||||
}
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
void Unicode::properties(int ch, CharacterProperties& props)
|
||||
{
|
||||
int type;
|
||||
int script;
|
||||
int category = _pcre_ucp_findprop(static_cast<unsigned>(ch), &type, &script);
|
||||
props.category = static_cast<CharacterCategory>(category);
|
||||
props.type = static_cast<CharacterType>(type);
|
||||
props.script = static_cast<Script>(script);
|
||||
}
|
||||
|
||||
|
||||
bool Unicode::isLower(int ch)
|
||||
{
|
||||
CharacterProperties props;
|
||||
properties(ch, props);
|
||||
return props.category == UCP_LETTER && props.type == UCP_LOWER_CASE_LETTER;
|
||||
}
|
||||
|
||||
|
||||
bool Unicode::isUpper(int ch)
|
||||
{
|
||||
CharacterProperties props;
|
||||
properties(ch, props);
|
||||
return props.category == UCP_LETTER && props.type == UCP_UPPER_CASE_LETTER;
|
||||
}
|
||||
|
||||
|
||||
int Unicode::toLower(int ch)
|
||||
{
|
||||
if (isUpper(ch))
|
||||
return static_cast<int>(_pcre_ucp_othercase(static_cast<unsigned>(ch)));
|
||||
else
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
int Unicode::toUpper(int ch)
|
||||
{
|
||||
if (isLower(ch))
|
||||
return static_cast<int>(_pcre_ucp_othercase(static_cast<unsigned>(ch)));
|
||||
else
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// Unicode.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Unicode.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: Unicode
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Unicode.h"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "pcre_internal.h"
|
||||
}
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
void Unicode::properties(int ch, CharacterProperties& props)
|
||||
{
|
||||
int type;
|
||||
int script;
|
||||
int category = _pcre_ucp_findprop(static_cast<unsigned>(ch), &type, &script);
|
||||
props.category = static_cast<CharacterCategory>(category);
|
||||
props.type = static_cast<CharacterType>(type);
|
||||
props.script = static_cast<Script>(script);
|
||||
}
|
||||
|
||||
|
||||
bool Unicode::isLower(int ch)
|
||||
{
|
||||
CharacterProperties props;
|
||||
properties(ch, props);
|
||||
return props.category == UCP_LETTER && props.type == UCP_LOWER_CASE_LETTER;
|
||||
}
|
||||
|
||||
|
||||
bool Unicode::isUpper(int ch)
|
||||
{
|
||||
CharacterProperties props;
|
||||
properties(ch, props);
|
||||
return props.category == UCP_LETTER && props.type == UCP_UPPER_CASE_LETTER;
|
||||
}
|
||||
|
||||
|
||||
int Unicode::toLower(int ch)
|
||||
{
|
||||
if (isUpper(ch))
|
||||
return static_cast<int>(_pcre_ucp_othercase(static_cast<unsigned>(ch)));
|
||||
else
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
int Unicode::toUpper(int ch)
|
||||
{
|
||||
if (isLower(ch))
|
||||
return static_cast<int>(_pcre_ucp_othercase(static_cast<unsigned>(ch)));
|
||||
else
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,88 +1,88 @@
|
|||
//
|
||||
// WindowsConsoleChannel.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/WindowsConsoleChannel.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: WindowsConsoleChannel
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/WindowsConsoleChannel.h"
|
||||
#include "Poco/Message.h"
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
WindowsConsoleChannel::WindowsConsoleChannel():
|
||||
_isFile(false),
|
||||
_hConsole(INVALID_HANDLE_VALUE)
|
||||
{
|
||||
_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
// check whether the console has been redirected
|
||||
DWORD mode;
|
||||
_isFile = (GetConsoleMode(_hConsole, &mode) == 0);
|
||||
}
|
||||
|
||||
|
||||
WindowsConsoleChannel::~WindowsConsoleChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void WindowsConsoleChannel::log(const Message& msg)
|
||||
{
|
||||
std::string text = msg.getText();
|
||||
text += "\r\n";
|
||||
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
if (_isFile)
|
||||
{
|
||||
DWORD written;
|
||||
WriteFile(_hConsole, text.data(), text.size(), &written, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring utext;
|
||||
UnicodeConverter::toUTF16(text, utext);
|
||||
DWORD written;
|
||||
WriteConsoleW(_hConsole, utext.data(), utext.size(), &written, NULL);
|
||||
}
|
||||
#else
|
||||
DWORD written;
|
||||
WriteFile(_hConsole, text.data(), text.size(), &written, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
//
|
||||
// WindowsConsoleChannel.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/WindowsConsoleChannel.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: WindowsConsoleChannel
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/WindowsConsoleChannel.h"
|
||||
#include "Poco/Message.h"
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
WindowsConsoleChannel::WindowsConsoleChannel():
|
||||
_isFile(false),
|
||||
_hConsole(INVALID_HANDLE_VALUE)
|
||||
{
|
||||
_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
// check whether the console has been redirected
|
||||
DWORD mode;
|
||||
_isFile = (GetConsoleMode(_hConsole, &mode) == 0);
|
||||
}
|
||||
|
||||
|
||||
WindowsConsoleChannel::~WindowsConsoleChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void WindowsConsoleChannel::log(const Message& msg)
|
||||
{
|
||||
std::string text = msg.getText();
|
||||
text += "\r\n";
|
||||
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
if (_isFile)
|
||||
{
|
||||
DWORD written;
|
||||
WriteFile(_hConsole, text.data(), text.size(), &written, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring utext;
|
||||
UnicodeConverter::toUTF16(text, utext);
|
||||
DWORD written;
|
||||
WriteConsoleW(_hConsole, utext.data(), utext.size(), &written, NULL);
|
||||
}
|
||||
#else
|
||||
DWORD written;
|
||||
WriteFile(_hConsole, text.data(), text.size(), &written, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
|
|
@ -1,183 +1,183 @@
|
|||
//
|
||||
// AsyncIOChannelTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "AsyncIOChannelTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/AsyncStreamChannel.h"
|
||||
#include "Poco/AsyncIOCommand.h"
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::AsyncStreamChannel;
|
||||
using Poco::AsyncIOCommand;
|
||||
using Poco::AsyncReadCommand;
|
||||
using Poco::AsyncWriteCommand;
|
||||
using Poco::AsyncSeekCommand;
|
||||
using Poco::AsyncIOEvent;
|
||||
using Poco::ActiveResult;
|
||||
using Poco::delegate;
|
||||
|
||||
|
||||
AsyncIOChannelTest::AsyncIOChannelTest(const std::string& name):
|
||||
CppUnit::TestCase(name),
|
||||
_completed(0),
|
||||
_failed(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncIOChannelTest::~AsyncIOChannelTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::testWrite()
|
||||
{
|
||||
std::stringstream str;
|
||||
AsyncStreamChannel channel(str);
|
||||
channel.enqueue(new AsyncWriteCommand("Hello", 5));
|
||||
channel.enqueue(new AsyncWriteCommand(", ", 2));
|
||||
ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
|
||||
result.wait();
|
||||
std::string s(str.str());
|
||||
assert (s == "Hello, world!");
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::testRead()
|
||||
{
|
||||
std::istringstream istr("Hello, world!");
|
||||
char buffer[16];
|
||||
AsyncStreamChannel channel(istr);
|
||||
ActiveResult<int> result = channel.enqueue(new AsyncReadCommand(buffer, sizeof(buffer)));
|
||||
result.wait();
|
||||
std::string s(buffer, result.data());
|
||||
assert (s == "Hello, world!");
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::testSeek()
|
||||
{
|
||||
std::istringstream istr("Hello, world!");
|
||||
char buffer[16];
|
||||
AsyncStreamChannel channel(istr);
|
||||
channel.enqueue(new AsyncSeekCommand(7, std::ios::beg));
|
||||
ActiveResult<int> result = channel.enqueue(new AsyncReadCommand(buffer, 5));
|
||||
result.wait();
|
||||
std::string s(buffer, result.data());
|
||||
assert (s == "world");
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::testEvents()
|
||||
{
|
||||
std::stringstream str;
|
||||
AsyncStreamChannel channel(str);
|
||||
AsyncIOCommand::Ptr pWrite(new AsyncWriteCommand("Hello, world!", 13));
|
||||
pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||
channel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||
assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
|
||||
ActiveResult<int> result = channel.enqueue(pWrite);
|
||||
pWrite->wait();
|
||||
result.wait();
|
||||
assert (pWrite->succeeded());
|
||||
assert (!pWrite->failed());
|
||||
assert (pWrite->state() == AsyncIOCommand::CMD_COMPLETED);
|
||||
assert (pWrite->result() == 13);
|
||||
assert (pWrite->exception() == 0);
|
||||
assert (_completed == 2);
|
||||
|
||||
reset();
|
||||
|
||||
std::istringstream istr;
|
||||
AsyncStreamChannel ichannel(istr);
|
||||
pWrite = new AsyncWriteCommand("Hello, world!", 13);
|
||||
pWrite->commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
|
||||
ichannel.commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
|
||||
pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||
ichannel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||
assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
|
||||
result = ichannel.enqueue(pWrite);
|
||||
pWrite->wait();
|
||||
result.wait();
|
||||
assert (!pWrite->succeeded());
|
||||
assert (pWrite->failed());
|
||||
assert (pWrite->exception() != 0);
|
||||
assert (_completed == 0);
|
||||
assert (_failed == 2);
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::setUp()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::reset()
|
||||
{
|
||||
_completed = 0;
|
||||
_failed = 0;
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::onCompleted(const void* sender, Poco::AsyncIOEvent& event)
|
||||
{
|
||||
++_completed;
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::onFailed(const void* sender, Poco::AsyncIOEvent& event)
|
||||
{
|
||||
++_failed;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* AsyncIOChannelTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOChannelTest");
|
||||
|
||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testWrite);
|
||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testRead);
|
||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testSeek);
|
||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testEvents);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// AsyncIOChannelTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "AsyncIOChannelTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/AsyncStreamChannel.h"
|
||||
#include "Poco/AsyncIOCommand.h"
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::AsyncStreamChannel;
|
||||
using Poco::AsyncIOCommand;
|
||||
using Poco::AsyncReadCommand;
|
||||
using Poco::AsyncWriteCommand;
|
||||
using Poco::AsyncSeekCommand;
|
||||
using Poco::AsyncIOEvent;
|
||||
using Poco::ActiveResult;
|
||||
using Poco::delegate;
|
||||
|
||||
|
||||
AsyncIOChannelTest::AsyncIOChannelTest(const std::string& name):
|
||||
CppUnit::TestCase(name),
|
||||
_completed(0),
|
||||
_failed(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AsyncIOChannelTest::~AsyncIOChannelTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::testWrite()
|
||||
{
|
||||
std::stringstream str;
|
||||
AsyncStreamChannel channel(str);
|
||||
channel.enqueue(new AsyncWriteCommand("Hello", 5));
|
||||
channel.enqueue(new AsyncWriteCommand(", ", 2));
|
||||
ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
|
||||
result.wait();
|
||||
std::string s(str.str());
|
||||
assert (s == "Hello, world!");
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::testRead()
|
||||
{
|
||||
std::istringstream istr("Hello, world!");
|
||||
char buffer[16];
|
||||
AsyncStreamChannel channel(istr);
|
||||
ActiveResult<int> result = channel.enqueue(new AsyncReadCommand(buffer, sizeof(buffer)));
|
||||
result.wait();
|
||||
std::string s(buffer, result.data());
|
||||
assert (s == "Hello, world!");
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::testSeek()
|
||||
{
|
||||
std::istringstream istr("Hello, world!");
|
||||
char buffer[16];
|
||||
AsyncStreamChannel channel(istr);
|
||||
channel.enqueue(new AsyncSeekCommand(7, std::ios::beg));
|
||||
ActiveResult<int> result = channel.enqueue(new AsyncReadCommand(buffer, 5));
|
||||
result.wait();
|
||||
std::string s(buffer, result.data());
|
||||
assert (s == "world");
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::testEvents()
|
||||
{
|
||||
std::stringstream str;
|
||||
AsyncStreamChannel channel(str);
|
||||
AsyncIOCommand::Ptr pWrite(new AsyncWriteCommand("Hello, world!", 13));
|
||||
pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||
channel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||
assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
|
||||
ActiveResult<int> result = channel.enqueue(pWrite);
|
||||
pWrite->wait();
|
||||
result.wait();
|
||||
assert (pWrite->succeeded());
|
||||
assert (!pWrite->failed());
|
||||
assert (pWrite->state() == AsyncIOCommand::CMD_COMPLETED);
|
||||
assert (pWrite->result() == 13);
|
||||
assert (pWrite->exception() == 0);
|
||||
assert (_completed == 2);
|
||||
|
||||
reset();
|
||||
|
||||
std::istringstream istr;
|
||||
AsyncStreamChannel ichannel(istr);
|
||||
pWrite = new AsyncWriteCommand("Hello, world!", 13);
|
||||
pWrite->commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
|
||||
ichannel.commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
|
||||
pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||
ichannel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
|
||||
assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
|
||||
result = ichannel.enqueue(pWrite);
|
||||
pWrite->wait();
|
||||
result.wait();
|
||||
assert (!pWrite->succeeded());
|
||||
assert (pWrite->failed());
|
||||
assert (pWrite->exception() != 0);
|
||||
assert (_completed == 0);
|
||||
assert (_failed == 2);
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::setUp()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::reset()
|
||||
{
|
||||
_completed = 0;
|
||||
_failed = 0;
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::onCompleted(const void* sender, Poco::AsyncIOEvent& event)
|
||||
{
|
||||
++_completed;
|
||||
}
|
||||
|
||||
|
||||
void AsyncIOChannelTest::onFailed(const void* sender, Poco::AsyncIOEvent& event)
|
||||
{
|
||||
++_failed;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* AsyncIOChannelTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOChannelTest");
|
||||
|
||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testWrite);
|
||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testRead);
|
||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testSeek);
|
||||
CppUnit_addTest(pSuite, AsyncIOChannelTest, testEvents);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,71 +1,71 @@
|
|||
//
|
||||
// AsyncIOChannelTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.h#2 $
|
||||
//
|
||||
// Definition of the AsyncIOChannelTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef AsyncIOChannelTest_INCLUDED
|
||||
#define AsyncIOChannelTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
|
||||
|
||||
class AsyncIOChannelTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
AsyncIOChannelTest(const std::string& name);
|
||||
~AsyncIOChannelTest();
|
||||
|
||||
void testWrite();
|
||||
void testRead();
|
||||
void testSeek();
|
||||
void testEvents();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
protected:
|
||||
void reset();
|
||||
void onCompleted(const void* sender, Poco::AsyncIOEvent& event);
|
||||
void onFailed(const void* sender, Poco::AsyncIOEvent& event);
|
||||
|
||||
private:
|
||||
int _completed;
|
||||
int _failed;
|
||||
};
|
||||
|
||||
|
||||
#endif // AsyncIOChannelTest_INCLUDED
|
||||
//
|
||||
// AsyncIOChannelTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.h#2 $
|
||||
//
|
||||
// Definition of the AsyncIOChannelTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef AsyncIOChannelTest_INCLUDED
|
||||
#define AsyncIOChannelTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/AsyncIOEvent.h"
|
||||
|
||||
|
||||
class AsyncIOChannelTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
AsyncIOChannelTest(const std::string& name);
|
||||
~AsyncIOChannelTest();
|
||||
|
||||
void testWrite();
|
||||
void testRead();
|
||||
void testSeek();
|
||||
void testEvents();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
protected:
|
||||
void reset();
|
||||
void onCompleted(const void* sender, Poco::AsyncIOEvent& event);
|
||||
void onFailed(const void* sender, Poco::AsyncIOEvent& event);
|
||||
|
||||
private:
|
||||
int _completed;
|
||||
int _failed;
|
||||
};
|
||||
|
||||
|
||||
#endif // AsyncIOChannelTest_INCLUDED
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
//
|
||||
// AsyncIOTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "AsyncIOTestSuite.h"
|
||||
#include "AsyncIOChannelTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* AsyncIOTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOTestSuite");
|
||||
|
||||
pSuite->addTest(AsyncIOChannelTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// AsyncIOTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "AsyncIOTestSuite.h"
|
||||
#include "AsyncIOChannelTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* AsyncIOTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOTestSuite");
|
||||
|
||||
pSuite->addTest(AsyncIOChannelTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
//
|
||||
// AsyncIOTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the AsyncIOTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef AsyncIOTestSuite_INCLUDED
|
||||
#define AsyncIOTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class AsyncIOTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // AsyncIOTestSuite_INCLUDED
|
||||
//
|
||||
// AsyncIOTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the AsyncIOTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef AsyncIOTestSuite_INCLUDED
|
||||
#define AsyncIOTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class AsyncIOTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // AsyncIOTestSuite_INCLUDED
|
||||
|
|
|
@ -1,214 +1,214 @@
|
|||
//
|
||||
// ConditionTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/ConditionTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ConditionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Runnable.h"
|
||||
#include "Poco/Condition.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::Thread;
|
||||
using Poco::Runnable;
|
||||
using Poco::Condition;
|
||||
using Poco::Mutex;
|
||||
using Poco::TimeoutException;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class WaitRunnable: public Runnable
|
||||
{
|
||||
public:
|
||||
WaitRunnable(Condition& cond, Mutex& mutex):
|
||||
_ran(false),
|
||||
_cond(cond),
|
||||
_mutex(mutex)
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
_mutex.lock();
|
||||
_cond.wait(_mutex);
|
||||
_mutex.unlock();
|
||||
_ran = true;
|
||||
}
|
||||
|
||||
bool ran() const
|
||||
{
|
||||
return _ran;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _ran;
|
||||
Condition& _cond;
|
||||
Mutex& _mutex;
|
||||
};
|
||||
|
||||
class TryWaitRunnable: public Runnable
|
||||
{
|
||||
public:
|
||||
TryWaitRunnable(Condition& cond, Mutex& mutex):
|
||||
_ran(false),
|
||||
_cond(cond),
|
||||
_mutex(mutex)
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
_mutex.lock();
|
||||
if (_cond.tryWait(_mutex, 10000))
|
||||
{
|
||||
_ran = true;
|
||||
}
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
bool ran() const
|
||||
{
|
||||
return _ran;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _ran;
|
||||
Condition& _cond;
|
||||
Mutex& _mutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
ConditionTest::ConditionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ConditionTest::~ConditionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ConditionTest::testSignal()
|
||||
{
|
||||
Condition cond;
|
||||
Mutex mtx;
|
||||
WaitRunnable r1(cond, mtx);
|
||||
WaitRunnable r2(cond, mtx);
|
||||
|
||||
Thread t1;
|
||||
Thread t2;
|
||||
|
||||
t1.start(r1);
|
||||
Thread::sleep(200);
|
||||
t2.start(r2);
|
||||
|
||||
assert (!r1.ran());
|
||||
assert (!r2.ran());
|
||||
|
||||
cond.signal();
|
||||
|
||||
t1.join();
|
||||
assert (r1.ran());
|
||||
|
||||
assert (!t2.tryJoin(200));
|
||||
|
||||
cond.signal();
|
||||
|
||||
t2.join();
|
||||
|
||||
assert (r2.ran());
|
||||
}
|
||||
|
||||
|
||||
void ConditionTest::testBroadcast()
|
||||
{
|
||||
Condition cond;
|
||||
Mutex mtx;
|
||||
WaitRunnable r1(cond, mtx);
|
||||
WaitRunnable r2(cond, mtx);
|
||||
TryWaitRunnable r3(cond, mtx);
|
||||
|
||||
Thread t1;
|
||||
Thread t2;
|
||||
Thread t3;
|
||||
|
||||
t1.start(r1);
|
||||
Thread::sleep(200);
|
||||
t2.start(r2);
|
||||
Thread::sleep(200);
|
||||
t3.start(r3);
|
||||
|
||||
assert (!r1.ran());
|
||||
assert (!r2.ran());
|
||||
assert (!r3.ran());
|
||||
|
||||
cond.signal();
|
||||
t1.join();
|
||||
|
||||
assert (r1.ran());
|
||||
assert (!t2.tryJoin(500));
|
||||
assert (!t3.tryJoin(500));
|
||||
|
||||
cond.broadcast();
|
||||
|
||||
t2.join();
|
||||
t3.join();
|
||||
|
||||
assert (r2.ran());
|
||||
assert (r3.ran());
|
||||
}
|
||||
|
||||
|
||||
void ConditionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ConditionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ConditionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConditionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ConditionTest, testSignal);
|
||||
CppUnit_addTest(pSuite, ConditionTest, testBroadcast);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// ConditionTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/ConditionTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ConditionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Runnable.h"
|
||||
#include "Poco/Condition.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::Thread;
|
||||
using Poco::Runnable;
|
||||
using Poco::Condition;
|
||||
using Poco::Mutex;
|
||||
using Poco::TimeoutException;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class WaitRunnable: public Runnable
|
||||
{
|
||||
public:
|
||||
WaitRunnable(Condition& cond, Mutex& mutex):
|
||||
_ran(false),
|
||||
_cond(cond),
|
||||
_mutex(mutex)
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
_mutex.lock();
|
||||
_cond.wait(_mutex);
|
||||
_mutex.unlock();
|
||||
_ran = true;
|
||||
}
|
||||
|
||||
bool ran() const
|
||||
{
|
||||
return _ran;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _ran;
|
||||
Condition& _cond;
|
||||
Mutex& _mutex;
|
||||
};
|
||||
|
||||
class TryWaitRunnable: public Runnable
|
||||
{
|
||||
public:
|
||||
TryWaitRunnable(Condition& cond, Mutex& mutex):
|
||||
_ran(false),
|
||||
_cond(cond),
|
||||
_mutex(mutex)
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
_mutex.lock();
|
||||
if (_cond.tryWait(_mutex, 10000))
|
||||
{
|
||||
_ran = true;
|
||||
}
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
bool ran() const
|
||||
{
|
||||
return _ran;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _ran;
|
||||
Condition& _cond;
|
||||
Mutex& _mutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
ConditionTest::ConditionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ConditionTest::~ConditionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ConditionTest::testSignal()
|
||||
{
|
||||
Condition cond;
|
||||
Mutex mtx;
|
||||
WaitRunnable r1(cond, mtx);
|
||||
WaitRunnable r2(cond, mtx);
|
||||
|
||||
Thread t1;
|
||||
Thread t2;
|
||||
|
||||
t1.start(r1);
|
||||
Thread::sleep(200);
|
||||
t2.start(r2);
|
||||
|
||||
assert (!r1.ran());
|
||||
assert (!r2.ran());
|
||||
|
||||
cond.signal();
|
||||
|
||||
t1.join();
|
||||
assert (r1.ran());
|
||||
|
||||
assert (!t2.tryJoin(200));
|
||||
|
||||
cond.signal();
|
||||
|
||||
t2.join();
|
||||
|
||||
assert (r2.ran());
|
||||
}
|
||||
|
||||
|
||||
void ConditionTest::testBroadcast()
|
||||
{
|
||||
Condition cond;
|
||||
Mutex mtx;
|
||||
WaitRunnable r1(cond, mtx);
|
||||
WaitRunnable r2(cond, mtx);
|
||||
TryWaitRunnable r3(cond, mtx);
|
||||
|
||||
Thread t1;
|
||||
Thread t2;
|
||||
Thread t3;
|
||||
|
||||
t1.start(r1);
|
||||
Thread::sleep(200);
|
||||
t2.start(r2);
|
||||
Thread::sleep(200);
|
||||
t3.start(r3);
|
||||
|
||||
assert (!r1.ran());
|
||||
assert (!r2.ran());
|
||||
assert (!r3.ran());
|
||||
|
||||
cond.signal();
|
||||
t1.join();
|
||||
|
||||
assert (r1.ran());
|
||||
assert (!t2.tryJoin(500));
|
||||
assert (!t3.tryJoin(500));
|
||||
|
||||
cond.broadcast();
|
||||
|
||||
t2.join();
|
||||
t3.join();
|
||||
|
||||
assert (r2.ran());
|
||||
assert (r3.ran());
|
||||
}
|
||||
|
||||
|
||||
void ConditionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ConditionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ConditionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConditionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ConditionTest, testSignal);
|
||||
CppUnit_addTest(pSuite, ConditionTest, testBroadcast);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,61 +1,61 @@
|
|||
//
|
||||
// ConditionTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/ConditionTest.h#2 $
|
||||
//
|
||||
// Definition of the ConditionTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ConditionTest_INCLUDED
|
||||
#define ConditionTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class ConditionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
ConditionTest(const std::string& name);
|
||||
~ConditionTest();
|
||||
|
||||
void testSignal();
|
||||
void testBroadcast();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // ConditionTest_INCLUDED
|
||||
//
|
||||
// ConditionTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/ConditionTest.h#2 $
|
||||
//
|
||||
// Definition of the ConditionTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ConditionTest_INCLUDED
|
||||
#define ConditionTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class ConditionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
ConditionTest(const std::string& name);
|
||||
~ConditionTest();
|
||||
|
||||
void testSignal();
|
||||
void testBroadcast();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // ConditionTest_INCLUDED
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,162 +1,162 @@
|
|||
//
|
||||
// DynamicAnyTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/DynamicAnyTest.h#2 $
|
||||
//
|
||||
// Tests for Any types
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef DynamicAnyTest_INCLUDED
|
||||
#define DynamicAnyTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class DynamicAnyTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DynamicAnyTest(const std::string& name);
|
||||
~DynamicAnyTest();
|
||||
|
||||
void testInt8();
|
||||
void testInt16();
|
||||
void testInt32();
|
||||
void testInt64();
|
||||
void testUInt8();
|
||||
void testUInt16();
|
||||
void testUInt32();
|
||||
void testUInt64();
|
||||
void testBool();
|
||||
void testChar();
|
||||
void testFloat();
|
||||
void testDouble();
|
||||
void testLong();
|
||||
void testULong();
|
||||
void testString();
|
||||
void testConversionOperator();
|
||||
void testComparisonOperators();
|
||||
void testArithmeticOperators();
|
||||
void testLimitsInt();
|
||||
void testLimitsFloat();
|
||||
void testCtor();
|
||||
void testIsStruct();
|
||||
void testIsArray();
|
||||
void testArrayIdxOperator();
|
||||
void testDynamicStructBasics();
|
||||
void testDynamicStruct();
|
||||
void testArrayToString();
|
||||
void testStructToString();
|
||||
void testArrayOfStructsToString();
|
||||
void testStructWithArraysToString();
|
||||
void testJSONDeserializeString();
|
||||
void testJSONDeserializePrimitives();
|
||||
void testJSONDeserializeArray();
|
||||
void testJSONDeserializeStruct();
|
||||
void testJSONDeserializeComplex();
|
||||
void testDate();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void testGetIdxMustThrow(Poco::DynamicAny& a1, std::vector<Poco::DynamicAny>::size_type n);
|
||||
template<typename T>
|
||||
void testGetIdx(Poco::DynamicAny& a1, std::vector<Poco::DynamicAny>::size_type n, const T& expectedResult)
|
||||
{
|
||||
Poco::DynamicAny& val1 = a1[n];
|
||||
assert (val1 == expectedResult);
|
||||
|
||||
const Poco::DynamicAny& c1 = a1;
|
||||
assert (a1 == c1); // silence the compiler
|
||||
const Poco::DynamicAny& cval1 = a1[n];
|
||||
assert (cval1 == expectedResult);
|
||||
}
|
||||
|
||||
|
||||
template<typename TL, typename TS>
|
||||
void testLimitsSigned()
|
||||
{
|
||||
TL iMin = std::numeric_limits<TS>::min();
|
||||
Poco::DynamicAny da = iMin - 1;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
|
||||
TL iMax = std::numeric_limits<TS>::max();
|
||||
da = iMax + 1;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
|
||||
template<typename TL, typename TS>
|
||||
void testLimitsFloatToInt()
|
||||
{
|
||||
Poco::DynamicAny da;
|
||||
|
||||
if (std::numeric_limits<TS>::is_signed)
|
||||
{
|
||||
TL iMin = static_cast<TL>(std::numeric_limits<TS>::min());
|
||||
da = iMin * 10;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
|
||||
TL iMax = static_cast<TL>(std::numeric_limits<TS>::max());
|
||||
da = iMax * 10;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
|
||||
template<typename TS, typename TU>
|
||||
void testLimitsSignedUnsigned()
|
||||
{
|
||||
assert (std::numeric_limits<TS>::is_signed);
|
||||
assert (!std::numeric_limits<TU>::is_signed);
|
||||
|
||||
TS iMin = std::numeric_limits<TS>::min();
|
||||
Poco::DynamicAny da = iMin;
|
||||
try { TU i; i = da.convert<TU>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
|
||||
template<typename TL, typename TS>
|
||||
void testLimitsUnsigned()
|
||||
{
|
||||
TL iMax = std::numeric_limits<TS>::max();
|
||||
Poco::DynamicAny da = iMax + 1;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // DynamicAnyTest_INCLUDED
|
||||
//
|
||||
// DynamicAnyTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/DynamicAnyTest.h#2 $
|
||||
//
|
||||
// Tests for Any types
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef DynamicAnyTest_INCLUDED
|
||||
#define DynamicAnyTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class DynamicAnyTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DynamicAnyTest(const std::string& name);
|
||||
~DynamicAnyTest();
|
||||
|
||||
void testInt8();
|
||||
void testInt16();
|
||||
void testInt32();
|
||||
void testInt64();
|
||||
void testUInt8();
|
||||
void testUInt16();
|
||||
void testUInt32();
|
||||
void testUInt64();
|
||||
void testBool();
|
||||
void testChar();
|
||||
void testFloat();
|
||||
void testDouble();
|
||||
void testLong();
|
||||
void testULong();
|
||||
void testString();
|
||||
void testConversionOperator();
|
||||
void testComparisonOperators();
|
||||
void testArithmeticOperators();
|
||||
void testLimitsInt();
|
||||
void testLimitsFloat();
|
||||
void testCtor();
|
||||
void testIsStruct();
|
||||
void testIsArray();
|
||||
void testArrayIdxOperator();
|
||||
void testDynamicStructBasics();
|
||||
void testDynamicStruct();
|
||||
void testArrayToString();
|
||||
void testStructToString();
|
||||
void testArrayOfStructsToString();
|
||||
void testStructWithArraysToString();
|
||||
void testJSONDeserializeString();
|
||||
void testJSONDeserializePrimitives();
|
||||
void testJSONDeserializeArray();
|
||||
void testJSONDeserializeStruct();
|
||||
void testJSONDeserializeComplex();
|
||||
void testDate();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void testGetIdxMustThrow(Poco::DynamicAny& a1, std::vector<Poco::DynamicAny>::size_type n);
|
||||
template<typename T>
|
||||
void testGetIdx(Poco::DynamicAny& a1, std::vector<Poco::DynamicAny>::size_type n, const T& expectedResult)
|
||||
{
|
||||
Poco::DynamicAny& val1 = a1[n];
|
||||
assert (val1 == expectedResult);
|
||||
|
||||
const Poco::DynamicAny& c1 = a1;
|
||||
assert (a1 == c1); // silence the compiler
|
||||
const Poco::DynamicAny& cval1 = a1[n];
|
||||
assert (cval1 == expectedResult);
|
||||
}
|
||||
|
||||
|
||||
template<typename TL, typename TS>
|
||||
void testLimitsSigned()
|
||||
{
|
||||
TL iMin = std::numeric_limits<TS>::min();
|
||||
Poco::DynamicAny da = iMin - 1;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
|
||||
TL iMax = std::numeric_limits<TS>::max();
|
||||
da = iMax + 1;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
|
||||
template<typename TL, typename TS>
|
||||
void testLimitsFloatToInt()
|
||||
{
|
||||
Poco::DynamicAny da;
|
||||
|
||||
if (std::numeric_limits<TS>::is_signed)
|
||||
{
|
||||
TL iMin = static_cast<TL>(std::numeric_limits<TS>::min());
|
||||
da = iMin * 10;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
|
||||
TL iMax = static_cast<TL>(std::numeric_limits<TS>::max());
|
||||
da = iMax * 10;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
|
||||
template<typename TS, typename TU>
|
||||
void testLimitsSignedUnsigned()
|
||||
{
|
||||
assert (std::numeric_limits<TS>::is_signed);
|
||||
assert (!std::numeric_limits<TU>::is_signed);
|
||||
|
||||
TS iMin = std::numeric_limits<TS>::min();
|
||||
Poco::DynamicAny da = iMin;
|
||||
try { TU i; i = da.convert<TU>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
|
||||
template<typename TL, typename TS>
|
||||
void testLimitsUnsigned()
|
||||
{
|
||||
TL iMax = std::numeric_limits<TS>::max();
|
||||
Poco::DynamicAny da = iMax + 1;
|
||||
try { TS i; i = da.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // DynamicAnyTest_INCLUDED
|
||||
|
|
|
@ -1,333 +1,333 @@
|
|||
//
|
||||
// FileStreamTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/FileStreamTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "FileStreamTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/TemporaryFile.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
FileStreamTest::FileStreamTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamTest::~FileStreamTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testRead()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||
char tmp[]={'\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||
std::string file(tmp);
|
||||
file.append(".txt");
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
char tmp[]={'\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||
std::string file(tmp);
|
||||
file.append(".txt");
|
||||
#else
|
||||
std::string file("testfile.txt");
|
||||
#endif
|
||||
|
||||
Poco::TemporaryFile::registerForDeletion(file);
|
||||
|
||||
Poco::FileOutputStream fos(file, std::ios::binary);
|
||||
fos << "sometestdata";
|
||||
fos.close();
|
||||
|
||||
Poco::FileInputStream fis(file);
|
||||
assert (fis.good());
|
||||
std::string read;
|
||||
fis >> read;
|
||||
assert (!read.empty());
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testWrite()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||
std::string file(tmp);
|
||||
file = "dummy_" + file + (".txt");
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||
std::string file(tmp);
|
||||
file = "dummy_" + file + ".txt";
|
||||
#else
|
||||
std::string file("dummy_file.txt");
|
||||
#endif
|
||||
|
||||
Poco::TemporaryFile::registerForDeletion(file);
|
||||
|
||||
Poco::FileOutputStream fos(file);
|
||||
assert (fos.good());
|
||||
fos << "hiho";
|
||||
fos.close();
|
||||
|
||||
Poco::FileInputStream fis(file);
|
||||
assert (fis.good());
|
||||
std::string read;
|
||||
fis >> read;
|
||||
assert (read == "hiho");
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testReadWrite()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||
std::string file(tmp);
|
||||
file = "dummy_" + file + (".txt");
|
||||
#else
|
||||
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||
std::string file(tmp);
|
||||
file = "dummy_" + file + ".txt";
|
||||
#endif
|
||||
|
||||
Poco::TemporaryFile::registerForDeletion(file);
|
||||
|
||||
Poco::FileStream fos(file);
|
||||
assert (fos.good());
|
||||
fos << "hiho";
|
||||
fos.seekg(0, std::ios::beg);
|
||||
std::string read;
|
||||
fos >> read;
|
||||
assert (read == "hiho");
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpen()
|
||||
{
|
||||
Poco::FileOutputStream ostr;
|
||||
ostr.open("test.txt", std::ios::out);
|
||||
assert (ostr.good());
|
||||
ostr.close();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeIn()
|
||||
{
|
||||
Poco::File f("nonexistent.txt");
|
||||
if (f.exists())
|
||||
f.remove();
|
||||
|
||||
try
|
||||
{
|
||||
Poco::FileInputStream istr("nonexistent.txt");
|
||||
fail("nonexistent file - must throw");
|
||||
}
|
||||
catch (Poco::Exception&)
|
||||
{
|
||||
}
|
||||
|
||||
f.createFile();
|
||||
Poco::FileInputStream istr("nonexistent.txt");
|
||||
assert (istr.good());
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeOut()
|
||||
{
|
||||
Poco::File f("test.txt");
|
||||
if (f.exists())
|
||||
f.remove();
|
||||
|
||||
Poco::FileOutputStream ostr1("test.txt");
|
||||
ostr1 << "Hello, world!";
|
||||
ostr1.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() != 0);
|
||||
|
||||
Poco::FileStream str1("test.txt");
|
||||
str1.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() != 0);
|
||||
|
||||
Poco::FileOutputStream ostr2("test.txt");
|
||||
ostr2.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() == 0);
|
||||
|
||||
f.remove();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeTrunc()
|
||||
{
|
||||
Poco::File f("test.txt");
|
||||
if (f.exists())
|
||||
f.remove();
|
||||
|
||||
Poco::FileOutputStream ostr1("test.txt");
|
||||
ostr1 << "Hello, world!";
|
||||
ostr1.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() != 0);
|
||||
|
||||
Poco::FileStream str1("test.txt", std::ios::trunc);
|
||||
str1.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() == 0);
|
||||
|
||||
f.remove();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeAte()
|
||||
{
|
||||
Poco::FileOutputStream ostr("test.txt");
|
||||
ostr << "0123456789";
|
||||
ostr.close();
|
||||
|
||||
Poco::FileStream str1("test.txt", std::ios::ate);
|
||||
int c = str1.get();
|
||||
assert (str1.eof());
|
||||
|
||||
str1.clear();
|
||||
str1.seekg(0);
|
||||
c = str1.get();
|
||||
assert (c == '0');
|
||||
|
||||
str1.close();
|
||||
|
||||
Poco::FileStream str2("test.txt", std::ios::ate);
|
||||
str2 << "abcdef";
|
||||
str2.seekg(0);
|
||||
std::string s;
|
||||
str2 >> s;
|
||||
assert (s == "0123456789abcdef");
|
||||
str2.close();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeApp()
|
||||
{
|
||||
Poco::FileOutputStream ostr("test.txt");
|
||||
ostr << "0123456789";
|
||||
ostr.close();
|
||||
|
||||
Poco::FileStream str1("test.txt", std::ios::app);
|
||||
|
||||
str1 << "abc";
|
||||
|
||||
str1.seekp(0);
|
||||
|
||||
str1 << "def";
|
||||
|
||||
str1.close();
|
||||
|
||||
Poco::FileInputStream istr("test.txt");
|
||||
std::string s;
|
||||
istr >> s;
|
||||
assert (s == "0123456789abcdef");
|
||||
istr.close();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testSeek()
|
||||
{
|
||||
Poco::FileStream str("test.txt", std::ios::trunc);
|
||||
str << "0123456789abcdef";
|
||||
|
||||
str.seekg(0);
|
||||
int c = str.get();
|
||||
assert (c == '0');
|
||||
|
||||
str.seekg(10);
|
||||
assert (str.tellg() == std::streampos(10));
|
||||
c = str.get();
|
||||
assert (c == 'a');
|
||||
assert (str.tellg() == std::streampos(11));
|
||||
|
||||
str.seekg(-1, std::ios::end);
|
||||
assert (str.tellg() == std::streampos(15));
|
||||
c = str.get();
|
||||
assert (c == 'f');
|
||||
assert (str.tellg() == std::streampos(16));
|
||||
|
||||
str.seekg(-1, std::ios::cur);
|
||||
assert (str.tellg() == std::streampos(15));
|
||||
c = str.get();
|
||||
assert (c == 'f');
|
||||
assert (str.tellg() == std::streampos(16));
|
||||
|
||||
str.seekg(-4, std::ios::cur);
|
||||
assert (str.tellg() == std::streampos(12));
|
||||
c = str.get();
|
||||
assert (c == 'c');
|
||||
assert (str.tellg() == std::streampos(13));
|
||||
|
||||
str.seekg(1, std::ios::cur);
|
||||
assert (str.tellg() == std::streampos(14));
|
||||
c = str.get();
|
||||
assert (c == 'e');
|
||||
assert (str.tellg() == std::streampos(15));
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* FileStreamTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FileStreamTest");
|
||||
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testRead);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testWrite);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testReadWrite);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpen);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeIn);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeOut);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeTrunc);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeAte);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeApp);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testSeek);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// FileStreamTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/FileStreamTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "FileStreamTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/TemporaryFile.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
FileStreamTest::FileStreamTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamTest::~FileStreamTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testRead()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||
char tmp[]={'\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||
std::string file(tmp);
|
||||
file.append(".txt");
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
char tmp[]={'\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||
std::string file(tmp);
|
||||
file.append(".txt");
|
||||
#else
|
||||
std::string file("testfile.txt");
|
||||
#endif
|
||||
|
||||
Poco::TemporaryFile::registerForDeletion(file);
|
||||
|
||||
Poco::FileOutputStream fos(file, std::ios::binary);
|
||||
fos << "sometestdata";
|
||||
fos.close();
|
||||
|
||||
Poco::FileInputStream fis(file);
|
||||
assert (fis.good());
|
||||
std::string read;
|
||||
fis >> read;
|
||||
assert (!read.empty());
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testWrite()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||
std::string file(tmp);
|
||||
file = "dummy_" + file + (".txt");
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||
std::string file(tmp);
|
||||
file = "dummy_" + file + ".txt";
|
||||
#else
|
||||
std::string file("dummy_file.txt");
|
||||
#endif
|
||||
|
||||
Poco::TemporaryFile::registerForDeletion(file);
|
||||
|
||||
Poco::FileOutputStream fos(file);
|
||||
assert (fos.good());
|
||||
fos << "hiho";
|
||||
fos.close();
|
||||
|
||||
Poco::FileInputStream fis(file);
|
||||
assert (fis.good());
|
||||
std::string read;
|
||||
fis >> read;
|
||||
assert (read == "hiho");
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testReadWrite()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_WIN32_UTF8)
|
||||
char tmp[]={'\xdf', '\xc4', '\xd6', '\xdc', '\xe4', '\xf6', '\xfc', '\0'};
|
||||
std::string file(tmp);
|
||||
file = "dummy_" + file + (".txt");
|
||||
#else
|
||||
char tmp[]={'\xc3', '\x9f', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\0'};
|
||||
std::string file(tmp);
|
||||
file = "dummy_" + file + ".txt";
|
||||
#endif
|
||||
|
||||
Poco::TemporaryFile::registerForDeletion(file);
|
||||
|
||||
Poco::FileStream fos(file);
|
||||
assert (fos.good());
|
||||
fos << "hiho";
|
||||
fos.seekg(0, std::ios::beg);
|
||||
std::string read;
|
||||
fos >> read;
|
||||
assert (read == "hiho");
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpen()
|
||||
{
|
||||
Poco::FileOutputStream ostr;
|
||||
ostr.open("test.txt", std::ios::out);
|
||||
assert (ostr.good());
|
||||
ostr.close();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeIn()
|
||||
{
|
||||
Poco::File f("nonexistent.txt");
|
||||
if (f.exists())
|
||||
f.remove();
|
||||
|
||||
try
|
||||
{
|
||||
Poco::FileInputStream istr("nonexistent.txt");
|
||||
fail("nonexistent file - must throw");
|
||||
}
|
||||
catch (Poco::Exception&)
|
||||
{
|
||||
}
|
||||
|
||||
f.createFile();
|
||||
Poco::FileInputStream istr("nonexistent.txt");
|
||||
assert (istr.good());
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeOut()
|
||||
{
|
||||
Poco::File f("test.txt");
|
||||
if (f.exists())
|
||||
f.remove();
|
||||
|
||||
Poco::FileOutputStream ostr1("test.txt");
|
||||
ostr1 << "Hello, world!";
|
||||
ostr1.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() != 0);
|
||||
|
||||
Poco::FileStream str1("test.txt");
|
||||
str1.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() != 0);
|
||||
|
||||
Poco::FileOutputStream ostr2("test.txt");
|
||||
ostr2.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() == 0);
|
||||
|
||||
f.remove();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeTrunc()
|
||||
{
|
||||
Poco::File f("test.txt");
|
||||
if (f.exists())
|
||||
f.remove();
|
||||
|
||||
Poco::FileOutputStream ostr1("test.txt");
|
||||
ostr1 << "Hello, world!";
|
||||
ostr1.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() != 0);
|
||||
|
||||
Poco::FileStream str1("test.txt", std::ios::trunc);
|
||||
str1.close();
|
||||
|
||||
assert (f.exists());
|
||||
assert (f.getSize() == 0);
|
||||
|
||||
f.remove();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeAte()
|
||||
{
|
||||
Poco::FileOutputStream ostr("test.txt");
|
||||
ostr << "0123456789";
|
||||
ostr.close();
|
||||
|
||||
Poco::FileStream str1("test.txt", std::ios::ate);
|
||||
int c = str1.get();
|
||||
assert (str1.eof());
|
||||
|
||||
str1.clear();
|
||||
str1.seekg(0);
|
||||
c = str1.get();
|
||||
assert (c == '0');
|
||||
|
||||
str1.close();
|
||||
|
||||
Poco::FileStream str2("test.txt", std::ios::ate);
|
||||
str2 << "abcdef";
|
||||
str2.seekg(0);
|
||||
std::string s;
|
||||
str2 >> s;
|
||||
assert (s == "0123456789abcdef");
|
||||
str2.close();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testOpenModeApp()
|
||||
{
|
||||
Poco::FileOutputStream ostr("test.txt");
|
||||
ostr << "0123456789";
|
||||
ostr.close();
|
||||
|
||||
Poco::FileStream str1("test.txt", std::ios::app);
|
||||
|
||||
str1 << "abc";
|
||||
|
||||
str1.seekp(0);
|
||||
|
||||
str1 << "def";
|
||||
|
||||
str1.close();
|
||||
|
||||
Poco::FileInputStream istr("test.txt");
|
||||
std::string s;
|
||||
istr >> s;
|
||||
assert (s == "0123456789abcdef");
|
||||
istr.close();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::testSeek()
|
||||
{
|
||||
Poco::FileStream str("test.txt", std::ios::trunc);
|
||||
str << "0123456789abcdef";
|
||||
|
||||
str.seekg(0);
|
||||
int c = str.get();
|
||||
assert (c == '0');
|
||||
|
||||
str.seekg(10);
|
||||
assert (str.tellg() == std::streampos(10));
|
||||
c = str.get();
|
||||
assert (c == 'a');
|
||||
assert (str.tellg() == std::streampos(11));
|
||||
|
||||
str.seekg(-1, std::ios::end);
|
||||
assert (str.tellg() == std::streampos(15));
|
||||
c = str.get();
|
||||
assert (c == 'f');
|
||||
assert (str.tellg() == std::streampos(16));
|
||||
|
||||
str.seekg(-1, std::ios::cur);
|
||||
assert (str.tellg() == std::streampos(15));
|
||||
c = str.get();
|
||||
assert (c == 'f');
|
||||
assert (str.tellg() == std::streampos(16));
|
||||
|
||||
str.seekg(-4, std::ios::cur);
|
||||
assert (str.tellg() == std::streampos(12));
|
||||
c = str.get();
|
||||
assert (c == 'c');
|
||||
assert (str.tellg() == std::streampos(13));
|
||||
|
||||
str.seekg(1, std::ios::cur);
|
||||
assert (str.tellg() == std::streampos(14));
|
||||
c = str.get();
|
||||
assert (c == 'e');
|
||||
assert (str.tellg() == std::streampos(15));
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileStreamTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* FileStreamTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FileStreamTest");
|
||||
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testRead);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testWrite);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testReadWrite);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpen);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeIn);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeOut);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeTrunc);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeAte);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeApp);
|
||||
CppUnit_addTest(pSuite, FileStreamTest, testSeek);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,69 +1,69 @@
|
|||
//
|
||||
// FileStreamTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/FileStreamTest.h#2 $
|
||||
//
|
||||
// Definition of the FileStreamTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef FileStreamTest_INCLUDED
|
||||
#define FileStreamTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class FileStreamTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
FileStreamTest(const std::string& name);
|
||||
~FileStreamTest();
|
||||
|
||||
void testRead();
|
||||
void testWrite();
|
||||
void testReadWrite();
|
||||
void testOpen();
|
||||
void testOpenModeIn();
|
||||
void testOpenModeOut();
|
||||
void testOpenModeTrunc();
|
||||
void testOpenModeAte();
|
||||
void testOpenModeApp();
|
||||
void testSeek();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // FileStreamTest_INCLUDED
|
||||
//
|
||||
// FileStreamTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/FileStreamTest.h#2 $
|
||||
//
|
||||
// Definition of the FileStreamTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef FileStreamTest_INCLUDED
|
||||
#define FileStreamTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class FileStreamTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
FileStreamTest(const std::string& name);
|
||||
~FileStreamTest();
|
||||
|
||||
void testRead();
|
||||
void testWrite();
|
||||
void testReadWrite();
|
||||
void testOpen();
|
||||
void testOpenModeIn();
|
||||
void testOpenModeOut();
|
||||
void testOpenModeTrunc();
|
||||
void testOpenModeAte();
|
||||
void testOpenModeApp();
|
||||
void testSeek();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // FileStreamTest_INCLUDED
|
||||
|
|
|
@ -1,242 +1,242 @@
|
|||
//
|
||||
// HashMapTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashMapTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashMapTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/HashMap.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
using Poco::HashMap;
|
||||
|
||||
|
||||
HashMapTest::HashMapTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashMapTest::~HashMapTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testInsert()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
assert (hm.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, i*2));
|
||||
assert (res.first->first == i);
|
||||
assert (res.first->second == i*2);
|
||||
assert (res.second);
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it != hm.end());
|
||||
assert (it->first == i);
|
||||
assert (it->second == i*2);
|
||||
assert (hm.size() == i + 1);
|
||||
}
|
||||
|
||||
assert (!hm.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it != hm.end());
|
||||
assert (it->first == i);
|
||||
assert (it->second == i*2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, 0));
|
||||
assert (res.first->first == i);
|
||||
assert (res.first->second == i*2);
|
||||
assert (!res.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testErase()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
assert (hm.size() == N);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hm.erase(i);
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it == hm.end());
|
||||
}
|
||||
assert (hm.size() == N/2);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it == hm.end());
|
||||
}
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it != hm.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it != hm.end());
|
||||
assert (it->first == i);
|
||||
assert (it->second == i*2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
std::map<int, int> values;
|
||||
IntMap::Iterator it = hm.begin();
|
||||
while (it != hm.end())
|
||||
{
|
||||
assert (values.find(it->first) == values.end());
|
||||
values[it->first] = it->second;
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testConstIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
std::map<int, int> values;
|
||||
IntMap::ConstIterator it = hm.begin();
|
||||
while (it != hm.end())
|
||||
{
|
||||
assert (values.find(it->first) == values.end());
|
||||
values[it->first] = it->second;
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testIndex()
|
||||
{
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
hm[1] = 2;
|
||||
hm[2] = 4;
|
||||
hm[3] = 6;
|
||||
|
||||
assert (hm.size() == 3);
|
||||
assert (hm[1] == 2);
|
||||
assert (hm[2] == 4);
|
||||
assert (hm[3] == 6);
|
||||
|
||||
try
|
||||
{
|
||||
const IntMap& im = hm;
|
||||
int x = im[4];
|
||||
fail("no such key - must throw");
|
||||
}
|
||||
catch (Poco::NotFoundException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HashMapTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashMapTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HashMapTest, testInsert);
|
||||
CppUnit_addTest(pSuite, HashMapTest, testErase);
|
||||
CppUnit_addTest(pSuite, HashMapTest, testIterator);
|
||||
CppUnit_addTest(pSuite, HashMapTest, testConstIterator);
|
||||
CppUnit_addTest(pSuite, HashMapTest, testIndex);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// HashMapTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashMapTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashMapTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/HashMap.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
using Poco::HashMap;
|
||||
|
||||
|
||||
HashMapTest::HashMapTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashMapTest::~HashMapTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testInsert()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
assert (hm.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, i*2));
|
||||
assert (res.first->first == i);
|
||||
assert (res.first->second == i*2);
|
||||
assert (res.second);
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it != hm.end());
|
||||
assert (it->first == i);
|
||||
assert (it->second == i*2);
|
||||
assert (hm.size() == i + 1);
|
||||
}
|
||||
|
||||
assert (!hm.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it != hm.end());
|
||||
assert (it->first == i);
|
||||
assert (it->second == i*2);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, 0));
|
||||
assert (res.first->first == i);
|
||||
assert (res.first->second == i*2);
|
||||
assert (!res.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testErase()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
assert (hm.size() == N);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hm.erase(i);
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it == hm.end());
|
||||
}
|
||||
assert (hm.size() == N/2);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it == hm.end());
|
||||
}
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it != hm.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assert (it != hm.end());
|
||||
assert (it->first == i);
|
||||
assert (it->second == i*2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
std::map<int, int> values;
|
||||
IntMap::Iterator it = hm.begin();
|
||||
while (it != hm.end())
|
||||
{
|
||||
assert (values.find(it->first) == values.end());
|
||||
values[it->first] = it->second;
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testConstIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
std::map<int, int> values;
|
||||
IntMap::ConstIterator it = hm.begin();
|
||||
while (it != hm.end())
|
||||
{
|
||||
assert (values.find(it->first) == values.end());
|
||||
values[it->first] = it->second;
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::testIndex()
|
||||
{
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
hm[1] = 2;
|
||||
hm[2] = 4;
|
||||
hm[3] = 6;
|
||||
|
||||
assert (hm.size() == 3);
|
||||
assert (hm[1] == 2);
|
||||
assert (hm[2] == 4);
|
||||
assert (hm[3] == 6);
|
||||
|
||||
try
|
||||
{
|
||||
const IntMap& im = hm;
|
||||
int x = im[4];
|
||||
fail("no such key - must throw");
|
||||
}
|
||||
catch (Poco::NotFoundException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashMapTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HashMapTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashMapTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HashMapTest, testInsert);
|
||||
CppUnit_addTest(pSuite, HashMapTest, testErase);
|
||||
CppUnit_addTest(pSuite, HashMapTest, testIterator);
|
||||
CppUnit_addTest(pSuite, HashMapTest, testConstIterator);
|
||||
CppUnit_addTest(pSuite, HashMapTest, testIndex);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
//
|
||||
// HashMapTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashMapTest.h#2 $
|
||||
//
|
||||
// Definition of the HashMapTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashMapTest_INCLUDED
|
||||
#define HashMapTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HashMapTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HashMapTest(const std::string& name);
|
||||
~HashMapTest();
|
||||
|
||||
void testInsert();
|
||||
void testErase();
|
||||
void testIterator();
|
||||
void testConstIterator();
|
||||
void testIndex();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HashMapTest_INCLUDED
|
||||
//
|
||||
// HashMapTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashMapTest.h#2 $
|
||||
//
|
||||
// Definition of the HashMapTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashMapTest_INCLUDED
|
||||
#define HashMapTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HashMapTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HashMapTest(const std::string& name);
|
||||
~HashMapTest();
|
||||
|
||||
void testInsert();
|
||||
void testErase();
|
||||
void testIterator();
|
||||
void testConstIterator();
|
||||
void testIndex();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HashMapTest_INCLUDED
|
||||
|
|
|
@ -1,205 +1,205 @@
|
|||
//
|
||||
// HashSetTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashSetTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/HashSet.h"
|
||||
#include <set>
|
||||
|
||||
|
||||
using Poco::HashSet;
|
||||
|
||||
|
||||
HashSetTest::HashSetTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashSetTest::~HashSetTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::testInsert()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int> hs;
|
||||
|
||||
assert (hs.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i);
|
||||
assert (*res.first == i);
|
||||
assert (res.second);
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it != hs.end());
|
||||
assert (*it == i);
|
||||
assert (hs.size() == i + 1);
|
||||
}
|
||||
|
||||
assert (!hs.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it != hs.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i);
|
||||
assert (*res.first == i);
|
||||
assert (!res.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::testErase()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int> hs;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
assert (hs.size() == N);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hs.erase(i);
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it == hs.end());
|
||||
}
|
||||
assert (hs.size() == N/2);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it == hs.end());
|
||||
}
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it != hs.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it != hs.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::testIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int> hs;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
std::set<int> values;
|
||||
HashSet<int>::Iterator it = hs.begin();
|
||||
while (it != hs.end())
|
||||
{
|
||||
assert (values.find(*it) == values.end());
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::testConstIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int> hs;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
std::set<int> values;
|
||||
HashSet<int>::ConstIterator it = hs.begin();
|
||||
while (it != hs.end())
|
||||
{
|
||||
assert (values.find(*it) == values.end());
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HashSetTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashSetTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HashSetTest, testInsert);
|
||||
CppUnit_addTest(pSuite, HashSetTest, testErase);
|
||||
CppUnit_addTest(pSuite, HashSetTest, testIterator);
|
||||
CppUnit_addTest(pSuite, HashSetTest, testConstIterator);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// HashSetTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashSetTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/HashSet.h"
|
||||
#include <set>
|
||||
|
||||
|
||||
using Poco::HashSet;
|
||||
|
||||
|
||||
HashSetTest::HashSetTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashSetTest::~HashSetTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::testInsert()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int> hs;
|
||||
|
||||
assert (hs.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i);
|
||||
assert (*res.first == i);
|
||||
assert (res.second);
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it != hs.end());
|
||||
assert (*it == i);
|
||||
assert (hs.size() == i + 1);
|
||||
}
|
||||
|
||||
assert (!hs.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it != hs.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i);
|
||||
assert (*res.first == i);
|
||||
assert (!res.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::testErase()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int> hs;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
assert (hs.size() == N);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hs.erase(i);
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it == hs.end());
|
||||
}
|
||||
assert (hs.size() == N/2);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it == hs.end());
|
||||
}
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it != hs.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
HashSet<int>::Iterator it = hs.find(i);
|
||||
assert (it != hs.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::testIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int> hs;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
std::set<int> values;
|
||||
HashSet<int>::Iterator it = hs.begin();
|
||||
while (it != hs.end())
|
||||
{
|
||||
assert (values.find(*it) == values.end());
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::testConstIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int> hs;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
std::set<int> values;
|
||||
HashSet<int>::ConstIterator it = hs.begin();
|
||||
while (it != hs.end())
|
||||
{
|
||||
assert (values.find(*it) == values.end());
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashSetTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HashSetTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashSetTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HashSetTest, testInsert);
|
||||
CppUnit_addTest(pSuite, HashSetTest, testErase);
|
||||
CppUnit_addTest(pSuite, HashSetTest, testIterator);
|
||||
CppUnit_addTest(pSuite, HashSetTest, testConstIterator);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,63 +1,63 @@
|
|||
//
|
||||
// HashSetTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.h#2 $
|
||||
//
|
||||
// Definition of the HashSetTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashSetTest_INCLUDED
|
||||
#define HashSetTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HashSetTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HashSetTest(const std::string& name);
|
||||
~HashSetTest();
|
||||
|
||||
void testInsert();
|
||||
void testErase();
|
||||
void testIterator();
|
||||
void testConstIterator();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HashSetTest_INCLUDED
|
||||
//
|
||||
// HashSetTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.h#2 $
|
||||
//
|
||||
// Definition of the HashSetTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashSetTest_INCLUDED
|
||||
#define HashSetTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HashSetTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HashSetTest(const std::string& name);
|
||||
~HashSetTest();
|
||||
|
||||
void testInsert();
|
||||
void testErase();
|
||||
void testIterator();
|
||||
void testConstIterator();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HashSetTest_INCLUDED
|
||||
|
|
|
@ -1,224 +1,224 @@
|
|||
//
|
||||
// HashTableTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashTableTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashTableTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/HashTable.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
HashTableTest::HashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashTableTest::~HashTableTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testInsert()
|
||||
{
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
HashTable<std::string, int> hashTable;
|
||||
assert (!hashTable.exists(s1));
|
||||
hashTable.insert(s1, 13);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 13);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 13);
|
||||
try
|
||||
{
|
||||
hashTable.insert(s1, 22);
|
||||
failmsg ("duplicate insert must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
try
|
||||
{
|
||||
hashTable.get(s2);
|
||||
failmsg ("getting a non inserted item must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
|
||||
assert (!hashTable.exists(s2));
|
||||
hashTable.insert(s2, 13);
|
||||
assert (hashTable.exists(s2));
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testUpdate()
|
||||
{
|
||||
// add code for second test here
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
HashTable<std::string, int> hashTable;
|
||||
hashTable.insert(s1, 13);
|
||||
hashTable.update(s1, 14);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 14);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 14);
|
||||
|
||||
// updating a non existing item must work too
|
||||
hashTable.update(s2, 15);
|
||||
assert (hashTable.get(s2) == 15);
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testOverflow()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testSize()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
||||
assert (hashTable.size() == 1);
|
||||
Poco::UInt32 h2 = hashTable.update("2", 2);
|
||||
assert (hashTable.size() == 2);
|
||||
hashTable.remove("1");
|
||||
assert (hashTable.size() == 1);
|
||||
hashTable.remove("3");
|
||||
assert (hashTable.size() == 1);
|
||||
hashTable.removeRaw("2", h2);
|
||||
assert (hashTable.size() == 0);
|
||||
hashTable.insert("1", 1);
|
||||
hashTable.insert("2", 2);
|
||||
assert (hashTable.size() == 2);
|
||||
hashTable.clear();
|
||||
assert (hashTable.size() == 0);
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testResize()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
hashTable.resize(19);
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
hashTable.resize(1009);
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testStatistic()
|
||||
{
|
||||
double relax = 0.001;
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
HashStatistic stat1(hashTable.currentState());
|
||||
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
||||
assert (stat1.maxPositionsOfTable() == 13);
|
||||
assert (stat1.maxEntriesPerHash() == 0);
|
||||
|
||||
hashTable.resize(19);
|
||||
stat1 = hashTable.currentState(true);
|
||||
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
||||
assert (stat1.maxPositionsOfTable() == 19);
|
||||
assert (stat1.maxEntriesPerHash() == 0);
|
||||
assert (stat1.detailedEntriesPerHash().size() == 19);
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
stat1 = hashTable.currentState(true);
|
||||
double expAvg = 1024.0/ 19;
|
||||
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
||||
assert (stat1.maxPositionsOfTable() == 19);
|
||||
assert (stat1.maxEntriesPerHash() > expAvg);
|
||||
hashTable.resize(1009);
|
||||
stat1 = hashTable.currentState(true);
|
||||
|
||||
expAvg = 1024.0/ 1009;
|
||||
|
||||
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
||||
assert (stat1.maxPositionsOfTable() == 1009);
|
||||
assert (stat1.maxEntriesPerHash() > expAvg);
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HashTableTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashTableTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HashTableTest, testInsert);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testUpdate);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testOverflow);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testSize);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testResize);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testStatistic);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// HashTableTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashTableTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashTableTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/HashTable.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
HashTableTest::HashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashTableTest::~HashTableTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testInsert()
|
||||
{
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
HashTable<std::string, int> hashTable;
|
||||
assert (!hashTable.exists(s1));
|
||||
hashTable.insert(s1, 13);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 13);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 13);
|
||||
try
|
||||
{
|
||||
hashTable.insert(s1, 22);
|
||||
failmsg ("duplicate insert must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
try
|
||||
{
|
||||
hashTable.get(s2);
|
||||
failmsg ("getting a non inserted item must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
|
||||
assert (!hashTable.exists(s2));
|
||||
hashTable.insert(s2, 13);
|
||||
assert (hashTable.exists(s2));
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testUpdate()
|
||||
{
|
||||
// add code for second test here
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
HashTable<std::string, int> hashTable;
|
||||
hashTable.insert(s1, 13);
|
||||
hashTable.update(s1, 14);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 14);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 14);
|
||||
|
||||
// updating a non existing item must work too
|
||||
hashTable.update(s2, 15);
|
||||
assert (hashTable.get(s2) == 15);
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testOverflow()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testSize()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
||||
assert (hashTable.size() == 1);
|
||||
Poco::UInt32 h2 = hashTable.update("2", 2);
|
||||
assert (hashTable.size() == 2);
|
||||
hashTable.remove("1");
|
||||
assert (hashTable.size() == 1);
|
||||
hashTable.remove("3");
|
||||
assert (hashTable.size() == 1);
|
||||
hashTable.removeRaw("2", h2);
|
||||
assert (hashTable.size() == 0);
|
||||
hashTable.insert("1", 1);
|
||||
hashTable.insert("2", 2);
|
||||
assert (hashTable.size() == 2);
|
||||
hashTable.clear();
|
||||
assert (hashTable.size() == 0);
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testResize()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
hashTable.resize(19);
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
hashTable.resize(1009);
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::testStatistic()
|
||||
{
|
||||
double relax = 0.001;
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
HashStatistic stat1(hashTable.currentState());
|
||||
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
||||
assert (stat1.maxPositionsOfTable() == 13);
|
||||
assert (stat1.maxEntriesPerHash() == 0);
|
||||
|
||||
hashTable.resize(19);
|
||||
stat1 = hashTable.currentState(true);
|
||||
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
||||
assert (stat1.maxPositionsOfTable() == 19);
|
||||
assert (stat1.maxEntriesPerHash() == 0);
|
||||
assert (stat1.detailedEntriesPerHash().size() == 19);
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
stat1 = hashTable.currentState(true);
|
||||
double expAvg = 1024.0/ 19;
|
||||
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
||||
assert (stat1.maxPositionsOfTable() == 19);
|
||||
assert (stat1.maxEntriesPerHash() > expAvg);
|
||||
hashTable.resize(1009);
|
||||
stat1 = hashTable.currentState(true);
|
||||
|
||||
expAvg = 1024.0/ 1009;
|
||||
|
||||
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
||||
assert (stat1.maxPositionsOfTable() == 1009);
|
||||
assert (stat1.maxEntriesPerHash() > expAvg);
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashTableTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HashTableTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashTableTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HashTableTest, testInsert);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testUpdate);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testOverflow);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testSize);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testResize);
|
||||
CppUnit_addTest(pSuite, HashTableTest, testStatistic);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,65 +1,65 @@
|
|||
//
|
||||
// HashTableTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashTableTest.h#2 $
|
||||
//
|
||||
// Definition of the HashTableTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashTableTest_INCLUDED
|
||||
#define HashTableTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HashTableTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HashTableTest(const std::string& name);
|
||||
~HashTableTest();
|
||||
|
||||
void testInsert();
|
||||
void testOverflow();
|
||||
void testUpdate();
|
||||
void testSize();
|
||||
void testResize();
|
||||
void testStatistic();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HashTableTest_INCLUDED
|
||||
//
|
||||
// HashTableTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashTableTest.h#2 $
|
||||
//
|
||||
// Definition of the HashTableTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashTableTest_INCLUDED
|
||||
#define HashTableTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HashTableTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HashTableTest(const std::string& name);
|
||||
~HashTableTest();
|
||||
|
||||
void testInsert();
|
||||
void testOverflow();
|
||||
void testUpdate();
|
||||
void testSize();
|
||||
void testResize();
|
||||
void testStatistic();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HashTableTest_INCLUDED
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
//
|
||||
// HashingTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashingTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashingTestSuite.h"
|
||||
#include "HashTableTest.h"
|
||||
#include "SimpleHashTableTest.h"
|
||||
#include "LinearHashTableTest.h"
|
||||
#include "HashSetTest.h"
|
||||
#include "HashMapTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HashingTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashingTestSuite");
|
||||
|
||||
pSuite->addTest(HashTableTest::suite());
|
||||
pSuite->addTest(SimpleHashTableTest::suite());
|
||||
pSuite->addTest(LinearHashTableTest::suite());
|
||||
pSuite->addTest(HashSetTest::suite());
|
||||
pSuite->addTest(HashMapTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// HashingTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashingTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashingTestSuite.h"
|
||||
#include "HashTableTest.h"
|
||||
#include "SimpleHashTableTest.h"
|
||||
#include "LinearHashTableTest.h"
|
||||
#include "HashSetTest.h"
|
||||
#include "HashMapTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HashingTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashingTestSuite");
|
||||
|
||||
pSuite->addTest(HashTableTest::suite());
|
||||
pSuite->addTest(SimpleHashTableTest::suite());
|
||||
pSuite->addTest(LinearHashTableTest::suite());
|
||||
pSuite->addTest(HashSetTest::suite());
|
||||
pSuite->addTest(HashMapTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
//
|
||||
// HashingTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashingTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the HashingTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashingTestSuite_INCLUDED
|
||||
#define HashingTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HashingTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HashingTestSuite_INCLUDED
|
||||
//
|
||||
// HashingTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/HashingTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the HashingTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashingTestSuite_INCLUDED
|
||||
#define HashingTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HashingTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HashingTestSuite_INCLUDED
|
||||
|
|
|
@ -1,374 +1,374 @@
|
|||
//
|
||||
// LinearHashTableTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "LinearHashTableTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/LinearHashTable.h"
|
||||
#include "Poco/HashTable.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::LinearHashTable;
|
||||
using Poco::HashTable;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::NumberFormatter;
|
||||
|
||||
|
||||
LinearHashTableTest::LinearHashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LinearHashTableTest::~LinearHashTableTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testInsert()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int> ht;
|
||||
|
||||
assert (ht.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i);
|
||||
assert (*res.first == i);
|
||||
assert (res.second);
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it != ht.end());
|
||||
assert (*it == i);
|
||||
assert (ht.size() == i + 1);
|
||||
}
|
||||
|
||||
assert (!ht.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it != ht.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i);
|
||||
assert (*res.first == i);
|
||||
assert (!res.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testErase()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int> ht;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
assert (ht.size() == N);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
ht.erase(i);
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it == ht.end());
|
||||
}
|
||||
assert (ht.size() == N/2);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it == ht.end());
|
||||
}
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it != ht.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it != ht.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int> ht;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
|
||||
std::set<int> values;
|
||||
LinearHashTable<int>::Iterator it = ht.begin();
|
||||
while (it != ht.end())
|
||||
{
|
||||
assert (values.find(*it) == values.end());
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testConstIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int> ht;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
|
||||
std::set<int> values;
|
||||
LinearHashTable<int>::ConstIterator it = ht.begin();
|
||||
while (it != ht.end())
|
||||
{
|
||||
assert (values.find(*it) == values.end());
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
|
||||
values.clear();
|
||||
const LinearHashTable<int> cht(ht);
|
||||
|
||||
LinearHashTable<int>::ConstIterator cit = cht.begin();
|
||||
while (cit != cht.end())
|
||||
{
|
||||
assert (values.find(*cit) == values.end());
|
||||
values.insert(*cit);
|
||||
++cit;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testPerformanceInt()
|
||||
{
|
||||
const int N = 5000000;
|
||||
Stopwatch sw;
|
||||
|
||||
{
|
||||
LinearHashTable<int> lht(N);
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
lht.insert(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
lht.find(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
|
||||
{
|
||||
HashTable<int, int> ht;
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(i, i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.exists(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
std::set<int> s;
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
s.insert(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
s.find(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testPerformanceStr()
|
||||
{
|
||||
const int N = 5000000;
|
||||
Stopwatch sw;
|
||||
|
||||
std::vector<std::string> values;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
values.push_back(NumberFormatter::format0(i, 8));
|
||||
}
|
||||
|
||||
{
|
||||
LinearHashTable<std::string> lht(N);
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
lht.insert(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
lht.find(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
|
||||
{
|
||||
HashTable<std::string, int> ht;
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(values[i], i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.exists(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
std::set<std::string> s;
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
s.insert(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
s.find(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* LinearHashTableTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("LinearHashTableTest");
|
||||
|
||||
CppUnit_addTest(pSuite, LinearHashTableTest, testInsert);
|
||||
CppUnit_addTest(pSuite, LinearHashTableTest, testErase);
|
||||
CppUnit_addTest(pSuite, LinearHashTableTest, testIterator);
|
||||
CppUnit_addTest(pSuite, LinearHashTableTest, testConstIterator);
|
||||
//CppUnit_addTest(pSuite, LinearHashTableTest, testPerformanceInt);
|
||||
//CppUnit_addTest(pSuite, LinearHashTableTest, testPerformanceStr);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// LinearHashTableTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "LinearHashTableTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/LinearHashTable.h"
|
||||
#include "Poco/HashTable.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::LinearHashTable;
|
||||
using Poco::HashTable;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::NumberFormatter;
|
||||
|
||||
|
||||
LinearHashTableTest::LinearHashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LinearHashTableTest::~LinearHashTableTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testInsert()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int> ht;
|
||||
|
||||
assert (ht.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i);
|
||||
assert (*res.first == i);
|
||||
assert (res.second);
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it != ht.end());
|
||||
assert (*it == i);
|
||||
assert (ht.size() == i + 1);
|
||||
}
|
||||
|
||||
assert (!ht.empty());
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it != ht.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i);
|
||||
assert (*res.first == i);
|
||||
assert (!res.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testErase()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int> ht;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
assert (ht.size() == N);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
ht.erase(i);
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it == ht.end());
|
||||
}
|
||||
assert (ht.size() == N/2);
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it == ht.end());
|
||||
}
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it != ht.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
LinearHashTable<int>::Iterator it = ht.find(i);
|
||||
assert (it != ht.end());
|
||||
assert (*it == i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int> ht;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
|
||||
std::set<int> values;
|
||||
LinearHashTable<int>::Iterator it = ht.begin();
|
||||
while (it != ht.end())
|
||||
{
|
||||
assert (values.find(*it) == values.end());
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testConstIterator()
|
||||
{
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int> ht;
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
|
||||
std::set<int> values;
|
||||
LinearHashTable<int>::ConstIterator it = ht.begin();
|
||||
while (it != ht.end())
|
||||
{
|
||||
assert (values.find(*it) == values.end());
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
|
||||
values.clear();
|
||||
const LinearHashTable<int> cht(ht);
|
||||
|
||||
LinearHashTable<int>::ConstIterator cit = cht.begin();
|
||||
while (cit != cht.end())
|
||||
{
|
||||
assert (values.find(*cit) == values.end());
|
||||
values.insert(*cit);
|
||||
++cit;
|
||||
}
|
||||
|
||||
assert (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testPerformanceInt()
|
||||
{
|
||||
const int N = 5000000;
|
||||
Stopwatch sw;
|
||||
|
||||
{
|
||||
LinearHashTable<int> lht(N);
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
lht.insert(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
lht.find(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
|
||||
{
|
||||
HashTable<int, int> ht;
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(i, i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.exists(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
std::set<int> s;
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
s.insert(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
s.find(i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::testPerformanceStr()
|
||||
{
|
||||
const int N = 5000000;
|
||||
Stopwatch sw;
|
||||
|
||||
std::vector<std::string> values;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
values.push_back(NumberFormatter::format0(i, 8));
|
||||
}
|
||||
|
||||
{
|
||||
LinearHashTable<std::string> lht(N);
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
lht.insert(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
lht.find(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
|
||||
{
|
||||
HashTable<std::string, int> ht;
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.insert(values[i], i);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
ht.exists(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
std::set<std::string> s;
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
s.insert(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
s.find(values[i]);
|
||||
}
|
||||
sw.stop();
|
||||
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LinearHashTableTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* LinearHashTableTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("LinearHashTableTest");
|
||||
|
||||
CppUnit_addTest(pSuite, LinearHashTableTest, testInsert);
|
||||
CppUnit_addTest(pSuite, LinearHashTableTest, testErase);
|
||||
CppUnit_addTest(pSuite, LinearHashTableTest, testIterator);
|
||||
CppUnit_addTest(pSuite, LinearHashTableTest, testConstIterator);
|
||||
//CppUnit_addTest(pSuite, LinearHashTableTest, testPerformanceInt);
|
||||
//CppUnit_addTest(pSuite, LinearHashTableTest, testPerformanceStr);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,65 +1,65 @@
|
|||
//
|
||||
// LinearHashTableTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.h#2 $
|
||||
//
|
||||
// Definition of the LinearHashTableTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef LinearHashTableTest_INCLUDED
|
||||
#define LinearHashTableTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class LinearHashTableTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
LinearHashTableTest(const std::string& name);
|
||||
~LinearHashTableTest();
|
||||
|
||||
void testInsert();
|
||||
void testErase();
|
||||
void testIterator();
|
||||
void testConstIterator();
|
||||
void testPerformanceInt();
|
||||
void testPerformanceStr();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // LinearHashTableTest_INCLUDED
|
||||
//
|
||||
// LinearHashTableTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.h#2 $
|
||||
//
|
||||
// Definition of the LinearHashTableTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef LinearHashTableTest_INCLUDED
|
||||
#define LinearHashTableTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class LinearHashTableTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
LinearHashTableTest(const std::string& name);
|
||||
~LinearHashTableTest();
|
||||
|
||||
void testInsert();
|
||||
void testErase();
|
||||
void testIterator();
|
||||
void testConstIterator();
|
||||
void testPerformanceInt();
|
||||
void testPerformanceStr();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // LinearHashTableTest_INCLUDED
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,79 +1,79 @@
|
|||
//
|
||||
// NamedTuplesTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/NamedTuplesTest.h#2 $
|
||||
//
|
||||
// Definition of the NamedTuplesTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef NamedTuplesTest_INCLUDED
|
||||
#define NamedTuplesTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class NamedTuplesTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
NamedTuplesTest(const std::string& name);
|
||||
~NamedTuplesTest();
|
||||
|
||||
void testNamedTuple1();
|
||||
void testNamedTuple2();
|
||||
void testNamedTuple3();
|
||||
void testNamedTuple4();
|
||||
void testNamedTuple5();
|
||||
void testNamedTuple6();
|
||||
void testNamedTuple7();
|
||||
void testNamedTuple8();
|
||||
void testNamedTuple9();
|
||||
void testNamedTuple10();
|
||||
void testNamedTuple11();
|
||||
void testNamedTuple12();
|
||||
void testNamedTuple13();
|
||||
void testNamedTuple14();
|
||||
void testNamedTuple15();
|
||||
void testNamedTuple16();
|
||||
void testNamedTuple17();
|
||||
void testNamedTuple18();
|
||||
void testNamedTuple19();
|
||||
void testNamedTuple20();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // NamedTuplesTest_INCLUDED
|
||||
//
|
||||
// NamedTuplesTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/NamedTuplesTest.h#2 $
|
||||
//
|
||||
// Definition of the NamedTuplesTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef NamedTuplesTest_INCLUDED
|
||||
#define NamedTuplesTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class NamedTuplesTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
NamedTuplesTest(const std::string& name);
|
||||
~NamedTuplesTest();
|
||||
|
||||
void testNamedTuple1();
|
||||
void testNamedTuple2();
|
||||
void testNamedTuple3();
|
||||
void testNamedTuple4();
|
||||
void testNamedTuple5();
|
||||
void testNamedTuple6();
|
||||
void testNamedTuple7();
|
||||
void testNamedTuple8();
|
||||
void testNamedTuple9();
|
||||
void testNamedTuple10();
|
||||
void testNamedTuple11();
|
||||
void testNamedTuple12();
|
||||
void testNamedTuple13();
|
||||
void testNamedTuple14();
|
||||
void testNamedTuple15();
|
||||
void testNamedTuple16();
|
||||
void testNamedTuple17();
|
||||
void testNamedTuple18();
|
||||
void testNamedTuple19();
|
||||
void testNamedTuple20();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // NamedTuplesTest_INCLUDED
|
||||
|
|
|
@ -1,116 +1,116 @@
|
|||
//
|
||||
// SharedMemoryTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/SharedMemoryTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SharedMemoryTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::SharedMemory;
|
||||
|
||||
|
||||
SharedMemoryTest::SharedMemoryTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryTest::~SharedMemoryTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryTest::testCreate()
|
||||
{
|
||||
SharedMemory mem("hi", 4096, SharedMemory::AM_WRITE);
|
||||
assert (mem.end()-mem.begin() == 4096);
|
||||
mem.begin()[0] = 'A';
|
||||
mem.end()[-1] = 'Z';
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryTest::testCreateFromFile()
|
||||
{
|
||||
Poco::Path p = findDataFile("testdata.txt");
|
||||
Poco::File f(p);
|
||||
assert (f.exists() && f.isFile());
|
||||
SharedMemory mem(f, SharedMemory::AM_READ);
|
||||
assert (mem.end() > mem.begin()); // valid?
|
||||
assert (mem.end() - mem.begin() == f.getSize());
|
||||
assert (mem.begin()[0] == 'A');
|
||||
assert (mem.end()[-5] == 'Z');
|
||||
}
|
||||
|
||||
|
||||
Poco::Path SharedMemoryTest::findDataFile(const std::string& afile)
|
||||
{
|
||||
Poco::Path root;
|
||||
root.makeAbsolute();
|
||||
Poco::Path result;
|
||||
while (!Poco::Path::find(root.toString(), "data", result))
|
||||
{
|
||||
root.makeParent();
|
||||
if (root.toString().empty() || root.toString() == "/")
|
||||
throw Poco::FileNotFoundException("Didn't find data subdir");
|
||||
}
|
||||
result.makeDirectory();
|
||||
result.setFileName(afile);
|
||||
Poco::File aFile(result.toString());
|
||||
if (!aFile.exists() || (aFile.exists() && !aFile.isFile()))
|
||||
throw Poco::FileNotFoundException("Didn't find file " + afile);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SharedMemoryTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SharedMemoryTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SharedMemoryTest, testCreate);
|
||||
CppUnit_addTest(pSuite, SharedMemoryTest, testCreateFromFile);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// SharedMemoryTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/SharedMemoryTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SharedMemoryTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::SharedMemory;
|
||||
|
||||
|
||||
SharedMemoryTest::SharedMemoryTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryTest::~SharedMemoryTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryTest::testCreate()
|
||||
{
|
||||
SharedMemory mem("hi", 4096, SharedMemory::AM_WRITE);
|
||||
assert (mem.end()-mem.begin() == 4096);
|
||||
mem.begin()[0] = 'A';
|
||||
mem.end()[-1] = 'Z';
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryTest::testCreateFromFile()
|
||||
{
|
||||
Poco::Path p = findDataFile("testdata.txt");
|
||||
Poco::File f(p);
|
||||
assert (f.exists() && f.isFile());
|
||||
SharedMemory mem(f, SharedMemory::AM_READ);
|
||||
assert (mem.end() > mem.begin()); // valid?
|
||||
assert (mem.end() - mem.begin() == f.getSize());
|
||||
assert (mem.begin()[0] == 'A');
|
||||
assert (mem.end()[-5] == 'Z');
|
||||
}
|
||||
|
||||
|
||||
Poco::Path SharedMemoryTest::findDataFile(const std::string& afile)
|
||||
{
|
||||
Poco::Path root;
|
||||
root.makeAbsolute();
|
||||
Poco::Path result;
|
||||
while (!Poco::Path::find(root.toString(), "data", result))
|
||||
{
|
||||
root.makeParent();
|
||||
if (root.toString().empty() || root.toString() == "/")
|
||||
throw Poco::FileNotFoundException("Didn't find data subdir");
|
||||
}
|
||||
result.makeDirectory();
|
||||
result.setFileName(afile);
|
||||
Poco::File aFile(result.toString());
|
||||
if (!aFile.exists() || (aFile.exists() && !aFile.isFile()))
|
||||
throw Poco::FileNotFoundException("Didn't find file " + afile);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SharedMemoryTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SharedMemoryTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SharedMemoryTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SharedMemoryTest, testCreate);
|
||||
CppUnit_addTest(pSuite, SharedMemoryTest, testCreateFromFile);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
//
|
||||
// SharedMemoryTest.h
|
||||
//
|
||||
// $Id: //poco/Main/template/test.h#7 $
|
||||
//
|
||||
// Definition of the SharedMemoryTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SharedMemoryTest_INCLUDED
|
||||
#define SharedMemoryTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class SharedMemoryTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SharedMemoryTest(const std::string& name);
|
||||
~SharedMemoryTest();
|
||||
|
||||
void testCreate();
|
||||
void testCreateFromFile();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
static Poco::Path findDataFile(const std::string& afile);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SharedMemoryTest_INCLUDED
|
||||
//
|
||||
// SharedMemoryTest.h
|
||||
//
|
||||
// $Id: //poco/Main/template/test.h#7 $
|
||||
//
|
||||
// Definition of the SharedMemoryTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SharedMemoryTest_INCLUDED
|
||||
#define SharedMemoryTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class SharedMemoryTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SharedMemoryTest(const std::string& name);
|
||||
~SharedMemoryTest();
|
||||
|
||||
void testCreate();
|
||||
void testCreateFromFile();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
static Poco::Path findDataFile(const std::string& afile);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SharedMemoryTest_INCLUDED
|
||||
|
|
|
@ -1,177 +1,177 @@
|
|||
//
|
||||
// SimpleHashTableTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/SimpleHashTableTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SimpleHashTableTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/SimpleHashTable.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
SimpleHashTableTest::SimpleHashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SimpleHashTableTest::~SimpleHashTableTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testInsert()
|
||||
{
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
SimpleHashTable<std::string, int> hashTable;
|
||||
assert (!hashTable.exists(s1));
|
||||
hashTable.insert(s1, 13);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 13);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 13);
|
||||
try
|
||||
{
|
||||
hashTable.insert(s1, 22);
|
||||
failmsg ("duplicate insert must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
try
|
||||
{
|
||||
hashTable.get(s2);
|
||||
failmsg ("getting a non inserted item must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
|
||||
assert (!hashTable.exists(s2));
|
||||
hashTable.insert(s2, 13);
|
||||
assert (hashTable.exists(s2));
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testUpdate()
|
||||
{
|
||||
// add code for second test here
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
SimpleHashTable<std::string, int> hashTable;
|
||||
hashTable.insert(s1, 13);
|
||||
hashTable.update(s1, 14);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 14);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 14);
|
||||
|
||||
// updating a non existing item must work too
|
||||
hashTable.update(s2, 15);
|
||||
assert (hashTable.get(s2) == 15);
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testOverflow()
|
||||
{
|
||||
SimpleHashTable<std::string, int> hashTable(31);
|
||||
for (int i = 0; i < 31; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 31; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testSize()
|
||||
{
|
||||
SimpleHashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
||||
assert (hashTable.size() == 1);
|
||||
Poco::UInt32 h2 = hashTable.update("2", 2);
|
||||
assert (hashTable.size() == 2);
|
||||
hashTable.clear();
|
||||
assert (hashTable.size() == 0);
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testResize()
|
||||
{
|
||||
SimpleHashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
hashTable.resize(2467);
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
hashTable.resize(3037);
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SimpleHashTableTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SimpleHashTableTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testInsert);
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testUpdate);
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testOverflow);
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testSize);
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testResize);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// SimpleHashTableTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/SimpleHashTableTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SimpleHashTableTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/SimpleHashTable.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
SimpleHashTableTest::SimpleHashTableTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SimpleHashTableTest::~SimpleHashTableTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testInsert()
|
||||
{
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
SimpleHashTable<std::string, int> hashTable;
|
||||
assert (!hashTable.exists(s1));
|
||||
hashTable.insert(s1, 13);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 13);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 13);
|
||||
try
|
||||
{
|
||||
hashTable.insert(s1, 22);
|
||||
failmsg ("duplicate insert must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
try
|
||||
{
|
||||
hashTable.get(s2);
|
||||
failmsg ("getting a non inserted item must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
|
||||
assert (!hashTable.exists(s2));
|
||||
hashTable.insert(s2, 13);
|
||||
assert (hashTable.exists(s2));
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testUpdate()
|
||||
{
|
||||
// add code for second test here
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
SimpleHashTable<std::string, int> hashTable;
|
||||
hashTable.insert(s1, 13);
|
||||
hashTable.update(s1, 14);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 14);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 14);
|
||||
|
||||
// updating a non existing item must work too
|
||||
hashTable.update(s2, 15);
|
||||
assert (hashTable.get(s2) == 15);
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testOverflow()
|
||||
{
|
||||
SimpleHashTable<std::string, int> hashTable(31);
|
||||
for (int i = 0; i < 31; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 31; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testSize()
|
||||
{
|
||||
SimpleHashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
||||
assert (hashTable.size() == 1);
|
||||
Poco::UInt32 h2 = hashTable.update("2", 2);
|
||||
assert (hashTable.size() == 2);
|
||||
hashTable.clear();
|
||||
assert (hashTable.size() == 0);
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::testResize()
|
||||
{
|
||||
SimpleHashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
hashTable.resize(2467);
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
hashTable.resize(3037);
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SimpleHashTableTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SimpleHashTableTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SimpleHashTableTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testInsert);
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testUpdate);
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testOverflow);
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testSize);
|
||||
CppUnit_addTest(pSuite, SimpleHashTableTest, testResize);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,65 +1,65 @@
|
|||
//
|
||||
// SimpleHashTableTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/SimpleHashTableTest.h#2 $
|
||||
//
|
||||
// Definition of the SimpleHashTableTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SimpleHashTableTest_INCLUDED
|
||||
#define SimpleHashTableTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class SimpleHashTableTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SimpleHashTableTest(const std::string& name);
|
||||
~SimpleHashTableTest();
|
||||
|
||||
void testInsert();
|
||||
void testOverflow();
|
||||
void testUpdate();
|
||||
void testSize();
|
||||
void testResize();
|
||||
void testStatistic();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SimpleHashTableTest_INCLUDED
|
||||
//
|
||||
// SimpleHashTableTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/SimpleHashTableTest.h#2 $
|
||||
//
|
||||
// Definition of the SimpleHashTableTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SimpleHashTableTest_INCLUDED
|
||||
#define SimpleHashTableTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class SimpleHashTableTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SimpleHashTableTest(const std::string& name);
|
||||
~SimpleHashTableTest();
|
||||
|
||||
void testInsert();
|
||||
void testOverflow();
|
||||
void testUpdate();
|
||||
void testSize();
|
||||
void testResize();
|
||||
void testStatistic();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SimpleHashTableTest_INCLUDED
|
||||
|
|
|
@ -1,89 +1,89 @@
|
|||
//
|
||||
// TextEncodingTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TextEncodingTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "TextEncodingTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/TextEncoding.h"
|
||||
#include "Poco/Latin1Encoding.h"
|
||||
|
||||
|
||||
using Poco::TextEncoding;
|
||||
using Poco::Latin1Encoding;
|
||||
|
||||
|
||||
TextEncodingTest::TextEncodingTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TextEncodingTest::~TextEncodingTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TextEncodingTest::testTextEncoding()
|
||||
{
|
||||
TextEncoding& utf8 = TextEncoding::byName("utf8");
|
||||
assert (std::string("UTF-8") == utf8.canonicalName());
|
||||
|
||||
TextEncoding& latin1 = TextEncoding::byName("latin1");
|
||||
assert (std::string("ISO-8859-1") == latin1.canonicalName());
|
||||
|
||||
TextEncoding& glob = TextEncoding::global();
|
||||
assert (std::string("UTF-8") == glob.canonicalName());
|
||||
|
||||
TextEncoding::global(new Latin1Encoding);
|
||||
|
||||
TextEncoding& glob2 = TextEncoding::global();
|
||||
assert (std::string("ISO-8859-1") == glob2.canonicalName());
|
||||
}
|
||||
|
||||
|
||||
void TextEncodingTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TextEncodingTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* TextEncodingTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextEncodingTest");
|
||||
|
||||
CppUnit_addTest(pSuite, TextEncodingTest, testTextEncoding);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// TextEncodingTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TextEncodingTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "TextEncodingTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/TextEncoding.h"
|
||||
#include "Poco/Latin1Encoding.h"
|
||||
|
||||
|
||||
using Poco::TextEncoding;
|
||||
using Poco::Latin1Encoding;
|
||||
|
||||
|
||||
TextEncodingTest::TextEncodingTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TextEncodingTest::~TextEncodingTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TextEncodingTest::testTextEncoding()
|
||||
{
|
||||
TextEncoding& utf8 = TextEncoding::byName("utf8");
|
||||
assert (std::string("UTF-8") == utf8.canonicalName());
|
||||
|
||||
TextEncoding& latin1 = TextEncoding::byName("latin1");
|
||||
assert (std::string("ISO-8859-1") == latin1.canonicalName());
|
||||
|
||||
TextEncoding& glob = TextEncoding::global();
|
||||
assert (std::string("UTF-8") == glob.canonicalName());
|
||||
|
||||
TextEncoding::global(new Latin1Encoding);
|
||||
|
||||
TextEncoding& glob2 = TextEncoding::global();
|
||||
assert (std::string("ISO-8859-1") == glob2.canonicalName());
|
||||
}
|
||||
|
||||
|
||||
void TextEncodingTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TextEncodingTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* TextEncodingTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextEncodingTest");
|
||||
|
||||
CppUnit_addTest(pSuite, TextEncodingTest, testTextEncoding);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,60 +1,60 @@
|
|||
//
|
||||
// TextEncodingTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TextEncodingTest.h#2 $
|
||||
//
|
||||
// Definition of the TextEncodingTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TextEncodingTest_INCLUDED
|
||||
#define TextEncodingTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class TextEncodingTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
TextEncodingTest(const std::string& name);
|
||||
~TextEncodingTest();
|
||||
|
||||
void testTextEncoding();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // TextEncodingTest_INCLUDED
|
||||
//
|
||||
// TextEncodingTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TextEncodingTest.h#2 $
|
||||
//
|
||||
// Definition of the TextEncodingTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TextEncodingTest_INCLUDED
|
||||
#define TextEncodingTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class TextEncodingTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
TextEncodingTest(const std::string& name);
|
||||
~TextEncodingTest();
|
||||
|
||||
void testTextEncoding();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // TextEncodingTest_INCLUDED
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,88 +1,88 @@
|
|||
//
|
||||
// TuplesTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TuplesTest.h#2 $
|
||||
//
|
||||
// Definition of the TuplesTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TuplesTest_INCLUDED
|
||||
#define TuplesTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class TuplesTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
TuplesTest(const std::string& name);
|
||||
~TuplesTest();
|
||||
|
||||
void testTuple1();
|
||||
void testTuple2();
|
||||
void testTuple3();
|
||||
void testTuple4();
|
||||
void testTuple5();
|
||||
void testTuple6();
|
||||
void testTuple7();
|
||||
void testTuple8();
|
||||
void testTuple9();
|
||||
void testTuple10();
|
||||
void testTuple11();
|
||||
void testTuple12();
|
||||
void testTuple13();
|
||||
void testTuple14();
|
||||
void testTuple15();
|
||||
void testTuple16();
|
||||
void testTuple17();
|
||||
void testTuple18();
|
||||
void testTuple19();
|
||||
void testTuple20();
|
||||
void testTupleOrder();
|
||||
void testMemOverhead();
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
|
||||
template <class T>
|
||||
void testTupleStrictWeak(const T& t1, const T& t2, const T& t3)
|
||||
{
|
||||
assert (t1 < t2 && !(t2 < t1)); // antisymmetric
|
||||
assert (t1 < t2 && t2 < t3 && t1 < t3); // transitive
|
||||
assert (!(t1 < t1)); // irreflexive
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // TuplesTest_INCLUDED
|
||||
//
|
||||
// TuplesTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TuplesTest.h#2 $
|
||||
//
|
||||
// Definition of the TuplesTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TuplesTest_INCLUDED
|
||||
#define TuplesTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class TuplesTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
TuplesTest(const std::string& name);
|
||||
~TuplesTest();
|
||||
|
||||
void testTuple1();
|
||||
void testTuple2();
|
||||
void testTuple3();
|
||||
void testTuple4();
|
||||
void testTuple5();
|
||||
void testTuple6();
|
||||
void testTuple7();
|
||||
void testTuple8();
|
||||
void testTuple9();
|
||||
void testTuple10();
|
||||
void testTuple11();
|
||||
void testTuple12();
|
||||
void testTuple13();
|
||||
void testTuple14();
|
||||
void testTuple15();
|
||||
void testTuple16();
|
||||
void testTuple17();
|
||||
void testTuple18();
|
||||
void testTuple19();
|
||||
void testTuple20();
|
||||
void testTupleOrder();
|
||||
void testMemOverhead();
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
|
||||
template <class T>
|
||||
void testTupleStrictWeak(const T& t1, const T& t2, const T& t3)
|
||||
{
|
||||
assert (t1 < t2 && !(t2 < t1)); // antisymmetric
|
||||
assert (t1 < t2 && t2 < t3 && t1 < t3); // transitive
|
||||
assert (!(t1 < t1)); // irreflexive
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // TuplesTest_INCLUDED
|
||||
|
|
|
@ -1,323 +1,323 @@
|
|||
//
|
||||
// TypeListTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TypeListTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "TypeListTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Tuple.h"
|
||||
#include "Poco/TypeList.h"
|
||||
#include "Poco/Void.h"
|
||||
#include <iostream>
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(disable:4800) // forcing value to bool 'true' or 'false' on MSVC 71
|
||||
#endif
|
||||
|
||||
using Poco::TypeList;
|
||||
using Poco::Tuple;
|
||||
using Poco::NullTypeList;
|
||||
using Poco::TypeListType;
|
||||
using Poco::TypeGetter;
|
||||
using Poco::TypeLocator;
|
||||
using Poco::TypeAppender;
|
||||
using Poco::TypeOneEraser;
|
||||
using Poco::TypeAllEraser;
|
||||
using Poco::TypeDuplicateEraser;
|
||||
using Poco::TypeOneReplacer;
|
||||
using Poco::TypeAllReplacer;
|
||||
using Poco::Int8;
|
||||
using Poco::UInt8;
|
||||
using Poco::Int16;
|
||||
using Poco::UInt16;
|
||||
using Poco::Int32;
|
||||
using Poco::UInt32;
|
||||
using Poco::Int8;
|
||||
using Poco::UInt8;
|
||||
using Poco::Int16;
|
||||
using Poco::UInt16;
|
||||
using Poco::Int32;
|
||||
using Poco::UInt32;
|
||||
using Poco::Void;
|
||||
|
||||
|
||||
TypeListTest::TypeListTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TypeListTest::~TypeListTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TypeListTest::testTypeList()
|
||||
{
|
||||
typedef TypeListType<Int8,
|
||||
UInt8,
|
||||
Int16,
|
||||
UInt16,
|
||||
Int32,
|
||||
UInt32,
|
||||
float,
|
||||
double,
|
||||
Int8,
|
||||
UInt8,
|
||||
Int16,
|
||||
UInt16,
|
||||
Int32,
|
||||
UInt32,
|
||||
float>::HeadType Type15;
|
||||
|
||||
Tuple<TypeGetter<0, Type15>::HeadType,
|
||||
TypeGetter<1, Type15>::HeadType,
|
||||
TypeGetter<2, Type15>::HeadType,
|
||||
TypeGetter<3, Type15>::HeadType,
|
||||
TypeGetter<4, Type15>::HeadType,
|
||||
TypeGetter<5, Type15>::HeadType,
|
||||
TypeGetter<6, Type15>::HeadType,
|
||||
TypeGetter<7, Type15>::HeadType,
|
||||
TypeGetter<8, Type15>::HeadType,
|
||||
TypeGetter<9, Type15>::HeadType> tuple;
|
||||
|
||||
static TypeLocator<Type15, Int8> pos0;
|
||||
static TypeLocator<Type15, UInt8> pos1;
|
||||
static TypeLocator<Type15, Int16> pos2;
|
||||
static TypeLocator<Type15, UInt16> pos3;
|
||||
static TypeLocator<Type15, Int32> pos4;
|
||||
static TypeLocator<Type15, UInt32> pos5;
|
||||
static TypeLocator<Type15, float> pos6;
|
||||
static TypeLocator<Type15, double> pos7;
|
||||
static TypeLocator<Type15, Int8> pos8;
|
||||
static TypeLocator<Type15, std::string> posUnknown;
|
||||
|
||||
assert (pos0.value == 0);
|
||||
assert (pos1.value == 1);
|
||||
assert (pos2.value == 2);
|
||||
assert (pos3.value == 3);
|
||||
assert (pos4.value == 4);
|
||||
assert (pos5.value == 5);
|
||||
assert (pos6.value == 6);
|
||||
assert (pos7.value == 7);
|
||||
assert (pos8.value == 0);
|
||||
assert (posUnknown.value == -1);
|
||||
|
||||
tuple.set<TypeLocator<Type15, Int32>::value >(-123);
|
||||
assert (-123 == tuple.get<4>());
|
||||
|
||||
assert (typeid(TypeGetter<0, Type15>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<0, Type15>::ConstHeadType) == typeid(const Int8));
|
||||
assert (typeid(TypeGetter<1, Type15>::HeadType) == typeid(UInt8));
|
||||
assert (typeid(TypeGetter<1, Type15>::ConstHeadType) == typeid(const UInt8));
|
||||
assert (typeid(TypeGetter<2, Type15>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, Type15>::ConstHeadType) == typeid(const Int16));
|
||||
assert (typeid(TypeGetter<3, Type15>::HeadType) == typeid(UInt16));
|
||||
assert (typeid(TypeGetter<3, Type15>::ConstHeadType) == typeid(const UInt16));
|
||||
assert (typeid(TypeGetter<4, Type15>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<4, Type15>::ConstHeadType) == typeid(const Int32));
|
||||
assert (typeid(TypeGetter<5, Type15>::HeadType) == typeid(UInt32));
|
||||
assert (typeid(TypeGetter<5, Type15>::ConstHeadType) == typeid(const UInt32));
|
||||
assert (typeid(TypeGetter<6, Type15>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<6, Type15>::ConstHeadType) == typeid(const float));
|
||||
assert (typeid(TypeGetter<7, Type15>::HeadType) == typeid(double));
|
||||
assert (typeid(TypeGetter<7, Type15>::ConstHeadType) == typeid(const double));
|
||||
assert (typeid(TypeGetter<8, Type15>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<8, Type15>::ConstHeadType) == typeid(const Int8));
|
||||
assert (typeid(TypeGetter<9, Type15>::HeadType) == typeid(UInt8));
|
||||
assert (typeid(TypeGetter<9, Type15>::ConstHeadType) == typeid(const UInt8));
|
||||
assert (typeid(TypeGetter<10, Type15>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<10, Type15>::ConstHeadType) == typeid(const Int16));
|
||||
assert (typeid(TypeGetter<11, Type15>::HeadType) == typeid(UInt16));
|
||||
assert (typeid(TypeGetter<11, Type15>::ConstHeadType) == typeid(const UInt16));
|
||||
assert (typeid(TypeGetter<12, Type15>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<12, Type15>::ConstHeadType) == typeid(const Int32));
|
||||
assert (typeid(TypeGetter<13, Type15>::HeadType) == typeid(UInt32));
|
||||
assert (typeid(TypeGetter<13, Type15>::ConstHeadType) == typeid(const UInt32));
|
||||
assert (typeid(TypeGetter<14, Type15>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<14, Type15>::ConstHeadType) == typeid(const float));
|
||||
|
||||
typedef TypeListType<Int8>::HeadType Type1;
|
||||
assert (1 == Type1::length);
|
||||
typedef TypeListType<Int16, Int32>::HeadType Type2;
|
||||
assert (2 == Type2::length);
|
||||
typedef TypeAppender<Type1, Type2>::HeadType Type3;
|
||||
assert (3 == Type3::length);
|
||||
|
||||
assert (typeid(TypeGetter<0, Type3>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, Type3>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, Type3>::HeadType) == typeid(Int32));
|
||||
|
||||
static TypeLocator<Type3, Int8> posNo1;
|
||||
static TypeLocator<Type3, Int16> posNo2;
|
||||
static TypeLocator<Type3, Int32> posNo3;
|
||||
|
||||
assert (posNo1.value == 0);
|
||||
assert (posNo2.value == 1);
|
||||
assert (posNo3.value == 2);
|
||||
|
||||
typedef TypeOneEraser<Type3, Int8>::HeadType TypeEraser1;
|
||||
assert (2 == TypeEraser1::length);
|
||||
assert (typeid(TypeGetter<0, TypeEraser1>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<1, TypeEraser1>::HeadType) == typeid(Int32));
|
||||
|
||||
typedef TypeOneEraser<Type3, Int16>::HeadType TypeEraser2;
|
||||
assert (2 == TypeEraser2::length);
|
||||
assert (typeid(TypeGetter<0, TypeEraser2>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeEraser2>::HeadType) == typeid(Int32));
|
||||
|
||||
typedef TypeOneEraser<Type3, Int32>::HeadType TypeEraser3;
|
||||
assert (2 == TypeEraser3::length);
|
||||
assert (typeid(TypeGetter<0, TypeEraser3>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeEraser3>::HeadType) == typeid(Int16));
|
||||
|
||||
typedef TypeListType<Int8,Int16,Int8,Int16,Int8>::HeadType Type5;
|
||||
typedef TypeAllEraser<Type5, Int8>::HeadType TypeAllEraser3;
|
||||
assert (2 == TypeAllEraser3::length);
|
||||
assert (typeid(TypeGetter<0, TypeAllEraser3>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<1, TypeAllEraser3>::HeadType) == typeid(Int16));
|
||||
|
||||
typedef TypeDuplicateEraser<Type5>::HeadType TypeDuplicateEraser1;
|
||||
assert (2 == TypeDuplicateEraser1::length);
|
||||
assert (typeid(TypeGetter<0, TypeDuplicateEraser1>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeDuplicateEraser1>::HeadType) == typeid(Int16));
|
||||
|
||||
typedef TypeOneReplacer<Type5, Int8, Int32>::HeadType TypeOneReplacer1;
|
||||
assert (5 == TypeOneReplacer1::length);
|
||||
assert (typeid(TypeGetter<0, TypeOneReplacer1>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<1, TypeOneReplacer1>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, TypeOneReplacer1>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<3, TypeOneReplacer1>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<4, TypeOneReplacer1>::HeadType) == typeid(Int8));
|
||||
|
||||
typedef TypeAllReplacer<Type5, Int8, Int32>::HeadType TypeAllReplacer1;
|
||||
assert (5 == TypeAllReplacer1::length);
|
||||
assert (typeid(TypeGetter<0, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<1, TypeAllReplacer1>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<3, TypeAllReplacer1>::HeadType) == typeid(Int16));
|
||||
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;
|
||||
assert (typeid(TypeGetter<0, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<1, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<2, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<3, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<4, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<5, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<6, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<7, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<8, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<9, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<10, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<11, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<12, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<13, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<14, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<15, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<16, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<17, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<18, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<19, TypeVoid>::HeadType) == typeid(Void));
|
||||
|
||||
|
||||
typedef TypeOneReplacer<TypeVoid, Void, Int8>::HeadType TypeFirstReplacer;
|
||||
assert (typeid(TypeGetter<0, TypeFirstReplacer>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<2, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<3, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<4, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<5, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<6, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<7, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<8, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<9, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<10, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<11, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<12, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<13, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<14, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<15, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<16, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<17, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<18, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<19, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
|
||||
typedef TypeOneReplacer<TypeFirstReplacer, Void, Int16>::HeadType TypeSecondReplacer;
|
||||
assert (typeid(TypeGetter<0, TypeSecondReplacer>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeSecondReplacer>::HeadType) == typeid(Int16));
|
||||
|
||||
typedef TypeOneReplacer<TypeSecondReplacer, Void, Int32>::HeadType TypeThirdReplacer;
|
||||
assert (typeid(TypeGetter<0, TypeThirdReplacer>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeThirdReplacer>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, TypeThirdReplacer>::HeadType) == typeid(Int32));
|
||||
|
||||
|
||||
typedef TypeAllReplacer<TypeThirdReplacer, Void, float>::HeadType TypeFourthReplacer;
|
||||
assert (typeid(TypeGetter<0, TypeFourthReplacer>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeFourthReplacer>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, TypeFourthReplacer>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<3, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<4, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<5, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<6, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<7, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<8, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<9, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<10, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<11, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<12, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<13, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<14, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<15, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<16, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<17, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<18, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<19, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
}
|
||||
|
||||
|
||||
void TypeListTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TypeListTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* TypeListTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TypeListTest");
|
||||
|
||||
CppUnit_addTest(pSuite, TypeListTest, testTypeList);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// TypeListTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TypeListTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "TypeListTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Tuple.h"
|
||||
#include "Poco/TypeList.h"
|
||||
#include "Poco/Void.h"
|
||||
#include <iostream>
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(disable:4800) // forcing value to bool 'true' or 'false' on MSVC 71
|
||||
#endif
|
||||
|
||||
using Poco::TypeList;
|
||||
using Poco::Tuple;
|
||||
using Poco::NullTypeList;
|
||||
using Poco::TypeListType;
|
||||
using Poco::TypeGetter;
|
||||
using Poco::TypeLocator;
|
||||
using Poco::TypeAppender;
|
||||
using Poco::TypeOneEraser;
|
||||
using Poco::TypeAllEraser;
|
||||
using Poco::TypeDuplicateEraser;
|
||||
using Poco::TypeOneReplacer;
|
||||
using Poco::TypeAllReplacer;
|
||||
using Poco::Int8;
|
||||
using Poco::UInt8;
|
||||
using Poco::Int16;
|
||||
using Poco::UInt16;
|
||||
using Poco::Int32;
|
||||
using Poco::UInt32;
|
||||
using Poco::Int8;
|
||||
using Poco::UInt8;
|
||||
using Poco::Int16;
|
||||
using Poco::UInt16;
|
||||
using Poco::Int32;
|
||||
using Poco::UInt32;
|
||||
using Poco::Void;
|
||||
|
||||
|
||||
TypeListTest::TypeListTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TypeListTest::~TypeListTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TypeListTest::testTypeList()
|
||||
{
|
||||
typedef TypeListType<Int8,
|
||||
UInt8,
|
||||
Int16,
|
||||
UInt16,
|
||||
Int32,
|
||||
UInt32,
|
||||
float,
|
||||
double,
|
||||
Int8,
|
||||
UInt8,
|
||||
Int16,
|
||||
UInt16,
|
||||
Int32,
|
||||
UInt32,
|
||||
float>::HeadType Type15;
|
||||
|
||||
Tuple<TypeGetter<0, Type15>::HeadType,
|
||||
TypeGetter<1, Type15>::HeadType,
|
||||
TypeGetter<2, Type15>::HeadType,
|
||||
TypeGetter<3, Type15>::HeadType,
|
||||
TypeGetter<4, Type15>::HeadType,
|
||||
TypeGetter<5, Type15>::HeadType,
|
||||
TypeGetter<6, Type15>::HeadType,
|
||||
TypeGetter<7, Type15>::HeadType,
|
||||
TypeGetter<8, Type15>::HeadType,
|
||||
TypeGetter<9, Type15>::HeadType> tuple;
|
||||
|
||||
static TypeLocator<Type15, Int8> pos0;
|
||||
static TypeLocator<Type15, UInt8> pos1;
|
||||
static TypeLocator<Type15, Int16> pos2;
|
||||
static TypeLocator<Type15, UInt16> pos3;
|
||||
static TypeLocator<Type15, Int32> pos4;
|
||||
static TypeLocator<Type15, UInt32> pos5;
|
||||
static TypeLocator<Type15, float> pos6;
|
||||
static TypeLocator<Type15, double> pos7;
|
||||
static TypeLocator<Type15, Int8> pos8;
|
||||
static TypeLocator<Type15, std::string> posUnknown;
|
||||
|
||||
assert (pos0.value == 0);
|
||||
assert (pos1.value == 1);
|
||||
assert (pos2.value == 2);
|
||||
assert (pos3.value == 3);
|
||||
assert (pos4.value == 4);
|
||||
assert (pos5.value == 5);
|
||||
assert (pos6.value == 6);
|
||||
assert (pos7.value == 7);
|
||||
assert (pos8.value == 0);
|
||||
assert (posUnknown.value == -1);
|
||||
|
||||
tuple.set<TypeLocator<Type15, Int32>::value >(-123);
|
||||
assert (-123 == tuple.get<4>());
|
||||
|
||||
assert (typeid(TypeGetter<0, Type15>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<0, Type15>::ConstHeadType) == typeid(const Int8));
|
||||
assert (typeid(TypeGetter<1, Type15>::HeadType) == typeid(UInt8));
|
||||
assert (typeid(TypeGetter<1, Type15>::ConstHeadType) == typeid(const UInt8));
|
||||
assert (typeid(TypeGetter<2, Type15>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, Type15>::ConstHeadType) == typeid(const Int16));
|
||||
assert (typeid(TypeGetter<3, Type15>::HeadType) == typeid(UInt16));
|
||||
assert (typeid(TypeGetter<3, Type15>::ConstHeadType) == typeid(const UInt16));
|
||||
assert (typeid(TypeGetter<4, Type15>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<4, Type15>::ConstHeadType) == typeid(const Int32));
|
||||
assert (typeid(TypeGetter<5, Type15>::HeadType) == typeid(UInt32));
|
||||
assert (typeid(TypeGetter<5, Type15>::ConstHeadType) == typeid(const UInt32));
|
||||
assert (typeid(TypeGetter<6, Type15>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<6, Type15>::ConstHeadType) == typeid(const float));
|
||||
assert (typeid(TypeGetter<7, Type15>::HeadType) == typeid(double));
|
||||
assert (typeid(TypeGetter<7, Type15>::ConstHeadType) == typeid(const double));
|
||||
assert (typeid(TypeGetter<8, Type15>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<8, Type15>::ConstHeadType) == typeid(const Int8));
|
||||
assert (typeid(TypeGetter<9, Type15>::HeadType) == typeid(UInt8));
|
||||
assert (typeid(TypeGetter<9, Type15>::ConstHeadType) == typeid(const UInt8));
|
||||
assert (typeid(TypeGetter<10, Type15>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<10, Type15>::ConstHeadType) == typeid(const Int16));
|
||||
assert (typeid(TypeGetter<11, Type15>::HeadType) == typeid(UInt16));
|
||||
assert (typeid(TypeGetter<11, Type15>::ConstHeadType) == typeid(const UInt16));
|
||||
assert (typeid(TypeGetter<12, Type15>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<12, Type15>::ConstHeadType) == typeid(const Int32));
|
||||
assert (typeid(TypeGetter<13, Type15>::HeadType) == typeid(UInt32));
|
||||
assert (typeid(TypeGetter<13, Type15>::ConstHeadType) == typeid(const UInt32));
|
||||
assert (typeid(TypeGetter<14, Type15>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<14, Type15>::ConstHeadType) == typeid(const float));
|
||||
|
||||
typedef TypeListType<Int8>::HeadType Type1;
|
||||
assert (1 == Type1::length);
|
||||
typedef TypeListType<Int16, Int32>::HeadType Type2;
|
||||
assert (2 == Type2::length);
|
||||
typedef TypeAppender<Type1, Type2>::HeadType Type3;
|
||||
assert (3 == Type3::length);
|
||||
|
||||
assert (typeid(TypeGetter<0, Type3>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, Type3>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, Type3>::HeadType) == typeid(Int32));
|
||||
|
||||
static TypeLocator<Type3, Int8> posNo1;
|
||||
static TypeLocator<Type3, Int16> posNo2;
|
||||
static TypeLocator<Type3, Int32> posNo3;
|
||||
|
||||
assert (posNo1.value == 0);
|
||||
assert (posNo2.value == 1);
|
||||
assert (posNo3.value == 2);
|
||||
|
||||
typedef TypeOneEraser<Type3, Int8>::HeadType TypeEraser1;
|
||||
assert (2 == TypeEraser1::length);
|
||||
assert (typeid(TypeGetter<0, TypeEraser1>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<1, TypeEraser1>::HeadType) == typeid(Int32));
|
||||
|
||||
typedef TypeOneEraser<Type3, Int16>::HeadType TypeEraser2;
|
||||
assert (2 == TypeEraser2::length);
|
||||
assert (typeid(TypeGetter<0, TypeEraser2>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeEraser2>::HeadType) == typeid(Int32));
|
||||
|
||||
typedef TypeOneEraser<Type3, Int32>::HeadType TypeEraser3;
|
||||
assert (2 == TypeEraser3::length);
|
||||
assert (typeid(TypeGetter<0, TypeEraser3>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeEraser3>::HeadType) == typeid(Int16));
|
||||
|
||||
typedef TypeListType<Int8,Int16,Int8,Int16,Int8>::HeadType Type5;
|
||||
typedef TypeAllEraser<Type5, Int8>::HeadType TypeAllEraser3;
|
||||
assert (2 == TypeAllEraser3::length);
|
||||
assert (typeid(TypeGetter<0, TypeAllEraser3>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<1, TypeAllEraser3>::HeadType) == typeid(Int16));
|
||||
|
||||
typedef TypeDuplicateEraser<Type5>::HeadType TypeDuplicateEraser1;
|
||||
assert (2 == TypeDuplicateEraser1::length);
|
||||
assert (typeid(TypeGetter<0, TypeDuplicateEraser1>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeDuplicateEraser1>::HeadType) == typeid(Int16));
|
||||
|
||||
typedef TypeOneReplacer<Type5, Int8, Int32>::HeadType TypeOneReplacer1;
|
||||
assert (5 == TypeOneReplacer1::length);
|
||||
assert (typeid(TypeGetter<0, TypeOneReplacer1>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<1, TypeOneReplacer1>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, TypeOneReplacer1>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<3, TypeOneReplacer1>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<4, TypeOneReplacer1>::HeadType) == typeid(Int8));
|
||||
|
||||
typedef TypeAllReplacer<Type5, Int8, Int32>::HeadType TypeAllReplacer1;
|
||||
assert (5 == TypeAllReplacer1::length);
|
||||
assert (typeid(TypeGetter<0, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<1, TypeAllReplacer1>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, TypeAllReplacer1>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<3, TypeAllReplacer1>::HeadType) == typeid(Int16));
|
||||
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;
|
||||
assert (typeid(TypeGetter<0, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<1, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<2, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<3, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<4, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<5, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<6, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<7, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<8, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<9, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<10, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<11, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<12, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<13, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<14, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<15, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<16, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<17, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<18, TypeVoid>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<19, TypeVoid>::HeadType) == typeid(Void));
|
||||
|
||||
|
||||
typedef TypeOneReplacer<TypeVoid, Void, Int8>::HeadType TypeFirstReplacer;
|
||||
assert (typeid(TypeGetter<0, TypeFirstReplacer>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<2, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<3, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<4, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<5, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<6, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<7, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<8, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<9, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<10, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<11, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<12, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<13, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<14, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<15, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<16, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<17, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<18, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
assert (typeid(TypeGetter<19, TypeFirstReplacer>::HeadType) == typeid(Void));
|
||||
|
||||
typedef TypeOneReplacer<TypeFirstReplacer, Void, Int16>::HeadType TypeSecondReplacer;
|
||||
assert (typeid(TypeGetter<0, TypeSecondReplacer>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeSecondReplacer>::HeadType) == typeid(Int16));
|
||||
|
||||
typedef TypeOneReplacer<TypeSecondReplacer, Void, Int32>::HeadType TypeThirdReplacer;
|
||||
assert (typeid(TypeGetter<0, TypeThirdReplacer>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeThirdReplacer>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, TypeThirdReplacer>::HeadType) == typeid(Int32));
|
||||
|
||||
|
||||
typedef TypeAllReplacer<TypeThirdReplacer, Void, float>::HeadType TypeFourthReplacer;
|
||||
assert (typeid(TypeGetter<0, TypeFourthReplacer>::HeadType) == typeid(Int8));
|
||||
assert (typeid(TypeGetter<1, TypeFourthReplacer>::HeadType) == typeid(Int16));
|
||||
assert (typeid(TypeGetter<2, TypeFourthReplacer>::HeadType) == typeid(Int32));
|
||||
assert (typeid(TypeGetter<3, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<4, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<5, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<6, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<7, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<8, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<9, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<10, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<11, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<12, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<13, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<14, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<15, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<16, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<17, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<18, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
assert (typeid(TypeGetter<19, TypeFourthReplacer>::HeadType) == typeid(float));
|
||||
}
|
||||
|
||||
|
||||
void TypeListTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TypeListTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* TypeListTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TypeListTest");
|
||||
|
||||
CppUnit_addTest(pSuite, TypeListTest, testTypeList);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,59 +1,59 @@
|
|||
//
|
||||
// TypeListTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TypeListTest.h#2 $
|
||||
//
|
||||
// Definition of the TypeListTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TypeListTest_INCLUDED
|
||||
#define TypeListTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class TypeListTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
TypeListTest(const std::string& name);
|
||||
~TypeListTest();
|
||||
|
||||
void testTypeList();
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // TypeListTest_INCLUDED
|
||||
//
|
||||
// TypeListTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/TypeListTest.h#2 $
|
||||
//
|
||||
// Definition of the TypeListTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TypeListTest_INCLUDED
|
||||
#define TypeListTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class TypeListTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
TypeListTest(const std::string& name);
|
||||
~TypeListTest();
|
||||
|
||||
void testTypeList();
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // TypeListTest_INCLUDED
|
||||
|
|
|
@ -1,122 +1,122 @@
|
|||
//
|
||||
// UTF8StringTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UTF8StringTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "UTF8StringTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/UTF8String.h"
|
||||
|
||||
|
||||
using Poco::UTF8;
|
||||
|
||||
|
||||
UTF8StringTest::UTF8StringTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
UTF8StringTest::~UTF8StringTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::testCompare()
|
||||
{
|
||||
std::string a1("aaaaa");
|
||||
std::string b1("bbbbb");
|
||||
|
||||
assert (UTF8::icompare(a1, b1) < 0);
|
||||
|
||||
std::string a2("aaaaa");
|
||||
std::string b2("BBBBB");
|
||||
|
||||
assert (UTF8::icompare(a2, b2) < 0);
|
||||
|
||||
std::string a3("AAAAA");
|
||||
std::string b3("bbbbb");
|
||||
|
||||
assert (UTF8::icompare(a3, b3) < 0);
|
||||
|
||||
std::string a4("aaaaa");
|
||||
std::string b4("AAAAA");
|
||||
|
||||
assert (UTF8::icompare(a4, b4) == 0);
|
||||
|
||||
std::string a5("AAAAA");
|
||||
std::string b5("bbbbb");
|
||||
|
||||
assert (UTF8::icompare(a5, b5) < 0);
|
||||
|
||||
std::string a6("\303\274\303\266\303\244"); // "u"a"o
|
||||
std::string b6("\303\234\303\226\303\204"); // "U"A"O
|
||||
|
||||
assert (UTF8::icompare(a6, b6) == 0);
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::testTransform()
|
||||
{
|
||||
std::string s1("abcde");
|
||||
UTF8::toUpperInPlace(s1);
|
||||
assert (s1 == "ABCDE");
|
||||
|
||||
std::string s2("aBcDe123");
|
||||
UTF8::toUpperInPlace(s2);
|
||||
assert (s2 == "ABCDE123");
|
||||
|
||||
std::string s3("\303\274\303\266\303\244"); // "u"a"o
|
||||
UTF8::toUpperInPlace(s3);
|
||||
assert (s3 == "\303\234\303\226\303\204"); // "U"A"O
|
||||
UTF8::toLowerInPlace(s3);
|
||||
assert (s3 == "\303\274\303\266\303\244"); // "U"A"O
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* UTF8StringTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UTF8StringTest");
|
||||
|
||||
CppUnit_addTest(pSuite, UTF8StringTest, testCompare);
|
||||
CppUnit_addTest(pSuite, UTF8StringTest, testTransform);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// UTF8StringTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UTF8StringTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "UTF8StringTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/UTF8String.h"
|
||||
|
||||
|
||||
using Poco::UTF8;
|
||||
|
||||
|
||||
UTF8StringTest::UTF8StringTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
UTF8StringTest::~UTF8StringTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::testCompare()
|
||||
{
|
||||
std::string a1("aaaaa");
|
||||
std::string b1("bbbbb");
|
||||
|
||||
assert (UTF8::icompare(a1, b1) < 0);
|
||||
|
||||
std::string a2("aaaaa");
|
||||
std::string b2("BBBBB");
|
||||
|
||||
assert (UTF8::icompare(a2, b2) < 0);
|
||||
|
||||
std::string a3("AAAAA");
|
||||
std::string b3("bbbbb");
|
||||
|
||||
assert (UTF8::icompare(a3, b3) < 0);
|
||||
|
||||
std::string a4("aaaaa");
|
||||
std::string b4("AAAAA");
|
||||
|
||||
assert (UTF8::icompare(a4, b4) == 0);
|
||||
|
||||
std::string a5("AAAAA");
|
||||
std::string b5("bbbbb");
|
||||
|
||||
assert (UTF8::icompare(a5, b5) < 0);
|
||||
|
||||
std::string a6("\303\274\303\266\303\244"); // "u"a"o
|
||||
std::string b6("\303\234\303\226\303\204"); // "U"A"O
|
||||
|
||||
assert (UTF8::icompare(a6, b6) == 0);
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::testTransform()
|
||||
{
|
||||
std::string s1("abcde");
|
||||
UTF8::toUpperInPlace(s1);
|
||||
assert (s1 == "ABCDE");
|
||||
|
||||
std::string s2("aBcDe123");
|
||||
UTF8::toUpperInPlace(s2);
|
||||
assert (s2 == "ABCDE123");
|
||||
|
||||
std::string s3("\303\274\303\266\303\244"); // "u"a"o
|
||||
UTF8::toUpperInPlace(s3);
|
||||
assert (s3 == "\303\234\303\226\303\204"); // "U"A"O
|
||||
UTF8::toLowerInPlace(s3);
|
||||
assert (s3 == "\303\274\303\266\303\244"); // "U"A"O
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* UTF8StringTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UTF8StringTest");
|
||||
|
||||
CppUnit_addTest(pSuite, UTF8StringTest, testCompare);
|
||||
CppUnit_addTest(pSuite, UTF8StringTest, testTransform);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,61 +1,61 @@
|
|||
//
|
||||
// UTF8StringTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UTF8StringTest.h#2 $
|
||||
//
|
||||
// Definition of the UTF8StringTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef UTF8StringTest_INCLUDED
|
||||
#define UTF8StringTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class UTF8StringTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
UTF8StringTest(const std::string& name);
|
||||
~UTF8StringTest();
|
||||
|
||||
void testCompare();
|
||||
void testTransform();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // UTF8StringTest_INCLUDED
|
||||
//
|
||||
// UTF8StringTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UTF8StringTest.h#2 $
|
||||
//
|
||||
// Definition of the UTF8StringTest class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef UTF8StringTest_INCLUDED
|
||||
#define UTF8StringTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class UTF8StringTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
UTF8StringTest(const std::string& name);
|
||||
~UTF8StringTest();
|
||||
|
||||
void testCompare();
|
||||
void testTransform();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // UTF8StringTest_INCLUDED
|
||||
|
|
|
@ -1,276 +1,276 @@
|
|||
//
|
||||
// UniqueExpireCacheTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireCacheTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "UniqueExpireCacheTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/UniqueExpireCache.h"
|
||||
#include "Poco/UniqueAccessExpireCache.h"
|
||||
#include "Poco/ExpirationDecorator.h"
|
||||
#include "Poco/AccessExpirationDecorator.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Thread.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
struct IntVal
|
||||
{
|
||||
int value;
|
||||
Poco::Timestamp validUntil;
|
||||
IntVal(int val, Poco::Timestamp::TimeDiff v):value(val), validUntil()
|
||||
{
|
||||
validUntil += (v*1000);
|
||||
}
|
||||
|
||||
const Poco::Timestamp& getExpiration() const
|
||||
{
|
||||
return validUntil;
|
||||
}
|
||||
};
|
||||
|
||||
typedef AccessExpirationDecorator<int> DIntVal;
|
||||
|
||||
#define DURSLEEP 250
|
||||
#define DURHALFSLEEP DURSLEEP / 2
|
||||
#define DURWAIT 300
|
||||
|
||||
|
||||
UniqueExpireCacheTest::UniqueExpireCacheTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
UniqueExpireCacheTest::~UniqueExpireCacheTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testClear()
|
||||
{
|
||||
UniqueExpireCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, DURSLEEP));
|
||||
aCache.add(3, IntVal(4, DURSLEEP));
|
||||
aCache.add(5, IntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
assert (aCache.get(3)->value == 4);
|
||||
assert (aCache.get(5)->value == 6);
|
||||
aCache.clear();
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testAccessClear()
|
||||
{
|
||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
assert (aCache.get(3)->value() == 4);
|
||||
assert (aCache.get(5)->value() == 6);
|
||||
aCache.clear();
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testAccessUpdate()
|
||||
{
|
||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
Thread::sleep(DURSLEEP/2);
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
Thread::sleep(DURSLEEP/2);
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
Thread::sleep(DURSLEEP/2);
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
Thread::sleep(DURSLEEP*2);
|
||||
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
aCache.remove(666); //must work too
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testExpire0()
|
||||
{
|
||||
UniqueExpireCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, 0));
|
||||
assert (!aCache.has(1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testAccessExpire0()
|
||||
{
|
||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, Timespan(0, 0)));
|
||||
assert (!aCache.has(1));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testExpireN()
|
||||
{
|
||||
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
UniqueExpireCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
SharedPtr<IntVal> tmp = aCache.get(1);
|
||||
assert (!tmp.isNull());
|
||||
assert (tmp->value == 2);
|
||||
Thread::sleep(DURWAIT);
|
||||
assert (!aCache.has(1));
|
||||
|
||||
// tmp must still be valid, access it
|
||||
assert (tmp->value == 2);
|
||||
tmp = aCache.get(1);
|
||||
assert (tmp.isNull());
|
||||
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
Thread::sleep(DURHALFSLEEP);
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
tmp = aCache.get(1);
|
||||
SharedPtr<IntVal> tmp2 = aCache.get(3);
|
||||
assert (tmp->value == 2);
|
||||
assert (tmp2->value == 4);
|
||||
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (tmp->value == 2); // 1-3
|
||||
assert (tmp2->value == 4); // 3-1
|
||||
tmp2 = aCache.get(3);
|
||||
assert (tmp2->value == 4);
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
assert (!aCache.has(3));
|
||||
assert (tmp2->value == 4);
|
||||
tmp = aCache.get(1);
|
||||
tmp2 = aCache.get(3);
|
||||
assert (!tmp);
|
||||
assert (!tmp2);
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
assert (!aCache.has(3));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testDuplicateAdd()
|
||||
{
|
||||
UniqueExpireCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
aCache.add(1, IntVal(3, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 3);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testAccessDuplicateAdd()
|
||||
{
|
||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
aCache.add(1, DIntVal(3, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value() == 3);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testExpirationDecorator()
|
||||
{
|
||||
typedef ExpirationDecorator<int> ExpireInt;
|
||||
UniqueExpireCache<int, ExpireInt> aCache;
|
||||
aCache.add(1, ExpireInt(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
aCache.add(1, ExpireInt(3, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value() == 3);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* UniqueExpireCacheTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UniqueExpireCacheTest");
|
||||
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testClear);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessClear);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessUpdate);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpire0);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessExpire0);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpireN);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testDuplicateAdd);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessDuplicateAdd);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpirationDecorator);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// UniqueExpireCacheTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireCacheTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "UniqueExpireCacheTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/UniqueExpireCache.h"
|
||||
#include "Poco/UniqueAccessExpireCache.h"
|
||||
#include "Poco/ExpirationDecorator.h"
|
||||
#include "Poco/AccessExpirationDecorator.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Thread.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
struct IntVal
|
||||
{
|
||||
int value;
|
||||
Poco::Timestamp validUntil;
|
||||
IntVal(int val, Poco::Timestamp::TimeDiff v):value(val), validUntil()
|
||||
{
|
||||
validUntil += (v*1000);
|
||||
}
|
||||
|
||||
const Poco::Timestamp& getExpiration() const
|
||||
{
|
||||
return validUntil;
|
||||
}
|
||||
};
|
||||
|
||||
typedef AccessExpirationDecorator<int> DIntVal;
|
||||
|
||||
#define DURSLEEP 250
|
||||
#define DURHALFSLEEP DURSLEEP / 2
|
||||
#define DURWAIT 300
|
||||
|
||||
|
||||
UniqueExpireCacheTest::UniqueExpireCacheTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
UniqueExpireCacheTest::~UniqueExpireCacheTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testClear()
|
||||
{
|
||||
UniqueExpireCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, DURSLEEP));
|
||||
aCache.add(3, IntVal(4, DURSLEEP));
|
||||
aCache.add(5, IntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
assert (aCache.get(3)->value == 4);
|
||||
assert (aCache.get(5)->value == 6);
|
||||
aCache.clear();
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testAccessClear()
|
||||
{
|
||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
assert (aCache.get(3)->value() == 4);
|
||||
assert (aCache.get(5)->value() == 6);
|
||||
aCache.clear();
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testAccessUpdate()
|
||||
{
|
||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
Thread::sleep(DURSLEEP/2);
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
Thread::sleep(DURSLEEP/2);
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
Thread::sleep(DURSLEEP/2);
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
Thread::sleep(DURSLEEP*2);
|
||||
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
aCache.remove(666); //must work too
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testExpire0()
|
||||
{
|
||||
UniqueExpireCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, 0));
|
||||
assert (!aCache.has(1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testAccessExpire0()
|
||||
{
|
||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, Timespan(0, 0)));
|
||||
assert (!aCache.has(1));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testExpireN()
|
||||
{
|
||||
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
UniqueExpireCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
SharedPtr<IntVal> tmp = aCache.get(1);
|
||||
assert (!tmp.isNull());
|
||||
assert (tmp->value == 2);
|
||||
Thread::sleep(DURWAIT);
|
||||
assert (!aCache.has(1));
|
||||
|
||||
// tmp must still be valid, access it
|
||||
assert (tmp->value == 2);
|
||||
tmp = aCache.get(1);
|
||||
assert (tmp.isNull());
|
||||
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
Thread::sleep(DURHALFSLEEP);
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
tmp = aCache.get(1);
|
||||
SharedPtr<IntVal> tmp2 = aCache.get(3);
|
||||
assert (tmp->value == 2);
|
||||
assert (tmp2->value == 4);
|
||||
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (tmp->value == 2); // 1-3
|
||||
assert (tmp2->value == 4); // 3-1
|
||||
tmp2 = aCache.get(3);
|
||||
assert (tmp2->value == 4);
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
assert (!aCache.has(3));
|
||||
assert (tmp2->value == 4);
|
||||
tmp = aCache.get(1);
|
||||
tmp2 = aCache.get(3);
|
||||
assert (!tmp);
|
||||
assert (!tmp2);
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
assert (!aCache.has(3));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testDuplicateAdd()
|
||||
{
|
||||
UniqueExpireCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
aCache.add(1, IntVal(3, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 3);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testAccessDuplicateAdd()
|
||||
{
|
||||
UniqueAccessExpireCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
aCache.add(1, DIntVal(3, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value() == 3);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::testExpirationDecorator()
|
||||
{
|
||||
typedef ExpirationDecorator<int> ExpireInt;
|
||||
UniqueExpireCache<int, ExpireInt> aCache;
|
||||
aCache.add(1, ExpireInt(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
aCache.add(1, ExpireInt(3, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value() == 3);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireCacheTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* UniqueExpireCacheTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UniqueExpireCacheTest");
|
||||
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testClear);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessClear);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessUpdate);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpire0);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessExpire0);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpireN);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testDuplicateAdd);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testAccessDuplicateAdd);
|
||||
CppUnit_addTest(pSuite, UniqueExpireCacheTest, testExpirationDecorator);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
//
|
||||
// UniqueExpireCacheTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireCacheTest.h#2 $
|
||||
//
|
||||
// Tests for ExpireCache
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef UniqueExpireCacheTest_INCLUDED
|
||||
#define UniqueExpireCacheTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class UniqueExpireCacheTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
UniqueExpireCacheTest(const std::string& name);
|
||||
~UniqueExpireCacheTest();
|
||||
|
||||
void testClear();
|
||||
void testAccessClear();
|
||||
void testDuplicateAdd();
|
||||
void testAccessDuplicateAdd();
|
||||
void testExpire0();
|
||||
void testAccessExpire0();
|
||||
void testExpireN();
|
||||
void testExpirationDecorator();
|
||||
void testAccessUpdate();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // UniqueExpireCacheTest_INCLUDED
|
||||
//
|
||||
// UniqueExpireCacheTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireCacheTest.h#2 $
|
||||
//
|
||||
// Tests for ExpireCache
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef UniqueExpireCacheTest_INCLUDED
|
||||
#define UniqueExpireCacheTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class UniqueExpireCacheTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
UniqueExpireCacheTest(const std::string& name);
|
||||
~UniqueExpireCacheTest();
|
||||
|
||||
void testClear();
|
||||
void testAccessClear();
|
||||
void testDuplicateAdd();
|
||||
void testAccessDuplicateAdd();
|
||||
void testExpire0();
|
||||
void testAccessExpire0();
|
||||
void testExpireN();
|
||||
void testExpirationDecorator();
|
||||
void testAccessUpdate();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // UniqueExpireCacheTest_INCLUDED
|
||||
|
|
|
@ -1,347 +1,347 @@
|
|||
//
|
||||
// UniqueExpireLRUCacheTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireLRUCacheTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "UniqueExpireLRUCacheTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/UniqueExpireLRUCache.h"
|
||||
#include "Poco/UniqueAccessExpireLRUCache.h"
|
||||
#include "Poco/AccessExpirationDecorator.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Thread.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
struct IntVal
|
||||
{
|
||||
int value;
|
||||
Poco::Timestamp validUntil;
|
||||
IntVal(int val, Poco::Timestamp::TimeDiff v):value(val), validUntil()
|
||||
{
|
||||
validUntil += (v*1000);
|
||||
}
|
||||
|
||||
const Poco::Timestamp& getExpiration() const
|
||||
{
|
||||
return validUntil;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef AccessExpirationDecorator<int> DIntVal;
|
||||
|
||||
|
||||
#define DURSLEEP 250
|
||||
#define DURHALFSLEEP DURSLEEP / 2
|
||||
#define DURWAIT 300
|
||||
|
||||
|
||||
UniqueExpireLRUCacheTest::UniqueExpireLRUCacheTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
UniqueExpireLRUCacheTest::~UniqueExpireLRUCacheTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testClear()
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, DURSLEEP));
|
||||
aCache.add(3, IntVal(4, DURSLEEP));
|
||||
aCache.add(5, IntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
assert (aCache.get(3)->value == 4);
|
||||
assert (aCache.get(5)->value == 6);
|
||||
aCache.clear();
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testAccessClear()
|
||||
{
|
||||
UniqueAccessExpireLRUCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
assert (aCache.get(3)->value() == 4);
|
||||
assert (aCache.get(5)->value() == 6);
|
||||
aCache.clear();
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
void UniqueExpireLRUCacheTest::testExpire0()
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, 0));
|
||||
assert (!aCache.has(1));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testExpireN()
|
||||
{
|
||||
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
SharedPtr<IntVal> tmp = aCache.get(1);
|
||||
assert (!tmp.isNull());
|
||||
assert (tmp->value == 2);
|
||||
Thread::sleep(DURWAIT);
|
||||
assert (!aCache.has(1));
|
||||
|
||||
// tmp must still be valid, access it
|
||||
assert (tmp->value == 2);
|
||||
tmp = aCache.get(1);
|
||||
assert (!tmp);
|
||||
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
Thread::sleep(DURHALFSLEEP);
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
tmp = aCache.get(1);
|
||||
SharedPtr<IntVal> tmp2 = aCache.get(3);
|
||||
assert (tmp->value == 2);
|
||||
assert (tmp2->value == 4);
|
||||
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (tmp->value == 2); // 1-3
|
||||
assert (tmp2->value == 4); // 3-1
|
||||
tmp2 = aCache.get(3);
|
||||
assert (tmp2->value == 4);
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
assert (!aCache.has(3));
|
||||
assert (tmp2->value == 4);
|
||||
tmp = aCache.get(1);
|
||||
tmp2 = aCache.get(3);
|
||||
assert (!tmp);
|
||||
assert (!tmp2);
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
assert (!aCache.has(3));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testCacheSize0()
|
||||
{
|
||||
// cache size 0 is illegal
|
||||
try
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(0);
|
||||
failmsg ("cache size of 0 is illegal, test should fail");
|
||||
}
|
||||
catch (Poco::InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testCacheSize1()
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(1);
|
||||
aCache.add(1, IntVal(2, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // replaces 1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.get(3)->value == 4);
|
||||
|
||||
aCache.add(5, IntVal(6, DURSLEEP));
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(5)->value == 6);
|
||||
|
||||
aCache.remove(5);
|
||||
assert (!aCache.has(5));
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testCacheSize2()
|
||||
{
|
||||
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(2);
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.get(1)->value == 2); // 1-3
|
||||
assert (aCache.get(3)->value == 4); // 3-1
|
||||
|
||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3|1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(5)->value == 6); // 5-3
|
||||
assert (aCache.get(3)->value == 4); // 3-5
|
||||
|
||||
// test remove from the end and the beginning of the list
|
||||
aCache.remove(5); // 3
|
||||
assert (!aCache.has(5));
|
||||
assert (aCache.get(3)->value == 4); // 3
|
||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3
|
||||
assert (aCache.get(3)->value == 4); // 3-5
|
||||
aCache.remove(3); // 5
|
||||
assert (!aCache.has(3));
|
||||
assert (aCache.get(5)->value == 6); // 5
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testCacheSizeN()
|
||||
{
|
||||
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.get(1)->value == 2); // 1-3
|
||||
assert (aCache.get(3)->value == 4); // 3-1
|
||||
|
||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(5)->value == 6); // 5-3-1
|
||||
assert (aCache.get(3)->value == 4); // 3-5-1
|
||||
|
||||
aCache.add(7, IntVal(8, DURSLEEP)); // 7-5-3|1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(7));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(5)->value == 6); // 5-7-3
|
||||
assert (aCache.get(3)->value == 4); // 3-5-7
|
||||
assert (aCache.get(7)->value == 8); // 7-3-5
|
||||
|
||||
// test remove from the end and the beginning of the list
|
||||
aCache.remove(5); // 7-3
|
||||
assert (!aCache.has(5));
|
||||
assert (aCache.get(3)->value == 4); // 3-7
|
||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3-7
|
||||
assert (aCache.get(7)->value == 8); // 7-5-3
|
||||
aCache.remove(7); // 5-3
|
||||
assert (!aCache.has(7));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.get(5)->value == 6); // 5-3
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
assert (!aCache.has(3));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testDuplicateAdd()
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
aCache.add(1, IntVal(3, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 3);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* UniqueExpireLRUCacheTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UniqueExpireLRUCacheTest");
|
||||
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testClear);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testAccessClear);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testExpire0);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testExpireN);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize0);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize1);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize2);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSizeN);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testDuplicateAdd);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
//
|
||||
// UniqueExpireLRUCacheTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireLRUCacheTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "UniqueExpireLRUCacheTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/UniqueExpireLRUCache.h"
|
||||
#include "Poco/UniqueAccessExpireLRUCache.h"
|
||||
#include "Poco/AccessExpirationDecorator.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Thread.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
struct IntVal
|
||||
{
|
||||
int value;
|
||||
Poco::Timestamp validUntil;
|
||||
IntVal(int val, Poco::Timestamp::TimeDiff v):value(val), validUntil()
|
||||
{
|
||||
validUntil += (v*1000);
|
||||
}
|
||||
|
||||
const Poco::Timestamp& getExpiration() const
|
||||
{
|
||||
return validUntil;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef AccessExpirationDecorator<int> DIntVal;
|
||||
|
||||
|
||||
#define DURSLEEP 250
|
||||
#define DURHALFSLEEP DURSLEEP / 2
|
||||
#define DURWAIT 300
|
||||
|
||||
|
||||
UniqueExpireLRUCacheTest::UniqueExpireLRUCacheTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
UniqueExpireLRUCacheTest::~UniqueExpireLRUCacheTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testClear()
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, DURSLEEP));
|
||||
aCache.add(3, IntVal(4, DURSLEEP));
|
||||
aCache.add(5, IntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
assert (aCache.get(3)->value == 4);
|
||||
assert (aCache.get(5)->value == 6);
|
||||
aCache.clear();
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testAccessClear()
|
||||
{
|
||||
UniqueAccessExpireLRUCache<int, DIntVal> aCache;
|
||||
aCache.add(1, DIntVal(2, DURSLEEP));
|
||||
aCache.add(3, DIntVal(4, DURSLEEP));
|
||||
aCache.add(5, DIntVal(6, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(1)->value() == 2);
|
||||
assert (aCache.get(3)->value() == 4);
|
||||
assert (aCache.get(5)->value() == 6);
|
||||
aCache.clear();
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
void UniqueExpireLRUCacheTest::testExpire0()
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache;
|
||||
aCache.add(1, IntVal(2, 0));
|
||||
assert (!aCache.has(1));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testExpireN()
|
||||
{
|
||||
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
SharedPtr<IntVal> tmp = aCache.get(1);
|
||||
assert (!tmp.isNull());
|
||||
assert (tmp->value == 2);
|
||||
Thread::sleep(DURWAIT);
|
||||
assert (!aCache.has(1));
|
||||
|
||||
// tmp must still be valid, access it
|
||||
assert (tmp->value == 2);
|
||||
tmp = aCache.get(1);
|
||||
assert (!tmp);
|
||||
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
Thread::sleep(DURHALFSLEEP);
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
tmp = aCache.get(1);
|
||||
SharedPtr<IntVal> tmp2 = aCache.get(3);
|
||||
assert (tmp->value == 2);
|
||||
assert (tmp2->value == 4);
|
||||
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (tmp->value == 2); // 1-3
|
||||
assert (tmp2->value == 4); // 3-1
|
||||
tmp2 = aCache.get(3);
|
||||
assert (tmp2->value == 4);
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
assert (!aCache.has(3));
|
||||
assert (tmp2->value == 4);
|
||||
tmp = aCache.get(1);
|
||||
tmp2 = aCache.get(3);
|
||||
assert (!tmp);
|
||||
assert (!tmp2);
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
assert (!aCache.has(3));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testCacheSize0()
|
||||
{
|
||||
// cache size 0 is illegal
|
||||
try
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(0);
|
||||
failmsg ("cache size of 0 is illegal, test should fail");
|
||||
}
|
||||
catch (Poco::InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testCacheSize1()
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(1);
|
||||
aCache.add(1, IntVal(2, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // replaces 1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.get(3)->value == 4);
|
||||
|
||||
aCache.add(5, IntVal(6, DURSLEEP));
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(5)->value == 6);
|
||||
|
||||
aCache.remove(5);
|
||||
assert (!aCache.has(5));
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testCacheSize2()
|
||||
{
|
||||
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(2);
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.get(1)->value == 2); // 1-3
|
||||
assert (aCache.get(3)->value == 4); // 3-1
|
||||
|
||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3|1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(5)->value == 6); // 5-3
|
||||
assert (aCache.get(3)->value == 4); // 3-5
|
||||
|
||||
// test remove from the end and the beginning of the list
|
||||
aCache.remove(5); // 3
|
||||
assert (!aCache.has(5));
|
||||
assert (aCache.get(3)->value == 4); // 3
|
||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3
|
||||
assert (aCache.get(3)->value == 4); // 3-5
|
||||
aCache.remove(3); // 5
|
||||
assert (!aCache.has(3));
|
||||
assert (aCache.get(5)->value == 6); // 5
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testCacheSizeN()
|
||||
{
|
||||
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
|
||||
aCache.add(3, IntVal(4, DURSLEEP)); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.get(1)->value == 2); // 1-3
|
||||
assert (aCache.get(3)->value == 4); // 3-1
|
||||
|
||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(5)->value == 6); // 5-3-1
|
||||
assert (aCache.get(3)->value == 4); // 3-5-1
|
||||
|
||||
aCache.add(7, IntVal(8, DURSLEEP)); // 7-5-3|1
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(7));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (aCache.get(5)->value == 6); // 5-7-3
|
||||
assert (aCache.get(3)->value == 4); // 3-5-7
|
||||
assert (aCache.get(7)->value == 8); // 7-3-5
|
||||
|
||||
// test remove from the end and the beginning of the list
|
||||
aCache.remove(5); // 7-3
|
||||
assert (!aCache.has(5));
|
||||
assert (aCache.get(3)->value == 4); // 3-7
|
||||
aCache.add(5, IntVal(6, DURSLEEP)); // 5-3-7
|
||||
assert (aCache.get(7)->value == 8); // 7-5-3
|
||||
aCache.remove(7); // 5-3
|
||||
assert (!aCache.has(7));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.get(5)->value == 6); // 5-3
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
assert (!aCache.has(3));
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::testDuplicateAdd()
|
||||
{
|
||||
UniqueExpireLRUCache<int, IntVal> aCache(3);
|
||||
aCache.add(1, IntVal(2, DURSLEEP)); // 1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 2);
|
||||
aCache.add(1, IntVal(3, DURSLEEP));
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.get(1)->value == 3);
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UniqueExpireLRUCacheTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* UniqueExpireLRUCacheTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UniqueExpireLRUCacheTest");
|
||||
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testClear);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testAccessClear);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testExpire0);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testExpireN);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize0);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize1);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSize2);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testCacheSizeN);
|
||||
CppUnit_addTest(pSuite, UniqueExpireLRUCacheTest, testDuplicateAdd);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
//
|
||||
// UniqueExpireLRUCacheTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireLRUCacheTest.h#2 $
|
||||
//
|
||||
// Tests for UniqueExpireLRUCache
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef UniqueExpireLRUCacheTest_INCLUDED
|
||||
#define UniqueExpireLRUCacheTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class UniqueExpireLRUCacheTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
UniqueExpireLRUCacheTest(const std::string& name);
|
||||
~UniqueExpireLRUCacheTest();
|
||||
|
||||
void testClear();
|
||||
void testAccessClear();
|
||||
void testExpire0();
|
||||
void testExpireN();
|
||||
void testCacheSize0();
|
||||
void testCacheSize1();
|
||||
void testCacheSize2();
|
||||
void testCacheSizeN();
|
||||
void testDuplicateAdd();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // UniqueExpireLRUCacheTest_INCLUDED
|
||||
//
|
||||
// UniqueExpireLRUCacheTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/UniqueExpireLRUCacheTest.h#2 $
|
||||
//
|
||||
// Tests for UniqueExpireLRUCache
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef UniqueExpireLRUCacheTest_INCLUDED
|
||||
#define UniqueExpireLRUCacheTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class UniqueExpireLRUCacheTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
UniqueExpireLRUCacheTest(const std::string& name);
|
||||
~UniqueExpireLRUCacheTest();
|
||||
|
||||
void testClear();
|
||||
void testAccessClear();
|
||||
void testExpire0();
|
||||
void testExpireN();
|
||||
void testCacheSize0();
|
||||
void testCacheSize1();
|
||||
void testCacheSize2();
|
||||
void testCacheSizeN();
|
||||
void testDuplicateAdd();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // UniqueExpireLRUCacheTest_INCLUDED
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче