LibreOffice Module cli_ure (master) 1
WeakBase.cs
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19using System;
20using System.Collections;
21using unoidl.com.sun.star.uno;
22using unoidl.com.sun.star.lang;
23
24namespace uno.util
25{
26
33public class WeakBase : XWeak, XTypeProvider
34{
35 // Contains all WeakAdapter which have been created in this class
36 // They have to be notified when this object dies
37 private WeakAdapter m_adapter = null;
38
39 protected static Hashtable s_types = new Hashtable();
40 protected static Hashtable s_impl_ids = new Hashtable();
41
42 // XWeak impl
48 public XAdapter queryAdapter()
49 {
50 if (null == m_adapter)
51 {
52 lock (this)
53 {
54 if (null == m_adapter)
55 m_adapter = new WeakAdapter( this );
56 }
57 }
58 return m_adapter;
59 }
60
68 {
69 if (null != m_adapter)
70 m_adapter.referentDying();
71 }
72
73 // XTypeProvider impl
74
80 public Type [] getTypes()
81 {
82 Type [] types;
83 Type type = GetType();
85 {
86 types = (Type []) s_types[ type ];
87 if (null == types)
88 {
89 Type [] interfaces = type.GetInterfaces();
90 ArrayList list = new ArrayList( interfaces.Length );
91 for ( Int32 pos = 0; pos < interfaces.Length; ++pos )
92 {
93 Type iface = interfaces[ pos ];
94 // xxx todo: as long as the bridge cannot introduce
95 // native CTS types into UNO on the fly
96 if (iface.FullName.StartsWith( "unoidl." ))
97 {
98 list.Add( iface );
99 }
100 }
101 Int32 len = list.Count;
102 Type [] ar = new Type [ len ];
103 for ( Int32 pos = 0; pos < len; ++pos )
104 ar[ pos ] = (Type) list[ pos ];
105 s_types[ type ] = ar;
106 types = ar;
107 }
108 }
109 return types;
110 }
111
112 public byte [] getImplementationId()
113 {
114 return new byte[0];
115 }
116
117 // System.Object
118 public override String ToString()
119 {
120 System.Text.StringBuilder buf =
121 new System.Text.StringBuilder( base.ToString(), 256 );
122 buf.Append( "\nUNO Object Implementation:\n\tInterfaces: " );
123 Type [] types = getTypes();
124 for ( Int32 pos = 0; pos < types.Length; ++pos )
125 {
126 buf.Append( types[ pos ].FullName );
127 if (pos < (types.Length -1))
128 buf.Append( ", " );
129 }
130 return buf.ToString();
131 }
132}
133
134}
135
std::unordered_map< std::string, LinkedList > Hashtable
An XAdapter implementation that holds a weak reference (System.WeakReference) to an object.
Definition: WeakAdapter.cs:34
This class can be used as a base class for UNO objects.
Definition: WeakBase.cs:34
~WeakBase()
Overrides of Object.Finalize method.
Definition: WeakBase.cs:67
byte[] getImplementationId()
Definition: WeakBase.cs:112
static Hashtable s_types
Definition: WeakBase.cs:39
XAdapter queryAdapter()
The returned XAdapter implementation can be used to keap a weak reference to this object.
Definition: WeakBase.cs:48
override String ToString()
Definition: WeakBase.cs:118
Type[] getTypes()
Returns an array of Type objects which represent all implemented UNO interfaces of this object.
Definition: WeakBase.cs:80
static Hashtable s_impl_ids
Definition: WeakBase.cs:40
WeakAdapter m_adapter
Definition: WeakBase.cs:37
void const * base
std::shared_ptr< osl::Mutex > const & lock()
ResultType type
size_t pos