Commit d53b81bfb480befd1a62942aa088ca857ff1d26c

Authored by knodlseder
1 parent 0562bb34

add type conversion extension

pyext/GEventAtom.i
... ... @@ -52,30 +52,33 @@ public:
52 52 GEventAtom(const GEventAtom& atom);
53 53 virtual ~GEventAtom(void);
54 54  
55   - // Event access methods
  55 + // Pure virtual methods
  56 + virtual void clear(void) = 0;
  57 + virtual GEvent* clone(void) const = 0;
  58 + virtual double size(void) const { return 1.0; }
56 59 virtual const GInstDir& dir(void) const = 0;
57 60 virtual const GEnergy& energy(void) const = 0;
58 61 virtual const GTime& time(void) const = 0;
59   - double counts(void) const { return 1.0; }
60   - double error(void) const { return 0.0; }
  62 + virtual double counts(void) const { return 1.0; }
  63 + virtual double error(void) const { return 0.0; }
61 64  
62 65 // Other methods
63   - virtual void clear(void) = 0;
64   - virtual double size(void) const { return 1.0; }
65   - virtual GEventAtom* clone(void) const = 0;
66   - virtual bool isatom(void) const { return true; }
67   - virtual bool isbin(void) const { return false; }
  66 + bool isatom(void) const { return true; }
  67 + bool isbin(void) const { return false; }
68 68 };
69 69  
70 70  
71 71 /***********************************************************************//**
72 72 * @brief GEventAtom class extension
  73 + *
  74 + * The GEventAtom method allow for type conversion.
73 75 ***************************************************************************/
74 76 %extend GEventAtom {
75   - /*
76   - char *__str__() {
77   - static std::string result = self->print();
78   - return ((char*)result.c_str());
  77 + GEventAtom(const GEvent& event) {
  78 + if (!events.isatom())
  79 + throw GException::bad_type("GEventAtom(GEvent&)",
  80 + "GEvent not an event atom");
  81 + GEventAtom* atom = new GEventAtom((GEventAtom&)event);
  82 + return atom;
79 83 }
80   - */
81 84 };
... ...
pyext/GEventBin.i
... ... @@ -54,30 +54,33 @@ public:
54 54 GEventBin(const GEventBin& bin);
55 55 virtual ~GEventBin(void);
56 56  
57   - // Event access methods
  57 + // Pure virtual methods
  58 + virtual void clear(void) = 0;
  59 + virtual GEvent* clone(void) const = 0;
  60 + virtual double size(void) const = 0;
58 61 virtual const GInstDir& dir(void) const = 0;
59 62 virtual const GEnergy& energy(void) const = 0;
60 63 virtual const GTime& time(void) const = 0;
61 64 virtual double counts(void) const = 0;
62   - virtual double error(void) const;
  65 + virtual double error(void) const = 0;
63 66  
64 67 // Other methods
65   - virtual void clear(void) = 0;
66   - virtual double size(void) const = 0;
67   - virtual GEventBin* clone(void) const = 0;
68   - bool isatom(void) const { return false; }
69   - bool isbin(void) const { return true; }
  68 + bool isatom(void) const { return false; }
  69 + bool isbin(void) const { return true; }
70 70 };
71 71  
72 72  
73 73 /***********************************************************************//**
74 74 * @brief GEventBin class extension
  75 + *
  76 + * The GEventBin method allow for type conversion.
75 77 ***************************************************************************/
76 78 %extend GEventBin {
77   - /*
78   - char *__str__() {
79   - static std::string result = self->print();
80   - return ((char*)result.c_str());
  79 + GEventBin(const GEvent& event) {
  80 + if (!event.isbin())
  81 + throw GException::bad_type("GEventBin(GEvent&)",
  82 + "GEvent not an event bin");
  83 + GEventBin* bin = new GEventBin((GEventBin&)event);
  84 + return bin;
81 85 }
82   - */
83 86 };
... ...