g4tools  5.4.0
image_reader
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_image_reader
5 #define tools_image_reader
6 
7 #include "forit"
8 
9 #include <string>
10 #include <vector>
11 
12 namespace tools {
13 namespace image {
14 
15 class ireader {
16 public:
17  virtual ~ireader() {}
18 public:
19  virtual ireader* copy() const = 0;
20  virtual bool is(const std::string&) const = 0;
21  virtual bool infos(std::ostream& a_out,const std::string& a_file,
22  unsigned int& a_width,unsigned int& a_height,
23  unsigned int& a_bpp) const = 0;
24  virtual unsigned char* read(std::ostream& a_out,const std::string& a_file,
25  unsigned int& a_width,unsigned int& a_height,
26  unsigned int& a_bpp) const = 0;
27  virtual unsigned char* read_part(std::ostream& a_out,
28  const std::string& a_file,
29  unsigned int a_sx,unsigned int a_sy,
30  unsigned int a_sw,unsigned int a_sh,
31  unsigned int& a_rw,unsigned int& a_rh,
32  unsigned int& a_rbpp) const = 0;
33 };
34 
35 class readers {
36 public:
37  typedef std::pair<std::string,ireader*> named_reader;
38 public:
39  readers(){}
40  virtual ~readers(){_clear();}
41 public:
42  readers(const readers& a_from) {
43  _copy(a_from.m_readers);
44  }
45  readers& operator=(const readers& a_from){
46  if(&a_from==this) return *this;
47  _copy(a_from.m_readers);
48  return *this;
49  }
50 public:
51  void add_reader(const std::string& a_name,ireader* a_reader) {
52  m_readers.push_back(named_reader(a_name,a_reader)); //take ownership of a_reader.
53  }
54  const std::vector<named_reader>& named_readers() const {return m_readers;}
55 protected:
56  void _clear(){
57  tools_vforit(named_reader,m_readers,it) delete (*it).second;
58  m_readers.clear();
59  }
60  void _copy(const std::vector<named_reader>& a_from) {
61  _clear();
62  tools_vforcit(named_reader,a_from,it) {
63  m_readers.push_back(named_reader((*it).first,(*it).second->copy()));
64  }
65  }
66 protected:
67  std::vector<named_reader> m_readers; //have a vector (and not a map) since the order is important.
68 };
69 
70 }}
71 
72 #endif
tools::image::readers::readers
readers(const readers &a_from)
Definition: image_reader:42
tools::image::ireader::read
virtual unsigned char * read(std::ostream &a_out, const std::string &a_file, unsigned int &a_width, unsigned int &a_height, unsigned int &a_bpp) const =0
tools::image::ireader::is
virtual bool is(const std::string &) const =0
tools::image::readers::_clear
void _clear()
Definition: image_reader:56
tools::image::readers::~readers
virtual ~readers()
Definition: image_reader:40
tools::image::ireader::infos
virtual bool infos(std::ostream &a_out, const std::string &a_file, unsigned int &a_width, unsigned int &a_height, unsigned int &a_bpp) const =0
tools::image::readers::readers
readers()
Definition: image_reader:39
tools::image::readers::operator=
readers & operator=(const readers &a_from)
Definition: image_reader:45
tools::image::ireader
Definition: image_reader:15
tools::image::ireader::read_part
virtual unsigned char * read_part(std::ostream &a_out, const std::string &a_file, unsigned int a_sx, unsigned int a_sy, unsigned int a_sw, unsigned int a_sh, unsigned int &a_rw, unsigned int &a_rh, unsigned int &a_rbpp) const =0
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::image::ireader::copy
virtual ireader * copy() const =0
tools::image::readers
Definition: image_reader:35
tools::image::readers::_copy
void _copy(const std::vector< named_reader > &a_from)
Definition: image_reader:60
tools::image::readers::add_reader
void add_reader(const std::string &a_name, ireader *a_reader)
Definition: image_reader:51
forit
tools::image::readers::named_readers
const std::vector< named_reader > & named_readers() const
Definition: image_reader:54
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::image::readers::m_readers
std::vector< named_reader > m_readers
Definition: image_reader:67
tools::image::ireader::~ireader
virtual ~ireader()
Definition: image_reader:17
tools::image::readers::named_reader
std::pair< std::string, ireader * > named_reader
Definition: image_reader:37