?? base_instanceobject.cpp
字號(hào):
/*
Copyright (c) 2008, Intel Corporation.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*///==============================================================================// base_InstanceObject.cpp//// Contents:// Implementation of InstanceObject class////==============================================================================#include "base_InstanceObject.h"#include "base_InstanceObject_Impl.h"using namespace Intel::Mobile::BaseAPI;//==============================================================================//class InstanceObject;//==============================================================================// C_Tor()//==============================================================================InstanceObject::InstanceObject( void *pImpl ) : EventClient( pImpl ){ if ( m_pImpl != NULL ) (*reinterpret_cast<ObjectImplPtr*>(m_pImpl))->SetOwner( this ); m_Properties = new PROPERTYMAP();}//==============================================================================// D_Tor()//==============================================================================InstanceObject::~InstanceObject(){ if ( m_pImpl ) // If we have a valid impl * delete the SMART POINTER object { PROPERTYMAP *pPropertyMap = reinterpret_cast<PROPERTYMAP *>(m_Properties); PROPERTYMAP::iterator iter; while ( !pPropertyMap->empty() ) { iter = pPropertyMap->begin(); delete (*iter).second; pPropertyMap->erase( iter ); } delete pPropertyMap; m_Properties = NULL; InstanceObjectImplPtr* pInstanceImpl = reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl); (*pInstanceImpl)->SetOwner( NULL ); // Remove this as owner of the impl. delete pInstanceImpl; }}//==============================================================================// GetType()//==============================================================================IntelMobileChar* InstanceObject::GetType() const{ return (*reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl))->GetType();}//==============================================================================// GetType()//==============================================================================IntelMobileChar* InstanceObject::GetKey() const{ return (*reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl))->GetKey();}//==============================================================================// AddObserver() //==============================================================================bool InstanceObject::AddObserver( Event::EventType eType, Observer& observer ){ if ( IsEventAvailable( eType ) ) { if ( m_pImpl ) { InstanceObjectImplPtr spImpl = *reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl); return spImpl->AddObserver( eType, *reinterpret_cast<ObserverImpl*>(observer.GetImpl()) ); } } else { IntelMobileException ex( IntelMobileText("InstanceObject : NotSupportEvent Exception"), IntelMobileText("AddObserver"), IntelMobileText("AddObserver") ); throw( ex ); } return false;} // AddObserver() //==============================================================================// RemoveObserver() : Remove it from the observer first. This returns a pointer // That may, or may not, be 'this' it is however garaunteed // to be of the same type.//==============================================================================bool InstanceObject::RemoveObserver( Event::EventType eType, Observer& observer ){ if ( IsEventAvailable( eType ) ) { if ( m_pImpl ) { InstanceObjectImplPtr spImpl = *reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl); return spImpl->RemoveObserver( eType, *reinterpret_cast<ObserverImpl*>(observer.GetImpl()) ); } } else { IntelMobileException ex( IntelMobileText("InstanceObject : NotSupportEvent Exception"), IntelMobileText("RemoveObserver"), IntelMobileText("RemoveObserver") ); throw( ex ); } return false;} // RemoveObserver() //==============================================================================// IsEventAvailable() : //==============================================================================bool InstanceObject::IsEventAvailable( Event::EventType eType ) { if ( m_pImpl ) { InstanceObjectImplPtr spImpl = *reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl); return spImpl->IsEventAvailable( eType ); } return false;} // IsEventAvailable()//==============================================================================// InvokeMethod()//==============================================================================IntelMobileChar* InstanceObject::InvokeMethod( IntelMobileChar* methodName, IntelMobileChar* param ){ if ( IsAvailable( methodName ) ) { return (*reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl))->InvokeMethod( methodName, param ); } else { IntelMobileException ex( IntelMobileText("InstanceObject : NotSupportMethod Exception"), IntelMobileText("InvokeMethod"), IntelMobileText("InvokeMethod") ); throw( ex ); }}//==============================================================================// GetPropertyByName()//==============================================================================Property* InstanceObject::GetPropertyByName( IntelMobileChar* name, IntelMobileChar* type, IntelMobileChar* nametype ){ PROPERTYMAP *pPropertyMap = reinterpret_cast<PROPERTYMAP *>(m_Properties); IntelMobileString namestr = name; PROPERTYMAP::iterator it = pPropertyMap->find( namestr ); if ( it != pPropertyMap->end() ) return (*it).second; Property* pProperty = NULL; if ( m_pImpl ) { InstanceObjectImplPtr spImpl = *reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl); PropertyBaseImpl *pPropImpl = spImpl->GetPropertyImplByName( name, type ); if ( pPropImpl ) { if ( ::strcmp(type, IntelMobileText("Byte")) == 0 ) pProperty = new ByteProperty( new PropertyBaseImplPtr( reinterpret_cast<BytePropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("Int")) == 0 ) pProperty = new IntProperty( new PropertyBaseImplPtr( reinterpret_cast<IntPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("UInt")) == 0 ) pProperty = new UIntProperty( new PropertyBaseImplPtr( reinterpret_cast<UIntPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("Int64")) == 0 ) pProperty = new Int64Property( new PropertyBaseImplPtr( reinterpret_cast<Int64PropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("UInt64")) == 0 ) pProperty = new UInt64Property( new PropertyBaseImplPtr( reinterpret_cast<UInt64PropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("String")) == 0 ) pProperty = new StringProperty( new PropertyBaseImplPtr( reinterpret_cast<StringPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("Bool")) == 0 ) pProperty = new BoolProperty( new PropertyBaseImplPtr( reinterpret_cast<BoolPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("DateTime")) == 0 ) pProperty = new DateTimeProperty( new PropertyBaseImplPtr( reinterpret_cast<DateTimePropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("Float")) == 0 ) pProperty = new FloatProperty( new PropertyBaseImplPtr( reinterpret_cast<FloatPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("ByteArray")) == 0 ) pProperty = new ByteArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<ByteArrayPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("IntArray")) == 0 ) pProperty = new IntArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<IntArrayPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("UIntArray")) == 0 ) pProperty = new UIntArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<UIntArrayPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("Int64Array")) == 0 ) pProperty = new Int64ArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<Int64ArrayPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("UInt64Array")) == 0 ) pProperty = new UInt64ArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<UInt64PropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("StringArray")) == 0 ) pProperty = new StringArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<StringArrayPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("BoolArray")) == 0 ) pProperty = new BoolArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<BoolArrayPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("DateTimeArray")) == 0 ) pProperty = new DateTimeArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<DateTimeArrayPropertyImpl *>(pPropImpl) ) ); else if ( ::strcmp(type, IntelMobileText("FloatArray")) == 0 ) pProperty = new FloatArrayProperty( new PropertyBaseImplPtr( reinterpret_cast<FloatArrayPropertyImpl *>(pPropImpl) ) ); else pProperty = new Property( NULL, IntelMobileText("DummyProperty") ); } } if ( pProperty == NULL ) pProperty = new Property( NULL, IntelMobileText("DummyProperty") ); //if(nametype) pProperty->SetNameType( nametype ); /*else pProperty->SetNameType( type );*/ pPropertyMap->insert( it, pair<IntelMobileString, Property*>(namestr, pProperty) ); return pProperty;}//==============================================================================// IsAvailable()//==============================================================================bool InstanceObject::IsAvailable( IntelMobileChar* methodName ){ if ( m_pImpl ) { return (*reinterpret_cast<InstanceObjectImplPtr*>(m_pImpl))->IsAvailable( methodName ); } return false;}//==============================================================================
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -