1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_dbos_SetFacade_hpp
38 #define anna_dbos_SetFacade_hpp
42 #include <anna/dbos/Set.hpp>
43 #include <anna/dbos/ObjectFacade.hpp>
50 Clase que facilita el acceso y uso de las clases encargadas de la instanciacion de multiples objetos a partir de los
51 datos contenidos en un medio fisico, que normalmente seria la tabla de una base de datos.
53 Esta nos facilita el manejo de instancias multiples, es decir, para una condicion de carga dada hay varios registros
54 o elementos del medio fisico que la cumplen.
56 La clase \em T debe tener definidos los siquientes metodos:
57 \li anna::dbos::Object::instantiate: Interpreta la informacin la del medio fisico para adecuarla a
59 \li void destroy () throw (): Libera los recursos reservados por este objeto
64 template <typename T> class SetFacade : public ObjectFacade < Set <T> > {
66 typedef typename Set<T>::iterator iterator;
67 typedef typename Set<T>::const_iterator const_iterator;
70 Devuelve el numero de elementos contenidos en el conjunto recibido como parametro.
71 Se puede usar sin tener que preocuparse por
72 el valor de la instancia del conjunto, ya que si este es NULL devolveria 0.
73 \param t Instancia del conjunto.
74 \return El numero de elementos que contiene el conjunto.
76 static int size(Set<T>* t) throw() { return (t == NULL) ? 0 : t->size(); }
79 Iterator al primer elemento del conjunto. Se puede usar sin tener que preocuparse por
80 el valor de la instancia del conjunto, ya que si este es NULL devolveria 0.
81 \return Un iterador del primer elemento del conjunto.
83 static iterator begin(Set<T>* t) throw() {
84 return (t == NULL) ? iterator(0) : t->begin();
88 Iterator al ultimo elemento del conjunto. Se puede usar sin tener que preocuparse por
89 el valor de la instancia del conjunto, ya que si este es NULL devolveria 0.
90 \return Un iterador del primer elemento del conjunto.
92 static iterator end(Set<T>* t) throw() {
93 return (t == NULL) ? iterator(0) : t->end();
97 Iterator al primer elemento del conjunto. Se puede usar sin tener que preocuparse por
98 el valor de la instancia del conjunto, ya que si este es NULL devolveria 0.
99 \return Un iterador del primer elemento del conjunto.
101 static const_iterator begin(const Set<T>* t) throw() {
102 return (t == NULL) ? const_iterator(0) : t->begin();
106 Iterator al ultimo elemento del conjunto. Se puede usar sin tener que preocuparse por
107 el valor de la instancia del conjunto, ya que si este es NULL devolveria 0.
108 \return Un iterador del primer elemento del conjunto.
110 static const_iterator end(const Set<T>* t) throw() {
111 return (t == NULL) ? const_iterator(0) : t->end();
114 Devuelve el objeto referenciado por el iterator recibido como parametro.
115 \return El objeto referenciado por el iterator recibido como parametro.
117 static T* data(iterator ii) throw() { return Set<T>::data(ii); }
120 Devuelve el objeto referenciado por el iterator recibido como parametro.
121 \return El objeto referenciado por el iterator recibido como parametro.
123 static const T* data(const_iterator ii) throw() { return Set<T>::data(ii); }
133 Definicion a la que hay que invocar en la implementacion de la clase que hereda
134 de anna::dbos::SetFacade.
136 \param T Nombre de la clase que vamos a tratar en el ambito de C++.
138 #define dbos_prepare_set(T) \
139 template <> anna::dbos::StorageArea* anna::dbos::ObjectFacade < anna::dbos::Set <T> >::st_storageArea = NULL
142 Definicion a la que hay que invocar dentro de la definicion de la clase que hereda
143 de anna::dbos::SetFacade.
145 \param T Nombre de la clase que vamos a tratar en el ambito de C++.
147 #define dbos_declare_set(T) \
148 friend class anna::Allocator<T>; \
149 friend class anna::dbos::Set <T>