You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Leo Sutic <le...@inspireinfrastructure.com> on 2001/11/19 09:28:06 UTC

Avalon/C++

All,

a while ago someone mentioned converting Avalon and Excalibur to C++. Back
then, I replied that porting it to C# might be a better idea, but since then
I have grown to appreciate the versality of the framework, and I believe
that the design patterns used in Avalon can be used not for just server
applications (I believe there is at least one person using it to write a
simulator).

Instead of talking about how it could be implemented in C++, I have done an
implementation of a component manager and some lifestyle interfaces. (So I
am afraid that in terms of functionality this is your regular version 0.0.0
freshmeat.net announcement.) The whole bunch is downloadable from
http://www.student.nada.kth.se/~d97-lsu/massdriver/ and all code is under an
Apache license unless explicitely mentioned otherwise in the code (there are
no instances that I know of).

The implementation relies heavily on RTTI at the moment, so this has to be
evaluated in relation to shared object files, different compilers, different
languages, project goals, etc.

SAMPLE:

/**
 * Component interface for the test component.
 */
class TestInterface : public virtual Component
{
public:
  /**
   * Single method.
   */
  virtual void  Method () = 0;

  /**
   * Default role for the component.
   * This UID is unique for the interface and
   * specialization should be done by using the
   * UID(UID&,UID&) constructor.
   */
  static const UID ROLE;
};

/**
 * Definition of the TestInterface's role.
 */
const UID TestInterface::ROLE(0x97413A80L, 0xDB8711D5L, 0xB1EB00C0L,
0x26010A22L);


/**
 * Implementation of the TestInterface.
 */
class TestComponent : public virtual AbstractComponent,
                      TestInterface,
                      Initializable,
                      AbstractComposable,
                      Disposable
{
public:
                TestComponent ();
  virtual      ~TestComponent ();

  virtual void  Dispose ();
  virtual void  Initialize ();
  virtual void  Method ();

  /**
   * Standard method to get a factory for the
   * component.
   */
  static ComponentFactory* GetFactory ();
};

void main (int, char*[])
{
  DefaultComponentManager* dcm = new DefaultComponentManager ();

  // Add our single component
  dcm->AddComponent (TestInterface::ROLE, TestComponent::GetFactory ());

  // Initialize the CM.
  dcm->Initialize ();

  // Cast to ComponentManager*.
  ComponentManager* cm = dynamic_cast<ComponentManager*> (dcm);

  if (cm != NULL)
  {
    // Guard the component to make sure it gets released no matter what
happens.
    Guard<TestInterface> tc (cm, TestInterface::ROLE);
    if (tc)
    {
      printf (" INFO: Got component.\n");
      cout << "Retrieved a " << typeid(tc).name() << endl;
      tc->Method ();
    }
    else
    {
      printf ("ERROR: Could not obtain component\n");
    }
    printf (" INFO: Leaving guard scope...\n");
  }
  else
  {
      printf ("ERROR: Unable to cast from DCM to CM\n");
  }
  printf (" INFO: Done with component\n");

  // Dispose and delete the CM.
  dcm->Dispose ();
  delete dcm;
}

/LS



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Avalon/C++

Posted by Peter Donald <pe...@apache.org>.
On Mon, 19 Nov 2001 19:28, Leo Sutic wrote:
> a while ago someone mentioned converting Avalon and Excalibur to C++. Back
> then, I replied that porting it to C# might be a better idea, but since
> then I have grown to appreciate the versality of the framework, and I
> believe that the design patterns used in Avalon can be used not for just
> server applications (I believe there is at least one person using it to
> write a simulator).

I completely agree that Avalon/Framework is not just for server products. 
Most of the places I actually use it is completely unrelated to serverside 
products. Simulations, geometry processing engines, ant2 proposal, object 
model source code generator etc ;) About the only "serverside" stuff I do is 
with Phoenix and even part of that is not server related.

I would love to see Berin rework his document to say that it is not only 
applicable in serverside environments ;) I have had a few "discussions" with 
people who point out that the guide saids it is serverside only and thus they 
shouldn't have to learn it (because weren't gonna use it in serverside 
environment).

> Instead of talking about how it could be implemented in C++, I have done an
> implementation of a component manager and some lifestyle interfaces. (So I
> am afraid that in terms of functionality this is your regular version 0.0.0
> freshmeat.net announcement.) The whole bunch is downloadable from
> http://www.student.nada.kth.se/~d97-lsu/massdriver/ and all code is under
> an Apache license unless explicitely mentioned otherwise in the code (there
> are no instances that I know of).

very very kool. Downloading it now ... ;)

>
> The implementation relies heavily on RTTI at the moment, so this has to be
> evaluated in relation to shared object files, different compilers,
> different languages, project goals, etc.
>
> SAMPLE:
>
> /**
>  * Component interface for the test component.
>  */
> class TestInterface : public virtual Component
> {
> public:
>   /**
>    * Single method.
>    */
>   virtual void  Method () = 0;
>
>   /**
>    * Default role for the component.
>    * This UID is unique for the interface and
>    * specialization should be done by using the
>    * UID(UID&,UID&) constructor.
>    */
>   static const UID ROLE;
> };
>
> /**
>  * Definition of the TestInterface's role.
>  */
> const UID TestInterface::ROLE(0x97413A80L, 0xDB8711D5L, 0xB1EB00C0L,
> 0x26010A22L);
>
>
> /**
>  * Implementation of the TestInterface.
>  */
> class TestComponent : public virtual AbstractComponent,
>                       TestInterface,
>                       Initializable,
>                       AbstractComposable,
>                       Disposable
> {
> public:
>                 TestComponent ();
>   virtual      ~TestComponent ();
>
>   virtual void  Dispose ();
>   virtual void  Initialize ();
>   virtual void  Method ();
>
>   /**
>    * Standard method to get a factory for the
>    * component.
>    */
>   static ComponentFactory* GetFactory ();
> };
>
> void main (int, char*[])
> {
>   DefaultComponentManager* dcm = new DefaultComponentManager ();
>
>   // Add our single component
>   dcm->AddComponent (TestInterface::ROLE, TestComponent::GetFactory ());
>
>   // Initialize the CM.
>   dcm->Initialize ();
>
>   // Cast to ComponentManager*.
>   ComponentManager* cm = dynamic_cast<ComponentManager*> (dcm);
>
>   if (cm != NULL)
>   {
>     // Guard the component to make sure it gets released no matter what
> happens.
>     Guard<TestInterface> tc (cm, TestInterface::ROLE);
>     if (tc)
>     {
>       printf (" INFO: Got component.\n");
>       cout << "Retrieved a " << typeid(tc).name() << endl;
>       tc->Method ();
>     }
>     else
>     {
>       printf ("ERROR: Could not obtain component\n");
>     }
>     printf (" INFO: Leaving guard scope...\n");
>   }
>   else
>   {
>       printf ("ERROR: Unable to cast from DCM to CM\n");
>   }
>   printf (" INFO: Done with component\n");
>
>   // Dispose and delete the CM.
>   dcm->Dispose ();
>   delete dcm;
> }
>
> /LS

-- 
Cheers,

Pete

"The fact that a believer is happier than a skeptic is no more to the
 point than the fact that a drunken man is happier than a sober one.
 The happiness of credulity is a cheap and dangerous quality."
        -- George Bernard Shaw

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>