/*
 * ASTL - the Automaton Standard Template Library.
 * C++ generic components for Finite State Machine handling.
 * Copyright (C) 2000 Vincent Le Maout (vlemaout@lexiquest.fr).
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

//
//	File:		    astl.h
//  Version:    ASTL 1.2
//	Copyright:	Vincent LE MAOUT
//	Date:		    02/2001
//	Descrition:	this file includes minimal set of ASTL headers
//              

#ifndef ASTL_1_2_H
#define ASTL_1_2_H

#ifdef _WIN32
#include <utility>   // bogus include to define std namespace
  #ifndef __GNUC__
    #ifndef WIN32
      #define WIN32
    #endif
  #endif
#endif

#ifdef WIN32
using namespace std;
// remove warnings about truncated type names (works once in a while):
#pragma warning( disable : 4786 ) 
#endif

#include <iterator>
#include <vector>
#include <functional>    // unary_function<>

// tag_traits<> definition + default tag
#include <tag.h>       


// skip_blanks_iterator implements DFA_*::const_iterator
// it skips holes in the pointers vector to internal states created by del_state
#ifndef WIN32
template <class T>
class skip_blanks_iterator : public forward_iterator<vector<T*>::size_type, unsigned int>
#else
template <class T>
class skip_blanks_iterator : public iterator<forward_iterator_tag, vector<T*>::size_type>
#endif
{
  typedef skip_blanks_iterator self;

private:
  const vector<T*> *Q;
  vector<T*>::size_type pos;

public:  
  skip_blanks_iterator(const vector<T*> *_Q, vector<T*>::size_type _pos)
    : Q(_Q), pos(_pos) { }

  skip_blanks_iterator() : Q(NULL), pos(0) { }
  skip_blanks_iterator(const self &x) : Q(x.Q), pos(x.pos) { }
  self& operator = (const self &x)
    {
      Q = x.Q;
      pos = x.pos;
      return (*this);
    }
  
  bool operator == (const self &x) {
    return (x.pos == pos && x.Q == Q);
  }
  
  bool operator != (const self &x) {
    return (x.pos != pos || x.Q != Q);
  }
  
  vector<T*>::size_type operator * () { 
    return (pos); 
  }
  
  self& operator ++ ()
    {
      for(++pos; pos < Q->size() && Q->operator[](pos) == NULL; ++pos);
      return (*this);
    }
  
  self operator ++ (int)
    {
      self tmp = *this;
      ++(*this);
      return (tmp);
    }
};

// alphabet_traits<> definition +
// basic alphabets + default alphabet
#include <alphabet.h>  

// base classes for DFA and NFA:
#include <fa_base.h>

#ifdef WIN32
// Microsoft STL doesn't implements identity function (VC++ 6.0) :
// (needed for default behavior on Tags in DFA_compact)
template <class T>
struct identity : public unary_function<T, T>
{
	const T& operator () (const T &x) {
		return (x);
	}
};

#endif // WIN32


#ifndef WIN32
// Ugly hack for dfa_bin, dfa_mtf, dfa_tr (to be fixed):
template <class T, class U>
bool operator== (const pair<T, U> &x, const pair<const T, U> &y) {
	return x.first == const_cast<T&>(y.first) && x.second == y.second;
}

template <class T, class U>
bool operator== (const pair<const T, U> &x, const pair<T, U> &y) {
	return const_cast<T&>(x.first) == y.first && x.second == y.second;
}
#endif

#endif // ASTL_1_2_H




