View Antoni Milton's profile on LinkedIn

Friday, February 26, 2010

How to check the directory exists or not from Makefile??

If the directory exists means, no need to untar the file.

setup:

if test -d DIR_NAME ; then echo NO NEED TO UNTAR ; else tar -xvf FILE.tar ; fi

Thursday, February 4, 2010

Singleton Design Pattern with example C++ code

The Singleton design pattern ensures only one instance of a class in an application. For example, Interfaces object need by both GUI and Back-end class. But only one interface object enough for the whole application (GUI + interface + Back-end)

Here need to develop the interface class as a Singleton class.

static CInterface *s_ptrInterface = 0;

class CInterface
{
private:
CInterface();
~ CInterface();
public:
static CInterface* getInterface()
{
 lock(); // for thread safe.
if( 0 != s_ptrInterface )
s_ptrInterface = new CInterface();
unlock();

return s_ptrInterface ;
}
}
Need to create the object for CInterface like below,
CInterface:: getInterface() // it’s always return the same object

Wednesday, February 3, 2010

Photograph Puzzle Maker

try this site,

http://www.flash-gear.com/npuz/

Tuesday, February 2, 2010

Object slicing example in C++

class Pet

{

string pname;

public:

Pet(const string& name) : pname(name) {}

virtual string name() const { return pname; }

virtual string description() const { return "This is " + pname; }

};


class Dog : public Pet

{

string favoriteActivity;

public:

Dog( const string& name, const string& activity): Pet(name), favoriteActivity(activity) {}

string description() const { return Pet::name() + " likes to " + favoriteActivity; }

};


void describe(Pet p)

{ // Slices the object

cout << p.description() << endl;

}


int main()

{

Pet p("Alfred");

Dog d("Fluffy", "sleep");

describe(p);

describe(d);

}