trunk: backport eventing from 1.4.3

This commit is contained in:
Marian Krivos
2012-02-05 12:16:58 +00:00
parent 59fe68edbe
commit 7d7c02c579
412 changed files with 3564 additions and 3634 deletions

View File

@@ -1,7 +1,7 @@
// //
// AbstractDelegate.h // AbstractDelegate.h
// //
// $Id: //poco/1.4/Foundation/include/Poco/AbstractDelegate.h#1 $ // $Id: //poco/1.4/Foundation/include/Poco/AbstractDelegate.h#4 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the AbstractDelegate template. // Implementation of the AbstractDelegate template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -48,45 +48,41 @@ namespace Poco {
template <class TArgs> template <class TArgs>
class AbstractDelegate class AbstractDelegate
/// Interface for Delegate and Expire /// Base class for Delegate and Expire.
/// Very similar to AbstractPriorityDelegate but having two separate files (no inheritance)
/// allows one to have compile-time checks when registering an observer
/// instead of run-time checks.
{ {
public: public:
AbstractDelegate(void* pTarget): _pTarget(pTarget) AbstractDelegate()
{
}
AbstractDelegate(const AbstractDelegate& del)
{
}
virtual ~AbstractDelegate()
{ {
poco_assert_dbg (_pTarget != 0); }
}
AbstractDelegate(const AbstractDelegate& del): _pTarget(del._pTarget) virtual bool notify(const void* sender, TArgs& arguments) = 0;
{ /// Invokes the delegate's callback function.
poco_assert_dbg (_pTarget != 0); /// Returns true if successful, or false if the delegate
} /// has been disabled or has expired.
virtual ~AbstractDelegate() virtual bool equals(const AbstractDelegate& other) const = 0;
{ /// Compares the AbstractDelegate with the other one for equality.
}
virtual bool notify(const void* sender, TArgs& arguments) = 0; virtual AbstractDelegate* clone() const = 0;
/// Returns false, if the Delegate is no longer valid, thus indicating an expire. /// Returns a deep copy of the AbstractDelegate.
virtual AbstractDelegate* clone() const = 0; virtual void disable() = 0;
/// Returns a deep-copy of the AbstractDelegate /// Disables the delegate, which is done prior to removal.
bool operator < (const AbstractDelegate<TArgs>& other) const virtual const AbstractDelegate* unwrap() const
/// For comparing AbstractDelegates in a collection. /// Returns the unwrapped delegate. Must be overridden by decorators
{ /// like Expire.
return _pTarget < other._pTarget; {
} return this;
}
void* target() const
{
return _pTarget;
}
protected:
void* _pTarget;
}; };

View File

@@ -1,7 +1,7 @@
// //
// AbstractEvent.h // AbstractEvent.h
// //
// $Id: //poco/1.4/Foundation/include/Poco/AbstractEvent.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/AbstractEvent.h#3 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Definition of the AbstractEvent class. // Definition of the AbstractEvent class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -53,74 +53,88 @@ namespace Poco {
template <class TArgs, class TStrategy, class TDelegate, class TMutex = FastMutex> template <class TArgs, class TStrategy, class TDelegate, class TMutex = FastMutex>
class AbstractEvent class AbstractEvent
/// An AbstractEvent is the super-class of all events. /// An AbstractEvent is the base class of all events.
/// It works similar to the way C# handles notifications (aka events in C#). /// It works similar to the way C# handles notifications (aka events in C#).
/// Events can be used to send information to a set of observers ///
/// which are registered at the event. The type of the data is specified with /// Events can be used to send information to a set of delegates
/// the template parameter TArgs. The TStrategy parameter must be a subclass /// which are registered with the event. The type of the data is specified with
/// of NotificationStrategy. The parameter TDelegate can either be a subclass of AbstractDelegate /// the template parameter TArgs. The TStrategy parameter must be a subclass
/// or of PriorityAbstractDelegate. /// of NotificationStrategy. The parameter TDelegate can either be a subclass of AbstractDelegate
/// /// or of AbstractPriorityDelegate.
/// Note that AbstractEvent should never be used directly. One ought to use ///
/// one of its subclasses which set the TStrategy and TDelegate template parameters /// Note that AbstractEvent should never be used directly. One ought to use
/// to fixed values. For most use-cases the BasicEvent template will be sufficient: /// one of its subclasses which set the TStrategy and TDelegate template parameters
/// #include "Poco/BasicEvent.h" /// to fixed values. For most use-cases the BasicEvent template will be sufficient:
/// #include "Poco/Delegate.h" ///
/// /// #include "Poco/BasicEvent.h"
/// If one requires delegates to be called in the order they registered, use FIFOEvent: /// #include "Poco/Delegate.h"
/// #include "Poco/FIFOEvent.h" ///
/// #include "Poco/Delegate.h" /// Note that as of release 1.4.2, the behavior of BasicEvent equals that of FIFOEvent,
/// /// so the FIFOEvent class is no longer necessary and provided for backwards compatibility
/// Both FIFOEvent and BasicEvent work with a standard delegate. They allow one object to register /// only.
/// exactly one delegate at an event. In contrast, a PriorityDelegate comes with an attached priority value ///
/// and allows one object to register for one priority value one delegate. Note that PriorityDelegates /// BasicEvent works with a standard delegate. They allow one object to register
/// only work with PriorityEvents: /// onr or more delegates with an event. In contrast, a PriorityDelegate comes with an attached priority value
/// #include "Poco/PriorityEvent.h" /// and allows one object to register for one priority value one or more delegates. Note that PriorityDelegates
/// #include "Poco/PriorityDelegate.h" /// only work with PriorityEvents:
/// ///
/// #include "Poco/PriorityEvent.h"
/// #include "Poco/PriorityDelegate.h"
///
/// Use events by adding them as public members to the object which is throwing notifications: /// Use events by adding them as public members to the object which is throwing notifications:
/// ///
/// class MyData /// class MyData
/// { /// {
/// public: /// public:
/// Poco::BasicEvent<int> AgeChanged; /// Poco::BasicEvent<int> dataChanged;
/// ///
/// MyData(); /// MyData();
/// ... /// ...
/// }; /// void setData(int i);
/// /// ...
/// Throwing the event can be done either by the events notify() or notifyAsync() method: /// private:
/// /// int _data;
/// /// };
/// Alternatively, instead of notify(), operator () can be used. ///
/// /// Firing the event is done either by calling the event's notify() or notifyAsync() method:
/// void MyData::setAge(int i) ///
/// { /// void MyData::setData(int i)
/// this->_age = i; /// {
/// AgeChanged(this, this->_age); /// this->_data = i;
/// } /// dataChanged.notify(this, this->_data);
/// /// }
/// Note that notify and notifyAsync do not catch exceptions, i.e. in case a delegate ///
/// throws an exception, the notify is immediately aborted and the exception is thrown /// Alternatively, instead of notify(), operator () can be used.
/// back to the caller. ///
/// /// void MyData::setData(int i)
/// Delegates can register methods at the event. In the case of a BasicEvent or FIFOEvent /// {
/// the Delegate template is used, in case of an PriorityEvent a PriorityDelegate is used. /// this->_data = i;
/// Mixing of observers, e.g. using a PriorityDelegate with a BasicEvent is not possible and /// dataChanged(this, this->_data);
/// checked for during compile time. /// }
/// Events require the observers to follow one of the following method signature: ///
/// /// Note that operator (), notify() and notifyAsync() do not catch exceptions, i.e. in case a
/// void onEvent(const void* pSender, TArgs& args); /// delegate throws an exception, notifying is immediately aborted and the exception is propagated
/// void onEvent(TArgs& args); /// back to the caller.
///
/// Delegates can register methods at the event. In the case of a BasicEvent
/// the Delegate template is used, in case of an PriorityEvent a PriorityDelegate is used.
/// Mixing of delegates, e.g. using a PriorityDelegate with a BasicEvent is not allowed and
/// can lead to compile-time and/or run-time errors. The standalone delegate() functions
/// can be used to construct Delegate objects.
///
/// Events require the observers to have one of the following method signatures:
///
/// void onEvent(const void* pSender, TArgs& args);
/// void onEvent(TArgs& args);
/// static void onEvent(const void* pSender, TArgs& args); /// static void onEvent(const void* pSender, TArgs& args);
/// static void onEvent(void* pSender, TArgs& args); /// static void onEvent(void* pSender, TArgs& args);
/// static void onEvent(TArgs& args); /// static void onEvent(TArgs& args);
/// ///
/// For performance reasons arguments are always sent by reference. This also allows observers /// For performance reasons arguments are always sent by reference. This also allows observers
/// to modify the sent argument. To prevent that, use <const TArg> as template /// to modify the event argument. To prevent that, use <[const TArg]> as template
/// parameter. A non-conformant method signature leads to compile errors. /// parameter. A non-conformant method signature leads to compile errors.
/// ///
/// Assuming that the observer meets the method signature requirement, it can register /// Assuming that the observer meets the method signature requirement, it can register
/// this method with the += operator: /// this method with the += operator:
/// ///
/// class MyController /// class MyController
@@ -131,34 +145,33 @@ class AbstractEvent
/// void onDataChanged(void* pSender, int& data); /// void onDataChanged(void* pSender, int& data);
/// ... /// ...
/// }; /// };
/// ///
/// MyController::MyController() /// MyController::MyController()
/// { /// {
/// _data.AgeChanged += delegate(this, &MyController::onDataChanged); /// _data.dataChanged += delegate(this, &MyController::onDataChanged);
/// } /// }
/// ///
/// In some cases it might be desirable to work with automatically expiring registrations. Simply add /// In some cases it might be desirable to work with automatically expiring registrations. Simply add
/// to delegate as 3rd parameter a expireValue (in milliseconds): /// to delegate as 3rd parameter a expireValue (in milliseconds):
/// ///
/// _data.DataChanged += delegate(this, &MyController::onDataChanged, 1000); /// _data.dataChanged += delegate(this, &MyController::onDataChanged, 1000);
/// ///
/// This will add a delegate to the event which will automatically be removed in 1000 millisecs. /// This will add a delegate to the event which will automatically be removed in 1000 millisecs.
/// ///
/// Unregistering happens via the -= operator. Forgetting to unregister a method will lead to /// Unregistering happens via the -= operator. Forgetting to unregister a method will lead to
/// segmentation faults later, when one tries to send a notify to a no longer existing object. /// segmentation faults later, when one tries to send a notify to a no longer existing object.
/// ///
/// MyController::~MyController() /// MyController::~MyController()
/// { /// {
/// _data.DataChanged -= delegate(this, &MyController::onDataChanged); /// _data.dataChanged -= delegate(this, &MyController::onDataChanged);
/// } /// }
/// ///
/// Working with PriorityDelegates as similar to working with BasicEvent/FIFOEvent.Instead of ''delegate'' /// Working with PriorityDelegate's as similar to working with BasicEvent.
/// simply use ''priorityDelegate''. /// Instead of delegate(), the priorityDelegate() function must be used
/// /// to create the PriorityDelegate.
/// For further examples refer to the event testsuites.
{ {
public: public:
AbstractEvent(): AbstractEvent():
_executeAsync(this, &AbstractEvent::executeAsyncImpl), _executeAsync(this, &AbstractEvent::executeAsyncImpl),
_enabled(true) _enabled(true)
{ {
@@ -173,44 +186,51 @@ public:
virtual ~AbstractEvent() virtual ~AbstractEvent()
{ {
} }
void operator += (const TDelegate& aDelegate) void operator += (const TDelegate& aDelegate)
/// Adds a delegate to the event. If the observer is equal to an /// Adds a delegate to the event.
/// already existing one (determined by the < operator), ///
/// it will simply replace the existing observer. /// Exact behavior is determined by the TStrategy.
/// This behavior is determined by the TStrategy. Current implementations {
/// (DefaultStrategy, FIFOStrategy) follow that guideline but future ones typename TMutex::ScopedLock lock(_mutex);
/// can deviate. _strategy.add(aDelegate);
{ }
typename TMutex::ScopedLock lock(_mutex);
_strategy.add(aDelegate); void operator -= (const TDelegate& aDelegate)
} /// Removes a delegate from the event.
///
void operator -= (const TDelegate& aDelegate) /// If the delegate is not found, this function does nothing.
/// Removes a delegate from the event. If the delegate is equal to an {
/// already existing one is determined by the < operator. typename TMutex::ScopedLock lock(_mutex);
/// If the observer is not found, the unregister will be ignored _strategy.remove(aDelegate);
{ }
typename TMutex::ScopedLock lock(_mutex);
_strategy.remove(aDelegate); void operator () (const void* pSender, TArgs& args)
} /// Shortcut for notify(pSender, args);
{
void operator () (const void* pSender, TArgs& args) notify(pSender, args);
{ }
notify(pSender, args);
} void operator () (TArgs& args)
/// Shortcut for notify(args).
{
notify(0, args);
}
void notify(const void* pSender, TArgs& args) void notify(const void* pSender, TArgs& args)
/// Sends a notification to all registered delegates. The order is /// Sends a notification to all registered delegates. The order is
/// determined by the TStrategy. This method is blocking. While executing, /// determined by the TStrategy. This method is blocking. While executing,
/// other objects can change the list of delegates. These changes don't /// the list of delegates may be modified. These changes don't
/// influence the current active notifications but are activated with /// influence the current active notifications but are activated with
/// the next notify. If one of the delegates throws an exception, the notify /// the next notify. If a delegate is removed during a notify(), the
/// method is immediately aborted and the exception is reported to the caller. /// delegate will no longer be invoked (unless it has already been
{ /// invoked prior to removal). If one of the delegates throws an exception,
Poco::ScopedLockWithUnlock<TMutex> lock(_mutex); /// the notify method is immediately aborted and the exception is propagated
/// to the caller.
{
Poco::ScopedLockWithUnlock<TMutex> lock(_mutex);
if (!_enabled) return; if (!_enabled) return;
// thread-safeness: // thread-safeness:
@@ -225,16 +245,17 @@ public:
/// Sends a notification to all registered delegates. The order is /// Sends a notification to all registered delegates. The order is
/// determined by the TStrategy. This method is not blocking and will /// determined by the TStrategy. This method is not blocking and will
/// immediately return. The delegates are invoked in a seperate thread. /// immediately return. The delegates are invoked in a seperate thread.
/// Call activeResult.wait() to wait until the notification has ended. /// Call activeResult.wait() to wait until the notification has ended.
/// While executing, other objects can change the delegate list. These changes don't /// While executing, other objects can change the delegate list. These changes don't
/// influence the current active notifications but are activated with /// influence the current active notifications but are activated with
/// the next notify. If one of the delegates throws an exception, the execution /// the next notify. If a delegate is removed during a notify(), the
/// is aborted and the exception is reported to the caller. /// delegate will no longer be invoked (unless it has already been
{ /// invoked prior to removal). If one of the delegates throws an exception,
NotifyAsyncParams params(pSender, args); /// the execution is aborted and the exception is propagated to the caller.
{
{ NotifyAsyncParams params(pSender, args);
typename TMutex::ScopedLock lock(_mutex); {
typename TMutex::ScopedLock lock(_mutex);
// thread-safeness: // thread-safeness:
// copy should be faster and safer than blocking until // copy should be faster and safer than blocking until
@@ -245,7 +266,6 @@ public:
params.ptrStrat = SharedPtr<TStrategy>(new TStrategy(_strategy)); params.ptrStrat = SharedPtr<TStrategy>(new TStrategy(_strategy));
params.enabled = _enabled; params.enabled = _enabled;
} }
ActiveResult<TArgs> result = _executeAsync(params); ActiveResult<TArgs> result = _executeAsync(params);
return result; return result;
} }
@@ -291,13 +311,13 @@ protected:
SharedPtr<TStrategy> ptrStrat; SharedPtr<TStrategy> ptrStrat;
const void* pSender; const void* pSender;
TArgs args; TArgs args;
bool enabled; bool enabled;
NotifyAsyncParams(const void* pSend, const TArgs& a):ptrStrat(), pSender(pSend), args(a), enabled(true) NotifyAsyncParams(const void* pSend, const TArgs& a):ptrStrat(), pSender(pSend), args(a), enabled(true)
/// default constructor reduces the need for TArgs to have an empty constructor, only copy constructor is needed. /// Default constructor reduces the need for TArgs to have an empty constructor, only copy constructor is needed.
{ {
} }
}; };
ActiveMethod<TArgs, NotifyAsyncParams, AbstractEvent> _executeAsync; ActiveMethod<TArgs, NotifyAsyncParams, AbstractEvent> _executeAsync;

View File

@@ -1,7 +1,7 @@
// //
// AbstractObserver.h // AbstractObserver.h
// //
// $Id: //poco/svn/Foundation/include/Poco/AbstractObserver.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/AbstractObserver.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Notifications // Package: Notifications
@@ -59,10 +59,10 @@ public:
AbstractObserver& operator = (const AbstractObserver& observer); AbstractObserver& operator = (const AbstractObserver& observer);
virtual void notify(Notification* pNf) const = 0; virtual void notify(Notification* pNf) const = 0;
virtual bool equals(const AbstractObserver& observer) const = 0; virtual bool equals(const AbstractObserver& observer) const = 0;
virtual bool accepts(Notification* pNf) const = 0; virtual bool accepts(Notification* pNf) const = 0;
virtual AbstractObserver* clone() const = 0; virtual AbstractObserver* clone() const = 0;
virtual void disable() = 0; virtual void disable() = 0;
}; };

View File

@@ -1,7 +1,7 @@
// //
// AbstractPriorityDelegate.h // AbstractPriorityDelegate.h
// //
// $Id: //poco/1.4/Foundation/include/Poco/AbstractPriorityDelegate.h#1 $ // $Id: //poco/1.4/Foundation/include/Poco/AbstractPriorityDelegate.h#3 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the AbstractPriorityDelegate template. // Implementation of the AbstractPriorityDelegate template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -41,65 +41,41 @@
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include "Poco/AbstractDelegate.h"
namespace Poco { namespace Poco {
template <class TArgs> template <class TArgs>
class AbstractPriorityDelegate class AbstractPriorityDelegate: public AbstractDelegate<TArgs>
/// Interface for PriorityDelegate and PriorityExpire. /// Base class for PriorityDelegate and PriorityExpire.
/// Very similar to AbstractDelegate but having two separate files (no inheritance) ///
/// allows to have compile-time checks when registering an observer /// Extends AbstractDelegate with a priority value.
/// instead of run-time checks.
{ {
public: public:
AbstractPriorityDelegate(void* pTarget, int prio): AbstractPriorityDelegate(int prio):
_pTarget(pTarget), _priority(prio)
_priority(prio) {
{ }
}
AbstractPriorityDelegate(const AbstractPriorityDelegate& del): AbstractPriorityDelegate(const AbstractPriorityDelegate& del):
_pTarget(del._pTarget), AbstractDelegate<TArgs>(del),
_priority(del._priority) _priority(del._priority)
{ {
} }
virtual ~AbstractPriorityDelegate() virtual ~AbstractPriorityDelegate()
{ {
} }
virtual bool notify(const void* sender, TArgs & arguments) = 0; int priority() const
/// Returns false, if the Delegate is no longer valid, thus indicating an expire {
return _priority;
virtual AbstractPriorityDelegate* clone() const = 0; }
// Returns a deep-copy of the object.
bool operator < (const AbstractPriorityDelegate<TArgs>& other) const
/// Operator used for comparing AbstractPriorityDelegates in a collection.
{
if (_priority == other._priority)
{
return _pTarget < other._pTarget;
}
return (_priority < other._priority);
}
void* target() const
{
return _pTarget;
}
int priority() const
{
return _priority;
}
protected: protected:
void* _pTarget; int _priority;
int _priority;
}; };

View File

@@ -1,7 +1,7 @@
// //
// AccessExpirationDecorator.h // AccessExpirationDecorator.h
// //
// $Id: //poco/1.4/Foundation/include/Poco/AccessExpirationDecorator.h#1 $ // $Id: //poco/1.4/Foundation/include/Poco/AccessExpirationDecorator.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Cache // Package: Cache

View File

@@ -1,7 +1,7 @@
// //
// ActiveDispatcher.h // ActiveDispatcher.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ActiveDispatcher.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ActiveDispatcher.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading

View File

@@ -1,7 +1,7 @@
// //
// ActiveResult.h // ActiveResult.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ActiveResult.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ActiveResult.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading

View File

@@ -1,7 +1,7 @@
// //
// ActiveRunnable.h // ActiveRunnable.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ActiveRunnable.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ActiveRunnable.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading

View File

@@ -1,7 +1,7 @@
// //
// ActiveStarter.h // ActiveStarter.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ActiveStarter.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ActiveStarter.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading

View File

@@ -1,7 +1,7 @@
// //
// Activity.h // Activity.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Activity.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Activity.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading

View File

@@ -1,7 +1,7 @@
// //
// Any.h // Any.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Any.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Any.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -54,151 +54,151 @@ class Any
/// by Applied Informatics. /// by Applied Informatics.
{ {
public: public:
Any(): Any():
_content(0) _content(0)
/// Creates an empty any type. /// Creates an empty any type.
{ {
} }
template <typename ValueType> template <typename ValueType>
Any(const ValueType& value): Any(const ValueType& value):
_content(new Holder<ValueType>(value)) _content(new Holder<ValueType>(value))
/// Creates an any which stores the init parameter inside. /// Creates an any which stores the init parameter inside.
/// ///
/// Example: /// Example:
/// Any a(13); /// Any a(13);
/// Any a(string("12345")); /// Any a(string("12345"));
{ {
} }
Any(const Any& other): Any(const Any& other):
_content(other._content ? other._content->clone() : 0) _content(other._content ? other._content->clone() : 0)
/// Copy constructor, works with empty Anys and initialized Any values. /// Copy constructor, works with empty Anys and initialized Any values.
{ {
} }
~Any() ~Any()
{ {
delete _content; delete _content;
} }
Any& swap(Any& rhs) Any& swap(Any& rhs)
/// Swaps the content of the two Anys. /// Swaps the content of the two Anys.
{ {
std::swap(_content, rhs._content); std::swap(_content, rhs._content);
return *this; return *this;
} }
template <typename ValueType> template <typename ValueType>
Any& operator = (const ValueType& rhs) Any& operator = (const ValueType& rhs)
/// Assignment operator for all types != Any. /// Assignment operator for all types != Any.
/// ///
/// Example: /// Example:
/// Any a = 13; /// Any a = 13;
/// Any a = string("12345"); /// Any a = string("12345");
{ {
Any(rhs).swap(*this); Any(rhs).swap(*this);
return *this; return *this;
} }
Any& operator = (const Any& rhs) Any& operator = (const Any& rhs)
/// Assignment operator for Any. /// Assignment operator for Any.
{ {
Any(rhs).swap(*this); Any(rhs).swap(*this);
return *this; return *this;
} }
bool empty() const bool empty() const
/// returns true if the Any is empty /// returns true if the Any is empty
{ {
return !_content; return !_content;
} }
const std::type_info& type() const const std::type_info& type() const
/// Returns the type information of the stored content. /// Returns the type information of the stored content.
/// If the Any is empty typeid(void) is returned. /// If the Any is empty typeid(void) is returned.
/// It is suggested to always query an Any for its type info before trying to extract /// It is suggested to always query an Any for its type info before trying to extract
/// data via an AnyCast/RefAnyCast. /// data via an AnyCast/RefAnyCast.
{ {
return _content ? _content->type() : typeid(void); return _content ? _content->type() : typeid(void);
} }
private: private:
class Placeholder class Placeholder
{ {
public: public:
virtual ~Placeholder() virtual ~Placeholder()
{ {
} }
virtual const std::type_info& type() const = 0; virtual const std::type_info& type() const = 0;
virtual Placeholder* clone() const = 0; virtual Placeholder* clone() const = 0;
}; };
template <typename ValueType> template <typename ValueType>
class Holder: public Placeholder class Holder: public Placeholder
{ {
public: public:
Holder(const ValueType& value): Holder(const ValueType& value):
_held(value) _held(value)
{ {
} }
virtual const std::type_info& type() const virtual const std::type_info& type() const
{ {
return typeid(ValueType); return typeid(ValueType);
} }
virtual Placeholder* clone() const virtual Placeholder* clone() const
{ {
return new Holder(_held); return new Holder(_held);
} }
ValueType _held; ValueType _held;
}; };
private: private:
template <typename ValueType> template <typename ValueType>
friend ValueType* AnyCast(Any*); friend ValueType* AnyCast(Any*);
template <typename ValueType> template <typename ValueType>
friend ValueType* UnsafeAnyCast(Any*); friend ValueType* UnsafeAnyCast(Any*);
template <typename ValueType> template <typename ValueType>
friend ValueType& RefAnyCast(Any&); friend ValueType& RefAnyCast(Any&);
template <typename ValueType> template <typename ValueType>
friend const ValueType& RefAnyCast(const Any&); friend const ValueType& RefAnyCast(const Any&);
Placeholder* _content; Placeholder* _content;
}; };
template <typename ValueType> template <typename ValueType>
inline ValueType* AnyCast(Any* operand) inline ValueType* AnyCast(Any* operand)
/// AnyCast operator used to extract the ValueType from an Any*. Will return a pointer /// AnyCast operator used to extract the ValueType from an Any*. Will return a pointer
/// to the stored value. /// to the stored value.
/// ///
/// Example Usage: /// Example Usage:
/// MyType* pTmp = AnyCast<MyType*>(pAny). /// MyType* pTmp = AnyCast<MyType*>(pAny).
/// Will return NULL if the cast fails, i.e. types don't match. /// Will return NULL if the cast fails, i.e. types don't match.
{ {
return operand && operand->type() == typeid(ValueType) return operand && operand->type() == typeid(ValueType)
? &static_cast<Any::Holder<ValueType>*>(operand->_content)->_held ? &static_cast<Any::Holder<ValueType>*>(operand->_content)->_held
: 0; : 0;
} }
template <typename ValueType> template <typename ValueType>
inline const ValueType* AnyCast(const Any* operand) inline const ValueType* AnyCast(const Any* operand)
/// AnyCast operator used to extract a const ValueType pointer from an const Any*. Will return a const pointer /// AnyCast operator used to extract a const ValueType pointer from an const Any*. Will return a const pointer
/// to the stored value. /// to the stored value.
/// ///
/// Example Usage: /// Example Usage:
/// const MyType* pTmp = AnyCast<MyType*>(pAny). /// const MyType* pTmp = AnyCast<MyType*>(pAny).
/// Will return NULL if the cast fails, i.e. types don't match. /// Will return NULL if the cast fails, i.e. types don't match.
{ {
return AnyCast<ValueType>(const_cast<Any*>(operand)); return AnyCast<ValueType>(const_cast<Any*>(operand));
} }
@@ -207,16 +207,16 @@ ValueType AnyCast(const Any& operand)
/// AnyCast operator used to extract a copy of the ValueType from an const Any&. /// AnyCast operator used to extract a copy of the ValueType from an const Any&.
/// ///
/// Example Usage: /// Example Usage:
/// MyType tmp = AnyCast<MyType>(anAny). /// MyType tmp = AnyCast<MyType>(anAny).
/// Will throw a BadCastException if the cast fails. /// Will throw a BadCastException if the cast fails.
/// Dont use an AnyCast in combination with references, i.e. MyType& tmp = ... or const MyType& = ... /// Dont use an AnyCast in combination with references, i.e. MyType& tmp = ... or const MyType& = ...
/// Some compilers will accept this code although a copy is returned. Use the RefAnyCast in /// Some compilers will accept this code although a copy is returned. Use the RefAnyCast in
/// these cases. /// these cases.
{ {
ValueType* result = AnyCast<ValueType>(const_cast<Any*>(&operand)); ValueType* result = AnyCast<ValueType>(const_cast<Any*>(&operand));
if (!result) if (!result)
throw BadCastException("Failed to convert between const Any types"); throw BadCastException("Failed to convert between const Any types");
return *result; return *result;
} }
@@ -225,30 +225,30 @@ ValueType AnyCast(Any& operand)
/// AnyCast operator used to extract a copy of the ValueType from an Any&. /// AnyCast operator used to extract a copy of the ValueType from an Any&.
/// ///
/// Example Usage: /// Example Usage:
/// MyType tmp = AnyCast<MyType>(anAny). /// MyType tmp = AnyCast<MyType>(anAny).
/// Will throw a BadCastException if the cast fails. /// Will throw a BadCastException if the cast fails.
/// Dont use an AnyCast in combination with references, i.e. MyType& tmp = ... or const MyType& tmp = ... /// Dont use an AnyCast in combination with references, i.e. MyType& tmp = ... or const MyType& tmp = ...
/// Some compilers will accept this code although a copy is returned. Use the RefAnyCast in /// Some compilers will accept this code although a copy is returned. Use the RefAnyCast in
/// these cases. /// these cases.
{ {
ValueType* result = AnyCast<ValueType>(&operand); ValueType* result = AnyCast<ValueType>(&operand);
if (!result) if (!result)
throw BadCastException("Failed to convert between Any types"); throw BadCastException("Failed to convert between Any types");
return *result; return *result;
} }
template <typename ValueType> template <typename ValueType>
const ValueType& RefAnyCast(const Any& operand) const ValueType& RefAnyCast(const Any & operand)
/// AnyCast operator used to return a const reference to the internal data. /// AnyCast operator used to return a const reference to the internal data.
/// ///
/// Example Usage: /// Example Usage:
/// const MyType& tmp = RefAnyCast<MyType>(anAny); /// const MyType& tmp = RefAnyCast<MyType>(anAny);
{ {
if (operand.type() == typeid(ValueType)) if (operand.type() == typeid(ValueType))
return static_cast<Any::Holder<ValueType>*>(operand._content)->_held; return static_cast<Any::Holder<ValueType>*>(operand._content)->_held;
else else
throw BadCastException("RefAnyCast: Failed to convert between const Any types"); throw BadCastException("RefAnyCast: Failed to convert between const Any types");
} }
@@ -256,37 +256,37 @@ template <typename ValueType>
ValueType& RefAnyCast(Any& operand) ValueType& RefAnyCast(Any& operand)
/// AnyCast operator used to return a reference to the internal data. /// AnyCast operator used to return a reference to the internal data.
/// ///
/// Example Usage: /// Example Usage:
/// MyType& tmp = RefAnyCast<MyType>(anAny); /// MyType& tmp = RefAnyCast<MyType>(anAny);
{ {
if (operand.type() == typeid(ValueType)) if (operand.type() == typeid(ValueType))
return static_cast<Any::Holder<ValueType>*>(operand._content)->_held; return static_cast<Any::Holder<ValueType>*>(operand._content)->_held;
else else
throw BadCastException("RefAnyCast: Failed to convert between Any types"); throw BadCastException("RefAnyCast: Failed to convert between Any types");
} }
template <typename ValueType> template <typename ValueType>
inline ValueType* UnsafeAnyCast(Any* operand) inline ValueType* UnsafeAnyCast(Any* operand)
/// The "unsafe" versions of AnyCast are not part of the /// The "unsafe" versions of AnyCast are not part of the
/// public interface and may be removed at any time. They are /// public interface and may be removed at any time. They are
/// required where we know what type is stored in the any and can't /// required where we know what type is stored in the any and can't
/// use typeid() comparison, e.g., when our types may travel across /// use typeid() comparison, e.g., when our types may travel across
/// different shared libraries. /// different shared libraries.
{ {
return &static_cast<Any::Holder<ValueType>*>(operand->_content)->_held; return &static_cast<Any::Holder<ValueType>*>(operand->_content)->_held;
} }
template <typename ValueType> template <typename ValueType>
inline const ValueType* UnsafeAnyCast(const Any* operand) inline const ValueType* UnsafeAnyCast(const Any* operand)
/// The "unsafe" versions of AnyCast are not part of the /// The "unsafe" versions of AnyCast are not part of the
/// public interface and may be removed at any time. They are /// public interface and may be removed at any time. They are
/// required where we know what type is stored in the any and can't /// required where we know what type is stored in the any and can't
/// use typeid() comparison, e.g., when our types may travel across /// use typeid() comparison, e.g., when our types may travel across
/// different shared libraries. /// different shared libraries.
{ {
return AnyCast<ValueType>(const_cast<Any*>(operand)); return AnyCast<ValueType>(const_cast<Any*>(operand));
} }

View File

@@ -1,7 +1,7 @@
// //
// ArchiveStrategy.h // ArchiveStrategy.h
// //
// $Id: //poco/Main/Foundation/include/Poco/ArchiveStrategy.h#5 $ // $Id: //poco/1.4/Foundation/include/Poco/ArchiveStrategy.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging

View File

@@ -1,7 +1,7 @@
// //
// AsyncChannel.h // AsyncChannel.h
// //
// $Id: //poco/svn/Foundation/include/Poco/AsyncChannel.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/AsyncChannel.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging

View File

@@ -1,7 +1,7 @@
// //
// AutoPtr.h // AutoPtr.h
// //
// $Id: //poco/svn/Foundation/include/Poco/AutoPtr.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/AutoPtr.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// AutoReleasePool.h // AutoReleasePool.h
// //
// $Id: //poco/svn/Foundation/include/Poco/AutoReleasePool.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/AutoReleasePool.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// Base64Decoder.h // Base64Decoder.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Base64Decoder.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Base64Decoder.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams
@@ -49,30 +49,30 @@ namespace Poco {
class Foundation_API Base64DecoderBuf: public UnbufferedStreamBuf class Foundation_API Base64DecoderBuf: public UnbufferedStreamBuf
/// This streambuf base64-decodes all data read /// This streambuf base64-decodes all data read
/// from the istream connected to it. /// from the istream connected to it.
/// ///
/// Note: For performance reasons, the characters /// Note: For performance reasons, the characters
/// are read directly from the given istream's /// are read directly from the given istream's
/// underlying streambuf, so the state /// underlying streambuf, so the state
/// of the istream will not reflect that of /// of the istream will not reflect that of
/// its streambuf. /// its streambuf.
{ {
public: public:
Base64DecoderBuf(std::istream& istr); Base64DecoderBuf(std::istream& istr);
~Base64DecoderBuf(); ~Base64DecoderBuf();
private: private:
int readFromDevice(); int readFromDevice();
int readOne(); int readOne();
unsigned char _group[3]; unsigned char _group[3];
int _groupLength; int _groupLength;
int _groupIndex; int _groupIndex;
std::streambuf& _buf; std::streambuf& _buf;
static unsigned char IN_ENCODING[256]; static unsigned char IN_ENCODING[256];
static bool IN_ENCODING_INIT; static bool IN_ENCODING_INIT;
private: private:
Base64DecoderBuf(const Base64DecoderBuf&); Base64DecoderBuf(const Base64DecoderBuf&);
@@ -101,17 +101,17 @@ private:
class Foundation_API Base64Decoder: public Base64DecoderIOS, public std::istream class Foundation_API Base64Decoder: public Base64DecoderIOS, public std::istream
/// This istream base64-decodes all data /// This istream base64-decodes all data
/// read from the istream connected to it. /// read from the istream connected to it.
/// ///
/// Note: For performance reasons, the characters /// Note: For performance reasons, the characters
/// are read directly from the given istream's /// are read directly from the given istream's
/// underlying streambuf, so the state /// underlying streambuf, so the state
/// of the istream will not reflect that of /// of the istream will not reflect that of
/// its streambuf. /// its streambuf.
{ {
public: public:
Base64Decoder(std::istream& istr); Base64Decoder(std::istream& istr);
~Base64Decoder(); ~Base64Decoder();
private: private:

View File

@@ -1,7 +1,7 @@
// //
// Base64Encoder.h // Base64Encoder.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Base64Encoder.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Base64Encoder.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams
@@ -49,17 +49,17 @@ namespace Poco {
class Foundation_API Base64EncoderBuf: public UnbufferedStreamBuf class Foundation_API Base64EncoderBuf: public UnbufferedStreamBuf
/// This streambuf base64-encodes all data written /// This streambuf base64-encodes all data written
/// to it and forwards it to a connected /// to it and forwards it to a connected
/// ostream. /// ostream.
/// ///
/// Note: The characters are directly written /// Note: The characters are directly written
/// to the ostream's streambuf, thus bypassing /// to the ostream's streambuf, thus bypassing
/// the ostream. The ostream's state is therefore /// the ostream. The ostream's state is therefore
/// not updated to match the buffer's state. /// not updated to match the buffer's state.
{ {
public: public:
Base64EncoderBuf(std::ostream& ostr); Base64EncoderBuf(std::ostream& ostr);
~Base64EncoderBuf(); ~Base64EncoderBuf();
int close(); int close();
@@ -80,13 +80,13 @@ private:
int writeToDevice(char c); int writeToDevice(char c);
unsigned char _group[3]; unsigned char _group[3];
int _groupLength; int _groupLength;
int _pos; int _pos;
int _lineLength; int _lineLength;
std::streambuf& _buf; std::streambuf& _buf;
static const unsigned char OUT_ENCODING[64]; static const unsigned char OUT_ENCODING[64];
friend class Base64DecoderBuf; friend class Base64DecoderBuf;
Base64EncoderBuf(const Base64EncoderBuf&); Base64EncoderBuf(const Base64EncoderBuf&);
@@ -119,17 +119,17 @@ class Foundation_API Base64Encoder: public Base64EncoderIOS, public std::ostream
/// This ostream base64-encodes all data /// This ostream base64-encodes all data
/// written to it and forwards it to /// written to it and forwards it to
/// a connected ostream. /// a connected ostream.
/// Always call close() when done /// Always call close() when done
/// writing data, to ensure proper /// writing data, to ensure proper
/// completion of the encoding operation. /// completion of the encoding operation.
/// ///
/// Note: The characters are directly written /// Note: The characters are directly written
/// to the ostream's streambuf, thus bypassing /// to the ostream's streambuf, thus bypassing
/// the ostream. The ostream's state is therefore /// the ostream. The ostream's state is therefore
/// not updated to match the buffer's state. /// not updated to match the buffer's state.
{ {
public: public:
Base64Encoder(std::ostream& ostr); Base64Encoder(std::ostream& ostr);
~Base64Encoder(); ~Base64Encoder();
private: private:

View File

@@ -1,7 +1,7 @@
// //
// BasicEvent.h // BasicEvent.h
// //
// $Id: //poco/svn/Foundation/include/Poco/BasicEvent.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/BasicEvent.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the BasicEvent template. // Implementation of the BasicEvent template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -36,14 +36,14 @@
// //
#ifndef Foundation_BasicEvent_INCLUDED #ifndef Foundation_BasicEvent_INCLUDED
#define Foundation_BasicEvent_INCLUDED #define Foundation_BasicEvent_INCLUDED
#include "Poco/AbstractEvent.h" #include "Poco/AbstractEvent.h"
#include "Poco/DefaultStrategy.h" #include "Poco/DefaultStrategy.h"
#include "Poco/AbstractDelegate.h" #include "Poco/AbstractDelegate.h"
#include "Poco/CompareFunctions.h" #include "Poco/Mutex.h"
namespace Poco { namespace Poco {
@@ -51,22 +51,15 @@ namespace Poco {
template <class TArgs, class TMutex = FastMutex> template <class TArgs, class TMutex = FastMutex>
class BasicEvent: public AbstractEvent < class BasicEvent: public AbstractEvent <
TArgs, DefaultStrategy<TArgs, AbstractDelegate<TArgs>, p_less<AbstractDelegate<TArgs> > >, TArgs, DefaultStrategy<TArgs, AbstractDelegate<TArgs> >,
AbstractDelegate<TArgs>, AbstractDelegate<TArgs>,
TMutex TMutex
> >
/// A BasicEvent uses internally a DefaultStrategy which /// A BasicEvent uses the DefaultStrategy which
/// invokes delegates in an arbitrary manner. /// invokes delegates in the order they have been registered.
/// Note that one object can only register one method to a BasicEvent.
/// Subsequent registrations will overwrite the existing delegate.
/// For example:
/// BasicEvent<int> event;
/// MyClass myObject;
/// event += delegate(&myObject, &MyClass::myMethod1);
/// event += delegate(&myObject, &MyClass::myMethod2);
/// ///
/// The second registration will overwrite the first one. The reason is simply that /// Please see the AbstractEvent class template documentation
/// function pointers can only be compared by equality but not by lower than. /// for more information.
{ {
public: public:
BasicEvent() BasicEvent()
@@ -86,4 +79,4 @@ private:
} // namespace Poco } // namespace Poco
#endif #endif // Foundation_BasicEvent_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// BinaryReader.h // BinaryReader.h
// //
// $Id: //poco/svn/Foundation/include/Poco/BinaryReader.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/BinaryReader.h#3 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams
@@ -53,11 +53,11 @@ class TextConverter;
class Foundation_API BinaryReader class Foundation_API BinaryReader
/// This class reads basic types (and std::vectors thereof) /// This class reads basic types (and std::vectors thereof)
/// in binary form into an input stream. /// in binary form into an input stream.
/// It provides an extractor-based interface similar to istream. /// It provides an extractor-based interface similar to istream.
/// The reader also supports automatic conversion from big-endian /// The reader also supports automatic conversion from big-endian
/// (network byte order) to little-endian and vice-versa. /// (network byte order) to little-endian and vice-versa.
/// Use a BinaryWriter to create a stream suitable for a BinaryReader. /// Use a BinaryWriter to create a stream suitable for a BinaryReader.
{ {
public: public:
@@ -70,17 +70,17 @@ public:
UNSPECIFIED_BYTE_ORDER = 4 /// unknown, byte-order will be determined by reading the byte-order mark UNSPECIFIED_BYTE_ORDER = 4 /// unknown, byte-order will be determined by reading the byte-order mark
}; };
BinaryReader(std::istream& istr, StreamByteOrder byteOrder = NATIVE_BYTE_ORDER); BinaryReader(std::istream& istr, StreamByteOrder byteOrder = NATIVE_BYTE_ORDER);
/// Creates the BinaryReader. /// Creates the BinaryReader.
BinaryReader(std::istream& istr, TextEncoding& encoding, StreamByteOrder byteOrder = NATIVE_BYTE_ORDER); BinaryReader(std::istream& istr, TextEncoding& encoding, StreamByteOrder byteOrder = NATIVE_BYTE_ORDER);
/// Creates the BinaryReader using the given TextEncoding. /// Creates the BinaryReader using the given TextEncoding.
/// ///
/// Strings will be converted from the specified encoding /// Strings will be converted from the specified encoding
/// to the currently set global encoding (see Poco::TextEncoding::global()). /// to the currently set global encoding (see Poco::TextEncoding::global()).
~BinaryReader(); ~BinaryReader();
/// Destroys the BinaryReader. /// Destroys the BinaryReader.
BinaryReader& operator >> (bool& value); BinaryReader& operator >> (bool& value);
BinaryReader& operator >> (char& value); BinaryReader& operator >> (char& value);
@@ -100,46 +100,46 @@ public:
BinaryReader& operator >> (UInt64& value); BinaryReader& operator >> (UInt64& value);
#endif #endif
BinaryReader& operator >> (std::string& value); BinaryReader& operator >> (std::string& value);
template <typename T> template <typename T>
BinaryReader& operator >> (std::vector<T>& value) BinaryReader& operator >> (std::vector<T>& value)
{ {
Poco::UInt32 size(0); Poco::UInt32 size(0);
T elem; T elem;
*this >> size; *this >> size;
if (!good()) return *this; if (!good()) return *this;
value.reserve(size); value.reserve(size);
while (this->good() && size-- > 0) while (this->good() && size-- > 0)
{ {
*this >> elem; *this >> elem;
value.push_back(elem); value.push_back(elem);
} }
return *this; return *this;
} }
void read7BitEncoded(UInt32& value); void read7BitEncoded(UInt32& value);
/// Reads a 32-bit unsigned integer in compressed format. /// Reads a 32-bit unsigned integer in compressed format.
/// See BinaryWriter::write7BitEncoded() for a description /// See BinaryWriter::write7BitEncoded() for a description
/// of the compression algorithm. /// of the compression algorithm.
#if defined(POCO_HAVE_INT64) #if defined(POCO_HAVE_INT64)
void read7BitEncoded(UInt64& value); void read7BitEncoded(UInt64& value);
/// Reads a 64-bit unsigned integer in compressed format. /// Reads a 64-bit unsigned integer in compressed format.
/// See BinaryWriter::write7BitEncoded() for a description /// See BinaryWriter::write7BitEncoded() for a description
/// of the compression algorithm. /// of the compression algorithm.
#endif #endif
void readRaw(std::streamsize length, std::string& value); void readRaw(std::streamsize length, std::string& value);
/// Reads length bytes of raw data into value. /// Reads length bytes of raw data into value.
void readRaw(char* buffer, std::streamsize length); void readRaw(char* buffer, std::streamsize length);
/// Reads length bytes of raw data into buffer. /// Reads length bytes of raw data into buffer.
void readBOM(); void readBOM();
/// Reads a byte-order mark from the stream and configures /// Reads a byte-order mark from the stream and configures
/// the reader for the encountered byte order. /// the reader for the encountered byte order.
/// A byte-order mark is a 16-bit integer with a value of 0xFEFF, /// A byte-order mark is a 16-bit integer with a value of 0xFEFF,
/// written in host byte order. /// written in host byte order.
@@ -163,9 +163,9 @@ public:
/// either BIG_ENDIAN_BYTE_ORDER or LITTLE_ENDIAN_BYTE_ORDER. /// either BIG_ENDIAN_BYTE_ORDER or LITTLE_ENDIAN_BYTE_ORDER.
private: private:
std::istream& _istr; std::istream& _istr;
bool _flipBytes; bool _flipBytes;
TextConverter* _pTextConverter; TextConverter* _pTextConverter;
}; };

View File

@@ -1,7 +1,7 @@
// //
// Buffer.h // Buffer.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Buffer.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Buffer.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -50,131 +50,131 @@ namespace Poco {
template <class T> template <class T>
class Buffer class Buffer
/// A buffer class that allocates a buffer of a given type and size. /// A buffer class that allocates a buffer of a given type and size.
/// Buffer can be zero-size, resized, copy-constructed and assigned. /// Buffer can be zero-size, resized, copy-constructed and assigned.
/// Memory allocation, resizing and deallocation is managed automatically. /// Memory allocation, resizing and deallocation is managed automatically.
/// ///
/// This class is useful everywhere where a temporary buffer /// This class is useful everywhere where a temporary buffer
/// is needed. /// is needed.
{ {
public: public:
Buffer(std::size_t size): Buffer(std::size_t size):
_size(size), _size(size),
_ptr(size ? new T[size] : 0) _ptr(size ? new T[size] : 0)
/// Creates and allocates the Buffer. /// Creates and allocates the Buffer.
{ {
} }
Buffer(): _size(0), _ptr(0) Buffer(): _size(0), _ptr(0)
/// Creates the Buffer. /// Creates the Buffer.
{ {
} }
Buffer(const Buffer& other):
/// Copy constructor.
_size(other._size),
_ptr(other._size ? new T[other._size] : 0)
{
if (_size)
std::memcpy(_ptr, other._ptr, _size * sizeof(T));
}
Buffer(const Buffer& other): Buffer& operator = (const Buffer& other)
/// Copy constructor. /// Assignment operator.
_size(other._size), {
_ptr(other._size ? new T[other._size] : 0) if (this != &other)
{ {
if (_size) Buffer tmp(other);
std::memcpy(_ptr, other._ptr, _size * sizeof(T)); swap(tmp);
} }
Buffer& operator = (const Buffer& other) return *this;
/// Assignment operator. }
{
if (this != &other)
{
Buffer tmp(other);
swap(tmp);
}
return *this; ~Buffer()
} /// Destroys the Buffer.
{
~Buffer() delete [] _ptr;
/// Destroys the Buffer. }
{
delete [] _ptr; void swap(Buffer& other)
} /// Swaps the buffer with another one.
{
void swap(Buffer& other) using std::swap;
/// Swaps the buffer with another one.
{ swap(_ptr, other._ptr);
using std::swap; swap(_size, other._size);
}
swap(_ptr, other._ptr);
swap(_size, other._size); std::size_t size() const
}
std::size_t size() const
/// Returns the size of the buffer. /// Returns the size of the buffer.
{ {
return _size; return _size;
} }
void clear() void clear()
/// Sets the contents of the bufer to zero. /// Sets the contents of the bufer to zero.
{ {
std::memset(_ptr, 0, _size * sizeof(T)); std::memset(_ptr, 0, _size * sizeof(T));
} }
void resize(std::size_t newSize, bool preserve = false) void resize(std::size_t newSize, bool preserve = false)
/// Resizes the buffer. If preserve is true, the contents /// Resizes the buffer. If preserve is true, the contents
/// of the buffer is preserved. If the newSize is smaller /// of the buffer is preserved. If the newSize is smaller
/// than the current size, data truncation will occur. /// than the current size, data truncation will occur.
/// ///
/// For efficiency sake, the default behavior is not to /// For efficiency sake, the default behavior is not to
/// preserve the contents. /// preserve the contents.
{ {
if (preserve) if (preserve)
{ {
if (_size == newSize) return; if (_size == newSize) return;
Buffer tmp; Buffer tmp;
tmp = *this; tmp = *this;
recreate(newSize); recreate(newSize);
std::size_t size = _size < tmp._size ? _size : tmp._size; std::size_t size = _size < tmp._size ? _size : tmp._size;
std::memcpy(_ptr, tmp._ptr, size * sizeof(T)); std::memcpy(_ptr, tmp._ptr, size * sizeof(T));
return; return;
} }
else if (_size == newSize) else if (_size == newSize)
{ {
clear(); clear();
return; return;
} }
recreate(newSize); recreate(newSize);
} }
void append(const T* buf, std::size_t sz) void append(const T* buf, std::size_t sz)
/// Resizes this buffer and appends the argument buffer. /// Resizes this buffer and appends the argument buffer.
{ {
if (0 == sz) return; if (0 == sz) return;
std::size_t oldSize = _size; std::size_t oldSize = _size;
resize(_size + sz, true); resize(_size + sz, true);
std::memcpy(_ptr + oldSize, buf, sz); std::memcpy(_ptr + oldSize, buf, sz);
} }
void append(const Buffer& buf) void append(const Buffer& buf)
/// Resizes this buffer and appends the argument buffer. /// Resizes this buffer and appends the argument buffer.
{ {
append(buf.begin(), buf.size()); append(buf.begin(), buf.size());
} }
std::size_t elementSize() const std::size_t elementSize() const
/// Returns the size of the buffer element. /// Returns the size of the buffer element.
{ {
return sizeof(T); return sizeof(T);
} }
std::size_t byteCount() const std::size_t byteCount() const
/// Returns the total length of the buffer in bytes. /// Returns the total length of the buffer in bytes.
{ {
return _size * sizeof(T); return _size * sizeof(T);
} }
T* begin() T* begin()
/// Returns a pointer to the beginning of the buffer. /// Returns a pointer to the beginning of the buffer.
{ {
return _ptr; return _ptr;
} }
@@ -193,18 +193,18 @@ public:
const T* end() const const T* end() const
/// Returns a pointer to the end of the buffer. /// Returns a pointer to the end of the buffer.
{ {
return _ptr + _size; return _ptr + _size;
} }
bool isEmpty() const bool isEmpty() const
/// Return true if buffer is empty. /// Return true if buffer is empty.
{ {
return 0 == _size; return 0 == _size;
} }
T& operator [] (std::size_t index) T& operator [] (std::size_t index)
{ {
poco_assert (index < _size); poco_assert (index < _size);
return _ptr[index]; return _ptr[index];
} }
@@ -214,26 +214,26 @@ public:
poco_assert (index < _size); poco_assert (index < _size);
return _ptr[index]; return _ptr[index];
} }
private: private:
void recreate(std::size_t newSize) void recreate(std::size_t newSize)
{ {
if (newSize != _size) if (newSize != _size)
{ {
delete [] _ptr; delete [] _ptr;
if (0 == newSize) if (0 == newSize)
_ptr = 0; _ptr = 0;
else else
_ptr = new T[newSize]; _ptr = new T[newSize];
_size = newSize; _size = newSize;
} }
} }
std::size_t _size; std::size_t _size;
T* _ptr; T* _ptr;
}; };

View File

@@ -1,7 +1,7 @@
// //
// BufferAllocator.h // BufferAllocator.h
// //
// $Id: //poco/svn/Foundation/include/Poco/BufferAllocator.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/BufferAllocator.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams

View File

@@ -1,7 +1,7 @@
// //
// BufferedBidirectionalStreamBuf.h // BufferedBidirectionalStreamBuf.h
// //
// $Id: //poco/Main/Foundation/include/Poco/BufferedBidirectionalStreamBuf.h#7 $ // $Id: //poco/1.4/Foundation/include/Poco/BufferedBidirectionalStreamBuf.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams

View File

@@ -1,7 +1,7 @@
// //
// BufferedStreamBuf.h // BufferedStreamBuf.h
// //
// $Id: //poco/Main/Foundation/include/Poco/BufferedStreamBuf.h#6 $ // $Id: //poco/1.4/Foundation/include/Poco/BufferedStreamBuf.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams

View File

@@ -1,7 +1,7 @@
// //
// Bugcheck.h // Bugcheck.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Bugcheck.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Bugcheck.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -96,10 +96,10 @@ protected:
// useful macros (these automatically supply line number and file name) // useful macros (these automatically supply line number and file name)
// //
#if defined(_DEBUG) #if defined(_DEBUG)
# define poco_assert_dbg(cond) \ #define poco_assert_dbg(cond) \
if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0 if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
#else #else
# define poco_assert_dbg(cond) #define poco_assert_dbg(cond)
#endif #endif
@@ -129,7 +129,7 @@ protected:
#if defined(_DEBUG) #if defined(_DEBUG)
# define poco_stdout_dbg(outstr) \ # define poco_stdout_dbg(outstr) \
std::cout << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl; std::cout << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
#else #else
# define poco_stdout_dbg(outstr) # define poco_stdout_dbg(outstr)
#endif #endif

View File

@@ -1,7 +1,7 @@
// //
// ByteOrder.h // ByteOrder.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ByteOrder.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ByteOrder.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// Channel.h // Channel.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Channel.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Channel.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging

View File

@@ -1,7 +1,7 @@
// //
// Checksum.h // Checksum.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Checksum.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Checksum.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// ClassLibrary.h // ClassLibrary.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ClassLibrary.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ClassLibrary.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: SharedLibrary // Package: SharedLibrary

View File

@@ -1,7 +1,7 @@
// //
// ClassLoader.h // ClassLoader.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ClassLoader.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ClassLoader.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: SharedLibrary // Package: SharedLibrary

View File

@@ -1,7 +1,7 @@
// //
// Condition.h // Condition.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Condition.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Condition.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading

View File

@@ -1,7 +1,7 @@
// //
// Config.h // Config.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Config.h#3 $ // $Id: //poco/1.4/Foundation/include/Poco/Config.h#3 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// Configurable.h // Configurable.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Configurable.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Configurable.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging

View File

@@ -1,7 +1,7 @@
// //
// ConsoleChannel.h // ConsoleChannel.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ConsoleChannel.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ConsoleChannel.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging

View File

@@ -1,7 +1,7 @@
// //
// CountingStream.h // CountingStream.h
// //
// $Id: //poco/svn/Foundation/include/Poco/CountingStream.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/CountingStream.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams

View File

@@ -1,7 +1,7 @@
// //
// DateTime.h // DateTime.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DateTime.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DateTime.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: DateTime // Package: DateTime
@@ -52,16 +52,16 @@ class Foundation_API DateTime
/// This class represents an instant in time, expressed /// This class represents an instant in time, expressed
/// in years, months, days, hours, minutes, seconds /// in years, months, days, hours, minutes, seconds
/// and milliseconds based on the Gregorian calendar. /// and milliseconds based on the Gregorian calendar.
/// The class is mainly useful for conversions between /// The class is mainly useful for conversions between
/// UTC, Julian day and Gregorian calendar dates. /// UTC, Julian day and Gregorian calendar dates.
/// ///
/// The date and time stored in a DateTime is always in UTC /// The date and time stored in a DateTime is always in UTC
/// (Coordinated Universal Time) and thus independent of the /// (Coordinated Universal Time) and thus independent of the
/// timezone in effect on the system. /// timezone in effect on the system.
/// ///
/// Conversion calculations are based on algorithms /// Conversion calculations are based on algorithms
/// collected and described by Peter Baum at /// collected and described by Peter Baum at
/// http://vsg.cape.com/~pbaum/date/date0.htm /// http://vsg.cape.com/~pbaum/date/date0.htm
/// ///
/// Internally, this class stores a date/time in two /// Internally, this class stores a date/time in two
/// forms (UTC and broken down) for performance reasons. Only use /// forms (UTC and broken down) for performance reasons. Only use
@@ -431,16 +431,6 @@ inline void swap(DateTime& d1, DateTime& d2)
} }
inline void DateTime::checkLimit(short& lower, short& higher, short limit)
{
if (lower >= limit)
{
higher += short(lower / limit);
lower = short(lower % limit);
}
}
} // namespace Poco } // namespace Poco

View File

@@ -1,7 +1,7 @@
// //
// DateTimeFormat.h // DateTimeFormat.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DateTimeFormat.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DateTimeFormat.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: DateTime // Package: DateTime

View File

@@ -1,7 +1,7 @@
// //
// DateTimeFormatter.h // DateTimeFormatter.h
// //
// $Id: //poco/Main/Foundation/include/Poco/DateTimeFormatter.h#4 $ // $Id: //poco/1.4/Foundation/include/Poco/DateTimeFormatter.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: DateTime // Package: DateTime
@@ -89,17 +89,17 @@ public:
/// * %H - hour (00 .. 23) /// * %H - hour (00 .. 23)
/// * %h - hour (00 .. 12) /// * %h - hour (00 .. 12)
/// * %a - am/pm /// * %a - am/pm
/// * %A - AM/PM /// * %A - AM/PM
/// * %M - minute (00 .. 59) /// * %M - minute (00 .. 59)
/// * %S - second (00 .. 59) /// * %S - second (00 .. 59)
/// * %s - seconds and microseconds (equivalent to %S.%F) /// * %s - seconds and microseconds (equivalent to %S.%F)
/// * %i - millisecond (000 .. 999) /// * %i - millisecond (000 .. 999)
/// * %c - centisecond (0 .. 9) /// * %c - centisecond (0 .. 9)
/// * %F - fractional seconds/microseconds (000000 - 999999) /// * %F - fractional seconds/microseconds (000000 - 999999)
/// * %z - time zone differential in ISO 8601 format (Z or +NN.NN) /// * %z - time zone differential in ISO 8601 format (Z or +NN.NN)
/// * %Z - time zone differential in RFC format (GMT or +NNNN) /// * %Z - time zone differential in RFC format (GMT or +NNNN)
/// * %% - percent sign /// * %% - percent sign
/// ///
/// Class DateTimeFormat defines format strings for various standard date/time formats. /// Class DateTimeFormat defines format strings for various standard date/time formats.
static std::string format(const DateTime& dateTime, const std::string& fmt, int timeZoneDifferential = UTC); static std::string format(const DateTime& dateTime, const std::string& fmt, int timeZoneDifferential = UTC);

View File

@@ -1,7 +1,7 @@
// //
// DateTimeParser.h // DateTimeParser.h
// //
// $Id: //poco/Main/Foundation/include/Poco/DateTimeParser.h#4 $ // $Id: //poco/1.4/Foundation/include/Poco/DateTimeParser.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: DateTime // Package: DateTime

View File

@@ -1,7 +1,7 @@
// //
// Debugger.h // Debugger.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Debugger.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Debugger.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// DefaultStrategy.h // DefaultStrategy.h
// //
// $Id: //poco/Main/Foundation/include/Poco/DefaultStrategy.h#5 $ // $Id: //poco/1.4/Foundation/include/Poco/DefaultStrategy.h#3 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the DefaultStrategy template. // Implementation of the DefaultStrategy template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -36,124 +36,100 @@
// //
#ifndef Foundation_DefaultStrategy_INCLUDED #ifndef Foundation_DefaultStrategy_INCLUDED
#define Foundation_DefaultStrategy_INCLUDED #define Foundation_DefaultStrategy_INCLUDED
#include "Poco/NotificationStrategy.h" #include "Poco/NotificationStrategy.h"
#include <memory> #include "Poco/SharedPtr.h"
#include <set>
#include <vector> #include <vector>
namespace Poco { namespace Poco {
template <class TArgs, class TDelegate, class TCompare> template <class TArgs, class TDelegate>
class DefaultStrategy//: public NotificationStrategy<TArgs, TDelegate> class DefaultStrategy: public NotificationStrategy<TArgs, TDelegate>
/// Default notification strategy. Allows one observer /// Default notification strategy.
/// to register exactly once. The observer must provide an ///
/// < (less-than) operator. /// Internally, a std::vector<> is used to store
/// delegate objects. Delegates are invoked in the
/// order in which they have been registered.
{ {
public: public:
typedef std::set<TDelegate*, TCompare> Delegates; typedef SharedPtr<TDelegate> DelegatePtr;
typedef typename Delegates::iterator Iterator; typedef std::vector<DelegatePtr> Delegates;
typedef typename Delegates::const_iterator ConstIterator; typedef typename Delegates::iterator Iterator;
public: public:
DefaultStrategy() DefaultStrategy()
{ {
} }
DefaultStrategy(const DefaultStrategy& s) DefaultStrategy(const DefaultStrategy& s):
{ _delegates(s._delegates)
operator = (s); {
} }
~DefaultStrategy() ~DefaultStrategy()
{ {
clear(); }
}
void notify(const void* sender, TArgs& arguments) void notify(const void* sender, TArgs& arguments)
{ {
std::vector<Iterator> delMe; for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
{
(*it)->notify(sender, arguments);
}
}
for (Iterator it = _observers.begin(); it != _observers.end(); ++it) void add(const TDelegate& delegate)
{ {
if (!(*it)->notify(sender, arguments)) _delegates.push_back(DelegatePtr(static_cast<TDelegate*>(delegate.clone())));
{ }
// schedule for deletion
delMe.push_back(it);
}
}
while (!delMe.empty())
{
typename std::vector<Iterator>::iterator vit = delMe.end();
--vit;
delete **vit;
_observers.erase(*vit);
delMe.pop_back();
}
}
void add(const TDelegate& delegate) void remove(const TDelegate& delegate)
{ {
Iterator it = _observers.find(const_cast<TDelegate*>(&delegate)); for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
if (it != _observers.end()) {
{ if (delegate.equals(**it))
delete *it; {
_observers.erase(it); (*it)->disable();
} _delegates.erase(it);
std::auto_ptr<TDelegate> pDelegate(delegate.clone()); return;
bool tmp = _observers.insert(pDelegate.get()).second; }
poco_assert (tmp); }
pDelegate.release(); }
}
void remove(const TDelegate& delegate)
{
Iterator it = _observers.find(const_cast<TDelegate*>(&delegate));
if (it != _observers.end())
{
delete *it;
_observers.erase(it);
}
}
DefaultStrategy& operator = (const DefaultStrategy& s) DefaultStrategy& operator = (const DefaultStrategy& s)
{ {
if (this != &s) if (this != &s)
{ {
for (ConstIterator it = s._observers.begin(); it != s._observers.end(); ++it) _delegates = s._delegates;
{ }
add(**it); return *this;
} }
}
return *this;
}
void clear() void clear()
{ {
for (Iterator it = _observers.begin(); it != _observers.end(); ++it) for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
{ {
delete *it; (*it)->disable();
} }
_observers.clear(); _delegates.clear();
} }
bool empty() const bool empty() const
{ {
return _observers.empty(); return _delegates.empty();
} }
protected: protected:
Delegates _observers; Delegates _delegates;
}; };
} // namespace Poco } // namespace Poco
#endif #endif // Foundation_DefaultStrategy_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// Delegate.h // Delegate.h
// //
// $Id: //poco/1.4/Foundation/include/Poco/Delegate.h#1 $ // $Id: //poco/1.4/Foundation/include/Poco/Delegate.h#5 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the Delegate template. // Implementation of the Delegate template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -44,22 +44,22 @@
#include "Poco/AbstractDelegate.h" #include "Poco/AbstractDelegate.h"
#include "Poco/FunctionDelegate.h" #include "Poco/FunctionDelegate.h"
#include "Poco/Expire.h" #include "Poco/Expire.h"
#include "Poco/Mutex.h"
namespace Poco { namespace Poco {
template <class TObj, class TArgs, bool withSender=true> template <class TObj, class TArgs, bool withSender = true>
class Delegate: public AbstractDelegate<TArgs> class Delegate: public AbstractDelegate<TArgs>
{ {
public: public:
typedef void (TObj::*NotifyMethod)(const void*, TArgs&); typedef void (TObj::*NotifyMethod)(const void*, TArgs&);
Delegate(TObj* obj, NotifyMethod method): Delegate(TObj* obj, NotifyMethod method):
AbstractDelegate<TArgs>(obj), _receiverObject(obj),
_receiverObject(obj), _receiverMethod(method)
_receiverMethod(method) {
{
} }
Delegate(const Delegate& delegate): Delegate(const Delegate& delegate):
@@ -74,33 +74,50 @@ public:
} }
Delegate& operator = (const Delegate& delegate) Delegate& operator = (const Delegate& delegate)
{ {
if (&delegate != this) if (&delegate != this)
{ {
this->_pTarget = delegate._pTarget; this->_receiverObject = delegate._receiverObject;
this->_receiverObject = delegate._receiverObject; this->_receiverMethod = delegate._receiverMethod;
this->_receiverMethod = delegate._receiverMethod; }
}
return *this; return *this;
} }
bool notify(const void* sender, TArgs& arguments) bool notify(const void* sender, TArgs& arguments)
{ {
(_receiverObject->*_receiverMethod)(sender, arguments); Mutex::ScopedLock lock(_mutex);
return true; // a "standard" delegate never expires if (_receiverObject)
} {
(_receiverObject->*_receiverMethod)(sender, arguments);
return true;
}
else return false;
}
AbstractDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{
const Delegate* pOtherDelegate = reinterpret_cast<const Delegate*>(other.unwrap());
return pOtherDelegate && _receiverObject == pOtherDelegate->_receiverObject && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{ {
return new Delegate(*this); return new Delegate(*this);
} }
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverObject = 0;
}
protected: protected:
TObj* _receiverObject; TObj* _receiverObject;
NotifyMethod _receiverMethod; NotifyMethod _receiverMethod;
Mutex _mutex;
private: private:
Delegate(); Delegate();
}; };
@@ -108,13 +125,12 @@ template <class TObj, class TArgs>
class Delegate<TObj, TArgs, false>: public AbstractDelegate<TArgs> class Delegate<TObj, TArgs, false>: public AbstractDelegate<TArgs>
{ {
public: public:
typedef void (TObj::*NotifyMethod)(TArgs&); typedef void (TObj::*NotifyMethod)(TArgs&);
Delegate(TObj* obj, NotifyMethod method): Delegate(TObj* obj, NotifyMethod method):
AbstractDelegate<TArgs>(obj), _receiverObject(obj),
_receiverObject(obj), _receiverMethod(method)
_receiverMethod(method) {
{
} }
Delegate(const Delegate& delegate): Delegate(const Delegate& delegate):
@@ -139,23 +155,41 @@ public:
return *this; return *this;
} }
bool notify(const void*, TArgs& arguments) bool notify(const void*, TArgs& arguments)
{ {
(_receiverObject->*_receiverMethod)(arguments); Mutex::ScopedLock lock(_mutex);
return true; // a "standard" delegate never expires if (_receiverObject)
} {
(_receiverObject->*_receiverMethod)(arguments);
return true;
}
else return false;
}
AbstractDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{
const Delegate* pOtherDelegate = reinterpret_cast<const Delegate*>(other.unwrap());
return pOtherDelegate && _receiverObject == pOtherDelegate->_receiverObject && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{ {
return new Delegate(*this); return new Delegate(*this);
} }
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverObject = 0;
}
protected: protected:
TObj* _receiverObject; TObj* _receiverObject;
NotifyMethod _receiverMethod; NotifyMethod _receiverMethod;
Mutex _mutex;
private: private:
Delegate(); Delegate();
}; };
@@ -173,7 +207,6 @@ static Delegate<TObj, TArgs, false> delegate(TObj* pObj, void (TObj::*NotifyMeth
} }
template <class TObj, class TArgs> template <class TObj, class TArgs>
static Expire<TArgs> delegate(TObj* pObj, void (TObj::*NotifyMethod)(const void*, TArgs&), Timestamp::TimeDiff expireMillisecs) static Expire<TArgs> delegate(TObj* pObj, void (TObj::*NotifyMethod)(const void*, TArgs&), Timestamp::TimeDiff expireMillisecs)
{ {
@@ -205,7 +238,7 @@ static Expire<TArgs> delegate(void (*NotifyMethod)(void*, TArgs&), Timestamp::Ti
template <class TArgs> template <class TArgs>
static Expire<TArgs> delegate(void (*NotifyMethod)(TArgs&), Timestamp::TimeDiff expireMillisecs) static Expire<TArgs> delegate(void (*NotifyMethod)(TArgs&), Timestamp::TimeDiff expireMillisecs)
{ {
return Expire<TArgs>(FunctionDelegate<TArgs, false>( NotifyMethod), expireMillisecs); return Expire<TArgs>(FunctionDelegate<TArgs, false>(NotifyMethod), expireMillisecs);
} }

View File

@@ -1,7 +1,7 @@
// //
// DigestEngine.h // DigestEngine.h
// //
// $Id: //poco/Main/Foundation/include/Poco/DigestEngine.h#3 $ // $Id: //poco/1.4/Foundation/include/Poco/DigestEngine.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Crypt // Package: Crypt
@@ -82,15 +82,15 @@ public:
/// The returned reference is valid until the next /// The returned reference is valid until the next
/// time digest() is called, or the engine object is destroyed. /// time digest() is called, or the engine object is destroyed.
static std::string digestToHex(const Digest& bytes); static std::string digestToHex(const Digest& bytes);
/// Converts a message digest into a string of hexadecimal numbers. /// Converts a message digest into a string of hexadecimal numbers.
static Digest digestFromHex(const std::string& digest); static Digest digestFromHex(const std::string& digest);
/// Converts a string created by digestToHex back to its Digest presentation /// Converts a string created by digestToHex back to its Digest presentation
protected: protected:
virtual void updateImpl(const void* data, unsigned length) = 0; virtual void updateImpl(const void* data, unsigned length) = 0;
/// Updates the digest with the given data. Must be implemented /// Updates the digest with the given data. Must be implemented
/// by subclasses. /// by subclasses.
private: private:

View File

@@ -1,7 +1,7 @@
// //
// DigestStream.h // DigestStream.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DigestStream.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DigestStream.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Crypt // Package: Crypt

View File

@@ -1,7 +1,7 @@
// //
// DirectoryIterator.h // DirectoryIterator.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DirectoryIterator.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DirectoryIterator.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// DirectoryIterator_UNIX.h // DirectoryIterator_UNIX.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DirectoryIterator_UNIX.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DirectoryIterator_UNIX.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// DirectoryIterator_VMS.h // DirectoryIterator_VMS.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DirectoryIterator_VMS.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DirectoryIterator_VMS.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// DirectoryIterator_WIN32.h // DirectoryIterator_WIN32.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DirectoryIterator_WIN32.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DirectoryIterator_WIN32.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// DirectoryIterator_WIN32U.h // DirectoryIterator_WIN32U.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DirectoryIterator_WIN32U.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DirectoryIterator_WIN32U.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// DynamicFactory.h // DynamicFactory.h
// //
// $Id: //poco/svn/Foundation/include/Poco/DynamicFactory.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/DynamicFactory.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// Environment.h // Environment.h
// //
// $Id: //poco/1.3/Foundation/include/Poco/Environment.h#3 $ // $Id: //poco/1.4/Foundation/include/Poco/Environment.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -71,22 +71,22 @@ public:
/// Sets the environment variable with the given name /// Sets the environment variable with the given name
/// to the given value. /// to the given value.
static std::string osName(); static std::string osName();
/// Returns the operating system name. /// Returns the operating system name.
static std::string osDisplayName(); static std::string osDisplayName();
/// Returns the operating system name in a /// Returns the operating system name in a
/// "user-friendly" way. /// "user-friendly" way.
/// ///
/// Currently this is only implemented for /// Currently this is only implemented for
/// Windows. There it will return names like /// Windows. There it will return names like
/// "Windows XP" or "Windows 7/Server 2008 SP2". /// "Windows XP" or "Windows 7/Server 2008 SP2".
/// On other platform, returns the same as /// On other platform, returns the same as
/// osName(). /// osName().
static std::string osVersion(); static std::string osVersion();
/// Returns the operating system version. /// Returns the operating system version.
static std::string osArchitecture(); static std::string osArchitecture();
/// Returns the operating system architecture. /// Returns the operating system architecture.

View File

@@ -1,7 +1,7 @@
// //
// Environment_UNIX.h // Environment_UNIX.h
// //
// $Id: //poco/1.3/Foundation/include/Poco/Environment_UNIX.h#3 $ // $Id: //poco/1.4/Foundation/include/Poco/Environment_UNIX.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -54,13 +54,13 @@ public:
typedef UInt8 NodeId[6]; /// Ethernet address. typedef UInt8 NodeId[6]; /// Ethernet address.
static std::string getImpl(const std::string& name); static std::string getImpl(const std::string& name);
static bool hasImpl(const std::string& name); static bool hasImpl(const std::string& name);
static void setImpl(const std::string& name, const std::string& value); static void setImpl(const std::string& name, const std::string& value);
static std::string osNameImpl(); static std::string osNameImpl();
static std::string osDisplayNameImpl(); static std::string osDisplayNameImpl();
static std::string osVersionImpl(); static std::string osVersionImpl();
static std::string osArchitectureImpl(); static std::string osArchitectureImpl();
static std::string nodeNameImpl(); static std::string nodeNameImpl();
static void nodeIdImpl(NodeId& id); static void nodeIdImpl(NodeId& id);
static unsigned processorCountImpl(); static unsigned processorCountImpl();

View File

@@ -1,7 +1,7 @@
// //
// Environment_VMS.h // Environment_VMS.h
// //
// $Id: //poco/1.3/Foundation/include/Poco/Environment_VMS.h#3 $ // $Id: //poco/1.4/Foundation/include/Poco/Environment_VMS.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -53,13 +53,13 @@ public:
typedef UInt8 NodeId[6]; /// Ethernet address. typedef UInt8 NodeId[6]; /// Ethernet address.
static std::string getImpl(const std::string& name); static std::string getImpl(const std::string& name);
static bool hasImpl(const std::string& name); static bool hasImpl(const std::string& name);
static void setImpl(const std::string& name, const std::string& value); static void setImpl(const std::string& name, const std::string& value);
static std::string osNameImpl(); static std::string osNameImpl();
static std::string osDisplayNameImpl(); static std::string osDisplayNameImpl();
static std::string osVersionImpl(); static std::string osVersionImpl();
static std::string osArchitectureImpl(); static std::string osArchitectureImpl();
static std::string nodeNameImpl(); static std::string nodeNameImpl();
static void nodeIdImpl(NodeId& id); static void nodeIdImpl(NodeId& id);
static unsigned processorCountImpl(); static unsigned processorCountImpl();

View File

@@ -1,7 +1,7 @@
// //
// Environment_VX.h // Environment_VX.h
// //
// $Id: //poco/1.4/Foundation/include/Poco/Environment_VX.h#1 $ // $Id: //poco/1.4/Foundation/include/Poco/Environment_VX.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -54,13 +54,13 @@ public:
typedef UInt8 NodeId[6]; /// Ethernet address. typedef UInt8 NodeId[6]; /// Ethernet address.
static std::string getImpl(const std::string& name); static std::string getImpl(const std::string& name);
static bool hasImpl(const std::string& name); static bool hasImpl(const std::string& name);
static void setImpl(const std::string& name, const std::string& value); static void setImpl(const std::string& name, const std::string& value);
static std::string osNameImpl(); static std::string osNameImpl();
static std::string osDisplayNameImpl(); static std::string osDisplayNameImpl();
static std::string osVersionImpl(); static std::string osVersionImpl();
static std::string osArchitectureImpl(); static std::string osArchitectureImpl();
static std::string nodeNameImpl(); static std::string nodeNameImpl();
static void nodeIdImpl(NodeId& id); static void nodeIdImpl(NodeId& id);
static unsigned processorCountImpl(); static unsigned processorCountImpl();

View File

@@ -1,7 +1,7 @@
// //
// Environment_WIN32.h // Environment_WIN32.h
// //
// $Id: //poco/1.3/Foundation/include/Poco/Environment_WIN32.h#3 $ // $Id: //poco/1.4/Foundation/include/Poco/Environment_WIN32.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -52,13 +52,13 @@ public:
typedef UInt8 NodeId[6]; /// Ethernet address. typedef UInt8 NodeId[6]; /// Ethernet address.
static std::string getImpl(const std::string& name); static std::string getImpl(const std::string& name);
static bool hasImpl(const std::string& name); static bool hasImpl(const std::string& name);
static void setImpl(const std::string& name, const std::string& value); static void setImpl(const std::string& name, const std::string& value);
static std::string osNameImpl(); static std::string osNameImpl();
static std::string osDisplayNameImpl(); static std::string osDisplayNameImpl();
static std::string osVersionImpl(); static std::string osVersionImpl();
static std::string osArchitectureImpl(); static std::string osArchitectureImpl();
static std::string nodeNameImpl(); static std::string nodeNameImpl();
static void nodeIdImpl(NodeId& id); static void nodeIdImpl(NodeId& id);
static unsigned processorCountImpl(); static unsigned processorCountImpl();
}; };

View File

@@ -1,7 +1,7 @@
// //
// Environment_WIN32U.h // Environment_WIN32U.h
// //
// $Id: //poco/1.3/Foundation/include/Poco/Environment_WIN32U.h#3 $ // $Id: //poco/1.4/Foundation/include/Poco/Environment_WIN32U.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -52,13 +52,13 @@ public:
typedef UInt8 NodeId[6]; /// Ethernet address. typedef UInt8 NodeId[6]; /// Ethernet address.
static std::string getImpl(const std::string& name); static std::string getImpl(const std::string& name);
static bool hasImpl(const std::string& name); static bool hasImpl(const std::string& name);
static void setImpl(const std::string& name, const std::string& value); static void setImpl(const std::string& name, const std::string& value);
static std::string osNameImpl(); static std::string osNameImpl();
static std::string osDisplayNameImpl(); static std::string osDisplayNameImpl();
static std::string osVersionImpl(); static std::string osVersionImpl();
static std::string osArchitectureImpl(); static std::string osArchitectureImpl();
static std::string nodeNameImpl(); static std::string nodeNameImpl();
static void nodeIdImpl(NodeId& id); static void nodeIdImpl(NodeId& id);
static unsigned processorCountImpl(); static unsigned processorCountImpl();
}; };

View File

@@ -1,7 +1,7 @@
// //
// Environment_WINCE.h // Environment_WINCE.h
// //
// $Id: //poco/1.4/Foundation/include/Poco/Environment_WINCE.h#1 $ // $Id: //poco/1.4/Foundation/include/Poco/Environment_WINCE.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -52,13 +52,13 @@ public:
typedef UInt8 NodeId[6]; /// Ethernet address. typedef UInt8 NodeId[6]; /// Ethernet address.
static std::string getImpl(const std::string& name); static std::string getImpl(const std::string& name);
static bool hasImpl(const std::string& name); static bool hasImpl(const std::string& name);
static void setImpl(const std::string& name, const std::string& value); static void setImpl(const std::string& name, const std::string& value);
static std::string osNameImpl(); static std::string osNameImpl();
static std::string osDisplayNameImpl(); static std::string osDisplayNameImpl();
static std::string osVersionImpl(); static std::string osVersionImpl();
static std::string osArchitectureImpl(); static std::string osArchitectureImpl();
static std::string nodeNameImpl(); static std::string nodeNameImpl();
static void nodeIdImpl(NodeId& id); static void nodeIdImpl(NodeId& id);
static unsigned processorCountImpl(); static unsigned processorCountImpl();

View File

@@ -1,7 +1,7 @@
// //
// ErrorHandler.h // ErrorHandler.h
// //
// $Id: //poco/svn/Foundation/include/Poco/ErrorHandler.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/ErrorHandler.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading
@@ -56,13 +56,13 @@ class Foundation_API ErrorHandler
/// about it. /// about it.
/// ///
/// The Thread class provides the possibility to register a /// The Thread class provides the possibility to register a
/// global ErrorHandler that is invoked whenever a thread has /// global ErrorHandler that is invoked whenever a thread has
/// been terminated by an unhandled exception. /// been terminated by an unhandled exception.
/// The ErrorHandler must be derived from this class and can /// The ErrorHandler must be derived from this class and can
/// provide implementations of all three handleException() overloads. /// provide implementations of all three exception() overloads.
/// ///
/// The ErrorHandler is always invoked within the context of /// The ErrorHandler is always invoked within the context of
/// the offending thread. /// the offending thread.
{ {
public: public:
ErrorHandler(); ErrorHandler();

View File

@@ -1,7 +1,7 @@
// //
// Event.h // Event.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Event.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Event.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading

View File

@@ -1,7 +1,7 @@
// //
// EventLogChannel.h // EventLogChannel.h
// //
// $Id: //poco/svn/Foundation/include/Poco/EventLogChannel.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/EventLogChannel.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging

View File

@@ -1,7 +1,7 @@
// //
// Event_POSIX.h // Event_POSIX.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Event_POSIX.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Event_POSIX.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading

View File

@@ -1,7 +1,7 @@
// //
// Event_WIN32.h // Event_WIN32.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Event_WIN32.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Event_WIN32.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Threading // Package: Threading
@@ -51,10 +51,10 @@ namespace Poco {
class Foundation_API EventImpl class Foundation_API EventImpl
{ {
protected: protected:
EventImpl(bool autoReset = false); EventImpl(bool autoReset);
~EventImpl(); ~EventImpl();
void setImpl(); void setImpl();
void waitImpl(); void waitImpl();
bool waitImpl(long milliseconds); bool waitImpl(long milliseconds);
void resetImpl(); void resetImpl();

View File

@@ -1,7 +1,7 @@
// //
// Expire.h // Expire.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Expire.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Expire.h#3 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the Expire template. // Implementation of the Expire template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -36,8 +36,8 @@
// //
#ifndef Foundation_Expire_INCLUDED #ifndef Foundation_Expire_INCLUDED
#define Foundation_Expire_INCLUDED #define Foundation_Expire_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
@@ -50,15 +50,14 @@ namespace Poco {
template <class TArgs> template <class TArgs>
class Expire: public AbstractDelegate<TArgs> class Expire: public AbstractDelegate<TArgs>
/// Decorator for AbstractDelegate adding automatic /// Decorator for AbstractDelegate adding automatic
/// expiring of registrations to AbstractDelegates. /// expiration of registrations to AbstractDelegate's.
{ {
public: public:
Expire(const AbstractDelegate<TArgs>& p, Timestamp::TimeDiff expireMillisecs): Expire(const AbstractDelegate<TArgs>& p, Timestamp::TimeDiff expireMillisecs):
AbstractDelegate<TArgs>(p), _pDelegate(p.clone()),
_pDelegate(p.clone()), _expire(expireMillisecs*1000)
_expire(expireMillisecs*1000) {
{
} }
Expire(const Expire& expire): Expire(const Expire& expire):
@@ -69,12 +68,12 @@ public:
{ {
} }
~Expire() ~Expire()
{ {
destroy(); delete _pDelegate;
} }
Expire& operator = (const Expire& expire) Expire& operator = (const Expire& expire)
{ {
if (&expire != this) if (&expire != this)
{ {
@@ -92,24 +91,28 @@ public:
if (!expired()) if (!expired())
return this->_pDelegate->notify(sender, arguments); return this->_pDelegate->notify(sender, arguments);
else else
return false; return false;
} }
AbstractDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{ {
return new Expire(*this); return other.equals(*_pDelegate);
} }
void destroy() AbstractDelegate<TArgs>* clone() const
{ {
delete this->_pDelegate; return new Expire(*this);
this->_pDelegate = 0; }
}
void disable()
{
_pDelegate->disable();
}
const AbstractDelegate<TArgs>& getDelegate() const const AbstractDelegate<TArgs>* unwrap() const
{ {
return *this->_pDelegate; return this->_pDelegate;
} }
protected: protected:
bool expired() const bool expired() const
@@ -129,4 +132,4 @@ private:
} // namespace Poco } // namespace Poco
#endif #endif // Foundation_Expire_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// FIFOEvent.h // FIFOEvent.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FIFOEvent.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FIFOEvent.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the FIFOEvent template. // Implementation of the FIFOEvent template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -36,42 +36,36 @@
// //
#ifndef Foundation_FIFOEvent_INCLUDED #ifndef Foundation_FIFOEvent_INCLUDED
#define Foundation_FIFOEvent_INCLUDED #define Foundation_FIFOEvent_INCLUDED
#include "Poco/AbstractEvent.h" #include "Poco/AbstractEvent.h"
#include "Poco/FIFOStrategy.h" #include "Poco/FIFOStrategy.h"
#include "Poco/AbstractDelegate.h" #include "Poco/AbstractDelegate.h"
#include "Poco/CompareFunctions.h"
namespace Poco { namespace Poco {
//@ deprecated
template <class TArgs, class TMutex = FastMutex> template <class TArgs, class TMutex = FastMutex>
class FIFOEvent: public AbstractEvent < class FIFOEvent: public AbstractEvent <
TArgs, TArgs,
FIFOStrategy<TArgs, AbstractDelegate<TArgs>, p_less<AbstractDelegate< TArgs> > >, FIFOStrategy<TArgs, AbstractDelegate<TArgs> >,
AbstractDelegate<TArgs>, AbstractDelegate<TArgs>,
TMutex TMutex
> >
/// A FIFOEvent uses internally a FIFOStrategy which guarantees /// A FIFOEvent uses internally a FIFOStrategy which guarantees
/// that delegates are invoked in the order they were added to /// that delegates are invoked in the order they were added to
/// the event. /// the event.
/// ///
/// Note that one object can only register one method to a FIFOEvent. /// Note that as of release 1.4.2, this is the default behavior
/// Subsequent registrations will overwrite the existing delegate. /// implemented by BasicEvent, so this class is provided
/// For example: /// for backwards compatibility only.
/// FIFOEvent<int> tmp;
/// MyClass myObject;
/// tmp += delegate(&myObject, &MyClass::myMethod1);
/// tmp += delegate(&myObject, &MyClass::myMethod2);
///
/// The second registration will overwrite the first one.
{ {
public: public:
FIFOEvent() FIFOEvent()
{ {
} }
@@ -88,4 +82,4 @@ private:
} // namespace Poco } // namespace Poco
#endif #endif // Foundation_FIFOEvent_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// FIFOStrategy.h // FIFOStrategy.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FIFOStrategy.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FIFOStrategy.h#3 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the FIFOStrategy template. // Implementation of the FIFOStrategy template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -35,132 +35,47 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Foundation_FIFOStrategy_INCLUDED
#define Foundation_FIFOStrategy_INCLUDED #ifndef Foundation_FIFOStrategy_INCLUDED
#define Foundation_FIFOStrategy_INCLUDED
#include "Poco/NotificationStrategy.h" #include "Poco/DefaultStrategy.h"
#include <map>
#include <list>
#include <memory>
namespace Poco { namespace Poco {
template <class TArgs, class TDelegate, class TCompare> //@ deprecated
class FIFOStrategy//: public NotificationStrategy<TArgs, TDelegate> template <class TArgs, class TDelegate>
class FIFOStrategy: public DefaultStrategy<TArgs, TDelegate>
/// Note: As of release 1.4.2, DefaultStrategy already
/// implements FIFO behavior, so this class is provided
/// for backwards compatibility only.
{ {
public: public:
typedef std::list<TDelegate*> Delegates; FIFOStrategy()
typedef typename Delegates::iterator Iterator; {
typedef typename Delegates::const_iterator ConstIterator; }
typedef std::map<TDelegate*, Iterator, TCompare> DelegateIndex;
typedef typename DelegateIndex::iterator IndexIterator;
typedef typename DelegateIndex::const_iterator ConstIndexIterator;
FIFOStrategy() FIFOStrategy(const FIFOStrategy& s):
{ DefaultStrategy<TArgs, TDelegate>(s)
} {
}
FIFOStrategy(const FIFOStrategy& s) ~FIFOStrategy()
{ {
operator = (s); }
}
~FIFOStrategy() FIFOStrategy& operator = (const FIFOStrategy& s)
{ {
clear(); DefaultStrategy<TArgs, TDelegate>::operator = (s);
} return *this;
}
void notify(const void* sender, TArgs& arguments)
{
std::vector<Iterator> delMe;
Iterator it = _observers.begin();
Iterator itEnd = _observers.end();
for (; it != itEnd; ++it)
{
if (!(*it)->notify(sender, arguments))
{
// schedule for deletion
delMe.push_back(it);
}
}
while (!delMe.empty())
{
typename std::vector<Iterator>::iterator vit = delMe.end();
--vit;
delete **vit;
_observers.erase(*vit);
delMe.pop_back();
}
}
void add(const TDelegate& delegate)
{
IndexIterator it = _observerIndex.find(const_cast<TDelegate*>(&delegate));
if (it != _observerIndex.end())
{
delete *it->second;
_observers.erase(it->second);
_observerIndex.erase(it);
}
std::auto_ptr<TDelegate> pDelegate(delegate.clone());
_observers.push_back(pDelegate.get());
bool tmp = _observerIndex.insert(make_pair(pDelegate.get(), --_observers.end())).second;
poco_assert (tmp);
pDelegate.release();
}
void remove(const TDelegate& delegate)
{
IndexIterator it = _observerIndex.find(const_cast<TDelegate*>(&delegate));
if (it != _observerIndex.end())
{
delete *it->second;
_observers.erase(it->second);
_observerIndex.erase(it);
}
}
FIFOStrategy& operator = (const FIFOStrategy& s)
{
if (this != &s)
{
for (ConstIterator it = s._observers.begin(); it != s._observers.end(); ++it)
{
add(**it);
}
}
return *this;
}
void clear()
{
for (Iterator it = _observers.begin(); it != _observers.end(); ++it)
{
delete *it;
}
_observers.clear();
_observerIndex.clear();
}
bool empty() const
{
return _observers.empty();
}
protected:
Delegates _observers; /// Stores the delegates in the order they were added.
DelegateIndex _observerIndex; /// For faster lookup when add/remove is used.
}; };
} // namespace Poco } // namespace Poco
#endif #endif // Foundation_FIFOStrategy_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// FPEnvironment.h // FPEnvironment.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FPEnvironment.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FPEnvironment.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// FPEnvironment_C99.h // FPEnvironment_C99.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FPEnvironment_C99.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FPEnvironment_C99.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// FPEnvironment_DEC.h // FPEnvironment_DEC.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FPEnvironment_DEC.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FPEnvironment_DEC.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// FPEnvironment_DUMMY.h // FPEnvironment_DUMMY.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FPEnvironment_DUMMY.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FPEnvironment_DUMMY.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// FPEnvironment_SUN.h // FPEnvironment_SUN.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FPEnvironment_SUN.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FPEnvironment_SUN.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// FPEnvironment_WIN32.h // FPEnvironment_WIN32.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FPEnvironment_WIN32.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FPEnvironment_WIN32.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// File.h // File.h
// //
// $Id: //poco/Main/Foundation/include/Poco/File.h#9 $ // $Id: //poco/1.4/Foundation/include/Poco/File.h#3 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem
@@ -157,33 +157,33 @@ public:
/// On such platforms, created() returns /// On such platforms, created() returns
/// the time of the last inode modification. /// the time of the last inode modification.
Timestamp getLastModified() const; Timestamp getLastModified() const;
/// Returns the modification date of the file. /// Returns the modification date of the file.
File& setLastModified(const Timestamp& ts); File& setLastModified(const Timestamp& ts);
/// Sets the modification date of the file. /// Sets the modification date of the file.
FileSize getSize() const; FileSize getSize() const;
/// Returns the size of the file in bytes. /// Returns the size of the file in bytes.
File& setSize(FileSize size); File& setSize(FileSize size);
/// Sets the size of the file in bytes. Can be used /// Sets the size of the file in bytes. Can be used
/// to truncate a file. /// to truncate a file.
File& setWriteable(bool flag = true); File& setWriteable(bool flag = true);
/// Makes the file writeable (if flag is true), or /// Makes the file writeable (if flag is true), or
/// non-writeable (if flag is false) by setting the /// non-writeable (if flag is false) by setting the
/// file's flags in the filesystem accordingly. /// file's flags in the filesystem accordingly.
File& setReadOnly(bool flag = true); File& setReadOnly(bool flag = true);
/// Makes the file non-writeable (if flag is true), or /// Makes the file non-writeable (if flag is true), or
/// writeable (if flag is false) by setting the /// writeable (if flag is false) by setting the
/// file's flags in the filesystem accordingly. /// file's flags in the filesystem accordingly.
File& setExecutable(bool flag = true); File& setExecutable(bool flag = true);
/// Makes the file executable (if flag is true), or /// Makes the file executable (if flag is true), or
/// non-executable (if flag is false) by setting /// non-executable (if flag is false) by setting
/// the file's permission bits accordingly. /// the file's permission bits accordingly.
/// ///
/// Does nothing on Windows and OpenVMS. /// Does nothing on Windows and OpenVMS.

View File

@@ -1,7 +1,7 @@
// //
// FileChannel.h // FileChannel.h
// //
// $Id: //poco/1.3/Foundation/include/Poco/FileChannel.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FileChannel.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging
@@ -137,13 +137,13 @@ class Foundation_API FileChannel: public Channel
/// for the "times" property are supported: /// for the "times" property are supported:
/// ///
/// * utc: Rotation strategy is based on UTC time (default). /// * utc: Rotation strategy is based on UTC time (default).
/// * local: Rotation strategy is based on local time. /// * local: Rotation strategy is based on local time.
/// ///
/// Archived log files can be compressed using the gzip compression /// Archived log files can be compressed using the gzip compression
/// method. Compressing can be controlled with the "compression" /// method. Compressing can be controlled with the "compression"
/// property. The following values for the "compress" property /// property. The following values for the "compress" property
/// are supported: /// are supported:
/// ///
/// * true: Compress archived log files. /// * true: Compress archived log files.
/// * false: Do not compress archived log files. /// * false: Do not compress archived log files.
/// ///
@@ -151,23 +151,23 @@ class Foundation_API FileChannel: public Channel
/// they reach a certain age, or if the number of archived /// they reach a certain age, or if the number of archived
/// log files reaches a given maximum number. This is /// log files reaches a given maximum number. This is
/// controlled by the purgeAge and purgeCount properties. /// controlled by the purgeAge and purgeCount properties.
/// ///
/// The purgeAge property can have the following values: /// The purgeAge property can have the following values:
/// ///
/// * "none" or "" no purging /// * "none" or "" no purging
/// * <n> [seconds] the maximum age is <n> seconds. /// * <n> [seconds] the maximum age is <n> seconds.
/// * <n> minutes: the maximum age is <n> minutes. /// * <n> minutes: the maximum age is <n> minutes.
/// * <n> hours: the maximum age is <n> hours. /// * <n> hours: the maximum age is <n> hours.
/// * <n> days: the maximum age is <n> days. /// * <n> days: the maximum age is <n> days.
/// * <n> weeks: the maximum age is <n> weeks. /// * <n> weeks: the maximum age is <n> weeks.
/// * <n> months: the maximum age is <n> months, where a month has 30 days. /// * <n> months: the maximum age is <n> months, where a month has 30 days.
/// ///
/// The purgeCount property has an integer value that specifies the maximum number /// The purgeCount property has an integer value that specifies the maximum number
/// of archived log files. If the number is exceeded, archived log files are /// of archived log files. If the number is exceeded, archived log files are
/// deleted, starting with the oldest. When "none" or empty string are /// deleted, starting with the oldest. When "none" or empty string are
/// supplied, they reset purgeCount to none (no purging). /// supplied, they reset purgeCount to none (no purging).
/// ///
/// For a more lightweight file channel class, see SimpleFileChannel. /// For a more lightweight file channel class, see SimpleFileChannel.
{ {
public: public:
FileChannel(); FileChannel();

View File

@@ -1,7 +1,7 @@
// //
// FileStream.h // FileStream.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FileStream.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FileStream.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams

View File

@@ -1,7 +1,7 @@
// //
// FileStreamFactory.h // FileStreamFactory.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FileStreamFactory.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FileStreamFactory.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: URI // Package: URI

View File

@@ -1,7 +1,7 @@
// //
// FileStream_POSIX.h // FileStream_POSIX.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FileStream_POSIX.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FileStream_POSIX.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams

View File

@@ -1,7 +1,7 @@
// //
// FileStream_WIN32.h // FileStream_WIN32.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FileStream_WIN32.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FileStream_WIN32.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams
@@ -58,15 +58,15 @@ public:
~FileStreamBuf(); ~FileStreamBuf();
/// Destroys the FileStream. /// Destroys the FileStream.
void open(const std::string& path, std::ios::openmode mode); void open(const std::string& path, std::ios::openmode mode);
/// Opens the given file in the given mode. /// Opens the given file in the given mode.
bool close(); bool close();
/// Closes the File stream buffer. Returns true if successful, /// Closes the File stream buffer. Returns true if successful,
/// false otherwise. /// false otherwise.
std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out); std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
/// change position by offset, according to way and mode /// change position by offset, according to way and mode
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out); std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
/// change to specified position, according to mode /// change to specified position, according to mode

View File

@@ -1,7 +1,7 @@
// //
// File_UNIX.h // File_UNIX.h
// //
// $Id: //poco/Main/Foundation/include/Poco/File_UNIX.h#6 $ // $Id: //poco/1.4/Foundation/include/Poco/File_UNIX.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// File_VMS.h // File_VMS.h
// //
// $Id: //poco/Main/Foundation/include/Poco/File_VMS.h#6 $ // $Id: //poco/1.4/Foundation/include/Poco/File_VMS.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// File_WIN32.h // File_WIN32.h
// //
// $Id: //poco/Main/Foundation/include/Poco/File_WIN32.h#6 $ // $Id: //poco/1.4/Foundation/include/Poco/File_WIN32.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// File_WIN32U.h // File_WIN32U.h
// //
// $Id: //poco/Main/Foundation/include/Poco/File_WIN32U.h#6 $ // $Id: //poco/1.4/Foundation/include/Poco/File_WIN32U.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// Format.h // Format.h
// //
// $Id: //poco/1.4/Foundation/include/Poco/Format.h#1 $ // $Id: //poco/1.4/Foundation/include/Poco/Format.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core
@@ -106,18 +106,18 @@ std::string Foundation_API format(const std::string& fmt, const Any& value);
/// If the number of characters in the output value is less than the specified width, blanks or /// If the number of characters in the output value is less than the specified width, blanks or
/// leading zeros are added, according to the specified flags (-, +, 0). /// leading zeros are added, according to the specified flags (-, +, 0).
/// ///
/// Precision is a nonnegative decimal integer, preceded by a period (.), which specifies the number of characters /// Precision is a nonnegative decimal integer, preceded by a period (.), which specifies the number of characters
/// to be printed, the number of decimal places, or the number of significant digits. /// to be printed, the number of decimal places, or the number of significant digits.
/// ///
/// Throws an InvalidArgumentException if an argument index is out of range. /// Throws an InvalidArgumentException if an argument index is out of range.
/// ///
/// Starting with release 1.4.3, an argument that does not match the format /// Starting with release 1.4.3, an argument that does not match the format
/// specifier no longer results in a BadCastException. The string [ERRFMT] is /// specifier no longer results in a BadCastException. The string [ERRFMT] is
/// written to the result string instead. /// written to the result string instead.
/// ///
/// If there are more format specifiers than values, the format specifiers without a corresponding value /// If there are more format specifiers than values, the format specifiers without a corresponding value
/// are copied verbatim to output. /// are copied verbatim to output.
/// ///
/// If there are more values than format specifiers, the superfluous values are ignored. /// If there are more values than format specifiers, the superfluous values are ignored.
/// ///
/// Usage Examples: /// Usage Examples:

View File

@@ -1,7 +1,7 @@
// //
// Formatter.h // Formatter.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Formatter.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Formatter.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging

View File

@@ -1,7 +1,7 @@
// //
// FormattingChannel.h // FormattingChannel.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FormattingChannel.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FormattingChannel.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Logging // Package: Logging

View File

@@ -1,7 +1,7 @@
// //
// FunctionDelegate.h // FunctionDelegate.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FunctionDelegate.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FunctionDelegate.h#4 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the FunctionDelegate template. // Implementation of the FunctionDelegate template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -36,12 +36,13 @@
// //
#ifndef Foundation_FunctionDelegate_INCLUDED #ifndef Foundation_FunctionDelegate_INCLUDED
#define Foundation_FunctionDelegate_INCLUDED #define Foundation_FunctionDelegate_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include "Poco/AbstractDelegate.h" #include "Poco/AbstractDelegate.h"
#include "Poco/Mutex.h"
namespace Poco { namespace Poco {
@@ -49,17 +50,16 @@ namespace Poco {
template <class TArgs, bool hasSender = true, bool senderIsConst = true> template <class TArgs, bool hasSender = true, bool senderIsConst = true>
class FunctionDelegate: public AbstractDelegate<TArgs> class FunctionDelegate: public AbstractDelegate<TArgs>
/// Wraps a C style function (or a C++ static function) to be used as /// Wraps a freestanding function or static member function
/// a delegate /// for use as a Delegate.
{ {
public: public:
typedef void (*NotifyMethod)(const void*, TArgs&); typedef void (*NotifyMethod)(const void*, TArgs&);
FunctionDelegate(NotifyMethod method): FunctionDelegate(NotifyMethod method):
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)), _receiverMethod(method)
_receiverMethod(method) {
{ }
}
FunctionDelegate(const FunctionDelegate& delegate): FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(delegate), AbstractDelegate<TArgs>(delegate),
@@ -81,22 +81,40 @@ public:
return *this; return *this;
} }
bool notify(const void* sender, TArgs& arguments) bool notify(const void* sender, TArgs& arguments)
{ {
(*_receiverMethod)(sender, arguments); Mutex::ScopedLock lock(_mutex);
return true; // a "standard" delegate never expires if (_receiverMethod)
} {
(*_receiverMethod)(sender, arguments);
return true;
}
else return false;
}
AbstractDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionDelegate* pOtherDelegate = dynamic_cast<const FunctionDelegate*>(other.unwrap());
return pOtherDelegate && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{ {
return new FunctionDelegate(*this); return new FunctionDelegate(*this);
} }
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected: protected:
NotifyMethod _receiverMethod; NotifyMethod _receiverMethod;
Mutex _mutex;
private: private:
FunctionDelegate(); FunctionDelegate();
}; };
@@ -104,13 +122,12 @@ template <class TArgs>
class FunctionDelegate<TArgs, true, false>: public AbstractDelegate<TArgs> class FunctionDelegate<TArgs, true, false>: public AbstractDelegate<TArgs>
{ {
public: public:
typedef void (*NotifyMethod)(void*, TArgs&); typedef void (*NotifyMethod)(void*, TArgs&);
FunctionDelegate(NotifyMethod method): FunctionDelegate(NotifyMethod method):
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)), _receiverMethod(method)
_receiverMethod(method) {
{ }
}
FunctionDelegate(const FunctionDelegate& delegate): FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(delegate), AbstractDelegate<TArgs>(delegate),
@@ -132,22 +149,40 @@ public:
return *this; return *this;
} }
bool notify(const void* sender, TArgs& arguments) bool notify(const void* sender, TArgs& arguments)
{ {
(*_receiverMethod)(const_cast<void*>(sender), arguments); Mutex::ScopedLock lock(_mutex);
return true; // a "standard" delegate never expires if (_receiverMethod)
} {
(*_receiverMethod)(const_cast<void*>(sender), arguments);
return true;
}
else return false;
}
AbstractDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionDelegate* pOtherDelegate = dynamic_cast<const FunctionDelegate*>(other.unwrap());
return pOtherDelegate && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{ {
return new FunctionDelegate(*this); return new FunctionDelegate(*this);
} }
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected: protected:
NotifyMethod _receiverMethod; NotifyMethod _receiverMethod;
Mutex _mutex;
private: private:
FunctionDelegate(); FunctionDelegate();
}; };
@@ -155,13 +190,12 @@ template <class TArgs, bool senderIsConst>
class FunctionDelegate<TArgs, false, senderIsConst>: public AbstractDelegate<TArgs> class FunctionDelegate<TArgs, false, senderIsConst>: public AbstractDelegate<TArgs>
{ {
public: public:
typedef void (*NotifyMethod)(TArgs&); typedef void (*NotifyMethod)(TArgs&);
FunctionDelegate(NotifyMethod method): FunctionDelegate(NotifyMethod method):
AbstractDelegate<TArgs>(*reinterpret_cast<void**>(&method)), _receiverMethod(method)
_receiverMethod(method) {
{ }
}
FunctionDelegate(const FunctionDelegate& delegate): FunctionDelegate(const FunctionDelegate& delegate):
AbstractDelegate<TArgs>(delegate), AbstractDelegate<TArgs>(delegate),
@@ -183,26 +217,44 @@ public:
return *this; return *this;
} }
bool notify(const void* sender, TArgs& arguments) bool notify(const void* sender, TArgs& arguments)
{ {
(*_receiverMethod)(arguments); Mutex::ScopedLock lock(_mutex);
return true; // a "standard" delegate never expires if (_receiverMethod)
} {
(*_receiverMethod)(arguments);
return true;
}
else return false;
}
AbstractDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionDelegate* pOtherDelegate = dynamic_cast<const FunctionDelegate*>(other.unwrap());
return pOtherDelegate && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{ {
return new FunctionDelegate(*this); return new FunctionDelegate(*this);
} }
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected: protected:
NotifyMethod _receiverMethod; NotifyMethod _receiverMethod;
Mutex _mutex;
private: private:
FunctionDelegate(); FunctionDelegate();
}; };
} // namespace Poco } // namespace Poco
#endif #endif // Foundation_FunctionDelegate_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// FunctionPriorityDelegate.h // FunctionPriorityDelegate.h
// //
// $Id: //poco/svn/Foundation/include/Poco/FunctionPriorityDelegate.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/FunctionPriorityDelegate.h#5 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -9,7 +9,7 @@
// //
// Implementation of the FunctionPriorityDelegate template. // Implementation of the FunctionPriorityDelegate template.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
@@ -36,12 +36,13 @@
// //
#ifndef Foundation_FunctionPriorityDelegate_INCLUDED #ifndef Foundation_FunctionPriorityDelegate_INCLUDED
#define Foundation_FunctionPriorityDelegate_INCLUDED #define Foundation_FunctionPriorityDelegate_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include "Poco/AbstractPriorityDelegate.h" #include "Poco/AbstractPriorityDelegate.h"
#include "Poco/Mutex.h"
namespace Poco { namespace Poco {
@@ -49,23 +50,23 @@ namespace Poco {
template <class TArgs, bool useSender = true, bool senderIsConst = true> template <class TArgs, bool useSender = true, bool senderIsConst = true>
class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs> class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
/// Wraps a C style function (or a C++ static fucntion) to be used as /// Wraps a freestanding function or static member function
/// a priority delegate /// for use as a PriorityDelegate.
{ {
public: public:
typedef void (*NotifyMethod)(const void*, TArgs&); typedef void (*NotifyMethod)(const void*, TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio): FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio), AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method) _receiverMethod(method)
{ {
} }
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority), AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod) _receiverMethod(delegate._receiverMethod)
{ {
} }
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
{ {
@@ -82,22 +83,40 @@ public:
{ {
} }
bool notify(const void* sender, TArgs& arguments) bool notify(const void* sender, TArgs& arguments)
{ {
(*_receiverMethod)(sender, arguments); Mutex::ScopedLock lock(_mutex);
return true; // per default the delegate never expires if (_receiverMethod)
} {
(*_receiverMethod)(sender, arguments);
return true;
}
else return false;
}
AbstractPriorityDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{ {
return new FunctionPriorityDelegate(*this); const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
} return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected: protected:
NotifyMethod _receiverMethod; NotifyMethod _receiverMethod;
Mutex _mutex;
private: private:
FunctionPriorityDelegate(); FunctionPriorityDelegate();
}; };
@@ -105,19 +124,19 @@ template <class TArgs>
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs> class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
{ {
public: public:
typedef void (*NotifyMethod)(void*, TArgs&); typedef void (*NotifyMethod)(void*, TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio): FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio), AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method) _receiverMethod(method)
{ {
} }
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority), AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod) _receiverMethod(delegate._receiverMethod)
{ {
} }
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
{ {
@@ -134,43 +153,60 @@ public:
{ {
} }
bool notify(const void* sender, TArgs& arguments) bool notify(const void* sender, TArgs& arguments)
{ {
(*_receiverMethod)(const_cast<void*>(sender), arguments); Mutex::ScopedLock lock(_mutex);
return true; // per default the delegate never expires if (_receiverMethod)
} {
(*_receiverMethod)(const_cast<void*>(sender), arguments);
return true;
}
else return false;
}
AbstractPriorityDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{ {
return new FunctionPriorityDelegate(*this); const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
} return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected: protected:
NotifyMethod _receiverMethod; NotifyMethod _receiverMethod;
Mutex _mutex;
private: private:
FunctionPriorityDelegate(); FunctionPriorityDelegate();
}; };
template <class TArgs> template <class TArgs>
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs> class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
{ {
public: public:
typedef void (*NotifyMethod)(TArgs&); typedef void (*NotifyMethod)(TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio): FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio), AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method) _receiverMethod(method)
{ {
} }
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate): FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority), AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod) _receiverMethod(delegate._receiverMethod)
{ {
} }
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate) FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
{ {
@@ -187,26 +223,44 @@ public:
{ {
} }
bool notify(const void* sender, TArgs& arguments) bool notify(const void* sender, TArgs& arguments)
{ {
(*_receiverMethod)(arguments); Mutex::ScopedLock lock(_mutex);
return true; // per default the delegate never expires if (_receiverMethod)
} {
(*_receiverMethod)(arguments);
return true;
}
else return false;
}
AbstractPriorityDelegate<TArgs>* clone() const bool equals(const AbstractDelegate<TArgs>& other) const
{ {
return new FunctionPriorityDelegate(*this); const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
} return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected: protected:
NotifyMethod _receiverMethod; NotifyMethod _receiverMethod;
Mutex _mutex;
private: private:
FunctionPriorityDelegate(); FunctionPriorityDelegate();
}; };
} // namespace Poco } // namespace Poco
#endif #endif // Foundation_FunctionPriorityDelegate_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// Glob.h // Glob.h
// //
// $Id: //poco/1.3/Foundation/include/Poco/Glob.h#3 $ // $Id: //poco/1.4/Foundation/include/Poco/Glob.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Filesystem // Package: Filesystem

View File

@@ -1,7 +1,7 @@
// //
// HMACEngine.h // HMACEngine.h
// //
// $Id: //poco/svn/Foundation/include/Poco/HMACEngine.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/HMACEngine.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Crypt // Package: Crypt

View File

@@ -1,127 +1,127 @@
// //
// Hash.h // Hash.h
// //
// $Id: //poco/Main/Foundation/include/Poco/Hash.h#4 $ // $Id: //poco/1.4/Foundation/include/Poco/Hash.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Hashing // Package: Hashing
// Module: Hash // Module: Hash
// //
// Definition of the Hash class. // Definition of the Hash class.
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
// //
// Permission is hereby granted, free of charge, to any person or organization // Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by // obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute, // this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the // execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to // Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following: // do so, all subject to the following:
// //
// The copyright notices in the Software and this entire statement, including // The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer, // the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and // must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative // all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by // works are solely in the form of machine-executable object code generated by
// a source language processor. // a source language processor.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
#ifndef Foundation_Hash_INCLUDED #ifndef Foundation_Hash_INCLUDED
#define Foundation_Hash_INCLUDED #define Foundation_Hash_INCLUDED
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include <cstddef> #include <cstddef>
namespace Poco { namespace Poco {
std::size_t Foundation_API hash(Int8 n); std::size_t Foundation_API hash(Int8 n);
std::size_t Foundation_API hash(UInt8 n); std::size_t Foundation_API hash(UInt8 n);
std::size_t Foundation_API hash(Int16 n); std::size_t Foundation_API hash(Int16 n);
std::size_t Foundation_API hash(UInt16 n); std::size_t Foundation_API hash(UInt16 n);
std::size_t Foundation_API hash(Int32 n); std::size_t Foundation_API hash(Int32 n);
std::size_t Foundation_API hash(UInt32 n); std::size_t Foundation_API hash(UInt32 n);
std::size_t Foundation_API hash(Int64 n); std::size_t Foundation_API hash(Int64 n);
std::size_t Foundation_API hash(UInt64 n); std::size_t Foundation_API hash(UInt64 n);
std::size_t Foundation_API hash(const std::string& str); std::size_t Foundation_API hash(const std::string& str);
template <class T> template <class T>
struct Hash struct Hash
/// A generic hash function. /// A generic hash function.
{ {
std::size_t operator () (T value) const std::size_t operator () (T value) const
/// Returns the hash for the given value. /// Returns the hash for the given value.
{ {
return Poco::hash(value); return Poco::hash(value);
} }
}; };
// //
// inlines // inlines
// //
inline std::size_t hash(Int8 n) inline std::size_t hash(Int8 n)
{ {
return static_cast<std::size_t>(n)*2654435761U; return static_cast<std::size_t>(n)*2654435761U;
} }
inline std::size_t hash(UInt8 n) inline std::size_t hash(UInt8 n)
{ {
return static_cast<std::size_t>(n)*2654435761U; return static_cast<std::size_t>(n)*2654435761U;
} }
inline std::size_t hash(Int16 n) inline std::size_t hash(Int16 n)
{ {
return static_cast<std::size_t>(n)*2654435761U; return static_cast<std::size_t>(n)*2654435761U;
} }
inline std::size_t hash(UInt16 n) inline std::size_t hash(UInt16 n)
{ {
return static_cast<std::size_t>(n)*2654435761U; return static_cast<std::size_t>(n)*2654435761U;
} }
inline std::size_t hash(Int32 n) inline std::size_t hash(Int32 n)
{ {
return static_cast<std::size_t>(n)*2654435761U; return static_cast<std::size_t>(n)*2654435761U;
} }
inline std::size_t hash(UInt32 n) inline std::size_t hash(UInt32 n)
{ {
return static_cast<std::size_t>(n)*2654435761U; return static_cast<std::size_t>(n)*2654435761U;
} }
inline std::size_t hash(Int64 n) inline std::size_t hash(Int64 n)
{ {
return static_cast<std::size_t>(n)*2654435761U; return static_cast<std::size_t>(n)*2654435761U;
} }
inline std::size_t hash(UInt64 n) inline std::size_t hash(UInt64 n)
{ {
return static_cast<std::size_t>(n)*2654435761U; return static_cast<std::size_t>(n)*2654435761U;
} }
} // namespace Poco } // namespace Poco
#endif // Foundation_Hash_INCLUDED #endif // Foundation_Hash_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// HashFunction.h // HashFunction.h
// //
// $Id: //poco/Main/Foundation/include/Poco/HashFunction.h#5 $ // $Id: //poco/1.4/Foundation/include/Poco/HashFunction.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Hashing // Package: Hashing

View File

@@ -1,7 +1,7 @@
// //
// HashMap.h // HashMap.h
// //
// $Id: //poco/svn/Foundation/include/Poco/HashMap.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/HashMap.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Hashing // Package: Hashing

View File

@@ -1,7 +1,7 @@
// //
// HashSet.h // HashSet.h
// //
// $Id: //poco/svn/Foundation/include/Poco/HashSet.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/HashSet.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Hashing // Package: Hashing

View File

@@ -1,7 +1,7 @@
// //
// HashStatistic.h // HashStatistic.h
// //
// $Id: //poco/svn/Foundation/include/Poco/HashStatistic.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/HashStatistic.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Hashing // Package: Hashing

View File

@@ -1,7 +1,7 @@
// //
// HashTable.h // HashTable.h
// //
// $Id: //poco/svn/Foundation/include/Poco/HashTable.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/HashTable.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Hashing // Package: Hashing
@@ -77,13 +77,13 @@ public:
_entries(0), _entries(0),
_size(0), _size(0),
_maxCapacity(initialSize) _maxCapacity(initialSize)
/// Creates the HashTable. /// Creates the HashTable.
{ {
_entries = new HashEntryMap*[initialSize]; _entries = new HashEntryMap*[initialSize];
std::memset(_entries, '\0', sizeof(HashEntryMap*)*initialSize); std::memset(_entries, '\0', sizeof(HashEntryMap*)*initialSize);
} }
HashTable(const HashTable& ht): HashTable(const HashTable& ht):
_entries(new HashEntryMap*[ht._maxCapacity]), _entries(new HashEntryMap*[ht._maxCapacity]),
_size(ht._size), _size(ht._size),
_maxCapacity(ht._maxCapacity) _maxCapacity(ht._maxCapacity)
@@ -312,13 +312,13 @@ public:
{ {
HashTableVector cpy = _entries; HashTableVector cpy = _entries;
_entries = 0; _entries = 0;
UInt32 oldSize = _maxCapacity; UInt32 oldSize = _maxCapacity;
_maxCapacity = newSize; _maxCapacity = newSize;
_entries = new HashEntryMap*[_maxCapacity]; _entries = new HashEntryMap*[_maxCapacity];
std::memset(_entries, '\0', sizeof(HashEntryMap*)*_maxCapacity); std::memset(_entries, '\0', sizeof(HashEntryMap*)*_maxCapacity);
if (_size == 0) if (_size == 0)
{ {
// no data was yet inserted // no data was yet inserted
delete[] cpy; delete[] cpy;
return; return;

View File

@@ -1,7 +1,7 @@
// //
// HexBinaryDecoder.h // HexBinaryDecoder.h
// //
// $Id: //poco/svn/Foundation/include/Poco/HexBinaryDecoder.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/HexBinaryDecoder.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams
@@ -52,25 +52,25 @@ class Foundation_API HexBinaryDecoderBuf: public UnbufferedStreamBuf
/// This streambuf decodes all hexBinary-encoded data read /// This streambuf decodes all hexBinary-encoded data read
/// from the istream connected to it. /// from the istream connected to it.
/// In hexBinary encoding, each binary octet is encoded as a character tuple, /// In hexBinary encoding, each binary octet is encoded as a character tuple,
/// consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code. /// consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code.
/// See also: XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/), /// See also: XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/),
/// section 3.2.15. /// section 3.2.15.
/// ///
/// Note: For performance reasons, the characters /// Note: For performance reasons, the characters
/// are read directly from the given istream's /// are read directly from the given istream's
/// underlying streambuf, so the state /// underlying streambuf, so the state
/// of the istream will not reflect that of /// of the istream will not reflect that of
/// its streambuf. /// its streambuf.
{ {
public: public:
HexBinaryDecoderBuf(std::istream& istr); HexBinaryDecoderBuf(std::istream& istr);
~HexBinaryDecoderBuf(); ~HexBinaryDecoderBuf();
private: private:
int readFromDevice(); int readFromDevice();
int readOne(); int readOne();
std::streambuf& _buf; std::streambuf& _buf;
}; };
@@ -94,18 +94,18 @@ class Foundation_API HexBinaryDecoder: public HexBinaryDecoderIOS, public std::i
/// This istream decodes all hexBinary-encoded data read /// This istream decodes all hexBinary-encoded data read
/// from the istream connected to it. /// from the istream connected to it.
/// In hexBinary encoding, each binary octet is encoded as a character tuple, /// In hexBinary encoding, each binary octet is encoded as a character tuple,
/// consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code. /// consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code.
/// See also: XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/), /// See also: XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/),
/// section 3.2.15. /// section 3.2.15.
/// ///
/// Note: For performance reasons, the characters /// Note: For performance reasons, the characters
/// are read directly from the given istream's /// are read directly from the given istream's
/// underlying streambuf, so the state /// underlying streambuf, so the state
/// of the istream will not reflect that of /// of the istream will not reflect that of
/// its streambuf. /// its streambuf.
{ {
public: public:
HexBinaryDecoder(std::istream& istr); HexBinaryDecoder(std::istream& istr);
~HexBinaryDecoder(); ~HexBinaryDecoder();
}; };

View File

@@ -1,7 +1,7 @@
// //
// HexBinaryEncoder.h // HexBinaryEncoder.h
// //
// $Id: //poco/svn/Foundation/include/Poco/HexBinaryEncoder.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/HexBinaryEncoder.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams
@@ -53,17 +53,17 @@ class Foundation_API HexBinaryEncoderBuf: public UnbufferedStreamBuf
/// to it in hexBinary encoding and forwards it to a connected /// to it in hexBinary encoding and forwards it to a connected
/// ostream. /// ostream.
/// In hexBinary encoding, each binary octet is encoded as a character tuple, /// In hexBinary encoding, each binary octet is encoded as a character tuple,
/// consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code. /// consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code.
/// See also: XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/), /// See also: XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/),
/// section 3.2.15. /// section 3.2.15.
/// ///
/// Note: The characters are directly written /// Note: The characters are directly written
/// to the ostream's streambuf, thus bypassing /// to the ostream's streambuf, thus bypassing
/// the ostream. The ostream's state is therefore /// the ostream. The ostream's state is therefore
/// not updated to match the buffer's state. /// not updated to match the buffer's state.
{ {
public: public:
HexBinaryEncoderBuf(std::ostream& ostr); HexBinaryEncoderBuf(std::ostream& ostr);
~HexBinaryEncoderBuf(); ~HexBinaryEncoderBuf();
int close(); int close();
@@ -86,10 +86,10 @@ public:
private: private:
int writeToDevice(char c); int writeToDevice(char c);
int _pos; int _pos;
int _lineLength; int _lineLength;
int _uppercase; int _uppercase;
std::streambuf& _buf; std::streambuf& _buf;
}; };
@@ -118,17 +118,17 @@ class Foundation_API HexBinaryEncoder: public HexBinaryEncoderIOS, public std::o
/// writing data, to ensure proper /// writing data, to ensure proper
/// completion of the encoding operation. /// completion of the encoding operation.
/// In hexBinary encoding, each binary octet is encoded as a character tuple, /// In hexBinary encoding, each binary octet is encoded as a character tuple,
/// consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code. /// consisting of two hexadecimal digits ([0-9a-fA-F]) representing the octet code.
/// See also: XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/), /// See also: XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/),
/// section 3.2.15. /// section 3.2.15.
/// ///
/// Note: The characters are directly written /// Note: The characters are directly written
/// to the ostream's streambuf, thus bypassing /// to the ostream's streambuf, thus bypassing
/// the ostream. The ostream's state is therefore /// the ostream. The ostream's state is therefore
/// not updated to match the buffer's state. /// not updated to match the buffer's state.
{ {
public: public:
HexBinaryEncoder(std::ostream& ostr); HexBinaryEncoder(std::ostream& ostr);
~HexBinaryEncoder(); ~HexBinaryEncoder();
}; };

View File

@@ -1,7 +1,7 @@
// //
// Instantiator.h // Instantiator.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Instantiator.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Instantiator.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Core // Package: Core

View File

@@ -1,7 +1,7 @@
// //
// KeyValueArgs.h // KeyValueArgs.h
// //
// $Id: //poco/svn/Foundation/include/Poco/KeyValueArgs.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/KeyValueArgs.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Cache // Package: Cache

View File

@@ -1,7 +1,7 @@
// //
// LRUCache.h // LRUCache.h
// //
// $Id: //poco/svn/Foundation/include/Poco/LRUCache.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/LRUCache.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Cache // Package: Cache
@@ -51,13 +51,13 @@ template <
class TKey, class TKey,
class TValue, class TValue,
class TMutex = FastMutex, class TMutex = FastMutex,
class TEventMutex = FastMutex class TEventMutex = FastMutex
> >
class LRUCache: public AbstractCache<TKey, TValue, LRUStrategy<TKey, TValue>, TMutex, TEventMutex> class LRUCache: public AbstractCache<TKey, TValue, LRUStrategy<TKey, TValue>, TMutex, TEventMutex>
/// An LRUCache implements Least Recently Used caching. The default size for a cache is 1024 entries. /// An LRUCache implements Least Recently Used caching. The default size for a cache is 1024 entries.
{ {
public: public:
LRUCache(long size = 1024): LRUCache(long size = 1024):
AbstractCache<TKey, TValue, LRUStrategy<TKey, TValue>, TMutex, TEventMutex>(LRUStrategy<TKey, TValue>(size)) AbstractCache<TKey, TValue, LRUStrategy<TKey, TValue>, TMutex, TEventMutex>(LRUStrategy<TKey, TValue>(size))
{ {
} }

View File

@@ -1,7 +1,7 @@
// //
// Latin9Encoding.h // Latin9Encoding.h
// //
// $Id: //poco/svn/Foundation/include/Poco/Latin9Encoding.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/Latin9Encoding.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Text // Package: Text

View File

@@ -1,7 +1,7 @@
// //
// LineEndingConverter.h // LineEndingConverter.h
// //
// $Id: //poco/svn/Foundation/include/Poco/LineEndingConverter.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/LineEndingConverter.h#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Streams // Package: Streams

Some files were not shown because too many files have changed in this diff Show More