tools/elf4rom/src/filefragment.h
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, either version 3 of the License, or
       
     8 * (at your option) any later version.
       
     9 *
       
    10 * This program is distributed in the hope that it will be useful,
       
    11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 * GNU Lesser General Public License for more details.
       
    14 * 
       
    15 * You should have received a copy of the GNU Lesser General Public License
       
    16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    17 */
       
    18 
       
    19 #ifndef FILEFRAGMENT_H_
       
    20 #define FILEFRAGMENT_H_
       
    21 
       
    22 #include <stddef.h>
       
    23 
       
    24 class OutputFile;
       
    25 
       
    26 class FileFragmentData
       
    27 {
       
    28 
       
    29 public:
       
    30 	FileFragmentData() :
       
    31 		iSize(0), iData(0)
       
    32 		{};
       
    33 	FileFragmentData(size_t aSize, char * aData) :
       
    34 		iSize(aSize), iData(aData)
       
    35 		{};
       
    36 	virtual ~FileFragmentData();
       
    37 	inline char* GetData() { return iData; };
       
    38 	inline size_t GetSize() { return iSize; };
       
    39 	inline void SetData(char * newVal) { iData = newVal; };
       
    40 	inline void SetSize(size_t newVal) { iSize = newVal; };
       
    41 
       
    42 private:
       
    43 	size_t iSize;
       
    44 	char* iData;
       
    45 };
       
    46 
       
    47 /**
       
    48  * Defines the interface for owners of FileFragments
       
    49  */
       
    50 class FileFragmentOwner
       
    51 {
       
    52 public:
       
    53 	FileFragmentOwner() :
       
    54 		iOffset(0)
       
    55 		{};
       
    56 		
       
    57 	FileFragmentOwner(size_t aOffset) :
       
    58 		iOffset(aOffset)
       
    59 		{};	
       
    60 		
       
    61 	virtual ~FileFragmentOwner();
       
    62 
       
    63 	virtual void GetFileFragmentData(FileFragmentData & aFileFragmentData ) =0;
       
    64 	virtual size_t Size() = 0;
       
    65 	virtual void DeleteFileFragmentData() = 0;
       
    66 	
       
    67 	virtual void AddData(OutputFile & aFile);
       
    68 	virtual size_t GetOffset() { return iOffset; }
       
    69 	virtual void SetOffset(size_t aOffset) { iOffset = aOffset; }
       
    70 	
       
    71 //protected:
       
    72 	void SetFileFragmentData(FileFragmentData & aFileFragmentData, size_t aSize, char * aData){
       
    73 		aFileFragmentData.SetSize(aSize);
       
    74 		aFileFragmentData.SetData(aData);
       
    75 	}		
       
    76 	
       
    77 protected:
       
    78 	size_t iOffset;
       
    79 };
       
    80 
       
    81 
       
    82 /**
       
    83  * Represents a fragment of file of a given size (in bytes) at a given offset (in
       
    84  * bytes).
       
    85  */
       
    86 class FileFragment
       
    87 {
       
    88 
       
    89 public:
       
    90 	FileFragment(size_t aOffset, size_t aSize, FileFragmentOwner * aOwner) :
       
    91 		iOffset(aOffset), iSize(aSize), iOwner(aOwner)
       
    92 		{};
       
    93 	virtual ~FileFragment();
       
    94 	
       
    95 	inline size_t GetOffset() const { return iOffset; };
       
    96 	inline size_t GetSize() const { return iSize; };
       
    97 	inline void SetOffset(size_t newVal) { iOffset = newVal; };
       
    98 	inline void SetSize(size_t newVal) { iSize = newVal; };
       
    99 	void Write(OutputFile * aFile);
       
   100 
       
   101 private:
       
   102 	/**
       
   103 	 * offset in bytes at which the fragment occurs in the file
       
   104 	 */
       
   105 	size_t iOffset;
       
   106 	/**
       
   107 	 * size in bytes of the file fragment
       
   108 	 */
       
   109 	size_t iSize;
       
   110 	/**
       
   111 	 * the owner of the file fragment
       
   112 	 */
       
   113 	FileFragmentOwner * iOwner;
       
   114 };
       
   115 
       
   116 #endif /*FILEFRAGMENT_H_*/