// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.

#ifndef tools_sg_sf_rotf
#define tools_sg_sf_rotf

#include "sf"

#include "../lina/rotf"

#include "../HEADER"

namespace tools {
namespace sg {

class sf_rotf : public bsf<rotf> {
  TOOLS_HEADER(sf_rotf,tools::sg::sf_rotf,bsf<rotf>)
public:
  virtual bool write(io::iwbuf& a_buffer) {
    const vec4<float>& vec = m_value.quat();
    const float* d = get_data(vec);
    return a_buffer.write_vec(vec.size(),d);
  }
  virtual bool read(io::irbuf& a_buffer) {
    vec4<float>& vec = m_value.quat();
    uint32 n;
    float* v;
    if(!a_buffer.read_vec(n,v)) return false;
    if(n!=vec.size()) {
      delete [] v;
      return false;
    }
    for(uint32 index=0;index<n;index++) vec[index] = v[index];
    delete [] v;
    return true;
  }
  virtual bool dump(std::ostream&) {
    return true;
  }
  virtual bool s_value(std::string& a_s) const {a_s.clear();return false;}
  virtual bool s2value(const std::string&) {return false;}
public:
  sf_rotf():parent(){}
  sf_rotf(const rotf& a_value):parent(a_value){}
  virtual ~sf_rotf(){}
public:
  sf_rotf(const sf_rotf& a_from):parent(a_from){}
  sf_rotf& operator=(const sf_rotf& a_from){
    parent::operator=(a_from);
    return *this;
  }
public:
  sf_rotf& operator=(const rotf& a_value){
    parent::operator=(a_value);
    return *this;
  }
public: //iv2ps
  void setValue(const vec3f& a_axis,float a_angle) {
    value(rotf(a_axis,a_angle));
  }
  void setValue(const rotf& a_value) {
    value(a_value);
  }
};

}}

#endif
