File: factory.cc

package info (click to toggle)
step 4%3A16.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,272 kB
  • ctags: 2,533
  • sloc: cpp: 16,886; xml: 511; python: 380; sh: 16; makefile: 1
file content (74 lines) | stat: -rw-r--r-- 2,483 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* This file is part of StepCore library.
   Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>

   StepCore library is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   StepCore library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with StepCore; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "factory.h"
#include "world.h"
#include "solver.h"
#include "collisionsolver.h"
#include "constraintsolver.h"

namespace StepCore {

// XXX: locking
void Factory::registerMetaObject(const MetaObject* metaObject)
{
    _metaObjects.insert(metaObject->className(), metaObject);
}

const MetaObject* Factory::metaObject(const QString& name) const
{
    return _metaObjects.value(name, NULL);
}

Object* Factory::newObject(const QString& name) const
{
    const MetaObject* metaObject = this->metaObject(name);
    if(!metaObject) return NULL;
    return metaObject->newObject();
}

Item* Factory::newItem(const QString& name) const
{
    const MetaObject* metaObject = this->metaObject(name);
    if(!metaObject || !metaObject->inherits<Item>()) return NULL;
    return static_cast<Item*>(metaObject->newObject());
}

Solver* Factory::newSolver(const QString& name) const
{
    const MetaObject* metaObject = this->metaObject(name);
    if(!metaObject || !metaObject->inherits<Solver>()) return NULL;
    return static_cast<Solver*>(metaObject->newObject());
}

CollisionSolver* Factory::newCollisionSolver(const QString& name) const
{
    const MetaObject* metaObject = this->metaObject(name);
    if(!metaObject || !metaObject->inherits<CollisionSolver>()) return NULL;
    return static_cast<CollisionSolver*>(metaObject->newObject());
}

ConstraintSolver* Factory::newConstraintSolver(const QString& name) const
{
    const MetaObject* metaObject = this->metaObject(name);
    if(!metaObject || !metaObject->inherits<ConstraintSolver>()) return NULL;
    return static_cast<ConstraintSolver*>(metaObject->newObject());
}

} // namespace StepCore