Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/xml/styles

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/xml/styles (Version 11.3.0) and /externals/g4tools/include/tools/xml/styles (Version 11.0.p1)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_xml_styles                            4 #ifndef tools_xml_styles
  5 #define tools_xml_styles                            5 #define tools_xml_styles
  6                                                     6 
  7 #include "../vpair"                                 7 #include "../vpair"
  8 #include "../sg/style_colormap"                     8 #include "../sg/style_colormap"
  9 #include "../smatch"                                9 #include "../smatch"
 10 #include "../sout"                                 10 #include "../sout"
 11 #include "../forit"                                11 #include "../forit"
 12 #include "../sbeg"                                 12 #include "../sbeg"
 13                                                    13 
 14 namespace tools {                                  14 namespace tools {
 15 namespace xml {                                    15 namespace xml {
 16                                                    16 
 17 class styles {                                     17 class styles {
 18 public:                                            18 public:
 19   styles(std::ostream& a_out):m_out(a_out){}       19   styles(std::ostream& a_out):m_out(a_out){}
 20   virtual ~styles(){}                              20   virtual ~styles(){}
 21 public:                                            21 public:
 22   styles(const styles& a_from)                     22   styles(const styles& a_from)
 23   :m_out(a_from.m_out)                             23   :m_out(a_from.m_out)
 24   ,m_named_styles(a_from.m_named_styles)           24   ,m_named_styles(a_from.m_named_styles)
 25   ,m_aliases(a_from.m_aliases)                     25   ,m_aliases(a_from.m_aliases)
 26   ,m_cmaps(a_from.m_cmaps)                         26   ,m_cmaps(a_from.m_cmaps)
 27   {}                                               27   {}
 28   styles& operator=(const styles& a_from){         28   styles& operator=(const styles& a_from){
 29     m_named_styles = a_from.m_named_styles;        29     m_named_styles = a_from.m_named_styles;
 30     m_aliases = a_from.m_aliases;                  30     m_aliases = a_from.m_aliases;
 31     m_cmaps = a_from.m_cmaps;                      31     m_cmaps = a_from.m_cmaps;
 32     return *this;                                  32     return *this;
 33   }                                                33   }
 34 public:                                            34 public:
 35   std::ostream& out() const {return m_out;}        35   std::ostream& out() const {return m_out;}
 36                                                    36 
 37   const sg::cmaps_t& cmaps() const {return m_c     37   const sg::cmaps_t& cmaps() const {return m_cmaps;}
 38   sg::cmaps_t& cmaps() {return m_cmaps;}           38   sg::cmaps_t& cmaps() {return m_cmaps;}
 39                                                    39 
 40   typedef std::pair<std::string,std::string> s     40   typedef std::pair<std::string,std::string> style_item_t;
 41   typedef std::vector<style_item_t> style_t;       41   typedef std::vector<style_item_t> style_t;
 42   typedef std::pair<std::string,style_t> named     42   typedef std::pair<std::string,style_t> named_style_t;
 43                                                    43 
 44   const std::vector<named_style_t>& named_styl     44   const std::vector<named_style_t>& named_styles() const {return m_named_styles;}
 45   std::vector<named_style_t>& named_styles() {     45   std::vector<named_style_t>& named_styles() {return m_named_styles;}
 46                                                    46 
 47   typedef std::pair<std::string,std::string> a     47   typedef std::pair<std::string,std::string> alias_t;
 48   const std::vector<alias_t>& aliases() const      48   const std::vector<alias_t>& aliases() const {return m_aliases;}
 49   std::vector<alias_t>& aliases() {return m_al     49   std::vector<alias_t>& aliases() {return m_aliases;}
 50                                                    50 
 51   const style_t* find_style(const std::string&     51   const style_t* find_style(const std::string& a_name) const {
 52     tools_vforcit(named_style_t,m_named_styles     52     tools_vforcit(named_style_t,m_named_styles,it){
 53       if((*it).first==a_name) return &((*it).s     53       if((*it).first==a_name) return &((*it).second);
 54     }                                              54     }
 55     return 0;                                      55     return 0;
 56   }                                                56   }
 57                                                    57 
 58 /*                                                 58 /*
 59   style_t* find_style(const std::string& a_nam     59   style_t* find_style(const std::string& a_name) {
 60     tools_vforit(named_style_t,m_named_styles,     60     tools_vforit(named_style_t,m_named_styles,it){
 61       if((*it).first==a_name) return &((*it).s     61       if((*it).first==a_name) return &((*it).second);
 62     }                                              62     }
 63     return 0;                                      63     return 0;
 64   }                                                64   }
 65   void remove_item_in_style(style_t& a_style,c     65   void remove_item_in_style(style_t& a_style,const std::string& a_item) {
 66     remove<std::string,std::string>(a_style,a_     66     remove<std::string,std::string>(a_style,a_item);
 67   }                                                67   }
 68 */                                                 68 */
 69                                                    69 
 70   void find_styles(const std::string& a_patter     70   void find_styles(const std::string& a_pattern,std::vector<std::string>& a_v) const {
 71     a_v.clear();                                   71     a_v.clear();
 72     tools_vforcit(named_style_t,m_named_styles     72     tools_vforcit(named_style_t,m_named_styles,it){
 73       if(match((*it).first,a_pattern)) a_v.pus     73       if(match((*it).first,a_pattern)) a_v.push_back((*it).first);
 74     }                                              74     }
 75   }                                                75   }
 76                                                    76 
 77   void add_style(const std::string& a_name,con     77   void add_style(const std::string& a_name,const style_t& a_style) {
 78     tools_vforit(named_style_t,m_named_styles,     78     tools_vforit(named_style_t,m_named_styles,it){
 79       if((*it).first==a_name) { //override         79       if((*it).first==a_name) { //override
 80         //::printf("debug : styles::add_style      80         //::printf("debug : styles::add_style : override : \"%s\"\n",a_name.c_str());
 81         (*it).second = a_style;                    81         (*it).second = a_style;
 82         return;                                    82         return;
 83       }                                            83       }
 84     }                                              84     }
 85     //::printf("debug : styles::add_style : pu     85     //::printf("debug : styles::add_style : push_back \"%s\"\n",a_name.c_str());
 86     m_named_styles.push_back(named_style_t(a_n     86     m_named_styles.push_back(named_style_t(a_name,a_style));
 87   }                                                87   }
 88                                                    88 
 89   void remove_styles(const std::string& a_patt     89   void remove_styles(const std::string& a_pattern) {
 90     std::vector<named_style_t>::iterator it;       90     std::vector<named_style_t>::iterator it;
 91     for(it=m_named_styles.begin();it!=m_named_     91     for(it=m_named_styles.begin();it!=m_named_styles.end();) {
 92       if(match((*it).first,a_pattern)) {           92       if(match((*it).first,a_pattern)) {
 93         it = m_named_styles.erase(it);             93         it = m_named_styles.erase(it);
 94       } else {                                     94       } else {
 95         it++;                                      95         it++;
 96       }                                            96       }
 97     }                                              97     }
 98   }                                                98   }
 99                                                    99 
100   void append(const styles& a_from) {             100   void append(const styles& a_from) {
101     //::printf("debug : styles::append ...\n")    101     //::printf("debug : styles::append ...\n");
102     tools_vforcit(named_style_t,a_from.m_named    102     tools_vforcit(named_style_t,a_from.m_named_styles,it) {
103       //::printf("debug : styles::append \"%s\    103       //::printf("debug : styles::append \"%s\"\n",(*it).first.c_str());
104       m_named_styles.push_back(*it);              104       m_named_styles.push_back(*it);
105     }                                             105     }
106   }                                               106   }
107                                                   107 
108   bool is_alias(const std::string& a_wanted,st    108   bool is_alias(const std::string& a_wanted,std::string& a_style) const {
109     if(find(m_aliases,a_wanted,a_style)) retur    109     if(find(m_aliases,a_wanted,a_style)) return true;
110     a_style = a_wanted;                           110     a_style = a_wanted;
111     return false;                                 111     return false;
112   }                                               112   }
113                                                   113 
114 /*                                                114 /*
115   bool res_string(const std::string& a_style,     115   bool res_string(const std::string& a_style,
116                          const std::string& a_    116                          const std::string& a_key,
117                          std::string& a_v) con    117                          std::string& a_v) const {
118     std::map<std::string,style_t>::const_itera    118     std::map<std::string,style_t>::const_iterator it = m_styles.find(a_style);
119     if(it==m_styles.end()) {a_v.clear();return    119     if(it==m_styles.end()) {a_v.clear();return false;}
120     const style_t& sty = (*it).second;            120     const style_t& sty = (*it).second;
121     if(!find(sty,a_key,a_v)) {a_v.clear();retu    121     if(!find(sty,a_key,a_v)) {a_v.clear();return false;}
122     return true;                                  122     return true;
123   }                                               123   }
124 */                                                124 */
125   template <class T>                              125   template <class T>
126   bool res_value(const style_t& a_sty,const st    126   bool res_value(const style_t& a_sty,const std::string& a_key,T& a_v,const std::string& a_msg) const {
127     //NOTE : if ret false, we do not set a_v t    127     //NOTE : if ret false, we do not set a_v to something.
128                                                   128 
129     std::string _s;                               129     std::string _s;
130     if(!find(a_sty,a_key,_s)) {                   130     if(!find(a_sty,a_key,_s)) {
131       if(a_msg.size()) {                          131       if(a_msg.size()) {
132         m_out << "tools::xml::styles::res_valu    132         m_out << "tools::xml::styles::res_value :"
133               << " key " << sout(a_key) << " n    133               << " key " << sout(a_key) << " not found"
134               << " in style " << sout(a_msg) <    134               << " in style " << sout(a_msg) << "."
135               << std::endl;                       135               << std::endl;
136       }                                           136       }
137       return false;                               137       return false;
138     }                                             138     }
139     T v;                                          139     T v;
140     if(!to(_s,v)) {                               140     if(!to(_s,v)) {
141       m_out << "tools::xml::styles::res_value     141       m_out << "tools::xml::styles::res_value :"
142             << " for key " << sout(a_key) << "    142             << " for key " << sout(a_key) << " not found"
143             << " in style " << sout(a_msg) <<     143             << " in style " << sout(a_msg) << "."
144             << " can't convert " << sout(_s) <    144             << " can't convert " << sout(_s) << " to value."
145             << std::endl;                         145             << std::endl;
146       return false;                               146       return false;
147     }                                             147     }
148     a_v = v;                                      148     a_v = v;
149     return true;                                  149     return true;
150   }                                               150   }
151                                                   151 
152   template <class T>                              152   template <class T>
153   bool res_value(const std::string& a_style,co    153   bool res_value(const std::string& a_style,const std::string& a_key,T& a_v) const {
154     //NOTE : if ret false, we do not set a_v t    154     //NOTE : if ret false, we do not set a_v to something.
155                                                   155 
156     //look if a_style is an alias :               156     //look if a_style is an alias :
157     std::string style;                            157     std::string style;
158     is_alias(a_style,style);                      158     is_alias(a_style,style);
159                                                   159 
160     const style_t* sty = find_style(style);       160     const style_t* sty = find_style(style);
161     if(!sty) {                                    161     if(!sty) {
162       //m_out << "tools::xml::styles::res_valu    162       //m_out << "tools::xml::styles::res_value :"
163       //      << " style " << sout(style) << "    163       //      << " style " << sout(style) << " not found."
164       //      << std::endl;                       164       //      << std::endl;
165       return false;                               165       return false;
166     }                                             166     }
167     T v;                                          167     T v;
168     if(!res_value<T>(*sty,a_key,v,style)) retu    168     if(!res_value<T>(*sty,a_key,v,style)) return false;
169     a_v = v;                                      169     a_v = v;
170     return true;                                  170     return true;
171   }                                               171   }
172                                                   172 
173   bool res_color(const style_t& a_sty,const st    173   bool res_color(const style_t& a_sty,const std::string& a_key,colorf& a_color,const std::string& a_msg) const {
174     //NOTE : if ret false, we do not set a_col    174     //NOTE : if ret false, we do not set a_color to something.
175     std::string _s;                            << 175     std::string s;
176     if(!find(a_sty,a_key,_s)) {                << 176     if(!find(a_sty,a_key,s)) {
177       if(a_msg.size()) {                          177       if(a_msg.size()) {
178         m_out << "tools::xml::styles::res_colo    178         m_out << "tools::xml::styles::res_color :"
179               << " key " << sout(a_key) << " n    179               << " key " << sout(a_key) << " not found"
180               << " in style " << sout(a_msg) <    180               << " in style " << sout(a_msg) << "."
181               << std::endl;                       181               << std::endl;
182       }                                           182       }
183       return false;                               183       return false;
184     }                                             184     }
185     if(!sg::find_color(m_cmaps,_s,a_color)) {  << 185     if(!sg::find_color(m_cmaps,s,a_color)) {
186       m_out << "tools::xml::styles::res_color     186       m_out << "tools::xml::styles::res_color :"
187             << " key " << sout(a_key) << " is     187             << " key " << sout(a_key) << " is not a color"
188             << " in style " << sout(a_msg) <<     188             << " in style " << sout(a_msg) << "."
189             << std::endl;                         189             << std::endl;
190       return false;                               190       return false;
191     }                                             191     }
192     return true;                                  192     return true;
193   }                                               193   }
194                                                   194 
195   bool res_color(const std::string& a_style,co    195   bool res_color(const std::string& a_style,const std::string& a_key,colorf& a_color) const {
196     //NOTE : if ret false, we do not set a_col    196     //NOTE : if ret false, we do not set a_color to something.
197                                                   197 
198     //look if a_style is an alias :               198     //look if a_style is an alias :
199     std::string style;                            199     std::string style;
200     is_alias(a_style,style);                      200     is_alias(a_style,style);
201                                                   201 
202     const style_t* sty = find_style(style);       202     const style_t* sty = find_style(style);
203     if(!sty) {                                    203     if(!sty) {
204       //m_out << "tools::xml::styles::res_colo    204       //m_out << "tools::xml::styles::res_color :"
205       //      << " style " << sout(style) << "    205       //      << " style " << sout(style) << " not found."
206       //      << std::endl;                       206       //      << std::endl;
207       return false;                               207       return false;
208     }                                             208     }
209                                                   209 
210     return res_color(*sty,a_key,a_color,style)    210     return res_color(*sty,a_key,a_color,style);
211   }                                               211   }
212                                                   212 
213   bool res_bool(const style_t& a_sty,const std    213   bool res_bool(const style_t& a_sty,const std::string& a_key,bool& a_v,const std::string& a_msg) const {
214     //NOTE : if ret false, we do not set a_v t    214     //NOTE : if ret false, we do not set a_v to something.
215     std::string _s;                            << 215     std::string s;
216     if(!find(a_sty,a_key,_s)) {                << 216     if(!find(a_sty,a_key,s)) {
217       if(a_msg.size()) {                          217       if(a_msg.size()) {
218         m_out << "tools::xml::styles::res_bool    218         m_out << "tools::xml::styles::res_bool :"
219               << " key " << sout(a_key) << " n    219               << " key " << sout(a_key) << " not found"
220               << " in style " << sout(a_msg) <    220               << " in style " << sout(a_msg) << "."
221               << std::endl;                       221               << std::endl;
222       }                                           222       }
223       return false;                               223       return false;
224     }                                             224     }
225     bool v;                                       225     bool v;
226     if(!to(_s,v)) {                            << 226     if(!to(s,v)) {
227       m_out << "tools::xml::styles::res_bool :    227       m_out << "tools::xml::styles::res_bool :"
228             << " for key " << sout(a_key) << "    228             << " for key " << sout(a_key) << " not found"
229             << " in style " << sout(a_msg) <<     229             << " in style " << sout(a_msg) << "."
230             << " can't convert " << sout(_s) < << 230             << " can't convert " << sout(s) << " to bool."
231             << std::endl;                         231             << std::endl;
232       return false;                               232       return false;
233     }                                             233     }
234     a_v = v;                                      234     a_v = v;
235     return true;                                  235     return true;
236   }                                               236   }
237                                                   237 
238   bool res_bool(const std::string& a_style,con    238   bool res_bool(const std::string& a_style,const std::string& a_key,bool& a_v) const {
239     //NOTE : if ret false, we do not set a_col    239     //NOTE : if ret false, we do not set a_color to something.
240                                                   240 
241     //look if a_style is an alias :               241     //look if a_style is an alias :
242     std::string style;                            242     std::string style;
243     is_alias(a_style,style);                      243     is_alias(a_style,style);
244                                                   244 
245     const style_t* sty = find_style(style);       245     const style_t* sty = find_style(style);
246     if(!sty) {                                    246     if(!sty) {
247       //m_out << "tools::xml::styles::res_colo    247       //m_out << "tools::xml::styles::res_color :"
248       //      << " style " << sout(style) << "    248       //      << " style " << sout(style) << " not found."
249       //      << std::endl;                       249       //      << std::endl;
250       return false;                               250       return false;
251     }                                             251     }
252                                                   252 
253     return res_bool(*sty,a_key,a_v,style);        253     return res_bool(*sty,a_key,a_v,style);
254   }                                               254   }
255                                                   255 
256   // for plotter :                                256   // for plotter :
257   template <class T> //T = [style,text_style,l    257   template <class T> //T = [style,text_style,line_style]
258   bool res_sg_style(const std::string& a_style    258   bool res_sg_style(const std::string& a_style,T& a_sg_style) const {
259     //NOTE : a_sg_style is changed according t    259     //NOTE : a_sg_style is changed according to what is found.
260     //       Then it is not fully reset by thi    260     //       Then it is not fully reset by this method.
261     const style_t* sty = find_style(a_style);     261     const style_t* sty = find_style(a_style);
262     if(!sty) {                                    262     if(!sty) {
263       //could be ok to not find a plotter sub     263       //could be ok to not find a plotter sub style.
264       //m_out << "tools::sg::gui_viewer::res_s    264       //m_out << "tools::sg::gui_viewer::res_sg_style :"
265       //      << " style " << sout(a_style) <<    265       //      << " style " << sout(a_style) << " not found."
266       //      << std::endl;                       266       //      << std::endl;
267       return false;                               267       return false;
268     }                                             268     }
269                                                   269 
270     std::string _s;                               270     std::string _s;
271     tools_vforcit(style_item_t,*sty,vit) {        271     tools_vforcit(style_item_t,*sty,vit) {
272       if(vit!=(*sty).begin()) _s += "\n";         272       if(vit!=(*sty).begin()) _s += "\n";
273       _s += (*vit).first;                         273       _s += (*vit).first;
274       _s += " ";                                  274       _s += " ";
275       _s += (*vit).second;                        275       _s += (*vit).second;
276     }                                             276     }
277     return a_sg_style.from_string(m_out,m_cmap    277     return a_sg_style.from_string(m_out,m_cmaps,_s);
278   }                                               278   }
279                                                   279 
280   typedef sg::style_colormap cmap_t;              280   typedef sg::style_colormap cmap_t;
281   bool find_colormap(const std::string& a_name    281   bool find_colormap(const std::string& a_name,cmap_t& a_cmap) const {
282     std::map<std::string,cmap_t>::const_iterat    282     std::map<std::string,cmap_t>::const_iterator it = m_cmaps.find(a_name);
283     if(it==m_cmaps.end()) return false;           283     if(it==m_cmaps.end()) return false;
284     a_cmap = (*it).second;                        284     a_cmap = (*it).second;
285     return true;                                  285     return true;
286   }                                               286   }
287   void add_colormap(const std::string& a_name,    287   void add_colormap(const std::string& a_name,const cmap_t& a_cmap) {
288     m_cmaps[a_name] = a_cmap;                     288     m_cmaps[a_name] = a_cmap;
289   }                                               289   }
290   //void clear_colormaps() {m_cmaps.clear();/*    290   //void clear_colormaps() {m_cmaps.clear();/*add default*/}
291                                                   291 
292 public:                                           292 public:
293   static bool is_plotter_style(const style_t&     293   static bool is_plotter_style(const style_t& a_sty) {
294     tools_vforcit(style_item_t,a_sty,it) {        294     tools_vforcit(style_item_t,a_sty,it) {
295       const std::string& key = (*it).first;       295       const std::string& key = (*it).first;
296       const std::string& sv = (*it).second;       296       const std::string& sv = (*it).second;
297       if((key=="tag")&&(sv=="plotter_style"))     297       if((key=="tag")&&(sv=="plotter_style")) return true;
298     }                                             298     }
299     return false;                                 299     return false;
300   }                                               300   }
301                                                   301 
302 public:                                           302 public:
303   void find_plotter_styles(std::vector<std::st    303   void find_plotter_styles(std::vector<std::string>& a_v) const {
304     a_v.clear();                                  304     a_v.clear();
305     tools_vforcit(named_style_t,m_named_styles    305     tools_vforcit(named_style_t,m_named_styles,it) {
306       if(is_plotter_style((*it).second)) a_v.p    306       if(is_plotter_style((*it).second)) a_v.push_back((*it).first);
307     }                                             307     }
308   }                                               308   }
309                                                   309 
310   void dump() {                                   310   void dump() {
311     tools_vforcit(named_style_t,m_named_styles    311     tools_vforcit(named_style_t,m_named_styles,it) {
312                                                   312 
313       m_out << "//////////////////////////////    313       m_out << "/////////////////////////////////////" << std::endl;
314       m_out << "/// " << (*it).first << std::e    314       m_out << "/// " << (*it).first << std::endl;
315       m_out << "//////////////////////////////    315       m_out << "/////////////////////////////////////" << std::endl;
316                                                   316 
317       const style_t& sty = (*it).second;          317       const style_t& sty = (*it).second;
318                                                   318 
319       tools_vforcit(style_item_t,sty,vit) {       319       tools_vforcit(style_item_t,sty,vit) {
320         m_out << " " << (*vit).first << " " <<    320         m_out << " " << (*vit).first << " " << (*vit).second << std::endl;
321       }                                           321       }
322                                                   322 
323     }                                             323     }
324   }                                               324   }
325                                                   325 
326   bool print_plotter_style(std::ostream& a_out    326   bool print_plotter_style(std::ostream& a_out,const std::string& a_style) {
327     std::string _beg = a_style+".";               327     std::string _beg = a_style+".";
328     bool found = false;                           328     bool found = false;
329     tools_vforcit(named_style_t,m_named_styles    329     tools_vforcit(named_style_t,m_named_styles,it) {
330       const std::string& _name = (*it).first;     330       const std::string& _name = (*it).first;
331       if((_name==a_style)||is_beg(_name,_beg))    331       if((_name==a_style)||is_beg(_name,_beg)) {
332         found = true;                             332         found = true;
333         a_out << (*it).first << " :" << std::e    333         a_out << (*it).first << " :" << std::endl;
334         const style_t& sty = (*it).second;        334         const style_t& sty = (*it).second;
335         tools_vforcit(style_item_t,sty,vit) {     335         tools_vforcit(style_item_t,sty,vit) {
336           if((*vit).first=="tag") continue;       336           if((*vit).first=="tag") continue;
337           a_out << " " << (*vit).first << " "     337           a_out << " " << (*vit).first << " " << (*vit).second << std::endl;
338         }                                         338         }
339       }                                           339       }
340     }                                             340     }
341     return found;                                 341     return found;
342   }                                               342   }
343                                                   343 
344   void list_plotter_styles(std::ostream& a_out    344   void list_plotter_styles(std::ostream& a_out) {
345     tools_vforcit(named_style_t,m_named_styles    345     tools_vforcit(named_style_t,m_named_styles,it) {
346       const style_t& sty = (*it).second;          346       const style_t& sty = (*it).second;
347       if(!styles::is_plotter_style(sty)) conti    347       if(!styles::is_plotter_style(sty)) continue;
348       a_out << (*it).first << std::endl;          348       a_out << (*it).first << std::endl;
349     }                                             349     }
350   }                                               350   }
351 protected:                                        351 protected:
352   std::ostream& m_out;                            352   std::ostream& m_out;
353   //styles :                                      353   //styles :
354   std::vector<named_style_t> m_named_styles;      354   std::vector<named_style_t> m_named_styles;
355   std::vector<alias_t> m_aliases;                 355   std::vector<alias_t> m_aliases;
356   //cmaps :                                       356   //cmaps :
357   sg::cmaps_t m_cmaps;                            357   sg::cmaps_t m_cmaps;
358 };                                                358 };
359                                                   359 
360 }}                                                360 }}
361                                                   361 
362 #include "tree"                                   362 #include "tree"
363 #include "../vmanip"                              363 #include "../vmanip"
364                                                   364 
365 namespace tools {                                 365 namespace tools {
366 namespace xml {                                   366 namespace xml {
367                                                   367 
368 inline void load_style(styles& a_styles,const     368 inline void load_style(styles& a_styles,const tree& a_tree) {
369   std::string name;                               369   std::string name;
370   a_tree.attribute_value("name",name);            370   a_tree.attribute_value("name",name);
371   if(name.empty()) {                              371   if(name.empty()) {
372     a_styles.out() << "tools::sg::gui_viewer::    372     a_styles.out() << "tools::sg::gui_viewer::load_style :"
373           << " <style> without name."             373           << " <style> without name."
374           << std::endl;                           374           << std::endl;
375     return;                                       375     return;
376   }                                               376   }
377                                                   377 
378   styles::style_t sty;                            378   styles::style_t sty;
379                                                   379 
380  {looper _for(a_tree);                            380  {looper _for(a_tree);
381   while(element* _elem = _for.next_element())     381   while(element* _elem = _for.next_element()) {
382                                                   382 
383       if(_elem->name()=="copy") {                 383       if(_elem->name()=="copy") {
384                                                   384 
385         std::string from;                         385         std::string from;
386         _elem->attribute_value("from",from); /    386         _elem->attribute_value("from",from); //expect another style name.
387         if(from.empty()) {                        387         if(from.empty()) {
388           a_styles.out() << "tools::sg::gui_vi    388           a_styles.out() << "tools::sg::gui_viewer::load_style :"
389                          << " <copy> without f    389                          << " <copy> without from."
390                          << std::endl;            390                          << std::endl;
391           return;                                 391           return;
392         }                                         392         }
393                                                   393 
394         const styles::style_t* csty = a_styles    394         const styles::style_t* csty = a_styles.find_style(from);
395         if(!csty) {                               395         if(!csty) {
396           a_styles.out() << "tools::sg::gui_vi    396           a_styles.out() << "tools::sg::gui_viewer::load_style :"
397                      << " <copy> : from " << s    397                      << " <copy> : from " << sout(from) << " not found."
398                      << std::endl;                398                      << std::endl;
399           return;                                 399           return;
400         }                                         400         }
401                                                   401 
402         append(sty,*csty);                        402         append(sty,*csty);
403                                                   403 
404       } else {                                    404       } else {
405         sty.push_back(styles::style_item_t(_el    405         sty.push_back(styles::style_item_t(_elem->name(),_elem->value()));
406       }                                           406       }
407                                                   407 
408   }}                                              408   }}
409                                                   409 
410   if(sty.size()) a_styles.add_style(name,sty);    410   if(sty.size()) a_styles.add_style(name,sty);
411 }                                                 411 }
412                                                   412 
413 inline void load_plotter_style(styles& a_style    413 inline void load_plotter_style(styles& a_styles,const tree& a_tree) {
414   std::string pname;                              414   std::string pname;
415   a_tree.attribute_value("name",pname);           415   a_tree.attribute_value("name",pname);
416   if(pname.empty()) {                             416   if(pname.empty()) {
417     a_styles.out() << "tools::sg::gui_viewer::    417     a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
418           << " <plotter_style> without name."     418           << " <plotter_style> without name."
419           << std::endl;                           419           << std::endl;
420     return;                                       420     return;
421   }                                               421   }
422                                                   422 
423  {styles::style_t sty;                            423  {styles::style_t sty;
424   sty.push_back(styles::style_item_t("tag","pl    424   sty.push_back(styles::style_item_t("tag","plotter_style"));
425                                                   425 
426  {looper _for(a_tree);                            426  {looper _for(a_tree);
427   while(element* _elem = _for.next_element())     427   while(element* _elem = _for.next_element()) {
428                                                   428 
429       if(_elem->name()=="copy") {                 429       if(_elem->name()=="copy") {
430                                                   430 
431         std::string from;                         431         std::string from;
432         _elem->attribute_value("from",from); /    432         _elem->attribute_value("from",from); //expect a plotter_style name.
433         if(from.empty()) {                        433         if(from.empty()) {
434           a_styles.out() << "tools::sg::gui_vi    434           a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
435                 << " <copy> without from."        435                 << " <copy> without from."
436                 << std::endl;                     436                 << std::endl;
437           return;                                 437           return;
438         }                                         438         }
439                                                   439 
440         const styles::style_t* csty = a_styles    440         const styles::style_t* csty = a_styles.find_style(from);
441         if(!csty) {                               441         if(!csty) {
442           a_styles.out() << "tools::sg::gui_vi    442           a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
443                 << " <copy> : from " << sout(f    443                 << " <copy> : from " << sout(from) << " not found."
444                 << std::endl;                     444                 << std::endl;
445           return;                                 445           return;
446         }                                         446         }
447         if(csty->size()) a_styles.add_style(pn    447         if(csty->size()) a_styles.add_style(pname,*csty);
448                                                   448 
449         if(styles::is_plotter_style(*csty)) {     449         if(styles::is_plotter_style(*csty)) {
450           //search all <from>.<sub_style> styl    450           //search all <from>.<sub_style> styles :
451           std::string head = from+".";            451           std::string head = from+".";
452           std::string::size_type l = head.size    452           std::string::size_type l = head.size();
453                                                   453 
454           styles sts(a_styles.out());             454           styles sts(a_styles.out());
455                                                   455 
456           const std::vector<styles::named_styl    456           const std::vector<styles::named_style_t>& nss = a_styles.named_styles();
457           tools_vforcit(styles::named_style_t,    457           tools_vforcit(styles::named_style_t,nss,it){
458             const std::string& name = (*it).fi    458             const std::string& name = (*it).first;
459             if(name.substr(0,l)==head) {          459             if(name.substr(0,l)==head) {
460               std::string tail = name.substr(l    460               std::string tail = name.substr(l,name.size()-l);
461               const styles::style_t& ssty = (*    461               const styles::style_t& ssty = (*it).second;
462               if(ssty.size()) sts.add_style(pn    462               if(ssty.size()) sts.add_style(pname+"."+tail,ssty);
463             }                                     463             }
464           }                                       464           }
465                                                   465 
466           a_styles.append(sts);                   466           a_styles.append(sts);
467                                                   467 
468         }                                         468         }
469                                                   469 
470                                                   470 
471       } else {                                    471       } else {
472         sty.push_back(styles::style_item_t(_el    472         sty.push_back(styles::style_item_t(_elem->name(),_elem->value()));
473       }                                           473       }
474                                                   474 
475   }}                                              475   }}
476                                                   476 
477   if(sty.size()) a_styles.add_style(pname,sty)    477   if(sty.size()) a_styles.add_style(pname,sty);}
478                                                   478 
479  {looper _for(a_tree);                            479  {looper _for(a_tree);
480   while(tree* _tree = _for.next_tree()) {         480   while(tree* _tree = _for.next_tree()) {
481                                                   481 
482       const std::string& tag = _tree->tag_name    482       const std::string& tag = _tree->tag_name();
483       if(tag=="style") {                          483       if(tag=="style") {
484                                                   484 
485         std::string name;                         485         std::string name;
486         _tree->attribute_value("name",name);      486         _tree->attribute_value("name",name);
487         if(name.empty()) {                        487         if(name.empty()) {
488           a_styles.out() << "tools::sg::gui_vi    488           a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
489                 << " <style> without name."       489                 << " <style> without name."
490                 << std::endl;                     490                 << std::endl;
491           return;                                 491           return;
492         }                                         492         }
493                                                   493 
494        {styles::style_t sty;                      494        {styles::style_t sty;
495                                                   495 
496        {looper _for2(*_tree);                     496        {looper _for2(*_tree);
497         while(element* _elem = _for2.next_elem    497         while(element* _elem = _for2.next_element()) {
498           if(_elem->name()=="copy") {             498           if(_elem->name()=="copy") {
499             std::string from;                     499             std::string from;
500             _elem->attribute_value("from",from    500             _elem->attribute_value("from",from); //expect another style name.
501             if(from.empty()) {                    501             if(from.empty()) {
502               a_styles.out() << "tools::sg::gu    502               a_styles.out() << "tools::sg::gui_viewer::load_plotter_style : (2) :"
503                              << " <copy> witho    503                              << " <copy> without from."
504                              << std::endl;        504                              << std::endl;
505               return;                             505               return;
506             }                                     506             }
507             const styles::style_t* csty = a_st    507             const styles::style_t* csty = a_styles.find_style(from);
508             if(!csty) {                           508             if(!csty) {
509               a_styles.out() << "tools::sg::gu    509               a_styles.out() << "tools::sg::gui_viewer::load_plotter_style : (2) :"
510                              << " <copy> : fro    510                              << " <copy> : from " << sout(from) << " not found."
511                             << std::endl;         511                             << std::endl;
512               return;                             512               return;
513             }                                     513             }
514             append(sty,*csty);                    514             append(sty,*csty);
515           } else {                                515           } else {
516             sty.push_back(styles::style_item_t    516             sty.push_back(styles::style_item_t(_elem->name(),_elem->value()));
517           }                                       517           }
518         }}                                        518         }}
519                                                   519 
520         if(sty.size()) {                          520         if(sty.size()) {
521           std::string path = pname+"."+name;      521           std::string path = pname+"."+name;
522           a_styles.add_style(path,sty);           522           a_styles.add_style(path,sty);
523         }}                                        523         }}
524                                                   524 
525       } else {                                    525       } else {
526         a_styles.out() << "tools::sg::gui_view    526         a_styles.out() << "tools::sg::gui_viewer::load_plotter_style :"
527               << " unexpected tag " << sout(ta    527               << " unexpected tag " << sout(tag) << "."
528               << std::endl;                       528               << std::endl;
529       }                                           529       }
530                                                   530 
531   }}                                              531   }}
532                                                   532 
533 }                                                 533 }
534                                                   534 
535 inline bool scan_style_tree(styles& a_styles,c    535 inline bool scan_style_tree(styles& a_styles,const tree& a_tree) {
536                                                   536 
537   if(a_tree.tag_name()!="styles") return false    537   if(a_tree.tag_name()!="styles") return false;
538                                                   538 
539   // look for aliases :                           539   // look for aliases :
540  {looper _for(a_tree);                            540  {looper _for(a_tree);
541   while(element* _elem = _for.next_element())     541   while(element* _elem = _for.next_element()) {
542                                                   542 
543       std::string name;                           543       std::string name;
544       _elem->attribute_value("name",name);        544       _elem->attribute_value("name",name);
545       if(name.empty()) {                          545       if(name.empty()) {
546         a_styles.out() << "tools::sg::gui_view    546         a_styles.out() << "tools::sg::gui_viewer::load_style :"
547               << " <alias> without name."         547               << " <alias> without name."
548               << std::endl;                       548               << std::endl;
549         continue;                                 549         continue;
550       }                                           550       }
551       add<std::string,std::string>(a_styles.al    551       add<std::string,std::string>(a_styles.aliases(),name,_elem->value());
552   }}                                              552   }}
553                                                   553 
554   // scan children :                              554   // scan children :
555  {looper _for(a_tree);                            555  {looper _for(a_tree);
556   while(tree* _tree = _for.next_tree()) {         556   while(tree* _tree = _for.next_tree()) {
557                                                   557 
558       const std::string& tag = _tree->tag_name    558       const std::string& tag = _tree->tag_name();
559       if(tag=="style") {                          559       if(tag=="style") {
560         load_style(a_styles,*_tree);              560         load_style(a_styles,*_tree);
561       } else if(tag=="plotter_style") {           561       } else if(tag=="plotter_style") {
562         load_plotter_style(a_styles,*_tree);      562         load_plotter_style(a_styles,*_tree);
563       }                                           563       }
564                                                   564 
565   }}                                              565   }}
566                                                   566 
567   return true;                                    567   return true;
568 }                                                 568 }
569 }}                                                569 }}
570                                                   570 
571 #endif                                            571 #endif