Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Misc > Archive::Off Topic

Archive::Off Topic Archive area for Off Topic's posts that were moved here after an inactivity period of 90 days.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-05-2004, 03:44 PM
Zkhava
Hill Giant
 
Join Date: Jul 2004
Posts: 206
Default C++

Heres Some Code for ya !

Code:
 #include 
using std::cout;
using std::string;

class Extension {
public:
   virtual ~Extension() { }
   void registerOwner( class Image* o ) { owner = o; }
protected:
   Image* owner;
};

class MosaicExtension : public Extension { public:
   void doMosaic();
};

class HeatExtension : public Extension { public:
   void doThermalSpectrum();
};


class Image {
   string name;
public:
   Image( string n ) : name(n) { }
   string getName()  { return name; }
   void display()    { cout getName() getName() registerOwner( this );
   }
   ~Lsat() { delete exten; }
   /*virtual*/ Extension* getExtension( const type_info& ti ) {
      if (typeid(MosaicExtension) == ti) return exten;
      return Image::getExtension( ti );
   }
};

class IR : public Image {
   Extension*  exten;
public:
   IR( string n, Extension* ex ) : Image( n ) {
      exten = ex;
      exten->registerOwner( this );
   }
   ~IR() { delete exten; }
   /*virtual*/ Extension* getExtension( const type_info& ti ) {
      if (typeid(HeatExtension) == ti) return exten;
      return Image::getExtension( ti );
   }
};


void main( void ) {
   Image* images[4] = {
      new Lsat( "Western hemisphere", new MosaicExtension() ),
      new IR( "Desert Storm",         new MosaicExtension()   ),
      new Lsat( "Amazon rain forest", new HeatExtension() ),
      new IR( "Gulf of Oman",         new HeatExtension()   ) };
   Extension*        ext;
   MosaicExtension*  mosaicExt;
   HeatExtension*    heatExt;

   for (int i=0; i < 4; i++) {
      images[i]->display();
      if (ext = images[i]->getExtension( typeid(MosaicExtension) )) {
         if (mosaicExt = dynamic_cast( ext ))
            mosaicExt->doMosaic();
      } else if (ext = images[i]->getExtension( typeid(HeatExtension) )) {
         if (heatExt = dynamic_cast( ext ))
            heatExt->doThermalSpectrum();
   }  }
   for (i=0; i < 4; i++) delete images[i];
&

Code:
// Purpose: messages travel both up and down the layers, 
// message interface per layer per direction, 
// one concrete Facade per layer (implements 1 or 2 interfaces) 
// Singleton access to Facade objects 

#include 
using namespace std; 

class ChildOf3 { public: virtual void downMessage() = 0; }; 
class ParentOf2 { public: virtual void upMessage() = 0; }; 
class ChildOf2 { public: virtual void downMessage() = 0; }; 
class ParentOf1 { public: virtual void upMessage() = 0; }; 

class C : public ParentOf2 { public: 
void execute(); 
void upMessage(); 
}; 
class B : public ParentOf1, public ChildOf3 { public: 
void upMessage(); 
void downMessage(); 
}; 
class A : public ChildOf2 { public: 
void downMessage(); 
void execute(); 
}; 

class SC { // Singleton Collection 
public: 
static C& layer3() { return cObject; } 
static B& layer2() { return bObject; } 
static A& layer1() { return aObject; } 
private: 
static C cObject; static B bObject; static A aObject; 
}; 
C SC::cObject; B SC::bObject; A SC::aObject; 

void thirdParty( ChildOf2& obj1, ChildOf3& obj2, ParentOf2& obj3 ) { 
obj1.downMessage(); 
obj2.downMessage(); 
obj3.upMessage(); 
} 

void main( void ) { 
SC::layer3().execute(); 
SC::layer1().execute(); 
thirdParty( SC::layer1(), SC::layer2(), SC::layer3() ); 
} 

// C::execute // A::execute // A::downMessage 
// B::downMessage // B::upMessage // B::downMessage 
// A::downMessage // C::upMessage // A::downMessage 
// C::upMessage 

void C::execute() { cout
Developers..... These are for a Little game im making so msg me on msn or something !

Zkhava~!
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 11:03 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3