[cig-commits] r7341 - in short/3D/PyLith/trunk/libsrc: . utils
brad at geodynamics.org
brad at geodynamics.org
Wed Jun 20 23:54:54 PDT 2007
Author: brad
Date: 2007-06-20 23:54:54 -0700 (Wed, 20 Jun 2007)
New Revision: 7341
Added:
short/3D/PyLith/trunk/libsrc/utils/LineParser.cc
short/3D/PyLith/trunk/libsrc/utils/LineParser.hh
Modified:
short/3D/PyLith/trunk/libsrc/Makefile.am
short/3D/PyLith/trunk/libsrc/utils/Makefile.am
Log:
Added LineParser for removing comments from MeshIOAscii files (and other text streams).
Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am 2007-06-21 04:38:49 UTC (rev 7340)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am 2007-06-21 06:54:54 UTC (rev 7341)
@@ -78,9 +78,11 @@
meshio/PsetFileBinary.cc \
meshio/SolutionIO.cc \
meshio/SolutionIOVTK.cc \
- topology/FieldsManager.cc
+ topology/FieldsManager.cc \
+ utils/LineParser.cc
-libpylith_la_LDFLAGS = -no-undefined $(PYTHON_LA_LDFLAGS)
+#libpylith_la_LDFLAGS = -no-undefined $(PYTHON_LA_LDFLAGS)
+libpylith_la_LDFLAGS = $(PYTHON_LA_LDFLAGS)
libpylith_la_LIBADD = \
$(PETSC_LIB) \
$(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
Added: short/3D/PyLith/trunk/libsrc/utils/LineParser.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/LineParser.cc 2007-06-21 04:38:49 UTC (rev 7340)
+++ short/3D/PyLith/trunk/libsrc/utils/LineParser.cc 2007-06-21 06:54:54 UTC (rev 7341)
@@ -0,0 +1,72 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "LineParser.hh" // implementation of class methods
+
+#include <iostream>
+#include <sstream>
+
+
+// ----------------------------------------------------------------------
+pylith::utils::LineParser::LineParser(std::istream& sin,
+ const char* delimiter,
+ const size_t bufsize) :
+ _in(sin),
+ _delimiter(delimiter),
+ _bufsize(bufsize),
+ _buffer(0)
+{ // constructor
+ _buffer = new char[bufsize];
+} // constructor
+
+// ----------------------------------------------------------------------
+pylith::utils::LineParser::~LineParser(void)
+{ // destructor
+ delete[] _buffer; _buffer = 0;
+} // destructor
+
+// ----------------------------------------------------------------------
+const std::string&
+pylith::utils::LineParser::next(void) {
+ _in.getline(_buffer, _bufsize);
+ _value = _buffer;
+ size_t pos = _value.find(_delimiter);
+ while (0 == pos && !_in.eof() && _in.good()) {
+ _in.getline(_buffer, _bufsize);
+ _value = _buffer;
+ pos = _value.find(_delimiter);
+ } // while
+ const size_t last = (pos == std::string::npos) ? _value.length() : pos;
+ _value = _value.substr(0, last);
+ return _value;
+} // next
+
+// ----------------------------------------------------------------------
+// Ignore input until character read.
+void
+pylith::utils::LineParser::ignore(const char marker)
+{ // ignore
+ _in.ignore(_bufsize, marker);
+} // ignore
+
+// ----------------------------------------------------------------------
+// Eat whitespace.
+void
+pylith::utils::LineParser::eatws(void)
+{ // eatws
+ _in >> std::ws;
+} // eatws
+
+
+// End of file
Added: short/3D/PyLith/trunk/libsrc/utils/LineParser.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/LineParser.hh 2007-06-21 04:38:49 UTC (rev 7340)
+++ short/3D/PyLith/trunk/libsrc/utils/LineParser.hh 2007-06-21 06:54:54 UTC (rev 7341)
@@ -0,0 +1,86 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/utils/LineParser.hh
+ *
+ * @brief C++ implementation of a simple text parser that removes
+ * comments and ignores input up to a given character.
+ */
+
+#if !defined(pylith_utils_lineparser_hh)
+#define pylith_utils_lineparser_hh
+
+#include <string> // HASA std::string
+#include <iosfwd> // USES std::istream
+
+namespace pylith {
+ namespace utils {
+ class LineParser;
+ } // utils
+} // pylith
+
+class pylith::utils::LineParser
+{ // LineParser
+
+// PUBLIC METHODS ///////////////////////////////////////////////////////
+public :
+
+ /** Constructor.
+ *
+ * @param sin Input stream.
+ * @param delimiter Comment that marks beginning of comment.
+ * @param bufsize Maximum size of line
+ */
+ LineParser(std::istream& sin,
+ const char* delimiter ="#",
+ const size_t bufsize =1024);
+
+ // Destructor.
+ ~LineParser(void);
+
+ /** Get next non-comment line from file.
+ *
+ * @returns String with next non-comment information.
+ */
+ const std::string& next(void);
+
+ /** Ignore input until character read.
+ *
+ * @param Character flagging to stop reading.
+ */
+ void ignore(const char marker);
+
+ /// Eat whitespace.
+ void eatws(void);
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+ LineParser(const LineParser&); ///< Not implemented
+ const LineParser& operator=(const LineParser&); ///< Not implemented
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+ std::istream& _in; ///< Input stream.
+ std::string _value; ///< Value for output.
+ std::string _delimiter; ///< Comment delimiter.
+ const int _bufsize; ///< Size of buffer for line input.
+ char* _buffer; ///< Buffer for line input.
+
+}; // LineParser
+
+#endif // pylith_utils_lineparser_hh
+
+
+// End of file
Modified: short/3D/PyLith/trunk/libsrc/utils/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/utils/Makefile.am 2007-06-21 04:38:49 UTC (rev 7340)
+++ short/3D/PyLith/trunk/libsrc/utils/Makefile.am 2007-06-21 06:54:54 UTC (rev 7341)
@@ -19,7 +19,8 @@
macrodefs.h \
petscfwd.h \
sievefwd.hh \
- sievetypes.hh
+ sievetypes.hh \
+ LineParser.hh
noinst_HEADERS =
More information about the cig-commits
mailing list