PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
DeviceState.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/devices/DeviceState.h
4// Purpose: Manages states of devices for use in the primary event loop.
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __DEVICESTATE_H__
28#define __DEVICESTATE_H__
29
30#include <iostream>
31#include "PDevice.h"
32#include "PEvent.h"
33
34using std::ostream;
35using std::cout;
36
37// This is a hypothetical 'state' of a device, which can be tested by a real device
38// to see if it is true about that device.
39
56
57
64
65
66//This is the generic DeviceState base class. It is a way to describe a set
67//of states of a device could be in, and then test against the actual state
68//of the device.
69// Subclasses include value state (tests for whether a device has a certain value',
70// IntervalState (tests whether a device's interface value lies within some 1-dimensional region,
71// and RegionState (tests whether a device's interface value lies within a 2-d region (think mouse location).
72//
73
75{
76public:
77 DeviceState(DeviceTest test, int interfaced, PDevice * device, PEBL_DEVICE_TYPE pdt);
78 virtual ~DeviceState();
79
80 virtual int GetInterface() const;
81 virtual int GetState(int iface) const;
82 virtual int TestDevice() const;
86 //Overload of the << operator
87 friend std::ostream & operator <<(ostream & out, const DeviceState & device );
88
89
90protected:
91
92 virtual std::ostream & SendToStream(std::ostream & out)const;
93
97 //, a button on a button-box, or a key on the keyboard.
100
103
104
105 PEBL_DEVICE_TYPE mPDT; //This keeps track of the ultimate device. For
106 //events, this will be different from mDevice, which will be
107 // an eventqueue.
108};
109
110
111//Determine whether device has a particular value
112//Here, mValue
114{
115public:
116 ValueState(int value, DeviceTest test, int interfaced, PDevice * device, PEBL_DEVICE_TYPE pdt);
117 virtual ~ValueState();
118 virtual int TestDevice() const;
119
120protected:
121 virtual std::ostream &SendToStream(std::ostream & out) const;
122private:
123 int mValue;
124};
125
126//Determine whether device has a particular value in a range
128{
129public:
131 IntervalState(int low, int high, DeviceTest test, int interfaced, PDevice * device, PEBL_DEVICE_TYPE pdt);
132 virtual ~IntervalState();
133 virtual int TestDevice() const;
134protected:
135 std::ostream &SendToStream(std::ostream & out) const;
136
137
138private:
139 int mLow;
140 int mHigh;
141
142};
143
144//Determine whether device has a particular value in a 2D range
146{
147public:
148 RegionState(int lowx, int highx, int lowy, int highy, DeviceTest test, int interfaced, PDevice * device, PEBL_DEVICE_TYPE pdt);
149 ~RegionState();
150 virtual int TestDevice()const;
151protected:
152 virtual std::ostream &SendToStream(std::ostream & out) const;
153
154private:
155 int mLowX;
156 int mHighX;
157
158 int mLowY;
159 int mHighY;
160
161};
162
163#endif
164
DeviceTestType
Definition DeviceState.h:59
@ DTT_REGIONSTATE
Definition DeviceState.h:62
@ DTT_INTERVALSTATE
Definition DeviceState.h:61
@ DTT_VALUESTATE
Definition DeviceState.h:60
DeviceTest
Definition DeviceState.h:41
@ DT_NOT_OUTSIDE
Definition DeviceState.h:49
@ DT_INSIDE
Definition DeviceState.h:48
@ DT_NOT_EQUAL
Definition DeviceState.h:42
@ DT_ON_EDGE
Definition DeviceState.h:52
@ DT_LESS_THAN_OR_EQUAL
Definition DeviceState.h:45
@ DT_TRUE
Definition DeviceState.h:53
@ DT_LESS_THAN
Definition DeviceState.h:44
@ DT_OUTSIDE
Definition DeviceState.h:50
@ DT_FALSE
Definition DeviceState.h:54
@ DT_GREATER_THAN_OR_EQUAL
Definition DeviceState.h:47
@ DT_NOT_INSIDE
Definition DeviceState.h:51
@ DT_EQUAL
Definition DeviceState.h:43
@ DT_GREATER_THAN
Definition DeviceState.h:46
PEBL_DEVICE_TYPE
Definition PDevice.h:40
friend std::ostream & operator<<(ostream &out, const DeviceState &device)
DeviceTest mDeviceTest
virtual int GetState(int iface) const
PDevice * GetEventQueue()
int mInterface
This is different from the value or values that an interface can take on.
Definition DeviceState.h:99
PEBL_DEVICE_TYPE mPDT
PDevice * mDevice
virtual std::ostream & SendToStream(std::ostream &out) const
PDevice * GetDevice()
Definition DeviceState.h:83
virtual PEBL_DEVICE_TYPE GetDeviceType()
Definition DeviceState.h:85
virtual int GetInterface() const
virtual ~DeviceState()
virtual int TestDevice() const
virtual int TestDevice() const
std::ostream & SendToStream(std::ostream &out) const
virtual ~IntervalState()
virtual int TestDevice() const
virtual std::ostream & SendToStream(std::ostream &out) const
virtual ~ValueState()
virtual std::ostream & SendToStream(std::ostream &out) const
virtual int TestDevice() const