#include "Utilities\commondefs.hpp" #include #define __INPUT_RAWEVENT_CPP_ #include "RawEvent.hpp" using namespace Input; // Whenever using to NOP, never use a reference to the shared_ptr (&). // Doing so makes it possible to replace the content of NOP with something else. // Instead, always make a copy of the shared_ptr to NOP. RAW_EVENT_DECL Input::RawEvent::shared_ptr Input::RawEvent::NOP(new Input::RawEvent()); RAW_EVENT_DECL RawEvent::RawEvent() :valid(true) // by default, each time we call the constructor, we're creating a valid instance ,source("") ,evtype("") ,eventTime() // call default constructor, initializing the timestamp to this instant in time, using the local clock. ,timeSource("") { // Event time always takes the current time - do this first to be as accurate as possible eventTime = chron::high_resolution_clock::now() ; BOOST_LOG_TRIVIAL(trace) << CLASS_METHOD << " called"; // Note in particular that the timestamp default constructor will be called, initializing the timestamp // to this instant in time, using the local clock. This is exactly what we want. parameter_strings parms; initialize(parms); // pick up the defaults } RAW_EVENT_DECL RawEvent::RawEvent(const parameter_strings & parms) { // Event time always takes the current time - do this first to be as accurate as possible eventTime = chron::high_resolution_clock::now() ; BOOST_LOG_TRIVIAL(trace) << CLASS_METHOD << " parameter_strings called"; initialize(parms); } RAW_EVENT_DECL void RawEvent::initialize(const parameter_strings & parms) { // Note in particular that the timestamp default constructor will be called, initializing the timestamp // to this instant in time, using the local clock. This is exactly what we want. valid = SET_PARM_OR_DFLT(parms, "valid", bool,true) ; source = SET_PARM_OR_DFLT(parms, "source", std::string,"") ; evtype = SET_PARM_OR_DFLT(parms, "evtype", std::string,"") ; timeSource = SET_PARM_OR_DFLT(parms, "timeSource", std::string, source) ; // default time source to same as event source } RAW_EVENT_DECL bool RawEvent::operator==(RawEvent const& cmp) const { // does a fast compare if possible, then does value compares if that doesn't work return (this == &cmp) || ( (valid == cmp.valid) && (source == cmp.source) && (evtype == cmp.evtype) && (eventTime ==cmp.eventTime) && (timeSource == cmp.timeSource) ); } RAW_EVENT_DECL RawEvent::~RawEvent(void) { // The static NOP instance above gets deleted at some arbitrary time when the program // ends, which means the log message below, if enabled, might print after Boost.Log // has already been reclaimed, causing an exception. // BOOST_LOG_TRIVIAL(trace) << CLASS_METHOD << " at " << this << " called"; } template RAW_EVENT_DECL void RawEvent::serialize(Archive &ar, const unsigned int version) { ar & valid; ar & source; ar & evtype; ar & boost::serialization::make_binary_object(&eventTime, sizeof(eventTime)); ar & timeSource; } #ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable : 4244) #endif #include #include #include #include BOOST_CLASS_EXPORT_IMPLEMENT(Input::RawEvent); BOOST_CLASS_IMPLEMENTATION(Input::RawEvent,boost::serialization::object_serializable); BOOST_CLASS_TRACKING(Input::RawEvent,boost::serialization::track_never); // without the explicit instantiations below, the program will // fail to link for lack of instantiantiation of the above function // note: the following failed to fix link errors for vc 7.0 ! template RAW_EVENT_DECL void RawEvent::serialize( boost::archive::text_iarchive & ar, const unsigned int file_version ); template RAW_EVENT_DECL void RawEvent::serialize( boost::archive::text_oarchive & ar, const unsigned int file_version ); template RAW_EVENT_DECL void RawEvent::serialize( boost::archive::binary_iarchive & ar, const unsigned int file_version ); template RAW_EVENT_DECL void RawEvent::serialize( boost::archive::binary_oarchive & ar, const unsigned int file_version ); #ifdef BOOST_MSVC # pragma warning(pop) #endif