#ifndef LEARN_AT____LEARN____CONTROLLER_HPP_
#define LEARN_AT____LEARN____CONTROLLER_HPP_

// /home/siemens/bip/examples/sync_lec/learn.bip:71:1
// include package "master" header
#include <learn.hpp>

#include <Atom.hpp>

// User include given in @cpp annotation
#include <utilities.hpp>

#include <learn/AtomIPort__learn__intPort.hpp>


#include <learn/AtomEPort__learn__intPort.hpp>

#include <learn/PV__learn__intPort.hpp>



class AT__learn__Controller : public Atom {
private:
   // internal ports & associated port values
    AtomIPort__learn__intPort &_iport_decl__getSpeedLimit;
    PV__learn__intPort _iport_decl_pv__getSpeedLimit;
    AtomIPort__learn__intPort &_iport_decl__getSpeed;
    PV__learn__intPort _iport_decl_pv__getSpeed;
    AtomIPort__learn__intPort &_iport_decl__brake;
    PV__learn__intPort _iport_decl_pv__brake;
    AtomIPort__learn__intPort &_iport_decl__throttle;
    PV__learn__intPort _iport_decl_pv__throttle;
    AtomIPort__learn__intPort &_iport_decl__noSpeedChange;
    PV__learn__intPort _iport_decl_pv__noSpeedChange;

    // exported ports
    AtomEPort__learn__intPort &_eport_decl__getSpeedLimit;
    AtomEPort__learn__intPort &_eport_decl__getSpeed;
    AtomEPort__learn__intPort &_eport_decl__brake;
    AtomEPort__learn__intPort &_eport_decl__throttle;
    AtomEPort__learn__intPort &_eport_decl__noSpeedChange;
public:
    AT__learn__Controller(const string &name , AtomIPort__learn__intPort &_iport_decl__getSpeedLimit, AtomIPort__learn__intPort &_iport_decl__getSpeed, AtomIPort__learn__intPort &_iport_decl__brake, AtomIPort__learn__intPort &_iport_decl__throttle, AtomIPort__learn__intPort &_iport_decl__noSpeedChange
                             
                             , AtomEPort__learn__intPort &_eport_decl__getSpeedLimit, AtomEPort__learn__intPort &_eport_decl__getSpeed, AtomEPort__learn__intPort &_eport_decl__brake, AtomEPort__learn__intPort &_eport_decl__throttle, AtomEPort__learn__intPort &_eport_decl__noSpeedChange
                             
                             );
    virtual ~AT__learn__Controller();

    virtual BipError& execute(PortValue &portValue);
    virtual BipError& execute(AtomExternalPort &portValue);
    virtual BipError& initialize();
    virtual string toString() const;

protected:
    BipError& update();

    BipError& executeInternalTransitions();
    BipError& checkInvariants();

    const static size_t bvector_size = 3/(8*sizeof(int))+((3%(8*sizeof(int))) > 0 ? 1 : 0);
    int __statesbv[ bvector_size ];

    // component data declarations
    int _id__speed;
    int _id__speedLimit;
    int _id__deltaSpeed;
    int _id__zero;

    // enabledness of transitions
    bool _transguard__1;
    bool _transguard__2;
    bool _transguard__3;
    bool _transguard__4;
    bool _transguard__5;

    // index of the latest executed transition
    int __previous;

    bool atIdle() const;
    bool toIdle();
    bool fromIdle();
    bool atGet() const;
    bool toGet();
    bool fromGet();
    bool atCompare() const;
    bool toCompare();
    bool fromCompare();
};

#endif // LEARN_AT____LEARN____CONTROLLER_HPP_
