Jpp
JGZFileWriter.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JGZFILEWRITER__
2 #define __JLANG__JGZFILEWRITER__
3 
4 #include <istream>
5 
6 #include "JLang/gzstream.h"
7 #include "JLang/JAccessible.hh"
9 #include "JLang/JException.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JLANG {}
17 namespace JPP { using namespace JLANG; }
18 
19 namespace JLANG {
20 
21 
22  /**
23  * Object reading from gzipped file.
24  *
25  * This class implements the JAccessibleObjectIterator interface.
26  */
27  template<class T>
28  class JGZFileWriter :
29  public ogzstream,
30  public JStreamObjectOutput <T>,
31  public JAccessibleObjectOutput<T>
32  {
33  public:
34  /**
35  * Default constructor.
36  */
38  ogzstream(),
39  JStreamObjectOutput<T>(static_cast<std::ostream&>(*this), "")
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param file_name file name
47  */
48  JGZFileWriter(const char* file_name) :
49  JAccessible(),
50  ogzstream(file_name),
51  JStreamObjectOutput<T>(static_cast<std::ostream&>(*this), "")
52  {}
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param file_name file name
59  * \param sep token separator
60  */
61  JGZFileWriter(const char* file_name,
62  const std::string& sep) :
63  JAccessible(),
64  ogzstream(file_name),
65  JStreamObjectOutput<T>(static_cast<std::ostream&>(*this), sep)
66  {}
67 
68 
69  /**
70  * Check is file is open.
71  *
72  * \return true if open; else false
73  */
74  virtual bool is_open() const
75  {
76  return ogzstream::is_open();
77  }
78 
79 
80  /**
81  * Open file.
82  *
83  * \param file_name file name
84  */
85  virtual void open(const char* file_name)
86  {
87  ogzstream::open(file_name);
88 
89  if (!this->is_open()) {
90  this->Throw(JFileOpenException(std::string("Error opening file ") + file_name));
91  }
92  }
93 
94 
95  /**
96  * Close file.
97  */
98  virtual void close()
99  {
101  }
102  };
103 }
104 
105 #endif
JException.hh
JLANG::JAccessible
Interface for named access of a device.
Definition: JAccessible.hh:20
gzstreambase::close
void close()
Definition: gzstream.h:185
JLANG::JFileOpenException
Exception for opening of file.
Definition: JException.hh:342
ogzstream
Definition: gzstream.h:213
JLANG::JGZFileWriter::open
virtual void open(const char *file_name)
Open file.
Definition: JGZFileWriter.hh:85
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JStreamObjectOutput
Template implementation of stream output for single data type.
Definition: JStreamObjectOutput.hh:28
JLANG::JGZFileWriter::is_open
virtual bool is_open() const
Check is file is open.
Definition: JGZFileWriter.hh:74
ogzstream::open
void open(const char *name, int open_mode=std::ios::out)
Definition: gzstream.h:218
JAccessible.hh
JLANG::JGZFileWriter
Object reading from gzipped file.
Definition: JGZFileWriter.hh:28
JLANG::JGZFileWriter::JGZFileWriter
JGZFileWriter()
Default constructor.
Definition: JGZFileWriter.hh:37
JLANG::JGZFileWriter::close
virtual void close()
Close file.
Definition: JGZFileWriter.hh:98
JLANG::JThrow< JAccessible >::Throw
static void Throw(const bool option)
Enable/disable throw option.
Definition: JThrow.hh:37
gzstream.h
JStreamObjectOutput.hh
std
Definition: jaanetDictionary.h:36
JLANG::JAccessibleObjectOutput
Interface for object output with named access.
Definition: JObjectOutput.hh:132
gzstreambase::is_open
bool is_open() const
Definition: gzstream.h:194
JLANG::JGZFileWriter::JGZFileWriter
JGZFileWriter(const char *file_name, const std::string &sep)
Constructor.
Definition: JGZFileWriter.hh:61
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JLANG::JGZFileWriter::JGZFileWriter
JGZFileWriter(const char *file_name)
Constructor.
Definition: JGZFileWriter.hh:48