]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/var_manager.cpp
* parser/expr_evaluator: expression evaluator using Reverse Polish Notation
[vlc] / modules / gui / skins2 / src / var_manager.cpp
1 /*****************************************************************************
2  * var_manager.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #include "var_manager.hpp"
26
27
28 VarManager::VarManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
29     m_tooltipText( pIntf ), m_helpText( pIntf )
30 {
31 }
32
33
34 VarManager::~VarManager()
35 {
36     // Delete the variables in the reverse order they were added
37     list<string>::const_iterator it1;
38     for( it1 = m_varList.begin(); it1 != m_varList.end(); it1++ )
39     {
40         m_varMap.erase(*it1);
41     }
42
43     // Delete the anonymous variables
44     while( !m_anonVarList.empty() )
45     {
46         m_anonVarList.pop_back();
47     }
48 }
49
50
51 VarManager *VarManager::instance( intf_thread_t *pIntf )
52 {
53     if( ! pIntf->p_sys->p_varManager )
54     {
55         VarManager *pVarManager;
56         pVarManager = new VarManager( pIntf );
57         if( pVarManager )
58         {
59             pIntf->p_sys->p_varManager = pVarManager;
60         }
61     }
62     return pIntf->p_sys->p_varManager;
63 }
64
65
66 void VarManager::destroy( intf_thread_t *pIntf )
67 {
68     if( pIntf->p_sys->p_varManager )
69     {
70         delete pIntf->p_sys->p_varManager;
71         pIntf->p_sys->p_varManager = NULL;
72     }
73 }
74
75
76 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
77 {
78     m_varMap[rName] = rcVar;
79     m_varList.push_front( rName );
80 }
81
82
83 void VarManager::registerVar( const VariablePtr &rcVar )
84 {
85     m_anonVarList.push_back( rcVar );
86 }
87
88
89 Variable *VarManager::getVar( const string &rName )
90 {
91     if( m_varMap.find( rName ) != m_varMap.end() )
92     {
93         return m_varMap[rName].get();
94     }
95     else
96     {
97         return NULL;
98     }
99 }
100
101
102 Variable *VarManager::getVar( const string &rName, const string &rType )
103 {
104     if( m_varMap.find( rName ) != m_varMap.end() )
105     {
106         Variable *pVar = m_varMap[rName].get();
107         // Check the variable type
108         if( pVar->getType() != rType )
109         {
110             msg_Warn( getIntf(), "Variable %s has incorrect type (%s instead"
111                       " of (%s)", rName.c_str(), pVar->getType().c_str(),
112                       rType.c_str() );
113             return NULL;
114         }
115         else
116         {
117             return pVar;
118         }
119     }
120     else
121     {
122         return NULL;
123     }
124 }
125