Changeset 288 in pacpusframework for trunk/include


Ignore:
Timestamp:
03/26/14 21:27:30 (10 years ago)
Author:
Marek Kurdej
Message:

Using boost::shared_ptr for storing components.

Location:
trunk/include/Pacpus
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/Pacpus/DbitePlayer/DbtPlyFileManager.h

    r181 r288  
    9797
    9898    /// a pointer on the player engine
    99     DbtPlyEngine * mEngine;
     99    boost::shared_ptr<DbtPlyEngine> mEngine;
    100100
    101101    QStringList getDbiteFilenameList() const;
  • trunk/include/Pacpus/DbitePlayer/DbtPlyTrigger.h

    r152 r288  
    6464
    6565private:
    66     DbtPlyEngine * mEngine;
     66    boost::shared_ptr<DbtPlyEngine> mEngine;
    6767};
    6868
  • trunk/include/Pacpus/DbitePlayer/DbtPlyUserInterface.h

    r152 r288  
    9999   
    100100private:
    101     DbtPlyEngine * mEngine;
     101    boost::shared_ptr<DbtPlyEngine> mEngine;
    102102
    103103    QWidget * wTel_ ;
  • trunk/include/Pacpus/kernel/ComponentBase.h

    r286 r288  
    2323#define DEF_PACPUS_COMPONENTBASE_H
    2424
    25 #include <Pacpus/kernel/ComponentManager.h>
     25//#include <Pacpus/kernel/ComponentManager.h>
    2626#include <Pacpus/kernel/InputOutputBase.h>
    2727// InputOutputInterface.h must be included, otherwise we could not use addInput, addOutput template methods
     
    3333#include <boost/program_options/options_description.hpp>
    3434#include <boost/program_options/value_semantic.hpp>
     35#include <QMap>
    3536#include <QString>
    36 #include <QMap>
    3737#include <string>
    3838
     
    5252namespace pacpus
    5353{
     54
     55class ComponentBase;
    5456
    5557class ComponentManager;
     
    9193    /// Ctor of ComponentBase.
    9294    /// @param name Name of your component.
    93     ComponentBase(const QString & name);
     95    ComponentBase(QString const& name);
    9496
    9597    /// Dtor of ComponentBase.
     
    195197    std::string mName;
    196198    std::string mTypeName;
    197    
     199    //QThread mThread;
     200
    198201    /// Whether to display or not the graphical interface (GUI)
    199202    bool hasGui() const;
  • trunk/include/Pacpus/kernel/ComponentFactory.h

    r89 r288  
    1616#define DEF_PACPUS_COMPONENTFACTORY_H
    1717
    18 #include <cassert>
    19 
    20 //#include <boost/static_assert.hpp>
    21 //#include <boost/type_traits/is_base_of.hpp>
     18#include <boost/assert.hpp>
     19#include <boost/static_assert.hpp>
     20#include <boost/type_traits/is_base_of.hpp>
    2221
    2322#include <Pacpus/kernel/ComponentFactoryBase.h>
     
    3736  static pacpus::ComponentFactory<className> sFactory(factoryName)
    3837
    39 namespace pacpus {
     38#define PACPUS_REGISTER_COMPONENT(Class) \
     39    static pacpus::ComponentFactory<Class> sFactory(#Class)
     40
     41namespace pacpus
     42{
    4043
    4144/// Use it to interface your components with the application.
     
    4750    : public ComponentFactoryBase
    4851{
    49     //static_assert(,"T must inherit from ComponentBase")
    50     //  BOOST_STATIC_ASSERT_MSG((boost::is_base_of<ComponentBase, T>::value), "T must inherit from ComponentBase");
     52    BOOST_STATIC_ASSERT_MSG((boost::is_base_of<ComponentBase, T>::value), "component T must inherit from ComponentBase");
     53
    5154public:
    5255    /** Ctor of ComponentFactory, initialize the factory of the components of type @em T.
    5356     * @param type Name of the type of the components.
    5457     */
    55     ComponentFactory(const QString& type);
     58    ComponentFactory(QString const& type);
    5659   
    5760    /** Dtor of ComponentFactory. */
     
    6164     * @return Name of the type of the components.
    6265     */
    63     const QString& getType() const;
     66    QString const& getType() const;
    6467
    6568protected:
    66     virtual ComponentBase* instantiateComponent(const QString& name);
    67  
     69    virtual ComponentSharedPointer instantiateComponent(QString const& name);
     70
    6871private:
    6972    QString mType;
     
    7174
    7275template <typename T>
    73 ComponentFactory<T>::ComponentFactory(const QString& type)
    74   : mType(type)
     76ComponentFactory<T>::ComponentFactory(QString const& type)
     77    : mType(type)
    7578{
    76     assert(!type.isEmpty());
     79    BOOST_ASSERT(!type.isEmpty());
    7780    addFactory(this, mType);
    7881}
     
    8487
    8588template <typename T>
    86 const QString& ComponentFactory<T>::getType() const
     89QString const& ComponentFactory<T>::getType() const
    8790{
    8891    return mType;
     
    9093
    9194template<typename T>
    92 ComponentBase* ComponentFactory<T>::instantiateComponent(const QString& name)
     95ComponentSharedPointer ComponentFactory<T>::instantiateComponent(QString const& name)
    9396{
    94     return new T(name);
     97    return ComponentSharedPointer(new T(name));
    9598}
    9699
    97 } // pacpus
     100} // namespace pacpus
    98101
    99102#endif // DEF_PACPUS_DBITEEXCEPTION_H
  • trunk/include/Pacpus/kernel/ComponentFactoryBase.h

    r196 r288  
    1818#include <Pacpus/kernel/PacpusLibConfig.h>
    1919
     20#include <boost/shared_ptr.hpp>
     21//#include <boost/weak_ptr.hpp>
     22
    2023class QString;
    2124
    22 namespace pacpus {
     25namespace pacpus
     26{
     27
     28class ComponentBase;
     29
     30typedef boost::shared_ptr<ComponentBase> ComponentSharedPointer;
     31//typedef boost::weak_ptr<ComponentBase> ComponentWeakPointer;
    2332
    2433class ComponentManager;
    25 class ComponentBase;
    2634
    2735/** ComponentFactoryBase
     
    3139{
    3240    friend class ComponentManager;
     41
    3342public:
    3443    /** Ctor of ComponentFactoryBase. */
     
    4251     * @return Pointer on the newly created component, you become the owner of its lifetime.
    4352     */
    44     virtual ComponentBase * instantiateComponent(const QString& name) = 0;
     53    virtual ComponentSharedPointer instantiateComponent(QString const& name) = 0;
    4554   
    4655    /** Register a new factory.
     
    4857     * @param type Name of the type created by the factory.
    4958     */
    50     void addFactory(ComponentFactoryBase* addr, const QString& type);
     59    void addFactory(ComponentFactoryBase* addr, QString const& type);
    5160   
    5261    /** Add a new component.
    5362     * @param name Name of the new component.
    5463     */
    55     void addComponent(const QString& name);
     64    void createComponent(QString const& name);
    5665
    5766private:
  • trunk/include/Pacpus/kernel/ComponentManager.h

    r207 r288  
    2828#include <QPluginLoader>
    2929
    30 namespace pacpus {
     30namespace pacpus
     31{
    3132
    3233class ComponentBase;
    3334
    3435/// @todo Documentation
    35 typedef QMap<QString, ComponentBase *> ComponentMap;
     36typedef QMap<QString, ComponentSharedPointer> ComponentMap;
    3637/// @todo Documentation
    37 typedef QMap<QString, ComponentFactoryBase *> FactoryMap;
     38typedef QMap<QString, ComponentFactoryBase* > FactoryMap;
    3839
    3940/// Singleton recording the components and managing them.
     
    5960    struct destroyer {
    6061        /// Invokes ComponentManager::destroy() method if @b mgr pointer is not null.
    61         void operator()(ComponentManager * mgr) const
     62        void operator()(ComponentManager* mgr) const
    6263        {
    6364            if (!mgr) {
     
    7273     * @return Number of components loaded by the manager.
    7374     */
    74     std::size_t loadComponents(const QString& file);
     75    std::size_t loadComponents(QString const& file);
    7576
    7677    /** Start all the components
     
    8384     * @return True if the component exists and has been started, otherwise false.
    8485     */
    85     bool start(const QString & component);
     86    bool start(QString const& component);
    8687
    8788    /** Stop all the components
     
    9495     * @return True if the component has been stopped, otherwise false.
    9596     */
    96     bool stop(const QString& component);
     97    bool stop(QString const& component);
    9798
    9899    /** Get a pointer to the component referred by @em name.
     
    100101     * @return Pointer to the component if it exists, otherwise @em NULL.
    101102     */
    102     ComponentBase* getComponent(const QString& name);
     103    ComponentSharedPointer getComponent(QString const& name);
    103104
    104105    /** Get the list of all the names of the component known by the manager.
     
    111112     * @return True if the plugin has been loaded, otherwise false.
    112113     */
    113     bool loadPlugin(const QString& filename);
     114    bool loadPlugin(QString const& filename);
    114115
    115116private:
    116     bool stop(ComponentBase* component) const;
     117    bool stop(ComponentSharedPointer component) const;
    117118
    118119    /// Create a new component of type 'type' and with the name 'name'
    119     bool createComponent(const QString& type, const QString& name);
     120    bool createComponent(QString const& type, QString const& name);
    120121
    121     bool checkComponent(const QString & componentName);
    122     bool checkComponentInput(const QString & componentName, const QString & inputName);
    123     bool checkComponentOutput(const QString & componentName, const QString & outputName);
     122    bool checkComponent(QString const& componentName);
     123    bool checkComponentInput(QString const& componentName, QString const& inputName);
     124    bool checkComponentOutput(QString const& componentName, QString const& outputName);
    124125
    125     bool createConnection(const QString& type, const QString& name, const QString& , int );
     126    bool createConnection(QString const& type, QString const& name, QString const& , int );
    126127
    127     bool registerComponent(ComponentBase* addr, const QString& name);
    128     bool registerComponentFactory(ComponentFactoryBase* addr, const QString& type);
     128    bool registerComponent(ComponentSharedPointer addr, QString const& name);
     129    bool registerComponentFactory(ComponentFactoryBase* addr, QString const& type);
    129130
    130     bool unregisterComponent(const QString& name);
    131     bool unregisterComponentFactory(const QString& type);
     131    bool unregisterComponent(QString const& name);
     132    bool unregisterComponentFactory(QString const& type);
    132133
    133134    // Allow 2 functions to access to private members of ComponentManager
    134     friend void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, const QString & type);
    135     friend void ComponentFactoryBase::addComponent(const QString & name);
     135    friend void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, QString const& type);
     136    friend void ComponentFactoryBase::createComponent(QString const& name);
    136137
    137138    /// private constructor accessible only via static create() function
  • trunk/include/Pacpus/kernel/XmlComponentConfig.h

    r270 r288  
    3535     * @param name Name of the ComponentFactory, by convention equal to class name.
    3636     */
    37     explicit XmlComponentConfig(const QString& name = QString::null);
     37    explicit XmlComponentConfig(QString const& name = QString::null);
    3838
    3939    /** Dtor of XmlComponentConfig. */
     
    4545     * @param name Name of the property.
    4646     */
    47     void addProperty(const QString& name);
     47    void addProperty(QString const& name);
    4848
    4949    /** Delete a property from the XML.
    5050     * @return False if the property does not exist, false otherwise.
    5151     */
    52     int delProperty(const QString& name);
     52    int delProperty(QString const& name);
    5353
    5454    /** Get the value of a property.
     
    5757     * @return Value of the property, @em defaultValue otherwise.
    5858     */
    59     QString getProperty(const QString& name, const QString& defaultValue = QString::null) const;
     59    QString getProperty(QString const& name, QString const& defaultValue = QString::null) const;
    6060
    6161    /** Get the value of a property as a boolean.
     
    6464     * @return Value of the property, @em defaultValue otherwise.
    6565     */
    66     bool getBoolProperty(const QString& name, bool defaultValue = false) const;
     66    bool getBoolProperty(QString const& name, bool defaultValue = false) const;
    6767
    6868    /** Get the value of a property as an integer.
     
    7171     * @return Value of the property, @em defaultValue otherwise.
    7272     */
    73     int getIntProperty(const QString& name, int defaultValue = 0) const;
     73    int getIntProperty(QString const& name, int defaultValue = 0) const;
    7474
    7575    /** Get the value of a property as a double.
     
    7878     * @return Value of the property, @em defaultValue otherwise.
    7979     */
    80     double getDoubleProperty(const QString& name, double defaultValue = 0.0) const;
     80    double getDoubleProperty(QString const& name, double defaultValue = 0.0) const;
    8181
    8282    /** Set the value of a property.
     
    8484     * @param value Value to set.
    8585     */
    86     void setProperty(const QString& name, const QString& value);
     86    void setProperty(QString const& name, QString const& value);
    8787
    8888    /** Check if a property exists.
     
    9090     * @return True if the property exists, false otherwise.
    9191     */
    92     bool hasProperty(const QString& name) const;
     92    bool hasProperty(QString const& name) const;
    9393   
    9494public:
  • trunk/include/Pacpus/kernel/XmlConfigFile.h

    r197 r288  
    4141class PACPUSLIB_API XmlConfigFile
    4242{
    43     friend XmlComponentConfig::XmlComponentConfig(const QString&);
     43    friend XmlComponentConfig::XmlComponentConfig(QString const&);
    4444    friend class ComponentManager;
    4545
Note: See TracChangeset for help on using the changeset viewer.