Writing a path solver

All the file paths used inside atoms can be filtered and expanded by custom PathSolverFilter objects. By default, Atoms has an internal path solver that expands environment variables. You can write your own filter.


Class definition

#include <Atoms/Globals.h>
#include <AtomsCore/Globals.h>
#include <AtomsUtils/PathSolver.h>

class MyPathSolverFilter: public AtomsUtils::PathSolverFilter
{
public:

	MyPathSolverFilter(const std::string& name): AtomsUtils::PathSolverFilter(name)
	{
		
	}

	virtual ~MyPathSolverFilter()
	{
		
	}

	virtual bool validate(const std::string& path) const override
	{
		// return true if this solver must filter this path
		return true;
	}

	virtual std::string solve(const std::string& path)const override
	{
		// Filter here the path
		return path;
	}
};


Atoms first the validate function, if this is true then it calls the solve function.

Register the new loader to atoms

extern "C"
{
	ATOMSPLUGIN_EXPORT bool initializePlugin()
	{
		AtomsPtr<AtomsUtils::PathSolverFilter> solver(new MyPathSolverFilter("mysolver"));
		AtomsUtils::PathSolver::instance().insertSolver(solver);
	}
	ATOMSPLUGIN_EXPORT bool uninitializePlugin()
	{
		AtomsUtils::PathSolver::instance().removeSolver("mysolver");
	}
}


Compile the plugin

Windows:

In visual studio, create a dll projects, add the atoms includes and add

BUILD_ATOMSPLUGIN,WIN,_CRT_SECURE_NO_WARNINGS,_CRT_NONSTDC_NO_DEPRECATE

to the preprocessor definitions.


Linux:

Compile as a shared object adding the atoms includes and BUILD_ATOMSPLUGIN to the preprocessor definitions.


Use the plugin

Add to the ATOMS_PLUGINS_PATH environment variable the folder where the plugin is located.

Copyright © 2017, Toolchefs LTD.