Jpp  16.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 override
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) override
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() override
99  {
101  }
102  };
103 }
104 
105 #endif
Exception for opening of file.
Definition: JException.hh:342
virtual void close() override
Close file.
Exceptions.
JGZFileWriter(const char *file_name, const std::string &sep)
Constructor.
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
Object reading from gzipped file.
void open(const char *name, int open_mode=std::ios::out)
Definition: gzstream.h:218
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void close()
Definition: gzstream.h:185
JGZFileWriter()
Default constructor.
Template implementation of stream output for single data type.
bool is_open() const
Definition: gzstream.h:194
virtual void open(const char *file_name) override
Open file.
Interface for object output with named access.
Interface for named access of a device.
Definition: JAccessible.hh:20
virtual bool is_open() const override
Check is file is open.
static void Throw(const bool option)
Enable/disable throw option.
Definition: JThrow.hh:37
JGZFileWriter(const char *file_name)
Constructor.