Clean up NPPM_ALLOCATEMARKER API

pull/12277/head
Don Ho 2022-10-03 01:28:55 +02:00
parent 11884bd97f
commit 83ee8f09bf
7 changed files with 19 additions and 52 deletions

View File

@ -1,42 +0,0 @@
// IDAllocator.h code is copyrighted (C) 2010 by Dave Brotherstone
// This file is part of Notepad++ project
// Copyright (C)2021 Don HO <don.h@free.fr>
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "IDAllocator.h"
IDAllocator::IDAllocator(int start, int maximumID)
: _start(start),
_nextID(start),
_maximumID(maximumID)
{
}
int IDAllocator::allocate(int quantity)
{
int retVal = -1;
if (_nextID + quantity <= _maximumID && quantity > 0)
{
retVal = _nextID;
_nextID += quantity;
}
return retVal;
}

View File

@ -22,10 +22,20 @@
class IDAllocator class IDAllocator
{ {
public: public:
IDAllocator(int start, int maximumID); IDAllocator(int start, int maximumID) : _start(start), _nextID(start), _maximumID(maximumID) {};
/// Returns -1 if not enough available /// Returns -1 if not enough available
int allocate(int quantity); int allocate(int quantity) {
int retVal = -1;
if (_nextID + quantity <= _maximumID && quantity > 0)
{
retVal = _nextID;
_nextID += quantity;
}
return retVal;
};
bool isInRange(int id) { return (id >= _start && id < _nextID); } bool isInRange(int id) { return (id >= _start && id < _nextID); }

View File

@ -808,11 +808,11 @@ bool PluginsManager::allocateCmdID(int numberRequired, int *start)
return retVal; return retVal;
} }
bool PluginsManager::allocateMarker(int numberRequired, int *start) bool PluginsManager::allocateMarker(int numberRequired, int* start)
{ {
bool retVal = true; bool retVal = true;
*start = _markerAlloc.allocate(numberRequired); *start = _markerAlloc.allocate(numberRequired);
if (-1 == *start) if (*start == -1)
{ {
*start = 0; *start = 0;
retVal = false; retVal = false;

View File

@ -116,7 +116,7 @@ public:
bool allocateCmdID(int numberRequired, int *start); bool allocateCmdID(int numberRequired, int *start);
bool inDynamicRange(int id) { return _dynamicIDAlloc.isInRange(id); } bool inDynamicRange(int id) { return _dynamicIDAlloc.isInRange(id); }
bool allocateMarker(int numberRequired, int *start); bool allocateMarker(int numberRequired, int* start);
generic_string getLoadedPluginNames() const; generic_string getLoadedPluginNames() const;
private: private:

View File

@ -117,8 +117,8 @@ const int MARK_BOOKMARK = 20;
const int MARK_HIDELINESBEGIN = 19; const int MARK_HIDELINESBEGIN = 19;
const int MARK_HIDELINESEND = 18; const int MARK_HIDELINESEND = 18;
const int MARK_HIDELINESUNDERLINE = 17; const int MARK_HIDELINESUNDERLINE = 17;
// 20 - 16 reserved for Notepad++ internal used // 20 - 17 reserved for Notepad++ internal used
// 15 - 0 are free to use for plugins // 16 - 0 are free to use for plugins
int getNbDigits(int aNum, int base); int getNbDigits(int aNum, int base);

View File

@ -415,8 +415,8 @@
#define ID_PLUGINS_CMD_DYNAMIC_LIMIT 24999 #define ID_PLUGINS_CMD_DYNAMIC_LIMIT 24999
#define MARKER_PLUGINS 3 #define MARKER_PLUGINS 1
#define MARKER_PLUGINS_LIMIT 19 #define MARKER_PLUGINS_LIMIT 15

View File

@ -436,7 +436,6 @@ copy ..\src\contextMenu.xml ..\binarm64\contextMenu.xml
<ClCompile Include="..\src\WinControls\FunctionList\functionParser.cpp" /> <ClCompile Include="..\src\WinControls\FunctionList\functionParser.cpp" />
<ClCompile Include="..\src\ScintillaComponent\GoToLineDlg.cpp" /> <ClCompile Include="..\src\ScintillaComponent\GoToLineDlg.cpp" />
<ClCompile Include="..\src\WinControls\DockingWnd\Gripper.cpp" /> <ClCompile Include="..\src\WinControls\DockingWnd\Gripper.cpp" />
<ClCompile Include="..\src\MISC\PluginsManager\IDAllocator.cpp" />
<ClCompile Include="..\src\WinControls\ImageListSet\ImageListSet.cpp" /> <ClCompile Include="..\src\WinControls\ImageListSet\ImageListSet.cpp" />
<ClCompile Include="..\src\uchardet\JpCntx.cpp" /> <ClCompile Include="..\src\uchardet\JpCntx.cpp" />
<ClCompile Include="..\src\uchardet\LangBulgarianModel.cpp" /> <ClCompile Include="..\src\uchardet\LangBulgarianModel.cpp" />