#ifndef _OURTYPES
#define _OURTYPES

#include <string>
#include <map>                          // maintains data about other robots

#include "../../00_nav_library/nav_aria_iface.h"


//* Place your data structure definitions or their header files here *

// global T-variable type that is internaly thread safe template <typename T> class AutoSynchronized { protected: T myVar; ArMutex myMutex; public: AutoSynchronized() : myVar(), myMutex() {} AutoSynchronized(const T& v) : myVar(v), myMutex() {} T getValue() { myMutex.lock(); T v=myVar; myMutex.unlock(); return(v); } void setValue(const T& v) { myMutex.lock(); myVar=v; myMutex.unlock(); } private: // block copying as ArMutex malfunctions if replicated AutoSynchronized(const AutoSynchronized<T>&); void operator=(const AutoSynchronized<T>&); }; template <typename T> class LockSynchronized { protected: T myVar; ArMutex myMutex; public: LockSynchronized() : myVar(), myMutex() {} LockSynchronized(const T& v) : myVar(v), myMutex() {} const T&getValue() const { return(myVar); } T& getValue() { return(myVar); } void setValue(const T& v) { myVar=v; } void lock() { myMutex.lock(); } void unlock() { myMutex.unlock(); } private: // block copying as ArMutex malfunctions if replicated LockSynchronized(const LockSynchronized<T>&); void operator=(const LockSynchronized<T>&); }; // global string variable type that can be used safely in multithreaded environment (if lock is used) class SynchronizedString { protected: std::string myString; ArMutex myMutex; public: SynchronizedString() : myString(), myMutex() {} SynchronizedString(const char* s) : myString(s), myMutex() {} SynchronizedString(const std::string& s) : myString(s), myMutex() {} const std::string& getString() const { return(myString); } std::string& getString() { return(myString); } void setString(const std::string& s) { myString=s; } void lock() { myMutex.lock(); } void unlock() { myMutex.unlock(); } private: // block copying as ArMutex malfunctions if replicated SynchronizedString(const SynchronizedString&); void operator=(const SynchronizedString&); }; // you may want to replace the structures defined below with ARIA's strctures and classes class RobotState { // this is needed for tracking the list of robots - sort of ARIA::ArPosWithTime public: bool located; // true if translation is known, false if still undetermined ArPose translation; // maping of robot internal coordiantes to ours ArPose position; // last known position (x,y,theta) in our coordinates long int timestamp; // time of last known position // Note: ArMutex malfunctions when used with assignment operator public: RobotState() : located(false), translation(), position(), timestamp(0) {} RobotState(bool is_located, const ArPose& cur_translation, const ArPose& cur_position, unsigned long cur_time) : located(is_located), translation(cur_translation), position(cur_position), timestamp(cur_time) {} }; #endif