i got a Problem with a template I created a generic class whcih stores global available Information. This class holds a private mutex to manage the access to the global info.
template<typename Mutex_Type_T, typename Struct_Type_T>
class CGlobal_Struct
{
public:
/**
* Exports data from this class to target
* @param target the actual target
* @param mutex_timeout Mutex wait time
* @return true in case of success
*/
bool Export(Struct_Type_T& target, const uint32_t mutex_timeout = 100);
/**
* Imports data to this class
* @param source The data to store in this class
* @param mutex_timeout Wait Time for Mutex
* @return true in case of success
*/
bool Import(const Struct_Type_T& source, const uint32_t mutex_timeout = 100);
/**
* 1) Loads Data to Buffer
* 2) performs user defined Operation by calling func_T(data, args)
* 3) stores back the data
* @param User defined function
* @param values class data to modify
* @param mutex_timeout Mutex wait time
* @return true in case of success
*/
template<typename func_T, typename func_arg_t>
bool Replace(func_T(Struct_Type_T& values, const func_arg_t args), const func_arg_t func_args,const uint32_t mutex_timeout = 100);
private:
mutex _mutex;
}
This implementation Looks like this
template<typename Mutex_Type_T, typename Struct_Type_T>
template<typename func_T, typename func_arg_t>
bool CGlobal_Struct<Mutex_Type_T, Struct_Type_T>::Replace(func_T(Struct_Type_T& values, const func_arg_t args),const func_arg_t func_args, const uint32_t mutex_timeout)
{
CLock_Guard lock(mutex);
//Lock access
if(false == lock.Lock(mutex_timeout))
{
//Locking failed
return false;
}
//Replace Data
func_T(data, func_args);
//Mutex is released automatically when we leave this function
return true;
}
Now first Question: is this template implementation correct?
Second: How would i call this replacement function from outside this class? Could you give me some help please?