Vaucanson  1.4.1
freemonoid_product.hh
1 // freemonoid_product.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2004, 2005, 2006, 2008 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_ALGEBRA_CONCEPT_FREEMONOID_PRODUCT_HH
18 # define VCSN_ALGEBRA_CONCEPT_FREEMONOID_PRODUCT_HH
19 
20 # include <vaucanson/algebra/concept/freemonoid_product_base.hh>
21 # include <vaucanson/algebra/implementation/monoid/monoid_rep.hh>
22 # include <vaucanson/algebra/implementation/series/series_rep.hh>
23 # include <vaucanson/misc/unique.hh>
24 
25 namespace vcsn {
26 
27  namespace algebra {
28 
32  /*---------------.
33  | Predeclaration |
34  `---------------*/
35 
36  template <class F, class S>
37  struct FreeMonoidProduct;
38 
39  /*------------------------------------------------------------.
40  | Specialization of the MonoidRep structure for this concept. |
41  `------------------------------------------------------------*/
42 
43  template <typename F, typename S>
44  struct MonoidRep<FreeMonoidProduct<F, S> > :
45  MonoidRepBase<MonoidRep, FreeMonoidProduct<F, S> >
46  {
48  std::string open_par;
49 
51  std::string sep;
52 
54  std::string close_par;
55 
56  MonoidRep();
57  };
58 
59  /*------------------------------------------------------------.
60  | Specialization of the SeriesRep structure for this concept. |
61  `------------------------------------------------------------*/
62 
63  template <typename Semiring, typename F, typename S>
64  struct SeriesRep<Semiring, FreeMonoidProduct<F, S> > :
65  SeriesRepBase<SeriesRep, Semiring, FreeMonoidProduct<F, S> >
66  {
67  // The type of the semiring.
68  typedef Semiring semiring_t;
69 
70  // The type of the monoid.
71  typedef FreeMonoidProduct<F, S> monoid_t;
72 
73  // The most derived type in the hierarchy.
74  typedef SeriesRep<semiring_t, monoid_t> self_t;
75 
76  // Pointer types.
77  typedef boost::shared_ptr<self_t> pointer_t;
78 
79  // Type helpers.
80  typedef SeriesRep<Semiring, F> first_rep_t;
81  typedef SeriesRep<Semiring, S> second_rep_t;
82 
84  first_rep_t& first_representation();
85  second_rep_t& second_representation();
86  const first_rep_t& first_representation() const;
87  const second_rep_t& second_representation() const;
88 
89  void disambiguate(const monoid_t&, pointer_t&);
90 
91  private:
92 
94  first_rep_t first_representation_;
95 
97  second_rep_t second_representation_;
98  };
99 
100  template <typename F, typename S>
101  bool operator==(boost::shared_ptr<MonoidRep<FreeMonoidProduct<F, S> > >,
102  boost::shared_ptr<MonoidRep<FreeMonoidProduct<F, S> > >);
103 
104  template <typename Semiring, typename F, typename S>
105  bool operator==(boost::shared_ptr<SeriesRep<Semiring,
106  FreeMonoidProduct<F, S> > >,
107  boost::shared_ptr<SeriesRep<Semiring,
108  FreeMonoidProduct<F, S> > >);
109 
110  /*------------------------.
111  | FreeMonoidProduct<F, S> |
112  `------------------------*/
113 
115  template<class F, class S>
117  : FreeMonoidProductBase< FreeMonoidProduct<F, S> >
118  {
119  // Type helpers.
120  typedef F first_monoid_t;
121  typedef S second_monoid_t;
122  typedef MonoidRep<FreeMonoidProduct<F, S> > monoid_rep_t;
123  typedef boost::shared_ptr<monoid_rep_t> shared_monoid_rep_t;
124 
126  FreeMonoidProduct(const F& a, const S& b);
127 
129  FreeMonoidProduct(const F& a, const S& b, monoid_rep_t mr);
130 
133 
138 
139  const first_monoid_t& first_monoid() const;
140 
142 
143  const second_monoid_t& second_monoid() const;
144 
146  const shared_monoid_rep_t representation() const;
147 
148  public:
150  void set_representation(monoid_rep_t mr);
151 
152  protected:
153  first_monoid_t first_monoid_;
154  second_monoid_t second_monoid_;
155  shared_monoid_rep_t rep_;
156  };
157 
158  template<class F, class S>
159  bool operator==(const FreeMonoidProduct<F, S>& m1,
160  const FreeMonoidProduct<F, S>& m2);
161 
165  } // ! algebra
166 
170  /*-----------------------------------------.
171  | dynamic_traits<FreeMonoidProduct<F, S> > |
172  `-----------------------------------------*/
174  template<class F, class S>
175  struct dynamic_traits<algebra::FreeMonoidProduct<F, S> >
176  : dynamic_traits<algebra::FreeMonoidProductBase<algebra::FreeMonoidProduct<F, S> > >
177  {
179  static const bool
180  ret = dynamic_traits<F>::ret or dynamic_traits<S>::ret;
181  };
182 
183  /*----------------------------------------.
184  | MetaElement<FreeMonoidProduct<F, S>, T> |
185  `----------------------------------------*/
188  template<class F, class S, typename T>
189  struct MetaElement<algebra::FreeMonoidProduct<F, S>, T>
190  : MetaElement<algebra::FreeMonoidProductBase<algebra::FreeMonoidProduct<F, S> >, T>
191  {
192  typedef F first_monoid_t;
193  typedef S second_monoid_t;
194  };
195 
200  template <class F, class S>
201  struct virtual_types<algebra::FreeMonoidProduct<F, S> >
202  : virtual_types<algebra::FreeMonoidProductBase<algebra::FreeMonoidProduct<F, S> > >
203  {
204  typedef F first_monoid_t;
205  typedef S second_monoid_t;
206  };
207 
208 } // vcsn
209 
210 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
211 # include <vaucanson/algebra/concept/freemonoid_product.hxx>
212 # endif // VCSN_USE_INTERFACE_ONLY
213 
214 
215 #endif // ! VCSN_ALGEBRA_CONCEPT_FREEMONOID_PRODUCT_HH