Jpp
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  * Get open status.
83  */
84  bool is_open() const
85  {
86  return fileDescriptor != FILE_CLOSED;
87  }
88 
89 
90  protected:
92  };
93 }
94 
95 #endif
JLANG::JAbstractFile::getFileDescriptor
int getFileDescriptor() const
Get file descriptor.
Definition: JAbstractFile.hh:75
JLANG::JAbstractFile::JAbstractFile
JAbstractFile()
Default constructor.
Definition: JAbstractFile.hh:33
JLANG::JAbstractFile
The JAbstractFile class encapsulates the c-style file descriptor.
Definition: JAbstractFile.hh:22
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JAbstractFile::FILE_CLOSED
static const int FILE_CLOSED
Definition: JAbstractFile.hh:27
JComparable.hh
JLANG::JAbstractFile::fileDescriptor
int fileDescriptor
Definition: JAbstractFile.hh:91
JLANG::JAbstractFile::JAbstractFile
JAbstractFile(const int file)
Constructor.
Definition: JAbstractFile.hh:43
JLANG::JComparable
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
JLANG::JAbstractFile::less
bool less(const JAbstractFile &file) const
Less than operation.
Definition: JAbstractFile.hh:64
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JLANG::JAbstractFile::JAbstractFile
JAbstractFile(FILE *stream)
Constructor.
Definition: JAbstractFile.hh:53
JLANG::JAbstractFile::is_open
bool is_open() const
Get open status.
Definition: JAbstractFile.hh:84