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

Last change on this file since 14399 was 14003, checked in by tbretz, 12 years ago
Replaced some 'const char*' with a const-refernce to a std::string
File size: 3.0 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//! Store the name in fName and the format in fFormat. Initializes fTime
23//! to an invalid time.
24//!
25//! @param name
26//! Name given to the event
27//!
28//! @param fmt
29//! If the event has data attached (like arguments of commands)
30//! the format can be given here. How the format string is defined
31//! is defined within the dim libarary. It is used in console
32//! and shell access to properly format the data sent with the event
33//!
34//! <B>From the dim manual:</B>
35//! The format parameter specifies the contents of the structure in
36//! the form T:N[;T:N]*[;T] where T is the item type: (I)nteger,
37//! (C)haracter, (L)ong, (S)hort, (F)loat, (D)ouble, and N is the
38//! number of such items. The type alone at the end means all
39//! following items are of the same type. Example: "I:3;F:2;C" means
40//! 3 Integers, 2 Floats and Characters until the end. The format
41//! parameter is used for communicating between different platforms.
42//!
43//
44Event::Event(const string &name, const string &fmt) :
45 fName(name), fFormat(fmt), fTime(Time::none), fQoS(0)
46{
47}
48
49// --------------------------------------------------------------------------
50//
51//! Copies the all contents from an EventImp. Note, that also the data
52//! area is copied. If the name contains a slash ('/') everything before
53//! the slash is removed.
54//!
55//! @param evt
56//! Reference to an object of type EventImp.
57//
58Event::Event(const EventImp &evt) : EventImp(evt),
59fName(evt.GetName()), fFormat(evt.GetFormat()),
60fData(evt.GetText(), evt.GetText()+evt.GetSize()), fTime(evt.GetTime()),
61fQoS(evt.GetQoS())
62{
63 const size_t pos = fName.find_first_of('/');
64 if (pos!=string::npos)
65 fName = fName.substr(pos+1);
66}
67
68// --------------------------------------------------------------------------
69//
70//! Copies the all contents from an EventImp. fData is initialized from the
71//! given memory. If the name contains a slash ('/') everything before
72//! the slash is removed.
73//!
74//! @param evt
75//! Reference to an object of type EventImp.
76//!
77//! @param ptr
78//! Pointer to the memory region to be copied.
79//!
80//! @param siz
81//! Size of the memory region to be copied.
82//
83Event::Event(const EventImp &evt, const char *ptr, size_t siz) : EventImp(evt),
84fName(evt.GetName()), fFormat(evt.GetFormat()),
85fData(ptr, ptr+siz), fTime(evt.GetTime()), fQoS(evt.GetQoS())
86{
87 const size_t pos = fName.find_first_of('/');
88 if (pos!=string::npos)
89 fName = fName.substr(pos+1);
90}
Note: See TracBrowser for help on using the repository browser.