Jpp  19.1.0
the software that should make you happy
JAbstractFile.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JABSTRACTFILE__
2 #define __JLANG__JABSTRACTFILE__
3 
4 #include <stdio.h>
5 
6 #include "JLang/JComparable.hh"
7 
8 
9 /**
10  * \author mdejong
11  */
12 
13 namespace JLANG {}
14 namespace JPP { using namespace JLANG; }
15 
16 namespace JLANG {
17 
18 
19  /**
20  * The JAbstractFile class encapsulates the c-style file descriptor.
21  */
22  class JAbstractFile :
23  public JComparable<JAbstractFile>
24  {
25  public:
26 
27  static const int FILE_CLOSED = -1;
28 
29 
30  /**
31  * Default constructor.
32  */
35  {}
36 
37 
38  /**
39  * Constructor.
40  *
41  * \param file file descriptor
42  */
43  JAbstractFile(const int file) :
44  fileDescriptor(file)
45  {}
46 
47 
48  /**
49  * Constructor.
50  *
51  * \param stream file stream
52  */
53  JAbstractFile(FILE* stream) :
54  fileDescriptor(fileno(stream))
55  {}
56 
57 
58  /**
59  * Less than operation.
60  *
61  * \param file JAbstractFile to be compared
62  * \return true if this file descriptor is less; else false
63  */
64  bool less(const JAbstractFile& file) const
65  {
66  return getFileDescriptor() < file.getFileDescriptor();
67  }
68 
69 
70  /**
71  * Get file descriptor.
72  *
73  * \return file descriptor
74  */
75  int getFileDescriptor() const
76  {
77  return fileDescriptor;
78  }
79 
80 
81  /**
82  * Set file descriptor.
83  *
84  * \param file file descriptor
85  */
86  void setFileDescriptor(const int file)
87  {
88  fileDescriptor = file;
89  }
90 
91 
92  /**
93  * Get open status.
94  */
95  bool is_open() const
96  {
97  return fileDescriptor != FILE_CLOSED;
98  }
99 
100 
101  protected:
103  };
104 }
105 
106 #endif
The JAbstractFile class encapsulates the c-style file descriptor.
JAbstractFile(const int file)
Constructor.
static const int FILE_CLOSED
int getFileDescriptor() const
Get file descriptor.
bool is_open() const
Get open status.
bool less(const JAbstractFile &file) const
Less than operation.
JAbstractFile()
Default constructor.
JAbstractFile(FILE *stream)
Constructor.
void setFileDescriptor(const int file)
Set file descriptor.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:139