Source code of Windows XP (NT5)
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.

107 lines
3.3 KiB

  1. //
  2. // MODULE: TEMPLATEREAD.H
  3. //
  4. // PURPOSE: template file reading classes
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Oleg Kalosha
  9. //
  10. // ORIGINAL DATE: 8-12-98
  11. //
  12. // NOTES:
  13. // 1. CTemplateReader has no public methods to apply the template. These must be supplied
  14. // by classes which inherit from CTemplateReader, and these must be supplied in a
  15. // suitably "stateless" manner.
  16. //
  17. // Version Date By Comments
  18. //--------------------------------------------------------------------
  19. // V3.0 08-04-98 OK
  20. //
  21. #ifndef __TEMPLATEREAD_H_
  22. #define __TEMPLATEREAD_H_
  23. #include "fileread.h"
  24. #include <map>
  25. using namespace std;
  26. ////////////////////////////////////////////////////////////////////////////////////
  27. // CTemplateInfo
  28. ////////////////////////////////////////////////////////////////////////////////////
  29. class CTemplateInfo
  30. {
  31. CString m_KeyStr; // key text which we will replace with m_SubstitutionStr
  32. CString m_SubstitutionStr; // text we will use to replace m_KeyStr
  33. public:
  34. CTemplateInfo();
  35. CTemplateInfo(const CString& key, const CString& substitution);
  36. virtual ~CTemplateInfo();
  37. CString& GetKeyStr() {return m_KeyStr;}
  38. virtual bool Apply(CString& target) const;
  39. // comparison methods are mainly to keep STL happy. Note that they only look at
  40. // m_KeyStr, not m_SubstitutionStr.
  41. inline BOOL operator == (const CTemplateInfo& two) const
  42. {
  43. return m_KeyStr == two.m_KeyStr;
  44. }
  45. inline BOOL operator < (const CTemplateInfo& two) const
  46. {
  47. return m_KeyStr < two.m_KeyStr;
  48. }
  49. };
  50. ////////////////////////////////////////////////////////////////////////////////////
  51. // CTemplateReader
  52. // This class reads template file and provides functionality to substitute key
  53. // sentences with text - do it all at once, or one-by-one.
  54. // The object of this class can be renewed with another template - in this case
  55. // all substitution actions will be performed on new template.
  56. // It can roll back "n" last substitutions
  57. ////////////////////////////////////////////////////////////////////////////////////
  58. class CTemplateReader : public CTextFileReader
  59. {
  60. protected:
  61. tstringstream m_StreamOutput; // streamed output, fully or partly substituted template
  62. // (which resides in CFileReader::m_StreamData)
  63. vector<CTemplateInfo> m_arrTemplateInfo; // contains key string - template info
  64. // pairs
  65. public:
  66. CTemplateReader(CPhysicalFileReader * pPhysicalFileReader, LPCTSTR szDefaultContents = NULL);
  67. ~CTemplateReader();
  68. protected:
  69. void SetOutputToTemplate();
  70. CTemplateReader& operator << (CTemplateInfo&); // apply
  71. CTemplateReader& operator >> (CTemplateInfo&); // roll back application for this CTemplateInfo
  72. void GetOutput(CString&);
  73. protected:
  74. // overrrides of inherited functions
  75. virtual void Parse(); // parse here is applying ALL elements of m_arrTemplateInfo
  76. // to a virgin template
  77. };
  78. ////////////////////////////////////////////////////////////////////////////////////
  79. // a concrete class that just provides simple string substitution
  80. ////////////////////////////////////////////////////////////////////////////////////
  81. class CSimpleTemplate : public CTemplateReader
  82. {
  83. public:
  84. CSimpleTemplate(CPhysicalFileReader * pPhysicalFileReader, LPCTSTR szDefaultContents = NULL);
  85. ~CSimpleTemplate();
  86. void CreatePage( const vector<CTemplateInfo> & arrTemplateInfo,
  87. CString& out );
  88. };
  89. #endif