feisty meow concerns codebase  2.140
bogon.cpp
Go to the documentation of this file.
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 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
void stuff(char *to_stuff, int count) const
a synonym for copy().
Definition: astring.h:216
int length() const
Returns the current length of the string.
Definition: astring.cpp:132
Definition: bogon.h:30
bogon & operator=(const bogon &to_copy)
Definition: bogon.cpp:39
~bogon()
Definition: bogon.cpp:48
int size() const
Definition: bogon.cpp:52
bogon(basis::abyte *to_copy)
Definition: bogon.cpp:26
basis::abyte * held() const
Definition: bogon.cpp:50
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
unsigned char abyte
A fairly important unit which is seldom defined...
Definition: definitions.h:51
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55