summaryrefslogtreecommitdiff
path: root/codemaker
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-05-30 15:17:54 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-06-01 15:35:09 +0100
commit7a69e30f96afc9563fd9179a765e3d1127c73b33 (patch)
treeb7aa287696100b0b5dea7de9bcfe94530f3e673f /codemaker
parent9276f7d5740a28b342db2a9bcd8644ff2f4f5742 (diff)
use rtl_Instance for the auto-generated local statics
Diffstat (limited to 'codemaker')
-rw-r--r--codemaker/source/cppumaker/cpputype.cxx131
-rw-r--r--codemaker/source/cppumaker/includes.cxx5
-rw-r--r--codemaker/source/cppumaker/includes.hxx2
3 files changed, 91 insertions, 47 deletions
diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx
index 4ec13e63c9f8..ca610fbaf08e 100644
--- a/codemaker/source/cppumaker/cpputype.cxx
+++ b/codemaker/source/cppumaker/cpputype.cxx
@@ -363,6 +363,7 @@ void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes)
const
{
//TODO: Only include what is really needed
+ includes.addRtlInstanceHxx();
includes.addOslMutexHxx();
includes.addType();
if (m_typeMgr.getTypeClass(m_typeName) == RT_TYPE_INTERFACE) {
@@ -593,16 +594,19 @@ void CppuType::dumpNormalGetCppuType(FileStream& o)
void CppuType::dumpComprehensiveGetCppuType(FileStream& o)
{
- dumpGetCppuTypePreamble(o);
-
- o << indent() << "static ::com::sun::star::uno::Type * the_pType = 0;\n";
+ if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
+ o << " namespace detail {\n\n";
+ }
- o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
+ OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1);
+ OString sStaticTypeClass = "the" + sType + "Type";
+ o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type, " << sStaticTypeClass << " >\n";
+ o << indent() << "{\n";
inc();
- o << indent() << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n";
-
- o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
+ o << indent() << "::com::sun::star::uno::Type operator()() const\n";
+ o << indent() << "{\n";
inc();
+
o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\""
<< m_typeName.replace('/', '.') << "\") );\n\n";
@@ -679,8 +683,8 @@ void CppuType::dumpComprehensiveGetCppuType(FileStream& o)
} else {
o << indent() << count << ",\n" << indent() << "0 );\n\n";
}
-
dec();
+
o << indent()
<< ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
" );\n\n");
@@ -688,15 +692,21 @@ void CppuType::dumpComprehensiveGetCppuType(FileStream& o)
o << indent() << "typelib_typedescription_release( pTD );\n"
<< indent() << "// End inline typedescription generation\n\n";
- o << indent() << "static ::com::sun::star::uno::Type the_staticType( "
+ o << indent() << "::com::sun::star::uno::Type the_staticType( "
<< getTypeClass(m_typeName) << ", sTypeName );\n";
- o << indent() << "the_pType = &the_staticType;\n";
+ o << indent() << "return the_staticType;\n";
dec();
o << indent() << "}\n";
dec();
- o << indent() << "}\n\n";
- o << indent() << "return *the_pType;\n";
+ o << indent() << "};\n\n";
+
+ if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
+ o << " }\n\n";
+ }
+
+ dumpGetCppuTypePreamble(o);
+ o << indent() << "return detail::" << sStaticTypeClass << "::get();\n";
dumpGetCppuTypePostamble(o);
}
@@ -1519,15 +1529,18 @@ void InterfaceType::dumpNormalGetCppuType(FileStream& o)
void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o)
{
- dumpGetCppuTypePreamble(o);
-
- o << indent() << "static ::com::sun::star::uno::Type * the_pType = 0;\n";
+ if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
+ o << " namespace detail {\n\n";
+ }
- o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
+ OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1);
+ OString sStaticTypeClass = "the" + sType + "Type";
+ o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type, " << sStaticTypeClass << " >\n";
+ o << indent() << "{\n";
inc();
- o << indent() << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n";
+ o << indent() << "::com::sun::star::uno::Type operator()() const\n";
+ o << indent() << "{\n";
- o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
inc();
o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\""
<< m_typeName.replace('/', '.') << "\") );\n\n";
@@ -1599,9 +1612,8 @@ void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o)
<< ("typelib_typedescription_release( (typelib_TypeDescription*)pTD"
" );\n\n");
- o << indent() << "static ::com::sun::star::uno::Type the_staticType( "
+ o << indent() << "::com::sun::star::uno::Type the_staticType( "
<< getTypeClass(m_typeName) << ", sTypeName );\n";
- o << indent() << "the_pType = &the_staticType;\n";
StringSet aTypes;
// type for RuntimeException is always needed
@@ -1621,12 +1633,20 @@ void InterfaceType::dumpComprehensiveGetCppuType(FileStream& o)
o << indent() << "// End inline typedescription generation\n";
+ o << indent() << "return the_staticType;\n";
+
dec();
+
o << indent() << "}\n";
dec();
- o << indent() << "}\n\n"
- << indent() << "return *the_pType;\n";
+ o << indent() << "};\n\n";
+
+ if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
+ o << " }\n\n";
+ }
+ dumpGetCppuTypePreamble(o);
+ o << indent() << "return detail::" << sStaticTypeClass << "::get();\n";
dumpGetCppuTypePostamble(o);
}
@@ -2781,14 +2801,20 @@ void StructureType::dumpNormalGetCppuType(FileStream & out) {
dumpGetCppuTypePostamble(out);
}
-void StructureType::dumpComprehensiveGetCppuType(FileStream & out) {
- dumpGetCppuTypePreamble(out);
- out << indent() << "static ::com::sun::star::uno::Type * the_pType = 0;\n"
- << indent() << "if (the_pType == 0) {\n";
+void StructureType::dumpComprehensiveGetCppuType(FileStream & out)
+{
+ if (codemaker::cppumaker::dumpNamespaceOpen(out, m_typeName, false)) {
+ out << " namespace detail {\n\n";
+ }
+
+ OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1);
+ OString sStaticTypeClass = "the" + sType + "Type";
+ out << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type, " << sStaticTypeClass << " >\n";
+ out << indent() << "{\n";
inc();
- out << indent()
- << "::osl::MutexGuard the_guard(::osl::Mutex::getGlobalMutex());\n"
- << indent() << "if (the_pType == 0) {\n";
+ out << indent() << "::com::sun::star::uno::Type operator()() const\n";
+ out << indent() << "{\n";
+
inc();
if (isPolymorphic()) {
out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent()
@@ -2912,18 +2938,21 @@ void StructureType::dumpComprehensiveGetCppuType(FileStream & out) {
out << ", " << fields << ", the_members);\n";
out << indent() << "::typelib_typedescription_register(&the_newType);\n";
out << indent() << "::typelib_typedescription_release(the_newType);\n";
- out << indent() << "static ::com::sun::star::uno::Type the_staticType("
+
+ out << indent() << "::com::sun::star::uno::Type the_staticType("
<< getTypeClass(m_typeName) << ", the_name);\n";
- out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n";
- out << indent() << "the_pType = &the_staticType;\n";
+ out << indent() << "return the_staticType;\n";
dec();
out << indent() << "}\n";
dec();
- out << indent() << "} else {\n";
- inc();
- out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n";
- dec();
- out << indent() << "}\n" << indent() << "return *the_pType;\n";
+ out << indent() << "};\n";
+
+ if (codemaker::cppumaker::dumpNamespaceClose(out, m_typeName, false)) {
+ out << " }\n\n";
+ }
+
+ dumpGetCppuTypePreamble(out);
+ out << indent() << "return detail::" << sStaticTypeClass << "::get();\n";
dumpGetCppuTypePostamble(out);
}
@@ -3584,15 +3613,18 @@ void EnumType::dumpNormalGetCppuType(FileStream& o)
void EnumType::dumpComprehensiveGetCppuType(FileStream& o)
{
- dumpGetCppuTypePreamble(o);
-
- o << indent() << "static ::com::sun::star::uno::Type * the_pType = 0;\n";
+ if (codemaker::cppumaker::dumpNamespaceOpen(o, m_typeName, false)) {
+ o << " namespace detail {\n\n";
+ }
- o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
+ OString sType = m_typeName.copy(m_typeName.lastIndexOf('/') + 1);
+ OString sStaticTypeClass = "the" + sType + "Type";
+ o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type, " << sStaticTypeClass << " >\n";
+ o << indent() << "{\n";
inc();
- o << indent() << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n";
+ o << indent() << "::com::sun::star::uno::Type operator()() const\n";
+ o << indent() << "{\n";
- o << indent() << "if (the_pType == 0)\n" << indent() << "{\n";
inc();
o << indent() << "::rtl::OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM(\""
<< m_typeName.replace('/', '.') << "\") );\n\n";
@@ -3644,16 +3676,21 @@ void EnumType::dumpComprehensiveGetCppuType(FileStream& o)
o << indent() << "typelib_typedescription_release( pTD );\n"
<< indent() << "// End inline typedescription generation\n\n";
- o << indent() << "static ::com::sun::star::uno::Type the_staticType( "
+ o << indent() << "::com::sun::star::uno::Type the_staticType( "
<< getTypeClass(m_typeName) << ", sTypeName );\n";
- o << indent() << "the_pType = &the_staticType;\n";
+ o << indent() << "return the_staticType;\n";
dec();
o << indent() << "}\n";
dec();
- o << indent() << "}\n\n"
- << indent() << "return *the_pType;\n";
+ o << indent() << "};\n\n";
+ if (codemaker::cppumaker::dumpNamespaceClose(o, m_typeName, false)) {
+ o << " }\n\n";
+ }
+
+ dumpGetCppuTypePreamble(o);
+ o << indent() << "return detail::" << sStaticTypeClass << "::get();\n";
dumpGetCppuTypePostamble(o);
}
diff --git a/codemaker/source/cppumaker/includes.cxx b/codemaker/source/cppumaker/includes.cxx
index 02021e660522..96e8313906d3 100644
--- a/codemaker/source/cppumaker/includes.cxx
+++ b/codemaker/source/cppumaker/includes.cxx
@@ -60,6 +60,7 @@ Includes::Includes(
m_includeRtlTextencH(false), m_includeRtlUstrbufHxx(false),
m_includeRtlUstringH(false),
m_includeRtlUstringHxx(dependencies.hasStringDependency()),
+ m_includeRtlInstanceHxx(false),
m_includeSalTypesH(
dependencies.hasBooleanDependency() || dependencies.hasByteDependency()
|| dependencies.hasShortDependency()
@@ -250,6 +251,10 @@ void Includes::dump(FileStream & out, rtl::OString const * companionHdl) {
dumpEmptyLineBeforeFirst(out, &first);
out << ("#include \"rtl/ustring.hxx\"\n");
}
+ if (m_includeRtlInstanceHxx) {
+ dumpEmptyLineBeforeFirst(out, &first);
+ out << "#include \"rtl/instance.hxx\"\n";
+ }
if (m_includeSalTypesH) {
dumpEmptyLineBeforeFirst(out, &first);
out << "#include \"sal/types.h\"\n";
diff --git a/codemaker/source/cppumaker/includes.hxx b/codemaker/source/cppumaker/includes.hxx
index 075e63057614..c8477a19e10a 100644
--- a/codemaker/source/cppumaker/includes.hxx
+++ b/codemaker/source/cppumaker/includes.hxx
@@ -61,6 +61,7 @@ public:
void addRtlUstrbufHxx() { m_includeRtlUstrbufHxx = true; }
void addRtlUstringH() { m_includeRtlUstringH = true; }
void addRtlUstringHxx() { m_includeRtlUstringHxx = true; }
+ void addRtlInstanceHxx() { m_includeRtlInstanceHxx = true; }
void addSalTypesH() { m_includeSalTypesH = true; }
void addTypelibTypeclassH() { m_includeTypelibTypeclassH = true; }
void addTypelibTypedescriptionH()
@@ -94,6 +95,7 @@ private:
bool m_includeRtlUstrbufHxx;
bool m_includeRtlUstringH;
bool m_includeRtlUstringHxx;
+ bool m_includeRtlInstanceHxx;
bool m_includeSalTypesH;
bool m_includeTypelibTypeclassH;
bool m_includeTypelibTypedescriptionH;