Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
data.h
1 /*
2  * Data module documentation
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2016, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_DATA_H_
22 #define ELM_DATA_H_
23 
24 #include <elm/data/util.h>
25 
26 namespace elm {
27 
355 /*
356  * @par custom_data Customizing the data structures
357  *
358  * The proposed data structure requires memory allocator, comparator or hash
359  * key computation to work. As a default, they use the default implementation
360  * of this features: @ref DefaultAllocator @ref Comparator or @ref HashKey.
361  * Yet, ELM provides a way to customize the data structures using the
362  * concept of data manager.
363  *
364  * A data manager groups together all facilities required to implement a data
365  * structure and let the data structure user to customize its implementation.
366  * There are basically three manager:
367  * * @ref EquivManager for data structures equality operations on their items,
368  * * @ref CompareManager for data structures requiring an absolute order on
369  * their items,
370  * * @ref HashManager for data structure requiring equality operations and
371  * hash value computation on their items.
372  *
373  * In addition, all managers provide allocation facilities. Basically, the
374  * data structures takes a manager as template parameter. To customize a
375  * data structure, one has to pass a different manager in this template
376  * parameter. In the example below, the @ref EquivManager of the
377  * @ref Vector class is changed to use a special memory allocator:
378  * ```
379  * class MyAllocator {
380  * ...
381  * };
382  *
383  * typedef EquivManager<int, Equiv<int>, MyAllocator> MyManager;
384  * Vector<int, MyManager> my_vector;
385  * ```
386  *
387  * Sometimes, static nature of a manager is not enough and you need to
388  * instantiate a customized manager with a specific object:
389  * ```
390  * class MyAllocator {
391  * ...
392  * };
393  * typedef EquivManager<int, Equiv<int>, MyAllocator> MyManager;
394  *
395  * MyAllocator my_allocator;
396  * MyManager my_manager(single<Equiv<int>>(), my_allocator);
397  *
398  * Vector<int, MyManager> my_vector(my_manager);
399  * ```
400  *
401  * @ref elm::single<T>() is used here to get a singleton instance of the given
402  * type: this prevents to clutter the memory with to many instance of a class
403  * that is actually a singleton.
404  *
405  * To ensure memory minimal footprint, a manager that does not contain any data
406  * (no instance) does not take place in the data structure. To achieve this,
407  * the data structure inherits from the manager. As a consequence, when the
408  * manager contains an instance, its constructor is called each time the data
409  * structure is built passing an instance reference as constructor parameter.
410  *
411  * In the example above, if we do not want to duplicate the allocators, it
412  * is required to have an implementation like below:
413  * ```
414  * class MyAllocator {
415  * ...
416  * };
417  * class MyManagerAllocator {
418  * public:
419  * MyManagerAllocator(MyAllocator& alloc): _alloc(alloc) { }
420  * MyManagerAllocator(MyManagerAllocator& a): _alloc(a._alloc) { }
421  * ...
422  * private:
423  * MyAllocator _alloc;
424  * };
425  * typedef EquivManager<int, Equiv<int>, MyManagerAllocator> MyManager;
426  *
427  * MyAllocator my_allocator;
428  * MyManager my_manager(single<Equiv<int>>(), MyManagerallocator(my_allocator));
429  *
430  * Vector<int, MyManager> my_vector(my_manager);
431  * ```
432  */
433 
459 namespace concept {
460 
466 template <class T>
467 struct Predicate {
468  bool operator()(const T& v);
469 };
470 
477 template <class T, class A>
479  bool operator()(const T& v, const A& a);
480 };
481 
489 template <class X, class Y>
490 struct Function {
491  typedef X x_t;
492  typedef Y y_t;
493  Y operator()(const X& x);
494 };
495 
503 template <class X, class Y, class A>
505  typedef X x_t;
506  typedef Y y_t;
507  Y operator()(const X& x, const A& a);
508 };
509 
510 } // concept
511 
512 
890 } // elm
891 
892 #endif /* ELM_DATA_H_ */
elm::concept::Function::operator()
Y operator()(const X &x)
elm::concept::Function
Definition: data.h:490
elm::concept::FunctionWithArg::y_t
Y y_t
Definition: data.h:506
elm::concept::FunctionWithArg::operator()
Y operator()(const X &x, const A &a)
elm
Definition: adapter.h:26
elm::concept::Function::x_t
X x_t
Definition: data.h:491
elm::concept::PredicateWithArg
Definition: data.h:478
elm::concept::Predicate::operator()
bool operator()(const T &v)
elm::concept::Function::y_t
Y y_t
Definition: data.h:492
elm::concept::FunctionWithArg
Definition: data.h:504
elm::concept::FunctionWithArg::x_t
X x_t
Definition: data.h:505
elm::concept::PredicateWithArg::operator()
bool operator()(const T &v, const A &a)