cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
svlFile.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Balazs Vagvolgyi
7  Created on: 2010
8 
9  (C) Copyright 2006-2010 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 #ifndef _svlFile_h
23 #define _svlFile_h
24 
26 
27 
28 class svlFile
29 {
30 public:
31  enum OpenMode {
32  R = 1,
33  W = 2
34  };
35 
36 public:
37  svlFile();
38  svlFile(const svlFile& file);
39  svlFile(const std::string& filepath, const OpenMode mode = R);
40  virtual ~svlFile();
41 
42  virtual int Open(const std::string& filepath, const OpenMode mode = R);
43  virtual int Close();
44  virtual bool IsOpen();
45 
46  virtual long long int Read(char* buffer, const long long int length);
47  virtual long long int Write(const char* buffer, const long long int length);
48 
49  template<class _ValueType>
50  bool Read(_ValueType& value)
51  {
52  long long int len = sizeof(_ValueType);
53  if (Read(reinterpret_cast<char*>(&value), len) < len) return false;
54  return true;
55  }
56 
57  template<class _ValueType>
58  bool Write(const _ValueType& value)
59  {
60  long long int len = sizeof(_ValueType);
61  if (Write(reinterpret_cast<const char*>(&value), len) < len) return false;
62  return true;
63  }
64 
65  virtual long long int GetLength();
66  virtual long long int GetPos();
67  virtual int Seek(const long long int abspos);
68 
69 private:
70  OpenMode Mode;
71  bool Opened;
72  long long int Length;
73 
74  // Internals that are OS-dependent in some way
75  enum {INTERNALS_SIZE = 16};
76  char* Internals;
77 
78  // Return the size of the actual object used by the OS.
79  // This is used for testing only.
80  static unsigned int SizeOfInternals();
81 };
82 
83 #endif // _svlFile_h
84 
virtual int Seek(const long long int abspos)
virtual long long int Read(char *buffer, const long long int length)
virtual int Close()
Definition: svlFile.h:32
bool Read(_ValueType &value)
Definition: svlFile.h:50
OpenMode
Definition: svlFile.h:31
Definition: svlFile.h:28
virtual long long int GetPos()
virtual long long int GetLength()
virtual int Open(const std::string &filepath, const OpenMode mode=R)
bool Write(const _ValueType &value)
Definition: svlFile.h:58
virtual bool IsOpen()
virtual ~svlFile()
Definition: svlFile.h:33
virtual long long int Write(const char *buffer, const long long int length)