<commit_before>#include <set>
#include "drafter.h"
#include "nan.h"
#include "refractToV8.h"
#include "refract/Element.h"
#include "refract/VisitorUtils.h" // TypeQuery and GetValue<T>
#include "refract/FilterVisitor.h" // Filtering just annotations
#include "refract/Iterate.h"
#include "Serialize.h" // Included because of serialize key for parseResult

using namespace v8;
using namespace refract;

struct v8Wrapper {

    bool sourcemap;
    Local<Value> v8_value;

    v8Wrapper(): sourcemap(false){};

    v8Wrapper(bool sourcemap): sourcemap(sourcemap){};

    void operator()(const NullElement& e);
    void operator()(const StringElement& e);
    void operator()(const NumberElement& e);
    void operator()(const BooleanElement& e);
    void operator()(const MemberElement& e);
    void operator()(const ArrayElement& e);
    void operator()(const EnumElement& e);
    void operator()(const ExtendElement& e);
    void operator()(const OptionElement& e);
    void operator()(const SelectElement& e);
    void operator()(const ObjectElement& e);
    void operator()(const IElement& e) {};
    void operator()(const RefElement& e);
    void operator()(const HolderElement& e);

    template<typename T>
    void operator()(const T& e) {
        static_assert(sizeof(T) == 0, "Unknown Element in v8Wrapper");
    }
};

const std::set<std::string> basic_elements = {
    "null",
    "string",
    "number",
    "boolean",
    "array",
    "object",
    "member"
};

Local<Value> v8_string(const std::string& value)
{
    return Nan::New<String>(value.c_str()).ToLocalChecked();
}

Local<Value> ElementToObject(const IElement* e, bool sourcemap)
{
    v8Wrapper f(sourcemap);
    Visitor v(f);
    e->content(v);
    return f.v8_value;
}

Local<Object> v8ElementCollection(const IElement::MemberElementCollection& collection, bool sourcemap)
{
    typedef IElement::MemberElementCollection::const_iterator iterator;

    Local<Object> result = Nan::New<Object>();

    for (iterator it = collection.begin(); it != collection.end(); ++it) {

        Local<Value> key;
        Local<Value> value;

        StringElement* str = TypeQueryVisitor::as<StringElement>((*it)->value.first);

        if (!sourcemap) {
            if (str && str->value == "sourceMap"){
                continue;
            }
        }

        if (str) {
            key = v8_string(str->value);
        }
        else if ((*it)->value.first) {
            key = ElementToObject((*it)->value.first, sourcemap);
        }

        if ((*it)->value.second) {
            value = ElementToObject((*it)->value.second, sourcemap);
        }

        result->Set(key, value);
    }

    return result;
}

Local<Object> v8Element(const IElement& e, bool sourcemap)
{
    Local<Object> res = Nan::New<Object>();
    res->Set(v8_string("element"), v8_string(e.element()));
    if (e.meta.size() > 0) {
        res->Set(v8_string("meta"), v8ElementCollection(e.meta, sourcemap));
    }

    if (e.element() == "annotation") {
        sourcemap = true;
    }

    if (e.attributes.size() > 0) {
        Local<Object> attrs = v8ElementCollection(e.attributes, sourcemap);
        MaybeLocal<Array> maybeProps = Nan::GetOwnPropertyNames(attrs);
        if (!maybeProps.IsEmpty()) {
            Local<Array> props = maybeProps.ToLocalChecked();
            if (props->Length() > 0) {
                res->Set(v8_string("attributes"), attrs);
            }
        }
    }
    return res;
}

template <typename T>
Local<Object> v8ValueList(const T& e, bool sourcemap)
{
    Local<Object> obj = v8Element(e, sourcemap);

    if (!e.empty()) {
        size_t i = 0;
        Local<Array> array = Nan::New<Array>();
        typedef typename T::ValueType::const_iterator iterator;

        for (iterator it = e.value.begin(); it != e.value.end(); ++i, ++it) {
            array->Set(i, ElementToObject(*it, sourcemap));
        }
        obj->Set(v8_string("content"), array);
    }

    return obj;
}

Local<Value> v8RefElement(const RefElement& e, bool sourcemap)
{
    typedef RefElement::ValueType::const_iterator iterator;
    Local<Object> obj = v8Element(e, sourcemap);

    obj->Set(v8_string("content"), v8_string(e.value));

    return obj;
}

void v8Wrapper::operator()(const NullElement& e)
{
    Local<Object> obj = v8Element(e, sourcemap);
    obj->Set(v8_string("content"), Nan::Null());
    v8_value = obj;
}

void v8Wrapper::operator()(const StringElement& e)
{
    Local<Object> obj = v8Element(e, sourcemap);
    if (!e.empty()) {
        obj->Set(v8_string("content"), v8_string(e.value));
    }
    v8_value = obj;
}

void v8Wrapper::operator()(const NumberElement& e)
{
    Local<Object> obj = v8Element(e, sourcemap);
    if (!e.empty()) {
        obj->Set(v8_string("content"), Nan::New<Number>(e.value));
    }
    v8_value = obj;
}

void v8Wrapper::operator()(const BooleanElement& e)
{
    Local<Object> obj = v8Element(e, sourcemap);
    if (!e.empty()) {
        obj->Set(v8_string("content"), Nan::New<Boolean>(e.value));
    }
    v8_value = obj;
}

void v8Wrapper::operator()(const MemberElement& e)
{
    Local<Object> content = Nan::New<Object>();
    Local<Value> key;
    Local<Value> value;

    if (e.value.first) {
        key = ElementToObject(e.value.first, sourcemap);
    }

    if (e.value.second) {
        value = ElementToObject(e.value.second, sourcemap);
    }

    Local<Object> obj = v8Element(e, sourcemap);
    content->Set(v8_string("key"), key);
    content->Set(v8_string("value"), value);
    obj->Set(v8_string("content"), content);
    v8_value = obj;
}

void v8Wrapper::operator()(const ArrayElement& e)
{
    const ArrayElement::ValueType* val = GetValue<ArrayElement>(e);

    Local<Array> array = Nan::New<Array>();

    size_t i = 0;

    for (ArrayElement::ValueType::const_iterator it = val->begin();
         it != val->end();
         ++i, ++it) {
        if (*it) {
            array->Set(i, ElementToObject(*it, sourcemap));
        }
    }

    Local<Object> res = v8Element(e, sourcemap);
    if (!e.empty()) {
        res->Set(v8_string("content"), array);
    }
    v8_value = res;
}

void v8Wrapper::operator()(const EnumElement& e)
{
    v8_value = v8ValueList(e, sourcemap);
}

void v8Wrapper::operator()(const ExtendElement& e)
{
    throw NotImplemented("ExtendElement serialization Not Implemented");
}

void v8Wrapper::operator()(const OptionElement& e)
{
    v8_value = v8ValueList(e, sourcemap);
}

void v8Wrapper::operator()(const SelectElement& e)
{
    v8_value = v8ValueList(e, sourcemap);
}

void v8Wrapper::operator()(const RefElement& e)
{
    v8_value = v8RefElement(e, sourcemap);
}

void v8Wrapper::operator()(const HolderElement& e)
{

    Local<Object> obj = v8Element(e, sourcemap);

    Local<Array> array = Nan::New<Array>();

    array->Set(0, ElementToObject(e.value, sourcemap));

    obj->Set(v8_string("content"), array);

    v8_value = obj;
}

void v8Wrapper::operator()(const ObjectElement& e)
{
    typedef ObjectElement::ValueType::const_iterator iterator;

    Local<Object> obj = v8Element(e, sourcemap);

    if(!e.value.empty()) {

        if (!e.empty()) {

            Local<Array> array = Nan::New<Array>();
            size_t i = 0;

            for (iterator it = e.value.begin(); it != e.value.end(); ++i, ++it) {
                array->Set(i, ElementToObject(*it, sourcemap));
            }

            obj->Set(v8_string("content"), array);
        }
    }

    v8_value = obj;
}

Local<Value> refract2v8(const IElement* res,
                        drafter_serialize_options serializeOptions)
{
    assert(res);

    v8Wrapper f(serializeOptions.sourcemap);
    Visitor v(f);
    res->content(v);

    return f.v8_value;

}

Local<Value> annotations2v8(const IElement* res)
{
    FilterVisitor filter(query::Element("annotation"));
    Iterate<Children> iterate(filter);

    iterate(*res);

    if (!filter.empty()) {

        std::vector<const IElement*> elements = filter.elements();
        Local<Array> array = Nan::New<Array>();
        size_t i = 0;

        for (std::vector<const IElement*>::const_iterator it = elements.begin();
             it != elements.end();
             ++i, ++it) {

            if (*it) {
                array->Set(i, ElementToObject(*it, true));
            }
        }

        Local<Object> annotations = Nan::New<Object>();
        annotations->Set(v8_string("element"),
                         v8_string(drafter::SerializeKey::ParseResult));
        annotations->Set(v8_string("content"), array);
        return annotations;
    }

    return Nan::Null();
}
<commit_msg>fix: Remove unused typedef<commit_after>#include <set>
#include "drafter.h"
#include "nan.h"
#include "refractToV8.h"
#include "refract/Element.h"
#include "refract/VisitorUtils.h" // TypeQuery and GetValue<T>
#include "refract/FilterVisitor.h" // Filtering just annotations
#include "refract/Iterate.h"
#include "Serialize.h" // Included because of serialize key for parseResult

using namespace v8;
using namespace refract;

struct v8Wrapper {

    bool sourcemap;
    Local<Value> v8_value;

    v8Wrapper(): sourcemap(false){};

    v8Wrapper(bool sourcemap): sourcemap(sourcemap){};

    void operator()(const NullElement& e);
    void operator()(const StringElement& e);
    void operator()(const NumberElement& e);
    void operator()(const BooleanElement& e);
    void operator()(const MemberElement& e);
    void operator()(const ArrayElement& e);
    void operator()(const EnumElement& e);
    void operator()(const ExtendElement& e);
    void operator()(const OptionElement& e);
    void operator()(const SelectElement& e);
    void operator()(const ObjectElement& e);
    void operator()(const IElement& e) {};
    void operator()(const RefElement& e);
    void operator()(const HolderElement& e);

    template<typename T>
    void operator()(const T& e) {
        static_assert(sizeof(T) == 0, "Unknown Element in v8Wrapper");
    }
};

const std::set<std::string> basic_elements = {
    "null",
    "string",
    "number",
    "boolean",
    "array",
    "object",
    "member"
};

Local<Value> v8_string(const std::string& value)
{
    return Nan::New<String>(value.c_str()).ToLocalChecked();
}

Local<Value> ElementToObject(const IElement* e, bool sourcemap)
{
    v8Wrapper f(sourcemap);
    Visitor v(f);
    e->content(v);
    return f.v8_value;
}

Local<Object> v8ElementCollection(const IElement::MemberElementCollection& collection, bool sourcemap)
{
    typedef IElement::MemberElementCollection::const_iterator iterator;

    Local<Object> result = Nan::New<Object>();

    for (iterator it = collection.begin(); it != collection.end(); ++it) {

        Local<Value> key;
        Local<Value> value;

        StringElement* str = TypeQueryVisitor::as<StringElement>((*it)->value.first);

        if (!sourcemap) {
            if (str && str->value == "sourceMap"){
                continue;
            }
        }

        if (str) {
            key = v8_string(str->value);
        }
        else if ((*it)->value.first) {
            key = ElementToObject((*it)->value.first, sourcemap);
        }

        if ((*it)->value.second) {
            value = ElementToObject((*it)->value.second, sourcemap);
        }

        result->Set(key, value);
    }

    return result;
}

Local<Object> v8Element(const IElement& e, bool sourcemap)
{
    Local<Object> res = Nan::New<Object>();
    res->Set(v8_string("element"), v8_string(e.element()));
    if (e.meta.size() > 0) {
        res->Set(v8_string("meta"), v8ElementCollection(e.meta, sourcemap));
    }

    if (e.element() == "annotation") {
        sourcemap = true;
    }

    if (e.attributes.size() > 0) {
        Local<Object> attrs = v8ElementCollection(e.attributes, sourcemap);
        MaybeLocal<Array> maybeProps = Nan::GetOwnPropertyNames(attrs);
        if (!maybeProps.IsEmpty()) {
            Local<Array> props = maybeProps.ToLocalChecked();
            if (props->Length() > 0) {
                res->Set(v8_string("attributes"), attrs);
            }
        }
    }
    return res;
}

template <typename T>
Local<Object> v8ValueList(const T& e, bool sourcemap)
{
    Local<Object> obj = v8Element(e, sourcemap);

    if (!e.empty()) {
        size_t i = 0;
        Local<Array> array = Nan::New<Array>();
        typedef typename T::ValueType::const_iterator iterator;

        for (iterator it = e.value.begin(); it != e.value.end(); ++i, ++it) {
            array->Set(i, ElementToObject(*it, sourcemap));
        }
        obj->Set(v8_string("content"), array);
    }

    return obj;
}

Local<Value> v8RefElement(const RefElement& e, bool sourcemap)
{
    Local<Object> obj = v8Element(e, sourcemap);

    obj->Set(v8_string("content"), v8_string(e.value));

    return obj;
}

void v8Wrapper::operator()(const NullElement& e)
{
    Local<Object> obj = v8Element(e, sourcemap);
    obj->Set(v8_string("content"), Nan::Null());
    v8_value = obj;
}

void v8Wrapper::operator()(const StringElement& e)
{
    Local<Object> obj = v8Element(e, sourcemap);
    if (!e.empty()) {
        obj->Set(v8_string("content"), v8_string(e.value));
    }
    v8_value = obj;
}

void v8Wrapper::operator()(const NumberElement& e)
{
    Local<Object> obj = v8Element(e, sourcemap);
    if (!e.empty()) {
        obj->Set(v8_string("content"), Nan::New<Number>(e.value));
    }
    v8_value = obj;
}

void v8Wrapper::operator()(const BooleanElement& e)
{
    Local<Object> obj = v8Element(e, sourcemap);
    if (!e.empty()) {
        obj->Set(v8_string("content"), Nan::New<Boolean>(e.value));
    }
    v8_value = obj;
}

void v8Wrapper::operator()(const MemberElement& e)
{
    Local<Object> content = Nan::New<Object>();
    Local<Value> key;
    Local<Value> value;

    if (e.value.first) {
        key = ElementToObject(e.value.first, sourcemap);
    }

    if (e.value.second) {
        value = ElementToObject(e.value.second, sourcemap);
    }

    Local<Object> obj = v8Element(e, sourcemap);
    content->Set(v8_string("key"), key);
    content->Set(v8_string("value"), value);
    obj->Set(v8_string("content"), content);
    v8_value = obj;
}

void v8Wrapper::operator()(const ArrayElement& e)
{
    const ArrayElement::ValueType* val = GetValue<ArrayElement>(e);

    Local<Array> array = Nan::New<Array>();

    size_t i = 0;

    for (ArrayElement::ValueType::const_iterator it = val->begin();
         it != val->end();
         ++i, ++it) {
        if (*it) {
            array->Set(i, ElementToObject(*it, sourcemap));
        }
    }

    Local<Object> res = v8Element(e, sourcemap);
    if (!e.empty()) {
        res->Set(v8_string("content"), array);
    }
    v8_value = res;
}

void v8Wrapper::operator()(const EnumElement& e)
{
    v8_value = v8ValueList(e, sourcemap);
}

void v8Wrapper::operator()(const ExtendElement& e)
{
    throw NotImplemented("ExtendElement serialization Not Implemented");
}

void v8Wrapper::operator()(const OptionElement& e)
{
    v8_value = v8ValueList(e, sourcemap);
}

void v8Wrapper::operator()(const SelectElement& e)
{
    v8_value = v8ValueList(e, sourcemap);
}

void v8Wrapper::operator()(const RefElement& e)
{
    v8_value = v8RefElement(e, sourcemap);
}

void v8Wrapper::operator()(const HolderElement& e)
{

    Local<Object> obj = v8Element(e, sourcemap);

    Local<Array> array = Nan::New<Array>();

    array->Set(0, ElementToObject(e.value, sourcemap));

    obj->Set(v8_string("content"), array);

    v8_value = obj;
}

void v8Wrapper::operator()(const ObjectElement& e)
{
    typedef ObjectElement::ValueType::const_iterator iterator;

    Local<Object> obj = v8Element(e, sourcemap);

    if(!e.value.empty()) {

        if (!e.empty()) {

            Local<Array> array = Nan::New<Array>();
            size_t i = 0;

            for (iterator it = e.value.begin(); it != e.value.end(); ++i, ++it) {
                array->Set(i, ElementToObject(*it, sourcemap));
            }

            obj->Set(v8_string("content"), array);
        }
    }

    v8_value = obj;
}

Local<Value> refract2v8(const IElement* res,
                        drafter_serialize_options serializeOptions)
{
    assert(res);

    v8Wrapper f(serializeOptions.sourcemap);
    Visitor v(f);
    res->content(v);

    return f.v8_value;

}

Local<Value> annotations2v8(const IElement* res)
{
    FilterVisitor filter(query::Element("annotation"));
    Iterate<Children> iterate(filter);

    iterate(*res);

    if (!filter.empty()) {

        std::vector<const IElement*> elements = filter.elements();
        Local<Array> array = Nan::New<Array>();
        size_t i = 0;

        for (std::vector<const IElement*>::const_iterator it = elements.begin();
             it != elements.end();
             ++i, ++it) {

            if (*it) {
                array->Set(i, ElementToObject(*it, true));
            }
        }

        Local<Object> annotations = Nan::New<Object>();
        annotations->Set(v8_string("element"),
                         v8_string(drafter::SerializeKey::ParseResult));
        annotations->Set(v8_string("content"), array);
        return annotations;
    }

    return Nan::Null();
}
<|endoftext|>


<commit_before>#include "diskio.hpp"
#include <string.h>

//
// System-independent functions
//

DiskIO::DiskIO()
{
    hDisk=0;
    is_open=false;

    memset(&disk_geometry,0,sizeof(GEOMETRY));
}

int DiskIO::Open(const char* disk)
{
    if(open_handle(disk)!=0)
        return ERR_OPEN_DISK;
    if(get_geometry()!=0)
        return ERR_GET_DISK_GEOMETRY;
    is_open=true;
    disk_image=false;
    return 0;
}

int DiskIO::Open(const char *disk, GEOMETRY geom)
{
    if(open_handle(disk)!=0)
        return ERR_OPEN_DISK;
    disk_geometry=geom;
    is_open=true;
    disk_image=true;
    return 0;
}

int  DiskIO::GetDiskSize(uint64_t &length)
{
    int ret = get_disk_length(length);
    if(ret!=0)
        return ERR_GET_DISK_SIZE;
    length/=disk_geometry.bps;
    return ret;
}

bool DiskIO::IsOpen()
{
    return is_open;
}

void DiskIO::Close()
{
    close_handle();
    is_open=false;
    disk_image=false;
}

const GEOMETRY &DiskIO::GetDiskGeometry()
{
    return disk_geometry;
}

int DiskIO::Seek(uint64_t pos)
{
    return seek(pos);
}

int DiskIO::Read(void *buff,uint32_t buffer_size)
{
    return read(buff,buffer_size);
}

int DiskIO::Write(const void *buff,uint32_t buffer_size)
{
    return write(buff,buffer_size);
}

void DiskIO::Sync()
{
    sync();
}

<commit_msg>Sync() on close; added SeekSector() function<commit_after>#include "diskio.hpp"
#include <string.h>

DiskIO::DiskIO()
{
    hDisk=0;
    is_open=false;

    memset(&disk_geometry,0,sizeof(GEOMETRY));
}

int DiskIO::Open(const char* disk)
{
    if(open_handle(disk)!=0)
        return ERR_OPEN_DISK;
    if(get_geometry()!=0)
        return ERR_GET_DISK_GEOMETRY;
    is_open=true;
    disk_image=false;
    return 0;
}

int DiskIO::Open(const char *disk, GEOMETRY geom)
{
    if(open_handle(disk)!=0)
        return ERR_OPEN_DISK;
    disk_geometry=geom;
    is_open=true;
    disk_image=true;
    return 0;
}

int  DiskIO::GetDiskSize(uint64_t &length)
{
    int ret = get_disk_length(length);
    if(ret!=0)
        return ERR_GET_DISK_SIZE;
    length/=disk_geometry.bps;
    return ret;
}

bool DiskIO::IsOpen()
{
    return is_open;
}

void DiskIO::Close()
{
    Sync();
    close_handle();
    is_open=false;
    disk_image=false;
}

const GEOMETRY &DiskIO::GetDiskGeometry()
{
    return disk_geometry;
}

int DiskIO::Seek(uint64_t pos)
{
   return seek(pos);
}

int DiskIO::SeekSector(uint64_t sector)
{
   return seek(sector*disk_geometry.bps);
}

int DiskIO::Read(void *buff,uint32_t buffer_size)
{
    return read(buff,buffer_size);
}

int DiskIO::Write(const void *buff,uint32_t buffer_size)
{
    return write(buff,buffer_size);
}

void DiskIO::Sync()
{
    sync();
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: formlinkdialog.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: kz $ $Date: 2008-03-05 17:11:08 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
#define EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX

#ifndef _SV_DIALOG_HXX
#include <vcl/dialog.hxx>
#endif
#ifndef _SV_FIXED_HXX
#include <vcl/fixed.hxx>
#endif
#ifndef _SV_BUTTON_HXX
#include <vcl/button.hxx>
#endif

/** === begin UNO includes === **/
#ifndef _COM_SUN_STAR_FORM_XFORM_HPP_
#include <com/sun/star/form/XForm.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
/** === end UNO includes === **/

#include <memory>

//............................................................................
namespace pcr
{
//............................................................................

    class FieldLinkRow;
    //========================================================================
    //= FormLinkDialog
    //========================================================================
    class FormLinkDialog : public ModalDialog
    {
    private:
        FixedText                       m_aExplanation;
        FixedText                       m_aDetailLabel;
        FixedText                       m_aMasterLabel;
        ::std::auto_ptr< FieldLinkRow > m_aRow1;
        ::std::auto_ptr< FieldLinkRow > m_aRow2;
        ::std::auto_ptr< FieldLinkRow > m_aRow3;
        ::std::auto_ptr< FieldLinkRow > m_aRow4;
        OKButton                        m_aOK;
        CancelButton                    m_aCancel;
        HelpButton                      m_aHelp;
        PushButton                      m_aSuggest;

        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
                                        m_xORB;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
                                        m_xDetailForm;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
                                        m_xMasterForm;

        ::com::sun::star::uno::Sequence< ::rtl::OUString >
                                        m_aRelationDetailColumns;
        ::com::sun::star::uno::Sequence< ::rtl::OUString >
                                        m_aRelationMasterColumns;

        ::rtl::OUString                 m_sDetailLabel;
        ::rtl::OUString                 m_sMasterLabel;

    public:
        FormLinkDialog(
            Window* _pParent,
            const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDetailForm,
            const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxMasterForm,
            const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
            const ::rtl::OUString& _sExplanation = ::rtl::OUString(),
            const ::rtl::OUString& _sDetailLabel = ::rtl::OUString(),
            const ::rtl::OUString& _sMasterLabel = ::rtl::OUString()
        );
        ~FormLinkDialog( );

        // Dialog overridables
        virtual short   Execute();

    private:
        DECL_LINK( OnSuggest,          void*         );
        DECL_LINK( OnFieldChanged,     FieldLinkRow* );
        DECL_LINK( OnInitialize, void*         );

        void        updateOkButton();
        void        initializeFieldLists();
        void        initializeColumnLabels();
        void        initializeLinks();
        void        initializeSuggest();
        void        commitLinkPairs();

        void        initializeFieldRowsFrom(
                        ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rDetailFields,
                        ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rMasterFields
                    );

        String      getFormDataSourceType(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm
                    ) const SAL_THROW(());

        void        getFormFields(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm,
                            ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rNames
                    ) const SAL_THROW(());

        void        ensureFormConnection(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps,
                            ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& /* [out] */ _rxConnection
                    ) const SAL_THROW(( ::com::sun::star::uno::Exception ));

        void        getConnectionMetaData(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps,
                            ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& /* [out] */ _rxMeta
                    ) const SAL_THROW(( ::com::sun::star::uno::Exception ));

        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
                    getCanonicUnderlyingTable( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps ) const;
        sal_Bool    getExistingRelation(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxLHS,
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxRHS,
                        ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rLeftFields,
                        ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rRightFields
                    ) const;
    };

//............................................................................
}   // namespace pcr
//............................................................................

#endif // EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
<commit_msg>INTEGRATION: CWS changefileheader (1.4.14); FILE MERGED 2008/04/01 15:15:17 thb 1.4.14.3: #i85898# Stripping all external header guards 2008/04/01 12:29:49 thb 1.4.14.2: #i85898# Stripping all external header guards 2008/03/31 12:31:43 rt 1.4.14.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: formlinkdialog.hxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
#define EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX

#include <vcl/dialog.hxx>
#include <vcl/fixed.hxx>
#ifndef _SV_BUTTON_HXX
#include <vcl/button.hxx>
#endif

/** === begin UNO includes === **/
#include <com/sun/star/form/XForm.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sdbc/XConnection.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
/** === end UNO includes === **/

#include <memory>

//............................................................................
namespace pcr
{
//............................................................................

    class FieldLinkRow;
    //========================================================================
    //= FormLinkDialog
    //========================================================================
    class FormLinkDialog : public ModalDialog
    {
    private:
        FixedText                       m_aExplanation;
        FixedText                       m_aDetailLabel;
        FixedText                       m_aMasterLabel;
        ::std::auto_ptr< FieldLinkRow > m_aRow1;
        ::std::auto_ptr< FieldLinkRow > m_aRow2;
        ::std::auto_ptr< FieldLinkRow > m_aRow3;
        ::std::auto_ptr< FieldLinkRow > m_aRow4;
        OKButton                        m_aOK;
        CancelButton                    m_aCancel;
        HelpButton                      m_aHelp;
        PushButton                      m_aSuggest;

        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
                                        m_xORB;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
                                        m_xDetailForm;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
                                        m_xMasterForm;

        ::com::sun::star::uno::Sequence< ::rtl::OUString >
                                        m_aRelationDetailColumns;
        ::com::sun::star::uno::Sequence< ::rtl::OUString >
                                        m_aRelationMasterColumns;

        ::rtl::OUString                 m_sDetailLabel;
        ::rtl::OUString                 m_sMasterLabel;

    public:
        FormLinkDialog(
            Window* _pParent,
            const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDetailForm,
            const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxMasterForm,
            const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
            const ::rtl::OUString& _sExplanation = ::rtl::OUString(),
            const ::rtl::OUString& _sDetailLabel = ::rtl::OUString(),
            const ::rtl::OUString& _sMasterLabel = ::rtl::OUString()
        );
        ~FormLinkDialog( );

        // Dialog overridables
        virtual short   Execute();

    private:
        DECL_LINK( OnSuggest,          void*         );
        DECL_LINK( OnFieldChanged,     FieldLinkRow* );
        DECL_LINK( OnInitialize, void*         );

        void        updateOkButton();
        void        initializeFieldLists();
        void        initializeColumnLabels();
        void        initializeLinks();
        void        initializeSuggest();
        void        commitLinkPairs();

        void        initializeFieldRowsFrom(
                        ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rDetailFields,
                        ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rMasterFields
                    );

        String      getFormDataSourceType(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm
                    ) const SAL_THROW(());

        void        getFormFields(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxForm,
                            ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rNames
                    ) const SAL_THROW(());

        void        ensureFormConnection(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps,
                            ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& /* [out] */ _rxConnection
                    ) const SAL_THROW(( ::com::sun::star::uno::Exception ));

        void        getConnectionMetaData(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps,
                            ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& /* [out] */ _rxMeta
                    ) const SAL_THROW(( ::com::sun::star::uno::Exception ));

        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
                    getCanonicUnderlyingTable( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxFormProps ) const;
        sal_Bool    getExistingRelation(
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxLHS,
                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxRHS,
                        ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rLeftFields,
                        ::com::sun::star::uno::Sequence< ::rtl::OUString >& /* [out] */ _rRightFields
                    ) const;
    };

//............................................................................
}   // namespace pcr
//............................................................................

#endif // EXTENSIONS_SOURCE_PROPCTRLR_FORMLINKDIALOG_HXX
<|endoftext|>


<commit_before>/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "filterdetect.hxx"
#include <osl/diagnose.h>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/document/XExtendedFilterDetection.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/beans/PropertyState.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <ucbhelper/content.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <boost/scoped_ptr.hpp>

using namespace com::sun::star::container;
using namespace com::sun::star::uno;
using namespace com::sun::star::beans;

namespace {

OUString supportedByType( const OUString& clipBoardFormat,  const OUString& resultString, const OUString& checkType)
{
    OUString sTypeName;
    if ( clipBoardFormat.match("doctype:") )
    {
        OUString tryStr = clipBoardFormat.copy(8);
        if (resultString.indexOf(tryStr) >= 0)
        {
            sTypeName = checkType;
        }
    }
    return sTypeName;
}

}

OUString SAL_CALL FilterDetect::detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& aArguments ) throw( com::sun::star::uno::RuntimeException, std::exception )
{
    OUString sTypeName;
    OUString sUrl;
    Sequence<PropertyValue > lProps ;

    com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInStream;
    const PropertyValue * pValue = aArguments.getConstArray();
    sal_Int32 nLength;
    OUString resultString;

    nLength = aArguments.getLength();
    sal_Int32 location=nLength;
    for (sal_Int32 i = 0 ; i < nLength; i++)
    {
        if ( pValue[i].Name == "TypeName" )
        {
            location=i;
        }
        else if ( pValue[i].Name == "URL" )
        {
            pValue[i].Value >>= sUrl;
        }
        else if ( pValue[i].Name == "InputStream" )
        {
            pValue[i].Value >>= xInStream ;
        }
    }
    try
    {
        if (!xInStream.is())
        {
            ::ucbhelper::Content aContent(
                sUrl, Reference< com::sun::star::ucb::XCommandEnvironment >(),
                mxCtx);
            xInStream = aContent.openStream();
            if (!xInStream.is())
            {
                return sTypeName;
            }
        }

        ::boost::scoped_ptr< SvStream > pInStream( ::utl::UcbStreamHelper::CreateStream( xInStream ) );
        pInStream->StartReadingUnicodeText( RTL_TEXTENCODING_DONTKNOW );
        sal_Size nUniPos = pInStream->Tell();

        const sal_uInt16 nSize = 4000;
        bool  bTryUtf16 = false;

        if ( nUniPos == 0 ) // No BOM detected, try to guess UTF-16 endianness
        {
            sal_uInt16 nHeader = 0;
            pInStream->ReadUInt16( nHeader );
            if ( nHeader == 0x003C )
                bTryUtf16 = true;
            else if ( nHeader == 0x3C00 )
            {
                bTryUtf16 = true;
                pInStream->SetEndianSwap( !pInStream->IsEndianSwap() );
            }
            pInStream->Seek( STREAM_SEEK_TO_BEGIN );
        }

        if ( nUniPos == 3 || ( nUniPos == 0 && !bTryUtf16 ) ) // UTF-8 or non-Unicode
            resultString = OStringToOUString( read_uInt8s_ToOString( *pInStream, nSize ), RTL_TEXTENCODING_UTF8 );
        else if ( nUniPos == 2 || bTryUtf16 ) // UTF-16
            resultString = read_uInt16s_ToOUString( *pInStream, nSize );

        if ( !resultString.startsWith( "<?xml" ) )
            // This is not an XML stream.  It makes no sense to try to detect
            // a non-XML file type here.
            return OUString();

        // test typedetect code
        Reference <XNameAccess> xTypeCont(mxCtx->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", mxCtx), UNO_QUERY);
        Sequence < OUString > myTypes= xTypeCont->getElementNames();
        nLength = myTypes.getLength();

        sal_Int32 new_nlength=0;
        sal_Int32 i = 0 ;
        while ((i < nLength) && (sTypeName.isEmpty()))
        {
            Any elem = xTypeCont->getByName(myTypes[i]);
            elem >>=lProps;
            new_nlength = lProps.getLength();
            sal_Int32 j =0;
            while (j < new_nlength && (sTypeName.isEmpty()))
            {
                OUString tmpStr;
                lProps[j].Value >>=tmpStr;
                if ( lProps[j].Name == "ClipboardFormat" && !tmpStr.isEmpty() )
                {
                    sTypeName = supportedByType(tmpStr,resultString, myTypes[i]);
                }
                j++;
            }
            i++;
        }
    }
    catch (const Exception &)
    {
        OSL_FAIL( "An Exception occurred while opening File stream" );
    }

    if (!sTypeName.isEmpty())
    {
        if (location == aArguments.getLength())
        {
            aArguments.realloc(nLength+1);
            aArguments[location].Name = "TypeName";
        }
        aArguments[location].Value <<=sTypeName;
    }

    return sTypeName;
}

// XInitialization
void SAL_CALL FilterDetect::initialize( const Sequence< Any >& /*aArguments*/ )
    throw (Exception, RuntimeException, std::exception)
{
}

OUString FilterDetect_getImplementationName ()
{
    return OUString( "com.sun.star.comp.filters.XMLFilterDetect" );
}

Sequence< OUString > FilterDetect_getSupportedServiceNames()
{
    Sequence < OUString > aRet(1);
    aRet[0] = "com.sun.star.document.ExtendedTypeDetection";
    return aRet;
}

Reference< XInterface > FilterDetect_createInstance( const Reference< XComponentContext > & context)
{
    return static_cast< cppu::OWeakObject * >( new FilterDetect( context ) );
}

// XServiceInfo
OUString SAL_CALL FilterDetect::getImplementationName(  )
    throw (RuntimeException, std::exception)
{
    return FilterDetect_getImplementationName();
}

sal_Bool SAL_CALL FilterDetect::supportsService( const OUString& rServiceName )
    throw (RuntimeException, std::exception)
{
    return cppu::supportsService( this, rServiceName );
}

Sequence< OUString > SAL_CALL FilterDetect::getSupportedServiceNames(  )
    throw (RuntimeException, std::exception)
{
    return FilterDetect_getSupportedServiceNames();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>filter: use more appropriate conversion from ASCII for arbitrary input<commit_after>/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "filterdetect.hxx"
#include <osl/diagnose.h>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/document/XExtendedFilterDetection.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/beans/PropertyState.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <ucbhelper/content.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <boost/scoped_ptr.hpp>

using namespace com::sun::star::container;
using namespace com::sun::star::uno;
using namespace com::sun::star::beans;

namespace {

OUString supportedByType( const OUString& clipBoardFormat,  const OUString& resultString, const OUString& checkType)
{
    OUString sTypeName;
    if ( clipBoardFormat.match("doctype:") )
    {
        OUString tryStr = clipBoardFormat.copy(8);
        if (resultString.indexOf(tryStr) >= 0)
        {
            sTypeName = checkType;
        }
    }
    return sTypeName;
}

}

OUString SAL_CALL FilterDetect::detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& aArguments ) throw( com::sun::star::uno::RuntimeException, std::exception )
{
    OUString sTypeName;
    OUString sUrl;
    Sequence<PropertyValue > lProps ;

    com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInStream;
    const PropertyValue * pValue = aArguments.getConstArray();
    sal_Int32 nLength;
    OUString resultString;

    nLength = aArguments.getLength();
    sal_Int32 location=nLength;
    for (sal_Int32 i = 0 ; i < nLength; i++)
    {
        if ( pValue[i].Name == "TypeName" )
        {
            location=i;
        }
        else if ( pValue[i].Name == "URL" )
        {
            pValue[i].Value >>= sUrl;
        }
        else if ( pValue[i].Name == "InputStream" )
        {
            pValue[i].Value >>= xInStream ;
        }
    }
    try
    {
        if (!xInStream.is())
        {
            ::ucbhelper::Content aContent(
                sUrl, Reference< com::sun::star::ucb::XCommandEnvironment >(),
                mxCtx);
            xInStream = aContent.openStream();
            if (!xInStream.is())
            {
                return sTypeName;
            }
        }

        ::boost::scoped_ptr< SvStream > pInStream( ::utl::UcbStreamHelper::CreateStream( xInStream ) );
        pInStream->StartReadingUnicodeText( RTL_TEXTENCODING_DONTKNOW );
        sal_Size nUniPos = pInStream->Tell();

        const sal_uInt16 nSize = 4000;
        bool  bTryUtf16 = false;

        if ( nUniPos == 0 ) // No BOM detected, try to guess UTF-16 endianness
        {
            sal_uInt16 nHeader = 0;
            pInStream->ReadUInt16( nHeader );
            if ( nHeader == 0x003C )
                bTryUtf16 = true;
            else if ( nHeader == 0x3C00 )
            {
                bTryUtf16 = true;
                pInStream->SetEndianSwap( !pInStream->IsEndianSwap() );
            }
            pInStream->Seek( STREAM_SEEK_TO_BEGIN );
        }

        if ( nUniPos == 3 || ( nUniPos == 0 && !bTryUtf16 ) ) // UTF-8 or non-Unicode
        {
            OString const str(read_uInt8s_ToOString(*pInStream, nSize));
            resultString = OUString(str.getStr(), str.getLength(),
                RTL_TEXTENCODING_ASCII_US,
                RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT|RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT|RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT);
        }
        else if ( nUniPos == 2 || bTryUtf16 ) // UTF-16
            resultString = read_uInt16s_ToOUString( *pInStream, nSize );

        if ( !resultString.startsWith( "<?xml" ) )
            // This is not an XML stream.  It makes no sense to try to detect
            // a non-XML file type here.
            return OUString();

        // test typedetect code
        Reference <XNameAccess> xTypeCont(mxCtx->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", mxCtx), UNO_QUERY);
        Sequence < OUString > myTypes= xTypeCont->getElementNames();
        nLength = myTypes.getLength();

        sal_Int32 new_nlength=0;
        sal_Int32 i = 0 ;
        while ((i < nLength) && (sTypeName.isEmpty()))
        {
            Any elem = xTypeCont->getByName(myTypes[i]);
            elem >>=lProps;
            new_nlength = lProps.getLength();
            sal_Int32 j =0;
            while (j < new_nlength && (sTypeName.isEmpty()))
            {
                OUString tmpStr;
                lProps[j].Value >>=tmpStr;
                if ( lProps[j].Name == "ClipboardFormat" && !tmpStr.isEmpty() )
                {
                    sTypeName = supportedByType(tmpStr,resultString, myTypes[i]);
                }
                j++;
            }
            i++;
        }
    }
    catch (const Exception &)
    {
        OSL_FAIL( "An Exception occurred while opening File stream" );
    }

    if (!sTypeName.isEmpty())
    {
        if (location == aArguments.getLength())
        {
            aArguments.realloc(nLength+1);
            aArguments[location].Name = "TypeName";
        }
        aArguments[location].Value <<=sTypeName;
    }

    return sTypeName;
}

// XInitialization
void SAL_CALL FilterDetect::initialize( const Sequence< Any >& /*aArguments*/ )
    throw (Exception, RuntimeException, std::exception)
{
}

OUString FilterDetect_getImplementationName ()
{
    return OUString( "com.sun.star.comp.filters.XMLFilterDetect" );
}

Sequence< OUString > FilterDetect_getSupportedServiceNames()
{
    Sequence < OUString > aRet(1);
    aRet[0] = "com.sun.star.document.ExtendedTypeDetection";
    return aRet;
}

Reference< XInterface > FilterDetect_createInstance( const Reference< XComponentContext > & context)
{
    return static_cast< cppu::OWeakObject * >( new FilterDetect( context ) );
}

// XServiceInfo
OUString SAL_CALL FilterDetect::getImplementationName(  )
    throw (RuntimeException, std::exception)
{
    return FilterDetect_getImplementationName();
}

sal_Bool SAL_CALL FilterDetect::supportsService( const OUString& rServiceName )
    throw (RuntimeException, std::exception)
{
    return cppu::supportsService( this, rServiceName );
}

Sequence< OUString > SAL_CALL FilterDetect::getSupportedServiceNames(  )
    throw (RuntimeException, std::exception)
{
    return FilterDetect_getSupportedServiceNames();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before><commit_msg>add sprites with manipulations<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: formenums.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: rt $ $Date: 2003-12-01 12:04:24 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _XMLOFF_FORMENUMS_HXX_
#define _XMLOFF_FORMENUMS_HXX_

#ifndef _XMLOFF_XMLEMENT_HXX
#include "xmlement.hxx"
#endif

//.........................................................................
namespace xmloff
{
//.........................................................................

    //=====================================================================
    //= OEnumMapper
    //=====================================================================
    class OEnumMapper
    {
    public:
        enum EnumProperties
        {
            epSubmitEncoding = 0,
            epSubmitMethod,
            epCommandType,
            epNavigationType,
            epTabCyle,
            epButtonType,
            epListSourceType,
            epCheckState,
            epTextAlign,
            epBorderWidth,
            epFontEmphasis,
            epFontRelief,
            epListLinkageType,

            KNOWN_ENUM_PROPERTIES
        };

    private:
        static const SvXMLEnumMapEntry* s_pEnumMap[KNOWN_ENUM_PROPERTIES];

    public:
        static const SvXMLEnumMapEntry* getEnumMap(EnumProperties _eProperty);
    };

//.........................................................................
}   // namespace xmloff
//.........................................................................

#endif // _XMLOFF_FORMENUMS_HXX_

/*************************************************************************
 * history:
 *  $Log: not supported by cvs2svn $
 *  Revision 1.7.24.2  2003/11/24 15:14:27  obo
 *  undo last change
 *
 *  Revision 1.7  2003/10/21 08:39:48  obo
 *  INTEGRATION: CWS formcelllinkage (1.6.190); FILE MERGED
 *  2003/10/01 09:55:22 fs 1.6.190.1: #i18994# merging the changes from the CWS fs002
 *
 *  Revision 1.6.190.1  2003/10/01 09:55:22  fs
 *  #i18994# merging the changes from the CWS fs002
 *
 *  Revision 1.6.186.1  2003/09/25 14:28:40  fs
 *  #18994# merging the changes from cws_srx645_fs002 branch
 *
 *  Revision 1.6.182.1  2003/09/18 14:00:38  fs
 *  #18995# changes for binding list boxes to cells, while exchanging selection indexes instead of strings
 *
 *  Revision 1.6  2001/06/07 12:25:52  fs
 *  #86096# enums for FontEmphasis and FontRelief
 *
 *  Revision 1.5  2000/12/19 12:13:57  fs
 *  some changes ... now the exported styles are XSL conform
 *
 *  Revision 1.4  2000/12/19 08:42:19  fs
 *  removed the epFontWidth
 *
 *  Revision 1.3  2000/12/18 15:14:35  fs
 *  some changes ... now exporting/importing styles
 *
 *  Revision 1.2  2000/12/06 17:28:05  fs
 *  changes for the formlayer import - still under construction
 *
 *  Revision 1.1  2000/11/17 19:02:06  fs
 *  initial checkin - export and/or import the applications form layer
 *
 *
 *  Revision 1.0 15.11.00 11:49:51  fs
 ************************************************************************/

<commit_msg>INTEGRATION: CWS frmcontrols01 (1.7.4); FILE MERGED 2003/10/29 07:02:32 fs 1.7.4.1: #i21605# value-range: orientation exported as attribute, not as generic property<commit_after>/*************************************************************************
 *
 *  $RCSfile: formenums.hxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: kz $ $Date: 2003-12-11 13:54:32 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _XMLOFF_FORMENUMS_HXX_
#define _XMLOFF_FORMENUMS_HXX_

#ifndef _XMLOFF_XMLEMENT_HXX
#include "xmlement.hxx"
#endif

//.........................................................................
namespace xmloff
{
//.........................................................................

    //=====================================================================
    //= OEnumMapper
    //=====================================================================
    class OEnumMapper
    {
    public:
        enum EnumProperties
        {
            epSubmitEncoding = 0,
            epSubmitMethod,
            epCommandType,
            epNavigationType,
            epTabCyle,
            epButtonType,
            epListSourceType,
            epCheckState,
            epTextAlign,
            epBorderWidth,
            epFontEmphasis,
            epFontRelief,
            epListLinkageType,
            epOrientation,

            KNOWN_ENUM_PROPERTIES
        };

    private:
        static const SvXMLEnumMapEntry* s_pEnumMap[KNOWN_ENUM_PROPERTIES];

    public:
        static const SvXMLEnumMapEntry* getEnumMap(EnumProperties _eProperty);
    };

//.........................................................................
}   // namespace xmloff
//.........................................................................

#endif // _XMLOFF_FORMENUMS_HXX_

<|endoftext|>


<commit_before>/*********************************************************************************
 *
 * Inviwo - Interactive Visualization Workshop
 *
 * Copyright (c) 2017 Inviwo Foundation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *********************************************************************************/

#include <modules/base/io/ivfsequencevolumereader.h>
#include <modules/base/io/ivfvolumewriter.h>

namespace inviwo {
IvfSequenceVolumeReader::IvfSequenceVolumeReader() {
    addExtension({"ivfs", "Sequence of Inviwo ivf volumes"});
}

std::shared_ptr<VolumeSequence> IvfSequenceVolumeReader::readData(const std::string &filePath) {
    std::string fileName = filePath;
    if (!filesystem::fileExists(fileName)) {
        std::string newPath = filesystem::addBasePath(fileName);

        if (filesystem::fileExists(newPath)) {
            fileName = newPath;
        } else {
            throw DataReaderException("Error could not find input file: " + fileName, IvwContext);
        }
    }

    auto volumes = std::make_shared<VolumeSequence>();

    auto dir = filesystem::getFileDirectory(fileName);

    std::vector<std::string> filenames;
    Deserializer d(fileName);
    d.deserialize("volumes", filenames , "volume");
    for (auto filename : filenames) {
        auto abs = filesystem::cleanupPath( dir + "/" + filename);
        volumes->push_back(reader_.readData(abs));
    }

    return volumes;
}

}  // namespace inviwo
<commit_msg>Base: Added missing include<commit_after>/*********************************************************************************
 *
 * Inviwo - Interactive Visualization Workshop
 *
 * Copyright (c) 2017 Inviwo Foundation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *********************************************************************************/

#include <modules/base/io/ivfsequencevolumereader.h>
#include <modules/base/io/ivfvolumewriter.h>
#include <inviwo/core/util/filesystem.h>

namespace inviwo {
IvfSequenceVolumeReader::IvfSequenceVolumeReader() {
    addExtension({"ivfs", "Sequence of Inviwo ivf volumes"});
}

std::shared_ptr<VolumeSequence> IvfSequenceVolumeReader::readData(const std::string &filePath) {
    std::string fileName = filePath;
    if (!filesystem::fileExists(fileName)) {
        std::string newPath = filesystem::addBasePath(fileName);

        if (filesystem::fileExists(newPath)) {
            fileName = newPath;
        } else {
            throw DataReaderException("Error could not find input file: " + fileName, IvwContext);
        }
    }

    auto volumes = std::make_shared<VolumeSequence>();

    auto dir = filesystem::getFileDirectory(fileName);

    std::vector<std::string> filenames;
    Deserializer d(fileName);
    d.deserialize("volumes", filenames , "volume");
    for (auto filename : filenames) {
        auto abs = filesystem::cleanupPath( dir + "/" + filename);
        volumes->push_back(reader_.readData(abs));
    }

    return volumes;
}

}  // namespace inviwo
<|endoftext|>


<commit_before>/*****************************************************************************************
*                                                                                *
* OpenSpace                                                                             *
*                                                                                *
* Copyright (c) 2014-2016                                                               *
*                                                                                *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this  *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify,    *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    *
* permit persons to whom the Software is furnished to do so, subject to the following   *
* conditions:                                                                           *
*                                                                                *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software.                                              *
*                                                                                *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE  *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                         *
****************************************************************************************/
#include <modules/base/rendering/screenspaceimage.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/filesystem/filesystem>

namespace openspace {
ScreenSpaceImage::ScreenSpaceImage(std::string texturePath)
		:ScreenSpaceRenderable()
		,_texturePath("texturePath", "Texture path", texturePath)

{
	_id = id();
	setName("ScreenSpaceImage" + std::to_string(_id));

	addProperty(_texturePath);
	registerProperties();
	OsEng.gui()._property.registerProperty(&_texturePath);

	_texturePath.onChange([this](){ loadTexture(); });
}

ScreenSpaceImage::~ScreenSpaceImage(){}

bool ScreenSpaceImage::initialize(){
	_originalViewportSize = OsEng.windowWrapper().currentWindowResolution();

	createPlane();
	createShaders();

	loadTexture();

	// Setting spherical/euclidean onchange handler
	_useFlatScreen.onChange([this](){
		useEuclideanCoordinates(_useFlatScreen.value());
	});
	return isReady();
}

bool ScreenSpaceImage::deinitialize(){
	glDeleteVertexArrays(1, &_quad);
	_quad = 0;

	glDeleteBuffers(1, &_vertexPositionBuffer);
	_vertexPositionBuffer = 0;

	_texturePath = "";
	_texture = nullptr;

	 RenderEngine& renderEngine = OsEng.renderEngine();
    if (_shader) {
        renderEngine.removeRenderProgram(_shader);
        _shader = nullptr;
    }

	return true;
}

void ScreenSpaceImage::render(){
	glm::mat4 rotation = rotationMatrix();
	glm::mat4 translation = translationMatrix();
	glm::mat4 scale = scaleMatrix();
	// scale = glm::scale(scale, glm::vec3(1.0f, -1.0f, 1.0f));
	glm::mat4 modelTransform = rotation*translation*scale;

	draw(modelTransform);
}

void ScreenSpaceImage::update(){}

bool ScreenSpaceImage::isReady() const{
	bool ready = true;
	if (!_shader)
		ready &= false;
	if(!_texture)
		ready &= false;
	return ready;
}

void ScreenSpaceImage::loadTexture() {
	if (_texturePath.value() != "") {
        std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath.value()));
		if (texture) {
			// LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
			texture->uploadTexture();

			// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
			texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);

            _texture = std::move(texture);
		}
	}
}

int ScreenSpaceImage::id(){
		static int id = 0;
		return id++;
}
}<commit_msg>add loggerCat<commit_after>/*****************************************************************************************
*                                                                                *
* OpenSpace                                                                             *
*                                                                                *
* Copyright (c) 2014-2016                                                               *
*                                                                                *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this  *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify,    *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    *
* permit persons to whom the Software is furnished to do so, subject to the following   *
* conditions:                                                                           *
*                                                                                *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software.                                              *
*                                                                                *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE  *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                         *
****************************************************************************************/
#include <modules/base/rendering/screenspaceimage.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/filesystem/filesystem>

namespace {
	const std::string _loggerCat = "ScreenSpaceImage";
}

namespace openspace {
ScreenSpaceImage::ScreenSpaceImage(std::string texturePath)
		:ScreenSpaceRenderable()
		,_texturePath("texturePath", "Texture path", texturePath)

{
	_id = id();
	setName("ScreenSpaceImage" + std::to_string(_id));

	addProperty(_texturePath);
	registerProperties();
	OsEng.gui()._property.registerProperty(&_texturePath);

	_texturePath.onChange([this](){ loadTexture(); });
}

ScreenSpaceImage::~ScreenSpaceImage(){}

bool ScreenSpaceImage::initialize(){
	_originalViewportSize = OsEng.windowWrapper().currentWindowResolution();

	createPlane();
	createShaders();

	loadTexture();

	// Setting spherical/euclidean onchange handler
	_useFlatScreen.onChange([this](){
		useEuclideanCoordinates(_useFlatScreen.value());
	});
	return isReady();
}

bool ScreenSpaceImage::deinitialize(){
	glDeleteVertexArrays(1, &_quad);
	_quad = 0;

	glDeleteBuffers(1, &_vertexPositionBuffer);
	_vertexPositionBuffer = 0;

	_texturePath = "";
	_texture = nullptr;

	 RenderEngine& renderEngine = OsEng.renderEngine();
    if (_shader) {
        renderEngine.removeRenderProgram(_shader);
        _shader = nullptr;
    }

	return true;
}

void ScreenSpaceImage::render(){
	glm::mat4 rotation = rotationMatrix();
	glm::mat4 translation = translationMatrix();
	glm::mat4 scale = scaleMatrix();
	glm::mat4 modelTransform = rotation*translation*scale;

	draw(modelTransform);
}

void ScreenSpaceImage::update(){}

bool ScreenSpaceImage::isReady() const{
	bool ready = true;
	if (!_shader)
		ready &= false;
	if(!_texture)
		ready &= false;
	return ready;
}

void ScreenSpaceImage::loadTexture() {
	if (_texturePath.value() != "") {
        std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath.value()));
		if (texture) {
			LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
			texture->uploadTexture();

			// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
			texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);

            _texture = std::move(texture);
		}
	}
}

int ScreenSpaceImage::id(){
		static int id = 0;
		return id++;
}
}<|endoftext|>


<commit_before><commit_msg>Explicitly disallows copying of VIAs, and marks the constructor as noexcept.<commit_after><|endoftext|>


<commit_before>//===- OptimizationDiagnosticInfo.cpp - Optimization Diagnostic -*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Optimization diagnostic interfaces.  It's packaged as an analysis pass so
// that by using this service passes become dependent on BFI as well.  BFI is
// used to compute the "hotness" of the diagnostic message.
//===----------------------------------------------------------------------===//

#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/LLVMContext.h"

using namespace llvm;

OptimizationRemarkEmitter::OptimizationRemarkEmitter(Function *F)
    : F(F), BFI(nullptr) {
  if (!F->getContext().getDiagnosticHotnessRequested())
    return;

  // First create a dominator tree.
  DominatorTree DT;
  DT.recalculate(*F);

  // Generate LoopInfo from it.
  LoopInfo LI;
  LI.analyze(DT);

  // Then compute BranchProbabilityInfo.
  BranchProbabilityInfo BPI;
  BPI.calculate(*F, LI);

  // Finally compute BFI.
  OwnedBFI = llvm::make_unique<BlockFrequencyInfo>(*F, BPI, LI);
  BFI = OwnedBFI.get();
}

Optional<uint64_t> OptimizationRemarkEmitter::computeHotness(const Value *V) {
  if (!BFI)
    return None;

  return BFI->getBlockProfileCount(cast<BasicBlock>(V));
}

namespace llvm {
namespace yaml {

template <> struct MappingTraits<DiagnosticInfoOptimizationBase *> {
  static void mapping(IO &io, DiagnosticInfoOptimizationBase *&OptDiag) {
    assert(io.outputting() && "input not yet implemented");

    if (io.mapTag("!Passed", OptDiag->getKind() == DK_OptimizationRemark))
      ;
    else if (io.mapTag("!Missed",
                       OptDiag->getKind() == DK_OptimizationRemarkMissed))
      ;
    else if (io.mapTag("!Analysis",
                       OptDiag->getKind() == DK_OptimizationRemarkAnalysis))
      ;
    else
      llvm_unreachable("todo");

    // These are read-only for now.
    DebugLoc DL = OptDiag->getDebugLoc();
    StringRef FN = OptDiag->getFunction().getName();

    StringRef PassName(OptDiag->PassName);
    io.mapRequired("Pass", PassName);
    io.mapRequired("Name", OptDiag->RemarkName);
    if (!io.outputting() || DL)
      io.mapOptional("DebugLoc", DL);
    io.mapRequired("Function", FN);
    io.mapOptional("Hotness", OptDiag->Hotness);
    io.mapOptional("Args", OptDiag->Args);
  }
};

template <> struct MappingTraits<DebugLoc> {
  static void mapping(IO &io, DebugLoc &DL) {
    assert(io.outputting() && "input not yet implemented");

    auto *Scope = cast<DIScope>(DL.getScope());
    StringRef File = Scope->getFilename();
    unsigned Line = DL.getLine();
    unsigned Col = DL.getCol();

    io.mapRequired("File", File);
    io.mapRequired("Line", Line);
    io.mapRequired("Column", Col);
  }

  static const bool flow = true;
};

template <> struct ScalarTraits<DiagnosticInfoOptimizationBase::Argument> {
  static void output(const DiagnosticInfoOptimizationBase::Argument &Arg,
                     void *, llvm::raw_ostream &out) {
    out << Arg.Key << ": " << Arg.Val;
  }

  static StringRef input(StringRef scalar, void *,
                         DiagnosticInfoOptimizationBase::Argument &Arg) {
    llvm_unreachable("input not yet implemented");
  }

  static bool mustQuote(StringRef) { return false; }
};

} // end namespace yaml
} // end namespace llvm

LLVM_YAML_IS_SEQUENCE_VECTOR(DiagnosticInfoOptimizationBase::Argument)

void OptimizationRemarkEmitter::computeHotness(
    DiagnosticInfoOptimizationBase &OptDiag) {
  Value *V = OptDiag.getCodeRegion();
  if (V)
    OptDiag.setHotness(computeHotness(V));
}

void OptimizationRemarkEmitter::emit(DiagnosticInfoOptimizationBase &OptDiag) {
  computeHotness(OptDiag);

  yaml::Output *Out = F->getContext().getDiagnosticsOutputFile();
  if (Out && OptDiag.isEnabled()) {
    auto *P = &const_cast<DiagnosticInfoOptimizationBase &>(OptDiag);
    *Out << P;
  }
  // FIXME: now that IsVerbose is part of DI, filtering for this will be moved
  // from here to clang.
  if (!OptDiag.isVerbose() || shouldEmitVerbose())
    F->getContext().diagnose(OptDiag);
}

void OptimizationRemarkEmitter::emitOptimizationRemark(const char *PassName,
                                                       const DebugLoc &DLoc,
                                                       const Value *V,
                                                       const Twine &Msg) {
  LLVMContext &Ctx = F->getContext();
  Ctx.diagnose(OptimizationRemark(PassName, *F, DLoc, Msg, computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemark(const char *PassName,
                                                       Loop *L,
                                                       const Twine &Msg) {
  emitOptimizationRemark(PassName, L->getStartLoc(), L->getHeader(), Msg);
}

void OptimizationRemarkEmitter::emitOptimizationRemarkMissed(
    const char *PassName, const DebugLoc &DLoc, const Value *V,
    const Twine &Msg, bool IsVerbose) {
  LLVMContext &Ctx = F->getContext();
  if (!IsVerbose || shouldEmitVerbose())
    Ctx.diagnose(
        OptimizationRemarkMissed(PassName, *F, DLoc, Msg, computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemarkMissed(
    const char *PassName, Loop *L, const Twine &Msg, bool IsVerbose) {
  emitOptimizationRemarkMissed(PassName, L->getStartLoc(), L->getHeader(), Msg,
                               IsVerbose);
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysis(
    const char *PassName, const DebugLoc &DLoc, const Value *V,
    const Twine &Msg, bool IsVerbose) {
  LLVMContext &Ctx = F->getContext();
  if (!IsVerbose || shouldEmitVerbose())
    Ctx.diagnose(
        OptimizationRemarkAnalysis(PassName, *F, DLoc, Msg, computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysis(
    const char *PassName, Loop *L, const Twine &Msg, bool IsVerbose) {
  emitOptimizationRemarkAnalysis(PassName, L->getStartLoc(), L->getHeader(),
                                 Msg, IsVerbose);
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisFPCommute(
    const char *PassName, const DebugLoc &DLoc, const Value *V,
    const Twine &Msg) {
  LLVMContext &Ctx = F->getContext();
  Ctx.diagnose(OptimizationRemarkAnalysisFPCommute(PassName, *F, DLoc, Msg,
                                                   computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisAliasing(
    const char *PassName, const DebugLoc &DLoc, const Value *V,
    const Twine &Msg) {
  LLVMContext &Ctx = F->getContext();
  Ctx.diagnose(OptimizationRemarkAnalysisAliasing(PassName, *F, DLoc, Msg,
                                                  computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisAliasing(
    const char *PassName, Loop *L, const Twine &Msg) {
  emitOptimizationRemarkAnalysisAliasing(PassName, L->getStartLoc(),
                                         L->getHeader(), Msg);
}

OptimizationRemarkEmitterWrapperPass::OptimizationRemarkEmitterWrapperPass()
    : FunctionPass(ID) {
  initializeOptimizationRemarkEmitterWrapperPassPass(
      *PassRegistry::getPassRegistry());
}

bool OptimizationRemarkEmitterWrapperPass::runOnFunction(Function &Fn) {
  BlockFrequencyInfo *BFI;

  if (Fn.getContext().getDiagnosticHotnessRequested())
    BFI = &getAnalysis<LazyBlockFrequencyInfoPass>().getBFI();
  else
    BFI = nullptr;

  ORE = llvm::make_unique<OptimizationRemarkEmitter>(&Fn, BFI);
  return false;
}

void OptimizationRemarkEmitterWrapperPass::getAnalysisUsage(
    AnalysisUsage &AU) const {
  LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
  AU.setPreservesAll();
}

char OptimizationRemarkEmitterAnalysis::PassID;

OptimizationRemarkEmitter
OptimizationRemarkEmitterAnalysis::run(Function &F,
                                       FunctionAnalysisManager &AM) {
  BlockFrequencyInfo *BFI;

  if (F.getContext().getDiagnosticHotnessRequested())
    BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
  else
    BFI = nullptr;

  return OptimizationRemarkEmitter(&F, BFI);
}

char OptimizationRemarkEmitterWrapperPass::ID = 0;
static const char ore_name[] = "Optimization Remark Emitter";
#define ORE_NAME "opt-remark-emitter"

INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
                      false, true)
INITIALIZE_PASS_DEPENDENCY(LazyBFIPass)
INITIALIZE_PASS_END(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
                    false, true)
<commit_msg>Fix for r282539 on the branch<commit_after>//===- OptimizationDiagnosticInfo.cpp - Optimization Diagnostic -*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Optimization diagnostic interfaces.  It's packaged as an analysis pass so
// that by using this service passes become dependent on BFI as well.  BFI is
// used to compute the "hotness" of the diagnostic message.
//===----------------------------------------------------------------------===//

#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/LLVMContext.h"

using namespace llvm;

OptimizationRemarkEmitter::OptimizationRemarkEmitter(Function *F)
    : F(F), BFI(nullptr) {
  if (!F->getContext().getDiagnosticHotnessRequested())
    return;

  // First create a dominator tree.
  DominatorTree DT;
  DT.recalculate(*F);

  // Generate LoopInfo from it.
  LoopInfo LI;
  LI.analyze(DT);

  // Then compute BranchProbabilityInfo.
  BranchProbabilityInfo BPI;
  BPI.calculate(*F, LI);

  // Finally compute BFI.
  OwnedBFI = llvm::make_unique<BlockFrequencyInfo>(*F, BPI, LI);
  BFI = OwnedBFI.get();
}

Optional<uint64_t> OptimizationRemarkEmitter::computeHotness(const Value *V) {
  if (!BFI)
    return None;

  return BFI->getBlockProfileCount(cast<BasicBlock>(V));
}

LLVM_YAML_IS_SEQUENCE_VECTOR(DiagnosticInfoOptimizationBase::Argument)

namespace llvm {
namespace yaml {

template <> struct MappingTraits<DiagnosticInfoOptimizationBase *> {
  static void mapping(IO &io, DiagnosticInfoOptimizationBase *&OptDiag) {
    assert(io.outputting() && "input not yet implemented");

    if (io.mapTag("!Passed", OptDiag->getKind() == DK_OptimizationRemark))
      ;
    else if (io.mapTag("!Missed",
                       OptDiag->getKind() == DK_OptimizationRemarkMissed))
      ;
    else if (io.mapTag("!Analysis",
                       OptDiag->getKind() == DK_OptimizationRemarkAnalysis))
      ;
    else
      llvm_unreachable("todo");

    // These are read-only for now.
    DebugLoc DL = OptDiag->getDebugLoc();
    StringRef FN = OptDiag->getFunction().getName();

    StringRef PassName(OptDiag->PassName);
    io.mapRequired("Pass", PassName);
    io.mapRequired("Name", OptDiag->RemarkName);
    if (!io.outputting() || DL)
      io.mapOptional("DebugLoc", DL);
    io.mapRequired("Function", FN);
    io.mapOptional("Hotness", OptDiag->Hotness);
    io.mapOptional("Args", OptDiag->Args);
  }
};

template <> struct MappingTraits<DebugLoc> {
  static void mapping(IO &io, DebugLoc &DL) {
    assert(io.outputting() && "input not yet implemented");

    auto *Scope = cast<DIScope>(DL.getScope());
    StringRef File = Scope->getFilename();
    unsigned Line = DL.getLine();
    unsigned Col = DL.getCol();

    io.mapRequired("File", File);
    io.mapRequired("Line", Line);
    io.mapRequired("Column", Col);
  }

  static const bool flow = true;
};

template <> struct ScalarTraits<DiagnosticInfoOptimizationBase::Argument> {
  static void output(const DiagnosticInfoOptimizationBase::Argument &Arg,
                     void *, llvm::raw_ostream &out) {
    out << Arg.Key << ": " << Arg.Val;
  }

  static StringRef input(StringRef scalar, void *,
                         DiagnosticInfoOptimizationBase::Argument &Arg) {
    llvm_unreachable("input not yet implemented");
  }

  static bool mustQuote(StringRef) { return false; }
};

} // end namespace yaml
} // end namespace llvm

void OptimizationRemarkEmitter::computeHotness(
    DiagnosticInfoOptimizationBase &OptDiag) {
  Value *V = OptDiag.getCodeRegion();
  if (V)
    OptDiag.setHotness(computeHotness(V));
}

void OptimizationRemarkEmitter::emit(DiagnosticInfoOptimizationBase &OptDiag) {
  computeHotness(OptDiag);

  yaml::Output *Out = F->getContext().getDiagnosticsOutputFile();
  if (Out && OptDiag.isEnabled()) {
    auto *P = &const_cast<DiagnosticInfoOptimizationBase &>(OptDiag);
    *Out << P;
  }
  // FIXME: now that IsVerbose is part of DI, filtering for this will be moved
  // from here to clang.
  if (!OptDiag.isVerbose() || shouldEmitVerbose())
    F->getContext().diagnose(OptDiag);
}

void OptimizationRemarkEmitter::emitOptimizationRemark(const char *PassName,
                                                       const DebugLoc &DLoc,
                                                       const Value *V,
                                                       const Twine &Msg) {
  LLVMContext &Ctx = F->getContext();
  Ctx.diagnose(OptimizationRemark(PassName, *F, DLoc, Msg, computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemark(const char *PassName,
                                                       Loop *L,
                                                       const Twine &Msg) {
  emitOptimizationRemark(PassName, L->getStartLoc(), L->getHeader(), Msg);
}

void OptimizationRemarkEmitter::emitOptimizationRemarkMissed(
    const char *PassName, const DebugLoc &DLoc, const Value *V,
    const Twine &Msg, bool IsVerbose) {
  LLVMContext &Ctx = F->getContext();
  if (!IsVerbose || shouldEmitVerbose())
    Ctx.diagnose(
        OptimizationRemarkMissed(PassName, *F, DLoc, Msg, computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemarkMissed(
    const char *PassName, Loop *L, const Twine &Msg, bool IsVerbose) {
  emitOptimizationRemarkMissed(PassName, L->getStartLoc(), L->getHeader(), Msg,
                               IsVerbose);
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysis(
    const char *PassName, const DebugLoc &DLoc, const Value *V,
    const Twine &Msg, bool IsVerbose) {
  LLVMContext &Ctx = F->getContext();
  if (!IsVerbose || shouldEmitVerbose())
    Ctx.diagnose(
        OptimizationRemarkAnalysis(PassName, *F, DLoc, Msg, computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysis(
    const char *PassName, Loop *L, const Twine &Msg, bool IsVerbose) {
  emitOptimizationRemarkAnalysis(PassName, L->getStartLoc(), L->getHeader(),
                                 Msg, IsVerbose);
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisFPCommute(
    const char *PassName, const DebugLoc &DLoc, const Value *V,
    const Twine &Msg) {
  LLVMContext &Ctx = F->getContext();
  Ctx.diagnose(OptimizationRemarkAnalysisFPCommute(PassName, *F, DLoc, Msg,
                                                   computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisAliasing(
    const char *PassName, const DebugLoc &DLoc, const Value *V,
    const Twine &Msg) {
  LLVMContext &Ctx = F->getContext();
  Ctx.diagnose(OptimizationRemarkAnalysisAliasing(PassName, *F, DLoc, Msg,
                                                  computeHotness(V)));
}

void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisAliasing(
    const char *PassName, Loop *L, const Twine &Msg) {
  emitOptimizationRemarkAnalysisAliasing(PassName, L->getStartLoc(),
                                         L->getHeader(), Msg);
}

OptimizationRemarkEmitterWrapperPass::OptimizationRemarkEmitterWrapperPass()
    : FunctionPass(ID) {
  initializeOptimizationRemarkEmitterWrapperPassPass(
      *PassRegistry::getPassRegistry());
}

bool OptimizationRemarkEmitterWrapperPass::runOnFunction(Function &Fn) {
  BlockFrequencyInfo *BFI;

  if (Fn.getContext().getDiagnosticHotnessRequested())
    BFI = &getAnalysis<LazyBlockFrequencyInfoPass>().getBFI();
  else
    BFI = nullptr;

  ORE = llvm::make_unique<OptimizationRemarkEmitter>(&Fn, BFI);
  return false;
}

void OptimizationRemarkEmitterWrapperPass::getAnalysisUsage(
    AnalysisUsage &AU) const {
  LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
  AU.setPreservesAll();
}

char OptimizationRemarkEmitterAnalysis::PassID;

OptimizationRemarkEmitter
OptimizationRemarkEmitterAnalysis::run(Function &F,
                                       FunctionAnalysisManager &AM) {
  BlockFrequencyInfo *BFI;

  if (F.getContext().getDiagnosticHotnessRequested())
    BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
  else
    BFI = nullptr;

  return OptimizationRemarkEmitter(&F, BFI);
}

char OptimizationRemarkEmitterWrapperPass::ID = 0;
static const char ore_name[] = "Optimization Remark Emitter";
#define ORE_NAME "opt-remark-emitter"

INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
                      false, true)
INITIALIZE_PASS_DEPENDENCY(LazyBFIPass)
INITIALIZE_PASS_END(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
                    false, true)
<|endoftext|>