A.I.M.S


writer.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 /*
35  * Data reader class
36  */
37 #ifndef AIMS_IO_WRITER_H
38 #define AIMS_IO_WRITER_H
39 
41 
42 
43 namespace aims
44 {
45 
47  {
48  public:
49  inline GenericWriter() {};
50  inline GenericWriter( const std::string& filename,
52  _filename( filename ), _options( options ) {}
53  virtual ~GenericWriter() {}
54 
61  template <typename T>
62  bool write( const T & obj, bool ascii = false,
63  const std::string* format = 0 );
64 
66  inline void setFileName( const std::string &fileName )
67  {
69  }
71  inline const std::string &fileName() const { return _filename; }
72  const carto::Object options() const { return _options; }
73  void setOptions( carto::Object opt ) { _options = opt; }
74 
75  virtual std::string writtenObjectType() const = 0;
76  virtual std::string writtenObjectDataType() const = 0;
77  virtual std::string writtenObjectFullType() const = 0;
78 
79  protected:
80  std::string _filename;
82 
83  };
84 
92  template<class T> class Writer : public GenericWriter
93  {
94  public:
95  inline Writer() {};
96  inline Writer( const std::string& filename,
98  GenericWriter( filename, options ) {}
99  virtual ~Writer() {}
100 
107  virtual bool write( const T & obj, bool ascii = false,
108  const std::string* format = 0 );
109 
110  virtual std::string writtenObjectType() const;
111  virtual std::string writtenObjectDataType() const;
112  virtual std::string writtenObjectFullType() const;
113  };
114 
115 }
116 
117 
118 template <class T>
119 inline aims::GenericWriter &
120 operator << ( aims::GenericWriter & writer, const T & thing )
121 {
122  writer.write( thing );
123  return writer;
124 }
125 
126 
127 template <class T>
128 inline aims::Writer<T> &
129 operator << ( aims::Writer<T> & writer, const T & thing )
130 {
131  writer.write( thing );
132  return writer;
133 }
134 
135 
136 #endif
137 
138 
bool write(const T &obj, bool ascii=false, const std::string *format=0)
Finds the correct format and writes the object.
Definition: writer_d.h:74
virtual ~Writer()
Definition: writer.h:99
virtual std::string writtenObjectDataType() const
Definition: writer_d.h:94
virtual ~GenericWriter()
Definition: writer.h:53
void setOptions(carto::Object opt)
Definition: writer.h:73
virtual std::string writtenObjectType() const
Definition: writer_d.h:87
const carto::Object options() const
Definition: writer.h:72
virtual bool write(const T &obj, bool ascii=false, const std::string *format=0)
Finds the correct format and writes the object.
Definition: writer_d.h:108
aims::GenericWriter & operator<<(aims::GenericWriter &writer, const T &thing)
Definition: writer.h:120
std::string _filename
Definition: writer.h:80
virtual std::string writtenObjectType() const =0
virtual std::string writtenObjectFullType() const
Definition: writer_d.h:101
GenericWriter(const std::string &filename, carto::Object options=carto::none())
Definition: writer.h:50
Generic writer for every format of Aims object.
Definition: writer.h:92
virtual std::string writtenObjectDataType() const =0
virtual std::string writtenObjectFullType() const =0
Object none()
Pointer to an empty aims::StructuringElement.
void setFileName(const std::string &fileName)
set output file name
Definition: writer.h:66
Writer(const std::string &filename, carto::Object options=carto::none())
Definition: writer.h:96
carto::Object _options
Definition: writer.h:81
const std::string & fileName() const
get output file name
Definition: writer.h:71