Sleeping Wombat Common Library  0.50.0
swCommonLibrary
ChunkRepr.h
Go to the documentation of this file.
1 #pragma once
2 
9 
14 
15 
16 namespace sw
17 {
18 
19 class ChunkRepr;
20 DEFINE_PTR_TYPE( ChunkRepr );
21 DEFINE_WPTR_TYPE( ChunkRepr );
22 
23 class ImplHCF;
24 
25 
27 class ChunkRepr : public std::enable_shared_from_this< ChunkRepr >
28 {
29  FRIEND_CLASS_TESTER( HCF );
30  FRIEND_CLASS_TESTER( ChunkRepr );
31 private:
32  ImplHCF* m_hcf;
33 
34  ChunkHeader m_header;
35 
37 
38  ChunkReprWPtr m_parent;
39  ChunkReprPtr m_nextChunk;
40  ChunkReprPtr m_childChunk;
41 
42  AttributeReprPtr m_firstAttrib;
43 
45 
46 private:
48  ChunkRepr ( ImplHCF* hcf, ChunkReprPtr& parent );
50  ChunkRepr ( ImplHCF* hcf, ChunkReprPtr& parent, Size fileOffset );
51 
52 public:
53  static ChunkReprPtr CreateFromFile ( ImplHCF* hcf, ChunkReprPtr parent, Size fileOffset );
54  static ChunkReprPtr Create ( ImplHCF* hcf, ChunkReprPtr parent );
55 
56 
57  Chunk CreateChunk ();
58 
61  Chunk NextChunk ();
62 
65  Chunk FirstChild ();
66 
68  bool HasChildren () const;
69 
72  Chunk ParentChunk ();
73 
74 
75  Attribute AddAttribute ( AttributeType type, const DataPtr data, Size dataSize );
76  bool Fill ( const DataPtr data, Size dataSize );
77 
80 
83 
84  void AddNextChunk ( ChunkReprPtr& newChunk );
85 
86 
87  bool CheckValidity () const;
88 
89 private:
90  bool CanAddAttribute () const;
91  bool CanCreateChunk () const;
92  bool CanFillData () const;
93  bool CanLoadData () const;
94 
95  void WriteHeader ( Size revertOffset );
96  void LoadHeader ( Size revertOffset );
97  void UpdateHeader ();
98 
99  DataUPack LoadData ();
100 };
101 
102 
103 } // sw
Definition: ChunkHeader.h:16
Size m_absolutOffset
Offset from beginning of file.
Definition: ChunkRepr.h:36
Definition: ChunkRepr.h:27
ChunkReprPtr m_childChunk
First child chunk.
Definition: ChunkRepr.h:40
Definition: Exception.h:11
Definition: ImplHCF.h:28
ChunkReprWPtr m_parent
Parent chunk.
Definition: ChunkRepr.h:38
Data pointer and it's size. This struct is used to transfer ownership of pointer. ...
Definition: AttributeTypes.h:34
Represents memory chunk in file.
Definition: Chunk.h:24
Main class for loading and writing HCF files.
Definition: HCF.h:34
DataUPack m_data
Contains chunk's data.
Definition: ChunkRepr.h:44
Plik zawiera definicje podstawowych typów zmiennych.
Chunk ParentChunk()
Get Chunks parent.
Definition: ChunkRepr.cpp:130
ChunkRepr(ImplHCF *hcf, ChunkReprPtr &parent)
Write only constructor.
Definition: ChunkRepr.cpp:19
DataPack AccessData()
Returns chunk's data.
Definition: ChunkRepr.cpp:205
Data pointer and it's size.
Definition: AttributeTypes.h:19
Definition: Attribute.h:21
ChunkReprPtr m_nextChunk
Next chunk on the same nesting level.
Definition: ChunkRepr.h:39
void UpdateHeader()
Updates header in file using current info from m_header field.
Definition: ChunkRepr.cpp:350
DataUPack StealData()
Returns chunk's data and transfers ownership to caller.
Definition: ChunkRepr.cpp:193
bool HasChildren() const
Check if you should call FirstChild or AccessData.
Definition: ChunkRepr.cpp:123
Chunk FirstChild()
Gets first child chunk of this chunk.
Definition: ChunkRepr.cpp:101
AttributeReprPtr m_firstAttrib
Attributes list.
Definition: ChunkRepr.h:42
Chunk NextChunk()
Gets next chunk on the same nesting level.
Definition: ChunkRepr.cpp:82