[Classes] [Prev] [Next] [Methods]

CResource

Methods Index

Heritage
Description
Usage
Enums
PwrResourceType
Protected Data Members
Public Methods
Constructor and Destructor
Resource State Methods
Resource Item Methods
Protected Methods
Copy and Assignment

CResource


Heritage

Superclass: CNotifier

Subclasses: CResourceWindow, CResourceMenu


Description

The purpose of the XVT-Power++ resource mechanism is to provide a consistent interface for URL resources.

CResource is an abstract class which encapsulates resource handling. CResource defines a common interface to URL-defined XVT-Power++ resources. Menu and window resources are already derived with CResourceMenu and CResourceWindow. You can derive similar resources for string list and dialog.

For instance, when you load a window from the resource file using a given resource ID, the window and its contents are loaded in memory. The contents might represent a set of controls, subsequently providing several resources with one single window resource ID.

XVT-Power++ puts in place a mechanism that lets you load the URL resource in memory once, and then request access to any particular resource item at any time without having to reload that resource from the URL file. This in done automatically in XVT-Power++. For a given resource ID (window or menu), CResource maintains a counter representing the number of XVT-Power++ objects using that particular resource. The CResource::Hold method loads an XVT resource into memory and increments the resource counter. It then parses the XVT resource into a structure that can be traversed later in the program using the CResource methods FirstItem and NextItem. The CResource::Release method decreases the counter and releases the memory associated with a resource when no other XVT-Power++ object is using this resource (i.e., when the counter reaches zero). CResourceItems is provided as a convenience class that calls the Hold and Release methods automatically.

See Also: For more information, see CResourceItems. For details on using resources with XVT-Power++, see the "Resources" chapter in the Guide to XVT Development Solution for C++.


Usage

const short kResErrBase = 5150;
CResource *theRes = new CResourceWindow(WIN_ID);
PwrAssert(theRes, kResErrBase + 1, "Unable to
bake resource.");

theRes->Hold();
theRes->FirstItem(); // reset iterator

long theId;
while (theId = theRes->NextItem()) {
CObjectRWC *theObject = NULL;
switch (theRes->GetItemType(theId)) {
case WC_BUTTON:
theObject = new NButton(itsEnclosure,
WIN_ID, theId);
break;
case WC_EDIT:
theObject = new NEdit(itsEnclosure,
WIN_ID, theId);
break;
}
PwrAssert(theObject, kResErrBase + 2,
"Unable to bake resource item.");
theRes->IObject(theId, theObject);
CastPtr(CView, theObject)->SetCommand(theId);
}
theRes->Release();

delete theRes;

Enums

PwrResourceType

PwrWindow An XVT Portability Toolkit window
PwrDialog An XVT Portability Toolkit dialog
PwrStringList An XVT Portability Toolkit string list
PwrMenuBar An XVT Portability Toolkit menubar


Protected Data Members

long itsId The resource ID (the start ID for resources that require more than one ID
long itsEndId The end ID
long itsHoldCount A counter that tracks of how many objects are accessing that resource
Type itsType The type of the resource


Public Methods

Constructor and Destructor

CResource(PwrResourceType theType, long theId, 
long theEndId = 0L);
virtual ~CResource(void);

Resource State Methods

virtual BOOLEAN Hold(void) = 0;
virtual void Release(void) = 0;
virtual long GetId(void) const;
virtual void SetId(long theID);
virtual long GetEndId(void) const;
virtual void SetEndId(long theId);
virtual PwrResourceType GetType(void) const;
virtual void SetType(PwrResourceType theType);

Resource Item Methods

virtual BOOLEAN IObject(long theId, 
CObjectRWC *theObject) = 0;
virtual long FirstItem(void) = 0;
virtual long NextItem(void) = 0;
virtual long GetItemType(long theId) = 0;

Protected Methods

Copy and Assignment

CResource(const CResource &theResource);
CResource & operator=(const CResource &theResource);


[Classes] [Prev] [Next] [Methods]

support@xvt.com


Visit our online help desk for tech support

Copyright © 2009, Providence Software Solutions Inc. All rights reserved.