/[escript]/branches/doubleplusgood/dudley/src/TagMap.cpp
ViewVC logotype

Annotation of /branches/doubleplusgood/dudley/src/TagMap.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4261 - (hide annotations)
Wed Feb 27 06:09:33 2013 UTC (6 years, 1 month ago) by jfenwick
File size: 2759 byte(s)
Initial all c++ build.
But ... there are now reinterpret_cast<>'s
1 gross 1044
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 4154 * Copyright (c) 2003-2013 by University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
7     * Primary Business: Queensland, Australia
8     * Licensed under the Open Software License version 3.0
9     * http://www.opensource.org/licenses/osl-3.0.php
10     *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     * Development since 2012 by School of Earth Sciences
13     *
14     *****************************************************************************/
15 gross 1044
16 jfenwick 3981 /************************************************************************************/
17 gross 1044
18 jfenwick 3086 /* Dudley: simple mapping fram names to tag keys via a linked list */
19 gross 1044
20 jfenwick 3981 /************************************************************************************/
21 gross 1044
22     #include "TagMap.h"
23 jfenwick 3227 #include "esysUtils/mem.h"
24     #include "string.h"
25 gross 1044
26 jfenwick 3981 /************************************************************************************/
27 gross 1044
28 jfenwick 3224 void Dudley_TagMap_insert(Dudley_TagMap ** tag_map, const char *name, index_t tag_key)
29 gross 1044 {
30 jfenwick 3224 Dudley_TagMap *map = NULL;
31     if (strlen(name) < 1)
32     {
33     Dudley_setError(VALUE_ERROR, "empty tag name.");
34     return;
35     }
36     if (strchr(name, 32) != NULL)
37     { /* check for space */
38     Dudley_setError(VALUE_ERROR, "tag name may not contain a space.");
39     return;
40     }
41     if (*tag_map == NULL)
42     {
43     map = MEMALLOC(1, Dudley_TagMap);
44     if (Dudley_checkPtr(map))
45     return;
46     map->name = MEMALLOC(strlen(name) + 1, char);
47     if (Dudley_checkPtr(map->name))
48     {
49     MEMFREE(map);
50     }
51     else
52     {
53     strcpy(map->name, name);
54     map->tag_key = tag_key;
55     map->next = NULL;
56     *tag_map = map;
57     }
58     }
59     else
60     {
61     if (strcmp((*tag_map)->name, name) == 0)
62     {
63     (*tag_map)->tag_key = tag_key;
64     }
65     else
66     {
67     Dudley_TagMap_insert(&((*tag_map)->next), name, tag_key);
68     }
69     }
70 gross 1044 }
71    
72 jfenwick 3224 index_t Dudley_TagMap_getTag(Dudley_TagMap * tag_map, const char *name)
73 gross 1044 {
74 jfenwick 3224 char error_msg[LenErrorMsg_MAX];
75     if (tag_map == NULL)
76     {
77     sprintf(error_msg, "Dudley_TagMap_getTag: unknown tag name %s.", name);
78     Dudley_setError(VALUE_ERROR, error_msg);
79     return -1;
80     }
81     else
82     {
83     if (strcmp(tag_map->name, name) == 0)
84     {
85     return tag_map->tag_key;
86     }
87     else
88     {
89     return Dudley_TagMap_getTag(tag_map->next, name);
90     }
91     }
92 gross 1044 }
93 jfenwick 3224
94     bool_t Dudley_TagMap_isValidTagName(Dudley_TagMap * tag_map, const char *name)
95 gross 1044 {
96 jfenwick 3224 if (tag_map == NULL)
97     {
98     return FALSE;
99     }
100     else
101     {
102     if (strcmp(tag_map->name, name) == 0)
103     {
104     return TRUE;
105     }
106     else
107     {
108     return Dudley_TagMap_isValidTagName(tag_map->next, name);
109     }
110     }
111 gross 1044 }
112 jfenwick 3224
113 jfenwick 3086 /* deallocates the Dudley_TagMap in by recursive calls */
114 gross 1044
115 jfenwick 3224 void Dudley_TagMap_free(Dudley_TagMap * in)
116     {
117     if (in != NULL)
118     {
119     Dudley_TagMap_free(in->next);
120     MEMFREE(in->name);
121     MEMFREE(in);
122     }
123     return;
124 gross 1044 }

  ViewVC Help
Powered by ViewVC 1.1.26