Vaucanson 1.4
freemonoid_product.hh
00001 // freemonoid_product.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2004, 2005, 2006, 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 #ifndef VCSN_ALGEBRA_CONCEPT_FREEMONOID_PRODUCT_HH
00018 # define VCSN_ALGEBRA_CONCEPT_FREEMONOID_PRODUCT_HH
00019 
00020 # include <vaucanson/algebra/concept/freemonoid_product_base.hh>
00021 # include <vaucanson/algebra/implementation/monoid/monoid_rep.hh>
00022 # include <vaucanson/algebra/implementation/series/series_rep.hh>
00023 # include <vaucanson/misc/unique.hh>
00024 
00025 namespace vcsn {
00026 
00027   namespace algebra {
00028   
00032     /*---------------.
00033     | Predeclaration |
00034     `---------------*/
00035 
00036     template <class F, class S>
00037     struct FreeMonoidProduct;
00038 
00039     /*------------------------------------------------------------.
00040     | Specialization of the MonoidRep structure for this concept. |
00041     `------------------------------------------------------------*/
00042 
00043     template <typename F, typename S>
00044     struct MonoidRep<FreeMonoidProduct<F, S> > :
00045            MonoidRepBase<MonoidRep, FreeMonoidProduct<F, S> >
00046     {
00048       std::string open_par;
00049 
00051       std::string sep;
00052 
00054       std::string close_par;
00055 
00056       MonoidRep();
00057     };
00058 
00059     /*------------------------------------------------------------.
00060     | Specialization of the SeriesRep structure for this concept. |
00061     `------------------------------------------------------------*/
00062 
00063     template <typename Semiring, typename F, typename S>
00064     struct SeriesRep<Semiring, FreeMonoidProduct<F, S> > :
00065            SeriesRepBase<SeriesRep, Semiring, FreeMonoidProduct<F, S> >
00066     {
00067       // The type of the semiring.
00068       typedef Semiring                          semiring_t;
00069 
00070       // The type of the monoid.
00071       typedef FreeMonoidProduct<F, S>           monoid_t;
00072 
00073       // The most derived type in the hierarchy.
00074       typedef SeriesRep<semiring_t, monoid_t>   self_t;
00075 
00076       // Pointer types.
00077       typedef boost::shared_ptr<self_t>         pointer_t;
00078 
00079       // Type helpers.
00080       typedef SeriesRep<Semiring, F> first_rep_t;
00081       typedef SeriesRep<Semiring, S> second_rep_t;
00082 
00084       first_rep_t& first_representation();
00085       second_rep_t& second_representation();
00086       const first_rep_t& first_representation() const;
00087       const second_rep_t& second_representation() const;
00088 
00089       void disambiguate(const monoid_t&, pointer_t&);
00090 
00091     private:
00092 
00094       first_rep_t first_representation_;
00095 
00097       second_rep_t second_representation_;
00098     };
00099 
00100     template <typename F, typename S>
00101     bool operator==(boost::shared_ptr<MonoidRep<FreeMonoidProduct<F, S> > >,
00102                     boost::shared_ptr<MonoidRep<FreeMonoidProduct<F, S> > >);
00103 
00104     template <typename Semiring, typename F, typename S>
00105     bool operator==(boost::shared_ptr<SeriesRep<Semiring,
00106                                                 FreeMonoidProduct<F, S> > >,
00107                     boost::shared_ptr<SeriesRep<Semiring,
00108                                                 FreeMonoidProduct<F, S> > >);
00109 
00110     /*------------------------.
00111     | FreeMonoidProduct<F, S> |
00112     `------------------------*/
00113 
00115     template<class F, class S>
00116     struct FreeMonoidProduct
00117       : FreeMonoidProductBase< FreeMonoidProduct<F, S> >
00118     {
00119       // Type helpers.
00120       typedef F first_monoid_t;
00121       typedef S second_monoid_t;
00122       typedef MonoidRep<FreeMonoidProduct<F, S> > monoid_rep_t;
00123       typedef boost::shared_ptr<monoid_rep_t> shared_monoid_rep_t;
00124 
00126       FreeMonoidProduct(const F& a, const S& b);
00127 
00129       FreeMonoidProduct(const F& a, const S& b, monoid_rep_t mr);
00130 
00132       FreeMonoidProduct(const FreeMonoidProduct& w);
00133 
00137       first_monoid_t&           first_monoid();
00138 
00139       const first_monoid_t&     first_monoid() const;
00140 
00141       second_monoid_t&          second_monoid();
00142 
00143       const second_monoid_t&    second_monoid() const;
00144 
00146       const shared_monoid_rep_t representation() const;
00147 
00148     public:
00150       void set_representation(monoid_rep_t mr);
00151 
00152     protected:
00153       first_monoid_t            first_monoid_;
00154       second_monoid_t           second_monoid_;
00155       shared_monoid_rep_t       rep_;
00156     };
00157 
00158     template<class F, class S>
00159     bool operator==(const FreeMonoidProduct<F, S>& m1,
00160                     const FreeMonoidProduct<F, S>& m2);
00161 
00165   } // ! algebra
00166   
00170   /*-----------------------------------------.
00171   | dynamic_traits<FreeMonoidProduct<F, S> > |
00172   `-----------------------------------------*/
00174   template<class F, class S>
00175   struct dynamic_traits<algebra::FreeMonoidProduct<F, S> >
00176     : dynamic_traits<algebra::FreeMonoidProductBase<algebra::FreeMonoidProduct<F, S> > >
00177   {
00179     static const bool
00180     ret = dynamic_traits<F>::ret or dynamic_traits<S>::ret;
00181   };
00182 
00183   /*----------------------------------------.
00184   | MetaElement<FreeMonoidProduct<F, S>, T> |
00185   `----------------------------------------*/
00188   template<class F, class S, typename T>
00189   struct MetaElement<algebra::FreeMonoidProduct<F, S>, T>
00190     : MetaElement<algebra::FreeMonoidProductBase<algebra::FreeMonoidProduct<F, S> >, T>
00191   {
00192     typedef F   first_monoid_t;
00193     typedef S   second_monoid_t;
00194   };
00195 
00200   template <class F, class S>
00201   struct virtual_types<algebra::FreeMonoidProduct<F, S> >
00202     : virtual_types<algebra::FreeMonoidProductBase<algebra::FreeMonoidProduct<F, S> > >
00203   {
00204     typedef F           first_monoid_t;
00205     typedef S           second_monoid_t;
00206   };
00207 
00208 } // vcsn
00209 
00210 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00211 #  include <vaucanson/algebra/concept/freemonoid_product.hxx>
00212 # endif // VCSN_USE_INTERFACE_ONLY
00213 
00214 
00215 #endif // ! VCSN_ALGEBRA_CONCEPT_FREEMONOID_PRODUCT_HH