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.

152 lines
5.3KB

  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 "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* doc;
  77. };
  78. //==============================================================================
  79. int getNumSections() const;
  80. const String getSectionName (int index) const;
  81. const CodeDocumentRef::Ptr getDocument (int index) const;
  82. const CodeDocumentRef::Ptr getDocumentFor (const String& sectionName, bool createIfNotFound);
  83. const String getSectionContent (const String& sectionName) const;
  84. void removeSection (const String& sectionName);
  85. class Iterator
  86. {
  87. public:
  88. Iterator (const String& documentText, CustomCodeList& customCode);
  89. ~Iterator();
  90. bool next();
  91. String textBefore, textAfter, sectionName;
  92. CodeDocumentRef::Ptr codeDocument;
  93. private:
  94. CustomCodeList& customCode;
  95. StringArray lines;
  96. int i;
  97. };
  98. private:
  99. StringArray sectionNames;
  100. ReferenceCountedArray <CodeDocumentRef> sectionContent;
  101. };
  102. //==============================================================================
  103. void applyToCode (String& codeTemplate, const File& targetFile,
  104. bool isForPreview, Project* project) const;
  105. private:
  106. //==============================================================================
  107. const String getClassDeclaration() const;
  108. const String getInitialiserList() const;
  109. int suffix;
  110. CodeGenerator (const CodeGenerator&);
  111. CodeGenerator& operator= (const CodeGenerator&);
  112. };
  113. #endif // __JUCER_CODEGENERATOR_H_F79AEF58__