ODIN
ldrser.h
1 /***************************************************************************
2  ldrser.h - description
3  -------------------
4  begin : Wed Aug 26 2015
5  copyright : (C) 2000-2021 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 LDRSER_H
19 #define LDRSER_H
20 
21 #include <tjutils/tjutils.h>
22 
23 
24 // some defines for Bruker-type strings
25 #define _BRUKER_MODE_STRING_CAP_START_ 1000
26 #define _BRUKER_MODE_STRING_MIN_SIZE_ 256
27 #define _BRUKER_MODE_STRING_CAP_FACTOR_ 3
28 
29 
30 class LDRbase; // forward declaration
31 class LDRblock; // forward declaration
32 
34 
43 enum compatMode {bruker,notBroken};
44 
46 
51 class LDRserBase {
52 
53  public:
54  LDRserBase() : top_level(true), compmode(notBroken) {}
55 
56  virtual STD_string get_default_file_prefix() const = 0;
57  virtual STD_string get_description() const = 0;
58 
59  virtual STD_string get_top_header() const = 0;
60 
61  virtual STD_string get_prefix(const LDRbase& ldr) const = 0;
62  virtual STD_string get_postfix(const LDRbase& ldr) const = 0;
63 
64  virtual STD_string extract_valstring(const STD_string& parstring) const = 0;
65 
66  virtual STD_string remove_comments(const STD_string& parstring) const = 0;
67 
68  virtual STD_string escape_characters(const STD_string& parstring) const = 0;
69  virtual STD_string deescape_characters(const STD_string& parstring) const = 0;
70 
71  virtual STD_string print_string(const STD_string& str) const = 0;
72  virtual STD_string parse_string(const STD_string& parstring) const = 0;
73 
74  virtual char left_string_quote() const = 0;
75  virtual char right_string_quote() const = 0;
76 
77  virtual STD_string get_blocklabel(const STD_string& parstring) const = 0;
78  virtual STD_string get_blockbody(const STD_string& parstring, bool including_delimiters) const = 0;
79 
80  virtual STD_string get_parlabel(const STD_string& parstring) const = 0;
81 
82  virtual void remove_next_ldr(STD_string& parstring) const = 0;
83 
84 
85  compatMode get_jdx_compatmode() const {return compmode;}
86 
87  // for XML
88  mutable bool top_level;
89 
90  // for JCAMP-DX
91  compatMode compmode;
92 };
93 
94 
96 
97 
102 class LDRserJDX : public LDRserBase {
103 
104  public:
105 
106  LDRserJDX(compatMode compat_mode=notBroken) {LDRserBase::compmode=compat_mode;}
107 
108  // overloading virtual functions from LDRserBase
109  STD_string get_default_file_prefix() const {return "jdx";}
110  STD_string get_description() const {return "JCAMP-DX (Joint Committee on Atomic and Molecular Physical Data)";}
111  STD_string get_top_header() const {return "";}
112  STD_string get_prefix(const LDRbase& ldr) const;
113  STD_string get_postfix(const LDRbase& ldr) const;
114  STD_string extract_valstring(const STD_string& parstring) const;
115  STD_string remove_comments(const STD_string& parstring) const;
116  STD_string escape_characters(const STD_string& parstring) const;
117  STD_string deescape_characters(const STD_string& parstring) const;
118  STD_string print_string(const STD_string& str) const;
119  STD_string parse_string(const STD_string& parstring) const;
120  char left_string_quote() const {return '<';}
121  char right_string_quote() const {return '>';}
122  STD_string get_blocklabel(const STD_string& parstring) const;
123  STD_string get_blockbody(const STD_string& parstring, bool including_delimiters) const;
124  STD_string get_parlabel(const STD_string& parstring) const;
125  void remove_next_ldr(STD_string& parstring) const;
126 
127 
128 };
129 
131 
132 
137 class LDRserXML : public LDRserBase {
138 
139  public:
140 
141  // overloading virtual functions from LDRserBase
142  STD_string get_default_file_prefix() const {return "xml";}
143  STD_string get_description() const {return "XML (Extensible Markup Language)";}
144  STD_string get_top_header() const {return "<?xml version=\"1.0\"?>\n";}
145  STD_string get_prefix(const LDRbase& ldr) const;
146  STD_string get_postfix(const LDRbase& ldr) const;
147  STD_string extract_valstring(const STD_string& parstring) const;
148  STD_string remove_comments(const STD_string& parstring) const;
149  STD_string escape_characters(const STD_string& parstring) const;
150  STD_string deescape_characters(const STD_string& parstring) const;
151  STD_string print_string(const STD_string& str) const {return str;}
152  STD_string parse_string(const STD_string& parstring) const;
153  char left_string_quote() const {return '\'';}
154  char right_string_quote() const {return '\'';}
155  STD_string get_blocklabel(const STD_string& parstring) const;
156  STD_string get_blockbody(const STD_string& parstring, bool including_delimiters) const;
157  STD_string get_parlabel(const STD_string& parstring) const;
158  void remove_next_ldr(STD_string& parstring) const;
159 
160  private:
161  STD_string str_between_delimiters(const STD_string& parstring, STD_string& startdelim, STD_string& enddelim) const;
162  static STD_string create_well_formed_tag(const STD_string& ldrlabel);
163 
164 };
165 
166 
167 
168 #endif