Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

Aggregate.h

Go to the documentation of this file.
00001 00002 #ifndef AGGREGATE_H 00003 #define AGGREGATE_H 00004 00005 #include "TupleDescription.h" 00006 #include "Registry.h" 00007 #include "Expression.h" 00008 00009 using namespace Borealis; 00010 00011 class Aggregate { 00012 public: 00013 Aggregate() : _out_size(0) {} 00014 virtual ~Aggregate() {} 00015 00016 class Window { 00017 public: 00018 #ifdef ENABLE_SERIALIZATION 00019 Window() {} 00020 #endif 00021 virtual ~Window() {} 00022 00023 virtual void init() {}; 00024 virtual void incr(const EvalContext& ctxt) throw (EvalException) {}; 00025 virtual void final(char *out_data) {}; 00026 00027 virtual void remove(const EvalContext& ctxt) throw (EvalException) {}; 00028 00029 const ptr<Aggregate> getAggregate() { return _agg; } 00030 void setAggregate(ptr<Aggregate> agg) { 00031 // _agg = &agg; 00032 _agg = agg; 00033 } 00034 00035 #ifdef ENABLE_SERIALIZATION 00036 NMSTL_SERIAL_BASE(Window, long, << _agg); 00037 /* 00038 void freeze(OSerial &out) const { 00039 out << _agg; 00040 } 00041 void unfreeze(ISerial &in) { 00042 in >> _agg; 00043 } 00044 */ 00045 #endif 00046 00047 protected: 00048 unsigned int numArgs() { return _agg->numArgs(); } 00049 Expression& arg(unsigned int index) { return _agg->arg(index); } 00050 00051 private: 00052 //Aggregate *_agg; 00053 ptr<Aggregate> _agg; 00054 }; 00055 00056 typedef ::Registry<Aggregate> Registry; 00057 00058 // Create a new window 00059 virtual Window *openWindow() { return new Window(); }; 00060 00061 // Figure out the output TupleDescription based on args; call 00062 // setTupleDescription 00063 virtual void setup(const ExprContext& ctxt) 00064 throw (AuroraException) {}; 00065 00066 void setArgs(const vector<ptr<Expression> >& args) { _args = args; } 00067 00068 int numOutputFields() const { return _out_fields.size(); } 00069 TupleDescription::Field getOutputField(unsigned int i) const { 00070 ASSERT(i < _out_fields.size()); 00071 return _out_fields[i]; 00072 } 00073 unsigned int getOutputSize() const { return _out_size; } 00074 TupleDescription getOutputTupleDescription() const { 00075 return TupleDescription(_out_fields.begin(), _out_fields.end()); 00076 } 00077 00078 virtual const string as_string() const { 00079 return "Aggregate(out:" + to_string(_out_fields) 00080 + " args:" + to_string(_args) + ")"; 00081 } 00082 00083 public: 00084 static ptr<Aggregate> parse(string expr, const ExprContext& ctxt) 00085 throw (ExprException); 00086 00087 protected: 00088 // Description of aggregate outputs; to be called by subclass 00089 // constructor 00090 void addOutputField(TupleDescription::Field field) { 00091 _out_fields.push_back(field); 00092 _out_size += field.getSize(); 00093 } 00094 00095 void addInt32OutputField( string name = string() ) 00096 { addOutputField( Field<int32>( name )); } 00097 00098 void addInt64OutputField( string name = string() ) 00099 { addOutputField( Field<int64>( name )); } 00100 00101 void addSingleOutputField( string name = string() ) 00102 { addOutputField( Field<single>( name )); } 00103 00104 void addDoubleOutputField( string name = string() ) 00105 { addOutputField( Field<double>( name )); } 00106 00107 void addStringOutputField( unsigned int length ) 00108 { addOutputField( Field<string>( length )); } 00109 00110 void addStringOutputField( string name, unsigned int length ) 00111 { addOutputField( Field<string>( name, length )); } 00112 00113 Expression &arg( unsigned int index ) const 00114 { 00115 ASSERT( index < _args.size() ); 00116 return( *_args[ index ]); 00117 } 00118 00119 unsigned int numArgs() const 00120 { 00121 return( _args.size() ); 00122 } 00123 00124 00125 private: 00126 vector<TupleDescription::Field> _out_fields; 00127 unsigned int _out_size; 00128 00129 vector<ptr<Expression> > _args; 00130 00131 public: 00132 #ifdef ENABLE_SERIALIZATION 00133 NMSTL_SERIAL_BASE(Aggregate, long, << _out_fields << _out_size); // << _args); 00134 /* 00135 void freeze(OSerial &out) const { 00136 out << _out_fields << _out_size; 00137 } 00138 void unfreeze(ISerial &in) { 00139 in >> _out_fields >> _out_size; 00140 } 00141 */ 00142 #endif 00143 00144 }; 00145 00146 #define AURORA_DECLARE_AGGREGATE(ClassName) AURORA_DECLARE_REG_CLASS(Aggregate, ClassName) 00147 #define AURORA_DEFINE_AGGREGATE(ClassName, FuncName) \ 00148 AURORA_DEFINE_REG_CLASS_WITH_KEY(Aggregate, ClassName, FuncName) 00149 00150 #endif

Generated on Fri Nov 12 15:15:20 2004 for Borealis by doxygen 1.3.8