Jpp  17.3.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
JLANG::JASCIIFileReader< T > Class Template Reference

Object reading from ASCII file. More...

#include <JASCIIFileReader.hh>

Inheritance diagram for JLANG::JASCIIFileReader< T >:
JLANG::JAccessibleInputStream JLANG::JStreamObjectIterator< T > JLANG::JAccessibleObjectIterator< T > JLANG::JAccessible JLANG::JAbstractObjectIterator< T > JLANG::JObjectIterator< T > JLANG::JAccessible JLANG::JThrow< JAccessible > JLANG::JObjectIterator< T > JLANG::JThrow< JAccessible >

Public Types

typedef JObjectIterator< T >
::pointer_type 
pointer_type
 

Public Member Functions

 JASCIIFileReader ()
 Default constructor. More...
 
 JASCIIFileReader (const char *file_name)
 Constructor. More...
 
virtual bool is_open () const
 Check is file is open. More...
 
virtual void open (const char *file_name)
 Open file. More...
 
virtual void close ()
 Close file. More...
 
virtual bool setObject (T &object) override
 Set object. More...
 
virtual bool hasNext () override
 Check availability of next element. More...
 
virtual const pointer_typenext () override
 Get next element. More...
 
virtual skip_type skip (const skip_type ns)
 Skip items. More...
 

Static Public Member Functions

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

Protected Attributes

std::istream & __in
 
T object
 object More...
 
bool has_next
 status More...
 

Static Protected Attributes

static bool do_throw
 throw option More...
 

Detailed Description

template<class T>
class JLANG::JASCIIFileReader< T >

Object reading from ASCII file.

This class implements the JAccessibleObjectIterator interface.

Definition at line 26 of file JASCIIFileReader.hh.

Member Typedef Documentation

template<class T>
typedef JObjectIterator<T>::pointer_type JLANG::JAbstractObjectIterator< T >::pointer_type
inherited

Definition at line 39 of file JAbstractObjectIterator.hh.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 35 of file JASCIIFileReader.hh.

35  :
37  JStreamObjectIterator<T>(static_cast<std::istream&>(*this))
38  {}
JAccessibleInputStream()
Default constructor.
template<class T >
JLANG::JASCIIFileReader< T >::JASCIIFileReader ( const char *  file_name)
inline

Constructor.

Parameters
file_namefile name

Definition at line 46 of file JASCIIFileReader.hh.

46  :
47  JAccessibleInputStream(file_name),
48  JStreamObjectIterator<T>(static_cast<std::istream&>(*this))
49  {}
JAccessibleInputStream()
Default constructor.

Member Function Documentation

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

Check is file is open.

Returns
true if open; else false

Implements JLANG::JAccessible.

Definition at line 53 of file JAccessibleStream.hh.

54  {
55  return std::ifstream::is_open();
56  }
virtual void JLANG::JAccessibleInputStream::open ( const char *  file_name)
inlinevirtualinherited

Open file.

Parameters
file_namefile name

Implements JLANG::JAccessible.

Reimplemented in JLANG::JAccessibleBinaryInputStream.

Definition at line 64 of file JAccessibleStream.hh.

65  {
66  std::ifstream::open(file_name);
67 
68  if (!this->is_open()) {
69  Throw(JFileOpenException(std::string("Error opening file ") + file_name));
70  }
71  }
Exception for opening of file.
Definition: JException.hh:342
T * open(const std::string &file_name)
Open file.
Definition: JeepToolkit.hh:346
then awk string
virtual bool is_open() const
Check is file is open.
static void Throw(const bool option)
Enable/disable throw option.
Definition: JThrow.hh:37
virtual void JLANG::JAccessibleInputStream::close ( )
inlinevirtualinherited

Close file.

Implements JLANG::JAccessible.

Definition at line 77 of file JAccessibleStream.hh.

78  {
80  }
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:386
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  }
static bool do_throw
throw option
Definition: JThrow.hh:28
static int JLANG::JThrow< JAccessible >::Throw ( const JException error,
const int  value = -1 
)
inlinestaticinherited

Throw exception or return error.

Parameters
errorexception
valuereturn code
Returns
return code

Definition at line 50 of file JThrow.hh.

51  {
52  using namespace std;
53 
54  if (do_throw) {
55  throw error;
56  }
57 
58  cerr << error.what() << endl;
59 
60  return value;
61  }
virtual const char * what() const override
Get error message.
Definition: JException.hh:48
static bool do_throw
throw option
Definition: JThrow.hh:28
template<class T >
virtual bool JLANG::JStreamObjectIterator< T >::setObject ( T object)
inlineoverridevirtualinherited

Set object.

Parameters
objectreference to object to be set
Returns
true if set; else false

Implements JLANG::JAbstractObjectIterator< T >.

Definition at line 45 of file JStreamObjectIterator.hh.

46  {
47  return (bool) (__in && __in >> object);
48  }
template<class T>
virtual bool JLANG::JAbstractObjectIterator< T >::hasNext ( )
inlineoverridevirtualinherited

Check availability of next element.

Returns
true if the iteration has more elements; else false

Implements JLANG::JObjectIterator< T >.

Definition at line 56 of file JAbstractObjectIterator.hh.

57  {
58  if (!has_next) {
59  has_next = this->setObject(object);
60  }
61 
62  return has_next;
63  }
virtual bool setObject(T &object)=0
Set object.
template<class T>
virtual const pointer_type& JLANG::JAbstractObjectIterator< T >::next ( )
inlineoverridevirtualinherited

Get next element.

Returns
pointer to element

Implements JLANG::JObjectIterator< T >.

Definition at line 71 of file JAbstractObjectIterator.hh.

72  {
73  if (has_next)
74  ps.reset(&this->object);
75  else
76  ps.reset(NULL);
77 
78  has_next = false;
79 
80  return ps;
81  }
virtual void reset() override
Reset pointer.
Definition: JPointer.hh:84
template<class T>
virtual skip_type JLANG::JObjectIterator< T >::skip ( const skip_type  ns)
inlinevirtualinherited

Skip items.

Parameters
nsnumber of items to skip
Returns
number of items skipped

Reimplemented in JLANG::JPipe< T >, JLANG::JPipe< JTail_t >, JLANG::JPipe< JHead_t >, JLANG::JSTDObjectIterator< T >, JLANG::JAbstractObjectReader< T >, JLANG::JAbstractObjectReader< JNullType >, JLANG::JAbstractObjectReader< const T >, JLANG::JAbstractObjectReader< JTail_t >, JLANG::JAbstractObjectReader< JHead_t >, JLANG::JAbstractObjectReader< KM3NETDAQ::KM3NETDAQ::JDAQEvent >, and JLANG::JAbstractObjectReader< JDAQSummaryslice >.

Definition at line 90 of file JObjectIterator.hh.

91  {
92  skip_type i = 0;
93 
94  for ( ; i != ns && hasNext(); ++i) {
95  next();
96  }
97 
98  return i;
99  }
unsigned int skip_type
Type definition for number of objects to skip.
std::vector< size_t > ns
virtual const pointer_type & next()=0
Get next element.
virtual bool hasNext()=0
Check availability of next element.

Member Data Documentation

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

throw option

Set default throw option to true.

Definition at line 28 of file JThrow.hh.

template<class T >
std::istream& JLANG::JStreamObjectIterator< T >::__in
protectedinherited

Definition at line 51 of file JStreamObjectIterator.hh.

template<class T>
T JLANG::JAbstractObjectIterator< T >::object
protectedinherited

object

Definition at line 34 of file JAbstractObjectIterator.hh.

template<class T>
bool JLANG::JAbstractObjectIterator< T >::has_next
protectedinherited

status

Definition at line 35 of file JAbstractObjectIterator.hh.


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