The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

157 lines
5.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_CODEGENERATOR_H_F79AEF58__
  19. #define __JUCER_CODEGENERATOR_H_F79AEF58__
  20. #include "../../jucer_Headers.h"
  21. #include "../Project/jucer_Project.h"
  22. //==============================================================================
  23. class CodeGenerator
  24. {
  25. public:
  26. //==============================================================================
  27. CodeGenerator();
  28. ~CodeGenerator();
  29. //==============================================================================
  30. String className;
  31. String parentClassInitialiser; // optional parent class initialiser to go before the items in the initialisers list
  32. StringArray memberInitialisers;
  33. String parentClasses;
  34. String constructorParams;
  35. String privateMemberDeclarations;
  36. String publicMemberDeclarations;
  37. StringArray includeFilesH, includeFilesCPP;
  38. String constructorCode;
  39. String destructorCode;
  40. String staticMemberDefinitions;
  41. String jucerMetadata;
  42. struct CallbackMethod
  43. {
  44. String requiredParentClass, returnType, prototype, content;
  45. bool hasPrePostUserSections;
  46. };
  47. OwnedArray<CallbackMethod> callbacks;
  48. String& getCallbackCode (const String& requiredParentClass,
  49. const String& returnType,
  50. const String& prototype,
  51. const bool hasPrePostUserSections);
  52. void removeCallback (const String& returnType, const String& prototype);
  53. const String getCallbackDeclarations() const;
  54. const String getCallbackDefinitions() const;
  55. const StringArray getExtraParentClasses() const;
  56. int getUniqueSuffix();
  57. //==============================================================================
  58. // An object to load and store all the user-defined bits of code as documents.
  59. class CustomCodeList : public ChangeBroadcaster
  60. {
  61. public:
  62. CustomCodeList();
  63. ~CustomCodeList();
  64. void reloadFrom (const String& fileContent);
  65. void applyTo (String& fileContent) const;
  66. bool needsSaving() const;
  67. //==============================================================================
  68. // Ref-counted wrapper for a code document..
  69. class CodeDocumentRef : public ReferenceCountedObject
  70. {
  71. public:
  72. CodeDocumentRef (CodeDocument* doc_) : doc (doc_) {}
  73. CodeDocument& getDocument() const throw() { return *doc; }
  74. typedef ReferenceCountedObjectPtr<CodeDocumentRef> Ptr;
  75. private:
  76. CodeDocument* const doc;
  77. CodeDocumentRef (const CodeDocumentRef&);
  78. CodeDocumentRef& operator= (const CodeDocumentRef&);
  79. };
  80. //==============================================================================
  81. int getNumSections() const;
  82. const String getSectionName (int index) const;
  83. const CodeDocumentRef::Ptr getDocument (int index) const;
  84. const CodeDocumentRef::Ptr getDocumentFor (const String& sectionName, bool createIfNotFound);
  85. const String getSectionContent (const String& sectionName) const;
  86. void removeSection (const String& sectionName);
  87. class Iterator
  88. {
  89. public:
  90. Iterator (const String& documentText, CustomCodeList& customCode);
  91. ~Iterator();
  92. bool next();
  93. String textBefore, textAfter, sectionName;
  94. CodeDocumentRef::Ptr codeDocument;
  95. private:
  96. CustomCodeList& customCode;
  97. StringArray lines;
  98. int i;
  99. Iterator (const Iterator&);
  100. Iterator& operator= (const Iterator&);
  101. };
  102. private:
  103. StringArray sectionNames;
  104. ReferenceCountedArray <CodeDocumentRef> sectionContent;
  105. };
  106. //==============================================================================
  107. void applyToCode (String& codeTemplate, const File& targetFile,
  108. bool isForPreview, Project* project) const;
  109. private:
  110. //==============================================================================
  111. const String getClassDeclaration() const;
  112. const String getInitialiserList() const;
  113. int suffix;
  114. CodeGenerator (const CodeGenerator&);
  115. CodeGenerator& operator= (const CodeGenerator&);
  116. };
  117. #endif // __JUCER_CODEGENERATOR_H_F79AEF58__