Back to Arangodb

Boost.Flyweight Factories reference

3rdParty/boost/1.78.0/libs/flyweight/doc/reference/factories.html

3.12.9.113.3 KB
Original Source

Boost.Flyweight Factories reference


Tags


Boost.Flyweight reference


Holders


Contents

Factories and factory specifiers

Given a type Key and an Assignable type Entry implicitly convertible to const Key&, a factory of Entry elements (implicitly associated to Key) is a Default Constructible entity able to store and retrieve immutable elements of type Entry. A factory is governed by an associated equivalence relation defined on Key so that no two Entry objects convertible to equivalent Keys can be stored simultaneously in the factory. Different factory types can use different equivalence relations.

In the following table, Factory is a factory of elements of type Entry, f denotes an object of type Factory, x is an object of type Entry and h is a value of Factory::handle_type.

Factory requirements. | expression | return type | assertion/note
pre/post-condition | | --- | --- | --- | | Factory::handle_type | handle to elements of type T
stored in the factory | handle_type is Assignable and its copy and
assignment operations never throw an exception. | | f.insert(x); | handle_type | Inserts a copy of x if there is no equivalent entry in f;
returns a handle to the inserted or equivalent element. | | f.erase(h); | void | Erases the element associated to h.
This operation does not throw. | | f.entry(h); | const Entry& | Returns a reference to the element associated to h.
This operation does not throw. |

Additionally to the basic thread safety guarantee which is implicitly assumed for most classes including the majority of components of the C++ standard library, it is required that the member function entry can be invoked simultaneously from different threads, even in the presence of concurrent accesses to insert and erase (as long as the entry returned by entry is not the one which is being erased).

A type S is said to be a factory specifier if:

  1. One of the following conditions is satisfied:

  2. is_factory<S>::type is boost::mpl::true_,

  3. S is of the form factory<S'>.

  4. S, or S' if (b) applies, is an MPL Lambda Expression such that invoking it with types (Entry, Key) resolves to a factory type of Entry elements (implicitly associated to Key).

Header "boost/flyweight/factory_tag.hpp" synopsis

namespaceboost{namespaceflyweights{structfactory\_marker;template\<typenameT\>structis\_factory;template\<typenameT\>structfactory;}// namespace boost::flyweights}// namespace boost

Class template is_factory

Unless specialized by the user, is_factory<T>::type is boost::mpl::true_ if T is derived from factory_marker, and it is boost::mpl::false_ otherwise.

Class template factory

factory<T> is a syntactic construct meant to indicate that T is a factory specifier without resorting to the mechanisms provided by the is_factory class template.

Header "boost/flyweight/hashed_factory_fwd.hpp" synopsis

namespaceboost{namespaceflyweights{template\<typenameEntry,typenameKey,typenameHash= **implementation defined** ,typenamePred= **implementation defined** ,typenameAllocator= **implementation defined** \>classhashed\_factory\_class;template\<typenameHash= **implementation defined** ,typenamePred= **implementation defined** ,typenameAllocator= **implementation defined** \>structhashed\_factory;}// namespace boost::flyweights}// namespace boost

hashed_factory_fwd.hpp forward declares the class templates hashed_factory_class and hashed_factory.

Header "boost/flyweight/hashed_factory.hpp" synopsis

Class template hashed_factory_class

hashed_factory_class is a Factory implemented with a hashed container.

template\<typenameEntry,typenameKey,typenameHash,typenamePred,typenameAllocator\>classhashed\_factory\_class{public:typedef **implementation defined** handle\_type;handle\_typeinsert(constEntry&x);voiderase(handle\_typeh);constEntry&entry(handle\_typeh);};

Hash is a Default ConstructibleUnary Function taking a single argument of type Key and returning a value of type std::size_t in the range [0, std::numeric_limits<std::size_t>::max()). Pred is a Default ConstructibleBinary Predicate inducing an equivalence relation on elements of Key. It is required that a Hash object return the same value for objects equivalent under Pred. The equivalence relation on Key associated to the factory is that induced by Pred. The default arguments for Hash and Pred are boost::hash<Key> and std::equal_to<Key>, respectively. Allocator must be an allocator of Entry objects satisfying the associated C++ requirements at [lib.allocator.requirements]. The default argument is std::allocator<Entry>. The internal hashed container upon which hashed_factory_class is based is constructed with default initialized objects of type Hash, Pred and Allocator.

Class template hashed_factory

Factory Specifier for hashed_factory_class.

template\<typenameHash,typenamePred,typenameAllocator\>structhashed\_factory;

hashed_factory<Hash,Pred,Allocator> is an MPL Metafunction Class such that the type

boost::mpl::apply\<hashed\_factory\<Hash,Pred,Allocator\>,Entry,Key\>::type

is the same as

boost::mpl::apply\<hashed\_factory\_class\<boost::mpl::\_1,boost::mpl::\_2,Hash,Pred,Allocator\>,Entry,Key\>::type

This implies that Hash, Pred and Allocator can be MPL Placeholder Expressions resolving to the actual types used by hashed_factory_class.

Header "boost/flyweight/set_factory_fwd.hpp" synopsis

namespaceboost{namespaceflyweights{template\<typenameEntry,typenameKey,typenameCompare= **implementation defined** ,typenameAllocator= **implementation defined** \>classset\_factory\_class;template\<typenameCompare= **implementation defined** ,typenameAllocator= **implementation defined** \>structset\_factory;}// namespace boost::flyweights}// namespace boost

set_factory_fwd.hpp forward declares the class templates set_factory_class and set_factory.

Header "boost/flyweight/set_factory.hpp" synopsis

Class template set_factory_class

set_factory_class is a Factory implemented on top of an orderded associative container.

template\<typenameEntry,typenameKey,typenameCompare,typenameAllocator\>classset\_factory\_class{public:typedef **implementation defined** handle\_type;handle\_typeinsert(constEntry&x);voiderase(handle\_typeh);constEntry&entry(handle\_typeh);};

Compare is a Default ConstructibleStrict Weak Ordering on Key. Two Keys x and y are considered equivalent if !c(x,y)&&!c(y,x) for c of type Compare. The default argument of Compare is std::less<Key>. Allocator must be an allocator of Entry objects satisfying the associated C++ requirements at [lib.allocator.requirements]. The default argument is std::allocator<Entry>. The internal container upon which set_factory_class is based is constructed with default initialized objects of type Compare and Allocator.

Class template set_factory

Factory Specifier for set_factory_class.

template\<typenameCompare,typenameAllocator\>structset\_factory;

set_factory<Compare,Allocator> is an MPL Metafunction Class such that the type

boost::mpl::apply\<set\_factory\<Compare,Allocator\>,Entry,Key\>::type

is the same as

boost::mpl::apply\<set\_factory\_class\<boost::mpl::\_1,boost::mpl::\_2,Compare,Allocator\>,Entry,Key\>::type

This implies that Compare and Allocator can be MPL Placeholder Expressions resolving to the actual types used by set_factory_class.

Header "boost/flyweight/assoc_container_factory_fwd.hpp" synopsis

namespaceboost{namespaceflyweights{template\<typenameContainer\>classassoc\_container\_factory\_class;template\<typenameContainerSpecifier\>structassoc\_container\_factory;}// namespace boost::flyweights}// namespace boost

assoc_container_factory_fwd.hpp forward declares the class templates assoc_container_factory_class and assoc_container_factory.

Header "boost/flyweight/assoc_container_factory.hpp" synopsis

Class template assoc_container_factory_class

assoc_container_factory_class wraps a suitable associative container to provide a Factory interface.

template\<typenameContainer\>classassoc\_container\_factory\_class{public:typedeftypenameContainer::iteratorhandle\_type;handle\_typeinsert(consttypenameContainer::value\_type&x);voiderase(handle\_typeh);consttypenameContainer::value\_type&entry(handle\_typeh);};

Container must be an (ordered or unordered) associative container such that

  1. Container::key_type is the same as Container::value_type (which is the entry type associated to the factory).
  2. Unique keys (rather than equivalent keys) are supported.
  3. Container is stable, i.e. its iterators are not invalidated upon insert or erase operations.

The equivalence relation associated to assoc_container_factory_class is the one induced by Container. If equivalence of elements of Container::value_type is determined solely on the basis of a type value_type' to which value_type is implicitly convertible, then assoc_container_factory_class is a factory of entries of type value_type implicitly associated to value_type'. For example, the instantiation

assoc\_container\_factory\_class\<std::set\<derived,std::less\<base\>\>// derived inherits from base\>

is a factory of derived elements implicitly associated to base.

Class template assoc_container_factory

Factory Specifier for assoc_container_factory_class.

template\<typenameContainerSpecifier\>structassoc\_container\_factory;

ContainerSpecifier must be an MPL Lambda Expression resolving, when invoked with (Entry, Key), to a type Container such that assoc_container_factory_class<Container> is a factory of Entry elements implicitly associated to Key.



Tags


Boost.Flyweight reference


Holders

Revised April 24th 2019

© Copyright 2006-2019 Joaquín M López Muñoz. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)