1 // Scintilla source code edit control 2 /** @file CatalogueModules.h 3 ** Lexer infrastructure. 4 ** Contains a list of LexerModules which can be searched to find a module appropriate for a 5 ** particular language. 6 **/ 7 // Copyright 1998-2010 by Neil Hodgson <[email protected]> 8 // The License.txt file describes the conditions under which this software may be distributed. 9 10 #ifndef CATALOGUEMODULES_H 11 #define CATALOGUEMODULES_H 12 13 namespace Scintilla { 14 15 class CatalogueModules { 16 std::vector<LexerModule *> lexerCatalogue; 17 public: Find(int language)18 const LexerModule *Find(int language) const { 19 for (const LexerModule *lm : lexerCatalogue) { 20 if (lm->GetLanguage() == language) { 21 return lm; 22 } 23 } 24 return nullptr; 25 } 26 Find(const char * languageName)27 const LexerModule *Find(const char *languageName) const noexcept { 28 if (languageName) { 29 for (const LexerModule *lm : lexerCatalogue) { 30 if (lm->languageName && (0 == strcmp(lm->languageName, languageName))) { 31 return lm; 32 } 33 } 34 } 35 return nullptr; 36 } 37 AddLexerModule(LexerModule * plm)38 void AddLexerModule(LexerModule *plm) { 39 lexerCatalogue.push_back(plm); 40 } 41 Count()42 unsigned int Count() const noexcept { 43 return static_cast<unsigned int>(lexerCatalogue.size()); 44 } 45 Name(unsigned int index)46 const char *Name(unsigned int index) const noexcept { 47 if (index < static_cast<unsigned int>(lexerCatalogue.size())) { 48 return lexerCatalogue[index]->languageName; 49 } else { 50 return ""; 51 } 52 } 53 Factory(unsigned int index)54 LexerFactoryFunction Factory(unsigned int index) const noexcept { 55 // Works for object lexers but not for function lexers 56 return lexerCatalogue[index]->fnFactory; 57 } 58 Create(unsigned int index)59 ILexer5 *Create(unsigned int index) const { 60 const LexerModule *plm = lexerCatalogue[index]; 61 if (!plm) { 62 return nullptr; 63 } 64 return plm->Create(); 65 } 66 }; 67 68 } 69 70 #endif 71