www.pudn.com > cppcc.rar > dfa_profile.hh


/*
 *  File:       dfa_profile.hh
 *              $Id: dfa_profile.hh,v 1.1 2002/06/23 23:42:39 alec Exp $
 *
 *  Author:     Alec Panoviciu (alecu@email.com)
 *
 *  Comments:
 *
 *  Revision history:
 *
 *  $Log: dfa_profile.hh,v $
 *  Revision 1.1  2002/06/23 23:42:39  alec
 *  profiling based optimization added
 *
 */


/* 
  Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program 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 General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 */

#ifndef __DFA_PROFILE_HH__
#define __DFA_PROFILE_HH__

#include 

#include "debug.h"
#include "scanner_dfa_spec.hh"
#include "basic_dfa_spec.hh"

class DfaStateProfile
{
public:

  DfaStateProfile (BasicDfaSpec::State &s);

  bool read (istream &is);

  void reset ();
  
  unsigned long int operator [] (int i)
  {
    ASSERT((0 <= i) && (i <= size()),
           "Bad index in DfaStateProfile::operator []")
    return freqs[i];
  }

  int size()
  {
    return freqs.size();
  }
  
private:
  
  vector freqs;
};

class BasicDfaProfile
{
public:

  BasicDfaProfile (BasicDfaSpec &dfa);

  bool read (istream &is);

  void reset ();
  
  DfaStateProfile& operator [] (int i)
  {
    ASSERT((0 <= i) && (i <= size()),
           "Bad index in BasicDfaProfile::operator []")
    return stateProfiles[i];
  }

  int size () const
  {
    return stateProfiles.size();
  }

private:
  
  vector stateProfiles;
};

class ScannerDfaProfile
{
public:

  ScannerDfaProfile (ScannerDfaSpec &dfa);

  bool read (istream &is);

  void reset ();
  
  BasicDfaProfile& operator [] (int i)
  {
    ASSERT((0 <= i) && (i <= size()),
           "Bad index in ScannerDfaProfile::operator []")
    return dfaProfiles[i];
  }

  int size() const
  {
    return dfaProfiles.size();
  }
  
  vector dfaProfiles;
};


#endif /* #ifndef __DFA_PROFILE_HH__ */