Main BLOGGER
Google
WWW THIS BLOG
Sunday, February 27, 2005
 
C++ implicit/explicit constructor
The Explicit Keyword
A constructor taking a single argument is by default an implicit conversion operator:
class C {
int I;
//...
public:
C(int i);//constructor and implicit conversion operator
//as well
};


void f() {
C c(0);
c = 5; //implicit conversion of 5 to a C object and
//then assignment
}

The compiler re-edits the above sample as if the programmer had written:
//////////////////////////////////////////////////////////////////////////////////////////
//"c=5;" transformed by the compiler into something like this:
/////////////////////////////////////////////////////////////////////////////////////////
C temp(5);//temporary object instantiated,
c = temp; //assigned using operator =
temp.C::~C(); //temp's destructor activated

In many cases, this conversion is intentional and well-behaved. But there are cases where such automatic conversion is undesirable, like the following:
class String {
int size;
char *p;
//..
public:
String (int sz); //constructor & implicit conversion
//operator; undesirable in this case
};
void f ()
{
String s(10);
//the following is a programmer's typo; yet it is not
//detected since it has an unexpected interpretation:
s = 100; //bad; 100 is converted to a String and then
//assigned to s.
}


In order to avoid such implicit conversions, a constructor taking one argument should be declared as explicit:
class String {
int size;
char *p;
//..
public:
//no implicit conversion
explicit String (int sz); //no implicit conversion
String (const char *s, int size n = 0); //implicit conv.
};
void f ()
{
String s(10);
s = 100; //now compile time error; explicit conversion
//required now:
s = String(100); //fine; explicit conversion
s = "st";//fine; implicit conversion allowed in this case
}


Written by Danny Kalev
http://www.devx.com/tips/Tip/12493

Saturday, February 26, 2005
 
Grid/P2P .com's and Commercial Companies
Avaki
Axceleon
Base One International
CapCal
Centrata
Cogiture
DataSynapse
Distributed Science
Elepar
Entropia.com
Grid Frastructure
GridSystems
GreenTea Tech
Groove Networks
IBM
Intel
Jivalti
Mithral
Mind Electric
Mojo Nation
Mesh Technologies
NewsToYou.com
NICE, Italy
Noemix, Inc.
Oracle
Parabon
Platform Computing
Popular Power
Powerllel
ProcessTree
Sharman Networks Kazza
Sun Gridware
Sysnet Solutions
Tsunami Research
Ubero
United Devices
Veritas
Xcomp

Tuesday, February 22, 2005
 
C++ reflection Day Two
1. set up things in ~/ken/C++Reflection directory
2. gccxml is installed in ~/usr/bin and runs successfully
3. generated the shared library for reflection successfully
in --/reflection/src/xct/reflection
$CC -o ArrayType.o -c ArrayType.cpp -I../..
$CC -o ClassType.o -c ClassType.cpp -I../..
$CC -o FundamentalType.o -c FundamentalType.cpp -I../..
$CC -o PointerType.o -c PointerType.cpp -I../..
$CC -o PtrHolder.o -c PtrHolder.cpp -I../..
$CC -o Type.o -c Type.cpp -I../..
$CC -o check.o -c check.cpp -I../..
$CC -shared -W1,-soname,libfoo.so -o libfoo.so ArrayType.o ClassType.o FundamentalType.o PointerType.o PtrHolder.o Type.o check.o
4. generated testing program successfully
in --/reflection/src/tests
$CC -o A_reflection.o -c A_reflection.cpp -I..
$CC -o B_reflection.o -c B_reflection.cpp -I..
$CC -o C_reflection.o -c C_reflection.cpp -I..
$CC -o B.o -c B.cpp -I..
$CC main.cpp -I.. -L../xct/reflection -lfoo A_reflection.o B_reflection.o C_reflection.o B.o
5. testing ok
mustang:~/ken/C++Reflection/reflection/src/tests> ./a.out
A::name: A
B::name: B
123987
98777
name: 1B
type name: 1B
B
type name: 1B
B
array class name: Pf, Pf

 
Expression template material
The C++ Expression Template material mostly came from:

http://osl.iu.edu/~tveldhui/papers/Template-Metaprograms/meta-art.html
http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html

Todd was actually a cubicle-mate for a period of time.

Monday, February 21, 2005
 
C++ reflection day one
1. installed cmake-2.0.5
2. installed gccxml-0.6.0
3. installed xerces-c-src_2_6_0
4. modified the Makefile and Makefile.incl in directory code_generator
- compiled Ok
- created CodeGenerator Ok
- in .cshrc added "setenv XERCESCROOT /home/pliu/xerces-c-src_2_6_0"
- copied "libXerces-c.so ..." to "/home/pliu/usr/lib",
indicated by "setenv LD_LIBRARY_PATH /home/pliu/usr/lib" in .cshrc
5. generated shared library for /src/xct/reflection
- using command line "$CC -shared -o libfoo.so *.cpp -I../.."

Sunday, February 20, 2005
 
A tutorial for smart pointer and operator overload


#include <iostream>
using namespace std;
class sp1
{
public:
int data;
sp1* operator ->() { return this;};
//overload "->" operator "." can not be overloaded
};


//a data object that can be reference to a user data object, and count the references
//to it, and increment and decrement the reference counter.
// this class is used internally by smart pointer class CPtr
template<typename T>
class CDataPacket
{
private:
int RefNum;
public:
T* pData;
CDataPacket();
~CDataPacket();
void DecRef();
void IncRef();
};

template<typename T>
void CDataPacket<T>::DecRef()
{
if (RefNum == 0) return;

RefNum--;
if (RefNum == 0)
delete this;
}

template<typename T>
void CDataPacket<T>::IncRef()
{
RefNum++;
}

template<typename T>
CDataPacket<T>::CDataPacket()
{
pData = NULL;
RefNum = 0;
}

template<typename T>
CDataPacket<T>::~CDataPacket()
{
delete pData;
}

//////////////////smart pointer////////////
template<typename T>
class CPtr
{
private:
CDataPacket<T> * Refs;
public:
~CPtr();
CPtr();
T* operator->();
T & operator*();
operator T*();
CPtr<T>& operator = ( T* p);
CPtr<T>& operator = ( CPtr<T>& p);
};


// scenario
// T* p = new <T>
// CPtr p_self = p;
//processing
// decrease the reference number on the DataPacket Refs if it exists
// if the reference number of Refs becomes zero, it will be garbage-collected
// create a new DataPacket with the value p
// increate the reference number on the new DataPacket
template<typename T>
CPtr<T>& CPtr<T>::operator= ( T* p)
{
cout<< "overload CPtr<T>& CPtr<T>::operator= ( T* p)" <<endl;
if (Refs) Refs->DecRef();
Refs = new CDataPacket<T>
Refs->pData = p;
Refs->IncRef();
return *this;
}

//scenario
// CPtr<T> p_self;
// CPtr<T> p;
// p_self = p;
//processing: the same as above
template<typename T>
CPtr<T>& CPtr<T>::operator= ( CPtr<T>& p)
{
cout<< "overload CPtr<T>& CPtr<T>::operator= ( CPtr<T>& p) " <<endl;
if ( Refs)
Refs->DecRef();
Refs = p.Refs;
Refs->IncRef();
return *this;
}

//scenario
// CPtr<T> p_self = new <T>
// delete p_self;
//processing: the same as above

template<typename T>
CPtr<T>::~CPtr()
{
Refs->DecRef();
}

//scenario
// CPtr<T> p_self = new <T>
//processing
// no DataPacket is assigned, so set it to NULL
template<typename T>
CPtr<T>::CPtr()
{
Refs = NULL;
}

//scenario
// CPtr<T> p_self = new <T>
// p_self->XXX
//processing
// return the pointer to actural data
template<typename T>
T* CPtr<T>::operator ->()
{
cout<< "overload T* CPtr<T>::operator ->()" <<endl;
return Refs->pData;
}

//scenario
// CPtr<T> p_self = new <T>
// (*p_self).XXX
//processing
// return the actural data
template<typename T>
T& CPtr<T>::operator *()
{
cout<< "overload T& CPtr<T>::operator *()" <<endl;
return *(Refs->pData);
}

// CPtr<T> p_self = new <T>
// p_self[0] = <T> a;
//processing
// return the pointer to actural data

template<typename T>
CPtr<T>::operator T*()
{
cout<< "overload CPtr<T>::operator T*()" <<endl;
return Refs->pData;

}

/////////////Testing Class///////////////
class test
{
private:
int data;

public:
test(int i){ data = i;};
~test(){ cout << " class #"<<data<<" destroyed."<< endl; };
void DoSomeThing(){ cout << " class #"<<data<<" doing something."<< endl; };
};

int main()
{
//test 1: sp1 overload ->
sp1 t;
cout << "input a number" <<endl;
cin >> t.data;
cout << t->data <<endl;

//test2: CPtr overload
CPtr<int> pii;
pii = new int[10]; //overload CPtr<T>& CPtr<T>::operator= ( T* p)
pii[0]=0; //overload CPtr<T>::operator T*()
pii[2]=10; //overload CPtr<T>::operator T*()
cout << pii[0] << endl; //overload CPtr<T>::operator T*()
cout << pii[2] << endl; //overload CPtr<T>::operator T*()

//test3: test class
CPtr<test> ts0,ts1,ts2;

ts0 = new test(0); // overload CPtr<T>& CPtr<T>::operator= ( T* p)
ts1 = new test(1); // overload CPtr<T>& CPtr<T>::operator= ( T* p)
ts2 = new test(2); // overload CPtr<T>& CPtr<T>::operator= ( T* p)

ts0->DoSomeThing(); // class #0 doing something. overload T* CPtr<T>::operator ->()
ts1->DoSomeThing(); // class #1 doing something.
ts2->DoSomeThing(); // class #2 doing something.

///////// ts0--->test(0)
///////// ts1--->test(1)
///////// ts2--->test(2)

ts0 = ts1; // class #0 destroyed.
///////// ts0--->test(1)
///////// ts1--->test(1)
///////// ts2--->test(2)
// test(0) is garbage-collected

ts1 = ts2; // overload CPtr<T>& CPtr<T>::operator= ( CPtr<T>& p)
///////// ts0--->test(1)
///////// ts1--->test(2)
///////// ts2--->test(2)

ts0->DoSomeThing(); // class #1 doing something.
ts1->DoSomeThing(); // class #2 doing something.
ts2->DoSomeThing(); // class #2 doing something.

ts1 = ts0;
///////// ts0--->test(1)
///////// ts1--->test(1)
///////// ts2--->test(2)
ts0->DoSomeThing(); //class #1 doing something.
ts1->DoSomeThing(); // class #1 doing something.
ts2->DoSomeThing(); // class #2 doing something.

(*ts0).DoSomeThing(); // class #1 doing something. overload T& CPtr<T>::operator *()
} // class #2 destroyed.class #1 destroyed.


 
A good C++ chinese BLOG
C++的罗浮宫 技术往往隐藏在细节之中
http://blog.csdn.net/pongba/category/37521.aspx

Wednesday, February 16, 2005
 
count the total number of lines of all *.cs files in the current directory and subdirectory
http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm

find -name '*.cs' -exec cat '{}' \; wc -l

Saturday, February 12, 2005
 
[7] Harrison C.G., Chess D.M., Kershenbaum, A., “Mobile Agents: Are They a Good Idea?”, Research Report, IBM Research, 1995.

[8] D. Lange, M. Oshima, G. Karjoth, and K. Kosaka, “Aglets: Programming Mobile Agents in Java,” In Proc. Worldwide Computing and its Applications (WWCA 97), Lecture Notes in Computer Science, Vol. 1274, 1997.

[9] D. Kotz, R. Gray, and D. Rus, “Future Directions for Mobile-Agent Research,” IEEE Distributed Systems Online, 3(8), Aug. 2002.

[10] R. Gray, G. Cybenko, et al., “D’Agents: Applications and Performance of a Mobile-Agent System,” Software - Practice and Experience, 32(6):543¨C573, May 2002.

[11] J. W. Stamos and D. K. Gifford. “Remote Evaluation,” ACM Trans. Programming Languages and Systems, 12(4):537¨C565, March 1990.

[12] Zakaria Maamar, Quan Z. Sheng, and Boualem Benatallah. “Interleaving web services composition and execution using software agents and delegation.” In AAMAS2003 Workshop on Web Services and Agent-based Engineering, 2003.

[13] Amir Padovitz, Shonali Krishnaswamy, Seng Wai Loke, “Toward Efficient and Smart Selection of Web Service.” In AAMAS2003 Workshop on Web Services and Agent-based Engineering, 2003.

[14] F. Ishikawa, N. Yoshioka, Y. Tahara, and S. Honiden, “Towards Synthesis of Web Services and Mobile Agents.” In AAMAS2004 Workshop on Web Services and Agent-based Engineering, 2004.

[15] Z. Maamar, Q.Z. Sheng, and B. Benatallah, "On Composite Web Services Provisioning in an Environment of Fixed and Mobile Computing Resourcesrticle", Information Technology and Managemenl, Kluwar Academic, 2004, pp 251-270. Vol 5, No 3-4

[16] Microsoft, ECMA and ISO/IEC C# and Common Language Infrastructure Standards, http://msdn.microsoft.com/net/ecma/

[17] “Tool Interface Standards. ELF: Executable and Linkable Format.” ftp://ftp.intel.com/pub/tis, 1998.


[18] Sun Microsystems, “The Java Language Specification,” http:/java.sun.com

[19] Specification: Business Process Execution Language for Web Services Version 1.1,
http://www-128.ibm.com/developerworks/library/ws-bpel/

Friday, February 11, 2005
 
Overview of XML Processing in .NET XML Web Services
- The central class is the XmlSerializer class, and its most importantmethods are the Serialize() and Deserialize() methods.

- All the XmlSerializer constructors expect to receive someinformation about the types of objects they are going to serialize or de-serialize. Most of them require passing in a type object directly.

- Once an instance of XmlSerializer class is created, it will generateand compile code on the fly to do serialization and de-serialization. The generated code is able to statically bind XML stream to target types.

- The on-the-fly code generation and compilation are computingintense. This leads to the "first invocation is slow" issue. But there will be no reflection overhead at serialize-/de-serialize-time.

- The generated de-serialization code in Deserialize() method is astream based pull parser. This parser checks the XML stream for content to instantiate the target type. If no matching type mapping is found it will throw an exception. In the parsing process, the XmlReader class provides forward-only, read-only access to a stream of XML data.

- In .NET, types can be annotated by attributes. The attributes arestored as the metadata in the Assembly. Attributes are used to control the XML stream generated by the XmlSerializer class, allowing you to set the XML namespace, element name, attribute name, and so on, of the XML stream.

- Given an XML Schema, you can run the XML Schema Definition tool toproduce a set of classes that are strongly typed to the schema and annotated with attributes.

References

1. A Comparison of XML Processing in .NET and J2EE http://www.idealliance.org/papers/dx_xml03/papers/06-01-03/06-01-03.html#s4.2

2. Introducing to XML Serialization in .NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconintroducingxmlserialization.asp

3. The XmlSerializer reference
http://www.topxml.com/xmlserializer/xmlserializer.asp

Thursday, February 10, 2005
 
Improve XML Web Services' Performance by Compressing SOAP
http://www.dotnetjunkies.com/Article/46630AE2-1C79-4D5F-827E-6C2857FF1D23.dcik

Debug into the XmlSerializer Generated code
http://www.hanselman.com/blog/CommentView,guid,4185d5c5-17ab-4ed6-b934-e244b9895b4c.aspx

 
How does .NET parse XML in serialization/de-serialization

Serialization/Deserialization in .NET

http://www.prescod.net/rest/dotnet/

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpovrSerializingObjects.asp

http://www.developer.com/net/csharp/article.php/3110371

-Question-

How does XmlSerializer work?

-Anwser-

http://www.topxml.com/xmlserializer/xmlserializer.asp


-Question-
The first method invocation on my web service is slow. I found the knowledgebasearticle

http://support.microsoft.com/default.aspx?scid=kb;en-us;323577

Using Ngen.exe didn't speed things up.Anyone know if there is a fix or workaround for this? Perhaps something thatcan be tuned in .NET or IIS?

-Anwser-
XmlSerializer generates and compiles code on the fly to do serializationand deserialization. This process is a big perf win for multipleserializations - the generated code is able to statically bind to targettypes so it doesn't have to use any reflection atserialize-/deserialize-time. I say multiple serializations because thereis an upfront cost to generate the serializer which must be amortized overmultiple serializations (so it makes most sense for long running apps suchas server-side web services).We addressed the "first invocation is slow" issue in Whidbey: we added afeature allowing to pre-generate the serialization assembly for the givencompiled client.Also a port to Everett was initiated (CDCR #1707) and the feature should beavailable soon.To obtain the client-side performance CDCR #1707 you have work with our PSS.

Thanks,Elena

-Question-
How to get the class source file generated on the fly by XmlSerializer ?

-Anwser-
http://msdn.microsoft.com/xml/default.aspx?pull=/library/en-us/dnxmlnet/html/trblshtxsd.asp

Troubleshooting Common Problems with the XmlSerializer
Summary: Christoph Schittko discusses various techniques for diagnosing common problems that occur when converting XML to objects and vice versa with XML Serialization technology in the .NET Framework. (13 printed pages)


-Question-
How to create custom xml serializers

-Anwser-
You can take the generated code, modify it to your pleasure, and add it to your application. And then your application can create an instance of XmlSerializer and tell it to use the modified reader and writer.

http://primates.ximian.com/~lluis/blog/pivot/entry.php?id=6


Wednesday, February 02, 2005
 
C++ interview
http://www.oneparticularharbor.net/sam/interview.html


The Liskov Substitution Principle
- Methods that use references to superclass must be able to use objects of subclasses without knowing it

The ability to substitute a subclass object for a superclass object is characteristic of good design.

The Open-Close principle
- Software entities, i.e., classes, modules, functions, and so forth, should be open for extension, but closed for modification

Any design that requires code changes to handle the introduction of a newly derived class is a bad design




Powered by Blogger

Google
WWW THIS BLOG