Merge branch 'release-2.140.101'
[feisty_meow.git] / nucleus / library / tests_structures / bogon.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : bogon                                                             *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *  Purpose:                                                                   *
7 *                                                                             *
8 *    A simple test object for amorphs.                                        *
9 *                                                                             *
10 *******************************************************************************
11 * Copyright (c) 1996-$now By Author.  This program is free software; you can  *
12 * redistribute it and/or modify it under the terms of the GNU General Public  *
13 * License as published by the Free Software Foundation; either version 2 of   *
14 * the License or (at your option) any later version.  This is online at:      *
15 *     http://www.fsf.org/copyleft/gpl.html                                    *
16 * Please send any updates to: fred@gruntose.com                               *
17 \*****************************************************************************/
18
19 #include "bogon.h"
20
21 #include <string.h>
22
23 using namespace basis;
24 using namespace structures;
25
26 bogon::bogon(abyte *to_copy) : my_held(NULL_POINTER)
27 {
28   if (to_copy) {
29     astring t((char *)to_copy);
30     if (t.length()) {
31       my_held = new abyte[t.length() + 1];
32       t.stuff((char *)my_held, t.length() + 1);
33     }
34   }
35 }
36
37 bogon::bogon(const bogon &to_copy) : my_held(NULL_POINTER) { operator = (to_copy); }
38
39 bogon &bogon::operator = (const bogon &to_copy) {
40   if (this == &to_copy) return *this;
41   astring t((char *)to_copy.my_held);
42   if (my_held) delete [] my_held;
43   my_held = new abyte[t.length() + 1];
44   t.stuff((char *)my_held, t.length() + 1);
45   return *this;
46 }
47
48 bogon::~bogon() { if (my_held) delete [] my_held; }
49
50 abyte *bogon::held() const { return my_held; }
51
52 int bogon::size() const { return my_held? int(strlen((char *)my_held) + 1) : 0; }
53