473,881 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design question: managing limited resources

Hi,

I am currently working on a computer vision system. At the moment I'm adding
support for firewire cameras. Since there is only one firewire system on a
computer, I have writen a firewire manager class as Singleton.

User access to firewire camera objects should only be accessable via
refereces obtained from this manager class. I want to avoid the creation of
more than one camera object accessing the same physical camera.

One solution might be making the constuctor (and the copy constructor) of
the camera class private and declaring the manager class a 'friend' to the
camera class:

class FwCamera {
private:
FwCamera ();
public:
...
friend class FwManager;
}

class FwManager {
public:
FwCamera& getCamera(int number_of_camer a);
...
}

Now only FwManger can control the construction and destruction of FwCamera
objects. The user can only get access to camera objects via the manager
class.

What I don't like is the keyword 'friend'. Is there a better way, to achieve
my my goals?

Thanks in advance,

Torsten
Jul 23 '05 #1
3 1518
Torsten Wiebesiek wrote:
I am currently working on a computer vision system. At the moment I'm adding
support for firewire cameras. Since there is only one firewire system on a
computer, I have writen a firewire manager class as Singleton.

User access to firewire camera objects should only be accessable via
refereces obtained from this manager class. I want to avoid the creation of
more than one camera object accessing the same physical camera.

One solution might be making the constuctor (and the copy constructor) of
the camera class private and declaring the manager class a 'friend' to the
camera class:

class FwCamera {
private:
FwCamera ();
public:
...
friend class FwManager;
}

class FwManager {
public:
FwCamera& getCamera(int number_of_camer a);
...
}

Now only FwManger can control the construction and destruction of FwCamera
objects. The user can only get access to camera objects via the manager
class.

What I don't like is the keyword 'friend'. Is there a better way, to achieve
my my goals?


Have either a nested class in FwCamera, which will keep the record of the
cameras it creates. Essentially you just put your FwManager inside the
FwCamera class and let them talk to each other.

If your compiler is such that will still require to declare FwManager
a friend (shouldn't really be necessary since it's a member and a member
should be allowed to access all members of its class), then you just
dissolve the managing functionality in the FwCamera class itself -- have
a "factory method" which will account the cameras created and return them
(or references or pointers to them).

class FwCamera {
FwCamera(); // private c-tor
public:
class Manager {
static FwCamera* getCamera();
};
};

...
// the user writes
FwCamera* pCamera = FwCamera::Manag er::getCamera() ;

Now, when you create other cameras, let them have a similar 'Manager'
class nested in them and the handling is going to be very similar.

In case when you need to dissolve the managing functionality, do something
like:

class FwCamera {
FwCamera(); // private c-tor
public:
static FwCamera* getCamera(); // will create a new one or return
// one of the pre-created ones
};

What you seem to be using is an extended "Singleton" pattern and as I
already mentioned a "Factory" or a "Factory Method" pattern. Read about
them in your favourite patterns source (book, NG, web).

V
Jul 23 '05 #2
Victor Bazarov wrote:
If your compiler is such that will still require to declare FwManager
a friend (shouldn't really be necessary since it's a member and a member
should be allowed to access all members of its class), [...]


I was shocked at first when I read that, for as long as I could
remember, every source I had ever consulted would state otherwise,
namely that nested class members were given no special privileges in
acessing the members of its nesting class.

I wrote a little test program and was even more shocked to see it get
through 2 different compilers (GCC 3.3.3 and MSVC 13.10.3077), as I was
sure I had had similar code fail compilation in the past. I felt
strongly tempted to post a message to this newsgroup in order to find
out what was going on. The last bit of reason left in my mind led me to
try Google Groups first and there was where I found a mention of "Defect
report 45" which addresses that very issue. Phew! What a relief...

Regards,

--
Ney André de Mello Zunino
Jul 23 '05 #3
"Ney André de Mello Zunino" <zu****@inf.ufs c.br> wrote...
[...] The last bit of reason left in my mind led [...]


LOL
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2045
by: Mike Sutton | last post by:
I had first tried a less active PHP group, but let me try here. I searched for this, but didn't find anything that appeared related. Possibly I didn't know what to search for. I am designing a web application using PHP, to which I am relatively new. I have seen some sites use the model whereby a single index page is created that handles authentication and receives option parameters telling the index what to load in the body of the...
5
1470
by: Murphy | last post by:
We are currently looking into the development of an application for booking resources and are researching the available options for recording and tracking these bookings. The possibilities we have presently for managing and tracking bookings are: a) Store bookings in SQL db and code the calendar functionality, showing existing bookings & availability b) Interface with Exchange c) Utilise a 3rd party product
8
1858
by: Gert Van den Eynde | last post by:
Hi all, I have a question on interface design: I have a set of objects that are interlinked in the real world: object of class A needs for example for the operator() an object of class B. On what arguments do you decide whether to pass a reference to the object of class B to the member function like this operator()(classB& objB) or to have in class A a data member (a const pointer to a class B object or so) and have this set during...
3
4153
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability. The User Experience, or how the user experiences the end product, is the key to acceptance. And that is where User Interface Design enters the design process. While product engineers focus on the technology, usability specialists focus on the user...
29
3593
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this one data field - but i'm not sure) :-) Background info:
17
2603
by: Divick | last post by:
Hi, I am designing an API and the problem that I have is more of a design issue. In my API say I have a class A and B, as shown below class A{ public: void doSomethingWithB( B * b) { //do something with b //possibly store in a list
1
1512
by: scpedicini | last post by:
Let's say that I've built an assembly, called myapi.dll whose default resource messages are english. Then let's say I create a german satellite assembly for the assembly called myapi.de.resources.dll. However, let's say that I have a german client who is using both myapi.dll and myapi.de.resources.dll; however, they would like to override a single resource string from myapi.de.resources.dll. Is it possible for them to create a "satellite...
7
1711
by: Diego F. | last post by:
Hello. I have a doubt about multi-threading, if it is or not the best way to achieve the following: I have a server application that listens a port through a socket. A client will send messages to that application (many messages). Because the amount of messages is huge, the server application should only send each received message to another process (a thread?) that manages the message, and then go with the next message. I want a...
4
1036
by: vpalexander | last post by:
I keep seeing destructor calls in wx for ad hoc dialogs and wonder if this is required, and if so, why would normal gc flow not be good? def GetDir(self,Caption,DefaultDir): dlg = wx.DirDialog(None,Caption,style = 1,defaultPath = DefaultDir,pos = (10,10)) res = dlg.ShowModal() pck = dialog.GetPath() dlg.Destroy()
0
9931
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11105
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10827
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10403
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7954
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5781
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4599
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.