Vaucanson  1.4.1
partial_rat_exp.hh
Go to the documentation of this file.
1 // partial_rat_exp.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGORITHMS_INTERNAL_PARTIAL_RAT_EXP_HH
18 # define VCSN_ALGORITHMS_INTERNAL_PARTIAL_RAT_EXP_HH
19 
32 # include <vaucanson/algebra/implementation/series/krat_exp_pattern.hh>
34 # include <vaucanson/algebra/implementation/series/krat.hh>
35 # include <list>
36 
37 namespace vcsn
38 {
39  /*---------------------.
40  | Traits for iterators |
41  `---------------------*/
42 
43  template <bool IsConst, typename T>
44  struct reference_type
45  { typedef T& ret; };
46 
47  template <typename T>
48  struct reference_type<true, T>
49  { typedef const T& ret; };
50 
51  template <bool IsConst, typename T>
52  struct iterator_type
53  { typedef typename T::iterator ret; };
54 
55  template <typename T>
56  struct iterator_type<true, T>
57  { typedef typename T::const_iterator ret; };
58 
59  /*-----------------.
60  | PartialExp class |
61  `-----------------*/
62 
63  // An implementation of Derivates represented by list of pointers.
64  template <typename Series, typename T>
65  struct PartialExp
66  {
67  // Common types
68  typedef Element<Series, T> exp_t;
69  typedef Series series_set_t;
70  typedef T series_set_elt_value_t;
71  typedef typename T::node_t node_t;
72  typedef typename exp_t::semiring_elt_t semiring_elt_t;
73 
74  /*
75  * A std::list is used because pop_front is needed,
76  * and we must be able to modify an element of the list.
77  */
78  typedef std::list<const node_t*> node_list_t;
79  typedef std::list<semiring_elt_t> semiring_elt_list_t;
80 
81  // Constructors
82  // Be carefull: the exp must be realtime !
83  PartialExp(const exp_t &e);
84  PartialExp(const exp_t &e, const semiring_elt_t& w);
85  PartialExp(const PartialExp &other);
86 
87  // Insert a new node into the list, and add another weight "after".
88  template <typename M, typename W>
89  PartialExp& insert(const rat::Node<M, W>* v);
90 
91  // Accessors
92  semiring_elt_list_t& weights();
93  const semiring_elt_list_t& weights() const;
94  node_list_t& nodes();
95  const node_list_t& nodes() const;
96 
97  // Operators to change weights
98  PartialExp& operator<<=(const semiring_elt_t& w);
99  PartialExp& operator>>=(const semiring_elt_t& w);
100 
101  // Accessor for the rat_exp and usefull methods
102  const exp_t& exp() const;
103  const Series& exp_structure() const;
104  const T& exp_value() const;
105 
106  protected:
107  // Protected attributes
108  const exp_t* rat_exp_;
109  semiring_elt_list_t semiring_elt_list_;
110  node_list_t node_list_;
111 
112  public:
113  // internal class for iterator and const_iterator
114  template <bool IsConst>
115  struct internal_iterator
116  {
117  public:
118  typedef typename
119  reference_type<IsConst,semiring_elt_t>::ret semiring_elt_ref_t;
120  typedef typename
121  reference_type<IsConst,const node_t*>::ret node_ref_t;
122  typedef typename
123  iterator_type<IsConst,semiring_elt_list_t>::ret semiring_elts_iterator_t;
124  typedef typename
125  iterator_type<IsConst,node_list_t>::ret nodes_iterator_t;
126  public:
127  internal_iterator(const semiring_elts_iterator_t&,
128  const nodes_iterator_t&);
129  internal_iterator& operator++();
130  internal_iterator operator++(int);
131  bool operator!=(const internal_iterator& other);
132  bool operator==(const internal_iterator& other);
133  semiring_elt_ref_t semiring_elt() const;
134  node_ref_t node() const;
135  bool on_node() const;
136  protected:
137  semiring_elts_iterator_t semiring_elts_iterator_;
138  nodes_iterator_t nodes_iterator_;
139  bool on_node_;
140  };
141 
142  // definitions of iterator and const_iterator
143  typedef internal_iterator<false> iterator;
144  typedef internal_iterator<true> const_iterator;
145 
146  // iterators functions
147  iterator begin();
148  iterator end();
149  const_iterator begin() const;
150  const_iterator end() const;
151  };
152 
153  /*---------------------.
154  | PartialExp functions |
155  `---------------------*/
156 
157  template <typename S, typename T>
158  std::ostream& operator<< (std::ostream& o, const PartialExp<S, T>& e);
159 
160  // Be carefull: the exp must be realtime !
161  template <typename S, typename T>
162  std::list<PartialExp<S, T> > prat_exp_convert(const std::list<Element<S, T> >& exp);
163 
164  template <typename S, typename T>
165  PartialExp<S, T> prat_exp_convert(const Element<S, T>& exp);
166 
167  template <typename S, typename T>
168  bool operator< (const PartialExp<S, T>& e1, const PartialExp<S, T>& e2);
169 
170  template <typename S, typename T>
171  bool operator== (const PartialExp<S, T>& e1, const PartialExp<S, T>& e2);
172 
173  template <typename S, typename T>
174  bool unweighted_eq(const PartialExp<S, T>& e1, const PartialExp<S, T>& e2);
175 
176  template <typename S, typename T>
177  bool unweighted_inf(const PartialExp<S, T>& e1, const PartialExp<S, T>& e2);
178 
179 } // vcsn
180 
181 
182 # if !defined VCSN_USE_INTERFACE_ONLY && !defined VCSN_USE_LIB
183 # include <vaucanson/algorithms/internal/partial_rat_exp.hxx>
184 #endif // VCSN_USE_INTERFACE_ONLY
185 
186 
187 #endif // ! VCSN_ALGORITHMS_INTERNAL_PARTIAL_RAT_EXP_HH