Sponsored Content
Full Discussion: c++ code
Top Forums Programming c++ code Post 302596928 by knowledgeSeeker on Wednesday 8th of February 2012 04:37:44 PM
Old 02-08-2012
c++ code

Dear All,

I know java but I am a newbie in c++ and I am trying to learn ns3 .

could anybody tell me what is going on in this two code snippets? ( these are talking from Chap 7 , ns3 tutorial)


Code:
class MyObject : public Object   {   public:     static TypeId GetTypeId (void)     {       static TypeId tid = TypeId ("MyObject")         .SetParent (Object::GetTypeId ())         .AddConstructor<MyObject> ()         .AddTraceSource ("MyInteger",                          "An integer value to trace.",                          MakeTraceSourceAccessor (&MyObject::m_myInt))         ;       return tid;     }          MyObject () {}     TracedValue<int32_t> m_myInt;   };

Code:
int   main (int argc, char *argv[])   {     Ptr<MyObject> myObject = CreateObject<MyObject> ();     myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback(&IntTrace));        myObject->m_myInt = 1234;   }

your help is HIGHLY appreciated

---------- Post updated at 11:37 PM ---------- Previous update was at 11:32 PM ----------

I will post the code snippets again here .

class MyObject : public Object
{
public:
static TypeId GetTypeId (void)
{
static TypeId tid = TypeId ("MyObject")
.SetParent (Object::GetTypeId ())
.AddConstructor<MyObject> ()
.AddTraceSource ("MyInteger",
"An integer value to trace.",
MakeTraceSourceAccessor (&MyObject::m_myInt))
;
return tid;
}
MyObject () {}
TracedValue<int32_t> m_myInt;
};

void
IntTrace (int32_t oldValue, int32_t newValue)
{
std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
}
 

6 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies

2. Programming

how i prepare a c++ code(c code) for implementing my own protocol format

helo my protocol format is given below { destno,mode,no.of packet,pktsize,,pktno,textsize,CRC} description:- { is starting flag destno - 4bytes mode - 1 byte no.of pkt - 4byes pktsize - 6 bytes ... (1 Reply)
Discussion started by: amitpansuria
1 Replies

3. Shell Programming and Scripting

translate ksh code to csh code

hi all, Can any 1 help me translate this korn shell code to C shell code : email=$(grep "^$1" $folder/config_2.txt | awk '{print $2'}) In config_2.txt the content is : which mean in korn shell , $1=groupname and $2=email address. Now i need to write in C shell script,when i set the... (2 Replies)
Discussion started by: proghack
2 Replies

4. UNIX for Dummies Questions & Answers

If ‘922’ Code does not exist on ‘03’ Record, ‘901’ Code will be there instead, move ‘03’ R

01,011600033,011600033,110516,0834,2,90,,2/ 02,011600033,011103093,1,110317,0834,,2/ 03,105581,,015,+00000416418,,,901,+00000000148,,,922,+000000 00354,,/ 03,113806,,015,+00000559618,,,901,+00000000096,,,922,+000000 00621,,/ 88,902,+0000000025218,,/... (1 Reply)
Discussion started by: sgoud
1 Replies

5. Shell Programming and Scripting

Block of code replacement in Java source code through Unix script

Hi, I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory. finally { if (null != hibernateSession && hibernateSession.isOpen()) { //hibernateSession.close(); } } It would be great if the script has... (2 Replies)
Discussion started by: hareeshram
2 Replies

6. Linux

Go to a line of code , skip few lines of code

Hi , I have a code where i am using a infinite while loop . some thing like below while do if then #go to line 20 fi command 1; command 2; #line 20: sleep 34; (5 Replies)
Discussion started by: Paarth
5 Replies
Rose::Object::MakeMethods::DateTime(3pm)		User Contributed Perl Documentation		  Rose::Object::MakeMethods::DateTime(3pm)

NAME
Rose::Object::MakeMethods::DateTime - Create methods that store DateTime objects. SYNOPSIS
package MyObject; use Rose::Object::MakeMethods::DateTime ( datetime => [ 'birthday', 'arrival' => { tz => 'UTC' } ], ); ... $obj = MyObject->new(birthday => '1/24/1984 1am'); $dt = $obj->birthday; # DateTime object $bday = $obj->birthday(format => '%B %E'); # 'January 24th' # Shortcut for $obj->birthday->clone->truncate(to => 'month'); $month = $obj->birthday(truncate => 'month'); $obj->birthday('blah'); # croaks - invalid date! $obj->birthday('1999-04-31'); # croaks - invalid date! DESCRIPTION
Rose::Object::MakeMethods::DateTime is a method maker that inherits from Rose::Object::MakeMethods. See the Rose::Object::MakeMethods documentation to learn about the interface. The method types provided by this module are described below. All methods work only with hash-based objects. METHODS TYPES
datetime Create get/set methods for scalar attributes that store DateTime objects. Options "hash_key" The key inside the hash-based object to use for the storage of this attribute. Defaults to the name of the method. "init_method" The name of the method to call when initializing the value of an undefined attribute. This option is only applicable when using the "get_set_init" interface. Defaults to the method name with the prefix "init_" added. This method should return a value that can be parsed by Rose::DateTime::Util's the parse_date() function. If the return value is a DateTime object, it will have its time zone set (see the "tz" option below) using DateTime's set_time_zone() method. "interface" Chooses one of the two possible interfaces. Defaults to "get_set". "tz" The time zone of the DateTime object to be stored. If present, this value will be passed as the second argument to Rose::DateTime::Util's the parse_date() function when creating DateTime objects for storage. If absent, DateTime objects will use the default time zone of the Rose::DateTime::Util class, which is set by Rose::DateTime::Util's time_zone() class method. See the Rose::DateTime::Util documentation for more information. Interfaces "get_set" Creates a get/set accessor method for an object attribute that stores a DateTime object. When called with a single argument, the argument is passed through Rose::DateTime::Util's parse_date() function in order to create the DateTime object that is stored. The current value of the attribute is returned. Passing a value that is not understood by Rose::DateTime::Util's parse_date() function causes a fatal error. When called with two arguments and the first argument is the string 'format', then the second argument is taken as a format specifier which is passed to Rose::DateTime::Util's format_date() function. The formatted string is returned. In other words, this: $obj->birthday(format => '%m/%d/%Y'); Is just a shortcut for this: Rose::DateTime::Util::format_date($obj->birthday, '%m/%d/%Y'); When called with two arguments and the first argument is the string 'truncate', then the second argument is taken as a truncation specifier which is passed to DateTime's truncate() method called on a clone of the existing DateTime object. The cloned, truncated DateTime object is returned. In other words, this: $obj->birthday(truncate => 'month'); Is just a shortcut for this: $obj->birthday->clone->truncate(to => 'month'); Passing more than two arguments or passing two arguments where the first argument is not 'format' or 'truncate' will cause a fatal error. "get_set_init" Behaves like the "get_set" interface unless the value of the attribute is undefined. In that case, the method specified by the "init_method" option is called, the return value is passed through Rose::DateTime::Util's parse_date() function, and the attribute is set to the return value. An init method that returns a value that is not understood by Rose::DateTime::Util's parse_date() function will cause a fatal error. Example: package MyObject; use Rose::Object::MakeMethods::DateTime ( datetime => [ 'birthday', 'arrival' => { tz => 'UTC' } ], 'datetime --get_set_init' => [ 'departure' => { tz => 'UTC' } ], ); sub init_departure { DateTime->new(month => 1, day => 10, year => 2000, time_zone => 'America/Chicago'); } ... $obj = MyObject->new(birthday => '1/24/1984 1am'); $dt = $obj->birthday; # DateTime object $bday = $obj->birthday(format => '%B %E'); # 'January 24th' # Shortcut for $obj->birthday->clone->truncate(to => 'month'); $month = $obj->birthday(truncate => 'month'); $obj->birthday('blah'); # croaks - invalid date! $obj->birthday('1999-04-31'); # croaks - invalid date! # DateTime object with time zone set to UTC $dt = $obj->arrival('2005-21-01 4pm'); # DateTime object with time zone set to UTC, not America/Chicago! # Start with 2000-01-10T00:00:00 America/Chicago, # then set_time_zone('UTC'), # which results in: 2000-01-10T06:00:00 UTC $dt = $obj->departure; print $dt; # "2000-01-10T06:00:00" AUTHOR
John C. Siracusa (siracusa@gmail.com) LICENSE
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-10-17 Rose::Object::MakeMethods::DateTime(3pm)
All times are GMT -4. The time now is 09:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy