IN2OSM  1.0.1
file< Ch >

Represents data loaded from a file. More...

#include <rapidxml_utils.hpp>

Collaboration diagram for file< Ch >:
Collaboration graph

Public Member Functions

 file (const char *filename)
 
 file (std::basic_istream< Ch > &stream)
 
Ch * data ()
 
const Ch * data () const
 
std::size_t size () const
 

Private Attributes

std::vector< Ch > m_data
 

Detailed Description

template<class Ch = char>
class rapidxml::file< Ch >

Represents data loaded from a file.

Definition at line 21 of file rapidxml_utils.hpp.

Constructor & Destructor Documentation

◆ file() [1/2]

file ( const char *  filename)
inline

Loads file into the memory. Data will be automatically destroyed by the destructor.

Parameters
filenameFilename to load.

Definition at line 28 of file rapidxml_utils.hpp.

29  {
30  using namespace std;
31 
32  // Open stream
33  basic_ifstream<Ch> stream(filename, ios::binary);
34  if (!stream)
35  throw runtime_error(string("cannot open file ") + filename);
36  stream.unsetf(ios::skipws);
37 
38  // Determine stream size
39  stream.seekg(0, ios::end);
40  size_t size = stream.tellg();
41  stream.seekg(0);
42 
43  // Load data and add terminating 0
44  m_data.resize(size + 1);
45  stream.read(&m_data.front(), static_cast<streamsize>(size));
46  m_data[size] = 0;
47  }
std::size_t size() const
std::vector< Ch > m_data
Here is the call graph for this function:

◆ file() [2/2]

file ( std::basic_istream< Ch > &  stream)
inline

Loads file into the memory. Data will be automatically destroyed by the destructor

Parameters
streamStream to load from

Definition at line 51 of file rapidxml_utils.hpp.

52  {
53  using namespace std;
54 
55  // Load data and add terminating 0
56  stream.unsetf(ios::skipws);
57  m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
58  if (stream.fail() || stream.bad())
59  throw runtime_error("error reading stream");
60  m_data.push_back(0);
61  }
std::vector< Ch > m_data

Member Function Documentation

◆ data() [1/2]

Ch* data ( )
inline

Gets file data.

Returns
Pointer to data of file.

Definition at line 65 of file rapidxml_utils.hpp.

66  {
67  return &m_data.front();
68  }
std::vector< Ch > m_data

◆ data() [2/2]

const Ch* data ( ) const
inline

Gets file data.

Returns
Pointer to data of file.

Definition at line 72 of file rapidxml_utils.hpp.

73  {
74  return &m_data.front();
75  }
std::vector< Ch > m_data

◆ size()

std::size_t size ( ) const
inline

Gets file data size.

Returns
Size of file data, in characters.

Definition at line 79 of file rapidxml_utils.hpp.

80  {
81  return m_data.size();
82  }
std::vector< Ch > m_data
Here is the caller graph for this function:

Member Data Documentation

◆ m_data

std::vector<Ch> m_data
private

Definition at line 86 of file rapidxml_utils.hpp.


The documentation for this class was generated from the following file: