jdxblock.h
1 /***************************************************************************
2  jdxblock.h - description
3  -------------------
4  begin : Sun Jun 6 2004
5  copyright : (C) 2000-2014 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef JDXBLOCK_H
19 #define JDXBLOCK_H
20 
21 #include <tjutils/tjstatic.h>
22 #include <tjutils/tjlist.h>
23 
24 #include <odinpara/jdxbase.h>
25 #include <odinpara/jdxtypes.h>
26 
34 
35 
42 class JcampDxBlock : public virtual JcampDxClass, public JDXList, public StaticHandler<JcampDxBlock> {
43 
44  public:
45 
50  JcampDxBlock(const STD_string& title="Parameter List",compatMode mode=notBroken);
51 
52 
57  JcampDxBlock(const JcampDxBlock& block);
58 
59 
64  ~JcampDxBlock();
65 
66 
71  JcampDxBlock& operator = (const JcampDxBlock& block);
72 
77  JcampDxBlock& merge(JcampDxBlock& block, bool onlyUserPars=true);
78 
84 
85 
91  STD_string printval(const STD_string& parameterName, bool append_unit=false) const;
92 
98  bool parseval(const STD_string& parameterName, const STD_string& value);
99 
100 
106  int parseblock(const STD_string& source);
107 
112  unsigned int numof_pars() const;
113 
114 
118  JcampDxClass* get_parameter(const STD_string& ldrlabel);
119 
120 
126  bool parameter_exists(const STD_string& ldrlabel) const;
127 
133  JcampDxBlock& set_prefix(const STD_string& prefix);
134 
140  JcampDxBlock& set_embedded(bool embedded) {embed=embedded; return *this;}
141 
147  bool is_embedded() const {return embed;}
148 
149 
150 
151 
155  JcampDxClass& operator [] (unsigned int i);
156 
160  const JcampDxClass& operator [] (unsigned int i) const;
161 
166 
167 
173 
179 
184 
185 
191  bool operator == (const JcampDxBlock& rhs) const {return !( ((*this)<rhs) || ((rhs<(*this))) );}
192 
193 
194 
201  bool operator < (const JcampDxBlock& rhs) const {return compare(rhs);}
202 
203 
210  bool compare(const JcampDxBlock& rhs, const STD_list<STD_string>* exclude=0, double accuracy=0.0) const;
211 
212 
213 #ifndef NO_CMDLINE
214  JcampDxBlock& parse_cmdline_options(int argc, char *argv[], bool modify=true);
215  STD_map<STD_string,STD_string> get_cmdline_options() const;
216  STD_string get_cmdline_usage(const STD_string& lineprefix="") const;
217 #endif
218 
219 
220  // functions for StaticHandler
221  static void init_static();
222  static void destroy_static();
223 
224  // overwriting virtual functions from JcampDxClass
225  STD_string print() const;
226  JcampDxClass& set_compatmode(compatMode compat_mode);
227  JcampDxClass& set_parmode(parameterMode parameter_mode);
228  JcampDxClass& set_filemode(fileMode file_mode);
229  STD_string get_parx_code(parxCodeType type, const ParxEquiv& equiv=ParxEquiv()) const;
230  STD_ostream& print2stream(STD_ostream& os) const;
231  bool parsevalstring (const STD_string&) {return true;}
232  bool parse(STD_string& parstring);
233  STD_string printvalstring() const {return "";}
234  JcampDxClass* create_copy() const {JcampDxBlock* result=new JcampDxBlock; result->create_copy(*this); return result;}
235  const char* get_typeInfo() const {return "JcampDxBlock";}
236  JcampDxBlock* cast(JcampDxBlock*) {return this;}
237  int load(const STD_string &filename);
238  int write(const STD_string &filename) const;
239  STD_string get_jdx_prefix() const {return "";}
240  STD_string get_jdx_postfix() const {return "";}
241 
242  protected:
243 
248  JcampDxBlock& append_member(JcampDxClass& ldr,const STD_string ldrlabel="");
249 
250 
251 
252 
253  private:
254  friend class JDXwidget;
255 
256  static STD_string extract_parlabel(const STD_string& parstring);
257 
258  STD_string print_header() const;
259  STD_string print_tail() const;
260 
261 
262  JDXList::constiter ldr_exists(const STD_string& label) const;
263  int parse_ldr_list(STD_string& parstring);
264 
265  STD_list<JcampDxClass*>* garbage;
266  bool embed;
267 
268 };
269 
270 
271 
277 #endif
278 
279