-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Traktor: Refactored "object store" in editor; no longer reference obj…
…ects using names but instead types.
- Loading branch information
Showing
45 changed files
with
252 additions
and
163 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
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,45 @@ | ||
/* | ||
* TRAKTOR | ||
* Copyright (c) 2024 Anders Pistol. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
#include "Core/Misc/ObjectStore.h" | ||
|
||
namespace traktor | ||
{ | ||
|
||
T_IMPLEMENT_RTTI_CLASS(L"traktor.ObjectStore", ObjectStore, Object) | ||
|
||
void ObjectStore::set(Object* object) | ||
{ | ||
const TypeInfo& objectType = type_of(object); | ||
auto it = std::remove_if(m_objects.begin(), m_objects.end(), [&](Object* object) { | ||
return is_type_of( | ||
type_of(object), | ||
objectType | ||
); | ||
}); | ||
m_objects.erase(it, m_objects.end()); | ||
m_objects.push_back(object); | ||
} | ||
|
||
bool ObjectStore::unset(Object* object) | ||
{ | ||
return m_objects.remove(object); | ||
} | ||
|
||
Object* ObjectStore::get(const TypeInfo& objectType) const | ||
{ | ||
auto it = std::find_if(m_objects.begin(), m_objects.end(), [&](Object* object) { | ||
return is_type_of( | ||
objectType, | ||
type_of(object) | ||
); | ||
}); | ||
return it != m_objects.end() ? *it : nullptr; | ||
} | ||
|
||
} |
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,57 @@ | ||
/* | ||
* TRAKTOR | ||
* Copyright (c) 2024 Anders Pistol. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
#pragma once | ||
|
||
#include "Core/Object.h" | ||
#include "Core/RefArray.h" | ||
#include "Core/Containers/SmallMap.h" | ||
|
||
// import/export mechanism. | ||
#undef T_DLLCLASS | ||
#if defined(T_CORE_EXPORT) | ||
# define T_DLLCLASS T_DLLEXPORT | ||
#else | ||
# define T_DLLCLASS T_DLLIMPORT | ||
#endif | ||
|
||
namespace traktor | ||
{ | ||
|
||
/*! Object store container, maps type to instance. | ||
* \ingroup Core | ||
*/ | ||
class T_DLLCLASS ObjectStore : public Object | ||
{ | ||
T_RTTI_CLASS; | ||
|
||
public: | ||
void set(Object* object); | ||
|
||
bool unset(Object* object); | ||
|
||
Object* get(const TypeInfo& objectType) const; | ||
|
||
template < typename ObjectType > | ||
ObjectType* get() const | ||
{ | ||
return dynamic_type_cast< ObjectType* >(get(type_of< ObjectType >())); | ||
} | ||
|
||
template < typename ObjectType > | ||
bool unset() | ||
{ | ||
Object* object = get< ObjectType >(); | ||
return object ? unset(object) : false; | ||
} | ||
|
||
private: | ||
RefArray< Object > m_objects; | ||
}; | ||
|
||
} |
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
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
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.