home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / NDR / src / NDR.h < prev   
Encoding:
C/C++ Source or Header  |  1991-06-14  |  3.8 KB  |  117 lines

  1. #ifndef RJS_NDR_CLASS_H
  2. #define RJS_NDR_CLASS_H
  3.  
  4. #include <iostream.h>
  5. #include <RJS/Transport.h>
  6.  
  7. class RJS_NDR_send;
  8. class RJS_NDR_receive;
  9.  
  10. typedef unsigned short NDR_range;
  11. typedef char *NDR_data;
  12.  
  13. class RJS_XNDR {
  14. public:
  15.     virtual void to_internal(RJS_NDR_receive &)=0;
  16.     virtual void to_external(RJS_NDR_send &)=0;
  17. };
  18.  
  19.  
  20. class RJS_NDR {
  21. public:
  22.     enum NDR_endian {
  23.         NdrBigEndian=0,
  24.         NdrLittleEndian=1
  25.     };
  26.      enum NDR_character {
  27.         NdrASCII=0,
  28.         NdrEBCDIC=1
  29.     };
  30.     enum NDR_floating {
  31.         NdrIEEE=0,
  32.         NdrVAX=1,
  33.         NdrCray=2,
  34.          NdrIBM=3
  35.     };
  36.         virtual void reset()=0;
  37.         virtual void reset(char *, int count)=0;
  38.         virtual char *raw_data()=0;
  39.         virtual NDR_range raw_length()=0;
  40.         static NDR_endian    local_endian()    { return ndr_endian; }
  41.         static NDR_character local_character() { return ndr_char;   }
  42.         static NDR_floating  local_floating()  { return ndr_float;  }
  43. private:
  44.         static NDR_endian    ndr_endian;
  45.         static NDR_character    ndr_char;
  46.         static NDR_floating    ndr_float;
  47. };
  48.  
  49. class RJS_NDR_send : public RJS_NDR {
  50. // friends!
  51.     friend RJS_Transport &operator<<(RJS_Transport &tr, RJS_NDR_send &ndr);
  52.     friend ostream &operator<<(ostream &, RJS_NDR_send &);
  53.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,RJS_XNDR &);
  54.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,RJS_NDR_send &);
  55.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,char);
  56.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,unsigned char);
  57.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,short);
  58.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,unsigned short); 
  59.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,int);
  60.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,unsigned int);
  61.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,float);
  62.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,double);
  63.  
  64.     friend RJS_NDR_send &operator<<(RJS_NDR_send &,const char*);
  65. public:
  66.     RJS_NDR_send();
  67.     RJS_NDR_send &insert(char *, int count); 
  68.     void reset();                    // reset for adding
  69.     void init(char *buffer,int size);        // reset for adding
  70.     char *raw_data() { return (char *) start_data; }
  71.     NDR_range raw_length() { return (end_data-start_data); }
  72. private:
  73.     // internal data    
  74.     NDR_data  start_data;    // start of data
  75.     NDR_data  end_data;    // pointer to end of NDR data
  76.     NDR_data  end_alloc;    // end of allocated data
  77. };
  78.  
  79. class RJS_NDR_receive : public RJS_NDR {
  80. //
  81. // friends!
  82.     friend RJS_Transport &operator>>(RJS_Transport &tr, RJS_NDR_receive &ndr);
  83.     friend ostream &operator<<(ostream &, RJS_NDR_receive &);
  84.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,RJS_XNDR &);
  85.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,RJS_NDR_receive &);
  86.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,char &);
  87.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,unsigned char &);
  88.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,short &);
  89.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,unsigned short &); 
  90.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,int &);
  91.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,unsigned int &);
  92.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,float &);
  93.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,double &);
  94.     friend RJS_NDR_receive &operator>>(RJS_NDR_receive &,char*);
  95. public:
  96.     RJS_NDR_receive() { start_data=NULL; outptr=NULL; end_data=NULL; }
  97.     RJS_NDR_receive &extract(char *, int &count); 
  98.     void reset();                    // reset
  99.     void init(char *buffer,int size);
  100.     char *raw_data()       { return start_data; }
  101.     NDR_range raw_length() { return (end_data-start_data); }    
  102.     NDR_endian    remote_endian()    { return rem_endian; }
  103.     NDR_character remote_character() { return rem_char;   }
  104.     NDR_floating  remote_floating()  { return rem_float;  }
  105.  
  106. private:
  107.     // internal data    
  108.     NDR_endian    rem_endian;    // remote representation
  109.     NDR_character    rem_char;
  110.     NDR_floating    rem_float;
  111.     NDR_data  start_data;    // start of data
  112.     NDR_data  outptr;    // pointer to current extract
  113.     NDR_data  end_data;    // end of the NDR
  114. };
  115.  
  116. #endif
  117.