summaryrefslogtreecommitdiff
path: root/ruby/src/IceRuby/ValueFactoryManager.h
blob: 169018024d0436d39de95c905589668b65174013 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_RUBY_OBJECT_FACTORY_H
#define ICE_RUBY_OBJECT_FACTORY_H

#include <Config.h>
#include <Ice/ValueFactory.h>
#include <IceUtil/Mutex.h>

namespace IceRuby
{

bool initValueFactoryManager(VALUE);

class FactoryWrapper : public Ice::ValueFactory
{
public:

    FactoryWrapper(VALUE, bool);

    virtual Ice::ValuePtr create(const std::string&);

    VALUE getObject() const;

    bool isObjectFactory() const;

    void mark();

    void destroy();

protected:

    VALUE _factory;
    bool _isObjectFactory;
};
typedef IceUtil::Handle<FactoryWrapper> FactoryWrapperPtr;

class DefaultValueFactory : public Ice::ValueFactory
{
public:

    virtual Ice::ValuePtr create(const std::string&);

    void setDelegate(const Ice::ValueFactoryPtr&);
    Ice::ValueFactoryPtr getDelegate() const { return _delegate; }

    VALUE getObject() const;

    void mark();

    void destroy();

private:

    Ice::ValueFactoryPtr _delegate;
};
typedef IceUtil::Handle<DefaultValueFactory> DefaultValueFactoryPtr;

class ValueFactoryManager : public Ice::ValueFactoryManager, public IceUtil::Mutex
{
public:

    ValueFactoryManager();
    ~ValueFactoryManager();

    virtual void add(const Ice::ValueFactoryPtr&, const std::string&);
    virtual Ice::ValueFactoryPtr find(const std::string&) const ICE_NOEXCEPT;

    void addValueFactory(VALUE, const std::string&);
    VALUE findValueFactory(const std::string&) const;
    void addObjectFactory(VALUE, const std::string&);
    VALUE findObjectFactory(const std::string&) const;

    void mark();
    void markSelf();

    VALUE getObject() const;

    void destroy();

private:

    typedef std::map<std::string, Ice::ValueFactoryPtr> FactoryMap;

    VALUE _self;
    FactoryMap _factories;
    DefaultValueFactoryPtr _defaultFactory;
};
typedef IceUtil::Handle<ValueFactoryManager> ValueFactoryManagerPtr;

}

#endif