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

var_manager.cpp

00001 /*****************************************************************************
00002  * var_manager.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: var_manager.cpp 11973 2005-08-02 23:26:22Z asmax $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include "var_manager.hpp"
00026 
00027 
00028 VarManager::VarManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
00029     m_pTooltipText( NULL ), m_pHelpText( NULL )
00030 {
00031     m_pTooltipText = new VarText( pIntf );
00032     m_pHelpText = new VarText( pIntf, false );
00033 }
00034 
00035 
00036 VarManager::~VarManager()
00037 {
00038     // Delete the variables in the reverse order they were added
00039     list<string>::const_iterator it1;
00040     for( it1 = m_varList.begin(); it1 != m_varList.end(); it1++ )
00041     {
00042         m_varMap.erase(*it1);
00043     }
00044 
00045     // Delete the anonymous variables
00046     while( !m_anonVarList.empty() )
00047     {
00048         m_anonVarList.pop_back();
00049     }
00050 
00051     delete m_pTooltipText;
00052 
00053     // Warning! the help text must be the last variable to be deleted,
00054     // because VarText destructor references it (FIXME: find a cleaner way?)
00055     delete m_pHelpText;
00056 }
00057 
00058 
00059 VarManager *VarManager::instance( intf_thread_t *pIntf )
00060 {
00061     if( ! pIntf->p_sys->p_varManager )
00062     {
00063         VarManager *pVarManager;
00064         pVarManager = new VarManager( pIntf );
00065         if( pVarManager )
00066         {
00067             pIntf->p_sys->p_varManager = pVarManager;
00068         }
00069     }
00070     return pIntf->p_sys->p_varManager;
00071 }
00072 
00073 
00074 void VarManager::destroy( intf_thread_t *pIntf )
00075 {
00076     if( pIntf->p_sys->p_varManager )
00077     {
00078         delete pIntf->p_sys->p_varManager;
00079         pIntf->p_sys->p_varManager = NULL;
00080     }
00081 }
00082 
00083 
00084 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
00085 {
00086     m_varMap[rName] = rcVar;
00087     m_varList.push_front( rName );
00088 }
00089 
00090 
00091 void VarManager::registerVar( const VariablePtr &rcVar )
00092 {
00093     m_anonVarList.push_back( rcVar );
00094 }
00095 
00096 
00097 Variable *VarManager::getVar( const string &rName )
00098 {
00099     if( m_varMap.find( rName ) != m_varMap.end() )
00100     {
00101         return m_varMap[rName].get();
00102     }
00103     else
00104     {
00105         return NULL;
00106     }
00107 }
00108 
00109 
00110 Variable *VarManager::getVar( const string &rName, const string &rType )
00111 {
00112     if( m_varMap.find( rName ) != m_varMap.end() )
00113     {
00114         Variable *pVar = m_varMap[rName].get();
00115         // Check the variable type
00116         if( pVar->getType() != rType )
00117         {
00118             msg_Warn( getIntf(), "Variable %s has incorrect type (%s instead"
00119                       " of (%s)", rName.c_str(), pVar->getType().c_str(),
00120                       rType.c_str() );
00121             return NULL;
00122         }
00123         else
00124         {
00125             return pVar;
00126         }
00127     }
00128     else
00129     {
00130         return NULL;
00131     }
00132 }
00133 

Generated on Tue Dec 20 10:14:42 2005 for vlc-0.8.4a by  doxygen 1.4.2