diff -r 000000000000 -r ba25891c3a9e secureswitools/swisistools/source/sisxlibrary/element.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/secureswitools/swisistools/source/sisxlibrary/element.h Thu Dec 17 08:51:10 2009 +0200 @@ -0,0 +1,247 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Note: This file may contain code to generate corrupt files for test purposes. +* Such code is excluded from production builds by use of compiler defines; +* it is recommended that such code should be removed if this code is ever published publicly. +* smart pointers; used as elements in SIS arrays and elsewhere +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __ELEMENT_H__ +#define __ELEMENT_H__ + +#include +#include + +#include "sharedcount.h" + + + + + +template struct shared_ptr_traits + { + typedef T& reference; + }; + + +template<> struct shared_ptr_traits + { + typedef void reference; + }; + + + + +template class CElement + + { +public: + typedef T* TPtr; + typedef typename shared_ptr_traits::reference TRef; + + CElement (); + + template explicit CElement (Y* ay) : + iPtr (ay), + iCount (ay) { } + + template + CElement& operator = (CElement const& r) + { + iPtr = r.iPtr; + iCount = r.iCount; + return *this; + } + + template void reset (Y* ay) + { + assert (ay == 0 || ay != iPtr); // can't self reset + this_type (ay).swap (*this); + } + + template + bool _internal_less (CElement const& rhs) const + { + return iCount < rhs.iCount; + } + void reset (); + TRef operator* () const + { + assert (iPtr != NULL); + return *iPtr; + } + T* operator -> () const; + T* get () const; + bool operator! () const; + long UseCount () const; + void swap (CElement& aOther); + + void Verify (const TUint32 aLanguages) const; + TUint32 ByteCount (const bool aInArray) const; + bool WasteOfSpace () const; + void MakeNeat (); + std::string Name () const; + void Dump (std::ostream& aStream, const int aLevel) const; + TUint32 ByteCountWithHeader (const bool aInArray) const; + void CalculateCrc (TCRC& aCRC, const bool aIsArrayElement) const; + std::string NoteIfOptional () const; +#ifdef GENERATE_ERRORS + virtual void CreateDefects (); +#endif // GENERATE_ERRORS + void SkipOldWriteNew (TSISStream& aFile) const; + +private: + T* iPtr; + CSharedCount iCount; + }; + + + +template inline CElement ::CElement () : + iPtr (NULL) + { + } + + +template inline void CElement ::reset () + { + this_type ().swap (*this); + } + + +template T* CElement ::operator -> () const + { + assert (iPtr != NULL); + return iPtr; + } + +template inline T* CElement ::get () const + { + return iPtr; + } + +template inline bool CElement ::operator! () const + { + return iPtr == 0; + } + +template inline long CElement ::UseCount () const + { + return iCount.UseCount (); + } + +template inline void CElement ::swap (CElement& aOther) + { + std::swap (iPtr, aOther.iPtr); + iCount.swap (aOther.iCount); + } + +template inline + void CElement ::Verify (const TUint32 aLanguages) const + { + iPtr -> Verify (aLanguages); + } + +template inline TUint32 CElement ::ByteCount (const bool aInArray) const + { + return iPtr -> ByteCount (aInArray); + } + +template inline bool CElement ::WasteOfSpace () const + { + return iPtr -> WasteOfSpace (); + } + +template inline void CElement ::MakeNeat () + { + iPtr -> MakeNeat (); + } + +template inline std::string CElement ::Name () const + { + return iPtr -> Name (); + } + +template inline + void CElement ::Dump (std::ostream& aStream, const int aLevel) const + { + iPtr -> Dump (aStream, aLevel); + } + +template inline + TUint32 CElement ::ByteCountWithHeader (const bool aInArray) const + { + return iPtr -> ByteCountWithHeader (aInArray); + } + +template inline + void CElement ::CalculateCrc (TCRC& aCRC, const bool aIsArrayElement) const + { + iPtr -> CalculateCrc (aCRC, aIsArrayElement); + } + +template inline std::string CElement ::NoteIfOptional () const + { + return iPtr -> NoteIfOptional (); + } + +#ifdef GENERATE_ERRORS +template inline void CElement ::CreateDefects () + { + iPtr -> CreateDefects (); + } +#endif // GENERATE_ERRORS + +template inline void CElement ::SkipOldWriteNew (TSISStream& aFile) const + { + iPtr -> SkipOldWriteNew (aFile); + } + +template inline bool operator == (CElement const& a, CElement const& b) + { + return a.get () == b.get (); + } + +template inline bool operator != (CElement const& a, CElement const& b) + { + return a.get () != b.get (); + } + +template inline bool operator < (CElement const& a, CElement const& b) + { + return a._internal_less (b); + } + +template inline void swap (CElement& a, CElement& b) + { + a.swap (b); + } + +template inline T* get_pointer (CElement const& p) + { + return p.get (); + } + + + +#endif // __ELEMENT_H__