joi, 14 aprilie 2011

Subversion: Get the modified files between two revisions

There is a simple command to get the modified files between two revisions in subversion. All you have to know are the two revision numbers and the path to the repository folder:

svn diff -r revision1:revision2 --summarize URL

or if you want to list the files modified between an older revision and the head revision, type:

svn diff -r revison:HEAD -- summarize URL

If you do not type summarize you will also get to the console output all the differences between the two revisions.
Example: I need to see which files have been modified since revision 3880:

svn diff -r 3880:HEAD --sumarize svn://mysvnserver/repository/somefolder
The svn diff command is more complex, so you can get more details here:
http://svnbook.red-bean.com/en/1.0/re09.html.

joi, 31 martie 2011

Serialize an array to XML in .NET Framework

Well, this is not too much of a big deal since with a little knowledge about Serialization you will be able to figure this out quite rapidly. I only thought of posting this here since I had in mind the issue of converting an array of (string) values into an XML format and then have it deserialized at a later time when I would have need the array again. For this purpose I used the XmlSerializer class and the MemoryStream class.
The example code I give below shows how to convert a string array to XML and then how to deserialize it from the XML format into a new array.

public static void SerializeDeserializeArray( )
{
    string[ ] strArr = new string[ ] {
        "C:\\Program Files\\myFile1.txt",
        "C:\\Program Files\\myFile2.txt",
        "C:\\Program Files\\myFile3.txt"
    };

    MemoryStream memStream = new MemoryStream( );
    StreamWriter sw = new StreamWriter( memStream );

    XmlSerializer ser = new XmlSerializer( typeof( string[ ] ) );
    ser.Serialize( sw, strArr );

    StreamReader sr = new StreamReader( memStream );

    memStream.Position = 0;
    string str = sr.ReadToEnd( );

    memStream.Position = 0;
    string[ ] deserArr = (string[ ] )ser.Deserialize( memStream );

    if( deserArr != null )
    {
        foreach( string s in deserArr )
        {
            Console.WriteLine( s );
        }
    }

    Console.WriteLine( );
}

miercuri, 16 martie 2011

Error C2872 ambiguous symbol

I was trying to compile one of my C++ projects and ran into this error:

Error 1 error C2872: 'IServiceProvider' : ambiguous symbol C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ocidl.h 8005


Among other files in the project, I had a header file which started like this:

using namespace System;
#include "MyHeader1.h"
#include "MyHeader2.h"


After a little research I have found the cause of this error. I turned on the /showIncludes option of the compiler and saw that one of my headers was actually including the "ocidl.h" file. The Build output will show, among others:
...
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\olectl.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack8.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ocidl.h
...

In order to fix this compile time error, I moved the using below the #include as below and it all started working again:
 
#include "MyHeader1.h"
#include "MyHeader2.h"

using namespace System;

joi, 17 februarie 2011

Passing an array to a function in C++

In C++ you if you want to modify an array inside a function, you should not return a pointer to it from within the function as this pointer will be out of scope when the function execution ends. You need to make sure that you allocate the array before passing it as a parameter:

int* buffer = new int[ BUFFER_SIZE];

arrayProcessing( buffer, BUFFER_SIZE );
#ifdef _DEBUG
DisplayBuffer( );
#endif

where arrayProcessing is defined like this:

int arrayProcessing( int* buffer, int size )
{
// TODO: modify elements of buffer.
}