/*
 * This file is part of the Cforall project
 *
 * $Id: SemanticError.h,v 1.1 2002/04/27 19:57:10 rcbilson Exp $
 *
 */

#ifndef SEMANTICERROR_H
#define SEMANTICERROR_H

#include <exception>
#include <string>
#include <strstream>
#include <list>
#include <iostream>

class SemanticError : public std::exception
{
public:
  SemanticError();
  SemanticError( std::string error );
  template< typename T > SemanticError( const std::string &error, const T *obj );
  ~SemanticError() throw() {}

  void append( SemanticError &other );
  bool isEmpty() const;
  void print( std::ostream &os );

  // constructs an exception using the given message and the printed
  // representation of the obj (T must have a print method)

private:
  std::list< std::string > errors;
};

template< typename T >
SemanticError::SemanticError( const std::string &error, const T *obj )
{
  std::ostrstream os;
  os << "Error: " << error;
  obj->print( os );
  errors.push_back( std::string( os.str(), os.pcount() ) );
}

#endif /* SEMANTICERROR_H */
