TimeManager.h 2.46 KB
#ifndef TIMEMANAGER_H
#define TIMEMANAGER_H

#include <ctime>

#include "../Common/Singleton.h"
#include "../Application/Application.h"
#include "../Common/TREPSTypes.h"
#include "../DataRecord/DataRecord.h"
#include "../XMLManager/XMLManager.h"
#include "TimePattern.h"

#define TREPS_TIMES_XSD "times.xsd"

using namespace TREPS::Common;
using namespace TREPS::DataRecord;
using namespace TREPS::Application;
using namespace TREPS::XMLManager;

namespace TREPS
{
	namespace TimeManager
	{
		class TimeManagerClass : public SingletonClass<TimeManagerClass>
		{
				friend class SingletonClass<TimeManagerClass>;

			public :
				TimeManagerClass(void);

				~TimeManagerClass(void);

				//load time formats file
				bool init(const char *file_path);

				//get pattern from time id
				string getPatternFromTimeId(const char *timeId);

				//retrieve time id from pattern
				string getTimeIdFromPattern(const char *pattern);

				//get time format from time id
				t_TimeFormat getFormatFromTimeId(const char *timeId);

				//retrieve time id from time format and pattern
				string getTimeIdFromFormatAndPattern(t_TimeFormat format, const char *pattern);

				//set current pattern
				bool setCurrentPattern(const char *pattern);

				//get current pattern used
				int getCurrentPatternSize(void);

				//try to detect the pattern
				string detectPattern(const char *value);

				//load from pattern
				bool from_PATTERN(const char *time, t_Time &t, bool verbose = true);

				//load from timestamp
				bool from_TIMESTAMP(time_t tt, t_Time &t);

				//load from decimal time
				bool from_DECIMAL(double d, t_Time &t);

				//laod from epoch time (CDF)
				bool from_EPOCH(double e, t_Time &t);

				//load from tt200 time (CDF)
				bool from_TT2000(long long tt, t_Time &t);

				//laod from ddtime (CDPP/DDServer)
				bool from_DDTIME(const char *dd_time, t_Time &t);

				//write to pattern
				string to_PATTERN(t_Time t);

				//write to timestamp
				time_t to_TIMESTAMP(t_Time t);

				//write to decimal time
				double to_DECIMAL(t_Time t);

				//write to epoch (CDF)
				double to_EPOCH(t_Time t);

				//write to tt2000 (CDF)
				long long int to_TT2000(t_Time t);

				//Write to ddtime (CDPP/DDServer)
				string to_DDTIME(t_Time t);

				//write to string
				string to_string(t_Time t, t_TimeFormat format, const char *pattern);

			private:

				ApplicationClass *app;

				XMLManagerClass *loader;

				TimePatternClass *crtPattern;

				NodeList getTimeNodeList(void);
		};
	}
}

#endif