summaryrefslogtreecommitdiff
path: root/dmserializers/importkeyvaluebase.h
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /dmserializers/importkeyvaluebase.h
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'dmserializers/importkeyvaluebase.h')
-rw-r--r--dmserializers/importkeyvaluebase.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/dmserializers/importkeyvaluebase.h b/dmserializers/importkeyvaluebase.h
new file mode 100644
index 0000000..771d048
--- /dev/null
+++ b/dmserializers/importkeyvaluebase.h
@@ -0,0 +1,84 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================
+
+#ifndef IMPORTKEYVALUEBASE_H
+#define IMPORTKEYVALUEBASE_H
+
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "datamodel/idatamodel.h"
+
+
+//-----------------------------------------------------------------------------
+// Forward declarations
+//-----------------------------------------------------------------------------
+class CUtlBuffer;
+class KeyValues;
+class CDmElement;
+
+
+//-----------------------------------------------------------------------------
+// Serialization class for Key Values
+//-----------------------------------------------------------------------------
+abstract_class CImportKeyValueBase : public IDmSerializer
+{
+public:
+ // Inherited from IDMSerializer
+ virtual bool StoresVersionInFile() const { return false; }
+ virtual bool IsBinaryFormat() const { return false; }
+ virtual bool Serialize( CUtlBuffer &buf, CDmElement *pRoot );
+ virtual bool Unserialize( CUtlBuffer &buf, const char *pEncodingName, int nEncodingVersion,
+ const char *pSourceFormatName, int nSourceFormatVersion,
+ DmFileId_t fileid, DmConflictResolution_t idConflictResolution, CDmElement **ppRoot );
+
+protected:
+ // Main entry point for derived classes to implement unserialization
+ virtual CDmElement* UnserializeFromKeyValues( KeyValues *pKeyValues ) = 0;
+
+ // Returns the file name associated with the unserialization
+ const char *FileName() const;
+
+ // Creates new elements
+ CDmElement* CreateDmElement( const char *pElementType, const char *pElementName, DmObjectId_t *pId );
+
+ // Recursively resolves all attributes pointing to elements
+ void RecursivelyResolveElement( CDmElement* pElement );
+
+ // Used to add typed attributes from keyvalues
+ bool AddBoolAttribute( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, bool *pDefault = NULL );
+ bool AddIntAttribute( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int *pDefault = NULL );
+ bool AddFloatAttribute( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, float *pDefault = NULL );
+ bool AddStringAttribute( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, const char *pDefault = NULL );
+
+ // Used to add typed attributes from keyvalues
+ bool AddBoolAttributeFlags( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int nFlags, bool *pDefault = NULL );
+ bool AddIntAttributeFlags( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int nFlags, int *pDefault = NULL );
+ bool AddFloatAttributeFlags( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int nFlags, float *pDefault = NULL );
+ bool AddStringAttributeFlags( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int nFlags, const char *pDefault = NULL );
+
+ // Used to output typed attributes to keyvalues
+ void PrintBoolAttribute( CDmElement* pElement, CUtlBuffer &outBuf, const char *pKeyName );
+ void PrintIntAttribute( CDmElement* pElement, CUtlBuffer &outBuf, const char *pKeyName );
+ void PrintFloatAttribute( CDmElement* pElement, CUtlBuffer &outBuf, const char *pKeyName );
+ void PrintStringAttribute( CDmElement* pElement, CUtlBuffer &outBuf, const char *pKeyName, bool bSkipEmptryStrings = false, bool bPrintValueOnly = false );
+
+private:
+ const char *m_pFileName;
+};
+
+
+//-----------------------------------------------------------------------------
+// Returns the file name associated with the unserialization
+//-----------------------------------------------------------------------------
+inline const char *CImportKeyValueBase::FileName() const
+{
+ return m_pFileName;
+}
+
+
+#endif // IMPORTKEYVALUEBASE_H