PixelLightAPI  .
Registry.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Registry.h                                     *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_REGISTRY_H__
00024 #define __PLCORE_REGISTRY_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/String/String.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Forward declarations                                  ]
00042 //[-------------------------------------------------------]
00043 class RegistryImpl;
00044 
00045 
00046 //[-------------------------------------------------------]
00047 //[ Classes                                               ]
00048 //[-------------------------------------------------------]
00049 /**
00050 *  @brief
00051 *    Registry key handle
00052 *
00053 *  @remarks
00054 *    For Windows OS: Please note, if you access the registry on a 64 bit OS by using
00055 *    a 32 bit application 'Wow6432Node' may be added automatically by the OS. Usually this
00056 *    is no problem as long as you always use a 32 bit application to access this data - but
00057 *    if you have a 64 bit application and want to access the same registry data the 32 bit
00058 *    application is using you have to keep this topic in mind.
00059 */
00060 class Registry {
00061 
00062 
00063     //[-------------------------------------------------------]
00064     //[ Public definitions                                    ]
00065     //[-------------------------------------------------------]
00066     public:
00067         /**
00068         *  @brief
00069         *    Registry types
00070         */
00071         enum ERegistry {
00072             None = 0,   /**< None */
00073             Windows     /**< Windows */
00074         };
00075 
00076         /**
00077         *  @brief
00078         *    Registry keys
00079         */
00080         enum EKey {
00081             KeyNone = 0,        /**< None */
00082             KeyClassesRoot,     /**< Classes root */
00083             KeyCurrentUser,     /**< Current user */
00084             KeyLocalMachine,    /**< Local machine */
00085             KeyUsers            /**< Users */
00086         };
00087 
00088         /**
00089         *  @brief
00090         *    Registry access
00091         */
00092         enum EAccess {
00093             RegRead   = 1,  /**< Read */
00094             RegWrite  = 2,  /**< Write */
00095             RegNotify = 4   /**< Notify */
00096         };
00097 
00098         /**
00099         *  @brief
00100         *    Registry value types
00101         */
00102         enum EType {
00103             TypeNone = 0,       /**< None */
00104             TypeBinary,         /**< Binary */
00105             TypeDWord,          /**< Double word */
00106             TypeString,         /**< String */
00107             TypeExpandString,   /**< Expand string */
00108             TypeMultiString     /**< Multi string */
00109         };
00110 
00111 
00112     //[-------------------------------------------------------]
00113     //[ Public functions                                      ]
00114     //[-------------------------------------------------------]
00115     public:
00116         /**
00117         *  @brief
00118         *    Constructor
00119         */
00120         PLCORE_API Registry();
00121 
00122         /**
00123         *  @brief
00124         *    Constructor
00125         *
00126         *  @param[in] nKey
00127         *    Registry key
00128         *  @param[in] sSubKey
00129         *    Name of subkey
00130         *  @param[in] nAccess
00131         *    Access modes (combination of 'EAccess' values)
00132         */
00133         PLCORE_API Registry(EKey nKey, const String &sSubKey, uint32 nAccess);
00134 
00135         /**
00136         *  @brief
00137         *    Copy constructor
00138         *
00139         *  @param[in] cRegistry
00140         *    Registry handle to copy
00141         */
00142         PLCORE_API Registry(const Registry &cRegistry);
00143 
00144         /**
00145         *  @brief
00146         *    Destructor
00147         */
00148         PLCORE_API ~Registry();
00149 
00150         /**
00151         *  @brief
00152         *    Get type of registry
00153         *
00154         *  @return
00155         *    Type of registry ('None' if no registry is available on your system!)
00156         */
00157         inline ERegistry GetRegistryType() const;
00158 
00159         /**
00160         *  @brief
00161         *    Open registry key
00162         *
00163         *  @param[in] nKey
00164         *    Registry key
00165         *  @param[in] sSubKey
00166         *    Name of subkey
00167         *  @param[in] nAccess
00168         *    Access modes (combination of 'EAccess' values)
00169         *
00170         *  @return
00171         *    'true' if all went fine, else 'false'
00172         */
00173         inline bool Open(EKey nKey, const String &sSubKey, uint32 nAccess);
00174 
00175         /**
00176         *  @brief
00177         *    Create a new registry key
00178         *
00179         *  @param[in] nKey
00180         *    Registry key
00181         *  @param[in] sSubKey
00182         *    Name of subkey
00183         *  @param[in] nAccess
00184         *    Access modes (combination of 'EAccess' values)
00185         *
00186         *  @return
00187         *    'true' if all went fine, else 'false'
00188         */
00189         inline bool Create(EKey nKey, const String &sSubKey, uint32 nAccess);
00190 
00191         /**
00192         *  @brief
00193         *    Delete the registry key
00194         *
00195         *  @return
00196         *    'true' if all went fine, else 'false'
00197         */
00198         inline bool Delete();
00199 
00200         /**
00201         *  @brief
00202         *    Close registry key
00203         */
00204         inline void Close();
00205 
00206         /**
00207         *  @brief
00208         *    Get ID of opened registry key
00209         *
00210         *  @return
00211         *    Key ID
00212         */
00213         inline EKey GetOpenKey() const;
00214 
00215         /**
00216         *  @brief
00217         *    Get name of opened sub-key
00218         *
00219         *  @return
00220         *    Name of sub-key
00221         */
00222         inline String GetOpenSubKey() const;
00223 
00224         /**
00225         *  @brief
00226         *    Get access modes
00227         *
00228         *  @return
00229         *    Access modes
00230         */
00231         inline uint32 GetOpenAccessMode() const;
00232 
00233         /**
00234         *  @brief
00235         *    Returns the number of sub-keys
00236         *
00237         *  @return
00238         *    Number of sub-keys
00239         */
00240         inline uint32 GetNumOfSubKeys() const;
00241 
00242         /**
00243         *  @brief
00244         *    Get a sub-key of the opened registry key
00245         *
00246         *  @param[in] nIndex
00247         *    Index of the sub-key
00248         *
00249         *  @return
00250         *    Name of the sub-key, or "" if no more sub-keys are present
00251         */
00252         inline String GetSubKey(uint32 nIndex) const;
00253 
00254         /**
00255         *  @brief
00256         *    Returns the number of values
00257         *
00258         *  @return
00259         *    Number of values
00260         */
00261         inline uint32 GetNumOfValues() const;
00262 
00263         /**
00264         *  @brief
00265         *    Get a value of the opened registry key
00266         *
00267         *  @param[in] nIndex
00268         *    Index of the value
00269         *
00270         *  @return
00271         *    Name of the value, or "" if no more values are present
00272         */
00273         inline String GetValue(uint32 nIndex) const;
00274 
00275         /**
00276         *  @brief
00277         *    Get the type of a given value
00278         *
00279         *  @param[in] sName
00280         *    Name of the value
00281         *
00282         *  @return
00283         *    Type of the value
00284         */
00285         inline EType GetValueType(const String &sName) const;
00286 
00287         /**
00288         *  @brief
00289         *    Get a value of type string
00290         *
00291         *  @param[in] sName
00292         *    Name of the value
00293         *
00294         *  @return
00295         *    String value
00296         */
00297         inline String GetValueString(const String &sName) const;
00298 
00299         /**
00300         *  @brief
00301         *    Get a value of type 'dword'
00302         *
00303         *  @param[in] sName
00304         *    Name of the value
00305         *
00306         *  @return
00307         *    Value
00308         */
00309         inline uint32 GetValueDWord(const String &sName) const;
00310 
00311         /**
00312         *  @brief
00313         *    Get a value of type binary
00314         *
00315         *  @param[in]  sName
00316         *    Name of the value
00317         *  @param[out] pBuffer
00318         *    Buffer to receive the value, if a null pointer, returns the number of  bytes required
00319         *  @param[in]  nSize
00320         *    Size of the given buffer in bytes, ignored if 'pBuffer' is a null pointer
00321         *
00322         *  @return
00323         *    Number of bytes written to the buffer
00324         */
00325         inline uint32 GetValueBinary(const String &sName, uint8 *pBuffer, uint32 nSize) const;
00326 
00327         /**
00328         *  @brief
00329         *    Set a value of type string
00330         *
00331         *  @param[in] sName
00332         *    Name of the value
00333         *  @param[in] sValue
00334         *    String value to set
00335         *
00336         *  @return
00337         *    'true' if all went fine, else 'false'
00338         */
00339         inline bool SetValueString(const String &sName, const String &sValue);
00340 
00341         /**
00342         *  @brief
00343         *    Set a value of type 'dword'
00344         *
00345         *  @param[in] sName
00346         *    Name of the value
00347         *  @param[in] nValue
00348         *    Value to set
00349         *
00350         *  @return
00351         *    'true' if all went fine, else 'false'
00352         */
00353         inline bool SetValueDWord(const String &sName, uint32 nValue);
00354 
00355         /**
00356         *  @brief
00357         *    Set a value of type binary
00358         *
00359         *  @param[in] sName
00360         *    Name of the value
00361         *  @param[in] pBuffer
00362         *    Buffer containing the value to set (if a null pointer, the function fails)
00363         *  @param[in] nSize
00364         *    Size of the given buffer in bytes
00365         *
00366         *  @return
00367         *    'true' if all went fine, else 'false'
00368         */
00369         inline bool SetValueBinary(const String &sName, const uint8 *pBuffer, uint32 nSize);
00370 
00371         /**
00372         *  @brief
00373         *    Write all values to the registry
00374         */
00375         inline void Flush();
00376 
00377         /**
00378         *  @brief
00379         *    Copy operator
00380         *
00381         *  @param[in] cRegistry
00382         *    Source registry to copy from
00383         *
00384         *  @return
00385         *    Reference to this instance
00386         */
00387         inline Registry &operator =(const Registry &cRegistry);
00388 
00389 
00390     //[-------------------------------------------------------]
00391     //[ Private data                                          ]
00392     //[-------------------------------------------------------]
00393     private:
00394         RegistryImpl *m_pRegistryImpl;  /**< Pointer to the system specific implementation (can be a null pointer!) */
00395 
00396 
00397 };
00398 
00399 
00400 //[-------------------------------------------------------]
00401 //[ Namespace                                             ]
00402 //[-------------------------------------------------------]
00403 } // PLCore
00404 
00405 
00406 //[-------------------------------------------------------]
00407 //[ Implementation                                        ]
00408 //[-------------------------------------------------------]
00409 #include "PLCore/Registry/Registry.inl"
00410 
00411 
00412 #endif // __PLCORE_REGISTRY_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:58
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported