File: CifString.C

package info (click to toggle)
librcsb-core-wrapper 1.005-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,576 kB
  • sloc: xml: 122,915; cpp: 25,250; ansic: 3,736; makefile: 1,033; sh: 772; lex: 294; yacc: 235; perl: 213; python: 121; csh: 30
file content (293 lines) | stat: -rw-r--r-- 10,498 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//$$FILE$$
//$$VERSION$$
//$$DATE$$
//$$LICENSE$$


#include <string>
#include <vector>

#include "Exceptions.h"
#include "CifString.h"


using std::string;
using std::vector;


const string CifString::CIF_DDL_CATEGORY_BLOCK("datablock");
const string CifString::CIF_DDL_CATEGORY_DATABLOCK("datablock");
const string CifString::CIF_DDL_CATEGORY_DATABLOCK_METHODS("datablock_methods");
const string CifString::CIF_DDL_CATEGORY_ITEM("item");
const string CifString::CIF_DDL_CATEGORY_ITEM_LINKED("item_linked");
const string CifString::CIF_DDL_CATEGORY_PDBX_ITEM_LINKED_GROUP("pdbx_item_linked_group");
const string CifString::CIF_DDL_CATEGORY_PDBX_ITEM_LINKED_GROUP_LIST("pdbx_item_linked_group_list");
const string CifString::CIF_DDL_CATEGORY_CATEGORY("category");
const string CifString::CIF_DDL_CATEGORY_CATEGORY_EXAMPLES("category_examples");
const string CifString::CIF_DDL_CATEGORY_NDB_CATEGORY_EXAMPLES("ndb_category_examples");
const string CifString::CIF_DDL_CATEGORY_CATEGORY_KEY("category_key");
const string CifString::CIF_DDL_CATEGORY_CATEGORY_GROUP("category_group");
const string CifString::CIF_DDL_CATEGORY_CATEGORY_GROUP_LIST("category_group_list");
const string CifString::CIF_DDL_CATEGORY_CATEGORY_METHODS("category_methods");
const string CifString::CIF_DDL_CATEGORY_SUB_CATEGORY("sub_category");
const string CifString::CIF_DDL_CATEGORY_SUB_CATEGORY_EXAMPLES("sub_category_examples");
const string CifString::CIF_DDL_CATEGORY_SUB_CATEGORY_METHODS("sub_category_methods");
const string CifString::CIF_DDL_CATEGORY_ITEM_SUB_CATEGORY("item_sub_category");
const string CifString::CIF_DDL_CATEGORY_ITEM_TYPE("item_type");
const string CifString::CIF_DDL_CATEGORY_ITEM_TYPE_CONDITIONS("item_type_conditions");
const string CifString::CIF_DDL_CATEGORY_ITEM_METHODS("item_methods");
const string CifString::CIF_DDL_CATEGORY_ITEM_TYPE_LIST("item_type_list");
const string CifString::CIF_DDL_CATEGORY_ITEM_STRUCTURE("item_structure");
const string CifString::CIF_DDL_CATEGORY_ITEM_STRUCTURE_LIST("item_structure_list");
const string CifString::CIF_DDL_CATEGORY_ITEM_DESCRIPTION("item_description");
const string CifString::CIF_DDL_CATEGORY_NDB_ITEM_DESCRIPTION("ndb_item_description");
const string CifString::CIF_DDL_CATEGORY_NDB_CATEGORY_DESCRIPTION("ndb_category_description");
const string CifString::CIF_DDL_CATEGORY_ITEM_EXAMPLES("item_examples");
const string CifString::CIF_DDL_CATEGORY_NDB_ITEM_EXAMPLES("ndb_item_examples");
const string CifString::CIF_DDL_CATEGORY_ITEM_DEPENDENT("item_dependent");
const string CifString::CIF_DDL_CATEGORY_ITEM_RELATED("item_related");
const string CifString::CIF_DDL_CATEGORY_ITEM_RANGE("item_range");
const string CifString::CIF_DDL_CATEGORY_ITEM_ENUMERATION("item_enumeration");
const string CifString::CIF_DDL_CATEGORY_NDB_ITEM_ENUMERATION("ndb_item_enumeration");
const string CifString::CIF_DDL_CATEGORY_ITEM_DEFAULT("item_default");
const string CifString::CIF_DDL_CATEGORY_ITEM_ALIASES("item_aliases");
const string CifString::CIF_DDL_CATEGORY_DICTIONARY("dictionary");
const string CifString::CIF_DDL_CATEGORY_DICTIONARY_HISTORY("dictionary_history");
const string CifString::CIF_DDL_CATEGORY_ITEM_UNITS("item_units");
const string CifString::CIF_DDL_CATEGORY_ITEM_UNITS_LIST("item_units_list");
const string CifString::CIF_DDL_CATEGORY_ITEM_UNITS_CONVERSION("item_units_conversion");
const string CifString::CIF_DDL_CATEGORY_METHOD_LIST("method_list");

const string CifString::CIF_DDL_ITEM_ID("id");
const string CifString::CIF_DDL_ITEM_CATEGORY_ID("category_id");
const string CifString::CIF_DDL_ITEM_SUB_CATEGORY_ID("sub_category_id");
const string CifString::CIF_DDL_ITEM_METHOD_ID("method_id");
const string CifString::CIF_DDL_ITEM_PARENT_NAME("parent_name");
const string CifString::CIF_DDL_ITEM_CHILD_NAME("child_name");
const string CifString::CIF_DDL_ITEM_CHILD_CATEGORY_ID("child_category_id");
const string CifString::CIF_DDL_ITEM_PARENT_CATEGORY_ID("parent_category_id");
const string CifString::CIF_DDL_ITEM_LINK_GROUP_ID("link_group_id");
const string CifString::CIF_DDL_ITEM_LABEL("label");
const string CifString::CIF_DDL_ITEM_CONTEXT("context");
const string CifString::CIF_DDL_ITEM_CONDITION_ID("condition_id");
const string CifString::CIF_DDL_ITEM_ALIAS_NAME("alias_name");
const string CifString::CIF_DDL_ITEM_DICTIONARY("dictionary");
const string CifString::CIF_DDL_ITEM_TITLE("title");
const string CifString::CIF_DDL_ITEM_VERSION("version");
const string CifString::CIF_DDL_ITEM_NAME("name");
const string CifString::CIF_DDL_ITEM_CODE("code");
const string CifString::CIF_DDL_ITEM_PRIMITIVE_CODE("primitive_code");
const string CifString::CIF_DDL_ITEM_CONSTRUCT("construct");
const string CifString::CIF_DDL_ITEM_ORGANIZATION("organization");
const string CifString::CIF_DDL_ITEM_INDEX("index");
const string CifString::CIF_DDL_ITEM_DIMENSION("dimension");
const string CifString::CIF_DDL_ITEM_DATABLOCK_ID("datablock_id");
const string CifString::CIF_DDL_ITEM_DESCRIPTION("description");
const string CifString::CIF_DDL_ITEM_NDB_DESCRIPTION("ndb_description");
const string CifString::CIF_DDL_ITEM_CASE("case");
const string CifString::CIF_DDL_ITEM_MANDATORY_CODE("mandatory_code");
const string CifString::CIF_DDL_ITEM_DETAIL("detail");
const string CifString::CIF_DDL_ITEM_MAXIMUM("maximum");
const string CifString::CIF_DDL_ITEM_MINIMUM("minimum");
const string CifString::CIF_DDL_ITEM_VALUE("value");
const string CifString::CIF_DDL_ITEM_DEPENDENT_NAME("dependent_name");
const string CifString::CIF_DDL_ITEM_RELATED_NAME("related_name");
const string CifString::CIF_DDL_ITEM_FUNCTION_CODE("function_code");
const string CifString::CIF_DDL_ITEM_OFFSET("file_offset");
const string CifString::CIF_DDL_ITEM_OPERATOR("operator");
const string CifString::CIF_DDL_ITEM_FACTOR("factor");
const string CifString::CIF_DDL_ITEM_FROM_CODE("from_code");
const string CifString::CIF_DDL_ITEM_TO_CODE("to_code");
const string CifString::CIF_DDL_ITEM_UPDATE("update");
const string CifString::CIF_DDL_ITEM_REVISION("revision");
const string CifString::CIF_DDL_ITEM_INLINE("item_inline");
const string CifString::CIF_DDL_ITEM_LANGUAGE("item_language");
const string CifString::CIF_DDL_ITEM_PARENT_ID("parent_id");


const string CifString::UnknownValue("?");
const string CifString::InapplicableValue(".");


void CifString::MakeCifItem(string& cifItem, const string& categoryName,
  const string& attribName)
{
    if (categoryName.empty())
    {
        throw EmptyValueException("Empty category name",
          "CifString::MakeCifItem");
    }

    if (attribName.empty())
    {
        throw EmptyValueException("Empty attribute name",
          "CifString::MakeCifItem");
    }

    cifItem = PREFIX_CHAR + categoryName + JOIN_CHAR + attribName;
}


void CifString::MakeCifItems(vector<string>& cifItems,
  const string& categoryName, const vector<string>& attribsNames)
{
    cifItems.assign(attribsNames.size(), string());

    for (unsigned int attribI = 0; attribI < attribsNames.size(); ++attribI)
    {
        MakeCifItem(cifItems[attribI], categoryName, attribsNames[attribI]);
    }
}


void CifString::GetItemFromCifItem(string& itemName, const string& cifItem)
{
    /* ----------------------------------------------------------------------
     Purpose: CifString::GetItemFromCifItem(itemName, cifItem)

     Get the itemName part of an item name (ie. _<category>.<itemName>)
     Return 1 for success or 0 otherwise.

     *--------------------------------------------------------------------- */

    unsigned int k, ilen;

    if (cifItem.empty() || (cifItem[0] != '_') || (ilen = cifItem.size()) < 4)
    {
        throw EmptyValueException("Invalid CIF item \"" + cifItem + "\"",
          "CifString::GetItemFromCifItem");
    }

    for (k = 1; k < ilen; ++k)
    {
        if (cifItem[k] == JOIN_CHAR)
            break;
    }

    if ((k == 1) || (k == (ilen - 1)))
    {
        throw EmptyValueException("Invalid CIF item \"" + cifItem + "\"",
          "CifString::GetItemFromCifItem");
    }

    itemName.clear();

    for (unsigned int i = k + 1; i < ilen; ++i)
    {
        itemName.push_back(cifItem[i]);
    }
}


void CifString::GetCategoryFromCifItem(string& categoryName,
    const string& cifItem)
/* ----------------------------------------------------------------------
 Purpose: CifString::GetCategoryFromCifItem(categoryName, cifItem)

 Get the category part of an item name (ie. _<category>.<keyword>)
 Return 1 for success or 0 otherwise.

 * ---------------------------------------------------------------------- */
{
    if (cifItem.empty() || (cifItem[0] != '_'))
    {
        throw EmptyValueException("Invalid CIF item \"" + cifItem + "\"",
          "CifString::GetCategoryFromCifItem");
    }

    // Skip the first char and search for a join character
    string::size_type dotIndex = cifItem.find(JOIN_CHAR, 1);

    if (dotIndex == string::npos)
    {
        throw EmptyValueException("Invalid CIF item \"" + cifItem + "\"",
          "CifString::GetCategoryFromCifItem");
#ifdef VLAD_DEL
        // If join char not found, set its index to be the end of the string.
        dotIndex = cifItem.size();
#endif
    }

    categoryName.clear();

    // Copy from the first char to the character prior to the dot char.
    categoryName.assign(cifItem, 1, dotIndex - 1);
}


bool CifString::IsEmptyValue(const string& value)
{
    if (value.empty() || (value == InapplicableValue) ||
      (value == UnknownValue))
    {
        return (true);
    }
    else
    {
        return (false);
    }
}


bool CifString::IsUnknownValue(const string& value)
{
    if (value.empty() || (value == UnknownValue))
    {
        return (true);
    }
    else
    {
        return (false);
    }
}


bool CifString::IsSpecialChar(const char charValue)
{
    switch (charValue)
    {
        case '(':
        case ')':
        case '[':
        case ']':
        case '{':
        case '}':
        {
            return (true);
            break;
        }
        default:
        {
            return (false);
            break;
        }
    }
}


bool CifString::IsSpecialFirstChar(const char charValue)
{
    switch (charValue)
    {
        case '$':
        case '#':
        case '_':
        case ';':
        case '(':
        case ')':
        case '[':
        case ']':
        case '{':
        case '}':
        {
            return (true);
            break;
        }
        default:
        {
            return (false);
            break;
        }
    }
}