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

Contents of /branches/trilinos_from_5897/dudley/src/TagMap.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6009 - (show annotations)
Wed Mar 2 04:13:26 2016 UTC (2 years, 11 months ago) by caltinay
File size: 2634 byte(s)
Much needed sync with trunk...

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 /****************************************************************************/
18
19 /* Dudley: simple mapping from names to tag keys via a linked list */
20
21 /****************************************************************************/
22
23 #include "TagMap.h"
24
25 namespace dudley {
26
27 void Dudley_TagMap_insert(Dudley_TagMap** tag_map, const char* name, index_t tag_key)
28 {
29 Dudley_TagMap *map = NULL;
30 if (strlen(name) < 1) {
31 throw escript::ValueError("TagMap_insert: empty tag name.");
32 }
33 if (strchr(name, 32) != NULL) {
34 throw escript::ValueError("TagMap_insert: tag name may not contain a space.");
35 }
36 if (*tag_map == NULL) {
37 map = new Dudley_TagMap;
38 map->name = new char[strlen(name) + 1];
39 strcpy(map->name, name);
40 map->tag_key = tag_key;
41 map->next = NULL;
42 *tag_map = map;
43 } else {
44 if (strcmp((*tag_map)->name, name) == 0) {
45 (*tag_map)->tag_key = tag_key;
46 } else {
47 Dudley_TagMap_insert(&((*tag_map)->next), name, tag_key);
48 }
49 }
50 }
51
52 index_t Dudley_TagMap_getTag(Dudley_TagMap * tag_map, const char *name)
53 {
54 if (tag_map == NULL) {
55 std::stringstream ss;
56 ss << "getTag: unknown tag name " << name << ".";
57 const std::string errorMsg(ss.str());
58 throw escript::ValueError(errorMsg);
59 } else {
60 if (strcmp(tag_map->name, name) == 0) {
61 return tag_map->tag_key;
62 } else {
63 return Dudley_TagMap_getTag(tag_map->next, name);
64 }
65 }
66 }
67
68 bool Dudley_TagMap_isValidTagName(Dudley_TagMap * tag_map, const char *name)
69 {
70 if (tag_map == NULL)
71 return false;
72
73 if (strcmp(tag_map->name, name) == 0)
74 return true;
75
76 return Dudley_TagMap_isValidTagName(tag_map->next, name);
77 }
78
79 /* deallocates the Dudley_TagMap in by recursive calls */
80
81 void Dudley_TagMap_free(Dudley_TagMap * in)
82 {
83 if (in != NULL)
84 {
85 Dudley_TagMap_free(in->next);
86 delete[] in->name;
87 delete in;
88 }
89 }
90
91 } // namespace dudley
92

Properties

Name Value
svn:mergeinfo /branches/4.0fordebian/dudley/src/TagMap.cpp:5567-5588 /branches/lapack2681/finley/src/TagMap.cpp:2682-2741 /branches/pasowrap/dudley/src/TagMap.cpp:3661-3674 /branches/py3_attempt2/dudley/src/TagMap.cpp:3871-3891 /branches/restext/finley/src/TagMap.cpp:2610-2624 /branches/ripleygmg_from_3668/dudley/src/TagMap.cpp:3669-3791 /branches/stage3.0/finley/src/TagMap.cpp:2569-2590 /branches/symbolic_from_3470/dudley/src/TagMap.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/dudley/src/TagMap.cpp:3517-3974 /release/3.0/finley/src/TagMap.cpp:2591-2601 /release/4.0/dudley/src/TagMap.cpp:5380-5406 /trunk/dudley/src/TagMap.cpp:4257-4344,5898-6007 /trunk/ripley/test/python/dudley/src/TagMap.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26