Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGGroupConnection.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 #include <stdlib.h>
00043 #include <stdio.h>
00044 #include <assert.h>
00045 
00046 #include "OSGConfig.h"
00047 #include "OSGGroupConnection.h"
00048 
00049 OSG_USING_NAMESPACE
00050 
00055 /*-------------------------------------------------------------------------*/
00056 /*                            constructor destructor                       */
00057 
00061 GroupConnection::GroupConnection(int zeroCopyThreshold):
00062     Connection(zeroCopyThreshold)
00063 {
00064 }
00065 
00069 GroupConnection::~GroupConnection(void)
00070 {
00071 }
00072 
00073 /*-------------------------------------------------------------------------*/
00074 /*                            channel handling                             */
00075 
00078 UInt32 GroupConnection::getChannelCount(void)
00079 {
00080     return _selection.size();
00081 }
00082 
00085 void GroupConnection::addSelection(Channel channel)
00086 {
00087     ChannelIndex index = _channelToIndex[channel];
00088     _selection[index] = true;
00089 }
00090 
00093 void GroupConnection::subSelection(Channel channel)
00094 {
00095     ChannelIndex index = _channelToIndex[channel];
00096     _selection[index] = false;
00097 }
00098 
00101 void GroupConnection::clearSelection(void)
00102 {
00103     std::fill(_selection.begin(),_selection.end(),false);
00104 }
00105 
00108 void GroupConnection::resetSelection(void)
00109 {
00110     std::fill(_selection.begin(),_selection.end(),true);
00111 }
00112 
00115 UInt32 GroupConnection::getSelectionCount(void)
00116 {
00117     UInt32 selectionCount=0;
00118     std::vector<UInt8>::iterator i;
00119     for(i=_selection.begin() ; i!=_selection.end() ; ++i)
00120         if(*i)
00121             selectionCount++;
00122     return selectionCount;
00123 }
00124 
00125 /*-------------------------------------------------------------------------*/
00126 /*                           internal channel handling                     */
00127 
00132 void GroupConnection::setDestination(const std::string &destination)
00133 {
00134     _destination = destination;
00135 }
00136 
00139 std::string GroupConnection::getDestination(void)
00140 {
00141     return _destination;
00142 }
00143 
00144 /*-------------------------------------------------------------------------*/
00145 /*                           internal channel handling                     */
00146 
00149 Connection::Channel GroupConnection::newChannelIndex(ChannelIndex index)
00150 {
00151     Channel channel;
00152     if(_reuseChannel.begin() != _reuseChannel.end())
00153     {
00154         channel = *(_reuseChannel.begin());
00155         _reuseChannel.pop_front();
00156     }
00157     else
00158     {
00159         channel = _channelToIndex.size();
00160         _channelToIndex.resize(channel+1);
00161     }
00162     if(index >= _indexToChannel.size())
00163         _indexToChannel.resize(index+1);
00164     if(index >= _selection.size())
00165         _selection.resize(index+1);
00166     // enable selection
00167     _selection[index] = true;
00168     // set index to channel mapping
00169     _indexToChannel[index] = channel;
00170     // set channel to index mapping
00171     _channelToIndex[channel] = index;
00172     return channel;
00173 }
00174 
00177 void GroupConnection::delChannelIndex(ChannelIndex index)
00178 {
00179     Channel channel = _indexToChannel[index];
00180     // erase from indexed arrays
00181     _selection     .erase(_selection.begin()      + index);
00182     _indexToChannel.erase(_indexToChannel.begin() + index);
00183     // move to reuse
00184     _reuseChannel.push_back(channel);
00185 }
00186 
00187 /*-------------------------------------------------------------------------*/
00188 /*                      channel / index mapping                            */
00189 
00190 GroupConnection::ChannelIndex GroupConnection::channelToIndex(Channel channel) const
00191 {
00192     return _channelToIndex[channel];
00193 }
00194 
00195 Connection::Channel GroupConnection::indexToChannel(ChannelIndex index) const
00196 {
00197     return _indexToChannel[index];
00198 }
00199 
00200 /*-------------------------------------------------------------------------*/
00201 /*                              cvs id's                                   */
00202 
00203 #ifdef __sgi
00204 #pragma set woff 1174
00205 #endif
00206 
00207 #ifdef OSG_LINUX_ICC
00208 #pragma warning( disable : 177 )
00209 #endif
00210 
00211 namespace
00212 {
00213     static Char8 cvsid_cpp       [] = "@(#)$Id: $";
00214     static Char8 cvsid_hpp       [] = OSG_GROUPCONNECTION_HEADER_CVSID;
00215 }
00216 

Generated on Thu Aug 25 04:05:59 2005 for OpenSG by  doxygen 1.4.3