epoc32/include/mw/coeutils.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
// COEUTILS.H
williamr@2
     2
williamr@2
     3
/*
williamr@2
     4
* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     5
* All rights reserved.
williamr@2
     6
* This component and the accompanying materials are made available
williamr@4
     7
* under the terms of "Eclipse Public License v1.0"
williamr@2
     8
* which accompanies this distribution, and is available
williamr@4
     9
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
    10
*
williamr@2
    11
* Initial Contributors:
williamr@2
    12
* Nokia Corporation - initial contribution.
williamr@2
    13
*
williamr@2
    14
* Contributors:
williamr@2
    15
*
williamr@2
    16
* Description:
williamr@2
    17
*
williamr@2
    18
*/
williamr@2
    19
williamr@2
    20
williamr@2
    21
williamr@2
    22
#ifndef __COEUTILS_H__
williamr@2
    23
#define __COEUTILS_H__
williamr@2
    24
williamr@2
    25
#include <e32std.h>
williamr@2
    26
class CCoeEnv;
williamr@2
    27
williamr@2
    28
/** Provides file and path utility functions.
williamr@2
    29
williamr@2
    30
@publishedAll
williamr@2
    31
@released */
williamr@2
    32
class ConeUtils
williamr@2
    33
	{
williamr@2
    34
public:
williamr@2
    35
	IMPORT_C static TBool FileExists(const TDesC& aFileName);
williamr@2
    36
	IMPORT_C static void EnsurePathExistsL(const TPtrC& aFileName);
williamr@2
    37
	};
williamr@2
    38
williamr@2
    39
williamr@2
    40
/** 
williamr@2
    41
Class encapsulates methods for opening and closing localised resource files
williamr@2
    42
in the CONE environment. The actual reading of resources from an opened 
williamr@2
    43
resource file is done using various CCoeEnv provided resource-reading 
williamr@2
    44
methods. The Cone Resource Loader API consists of the RCoeResourceLoader class.
williamr@2
    45
williamr@2
    46
Only one resource at a time may be opened by one RCoeResourceLoader instance. 
williamr@2
    47
You can use several RCoeResourceLoader instances for accessing several 
williamr@2
    48
resources simultaneously or use one instance and close the previous resource
williamr@2
    49
before opening a new one.
williamr@2
    50
williamr@2
    51
The implementation uses BaflUtils::NearestLanguageFile to search for
williamr@2
    52
a localised resource in proper search order.
williamr@2
    53
 
williamr@2
    54
Usage example:  
williamr@2
    55
williamr@2
    56
@code
williamr@2
    57
#include <coeutils.h>  
williamr@2
    58
williamr@2
    59
// Get CCoeEnv instance
williamr@2
    60
CEikonEnv* eikEnv = CEikonEnv::Static();
williamr@2
    61
// Initialize loader
williamr@2
    62
RCoeResourceLoader rLoader(eikEnv);
williamr@2
    63
williamr@2
    64
// Push resource loader to cleanup stack, so that it will always be properly 
williamr@2
    65
// closed when popped.
williamr@2
    66
CleanupClosePushL(rLoader);
williamr@2
    67
williamr@2
    68
// Open resource file
williamr@2
    69
_LIT( KSampleResourceFileName, "Z:\\System\\Apps\\sample\\sample.rsc" );
williamr@2
    70
TFileName fileName(KSampleResourceFileName);
williamr@2
    71
rLoader.OpenL(fileName);
williamr@2
    72
williamr@2
    73
// Read a resource   
williamr@2
    74
iSomeArray = eikEnv->ReadDesC16ArrayResourceL(R_SOME_RESOURCE);
williamr@2
    75
williamr@2
    76
// Pop and destroy rLoader from stack. 
williamr@2
    77
// This also calls the rLoader close function after CleanupClosePushL is used.
williamr@2
    78
CleanupStack::PopAndDestroy(); // rLoader
williamr@2
    79
@endcode
williamr@2
    80
williamr@2
    81
@publishedAll
williamr@2
    82
@released */
williamr@2
    83
NONSHARABLE_CLASS(RCoeResourceLoader)
williamr@2
    84
    {
williamr@2
    85
public:
williamr@2
    86
    IMPORT_C RCoeResourceLoader(CCoeEnv& aEnv);
williamr@2
    87
    IMPORT_C TInt Open(TFileName& aFileName);
williamr@2
    88
    IMPORT_C void OpenL(TFileName& aFileName);
williamr@2
    89
    IMPORT_C void Close();
williamr@2
    90
private:
williamr@2
    91
    // Prohibit copy constructor and assigment operator because not deriving from CBase.
williamr@2
    92
    RCoeResourceLoader();
williamr@2
    93
    RCoeResourceLoader(const RCoeResourceLoader&);
williamr@2
    94
    RCoeResourceLoader& operator= (const RCoeResourceLoader&);
williamr@2
    95
private:
williamr@2
    96
    // Needed for closing
williamr@2
    97
    CCoeEnv& iEnv; 
williamr@2
    98
    TInt iResourceFileOffset;
williamr@2
    99
    };
williamr@2
   100
williamr@2
   101
williamr@2
   102
#endif	// __COEUTILS_H__