Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JIOToolkit.hh
Go to the documentation of this file.
1 #ifndef __JIO__JIOTOOLKIT__
2 #define __JIO__JIOTOOLKIT__
3 
4 #include "JLang/JException.hh"
5 #include "JIO/JFileStreamIO.hh"
6 #include "JIO/JSTDIO.hh"
7 
8 
9 /**
10  * \file
11  * Auxiliary methods for binary I/O.
12  * \author mdejong
13  */
14 namespace JIO {}
15 namespace JPP { using namespace JIO; }
16 
17 namespace JIO {
18 
21 
22 
23  /**
24  * Load object from input file.
25  *
26  * \param file_name file name
27  * \param object object to be read
28  */
29  template<class T>
30  inline void load(const char* file_name, T& object)
31  {
32  JFileStreamReader in(file_name);
33 
34  if (!in) {
35  throw JFileOpenException(std::string("Error opening file ") + file_name);
36  }
37 
38  in.load(object);
39 
40  if (!in) {
41  throw JFileReadException(std::string("Error reading file ") + file_name);
42  }
43 
44  in.close();
45  }
46 
47 
48  /**
49  * Store object to output file.
50  *
51  * \param file_name file name
52  * \param object object to be written
53  */
54  template<class T>
55  inline void store(const char* file_name, const T& object)
56  {
57  JFileStreamWriter out(file_name);
58 
59  if (!out) {
60  throw JFileOpenException(std::string("Error opening file ") + file_name);
61  }
62 
63  out.store(object);
64  out.close();
65  }
66 }
67 
68 #endif
Exception for opening of file.
Definition: JException.hh:342
Exception for reading of file.
Definition: JException.hh:378
Exceptions.
JWriter & store(const JSerialisable &object)
Write object.
void close()
Close file.
JReader & load(JSerialisable &object)
Read object.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
then awk string
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
Binary buffered file output.
Binary buffered file input.
STD extensions for binary I/O.