|
I think (and I might be incorrect on this) that the poster you were originally quoting was saying that you could do the same thing using an abstract base class, one implementation per Delegate in your example. And you'd get about the same separation of concerns as well.
This sort of thing tends to be horses for courses - people who think in OO terms are likely to grab onto using interfaces for everything while people who think in compositional or functional terms will tend to reach for templates.
Cheers,
Ash
|
|
|
|
|
Aescleal wrote: This sort of thing tends to be horses for courses - people who think in OO terms are likely to grab onto using interfaces for everything while people who think in compositional or functional terms will tend to reach for templates.
It's not exactly the same, if you don't mind... With functors of that kind you get a first class object representation of a function, basically grabbing the best of both worlds. If you go the pure OO-way , you define an ISubscriber and end up with a variation of the observer pattern. Then, the components are loosely coupled (by sharing the ISubscriber definition) but they are coupled: The only way to subscribe for the Publisher service is to feed him with polymorphic ISubscriber instances.
With the approach sketched above, the Publisher is not coupled to a consumer of it's services at all - the subscriber only needs to satisfy the signature of Delegate . So the "wire up" part could look like this:
bool LooseSubscriber() {
std::out << "LooseSubscriber called" << std::endl;
return true;
}
int main() {
Publisher tPub;
Subscriber tSubs(0);
tPub.Connect
(bind(mem_fn(&Subscriber::FileMenu), tSubs));
tPub.Connect
(LooseSubscriber);
tPub.Connect
([] (void)->bool {
std::out << "lambda Subscriber called" << std::endl;
return true;
});
}
|
|
|
|
|
I didn't say it was exactly the same - you're preaching to the choir here. As I said you get almost the same separation of concerns - the difference is instead of defining an interface (which subscriber doesn't have to be derived from...) you're using a functor from the standard library.
|
|
|
|
|
Aescleal wrote: you're preaching to the choir
You've got me, I could not resist... We've probably lost the thread starter now, but I just wanted to show him/her that with a little help from the std library, pointers to member functions are easy to use.
Cheers,
Paul
|
|
|
|
|
Hi,
I am facing a problem related to window handle.
I have loaded two different OCXs in different instances of the same container application(OLE Server).
In OnCreate() method of second OCX control I am calling the AfxGetMainWnd()function.
It is called after calling the base class function of OnCreate() method.
Now trying to run both instances simultaneously.
The problem is sometimes AfxGetMainWnd()function returns the pointer to a window of first OCX control which is loaded in the first container instance just before. Why it happens?
Thankx in advance.
Regards,
SUnil
|
|
|
|
|
I have done my code to resize the controls of window when we drag the window..its working fine in normal scenario...
if we un check the option show window contents while dragging in performance settings(MyComputer->properties->advance->performance->Settings) of windows.
my window controls are not getting resized any method to over come this....thanks in advance
|
|
|
|
|
where did you place the code to resize the controls? If its is in OnSizing(), try by moving it to OnSize(). Check ::Iswindow() on any of the controls before resizing them, since OnSize will be called once before the child controls are created.
|
|
|
|
|
See if the Extras section of this article helps.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi developers, i try to write a file in binary format. But that file is not in binary format, i dont know what's wrong in my code
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file("file path", ios_base::binary | ios_base::in);
char buf[] = "BinaryFile";
file.write(buf, sizeof(buf));
file.close();
}
Thanks in Advance
|
|
|
|
|
You have posted the same question twice; you already have an answer here[^]
|
|
|
|
|
Hi developers, i try to write a file in binary format. But that file is not in binary format, i dont know what's wrong in my code
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file("file path", ios_base::binary | ios_base::in);
char buf[] = "BinaryFile";
file.write(buf, sizeof(buf));
file.close();
}
Thanks in Advance
|
|
|
|
|
ganesh_IT wrote: fstream file("file path", ios_base::binary | ios_base::in);
Shouldn't the above line be
fstream file("file path", ios_base::binary | ios_base::out);
?
ganesh_IT wrote: char buf[] = "BinaryFile"
You're writing a bunch of ASCII characters to a binary file, i.e. you're creating, by definition, a ASCII text file.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ganesh_IT wrote: using namespace std;int main(){ fstream file("file path", ios_base::binary | ios_base::in); char buf[] = "BinaryFile"; file.write(buf, sizeof(buf)); file.close();}
if file exist, it will over right it.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi!
I've to create a Menu System. I wrote a class for Initial Menu page(which contains 4 buttons) and another class for the next page(e.g when clicking the options button in the initial Menu page). I've crated an object of the second class inside the corresponding button's click event at the first class. Similarly I've created an object of the first class inside the back button's click event of the second class. I've created the device(device is necessary to display the gui elements) at each class's constructors. So my second menu page is loaded in a separate window(device). What to do to load it in the same window?
|
|
|
|
|
I don't think it's a good design to create a new instance of a menu page every time a menu button is clicked. Think what will happen if the user repeatedly clicks Options, Back, Options, Back, ...
IMO it would be better to just exit from a menu if the back button is clicked, returning to the event handler that created that page in the first place. This way you can reuse your instances, and also easily keep you state / settings.
Now a question for you: What GUI system are you using? Win32 windows / MFC / OpenGL with home made menus / etc. It's impossible to answer your question without this information.
|
|
|
|
|
I'm using Irrlicht Engine.
|
|
|
|
|
You need to be a bit more specific in your problem descriptions. Are you using a irr::gui::IGUIWindow? What did you try? Do you have a small code snippet to share, showing your problem?
PS. There is a specific irrlicht forum here[^]. They might be better at answering your questions.
|
|
|
|
|
Hi!
This is my initial Menu class.
#include <irrlicht.h>
#include "../include/InitMenu.h"
#include "../include/OptionsMenu.h"
#include <stdio.h>
#include <stdlib.h>
using namespace irr;
using namespace core;
using namespace video;
using namespace gui;
using namespace io;
using namespace scene;
class COptionsMenu;
InitEventReceiver::InitEventReceiver(SInitMenuContext &context):initMenuContext(context)
{
}
bool InitEventReceiver::OnEvent(const irr::SEvent& event)
{
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED)
{
s32 idBtn = event.GUIEvent.Caller->getID();
switch(idBtn)
{
case PLAY_BUTTON:
return true;
break;
case OPTIONS_BUTTON:
{
COptionsMenu *optMNU = new COptionsMenu();
optMNU->runGame();
initMenuContext.device->closeDevice();
return true;
break;
}
case CREDITS_BUTTON:
return true;
break;
case EXIT_BUTTON:
initMenuContext.device->closeDevice();
break;
return true;
default:
return false;
}
return true;
}
return false;
}
CInitMenu::CInitMenu()
{
IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<u32>(640,480),16,false,false,false,0);
dev = device;
int width = 180;
int height = 50;
int x = (device->getVideoDriver()->getScreenSize().Width - 200)/2;
int y = 100;
SColor WHITE = video::SColor(255,255,255,255);
SColor BLUE = video::SColor(255,0,0,255);
gui::IGUISkin* skin = device->getGUIEnvironment()->createSkin(EGUI_SKIN_TYPE::EGST_WINDOWS_METALLIC);
skin->setColor(gui::EGDC_BUTTON_TEXT,WHITE);
skin->setColor(gui::EGDC_WINDOW,BLUE);
device->getGUIEnvironment()->setSkin(skin);
device->getSceneManager()->loadScene("Data/experimentalMenuSystem/Shop.irr");
device->getSceneManager()->addCameraSceneNode(0,core::vector3df(0,100,0),core::vector3df(0,0,100),-1,true);
m_pPlayButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,PLAY_BUTTON,L"Play");
y = y+height;
m_pOptionsButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,OPTIONS_BUTTON,L"Options");
y = y+height;
m_pCreditsButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,CREDITS_BUTTON,L"Credits");
y = y+height;
m_pExitButton = device->getGUIEnvironment()->addButton(core::recti(x,y,x+width,y+height),0,EXIT_BUTTON,L"Exit");
initMnuContext.device = device;
initMnuContext.m_pPlayButton = m_pPlayButton;
initMnuContext.m_pOptionsButton = m_pOptionsButton;
initMnuContext.m_pCreditsButton = m_pCreditsButton;
initMnuContext.m_pExitButton = m_pExitButton;
}
int main(int argc, char **argv)
{
CInitMenu* cIMNU = new CInitMenu();
cIMNU->runGame();
}
void CInitMenu::runGame()
{
InitEventReceiver initReceiver(initMnuContext);
dev->setEventReceiver(&initReceiver);
while(dev->run())
{
if (dev->isWindowActive())
{
dev->getVideoDriver()->beginScene(true, true, video::SColor(0,200,200,200));
dev->getSceneManager()->drawAll();
dev->getGUIEnvironment()->drawAll();
dev->getVideoDriver()->endScene();
}
}
dev->drop();
}
This is Options Menu class:
#include <irrlicht.h>
#include "../include/OptionsMenu.h"
#include "../include/InitMenu.h"
using namespace irr;
using namespace core;
using namespace video;
using namespace gui;
using namespace io;
using namespace scene;
OptionsEventReceiver::OptionsEventReceiver(SOptionsContext &optionsContext):OptionsContext(optionsContext)
{
}
bool OptionsEventReceiver::OnEvent(const irr::SEvent& event)
{
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED)
{
s32 idBtn = event.GUIEvent.Caller->getID();
printf("Button Clicked: %d \n",idBtn);
switch(idBtn)
{
case PROFILE_BUTTON:
return true;
break;
case FAVOURITES_BUTTON:
return true;
break;
case MATCH_RESULT_BUTTON:
return true;
break;
case OPTIONS_BACK_BUTTON:
{
CInitMenu *cInitMNU = new CInitMenu();
cInitMNU->runGame();
OptionsContext.device->closeDevice();
return true;
break;
}
default:
return false;
}
return false;
}
}
COptionsMenu::COptionsMenu()
{
IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<u32>(640,480),16,false,false,false,0);
dev = device;
int width = 180;
int height = 50;
int x = (device->getVideoDriver()->getScreenSize().Width - 200)/2;
int y = 100;
SColor WHITE = video::SColor(255,255,255,255);
SColor BLUE = video::SColor(255,0,0,255);
gui::IGUISkin* skin = device->getGUIEnvironment()->createSkin(EGUI_SKIN_TYPE::EGST_WINDOWS_METALLIC);
skin->setColor(gui::EGDC_BUTTON_TEXT,WHITE);
skin->setColor(gui::EGDC_WINDOW,BLUE);
device->getGUIEnvironment()->setSkin(skin);
device->getSceneManager()->loadScene("Data/experimentalMenuSystem/Shop.irr");
device->getSceneManager()->addCameraSceneNode(0,core::vector3df(0,100,0),core::vector3df(0,0,100),-1,true);
m_pPlayerProfileButton = device->getGUIEnvironment()->addButton(recti(x,y,x+width,y+height),0,PROFILE_BUTTON,L"Player Profile");
y = y+height;
m_pFavouritesButton = device->getGUIEnvironment()->addButton(recti(x,y,x+width,y+height),0,FAVOURITES_BUTTON,L"Favorites");
y = y+height;
m_pMatchResultButton = device->getGUIEnvironment()->addButton(recti(x,y,x+width,y+height),0,MATCH_RESULT_BUTTON,L"Match Result");
m_pOptionsBackButton = device->getGUIEnvironment()->addButton(recti(0,400,192,458),0,OPTIONS_BACK_BUTTON,L"Back");
optionsContext.device = device;
optionsContext.m_pPlayerProfileButton = m_pPlayerProfileButton;
optionsContext.m_pFavouritesButton = m_pFavouritesButton;
optionsContext.m_pMatchResultButton = m_pMatchResultButton;
optionsContext.m_pOptionsBackButton = m_pOptionsBackButton;
}
void COptionsMenu::runGame()
{
OptionsEventReceiver optReceiver(optionsContext);
dev->setEventReceiver(&optReceiver);
while(dev->run())
{
if (dev->isWindowActive())
{
dev->getVideoDriver()->beginScene(true, true, video::SColor(0,200,200,200));
dev->getSceneManager()->drawAll();
dev->getGUIEnvironment()->drawAll();
dev->getVideoDriver()->endScene();
}
}
dev->drop();
}
|
|
|
|
|
There are some basic issues with your code.
case EXIT_BUTTON:
initMenuContext.device->closeDevice();
break;
return true;
You don't need both break and return. Especially not in this order. You are only making it harder for yourself to follow the program flow.
This
SColor WHITE = video::SColor(255,255,255,255); is the same as
SColor WHITE(255,255,255,255); Don't type more than you have to to keep readability.
This
CInitMenu* cIMNU = new CInitMenu();
cIMNU->runGame();
will leak memory and should be written something like
CInitMenu().runGame();
even though I think having the main menu as the object root of your app is a bit skewed.
Now, why do you want the new menu appear in the same window? It looks like the GUI system is designed for having child dialogs. An alternative could be to use their tab control.
If you still need to open the menu in the same window, I see no other alternative than to remove (or hide) the original controls, and insert your new ones. But don't take my word for it. I have only seen the GUI classes for about 5 minutes. Ask for a solution in the other forum I gave a link to.
|
|
|
|
|
Ok. Can you help me to write the above classes using singleton? Instead of creating a device at each class's constructor, I've to create only one device and use it for any gui classes in my menu implementation. Is this the correct way to solve my problem?
|
|
|
|
|
T.RATHA KRISHNAN wrote: Can you help me to write the above classes using singleton? No.
If you want access to the device through a singleton class, you can read how it's done
right here[^] Since you don't need a thread safe singleton, it's one of the easiest patterns to implement.
If its the correct way or not, I have no idea. One idea is that you ask in the irrlicht forum I think I gave you a link to.
|
|
|
|
|
hello guys...im VERY new to this. I have a button on the form inwhich im calling the basic lineInitializeEx function...but the code is not compiling and showing two error
1) unresolved external symbol_lineInitializeExA referenced in function ....
2) unresolved externals
Here is the code im using..
HLINEAPP lineApp;
HANDLE TapiEvent;
HLINE hLine;
HCALL hCall;
LINEINITIALIZEEXPARAMS LineInitializeExParams;
LONG result;
DWORD tapiVersion;
DWORD numDevs;
tapiVersion = 0x00020000;
EventReply = CreateEvent(NULL,FALSE,FALSE,NULL);
memset(&LineInitializeExParams,0,sizeof(LINEINITIALIZEEXPARAMS));
LineInitializeExParams.dwTotalSize = sizeof(LINEINITIALIZEEXPARAMS);
LineInitializeExParams.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
result = lineInitializeEx(&lineApp,NULL,NULL,"CallTest",&numDevs,&tapiVersion,&LineInitializeExParams);
if (result!=0) {
MessageBox("somtehing went wrong");
}
what can be the problem thanx for ur thoughts
|
|
|
|
|
This is a linker error. It lets you know that the function lineInitializeEx is not defined. Its implementation is missing. In this case you have forgotten to link against the tapi32.lib.
|
|
|
|
|
|
As Niklas Lindquist said you need to link against the tapi library.
You can do the following -
Add #pragma comment(lib, "tapi32") in stdafx.h or any other file.
OR
Add tapi32.lib in Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies .
|
|
|
|
|