Dienstag, 24. November 2009

Nice example on: Adapter in C++: External Polymorphism

I just keeping this here to be able to remember the nice way to manage the different classes from the base framework, actually this one is used in the analyzer project.

The original example is taken form the Design Patterns book


01
Specify the new desired interface
Design a “wrapper” class that can “impedance match” the old to the new
The client uses (is coupled to) the new interface
The adapter/wrapper “maps” to the legacy implementation
02
#include "stdafx.h"
#include 

using namespace std;
class ExecuteInterface {
public:
// 1. Specify the new interface
virtual ~ExecuteInterface(){}
virtual void execute() = 0;
};

2. Design a "wrapper" or "adapter" class
template 
class ExecuteAdapter: public ExecuteInterface {
public:
ExecuteAdapter(TYPE *o, void(TYPE:: *m)()) {
object = o;
method = m;
}
~ExecuteAdapter() {
delete object;
}

// 4. The adapter/wrapper "maps" the new to the legacy implementation
void execute() {  /* the new */
(object->*method)();
}
private:
TYPE *object; // ptr-to-object attribute

void(TYPE:: *method)(); /* the old */     // ptr-to-member-function attribute
};


// The old: three totally incompatible classes
// no common base class,
class Fea {
public:
// no hope of polymorphism
~Fea() {
cout << "Fea::dtor" << endl;   }   
void doThis() {     cout << "Fea::doThis()" << endl;   } };  

class Feye {   public:~Feye() { 
cout << "Feye::dtor" << endl;   }   
void doThat() {
cout << "Feye::doThat()" << endl;   } };  
class Pheau {   
public:
~Pheau() {
cout << "Pheau::dtor" << endl;   }
void doTheOther() {
cout << "Pheau::doTheOther()" << endl;   } };   /* the new is returned */ ExecuteInterface **initialize() {
ExecuteInterface **array = new ExecuteInterface *[3];    /* the old is below */
array[0] = new ExecuteAdapter < Fea > (new Fea(), &Fea::doThis);
array[1] = new ExecuteAdapter < Feye > (new Feye(), &Feye::doThat);
array[2] = new ExecuteAdapter < Pheau > (new Pheau(), &Pheau::doTheOther);
return array;
}

int main() {
ExecuteInterface **objects = initialize();
for (int i = 0; i < 3; i++) {    objects[i]->execute();
}

// 3. Client uses the new (polymporphism)
for (i = 0; i < 3; i++) {
delete objects[i];
}
delete objects;
return 0;
}
The result output:
Fea::doThis()
Feye::doThat()
Pheau::doTheOther()
Fea::dtor
Feye::dtor
Pheau::dtor

Dienstag, 4. August 2009

Some tips and tricks I used to trace the particles

















This post is just MySQL helper to manage my particles in the database.
With help of my best fiend Karine.

What WE DID!!
create procedure proc @snap int
as

select * into #t from MODEL7_test2 where snap between @snap-10 and @snap+10

heto

select ID, MIN( SQRT( POW((a.posx-b.xc),2)+POW((a.posy-b.yc),2)+POW((a.posz-b.zc),2))) as MinPosMax, Max(SQRT( POW((a.posx-b.xc),2)+POW((a.posy-b.yc),2)+POW((a.posz-b.zc),2))) as MaxPos from #t as a
inner join COMDB_MODEL7 as b on a.snap=b.snap
where a.id in (select id from MODEL7_test2 where snap=@snap) group by id;
oy verchi toxum el where a.id in (select id from #t where snap=@snap

CREATE TEMPORARY TABLE t1 AS SELECT *
FROM MODEL7_test2
WHERE snap
BETWEEN 501 -1
AND 501 +1

create temporary table t1 as select * from MODEL7_test2 where snap between 501-1 and 501+1;
select ID, MIN( SQRT( POW((a.posx-b.xc),2)+POW((a.posy-b.yc),2)+POW((a.posz-b.zc),2))) as MinPosMax, Max(SQRT( POW((a.posx-b.xc),2)+POW((a.posy-b.yc),2)+POW((a.posz-b.zc),2))) as MaxPos from t1 as a
inner join COMDB_MODEL7 as b on a.snap=b.snap and a.snap between 501-1 and 501+1 where a.id in (select id from MODEL7_test2 where snap=501) group by id;

CREATE TEMPORARY TABLE t1 AS SELECT *
FROM MODEL7_test2
WHERE snap
BETWEEN 501 -1
AND 501 +1;# Affected rows: 1978554
SELECT ID, MIN( SQRT( POW( (
a.posx - b.xc
), 2 ) + POW( (
a.posy - b.yc
), 2 ) + POW( (
a.posz - b.zc
), 2 ) ) ) AS MinPos, Max( SQRT( POW( (
a.posx - b.xc
), 2 ) + POW( (
a.posy - b.yc
), 2 ) + POW( (
a.posz - b.zc
), 2 ) ) ) AS MaxPos
FROM t1 AS a
INNER JOIN COMDB_MODEL7 AS b ON a.snap = b.snap
GROUP BY id;
-------------------------------------------------------------

Donnerstag, 30. Juli 2009

Close to Marseille: Fire initiated by some military experiments, eg. "Firing from machine guns just for fun in hot season".
At the evening about 6 water bombers attempting to get fire under the control. But is was unsuccessful.


.
Posted by Picasa

Pais: More details on Notre Dame de Paris

Last week I have been in Paris. So I found some interesting details on on Notre Dame de Paris:
Posted by Picasa


Another image is here, I have not seen those people before. Maybe I miss them somehow.

Donnerstag, 25. Juni 2009

Finally I have figured out how to extract the gadget -2 file region based on the stellar particles IDs.
The code I have published on the http://gad2extract.googlecode.com.
Actually by svn you can get like this:
svn checkout http://gad2extract.googlecode.com/svn/trunk/ gad2extract-read-only