g4tools  5.4.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
tools::xml::styles Class Reference

Public Types

typedef std::pair< std::string, std::string > style_item_t
 
typedef std::vector< style_item_tstyle_t
 
typedef std::pair< std::string, style_tnamed_style_t
 
typedef std::pair< std::string, std::string > alias_t
 
typedef sg::style_colormap cmap_t
 

Public Member Functions

 styles (std::ostream &a_out)
 
virtual ~styles ()
 
 styles (const styles &a_from)
 
stylesoperator= (const styles &a_from)
 
std::ostream & out () const
 
const sg::cmaps_tcmaps () const
 
sg::cmaps_tcmaps ()
 
const std::vector< named_style_t > & named_styles () const
 
std::vector< named_style_t > & named_styles ()
 
const std::vector< alias_t > & aliases () const
 
std::vector< alias_t > & aliases ()
 
const style_tfind_style (const std::string &a_name) const
 
void find_styles (const std::string &a_pattern, std::vector< std::string > &a_v) const
 
void add_style (const std::string &a_name, const style_t &a_style)
 
void remove_styles (const std::string &a_pattern)
 
void append (const styles &a_from)
 
bool is_alias (const std::string &a_wanted, std::string &a_style) const
 
template<class T >
bool res_value (const style_t &a_sty, const std::string &a_key, T &a_v, const std::string &a_msg) const
 
template<class T >
bool res_value (const std::string &a_style, const std::string &a_key, T &a_v) const
 
bool res_color (const style_t &a_sty, const std::string &a_key, colorf &a_color, const std::string &a_msg) const
 
bool res_color (const std::string &a_style, const std::string &a_key, colorf &a_color) const
 
bool res_bool (const style_t &a_sty, const std::string &a_key, bool &a_v, const std::string &a_msg) const
 
bool res_bool (const std::string &a_style, const std::string &a_key, bool &a_v) const
 
template<class T >
bool res_sg_style (const std::string &a_style, T &a_sg_style) const
 
bool find_colormap (const std::string &a_name, cmap_t &a_cmap) const
 
void add_colormap (const std::string &a_name, const cmap_t &a_cmap)
 
void find_plotter_styles (std::vector< std::string > &a_v) const
 
void dump ()
 
bool print_plotter_style (std::ostream &a_out, const std::string &a_style)
 
void list_plotter_styles (std::ostream &a_out)
 

Static Public Member Functions

static bool is_plotter_style (const style_t &a_sty)
 

Protected Attributes

std::ostream & m_out
 
std::vector< named_style_tm_named_styles
 
std::vector< alias_tm_aliases
 
sg::cmaps_t m_cmaps
 

Detailed Description

Definition at line 17 of file styles.

Member Typedef Documentation

◆ alias_t

typedef std::pair<std::string,std::string> tools::xml::styles::alias_t

Definition at line 47 of file styles.

◆ cmap_t

Definition at line 280 of file styles.

◆ named_style_t

typedef std::pair<std::string,style_t> tools::xml::styles::named_style_t

Definition at line 42 of file styles.

◆ style_item_t

typedef std::pair<std::string,std::string> tools::xml::styles::style_item_t

Definition at line 40 of file styles.

◆ style_t

Definition at line 41 of file styles.

Constructor & Destructor Documentation

◆ styles() [1/2]

tools::xml::styles::styles ( std::ostream &  a_out)
inline

Definition at line 19 of file styles.

19 :m_out(a_out){}

◆ ~styles()

virtual tools::xml::styles::~styles ( )
inlinevirtual

Definition at line 20 of file styles.

20 {}

◆ styles() [2/2]

tools::xml::styles::styles ( const styles a_from)
inline

Definition at line 22 of file styles.

23  :m_out(a_from.m_out)
24  ,m_named_styles(a_from.m_named_styles)
25  ,m_aliases(a_from.m_aliases)
26  ,m_cmaps(a_from.m_cmaps)
27  {}

Member Function Documentation

◆ add_colormap()

void tools::xml::styles::add_colormap ( const std::string &  a_name,
const cmap_t a_cmap 
)
inline

Definition at line 287 of file styles.

287  {
288  m_cmaps[a_name] = a_cmap;
289  }

◆ add_style()

void tools::xml::styles::add_style ( const std::string &  a_name,
const style_t a_style 
)
inline

Definition at line 77 of file styles.

77  {
79  if((*it).first==a_name) { //override
80  //::printf("debug : styles::add_style : override : \"%s\"\n",a_name.c_str());
81  (*it).second = a_style;
82  return;
83  }
84  }
85  //::printf("debug : styles::add_style : push_back \"%s\"\n",a_name.c_str());
86  m_named_styles.push_back(named_style_t(a_name,a_style));
87  }

◆ aliases() [1/2]

std::vector<alias_t>& tools::xml::styles::aliases ( )
inline

Definition at line 49 of file styles.

49 {return m_aliases;}

◆ aliases() [2/2]

const std::vector<alias_t>& tools::xml::styles::aliases ( ) const
inline

Definition at line 48 of file styles.

48 {return m_aliases;}

◆ append()

void tools::xml::styles::append ( const styles a_from)
inline

Definition at line 100 of file styles.

100  {
101  //::printf("debug : styles::append ...\n");
102  tools_vforcit(named_style_t,a_from.m_named_styles,it) {
103  //::printf("debug : styles::append \"%s\"\n",(*it).first.c_str());
104  m_named_styles.push_back(*it);
105  }
106  }

◆ cmaps() [1/2]

sg::cmaps_t& tools::xml::styles::cmaps ( )
inline

Definition at line 38 of file styles.

38 {return m_cmaps;}

◆ cmaps() [2/2]

const sg::cmaps_t& tools::xml::styles::cmaps ( ) const
inline

Definition at line 37 of file styles.

37 {return m_cmaps;}

◆ dump()

void tools::xml::styles::dump ( )
inline

Definition at line 310 of file styles.

310  {
312 
313  m_out << "/////////////////////////////////////" << std::endl;
314  m_out << "/// " << (*it).first << std::endl;
315  m_out << "/////////////////////////////////////" << std::endl;
316 
317  const style_t& sty = (*it).second;
318 
319  tools_vforcit(style_item_t,sty,vit) {
320  m_out << " " << (*vit).first << " " << (*vit).second << std::endl;
321  }
322 
323  }
324  }

◆ find_colormap()

bool tools::xml::styles::find_colormap ( const std::string &  a_name,
cmap_t a_cmap 
) const
inline

Definition at line 281 of file styles.

281  {
282  std::map<std::string,cmap_t>::const_iterator it = m_cmaps.find(a_name);
283  if(it==m_cmaps.end()) return false;
284  a_cmap = (*it).second;
285  return true;
286  }

◆ find_plotter_styles()

void tools::xml::styles::find_plotter_styles ( std::vector< std::string > &  a_v) const
inline

Definition at line 303 of file styles.

303  {
304  a_v.clear();
306  if(is_plotter_style((*it).second)) a_v.push_back((*it).first);
307  }
308  }

◆ find_style()

const style_t* tools::xml::styles::find_style ( const std::string &  a_name) const
inline

Definition at line 51 of file styles.

51  {
53  if((*it).first==a_name) return &((*it).second);
54  }
55  return 0;
56  }

◆ find_styles()

void tools::xml::styles::find_styles ( const std::string &  a_pattern,
std::vector< std::string > &  a_v 
) const
inline

Definition at line 70 of file styles.

70  {
71  a_v.clear();
73  if(match((*it).first,a_pattern)) a_v.push_back((*it).first);
74  }
75  }

◆ is_alias()

bool tools::xml::styles::is_alias ( const std::string &  a_wanted,
std::string &  a_style 
) const
inline

Definition at line 108 of file styles.

108  {
109  if(find(m_aliases,a_wanted,a_style)) return true;
110  a_style = a_wanted;
111  return false;
112  }

◆ is_plotter_style()

static bool tools::xml::styles::is_plotter_style ( const style_t a_sty)
inlinestatic

Definition at line 293 of file styles.

293  {
294  tools_vforcit(style_item_t,a_sty,it) {
295  const std::string& key = (*it).first;
296  const std::string& sv = (*it).second;
297  if((key=="tag")&&(sv=="plotter_style")) return true;
298  }
299  return false;
300  }

◆ list_plotter_styles()

void tools::xml::styles::list_plotter_styles ( std::ostream &  a_out)
inline

Definition at line 344 of file styles.

344  {
346  const style_t& sty = (*it).second;
347  if(!styles::is_plotter_style(sty)) continue;
348  a_out << (*it).first << std::endl;
349  }
350  }

◆ named_styles() [1/2]

std::vector<named_style_t>& tools::xml::styles::named_styles ( )
inline

Definition at line 45 of file styles.

45 {return m_named_styles;}

◆ named_styles() [2/2]

const std::vector<named_style_t>& tools::xml::styles::named_styles ( ) const
inline

Definition at line 44 of file styles.

44 {return m_named_styles;}

◆ operator=()

styles& tools::xml::styles::operator= ( const styles a_from)
inline

Definition at line 28 of file styles.

28  {
29  m_named_styles = a_from.m_named_styles;
30  m_aliases = a_from.m_aliases;
31  m_cmaps = a_from.m_cmaps;
32  return *this;
33  }

◆ out()

std::ostream& tools::xml::styles::out ( ) const
inline

Definition at line 35 of file styles.

35 {return m_out;}

◆ print_plotter_style()

bool tools::xml::styles::print_plotter_style ( std::ostream &  a_out,
const std::string &  a_style 
)
inline

Definition at line 326 of file styles.

326  {
327  std::string _beg = a_style+".";
328  bool found = false;
330  const std::string& _name = (*it).first;
331  if((_name==a_style)||is_beg(_name,_beg)) {
332  found = true;
333  a_out << (*it).first << " :" << std::endl;
334  const style_t& sty = (*it).second;
335  tools_vforcit(style_item_t,sty,vit) {
336  if((*vit).first=="tag") continue;
337  a_out << " " << (*vit).first << " " << (*vit).second << std::endl;
338  }
339  }
340  }
341  return found;
342  }

◆ remove_styles()

void tools::xml::styles::remove_styles ( const std::string &  a_pattern)
inline

Definition at line 89 of file styles.

89  {
90  std::vector<named_style_t>::iterator it;
91  for(it=m_named_styles.begin();it!=m_named_styles.end();) {
92  if(match((*it).first,a_pattern)) {
93  it = m_named_styles.erase(it);
94  } else {
95  it++;
96  }
97  }
98  }

◆ res_bool() [1/2]

bool tools::xml::styles::res_bool ( const std::string &  a_style,
const std::string &  a_key,
bool &  a_v 
) const
inline

Definition at line 238 of file styles.

238  {
239  //NOTE : if ret false, we do not set a_color to something.
240 
241  //look if a_style is an alias :
242  std::string style;
243  is_alias(a_style,style);
244 
245  const style_t* sty = find_style(style);
246  if(!sty) {
247  //m_out << "tools::xml::styles::res_color :"
248  // << " style " << sout(style) << " not found."
249  // << std::endl;
250  return false;
251  }
252 
253  return res_bool(*sty,a_key,a_v,style);
254  }

◆ res_bool() [2/2]

bool tools::xml::styles::res_bool ( const style_t a_sty,
const std::string &  a_key,
bool &  a_v,
const std::string &  a_msg 
) const
inline

Definition at line 213 of file styles.

213  {
214  //NOTE : if ret false, we do not set a_v to something.
215  std::string s;
216  if(!find(a_sty,a_key,s)) {
217  if(a_msg.size()) {
218  m_out << "tools::xml::styles::res_bool :"
219  << " key " << sout(a_key) << " not found"
220  << " in style " << sout(a_msg) << "."
221  << std::endl;
222  }
223  return false;
224  }
225  bool v;
226  if(!to(s,v)) {
227  m_out << "tools::xml::styles::res_bool :"
228  << " for key " << sout(a_key) << " not found"
229  << " in style " << sout(a_msg) << "."
230  << " can't convert " << sout(s) << " to bool."
231  << std::endl;
232  return false;
233  }
234  a_v = v;
235  return true;
236  }

◆ res_color() [1/2]

bool tools::xml::styles::res_color ( const std::string &  a_style,
const std::string &  a_key,
colorf a_color 
) const
inline

Definition at line 195 of file styles.

195  {
196  //NOTE : if ret false, we do not set a_color to something.
197 
198  //look if a_style is an alias :
199  std::string style;
200  is_alias(a_style,style);
201 
202  const style_t* sty = find_style(style);
203  if(!sty) {
204  //m_out << "tools::xml::styles::res_color :"
205  // << " style " << sout(style) << " not found."
206  // << std::endl;
207  return false;
208  }
209 
210  return res_color(*sty,a_key,a_color,style);
211  }

◆ res_color() [2/2]

bool tools::xml::styles::res_color ( const style_t a_sty,
const std::string &  a_key,
colorf a_color,
const std::string &  a_msg 
) const
inline

Definition at line 173 of file styles.

173  {
174  //NOTE : if ret false, we do not set a_color to something.
175  std::string s;
176  if(!find(a_sty,a_key,s)) {
177  if(a_msg.size()) {
178  m_out << "tools::xml::styles::res_color :"
179  << " key " << sout(a_key) << " not found"
180  << " in style " << sout(a_msg) << "."
181  << std::endl;
182  }
183  return false;
184  }
185  if(!sg::find_color(m_cmaps,s,a_color)) {
186  m_out << "tools::xml::styles::res_color :"
187  << " key " << sout(a_key) << " is not a color"
188  << " in style " << sout(a_msg) << "."
189  << std::endl;
190  return false;
191  }
192  return true;
193  }

◆ res_sg_style()

template<class T >
bool tools::xml::styles::res_sg_style ( const std::string &  a_style,
T &  a_sg_style 
) const
inline

Definition at line 258 of file styles.

258  {
259  //NOTE : a_sg_style is changed according to what is found.
260  // Then it is not fully reset by this method.
261  const style_t* sty = find_style(a_style);
262  if(!sty) {
263  //could be ok to not find a plotter sub style.
264  //m_out << "tools::sg::gui_viewer::res_sg_style :"
265  // << " style " << sout(a_style) << " not found."
266  // << std::endl;
267  return false;
268  }
269 
270  std::string _s;
271  tools_vforcit(style_item_t,*sty,vit) {
272  if(vit!=(*sty).begin()) _s += "\n";
273  _s += (*vit).first;
274  _s += " ";
275  _s += (*vit).second;
276  }
277  return a_sg_style.from_string(m_out,m_cmaps,_s);
278  }

◆ res_value() [1/2]

template<class T >
bool tools::xml::styles::res_value ( const std::string &  a_style,
const std::string &  a_key,
T &  a_v 
) const
inline

Definition at line 153 of file styles.

153  {
154  //NOTE : if ret false, we do not set a_v to something.
155 
156  //look if a_style is an alias :
157  std::string style;
158  is_alias(a_style,style);
159 
160  const style_t* sty = find_style(style);
161  if(!sty) {
162  //m_out << "tools::xml::styles::res_value :"
163  // << " style " << sout(style) << " not found."
164  // << std::endl;
165  return false;
166  }
167  T v;
168  if(!res_value<T>(*sty,a_key,v,style)) return false;
169  a_v = v;
170  return true;
171  }

◆ res_value() [2/2]

template<class T >
bool tools::xml::styles::res_value ( const style_t a_sty,
const std::string &  a_key,
T &  a_v,
const std::string &  a_msg 
) const
inline

Definition at line 126 of file styles.

126  {
127  //NOTE : if ret false, we do not set a_v to something.
128 
129  std::string _s;
130  if(!find(a_sty,a_key,_s)) {
131  if(a_msg.size()) {
132  m_out << "tools::xml::styles::res_value :"
133  << " key " << sout(a_key) << " not found"
134  << " in style " << sout(a_msg) << "."
135  << std::endl;
136  }
137  return false;
138  }
139  T v;
140  if(!to(_s,v)) {
141  m_out << "tools::xml::styles::res_value :"
142  << " for key " << sout(a_key) << " not found"
143  << " in style " << sout(a_msg) << "."
144  << " can't convert " << sout(_s) << " to value."
145  << std::endl;
146  return false;
147  }
148  a_v = v;
149  return true;
150  }

Member Data Documentation

◆ m_aliases

std::vector<alias_t> tools::xml::styles::m_aliases
protected

Definition at line 355 of file styles.

◆ m_cmaps

sg::cmaps_t tools::xml::styles::m_cmaps
protected

Definition at line 357 of file styles.

◆ m_named_styles

std::vector<named_style_t> tools::xml::styles::m_named_styles
protected

Definition at line 354 of file styles.

◆ m_out

std::ostream& tools::xml::styles::m_out
protected

Definition at line 352 of file styles.


The documentation for this class was generated from the following file:
tools::xml::styles::m_aliases
std::vector< alias_t > m_aliases
Definition: styles:355
tools::xml::styles::is_alias
bool is_alias(const std::string &a_wanted, std::string &a_style) const
Definition: styles:108
tools::xml::styles::m_named_styles
std::vector< named_style_t > m_named_styles
Definition: styles:354
tools::xml::styles::m_cmaps
sg::cmaps_t m_cmaps
Definition: styles:357
tools::match
bool match(const std::string &a_string, const std::string &a_pattern, bool a_check_for_wilds=true)
Definition: smatch:12
tools::sg::find_color
bool find_color(const cmaps_t &a_cmaps, const std::string &a_s, colorf &a_col)
Definition: style_colormap:549
tools::xml::styles::style_item_t
std::pair< std::string, std::string > style_item_t
Definition: styles:40
tools::xml::styles::style_t
std::vector< style_item_t > style_t
Definition: styles:41
tools::is_beg
bool is_beg(const std::string &a_s, const std::string &a_b, bool a_forward=true)
Definition: sbeg:11
tools::find
bool find(const std::map< K, V > &a_map, const K &a_key, V &a_value)
Definition: mapmanip:86
tools::xml::styles::res_color
bool res_color(const style_t &a_sty, const std::string &a_key, colorf &a_color, const std::string &a_msg) const
Definition: styles:173
tools::xml::styles::res_bool
bool res_bool(const style_t &a_sty, const std::string &a_key, bool &a_v, const std::string &a_msg) const
Definition: styles:213
tools::xml::styles::m_out
std::ostream & m_out
Definition: styles:352
tools::to
std::vector< std::string > to(int a_argc, char **a_argv)
Definition: args:507
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::file::found
bool found(const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
Definition: file:507
tools::xml::styles::named_style_t
std::pair< std::string, style_t > named_style_t
Definition: styles:42
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::xml::styles::is_plotter_style
static bool is_plotter_style(const style_t &a_sty)
Definition: styles:293
tools::xml::styles::find_style
const style_t * find_style(const std::string &a_name) const
Definition: styles:51