Spinning Topp Logo BlackTopp Studios
inc
filestream.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _resourcefilestream_h
41 #define _resourcefilestream_h
42 
43 #include "Resource/datastream.h"
44 
45 /// @file
46 /// @brief Declaration of FileStream
47 
48 namespace Mezzanine
49 {
50  namespace Resource
51  {
52  ///////////////////////////////////////////////////////////////////////////////
53  /// @brief This represents a stream to a file on disk using the C++ file stream API.
54  /// @details
55  ///////////////////////////////////////
57  {
58  protected:
59  /// @internal
60  /// @brief The buffer object containing most or all of the functionality for this stream.
61  std::filebuf FileBuffer;
62 
63  /// @internal
64  /// @brief The path and name of the file this stream is currently open to.
66  /// @internal
67  /// @brief The type of access this stream has to the file.
69  /// @internal
70  /// @brief The size of the stream.
72  public:
73  /// @brief Blank constructor.
74  FileStream();
75  /// @brief Open constructor.
76  /// @param File The combined name and path to the file to be opened.
77  /// @param Mode The configuration to open the file with.
78  FileStream(const String& File, const Whole Mode = Resource::SF_Read | Resource::SF_Write);
79  /// @brief Split Open constructor.
80  /// @param FileName The name of the file to be opened.
81  /// @param FilePath The path to the file to be opened.
82  /// @param Mode The configuration to open the file with.
83  FileStream(const String& FileName, const String& FilePath, const Whole Mode = Resource::SF_Read | Resource::SF_Write);
84  /// @brief Class destructor.
85  virtual ~FileStream();
86 
87  ///////////////////////////////////////////////////////////////////////////////
88  // Utility Methods
89 
90  /// @brief Opens this stream to a file.
91  /// @exception If the stream fails to open the file specified, a IO_FILE_NOT_FOUND_EXCEPTION will be thrown.
92  /// @param File The combined name and path to the file to be opened.
93  /// @param Mode The configuration to open the file with.
94  void OpenFile(const String& File, const Whole Mode = Resource::SF_Read | Resource::SF_Write);
95  /// @brief Opens this stream to a file.
96  /// @exception If the stream fails to open the file specified, a IO_FILE_NOT_FOUND_EXCEPTION will be thrown.
97  /// @param FileName The name of the file to be opened.
98  /// @param FilePath The path to the file to be opened.
99  /// @param Mode The configuration to open the file with.
100  void OpenFile(const String& FileName, const String& FilePath, const Whole Mode = Resource::SF_Read | Resource::SF_Write);
101  /// @brief Gets whether or not this stream is currently open to a file.
102  /// @return Returns true if this is streaming to/from a file. False otherwise.
103  Boole IsOpenToFile() const;
104  /// @brief Closes the file that is currently opened.
105  void CloseFile();
106 
107  /// @brief Gets the path and name of the file that this stream is currently open to.
108  /// @return Returns a const String reference containing the path and name of the currently open file.
109  const String& GetFilePathAndName() const;
110  /// @brief Gets the flags that were used to open the file.
111  /// @return Returns a bitfield describing the flags used to open the file. If this stream is not open to a file it will return Resource::SF_None.
112  Whole GetSteamFlags() const;
113 
114  ///////////////////////////////////////////////////////////////////////////////
115  // Stream Base Operations
116 
117  /// @copydoc StreamBase::GetSize() const
118  virtual StreamSize GetSize() const;
119  };//FileStream
120  }//Resource
121 }//Mezzanine
122 
123 #endif
StreamSize Size
The size of the stream.
Definition: filestream.h:71
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Whole Flags
The type of access this stream has to the file.
Definition: filestream.h:68
Base class for streams that support both read and write operations.
Definition: datastream.h:263
Permit write operations on the stream.
Definition: datastream.h:69
String OpenFileName
The path and name of the file this stream is currently open to.
Definition: filestream.h:65
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
This represents a stream to a file on disk using the C++ file stream API.
Definition: filestream.h:56
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
std::streamsize StreamSize
Convenience define for the stream size datatype.
Definition: datastream.h:61
std::filebuf FileBuffer
The buffer object containing most or all of the functionality for this stream.
Definition: filestream.h:61
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Declaration of DataStream.
Permit read operations on the stream.
Definition: datastream.h:68