Vaucanson 1.4
|
00001 // vgraph_container.hxx: this file is part of the Vaucanson project. 00002 // 00003 // Vaucanson, a generic library for finite state machines. 00004 // 00005 // Copyright (C) 2007, 2008 The Vaucanson Group. 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // The complete GNU General Public Licence Notice can be found as the 00013 // `COPYING' file in the root directory. 00014 // 00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file. 00016 // 00017 00018 #ifndef VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_VGRAPH_CONTAINER_HXX 00019 # define VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_VGRAPH_CONTAINER_HXX 00020 00021 # include <vaucanson/automata/implementation/bmig/vgraph_container.hh> 00022 00023 namespace vcsn 00024 { 00025 namespace bmig 00026 { 00027 00028 /*--------------------. 00029 | Convenient macros. | 00030 `--------------------*/ 00031 00032 # define TPARAM \ 00033 template<typename EdgesIterator, typename GraphData, typename HTransition> 00034 00035 /*--------------------------. 00036 | VGraphContainer iterator. | 00037 `--------------------------*/ 00038 00039 # define ITERATOR \ 00040 VGraphContainerIterator<EdgesIterator, GraphData, HTransition> 00041 00042 TPARAM 00043 ITERATOR::VGraphContainerIterator(const GraphData& c, 00044 EdgesIterator i) 00045 : container_(c) 00046 { 00047 if (i != c.end()) 00048 { 00049 it_ = i++; 00050 next_ = i; 00051 } 00052 else 00053 { 00054 it_ = i; 00055 next_ = i; 00056 } 00057 } 00058 00059 00060 TPARAM 00061 HTransition 00062 ITERATOR::operator*() const 00063 { 00064 return HTransition(it_); 00065 } 00066 00067 TPARAM 00068 bool 00069 ITERATOR::operator==(const VGraphContainerIterator& v) const 00070 { 00071 return v.it_ == it_; 00072 } 00073 00074 TPARAM 00075 bool 00076 ITERATOR::operator!=(const VGraphContainerIterator& v) const 00077 { 00078 return v.it_ != it_; 00079 } 00080 00081 TPARAM 00082 ITERATOR& 00083 ITERATOR::operator++() 00084 { 00085 if (next_ != container_.end()) 00086 it_ = next_++; 00087 else 00088 it_ = next_; 00089 return *this; 00090 } 00091 00092 TPARAM 00093 ITERATOR 00094 ITERATOR::operator++(int) 00095 { 00096 iterator tmp = it_; 00097 if (next_ != container_.end()) 00098 it_ = next_++; 00099 else 00100 it_ = next_; 00101 return ITERATOR(container_, tmp); 00102 } 00103 00104 /*-----------------------------------------. 00105 | Container wrapper for Boost multi_index. | 00106 `-----------------------------------------*/ 00107 00108 # define CONTAINER \ 00109 VGraphContainer<EdgesIterator, GraphData, HTransition> 00110 00111 TPARAM 00112 CONTAINER::VGraphContainer(const GraphData& g) 00113 : graph_(g) 00114 { 00115 } 00116 00117 TPARAM 00118 typename CONTAINER::iterator 00119 CONTAINER::begin() const 00120 { 00121 return ITERATOR(graph_, graph_.begin()); 00122 } 00123 00124 TPARAM 00125 typename CONTAINER::iterator 00126 CONTAINER::end() const 00127 { 00128 return ITERATOR(graph_, graph_.end()); 00129 } 00130 00131 TPARAM 00132 size_t 00133 CONTAINER::size() const 00134 { 00135 return graph_.size(); 00136 } 00137 00138 } 00139 } 00140 00141 # undef ITERATOR 00142 # undef CONTAINER 00143 # undef BMIGRAPH 00144 #endif // !VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_VGRAPH_CONTAINER_HXX 00145