PackerBase.hh 891 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
#ifndef PackerBase_HH
#define PackerBase_HH

#include <iostream>
#include <cstdint>
#include <cmath>
#include <cassert>

#include "utilities.cc"

dauncey's avatar
dauncey committed
11 12
template <class Uint>
class PackerBaseUint {
13
public:
dauncey's avatar
dauncey committed
14
  PackerBaseUint() : fDatum(0) {
15 16
  }
 
dauncey's avatar
dauncey committed
17
  ~PackerBaseUint() {
18 19
  }
  
dauncey's avatar
dauncey committed
20
  void datum(Uint d) {
21 22 23
    fDatum=d;
  }

dauncey's avatar
dauncey committed
24
  Uint datum() const {
25 26 27 28
    return fDatum;
  }

  virtual std::string name() const {
dauncey's avatar
dauncey committed
29 30 31
    std::ostringstream sout;
    sout << "PackerBaseUint" << sizeof(Uint);
    return sout.str();
32 33 34 35 36 37 38 39 40 41
  }
  
  virtual void pack(uint32_t d) {
    assert(false);
  }

  virtual uint32_t unpack() const {
    assert(false);
  }
  void print() const {
dauncey's avatar
dauncey committed
42
    std::cout << "PackerBaseUint::print()  Datum = "
43 44 45 46 47 48
	      << printDec(fDatum) << " = "
	      << printHex(fDatum) << " = "
	      << printBin(fDatum) << std::endl;
  }

protected:
dauncey's avatar
dauncey committed
49
  Uint fDatum;
50 51
};

dauncey's avatar
dauncey committed
52 53
typedef PackerBaseUint<uint8_t> PackerBase;

54
#endif