home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Function calls whenever an object is accessed. . .

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1635
Discussions: 200,951, Posts: 2,379,471, Members: 246,313
Old January 9th, 2006, 03:24 PM   Digg it!   #1 (permalink)
Member
 
Join Date: Sep 2004
Location: Your living room...
Posts: 417
Function calls whenever an object is accessed. . .

Is anyone familiar with any language that provides a function call similar to a constructor, but that get called EVERY time the object is accessed; not just on initialization? I mean, I know I could simply manually add a specific function call to every function, but I am hoping for some existing implementation that has something available already.
__________________
I reserve the right to contradict myself. . .
gberz3 is offline   Reply With Quote
Old January 11th, 2006, 12:45 PM     #2 (permalink)
Banned
 
Iturea's Avatar
 
Join Date: Jan 2004
Location: Earth
Posts: 420
I have never heard of anything like that before, but if you had one main function that called the other functions in the object then since every call had to go through main first you could add the function you wanted called everytime there...
Iturea is offline   Reply With Quote
Old January 11th, 2006, 12:56 PM     #3 (permalink)
Member
 
Join Date: Sep 2004
Location: Your living room...
Posts: 417
need "self-aware"objects. . .

Well, I understand that I can create a function, then manually have every other function call that one before it itself executes, but that isn't what I'm looking for. I need self-aware objects that can call a specific function every single time the object itself is accessed. Sort of like an __init__ during object initialization, except this one is called EVERY time the object is accessed; not just during creation.
gberz3 is offline   Reply With Quote
Old January 11th, 2006, 01:58 PM     #4 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,241
Send a message via AIM to Rootstonian
That's kind of confusing, at least to me...

Class Points {

private:
int x, y, r, l, w, h;

public:
Points::Points{ (x = 0, y = 0, r = 0, l = 0, w = 0, h = 0) }
Points::draw_circle(int x, int y, int r) {}
Points::draw_square(int x, int y) {}
};

void main(void) {

int x = 4, y =5, r = 2;

Points my_points; // Constructor called here

my_points.draw_circle(x, y, r); // WHAT DO YOU WANT CALLED???

}
Rootstonian is offline   Reply With Quote
Old January 11th, 2006, 02:08 PM     #5 (permalink)
Member
 
Join Date: Sep 2004
Location: Your living room...
Posts: 417
Quote:
Originally Posted by Rootstonian
That's kind of confusing, at least to me...

I want:

Code:
Class Points {

private:
int x, y, r, l, w, h;
void alwayscalledwhenaccessed;


public:
Points::Points{ (x = 0, y = 0, r = 0, l = 0, w = 0, h = 0) }
Points::draw_circle(int x, int y, int r) {}
Points::draw_square(int x, int y) {}
};

void main(void) {

int x = 4, y =5, r = 2;

Points my_points; // Constructor called here

my_points.draw_circle(x, y, r); //I want alwayscalledwhenaccessed called here 
my_points.draw_square(x,y); //and here. . .

}
. . .just as the powers that be *know* to call the contructor (although the call stack would obviously be different) I want it to simply *know* to call the allwayscallwhenaccessed method. I'm curious as to whether any languages offer this.
gberz3 is offline   Reply With Quote
Old January 11th, 2006, 02:24 PM     #6 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,241
Send a message via AIM to Rootstonian
Wow, that's a trip!

I'm a bit rusty on this, but how is the Points Constructor called? I imagine it's done behind the scenes at the instantiation, but still a "manual" process (someone coded *something* there).

I just don't see it, unless you do as you DON'T want to have:
"this->alwayscalledwhenaccessed();" in each method...sorry dude...my brain is toast at this point of the programming work day
Rootstonian is offline   Reply With Quote
Old January 11th, 2006, 02:31 PM     #7 (permalink)
Member
 
Join Date: Sep 2004
Location: Your living room...
Posts: 417
Quote:
Originally Posted by Rootstonian
Wow, that's a trip!

I'm a bit rusty on this, but how is the Points Constructor called? I imagine it's done behind the scenes at the instantiation, but still a "manual" process (someone coded *something* there).

. . .


Right, I'm sure it is *coded* in there somewhere. But that's exactly what I'm asking: If they *coded* the ability to call a contructor/destructor, it certainly seems possible to have coded an intermediary of sorts that gets called in process whenever the object is accessed. Whether anyone has actually done this or not is my concern. It would really be nice if something existed already.
gberz3 is offline   Reply With Quote
Old January 11th, 2006, 02:37 PM     #8 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,552
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
How and when a constructor is called depends on the language. Some call it for you (Java) others require a call to the constructor in the code. In java it goes "Oh you declared a variable, certainly you want the constructor" and it does it for you.
C++ on the other hand makes no such assumption and you have to call the constructor yourself or you will simply have garbage data and unitialized variables. IIRC this is all done in the compiler.

As far as getting this done though, the only chance you have of actually accomplishing this would be to try and register an event for accessing. It would be better just to call the function from each member function. There is no language to my knowledge with "Aware" objects. You would need to code this awareness into an object.

Jkrohn
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.
jkrohn is offline   Reply With Quote
Old January 11th, 2006, 02:47 PM     #9 (permalink)
Member
 
Join Date: Sep 2004
Location: Your living room...
Posts: 417
Quote:
Originally Posted by jkrohn
How and when a constructor is called depends on the language.
. . .
As far as getting this done though, the only chance you have of actually accomplishing this would be to try and register an event for accessing. It would be better just to call the function from each member function. There is no language to my knowledge with "Aware" objects. You would need to code this awareness into an object.
Jkrohn

Yeah, I'm aware that different languages handle it differently. I was just hoping for one that, like Java, assumed responsibility and triggered certain methods (similar to constructors/destructors) on the fly.

I was just discussing it with someone in the office, and they recommended "aspect-oriented" programming; specifically AspectJ. I'll check into it and see if that is of any use.

Thanks for the input so far!
gberz3 is offline   Reply With Quote
Old January 12th, 2006, 11:42 AM     #10 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,241
Send a message via AIM to Rootstonian
In thinking some more about this, it really sounds like what Windows programming does. It is message based; mouse clicks, keyboard hits etc. are are put into a message queue and processed. In this environment, your INIT routine could be called on every mouse click, or mouse move or key click or windows min/maximize or every clock tick for that matter (last I knew, that was 18.2 times per second )
Rootstonian is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Toshiba laptop function keys won't function sparkle Technical Support 2 September 25th, 2004 04:20 PM
Recently Accessed Documents DanGrease Applications and Operating Systems 2 March 26th, 2004 09:46 AM
Finding out what a file is being accessed by? Linkin' Park Applications and Operating Systems 2 November 11th, 2002 12:02 AM
Passing a class object variable to another object variable ILC Webmastering and Programming 1 March 1st, 2002 02:10 AM
C++ Function Calls vorte[x] Webmastering and Programming 34 January 15th, 2002 03:08 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
The disrespect of Obama by Russian .. (39)
Is It Just Me? (2942)
Making Health Care Worse (178)
Wireless Televisions. (12)
CPU fan stops spinning randomly (8)
windows 7 problem (7)
Regular Build (11)
Is the PSU I received dead? (12)
radeon x850xt platinum & shader.. (6)
Print spooler problem (15)
windows vista security holes (10)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Dept. of HS: NSA 'Helped' Develop V.. (16)
Recent Discussions
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Modern Warfare 2: Who Bought It? (63)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Laptop with wireless problem. (3)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
windows vista security holes (10)
Point and Shoot Camera Suggestions. (4)
Multiple Restarts Required at Boot (2)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Hp Artist Edition + Matching Bag (0)
Asus P4G8X Mobo (6)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)


All times are GMT -4. The time now is 01:32 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28