Hello,
I basically want to implement a general resource manager which should have
a caching and a loading policy so that I can exchange those. Here's some
example code of how it should work:
ResourceManager < SimpleCachingPo licy<Image, SimpleImageLoad er> > imageMgr;
ResourceManager < SimpleCachingPo licy<Sound, SimpleSoundLoad er> > soundMgr;
imageMgr.Load(f ilename, 1234);
soundMgr.Load(f ilename, "foo", 5.37);
So we have two managers which load sound and images respectively and both
use the same caching policy. However, notice that the arguments of the
Load function are different.
Now I want to write a SimpleCachingPo licy that can take an arbitrary
object (or pointer to it). I tried like this:
template<typena me ResourceType, typename LoadingPolicy>
class SimpleCachingPo licy
{
public:
ResourceType Load(... what to put here, the arguments into this func are
different for each ResourceType ...)
{
if ( IsCached(... same arguments as above ...) ) return obj;
obj=LoadingPoli cy::LoadObject( ... same args as above ...);
AddToCache(obj) ;
return obj;
}
};
The problem one can see here is that I would need to write the Load
function several times, one version for each parameter. I thought I could
apply functors here, but I am not sure how I can do this. Can you give me
any hints what I can do to solve this problem? Is there a way round
needing to make several versions of Load(...)?
Thanks a lot for your help!
-Matthias 1 1207
Matthias wrote: I basically want to implement a general resource manager which should have a caching and a loading policy so that I can exchange those. Here's some example code of how it should work:
ResourceManager < SimpleCachingPo licy<Image, SimpleImageLoad er> > imageMgr; ResourceManager < SimpleCachingPo licy<Sound, SimpleSoundLoad er> > soundMgr;
imageMgr.Load(f ilename, 1234); soundMgr.Load(f ilename, "foo", 5.37);
So we have two managers which load sound and images respectively and both use the same caching policy. However, notice that the arguments of the Load function are different. Now I want to write a SimpleCachingPo licy that can take an arbitrary object (or pointer to it). I tried like this:
template<typena me ResourceType, typename LoadingPolicy> class SimpleCachingPo licy { public: ResourceType Load(... what to put here, the arguments into this func are different for each ResourceType ...) { if ( IsCached(... same arguments as above ...) ) return obj; obj=LoadingPoli cy::LoadObject( ... same args as above ...);
So, it's apparent that your 'SimpleCachingP olicy' is not that simple,
is it? Essentially, on one hand, you're trying to keep the interface
the same since it's the caller that should define it, and OTOH you're
forced to provide several of those since it ultimately depends on the
type of the template argument...
AddToCache(obj) ; return obj; } };
The problem one can see here is that I would need to write the Load function several times, one version for each parameter. I thought I could apply functors here, but I am not sure how I can do this. Can you give me any hints what I can do to solve this problem? Is there a way round needing to make several versions of Load(...)?
I don't think so. You can try to work around the necessity to have
several 'Load' members in the same class template by inheriting it from
different 'Loaders', which you will specialise on the type of Resource,
but it will only move the problem from one class into the other. You
still will have to "make several versions of Load".
V This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ash |
last post by:
Hello all,
I am hoping this is the appropriate newsgroup for a C++ interface
design question. I am trying to design an interface for a subscriber
to register/deregister handlers for various events. The callbacks
specified by the subscriber will be called when the events get
trigerred in a different thread. Each event has different kinds of...
|
by: Adrian |
last post by:
Normalization Question - Please bear with me, hopefully things will be
clear at the end of the question.
Given a treaty table containg treaties; Treaty1, Treaty2 etc and a
benefit table; Benefit1, Benefit2 etc. A treaty can only have certain
benefits:-
For example Treaty 1 can process Benefit1 and Benefit2.
To maintain this...
|
by: websphereguru |
last post by:
Hi,
I am having a tough time coming up with a good design for a webpage.
The following is a brief description of what i am trying to achieve.
The requirement is for an insurance company and the goal is to gather
insurance policy information to give its users a quote.
The user can add/edit/delete policies before submitting it and going to...
|
by: adb |
last post by:
I came up with a replication configuration that is basically the result
of
all the restrictions of replication as well as the restrictions of
allowable software on work PC's and I was curious if anyone would point
out
any flaws or possible problems with the design.
I'm limited to Access 2000 professional edition (Thus I cannot use...
|
by: Fraser Ross |
last post by:
Functors taking 1 argument for operator() should inherit from
unary_function and those with 2 arguments should inherit from
binary_function. If a functor has zero arguments for its operator()
should it inherit from anything to make it adaptable? I've not heard of
anything before which is surprising. If books don't talk about it then
its an...
| |
by: vbnetguy |
last post by:
Hi All, I have read MANY posts on how to track changes to data over
time
It appears there are two points of view
1. Each record supports a Change Indicator flag to
indicate the current record
(would this be EVERY table?)
2. Each table is duplicated as an archive table and
triggers are used to update archive
|
by: tryptik |
last post by:
Hello all,
I have a question about iterators. I have a container of functors
that operate on an std::string. The functors go something like this:
class Functor {
std::string operator()(const std::string& s) {/*manipulate
string*/; return newString;}
};
|
by: Jon Slaughter |
last post by:
I'm trying to mess with functors and the way I want it to work is that when
I create a functor it will automatically add itself to an array.
The attached code demonstrates what I mean. The problem is that its a bit
unsatisfactory and I'd like to improve it.
In the constructor of TClassA
Functors<TClassA, std::string*Functor = new...
|
by: DerrickH |
last post by:
I have a template class with three policies: PolicyA, PolicyB, and
PolicyC. The design dilemma I am having is that B and C depend upon A,
but I would like my Host class to derive from all three. In all three
cases I would like to take advantage of enriched policies.
template <
class PolicyA,
template <classclass PolicyB,
template...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |