summaryrefslogtreecommitdiff
path: root/desktop/inc
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2013-11-15 12:09:10 +0000
committerMichael Meeks <michael.meeks@collabora.com>2013-11-15 13:45:58 +0000
commit9013a3a76dd773cf3f292267c9aac8046f19f0aa (patch)
tree501cc50731df78ddb44353dc466f1af9a8bbd831 /desktop/inc
parent96e23cb9305da8b00db2587104932ee9d5d3122c (diff)
liblibo: expose a C API for ABI reasons, and wrap with C++.
Change-Id: I7b3bcead05788e663d94724522bfa3f227b15499
Diffstat (limited to 'desktop/inc')
-rw-r--r--desktop/inc/liblibreoffice.h46
-rw-r--r--desktop/inc/liblibreoffice.hxx46
2 files changed, 84 insertions, 8 deletions
diff --git a/desktop/inc/liblibreoffice.h b/desktop/inc/liblibreoffice.h
new file mode 100644
index 000000000000..db3b8358a9af
--- /dev/null
+++ b/desktop/inc/liblibreoffice.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_DESKTOP_INC_LIBLIBREOFFICE_H
+#define INCLUDED_DESKTOP_INC_LIBLIBREOFFICE_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+typedef struct _LibreOffice LibreOffice;
+typedef struct _LibreOfficeDocument LibreOfficeDocument;
+
+struct _LibreOffice {
+ int nSize;
+
+ void (*destroy) (LibreOffice *pThis);
+ int (*initialize) (LibreOffice *pThis,
+ const char *pInstallPath);
+ LibreOfficeDocument *(*documentLoad) (LibreOffice *pThis,
+ const char *pURL);
+ char * (*getError) (LibreOffice *pThis);
+};
+
+struct _LibreOfficeDocument {
+ int nSize;
+
+ void (*destroy) (LibreOfficeDocument *pThis);
+ int (*saveAs) (LibreOfficeDocument *pThis,
+ const char *pUrl, const char *pFormat);
+};
+
+LibreOffice *lo_init (const char *install_path);
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/inc/liblibreoffice.hxx b/desktop/inc/liblibreoffice.hxx
index 28c23476c899..81207ac4eedc 100644
--- a/desktop/inc/liblibreoffice.hxx
+++ b/desktop/inc/liblibreoffice.hxx
@@ -10,30 +10,60 @@
#ifndef INCLUDED_DESKTOP_INC_LIBLIBREOFFICE_HXX
#define INCLUDED_DESKTOP_INC_LIBLIBREOFFICE_HXX
+#include <liblibreoffice.h>
+
+/*
+ * The reasons this C++ code is not as pretty as it could be are:
+ * a) provide a pure C API - that's useful for some people
+ * b) allow ABI stability - C++ vtables are not good for that.
+ * c) avoid C++ types as part of the API.
+ */
+
class LODocument
{
+ LibreOfficeDocument *mpDoc;
public:
- virtual ~LODocument() {}
+ inline LODocument( LibreOfficeDocument *pDoc ) : mpDoc( pDoc ) {}
+ inline ~LODocument() { mpDoc->destroy( mpDoc ); }
// Save as the given format, if format is NULL sniff from ext'n
- virtual bool saveAs (const char *url, const char *format = NULL) = 0;
+ inline bool saveAs( const char *url, const char *format = NULL )
+ {
+ return mpDoc->saveAs( mpDoc, url, format );
+ }
};
class LibLibreOffice
{
+ LibreOffice *mpThis;
public:
- virtual ~LibLibreOffice () {};
+ inline LibLibreOffice( LibreOffice *pThis ) : mpThis( pThis ) {}
+ inline ~LibLibreOffice() { mpThis->destroy( mpThis ); };
- virtual bool initialize (const char *installPath) = 0;
+ inline bool initialize( const char *installPath )
+ {
+ return mpThis->initialize( mpThis, installPath );
+ }
- virtual LODocument *documentLoad (const char *url) = 0;
+ inline LODocument *documentLoad( const char *url )
+ {
+ LibreOfficeDocument *pDoc = mpThis->documentLoad( mpThis, url );
+ if( !pDoc )
+ return NULL;
+ return new LODocument( pDoc );
+ }
// return the last error as a string, free me.
- virtual char *getError() = 0;
-
+ inline char *getError() { return mpThis->getError( mpThis ); }
};
-LibLibreOffice *lo_init (const char *install_path);
+inline LibLibreOffice *lo_cpp_init( const char *install_path )
+{
+ LibreOffice *pThis = lo_init( install_path );
+ if( !pThis || !pThis->nSize > 0 )
+ return NULL;
+ return new LibLibreOffice( pThis );
+}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */