Added some includes
[h316.git] / pc-tools / ldc2 / src / tape_block.hh
index 9f162df471d7b629ad397440a6f6e844c2b94109..64f13fd1ba0920831b55992e54612cbdc36f169f 100644 (file)
@@ -1,5 +1,24 @@
-#ifndef TAPE_BLOCK_H
-#define TAPE_BLOCK_H
+/******************************************************************************
+ * 
+ * LDC2 source code
+ *
+ * $Date: 2007/12/23 15:25:11 $
+ * $Author: hachti $
+ *
+ * $Log: tape_block.hh,v $
+ * Revision 2.1  2007/12/23 15:25:11  hachti
+ * *** empty log message ***
+ *
+ * Revision 2.0  2007-03-26 01:00:40  hachti
+ * *** empty log message ***
+ *
+ *
+ ******************************************************************************/
+#ifndef TAPE_BLOCK_HH
+#define TAPE_BLOCK_HH
+
+using namespace std;
 
 /*!
  *\brief Tape data block base class.
  * That may be some kind of data block or a end of tape mark.
  */
 class tape_block{
-
+  
 public: // types
-
-  /*!
-   *\brief Initialisation state.
-   */
-  typedef enum {
-    TBS_OK,          //!< Block successfully initialised
-    TBS_EOF_LEGAL,   //!< Legal EOF while initialising
-    TBS_EOF_ILLEGAL, //!< Illegal EOF while initialising
-    TBS_CHECKSUM,    //!< Checksum error 
-    TBS_IOERR,       //!< I/O-Error while reading
-    TBS_DEFAULT      //!< Block not initialised.
-  } tb_state_t;
-
+  
   /*!
    * Tape block types.
    */
   typedef enum {
     TBT_DATA=0x10,   //!< Data block
     TBT_EOT,         //!< End of tape block
-    TBT_DISCARD      //!< Invalid block, check block_type
+    TBT_BROKEN,      //!< A broken block
   } tb_type_t;
-
-public: // methods
-
-  static tape_block * 
-  gen_from_fd(int  fd,
-             void(*input_start)(void *)=0,
-             void (*input_stop)(void *)=0,
-             void * start_stop_arg=0
-             );
   
+  /*!
+   *\brief Local base class for exceptions.
+   */
+  class exception {
+  protected:
+    exception();
+  public:
+    virtual ~exception();
+    tape_block * get_block();
+  protected:
+    tape_block * m_broken_block;
+  };
+  
+  /*!
+   *\brief Checksum error exception.
+   */
+  class checksum_error_exception
+    : public exception {
+  public:
+    checksum_error_exception(tape_block * block);
+  };
+  
+  /*!
+   *\brief EOF while reading block exception.
+   */
+  class eof_illegal_exception
+    : public exception {
+  public:
+    eof_illegal_exception(tape_block * block);
+  };
+  
+  /*!
+   *\brief EOF after reading block exception.
+   */
+  class eof_legal_exception
+    : public exception {
+  public:
+    eof_legal_exception(int bytes_consumed);
+    int get_consumed();
+  private:
+    int bytes_consumed;
+    tape_block * get_block();
+  };
+  
+  /*!
+   *\brief IO error exception.
+   */
+  class io_error_exception
+    : exception {
+  public:
+    io_error_exception();
+  private:
+    tape_block * get_block();
+  };
+  
+public: // methods
   virtual ~tape_block();
-  tb_state_t get_state();
-  int get_raw_size();
-  unsigned char * get_raw_data();
+  
+  tape_block(tape_block &);
+  void operator=(tape_block &);
+  
   virtual int get_type();
   virtual int get_subtype();
+  virtual vector<string> get_description();
+  int get_raw_size();
+  int get_discarded_bytes();
+  unsigned char * get_raw_data();
+  virtual int dump_to_fd(int fd);
+  virtual bool is_endblock();
+  virtual vector<string> get_exported_symbols();
+  virtual vector<string> get_called_symbols();
+  virtual vector<string> dump_contents();
+  virtual bool has_known_type();
 
-protected: // methods
-  tape_block(tape_block &);
-
-private: // methods
-
-private:   // methods
+  static tape_block * gen_from_fd(int  fd,
+                                 void(*input_start)(void *)=0,
+                                 void (*input_stop)(void *)=0,
+                                 void * start_stop_arg=0
+                                 );
+  
+protected:   // methods
   tape_block();
+  string get_typestring();
+  
+private:   // methods
   tape_block (int  fd_p,
              void(*input_start)(void *)=0,
              void (*input_stop)(void *)=0,
              void * start_stop_arg=0
              );
+  
   int init_words(void);
   int test_checksum(); 
-
+  
 protected: // members
   int block_type;             //!< Type of this block.
-  tb_state_t init_state;      //!< Initialisation state.
-  int data_read;              //!< Total data consumption during intialisation.
+  bool m_has_known_type;      //!< Block is of a documented type.
+  int discarded_bytes;        //!< Amount of bytes discarded before beginning.
   unsigned char * raw_data;   //!< Raw block data in bytes.
   int raw_size;               //!< Size of the raw data.
   unsigned short * word_data; //!< Data organized in machine words.
   int word_size;              //!< Size of the blocks in machine words.
-
-}; // tape_block
-
+  int poolsize;               //!< Amount of data malloc'ed 
+}; // class tape_block
 
 #endif