WIP adding directory structure
This commit is contained in:
67
kraken/resources/unknown/KRUnknown.cpp
Executable file
67
kraken/resources/unknown/KRUnknown.cpp
Executable file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// KRUnknown.cpp
|
||||
// Kraken Engine
|
||||
//
|
||||
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include "KRUnknown.h"
|
||||
|
||||
using namespace mimir;
|
||||
|
||||
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
||||
{
|
||||
m_pData = new Block();
|
||||
m_extension = extension;
|
||||
}
|
||||
|
||||
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
|
||||
{
|
||||
m_pData = data;
|
||||
m_extension = extension;
|
||||
}
|
||||
|
||||
KRUnknown::~KRUnknown()
|
||||
{
|
||||
delete m_pData;
|
||||
}
|
||||
|
||||
std::string KRUnknown::getExtension()
|
||||
{
|
||||
return m_extension;
|
||||
}
|
||||
|
||||
bool KRUnknown::save(Block& data)
|
||||
{
|
||||
data.append(*m_pData);
|
||||
return true;
|
||||
}
|
||||
|
||||
Block* KRUnknown::getData()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
57
kraken/resources/unknown/KRUnknown.h
Executable file
57
kraken/resources/unknown/KRUnknown.h
Executable file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// KRUnknown.h
|
||||
// Kraken Engine
|
||||
//
|
||||
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include "KRContextObject.h"
|
||||
#include "block.h"
|
||||
#include "resources/KRResource.h"
|
||||
|
||||
class KRUnknown : public KRResource
|
||||
{
|
||||
|
||||
public:
|
||||
KRUnknown(KRContext& context, std::string name, std::string extension);
|
||||
KRUnknown(KRContext& context, std::string name, std::string extension, mimir::Block* data);
|
||||
virtual ~KRUnknown();
|
||||
|
||||
virtual std::string getExtension();
|
||||
|
||||
virtual bool save(mimir::Block& data);
|
||||
|
||||
mimir::Block* getData();
|
||||
|
||||
private:
|
||||
|
||||
std::string m_extension;
|
||||
mimir::Block* m_pData;
|
||||
};
|
||||
117
kraken/resources/unknown/KRUnknownManager.cpp
Executable file
117
kraken/resources/unknown/KRUnknownManager.cpp
Executable file
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// KRUnknownManager.cpp
|
||||
// Kraken Engine
|
||||
//
|
||||
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include "KRUnknownManager.h"
|
||||
#include "KREngine-common.h"
|
||||
|
||||
using namespace mimir;
|
||||
|
||||
KRUnknownManager::KRUnknownManager(KRContext& context) : KRResourceManager(context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KRUnknownManager::~KRUnknownManager()
|
||||
{
|
||||
for (unordered_map<std::string, unordered_map<std::string, KRUnknown*> >::iterator extension_itr = m_unknowns.begin(); extension_itr != m_unknowns.end(); extension_itr++) {
|
||||
for (unordered_map<std::string, KRUnknown*>::iterator name_itr = (*extension_itr).second.begin(); name_itr != (*extension_itr).second.end(); name_itr++) {
|
||||
delete (*name_itr).second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unordered_map<std::string, unordered_map<std::string, KRUnknown*> >& KRUnknownManager::getUnknowns()
|
||||
{
|
||||
return m_unknowns;
|
||||
}
|
||||
|
||||
void KRUnknownManager::add(KRUnknown* unknown)
|
||||
{
|
||||
std::string lower_name = unknown->getName();
|
||||
std::string lower_extension = unknown->getExtension();
|
||||
|
||||
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
|
||||
std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower);
|
||||
|
||||
unordered_map<std::string, unordered_map<std::string, KRUnknown*> >::iterator extension_itr = m_unknowns.find(lower_extension);
|
||||
if (extension_itr == m_unknowns.end()) {
|
||||
m_unknowns[lower_extension] = unordered_map<std::string, KRUnknown*>();
|
||||
extension_itr = m_unknowns.find(lower_extension);
|
||||
}
|
||||
|
||||
unordered_map<std::string, KRUnknown*>::iterator name_itr = (*extension_itr).second.find(lower_name);
|
||||
if (name_itr != (*extension_itr).second.end()) {
|
||||
delete (*name_itr).second;
|
||||
(*name_itr).second = unknown;
|
||||
} else {
|
||||
(*extension_itr).second[lower_name] = unknown;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
KRResource* KRUnknownManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||
{
|
||||
// KRUnknown's can have any extension
|
||||
return load(name, extension, data);
|
||||
}
|
||||
|
||||
KRResource* KRUnknownManager::getResource(const std::string& name, const std::string& extension)
|
||||
{
|
||||
// KRUnknown's can have any extension
|
||||
return get(name, extension);
|
||||
}
|
||||
|
||||
KRUnknown* KRUnknownManager::load(const std::string& name, const std::string& extension, Block* data)
|
||||
{
|
||||
KRUnknown* unknown = new KRUnknown(getContext(), name, extension, data);
|
||||
if (unknown) add(unknown);
|
||||
return unknown;
|
||||
}
|
||||
|
||||
KRUnknown* KRUnknownManager::get(const std::string& name, const std::string& extension)
|
||||
{
|
||||
std::string lower_name = name;
|
||||
std::string lower_extension = extension;
|
||||
|
||||
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
|
||||
std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower);
|
||||
|
||||
return m_unknowns[lower_extension][lower_name];
|
||||
}
|
||||
|
||||
|
||||
const unordered_map<std::string, KRUnknown*>& KRUnknownManager::get(const std::string& extension)
|
||||
{
|
||||
std::string lower_extension = extension;
|
||||
std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower);
|
||||
return m_unknowns[lower_extension];
|
||||
}
|
||||
|
||||
63
kraken/resources/unknown/KRUnknownManager.h
Executable file
63
kraken/resources/unknown/KRUnknownManager.h
Executable file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// KRUnknownManager.h
|
||||
// Kraken Engine
|
||||
//
|
||||
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "resources/KRResourceManager.h"
|
||||
|
||||
#include "KRUnknown.h"
|
||||
#include "KRContextObject.h"
|
||||
#include "block.h"
|
||||
|
||||
class KRUnknownManager : public KRResourceManager
|
||||
{
|
||||
public:
|
||||
KRUnknownManager(KRContext& context);
|
||||
virtual ~KRUnknownManager();
|
||||
|
||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||
|
||||
void add(KRUnknown* unknown);
|
||||
|
||||
KRUnknown* load(const std::string& name, const std::string& extension, mimir::Block* data);
|
||||
KRUnknown* get(const std::string& name, const std::string& extension);
|
||||
|
||||
|
||||
const unordered_map<std::string, KRUnknown*>& get(const std::string& extension);
|
||||
|
||||
unordered_map<std::string, unordered_map<std::string, KRUnknown*> >& getUnknowns();
|
||||
|
||||
private:
|
||||
unordered_map<std::string, unordered_map<std::string, KRUnknown*> > m_unknowns;
|
||||
};
|
||||
Reference in New Issue
Block a user