Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Operating with common std::iostream instead of only file streams #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions core/lib/FileHandling/FFStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
// 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
//
//============================================================================

//============================================================================
//
//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.
//
//=============================================================================
Expand Down Expand Up @@ -85,6 +85,13 @@ namespace gpstk
open(fn, mode);
}

FFStream ::
FFStream( std::basic_iostream<char>& anotherStream )
: recordNumber(0)
{
std::basic_iostream<char>::init(anotherStream.rdbuf());
clear();
}

void FFStream ::
open( const std::string& fn,
Expand All @@ -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<char>::init(fileStream.rdbuf());
std::basic_iostream<char>::setstate(fileStream.rdstate());
} // End of method 'FFStream::open()'


Expand All @@ -123,7 +132,7 @@ namespace gpstk
isFFStream(std::istream& i)
{
try
{
{
(void)dynamic_cast<FFStream&>(i);
}
catch(...)
Expand Down Expand Up @@ -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 ::
Expand Down Expand Up @@ -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));
Expand All @@ -320,7 +329,7 @@ namespace gpstk
recordNumber = initialRecordNumber;
setstate(std::ios::failbit);
conditionalThrow();
}
}
// catches some errors we can encounter
catch (FFStreamError& e)
{
Expand Down Expand Up @@ -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
22 changes: 16 additions & 6 deletions core/lib/FileHandling/FFStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
// 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
//
//============================================================================

//============================================================================
//
//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.
//
//=============================================================================
Expand Down Expand Up @@ -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<char>
{
public:
/// Default constructor, initialize internal data
Expand All @@ -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<char>& anotherStream);

/**
* Overrides fstream::open so derived classes can make appropriate
* internal changes (line count, header info, etc).
Expand Down Expand Up @@ -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;

Expand All @@ -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.
Expand Down
16 changes: 11 additions & 5 deletions core/lib/FileHandling/FFTextStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
// 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
//
//============================================================================

//============================================================================
//
//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.
//
//=============================================================================
Expand Down Expand Up @@ -73,6 +73,12 @@ namespace gpstk
init();
}

FFTextStream ::
FFTextStream(std::basic_iostream<char>& anotherStream)
: FFStream(anotherStream)
{
init();
};

void FFTextStream ::
open( const char* fn,
Expand Down
16 changes: 11 additions & 5 deletions core/lib/FileHandling/FFTextStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
// 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
//
//============================================================================

//============================================================================
//
//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.
//
//=============================================================================
Expand Down Expand Up @@ -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<char>& anotherStream );

/// Overrides open to reset the line number.
virtual void open( const char* fn,
std::ios::openmode mode );
Expand Down
24 changes: 15 additions & 9 deletions core/lib/FileHandling/RINEX3/Rinex3NavStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
// 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
//
//============================================================================

//============================================================================
//
//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.
//
//=============================================================================
Expand Down Expand Up @@ -57,6 +57,12 @@ namespace gpstk
init();
}

Rinex3NavStream ::
Rinex3NavStream(std::basic_iostream<char>& anotherStream)
: FFTextStream(anotherStream)
{
init();
}

Rinex3NavStream ::
~Rinex3NavStream()
Expand All @@ -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();
}
}
25 changes: 15 additions & 10 deletions core/lib/FileHandling/RINEX3/Rinex3NavStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
// 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
//
//============================================================================

//============================================================================
//
//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.
//
//=============================================================================
Expand Down Expand Up @@ -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<char>& 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;

Expand Down
Loading