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.

160 lines
5.6KB

  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. MemoryBlock componentStateData;
  43. struct CallbackMethod
  44. {
  45. String requiredParentClass, returnType, prototype, content;
  46. bool hasPrePostUserSections;
  47. };
  48. OwnedArray<CallbackMethod> callbacks;
  49. void addPrivateMember (const String& type, const String& name);
  50. String& getCallbackCode (const String& requiredParentClass,
  51. const String& returnType,
  52. const String& prototype,
  53. const bool hasPrePostUserSections);
  54. void removeCallback (const String& returnType, const String& prototype);
  55. const String getCallbackDeclarations() const;
  56. const String getCallbackDefinitions() const;
  57. const StringArray getExtraParentClasses() const;
  58. int getUniqueSuffix();
  59. //==============================================================================
  60. // An object to load and store all the user-defined bits of code as documents.
  61. class CustomCodeList : public ChangeBroadcaster
  62. {
  63. public:
  64. CustomCodeList();
  65. ~CustomCodeList();
  66. void reloadFrom (const String& fileContent);
  67. void applyTo (String& fileContent) const;
  68. bool needsSaving() const;
  69. //==============================================================================
  70. // Ref-counted wrapper for a code document..
  71. class CodeDocumentRef : public ReferenceCountedObject
  72. {
  73. public:
  74. CodeDocumentRef() {}
  75. CodeDocument& getDocument() throw() { return doc; }
  76. typedef ReferenceCountedObjectPtr<CodeDocumentRef> Ptr;
  77. private:
  78. CodeDocument doc;
  79. CodeDocumentRef (const CodeDocumentRef&);
  80. CodeDocumentRef& operator= (const CodeDocumentRef&);
  81. };
  82. //==============================================================================
  83. int getNumSections() const;
  84. const String getSectionName (int index) const;
  85. const CodeDocumentRef::Ptr getDocument (int index) const;
  86. const CodeDocumentRef::Ptr getDocumentFor (const String& sectionName, bool createIfNotFound);
  87. const String getSectionContent (const String& sectionName) const;
  88. void removeSection (const String& sectionName);
  89. class Iterator
  90. {
  91. public:
  92. Iterator (const String& documentText, CustomCodeList& customCode);
  93. ~Iterator();
  94. bool next();
  95. String textBefore, textAfter, sectionName;
  96. CodeDocumentRef::Ptr codeDocument;
  97. private:
  98. CustomCodeList& customCode;
  99. StringArray lines;
  100. int i;
  101. Iterator (const Iterator&);
  102. Iterator& operator= (const Iterator&);
  103. };
  104. private:
  105. StringArray sectionNames;
  106. ReferenceCountedArray <CodeDocumentRef> sectionContent;
  107. };
  108. //==============================================================================
  109. void applyToCode (String& codeTemplate, const File& targetFile,
  110. bool isForPreview, Project* project) const;
  111. private:
  112. //==============================================================================
  113. const String getClassDeclaration() const;
  114. const String getInitialiserList() const;
  115. int suffix;
  116. CodeGenerator (const CodeGenerator&);
  117. CodeGenerator& operator= (const CodeGenerator&);
  118. };
  119. #endif // __JUCER_CODEGENERATOR_H_F79AEF58__