Changeset 15 in pacpusframework for trunk/include/Pacpus


Ignore:
Timestamp:
Jan 8, 2013, 1:47:28 AM (12 years ago)
Author:
sgosseli
Message:

Many improvement (documentation and coding style).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/Pacpus/kernel/ComponentFactory.h

    r3 r15  
    1 // ********************************************************************
    2 //  created:    2006/02/14 - 15:39
    3 //  filename:   ComponentFactory.h
    4 //
    5 //  author:     Gerald Dherbomez
    6 //
    7 //  purpose:    Template class ComponentFactory.
    8 //              Use it to interface your components with the application
    9 // *********************************************************************
     1/**
     2 *
     3 * Distributed under the UTC Heudiascy Pacpus License, Version 1.0.
     4 * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved.
     5 *
     6 * See the LICENSE file for more information or a copy at:
     7 *   http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt
     8 *
     9 */
    1010
    1111#ifndef COMPONENTFACTORY_H
    1212#define COMPONENTFACTORY_H
    1313
     14#include <cassert>
     15
    1416#include "ComponentFactoryBase.h"
    1517
     18#include <QtGlobal>
    1619#include <QString>
    1720
     
    2326  static pacpus::ComponentFactory<className> sFactory(factoryName)
    2427
    25 namespace pacpus {
     28namespace pacpus
     29{
     30  /** ComponentFactory
     31   * @brief Use it to interface your components with the application.
     32   *
     33   * @example
     34   *   REGISTER_COMPONENT("DummyComponent", DummyComponent);
     35   */
     36  template <typename T>
     37  class ComponentFactory
     38    : public ComponentFactoryBase
     39  {
     40    public:
     41      /** Ctor of ComponentFactory, initialize the factory of the components of type @em T.
     42       * @param type Name of the type of the components.
     43       */
     44      ComponentFactory(const QString& type);
     45     
     46      /** Dtor of ComponentFactory. */
     47      virtual ~ComponentFactory();
    2648
    27 template <typename T>
    28 class ComponentFactory
    29         : public ComponentFactoryBase
    30 {
    31 public:
    32     ComponentFactory(QString type);
    33     virtual ~ComponentFactory();
     49      /** Get the name of the type of the components.
     50       * @return Name of the type of the components.
     51       */
     52      const QString& getType() const;
    3453
    35     const QString & getType() const;
     54    protected:
     55      virtual ComponentBase* instantiateComponent(const QString& name);
     56     
     57    private:
     58      QString mType;
     59  };
    3660
    37 protected:
    38     virtual ComponentBase * instantiateComponent(const QString & name);
    3961
    40 private:
    41     QString mType;
    42 };
     62  template <typename T>
     63  ComponentFactory<T>::ComponentFactory(const QString& type)
     64    : mType(type)
     65  {
     66    assert(!type.isEmpty());
     67    addFactory(this, mType);
     68  }
    4369
    44 ////////////////////////////////////////////////////////////////////////////////
    45 template <typename T>
    46 ComponentFactory<T>::ComponentFactory(QString type)
    47     : mType(type)
    48 {
    49     addFactory(this, mType);
     70  template<typename T>
     71  ComponentFactory<T>::~ComponentFactory()
     72  {
     73  }
     74
     75  template <typename T>
     76  const QString& ComponentFactory<T>::getType() const
     77  {
     78    return mType;
     79  }
     80
     81  template<typename T>
     82  ComponentBase* ComponentFactory<T>::instantiateComponent(const QString& name)
     83  {
     84    return new T(name);
     85  }
    5086}
    5187
    52 template<typename T>
    53 ComponentFactory<T>::~ComponentFactory()
    54 {
    55 }
    56 
    57 template <typename T>
    58 const QString & ComponentFactory<T>::getType() const
    59 {
    60     return mType;
    61 }
    62 
    63 template<typename T>
    64 ComponentBase * ComponentFactory<T>::instantiateComponent(const QString & name)
    65 {
    66     T * component = new T(name);
    67     return component;
    68 }
    69 
    70 } // namespace pacpus
    71 
    7288#endif // COMPONENTFACTORY_H
Note: See TracChangeset for help on using the changeset viewer.