g4tools  5.4.0
zb_manager
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_sg_zb_manager
5 #define tools_sg_zb_manager
6 
7 #include "render_manager"
8 
9 #ifdef TOOLS_MEM
10 #include "../mem"
11 #endif
12 
13 #include <map>
14 
15 namespace tools {
16 namespace sg {
17 
18 class zb_manager : public virtual render_manager {
19  typedef render_manager parent;
20 public:
22  virtual void* cast(const std::string& a_class) const {
23  if(void* p = cmp_cast<zb_manager>(this,a_class)) {return p;}
24  else return 0;
25  }
26 public:
27  virtual bool begin_render(int,int,unsigned int,unsigned int,float,float,float,float,bool = true) {return true;}
28  virtual void end_render() {}
29 
30  virtual unsigned int create_texture(const img_byte& a_img,bool /*a_NEAREST*/) {
31  m_gen_id++; //never return 0.
32  m_gstos[m_gen_id] = a_img;
33  return m_gen_id;
34  }
35 
36  virtual unsigned int create_gsto_from_data(size_t,const float*) {return 0;}
37 
38  virtual bool is_gsto_id_valid(unsigned int a_id) const {
39  gstos_t::const_iterator it = m_gstos.find(a_id);
40  if(it==m_gstos.end()) return false;
41  return true;
42  }
43  virtual void delete_gsto(unsigned int a_id) {
44  gstos_t::iterator it = m_gstos.find(a_id);
45  if(it!=m_gstos.end()) m_gstos.erase(it);
46  }
47 
48  //
49  virtual gsto_mode get_gsto_mode() const {return gsto_memory;}
50  virtual void set_gsto_mode(gsto_mode) {}
51  virtual void available_gsto_modes(std::vector<std::string>& a_v) {a_v.clear();}
52  virtual void available_not_memory_gsto_mode(std::string& a_s) const {a_s.clear();}
53  virtual size_t used_texture_memory() const {return 0;}
54  virtual size_t gstos_size() const {return 0;}
55 public:
57 #ifdef TOOLS_MEM
58  mem::increment(s_class().c_str());
59 #endif
60  }
61  virtual ~zb_manager(){
62  m_gstos.clear();
63 #ifdef TOOLS_MEM
64  mem::decrement(s_class().c_str());
65 #endif
66  }
67 public:
68  zb_manager(const zb_manager& a_from)
69  :parent(a_from)
70  ,m_gen_id(0)
71  ,m_gstos()
72  {
73 #ifdef TOOLS_MEM
74  mem::increment(s_class().c_str());
75 #endif
76  }
77  zb_manager& operator=(const zb_manager& a_from){
78  if(&a_from==this) return *this;
79  m_gen_id = 0;
80  m_gstos.clear();
81  return *this;
82  }
83 public:
84  bool find(unsigned int a_id,img_byte& a_img) {
85  gstos_t::iterator it = m_gstos.find(a_id);
86  if(it==m_gstos.end()) return false;
87  a_img = (*it).second;
88  return true;
89  }
90  //void cleanup() {}
91  void delete_gstos() {m_gstos.clear();}
92 protected:
93  unsigned int m_gen_id;
94  typedef std::map<unsigned int,img_byte> gstos_t;
95  gstos_t m_gstos; //only textures for the moment.
96 };
97 
98 }}
99 
100 #endif
tools::sg::zb_manager::get_gsto_mode
virtual gsto_mode get_gsto_mode() const
Definition: zb_manager:49
tools::img< unsigned char >
tools::sg::gsto_mode
gsto_mode
Definition: enums:172
tools::sg::zb_manager::delete_gstos
void delete_gstos()
Definition: zb_manager:91
tools::sg::zb_manager::zb_manager
zb_manager(const zb_manager &a_from)
Definition: zb_manager:68
tools::sg::zb_manager::available_gsto_modes
virtual void available_gsto_modes(std::vector< std::string > &a_v)
Definition: zb_manager:51
tools::sg::zb_manager::gstos_size
virtual size_t gstos_size() const
Definition: zb_manager:54
tools::sg::zb_manager::create_texture
virtual unsigned int create_texture(const img_byte &a_img, bool)
Definition: zb_manager:30
TOOLS_SCLASS
#define TOOLS_SCLASS(a_name)
Definition: S_STRING:41
tools::sg::zb_manager::is_gsto_id_valid
virtual bool is_gsto_id_valid(unsigned int a_id) const
Definition: zb_manager:38
tools::sg::zb_manager::set_gsto_mode
virtual void set_gsto_mode(gsto_mode)
Definition: zb_manager:50
render_manager
tools::sg::render_manager
Definition: render_manager:16
tools::sg::zb_manager::m_gstos
gstos_t m_gstos
Definition: zb_manager:95
tools::sg::zb_manager::m_gen_id
unsigned int m_gen_id
Definition: zb_manager:93
tools::sg::zb_manager::delete_gsto
virtual void delete_gsto(unsigned int a_id)
Definition: zb_manager:43
tools::sg::zb_manager
Definition: zb_manager:18
tools::sg::zb_manager::cast
virtual void * cast(const std::string &a_class) const
Definition: zb_manager:22
tools::sg::zb_manager::operator=
zb_manager & operator=(const zb_manager &a_from)
Definition: zb_manager:77
tools::sg::zb_manager::~zb_manager
virtual ~zb_manager()
Definition: zb_manager:61
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::gsto_memory
@ gsto_memory
Definition: enums:173
tools::sg::zb_manager::gstos_t
std::map< unsigned int, img_byte > gstos_t
Definition: zb_manager:94
tools::sg::zb_manager::end_render
virtual void end_render()
Definition: zb_manager:28
tools::sg::zb_manager::used_texture_memory
virtual size_t used_texture_memory() const
Definition: zb_manager:53
tools::sg::zb_manager::begin_render
virtual bool begin_render(int, int, unsigned int, unsigned int, float, float, float, float, bool=true)
Definition: zb_manager:27
tools::sg::zb_manager::available_not_memory_gsto_mode
virtual void available_not_memory_gsto_mode(std::string &a_s) const
Definition: zb_manager:52
tools::sg::zb_manager::find
bool find(unsigned int a_id, img_byte &a_img)
Definition: zb_manager:84
tools::sg::zb_manager::zb_manager
zb_manager()
Definition: zb_manager:56
tools::sg::zb_manager::create_gsto_from_data
virtual unsigned int create_gsto_from_data(size_t, const float *)
Definition: zb_manager:36