OpenClonk
C4ComponentHost.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Holds a single text file component from a group */
19 
20 #ifndef INC_C4ComponentHost
21 #define INC_C4ComponentHost
22 
24 {
25 public:
26  C4ComponentHost() = default;
27  virtual ~C4ComponentHost() { Clear(); }
28  const char *GetFilePath() const { return FilePath.getData(); }
29  void Clear() { Data.Clear(); OnLoad(); }
30  const char *GetData() const { return Data.getData(); }
31  const StdStrBuf & GetDataBuf() const { return Data; }
32  size_t GetDataSize() const { return Data.getLength(); }
33  bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage=nullptr);
34  bool Load(C4GroupSet &hGroupSet, const char *szFilename, const char *szLanguage=nullptr);
35  bool GetLanguageString(const char *szLanguage, StdStrBuf &rTarget);
36 protected:
37  // The component host's Data has changed. This callback can be used by
38  // derived classes to reload internal structures.
39  virtual void OnLoad() {}
40 
44  void CopyFilePathFromGroup(const C4Group &hGroup);
45  void FinishLoad(const StdStrBuf &, C4Group &hGroup);
46 };
47 
48 #endif
virtual ~C4ComponentHost()
bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage=nullptr)
C4ComponentHost()=default
const StdStrBuf & GetDataBuf() const
const char * GetData() const
StdCopyStrBuf Filename
size_t GetDataSize() const
void CopyFilePathFromGroup(const C4Group &hGroup)
virtual void OnLoad()
void FinishLoad(const StdStrBuf &, C4Group &hGroup)
const char * GetFilePath() const
StdCopyStrBuf FilePath
StdCopyStrBuf Data
bool GetLanguageString(const char *szLanguage, StdStrBuf &rTarget)
const char * getData() const
Definition: StdBuf.h:442
void Clear()
Definition: StdBuf.h:466
size_t getLength() const
Definition: StdBuf.h:445