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
|
// Copyright (c) 1997 by Jim Lynch.
// Copyright (c) 2010 by Philipp Schafft.
// This software comes with NO WARRANTY WHATSOEVER.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 dated June, 1991, or, at your
// option, any LATER version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 USA
//
// On Debian Linux systems, the complete text of the GNU General
// Public License can be found in `/usr/doc/copyright/GPL' (on some
// installations) or /usr/share/common-licenses/GPL (on newer
// ones).
#ifndef Animal_h
#define Animal_h
#include "Record.h"
#include <sstream>
#include "str-conversions.h"
class Animal : public Record
{
private:
std::string *animal;
void Default(void)
{
animal = new std::string;
}
void Set(const char *anAnimal)
{
animal = new std::string(anAnimal);
}
void Copy(const Animal &orig)
{
if(orig.animal)
{
animal = new std::string(*orig.animal);
}
else
{
animal = 0;
}
}
protected:
virtual void Destroy(void)
{
if(animal)
delete animal;
animal = 0;
}
virtual void SetNull(void)
{
animal = new std::string;
}
virtual void SetFromDataString(const char *theDataString)
{
const char *data = theDataString;
if(data[0] == 'a')
{
std::istringstream it(data + 2);
std::ostringstream theAnimal;
// grab the animal text
char nextCh = it.get();
while(nextCh != '|')
{
theAnimal << nextCh;
nextCh = it.get();
}
animal = new std::string(MakeCStringCopy(theAnimal));
}
else
SetNull();
}
public:
Animal()
{
Default();
}
Animal(const char *anAnimal)
{
Set(anAnimal);
}
Animal(std::string &anAnimal)
{
Set(anAnimal.c_str());
}
Animal(const Animal &orig)
{
Copy(orig);
}
Animal &operator=(const Animal &orig)
{
Destroy();
Copy(orig);
return *this;
}
virtual ~Animal()
{
Destroy();
}
Animal(Db &handle, const char *animalKey)
{
Default();
Read(handle, animalKey);
}
Animal(Db &handle, const std::string &animalKey)
{
Default();
Read(handle, animalKey);
}
virtual const char *FormNewDataCString() const
{
std::string temp = "a|";
if(animal)
temp += (*animal);
temp += "|";
return MakeCStringCopy(temp);
}
virtual void Print(std::ostream &out) const
{
out << (animal ? (*animal) : std::string());
}
};
#endif
|