Add AbstractObject, cyclic_iterator, Journal improvements

This commit is contained in:
Vinnie Falco
2013-11-30 18:23:28 -08:00
parent 370d98a858
commit 893b2d4587
9 changed files with 680 additions and 95 deletions

View File

@@ -25,13 +25,13 @@
#define BEAST_SMARTPTR_ABSTRACTOBJECT_H_INCLUDED
#include <list>
#include <memory>
#include <stdexcept>
#include <typeinfo>
#include "../Atomic.h"
#include "../Config.h"
#include "../Uncopyable.h"
#include "../intrusive/LockFreeStack.h"
#include "../smart_ptr/ScopedPointer.h"
namespace beast {
namespace abstract {
@@ -235,15 +235,17 @@ public:
Derived must be a subclass of Interface
*/
template <typename Derived>
void add_interface (ScopedPointer <Derived>&& derived)
void add_interface (Derived* derived)
{
std::unique_ptr <BasicInterface> base_interface (
derived);
if (has_interface <Derived> ())
throw std::invalid_argument ("non-unique");
m_set.emplace_back (derived);
m_set.emplace_back (base_interface.release ());
}
private:
typedef std::list <ScopedPointer <BasicInterface>> Set;
typedef std::list <std::unique_ptr <BasicInterface>> Set;
Set m_set;
};

View File

@@ -66,8 +66,7 @@ public:
void create_interfaces (Object& object)
{
object.add_interface (ScopedPointer <Interface1> (
new Interface1));
object.add_interface (new Interface1);
}
};
@@ -91,8 +90,7 @@ public:
void create_interfaces (Object& object)
{
object.add_interface (ScopedPointer <Interface2> (
new Interface2));
object.add_interface (new Interface2);
}
};
@@ -112,12 +110,11 @@ public:
// find existing interfaces
expect (object.find_interface <Interface1> () != nullptr);
expect (object.find_interface <Interface2> () != nullptr);
// add duplicate interface
try
{
object.add_interface (ScopedPointer <Interface1> (
new Interface1));
object.add_interface (new Interface1);
fail ("uncaught exeption");
}
catch (std::invalid_argument const&)