COIN-OR::LEMON - Graph Library

Ticket #17: 8bed1c3a6080.patch

File 8bed1c3a6080.patch, 31.0 KB (added by Alpar Juttner, 16 years ago)
  • lemon/arg_parser.h

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1222674159 -7200
    # Node ID 8bed1c3a6080206eb1bc9b32fd70783db5c71358
    # Parent  bb40b6db0a587e98535e84eb2b9c92f3df972b6a
    Simplifying exceptions
    
     - Using asserts instead of exceptions for unitialized parameters
     - Only the IO exceptions are used in the lemon
     - DataFormatError is renamed to IoError
     - The IoError is simplified
    
    diff --git a/lemon/arg_parser.h b/lemon/arg_parser.h
    a b  
    310310
    311311    ///This is the type of the return value of ArgParser::operator[]().
    312312    ///It automatically converts to \c int, \c double, \c bool or
    313     ///\c std::string if the type of the option matches, otherwise it
    314     ///throws an exception (i.e. it performs runtime type checking).
     313    ///\c std::string if the type of the option matches, which is checked
     314    ///with an \ref LEMON_ASSERT "assertion" (i.e. it performs runtime
     315    ///type checking).
    315316    class RefType
    316317    {
    317318      const ArgParser &_parser;
  • lemon/bfs.h

    diff --git a/lemon/bfs.h b/lemon/bfs.h
    a b  
    135135#endif
    136136  class Bfs {
    137137  public:
    138     ///\ref Exception for uninitialized parameters.
    139 
    140     ///This error represents problems in the initialization of the
    141     ///parameters of the algorithm.
    142     class UninitializedParameter : public lemon::UninitializedParameter {
    143     public:
    144       virtual const char* what() const throw() {
    145         return "lemon::Bfs::UninitializedParameter";
    146       }
    147     };
    148138
    149139    ///The type of the digraph the algorithm runs on.
    150140    typedef typename TR::Digraph Digraph;
     
    232222      typedef T PredMap;
    233223      static PredMap *createPredMap(const Digraph &)
    234224      {
    235         throw UninitializedParameter();
     225        LEMON_ASSERT(false, "PredMap is not initialized");
    236226      }
    237227    };
    238228    ///\brief \ref named-templ-param "Named parameter" for setting
     
    250240      typedef T DistMap;
    251241      static DistMap *createDistMap(const Digraph &)
    252242      {
    253         throw UninitializedParameter();
     243        LEMON_ASSERT(false, "DistMap is not initialized");
    254244      }
    255245    };
    256246    ///\brief \ref named-templ-param "Named parameter" for setting
     
    268258      typedef T ReachedMap;
    269259      static ReachedMap *createReachedMap(const Digraph &)
    270260      {
    271         throw UninitializedParameter();
     261        LEMON_ASSERT(false, "ReachedMap is not initialized");
    272262      }
    273263    };
    274264    ///\brief \ref named-templ-param "Named parameter" for setting
     
    286276      typedef T ProcessedMap;
    287277      static ProcessedMap *createProcessedMap(const Digraph &)
    288278      {
    289         throw UninitializedParameter();
     279        LEMON_ASSERT(false, "ProcessedMap is not initialized");
    290280      }
    291281    };
    292282    ///\brief \ref named-templ-param "Named parameter" for setting
     
    10401030    ///\return \c true if \c t is reachable form \c s.
    10411031    bool run(Node s, Node t)
    10421032    {
    1043       if (s==INVALID || t==INVALID) throw UninitializedParameter();
    10441033      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    10451034      if (Base::_pred)
    10461035        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
     
    13231312  class BfsVisit {
    13241313  public:
    13251314
    1326     /// \brief \ref Exception for uninitialized parameters.
    1327     ///
    1328     /// This error represents problems in the initialization
    1329     /// of the parameters of the algorithm.
    1330     class UninitializedParameter : public lemon::UninitializedParameter {
    1331     public:
    1332       virtual const char* what() const throw()
    1333       {
    1334         return "lemon::BfsVisit::UninitializedParameter";
    1335       }
    1336     };
    1337 
    13381315    ///The traits class.
    13391316    typedef _Traits Traits;
    13401317
     
    13891366    struct SetReachedMapTraits : public Traits {
    13901367      typedef T ReachedMap;
    13911368      static ReachedMap *createReachedMap(const Digraph &digraph) {
    1392         throw UninitializedParameter();
     1369        LEMON_ASSERT(false, "ReachedMap is not initialized");
    13931370      }
    13941371    };
    13951372    /// \brief \ref named-templ-param "Named parameter" for setting
  • lemon/concepts/heap.h

    diff --git a/lemon/concepts/heap.h b/lemon/concepts/heap.h
    a b  
    129129      /// already stored in the heap.
    130130      /// Otherwise it inserts the given item with the given priority.
    131131      ///
    132       /// It may throw an \ref UnderflowPriorityException.
    133132      /// \param i The item.
    134133      /// \param p The priority.
    135134      void set(const Item &i, const Prio &p) {}
  • lemon/dfs.h

    diff --git a/lemon/dfs.h b/lemon/dfs.h
    a b  
    136136#endif
    137137  class Dfs {
    138138  public:
    139     ///\ref Exception for uninitialized parameters.
    140 
    141     ///This error represents problems in the initialization of the
    142     ///parameters of the algorithm.
    143     class UninitializedParameter : public lemon::UninitializedParameter {
    144     public:
    145       virtual const char* what() const throw() {
    146         return "lemon::Dfs::UninitializedParameter";
    147       }
    148     };
    149139
    150140    ///The type of the digraph the algorithm runs on.
    151141    typedef typename TR::Digraph Digraph;
     
    232222      typedef T PredMap;
    233223      static PredMap *createPredMap(const Digraph &)
    234224      {
    235         throw UninitializedParameter();
     225        LEMON_ASSERT(false, "PredMap is not initialized");
    236226      }
    237227    };
    238228    ///\brief \ref named-templ-param "Named parameter" for setting
     
    250240      typedef T DistMap;
    251241      static DistMap *createDistMap(const Digraph &)
    252242      {
    253         throw UninitializedParameter();
     243        LEMON_ASSERT(false, "DistMap is not initialized");
    254244      }
    255245    };
    256246    ///\brief \ref named-templ-param "Named parameter" for setting
     
    268258      typedef T ReachedMap;
    269259      static ReachedMap *createReachedMap(const Digraph &)
    270260      {
    271         throw UninitializedParameter();
     261        LEMON_ASSERT(false, "ReachedMap is not initialized");
    272262      }
    273263    };
    274264    ///\brief \ref named-templ-param "Named parameter" for setting
     
    286276      typedef T ProcessedMap;
    287277      static ProcessedMap *createProcessedMap(const Digraph &)
    288278      {
    289         throw UninitializedParameter();
     279        LEMON_ASSERT(false, "ProcessedMap is not initialized");
    290280      }
    291281    };
    292282    ///\brief \ref named-templ-param "Named parameter" for setting
     
    974964    ///\return \c true if \c t is reachable form \c s.
    975965    bool run(Node s, Node t)
    976966    {
    977       if (s==INVALID || t==INVALID) throw UninitializedParameter();
    978967      Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    979968      if (Base::_pred)
    980969        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
     
    12701259  class DfsVisit {
    12711260  public:
    12721261
    1273     /// \brief \ref Exception for uninitialized parameters.
    1274     ///
    1275     /// This error represents problems in the initialization
    1276     /// of the parameters of the algorithm.
    1277     class UninitializedParameter : public lemon::UninitializedParameter {
    1278     public:
    1279       virtual const char* what() const throw()
    1280       {
    1281         return "lemon::DfsVisit::UninitializedParameter";
    1282       }
    1283     };
    1284 
    12851262    ///The traits class.
    12861263    typedef _Traits Traits;
    12871264
     
    13361313    struct SetReachedMapTraits : public Traits {
    13371314      typedef T ReachedMap;
    13381315      static ReachedMap *createReachedMap(const Digraph &digraph) {
    1339         throw UninitializedParameter();
     1316        LEMON_ASSERT(false, "ReachedMap is not initialized");
    13401317      }
    13411318    };
    13421319    /// \brief \ref named-templ-param "Named parameter" for setting
  • lemon/dijkstra.h

    diff --git a/lemon/dijkstra.h b/lemon/dijkstra.h
    a b  
    225225#endif
    226226  class Dijkstra {
    227227  public:
    228     ///\ref Exception for uninitialized parameters.
    229 
    230     ///This error represents problems in the initialization of the
    231     ///parameters of the algorithm.
    232     class UninitializedParameter : public lemon::UninitializedParameter {
    233     public:
    234       virtual const char* what() const throw() {
    235         return "lemon::Dijkstra::UninitializedParameter";
    236       }
    237     };
    238228
    239229    ///The type of the digraph the algorithm runs on.
    240230    typedef typename TR::Digraph Digraph;
     
    332322      typedef T PredMap;
    333323      static PredMap *createPredMap(const Digraph &)
    334324      {
    335         throw UninitializedParameter();
     325        LEMON_ASSERT(false, "PredMap is not initialized");
    336326      }
    337327    };
    338328    ///\brief \ref named-templ-param "Named parameter" for setting
     
    351341      typedef T DistMap;
    352342      static DistMap *createDistMap(const Digraph &)
    353343      {
    354         throw UninitializedParameter();
     344        LEMON_ASSERT(false, "DistMap is not initialized");
    355345      }
    356346    };
    357347    ///\brief \ref named-templ-param "Named parameter" for setting
     
    370360      typedef T ProcessedMap;
    371361      static ProcessedMap *createProcessedMap(const Digraph &)
    372362      {
    373         throw UninitializedParameter();
     363        LEMON_ASSERT(false, "ProcessedMap is not initialized");
    374364      }
    375365    };
    376366    ///\brief \ref named-templ-param "Named parameter" for setting
     
    408398      typedef CR HeapCrossRef;
    409399      typedef H Heap;
    410400      static HeapCrossRef *createHeapCrossRef(const Digraph &) {
    411         throw UninitializedParameter();
     401        LEMON_ASSERT(false, "HeapCrossRef is not initialized");
    412402      }
    413403      static Heap *createHeap(HeapCrossRef &)
    414404      {
    415         throw UninitializedParameter();
     405        LEMON_ASSERT(false, "Heap is not initialized");
    416406      }
    417407    };
    418408    ///\brief \ref named-templ-param "Named parameter" for setting
     
    11581148    ///in order to compute the shortest path to each node.
    11591149    void run(Node s)
    11601150    {
    1161       if (s==INVALID) throw UninitializedParameter();
    11621151      Dijkstra<Digraph,LengthMap,TR>
    11631152        dijk(*reinterpret_cast<const Digraph*>(Base::_g),
    11641153             *reinterpret_cast<const LengthMap*>(Base::_length));
     
    11801169    ///\return \c true if \c t is reachable form \c s.
    11811170    bool run(Node s, Node t)
    11821171    {
    1183       if (s==INVALID || t==INVALID) throw UninitializedParameter();
    11841172      Dijkstra<Digraph,LengthMap,TR>
    11851173        dijk(*reinterpret_cast<const Digraph*>(Base::_g),
    11861174             *reinterpret_cast<const LengthMap*>(Base::_length));
  • lemon/error.h

    diff --git a/lemon/error.h b/lemon/error.h
    a b  
    3535  /// \addtogroup exceptions
    3636  /// @{
    3737
    38   /// \brief Exception safe wrapper class.
     38  /// \brief Generic exception class.
    3939  ///
    40   /// Exception safe wrapper class to implement the members of exceptions.
    41   template <typename _Type>
    42   class ExceptionMember {
    43   public:
    44     typedef _Type Type;
    45 
    46     ExceptionMember() throw() {
    47       try {
    48         ptr.reset(new Type());
    49       } catch (...) {}
    50     }
    51 
    52     ExceptionMember(const Type& type) throw() {
    53       try {
    54         ptr.reset(new Type());
    55         if (ptr.get() == 0) return;
    56         *ptr = type;
    57       } catch (...) {}
    58     }
    59 
    60     ExceptionMember(const ExceptionMember& copy) throw() {
    61       try {
    62         if (!copy.valid()) return;
    63         ptr.reset(new Type());
    64         if (ptr.get() == 0) return;
    65         *ptr = copy.get();
    66       } catch (...) {}
    67     }
    68 
    69     ExceptionMember& operator=(const ExceptionMember& copy) throw() {
    70       if (ptr.get() == 0) return;
    71       try {
    72         if (!copy.valid()) return;
    73         *ptr = copy.get();
    74       } catch (...) {}
    75     }
    76 
    77     void set(const Type& type) throw() {
    78       if (ptr.get() == 0) return;
    79       try {
    80         *ptr = type;
    81       } catch (...) {}
    82     }
    83 
    84     const Type& get() const {
    85       return *ptr;
    86     }
    87 
    88     bool valid() const throw() {
    89       return ptr.get() != 0;
    90     }
    91 
    92   private:
    93     std::auto_ptr<_Type> ptr;
    94   };
    95 
    96   /// Exception-safe convenient error message builder class.
    97 
    98   /// Helper class which provides a convenient ostream-like (operator <<
    99   /// based) interface to create a string message. Mostly useful in
    100   /// exception classes (therefore the name).
    101   class ErrorMessage {
    102   protected:
    103     ///\e
    104 
    105     mutable std::auto_ptr<std::ostringstream> buf;
    106 
    107     ///\e
    108     bool init() throw() {
    109       try {
    110         buf.reset(new std::ostringstream);
    111       }
    112       catch(...) {
    113         buf.reset();
    114       }
    115       return buf.get();
    116     }
    117 
    118   public:
    119 
    120     ///\e
    121     ErrorMessage() throw() { init(); }
    122 
    123     ErrorMessage(const ErrorMessage& em) throw() : buf(em.buf) { }
    124 
    125     ///\e
    126     ErrorMessage(const char *msg) throw() {
    127       init();
    128       *this << msg;
    129     }
    130 
    131     ///\e
    132     ErrorMessage(const std::string &msg) throw() {
    133       init();
    134       *this << msg;
    135     }
    136 
    137     ///\e
    138     template <typename T>
    139     ErrorMessage& operator<<(const T &t) throw() {
    140       if( ! buf.get() ) return *this;
    141 
    142       try {
    143         *buf << t;
    144       }
    145       catch(...) {
    146         buf.reset();
    147       }
    148       return *this;
    149     }
    150 
    151     ///\e
    152     const char* message() throw() {
    153       if( ! buf.get() ) return 0;
    154 
    155       const char* mes = 0;
    156       try {
    157         mes = buf->str().c_str();
    158       }
    159       catch(...) {}
    160       return mes;
    161     }
    162 
    163   };
    164 
    165   /// Generic exception class.
    166 
    16740  /// Base class for exceptions used in LEMON.
    16841  ///
    16942  class Exception : public std::exception {
    17043  public:
    171     ///\e
     44    ///\e Constructor
    17245    Exception() {}
    173     ///\e
     46    ///\e Virtual destructor
    17447    virtual ~Exception() throw() {}
    175     ///\e
     48    ///\e A short description of the exception
    17649    virtual const char* what() const throw() {
    17750      return "lemon::Exception";
    17851    }
    17952  };
    18053
    181   /// One of the two main subclasses of \ref Exception.
    182 
    183   /// Logic errors represent problems in the internal logic of a program;
    184   /// in theory, these are preventable, and even detectable before the
    185   /// program runs (e.g. violations of class invariants).
    186   ///
    187   /// A typical example for this is \ref UninitializedParameter.
    188   class LogicError : public Exception {
    189   public:
    190     virtual const char* what() const throw() {
    191       return "lemon::LogicError";
    192     }
    193   };
    194 
    195   /// \ref Exception for uninitialized parameters.
    196 
    197   /// This error represents problems in the initialization
    198   /// of the parameters of the algorithms.
    199   class UninitializedParameter : public LogicError {
    200   public:
    201     virtual const char* what() const throw() {
    202       return "lemon::UninitializedParameter";
    203     }
    204   };
    205 
    206 
    207   /// One of the two main subclasses of \ref Exception.
    208 
    209   /// Runtime errors represent problems outside the scope of a program;
    210   /// they cannot be easily predicted and can generally only be caught
    211   /// as the program executes.
    212   class RuntimeError : public Exception {
    213   public:
    214     virtual const char* what() const throw() {
    215       return "lemon::RuntimeError";
    216     }
    217   };
    218 
    21954  ///\e
    220   class RangeError : public RuntimeError {
    221   public:
    222     virtual const char* what() const throw() {
    223       return "lemon::RangeError";
    224     }
    225   };
    226 
    227   ///\e
    228   class IoError : public RuntimeError {
    229   public:
    230     virtual const char* what() const throw() {
    231       return "lemon::IoError";
    232     }
    233   };
    234 
    235   ///\e
    236   class DataFormatError : public IoError {
     55  class DataFormatError : Exception {
    23756  protected:
    238     ExceptionMember<std::string> _message;
    239     ExceptionMember<std::string> _file;
     57    std::string _message;
     58    std::string _file;
    24059    int _line;
    24160
    242     mutable ExceptionMember<std::string> _message_holder;
     61    mutable std::string _what;
    24362  public:
    24463
    245     DataFormatError(const DataFormatError &dfe) :
    246       IoError(dfe), _message(dfe._message), _file(dfe._file),
    247       _line(dfe._line) {}
    248 
    249     ///\e
    250     explicit DataFormatError(const char *the_message)
    251       : _message(the_message), _line(0) {}
    252 
    253     ///\e
    254     DataFormatError(const std::string &file_name, int line_num,
    255                     const char *the_message)
    256       : _message(the_message), _line(line_num) { file(file_name); }
    257 
    258     ///\e
    259     void line(int ln) { _line = ln; }
    260     ///\e
    261     void message(const std::string& msg) { _message.set(msg); }
    262     ///\e
    263     void file(const std::string &fl) { _file.set(fl); }
    264 
    265     ///\e
    266     int line() const { return _line; }
    267     ///\e
    268     const char* message() const {
    269       if (_message.valid() && !_message.get().empty()) {
    270         return _message.get().c_str();
    271       } else {
    272         return 0;
    273       }
     64    /// Copy constructor
     65    DataFormatError(const DataFormatError &error) {
     66      message(error._message);
     67      file(error._file);
     68      line(error._line);
    27469    }
    27570
    276     /// \brief Returns the filename.
    277     ///
    278     /// Returns \e null if the filename was not specified.
    279     const char* file() const {
    280       if (_file.valid() && !_file.get().empty()) {
    281         return _file.get().c_str();
    282       } else {
    283         return 0;
    284       }
     71    /// Constructor
     72    explicit DataFormatError(const char *message) {
     73      DataFormatError::message(message);
     74      _line = 0;
    28575    }
    28676
    287     ///\e
     77    /// Constructor
     78    explicit DataFormatError(const std::string &message) {
     79      DataFormatError::message(message);
     80      _line = 0;
     81    }
     82
     83    /// Constructor
     84    DataFormatError(const std::string &file, int line, const char *message) {
     85      DataFormatError::message(message);
     86      DataFormatError::file(file);
     87      DataFormatError::line(line);
     88    }
     89
     90    /// Constructor
     91    DataFormatError(const std::string &file, int line,
     92                    const std::string &message) {
     93      DataFormatError::message(message);
     94      DataFormatError::file(file);
     95      DataFormatError::line(line);
     96    }
     97
     98    /// Virtual destructor
     99    virtual ~DataFormatError() throw() {}
     100
     101    /// Set the line number
     102    void line(int line) { _line = line; }
     103
     104    /// Set the error message
     105    void message(const char *message) {
     106      try {
     107        _message = message;
     108      } catch (...) {}
     109    }
     110
     111    /// Set the error message
     112    void message(const std::string& message) {
     113      try {
     114        _message = message;
     115      } catch (...) {}
     116    }
     117
     118    /// Set the file name
     119    void file(const std::string &file) {
     120      try {
     121        _file = file;
     122      } catch (...) {}
     123    }
     124
     125    /// \brief Returns the line number
     126    ///
     127    /// Returns the line number or zero if it was not specified.
     128    int line() const { return _line; }
     129
     130    /// Returns the error message
     131    const std::string& message() const {
     132      return _message;
     133    }
     134
     135    /// \brief Returns the filename
     136    ///
     137    /// Returns the filename or empty string if the filename was not
     138    /// specified.
     139    const std::string& file() const {
     140      return _file;
     141    }
     142
     143    /// \brief Returns a short error message
     144    ///
     145    /// Returns a short error message which contains the message, the
     146    /// file name and the line number.
    288147    virtual const char* what() const throw() {
    289148      try {
    290         std::ostringstream ostr;
    291         ostr << "lemon:DataFormatError" << ": ";
    292         if (message()) ostr << message();
    293         if( file() || line() != 0 ) {
    294           ostr << " (";
    295           if( file() ) ostr << "in file '" << file() << "'";
    296           if( file() && line() != 0 ) ostr << " ";
    297           if( line() != 0 ) ostr << "at line " << line();
    298           ostr << ")";
     149        _what.clear();
     150        std::ostringstream oss;
     151        oss << "lemon:DataFormatError" << ": ";
     152        oss << message();
     153        if (!file().empty() || line() != 0) {
     154          oss << " (";
     155          if (!file().empty()) oss << "in file '" << file() << "'";
     156          if (!file().empty() && line() != 0) oss << " ";
     157          if (line() != 0) oss << "at line " << line();
     158          oss << ")";
    299159        }
    300         _message_holder.set(ostr.str());
     160        _what = oss.str();
    301161      }
    302162      catch (...) {}
    303       if( _message_holder.valid()) return _message_holder.get().c_str();
    304       return "lemon:DataFormatError";
     163      if (!_what.empty()) return _what.c_str();
     164      else return "lemon:DataFormatError";
    305165    }
    306166
    307     virtual ~DataFormatError() throw() {}
    308   };
    309 
    310   ///\e
    311   class FileOpenError : public IoError {
    312   protected:
    313     ExceptionMember<std::string> _file;
    314 
    315     mutable ExceptionMember<std::string> _message_holder;
    316   public:
    317 
    318     FileOpenError(const FileOpenError &foe) :
    319       IoError(foe), _file(foe._file) {}
    320 
    321     ///\e
    322     explicit FileOpenError(const std::string& fl)
    323       : _file(fl) {}
    324 
    325 
    326     ///\e
    327     void file(const std::string &fl) { _file.set(fl); }
    328 
    329     /// \brief Returns the filename.
    330     ///
    331     /// Returns \e null if the filename was not specified.
    332     const char* file() const {
    333       if (_file.valid() && !_file.get().empty()) {
    334         return _file.get().c_str();
    335       } else {
    336         return 0;
    337       }
    338     }
    339 
    340     ///\e
    341     virtual const char* what() const throw() {
    342       try {
    343         std::ostringstream ostr;
    344         ostr << "lemon::FileOpenError" << ": ";
    345         ostr << "Cannot open file - " << file();
    346         _message_holder.set(ostr.str());
    347       }
    348       catch (...) {}
    349       if( _message_holder.valid()) return _message_holder.get().c_str();
    350       return "lemon::FileOpenError";
    351     }
    352     virtual ~FileOpenError() throw() {}
    353   };
    354 
    355   class IoParameterError : public IoError {
    356   protected:
    357     ExceptionMember<std::string> _message;
    358     ExceptionMember<std::string> _file;
    359 
    360     mutable ExceptionMember<std::string> _message_holder;
    361   public:
    362 
    363     IoParameterError(const IoParameterError &ile) :
    364       IoError(ile), _message(ile._message), _file(ile._file) {}
    365 
    366     ///\e
    367     explicit IoParameterError(const char *the_message)
    368       : _message(the_message) {}
    369 
    370     ///\e
    371     IoParameterError(const char *file_name, const char *the_message)
    372       : _message(the_message), _file(file_name) {}
    373 
    374      ///\e
    375     void message(const std::string& msg) { _message.set(msg); }
    376     ///\e
    377     void file(const std::string &fl) { _file.set(fl); }
    378 
    379      ///\e
    380     const char* message() const {
    381       if (_message.valid()) {
    382         return _message.get().c_str();
    383       } else {
    384         return 0;
    385       }
    386     }
    387 
    388     /// \brief Returns the filename.
    389     ///
    390     /// Returns \c 0 if the filename was not specified.
    391     const char* file() const {
    392       if (_file.valid()) {
    393         return _file.get().c_str();
    394       } else {
    395         return 0;
    396       }
    397     }
    398 
    399     ///\e
    400     virtual const char* what() const throw() {
    401       try {
    402         std::ostringstream ostr;
    403         if (message()) ostr << message();
    404         if (file()) ostr << "(when reading file '" << file() << "')";
    405         _message_holder.set(ostr.str());
    406       }
    407       catch (...) {}
    408       if( _message_holder.valid() ) return _message_holder.get().c_str();
    409       return "lemon:IoParameterError";
    410     }
    411     virtual ~IoParameterError() throw() {}
    412167  };
    413168
    414169  /// @}
  • lemon/lgf_reader.h

    diff --git a/lemon/lgf_reader.h b/lemon/lgf_reader.h
    a b  
    166166        if (it == _map.end()) {
    167167          std::ostringstream msg;
    168168          msg << "Item not found: " << str;
    169           throw DataFormatError(msg.str().c_str());
     169          throw DataFormatError(msg.str());
    170170        }
    171171        return it->second;
    172172      }
     
    859859          if (maps.find(map) != maps.end()) {
    860860            std::ostringstream msg;
    861861            msg << "Multiple occurence of node map: " << map;
    862             throw DataFormatError(msg.str().c_str());
     862            throw DataFormatError(msg.str());
    863863          }
    864864          maps.insert(std::make_pair(map, index));
    865865          ++index;
     
    871871          if (jt == maps.end()) {
    872872            std::ostringstream msg;
    873873            msg << "Map not found in file: " << _node_maps[i].first;
    874             throw DataFormatError(msg.str().c_str());
     874            throw DataFormatError(msg.str());
    875875          }
    876876          map_index[i] = jt->second;
    877877        }
     
    895895          if (!_reader_bits::readToken(line, tokens[i])) {
    896896            std::ostringstream msg;
    897897            msg << "Column not found (" << i + 1 << ")";
    898             throw DataFormatError(msg.str().c_str());
     898            throw DataFormatError(msg.str());
    899899          }
    900900        }
    901901        if (line >> std::ws >> c)
     
    914914          if (it == _node_index.end()) {
    915915            std::ostringstream msg;
    916916            msg << "Node with label not found: " << tokens[label_index];
    917             throw DataFormatError(msg.str().c_str());
     917            throw DataFormatError(msg.str());
    918918          }
    919919          n = it->second;
    920920        }
     
    952952          if (maps.find(map) != maps.end()) {
    953953            std::ostringstream msg;
    954954            msg << "Multiple occurence of arc map: " << map;
    955             throw DataFormatError(msg.str().c_str());
     955            throw DataFormatError(msg.str());
    956956          }
    957957          maps.insert(std::make_pair(map, index));
    958958          ++index;
     
    964964          if (jt == maps.end()) {
    965965            std::ostringstream msg;
    966966            msg << "Map not found in file: " << _arc_maps[i].first;
    967             throw DataFormatError(msg.str().c_str());
     967            throw DataFormatError(msg.str());
    968968          }
    969969          map_index[i] = jt->second;
    970970        }
     
    997997          if (!_reader_bits::readToken(line, tokens[i])) {
    998998            std::ostringstream msg;
    999999            msg << "Column not found (" << i + 1 << ")";
    1000             throw DataFormatError(msg.str().c_str());
     1000            throw DataFormatError(msg.str());
    10011001          }
    10021002        }
    10031003        if (line >> std::ws >> c)
     
    10121012          if (it == _node_index.end()) {
    10131013            std::ostringstream msg;
    10141014            msg << "Item not found: " << source_token;
    1015             throw DataFormatError(msg.str().c_str());
     1015            throw DataFormatError(msg.str());
    10161016          }
    10171017          Node source = it->second;
    10181018
     
    10201020          if (it == _node_index.end()) {
    10211021            std::ostringstream msg;
    10221022            msg << "Item not found: " << target_token;
    1023             throw DataFormatError(msg.str().c_str());
     1023            throw DataFormatError(msg.str());
    10241024          }
    10251025          Node target = it->second;
    10261026
     
    10351035          if (it == _arc_index.end()) {
    10361036            std::ostringstream msg;
    10371037            msg << "Arc with label not found: " << tokens[label_index];
    1038             throw DataFormatError(msg.str().c_str());
     1038            throw DataFormatError(msg.str());
    10391039          }
    10401040          a = it->second;
    10411041        }
     
    10711071          if (it != read_attr.end()) {
    10721072            std::ostringstream msg;
    10731073            msg << "Multiple occurence of attribute " << attr;
    1074             throw DataFormatError(msg.str().c_str());
     1074            throw DataFormatError(msg.str());
    10751075          }
    10761076          read_attr.insert(attr);
    10771077        }
     
    10931093        if (read_attr.find(it->first) == read_attr.end()) {
    10941094          std::ostringstream msg;
    10951095          msg << "Attribute not found in file: " << it->first;
    1096           throw DataFormatError(msg.str().c_str());
     1096          throw DataFormatError(msg.str());
    10971097        }
    10981098      }
    10991099    }
     
    16871687          if (maps.find(map) != maps.end()) {
    16881688            std::ostringstream msg;
    16891689            msg << "Multiple occurence of node map: " << map;
    1690             throw DataFormatError(msg.str().c_str());
     1690            throw DataFormatError(msg.str());
    16911691          }
    16921692          maps.insert(std::make_pair(map, index));
    16931693          ++index;
     
    16991699          if (jt == maps.end()) {
    17001700            std::ostringstream msg;
    17011701            msg << "Map not found in file: " << _node_maps[i].first;
    1702             throw DataFormatError(msg.str().c_str());
     1702            throw DataFormatError(msg.str());
    17031703          }
    17041704          map_index[i] = jt->second;
    17051705        }
     
    17231723          if (!_reader_bits::readToken(line, tokens[i])) {
    17241724            std::ostringstream msg;
    17251725            msg << "Column not found (" << i + 1 << ")";
    1726             throw DataFormatError(msg.str().c_str());
     1726            throw DataFormatError(msg.str());
    17271727          }
    17281728        }
    17291729        if (line >> std::ws >> c)
     
    17421742          if (it == _node_index.end()) {
    17431743            std::ostringstream msg;
    17441744            msg << "Node with label not found: " << tokens[label_index];
    1745             throw DataFormatError(msg.str().c_str());
     1745            throw DataFormatError(msg.str());
    17461746          }
    17471747          n = it->second;
    17481748        }
     
    17801780          if (maps.find(map) != maps.end()) {
    17811781            std::ostringstream msg;
    17821782            msg << "Multiple occurence of edge map: " << map;
    1783             throw DataFormatError(msg.str().c_str());
     1783            throw DataFormatError(msg.str());
    17841784          }
    17851785          maps.insert(std::make_pair(map, index));
    17861786          ++index;
     
    17921792          if (jt == maps.end()) {
    17931793            std::ostringstream msg;
    17941794            msg << "Map not found in file: " << _edge_maps[i].first;
    1795             throw DataFormatError(msg.str().c_str());
     1795            throw DataFormatError(msg.str());
    17961796          }
    17971797          map_index[i] = jt->second;
    17981798        }
     
    18251825          if (!_reader_bits::readToken(line, tokens[i])) {
    18261826            std::ostringstream msg;
    18271827            msg << "Column not found (" << i + 1 << ")";
    1828             throw DataFormatError(msg.str().c_str());
     1828            throw DataFormatError(msg.str());
    18291829          }
    18301830        }
    18311831        if (line >> std::ws >> c)
     
    18401840          if (it == _node_index.end()) {
    18411841            std::ostringstream msg;
    18421842            msg << "Item not found: " << source_token;
    1843             throw DataFormatError(msg.str().c_str());
     1843            throw DataFormatError(msg.str());
    18441844          }
    18451845          Node source = it->second;
    18461846
     
    18481848          if (it == _node_index.end()) {
    18491849            std::ostringstream msg;
    18501850            msg << "Item not found: " << target_token;
    1851             throw DataFormatError(msg.str().c_str());
     1851            throw DataFormatError(msg.str());
    18521852          }
    18531853          Node target = it->second;
    18541854
     
    18631863          if (it == _edge_index.end()) {
    18641864            std::ostringstream msg;
    18651865            msg << "Edge with label not found: " << tokens[label_index];
    1866             throw DataFormatError(msg.str().c_str());
     1866            throw DataFormatError(msg.str());
    18671867          }
    18681868          e = it->second;
    18691869        }
     
    18991899          if (it != read_attr.end()) {
    19001900            std::ostringstream msg;
    19011901            msg << "Multiple occurence of attribute " << attr;
    1902             throw DataFormatError(msg.str().c_str());
     1902            throw DataFormatError(msg.str());
    19031903          }
    19041904          read_attr.insert(attr);
    19051905        }
     
    19211921        if (read_attr.find(it->first) == read_attr.end()) {
    19221922          std::ostringstream msg;
    19231923          msg << "Attribute not found in file: " << it->first;
    1924           throw DataFormatError(msg.str().c_str());
     1924          throw DataFormatError(msg.str());
    19251925        }
    19261926      }
    19271927    }
     
    22412241          if (extra_sections.find(section) != extra_sections.end()) {
    22422242            std::ostringstream msg;
    22432243            msg << "Multiple occurence of section " << section;
    2244             throw DataFormatError(msg.str().c_str());
     2244            throw DataFormatError(msg.str());
    22452245          }
    22462246          Sections::iterator it = _sections.find(section);
    22472247          if (it != _sections.end()) {
     
    22602260        if (extra_sections.find(it->first) == extra_sections.end()) {
    22612261          std::ostringstream os;
    22622262          os << "Cannot find section: " << it->first;
    2263           throw DataFormatError(os.str().c_str());
     2263          throw DataFormatError(os.str());
    22642264        }
    22652265      }
    22662266    }