// (c) COPYRIGHT URI/MIT 1994-1996,1999 // Please read the full copyright statement in the file COPYRIGHT. // // Authors: // jhrg,jimg James Gallagher (jgallagher@gso.uri.edu) // reza Reza Nekovei (reza@intcomm.net) // To hold and managed a set of open Connect *'s. // // jhrg 9/30/94 // $Log: Connections.cc,v $ // Revision 1.12 1999/05/04 19:47:20 jimg // Fixed copyright statements. Removed more of the GNU classes. // // Revision 1.11 1999/04/29 03:04:52 jimg // Merged ferret changes // // Revision 1.10.6.1 1999/04/14 22:33:46 jimg // Removed assert() in del_connect() method. It is OK for the _conns[i] to be // NULL when this method is called. // // Revision 1.10 1999/03/18 01:05:58 jimg // Removed the assertion that checked the _conns member when operator[] was // used. This was failing when people called close API calls (e.g., nc_close()) // more than once for a single file descriptor. // // Revision 1.9 1996/09/19 16:16:09 jimg // Added some comments. Removed config_dap.h. // // Revision 1.8 1996/06/08 00:19:44 jimg // Added config_dap.h in place of config_netio.h // // Revision 1.7 1996/05/31 23:29:31 jimg // Updated copyright notice. // // Revision 1.6 1996/05/22 18:05:06 jimg // Merged files from the old netio directory into the dap directory. // Removed the errmsg library from the software. // // Revision 1.5 1995/07/09 21:20:46 jimg // Fixed date in copyright (it now reads `Copyright 1995 ...'). // // Revision 1.4 1995/07/09 21:14:47 jimg // Added copyright. // // Revision 1.3 1995/05/22 20:43:56 jimg // Added #include "config_netio.h" // // Revision 1.2 1995/04/17 03:21:45 jimg // Added debug.h and some debugging code. // // Revision 1.1 1995/01/10 16:23:05 jimg // Created new `common code' library for the net I/O stuff. // // Revision 1.2 1994/11/18 21:12:19 reza // Changed it to a template class for derived classes of the Connect // // Revision 1.1 1994/10/05 18:02:10 jimg // First version of the connection management classes. // This commit also includes early versions of the test code. // #ifdef __GNUG__ #pragma implemenation #endif #include #include "debug.h" #include "Connections.h" // private mfuncs template void Connections::init_array(int i) { while (i--) { _free.prepend(i); _conns[i] = NULL; } } // public mfuncs template Connections::Connections(int i) { _max_con = i; _conns = new T[i]; init_array(_max_con); DBG(cerr << "Finished Connections ctor (" << i << ")\n"); } template Connections::Connections(const Connections &cs) { _max_con = cs._max_con; _conns = new T[_max_con]; init_array(_max_con); } template Connections::~Connections() { delete [] _conns; } template Connections & Connections::operator=(const Connections &rhs) { if (this == &rhs) return *this; _max_con = rhs._max_con; _conns = new T[_max_con]; init_array(_max_con); return *this; } // Given an index into the array of managed connections, return the // corresponding Connect *. // // NB: Return a reference so that this will work on both the left and right // sides of the assignement operator! // // Returns: A reference to the Connect * template T & Connections::operator[](int i) { return _conns[i]; } // Add the Connect * to the array of managed connections. // // Returns: integer index to Connect * or -1 if the array is full. template int Connections::add_connect(T c) { if (_free.empty()) { cerr << "add_connect: too many connects, cannot add another" << endl; return -1; } int i = _free.remove_front(); // pop the first element assert(!_conns[i]); _conns[i] = c; return i; } // Remove a connection from the array of managed conections. The caller is // responsible for deleting the Connect * BEFORE calling this member // function. // // Returns: void template void Connections::del_connect(int i) { _free.prepend(i); _conns[i] = NULL; }