FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
StreamIOError.h
1 /*
2  This software is Copyright by the Board of Trustees of Michigan
3  State University (c) Copyright 2005.
4 
5  You may use this software under the terms of the GNU public license
6  (GPL). The terms of this license are described at:
7 
8  http://www.gnu.org/licenses/gpl.txt
9 
10  Author:
11  Ron Fox
12  NSCL
13  Michigan State University
14  East Lansing, MI 48824-1321
15 */
16 
17 // Class: CStreamIOError //ANSI C++
18 //
19 // Encapsulates error conditions on an ios
20 // derived object as an exception.
21 // Note that objects of this type carry with them
22 // a reference to the stream on which the condition
23 // was detected. This reference may become invalid
24 // if the exception propagates up the call stack
25 // far enough to cause the stream to be destroyed.
26 // I would have ideally liked to carry a copy of the stream,
27 // however far too few ios derived classes are derived
28 // from ***_withassign to make this practical.
29 //
30 // Author:
31 // Ron Fox
32 // NSCL
33 // Michigan State University
34 // East Lansing, MI 48824-1321
35 // mailto: fox@nscl.msu.edu
36 //
37 // (c) Copyright NSCL 1999, All rights reserved StreamIOError.h
38 //
39 
40 #ifndef STREAMIOERROR_H //Required for current class
41 #define STREAMIOERROR_H
42 
43  //Required for base classes
44 #ifndef EXCEPTION_H
45 #include "Exception.h"
46 #endif
47 
48 #include <string>
49 
50 
51 class CStreamIOError : public CException
52 {
53 public: // Data types;
54  typedef enum _IoStreamConditions {
55  EndFile,
56  BadSet,
57  FailSet
58  } IoStreamConditions;
59 
60 private:
61  IoStreamConditions m_eReason; //Reason for the throw
62  std::ios& m_rStream; //Reference to stream <may be invalid>
63  char m_sReasonText[1000]; // Reason for failure built here.
64  static const char** m_svErrorMessages; //Pointer to error message table.
65 
66 
67 public:
68 
69  CStreamIOError(IoStreamConditions eReason,
70  const char* pDoing, std::ios& rStream) :
71  CException(pDoing),
72  m_eReason(eReason),
73  m_rStream(rStream)
74  {}
75 
76  CStreamIOError(IoStreamConditions eReason,
77  const std::string& rDoing, std::ios& rStream) :
78  CException(rDoing),
79  m_eReason(eReason),
80  m_rStream(rStream)
81  {}
82 
83 
84  ~ CStreamIOError ( ) // Destructor
85  { }
86 
87  //Copy constructor
88 
89  CStreamIOError (const CStreamIOError& aCStreamIOError ) :
90  CException (aCStreamIOError),
91  m_eReason(aCStreamIOError.m_eReason),
92  m_rStream(aCStreamIOError.m_rStream)
93  {
94  }
95 
96  // Operator= Assignment Operator
97  // The existence of reference member data inhibits this
98  // operator:
99  //
100 private:
101  CStreamIOError& operator= (const CStreamIOError& aCStreamIOError);
102 public:
103 
104  //Operator== Equality Operator
105  // We'll have to compare references by comparing their
106  // addresses:
107  //
108  int operator== (const CStreamIOError& aCStreamIOError) const {
109  return ( CException::operator==(aCStreamIOError) &&
110  (m_eReason == aCStreamIOError.m_eReason) &&
111  (&m_rStream == &aCStreamIOError.m_rStream)
112  );
113  }
114  int operator!=(const CStreamIOError& aCStreamIOError) const {
115  return !(this->operator==(aCStreamIOError));
116  }
117 
118 // Selectors:
119 
120 public:
121 
122  IoStreamConditions getReason() const
123  {
124  return m_eReason;
125  }
126  std::ios& getStream()
127  {
128  return m_rStream;
129  }
130 
131  const char* getErrorMessage() const; // Return just error msg.
132 
133 
134 // Mutators:
135 
136 protected:
137 
138  void setReason (const IoStreamConditions am_eReason)
139  {
140  m_eReason = am_eReason;
141  }
142 
143 public:
144 
145  virtual const char* ReasonText () const;
146  virtual int ReasonCode () const;
147 
148 
149 };
150 
151 #endif
Definition: StreamIOError.h:51
Definition: Exception.h:41