1 #ifndef TableSAXReader_h
2 #define TableSAXReader_h
8 #include <libxml/tree.h>
9 #include <libxml/parser.h>
10 #include <libxml/parserInternals.h>
23 return (v < 0.0) ? v : -v;
36 std::ostringstream oss;
39 if (iter != aSet.end())
42 while (iter != aSet.end())
43 oss <<
"," << *iter++;
57 std::set<T>
SetAndSet(
const std::set<T>& s1,
const std::set<T>& s2) {
59 typename std::set<T>::iterator iter1_s, iter2_s;
60 for (iter1_s = s1.begin(); iter1_s != s1.end(); iter1_s++) {
61 if ((iter2_s = s2.find(*iter1_s)) != s2.end())
62 result.insert(*iter1_s);
71 const std::vector<asdm::ScanRow *>&
scans;
89 int64_t currentScanStartTime, currentScanEndTime;
90 int64_t rowStartTime, rowEndTime;
92 currentScanStartTime = (*iter)->getStartTime().get();
93 currentScanEndTime = (*iter)->getEndTime().get();
95 rowStartTime = row->getTimeInterval().getStart().get();
96 rowEndTime = rowStartTime + row->getTimeInterval().getDuration().get();
97 if (
std::max(currentScanStartTime, rowStartTime) <
std::min(currentScanEndTime, rowEndTime))
105 const std::vector<T *> &
operator() (
const std::vector<T *>& rows,
bool ignoreTime=
false) {
106 if (ignoreTime)
return rows;
120 const std::vector<asdm::ScanRow *>&
scans;
131 int64_t currentScanStartTime, currentScanEndTime;
133 rowTime = row->getTime().get();
135 currentScanStartTime = (*iter)->getStartTime().get();
136 currentScanEndTime = (*iter)->getEndTime().get();
137 if ((currentScanStartTime <= rowTime) && (rowTime < currentScanEndTime))
145 const std::vector<T *> &
operator() (
const std::vector<T *>& rows,
bool ignoreTime=
false) {
146 if (ignoreTime)
return rows;
176 template<
typename Enum,
typename CEnum>
186 template<
typename PhysicalQuantity,
typename BasicType>
188 return (BasicType) value.get();
194 #if defined(__APPLE__)
195 #include <mach-o/dyld.h>
199 return (_NSGetExecutablePath(path, &size) == 0) ? std::string(path) :
"";
205 char result[ PATH_MAX ];
206 ssize_t count = readlink(
"/proc/self/exe", result, PATH_MAX );
207 return std::string( result, (count > 0) ? count : 0);
220 #define CONTEXT_P ((ParserContext<T, R, RFilter> *)myContext_p)
221 #define V2CTX_P(v_p) ((ParserContext<T, R, RFilter> *) v_p)
223 template<
class T,
class R,
class RFilter>
226 enum StatesEnum {
UNSET,
START,
IN_TABLE,
IN_ENTITY,
AFTER_ENTITY,
IN_CONTAINER_ENTITY,
AFTER_CONTAINER_ENTITY,
IN_ROW,
AFTER_ROW,
IN_ATTRIBUTE,
END};
230 std::vector<std::shared_ptr<R> >
rows;
233 void (*
tableFiller_f_p) (
const std::vector<R*>&, std::map<AtmPhaseCorrectionMod::AtmPhaseCorrection, ASDM2MSFiller*>&);
234 std::map<AtmPhaseCorrectionMod::AtmPhaseCorrection, ASDM2MSFiller*>*
msFillers_m_p;
247 template <
class T,
class R,
class RFilter>
250 typedef void (*
TableFiller)(
const std::vector<R*>&, std::map<AtmPhaseCorrectionMod::AtmPhaseCorrection, ASDM2MSFiller*>&);
265 myContext.tableFiller_f_p = tableFiller_f_p;
286 void operator() (
const std::string& asdmDirectory,
bool ignoreTime) {
288 std::string tablePath = asdmDirectory +
"/"+
T::name() +
".xml";
297 const xmlChar* expectedElement = NULL;
306 expectedElement =
V2CTX_P(v_p)->topLevelElement_p;
312 expectedElement =
V2CTX_P(v_p)->entityElement_p;
318 expectedElement =
V2CTX_P(v_p)->containerEntityElement_p;
327 V2CTX_P(v_p)->row_sp = std::shared_ptr<R>(tableRef.newRow());
328 expectedElement =
V2CTX_P(v_p)->rowElement_p;
336 expectedElement = NULL;
337 V2CTX_P(v_p)->currentElement = (
char *) name;
348 std::string message =
"Unexpected '" + std::string((
char *) name) +
"'.";
353 V2CTX_P(v_p)->state = nextState;
367 switch (currentState) {
374 if (
V2CTX_P(v_p)->rows.size() > 0) {
375 std::vector<R*> tmp(
V2CTX_P(v_p)->rows.size());
376 for (
unsigned int iR = 0; iR < tmp.size(); iR++) tmp[iR] =
V2CTX_P(v_p)->rows[iR].get();
377 const std::vector<R*>& filteredRows = (*(
V2CTX_P(v_p)->rFilter_p))(tmp,
V2CTX_P(v_p)->ignoreTime);
378 if (filteredRows.size() > 0) {
379 (*(
V2CTX_P(v_p)->tableFiller_f_p))(filteredRows , *(
V2CTX_P(v_p)->msFillers_m_p));
384 std::ostringstream oss;
386 oss <<
"Appended " << filteredRows.size() <<
" rows to the MS SYSPOWER table." << endl;
420 if (
V2CTX_P(v_p)->rows.size() ==
V2CTX_P(v_p)->maxNumberOfRowsInMem) {
421 std::vector<R*> tmp(
V2CTX_P(v_p)->rows.size());
422 for (
unsigned int iR = 0; iR < tmp.size(); iR++) tmp[iR] =
V2CTX_P(v_p)->rows[iR].get();
423 const std::vector<R*>& filteredRows = (*(
V2CTX_P(v_p)->rFilter_p))(tmp,
V2CTX_P(v_p)->ignoreTime);
424 if (filteredRows.size() > 0) {
425 (*(
V2CTX_P(v_p)->tableFiller_f_p))(filteredRows , *(
V2CTX_P(v_p)->msFillers_m_p));
430 std::ostringstream oss;
432 oss <<
"Appended " << filteredRows.size() <<
" rows to the MS SYSPOWER table." << endl;
449 std::string message =
"Unexpected '" + std::string((
char *) name) +
"'.";
453 V2CTX_P(v_p)->state = nextState;
464 V2CTX_P(v_p)->currentValue = std::string((
char * ) ch, len);
475 xmlSAXHandler handler = {};
482 static void error(
const std::string & message) {
487 std::string message =
"Unexpected opening tag '" + std::string((
const char *) name) +
"', I was expecting '" + std::string((
const char*) expectedName) +
"'.";
492 std::string message =
"Unexpected closing tag '" + std::string((
const char *) name) +
"'.";
505 cout <<
"Enter '" << name <<
"' (depth = " <<
V2CTX_P(v_p)->depth <<
")" << endl;
509 cout <<
"Exit from '" << name <<
"' (depth = " <<
V2CTX_P(v_p)->depth <<
")" << endl;
rowsInAScanbyTimeIntervalFunctor(const std::vector< asdm::ScanRow * > &scans)
std::map< AtmPhaseCorrectionMod::AtmPhaseCorrection, ASDM2MSFiller * > * msFillers_m_p
Elements::const_iterator const_iterator
std::vector< T * > result
bool operator()(std::vector< T > &x)
bool timeIsInAScan(T *row, const std::vector< asdm::ScanRow * > &scans)
A template function which checks if there is at least one element scan of the vector scans for which ...
const std::vector< asdm::ScanRow * > & scans
const xmlChar * rowElement_p
BasicType basicTypeValue(PhysicalQuantity value)
template function meant to return a value of type BasicType out of a value expected to be of one of t...
static void checkOpeningElement(const xmlChar *name, const xmlChar *expectedName)
static void end_element_callback(void *v_p, const xmlChar *name)
Defines the action to perform when an event "closing tag" occurs.
~TableSAXReader()
The destructor.
The ASDM class is the container for all tables.
static void exitElementInfo(void *v_p, const xmlChar *name)
const xmlChar * topLevelElement_p
rowsInAScanbyTimeFunctor(const std::vector< asdm::ScanRow * > &scans)
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
static LogSinkInterface & globalSink()
Get/set the global sink or check if the global sink is null.
const std::vector< T * > & operator()(const std::vector< T * > &rows, bool ignoreTime=false)
std::shared_ptr< R > row_sp
std::vector< std::shared_ptr< R > > rows
static void unexpectedOpeningElement(const xmlChar *name, const xmlChar *expectedName)
const xmlChar * entityElement_p
static void enterElementInfo(void *v_p, const xmlChar *name)
static void error(const std::string &message)
std::string path(const std::string &name)
static Bool postGlobally(const LogMessage &message)
Send message to the global sink only.
void operator()(const std::string &asdmDirectory, bool ignoreTime)
It will be used as a functor.
std::string topLevelElement_s
static void checkClosingElement(const xmlChar *name, const xmlChar *expectedName)
TableSAXReader(bool verbose, RFilter &rFilter, TableFiller tableFiller_f_p, std::map< AtmPhaseCorrectionMod::AtmPhaseCorrection, ASDM2MSFiller * > &msFillers_m)
An empty contructor.
A boolean template functor which returns the value of the expression x.size() < y.
const xmlChar * containerEntityElement_p
const std::vector< T * > & operator()(const std::vector< T * > &rows, bool ignoreTime=false)
static void characters_callback(void *v_p, const xmlChar *ch, int len)
Defines the action to be performed while parsing any text outside of a tag.
void(* tableFiller_f_p)(const std::vector< R * > &, std::map< AtmPhaseCorrectionMod::AtmPhaseCorrection, ASDM2MSFiller * > &)
A template functor which returns -|v|.
static void start_element_callback(void *v_p, const xmlChar *name, const xmlChar **)
Defines the action to perform when an event "opening tag" occurs.
The ConversionException class represents an exception when an error occurs in converting a table to i...
unsigned int maxNumberOfRowsInMem
std::string stringValue(Enum literal)
A template function which returns a string from an (expectedly) enumeration and its associated helper...
std::string currentElement
LogOrigin: The source code location of the originator of a LogMessage.
const std::vector< asdm::ScanRow * > & scans
static xmlSAXHandler initSAXHandler()
std::set< T > SetAndSet(const std::set< T > &s1, const std::set< T > &s2)
Returns the intersection of two sets.
std::vector< T * > result
static void unexpectedClosingElement(const xmlChar *name)
static xmlSAXHandler myHandler
ParserContext< T, R, RFilter > myContext
void(* TableFiller)(const std::vector< R * > &, std::map< AtmPhaseCorrectionMod::AtmPhaseCorrection, ASDM2MSFiller * > &)
Informational log messages with with time, priority, and origin.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
T getenv(const char *name, const T defaultVal)
std::string displaySet(const std::set< T > &aSet)
A template function which returns a string representing the contents of a set of elements of type T...
bool timeIntervalIntersectsAScan(T *row, const std::vector< asdm::ScanRow * > &scans)
A function which returns true if and only there is at least one element in the vector 'scans' for whi...