1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "var_manager.hpp"
28 VarManager::VarManager( intf_thread_t
*pIntf
): SkinObject( pIntf
),
29 m_pTooltipText( NULL
), m_pHelpText( NULL
)
31 m_pTooltipText
= new VarText( pIntf
);
32 m_pHelpText
= new VarText( pIntf
, false );
36 VarManager::~VarManager()
38 // Delete the variables in the reverse order they were added
39 list
<string
>::const_iterator it1
;
40 for( it1
= m_varList
.begin(); it1
!= m_varList
.end(); it1
++ )
45 // Delete the anonymous variables
46 while( !m_anonVarList
.empty() )
48 m_anonVarList
.pop_back();
52 delete m_pTooltipText
;
54 // Warning! the help text must be the last variable to be deleted,
55 // because VarText destructor references it (FIXME: find a cleaner way?)
60 VarManager
*VarManager::instance( intf_thread_t
*pIntf
)
62 if( ! pIntf
->p_sys
->p_varManager
)
64 VarManager
*pVarManager
;
65 pVarManager
= new VarManager( pIntf
);
68 pIntf
->p_sys
->p_varManager
= pVarManager
;
71 return pIntf
->p_sys
->p_varManager
;
75 void VarManager::destroy( intf_thread_t
*pIntf
)
77 delete pIntf
->p_sys
->p_varManager
;
78 pIntf
->p_sys
->p_varManager
= NULL
;
82 void VarManager::registerVar( const VariablePtr
&rcVar
, const string
&rName
)
84 m_varMap
[rName
] = rcVar
;
85 m_varList
.push_front( rName
);
87 m_anonVarList
.push_back( rcVar
);
91 void VarManager::registerVar( const VariablePtr
&rcVar
)
93 m_anonVarList
.push_back( rcVar
);
97 Variable
*VarManager::getVar( const string
&rName
)
99 if( m_varMap
.find( rName
) != m_varMap
.end() )
101 return m_varMap
[rName
].get();
110 Variable
*VarManager::getVar( const string
&rName
, const string
&rType
)
112 if( m_varMap
.find( rName
) != m_varMap
.end() )
114 Variable
*pVar
= m_varMap
[rName
].get();
115 // Check the variable type
116 if( pVar
->getType() != rType
)
118 msg_Warn( getIntf(), "variable %s has incorrect type (%s instead"
119 " of (%s)", rName
.c_str(), pVar
->getType().c_str(),
135 void VarManager::registerConst( const string
&rName
, const string
&rValue
)
137 m_constMap
[rName
] = rValue
;
141 string
VarManager::getConst( const string
&rName
)
143 return m_constMap
[rName
];