Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.7 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef IMPORTKEYVALUEBASE_H
  7. #define IMPORTKEYVALUEBASE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/idatamodel.h"
  12. //-----------------------------------------------------------------------------
  13. // Forward declarations
  14. //-----------------------------------------------------------------------------
  15. class CUtlBuffer;
  16. class KeyValues;
  17. class CDmElement;
  18. //-----------------------------------------------------------------------------
  19. // Serialization class for Key Values
  20. //-----------------------------------------------------------------------------
  21. abstract_class CImportKeyValueBase : public IDmSerializer
  22. {
  23. public:
  24. // Inherited from IDMSerializer
  25. virtual bool StoresVersionInFile() const { return false; }
  26. virtual bool IsBinaryFormat() const { return false; }
  27. virtual bool Serialize( CUtlBuffer &buf, CDmElement *pRoot );
  28. virtual bool Unserialize( CUtlBuffer &buf, const char *pEncodingName, int nEncodingVersion,
  29. const char *pSourceFormatName, int nSourceFormatVersion,
  30. DmFileId_t fileid, DmConflictResolution_t idConflictResolution, CDmElement **ppRoot );
  31. protected:
  32. // Main entry point for derived classes to implement unserialization
  33. virtual CDmElement* UnserializeFromKeyValues( KeyValues *pKeyValues ) = 0;
  34. // Returns the file name associated with the unserialization
  35. const char *FileName() const;
  36. // Creates new elements
  37. CDmElement* CreateDmElement( const char *pElementType, const char *pElementName, DmObjectId_t *pId );
  38. // Recursively resolves all attributes pointing to elements
  39. void RecursivelyResolveElement( CDmElement* pElement );
  40. // Used to add typed attributes from keyvalues
  41. bool AddBoolAttribute( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, bool *pDefault = NULL );
  42. bool AddIntAttribute( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int *pDefault = NULL );
  43. bool AddFloatAttribute( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, float *pDefault = NULL );
  44. bool AddStringAttribute( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, const char *pDefault = NULL );
  45. // Used to add typed attributes from keyvalues
  46. bool AddBoolAttributeFlags( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int nFlags, bool *pDefault = NULL );
  47. bool AddIntAttributeFlags( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int nFlags, int *pDefault = NULL );
  48. bool AddFloatAttributeFlags( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int nFlags, float *pDefault = NULL );
  49. bool AddStringAttributeFlags( CDmElement* pElement, KeyValues *pKeyValue, const char *pKeyName, int nFlags, const char *pDefault = NULL );
  50. // Used to output typed attributes to keyvalues
  51. void PrintBoolAttribute( CDmElement* pElement, CUtlBuffer &outBuf, const char *pKeyName );
  52. void PrintIntAttribute( CDmElement* pElement, CUtlBuffer &outBuf, const char *pKeyName );
  53. void PrintFloatAttribute( CDmElement* pElement, CUtlBuffer &outBuf, const char *pKeyName );
  54. void PrintStringAttribute( CDmElement* pElement, CUtlBuffer &outBuf, const char *pKeyName, bool bSkipEmptryStrings = false, bool bPrintValueOnly = false );
  55. private:
  56. const char *m_pFileName;
  57. };
  58. //-----------------------------------------------------------------------------
  59. // Returns the file name associated with the unserialization
  60. //-----------------------------------------------------------------------------
  61. inline const char *CImportKeyValueBase::FileName() const
  62. {
  63. return m_pFileName;
  64. }
  65. #endif // IMPORTKEYVALUEBASE_H