BatteryState.h

00001 /* -*- mode:c++ -*- ********************************************************
00002  * Energy Framework for Omnet++, version 0.9
00003  *
00004  * Author:  Laura Marie Feeney
00005  *
00006  * Copyright 2009 Swedish Institute of Computer Science.
00007  *
00008  * This software is provided `as is' and without any express or implied
00009  * warranties, including, but not limited to, the implied warranties of
00010  * merchantability and fitness for a particular purpose.
00011  *
00012  ***************************************************************************/
00013 
00014 #ifndef BATTERYSTATE_H
00015 #define BATTERYSTATE_H
00016 
00017 #include <omnetpp.h>
00018 #include "BaseUtility.h"
00019 #include <sstream>
00020 
00031 class BatteryState : public BBItem
00032 {
00033   BBITEM_METAINFO(BBItem);
00034 
00035 protected:
00037   double nominal;
00039   double absolute;
00040 
00041 public:
00042 
00047   BatteryState(double n=-1) :
00048     BBItem(), nominal(n)
00049   {};
00050 
00052   double getRel() const {
00053     return absolute/nominal;
00054   }
00055 
00057   double getAbs() const {
00058     return absolute;
00059   }
00060 
00062   void set(double s) {
00063     absolute = s;
00064   }
00065 
00067   std::string info() const {
00068     std::ostringstream ost;
00069     ost << " battery at "<<  (absolute/nominal) * 100 <<"%";
00070     return ost.str();
00071   }
00072 };
00073 
00074 #endif