cresultrecorder.h

00001 //==========================================================================
00002 //  CRESULTRECORDER.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //  Author: Andras Varga
00007 //
00008 //==========================================================================
00009 
00010 /*--------------------------------------------------------------*
00011   Copyright (C) 1992-2008 Andras Varga
00012   Copyright (C) 2006-2008 OpenSim Ltd.
00013 
00014   This file is distributed WITHOUT ANY WARRANTY. See the file
00015   `license' for details on this and other legal matters.
00016 *--------------------------------------------------------------*/
00017 
00018 #ifndef __CRESULTRECORDER_H
00019 #define __CRESULTRECORDER_H
00020 
00021 #include "cresultlistener.h"
00022 #include "ccomponent.h"
00023 #include "onstartup.h"
00024 #include "globals.h"
00025 
00026 NAMESPACE_BEGIN
00027 
00028 class cResultRecorder;
00029 class cProperty;
00030 
00040 #define Register_ResultRecorder(NAME, CLASSNAME) \
00041   static cResultRecorder *__FILEUNIQUENAME__() {return new CLASSNAME;} \
00042   EXECUTE_ON_STARTUP(resultRecorders.getInstance()->add(new cResultRecorderDescriptor(NAME,__FILEUNIQUENAME__));)
00043 
00044 
00051 class SIM_API cResultRecorder : public cResultListener
00052 {
00053     private:
00054         cComponent *component;
00055         const char *statisticName;
00056         const char *recordingMode;
00057         cProperty *attrsProperty;  // property to take result attributes from (normally @statistic[statisticName])
00058         opp_string_map *manualAttrs; // if non-null, overrides attrsProperty
00059 
00060     protected:
00061         virtual opp_string_map getStatisticAttributes(); // order: manualAttrs, then attrsProperty
00062         virtual opp_string_map getStatisticAttributesFrom(cProperty *property);
00063         virtual void tweakTitle(opp_string& title);
00064 
00065     public:
00073         virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs=NULL);
00074         virtual ~cResultRecorder() {delete manualAttrs;}
00075         virtual cComponent *getComponent() const {return component;}
00076         virtual const char *getStatisticName() const {return statisticName;}
00077         virtual const char *getRecordingMode() const {return recordingMode;}
00078         virtual std::string getResultName() const {return std::string(getStatisticName())+":"+getRecordingMode();}
00079 };
00080 
00088 class SIM_API cNumericResultRecorder : public cResultRecorder
00089 {
00090     protected:
00091         // all receiveSignal() methods either throw error or delegate here.
00092         virtual void collect(simtime_t_cref t, double value) = 0;
00093     public:
00094         virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b);
00095         virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l);
00096         virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l);
00097         virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d);
00098         virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v);
00099         virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s);
00100         virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj);
00101 };
00102 
00108 class SIM_API cResultRecorderDescriptor : public cNoncopyableOwnedObject
00109 {
00110   private:
00111     cResultRecorder *(*creatorfunc)();
00112 
00113   public:
00117     cResultRecorderDescriptor(const char *name, cResultRecorder *(*f)());
00118 
00123     cResultRecorder *create() const  {return creatorfunc();}
00124 
00129     static cResultRecorderDescriptor *find(const char *name);
00130 
00134     static cResultRecorderDescriptor *get(const char *name);
00135 };
00136 
00137 NAMESPACE_END
00138 
00139 #endif
00140 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3