1 /* 2 Gri - A language for scientific graphics programming 3 Copyright (C) 2008 Daniel Kelley 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along 16 with this program; if not, write to the Free Software Foundation, Inc., 17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 // Store synonym name/value 21 #if !defined(_grisynonym_h_) 22 #define _grisynonym_h_ 23 #include "GCounter.hh" 24 #if 1 25 class GriSynonym : public GriCounter 26 { 27 public: GriSynonym()28 GriSynonym() { 29 ; 30 } GriSynonym(const char * the_name,const char * the_value)31 GriSynonym(const char *the_name, const char *the_value) { 32 name.assign(the_name); 33 value.assign(the_value); 34 } GriSynonym(const GriSynonym & c)35 GriSynonym(const GriSynonym& c) { 36 name.assign(c.get_name()); 37 value.assign(c.get_value_quietly()); 38 } ~GriSynonym()39 ~GriSynonym() { 40 #if 0 // BUG 2001-feb-17 -- not sure on next 2 lines 41 name.string::~string(); // not executed 42 value.string::~string(); // not executed 43 #endif 44 } setNameValue(const char * the_name,const char * the_value)45 void setNameValue(const char *the_name, const char *the_value) { 46 name.assign(the_name); 47 value.assign(the_value); 48 } set_value(const char * the_value)49 void set_value(const char *the_value) {value.assign(the_value); } get_name(void) const50 const char *get_name(void) const {return name.c_str();}; get_value(void)51 const char *get_value(void) {incrementCount(); return value.c_str();}; get_value_quietly(void) const52 const char *get_value_quietly(void) const {return value.c_str();}; operator =(const GriSynonym & n)53 GriSynonym& operator=(const GriSynonym& n) { 54 name.assign(n.get_name()); 55 value.assign(n.get_value_quietly()); 56 return *this; 57 } 58 private: 59 std::string name; 60 std::string value; 61 }; 62 63 64 65 #else 66 67 class GriSynonym : public GriCounter 68 { 69 public: GriSynonym()70 GriSynonym() { 71 name = new char [1]; if (!name) OUT_OF_MEMORY; 72 name[0] = '\0'; 73 value = new char [1]; if (!value) OUT_OF_MEMORY; 74 value[0] = '\0'; 75 } GriSynonym(const char * the_name,const char * the_value)76 GriSynonym(const char *the_name, const char *the_value) { 77 name = new char [1 + strlen(the_name)]; if (!name) OUT_OF_MEMORY; 78 strcpy(name, the_name); 79 value = new char [1 + strlen(the_value)]; if (!value) OUT_OF_MEMORY; 80 strcpy(value, the_value); 81 } GriSynonym(const GriSynonym & c)82 GriSynonym(const GriSynonym& c) { 83 name = new char [1 + strlen(c.getName())]; 84 if (!name) OUT_OF_MEMORY; 85 strcpy(name, c.getName()); 86 value = new char [1 + strlen(c.get_value_quietly())]; 87 if (!value) OUT_OF_MEMORY; 88 strcpy(value, c.get_value_quietly()); 89 } ~GriSynonym()90 ~GriSynonym() { 91 #if 0 92 delete [] name; 93 delete [] value; 94 #endif 95 } setNameValue(const char * the_name,const char * the_value)96 void setNameValue(const char *the_name, const char *the_value) { 97 if (strlen(the_name) > strlen(name)) { 98 delete [] name; 99 name = new char [1 + strlen(the_name)]; 100 if (!name) OUT_OF_MEMORY; 101 } 102 strcpy(name, the_name); 103 if (strlen(the_value) > strlen(value)) { 104 delete [] value; 105 value = new char [1 + strlen(the_value)]; 106 if (!value) OUT_OF_MEMORY; 107 } 108 strcpy(value, the_value); 109 } set_value(const char * the_value)110 void set_value(const char *the_value) { 111 if (strlen(the_value) > strlen(value)) { 112 delete [] value; 113 value = new char[1 + strlen(the_value)]; 114 if (!value) OUT_OF_MEMORY; 115 } 116 strcpy(value, the_value); 117 } getName(void) const118 char *getName(void) const {return name;}; getValue(void)119 char *getValue(void) {incrementCount(); return value;}; get_value_quietly(void) const120 char *get_value_quietly(void) const {return value;}; operator =(const GriSynonym & n)121 GriSynonym& operator=(const GriSynonym& n) { 122 char *cp = n.getName(); 123 if (strlen(cp) > strlen(name)) { 124 delete [] name; 125 name = new char [1 + strlen(cp)]; 126 if (!name) OUT_OF_MEMORY; 127 } 128 strcpy(name, cp); 129 cp = n.get_value_quietly(); 130 if (strlen(cp) > strlen(value)) { 131 delete [] value; 132 value = new char [1 + strlen(cp)]; 133 if (!value) OUT_OF_MEMORY; 134 } 135 strcpy(value, cp); 136 return *this; 137 } 138 private: 139 char *name; 140 char *value; 141 }; 142 #endif 143 144 #endif 145