00001 /* 00002 * ASTL - the Automaton Standard Template Library. 00003 * C++ generic components for Finite State Automata handling. 00004 * Copyright (C) 2000-2003 Vincent Le Maout (vincent.lemaout@chello.fr). 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #ifndef ASTL_STATE_H 00023 #define ASTL_STATE_H 00024 00025 // A generic state structure storing a pair<tag, transition container> 00026 // Used by DFA_base to allocate/deallocate states 00027 // 00028 // Type requirements: 00029 // - Tag is default contructible, copy constructible, assignable 00030 // - TransitionContainer is default constructible, copy constructible, assignable, 00031 // equality comparable and defines two methods size() 00032 // 00033 // This template is specialized for empty_tag in order to save memory space when 00034 // no tags are required 00035 00036 #include <astl.h> 00037 00038 namespace astl { 00039 00040 template <typename Tag, typename TransitionContainer> 00041 class state_data 00042 { 00043 protected: 00044 Tag t; 00045 TransitionContainer e; 00046 00047 public: 00048 Tag& tag() { 00049 return t; 00050 } 00051 const Tag& tag() const { 00052 return t; 00053 } 00054 TransitionContainer& edges() { 00055 return e; 00056 } 00057 const TransitionContainer& edges() const { 00058 return e; 00059 } 00060 }; 00061 00062 // A partial specialization of the state structure to save 00063 // space when no tags are required: 00064 00065 #ifndef _MSC_VER 00066 template <typename TransitionContainer> 00067 class state_data<empty_tag, TransitionContainer> 00068 { 00069 protected: 00070 static empty_tag t; // consistent with the previous interface 00071 TransitionContainer e; 00072 00073 public: 00074 empty_tag& tag() { 00075 return t; 00076 } 00077 const empty_tag& tag() const { 00078 return t; 00079 } 00080 TransitionContainer& edges() { 00081 return e; 00082 } 00083 const TransitionContainer& edges() const { 00084 return e; 00085 } 00086 }; 00087 00088 template <typename TransitionContainer> 00089 empty_tag state_data<empty_tag, TransitionContainer>::t; 00090 #endif // _MSC_VER 00091 00092 } // namespace astl 00093 00094 #endif // ASTL_STATE_H