Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JLANG::JASCIIFileWriter< T > Class Template Reference

Object(s) writing to ASCII file. More...

#include <JASCIIFileWriter.hh>

Inheritance diagram for JLANG::JASCIIFileWriter< T >:
JLANG::JAccessibleOutputStream JLANG::JStreamObjectOutput< T > JLANG::JAccessibleObjectOutput< T > JLANG::JAccessible JLANG::JObjectOutput< T > JLANG::JObjectOutput< T > JLANG::JAccessible JLANG::JThrow< JAccessible > JLANG::JThrow< JAccessible >

Public Member Functions

 JASCIIFileWriter ()
 Default constructor.
 
 JASCIIFileWriter (const char *file_name)
 Constructor.
 
 JASCIIFileWriter (const char *file_name, const std::string &sep)
 Constructor.
 
virtual bool is_open () const
 Check is file is open.
 
virtual void open (const char *file_name)
 Open file.
 
virtual void close ()
 Close file.
 
virtual bool put (const T &object) override
 Object output.
 
const std::string & getSeparator () const
 Get token separator.
 
void setSeparator (const std::string &sep)
 Set token separator.
 

Static Public Member Functions

static void Throw (const bool option)
 Enable/disable throw option.
 
static int Throw (const JException_t &error, const int value=-1)
 Throw exception or return error.
 

Static Protected Attributes

static bool do_throw
 throw option
 

Private Attributes

std::ostream & __out
 
std::string __sep
 

Detailed Description

template<class T>
class JLANG::JASCIIFileWriter< T >

Object(s) writing to ASCII file.

This class implements the JAccessibleObjectOutput interface.

Definition at line 27 of file JASCIIFileWriter.hh.

Constructor & Destructor Documentation

◆ JASCIIFileWriter() [1/3]

template<class T >
JLANG::JASCIIFileWriter< T >::JASCIIFileWriter ( )
inline

Default constructor.

Definition at line 36 of file JASCIIFileWriter.hh.

36 :
38 JStreamObjectOutput<T>(static_cast<std::ostream&>(*this), "")
39 {}
JAccessibleOutputStream()
Default constructor.
JStreamObjectOutput(std::ostream &out, const std::string &sep="")
Constructor.

◆ JASCIIFileWriter() [2/3]

template<class T >
JLANG::JASCIIFileWriter< T >::JASCIIFileWriter ( const char * file_name)
inline

Constructor.

Parameters
file_namefile name

Definition at line 47 of file JASCIIFileWriter.hh.

47 :
48 JAccessibleOutputStream(file_name),
49 JStreamObjectOutput<T>(static_cast<std::ostream&>(*this), "")
50 {}

◆ JASCIIFileWriter() [3/3]

template<class T >
JLANG::JASCIIFileWriter< T >::JASCIIFileWriter ( const char * file_name,
const std::string & sep )
inline

Constructor.

Parameters
file_namefile name
septoken separator

Definition at line 59 of file JASCIIFileWriter.hh.

60 :
61 JAccessibleOutputStream(file_name),
62 JStreamObjectOutput<T>(static_cast<std::ostream&>(*this), sep)
63 {}

Member Function Documentation

◆ is_open()

virtual bool JLANG::JAccessibleOutputStream::is_open ( ) const
inlinevirtualinherited

Check is file is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 118 of file JAccessibleStream.hh.

119 {
120 return std::ofstream::is_open();
121 }

◆ open()

virtual void JLANG::JAccessibleOutputStream::open ( const char * file_name)
inlinevirtualinherited

Open file.

Parameters
file_namefile name

Implements JLANG::JAccessible.

Reimplemented in JLANG::JAccessibleBinaryOutputStream.

Definition at line 129 of file JAccessibleStream.hh.

130 {
131 std::ofstream::open(file_name);
132
133 if (!this->is_open()) {
134 Throw(JFileOpenException(std::string("Error opening file ") + file_name));
135 }
136 }
virtual bool is_open() const
Check is file is open.
static void Throw(const bool option)
Definition JThrow.hh:37

◆ close()

virtual void JLANG::JAccessibleOutputStream::close ( )
inlinevirtualinherited

Close file.

Implements JLANG::JAccessible.

Definition at line 142 of file JAccessibleStream.hh.

143 {
144 std::ofstream::close();
145 }

◆ put()

template<class T >
virtual bool JLANG::JStreamObjectOutput< T >::put ( const T & object)
inlineoverridevirtualinherited

Object output.

Parameters
objectobject
Returns
true if OK; else false

Implements JLANG::JObjectOutput< T >.

Definition at line 51 of file JStreamObjectOutput.hh.

52 {
53 __out << object << __sep;
54
55 return (bool) __out;
56 }

◆ getSeparator()

template<class T >
const std::string & JLANG::JStreamObjectOutput< T >::getSeparator ( ) const
inlineinherited

Get token separator.

Returns
separator

Definition at line 64 of file JStreamObjectOutput.hh.

65 {
66 return this->__sep;
67 }

◆ setSeparator()

template<class T >
void JLANG::JStreamObjectOutput< T >::setSeparator ( const std::string & sep)
inlineinherited

Set token separator.

Parameters
sepseparator

Definition at line 75 of file JStreamObjectOutput.hh.

76 {
77 this->__sep = sep;
78 }

◆ Throw() [1/2]

static void JLANG::JThrow< JAccessible >::Throw ( const bool option)
inlinestaticinherited

Enable/disable throw option.

Parameters
optiontrue enable; false disable

Definition at line 37 of file JThrow.hh.

38 {
39 do_throw = option;
40 }

◆ Throw() [2/2]

static int JLANG::JThrow< JAccessible >::Throw ( const JException_t & error,
const int value = -1 )
inlinestaticinherited

Throw exception or return error.

Parameters
errorexception
valuereturn code
Returns
return code

Definition at line 51 of file JThrow.hh.

52 {
53 using namespace std;
54
55 if (do_throw) {
56 throw error;
57 }
58
59 cerr << error.what() << endl;
60
61 return value;
62 }

Member Data Documentation

◆ __out

template<class T >
std::ostream& JLANG::JStreamObjectOutput< T >::__out
privateinherited

Definition at line 81 of file JStreamObjectOutput.hh.

◆ __sep

template<class T >
std::string JLANG::JStreamObjectOutput< T >::__sep
privateinherited

Definition at line 82 of file JStreamObjectOutput.hh.

◆ do_throw

bool JLANG::JThrow< JAccessible >::do_throw
staticprotectedinherited

throw option

Set default throw option to true.

Definition at line 28 of file JThrow.hh.


The documentation for this class was generated from the following file: