source: trunk/FACT++/src/Event.cc@ 13452

Last change on this file since 13452 was 10183, checked in by tbretz, 14 years ago
New import.
File size: 4.3 KB
Line 
1// **************************************************************************
2/** @class Event
3
4@brief Concerete implementation of an EventImp stroring name, format, data and time
5
6This is the implementation of an event which can be posted to a state
7machine, hosting all the data itself. In addition to the base class
8it has storage for name, format, the data and a time stamp.
9
10*/
11// **************************************************************************
12#include "Event.h"
13
14#include <iostream>
15
16#include "Time.h"
17
18using namespace std;
19
20// --------------------------------------------------------------------------
21//
22//! Propagate the targetstate to the base class EventImp and store the
23//! name in fName and the format in fFormat. Initializes fTime to
24//! an invalid time.
25//!
26//! @param targetstate
27//! Target state to be propagated to the base class constructor
28//!
29//! @param name
30//! Name given to the event
31//!
32//! @param fmt
33//! If the event has data attached (like arguments of commands)
34//! the format can be given here. How the format string is defined
35//! is defined within the dim libarary. It is used in console
36//! and shell access to properly format the data sent with the event
37//!
38//! <B>From the dim manual:</B>
39//! The format parameter specifies the contents of the structure in
40//! the form T:N[;T:N]*[;T] where T is the item type: (I)nteger,
41//! (C)haracter, (L)ong, (S)hort, (F)loat, (D)ouble, and N is the
42//! number of such items. The type alone at the end means all
43//! following items are of the same type. Example: "I:3;F:2;C" means
44//! 3 Integers, 2 Floats and Characters until the end. The format
45//! parameter is used for communicating between different platforms.
46//!
47//
48Event::Event(int targetstate, const char *name, const char *fmt) : EventImp(targetstate),
49 fName(name), fFormat(fmt), fTime(Time::none)
50{
51}
52
53// --------------------------------------------------------------------------
54//
55//! Store the name in fName and the format in fFormat. Initializes fTime
56//! to an invalid time.
57//!
58//! @param name
59//! Name given to the event
60//!
61//! @param fmt
62//! If the event has data attached (like arguments of commands)
63//! the format can be given here. How the format string is defined
64//! is defined within the dim libarary. It is used in console
65//! and shell access to properly format the data sent with the event
66//!
67//! <B>From the dim manual:</B>
68//! The format parameter specifies the contents of the structure in
69//! the form T:N[;T:N]*[;T] where T is the item type: (I)nteger,
70//! (C)haracter, (L)ong, (S)hort, (F)loat, (D)ouble, and N is the
71//! number of such items. The type alone at the end means all
72//! following items are of the same type. Example: "I:3;F:2;C" means
73//! 3 Integers, 2 Floats and Characters until the end. The format
74//! parameter is used for communicating between different platforms.
75//!
76//
77Event::Event(const string &name, const char *fmt) :
78 fName(name), fFormat(fmt), fTime(Time::none)
79{
80}
81
82// --------------------------------------------------------------------------
83//
84//! Copies the all contents from an EventImp. Note, that also the data
85//! area is copied. If the name contains a slash ('/') everything before
86//! the slash is removed.
87//!
88//! @param evt
89//! Reference to an object of type EventImp.
90//
91Event::Event(const EventImp &evt) : EventImp(evt),
92fName(evt.GetName()), fFormat(evt.GetFormat()),
93fData(evt.GetText(), evt.GetText()+evt.GetSize()), fTime(evt.GetTime())
94{
95 const size_t pos = fName.find_first_of('/');
96 if (pos!=string::npos)
97 fName = fName.substr(pos+1);
98}
99
100// --------------------------------------------------------------------------
101//
102//! Copies the all contents from an EventImp. fData is initialized from the
103//! given memory. If the name contains a slash ('/') everything before
104//! the slash is removed.
105//!
106//! @param evt
107//! Reference to an object of type EventImp.
108//!
109//! @param ptr
110//! Pointer to the memory region to be copied.
111//!
112//! @param siz
113//! Size of the memory region to be copied.
114//
115Event::Event(const EventImp &evt, const char *ptr, size_t siz) : EventImp(evt),
116fName(evt.GetName()), fFormat(evt.GetFormat()),
117fData(ptr, ptr+siz)
118{
119 const size_t pos = fName.find_first_of('/');
120 if (pos!=string::npos)
121 fName = fName.substr(pos+1);
122}
Note: See TracBrowser for help on using the repository browser.