Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ViewManager.cc

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * $Id: ViewManager.cc,v 1.2 2001/08/23 00:32:05 frehe Exp $
00003  *
00004  *
00005  * COPYRIGHT INFORMATION
00006  *
00007  * This file is part of RoboSoc created by Fredrik Heintz <frehe@ida.liu.se>
00008  * Copyright (C) 1999, 2000 Fredrik Heintz, Linköping University, Sweden
00009  *
00010  * You are allowed to modify and use this code as long as you retain this
00011  * notice. If you make any changes or have any comments I would appreciate
00012  * it if you send me a message. For more information, please see
00013  * http://www.ida.liu.se/~frehe/RoboCup/RoboSoc/
00014  *
00015  *
00016  * IDENTIFICATION
00017  *
00018  * Filename: ViewManager.cc
00019  * Unitname: Framework
00020  * $Revision: 1.2 $
00021  * Created by: Fredrik Heintz 1999-xx-xx
00022  * Last modified by $Author: frehe $ $Date: 2001/08/23 00:32:05 $
00023  *
00024  *
00025  * HISTORY
00026  *
00027  * $Log: ViewManager.cc,v $
00028  * Revision 1.2  2001/08/23 00:32:05  frehe
00029  * Removed dependencies.
00030  *
00031  * Revision 1.1  2000/09/03 22:08:47  frehe
00032  * Imported the current version of RoboSoc (soon to be v2.5.0)
00033  *
00034  */
00035 
00048 #include "ViewManager.h"
00049 #include "View.h"
00050 
00051 
00052 RS_BEGIN_NAMESPACE
00053 
00054 
00055 ViewManager* ViewManager::onlyInstance(NULL);
00056 
00057 
00058 ViewManager* ViewManager::instance()
00059 {
00060   if ( onlyInstance == NULL ) {
00061     onlyInstance = new ViewManager();
00062   }
00063   return onlyInstance;
00064 }
00065 
00066 
00067 bool ViewManager::addView(View* view, const bool persistent)
00068 {
00069   // AddView returns true if the view was added, otherwise false.
00070   
00071   std::map<ViewId, ViewData>::value_type item(view->getId(),
00072                 ViewData(view, persistent));
00073 
00074   std::pair<std::map<ViewId, ViewData>::iterator, bool> r;
00075   r = theViews.insert(item);
00076 
00077   return r.second;
00078 
00079   // Returns a pointer to the view with the same id as the
00080   // view supplied.
00081   // return theViews.insert(std::map<ViewId, ViewData>::value_type(view->GetID(), ViewData(view, persistent))).first->second.GetViewPointer();
00082 
00083 }  
00084 
00085 
00086 View* ViewManager::getView(const ViewId v_id)
00087 {
00088   // Returns a pointer to the wanted view or NULL if the
00089   // view doesn't exist.
00090   // Also increment the reference counter.
00091   
00092   std::map<ViewId, ViewData>::iterator r = theViews.find(v_id);
00093 
00094   if ( r != theViews.end() ) {
00095     r->second.increaseReferenceCount();
00096     return r->second.getViewPointer();
00097   } else {
00098     return NULL;
00099   }
00100   
00101 }
00102 
00103 
00104 void ViewManager::releaseView(const ViewId v_id)
00105 {
00106   // Decrement reference count if the view exist.
00107   // If the view is no longer in use delete it.
00108 
00109   std::map<ViewId, ViewData>::iterator r = theViews.find(v_id);
00110 
00111   if ( r != theViews.end() ) {
00112     r->second.decreaseReferenceCount();
00113 
00114     if ( !r->second.isUsed() )
00115       theViews.erase(r);
00116   }
00117 
00118 }
00119 
00120 void ViewManager::setViewPersistence(ViewId v_id, const bool persistence)
00121 {
00122   // If the view exist change its persistence.
00123   std::map<ViewId, ViewData>::iterator r = theViews.find(v_id);
00124 
00125   if ( r != theViews.end() ) {
00126     r->second.setPersistence(persistence);
00127 
00128     if ( !r->second.isUsed() )
00129       theViews.erase(r);
00130   }
00131 }
00132   
00133 
00134 ViewManager::ViewManager()
00135   : theViews(),
00136     currentUpdateNumber(0)
00137 {
00138 }
00139 
00140 
00141 void ViewManager::forEach(void (*fn)(View*))
00142 {
00143   // Apply fn to all views.
00144   for ( std::map<ViewId, ViewData>::iterator i = theViews.begin();
00145   i != theViews.end(); ++i )
00146     fn(i->second.getViewPointer());
00147 }
00148 
00149 
00150 void ViewManager::forEach(ViewUpdateResult (View::*fn)(const UInt32),
00151          const UInt32 val)
00152 {
00153   // Apply fn to all views.
00154   for ( std::map<ViewId, ViewData>::iterator i = theViews.begin();
00155   i != theViews.end(); ++i )
00156     (i->second.getViewPointer()->*fn)(val);
00157 }
00158 
00159 
00160 RS_END_NAMESPACE
00161 
00162 
00163 /* CONDITIONAL INCLUSION OF INLINE DEFINITIONS
00164  *
00165  * If the compiler or debugger does not understand the keyword inline then
00166  * include the inline definitions here, otherwise include them in the
00167  * declaration file.
00168  *
00169  * This is controlled by a flag called RS_USE_INLINE, which is usually
00170  * defined. It can be set by the user by giving the compiler an argument
00171  * usually -DRS_USE_INLINE (to define it) or -URS_USE_INLINE (to undefine it).
00172  */
00173 
00174 #ifndef RS_USE_INLINE
00175 #  include "ViewManager.icc"
00176 #endif

Generated on Mon Aug 29 07:58:04 2011 for RoboSoc by doxygen1.3-rc3