// =======================================================================================
// F2_port.h
// Time-stamp: <2004-02-24 19:21:40 aknoblau>
// Definition of ports for communication between components
// programmed in April 2001 by Andreas Knoblauch
// Department of Neural Information Processing
// University of Ulm, Germany
// Version 1.0 alpha
// last documented change: April 23, 2001
// =======================================================================================
// types/classes/interfaces:
// TPort
// TMPort_s, TMPort_b, TMPort_pb
// TMPort_qs,TMPort_qb,TMPort_qpb
// TMPort_a
// ---------------------------------------------------------------------------------------
// global objects:
// ---------------------------------------------------------------------------------------
// related modules:
// ---------------------------------------------------------------------------------------
// notes:
// ---------------------------------------------------------------------------------------
// history:
// Version 1.0 alpha programmed on April 23, 2001 by Andreas Knoblauch
// ---------------------------------------------------------------------------------------
// bugs:
// ---------------------------------------------------------------------------------------
// 2 do: - TComponent als Feld eines Ports
// - eventuell (nicht so wichtig): topographie in TPort integrieren
// - fuer packed ports: bitInfo und Zugriffe a la setBit() an F2_types.h anpassen
// i.e. F2_types stellt schon die bitInfo<..> Objekte und die setBit- Zugriffe
// zur Verfuegung!
// =======================================================================================
#ifndef F2_port_H
#define F2_port_H
#include
#include "F2_switches.h"
#include "F2_types.h"
#include "F2_layout.h"
// **************************************************************************************************************************
// **************************************************************************************************************************
/**
* TMPort
* base template class for queued ports for communication between system components
* note: for increasing transmission delay, queue is decremented(!), not incremented!!
*
* @short base template class for queued ports for communication between system components
* @author Andreas Knoblauch
* @version 1.0 alpha,
* last change: April 23, 2001
*/
template
class TMPort {
// **************************************************************************************************************************
public:
typedef enum { DIRECTION_IN , // value for direction: TMPort is used as input buffer (InPort) read by the owning TComponent
DIRECTION_OUT, // value for direction: TMPort is used as output buffer (OutPort) written by owning TComponent
DIRECTION_BI // value for direction: TMPort is used as input and ouput buffer
} TDirection;
typedef enum { TYPE_GRADUAL, // value for type: data field is gradual numerical type
TYPE_BOOL, // value for type: data field is (unpacked) boolean
TYPE_PACKEDBOOL // value for type: data field is packed boolean
} TType;
string name; // id of TMPort
const TDirection direction; // data transfer direction of the TMPort
const TType type; // type of TMPort (simple, bool or packed bool)
TLayout *layout; // reference to a layout
const int N; // number of data units (unqueued)
const int dataN; // size of (unqueued) data in TNum units; differs from N for packed ports
const int qN; // length of queue for delays
int qPos; // current position in the queue, updated (decremented!!) by step()
TNum **qData; // queued numerical data, access via data[delay][idx]
TNum *data; // pointer to current position in qData, i.e. data = qData[qPos], updated by step()
// constructors/destructors
TMPort(string name_arg, TLayout* layout_arg, TDirection dir_arg, TType type_arg, int dataN_arg, int qN_arg);
TMPort(string name_arg, TLayout* layout_arg, TDirection dir_arg, TType type_arg, int dataN_arg, int qN_arg, TNum **qData_arg);
~TMPort();
// create/uncreate methods (to easily create and delete descendants)
static TMPort* create(string type_arg, string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg);
static TMPort* create(TType type_arg, string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg);
static TMPort* create(string type_arg, string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg, TNum **qData_arg);
static TMPort* create(TType type_arg, string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg, TNum **qData_arg);
static TMPort* create_gradual (string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg);
static TMPort* create_gradual (string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg, TNum **qData_arg);
static TMPort* create_bool (string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg);
static TMPort* create_bool (string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg, TNum **qData_arg);
static TMPort* create_packedbool (string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg);
static TMPort* create_packedbool (string name_arg, TLayout* layout_arg, int qN_arg, TDirection dir_arg, TNum **qData_arg);
static void uncreate (TMPort* p);
static void uncreate_gradual (TMPort* p);
static void uncreate_bool (TMPort* p);
static void uncreate_packedbool(TMPort* p);
// static port buffer methods
static const int portBufferLen=5;
#if GNU==1
static TMPort* portBuffer[];
#else
static TMPort* portBuffer[portBufferLen];
#endif
static TMPort**getPortBuffer(TMPort* port);
static TMPort**getPortBuffer(TMPort* port1,TMPort* port2);
static TMPort**getPortBuffer(TMPort* port1,TMPort* port2,TMPort* port3);
static TMPort**getPortBuffer(TMPort* port1,TMPort* port2,TMPort* port3,TMPort* port4);
static TMPort**getPortBuffer(TMPort* port1,TMPort* port2,TMPort* port3,TMPort* port4,TMPort* port5);
// methods
inline void init(); // initialize port (i.e. reset all queue data to 0)
inline void step(); // resets data and decrements qPos/data after read-out (for InPorts), see implementation
inline void dec_qPos(); // as step(), but only decrements qPos/data
void outputState(ostream& os); // output of all fields of the object
void outputState(ostream& os, int complete); // if complete==0 then only output of the most important fields
private:
int referencedFlag; // set if qData is referenced, so it must not be deleted in case of
int qPos_last; // next value for qPos=0 when decrementing in step()
TNum *data_last; // next value for data=qData[0] when decrementing in step()
};
// **************************************************************************************************************************
// **************************************************************************************************************************
/**
* TMgPort
* port template for queued gradual numerical data
* template is instantiated with a integer or float type TNum
*
* @short port template for queued gradual numerical data
* @author Andreas Knoblauch
* @version 1.0 alpha,
* last change: April 23, 2001
*/
template
class TMgPort : public TMPort {
// **************************************************************************************************************************
public:
TMgPort(string name_arg, TLayout* layout_arg, int qN_arg, typename TMgPort::TDirection dir_arg); // unreferenced constructor
TMgPort(string name_arg, TLayout* layout_arg, int qN_arg, typename TMgPort::TDirection dir_arg, TNum **qData_arg); // referenced constructor
~TMgPort(); // destructor
inline void set(int idx, TNum val); // sets data[idx] to val, direct access via the public data may be faster!
inline void set(unsigned int offset, int idx, TNum val); // sets qData[(qPos-offset)mod qN][idx] to val, note 0<=offset
class TMbPort : public TMPort {
// **************************************************************************************************************************
public:
TMbPort(string name_arg, TLayout* layout_arg, int qN_arg, typename TMbPort::TDirection dir_arg); // unreferenced constructor
TMbPort(string name_arg, TLayout* layout_arg, int qN_arg, typename TMbPort::TDirection dir_arg, TNum **qData_arg); // referenced constructor
~TMbPort(); // destructor
inline void set(int idx, TNum val); // sets data[idx] to val, direct access via the public data may be faster!
inline void set(unsigned int offset, int idx, TNum val); // sets qData[(qPos-offset)mod qN][idx] to val, note 0<=offset
class TMpPort : public TMPort {
// **************************************************************************************************************************
public:
static const TMBitInfo bitInfo; // information about type TNum
TMpPort(string name_arg, TLayout* layout_arg, int qN_arg, typename TMpPort::TDirection dir_arg); // unreferenced constructor
TMpPort(string name_arg, TLayout* layout_arg, int qN_arg, typename TMpPort::TDirection dir_arg, TNum **qData_arg); // referenced constructor
~TMpPort(); // destructor
inline void set(int idx, TNum val); // sets bit idx of data to val, direct access via public data may be faster!
inline void set(unsigned int offset, int idx, TNum val); // sets bit idx of qData[(qPos-offset)mod qN] to val, note 0<=offset slower)
void setbit_not_inline(int idx); // only for tests: same as setbit(), but without inline declaration
inline void setbit_borst(int idx); // only for tests: same as setbit(), but implemented by the pope of informatics, Marcus Borst!!
};
// include inline methods
#define INLINE 1
#include "F2_port.cpp"
#undef INLINE
#endif /* F2_port_H */
| Generated by: aknoblau on synfire on Sat May 1 14:32:16 2004, using kdoc 2.0a54. |