Need help understanding code

c++ moderated

Need help understanding code

Postby p_mdriyaz » Wed, 01 Dec 2004 06:44:07 GMT

Hi,

Could somebody tell me what this following code means (syntax wise)

MessageIOGateway :: MessageIOGateway(int32 encoding) :
   _maxIncomingMessageSize(MUSCLE_NO_LIMIT),
   _outgoingEncoding(encoding),
   _aboutToFlattenCallback(NULL), _aboutToFlattenCallbackData(NULL),
   _flattenedCallback(NULL), _flattenedCallbackData(NULL),
   _unflattenedCallback(NULL), _unflattenedCallbackData(NULL)
#ifdef MUSCLE_ENABLE_ZLIB_ENCODING
   , _sendCodec(NULL), _recvCodec(NULL)
#endif
{
   /* empty */
}


Thank you,
Riyaz

      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Re: Need help understanding code

Postby Antoun Kanawati » Wed, 01 Dec 2004 19:56:04 GMT


 > Hi,
 >
 > Could somebody tell me what this following code means (syntax wise)
 >
 > MessageIOGateway :: MessageIOGateway(int32 encoding) :
 >    _maxIncomingMessageSize(MUSCLE_NO_LIMIT),
 >    _outgoingEncoding(encoding),
 >    _aboutToFlattenCallback(NULL), _aboutToFlattenCallbackData(NULL),
 >    _flattenedCallback(NULL), _flattenedCallbackData(NULL),
 >    _unflattenedCallback(NULL), _unflattenedCallbackData(NULL)
 > #ifdef MUSCLE_ENABLE_ZLIB_ENCODING
 >    , _sendCodec(NULL), _recvCodec(NULL)
 > #endif
 > {
 >    /* empty */
 > }

It's a constructor implementation, initializing a whole bunch of
members, and the class declaration probably has something like
the following:

#ifdef MUSCLE_ENABLE_ZLIB_ENCODING
    Foo *_sendCodec;
    Bar *_recvCodec;
#endif

-- 
A. Kanawati
 XXXX@XXXXX.COM 

      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Re: Need help understanding code

Postby Victor Bazarov » Wed, 01 Dec 2004 19:57:20 GMT

"Mohammed Riyaz" < XXXX@XXXXX.COM > wrote...
 > Could somebody tell me what this following code means (syntax wise)
 >
 > MessageIOGateway :: MessageIOGateway(int32 encoding) :
 >   _maxIncomingMessageSize(MUSCLE_NO_LIMIT),
 >   _outgoingEncoding(encoding),
 >   _aboutToFlattenCallback(NULL), _aboutToFlattenCallbackData(NULL),
 >   _flattenedCallback(NULL), _flattenedCallbackData(NULL),
 >   _unflattenedCallback(NULL), _unflattenedCallbackData(NULL)
 > #ifdef MUSCLE_ENABLE_ZLIB_ENCODING
 >   , _sendCodec(NULL), _recvCodec(NULL)
 > #endif
 > {
 >   /* empty */
 > }

Not sure which part you're finding puzzling.  Perhaps the colon and
the commas.  If so, look up "constructor initializer list" in your
favourite C++ book.

V


      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Re: Need help understanding code

Postby Joe » Wed, 01 Dec 2004 20:02:17 GMT





 > Hi,
 >
 > Could somebody tell me what this following code means (syntax wise)
 >
 > MessageIOGateway :: MessageIOGateway(int32 encoding) :
 >   _maxIncomingMessageSize(MUSCLE_NO_LIMIT),
 >   _outgoingEncoding(encoding),
 >   _aboutToFlattenCallback(NULL), _aboutToFlattenCallbackData(NULL),
 >   _flattenedCallback(NULL), _flattenedCallbackData(NULL),
 >   _unflattenedCallback(NULL), _unflattenedCallbackData(NULL)
 > #ifdef MUSCLE_ENABLE_ZLIB_ENCODING
 >   , _sendCodec(NULL), _recvCodec(NULL)
 > #endif
 > {
 >   /* empty */
 > }

This is the constructor for the class "MessagelOGateway".
The constructor takes an int32 argument "encoding"
Everything after the ":" are member initialization

Joe



      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


Re: Need help understanding code

Postby jjr2004a » Thu, 02 Dec 2004 06:57:02 GMT

> Could somebody tell me what this following code means (syntax wise)
This is just a constructor definition in a .cpp file for the
class MessageIOGateway.  What don't you understand?  There's
some uppercase items (constants? #defines?) and the #ifdef
that may be declared somewhere else, but it's still a ctor.

It's no different than this simplified class:

// X.h file
class X {
  X(int i);
  int _x, _y;
};

// x.cpp file
X::X(int i) : _x(i), _y(2)
{
}

      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


Re: Need help understanding code

Postby Julien Lamy » Thu, 02 Dec 2004 07:01:35 GMT



1. This is a constructor for the class MessageIOGateway : a "member 
function" having the same name as the class it is in is called a 
constructor.
See  http://www.**--****.com/ ++-faq-lite/ctors.html
2. All the stuff like _maxIncomingMessageSize(MUSCLE_NO_LIMIT) are 
initializations of members of the class.
See  http://www.**--****.com/ ++-faq-lite/ctors.html#faq-10.6
3. The #ifdef/#endif initializes some extra members if the symbol 
MUSCLE_ENABLE_ZLIB_ENCODING is defined.

HTH,
Julien

      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


Re: Need help understanding code

Postby Gerhard Menzl » Thu, 02 Dec 2004 07:04:34 GMT




It's the definition of a constructor of a class named MessageIOGateway 
with an extensive member initialization list and an empty body.

Which part are you having problems with?

-- 
Gerhard Menzl

#dogma int main ()

Humans may reply by replacing the obviously faked part of my e-mail 
address with "kapsch".

      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Re: Need help understanding code

Postby broeni » Thu, 02 Dec 2004 07:07:38 GMT



It is the definition of a constructor for the class MessageIOGateway,
it takes an argument how the outgoing message should be encoded.
All pointer data members are initialized with 0. 

If compression is enabled (i.e., MUSCLE_ENABLE_ZLIB_ENCODING is defined)
MessageIOGateway has additional data members for the outgoing and
incoming codec to use.

Stephan Brnimann
 XXXX@XXXXX.COM 
      Open source rating and billing engine for communication networks.

      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Similar Threads:

1.need help understanding this code snippet

 got the following code snippet that i've modified off the internet to work - 
but damn if i know how and i dont like that.  im having trouble with the 
following thread declaration that creates the thread, calls the ScanPorts 
method in the ScanPorts class and somehow passes in the array list 
scannedSystems.  i'm stumped - how does it do all that on one line?  thanks 
all.

private ArrayList scannedSystems;
scannedSystems.Add(new ScanPorts(ipAddress, port);
Thread scanThread = new Thread ( new ThreadStart 
(((ScanPorts)scannedSystems[0]).systemScan));
scanThread.Start();

public class ScanPorts
{
    private string address = "";
    private int scannedPort;

	public ScanPorts(string ipAddress, int port)
	{
		string address = ipAddress;
		int scannedPort = port;
	}
	public void systemScan()
	{
		TcpClient tcpClient = new TcpClient();
		try
		{
			tcpClient.Connect(address, scannedPort);
		} 
		catch{}
	}
}

2.Need help in understanding C++ code

Hi,

I found the following c++ code, but I need help in understand what it
is trying to do:
if the caller does this
DPRINTF(D_MINI_FS, ("CHXMiniFileSystem()\n"));

what will happen according to the following macro?


    extern void dprintf( const char *, ... )
#ifdef __GNUC__
	__attribute__((format(printf,1,2)))
#endif /* __GNUC__ */
    ;
    extern void dprintfx( const char *, ... )
#ifdef __GNUC__
	__attribute__((format(printf,1,2)))
#endif /* __GNUC__ */
    ;

#ifdef DEVEL_DEBUG
#define	DPRINTF(mask,x)	if (debug_level() & (mask))	{	\
	dprintf("%s:%d ", __FILE__, __LINE__); dprintfx x; } else
#else
#define	DPRINTF(mask,x)	if (debug_level() & (mask)) dprintf x; else
#endif /* DEVEL_DEBUG */

3.New @ programming really need a tutor and im struggling and i need some help understanding

one of my assignments is create a class named numbers whose
Main()method holds two interger variables, assign values to the
variables. within the class, create two methods, Sum() and
Difference(),that compute the sum of the difference between the values
of the two variables, respectively. each method should perform the
computation and display the results. in turn call each of the two
methods from Main(), passing the values of the two interger valuesof
the two interger variables.


then

B 

Add a method named Product() to the Numbers class. This method should
compute the multiplication product of the two intergers. but not
display the answer. instead it should return the answer to the calling
Main() program, which displays the answer.


sorry for the sloppy typing and if any help or ideas is available it
is greatly appreciated.

4.Need some help understanding abstract

I have a class that I need to adapt to various scenarios. Some 
properties and methods will be needed in every case, while other's are 
unique for one case. So I made a base class, and a set of other derived 
classes for each scenario.

But I don't understand this fully. There are not only methods in my 
original class. It has data too, in private fields.

public class OriginalClass
{
     private string field1;
     private string field2;

     // Constructor
     public OriginalClass(string field1, string field2)
     {
         this.field1 = field1;
         this.field2 = field2;
     }

     public void ProcessData()
     {
         // Using field1 and field2 here.
     }
}

Does this mean it's no use having fields in an abstract class? I wonder 
if I have to write derived classes so that each method takes all the 
data necessary as parameters? Like this:

public class BaseClass
{
     // No private fields and no constructor

     public void ProcessData(string field1, string field2)
     {
         // Using field1 and field2 here.
     }
}

public class DerivedClass
{
     private string field1;
     private string field2;

     public DerivedClass(string field1, string field2)
     {
         this.field1 = field1;
         this.field2 = field2;

         ProcessData(field1, field2);
     }
}

Gustaf

5.Need help understanding how to call unmanaged dll

I bought a USB IR reciever and installed the driver.  The developer
kit gives a DLL with the following information:
C++ Builder / Microsoft Visual C++:

  #ifdef __cplusplus
  extern "C" {
  #endif

  int __stdcall DoGetInfraCode(uchar * code, int extra, int *
codeLen);

  #ifdef __cplusplus
    }
  #endif

So in my C# project I have done this:

    public class IgorUSB
    {
        [DllImport("IgorUSB.dll")]
        public static extern int DoGetInfraCode(ref byte[] code, int
extra, ref int codeLen);
    }
Which I assume it the correct way to define the wrapper to the dll.

Next I added this to my Windows Form:

        private void Form1_Load(object sender, EventArgs e)
        {
            byte[] code = new byte[12];
            int extra = 0;
            int len = 0;
            IgorUSB.DoGetInfraCode(ref code, extra, ref len);
        }

But I get the following error when I run it:

"LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not
attempt to run managed code inside a DllMain or image initialization
function since doing so can cause the application to hang."

Does my code look correct?  The only thing I can think of is the when
this DLL is loaded it pops up a message box.  Could that be the
problem?

6. I just don't understand how enums work.....Help needed

7. Some Errors need help understanding

8. need your help in understanding COM events using ATL



Return to c++ moderated

 

Who is online

Users browsing this forum: No registered users and 72 guest