Files
projectm/src/libprojectM/PresetFactoryManager.hpp
Mischa Spiegelmock e49720ecfa Preset subdirs (#385)
Scanning textures/presets dirs for textures and scanning preset dir for presets.
Scanning is now done recursively, so presets and textures can be organized into subdirectories instead of needing to be flattened into a single directory.

On POSIX systems makes use of [ftw](https://linux.die.net/man/3/ftw) which should be relatively efficient. Otherwise falls back to recursing with `dirent` (for windows).

Probably should have made an autoconf check for `ftw` instead of doing `#ifdef WIN32`. 

* Scan subdirectories in presets directory

* remove preset subdir config

* Recursively scan for textures too, add c++-17 compatibility

* Refactor directory scanning code so it's reused by texture loader and preset loader. Make cross-platform (maybe)

* filescanner in makefile

* extension filter for file loader

* make extensions match up'

* need string.h

* Add FileScanner.cpp to win build (maybe)

* scan all dirs

* #ifndef #ifdef is def fun

* bogus comment

* bleh

* bleh

* itunes plugin with c++17

* EyeTunes needs to know about the FileScanner

Co-authored-by: milkdropper.com <milkdropper.com@gmail.com>
Co-authored-by: milkdropper <59471060+milkdropper@users.noreply.github.com>
2020-07-28 22:01:56 +03:00

63 lines
2.0 KiB
C++

//
// C++ Implementation: PresetFactoryManager
//
// Description:
//
//
// Author: Carmelo Piccione <carmelo.piccione@gmail.com>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef __PRESET_FACTORY_MANAGER_HPP
#define __PRESET_FACTORY_MANAGER_HPP
#include "PresetFactory.hpp"
/// A simple exception class to strongly type all preset factory related issues
class PresetFactoryException : public std::exception
{
public:
inline PresetFactoryException(const std::string & message) : _message(message) {}
virtual ~PresetFactoryException() throw() {}
const std::string & message() const { return _message; }
private:
std::string _message;
};
/// A manager of preset factories
class PresetFactoryManager {
public:
PresetFactoryManager();
~PresetFactoryManager();
/// Initializes the manager with mesh sizes specified
/// \param gx the width of the mesh
/// \param gy the height of the mesh
/// \note This must be called once before any other methods
void initialize(int gx, int gy);
/// Requests a factory given a preset extension type
/// \param extension a string denoting the preset suffix type
/// \throws PresetFactoryException if the extension is unhandled
/// \returns a valid preset factory associated with the extension
PresetFactory & factory(const std::string & extension);
/// Tests if an extension has been registered with a factory
/// \param extension the file name extension to verify
/// \returns true if a factory exists, false otherwise
bool extensionHandled(const std::string & extension) const;
std::unique_ptr<Preset> allocate(const std::string & url, const std::string & name);
std::vector<std::string> extensionsHandled() const;
private:
int _gx, _gy;
mutable std::map<std::string, PresetFactory *> _factoryMap;
mutable std::vector<PresetFactory *> _factoryList;
void registerFactory(const std::string & extension, PresetFactory * factory);
volatile bool initialized;
};
#endif