// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_sg_sf_vec #define tools_sg_sf_vec #include "sf" namespace tools { namespace sg { template //exa sf_vec class sf_vec : public bsf { typedef bsf parent; public: static const std::string& s_class() { static const std::string s_v("tools::sg::sf_vec<"+stype(T())+","+stype(TT())+">"); return s_v; } virtual void* cast(const std::string& a_class) const { if(void* p = cmp_cast< sf_vec >(this,a_class)) {return p;} return parent::cast(a_class); } virtual const std::string& s_cls() const {return s_class();} public: virtual bool write(io::iwbuf& a_buffer) { const T& vec = parent::m_value; const TT* d = get_data(vec); return a_buffer.write_vec(vec.size(),d); } virtual bool read(io::irbuf& a_buffer) { T& vec = parent::m_value; uint32 n; TT* v; if(!a_buffer.read_vec(n,v)) { //::printf("debug : sf_vec::read : failed(0).\n"); return false; } if(n!=vec.size()) { delete [] v; #ifdef TOOLS_MEM mem::decrement(s_new().c_str()); #endif //::printf("debug : sf_vec::read : failed(1) : %d (expected %d).\n", // n,vec.size()); return false; } for(uint32 index=0;index