feisty meow concerns codebase  2.140
node.h
Go to the documentation of this file.
1 #ifndef NODE_CLASS
2 #define NODE_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : node *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1992-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/definitions.h>
19 
20 namespace nodes {
21 
22 // forward:
23 class node_link_amorph;
24 
26 
40 class node : public virtual basis::root_object
41 {
42 public:
43  node(int number_of_links = 0);
45 
58  virtual ~node();
60 
65  int links() const;
67 
68  void set_link(int link_number, node *new_link);
70 
74  node *get_link(int link_number) const;
76 
78  void zap_link(int link_number);
80 
81  void insert_link(int where, node *to_add = NULL_POINTER);
83 
88  int which(node *to_find) const;
90 
94 private:
95  node_link_amorph *_links;
96 
97  void set_empty(int link_number);
99 
100  // disallowed:
101  node(const node &);
102  node &operator =(const node &);
103 };
104 
106 
108 
113 template <class contents>
114 class basket : public node
115 {
116 public:
117  basket(int links, const contents &to_store = contents())
118  : node(links), _storage(to_store) {}
119 
120  basket(const basket &to_copy) { *this = to_copy; }
121 
122  basket &operator = (const contents &to_copy)
123  { if (&to_copy != this) _storage = to_copy; return *this; }
124 
125  const contents &stored() const { return _storage; }
127  contents &stored() { return _storage; }
129 
130 private:
131  contents _storage;
132 };
133 
134 } // end namespace.
135 
136 #endif
137 
the basket class holds an object and supports connecting them as nodes.
Definition: node.h:115
const contents & stored() const
allows a peek at the stored object.
Definition: node.h:125
basket(const basket &to_copy)
Definition: node.h:120
basket(int links, const contents &to_store=contents())
Definition: node.h:117
contents & stored()
provides access to the stored object.
Definition: node.h:127
basket & operator=(const contents &to_copy)
Definition: node.h:122
An object representing the interstitial cell in most linked data structures.
Definition: node.h:41
void zap_link(int link_number)
the specified link is removed from the node.
Definition: node.cpp:68
void set_link(int link_number, node *new_link)
Connects the node "new_link" to this node.
Definition: node.cpp:62
int links() const
Returns the number of links the node currently holds.
Definition: node.cpp:51
void insert_link(int where, node *to_add=NULL_POINTER)
adds a new link prior to the position specified in "where".
Definition: node.cpp:74
node(int number_of_links=0)
the constructor provides for "number_of_links" links initially.
Definition: node.cpp:41
virtual ~node()
the destructor simply invalidates the node.
Definition: node.cpp:45
int which(node *to_find) const
locates the index where "to_find" lives in our list of links.
Definition: node.cpp:91
node * get_link(int link_number) const
Returns the node that is connected to the specified "link_number".
Definition: node.cpp:85
Constants and objects used throughout HOOPLE.
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32