epoc32/include/mw/cnode.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.
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // This contains the definitions of CDataDelete, CDataNoDelete, CIntAttribute, CNode, and CTypedNode.
    15 // CDataNoDelete is a base class to CDataDelete and are essentially a wrapper around an HBufC16.
    16 // The node owns the data that is added to it and therefore is responsible for deleting all its data,
    17 // hence theses two classes allow a user to have non deletable data. Internally to the node it is also 
    18 // sometimes necessary to change the data into either deletable or non-deletable data api's are provided
    19 // for this.
    20 // CIntAttribute is wrapper around a TInt, this is provided as the nodes attribute value is a CBase* however
    21 // it might be desirable to store integer's in here. Attribute value is owned by the node therefore the node is
    22 // responsible for deleting it.
    23 // CNode is the basis for constructing a tree. It consists of an array of child nodes, node type, a parent node,
    24 // an array of attributes, and a data member. Internally the data member is defined as CDataNoDelete however
    25 // to the user all the exported api's take an HBufC16*. Data is owned by the node and is destroyed by the node,
    26 // However in certain circumstances this is not desirable hence the api's to make the data non-deletable. The
    27 // node type is defined as a TAny* however normal usage would use the templated node - CTypedNode. The node type
    28 // is used to identify groups of nodes. The attribute array is fairy simple and consists of AttributeType and 
    29 // AttributeValue. AttributeType can be defined by using the templated class and should be a 32bit value. AttributeValue
    30 // can be any object derived from CBase and the node takes ownership therefore the node delete's it.
    31 // Basic usage should be to use the templated class in order to make use of the templated types (TNodeType,TAttributeType).
    32 // Create a node for example:
    33 // CTypedNode<CNode*, const TDesC*> *tree = CTypedNode<CNode*, const TDesC*>::NewL(0,0);
    34 // add a new child:
    35 // CNODE *TestChildNode1 = tree->AppendNodeL(aTempNodeForNodeType);
    36 // add some data:
    37 // TestChildNode1->SetDataL(aHBufC16);
    38 // add an attribute:
    39 // TestChildNode1->->AddAttributeL(aTAttributeType,aCBasePointerAttributeValue);
    40 // Explanation of individual api's is documented below.
    41 //
    42 
    43  
    44 
    45 #ifndef __CNODE_H__
    46 #define __CNODE_H__
    47 
    48 #include <e32base.h>
    49 #include <f32file.h>
    50 
    51 
    52 /**
    53 	@file
    54 	@publishedAll
    55 	@deprecated
    56 */
    57 
    58 //Granularity of arrays
    59 const TInt KGranularity = 5;
    60 
    61 //enum of panic reasons
    62 enum TNodePanic
    63 	{
    64 	ENodeBadArgument,
    65 	ENodeNoChildren,
    66 	ENoData,
    67 	EAttributeFailure
    68 	};
    69 
    70 //node panic function
    71 inline void Panic(TNodePanic aPanic);
    72 
    73 //Wrapper around an HBufC16 doesn't delete data
    74 //##ModelId=3B666BCC0303
    75 class CDataNoDelete : public CBase
    76 /** Provides a wrapper around an HBufC16: the buffer is not deleted when the object is deleted.
    77 */
    78 	{
    79 public:
    80 	//##ModelId=3B666BCC032D
    81 	CDataNoDelete(HBufC16* aData);
    82 	//##ModelId=3B666BCC032C
    83 	virtual ~CDataNoDelete();
    84 	//##ModelId=3B666BCC0324
    85 	HBufC16* SetData(HBufC16* aData);
    86 	//##ModelId=3B666BCC0322
    87 	virtual void ResetDataPointer(HBufC16* aData);
    88 	//##ModelId=3B666BCC0321
    89 	HBufC16* Data();
    90 
    91 protected:
    92 	/** The wrapped buffer. */
    93 	//##ModelId=3B666BCC0319
    94 	HBufC16* iData;
    95 	};
    96 
    97 //Wrapper around an HBufC16 does delete data
    98 //##ModelId=3B666BCC0399
    99 class CDataDelete : public CDataNoDelete
   100 /** Provides a wrapper around an HBufC16: the buffer is deleted when the 
   101 object is deleted.
   102 */
   103 	{
   104 public:
   105 	//##ModelId=3B666BCC03B7
   106 	CDataDelete(HBufC16* aData);
   107 	//##ModelId=3B666BCC03B0
   108 	virtual ~CDataDelete();
   109 	//##ModelId=3B666BCC03AE
   110 	virtual void ResetDataPointer(HBufC16* aData);
   111 	};
   112 
   113 //Wrapper around an HBufC16 does delete data (FileName)
   114 // After Removing referenced File 
   115 //##ModelId=3B666BC7026F
   116 class CFileDataDelete : public CDataNoDelete
   117 /** Provides a wrapper around a filename: the referenced file is deleted when the object is deleted.
   118 */
   119 	{
   120 public:
   121 	//##ModelId=3B666BC7028F
   122 	CFileDataDelete(HBufC16* aData);
   123 	//##ModelId=3B666BC7028E
   124 	virtual ~CFileDataDelete();
   125 	//##ModelId=3B666BC70285
   126 	virtual void ResetDataPointer(HBufC16* aData);
   127 private:
   128 	//##ModelId=3B666BC70284
   129 	void RemoveFile();
   130 	};
   131 
   132 //Wrapper around a TInt used for attribute values in order to allow the node to call a dtor
   133 //##ModelId=3B666BC6023E
   134 class CIntAttribute : public CBase
   135 /** Provides an object wrapper around a TInt value. */
   136 	{
   137 public:
   138 	//##ModelId=3B666BC6025B
   139 	inline CIntAttribute(TInt aInteger);		
   140 	//##ModelId=3B666BC6025A
   141 	inline TInt Int() const;
   142 private:
   143 	//##ModelId=3B666BC60264
   144 	CIntAttribute();
   145 	//##ModelId=3B666BC60253
   146 	TInt iInteger;
   147 	};
   148 
   149 //
   150 // Node class
   151 // Normal usage would be to use CTypedNode in order to use specific templated types
   152 //
   153 
   154 //##ModelId=3B666BCD02D2
   155 class CNode : public CBase 
   156 	{
   157 public:
   158 	//##ModelId=3B666BCE0139
   159 	IMPORT_C ~CNode();
   160 
   161 	//NewL parameters aType to indentify the type of node, CNode* to set the parent of this node
   162 	//##ModelId=3B666BCE0125
   163 	IMPORT_C static CNode* NewL(TAny* aType,CNode* aParent);
   164 
   165 	//Deletes a child node which is passed in as a parameter
   166 	//##ModelId=3B666BCE011C
   167 	IMPORT_C void DeleteChildNode(CNode* aNode);
   168 
   169 	//Deletes all the child nodes haging of this node
   170 	//##ModelId=3B666BCE011B
   171 	IMPORT_C void DeleteAllChildNodes();
   172 
   173 	//Creates a new node and adds it to the childlist, reference to new node is returned. Can leave if it can't allocate memory for a new node
   174 	//Type of node is the parameter
   175 	//##ModelId=3B666BCE0108
   176 	IMPORT_C CNode& AppendNodeL(TAny* aType = 0);
   177 
   178 	//Appends a node which is passed in as a parameter to this node, so its added to the childlist
   179 	//##ModelId=3B666BCE00FD
   180 	IMPORT_C void AppendNodeToThisNodeL(CNode* aNode);
   181 
   182 	//Sets the data in the node to the parameter that is passed in. It's deletable and the node will delete it in dtor
   183 	//Push aDataNowNodeOwns onto the CleanupStack before calling then pop off on return
   184 	//##ModelId=3B666BCE00F3
   185 	IMPORT_C void SetDataL(HBufC16* aDataNowNodeOwns);
   186 
   187 	//returns the data stored in the node, which is returned as an HBufC16*
   188 	//##ModelId=3B666BCE00EB
   189 	IMPORT_C HBufC16* Data() const;
   190 
   191 	//WARNING this function can leave as it deletes the wrapper object and then creates
   192 	//a new non deletable wrapper object and sets the data pointer inside the new object
   193 	//IF THIS LEAVES YOU WILL LOSE YOUR DATA
   194 	//##ModelId=3B666BCE00EA
   195 	IMPORT_C void SetDataNoDeleteL();
   196 
   197 	//WARNING this function can leave as it deletes the wrapper object and then creates
   198 	//a new deletable wrapper object then sets the pointer in the new object
   199 	//##ModelId=3B666BCE00E9
   200 	IMPORT_C void ClearSetDataNoDeleteL();
   201 
   202 	// Sets the data in the node to the FileName parameter that is passed in. 
   203 	// It's deletable and the node will delete it, and the file it refers to in dtor
   204 	// Push aDataLocationNowNodeOwns onto the CleanupStack before calling then pop off on return
   205 	//##ModelId=3B666BCE00DF
   206 	IMPORT_C void SetFileDataL(HBufC16* aFileDataLocationNowNodeOwns);
   207 
   208 	//Resets the data pointer to point to aData parameter will delete the data that is owned by the node
   209 	//##ModelId=3B666BCE00D5
   210 	IMPORT_C void ResetDataPointer(HBufC16* aData);
   211 
   212 	//returns a reference to the absolute root of the tree
   213 	//##ModelId=3B666BCE00CB
   214 	IMPORT_C const CNode& Root() const;
   215 
   216 	//returns a child node which is stored in the array of children. The child node is accessed by the index that is the parameter.
   217 	//##ModelId=3B666BCE00C1
   218 	IMPORT_C CNode* Child(TInt aByIndex) const;
   219 
   220 	//Returns either the first child of this node if the parameter is NULL. Or it returns the next chld in the array after
   221 	//the child passed in as a parameter
   222 	//##ModelId=3B666BCE00AE
   223 	IMPORT_C CNode* NextChild(const CNode* aNode = NULL) const;
   224 
   225 	//returns the previous child to the child passed in as a parameter. The node parameter is a reference because its the child previous
   226 	//to the node passed in which obviously must exist
   227 	//##ModelId=3B666BCE00A4
   228 	IMPORT_C CNode* PrevChild(const CNode& aNode) const;
   229 
   230 	//Returns the parent of this node
   231 	//##ModelId=3B666BCE00A3
   232 	IMPORT_C CNode* Parent() const;
   233 
   234 	//WARNING this function can leave as it calls AppendNodeToThisNode. The aParent parameter is the node to which you would like to make
   235 	//the parent of 'this' node.
   236 	//It removes itself from the childlist of it's current parent
   237 	//##ModelId=3B666BCE0099
   238 	IMPORT_C void ReparentL(CNode* aParent);
   239 
   240 	//Returns the next sibling which means in effect that it asks for the next child of its parent.
   241 	//Sibling means brother or sister.
   242 	//##ModelId=3B666BCE0090
   243 	IMPORT_C CNode* NextSibling() const;
   244 
   245 	//Returns the previous sibling which means in effect that it asks for the previous child of its parent.
   246 	//Sibling means brother or sister.
   247 	//##ModelId=3B666BCE008F
   248 	IMPORT_C CNode* PrevSibling() const;
   249 
   250 	//returns the number of children that this node has
   251 	//##ModelId=3B666BCE0085
   252 	IMPORT_C TInt NumberImmediateChildren() const;
   253 
   254 	//Deletes the attribute of which is of aAttributeType (the parameter)
   255 	//WARNING Attribute values of nodes will be deleted as the node owns them if you don't want it deleted then use a wrapper
   256 	//##ModelId=3B666BCE007C
   257 	IMPORT_C void DeleteAttribute(TAny* aAttributeType);
   258 
   259 	//Deletes all the attributes of this node
   260 	//WARNING Attribute values of nodes will be deleted as the node owns them if you don't want it deleted then use a wrapper
   261 	//##ModelId=3B666BCE007B
   262 	IMPORT_C void DeleteAllAttributes();
   263 
   264 	//remove an attribute without deleting it, this is done by simply setting the attributeValue pointer to NULL
   265 	//WARNING you are now responsiblefor the destruction of this attribute value
   266 	//##ModelId=3B666BCE0071
   267 	IMPORT_C void RemoveAttributeNoDelete(TAny* aAttributeType);
   268 
   269 	// Returns the number of attributes that this node has
   270 	//##ModelId=3B666BCE0067
   271 	IMPORT_C TInt AttributeCount() const;
   272 
   273 	//Returns the type of attribute (AttributeType) at a given index...NOT the attributeValue
   274 	//##ModelId=3B666BCE005D
   275 	IMPORT_C TAny* AttributeTypeByIndex(TInt aIndex) const; 
   276 
   277 	//Returns the value of an attribute (AttributeValue) at a given index...NOT the attributeType
   278 	//##ModelId=3B666BCE003F
   279 	IMPORT_C CBase* AttributeByIndex(TInt aIndex) const;
   280 	//##ModelId=3B666BCE0049
   281 	IMPORT_C CBase* AttributeByIndex(TInt aIndex,TAny*& aType) const;
   282 
   283 	//Adds an attribute, parameters are the type of attribute and its value
   284 	//WARNING node takes ownership of aAttributeValue
   285 	//Push aAttributeValue onto the CleanupStack before calling then pop off on return
   286 	//##ModelId=3B666BCE002B
   287 	IMPORT_C void AddAttributeL(TAny* AttributeType, CBase* aAttributeValue);
   288 
   289 	//Adds data to the node and also adds an attribute, parameters are the Data to be added, the type of attribute and its value
   290 	//WARNING node takes ownership of aData and aAttributeValue
   291 	//Push aAttributeValue and aData onto the CleanupStack before calling then pop off on return
   292 	//##ModelId=3B666BCE000D
   293 	IMPORT_C void AddDataAndAttributeL(HBufC16 *aData, TAny* AttributeType, CBase* aAttributeValue);
   294 
   295 	//Returns an attribute value for the given AttributeType(the parameter)
   296 	//##ModelId=3B666BCE0003
   297 	IMPORT_C CBase* Attribute(TAny* AttributeType) const;
   298 
   299 	//Returns TRUE if the attribute of the given type exists
   300 	//##ModelId=3B666BCD03E1
   301 	IMPORT_C TBool AttributeExists(TAny* aAttributeType) const;
   302 
   303 	//Returns the node type
   304 	//##ModelId=3B666BCD03D7
   305 	IMPORT_C TAny* Type() const;
   306 
   307 	//Sets the node type to be aType (the parameter)
   308 	//##ModelId=3B666BCD03CD
   309 	IMPORT_C void SetType(TAny* aType);
   310 
   311 
   312 protected:
   313 	//ctor
   314 	//##ModelId=3B666BCD03B9
   315 	CNode(TAny* aType, CNode* aParent);
   316 
   317 	//internal finds a child which is passed in as a parameter
   318 	//##ModelId=3B666BCD03AF
   319 	TInt FindChild(const CNode* aNode) const;
   320 
   321 	//##ModelId=3B666BCD03A7
   322 	HBufC16* SetupDeletableOrNonDeleteableDataLC();
   323 	//##ModelId=3B666BCD03A6
   324 	void AdjustBasePointers();
   325 private:
   326 	// Reserved for future expansion
   327 	//##ModelId=3B666BCD039B
   328 	virtual void Reserved1();			
   329 	//##ModelId=3B666BCD03A5
   330 	virtual void Reserved1() const;
   331 
   332 protected:
   333 	//the Type of Node
   334 	//##ModelId=3B666BCD0392
   335 	TAny* iType;
   336 
   337 	//This Nodes parent
   338 	//##ModelId=3B666BCD037E
   339 	CNode *iParent;
   340 
   341 	// stores attribute type and value. iTypes must be Flat array
   342 	//##ModelId=3B666BCD0372
   343 	CArrayPtrFlat<CBase> iValues;
   344 	//##ModelId=3B666BCD034C
   345 	CArrayPtrFlat<TAny> iTypes;
   346 
   347 	//##ModelId=3B666BCD0324
   348 	TInt32* iTypesBasePtr;
   349 	//##ModelId=3B666BCD0310
   350 	CDataNoDelete* iDataValue;
   351 //
   352 	//An array of child nodes
   353 	//##ModelId=3B666BCD02FC
   354 	CArrayPtr<CNode> *iChildList;
   355 private:
   356 	//##ModelId=3B666BCD02DF
   357 	TAny*	iReserved;						// Reserved for future expansion
   358 	};
   359 
   360 
   361 //CTypedNode is derived from CNode and is a thin template. TNodeType you should define as a 32 bit value
   362 //TAttributeType should be defined as a 32 bit value
   363 //FOR EXPLANATION OF API'S SEE ABOVE 
   364 //##ModelId=3B666BCC01A4
   365 template <class TNodeType, class TAttributeType>
   366 class CTypedNode : public CNode 
   367 /** Template class for a node in a node tree.
   368 
   369 The node type is set to the template parameter TNodeType and the attribute type to 
   370 TAttributeType. These parameters should be pointers to the type required to store 
   371 the type value: e.g. for a string, a const TDesC*.
   372 
   373 The class is thin template over CNode. */
   374 	{
   375 public:
   376 	//##ModelId=3B666BCC024A
   377 	inline static CTypedNode* NewL(TNodeType aType,CNode* aParent);
   378 	//##ModelId=3B666BCC0248
   379 	inline void DeleteChildNode(CNode* aNode);
   380 	//##ModelId=3B666BCC0247
   381 	inline void DeleteAllChildNodes();
   382 	//##ModelId=3B666BCC0245
   383 	inline CTypedNode<TNodeType,TAttributeType>& AppendNodeL(TNodeType aType);
   384 	//##ModelId=3B666BCC023B
   385 	inline void AppendNodeToThisNodeL(CNode* aNode);
   386 	//##ModelId=3B666BCC0228
   387 	inline void SetDataL(HBufC16* aDataNowNodeOwns);
   388 	//##ModelId=3B666BCC0227
   389 	inline void SetDataNoDeleteL();
   390 	//##ModelId=3B666BCC0221
   391 	inline void ClearSetDataNoDeleteL();
   392 	//##ModelId=3B666BCC021F
   393 	inline void SetFileDataL(HBufC16* aFileDataLocationNowNodeOwns);
   394 	//##ModelId=3B666BCC021D
   395 	inline void ResetDataPointer(HBufC16* aData);
   396 	//##ModelId=3B666BCC0215
   397 	inline HBufC16* Data() const;
   398 	//##ModelId=3B666BCC0214
   399 	inline const CTypedNode& Root() const;
   400 	//##ModelId=3B666BCC020B
   401 	inline CTypedNode* Child(TInt aByIndex) const;
   402 	//##ModelId=3B666BCC0209
   403 	inline CTypedNode* NextChild(const CNode* aNode = NULL) const;
   404 	//##ModelId=3B666BCC0201
   405 	inline CTypedNode* PrevChild( const CNode& aNode) const;
   406 	//##ModelId=3B666BCC0200
   407 	inline CTypedNode* Parent() const;
   408 	//##ModelId=3B666BCC01FE
   409 	inline void ReparentL(CNode* aParent);
   410 	//##ModelId=3B666BCC01F5
   411 	inline CTypedNode* NextSibling() const;
   412 	//##ModelId=3B666BCC01F4
   413 	inline CTypedNode* PrevSibling() const;
   414 	//##ModelId=3B666BCC01EE
   415 	inline TInt NumberImmediateChildren() const;
   416 	//##ModelId=3B666BCC01EC
   417 	inline void DeleteAttribute(TAttributeType aAttributeType);
   418 	//##ModelId=3B666BCC01EB
   419 	inline void DeleteAllAttributes();
   420 	//##ModelId=3B666BCC01E5
   421 	inline void RemoveAttributeNoDelete(TAttributeType aAttributeType);
   422 	//##ModelId=3B666BCC01E4
   423 	inline TInt AttributeCount() const; // Returns the number of attributes
   424 	//##ModelId=3B666BCC01E2
   425 	inline TAttributeType AttributeTypeByIndex(TInt aIndex) const; 
   426 	//##ModelId=3B666BCC01DC
   427 	inline CBase* AttributeByIndex(TInt aIndex) const; 
   428 	//##ModelId=3B666BCC01DE
   429 	inline CBase* AttributeByIndex(TInt aIndex,TAttributeType& aType) const; 
   430 	//##ModelId=3B666BCC01D9
   431 	inline void AddAttributeL(TAttributeType aAttributeType, CBase* aAttributeValue);
   432 	//##ModelId=3B666BCC01D0
   433 	inline void AddDataAndAttributeL(HBufC16 *aData, TAttributeType aAttributeType, CBase* aAttributeValue);
   434 	//##ModelId=3B666BCC01CE
   435 	inline CBase* Attribute(TAttributeType aAttributeType) const;
   436 	//##ModelId=3B666BCC01CC
   437 	inline TBool AttributeExists(TAttributeType aAttributeType) const;
   438 	//##ModelId=3B666BCC01C9
   439 	inline TNodeType Type() const;
   440 	//##ModelId=3B666BCC01C7
   441 	inline void SetType(TNodeType aType);
   442 protected:
   443 	//##ModelId=3B666BCC01C4
   444 	CTypedNode(TNodeType aType, CNode* aParent);
   445 	};
   446 #include <cnode.inl>
   447 #endif