INET Framework for OMNeT++/OMNEST
inet::power::EnergySourceBase Class Reference

#include <EnergySourceBase.h>

Inheritance diagram for inet::power::EnergySourceBase:
inet::power::IEnergySource inet::power::CcEnergySourceBase inet::power::EnergyStorageBase inet::power::EpEnergySourceBase inet::power::CcEnergyStorageBase inet::power::EpEnergyStorageBase inet::power::SimpleCcBattery inet::power::IdealEpEnergyStorage inet::power::SimpleEpEnergyStorage

Public Member Functions

virtual int getNumEnergyConsumers () const override
 Returns the number of energy consumers in the range [0, +infinity). More...
 
virtual const IEnergyConsumergetEnergyConsumer (int index) const override
 Returns the energy consumer for the provided index. More...
 
virtual void addEnergyConsumer (const IEnergyConsumer *energyConsumer) override
 Adds a new energy consumer to the energy source. More...
 
virtual void removeEnergyConsumer (const IEnergyConsumer *energyConsumer) override
 Removes a previously added energy consumer from this energy source. More...
 
- Public Member Functions inherited from inet::power::IEnergySource
virtual ~IEnergySource ()
 

Protected Attributes

std::vector< const IEnergyConsumer * > energyConsumers
 

Member Function Documentation

void inet::power::EnergySourceBase::addEnergyConsumer ( const IEnergyConsumer energyConsumer)
overridevirtual

Adds a new energy consumer to the energy source.

The energyConsumer parameter must not be nullptr.

Implements inet::power::IEnergySource.

Reimplemented in inet::power::CcEnergySourceBase, inet::power::EpEnergySourceBase, inet::power::CcEnergyStorageBase, and inet::power::EpEnergyStorageBase.

Referenced by inet::power::CcEnergySourceBase::addEnergyConsumer(), and inet::power::EpEnergySourceBase::addEnergyConsumer().

31 {
32  energyConsumers.push_back(energyConsumer);
33 }
std::vector< const IEnergyConsumer * > energyConsumers
Definition: EnergySourceBase.h:30
const IEnergyConsumer * inet::power::EnergySourceBase::getEnergyConsumer ( int  index) const
overridevirtual

Returns the energy consumer for the provided index.

This functions throws an exception if the index is out of range, and it never returns nullptr.

Implements inet::power::IEnergySource.

26 {
27  return energyConsumers[index];
28 }
std::vector< const IEnergyConsumer * > energyConsumers
Definition: EnergySourceBase.h:30
virtual int inet::power::EnergySourceBase::getNumEnergyConsumers ( ) const
inlineoverridevirtual

Returns the number of energy consumers in the range [0, +infinity).

Implements inet::power::IEnergySource.

33 { return energyConsumers.size(); }
std::vector< const IEnergyConsumer * > energyConsumers
Definition: EnergySourceBase.h:30
void inet::power::EnergySourceBase::removeEnergyConsumer ( const IEnergyConsumer energyConsumer)
overridevirtual

Removes a previously added energy consumer from this energy source.

This functions throws an exception if the consumer is not found.

Implements inet::power::IEnergySource.

Reimplemented in inet::power::CcEnergySourceBase, inet::power::EpEnergySourceBase, inet::power::CcEnergyStorageBase, and inet::power::EpEnergyStorageBase.

Referenced by inet::power::CcEnergySourceBase::removeEnergyConsumer(), and inet::power::EpEnergySourceBase::removeEnergyConsumer().

36 {
37  auto it = std::find(energyConsumers.begin(), energyConsumers.end(), energyConsumer);
38  if (it == energyConsumers.end())
39  throw cRuntimeError("Energy consumer not found");
40  else
41  energyConsumers.erase(it);
42 }
std::vector< const IEnergyConsumer * > energyConsumers
Definition: EnergySourceBase.h:30
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48

Member Data Documentation


The documentation for this class was generated from the following files: