Changeset 256 in Sophya for trunk/SophyaLib/BaseTools


Ignore:
Timestamp:
Apr 23, 1999, 2:38:18 PM (26 years ago)
Author:
ansari
Message:

reorg exc, ppersist tags...

Location:
trunk/SophyaLib/BaseTools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/SysTools.o.list

    r255 r256  
    11ctimer.o
    22md5.o
     3ndatablock.o
    34pdlmgr.o
    45peidainit.o
  • trunk/SophyaLib/BaseTools/pexceptions.h

    r251 r256  
    44
    55#include "machdefs.h"
    6 //#include <exception>
    76#include <string>
    87
     
    1211
    1312  // Ancestor for PError and PException
    14   class PThrowable { // : public exception {
    15         public:
    16                 explicit PThrowable(const string& m) : msg(m) {}
    17                 virtual ~PThrowable() { }
    18                 virtual string const& Msg() const  {return msg;}
    19         private:
    20                 string msg;
     13  // It has a message, and an id to give more
     14  // information on the exception.
     15  class PThrowable {
     16  public:
     17    explicit PThrowable(const string& m, int ident=0)
     18      : msg(m), id(ident) {}
     19    virtual ~PThrowable() { }
     20    virtual string const& Msg() const  {return msg;}
     21  private:
     22    string msg;
     23    int    id;
    2124  };
    22 
     25 
    2326  // A PError is a serious logic error. Usually not caught...
    2427  class PError : public PThrowable {
    25         public:
    26         explicit PError(const string& m) : PThrowable(m) {}
     28  public:
     29    explicit PError(const string& m, int id=0) : PThrowable(m,id) {}
    2730  };
    2831 
    2932  // A PException is not as serious... Can be caught.
    3033  class PException : public PThrowable {
    31         public:
    32         explicit PException(const string& m) : PThrowable(m) {}
     34  public:
     35    explicit PException(const string& m, int id=0) : PThrowable(m,id) {}
     36  };
     37 
     38  // Errors
     39  // Memory allocation failure
     40  class AllocationError : public PError {
     41  public:
     42    explicit AllocationError(const string& m, int id=0) : PError(m,id) {}
     43  };
     44 
     45  // Null pointer error
     46  class NullPtrError : public PError {
     47  public:
     48    explicit NullPtrError(const string& m, int id=0) : PError(m,id) {}
     49  };
     50 
     51  // Size mismatch between objects
     52  class SzMismatchError : public PError {
     53  public:
     54    explicit SzMismatchError(const string& m, int id=0) : PError(m,id) {}
     55  };
     56 
     57  // Out of bounds for array, matrix, etc.
     58  class RangeCheckError : public PError {
     59  public:
     60    explicit RangeCheckError(const string& m, int id=0) : PError(m,id) {}
     61  };
     62 
     63  // Invalid parameter to method/constructor...
     64  class ParmError : public PError {
     65  public:
     66    explicit ParmError(const string& m, int id=0) : PError(m,id) {}
     67  };
     68 
     69  // Calling a forbidden method, trying a forbidden operation
     70  class ForbiddenError : public PError {
     71  public:
     72    explicit ForbiddenError(const string& m, int id=0) : PError(m,id) {}
     73  };
     74 
     75  // ASSERT macro failure. The message is the assertion...
     76  class AssertionFailedError : public PError {
     77  public:
     78    explicit AssertionFailedError(const string& m, int id=0) : PError(m,id) {}
     79  };
     80 
     81  // Standard exceptions
     82  //
     83  // PException
     84  //   IOExc
     85  //     FileFormatExc
     86  //   TypeMismatchExc
     87  //   DuplicateIdExc
     88  //   NotFoundExc
     89  //   MathExc
     90  //     SingMatxExc
     91 
     92  // generic IO Exception
     93  class IOExc : public PException {
     94  public:
     95    explicit IOExc(const string& m, int id=0) : PException(m,id) {}
    3396  };
    3497
    35   // Errors
    36   class AllocationError : public PError {
    37     public:
    38         explicit AllocationError(const string& m) : PError(m) {}
     98  // Bad type -> keep ?
     99  class TypeMismatchExc : public PException {
     100  public:
     101    explicit TypeMismatchExc(const string& m, int id=0) : PException(m,id) {}
    39102  };
    40103 
    41   class NullPtrError : public PError {
    42     public:
    43         explicit NullPtrError(const string& m) : PError(m) {}
     104  class MathExc : public PException {
     105  public:
     106    explicit MathExc(const string& m, int id=0) : PException(m,id) {}
     107  };
     108 
     109  class DuplicateIdExc : public PException {
     110  public:
     111    explicit DuplicateIdExc(const string& m, int id=0) : PException(m,id) {}
     112  };
     113 
     114  class NotFoundExc : public PException {
     115  public:
     116    explicit NotFoundExc(const string& m, int id=0) : PException(m,id) {}
     117  };
     118 
     119  class CaughtSignalExc : public PException {
     120  public:
     121    explicit CaughtSignalExc(const string& m, int id=0) : PException(m,id) {}
    44122  };
    45123
    46   class SzMismatchError : public PError {
    47     public:
    48         explicit SzMismatchError(const string& m) : PError(m) {}
    49   };
    50 
    51   class RangeCheckError : public PError {
    52     public:
    53         explicit RangeCheckError(const string& m) : PError(m) {}
    54   };
    55 
    56   class ParmError : public PError {
    57     public:
    58         explicit ParmError(const string& m) : PError(m) {}
    59   };
    60 
    61   class ForbiddenError : public PError {
    62     public:
    63         explicit ForbiddenError(const string& m) : PError(m) {}
    64   };
    65 
    66   class AssertionFailedError : public PError {
    67     public:
    68         explicit AssertionFailedError(const string& m) : PError(m) {}
    69   };
    70 
    71   // Standard exceptions
    72   class TypeMismatchExc : public PException {
    73     public:
    74         explicit TypeMismatchExc(const string& m) : PException(m) {}
    75   };
    76 
    77   class FileExc : public PException {
    78     public:
    79         explicit FileExc(const string& m) : PException(m) {}
    80   };
    81 
    82   class FileFormatExc : public PException {
    83     public:
    84         explicit FileFormatExc(const string& m) : PException(m) {}
    85   };
    86 
    87   class DuplicateIdExc : public PException {
    88     public:
    89         explicit DuplicateIdExc(const string& m) : PException(m) {}
    90   };
    91 
    92   class NotFoundExc : public PException {
    93     public:
    94         explicit NotFoundExc(const string& m) : PException(m) {}
    95   };
    96 
    97   class CaughtSignalExc : public PException {
    98     public:
    99         explicit CaughtSignalExc(const string& m) : PException(m) {}
     124  // Bad file format
     125  class FileFormatExc : public IOExc {
     126  public:
     127    explicit FileFormatExc(const string& m, int id=0) : IOExc(m,id) {}
    100128  };
    101129 
    102   class SingMatrixExc : public PException {
    103     public:
    104         explicit SingMatrixExc(const string& m) : PException(m) {}
     130  class SingMatrixExc : public MathExc {
     131  public:
     132    explicit SingMatrixExc(const string& m, int id=0) : MathExc(m,id) {}
    105133  };
    106134 
    107 
     135 
    108136}
    109137
     
    149177#define inconsistentErr  ParmError("")
    150178#define sizeMismatchErr  SzMismatchError("")
    151 #define fileErr          FileExc("")
     179#define fileErr          IOExc("")
    152180#define nullPtrErr       NullPtrError("")
    153181#define singMatxErr      SingMatrixExc("")
  • trunk/SophyaLib/BaseTools/ppersist.cc

    r251 r256  
    150150  s.GetRawByte(ppstype);
    151151  if (ppstype != PInPersist::PPS_OBJECT) {
    152     throw TypeMismatchExc("PPersist::Read : not an object in flow");
     152    throw FileFormatExc("PPersist::Read : not an object in flow");
    153153  }
    154154 
     
    157157  s.GetRawU8(classId);
    158158  if (classId != PIOPersist::Hash(typeid(*this).name())) {
    159     throw TypeMismatchExc("PPersist::Read : not the same object type");
     159    throw FileFormatExc("PPersist::Read : not the same object type");
    160160  }
    161161
     
    302302
    303303
     304int
     305PInPersist::NbTags()
     306{
     307  return tags.size();
     308}
     309
    304310bool
    305311PInPersist::GotoTag(string const& name)
     
    312318  return(true);
    313319}
     320
     321bool
     322PInPersist::GotoTagNum(int itag)
     323{
     324  if (itag<0 || itag >= tags.size()) return false;
     325  map<string, int_8>::iterator i = tags.begin();
     326  for (int j=0; j<itag; j++) i++;
     327  s->seekg((*i).second);
     328  return(true);
     329}
     330
    314331
    315332//++
     
    419436  GetRawByte(ppstype);
    420437  if (ppstype != PPS_SIMPLE + datasz)
    421     throw TypeMismatchExc("PInPersist::CheckTag   bad type in ppersist file");
     438    throw FileFormatExc("PInPersist::CheckTag   bad type in ppersist file");
    422439}
    423440
     
    430447  if (sz <= 0x7fff) {
    431448    if (ppstype != PPS_SIMPLE_ARRAY + datasz)
    432       throw TypeMismatchExc("PInPersist::CheckTag   bad type in ppersist file");
     449      throw FileFormatExc("PInPersist::CheckTag   bad type in ppersist file");
    433450    int_2 ff;
    434451    GetRawI2(ff); filesz=ff;
    435452  } else if (sz <= 0x7fffffff) {
    436453    if (ppstype != PPS_SIMPLE_ARRAY4 + datasz)
    437       throw TypeMismatchExc("PInPersist::CheckTag   bad type in ppersist file");
     454      throw FileFormatExc("PInPersist::CheckTag   bad type in ppersist file");
    438455    int_4 ff;
    439456    GetRawI4(ff); filesz=ff;
    440457  } else {
    441458    if (ppstype != PPS_SIMPLE_ARRAY8 + datasz)
    442       throw TypeMismatchExc("PInPersist::CheckTag   bad type in ppersist file");
     459      throw FileFormatExc("PInPersist::CheckTag   bad type in ppersist file");
    443460    uint_8 ff;
    444461    GetRawU8(ff); filesz=ff;
    445462  }
    446463  if (filesz != sz)
    447     throw TypeMismatchExc("PInPersist::CheckTag   bad array size in ppersist file");
     464    throw FileFormatExc("PInPersist::CheckTag   bad array size in ppersist file");
    448465}
    449466
     
    646663  GetRawByte(ppstype);
    647664  if (ppstype != PPS_LINE)
    648     throw TypeMismatchExc("PInPersist::GetLine   bad type in ppersist file");
     665    throw FileFormatExc("PInPersist::GetLine   bad type in ppersist file");
    649666  s->getline(ptr, len, '\n');
    650667}
     
    656673  GetRawByte(ppstype);
    657674  if (ppstype != PPS_STRING)
    658     throw TypeMismatchExc("PInPersist::GetLine   bad type in ppersist file");
     675    throw FileFormatExc("PInPersist::GetLine   bad type in ppersist file");
    659676  int_2 len;
    660677  GetRawI2(len);
     
    673690  GetRawByte(ppstype);
    674691  if (ppstype != PPS_OBJECT && ppstype != PPS_REFERENCE && ppstype != PPS_NULL) {
    675     throw TypeMismatchExc("PInPersist::ReadObject : not an object in flow");
     692    throw FileFormatExc("PInPersist::ReadObject : not an object in flow");
    676693  }
    677694
  • trunk/SophyaLib/BaseTools/ppersist.h

    r252 r256  
    107107
    108108    bool   GotoTag(string const& name);
     109    int    NbTags();
     110    bool   GotoTagNum(int itag);  // 0..NbTags-1
    109111
    110112    void   GetByte (char& c);
Note: See TracChangeset for help on using the changeset viewer.