void
        conversion()
        {
            // This is more a compile test ...
            const long int xx = 4711;
            Chamaeleon<long int> aa(xx);
            Chamaeleon<unsigned long int> bb(aa);

            bb = aa;

            CPPUNIT_ASSERT_EQUAL( static_cast<unsigned long int>(xx), bb.unHide() );

            Chamaeleon<C*> cPtr(NULL);
            Chamaeleon<A*> aPtr(cPtr);
            aPtr = cPtr;
        }
Esempio n. 2
0
int main(int argc, char *argv[])
{
    // The types of the pointed elements are given in the < >
    // as is normally the case with templated objects
    autoPtr<label> aPtr;

    // function set is used to assign data to variable
    aPtr.set(new label(11));

    // the dereferencing operator for autoPtr is ()
    Info << "aPtr() = " << aPtr() << endl;

    // valid() returns true if the autoPtr points at a valid object
    if(aPtr.valid()) Info << "aPtr points a valid object " << endl;

    autoPtr<label> bPtr;

    // function ptr() return the pointer for reuse and clears the autoPtr
    label *cPtr = aPtr.ptr();
/*****************************************************************\
    // this line causes an error as aPtr is already cleared
    Info << "aPtr() = " << aPtr() << endl;
\*****************************************************************/

    // function set(pointer) sets autoPtr, or returns error if already set
    // use reset(pointer) instead to overwrite
    bPtr.set(cPtr);
    Info << "bPtr() = " << bPtr() << endl;

    // function clear() clears the pointed object if valid, otherwise does nothing
    bPtr.clear();

    // cPtr object is already cleared by bPtr.clear()
    Info << "*cPtr = " << *cPtr << endl;

    return 0;
}
Esempio n. 3
0
// Factory: safe construction of object before thread start
std::unique_ptr<Active> Active::createActive(){
  std::unique_ptr<Active> aPtr(new Active());
  aPtr->thd_ = std::thread(&Active::run, aPtr.get());
  return aPtr;
}
Esempio n. 4
0
void CLogFileControl::WriteXml(const TDesC8 &aDes)
/**
 * @param aDes - send a aDes string in xml format to a log file
 */
	{
/*--------- Maintaince Warning:  -----------------------------------
******* the fomat of below is sensible from client original format.  
******* Any change should match actual string formated from client. 
******* Double check the code on client side 

* The current assumtion of format:
* First string values are seperated by sign " - " and extra pair of fields are
* seperated from main log message  by long unusual string "LogFieldsRequiredBeingAddedToAboveLogMessage"
* The \t used to seperate field name and field value and \r\n used to seperate
* each other from those pairs of field
* \t\t\t\t\t\t is used to end of whole string
--------------------------------------------------------------------------------*/
		_LIT8(KxmlHeader,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<LOGFILE>");
		//The order of variables:
		// time 		- aTime
		// Severity 	- aSeverity
		// Thread 		- aThread
		// Filename 	- aFilename
		// Linenumber 	- aLinenumber
		// Text 		- aText
		
		// Start of string retrive/deformating 
		HBufC8* pBuf1 = HBufC8::New(KMaxLoggerLineLength*2); //(aDes.Length()+200);
		if(!pBuf1)
			{
			return; // no memory 
			}
		TPtr8 aPtr(pBuf1->Des());  // used for searching
		TPtr8 alogbuf(pBuf1->Des());  //used for final log
		aPtr.Append(aDes);
		TPtrC8 SearchBuf;
		TInt aCount[8]; 
		aCount[0]=0;
		TInt posI(0);

        // retrive log message:
		// Retrive common part of log message:
		TInt i=0;
		for(i=1; i<6; i++)
			{
			SearchBuf.Set(aPtr.Mid(posI));
			aCount[i]=SearchBuf.Find(KSeperation8)+posI;
			posI=aCount[i]+3;
			if(aCount[i]<aCount[i-1])	
                {
                delete pBuf1;
                return; // wrong format string from client
                }
			}
		// seperating common log message and extra log fields will be easy for future maintaince.
		TLogField8* alogField = new TLogField8[6];  // the common part of log message for both 
								  					// with and without extra log fields
		if(!alogField) 
            {
            delete pBuf1;
            return; // no memory
            }

		TLogField8* extralogField=NULL; // only applied to extra log fields

		TInt alength=0;  // a length of array of extra log fields

		alogField[0].iLogTag8.Copy(_L8("TIME"));
		alogField[1].iLogTag8.Copy(_L8("SEVERITY"));
		alogField[2].iLogTag8.Copy(_L8("THREAD"));
		alogField[3].iLogTag8.Copy(_L8("FILENAME"));
		alogField[4].iLogTag8.Copy(_L8("LINENUMBER"));
		alogField[5].iLogTag8.Copy(_L8("TEXT"));
			
		alogField[0].iLogValue8.Copy(aPtr.Mid(aCount[0],aCount[1]-aCount[0]));
		for(i=1; i<5; i++)
			{
			alogField[i].iLogValue8.Copy(aPtr.Mid(aCount[i]+3,aCount[i+1]-aCount[i]-3));				
			}

		SearchBuf.Set(aPtr.Mid(posI));
		aCount[6]=SearchBuf.Find(_L8("LogFieldsRequiredBeingAddedToAboveLogMessage"))+posI; 
		if(aCount[6]<posI)  // no addtional fields. Find return value is KErrNotFound or >0
			{
			alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aDes.Length()-aCount[5]-5));
			}
		else
            {
			alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aCount[6]-aCount[5]-5));
			posI=aCount[6]+45;  //45 is from the length of long string and a tab
			SearchBuf.Set(aPtr.Mid(posI));
			aCount[7]=SearchBuf.Find(_L8("\r\n"))+posI;
			TLex8 lex(aPtr.Mid(posI,aCount[7]-posI));  // get the length
			TInt err=lex.Val(alength); 
			if (err)
                alength=0; // ignor the extra log fields. Let the log go

			// Retrive the extra log fields
			extralogField = new TLogField8[alength];
			if(!extralogField)
                {
                delete pBuf1; 
                return; // no memory
                }
			for(TInt i=0; i<alength; i++)
				{
				aCount[6]=aCount[7]+2;
				SearchBuf.Set(aPtr.Mid(aCount[6]));
				aCount[7]=SearchBuf.Find(_L8("\t"))+aCount[6];
				extralogField[i].iLogTag8.Copy(aPtr.Mid(aCount[6],aCount[7]-aCount[6]));
				aCount[6]=aCount[7]+1;
				SearchBuf.Set(aPtr.Mid(aCount[6]));
				aCount[7]=SearchBuf.Find(_L8("\r\n"))+aCount[6];
				extralogField[i].iLogValue8.Copy(aPtr.Mid(aCount[6],aCount[7]-aCount[6]));
				}
            }
		// Start to organize an XML format:
		TInt afileSize;
		_LIT(KLogMutex, "LoggingServerMutex");
		RMutex mutex;
		TInt r = mutex.CreateGlobal(KLogMutex);
		if(r==KErrAlreadyExists)
			r = mutex.OpenGlobal(KLogMutex);  
		
		if(!r)
            mutex.Wait(); // If still failed, let logging go without bother the mutex.
		iLogFile.Size(afileSize);
		if(afileSize<12) // 12 is from charters of "\r\n</LOGFILE>" 
					//It shoud happened once at the beginning of the file
					// such as overwrite mode
            {
			afileSize=12; // used for lock position
			alogbuf.Copy(KxmlHeader);
			}
		alogbuf.Append(_L8("\r\n<MESSAGE>\r\n"));
		for(TInt i=0; i<6; i++)
			{
			alogbuf.Append(_L8("  <"));
			alogbuf.Append(alogField[i].iLogTag8);
			alogbuf.Append(_L8(">"));
			alogbuf.Append(alogField[i].iLogValue8);
			alogbuf.Append(_L8("</"));
			alogbuf.Append(alogField[i].iLogTag8);
			alogbuf.Append(_L8(">\r\n"));				
			}
		for(TInt i=0; i<alength; i++)  
			{
			alogbuf.Append(_L8("  <"));
			alogbuf.Append(extralogField[i].iLogTag8);
			alogbuf.Append(_L8(">"));
			alogbuf.Append(extralogField[i].iLogValue8);
			alogbuf.Append(_L8("</"));
			alogbuf.Append(extralogField[i].iLogTag8);
			alogbuf.Append(_L8(">\r\n"));				
			}
		
		alogbuf.Append(_L8("</MESSAGE>"));
		alogbuf.Append(_L8("\r\n</LOGFILE>"));
		
		iLogFile.Write(afileSize-12, alogbuf,iStatus);
													
		if(!r)	
			{
			mutex.Signal();
			mutex.Close();				
			} 

		if(extralogField)
            delete[] extralogField;

		delete[] alogField;	
		delete pBuf1;
	}