/* Copyright (c) 2002-2012 Croteam Ltd. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef SE_INCL_SELECTION_CPP #define SE_INCL_SELECTION_CPP #ifdef PRAGMA_ONCE #pragma once #endif #include #include /* * Select one object. */ template void CSelection::Select(cType &tToSelect) { // if the object is not yet selected if (!tToSelect.IsSelected(ulFlag)) { // select it tToSelect.Select(ulFlag); // add it to this container Add(&tToSelect); // if the object is already selected } else { ASSERTALWAYS("Object already selected!"); } } /* * Deselect one object. */ template void CSelection::Deselect(cType &tToSelect) { // if the object is selected if (tToSelect.IsSelected(ulFlag)) { // deselect it tToSelect.Deselect(ulFlag); // remove it from this container Remove(&tToSelect); // if the object is not selected } else { ASSERTALWAYS("Object is not selected!"); } } /* * Test if one object is selected. */ template BOOL CSelection::IsSelected(cType &tToSelect) { // test if the object is selected return tToSelect.IsSelected(ulFlag); } /* * Deselect all objects. */ template void CSelection::Clear(void) { // for all objects in the container FOREACHINDYNAMICCONTAINER(*this, cType, itObject) { // object must be allocated and valid ASSERT(_CrtIsValidPointer(&*itObject, sizeof(cType), TRUE)); /* ASSERT(_CrtIsValidHeapPointer(&*itObject)); ASSERT(_CrtIsMemoryBlock(&*itObject, sizeof(cType), NULL, NULL, NULL )); */ // deselect it itObject->Deselect(ulFlag); } // clear the entire container at once CDynamicContainer::Clear(); } template cType *CSelection::GetFirstInSelection(void) { if( Count() == 0) { return NULL; } return (cType *) &CDynamicContainer::GetFirst(); } #endif /* include-once check. */