Generated on Wed Nov 1 15:04:38 2006 for Gecode by doxygen 1.4.5

dfa.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2004
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-04 16:03:26 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3512 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode {
00023 
00028   class DFA::Transitions {
00029   private:
00031     const Transition* c_trans;
00033     const Transition* e_trans;
00034   public:
00036     Transitions(const DFA& d);
00038     bool operator()(void) const;
00040     void operator++(void);
00042     const Transition* transition(void) const;
00043   };
00044 
00049   class DFA::DFAI {
00050   public:
00052     unsigned int use_cnt;
00054     unsigned int n_states;
00056     unsigned int n_trans;
00058     int          final_fst;
00060     int          final_lst;
00062     Transition   trans[1];
00064     GECODE_INT_EXPORT DFAI* copy(void);
00065   };
00066 
00067 
00068   forceinline
00069   DFA::DFA(void) {}
00070 
00071   forceinline
00072   DFA::DFA(int start, Transition t_spec[], int f_spec[], bool minimize) {
00073     init(start,t_spec,f_spec,minimize);
00074   }
00075 
00076 
00077   forceinline
00078   DFA::DFA(const DFA& d)
00079     : dfai(d.dfai) {
00080     dfai->use_cnt++;
00081   }
00082 
00083   inline void
00084   DFA::update(bool share, DFA& d) {
00085     if (share) {
00086       dfai = d.dfai;
00087       dfai->use_cnt++;
00088     } else {
00089       dfai = d.dfai->copy();
00090     }
00091   }
00092 
00093   forceinline
00094   DFA::~DFA(void) {
00095     if (--dfai->use_cnt == 0)
00096       Memory::free(dfai);
00097   }
00098 
00099   forceinline const DFA&
00100   DFA::operator=(const DFA& d) {
00101     if (&d != this) {
00102       if (--dfai->use_cnt == 0)
00103         Memory::free(dfai);
00104       dfai = d.dfai;
00105       dfai->use_cnt++;
00106     }
00107     return *this;
00108   }
00109 
00110   forceinline unsigned int
00111   DFA::n_states(void) const {
00112     return dfai->n_states;
00113   }
00114 
00115   forceinline unsigned int
00116   DFA::n_transitions(void) const {
00117     return dfai->n_trans;
00118   }
00119 
00120   forceinline int
00121   DFA::final_fst(void) const {
00122     return dfai->final_fst;
00123   }
00124 
00125   forceinline int
00126   DFA::final_lst(void) const {
00127     return dfai->final_lst;
00128   }
00129 
00130   forceinline int
00131   DFA::symbol_min(void) const {
00132     int n = dfai->n_trans;
00133     return (n > 0) ? dfai->trans[0].symbol : Limits::Int::int_min;
00134   }
00135 
00136   forceinline int
00137   DFA::symbol_max(void) const {
00138     int n = dfai->n_trans;
00139     return (n > 0) ? dfai->trans[n-1].symbol : Limits::Int::int_max;
00140   }
00141 
00142 
00143 
00144   /*
00145    * Iterating over all transitions
00146    *
00147    */
00148 
00149   forceinline
00150   DFA::Transitions::Transitions(const DFA& d)
00151     : c_trans(&d.dfai->trans[0]), e_trans(c_trans+d.dfai->n_trans) {}
00152 
00153   forceinline bool
00154   DFA::Transitions::operator()(void) const {
00155     return c_trans < e_trans;
00156   }
00157 
00158   forceinline void
00159   DFA::Transitions::operator++(void) {
00160     c_trans++;
00161   }
00162 
00163   forceinline const DFA::Transition*
00164   DFA::Transitions::transition(void) const {
00165     return c_trans;
00166   }
00167 
00168 }
00169 
00170 
00171 // STATISTICS: int-prop
00172