imgtools/romtools/rombuild/r_dir.h
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __R_DIR_H__
       
    20 #define __R_DIR_H__
       
    21 
       
    22 #include <e32std.h>
       
    23 
       
    24 // Generalised set handling
       
    25 class SetMember
       
    26 	{
       
    27 public:
       
    28 	TBool operator==(const SetMember& aMember) {return(Compare(aMember)==0);}
       
    29 	virtual SetMember* Copy() const =0;
       
    30 	virtual void Close();
       
    31 public:
       
    32 	TInt Type() const {return iType;}
       
    33 	virtual TInt Compare(const SetMember& aMember) const =0;
       
    34 	virtual void DebugPrint() const =0;
       
    35 protected:
       
    36 	virtual ~SetMember();
       
    37 	SetMember(TInt aType) : iType(aType) {TotalInSystem++;}
       
    38 	SetMember(const SetMember& aMember) : iType(aMember.iType) {TotalInSystem++;}
       
    39 	TBool operator<(const SetMember& aMember) {return(Compare(aMember)<0);}
       
    40 	TBool operator>(const SetMember& aMember) {return(Compare(aMember)>0);}
       
    41 private:
       
    42 	TInt iType;
       
    43 	static TInt TotalInSystem;
       
    44 	};
       
    45 
       
    46 class FiniteSet : public SetMember
       
    47 	{
       
    48 protected:
       
    49 	enum TFiniteSetType {EFiniteSetType=100};
       
    50 public:
       
    51 	static FiniteSet* New(TInt aMaxCount);
       
    52 	static FiniteSet* Singleton(TInt aMaxCount, const SetMember& aMember);
       
    53 	virtual ~FiniteSet();
       
    54 	virtual SetMember* Copy() const;
       
    55 	TInt Find(const SetMember& aMember) const;
       
    56 	TBool SubsetOf(const FiniteSet& aSet) const;
       
    57 	TInt Intersection(const FiniteSet& aSet);
       
    58 	TInt Union(const FiniteSet& aSet);
       
    59 	TInt Difference(const FiniteSet& aSet);
       
    60 	TInt Add(const SetMember& aMember);
       
    61 	TInt Remove(const SetMember& aMember);
       
    62 	SetMember* Detach(TInt anIndex);
       
    63 	TInt Count() const {return iCount;}
       
    64 	TBool Empty() const {return !iCount;}
       
    65 	SetMember& operator[](TInt anIndex) const {return *iMembers[anIndex];}
       
    66 	virtual void DebugPrint() const;
       
    67 protected:
       
    68 	FiniteSet(TInt aMaxCount);
       
    69 	FiniteSet(const FiniteSet& aSet);
       
    70 	FiniteSet* Construct();
       
    71 	virtual TInt Compare(const SetMember& aMember) const;
       
    72 	TInt Find(const SetMember& aMember, TInt& anIndex) const;
       
    73 	TInt Insert(const SetMember& aMember, TInt anIndex);
       
    74 protected:
       
    75 	TInt iMaxCount;
       
    76 	TInt iCount;
       
    77 	SetMember** iMembers;
       
    78 	};
       
    79 
       
    80 // ROMBUILD-specific stuff
       
    81 #include <e32rom.h>
       
    82 
       
    83 class CObeyFile;
       
    84 class TRomNode;
       
    85 class THardwareVariant;
       
    86 
       
    87 class RomFileStructure;
       
    88 class TVariantList
       
    89 	{
       
    90 public:
       
    91 	enum {EMaxVariants=32};
       
    92 	static void Setup(CObeyFile* aObey);
       
    93 	TVariantList() : iList(0)
       
    94 		{}
       
    95 	TVariantList(TInt aVariant)
       
    96 		{iList=TUint(1<<aVariant);}
       
    97 	TVariantList(THardwareVariant a);
       
    98 	void Add(TInt aVariant)
       
    99 		{iList|=TUint(1<<aVariant);}
       
   100 	TVariantList& Union(const TVariantList aList)
       
   101 		{iList|=aList.iList; return *this;}
       
   102 	TVariantList& Intersection(const TVariantList aList)
       
   103 		{iList&=aList.iList; return *this;}
       
   104 	TBool operator==(const TVariantList aList) const
       
   105 		{return(iList==aList.iList);}
       
   106 	TBool operator!=(const TVariantList aList) const
       
   107 		{return(iList!=aList.iList);}
       
   108 	TBool operator<=(const TVariantList aList) const
       
   109 		{return(iList==(iList&aList.iList));}
       
   110 	TBool operator>=(const TVariantList aList) const
       
   111 		{return(iList==(iList|aList.iList));}
       
   112 	TBool operator[](TInt aVariant) const
       
   113 		{return(iList&TUint(1<<aVariant));}
       
   114 	TBool Empty() const
       
   115 		{return !iList;}
       
   116 	TUint Mask() const
       
   117 		{return iList;}
       
   118 	THardwareVariant Lookup() const;
       
   119 	static void SetNumVariants(TInt aNumVariants);
       
   120 	static void SetVariants(THardwareVariant* aVariants);
       
   121 private:
       
   122 	friend class RomFileStructure;
       
   123 	TUint iList;
       
   124 	static TInt NumVariants;
       
   125 	static THardwareVariant Variants[EMaxVariants];
       
   126 	};
       
   127 
       
   128 class Entry : public SetMember
       
   129 	{
       
   130 public:
       
   131 	Entry(TInt aType) : SetMember(aType), iRomNode(NULL) {}
       
   132 	Entry(const Entry& anEntry) : SetMember(anEntry), iRomNode(NULL) {}
       
   133 	TBool IsFile() const {return (Type()==EFile);}
       
   134 	TBool IsDir() const {return (Type()==EDir);}
       
   135 	TVariantList Variants() const {return iVariants;}
       
   136 	TRomEntry* CreateRomEntry(char*& anAddr) const;
       
   137 	void Restrict(TVariantList aList) {iVariants.Intersection(aList);}
       
   138 	const TText* Name() const;
       
   139 protected:
       
   140 	enum {EFile=0, EDir=1};
       
   141 	TVariantList iVariants;
       
   142 	TRomNode* iRomNode;
       
   143 	};
       
   144 
       
   145 class FileEntry : public Entry
       
   146 	{
       
   147 public:
       
   148 	static FileEntry* New(TRomNode* aFile);
       
   149 	virtual SetMember* Copy() const;
       
   150 	virtual ~FileEntry();
       
   151 	virtual void DebugPrint() const;
       
   152 protected:
       
   153 	FileEntry() : Entry(EFile) {}
       
   154 	FileEntry(const FileEntry& aFileEntry);
       
   155 	virtual TInt Compare(const SetMember& aMember) const;
       
   156 	};
       
   157 
       
   158 class Directory;
       
   159 class DirEntry : public Entry
       
   160 	{
       
   161 public:
       
   162 	static DirEntry* New(TRomNode* aFile, Directory* aDir);
       
   163 	virtual SetMember* Copy() const;
       
   164 	virtual ~DirEntry();
       
   165 	Directory* Dir() const {return iDir;}
       
   166 	TRomDir* CreateRomEntries(char*& anAddr) const;
       
   167 	virtual void DebugPrint() const;
       
   168 protected:
       
   169 	DirEntry() : Entry(EDir) {}
       
   170 	DirEntry(const DirEntry& aDirEntry);
       
   171 	virtual TInt Compare(const SetMember& aMember) const;
       
   172 protected:
       
   173 	Directory* iDir;
       
   174 	};
       
   175 
       
   176 class Directory : public FiniteSet
       
   177 	{
       
   178 public:
       
   179 	static Directory* New(TInt aMaxCount, TVariantList aList);
       
   180 	TInt Compile(const FiniteSet& aSet);
       
   181 	TInt Merge(const Directory& aDir);
       
   182 	TVariantList Variants() const {return iVariants;}
       
   183 	virtual void DebugPrint() const;
       
   184 	void Open();
       
   185 	virtual void Close();
       
   186 protected:
       
   187 	Directory(TInt aMaxCount);
       
   188 private:
       
   189 	Directory(const Directory &);
       
   190 	~Directory();
       
   191 protected:
       
   192 	friend class DirEntry;
       
   193 	TVariantList iVariants;
       
   194 	TRomDir* iRomDir;
       
   195 private:
       
   196 	static TInt DirectoryCount;
       
   197 private:
       
   198 	TInt iAccessCount;
       
   199 	TInt iIdentifier;
       
   200 	};
       
   201 
       
   202 class RomFileStructure : public FiniteSet
       
   203 	{
       
   204 public:
       
   205 	static RomFileStructure* New(TInt aMaxCount);
       
   206 	~RomFileStructure();
       
   207 	void Destroy();
       
   208 	TInt ProcessDirectory(TRomNode* aDir);
       
   209 protected:
       
   210 	RomFileStructure(TInt aMaxCount);
       
   211 	};
       
   212 
       
   213 
       
   214 #endif