<commit_before>/*************************************************************************
 *
 *  $RCSfile: xmlexchg.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: vg $ $Date: 2005-03-23 11:48:43 $
 *
 *  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 _SVX_XMLEXCHG_HXX_
#define _SVX_XMLEXCHG_HXX_

#ifndef _TRANSFER_HXX
#include <svtools/transfer.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

namespace com {
    namespace sun {
        namespace star {
            namespace beans {
                class SAL_NO_VTABLE XPropertySet;
            }
        }
    }
}

//........................................................................
namespace svx
{
//........................................................................

    //====================================================================
    //= OXFormsDescriptor
    //====================================================================

    struct SVX_DLLPUBLIC OXFormsDescriptor {

        String szName;
        String szServiceName;
        ::com::sun::star::uno::Reference
            < ::com::sun::star::beans::XPropertySet >
                xPropSet;

        inline OXFormsDescriptor( void ) {}
        inline OXFormsDescriptor( const OXFormsDescriptor &rhs ) { *this=rhs; }
        inline OXFormsDescriptor &operator = ( const OXFormsDescriptor &rhs ) {
            szName = rhs.szName;
            szServiceName = rhs.szServiceName;
            xPropSet = rhs.xPropSet;
            return (*this);
        }
    };

    //====================================================================
    //= OXFormsTransferable
    //====================================================================
    class SVX_DLLPUBLIC OXFormsTransferable : public TransferableHelper {

        protected:

            // TransferableHelper overridables
            virtual void        AddSupportedFormats();
            virtual sal_Bool    GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );

            static sal_uInt32   getDescriptorFormatId();

            OXFormsDescriptor m_aDescriptor;

        public:

            /** construct the transferable
            */
            OXFormsTransferable( const OXFormsDescriptor &rhs );

            /** extracts an xform descriptor from the transferable given
            */
            static const OXFormsDescriptor &extractDescriptor( const TransferableDataHelper& _rData );
    };

//........................................................................
}   // namespace svx
//........................................................................

#endif // _SVX_XMLEXCHG_HXX_

<commit_msg>INTEGRATION: CWS ooo19126 (1.3.252); FILE MERGED 2005/09/05 14:17:18 rt 1.3.252.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: xmlexchg.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 19:49:48 $
 *
 *  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 _SVX_XMLEXCHG_HXX_
#define _SVX_XMLEXCHG_HXX_

#ifndef _TRANSFER_HXX
#include <svtools/transfer.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

namespace com {
    namespace sun {
        namespace star {
            namespace beans {
                class SAL_NO_VTABLE XPropertySet;
            }
        }
    }
}

//........................................................................
namespace svx
{
//........................................................................

    //====================================================================
    //= OXFormsDescriptor
    //====================================================================

    struct SVX_DLLPUBLIC OXFormsDescriptor {

        String szName;
        String szServiceName;
        ::com::sun::star::uno::Reference
            < ::com::sun::star::beans::XPropertySet >
                xPropSet;

        inline OXFormsDescriptor( void ) {}
        inline OXFormsDescriptor( const OXFormsDescriptor &rhs ) { *this=rhs; }
        inline OXFormsDescriptor &operator = ( const OXFormsDescriptor &rhs ) {
            szName = rhs.szName;
            szServiceName = rhs.szServiceName;
            xPropSet = rhs.xPropSet;
            return (*this);
        }
    };

    //====================================================================
    //= OXFormsTransferable
    //====================================================================
    class SVX_DLLPUBLIC OXFormsTransferable : public TransferableHelper {

        protected:

            // TransferableHelper overridables
            virtual void        AddSupportedFormats();
            virtual sal_Bool    GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );

            static sal_uInt32   getDescriptorFormatId();

            OXFormsDescriptor m_aDescriptor;

        public:

            /** construct the transferable
            */
            OXFormsTransferable( const OXFormsDescriptor &rhs );

            /** extracts an xform descriptor from the transferable given
            */
            static const OXFormsDescriptor &extractDescriptor( const TransferableDataHelper& _rData );
    };

//........................................................................
}   // namespace svx
//........................................................................

#endif // _SVX_XMLEXCHG_HXX_

<|endoftext|>


<commit_before><commit_msg>:construction: test(lexer): updated the test for lexer<commit_after><|endoftext|>


<commit_before>/** \brief Utility for finding potentially doubly-mapped PPN's.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2019 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include "FileUtil.h"
#include "MapUtil.h"
#include "MARC.h"
#include "StringUtil.h"
#include "util.h"

namespace {

void ProcessRecords(MARC::Reader * const marc_reader, std::unordered_map<std::string, std::string> * const old_bsz_to_new_k10plus_ppns_map,
                    std::unordered_set<std::string> * const new_k10plus_ppns)
{
    unsigned identity_count(0), old_to_new_count(0);
    while (const MARC::Record record = marc_reader->read()) {
        for (const auto &field : record.getTagRange("035")) {
            new_k10plus_ppns->emplace(record.getControlNumber());
            const auto subfield_a(field.getFirstSubfieldWithCode('a'));
            if (StringUtil::StartsWith(subfield_a, "(DE-576)")) {
                const std::string old_bsz_ppn(subfield_a.substr(__builtin_strlen( "(DE-576)")));
                if (unlikely(old_bsz_ppn == record.getControlNumber()))
                    ++identity_count;
                else {
                    (*old_bsz_to_new_k10plus_ppns_map)[old_bsz_ppn] = record.getControlNumber();
                    ++old_to_new_count;
                }
                continue;
            }
        }
    }

    LOG_INFO("Found " + std::to_string(identity_count) + " identity mappings.");
    LOG_INFO("Found " + std::to_string(old_to_new_count) + " mappings of old BSZ PPN's to new K10+ PPN's.");
}

} // unnamed namespace

int Main(int argc, char *argv[]) {
    if (argc != 3)
        ::Usage("marc_records backpatch.map");

    std::unordered_map<std::string, std::string> old_bsz_to_new_k10plus_ppns_map;
    std::unordered_set<std::string> new_k10plus_ppns;

    auto marc_reader(MARC::Reader::Factory(argv[1]));
    ProcessRecords(marc_reader.get(), &old_bsz_to_new_k10plus_ppns_map, &new_k10plus_ppns);

    std::unordered_map<std::string, std::string> k10plus_to_k10plus_map;
    for (const auto &bsz_and_k10plus_ppns : old_bsz_to_new_k10plus_ppns_map) {
        // Is the replaced PPN an old BSZ PPN?
        unsigned replacement_count(0);
        std::string final_k10plus_ppn(bsz_and_k10plus_ppns.second);
        for (;;) {
            auto bsz_and_k10plus_ppn2(old_bsz_to_new_k10plus_ppns_map.find(final_k10plus_ppn));
            if (bsz_and_k10plus_ppn2 == old_bsz_to_new_k10plus_ppns_map.cend())
                break;
            final_k10plus_ppn = bsz_and_k10plus_ppn2->second;
            ++replacement_count;
        }
        if (replacement_count > 1)
            k10plus_to_k10plus_map[final_k10plus_ppn] = bsz_and_k10plus_ppns.second;
    }
    LOG_INFO("Found " + std::to_string(k10plus_to_k10plus_map.size()) + " doubly mapped candidates.");

    MapUtil::SerialiseMap(argv[3], k10plus_to_k10plus_map);

    return EXIT_SUCCESS;
}
<commit_msg>Will the nightmare never end?<commit_after>/** \brief Utility for finding potentially doubly-mapped PPN's.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2019 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include "FileUtil.h"
#include "MapUtil.h"
#include "MARC.h"
#include "StringUtil.h"
#include "util.h"

namespace {

void ProcessRecords(MARC::Reader * const marc_reader, std::unordered_map<std::string, std::string> * const old_bsz_to_new_k10plus_ppns_map,
                    std::unordered_set<std::string> * const new_k10plus_ppns)
{
    unsigned identity_count(0), old_to_new_count(0);
    while (const MARC::Record record = marc_reader->read()) {
        for (const auto &field : record.getTagRange("035")) {
            new_k10plus_ppns->emplace(record.getControlNumber());
            const auto subfield_a(field.getFirstSubfieldWithCode('a'));
            if (StringUtil::StartsWith(subfield_a, "(DE-576)")) {
                const std::string old_bsz_ppn(subfield_a.substr(__builtin_strlen( "(DE-576)")));
                if (unlikely(old_bsz_ppn == record.getControlNumber()))
                    ++identity_count;
                else {
                    (*old_bsz_to_new_k10plus_ppns_map)[old_bsz_ppn] = record.getControlNumber();
                    ++old_to_new_count;
                }
                continue;
            }
        }
    }

    LOG_INFO("Found " + std::to_string(identity_count) + " identity mappings.");
    LOG_INFO("Found " + std::to_string(old_to_new_count) + " mappings of old BSZ PPN's to new K10+ PPN's.");
}

} // unnamed namespace

int Main(int argc, char *argv[]) {
    if (argc != 4)
        ::Usage("title_records authority_records backpatch.map");

    std::unordered_map<std::string, std::string> old_bsz_to_new_k10plus_ppns_map;
    std::unordered_set<std::string> new_k10plus_ppns;

    auto marc_reader(MARC::Reader::Factory(argv[1]));
    ProcessRecords(marc_reader.get(), &old_bsz_to_new_k10plus_ppns_map, &new_k10plus_ppns);

    auto marc_reader2(MARC::Reader::Factory(argv[2]));
    ProcessRecords(marc_reader2.get(), &old_bsz_to_new_k10plus_ppns_map, &new_k10plus_ppns);

    std::unordered_map<std::string, std::string> k10plus_to_k10plus_map;
    for (const auto &bsz_and_k10plus_ppns : old_bsz_to_new_k10plus_ppns_map) {
        // Is the replaced PPN an old BSZ PPN?
        unsigned replacement_count(0);
        std::string final_k10plus_ppn(bsz_and_k10plus_ppns.first);
        const std::string correct_substitution(bsz_and_k10plus_ppns.second);
        for (;;) {
            auto bsz_and_k10plus_ppn2(old_bsz_to_new_k10plus_ppns_map.find(final_k10plus_ppn));
            if (bsz_and_k10plus_ppn2 == old_bsz_to_new_k10plus_ppns_map.cend())
                break;
            final_k10plus_ppn = bsz_and_k10plus_ppn2->second;
            ++replacement_count;
        }
        if (replacement_count > 1)
            k10plus_to_k10plus_map[final_k10plus_ppn] = correct_substitution;
    }
    LOG_INFO("Found " + std::to_string(k10plus_to_k10plus_map.size()) + " doubly mapped candidates.");

    MapUtil::SerialiseMap(argv[3], k10plus_to_k10plus_map);

    return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>/** \brief Utility for finding potentially doubly-mapped PPN's.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2019 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include "FileUtil.h"
#include "MapUtil.h"
#include "MARC.h"
#include "StringUtil.h"
#include "util.h"

namespace {

void ProcessRecords(MARC::Reader * const marc_reader, std::unordered_map<std::string, std::string> * const old_bsz_to_new_k10plus_ppns_map,
                    std::unordered_set<std::string> * const new_k10plus_ppns)
{
    unsigned identity_count(0), old_to_new_count(0);
    while (const MARC::Record record = marc_reader->read()) {
        for (const auto &field : record.getTagRange("035")) {
            new_k10plus_ppns->emplace(record.getControlNumber());
            const auto subfield_a(field.getFirstSubfieldWithCode('a'));
            if (StringUtil::StartsWith(subfield_a, "(DE-576)")) {
                const std::string old_bsz_ppn(subfield_a.substr(__builtin_strlen( "(DE-576)")));
                if (unlikely(old_bsz_ppn == record.getControlNumber()))
                    ++identity_count;
                else {
                    (*old_bsz_to_new_k10plus_ppns_map)[old_bsz_ppn] = record.getControlNumber();
                    ++old_to_new_count;
                }
                continue;
            }
        }
    }

    LOG_INFO("Found " + std::to_string(identity_count) + " identity mappings.");
    LOG_INFO("Found " + std::to_string(old_to_new_count) + " mappings of old BSZ PPN's to new K10+ PPN's.");
}

} // unnamed namespace

int Main(int argc, char *argv[]) {
    if (argc != 4)
        ::Usage("title_records authority_records\nGenerates two output files: title_backpatch.map and authority_backpatch.map");

    std::unordered_map<std::string, std::string> old_bsz_to_new_k10plus_ppns_map;
    std::unordered_set<std::string> new_k10plus_ppns;

    auto marc_reader(MARC::Reader::Factory(argv[1]));
    ProcessRecords(marc_reader.get(), &old_bsz_to_new_k10plus_ppns_map, &new_k10plus_ppns);

    auto marc_reader2(MARC::Reader::Factory(argv[2]));
    ProcessRecords(marc_reader2.get(), &old_bsz_to_new_k10plus_ppns_map, &new_k10plus_ppns);

    std::unordered_map<std::string, std::string> k10plus_to_k10plus_map;
    for (const auto &bsz_and_k10plus_ppns : old_bsz_to_new_k10plus_ppns_map) {
        // Is the replaced PPN an old BSZ PPN?
        unsigned replacement_count(0);
        std::string final_k10plus_ppn(bsz_and_k10plus_ppns.second);
        for (;;) {
            auto bsz_and_k10plus_ppn2(old_bsz_to_new_k10plus_ppns_map.find(final_k10plus_ppn));
            if (bsz_and_k10plus_ppn2 == old_bsz_to_new_k10plus_ppns_map.cend())
                break;
            final_k10plus_ppn = bsz_and_k10plus_ppn2->second;
            ++replacement_count;
        }
        if (replacement_count > 1)
            k10plus_to_k10plus_map[final_k10plus_ppn] = bsz_and_k10plus_ppns.second;
    }
    LOG_INFO("Found " + std::to_string(k10plus_to_k10plus_map.size()) + " doubly mapped candidates.");

    MapUtil::SerialiseMap(argv[3], k10plus_to_k10plus_map);

    return EXIT_SUCCESS;
}
<commit_msg>Only process a single MARC input file.<commit_after>/** \brief Utility for finding potentially doubly-mapped PPN's.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2019 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include "FileUtil.h"
#include "MapUtil.h"
#include "MARC.h"
#include "StringUtil.h"
#include "util.h"

namespace {

void ProcessRecords(MARC::Reader * const marc_reader, std::unordered_map<std::string, std::string> * const old_bsz_to_new_k10plus_ppns_map,
                    std::unordered_set<std::string> * const new_k10plus_ppns)
{
    unsigned identity_count(0), old_to_new_count(0);
    while (const MARC::Record record = marc_reader->read()) {
        for (const auto &field : record.getTagRange("035")) {
            new_k10plus_ppns->emplace(record.getControlNumber());
            const auto subfield_a(field.getFirstSubfieldWithCode('a'));
            if (StringUtil::StartsWith(subfield_a, "(DE-576)")) {
                const std::string old_bsz_ppn(subfield_a.substr(__builtin_strlen( "(DE-576)")));
                if (unlikely(old_bsz_ppn == record.getControlNumber()))
                    ++identity_count;
                else {
                    (*old_bsz_to_new_k10plus_ppns_map)[old_bsz_ppn] = record.getControlNumber();
                    ++old_to_new_count;
                }
                continue;
            }
        }
    }

    LOG_INFO("Found " + std::to_string(identity_count) + " identity mappings.");
    LOG_INFO("Found " + std::to_string(old_to_new_count) + " mappings of old BSZ PPN's to new K10+ PPN's.");
}

} // unnamed namespace

int Main(int argc, char *argv[]) {
    if (argc != 3)
        ::Usage("marc_records backpatch.map");

    std::unordered_map<std::string, std::string> old_bsz_to_new_k10plus_ppns_map;
    std::unordered_set<std::string> new_k10plus_ppns;

    auto marc_reader(MARC::Reader::Factory(argv[1]));
    ProcessRecords(marc_reader.get(), &old_bsz_to_new_k10plus_ppns_map, &new_k10plus_ppns);

    std::unordered_map<std::string, std::string> k10plus_to_k10plus_map;
    for (const auto &bsz_and_k10plus_ppns : old_bsz_to_new_k10plus_ppns_map) {
        // Is the replaced PPN an old BSZ PPN?
        unsigned replacement_count(0);
        std::string final_k10plus_ppn(bsz_and_k10plus_ppns.second);
        for (;;) {
            auto bsz_and_k10plus_ppn2(old_bsz_to_new_k10plus_ppns_map.find(final_k10plus_ppn));
            if (bsz_and_k10plus_ppn2 == old_bsz_to_new_k10plus_ppns_map.cend())
                break;
            final_k10plus_ppn = bsz_and_k10plus_ppn2->second;
            ++replacement_count;
        }
        if (replacement_count > 1)
            k10plus_to_k10plus_map[final_k10plus_ppn] = bsz_and_k10plus_ppns.second;
    }
    LOG_INFO("Found " + std::to_string(k10plus_to_k10plus_map.size()) + " doubly mapped candidates.");

    MapUtil::SerialiseMap(argv[3], k10plus_to_k10plus_map);

    return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>/** \brief Utility for adding back links to links found in 7?? fields $w subfields.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2019 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <algorithm>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "MARC.h"
#include "StringUtil.h"
#include "util.h"

namespace {

struct RecordInfo {
    std::vector<std::pair<std::string, std::string>> ppns_and_titles_;
public:
    RecordInfo() = default;
    RecordInfo(const RecordInfo &other) = default;
    RecordInfo(const std::string &ppn, const std::string &title): ppns_and_titles_ { { ppn, title } } { }
    void addPPNAndTitle(const std::string &ppn, const std::string &title) { ppns_and_titles_.emplace_back(ppn, title); }
    RecordInfo &operator=(const RecordInfo &rhs) = default;
};

std::vector<std::string> GetReferencedPPNs(const MARC::Record &record) {
    std::vector<std::string> referenced_ppns;

    for (const auto &field : record) {
        // We only look at fields whose tags start with a 7.
        if (field.getTag().c_str()[0] != '7')
            continue;

        const MARC::Subfields subfields(field.getSubfields());
        for (const auto &subfield : subfields) {
            if (subfield.code_ == 'w' and StringUtil::StartsWith(subfield.value_, "(DE-627)"))
                referenced_ppns.emplace_back(subfield.value_.substr(__builtin_strlen("(DE-627)")));
        }
    }

    return referenced_ppns;
}

void ProcessRecords(MARC::Reader * const marc_reader, std::unordered_map<std::string, RecordInfo> * const ppn_to_description_map) {
    unsigned record_count(0);

    while (const MARC::Record record = marc_reader->read()) {
        ++record_count;

        const auto referenced_ppns(GetReferencedPPNs(record));
        for (const auto &referenced_ppn : referenced_ppns) {
            auto iter(ppn_to_description_map->find(referenced_ppn));
            if (iter == ppn_to_description_map->end())
                ppn_to_description_map->emplace(referenced_ppn, RecordInfo(record.getControlNumber(), record.getMainTitle()));
            else
                iter->second.addPPNAndTitle(record.getControlNumber(), record.getMainTitle());
        }
    }

    LOG_INFO("Processed " + std::to_string(record_count) + " MARC record(s).");
    LOG_INFO("Found " + std::to_string(ppn_to_description_map->size()) + " cross references.");
}

void AddMissingBackLinks(MARC::Reader * const marc_reader, MARC::Writer * const marc_writer,
                         const std::unordered_map<std::string, RecordInfo> &ppn_to_description_map)
{
    unsigned added_count(0);
    while (MARC::Record record = marc_reader->read()) {
        const auto ppn_and_record(ppn_to_description_map.find(record.getControlNumber()));
        if (ppn_and_record != ppn_to_description_map.cend()) {
            const auto referenced_ppns(GetReferencedPPNs(record));
            for (const auto &ppn_and_title : ppn_and_record->second.ppns_and_titles_) {
                if (std::find_if(referenced_ppns.cbegin(), referenced_ppns.cend(),
                                 [ppn_and_record](const std::string &referenced_ppn){ return ppn_and_record->first == referenced_ppn; })
                    == referenced_ppns.cend()) {
                    record.insertField("799", { { 'a', ppn_and_title.second }, { 'w', "(DE-627)" + ppn_and_title.first } });
                    ++added_count;
                }
            }
        }

        marc_writer->write(record);
    }

    LOG_INFO("Added " + std::to_string(added_count) + " missing back links.");
}

} // unnamed namespace

int Main(int argc, char *argv[]) {
    if (argc != 3)
        ::Usage("marc_input marc_output");

    auto marc_reader(MARC::Reader::Factory(argv[1]));
    std::unordered_map<std::string, RecordInfo> ppn_to_description_map;
    ProcessRecords(marc_reader.get(), &ppn_to_description_map);
    marc_reader->rewind();

    auto marc_writer(MARC::Writer::Factory(argv[2]));
    AddMissingBackLinks(marc_reader.get(), marc_writer.get(), ppn_to_description_map);

    return EXIT_SUCCESS;
}
<commit_msg>Do not generate down links from superior works.<commit_after>/** \brief Utility for adding back links to links found in 7?? fields $w subfields.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2019 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <algorithm>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "MARC.h"
#include "StringUtil.h"
#include "util.h"

namespace {

struct RecordInfo {
    std::vector<std::pair<std::string, std::string>> ppns_and_titles_;
public:
    RecordInfo() = default;
    RecordInfo(const RecordInfo &other) = default;
    RecordInfo(const std::string &ppn, const std::string &title): ppns_and_titles_ { { ppn, title } } { }
    void addPPNAndTitle(const std::string &ppn, const std::string &title) { ppns_and_titles_.emplace_back(ppn, title); }
    RecordInfo &operator=(const RecordInfo &rhs) = default;
};

std::vector<std::string> GetReferencedPPNs(const MARC::Record &record) {
    std::vector<std::string> referenced_ppns;

    for (const auto &field : record) {
        // We only look at fields whose tags start with a 7.
        if (field.getTag().c_str()[0] != '7' or field.getTag().toString() == "773")
            continue;

        const MARC::Subfields subfields(field.getSubfields());
        for (const auto &subfield : subfields) {
            if (subfield.code_ == 'w' and StringUtil::StartsWith(subfield.value_, "(DE-627)"))
                referenced_ppns.emplace_back(subfield.value_.substr(__builtin_strlen("(DE-627)")));
        }
    }

    return referenced_ppns;
}

void ProcessRecords(MARC::Reader * const marc_reader, std::unordered_map<std::string, RecordInfo> * const ppn_to_description_map) {
    unsigned record_count(0), cross_link_count(0);

    while (const MARC::Record record = marc_reader->read()) {
        ++record_count;

        const auto referenced_ppns(GetReferencedPPNs(record));
        for (const auto &referenced_ppn : referenced_ppns) {
            auto iter(ppn_to_description_map->find(referenced_ppn));
            if (iter == ppn_to_description_map->end())
                ppn_to_description_map->emplace(referenced_ppn, RecordInfo(record.getControlNumber(), record.getMainTitle()));
            else
                iter->second.addPPNAndTitle(record.getControlNumber(), record.getMainTitle());
            ++cross_link_count;
        }
    }

    LOG_INFO("Processed " + std::to_string(record_count) + " MARC record(s).");
    LOG_INFO("Found " + std::to_string(cross_link_count) + " cross references to " + std::to_string(ppn_to_description_map->size())
             + " records.");
}

void AddMissingBackLinks(MARC::Reader * const marc_reader, MARC::Writer * const marc_writer,
                         const std::unordered_map<std::string, RecordInfo> &ppn_to_description_map)
{
    unsigned added_count(0);
    while (MARC::Record record = marc_reader->read()) {
        const auto ppn_and_record(ppn_to_description_map.find(record.getControlNumber()));
        if (ppn_and_record != ppn_to_description_map.cend()) {
            const auto referenced_ppns(GetReferencedPPNs(record));
            for (const auto &ppn_and_title : ppn_and_record->second.ppns_and_titles_) {
                if (std::find_if(referenced_ppns.cbegin(), referenced_ppns.cend(),
                                 [ppn_and_record](const std::string &referenced_ppn){ return ppn_and_record->first == referenced_ppn; })
                    == referenced_ppns.cend()) {
                    record.insertField("799", { { 'a', ppn_and_title.second }, { 'w', "(DE-627)" + ppn_and_title.first } });
                    ++added_count;
                }
            }
        }

        marc_writer->write(record);
    }

    LOG_INFO("Added " + std::to_string(added_count) + " missing back links.");
}

} // unnamed namespace

int Main(int argc, char *argv[]) {
    if (argc != 3)
        ::Usage("marc_input marc_output");

    auto marc_reader(MARC::Reader::Factory(argv[1]));
    std::unordered_map<std::string, RecordInfo> ppn_to_description_map;
    ProcessRecords(marc_reader.get(), &ppn_to_description_map);
    marc_reader->rewind();

    auto marc_writer(MARC::Writer::Factory(argv[2]));
    AddMissingBackLinks(marc_reader.get(), marc_writer.get(), ppn_to_description_map);

    return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before><commit_msg>Reduce to static_cast any reinterpret_cast from void pointers<commit_after><|endoftext|>


<commit_before>//===--------------------------------------------------------------------------------*- C++ -*-===//
//                         _       _
//                        | |     | |
//                    __ _| |_ ___| | __ _ _ __   __ _
//                   / _` | __/ __| |/ _` | '_ \ / _` |
//                  | (_| | || (__| | (_| | | | | (_| |
//                   \__, |\__\___|_|\__,_|_| |_|\__, | - GridTools Clang DSL
//                    __/ |                       __/ |
//                   |___/                       |___/
//
//
//  This file is distributed under the MIT License (MIT).
//  See LICENSE.txt for details.
//
//===------------------------------------------------------------------------------------------===//

#include "gtclang/Driver/CompilerInstance.h"
#include "dawn/Support/Compiler.h"
#include "gtclang/Support/ClangCompat/CompilerInvocation.h"
#include "gtclang/Support/Config.h"
#include "gtclang/Support/Logger.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Tool.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
#include <iostream>
#include <memory>
#include <string>
#include <utility>

namespace gtclang {

namespace {

std::string getExecutablePath(const char* argv0) {
  // This just needs to be some symbol in the binary;
  // C++ doesn't allow taking the address of ::main however.
  void* main_addr = (void*)(intptr_t)getExecutablePath;
  return llvm::sys::fs::getMainExecutable(argv0, main_addr);
}

} // namespace

clang::CompilerInstance* createCompilerInstance(llvm::SmallVectorImpl<const char*>& args) {
  using namespace clang;
  using namespace llvm;

  void* mainAddr = (void*)(intptr_t)getExecutablePath;
  std::string path = getExecutablePath(args[0]);

  // Setup diagnostics engine
  IntrusiveRefCntPtr<DiagnosticOptions> diagnosticOptions = new DiagnosticOptions;
  TextDiagnosticPrinter* diagnosticClient = new TextDiagnosticPrinter(errs(), &*diagnosticOptions);

  IntrusiveRefCntPtr<clang::DiagnosticIDs> diagnosticID(new DiagnosticIDs());
  DiagnosticsEngine diagnostics(diagnosticID, &*diagnosticOptions, diagnosticClient);

  // Setup driver
  driver::Driver driver(path, llvm::sys::getDefaultTargetTriple(), diagnostics);
  driver.setTitle("gridtools clang");

  args.push_back("-fsyntax-only");
  std::unique_ptr<driver::Compilation> compilation(driver.BuildCompilation(args));
  if(!compilation)
    return nullptr;

  // We expect to get back exactly one command job, if we didn't something failed. Extract that
  // job from the compilation
  const driver::JobList& jobs = compilation->getJobs();
  if(jobs.size() != 1 || !isa<driver::Command>(*jobs.begin())) {
    llvm::errs() << "error: expected exactly one input file\n";
    return nullptr;
  }

  const driver::Command& command = cast<driver::Command>(*jobs.begin());
  if(StringRef(command.getCreator().getName()) != "clang") {
    diagnostics.Report(clang::diag::err_fe_expected_clang_command);
    return nullptr;
  }

  // Initialize a compiler invocation object from the clang (-cc1) arguments
  llvm::opt::ArgStringList& ccArgs = const_cast<llvm::opt::ArgStringList&>(command.getArguments());

#ifdef __APPLE__
  // Set the root where system headers are located.
  ccArgs.push_back("-internal-isystem");
  ccArgs.push_back(GTCLANG_CLANG_RESSOURCE_INCLUDE_PATH "/../../../../include/c++/v1/");
  // 20191208: -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk does not work, so we
  // add the full path manually
  ccArgs.push_back("-internal-isystem");
  ccArgs.push_back("/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include");
#endif

  // NOTE: This is a kind of a hack. The problem is that Clang tools are meant to be run from the
  // the same binary directory as Clang itself and thus rely on finding the internal header files in
  // `../lib/clang/X.X.X/include`. However, this is usually not the case for us! We just pass the
  // include dirs manually to cc1 which we grabbed from llvm-config in CMake.
  ccArgs.push_back("-internal-isystem");
  ccArgs.push_back(GTCLANG_CLANG_RESSOURCE_INCLUDE_PATH);

  std::shared_ptr<CompilerInvocation> CI(new CompilerInvocation);
  clang_compat::CompilerInvocation::CreateFromArgs(*CI, ccArgs, diagnostics);
  CI->getFrontendOpts().DisableFree = false;

  // Create a compiler instance to handle the actual work.
  DAWN_LOG(INFO) << "Creating GTClang compiler instance ...";
  CompilerInstance* GTClang = new CompilerInstance;
  GTClang->setInvocation(CI);

  // Create the compilers actual diagnostics engine
  GTClang->createDiagnostics();
  if(!GTClang->hasDiagnostics())
    return nullptr;

  // Check that we are at least in C++11 mode and correct if necessary
  auto& langOpts = GTClang->getLangOpts();
  if(!langOpts.CPlusPlus11 && !langOpts.CPlusPlus14 && !langOpts.CPlusPlus17) {
    DAWN_LOG(WARNING) << "C++98 mode detected; switching to C++11";
    langOpts.CPlusPlus11 = 1;
  }

  // Infer the builtin (ressource) include path if unspecified
  if(GTClang->getHeaderSearchOpts().UseBuiltinIncludes &&
     GTClang->getHeaderSearchOpts().ResourceDir.empty())
    GTClang->getHeaderSearchOpts().ResourceDir =
        CompilerInvocation::GetResourcesPath(args[0], mainAddr);

  // Add the path to our DSL runtime
  SmallVector<StringRef, 2> DSLIncludes;
  StringRef(GTCLANG_DSL_INCLUDES).split(DSLIncludes, ';');
  for(const auto& path : DSLIncludes) {
    DAWN_LOG(INFO) << "Adding DSL include path: " << path.str();
    GTClang->getHeaderSearchOpts().AddPath(path, clang::frontend::System, false, true);
  }

  // Show the invocation, with -v
  if(CI->getHeaderSearchOpts().Verbose) {
    errs() << "gtclang invocation:\n";
    jobs.Print(errs(), "\n", true);
    errs() << "\n";
  }

  return GTClang;
}

} // namespace gtclang
<commit_msg>Fix for GCC on MacOS (#716)<commit_after>//===--------------------------------------------------------------------------------*- C++ -*-===//
//                         _       _
//                        | |     | |
//                    __ _| |_ ___| | __ _ _ __   __ _
//                   / _` | __/ __| |/ _` | '_ \ / _` |
//                  | (_| | || (__| | (_| | | | | (_| |
//                   \__, |\__\___|_|\__,_|_| |_|\__, | - GridTools Clang DSL
//                    __/ |                       __/ |
//                   |___/                       |___/
//
//
//  This file is distributed under the MIT License (MIT).
//  See LICENSE.txt for details.
//
//===------------------------------------------------------------------------------------------===//

#include "gtclang/Driver/CompilerInstance.h"
#include "dawn/Support/Compiler.h"
#include "gtclang/Support/ClangCompat/CompilerInvocation.h"
#include "gtclang/Support/Config.h"
#include "gtclang/Support/Logger.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Tool.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
#include <iostream>
#include <memory>
#include <string>
#include <utility>

namespace gtclang {

namespace {

std::string getExecutablePath(const char* argv0) {
  // This just needs to be some symbol in the binary;
  // C++ doesn't allow taking the address of ::main however.
  void* main_addr = (void*)(intptr_t)getExecutablePath;
  return llvm::sys::fs::getMainExecutable(argv0, main_addr);
}

} // namespace

clang::CompilerInstance* createCompilerInstance(llvm::SmallVectorImpl<const char*>& args) {
  using namespace clang;
  using namespace llvm;

  void* mainAddr = (void*)(intptr_t)getExecutablePath;
  std::string path = getExecutablePath(args[0]);

  // Setup diagnostics engine
  IntrusiveRefCntPtr<DiagnosticOptions> diagnosticOptions = new DiagnosticOptions;
  TextDiagnosticPrinter* diagnosticClient = new TextDiagnosticPrinter(errs(), &*diagnosticOptions);

  IntrusiveRefCntPtr<clang::DiagnosticIDs> diagnosticID(new DiagnosticIDs());
  DiagnosticsEngine diagnostics(diagnosticID, &*diagnosticOptions, diagnosticClient);

  // Setup driver
  driver::Driver driver(path, llvm::sys::getDefaultTargetTriple(), diagnostics);
  driver.setTitle("gridtools clang");

  args.push_back("-fsyntax-only");
  std::unique_ptr<driver::Compilation> compilation(driver.BuildCompilation(args));
  if(!compilation)
    return nullptr;

  // We expect to get back exactly one command job, if we didn't something failed. Extract that
  // job from the compilation
  const driver::JobList& jobs = compilation->getJobs();
  if(jobs.size() != 1 || !isa<driver::Command>(*jobs.begin())) {
    llvm::errs() << "error: expected exactly one input file\n";
    return nullptr;
  }

  const driver::Command& command = cast<driver::Command>(*jobs.begin());
  if(StringRef(command.getCreator().getName()) != "clang") {
    diagnostics.Report(clang::diag::err_fe_expected_clang_command);
    return nullptr;
  }

  // Initialize a compiler invocation object from the clang (-cc1) arguments
  llvm::opt::ArgStringList& ccArgs = const_cast<llvm::opt::ArgStringList&>(command.getArguments());

#ifdef __APPLE__
  // Set the root where system headers are located.
  ccArgs.push_back("-internal-isystem");
  ccArgs.push_back(GTCLANG_CLANG_RESSOURCE_INCLUDE_PATH "/../../../../include/c++/v1/");
  ccArgs.push_back("-internal-isystem");
  ccArgs.push_back("/Library/Developer/CommandLineTools/usr/include/c++/v1");
  // 20191208: -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk does not work, so we
  // add the full path manually
  ccArgs.push_back("-internal-isystem");
  ccArgs.push_back("/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include");
#endif

  // NOTE: This is a kind of a hack. The problem is that Clang tools are meant to be run from the
  // the same binary directory as Clang itself and thus rely on finding the internal header files in
  // `../lib/clang/X.X.X/include`. However, this is usually not the case for us! We just pass the
  // include dirs manually to cc1 which we grabbed from llvm-config in CMake.
  ccArgs.push_back("-internal-isystem");
  ccArgs.push_back(GTCLANG_CLANG_RESSOURCE_INCLUDE_PATH);

  std::shared_ptr<CompilerInvocation> CI(new CompilerInvocation);
  clang_compat::CompilerInvocation::CreateFromArgs(*CI, ccArgs, diagnostics);
  CI->getFrontendOpts().DisableFree = false;

  // Create a compiler instance to handle the actual work.
  DAWN_LOG(INFO) << "Creating GTClang compiler instance ...";
  CompilerInstance* GTClang = new CompilerInstance;
  GTClang->setInvocation(CI);

  // Create the compilers actual diagnostics engine
  GTClang->createDiagnostics();
  if(!GTClang->hasDiagnostics())
    return nullptr;

  // Check that we are at least in C++11 mode and correct if necessary
  auto& langOpts = GTClang->getLangOpts();
  if(!langOpts.CPlusPlus11 && !langOpts.CPlusPlus14 && !langOpts.CPlusPlus17) {
    DAWN_LOG(WARNING) << "C++98 mode detected; switching to C++11";
    langOpts.CPlusPlus11 = 1;
  }

  // Infer the builtin (ressource) include path if unspecified
  if(GTClang->getHeaderSearchOpts().UseBuiltinIncludes &&
     GTClang->getHeaderSearchOpts().ResourceDir.empty())
    GTClang->getHeaderSearchOpts().ResourceDir =
        CompilerInvocation::GetResourcesPath(args[0], mainAddr);

  // Add the path to our DSL runtime
  SmallVector<StringRef, 2> DSLIncludes;
  StringRef(GTCLANG_DSL_INCLUDES).split(DSLIncludes, ';');
  for(const auto& path : DSLIncludes) {
    DAWN_LOG(INFO) << "Adding DSL include path: " << path.str();
    GTClang->getHeaderSearchOpts().AddPath(path, clang::frontend::System, false, true);
  }

  // Show the invocation, with -v
  if(CI->getHeaderSearchOpts().Verbose) {
    errs() << "gtclang invocation:\n";
    jobs.Print(errs(), "\n", true);
    errs() << "\n";
  }

  return GTClang;
}

} // namespace gtclang
<|endoftext|>


<commit_before><commit_msg>framework: fix utest hang occasionally<commit_after><|endoftext|>


<commit_before>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
    ui->setupUi(this);

    universe = &ui->centralwidget->universe;

    planetCountLabel = new QLabel(ui->statusbar);
    planetCountLabel->setFixedWidth(120);
    ui->statusbar->addPermanentWidget(planetCountLabel);
    fpsLabel = new QLabel(ui->statusbar);
    fpsLabel->setFixedWidth(120);
    ui->statusbar->addPermanentWidget(fpsLabel);
    averagefpsLabel = new QLabel(ui->statusbar);
    averagefpsLabel->setFixedWidth(160);
    ui->statusbar->addPermanentWidget(averagefpsLabel);

    connect(ui->actionCenter_All,                   SIGNAL(triggered()), universe, SLOT(centerAll()));
    connect(ui->actionInteractive_Planet_Placement, SIGNAL(triggered()), ui->centralwidget, SLOT(beginInteractiveCreation()));

    connect(ui->centralwidget, SIGNAL(updatePlanetCountStatusMessage(QString)), planetCountLabel, SLOT(setText(QString)));
    connect(ui->centralwidget, SIGNAL(updateFPSStatusMessage(QString)),         fpsLabel,         SLOT(setText(QString)));
    connect(ui->centralwidget, SIGNAL(updateAverageFPSStatusMessage(QString)),  averagefpsLabel,  SLOT(setText(QString)));
}

MainWindow::~MainWindow(){
    delete ui;
    delete planetCountLabel;
    delete averagefpsLabel;
    delete fpsLabel;
}

void MainWindow::on_actionExit_triggered(){
    float tmpsimspeed = universe->simspeed;
    universe->simspeed = 0.0f;

    QMessageBox areYouSureMsgbox(this);
    areYouSureMsgbox.setText(tr("Are you sure you wish to exit? (universe will not be saved...)"));
    areYouSureMsgbox.setWindowTitle(tr("Are You Sure?"));
    areYouSureMsgbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    areYouSureMsgbox.setDefaultButton(QMessageBox::Yes);
    areYouSureMsgbox.setIcon(QMessageBox::Warning);

    int input = areYouSureMsgbox.exec();

    if(input == QMessageBox::Yes){
        this->close();
    }
    universe->simspeed = tmpsimspeed;
}

void MainWindow::on_createPlanet_PushButton_clicked(){
    universe->selected = universe->createPlanet(QVector3D(ui->newPosX_SpinBox->value(),      ui->newPosY_SpinBox->value(),      ui->newPosZ_SpinBox->value()),
                                                QVector3D(ui->newVelocityX_SpinBox->value(), ui->newVelocityY_SpinBox->value(), ui->newVelocityZ_SpinBox->value()) * velocityfac,
                                                ui->newMass_SpinBox->value());
}

void MainWindow::on_speed_Dial_valueChanged(int value){
    universe->simspeed = (value*  speeddialmax) / ui->speed_Dial->maximum();
    ui->speedDisplay_lcdNumber->display(universe->simspeed);
    if(universe->simspeed <= 0.0f){
        ui->PauseResume_Button->setText(tr("Resume"));
        ui->PauseResume_Button->setIcon(QIcon(":/icons/silk/control_play_blue.png"));
    }
    else{
        ui->PauseResume_Button->setText(tr("Pause"));
        ui->PauseResume_Button->setIcon(QIcon(":/icons/silk/control_pause_blue.png"));
    }
}

void MainWindow::on_PauseResume_Button_clicked(){
    if(universe->simspeed <= 0.0f){
        universe->simspeed = 1.0f;
        ui->PauseResume_Button->setText(tr("Pause"));
        ui->PauseResume_Button->setIcon(QIcon(":/icons/silk/control_pause_blue.png"));
    }
    else{
        universe->simspeed = 0.0f;
        ui->PauseResume_Button->setText(tr("Resume"));
        ui->PauseResume_Button->setIcon(QIcon(":/icons/silk/control_play_blue.png"));
    }
    ui->speedDisplay_lcdNumber->display(universe->simspeed);
    ui->speed_Dial->setValue((universe->simspeed / speeddialmax) * ui->speed_Dial->maximum());
}

void MainWindow::on_actionTake_Screenshot_triggered(){
    ui->centralwidget->doScreenshot = true;
}

void MainWindow::on_actionDelete_triggered(){
    if(universe->selected){
        universe->planets.remove(universe->selected);
    }
}

void MainWindow::on_actionClear_Velocity_triggered(){
    if(universe->planets.contains(universe->selected)){
        universe->planets[universe->selected].velocity = QVector3D();
    }
}

void MainWindow::on_actionNew_Simulation_triggered(){
    float tmpsimspeed = universe->simspeed;
    universe->simspeed = 0.0f;

    QMessageBox areYouSureMsgbox(this);
    areYouSureMsgbox.setText(tr("Are you sure you wish to destroy the universe? (i.e. delete all planets.)"));
    areYouSureMsgbox.setWindowTitle(tr("Are You Sure?"));
    areYouSureMsgbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    areYouSureMsgbox.setDefaultButton(QMessageBox::Yes);
    areYouSureMsgbox.setIcon(QMessageBox::Warning);

    int input = areYouSureMsgbox.exec();

    if(input == QMessageBox::Yes){
       universe->deleteAll();
    }
    universe->simspeed = tmpsimspeed;
}

void MainWindow::on_actionOff_triggered(){
    ui->centralwidget->displaysettings &= ~PlanetsWidget::SolidLineGrid;
    ui->centralwidget->displaysettings &= ~PlanetsWidget::PointGrid;
    ui->actionLines->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::SolidLineGrid);
    ui->actionPoints->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PointGrid);
}

void MainWindow::on_actionLines_triggered(){
    ui->centralwidget->displaysettings |= PlanetsWidget::SolidLineGrid;
    ui->centralwidget->displaysettings &= ~PlanetsWidget::PointGrid;
    ui->actionLines->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::SolidLineGrid);
    ui->actionPoints->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PointGrid);
}

void MainWindow::on_actionPoints_triggered(){
    ui->centralwidget->displaysettings &= ~PlanetsWidget::SolidLineGrid;
    ui->centralwidget->displaysettings |= PlanetsWidget::PointGrid;
    ui->actionLines->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::SolidLineGrid);
    ui->actionPoints->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PointGrid);
}

void MainWindow::on_actionOpen_Simulation_triggered(){
    float tmpsimspeed = universe->simspeed;
    universe->simspeed = 0;

    QString filename = QFileDialog::getOpenFileName(this,tr("Open Simulation"), "", tr("Simulation files (*.uni *.xml)"));
    universe->load(filename);

    universe->simspeed = tmpsimspeed;
}

void MainWindow::on_actionSave_Simulation_triggered(){
    float tmpsimspeed = universe->simspeed;
    universe->simspeed = 0;

    QString filename = QFileDialog::getSaveFileName(this,tr("Save Simulation"), "", tr("Simulation files (*.uni *.xml)"));
    universe->save(filename);

    universe->simspeed = tmpsimspeed;
}

void MainWindow::on_actionDraw_Paths_triggered(){
    ui->centralwidget->displaysettings ^= PlanetsWidget::PlanetTrails;

    ui->actionDraw_Paths->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PlanetTrails);
}

void MainWindow::on_actionMotion_Blur_triggered(){
    ui->centralwidget->displaysettings ^= PlanetsWidget::MotionBlur;

    ui->actionMotion_Blur->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::MotionBlur);
}

void MainWindow::on_followPlanetPushButton_clicked(){
    ui->centralwidget->following = universe->selected;
    ui->centralwidget->followState = PlanetsWidget::Single;

}

void MainWindow::on_clearFollowPushButton_clicked(){
    ui->centralwidget->following = 0;
    ui->centralwidget->followState = PlanetsWidget::FollowNone;
}

void MainWindow::on_actionAbout_triggered(){
    QMessageBox::about(this, "About Planets3D",
                       tr(""
                       "
Planets3D is a 3D gravitational simulator, inspired by Planets
"
                       "
Website: github.com/chipgw/planets-3d
"
                       "
Git sha1: %1
"
                       "
Build type: %2
"
                       "").arg(version::git_revision).arg(version::build_type));
}

void MainWindow::on_actionAbout_Qt_triggered(){
    QMessageBox::aboutQt(this);
}

void MainWindow::on_followPlainAveragePushButton_clicked(){
    ui->centralwidget->followState = PlanetsWidget::PlainAverage;
}

void MainWindow::on_followWeightedAveragePushButton_clicked(){
    ui->centralwidget->followState = PlanetsWidget::WeightedAverage;
}

void MainWindow::on_stepsPerFrameSpinBox_valueChanged(int value){
    ui->centralwidget->stepsPerFrame = value;
}

void MainWindow::on_trailLengthSpinBox_valueChanged(int value){
    Planet::pathLength = value;
}

void MainWindow::on_gridRangeSpinBox_valueChanged(int value){
    ui->centralwidget->gridRange = (value - 1) / 2;
}

void MainWindow::on_actionPlanet_Colors_triggered(){
    ui->centralwidget->displaysettings ^= PlanetsWidget::PlanetColors;

    ui->actionMotion_Blur->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PlanetColors);
}
<commit_msg>minor error in last commit.<commit_after>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
    ui->setupUi(this);

    universe = &ui->centralwidget->universe;

    planetCountLabel = new QLabel(ui->statusbar);
    planetCountLabel->setFixedWidth(120);
    ui->statusbar->addPermanentWidget(planetCountLabel);
    fpsLabel = new QLabel(ui->statusbar);
    fpsLabel->setFixedWidth(120);
    ui->statusbar->addPermanentWidget(fpsLabel);
    averagefpsLabel = new QLabel(ui->statusbar);
    averagefpsLabel->setFixedWidth(160);
    ui->statusbar->addPermanentWidget(averagefpsLabel);

    connect(ui->actionCenter_All,                   SIGNAL(triggered()), universe, SLOT(centerAll()));
    connect(ui->actionInteractive_Planet_Placement, SIGNAL(triggered()), ui->centralwidget, SLOT(beginInteractiveCreation()));

    connect(ui->centralwidget, SIGNAL(updatePlanetCountStatusMessage(QString)), planetCountLabel, SLOT(setText(QString)));
    connect(ui->centralwidget, SIGNAL(updateFPSStatusMessage(QString)),         fpsLabel,         SLOT(setText(QString)));
    connect(ui->centralwidget, SIGNAL(updateAverageFPSStatusMessage(QString)),  averagefpsLabel,  SLOT(setText(QString)));
}

MainWindow::~MainWindow(){
    delete ui;
    delete planetCountLabel;
    delete averagefpsLabel;
    delete fpsLabel;
}

void MainWindow::on_actionExit_triggered(){
    float tmpsimspeed = universe->simspeed;
    universe->simspeed = 0.0f;

    QMessageBox areYouSureMsgbox(this);
    areYouSureMsgbox.setText(tr("Are you sure you wish to exit? (universe will not be saved...)"));
    areYouSureMsgbox.setWindowTitle(tr("Are You Sure?"));
    areYouSureMsgbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    areYouSureMsgbox.setDefaultButton(QMessageBox::Yes);
    areYouSureMsgbox.setIcon(QMessageBox::Warning);

    int input = areYouSureMsgbox.exec();

    if(input == QMessageBox::Yes){
        this->close();
    }
    universe->simspeed = tmpsimspeed;
}

void MainWindow::on_createPlanet_PushButton_clicked(){
    universe->selected = universe->createPlanet(QVector3D(ui->newPosX_SpinBox->value(),      ui->newPosY_SpinBox->value(),      ui->newPosZ_SpinBox->value()),
                                                QVector3D(ui->newVelocityX_SpinBox->value(), ui->newVelocityY_SpinBox->value(), ui->newVelocityZ_SpinBox->value()) * velocityfac,
                                                ui->newMass_SpinBox->value());
}

void MainWindow::on_speed_Dial_valueChanged(int value){
    universe->simspeed = (value*  speeddialmax) / ui->speed_Dial->maximum();
    ui->speedDisplay_lcdNumber->display(universe->simspeed);
    if(universe->simspeed <= 0.0f){
        ui->PauseResume_Button->setText(tr("Resume"));
        ui->PauseResume_Button->setIcon(QIcon(":/icons/silk/control_play_blue.png"));
    }
    else{
        ui->PauseResume_Button->setText(tr("Pause"));
        ui->PauseResume_Button->setIcon(QIcon(":/icons/silk/control_pause_blue.png"));
    }
}

void MainWindow::on_PauseResume_Button_clicked(){
    if(universe->simspeed <= 0.0f){
        universe->simspeed = 1.0f;
        ui->PauseResume_Button->setText(tr("Pause"));
        ui->PauseResume_Button->setIcon(QIcon(":/icons/silk/control_pause_blue.png"));
    }
    else{
        universe->simspeed = 0.0f;
        ui->PauseResume_Button->setText(tr("Resume"));
        ui->PauseResume_Button->setIcon(QIcon(":/icons/silk/control_play_blue.png"));
    }
    ui->speedDisplay_lcdNumber->display(universe->simspeed);
    ui->speed_Dial->setValue((universe->simspeed / speeddialmax) * ui->speed_Dial->maximum());
}

void MainWindow::on_actionTake_Screenshot_triggered(){
    ui->centralwidget->doScreenshot = true;
}

void MainWindow::on_actionDelete_triggered(){
    if(universe->selected){
        universe->planets.remove(universe->selected);
    }
}

void MainWindow::on_actionClear_Velocity_triggered(){
    if(universe->planets.contains(universe->selected)){
        universe->planets[universe->selected].velocity = QVector3D();
    }
}

void MainWindow::on_actionNew_Simulation_triggered(){
    float tmpsimspeed = universe->simspeed;
    universe->simspeed = 0.0f;

    QMessageBox areYouSureMsgbox(this);
    areYouSureMsgbox.setText(tr("Are you sure you wish to destroy the universe? (i.e. delete all planets.)"));
    areYouSureMsgbox.setWindowTitle(tr("Are You Sure?"));
    areYouSureMsgbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    areYouSureMsgbox.setDefaultButton(QMessageBox::Yes);
    areYouSureMsgbox.setIcon(QMessageBox::Warning);

    int input = areYouSureMsgbox.exec();

    if(input == QMessageBox::Yes){
       universe->deleteAll();
    }
    universe->simspeed = tmpsimspeed;
}

void MainWindow::on_actionOff_triggered(){
    ui->centralwidget->displaysettings &= ~PlanetsWidget::SolidLineGrid;
    ui->centralwidget->displaysettings &= ~PlanetsWidget::PointGrid;
    ui->actionLines->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::SolidLineGrid);
    ui->actionPoints->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PointGrid);
}

void MainWindow::on_actionLines_triggered(){
    ui->centralwidget->displaysettings |= PlanetsWidget::SolidLineGrid;
    ui->centralwidget->displaysettings &= ~PlanetsWidget::PointGrid;
    ui->actionLines->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::SolidLineGrid);
    ui->actionPoints->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PointGrid);
}

void MainWindow::on_actionPoints_triggered(){
    ui->centralwidget->displaysettings &= ~PlanetsWidget::SolidLineGrid;
    ui->centralwidget->displaysettings |= PlanetsWidget::PointGrid;
    ui->actionLines->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::SolidLineGrid);
    ui->actionPoints->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PointGrid);
}

void MainWindow::on_actionOpen_Simulation_triggered(){
    float tmpsimspeed = universe->simspeed;
    universe->simspeed = 0;

    QString filename = QFileDialog::getOpenFileName(this,tr("Open Simulation"), "", tr("Simulation files (*.uni *.xml)"));
    universe->load(filename);

    universe->simspeed = tmpsimspeed;
}

void MainWindow::on_actionSave_Simulation_triggered(){
    float tmpsimspeed = universe->simspeed;
    universe->simspeed = 0;

    QString filename = QFileDialog::getSaveFileName(this,tr("Save Simulation"), "", tr("Simulation files (*.uni *.xml)"));
    universe->save(filename);

    universe->simspeed = tmpsimspeed;
}

void MainWindow::on_actionDraw_Paths_triggered(){
    ui->centralwidget->displaysettings ^= PlanetsWidget::PlanetTrails;

    ui->actionDraw_Paths->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PlanetTrails);
}

void MainWindow::on_actionMotion_Blur_triggered(){
    ui->centralwidget->displaysettings ^= PlanetsWidget::MotionBlur;

    ui->actionMotion_Blur->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::MotionBlur);
}

void MainWindow::on_followPlanetPushButton_clicked(){
    ui->centralwidget->following = universe->selected;
    ui->centralwidget->followState = PlanetsWidget::Single;

}

void MainWindow::on_clearFollowPushButton_clicked(){
    ui->centralwidget->following = 0;
    ui->centralwidget->followState = PlanetsWidget::FollowNone;
}

void MainWindow::on_actionAbout_triggered(){
    QMessageBox::about(this, "About Planets3D",
                       tr(""
                       "
Planets3D is a 3D gravitational simulator, inspired by Planets
"
                       "
Website: github.com/chipgw/planets-3d
"
                       "
Git sha1: %1
"
                       "
Build type: %2
"
                       "").arg(version::git_revision).arg(version::build_type));
}

void MainWindow::on_actionAbout_Qt_triggered(){
    QMessageBox::aboutQt(this);
}

void MainWindow::on_followPlainAveragePushButton_clicked(){
    ui->centralwidget->followState = PlanetsWidget::PlainAverage;
}

void MainWindow::on_followWeightedAveragePushButton_clicked(){
    ui->centralwidget->followState = PlanetsWidget::WeightedAverage;
}

void MainWindow::on_stepsPerFrameSpinBox_valueChanged(int value){
    ui->centralwidget->stepsPerFrame = value;
}

void MainWindow::on_trailLengthSpinBox_valueChanged(int value){
    Planet::pathLength = value;
}

void MainWindow::on_gridRangeSpinBox_valueChanged(int value){
    ui->centralwidget->gridRange = (value - 1) / 2;
}

void MainWindow::on_actionPlanet_Colors_triggered(){
    ui->centralwidget->displaysettings ^= PlanetsWidget::PlanetColors;

    ui->actionPlanet_Colors->setChecked(ui->centralwidget->displaysettings & PlanetsWidget::PlanetColors);
}
<|endoftext|>


<commit_before>#include <getopt.h>
#include "dlib/bam_util.h"

int usage(char **argv, int retcode=EXIT_FAILURE) {
    fprintf(stderr, "MASKRIPPER version %s.\n"
                    "Usage: maskripper <opts> in.bam out.bam\n"
                    "Flags:\n-m: Minimum trimmed read length. Default: 0.\n"
                    "-l: output compression level. Default: 6.\n"
                    "-S: output in sam format.\n"
                    "-s: perform single-end analyisis. This option results in imbalanced pairs on paired-end data.\n"
                    "Use - for stdin or stdout.\n", MASKRIPPER_VERSION);
    return retcode;
}
struct opts_t {
    uint8_t *data;
    uint32_t l_data:16;
    uint32_t m_data:16;
    uint32_t n_cigar:8;
    uint32_t min_trimmed_len:8;
    ~opts_t() {if(data) free(data);}
    void resize(uint32_t new_min) {
        if(new_min > m_data) {
            m_data = new_min;
            kroundup32(m_data);
            data = (uint8_t *)realloc(data, m_data * sizeof(uint8_t));
        }
    }
};

static int trim_ns(bam1_t *b, void *data) {
    // Currently passes all reads to keep balanced pairs. TODO: rewrite for pairs of reads and filter if both fail.
    opts_t *op((opts_t *)data);
    assert(bam_aux_get(b, "PV"));
    std::vector<uint8_t> aux(bam_get_aux(b), bam_get_aux(b) + bam_get_l_aux(b));
    int tmp;
    uint8_t *const seq(bam_get_seq(b));
    uint32_t *const cigar(bam_get_cigar(b));
    op->n_cigar = b->core.n_cigar;
    op->resize(b->l_data); // Make sure it's big enough to hold everything.
    memcpy(op->data, b->data, b->core.l_qname);

    // Get #Ns at the beginning
    for(tmp = 0; bam_seqi(seq, tmp) == dlib::htseq::HTS_N; ++tmp);
    const int n_start(tmp);

    if(tmp == b->core.l_qseq - 1) // all bases are N -- garbage read
         return 1; // Currently outputting to avoid

    // Get #Ns at the end
    for(tmp = b->core.l_qseq - 1; bam_seqi(seq, tmp) == dlib::htseq::HTS_N; --tmp);
    const int n_end(b->core.l_qseq - 1 - tmp);

    // Get new length for read
    const int final_len(b->core.l_qseq - n_end - n_start);
    if(final_len < op->min_trimmed_len) // Too short.
        return 1;

    if(n_end) {
        if((tmp = bam_cigar_oplen(cigar[b->core.n_cigar - 1]) - n_end) == 0) {
            LOG_DEBUG("Entire cigar operation is the softclip. Decrease the number of new cigar operations.\n");
            --op->n_cigar;
        } else {
            LOG_DEBUG("Updating second cigar operation in-place.\n");
            cigar[b->core.n_cigar - 1] = bam_cigar_gen(tmp, BAM_CSOFT_CLIP);
        }
    }

    // Get new n_cigar.
    if((tmp = bam_cigar_oplen(*cigar) - n_start) == 0) {
        --op->n_cigar;
        memcpy(op->data + b->core.l_qname, cigar + 1, op->n_cigar << 2); // << 2 for 4 bit per cigar op
    } else {
        if(n_start) *cigar = bam_cigar_gen(tmp, BAM_CSOFT_CLIP);
        memcpy(op->data + b->core.l_qname, cigar, op->n_cigar << 2);
    }
    uint8_t *opseq(op->data + b->core.l_qname + (op->n_cigar << 2)); // Pointer to the seq region of new data field.
    for(tmp = 0; tmp < final_len >> 1; ++tmp) {
        opseq[tmp] = (bam_seqi(seq, ((tmp << 1) + n_start)) << 4) | (bam_seqi(seq, (tmp << 1) + n_start + 1));
        assert(bam_seqi(opseq, tmp * 2) == bam_seqi(seq, (2 * tmp + n_start)));
        assert(bam_seqi(opseq, tmp * 2 + 1) == bam_seqi(seq, (2 * tmp + n_start + 1)));
    }
#if 0
    char tmpbuf[300];
    for(tmp = 0; tmp < final_len; ++tmp) {
        tmpbuf[tmp] = seq_nt16_str[bam_seqi(opseq, tmp)];
    }
    tmpbuf[tmp] = '\0';
    assert(strcmp(tmpbuf, "ANNCNNNGNNNNTNNNNCNNGGNNNNNNNNNCNNNNCNNNNNNNNAAAANNTNNNAAAAAAAAAAGAGAGAGGGAGAGAGACTATACACAGGCACCACCACATTTGGCTAATTTTT") == 0);
#endif

    // Copy in qual and all of aux.
    tmp = bam_get_l_aux(b);
    memcpy(opseq + ((final_len + 1) >> 1), bam_get_qual(b) + n_start, final_len + tmp);
    // Switch data strings
    std::swap(op->data, b->data);
    b->core.n_cigar = op->n_cigar;
    //b->l_data = b->core.l_qname + (op->n_cigar << 2) + ((final_len + 1) >> 1) + final_len + tmp;
    b->core.l_qseq = final_len;
    memcpy(bam_get_aux(b), aux.data(), aux.size());
    b->l_data = (bam_get_aux(b) - b->data) + aux.size();
    //trim_array_tags(b, n_start, n_end, final_len);
    if(n_end)
        bam_aux_append(b, "NE", 'i', sizeof(int), (uint8_t *)&n_end);
    if(n_start)
        bam_aux_append(b, "NS", 'i', sizeof(int), (uint8_t *)&n_start);
    const uint32_t *pvar = (uint32_t *)dlib::array_tag(b, "PV");
    tmp = b->core.flag & BAM_FREVERSE ? n_end: n_start;
    std::vector<uint32_t>pvals(pvar + tmp, pvar + final_len + tmp);
    const uint32_t *fvar = (uint32_t *)dlib::array_tag(b, "FA");
    std::vector<uint32_t>fvals(fvar + tmp, fvar + final_len + tmp);
    bam_aux_del(b, bam_aux_get(b, "PV"));
    bam_aux_del(b, bam_aux_get(b, "FA"));
    dlib::bam_aux_array_append(b, "PV", 'I', sizeof(uint32_t), final_len, (uint8_t *)pvals.data());
    dlib::bam_aux_array_append(b, "FA", 'I', sizeof(uint32_t), final_len, (uint8_t *)fvals.data());
    return 0;
}

static int pe_trim_ns(bam1_t *b1, bam1_t *b2, void *aux)
{
    return trim_ns(b1, aux) && trim_ns(b2, aux);
}

int main(int argc, char *argv[]) {
    if(argc < 3)
        return usage(argv);

    if(strcmp(argv[1], "--help") == 0)
        return usage(argv, EXIT_SUCCESS);

    int c;
    int is_se{0};
    char out_mode[4] = "wb";
    opts_t opts{0};
    while((c = getopt(argc, argv, "m:l:h?sS")) > -1) {
        switch(c) {
        case 'm': opts.min_trimmed_len = (uint32_t)atoi(optarg); break;
        case 'l': out_mode[2] = atoi(optarg) % 10 + '0'; break;
        case 's': is_se = 1; break;
        case 'S': sprintf(out_mode, "w"); break;
        case 'h': case '?': return usage(argv, EXIT_SUCCESS);
        }
    }
    if(argc - 2 != optind)
        LOG_EXIT("Required: precisely two positional arguments (in bam, out bam).\n");

    LOG_DEBUG("ZOUNDS\n");
    // Actually this function. You can't really apply a null function....
    dlib::BamHandle inHandle(argv[optind]);
    dlib::BamHandle outHandle(argv[optind + 1], inHandle.header, out_mode);
    if(is_se) {
        dlib::abstract_single_iter(inHandle.fp, inHandle.header, outHandle.fp,
                                   &trim_ns, (void *)&opts);
    } else {
        dlib::abstract_pair_iter(inHandle.fp, inHandle.header, outHandle.fp, &pe_trim_ns, (void *)&opts);
    }
    return EXIT_SUCCESS;
}
<commit_msg>Update maskripper.cpp<commit_after>#include <getopt.h>
#include "dlib/bam_util.h"

int usage(char **argv, int retcode=EXIT_FAILURE) {
    fprintf(stderr, "MASKRIPPER version %s.\n"
                    "Usage: maskripper <opts> in.bam out.bam\n"
                    "Flags:\n-m: Minimum trimmed read length. Default: 0.\n"
                    "-l: output compression level. Default: 6.\n"
                    "-S: output in sam format.\n"
                    "-s: perform single-end analyisis. This option results in imbalanced pairs on paired-end data.\n"
                    "Use - for stdin or stdout.\n", MASKRIPPER_VERSION);
    return retcode;
}

struct opts_t {
    uint8_t *data;
    uint32_t l_data:16;
    uint32_t m_data:16;
    uint32_t n_cigar:8;
    uint32_t min_trimmed_len:8;
    ~opts_t() {if(data) free(data);}
    void resize(uint32_t new_min) {
        if(new_min > m_data) {
            m_data = new_min;
            kroundup32(m_data);
            data = (uint8_t *)realloc(data, m_data * sizeof(uint8_t));
        }
    }
};

static int trim_ns(bam1_t *b, void *data) {
    // Currently passes all reads to keep balanced pairs. TODO: rewrite for pairs of reads and filter if both fail.
    opts_t *op((opts_t *)data);
    assert(bam_aux_get(b, "PV"));
    std::vector<uint8_t> aux(bam_get_aux(b), bam_get_aux(b) + bam_get_l_aux(b));
    int tmp;
    uint8_t *const seq(bam_get_seq(b));
    uint32_t *const cigar(bam_get_cigar(b));
    op->n_cigar = b->core.n_cigar;
    op->resize(b->l_data); // Make sure it's big enough to hold everything.
    memcpy(op->data, b->data, b->core.l_qname);

    // Get #Ns at the beginning
    for(tmp = 0; bam_seqi(seq, tmp) == dlib::htseq::HTS_N; ++tmp);
    const int n_start(tmp);

    if(tmp == b->core.l_qseq - 1) // all bases are N -- garbage read
         return 1; // Currently outputting to avoid

    // Get #Ns at the end
    for(tmp = b->core.l_qseq - 1; bam_seqi(seq, tmp) == dlib::htseq::HTS_N; --tmp);
    const int n_end(b->core.l_qseq - 1 - tmp);

    // Get new length for read
    const int final_len(b->core.l_qseq - n_end - n_start);
    if(final_len < op->min_trimmed_len) // Too short.
        return 1;

    if(n_end) {
        if((tmp = bam_cigar_oplen(cigar[b->core.n_cigar - 1]) - n_end) == 0) {
            LOG_DEBUG("Entire cigar operation is the softclip. Decrease the number of new cigar operations.\n");
            --op->n_cigar;
        } else {
            LOG_DEBUG("Updating second cigar operation in-place.\n");
            cigar[b->core.n_cigar - 1] = bam_cigar_gen(tmp, BAM_CSOFT_CLIP);
        }
    }

    // Get new n_cigar.
    if((tmp = bam_cigar_oplen(*cigar) - n_start) == 0) {
        --op->n_cigar;
        memcpy(op->data + b->core.l_qname, cigar + 1, op->n_cigar << 2); // << 2 for 4 bit per cigar op
    } else {
        if(n_start) *cigar = bam_cigar_gen(tmp, BAM_CSOFT_CLIP);
        memcpy(op->data + b->core.l_qname, cigar, op->n_cigar << 2);
    }
    uint8_t *opseq(op->data + b->core.l_qname + (op->n_cigar << 2)); // Pointer to the seq region of new data field.
    for(tmp = 0; tmp < final_len >> 1; ++tmp) {
        opseq[tmp] = (bam_seqi(seq, ((tmp << 1) + n_start)) << 4) | (bam_seqi(seq, (tmp << 1) + n_start + 1));
        assert(bam_seqi(opseq, tmp * 2) == bam_seqi(seq, (2 * tmp + n_start)));
        assert(bam_seqi(opseq, tmp * 2 + 1) == bam_seqi(seq, (2 * tmp + n_start + 1)));
    }
#if 0
    char tmpbuf[300];
    for(tmp = 0; tmp < final_len; ++tmp) {
        tmpbuf[tmp] = seq_nt16_str[bam_seqi(opseq, tmp)];
    }
    tmpbuf[tmp] = '\0';
    assert(strcmp(tmpbuf, "ANNCNNNGNNNNTNNNNCNNGGNNNNNNNNNCNNNNCNNNNNNNNAAAANNTNNNAAAAAAAAAAGAGAGAGGGAGAGAGACTATACACAGGCACCACCACATTTGGCTAATTTTT") == 0);
#endif

    // Copy in qual and all of aux.
    tmp = bam_get_l_aux(b);
    memcpy(opseq + ((final_len + 1) >> 1), bam_get_qual(b) + n_start, final_len + tmp);
    // Switch data strings
    std::swap(op->data, b->data);
    b->core.n_cigar = op->n_cigar;
    //b->l_data = b->core.l_qname + (op->n_cigar << 2) + ((final_len + 1) >> 1) + final_len + tmp;
    b->core.l_qseq = final_len;
    memcpy(bam_get_aux(b), aux.data(), aux.size());
    b->l_data = (bam_get_aux(b) - b->data) + aux.size();
    //trim_array_tags(b, n_start, n_end, final_len);
    if(n_end) bam_aux_append(b, "NE", 'i', sizeof(int), (uint8_t *)&n_end);
    if(n_start) bam_aux_append(b, "NS", 'i', sizeof(int), (uint8_t *)&n_start);
    const uint32_t *pvar = (uint32_t *)dlib::array_tag(b, "PV");
    tmp = b->core.flag & BAM_FREVERSE ? n_end: n_start;
    std::vector<uint32_t>pvals(pvar + tmp, pvar + final_len + tmp);
    const uint32_t *fvar = (uint32_t *)dlib::array_tag(b, "FA");
    std::vector<uint32_t>fvals(fvar + tmp, fvar + final_len + tmp);
    bam_aux_del(b, bam_aux_get(b, "PV"));
    bam_aux_del(b, bam_aux_get(b, "FA"));
    dlib::bam_aux_array_append(b, "PV", 'I', sizeof(uint32_t), final_len, (uint8_t *)pvals.data());
    dlib::bam_aux_array_append(b, "FA", 'I', sizeof(uint32_t), final_len, (uint8_t *)fvals.data());
    return 0;
}

static int pe_trim_ns(bam1_t *b1, bam1_t *b2, void *aux)
{
    return trim_ns(b1, aux) && trim_ns(b2, aux);
}

int main(int argc, char *argv[]) {
    if(argc < 3)
        return usage(argv);

    if(strcmp(argv[1], "--help") == 0)
        return usage(argv, EXIT_SUCCESS);

    int c;
    int is_se{0};
    char out_mode[4] = "wb";
    opts_t opts{0};
    while((c = getopt(argc, argv, "m:l:h?sS")) > -1) {
        switch(c) {
        case 'm': opts.min_trimmed_len = (uint32_t)atoi(optarg); break;
        case 'l': out_mode[2] = atoi(optarg) % 10 + '0'; break;
        case 's': is_se = 1; break;
        case 'S': sprintf(out_mode, "w"); break;
        case 'h': case '?': return usage(argv, EXIT_SUCCESS);
        }
    }

    if(argc - 2 != optind) LOG_EXIT("Required: precisely two positional arguments (in bam, out bam).\n");

    dlib::BamHandle inHandle(argv[optind]);
    dlib::BamHandle outHandle(argv[optind + 1], inHandle.header, out_mode);
    if(is_se)
        dlib::abstract_single_iter(inHandle.fp, inHandle.header, outHandle.fp,
                                   &trim_ns, (void *)&opts);
    else dlib::abstract_pair_iter(inHandle.fp, inHandle.header, outHandle.fp,
                                  &pe_trim_ns, (void *)&opts);
    return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>/*
  MspFlash.h - Read/Write flash memory library for MSP430 Energia
  Copyright (c) 2012 Peter Brier.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
#include "MspFlash.h"
#include <msp430.h>

// The Flash clock must be between 200 and 400 kHz to operate correctly
// TODO: calculate correct devider (0..64) depending on clock frequenct (F_CPU)
// Now we set F_CPU/64 is 250khz at F_CPU = 16MHz

#define FLASHCLOCK FSSEL1+((F_CPU/400000L) & 63); // SCLK

// erase flash, make sure pointer is in the segment you wish to erase, otherwise you may erase you program or some data
void MspFlashClass::erase(unsigned char *flash)
{
  WDTCTL = WDTPW+WDTHOLD;   // Disable WDT
  FCTL2 = FWKEY+FLASHCLOCK; // SMCLK/2
  FCTL3 = FWKEY;            // Clear LOCK
  FCTL1 = FWKEY+ERASE;      //Enable segment erase
  *flash = 0;               // Dummy write, erase Segment
  FCTL3 = FWKEY+LOCK;       // Done, set LOCK
}

// load from memory, at segment boundary
void MspFlashClass::read(unsigned char *flash, unsigned char *dest, int len)
{
  while(len--)
   *(dest++) = *(flash++);
}

// save in to flash (at segment boundary)
void MspFlashClass::write(unsigned char *flash, unsigned char *src, int len)
{
 WDTCTL = WDTPW+WDTHOLD;   // Disable WDT
 FCTL2 = FWKEY+FLASHCLOCK; // SMCLK/2
 FCTL3 = FWKEY;            // Clear LOCK
 FCTL1 = FWKEY+WRT;        // Enable write
 while(len--)      // Copy data
   *(flash++) = *(src++);
 FCTL1 = FWKEY;            //Done. Clear WRT
 FCTL3 = FWKEY+LOCK;       // Set LOCK
}

MspFlashClass Flash;
<commit_msg>Fix for delay() freeze after Flash.erase and read<commit_after>/*
  MspFlash.h - Read/Write flash memory library for MSP430 Energia
  Copyright (c) 2012 Peter Brier.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
#include "MspFlash.h"
#include <msp430.h>

// The Flash clock must be between 200 and 400 kHz to operate correctly
// TODO: calculate correct devider (0..64) depending on clock frequenct (F_CPU)
// Now we set F_CPU/64 is 250khz at F_CPU = 16MHz

#define FLASHCLOCK FSSEL1+((F_CPU/400000L) & 63); // SCLK

// erase flash, make sure pointer is in the segment you wish to erase, otherwise you may erase you program or some data
void MspFlashClass::erase(unsigned char *flash)
{
  WDTCTL = WDTPW+WDTHOLD;   // Disable WDT
  FCTL2 = FWKEY+FLASHCLOCK; // SMCLK/2
  FCTL3 = FWKEY;            // Clear LOCK
  FCTL1 = FWKEY+ERASE;      //Enable segment erase
  *flash = 0;               // Dummy write, erase Segment
  FCTL3 = FWKEY+LOCK;       // Done, set LOCK
  WDTCTL = WDTPW;           // Enable WDT
}

// load from memory, at segment boundary
void MspFlashClass::read(unsigned char *flash, unsigned char *dest, int len)
{
  while(len--)
   *(dest++) = *(flash++);
}

// save in to flash (at segment boundary)
void MspFlashClass::write(unsigned char *flash, unsigned char *src, int len)
{
 WDTCTL = WDTPW+WDTHOLD;   // Disable WDT
 FCTL2 = FWKEY+FLASHCLOCK; // SMCLK/2
 FCTL3 = FWKEY;            // Clear LOCK
 FCTL1 = FWKEY+WRT;        // Enable write
 while(len--)      // Copy data
   *(flash++) = *(src++);
 FCTL1 = FWKEY;            //Done. Clear WRT
 FCTL3 = FWKEY+LOCK;       // Set LOCK
  WDTCTL = WDTPW;           // Enable WDT
}

MspFlashClass Flash;
<|endoftext|>


<commit_before>#include "bladepsgi.hpp"

#include <sys/socket.h>
#include <sys/un.h>

#include <sstream>

static std::string
int64_to_string(int64_t value)
{
	std::ostringstream oss;
	oss << value;
	return oss.str();
}

static void
monitoring_sigquit_handler(int _unused)
{
	/* behave like worker_sigquit_handler */
	(void) _unused;
	_exit(2);
}

BPSGIMonitoring::BPSGIMonitoring(BPSGIMainApplication *mainapp)
	: mainapp_(mainapp)
{
}

void
BPSGIMonitoring::HandleClient(int listensockfd, std::vector<char> worker_status_array)
{
	struct sockaddr_un their_addr;
	socklen_t addr_size = sizeof(their_addr);

	int clientfd = accept(listensockfd, (struct sockaddr *) &their_addr, &addr_size);
	if (clientfd == -1)
	{
		if (errno == EINTR || errno == ECONNABORTED)
		{
			/* we'll get called again if there's still a client waiting */
			return;
		}
		throw SyscallException("accept", errno);
	}

	auto shmem = mainapp_->shmem();

	auto statdata = std::string(worker_status_array.data(), worker_status_array.size()) + "\n";
	statdata += int64_to_string(shmem->ReadRequestCounter()) + "\n";
	for (auto && sem : shmem->semaphores_)
		statdata += "sem " + sem->name() + ": " + int64_to_string(sem->Read()) + "\n";
	for (auto && atm : shmem->atomics_)
		statdata += "atomic " + atm->name() + ": " + int64_to_string(atm->Read()) + "\n";

	auto written = write(clientfd, statdata.c_str(), statdata.size());
	(void) written;
	shutdown(clientfd, SHUT_RDWR);
	close(clientfd);
}

int
BPSGIMonitoring::Run()
{
	mainapp_->SubprocessInit("monitoring", SUBP_NO_DEATHSIG);
	mainapp_->SetSignalHandler(SIGINT, SIG_DFL);
	mainapp_->SetSignalHandler(SIGTERM, SIG_DFL);
	mainapp_->SetSignalHandler(SIGQUIT, monitoring_sigquit_handler);
	mainapp_->UnblockSignals();

	int listen_sockfd = mainapp_->stats_sockfd();

	int nworkers = mainapp_->nworkers();
	auto worker_status_data = std::vector<char>(nworkers);
	auto shmem = mainapp_->shmem();

	for (;;)
	{
		struct timeval tv;
		fd_set fds;

		if (mainapp_->RunnerDied())
		{
			if (mainapp_->shmem()->SetShouldExitImmediately())
				mainapp_->Log(LS_FATAL, "monitoring process noticed that the parent process has died; terminating all processes");
			_exit(1);
		}

		memset(&tv, 0, sizeof(tv));
		tv.tv_sec = 1;
		tv.tv_usec = 0;

		FD_ZERO(&fds);
		FD_SET(listen_sockfd, &fds);

		int ret = select(listen_sockfd + 1, &fds, NULL, NULL, &tv);
		if (ret == 0)
			continue;
		else if (ret == -1)
		{
			if (errno != EINTR)
				throw SyscallException("select", errno);
		}
		else if (ret == 1)
		{
			shmem->GetAllWorkerStatuses(nworkers, worker_status_data.data());
			HandleClient(listen_sockfd, worker_status_data);
			continue;
		}
		else
			throw SyscallException("select", "unexpected return value %d", ret);
	}
}
<commit_msg>Separate internal monitoring data from user objects with an empty line<commit_after>#include "bladepsgi.hpp"

#include <sys/socket.h>
#include <sys/un.h>

#include <sstream>

static std::string
int64_to_string(int64_t value)
{
	std::ostringstream oss;
	oss << value;
	return oss.str();
}

static void
monitoring_sigquit_handler(int _unused)
{
	/* behave like worker_sigquit_handler */
	(void) _unused;
	_exit(2);
}

BPSGIMonitoring::BPSGIMonitoring(BPSGIMainApplication *mainapp)
	: mainapp_(mainapp)
{
}

void
BPSGIMonitoring::HandleClient(int listensockfd, std::vector<char> worker_status_array)
{
	struct sockaddr_un their_addr;
	socklen_t addr_size = sizeof(their_addr);

	int clientfd = accept(listensockfd, (struct sockaddr *) &their_addr, &addr_size);
	if (clientfd == -1)
	{
		if (errno == EINTR || errno == ECONNABORTED)
		{
			/* we'll get called again if there's still a client waiting */
			return;
		}
		throw SyscallException("accept", errno);
	}

	auto shmem = mainapp_->shmem();

	auto statdata = std::string(worker_status_array.data(), worker_status_array.size()) + "\n";
	statdata += int64_to_string(shmem->ReadRequestCounter()) + "\n";
	statdata += "\n";
	for (auto && sem : shmem->semaphores_)
		statdata += "sem " + sem->name() + ": " + int64_to_string(sem->Read()) + "\n";
	for (auto && atm : shmem->atomics_)
		statdata += "atomic " + atm->name() + ": " + int64_to_string(atm->Read()) + "\n";

	auto written = write(clientfd, statdata.c_str(), statdata.size());
	(void) written;
	shutdown(clientfd, SHUT_RDWR);
	close(clientfd);
}

int
BPSGIMonitoring::Run()
{
	mainapp_->SubprocessInit("monitoring", SUBP_NO_DEATHSIG);
	mainapp_->SetSignalHandler(SIGINT, SIG_DFL);
	mainapp_->SetSignalHandler(SIGTERM, SIG_DFL);
	mainapp_->SetSignalHandler(SIGQUIT, monitoring_sigquit_handler);
	mainapp_->UnblockSignals();

	int listen_sockfd = mainapp_->stats_sockfd();

	int nworkers = mainapp_->nworkers();
	auto worker_status_data = std::vector<char>(nworkers);
	auto shmem = mainapp_->shmem();

	for (;;)
	{
		struct timeval tv;
		fd_set fds;

		if (mainapp_->RunnerDied())
		{
			if (mainapp_->shmem()->SetShouldExitImmediately())
				mainapp_->Log(LS_FATAL, "monitoring process noticed that the parent process has died; terminating all processes");
			_exit(1);
		}

		memset(&tv, 0, sizeof(tv));
		tv.tv_sec = 1;
		tv.tv_usec = 0;

		FD_ZERO(&fds);
		FD_SET(listen_sockfd, &fds);

		int ret = select(listen_sockfd + 1, &fds, NULL, NULL, &tv);
		if (ret == 0)
			continue;
		else if (ret == -1)
		{
			if (errno != EINTR)
				throw SyscallException("select", errno);
		}
		else if (ret == 1)
		{
			shmem->GetAllWorkerStatuses(nworkers, worker_status_data.data());
			HandleClient(listen_sockfd, worker_status_data);
			continue;
		}
		else
			throw SyscallException("select", "unexpected return value %d", ret);
	}
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: JoinDesignView.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 15:29:02 $
 *
 *  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 DBAUI_JOINDESIGNVIEW_HXX
#define DBAUI_JOINDESIGNVIEW_HXX

#ifndef DBAUI_DATAVIEW_HXX
#include "dataview.hxx"
#endif
#ifndef _VECTOR_
#include <vector>
#endif
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif
#ifndef DBAUI_ENUMTYPES_HXX
#include "QEnumTypes.hxx"
#endif
//#ifndef DBAUI_JOINTABLEVIEW_HXX
//#include "JoinTableView.hxx"
//#endif

namespace dbaui
{
    class OAddTableDlg;
    class OTableConnection;
    class OConnectionLineData;
    class OJoinController;
    class OScrollWindowHelper;
    class OJoinTableView;
    class OTableWindow;

    class OJoinDesignView : public ODataView
    {
    protected:
        OScrollWindowHelper*    m_pScrollWindow;    // contains only the scrollbars
        OJoinTableView*         m_pTableView;       // presents the upper window
        OAddTableDlg*           m_pAddTabDlg;       // create by the first execute of the add table slot
        OJoinController*        m_pController;

    public:
        OJoinDesignView(Window* pParent,
                        OJoinController* _pController,
                        const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& );
        virtual ~OJoinDesignView();

        // set the view readonly or not
        virtual void setReadOnly(sal_Bool _bReadOnly);
        // set the statement for representation
        /// late construction
        virtual void Construct();
        virtual void initialize();
        virtual void KeyInput( const KeyEvent& rEvt );

        virtual void SaveTabWinUIConfig(OTableWindow* pWin);
        OJoinController* getController() const { return m_pController; }
        // returs the add table dialog from the design view
        OAddTableDlg* getAddTableDialog() { return m_pAddTabDlg; }
        // called when fields are deleted
        // called when a table from tabeview was deleted
        void TableDeleted(const ::rtl::OUString& rAliasName);

        OJoinTableView* getTableView() const { return m_pTableView; }
        void zoomTableView(const Fraction& _rFraction);
        void SaveUIConfig();
    protected:
        // return the Rectangle where I can paint myself
        virtual void resizeDocumentView(Rectangle& rRect);
        DECL_LINK( SplitHdl, void* );
    };
}
#endif // DBAUI_JOINDESIGNVIEW_HXX

<commit_msg>INTEGRATION: CWS qiq (1.7.124); FILE MERGED 2006/05/17 11:45:15 fs 1.7.124.2: #i51143# AddTableDialog is now in the responsibility of the controller, not the view (allows late construction as needed) 2006/05/12 11:09:00 fs 1.7.124.1: #i51143# +m_pDialogContext<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: JoinDesignView.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: obo $ $Date: 2006-07-10 15:28:19 $
 *
 *  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 DBAUI_JOINDESIGNVIEW_HXX
#define DBAUI_JOINDESIGNVIEW_HXX

#ifndef DBAUI_DATAVIEW_HXX
#include "dataview.hxx"
#endif
#ifndef _VECTOR_
#include <vector>
#endif
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif
#ifndef DBAUI_ENUMTYPES_HXX
#include "QEnumTypes.hxx"
#endif

#include <memory>

namespace dbaui
{
    class OTableConnection;
    class OConnectionLineData;
    class OJoinController;
    class OScrollWindowHelper;
    class OJoinTableView;
    class OTableWindow;

    class OJoinDesignView : public ODataView
    {
    protected:
        OScrollWindowHelper*    m_pScrollWindow;    // contains only the scrollbars
        OJoinTableView*         m_pTableView;       // presents the upper window
        OJoinController*        m_pController;

    public:
        OJoinDesignView(Window* pParent,
                        OJoinController* _pController,
                        const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& );
        virtual ~OJoinDesignView();

        // set the view readonly or not
        virtual void setReadOnly(sal_Bool _bReadOnly);
        // set the statement for representation
        /// late construction
        virtual void Construct();
        virtual void initialize();
        virtual void KeyInput( const KeyEvent& rEvt );

        virtual void SaveTabWinUIConfig(OTableWindow* pWin);
        OJoinController* getController() const { return m_pController; }
        // called when fields are deleted
        // called when a table from tabeview was deleted
        void TableDeleted(const ::rtl::OUString& rAliasName);

        OJoinTableView* getTableView() const { return m_pTableView; }
        void zoomTableView(const Fraction& _rFraction);
        void SaveUIConfig();
    protected:
        // return the Rectangle where I can paint myself
        virtual void resizeDocumentView(Rectangle& rRect);
        DECL_LINK( SplitHdl, void* );
    };
}
#endif // DBAUI_JOINDESIGNVIEW_HXX

<|endoftext|>