VNetState.cpp
Engine/source/Verve/VPath/VNetState.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Verve 4// Copyright (C) 2014 - Violent Tulip 5// 6// Permission is hereby granted, free of charge, to any person obtaining a copy 7// of this software and associated documentation files (the "Software"), to 8// deal in the Software without restriction, including without limitation the 9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10// sell copies of the Software, and to permit persons to whom the Software is 11// furnished to do so, subject to the following conditions: 12// 13// The above copyright notice and this permission notice shall be included in 14// all copies or substantial portions of the Software. 15// 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22// IN THE SOFTWARE. 23//----------------------------------------------------------------------------- 24#include "VNetState.h" 25 26//----------------------------------------------------------------------------- 27 28U32 VNetState::gInvalidMask = 0; 29 30//----------------------------------------------------------------------------- 31 32VNetState::VNetState() : 33 mMask( 0 ) 34{ 35} 36 37VNetState::~VNetState( void ) 38{ 39 for ( VNetState::iterator itr = begin(); itr != end(); itr++ ) 40 { 41 // Fetch info. 42 VNetStateInfo *state = ( *itr ); 43 // Delete State. 44 delete state; 45 } 46 47 // Clear. 48 clear(); 49} 50 51//----------------------------------------------------------------------------- 52// 53// Connection Methods. 54// 55//----------------------------------------------------------------------------- 56 57bool VNetState::isConnection( NetConnection *pConnection ) 58{ 59 for ( VNetState::iterator itr = begin(); itr != end(); itr++ ) 60 { 61 VNetStateInfo *state = ( *itr ); 62 if ( state->Connection == pConnection ) 63 { 64 // Valid. 65 return true; 66 } 67 } 68 69 // Invalid. 70 return false; 71} 72 73void VNetState::addConnection( NetConnection *pConnection ) 74{ 75 // Init State. 76 VNetStateInfo *state = new VNetStateInfo( pConnection, mMask ); 77 // Add. 78 push_back( state ); 79} 80 81void VNetState::clearConnection( NetConnection *pConnection ) 82{ 83 for ( VNetState::iterator itr = begin(); itr != end(); itr++ ) 84 { 85 VNetStateInfo *state = ( *itr ); 86 if ( state->Connection == pConnection ) 87 { 88 // Delete. 89 delete state; 90 // Erase. 91 erase( itr ); 92 // Quit. 93 return; 94 } 95 } 96} 97 98//----------------------------------------------------------------------------- 99// 100// Mask Methods. 101// 102//----------------------------------------------------------------------------- 103 104VNetStateInfo *VNetState::getState( NetConnection *pConnection ) 105{ 106 for ( VNetState::iterator itr = begin(); itr != end(); itr++ ) 107 { 108 VNetStateInfo *state = ( *itr ); 109 if ( state->Connection == pConnection ) 110 { 111 return state; 112 } 113 } 114 115 return NULL; 116} 117 118void VNetState::setMaskBits( const U32 &pMask ) 119{ 120 // Apply Mask. 121 mMask |= pMask; 122 123 for ( VNetState::iterator itr = begin(); itr != end(); itr++ ) 124 { 125 // Fetch info. 126 VNetStateInfo *state = ( *itr ); 127 // Apply Mask. 128 state->Mask |= pMask; 129 } 130} 131 132void VNetState::clearMaskBits( const U32 &pMask ) 133{ 134 // Clear Mask. 135 mMask &= ~pMask; 136 137 for ( VNetState::iterator itr = begin(); itr != end(); itr++ ) 138 { 139 // Fetch info. 140 VNetStateInfo *state = ( *itr ); 141 // Clear Mask. 142 state->Mask &= ~pMask; 143 } 144} 145