inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_sg_f2plot 00005 #define inlib_sg_f2plot 00006 00007 // Connexion inlib/func to sg/plotter. 00008 00009 // Inheritance : 00010 #include "plottable" 00011 00012 //#include "../func" 00013 00014 #include "../smanip" 00015 00016 namespace inlib { 00017 namespace sg { 00018 00019 template <class T> 00020 class f1d2plot : public virtual func1D { 00021 public: 00022 static const std::string& s_class() { 00023 static const std::string s_v("inlib::sg::f1d2plot"); 00024 return s_v; 00025 } 00026 public: 00027 virtual void* cast(const std::string& a_class) const { 00028 if(void* p = inlib::cmp_cast<f1d2plot>(this,a_class)) {return p;} 00029 return func1D::cast(a_class); 00030 } 00031 public: //plottable 00032 virtual plottable* copy() const {return new f1d2plot(*this);} 00033 virtual bool is_valid() const {return true;} 00034 virtual std::string name(){return m_name;} 00035 virtual void set_name(const std::string& a_s) {m_name = a_s;} 00036 virtual std::string title(){return m_title;} 00037 virtual std::string legend(){return m_legend;} 00038 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 00039 00040 virtual std::string infos(const std::string& a_opts){ 00041 std::string f_lf("\n"); 00042 std::string sinfos; 00043 std::vector<std::string> words; 00044 inlib::words(a_opts," ",false,words); 00045 std::vector<std::string>::const_iterator it; 00046 for(it=words.begin();it!=words.end();++it) { 00047 if(((*it)=="name") && m_name.size()) { 00048 if(sinfos.size()) sinfos += f_lf; 00049 sinfos += "Name\n"; 00050 sinfos += m_name; 00051 } 00052 } 00053 return sinfos; 00054 } 00055 public: //func1D 00056 virtual bool value(float aX,float& aValue) const { 00057 if(!m_data.in_domain(aX)) return false; 00058 aValue = (float)m_data.value(aX); 00059 return true; 00060 } 00061 00062 virtual unsigned int x_steps() const {return 100;} 00063 virtual float x_min() const {return 0;} 00064 virtual float x_max() const {return 0;} 00065 public: 00066 f1d2plot(const T& a_data) 00067 :m_data(a_data) 00068 {} 00069 virtual ~f1d2plot(){} 00070 protected: 00071 f1d2plot(const f1d2plot& a_from) 00072 :plottable(a_from),func1D(a_from) 00073 ,m_data(a_from.m_data) 00074 ,m_name(a_from.m_name) 00075 ,m_legend(a_from.m_legend) 00076 ,m_title(a_from.m_title) 00077 {} 00078 private: 00079 f1d2plot& operator=(const f1d2plot&){return *this;} 00080 private: 00081 const T& m_data; 00082 std::string m_name; 00083 std::string m_legend; 00084 std::string m_title; 00085 }; 00086 00087 }} 00088 00089 #endif