diff --git a/core/lib/FileHandling/FFStream.cpp b/core/lib/FileHandling/FFStream.cpp index 7e6af0615..3456a6967 100644 --- a/core/lib/FileHandling/FFStream.cpp +++ b/core/lib/FileHandling/FFStream.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with GPSTk; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA -// +// // Copyright 2004, The University of Texas at Austin // //============================================================================ @@ -23,13 +23,13 @@ //============================================================================ // //This software developed by Applied Research Laboratories at the University of -//Texas at Austin, under contract to an agency or agencies within the U.S. +//Texas at Austin, under contract to an agency or agencies within the U.S. //Department of Defense. The U.S. Government retains all rights to use, -//duplicate, distribute, disclose, or release this software. +//duplicate, distribute, disclose, or release this software. // -//Pursuant to DoD Directive 523024 +//Pursuant to DoD Directive 523024 // -// DISTRIBUTION STATEMENT A: This software has been approved for public +// DISTRIBUTION STATEMENT A: This software has been approved for public // release, distribution is unlimited. // //============================================================================= @@ -85,6 +85,13 @@ namespace gpstk open(fn, mode); } + FFStream :: + FFStream( std::basic_iostream& anotherStream ) + : recordNumber(0) + { + std::basic_iostream::init(anotherStream.rdbuf()); + clear(); + } void FFStream :: open( const std::string& fn, @@ -105,7 +112,9 @@ namespace gpstk // classes typically will want to do their initialization // AFTER the parent. init(fn, mode); - std::fstream::open(fn, mode); + fileStream.open(fn, mode); + std::basic_iostream::init(fileStream.rdbuf()); + std::basic_iostream::setstate(fileStream.rdstate()); } // End of method 'FFStream::open()' @@ -123,7 +132,7 @@ namespace gpstk isFFStream(std::istream& i) { try - { + { (void)dynamic_cast(i); } catch(...) @@ -275,7 +284,7 @@ namespace gpstk - // the crazy double try block is so that no gpstk::Exception throws + // the crazy double try block is so that no gpstk::Exception throws // get masked, allowing all exception information (line numbers, text, // etc) to be retained. void FFStream :: @@ -309,7 +318,7 @@ namespace gpstk setstate(std::ios::failbit); conditionalThrow(); } - catch (gpstk::StringUtils::StringException& e) + catch (gpstk::StringUtils::StringException& e) { e.addText("In record " + gpstk::StringUtils::asString(recordNumber)); @@ -320,7 +329,7 @@ namespace gpstk recordNumber = initialRecordNumber; setstate(std::ios::failbit); conditionalThrow(); - } + } // catches some errors we can encounter catch (FFStreamError& e) { @@ -378,5 +387,16 @@ namespace gpstk } // End of method 'FFStream::tryFFStreamPut()' + void FFStream::close() + { + if (fileStream && fileStream.is_open()) + fileStream.close(); + } + bool FFStream::is_open() + { + if(fileStream) + return fileStream.is_open(); + return true; + } } // End of namespace gpstk diff --git a/core/lib/FileHandling/FFStream.hpp b/core/lib/FileHandling/FFStream.hpp index e0c54151a..8476f72fa 100644 --- a/core/lib/FileHandling/FFStream.hpp +++ b/core/lib/FileHandling/FFStream.hpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with GPSTk; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA -// +// // Copyright 2004, The University of Texas at Austin // //============================================================================ @@ -23,13 +23,13 @@ //============================================================================ // //This software developed by Applied Research Laboratories at the University of -//Texas at Austin, under contract to an agency or agencies within the U.S. +//Texas at Austin, under contract to an agency or agencies within the U.S. //Department of Defense. The U.S. Government retains all rights to use, -//duplicate, distribute, disclose, or release this software. +//duplicate, distribute, disclose, or release this software. // -//Pursuant to DoD Directive 523024 +//Pursuant to DoD Directive 523024 // -// DISTRIBUTION STATEMENT A: This software has been approved for public +// DISTRIBUTION STATEMENT A: This software has been approved for public // release, distribution is unlimited. // //============================================================================= @@ -118,7 +118,7 @@ namespace gpstk * @warning When using open(), the internal header data of the stream * is not guaranteed to be retained. */ - class FFStream : public std::fstream + class FFStream : public std::basic_iostream { public: /// Default constructor, initialize internal data @@ -141,6 +141,12 @@ namespace gpstk */ FFStream( const std::string& fn, std::ios::openmode mode=std::ios::in ); + /** Construction from another stream for decoration + * + * @param anotherStream + */ + FFStream( std::basic_iostream& anotherStream); + /** * Overrides fstream::open so derived classes can make appropriate * internal changes (line count, header info, etc). @@ -170,6 +176,9 @@ namespace gpstk /// Check if the input stream is the kind of RinexObsStream static bool isFFStream(std::istream& i); + virtual void close(); + virtual bool is_open(); + /// This stores the most recently thrown exception. FFStreamError mostRecentException; @@ -185,6 +194,7 @@ namespace gpstk protected: + std::fstream fileStream; // used only in file system case; /// Encapsulates shared try/catch blocks for all file types /// to hide std::exception. diff --git a/core/lib/FileHandling/FFTextStream.cpp b/core/lib/FileHandling/FFTextStream.cpp index b5f1a8b8b..7bce96867 100644 --- a/core/lib/FileHandling/FFTextStream.cpp +++ b/core/lib/FileHandling/FFTextStream.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with GPSTk; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA -// +// // Copyright 2004, The University of Texas at Austin // //============================================================================ @@ -23,13 +23,13 @@ //============================================================================ // //This software developed by Applied Research Laboratories at the University of -//Texas at Austin, under contract to an agency or agencies within the U.S. +//Texas at Austin, under contract to an agency or agencies within the U.S. //Department of Defense. The U.S. Government retains all rights to use, -//duplicate, distribute, disclose, or release this software. +//duplicate, distribute, disclose, or release this software. // -//Pursuant to DoD Directive 523024 +//Pursuant to DoD Directive 523024 // -// DISTRIBUTION STATEMENT A: This software has been approved for public +// DISTRIBUTION STATEMENT A: This software has been approved for public // release, distribution is unlimited. // //============================================================================= @@ -73,6 +73,12 @@ namespace gpstk init(); } + FFTextStream :: + FFTextStream(std::basic_iostream& anotherStream) + : FFStream(anotherStream) + { + init(); + }; void FFTextStream :: open( const char* fn, diff --git a/core/lib/FileHandling/FFTextStream.hpp b/core/lib/FileHandling/FFTextStream.hpp index 4e8204487..64888d556 100644 --- a/core/lib/FileHandling/FFTextStream.hpp +++ b/core/lib/FileHandling/FFTextStream.hpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with GPSTk; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA -// +// // Copyright 2004, The University of Texas at Austin // //============================================================================ @@ -23,13 +23,13 @@ //============================================================================ // //This software developed by Applied Research Laboratories at the University of -//Texas at Austin, under contract to an agency or agencies within the U.S. +//Texas at Austin, under contract to an agency or agencies within the U.S. //Department of Defense. The U.S. Government retains all rights to use, -//duplicate, distribute, disclose, or release this software. +//duplicate, distribute, disclose, or release this software. // -//Pursuant to DoD Directive 523024 +//Pursuant to DoD Directive 523024 // -// DISTRIBUTION STATEMENT A: This software has been approved for public +// DISTRIBUTION STATEMENT A: This software has been approved for public // release, distribution is unlimited. // //============================================================================= @@ -83,6 +83,12 @@ namespace gpstk FFTextStream( const std::string& fn, std::ios::openmode mode=std::ios::in ); + /** Common constructor. + * + * @param anotherStream stream. + */ + FFTextStream( std::basic_iostream& anotherStream ); + /// Overrides open to reset the line number. virtual void open( const char* fn, std::ios::openmode mode ); diff --git a/core/lib/FileHandling/RINEX3/Rinex3NavStream.cpp b/core/lib/FileHandling/RINEX3/Rinex3NavStream.cpp index 4780c262b..b267a72eb 100644 --- a/core/lib/FileHandling/RINEX3/Rinex3NavStream.cpp +++ b/core/lib/FileHandling/RINEX3/Rinex3NavStream.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with GPSTk; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA -// +// // Copyright 2004, The University of Texas at Austin // //============================================================================ @@ -23,13 +23,13 @@ //============================================================================ // //This software developed by Applied Research Laboratories at the University of -//Texas at Austin, under contract to an agency or agencies within the U.S. +//Texas at Austin, under contract to an agency or agencies within the U.S. //Department of Defense. The U.S. Government retains all rights to use, -//duplicate, distribute, disclose, or release this software. +//duplicate, distribute, disclose, or release this software. // -//Pursuant to DoD Directive 523024 +//Pursuant to DoD Directive 523024 // -// DISTRIBUTION STATEMENT A: This software has been approved for public +// DISTRIBUTION STATEMENT A: This software has been approved for public // release, distribution is unlimited. // //============================================================================= @@ -57,6 +57,12 @@ namespace gpstk init(); } + Rinex3NavStream :: + Rinex3NavStream(std::basic_iostream& anotherStream) + : FFTextStream(anotherStream) + { + init(); + } Rinex3NavStream :: ~Rinex3NavStream() @@ -66,16 +72,16 @@ namespace gpstk void Rinex3NavStream :: open(const char* fn, std::ios::openmode mode) - { - FFTextStream::open(fn, mode); + { + FFTextStream::open(fn, mode); init(); } void Rinex3NavStream :: init() - { - headerRead = false; + { + headerRead = false; header = Rinex3NavHeader(); } } diff --git a/core/lib/FileHandling/RINEX3/Rinex3NavStream.hpp b/core/lib/FileHandling/RINEX3/Rinex3NavStream.hpp index 90529a3df..d691e81a9 100644 --- a/core/lib/FileHandling/RINEX3/Rinex3NavStream.hpp +++ b/core/lib/FileHandling/RINEX3/Rinex3NavStream.hpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with GPSTk; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA -// +// // Copyright 2004, The University of Texas at Austin // //============================================================================ @@ -23,13 +23,13 @@ //============================================================================ // //This software developed by Applied Research Laboratories at the University of -//Texas at Austin, under contract to an agency or agencies within the U.S. +//Texas at Austin, under contract to an agency or agencies within the U.S. //Department of Defense. The U.S. Government retains all rights to use, -//duplicate, distribute, disclose, or release this software. +//duplicate, distribute, disclose, or release this software. // -//Pursuant to DoD Directive 523024 +//Pursuant to DoD Directive 523024 // -// DISTRIBUTION STATEMENT A: This software has been approved for public +// DISTRIBUTION STATEMENT A: This software has been approved for public // release, distribution is unlimited. // //============================================================================= @@ -62,21 +62,26 @@ namespace gpstk public: /// Default constructor Rinex3NavStream(); - - /** Constructor + + /** Constructor * Opens a file named \a fn using ios::openmode \a mode. */ Rinex3NavStream(const char* fn, std::ios::openmode mode=std::ios::in); - + + /** Constructor + * Operates with \a anotherStream as navigation stream. + */ + Rinex3NavStream(std::basic_iostream& anotherStream); + /// Destructor virtual ~Rinex3NavStream(); - + /// overrides open to reset the header virtual void open(const char* fn, std::ios::openmode mode); /// RINEX NAV header for this file. Rinex3NavHeader header; - + /// Flag showing whether or not the header has been read. bool headerRead; diff --git a/core/lib/FileHandling/RINEX3/Rinex3ObsStream.cpp b/core/lib/FileHandling/RINEX3/Rinex3ObsStream.cpp index 220252ed4..af4488171 100644 --- a/core/lib/FileHandling/RINEX3/Rinex3ObsStream.cpp +++ b/core/lib/FileHandling/RINEX3/Rinex3ObsStream.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with GPSTk; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA -// +// // Copyright 2004, The University of Texas at Austin // //============================================================================ @@ -23,13 +23,13 @@ //============================================================================ // //This software developed by Applied Research Laboratories at the University of -//Texas at Austin, under contract to an agency or agencies within the U.S. +//Texas at Austin, under contract to an agency or agencies within the U.S. //Department of Defense. The U.S. Government retains all rights to use, -//duplicate, distribute, disclose, or release this software. +//duplicate, distribute, disclose, or release this software. // -//Pursuant to DoD Directive 523024 +//Pursuant to DoD Directive 523024 // -// DISTRIBUTION STATEMENT A: This software has been approved for public +// DISTRIBUTION STATEMENT A: This software has been approved for public // release, distribution is unlimited. // //============================================================================= @@ -67,6 +67,12 @@ namespace gpstk init(); } + Rinex3ObsStream :: + Rinex3ObsStream( std::basic_iostream& anotherStream ) + : FFTextStream(anotherStream) + { + init(); + } Rinex3ObsStream :: ~Rinex3ObsStream() diff --git a/core/lib/FileHandling/RINEX3/Rinex3ObsStream.hpp b/core/lib/FileHandling/RINEX3/Rinex3ObsStream.hpp index 5f3942b62..63b036dd4 100644 --- a/core/lib/FileHandling/RINEX3/Rinex3ObsStream.hpp +++ b/core/lib/FileHandling/RINEX3/Rinex3ObsStream.hpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with GPSTk; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA -// +// // Copyright 2004, The University of Texas at Austin // //============================================================================ @@ -23,13 +23,13 @@ //============================================================================ // //This software developed by Applied Research Laboratories at the University of -//Texas at Austin, under contract to an agency or agencies within the U.S. +//Texas at Austin, under contract to an agency or agencies within the U.S. //Department of Defense. The U.S. Government retains all rights to use, -//duplicate, distribute, disclose, or release this software. +//duplicate, distribute, disclose, or release this software. // -//Pursuant to DoD Directive 523024 +//Pursuant to DoD Directive 523024 // -// DISTRIBUTION STATEMENT A: This software has been approved for public +// DISTRIBUTION STATEMENT A: This software has been approved for public // release, distribution is unlimited. // //============================================================================= @@ -82,6 +82,12 @@ namespace gpstk Rinex3ObsStream( const std::string fn, std::ios::openmode mode = std::ios::in ); + /** Common constructor. + * + * @param[in] anotherStream the RINEX stream to open + */ + Rinex3ObsStream( std::basic_iostream& anotherStream ); + /// Destructor virtual ~Rinex3ObsStream();