DirectChannel.h 2.55 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#ifndef CLASSIC_DirectChannel_HH
#define CLASSIC_DirectChannel_HH

// ------------------------------------------------------------------------
// $RCSfile: DirectChannel.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: DirectChannel
//
// ------------------------------------------------------------------------
// Class category: Channels
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:35 $
// $Author: fci $
//
// ------------------------------------------------------------------------

#include "Channels/Channel.h"


// Class DirectChannel
// ------------------------------------------------------------------------
/// Direct access to a [b]double[/b] variable.
//  Class DirectChannel allows direct access to a [b]double[/b] variable.

class DirectChannel: public Channel {

public:

    /// Constructor.
    //  The constructed channel gives read/write access to the variable
    //  [b]value[/b].  The variable [b]value[/b] must not be destroyed as
    //  long as this channel is active.
    explicit DirectChannel(double &value);

    DirectChannel(const DirectChannel &);
    virtual ~DirectChannel();

    /// Duplicate the channel.
    virtual DirectChannel *clone() const;

    /// Store into channel.
    //  If the channel can be written,
    //  store [b]value[/b] into it and return true,
    //  otherwise return false.
    virtual bool set(double);

    /// Fetch from channel.
    //  If the channel can be read, set [b]value[/b] and return true,
    //  otherwise return false.
    virtual bool get(double &) const;

private:

    // Not implemented.
    DirectChannel();
    const DirectChannel &operator=(const DirectChannel &);

    // The address of the variable to be read or written.
    double &reference;
};


inline DirectChannel::DirectChannel(double &value):
    reference(value)
{}


inline DirectChannel::DirectChannel(const DirectChannel &rhs):
75
    Channel(),
gsell's avatar
gsell committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    reference(rhs.reference)
{}


inline DirectChannel::~DirectChannel()
{}


inline DirectChannel *DirectChannel::clone() const {
    return new DirectChannel(*this);
}


inline bool DirectChannel::set(double value) {
    reference = value;
    return true;
}


inline bool DirectChannel::get(double &value) const {
    value = reference;
    return true;
}


#endif // CLASSIC_DirectChannel_HH