/RbfConv/TextFileWriter.h

http://modstudio2.googlecode.com/ · C Header · 85 lines · 28 code · 9 blank · 48 comment · 0 complexity · 56f5909e79d4baf9690c0747b2612516 MD5 · raw file

  1. /*
  2. Copyright (c) 2008 Peter "Corsix" Cawley
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #pragma once
  23. #define RAINMAN2_NO_WX
  24. #define RAINMAN2_NO_LUA
  25. #include <Rainman2.h>
  26. class RbfTxtWriter
  27. {
  28. public:
  29. RbfTxtWriter(IFile *pOutputFile);
  30. ~RbfTxtWriter();
  31. void writeTable(IAttributeTable *pTable);
  32. void writeValue(IAttributeValue *pValue);
  33. //! Write the current indentation string
  34. void writeLinePrefix();
  35. void setUCS(UcsFile *pUcsFile, long iUcsReferenceThreshold = 100);
  36. //! Configure indentation behaviour
  37. /*!
  38. \param iIndentSize The number of characters to use per indentation level
  39. \param cIndentChar The character to use when indenting
  40. \param cLevelMarker The character to use when indenting to mark the indentation level
  41. This should be called before any writing occurs, as otherwise the changes will not
  42. take effect fully or consistently.
  43. If given the parameters (3, 'a', 'B'), indentation would be:
  44. // indentation level 0
  45. Baa // indentation level 1
  46. BaaBaa // indentation level 2
  47. BaaBaaBaa // indentation level 3
  48. BaaBaaBaaBaa // indentation level 4
  49. As can be seen, indentation always uses iIndentSize characters, the first of which is
  50. cLevelMarker, the remainder being cIndentChar.
  51. */
  52. void setIndentProperties(int iIndentSize = 2, char cIndentChar = ' ', char cLevelMarker = '|');
  53. //! Increase the indent level
  54. void indent();
  55. //! Decrease the indent level
  56. /*!
  57. Will not decrease the indent level to below 0.
  58. */
  59. void unindent();
  60. protected:
  61. BufferingOutputStream<char> m_oOutput; //!< Buffer for writing output
  62. char *m_sIndentArray;
  63. UcsFile *m_pUcsFile;
  64. long m_iUcsReferenceThreshold;
  65. int m_iIndentLevel, //!< The number of characters of indentation currently being used
  66. m_iSpacesPerLevel, //!< The number of characters to use per indentation level
  67. m_iIndentArrayLength;
  68. char m_sBuffer[32]; //!< Buffer to use for sprintf and similar calls
  69. char m_cIndentChar; //!< The major indentation character
  70. char m_cIndentLevelChar; //!< The indentation level character
  71. };