Sleeping Wombat Common Library  0.50.0
swCommonLibrary
Chunk.h
Go to the documentation of this file.
1 #pragma once
2 
11 
12 namespace sw
13 {
14 
15 class ChunkRepr;
16 DEFINE_PTR_TYPE( ChunkRepr );
17 
18 
24 class Chunk
25 {
26  FRIEND_CLASS_TESTER( HCF );
27 private:
28 
29  ChunkReprPtr m_chunkPtr;
30 
31 protected:
32 public:
33  explicit Chunk () = default;
34  explicit Chunk ( ChunkReprPtr chunkRepr );
35  ~Chunk() = default;
36 
39 
40  Chunk CreateChunk ();
41 
44  Chunk NextChunk ();
45 
48  Chunk FirstChild ();
49 
51  bool HasChildren ();
52 
55  Chunk ParentChunk ();
56 
58 
61 
64  bool Fill ( const DataPtr data, Size dataSize );
65 
68 
73 
75 
78 
79  Attribute AddAttribute ( AttributeType type, const DataPtr data, Size dataSize );
80 
84  template< typename AttributeStruct >
85  Attribute AddAttribute ( AttributeType type, const AttributeStruct& content );
86 
89  template< typename AttributeStruct >
90  Attribute AddAttribute ( const AttributeStruct& content );
92 
94  bool IsValid () const;
95 
96  bool operator== ( Chunk other ) const;
97 };
98 
99 //====================================================================================//
100 // Implementation
101 //====================================================================================//
102 
103 
104 // ================================ //
105 //
106 template< typename AttributeStruct >
107 inline Attribute Chunk::AddAttribute ( AttributeType type, const AttributeStruct& content )
108 {
109  if( IsValid() )
110  return m_chunkPtr->AddAttribute( type, (const DataPtr)&content, sizeof( AttributeStruct ) );
111  return Attribute( nullptr );
112 }
113 
114 // ================================ //
115 //
116 template< typename AttributeStruct >
117 inline Attribute Chunk::AddAttribute ( const AttributeStruct& content )
118 {
119  if( IsValid() )
120  return AddAttribute( GetAttributeTypeID< AttributeStruct >(), content );
121  return Attribute( nullptr );
122 }
123 
124 
125 } // sw
Chunk ParentChunk()
Get Chunks parent.
Definition: Chunk.cpp:59
Chunk FirstChild()
Gets first child chunk of this chunk.
Definition: Chunk.cpp:41
DataPack AccessData()
Returns chunk's data.
Definition: Chunk.cpp:95
Definition: Exception.h:11
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
Plik zawiera definicje podstawowych typów zmiennych.
bool HasChildren()
Check if you should call FirstChild or AccessData.
Definition: Chunk.cpp:50
Attribute AddAttribute(AttributeType type, const DataPtr data, Size dataSize)
Adds attribute and fills it with data.
Definition: Chunk.cpp:68
Data pointer and it's size.
Definition: AttributeTypes.h:19
Chunk NextChunk()
Gets next chunk on the same nesting level.
Definition: Chunk.cpp:32
bool Fill(const DataPtr data, Size dataSize)
Fills chunk with data. You can fill only chunks without children. One filled chunk, can't add children anymore.
Definition: Chunk.cpp:77
Definition: Attribute.h:21
bool IsValid() const
Checks if you can use this attribute properly.
Definition: Chunk.cpp:104
Chunk CreateChunk()
Create child chunk.
Definition: Chunk.cpp:23
DataUPack StealData()
Returns chunk's data and transfers ownership to caller.
Definition: Chunk.cpp:86