Code: Alles auswählen
#ifndef ORG_PROGGEN_DEDUPE_CLI_ACTION_H
#define ORG_PROGGEN_DEDUPE_CLI_ACTION_H
#include <boost/function.hpp>
#include <kernel.h>
#include <command.h>
#include <cli.h>
namespace Dedupe
{
namespace CLI
{
/**
*A Action object holds a list of allowed commands and the
*function which should be executed, if the correct commands are given.
*/
class Action
{
public:
/**
* KFPointer is a function pointer which can be every function from
*the kernel with the following signature: returning type bool, Argument
*Dedupe::FilePath
*/
typedef boost::function<bool ( Dedupe::Core::Kernel*, Dedupe::FilePath )>
KFPointer;
typedef boost::function<bool ( Dedupe::CLI::CLI* )> CFPointer;
/**
*Give a Dedupe::CLI::CommandList, the adress of the function that
*should be executed, if the right arguments are given and the current
*kernel object
*/
Action( Dedupe::CLI::CommandList List,
KFPointer Functionpointer,
Dedupe::Core::Kernel Kernel )
: List( List ),
functionpointer( Functionpointer ),
Kernel( Kernel ),
disabled( false )
{
/*sort the list, cause the list from CheckAllowed will also be sorted,
to make sure, different positions don't result in a error */
std::sort( List.begin(), List.end() );
}
Action() : disabled( true ) {}
/**
*Check if the holded list of commands and the given is equal
*/
bool CheckAllowed( Dedupe::CLI::CommandList ComList ) const
{
if( disabled == true ) return false;
std::sort( ComList.begin(), ComList.end() );
return ( ComList == List );
}
/**
*Execute the function. The function argument musst be given here.
*@param Dedupe::FilePath @return true if holded function returns true
*/
inline bool ExecFunction( Dedupe::FilePath Path )
{
if( disabled == true ) return false;
//See reference of boost.Function
return functionpointer( &Kernel, Path );
}
private:
Dedupe::CLI::CommandList List;
Dedupe::CLI::Action::KFPointer functionpointer;
Dedupe::Core::Kernel Kernel;
bool disabled;
};
}
}
#endif
Code: Alles auswählen
typedef boost::function<bool ( Dedupe::CLI::CLI* )> CFPointer;
Ich sehe vermutlich vor lauter Bäumen den Wald nicht mehr, aber bitte HILFE, sonst drehe ich hier noch ab...
Hier noch die cli.h
Code: Alles auswählen
#ifndef ORG_PROGGEN_DEDUPE_CLI_CLI_H
#define ORG_PROGGEN_DEDUPE_CLI_CLI_H
#include <string>
#include <vector>
#include <iostream>
#include <searchfiles.h>
#include <commandgroup.h>
namespace Dedupe
{
/**
*CLI stands for Command Line Interface and contains everything
*from that userinterface
*/
namespace CLI
{
/**
*StartArgs is a simple string vector for
*the start arguments from main()
*/
typedef std::vector<std::string> StartArgs;
class CLI
{
public:
CLI( Dedupe::CLI::StartArgs const &Args );
bool RegisterGroup( Dedupe::CLI::CommandGroup Group );
void PrintHelp();
private:
Dedupe::FileSearch::FileStream GivenPaths;
short HandleArgs( Dedupe::CLI::StartArgs const &Args );
};
}
}
#endif
