what is going on in this function?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2005
Posts: 61
Reputation: johnray31 is an unknown quantity at this point 
Solved Threads: 0
johnray31 johnray31 is offline Offline
Junior Poster in Training

what is going on in this function?

 
0
  #1
Jan 7th, 2009
Hi guys ,
i am very new to this language so can you tell me which style below function is showing in C++.

  1. SmeConfigRnc::SmeConfigRnc(uint32_t rncId, uint16_t pc) : m_RncId(rncId), m_Pc(pc)
  2. {
  3. //Allocate userId
  4. m_UserId = SmeConfigMgr::GetInstance()->GetFromFreeUserIdPool();
  5. printf("Allocated for RNC, User Id=%d\n", m_UserId);
  6. //Allocate mtpSap
  7. m_MtpSapId = SmeConfigMgr::GetInstance()->GetFromFreeMtpSapIdPool();
  8. printf("Allocated for RNC, MTP SAP=%d\n", m_MtpSapId);
  9. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 302
Reputation: JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough 
Solved Threads: 52
JasonHippy's Avatar
JasonHippy JasonHippy is offline Offline
Posting Whiz

Re: what is going on in this function?

 
3
  #2
Jan 7th, 2009
I'm not sure exactly what you're asking when you say
"can you tell me which style below function is showing in C++"

But I can answer the question in the topic title
"what is going on in this function?"

  1. SmeConfigRnc::SmeConfigRnc(uint32_t rncId, uint16_t pc) : m_RncId(rncId), m_Pc(pc)
  2. {
  3. //Allocate userId
  4. m_UserId = SmeConfigMgr::GetInstance()->GetFromFreeUserIdPool();
  5. printf("Allocated for RNC, User Id=%d\n", m_UserId);
  6. //Allocate mtpSap
  7. m_MtpSapId = SmeConfigMgr::GetInstance()->GetFromFreeMtpSapIdPool();
  8. printf("Allocated for RNC, MTP SAP=%d\n", m_MtpSapId);
  9. }

This line:
  1. SmeConfigRnc::SmeConfigRnc(uint32_t rncId, uint16_t pc) : m_RncId(rncId), m_Pc(pc)
Is the constructor for a class called SmeConfigRnc.
The two parameters (rncId and pc) look as though they are user defined types (uint32_t and uint16_t) which are probably defined elsewhere using typedef statements.. (Otherwise they could be primitive types specific to the compiler being used to compile the program!)
Either way it looks as if they are a 32 bit unsigned integer and a 16 bit unsigned integer.

In the part of the constructor code which says:
  1. : m_RncId(rncId), m_Pc(pc)
Two member variables ( m_RncId and m_Pc) are assigned the values passed into the constructor (i.e. the values of rncId and pc respectively)

The first line in the constructors body (after the comment):
  1. m_UserId = SmeConfigMgr::GetInstance()->GetFromFreeUserIdPool();
This line is doing quite a lot.
SmeConfigMgr looks like it's probably a singleton (a class which can only have one instance in memory), the GetInstance() function will be a static member function of the SmeConfigMgr class which will return a pointer to the current instance of the SmeConfigMgr class.

Basically this line gets a pointer to the SmeConfigMgr class and then calls the GetFromFreeUserIdPool() method of SmeConfigMgr (which I assume returns some kind of int). m_UserId is then assigned the value returned by the call to SmeConfigMgr::GetFromFreeUserIdPool()

The printf statement (which is poor practice to use in a c++ app, std::cout should really be used!) prints a message to the console and shows the value of m_UserId.

Similarly:
  1. m_MtpSapId = SmeConfigMgr::GetInstance()->GetFromFreeMtpSapIdPool();
  2. printf("Allocated for RNC, MTP SAP=%d\n", m_MtpSapId);

This time a pointer to the current instance of SmeConfigMgr is obtained using a call to SmeConfigMgr::GetInstance() and then the GetFromFreeMtpSapIdPool() method of SmeConfigMgr is called.
m_MtpSapId is assigned the value returned by the call to GetFromFreeMtpSapIdPool()

Finally a printf is used to print a message and the value of m_MtpSapId to the console.

I hope that is of some help!

Cheers for now,
Jason.
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC