JSBSourceWriter.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #pragma once
  8. #include <Atomic/Container/Str.h>
  9. using namespace Atomic;
  10. namespace ToolCore
  11. {
  12. class JSBSourceWriter
  13. {
  14. public:
  15. void SetIndentSpaces(int spaces) { indentSpaces_ = spaces; }
  16. void Indent() { indentLevel_++; GenerateIndentSpaces(); }
  17. void Dedent() { indentLevel_--; assert(indentLevel_ >= 0); GenerateIndentSpaces(); }
  18. String IndentLine(const String& line) { return indent_ + line; }
  19. const String& GetIndent() { return indent_; }
  20. protected:
  21. void GenerateIndentSpaces() {
  22. int spaces = indentSpaces_ * indentLevel_;
  23. indent_.Clear();
  24. while (spaces--) {
  25. indent_ += " ";
  26. }
  27. }
  28. String indent_;
  29. JSBSourceWriter() : indentLevel_(0), indentSpaces_(3) {}
  30. ~JSBSourceWriter() {}
  31. int indentSpaces_;
  32. int indentLevel_;
  33. };
  34. }