strusBase  0.17
dataRecordFile.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
9 #ifndef _STRUS_BASE_DATA_RECORD_FILE_HPP_INCLUDED
10 #define _STRUS_BASE_DATA_RECORD_FILE_HPP_INCLUDED
11 #include "strus/base/fileio.hpp"
12 #include <vector>
13 #include <string>
14 #include <cstdio>
15 
16 namespace strus
17 {
18 
20 #ifdef _MSC_VER
21 class DataRecordFile;
22 //... Posix file functions do not open a file in shared read mode in Windows.
23 // Therefore we need an own implementation with Win file functions that is not available yet.
24 #else
25 class DataRecordFile
27 {
28 public:
31 
32 public:
37 
45  bool open( const std::string& filename, const Mode& mode_, unsigned int recordsize_, unsigned int headersize_=0, const void* headerstruct=0);
46 
50  const void* read( std::size_t fpos);
51 
54  const void* read();
55 
58  const void* header();
59 
63  bool append( const void* recbuf);
64 
67  bool close();
68 
71  int error() const;
72 
74  std::size_t recordsize() const {return m_recordsize;}
75 
77  std::size_t size();
78 
79 private:
80  FILE* m_fh;
81  Mode m_mode;
82  int m_errno;
83  unsigned int m_recordsize;
84  unsigned int m_headersize;
85  std::size_t m_recordindex;
86  void* m_recbuf;
87  void* m_hdrbuf;
88 
89 private:
90 #if __cplusplus >= 201103L
91  DataRecordFile( const DataRecordFile&) = delete;
92  void operator=( const DataRecordFile&) = delete;
93 #else
94  DataRecordFile( const DataRecordFile&){}
95  void operator=( const DataRecordFile&){}
96 #endif
97 };
98 #endif
99 
100 }//namespace
101 #endif
102 
bool open(const std::string &filename, const Mode &mode_, unsigned int recordsize_, unsigned int headersize_=0, const void *headerstruct=0)
Open a file.
std::size_t recordsize() const
Get the size of one record of this file.
Definition: dataRecordFile.hpp:74
DataRecordFile()
Constructor.
bool append(const void *recbuf)
Append a record at the end of the file.
Definition: dataRecordFile.hpp:30
const void * header()
Get a pointer to the header of of the file.
Definition: dataRecordFile.hpp:30
Basic portable file type for collections of equal sized records with random access.
Definition: dataRecordFile.hpp:26
const void * read()
Read the record at the current file position of the file.
~DataRecordFile()
Destructor.
int error() const
Get the error of the last operation to this file.
std::size_t size()
Get the number of records stored in the file.
Definition: dataRecordFile.hpp:30
Mode
Implemented modes to access a data record file.
Definition: dataRecordFile.hpp:30
bool close()
Close the file.