1 #ifndef TABLE_STREAM_READER_H
2 #define TABLE_STREAM_READER_H
4 #include <libxml/parser.h>
5 #include <libxml/tree.h>
11 #include <sys/types.h>
15 #define READBUFFERSIZE ( 50 * 1024 * 1024 )
58 void open(
const std::string& directory){
67 struct stat filestatus;
85 doc = xmlReadMemory(xmlHeader.data(), xmlHeader.size(),
"BinaryTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
89 xmlNode* root_element = xmlDocGetRootElement(doc);
90 if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
94 if ( std::string(
"ASDMBinaryTable").compare((
const char*) root_element->name) == 0) {
99 }
else if (std::string(
T::name()+
"Table").compare((
const char*) root_element->name) == 0) {
105 xmlNode* child = root_element->children;
108 bulkStoreRef = (child == 0) ? 0 : ( (child->next) == 0 ? 0 : child->next->next );
110 if ( bulkStoreRef == 0 || (bulkStoreRef->type != XML_ELEMENT_NODE) || (std::string(
"BulkStoreRef").compare((
const char*) bulkStoreRef->name) != 0))
114 _xmlAttr* byteOrderAttr = 0;
115 for (
struct _xmlAttr* attr = bulkStoreRef->properties; attr; attr = attr->next) {
116 if (std::string(
"byteOrder").compare((
const char*) attr->name) == 0) {
117 byteOrderAttr = attr;
122 if (byteOrderAttr == 0)
125 std::string byteOrderValue = std::string((
const char*) byteOrderAttr->children->content);
132 xmlNode* attributes = bulkStoreRef->next;
133 if ( attributes == 0 || (attributes->type != XML_ELEMENT_NODE) || (std::string(
"Attributes").compare((
const char*) attributes->name) != 0))
136 xmlNode* childOfAttributes = attributes->children;
138 while ( childOfAttributes != 0 && (childOfAttributes->type == XML_ELEMENT_NODE) ) {
139 attributesSeq.push_back(std::string((
const char*) childOfAttributes->name));
140 childOfAttributes = childOfAttributes->next;
197 unsigned int nread = 0;
199 while (
hasRows() && nread < nRows ) {
283 for (
unsigned int i = 0; i <
rows.size(); i++)
293 #ifndef WITHOUT_BOOST
302 }
while (line.size() != 0 && numSkips <= maxSkips);
304 if (numSkips > maxSkips) {
305 std::ostringstream oss;
306 oss <<
"could not find an empty line is less than " << maxSkips + 1 <<
" lines." << std::endl;
313 unsigned long long whereAmI =
tableFile.tellg();
316 std::ostringstream oss ;
317 oss <<
"TableStreamReader::nextLine() : I could not read a line in '" <<
tablePath <<
"' at position " << whereAmI <<
".";
326 size_t colonIndex = hf.find(
":");
327 if (colonIndex == std::string::npos)
330 if (colonIndex > 0) {
331 name = hf.substr(0, colonIndex);
335 if (colonIndex < hf.size()) {
336 value = hf.substr(colonIndex+1);
340 return make_pair(name, value);
348 #ifndef WITHOUT_BOOST
349 if (! boost::algorithm::iends_with(
currentLine,
"IME-Version: 1.0"))
351 std::string versionEnd =
"IME-Version: 1.0";
374 #ifndef WITHOUT_BOOST
375 std::string s = boost::trim_copy(
nextLine());
376 while (boost::algorithm::iends_with(s,
";")) {
380 std::string s = asdm::trim_copy(
nextLine());
381 while (s.back()==
';') {
388 #ifndef WITHOUT_BOOST
389 if (boost::algorithm::to_upper_copy(hf2pair.first) != hf)
392 if (asdm::str_toupper(hf2pair.first) != hf)
401 std::string dashdashBoundary =
"--"+boundary;
403 while ((numLines <= maxLines) && (line.compare(dashdashBoundary) != 0)) {
408 if (numLines > maxLines) {
409 std::ostringstream oss;
410 oss <<
"could not find the boundary std::string '"<< boundary <<
"' in less than " << maxLines + 1 <<
" lines." << std::endl;
421 #ifndef WITHOUT_BOOST
430 while ( numLines <= maxLines && line.find(
"--"+boundary) == std::string::npos ) {
432 #ifndef WITHOUT_BOOST
441 if (numLines > maxLines) {
442 std::ostringstream oss;
443 oss <<
"could not find the boundary std::string '"<< boundary <<
"' in less than " << maxLines + 1 <<
" lines." << std::endl;
450 std::vector<std::string> cvValueItems;
452 #ifndef WITHOUT_BOOST
455 asdm::strsplit(ctValue,
';',cvValueItems);
457 std::vector<std::string> cvValueItemsNameValue;
459 cvValueItemsNameValue.clear();
460 #ifndef WITHOUT_BOOST
462 std::string boundary;
463 if ((cvValueItemsNameValue.size() > 1) && (boost::to_upper_copy(boost::trim_copy(cvValueItemsNameValue[0])) ==
"BOUNDARY") && (
unquote(cvValueItemsNameValue[1], boundary).size() > 0))
466 asdm::strsplit(*iter,
'=',cvValueItemsNameValue);
467 std::string boundary;
468 if ((cvValueItemsNameValue.size() > 1) && (asdm::str_toupper(asdm::trim_copy(cvValueItemsNameValue[0])) ==
"BOUNDARY") && (
unquote(cvValueItemsNameValue[1], boundary).size() > 0))
475 std::string
unquote(
const std::string& s, std::string& unquoted) {
477 if (((s.at(0) ==
'"') && (s.at(s.size()-1) ==
'"')) || ((s.at(0) ==
'\'') && (s.at(s.size()-1) ==
'\''))) {
481 unquoted = s.substr(1, s.size() - 2);
Elements::const_iterator const_iterator
std::vector< std::string > attributesSeq
A class to represent byte order information.
std::pair< std::string, std::string > headerField2Pair(const std::string &hf)
void close()
Releases all the resources allocated to the instance which can be reused with another file...
const std::vector< R * > & nextNRows(unsigned int nRows)
Reads at most n rows in the file, creates as many memory representations of these rows and return the...
The ASDM class is the container for all tables.
std::vector< casacore::String > split(const casacore::String &string, const casacore::String &splitter, bool ignoreConsecutiveSplitters=false)
void checkState(Transition t, const std::string &methodName) const
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
void skipUntilEmptyLine(int maxSkips)
virtual ~TableStreamReader()
The destructor.
std::streampos whereRowsStart
static const ByteOrder * fromString(const std::string &s)
Convert a string to a const ByteOrder*.
bool hasRows()
Returns true if the end of the file has not been reached.
TableExprNode trim(const TableExprNode &node)
Representable & getTable(std::string tableName)
Return the table, as a Representable object, with the specified name.
std::string unquote(const std::string &s, std::string &unquoted)
std::string requireMIMEHeader()
The ConversionException class represents an exception when an error occurs in converting a table to i...
std::string requireBoundaryInCT(const std::string &ctValue)
asdm::EndianIFStream eifs
const Double second
Time interval [T]:
void reset()
Repositions the read head to the beginning of the table.
TableStreamReader()
An empty constructor.
std::string accumulateUntilBoundary(const std::string &boundary, int maxLines)
const std::vector< R * > & untilNBytes(unsigned int nBytes)
Reads as many rows as possible in the file, keeps their in memory representation until the number of ...
static Entity fromBin(EndianIStream &eis)
Read the binary representation of an Enity from a EndianIStream and use the read value to set an Enti...
static const ByteOrder * Big_Endian
off_t endBoundarySizeInBytes
void open(const std::string &directory)
Opens a file expected to contain an ASDM table of type T with rows of type R.
A generic class to read a file containing an ASDM table as a stream.
void clear()
Empty the local storage containing the rows obtained during the last read operation.
std::pair< std::string, std::string > requireHeaderField(const std::string &hf)
void requireBoundary(const std::string &boundary, int maxLines)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
The Entity class is an identification of a persistant entity in the ALMA archive. ...