//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TRegObject.h // = Version : ver2.0 // = Author : xlc // = CreateDate : 2002-09-09 // = Description: 类的声明 // = Maintainers: // //-----------------------------------------------------------------------------+ // This is a part of the Active Template Library. // Copyright (C) 1996-1998 Microsoft Corporation // All rights reserved. // // This source code is only intended as a supplement to the // Active Template Library Reference and related // electronic documentation provided with the library. // See these sources for detailed information regarding the // Active Template Library product. #ifndef _TREGOBJECT_H_ #define _TREGOBJECT_H_ class TRegObject { friend class TRegProperty; public: class PropMemberEntry { CString m_Name; BYTE * m_pValue ; public: PropMemberEntry ( BYTE *pValue , LPCTSTR pszName ) { ASSERT( pValue ); m_pValue = pValue; m_Name = pszName; } LPCTSTR GetName() { return (const TCHAR *)m_Name; } BYTE *GetPValue() { ASSERT( m_pValue ); return m_pValue; } }; class DWORDEntry : public PropMemberEntry { public: DWORDEntry ( DWORD *pValue , LPCTSTR pszName ) : PropMemberEntry ( (BYTE *)pValue , pszName ) { } DWORD GetValue() { return *(DWORD *)PropMemberEntry::GetPValue(); } DWORD *GetPValue() { return (DWORD *)PropMemberEntry::GetPValue(); } DWORD &GetReference() { return *(DWORD *)PropMemberEntry::GetPValue(); } }; class intEntry : public PropMemberEntry { public: intEntry ( int *pValue , LPCTSTR pszName ) : PropMemberEntry ( (BYTE *)pValue , pszName ) { } int GetValue() { return *(int *)PropMemberEntry::GetPValue(); } int *GetPValue() { return (int *)PropMemberEntry::GetPValue(); } int &GetReference() { return *(int *)PropMemberEntry::GetPValue(); } }; class boolEntry : public PropMemberEntry { public: boolEntry ( bool *pValue , LPCTSTR pszName ) : PropMemberEntry ( (BYTE *)pValue , pszName ) { ; } bool GetValue() { return *(bool *)PropMemberEntry::GetPValue(); } bool *GetPValue() { return (bool *)PropMemberEntry::GetPValue(); } bool &GetReference() { return *(bool *)PropMemberEntry::GetPValue(); } }; class CStringEntry : public PropMemberEntry { public: CStringEntry ( CString *pValue , LPCTSTR pszName ) : PropMemberEntry ( (BYTE *)pValue , pszName ) { } CString GetValue() { return *(CString *)PropMemberEntry::GetPValue(); } CString *GetPValue() { return (CString *)PropMemberEntry::GetPValue(); } CString &GetReference() { return *(CString *)PropMemberEntry::GetPValue(); } }; public: TRegObject(const TRegObject ®Obj); TRegObject(LPCTSTR pszObjectKey, bool bVersionized = FALSE, LPCTSTR pszClassname = NULL, TRegProperty *pobjMaster= NULL, bool bDeleteByRegProperty = FALSE); virtual ~TRegObject (); virtual bool Store(); virtual bool Read(); virtual bool Exchange( bool bStoring ); TRegObject & operator = ( const TRegObject & ); void SetTopRootKey(HKEY hKey); void SetMaster( TRegProperty * pobjMaster ); void SetObjectKey( LPCTSTR pszObjectKey ); void SetClassname( LPCTSTR pszClassname ); void SetMasterKey( LPCTSTR pszMasterKey ); CString GetKey() const; CString GetMasterKey() const; bool Init(); bool SetValue ( LPCTSTR pszName , int nValue); bool SetValue ( LPCTSTR pszName , bool bValue); bool SetValue ( LPCTSTR pszName , DWORD dwValue); bool SetValue ( LPCTSTR pszName , double dValue); bool SetValue ( LPCTSTR pszName , LPCTSTR *pszValue); bool SetValue ( LPCTSTR pszName , BYTE *pValue , DWORD size); bool SetValue ( LPCTSTR pszName , LPCTSTR pszValue , bool bUnExanded = FALSE); bool GetValue ( LPCTSTR pszName , int &nValue); bool GetValue ( LPCTSTR pszName , bool &bValue); bool GetValue ( LPCTSTR pszName , DWORD &dwValue); bool GetValue ( LPCTSTR pszName , double &dValue); bool GetValue ( LPCTSTR pszName , BYTE *pValue , DWORD size); bool GetValue ( LPCTSTR pszName , CString &Value , bool * pbUnExanded = NULL); bool GetValue ( LPCTSTR pszName , LPTSTR pszValue , DWORD size , bool * pbUnExanded); bool AttachValue ( int *pintValue , LPCTSTR pszName); bool AttachValue ( DWORD *pdwValue , LPCTSTR pszName); bool AttachValue ( bool *pboolValue , LPCTSTR pszName); bool AttachValue ( CString *pstrValue , LPCTSTR pszName); protected: TRegObject (); bool CheckExists (); bool Open (bool bCreate = true, REGSAM samDesired = KEY_READ | KEY_WRITE); void Close (); bool GetValue ( LPCTSTR pszName ); protected: BYTE *m_pData; DWORD m_DataType; DWORD m_DataSize; private: void init (); void clear (); private: TRegProperty * m_pobjMaster; LONG m_Retcode; HKEY m_hkObject; HKEY m_hKeyTopRoot; bool m_bVersionized; bool m_bDeleteByRegProperty; DWORD m_dwDisposition; REGSAM m_bOpen; CString m_ObjectKey; CString m_Classname; CPtrArray m_ArrDWORD; CPtrArray m_ArrCString; CPtrArray m_ArrInt; CPtrArray m_ArrBool; }; #endif