Warning, /include/Geant4/tools/sg/sf_vec is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_sf_vec
0005 #define tools_sg_sf_vec
0006
0007 #include "sf"
0008
0009 #include "../tokenize"
0010
0011 namespace tools {
0012 namespace sg {
0013
0014 template <class T,class TT> //exa sf_vec<colorf,float>
0015 class sf_vec : public bsf<T> {
0016 typedef bsf<T> parent;
0017 public:
0018 static const std::string& s_class() {
0019 static const std::string s_v("tools::sg::sf_vec<"+stype(T())+","+stype(TT())+">");
0020 return s_v;
0021 }
0022 virtual void* cast(const std::string& a_class) const {
0023 if(void* p = cmp_cast< sf_vec<T,TT> >(this,a_class)) {return p;}
0024 return parent::cast(a_class);
0025 }
0026 virtual const std::string& s_cls() const {return s_class();}
0027 public:
0028 virtual bool write(io::iwbuf& a_buffer) {
0029 const T& vec = parent::m_value;
0030 const TT* d = get_data(vec);
0031 return a_buffer.write_vec(vec.size(),d);
0032 }
0033 virtual bool read(io::irbuf& a_buffer) {
0034 T& vec = parent::m_value;
0035 uint32 n;
0036 TT* v;
0037 if(!a_buffer.read_vec(n,v)) {
0038 return false;
0039 }
0040 if(n!=vec.size()) {
0041 delete [] v;
0042 return false;
0043 }
0044 for(uint32 index=0;index<n;index++) vec[index] = v[index];
0045 delete [] v;
0046 return true;
0047 }
0048 virtual bool dump(std::ostream& a_out) {
0049 a_out << parent::m_value << std::endl;
0050 return true;
0051 }
0052 virtual bool s_value(std::string& a_s) const {
0053 a_s.clear();
0054 const T& vec = parent::m_value;
0055 for(size_t index=0;index<vec.size();index++) {
0056 if(index) a_s += ' ';
0057 std::ostringstream strm;
0058 strm << vec[index];
0059 a_s += strm.str();
0060 }
0061 return true;
0062 }
0063 virtual bool s2value(const std::string& a_s) {
0064 std::vector<std::string> ws;
0065 words(a_s," ",false,ws);
0066 T& vec = parent::m_value;
0067 if(ws.size()!=vec.size()) return false;
0068 T old_vec = vec;
0069 for(size_t index=0;index<vec.size();index++) {
0070 std::istringstream strm(ws[index].c_str());
0071 TT v;
0072 strm >> v;
0073 if(strm.fail()) {
0074 vec = old_vec;
0075 return false;
0076 }
0077 if(vec[index]!=v) parent::m_touched = true;
0078 vec[index] = v;
0079 }
0080 return true;
0081 }
0082 public:
0083 sf_vec():parent(){}
0084 sf_vec(const T& a_value):parent(a_value){}
0085 virtual ~sf_vec(){}
0086 public:
0087 sf_vec(const sf_vec& a_from)
0088 :parent(a_from){}
0089 sf_vec& operator=(const sf_vec& a_from){
0090 parent::operator=(a_from);
0091 return *this;
0092 }
0093 public:
0094 sf_vec& operator=(const T& a_value){
0095 parent::operator=(a_value);
0096 return *this;
0097 }
0098 sf_vec& operator+=(const T& a_value) {
0099 parent::value(parent::value()+a_value);
0100 return *this;
0101 }
0102 };
0103
0104 }}
0105
0106 #endif