-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created ListsDeclaration.inc and ListsBody.inc to create list of obje…
…cts (or base types) without exposing std::vector or std::list. Modified Configuration.h to declare class ConfigurationPtrList. Replaced usage of Node class in ConfigManager. For issue #102
- Loading branch information
1 parent
e15348a
commit deccf01
Showing
11 changed files
with
286 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/********************************************************************************** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Antoine Beauchamp | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*********************************************************************************/ | ||
|
||
namespace shellanything | ||
{ | ||
|
||
struct SA_LISTS_CLASS_NAME::PImpl | ||
{ | ||
std::vector<SA_LISTS_CLASS_NAME::Element> elements; | ||
}; | ||
|
||
SA_LISTS_CLASS_NAME::SA_LISTS_CLASS_NAME() | ||
{ | ||
mPImpl = new SA_LISTS_CLASS_NAME::PImpl(); | ||
} | ||
|
||
SA_LISTS_CLASS_NAME::~SA_LISTS_CLASS_NAME() | ||
{ | ||
delete mPImpl; | ||
} | ||
|
||
SA_LISTS_CLASS_NAME::SA_LISTS_CLASS_NAME(const SA_LISTS_CLASS_NAME& listcopy) | ||
{ | ||
mPImpl = new SA_LISTS_CLASS_NAME::PImpl(); | ||
(*this) = listcopy; | ||
} | ||
|
||
SA_LISTS_CLASS_NAME& SA_LISTS_CLASS_NAME::operator=(const SA_LISTS_CLASS_NAME& listcopy) | ||
{ | ||
mPImpl->elements = listcopy.mPImpl->elements; | ||
return (*this); | ||
} | ||
|
||
size_t SA_LISTS_CLASS_NAME::GetSize() const | ||
{ | ||
return mPImpl->elements.size(); | ||
} | ||
|
||
void SA_LISTS_CLASS_NAME::Clear() | ||
{ | ||
return mPImpl->elements.clear(); | ||
} | ||
|
||
SA_LISTS_CLASS_NAME::Element & SA_LISTS_CLASS_NAME::GetElement(size_t index) | ||
{ | ||
return mPImpl->elements[index]; | ||
} | ||
|
||
const SA_LISTS_CLASS_NAME::Element & SA_LISTS_CLASS_NAME::GetElement(size_t index) const | ||
{ | ||
return mPImpl->elements[index]; | ||
} | ||
|
||
size_t SA_LISTS_CLASS_NAME::FindElement(const SA_LISTS_CLASS_NAME::Element & value) const | ||
{ | ||
//std::vector<SA_LISTS_CLASS_NAME::Element>::iterator it; | ||
//it = std::find(mPImpl->elements.begin(), mPImpl->elements.end(), value); | ||
//bool found = (it != mPImpl->elements.end()); | ||
//return found; | ||
|
||
std::vector<SA_LISTS_CLASS_NAME::Element>& v = mPImpl->elements; | ||
for (size_t i = 0; i < v.size(); i++) | ||
{ | ||
const SA_LISTS_CLASS_NAME::Element & element = v[i]; | ||
if (element == value) | ||
return i; | ||
} | ||
|
||
return INVALID_INDEX; | ||
} | ||
|
||
void SA_LISTS_CLASS_NAME::AddElement(SA_LISTS_CLASS_NAME::Element instance) | ||
{ | ||
return mPImpl->elements.push_back(instance); | ||
} | ||
|
||
void SA_LISTS_CLASS_NAME::RemoveElementByValue(SA_LISTS_CLASS_NAME::Element value) | ||
{ | ||
size_t index = FindElement(value); | ||
if (index != INVALID_INDEX) | ||
RemoveElementByIndex(index); | ||
} | ||
|
||
void SA_LISTS_CLASS_NAME::RemoveElementByIndex(size_t index) | ||
{ | ||
if (index != INVALID_INDEX) | ||
mPImpl->elements.erase(mPImpl->elements.begin() + index); | ||
} | ||
|
||
} //namespace shellanything |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/********************************************************************************** | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Antoine Beauchamp | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*********************************************************************************/ | ||
|
||
namespace shellanything | ||
{ | ||
|
||
/// <summary> | ||
/// A structure that contains a list of Configuration class pointers. | ||
/// </summary> | ||
class SA_LISTS_CLASS_NAME | ||
{ | ||
public: | ||
SA_LISTS_CLASS_NAME(); | ||
virtual ~SA_LISTS_CLASS_NAME(); | ||
|
||
static const size_t INVALID_INDEX = (size_t)-1; | ||
|
||
SA_LISTS_CLASS_NAME(const SA_LISTS_CLASS_NAME& listcopy); | ||
SA_LISTS_CLASS_NAME& operator=(const SA_LISTS_CLASS_NAME& listcopy); | ||
|
||
/// <summary> | ||
/// A custom type definition for the base type | ||
/// </summary> | ||
typedef SA_LISTS_BASE_TYPE Element; | ||
|
||
/// <summary> | ||
/// Get the number of element in the list. | ||
/// </summary> | ||
size_t GetSize() const; | ||
inline size_t size() const { return GetSize(); } // for std::vector and std::list code compatibility. | ||
|
||
/// <summary> | ||
/// Remove all elements in the list. | ||
/// </summary> | ||
void Clear(); | ||
|
||
/// <summary> | ||
/// Get an element from an index. | ||
/// </summary> | ||
/// <param name="index">The index of the requested instance.</param> | ||
/// <returns>Returns a valid element if the index is valid. Returns an invalid element otherwise.</returns> | ||
Element & GetElement(size_t index); | ||
const Element & GetElement(size_t index) const; | ||
inline Element & operator[](size_t index) { return GetElement(index); } | ||
inline const Element & operator[](size_t index) const { return GetElement(index); } | ||
|
||
/// <summary> | ||
/// Find an element in the list. | ||
/// </summary> | ||
/// <param name="value">A value to find.</param> | ||
/// <returns>Returns true when the element is found. Returns false otherwise.</returns> | ||
size_t FindElement(const Element & value) const; | ||
|
||
/// <summary> | ||
/// Add a value to the list. | ||
/// </summary> | ||
/// <param name="value">The value to add.</param> | ||
void AddElement(Element value); | ||
|
||
/// <summary> | ||
/// Remove a value from the list. | ||
/// </summary> | ||
/// <param name="value">The value to remove.</param> | ||
void RemoveElementByValue(Element value); | ||
|
||
/// <summary> | ||
/// Remove a value from the list. | ||
/// </summary> | ||
/// <param name="index">The index of the value to remove.</param> | ||
void RemoveElementByIndex(size_t index); | ||
|
||
private: | ||
struct PImpl; | ||
PImpl* mPImpl; | ||
}; | ||
|
||
} //namespace shellanything |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.