<commit_before>/** \brief A MARC-21 filter utility that can remove records based on patterns for MARC subfields.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2016 Universitätsbiblothek 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 <memory>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <getopt.h>
#include "DirectoryEntry.h"
#include "FileUtil.h"
#include "Leader.h"
#include "MarcUtil.h"
#include "MarcXmlWriter.h"
#include "MediaTypeUtil.h"
#include "RegexMatcher.h"
#include "StringUtil.h"
#include "Subfields.h"
#include "util.h"

void Usage() {
    std::cerr << "usage: " << progname << " (--drop|--keep|--remove-fields) [--output-format=(marc-xml|marc-21)] marc_input marc_output field_or_subfieldspec1:regex1 "
              << "[field_or_subfieldspec2:regex2 .. field_or_subfieldspecN:regexN]\n"
              << "       where \"field_or_subfieldspec\" must either be a MARC tag or a MARC tag followed by a\n"
              << "       single-character subfield code and \"regex\" is a Perl-compatible regular expression.\n"
              << "       If you don't specify an output format it will be the same as the input format.\n\n";

    std::exit(EXIT_FAILURE);
}

class CompiledPattern {
    std::string tag_;
    char subfield_code_;
    RegexMatcher matcher_;
public:
    static const char NO_SUBFIELD_CODE;
public:
    CompiledPattern(const std::string &tag, const char subfield_code,  const RegexMatcher &matcher)
        : tag_(tag), subfield_code_(subfield_code), matcher_(matcher) {}
    const std::string &getTag() const { return tag_; }
    bool hasSubfieldCode() const { return subfield_code_ != NO_SUBFIELD_CODE; }
    char getSubfieldCode() const { return subfield_code_; }
    bool fieldMatched(const std::string &field_contents) const;
    bool subfieldMatched(const std::string &subfield_contents) const;
};

const char CompiledPattern::NO_SUBFIELD_CODE('\0');

bool CompiledPattern::fieldMatched(const std::string &field_contents) const {
    std::string err_msg;
    const bool retval = matcher_.matched(field_contents, &err_msg);
    if (not retval and not err_msg.empty())
        Error("Unexpected error while trying to match a field in CompiledPattern::fieldMatched(): " + err_msg);

    return retval;
}

bool CompiledPattern::subfieldMatched(const std::string &subfield_contents) const {
    std::string err_msg;
    const bool retval = matcher_.matched(subfield_contents, &err_msg);
    if (not retval and not err_msg.empty())
        Error("Unexpected error while trying to match a subfield in CompiledPattern::subfieldMatched(): " + err_msg);

    return retval;
}

// Expects "patterns" to contain strings that look like TTTS:REGEX where TTT are 3 characters specifying a field,
// S is a subfield code and REGEX is a PCRE-style regex supporting UTF8 that should match subfield contents.
// Alteratively a pattern can look like TTT:REGEX where TTT is a tag and we have no subfield code.
bool CompilePatterns(const std::vector<std::string> &patterns, std::vector<CompiledPattern> * const compiled_patterns,
                     std::string * const err_msg)
{
    compiled_patterns->clear();
    compiled_patterns->reserve(patterns.size());

    for (const auto &pattern : patterns) {
        std::string tag;
        char subfield_code;
        std::string::size_type first_colon_pos = pattern.find(':');
        if (first_colon_pos == std::string::npos) {
            *err_msg = "missing colon!";
            return false;
        } else if (first_colon_pos == DirectoryEntry::TAG_LENGTH) {
            tag = pattern.substr(0, 3);
            subfield_code = CompiledPattern::NO_SUBFIELD_CODE;
        } else if (first_colon_pos == DirectoryEntry::TAG_LENGTH + 1) {
            tag = pattern.substr(0, 3);
            subfield_code = pattern[3];
        } else {
            *err_msg = "colon in wrong position (" + std::to_string(first_colon_pos) + ")! (Tag length must be "
                       + std::to_string(DirectoryEntry::TAG_LENGTH) + ".)";
            return false;
        }

        const std::string regex_string(pattern.substr(first_colon_pos + 1));
        RegexMatcher * const new_matcher(RegexMatcher::RegexMatcherFactory(regex_string, err_msg));
        if (new_matcher == nullptr) {
            *err_msg = "failed to compile regular expression: \"" + regex_string + "\"! (" + *err_msg +")";
            return false;
        }

        compiled_patterns->push_back(CompiledPattern(tag, subfield_code, std::move(*new_matcher)));
        delete new_matcher;
    }

    return true;
}

/** Returns true if we have at least one match. */
bool Matched(const MarcUtil::Record &record, const std::vector<DirectoryEntry> &dir_entries,
             const std::vector<std::string> &fields, const std::vector<CompiledPattern> &compiled_patterns,
             std::vector<size_t> * const matched_field_indices)
{
    matched_field_indices->clear();

    bool matched_at_least_one(false);
    for (const auto &compiled_pattern : compiled_patterns) {
        ssize_t index(record.getFieldIndex(compiled_pattern.getTag()));
        if (index == -1)
            continue;

        for (/* Intentionally empty! */;
             static_cast<size_t>(index) < fields.size() and dir_entries[index].getTag() == compiled_pattern.getTag();
             ++index)
        {
            if (compiled_pattern.hasSubfieldCode()) {
                const Subfields subfields(fields[index]);
                const auto begin_end(subfields.getIterators(compiled_pattern.getSubfieldCode()));
                for (auto subfield_code_and_value(begin_end.first); subfield_code_and_value != begin_end.second;
                     ++subfield_code_and_value)
                {
                    if (compiled_pattern.subfieldMatched(subfield_code_and_value->second)) {
                        matched_field_indices->emplace_back(index);
                        matched_at_least_one = true;
                    }
                }
            } else if (compiled_pattern.fieldMatched(fields[index])) {
                matched_field_indices->emplace_back(index);
                matched_at_least_one = true;
            }
        }
    }

    return matched_at_least_one;
}

namespace {

enum class OutputFormat { MARC_XML, MARC_21, SAME_AS_INPUT };
enum class OperationType { KEEP, DROP, REMOVE_FIELDS };

} // unnamed namespace

void Filter(const bool input_is_xml, const OutputFormat output_format, const std::vector<std::string> &patterns,
            const OperationType operation_type, File * const input, File * const output)
{
    MarcXmlWriter *xml_writer(nullptr);
    if ((output_format == OutputFormat::SAME_AS_INPUT and input_is_xml) or output_format == OutputFormat::MARC_XML)
        xml_writer = new MarcXmlWriter(output);

    std::vector<CompiledPattern> compiled_patterns;
    std::string err_msg;
    if (not CompilePatterns(patterns, &compiled_patterns, &err_msg))
        Error("Error while compiling patterns: " + err_msg);

    unsigned total_count(0), kept_count(0), modified_count(0);
    while (MarcUtil::Record record = input_is_xml ? MarcUtil::Record::XmlFactory(input)
                                                  : MarcUtil::Record::BinaryFactory(input))
    {
        record.setRecordWillBeWrittenAsXml(input_is_xml);
        ++total_count;

        const std::vector<DirectoryEntry> &dir_entries(record.getDirEntries());
        const std::vector<std::string> &fields(record.getFields());
        std::vector<size_t> matched_field_indices;
        if (Matched(record, dir_entries, fields, compiled_patterns, &matched_field_indices)) {
            if (operation_type == OperationType::KEEP) {
                xml_writer != nullptr ? record.write(xml_writer) : record.write(output);
                ++kept_count;
            } else if (operation_type == OperationType::REMOVE_FIELDS) {
                std::sort(matched_field_indices.begin(), matched_field_indices.end(), std::greater<size_t>());
                for (const auto field_index : matched_field_indices)
                    record.deleteField(field_index);
                xml_writer != nullptr ? record.write(xml_writer) : record.write(output);
                ++modified_count;
            }
        } else if (operation_type == OperationType::DROP) {
            xml_writer != nullptr ? record.write(xml_writer) : record.write(output);
            ++kept_count;
        }
    }

    if (not err_msg.empty())
        Error(err_msg);

    delete xml_writer;

    if (operation_type == OperationType::REMOVE_FIELDS)
        std::cerr << "Modified " << modified_count << " of " << total_count << " record(s).\n";
    else
        std::cerr << "Kept " << kept_count << " of " << total_count << " record(s).\n";
}

int main(int argc, char **argv) {
    ::progname = argv[0];

    if (argc < 5)
        Usage();

    OperationType operation_type;
    if (std::strcmp(argv[1], "--keep") == 0)
        operation_type = OperationType::KEEP;
    else if (std::strcmp(argv[1], "--drop") == 0)
        operation_type = OperationType::DROP;
    else if (std::strcmp(argv[1], "--remove-fields") == 0)
        operation_type = OperationType::REMOVE_FIELDS;
    else
        Error("expected --keep, --drop or --remove-field as the first argument!");

    OutputFormat output_format(OutputFormat::SAME_AS_INPUT);
    if (StringUtil::StartsWith(argv[2], "--output-format=")) {
        if (std::strcmp(argv[2] + std::strlen("--output-format="), "marc-xml") == 0)
            output_format = OutputFormat::MARC_XML;
        else if (std::strcmp(argv[2] + std::strlen("--output-format="), "marc-21") == 0)
            output_format = OutputFormat::MARC_21;
        else
            Error("unknown output format \"" + std::string(argv[2] + 16)
                  + "\"!  Must be \"marc-xml\" or \"marc-21\".");
        ++argv, --argc;
    }

    const std::string input_filename(argv[2]);
    const std::string media_type(MediaTypeUtil::GetFileMediaType(input_filename));
    if (unlikely(media_type.empty()))
        Error("can't determine media type of \"" + input_filename + "\"!");
    if (media_type != "application/xml" and media_type != "application/marc")
        Error("\"" + input_filename + "\" is neither XML nor MARC-21 data!");
    const bool input_is_xml(media_type == "application/xml");

    std::unique_ptr<File> input(FileUtil::OpenInputFileOrDie(input_filename));
    std::unique_ptr<File> output(FileUtil::OpenOutputFileOrDie(argv[3]));

    std::vector<std::string> patterns;
    for (int arg_no(4); arg_no < argc; ++arg_no)
        patterns.emplace_back(argv[arg_no]);

    try {
        Filter(input_is_xml, output_format, patterns, operation_type, input.get(), output.get());
    } catch (const std::exception &x) {
        Error("caught exception: " + std::string(x.what()));
    }
}
<commit_msg>Fixed a bug where invocations with --remove-fields removed all records that had no matching fields.<commit_after>/** \brief A MARC-21 filter utility that can remove records based on patterns for MARC subfields.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2016 Universitätsbiblothek 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 <memory>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <getopt.h>
#include "DirectoryEntry.h"
#include "FileUtil.h"
#include "Leader.h"
#include "MarcUtil.h"
#include "MarcXmlWriter.h"
#include "MediaTypeUtil.h"
#include "RegexMatcher.h"
#include "StringUtil.h"
#include "Subfields.h"
#include "util.h"

void Usage() {
    std::cerr << "usage: " << progname << " (--drop|--keep|--remove-fields) [--output-format=(marc-xml|marc-21)] marc_input marc_output field_or_subfieldspec1:regex1 "
              << "[field_or_subfieldspec2:regex2 .. field_or_subfieldspecN:regexN]\n"
              << "       where \"field_or_subfieldspec\" must either be a MARC tag or a MARC tag followed by a\n"
              << "       single-character subfield code and \"regex\" is a Perl-compatible regular expression.\n"
              << "       If you don't specify an output format it will be the same as the input format.\n\n";

    std::exit(EXIT_FAILURE);
}

class CompiledPattern {
    std::string tag_;
    char subfield_code_;
    RegexMatcher matcher_;
public:
    static const char NO_SUBFIELD_CODE;
public:
    CompiledPattern(const std::string &tag, const char subfield_code,  const RegexMatcher &matcher)
        : tag_(tag), subfield_code_(subfield_code), matcher_(matcher) {}
    const std::string &getTag() const { return tag_; }
    bool hasSubfieldCode() const { return subfield_code_ != NO_SUBFIELD_CODE; }
    char getSubfieldCode() const { return subfield_code_; }
    bool fieldMatched(const std::string &field_contents) const;
    bool subfieldMatched(const std::string &subfield_contents) const;
};

const char CompiledPattern::NO_SUBFIELD_CODE('\0');

bool CompiledPattern::fieldMatched(const std::string &field_contents) const {
    std::string err_msg;
    const bool retval = matcher_.matched(field_contents, &err_msg);
    if (not retval and not err_msg.empty())
        Error("Unexpected error while trying to match a field in CompiledPattern::fieldMatched(): " + err_msg);

    return retval;
}

bool CompiledPattern::subfieldMatched(const std::string &subfield_contents) const {
    std::string err_msg;
    const bool retval = matcher_.matched(subfield_contents, &err_msg);
    if (not retval and not err_msg.empty())
        Error("Unexpected error while trying to match a subfield in CompiledPattern::subfieldMatched(): " + err_msg);

    return retval;
}

// Expects "patterns" to contain strings that look like TTTS:REGEX where TTT are 3 characters specifying a field,
// S is a subfield code and REGEX is a PCRE-style regex supporting UTF8 that should match subfield contents.
// Alteratively a pattern can look like TTT:REGEX where TTT is a tag and we have no subfield code.
bool CompilePatterns(const std::vector<std::string> &patterns, std::vector<CompiledPattern> * const compiled_patterns,
                     std::string * const err_msg)
{
    compiled_patterns->clear();
    compiled_patterns->reserve(patterns.size());

    for (const auto &pattern : patterns) {
        std::string tag;
        char subfield_code;
        std::string::size_type first_colon_pos = pattern.find(':');
        if (first_colon_pos == std::string::npos) {
            *err_msg = "missing colon!";
            return false;
        } else if (first_colon_pos == DirectoryEntry::TAG_LENGTH) {
            tag = pattern.substr(0, 3);
            subfield_code = CompiledPattern::NO_SUBFIELD_CODE;
        } else if (first_colon_pos == DirectoryEntry::TAG_LENGTH + 1) {
            tag = pattern.substr(0, 3);
            subfield_code = pattern[3];
        } else {
            *err_msg = "colon in wrong position (" + std::to_string(first_colon_pos) + ")! (Tag length must be "
                       + std::to_string(DirectoryEntry::TAG_LENGTH) + ".)";
            return false;
        }

        const std::string regex_string(pattern.substr(first_colon_pos + 1));
        RegexMatcher * const new_matcher(RegexMatcher::RegexMatcherFactory(regex_string, err_msg));
        if (new_matcher == nullptr) {
            *err_msg = "failed to compile regular expression: \"" + regex_string + "\"! (" + *err_msg +")";
            return false;
        }

        compiled_patterns->push_back(CompiledPattern(tag, subfield_code, std::move(*new_matcher)));
        delete new_matcher;
    }

    return true;
}

/** Returns true if we have at least one match. */
bool Matched(const MarcUtil::Record &record, const std::vector<DirectoryEntry> &dir_entries,
             const std::vector<std::string> &fields, const std::vector<CompiledPattern> &compiled_patterns,
             std::vector<size_t> * const matched_field_indices)
{
    matched_field_indices->clear();

    bool matched_at_least_one(false);
    for (const auto &compiled_pattern : compiled_patterns) {
        ssize_t index(record.getFieldIndex(compiled_pattern.getTag()));
        if (index == -1)
            continue;

        for (/* Intentionally empty! */;
             static_cast<size_t>(index) < fields.size() and dir_entries[index].getTag() == compiled_pattern.getTag();
             ++index)
        {
            if (compiled_pattern.hasSubfieldCode()) {
                const Subfields subfields(fields[index]);
                const auto begin_end(subfields.getIterators(compiled_pattern.getSubfieldCode()));
                for (auto subfield_code_and_value(begin_end.first); subfield_code_and_value != begin_end.second;
                     ++subfield_code_and_value)
                {
                    if (compiled_pattern.subfieldMatched(subfield_code_and_value->second)) {
                        matched_field_indices->emplace_back(index);
                        matched_at_least_one = true;
                    }
                }
            } else if (compiled_pattern.fieldMatched(fields[index])) {
                matched_field_indices->emplace_back(index);
                matched_at_least_one = true;
            }
        }
    }

    return matched_at_least_one;
}

namespace {

enum class OutputFormat { MARC_XML, MARC_21, SAME_AS_INPUT };
enum class OperationType { KEEP, DROP, REMOVE_FIELDS };

} // unnamed namespace

void Filter(const bool input_is_xml, const OutputFormat output_format, const std::vector<std::string> &patterns,
            const OperationType operation_type, File * const input, File * const output)
{
    MarcXmlWriter *xml_writer(nullptr);
    if ((output_format == OutputFormat::SAME_AS_INPUT and input_is_xml) or output_format == OutputFormat::MARC_XML)
        xml_writer = new MarcXmlWriter(output);

    std::vector<CompiledPattern> compiled_patterns;
    std::string err_msg;
    if (not CompilePatterns(patterns, &compiled_patterns, &err_msg))
        Error("Error while compiling patterns: " + err_msg);

    unsigned total_count(0), kept_count(0), modified_count(0);
    while (MarcUtil::Record record = input_is_xml ? MarcUtil::Record::XmlFactory(input)
                                                  : MarcUtil::Record::BinaryFactory(input))
    {
        record.setRecordWillBeWrittenAsXml(input_is_xml);
        ++total_count;

        const std::vector<DirectoryEntry> &dir_entries(record.getDirEntries());
        const std::vector<std::string> &fields(record.getFields());
        std::vector<size_t> matched_field_indices;
        if (Matched(record, dir_entries, fields, compiled_patterns, &matched_field_indices)) {
            if (operation_type == OperationType::KEEP) {
                xml_writer != nullptr ? record.write(xml_writer) : record.write(output);
                ++kept_count;
            } else if (operation_type == OperationType::REMOVE_FIELDS) {
                std::sort(matched_field_indices.begin(), matched_field_indices.end(), std::greater<size_t>());
                for (const auto field_index : matched_field_indices)
                    record.deleteField(field_index);
                xml_writer != nullptr ? record.write(xml_writer) : record.write(output);
                ++modified_count;
            }
        } else if (operation_type == OperationType::DROP or operation_type == OperationType::REMOVE_FIELDS) {
            xml_writer != nullptr ? record.write(xml_writer) : record.write(output);
            ++kept_count;
        }
    }

    if (not err_msg.empty())
        Error(err_msg);

    delete xml_writer;

    if (operation_type == OperationType::REMOVE_FIELDS)
        std::cerr << "Modified " << modified_count << " of " << total_count << " record(s).\n";
    else
        std::cerr << "Kept " << kept_count << " of " << total_count << " record(s).\n";
}

int main(int argc, char **argv) {
    ::progname = argv[0];

    if (argc < 5)
        Usage();

    OperationType operation_type;
    if (std::strcmp(argv[1], "--keep") == 0)
        operation_type = OperationType::KEEP;
    else if (std::strcmp(argv[1], "--drop") == 0)
        operation_type = OperationType::DROP;
    else if (std::strcmp(argv[1], "--remove-fields") == 0)
        operation_type = OperationType::REMOVE_FIELDS;
    else
        Error("expected --keep, --drop or --remove-field as the first argument!");

    OutputFormat output_format(OutputFormat::SAME_AS_INPUT);
    if (StringUtil::StartsWith(argv[2], "--output-format=")) {
        if (std::strcmp(argv[2] + std::strlen("--output-format="), "marc-xml") == 0)
            output_format = OutputFormat::MARC_XML;
        else if (std::strcmp(argv[2] + std::strlen("--output-format="), "marc-21") == 0)
            output_format = OutputFormat::MARC_21;
        else
            Error("unknown output format \"" + std::string(argv[2] + 16)
                  + "\"!  Must be \"marc-xml\" or \"marc-21\".");
        ++argv, --argc;
    }

    const std::string input_filename(argv[2]);
    const std::string media_type(MediaTypeUtil::GetFileMediaType(input_filename));
    if (unlikely(media_type.empty()))
        Error("can't determine media type of \"" + input_filename + "\"!");
    if (media_type != "application/xml" and media_type != "application/marc")
        Error("\"" + input_filename + "\" is neither XML nor MARC-21 data!");
    const bool input_is_xml(media_type == "application/xml");

    std::unique_ptr<File> input(FileUtil::OpenInputFileOrDie(input_filename));
    std::unique_ptr<File> output(FileUtil::OpenOutputFileOrDie(argv[3]));

    std::vector<std::string> patterns;
    for (int arg_no(4); arg_no < argc; ++arg_no)
        patterns.emplace_back(argv[arg_no]);

    try {
        Filter(input_is_xml, output_format, patterns, operation_type, input.get(), output.get());
    } catch (const std::exception &x) {
        Error("caught exception: " + std::string(x.what()));
    }
}
<|endoftext|>


<commit_before>//===-- Mips16FrameLowering.cpp - Mips16 Frame Information ----------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the Mips16 implementation of TargetFrameLowering class.
//
//===----------------------------------------------------------------------===//

#include "Mips16FrameLowering.h"
#include "MipsInstrInfo.h"
#include "MCTargetDesc/MipsBaseInfo.h"
#include "llvm/Function.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Support/CommandLine.h"

using namespace llvm;

void Mips16FrameLowering::emitPrologue(MachineFunction &MF) const {
  MachineBasicBlock &MBB = MF.front();
  MachineFrameInfo *MFI = MF.getFrameInfo();
  const MipsInstrInfo &TII =
    *static_cast<const MipsInstrInfo*>(MF.getTarget().getInstrInfo());
  MachineBasicBlock::iterator MBBI = MBB.begin();
  DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
  uint64_t StackSize = MFI->getStackSize();

  // No need to allocate space on the stack.
  if (StackSize == 0 && !MFI->adjustsStack()) return;

  // Adjust stack.
  if (isInt<16>(-StackSize))
    BuildMI(MBB, MBBI, dl, TII.get(Mips::SaveRaF16)).addImm(StackSize);
}

void Mips16FrameLowering::emitEpilogue(MachineFunction &MF,
                                 MachineBasicBlock &MBB) const {
  MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
  MachineFrameInfo *MFI = MF.getFrameInfo();
  const MipsInstrInfo &TII =
    *static_cast<const MipsInstrInfo*>(MF.getTarget().getInstrInfo());
  DebugLoc dl = MBBI->getDebugLoc();
  uint64_t StackSize = MFI->getStackSize();

  if (!StackSize)
    return;

  // Adjust stack.
  if (isInt<16>(StackSize))
    // assumes stacksize multiple of 8
    BuildMI(MBB, MBBI, dl, TII.get(Mips::RestoreRaF16)).addImm(StackSize);
}

bool Mips16FrameLowering::
spillCalleeSavedRegisters(MachineBasicBlock &MBB,
                          MachineBasicBlock::iterator MI,
                          const std::vector<CalleeSavedInfo> &CSI,
                          const TargetRegisterInfo *TRI) const {
  MachineFunction *MF = MBB.getParent();
  MachineBasicBlock *EntryBlock = MF->begin();
  const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();

  //
  // Registers RA, S0,S1 are the callee saved registers and they
  // will be saved with the "save" instruction
  // during emitPrologue
  //
  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
    // Add the callee-saved register as live-in. Do not add if the register is
    // RA and return address is taken, because it has already been added in
    // method MipsTargetLowering::LowerRETURNADDR.
    // It's killed at the spill, unless the register is RA and return address
    // is taken.
    unsigned Reg = CSI[i].getReg();
    bool IsRAAndRetAddrIsTaken = (Reg == Mips::RA)
      && MF->getFrameInfo()->isReturnAddressTaken();
    if (!IsRAAndRetAddrIsTaken)
      EntryBlock->addLiveIn(Reg);
  }

  return true;
}

bool Mips16FrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
                                          MachineBasicBlock::iterator MI,
                                       const std::vector<CalleeSavedInfo> &CSI,
                                       const TargetRegisterInfo *TRI) const {
  //
  // Registers RA,S0,S1 are the callee saved registers and they will be restored
  // with the restore instruction during emitEpilogue.
  // We need to override this virtual function, otherwise llvm will try and
  // restore the registers on it's on from the stack.
  //

  return true;
}

bool
Mips16FrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
  // FIXME: implement.
  return true;
}

void Mips16FrameLowering::
processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
                                     RegScavenger *RS) const {
  MF.getRegInfo().setPhysRegUsed(Mips::RA);
  MF.getRegInfo().setPhysRegUsed(Mips::S0);
  MF.getRegInfo().setPhysRegUsed(Mips::S1);
}

const MipsFrameLowering *
llvm::createMips16FrameLowering(const MipsSubtarget &ST) {
  return new Mips16FrameLowering(ST);
}
<commit_msg>Mips16FrameLowering.cpp: Remove unused TII introduced in r164349. [-Wunused-variable]<commit_after>//===-- Mips16FrameLowering.cpp - Mips16 Frame Information ----------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the Mips16 implementation of TargetFrameLowering class.
//
//===----------------------------------------------------------------------===//

#include "Mips16FrameLowering.h"
#include "MipsInstrInfo.h"
#include "MCTargetDesc/MipsBaseInfo.h"
#include "llvm/Function.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Support/CommandLine.h"

using namespace llvm;

void Mips16FrameLowering::emitPrologue(MachineFunction &MF) const {
  MachineBasicBlock &MBB = MF.front();
  MachineFrameInfo *MFI = MF.getFrameInfo();
  const MipsInstrInfo &TII =
    *static_cast<const MipsInstrInfo*>(MF.getTarget().getInstrInfo());
  MachineBasicBlock::iterator MBBI = MBB.begin();
  DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
  uint64_t StackSize = MFI->getStackSize();

  // No need to allocate space on the stack.
  if (StackSize == 0 && !MFI->adjustsStack()) return;

  // Adjust stack.
  if (isInt<16>(-StackSize))
    BuildMI(MBB, MBBI, dl, TII.get(Mips::SaveRaF16)).addImm(StackSize);
}

void Mips16FrameLowering::emitEpilogue(MachineFunction &MF,
                                 MachineBasicBlock &MBB) const {
  MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
  MachineFrameInfo *MFI = MF.getFrameInfo();
  const MipsInstrInfo &TII =
    *static_cast<const MipsInstrInfo*>(MF.getTarget().getInstrInfo());
  DebugLoc dl = MBBI->getDebugLoc();
  uint64_t StackSize = MFI->getStackSize();

  if (!StackSize)
    return;

  // Adjust stack.
  if (isInt<16>(StackSize))
    // assumes stacksize multiple of 8
    BuildMI(MBB, MBBI, dl, TII.get(Mips::RestoreRaF16)).addImm(StackSize);
}

bool Mips16FrameLowering::
spillCalleeSavedRegisters(MachineBasicBlock &MBB,
                          MachineBasicBlock::iterator MI,
                          const std::vector<CalleeSavedInfo> &CSI,
                          const TargetRegisterInfo *TRI) const {
  MachineFunction *MF = MBB.getParent();
  MachineBasicBlock *EntryBlock = MF->begin();

  //
  // Registers RA, S0,S1 are the callee saved registers and they
  // will be saved with the "save" instruction
  // during emitPrologue
  //
  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
    // Add the callee-saved register as live-in. Do not add if the register is
    // RA and return address is taken, because it has already been added in
    // method MipsTargetLowering::LowerRETURNADDR.
    // It's killed at the spill, unless the register is RA and return address
    // is taken.
    unsigned Reg = CSI[i].getReg();
    bool IsRAAndRetAddrIsTaken = (Reg == Mips::RA)
      && MF->getFrameInfo()->isReturnAddressTaken();
    if (!IsRAAndRetAddrIsTaken)
      EntryBlock->addLiveIn(Reg);
  }

  return true;
}

bool Mips16FrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
                                          MachineBasicBlock::iterator MI,
                                       const std::vector<CalleeSavedInfo> &CSI,
                                       const TargetRegisterInfo *TRI) const {
  //
  // Registers RA,S0,S1 are the callee saved registers and they will be restored
  // with the restore instruction during emitEpilogue.
  // We need to override this virtual function, otherwise llvm will try and
  // restore the registers on it's on from the stack.
  //

  return true;
}

bool
Mips16FrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
  // FIXME: implement.
  return true;
}

void Mips16FrameLowering::
processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
                                     RegScavenger *RS) const {
  MF.getRegInfo().setPhysRegUsed(Mips::RA);
  MF.getRegInfo().setPhysRegUsed(Mips::S0);
  MF.getRegInfo().setPhysRegUsed(Mips::S1);
}

const MipsFrameLowering *
llvm::createMips16FrameLowering(const MipsSubtarget &ST) {
  return new Mips16FrameLowering(ST);
}
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * @file text-label-example.cpp
 * @brief Basic usage of TextLabel control
 */

// EXTERNAL INCLUDES
#include <dali-toolkit/dali-toolkit.h>
#include <dali/public-api/text-abstraction/text-abstraction.h>

// INTERNAL INCLUDES
#include "center-layout.h"
#include "shared/multi-language-strings.h"

using namespace Dali;
using namespace Dali::Toolkit;
using namespace MultiLanguageStrings;

namespace
{
  const unsigned int KEY_ZERO = 10;
  const unsigned int KEY_ONE = 11;
  const unsigned int KEY_M = 58;
  const unsigned int KEY_L = 46;
}

/**
 * @brief The main class of the demo.
 */
class TextLabelExample : public ConnectionTracker
{
public:

  TextLabelExample( Application& application )
  : mApplication( application ),
    mLanguageId( 0u )
  {
    // Connect to the Application's Init signal
    mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
  }

  ~TextLabelExample()
  {
    // Nothing to do here.
  }

  /**
   * One-time setup in response to Application InitSignal.
   */
  void Create( Application& application )
  {
    Stage stage = Stage::GetCurrent();

    stage.SetBackgroundColor( Color::BLUE );
    stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
    Vector2 stageSize = stage.GetSize();

    CenterLayout centerLayout = CenterLayout::New();
    centerLayout.SetParentOrigin( ParentOrigin::CENTER );
    centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f );
    stage.Add( centerLayout );

    mLabel = TextLabel::New();
    mLabel.SetBackgroundColor( Color::BLACK );
    centerLayout.Add( mLabel );

    mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
    mLabel.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );

    Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
    std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
  }

  /**
   * Main key event handler
   */
  void OnKeyEvent(const KeyEvent& event)
  {
    if(event.state == KeyEvent::Down)
    {
      if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
      {
        mApplication.Quit();
      }
      else if( event.IsCtrlModifier() )
      {
        switch( event.keyCode )
        {
          case KEY_ZERO: // fall through
          case KEY_ONE:
          {
            mLabel.SetProperty( TextLabel::Property::RENDERING_BACKEND, event.keyCode - 10 );
            break;
          }
          case KEY_M:
          {
            bool multiLine = mLabel.GetProperty<bool>( TextLabel::Property::MULTI_LINE );
            mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine );
            break;
          }
          case KEY_L:
          {
            const Language& language = LANGUAGES[ mLanguageId ];

            mLabel.SetProperty( TextLabel::Property::TEXT, language.text );

            if( ++mLanguageId >= NUMBER_OF_LANGUAGES )
            {
              mLanguageId = 0u;
            }
          }
        }
      }
    }
  }

private:

  Application& mApplication;

  TextLabel mLabel;

  unsigned int mLanguageId;
};

void RunTest( Application& application )
{
  TextLabelExample test( application );

  application.MainLoop();
}

/** Entry point for Linux & Tizen applications */
int main( int argc, char **argv )
{
  Application application = Application::New( &argc, &argv );

  RunTest( application );

  return 0;
}
<commit_msg>Alignment option added.<commit_after>/*
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * @file text-label-example.cpp
 * @brief Basic usage of TextLabel control
 */

// EXTERNAL INCLUDES
#include <dali-toolkit/dali-toolkit.h>
#include <dali/public-api/text-abstraction/text-abstraction.h>

// INTERNAL INCLUDES
#include "center-layout.h"
#include "shared/multi-language-strings.h"

using namespace Dali;
using namespace Dali::Toolkit;
using namespace MultiLanguageStrings;

namespace
{
  const unsigned int KEY_ZERO = 10;
  const unsigned int KEY_ONE = 11;
  const unsigned int KEY_A = 38;
  const unsigned int KEY_M = 58;
  const unsigned int KEY_L = 46;

  const char* ALIGNMENT_STRING_TABLE[] =
  {
    "BEGIN",
    "CENTER",
    "END"
  };

  const unsigned int ALIGNMENT_STRING_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0u] );
}

/**
 * @brief The main class of the demo.
 */
class TextLabelExample : public ConnectionTracker
{
public:

  TextLabelExample( Application& application )
  : mApplication( application ),
    mLanguageId( 0u ),
    mAlignment( 0u )
  {
    // Connect to the Application's Init signal
    mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
  }

  ~TextLabelExample()
  {
    // Nothing to do here.
  }

  /**
   * One-time setup in response to Application InitSignal.
   */
  void Create( Application& application )
  {
    Stage stage = Stage::GetCurrent();

    stage.SetBackgroundColor( Color::BLUE );
    stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
    Vector2 stageSize = stage.GetSize();

    CenterLayout centerLayout = CenterLayout::New();
    centerLayout.SetParentOrigin( ParentOrigin::CENTER );
    centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f );
    stage.Add( centerLayout );

    mLabel = TextLabel::New();
    mLabel.SetBackgroundColor( Color::BLACK );
    centerLayout.Add( mLabel );

    mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
    mLabel.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );

    Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
    std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
  }

  /**
   * Main key event handler
   */
  void OnKeyEvent(const KeyEvent& event)
  {
    if(event.state == KeyEvent::Down)
    {
      if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
      {
        mApplication.Quit();
      }
      else if( event.IsCtrlModifier() )
      {
        switch( event.keyCode )
        {
          case KEY_ZERO: // fall through
          case KEY_ONE:
          {
            mLabel.SetProperty( TextLabel::Property::RENDERING_BACKEND, event.keyCode - 10 );
            break;
          }
          case KEY_A:
          {
            if( ++mAlignment >= ALIGNMENT_STRING_COUNT )
            {
              mAlignment = 0u;
            }

            mLabel.SetProperty( TextLabel::Property::ALIGNMENT, ALIGNMENT_STRING_TABLE[ mAlignment ] );
            break;
          }
          case KEY_M:
          {
            bool multiLine = mLabel.GetProperty<bool>( TextLabel::Property::MULTI_LINE );
            mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine );
            break;
          }
          case KEY_L:
          {
            const Language& language = LANGUAGES[ mLanguageId ];

            mLabel.SetProperty( TextLabel::Property::TEXT, language.text );

            if( ++mLanguageId >= NUMBER_OF_LANGUAGES )
            {
              mLanguageId = 0u;
            }
            break;
          }
        }
      }
    }
  }

private:

  Application& mApplication;

  TextLabel mLabel;

  unsigned int mLanguageId;
  unsigned int mAlignment;
};

void RunTest( Application& application )
{
  TextLabelExample test( application );

  application.MainLoop();
}

/** Entry point for Linux & Tizen applications */
int main( int argc, char **argv )
{
  Application application = Application::New( &argc, &argv );

  RunTest( application );

  return 0;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: SalGtkFilePicker.hxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: kz $ $Date: 2008-04-03 16:45:41 $
 *
 *  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 _SALGTKFILEPICKER_HXX_
#define _SALGTKFILEPICKER_HXX_

//_______________________________________________________________________________________________________________________
//  includes of other projects
//_______________________________________________________________________________________________________________________

#ifndef _CPPUHELPER_COMPBASE10_HXX_
#include <cppuhelper/compbase10.hxx>
#endif

#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
#include <com/sun/star/lang/XInitialization.hpp>
#endif

#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERNOTIFIER_HPP_
#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
#endif

#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILTERMANAGER_HPP_
#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
#endif

#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILTERGROUPMANAGER_HPP_
#include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
#endif

#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERCONTROLACCESS_HPP_
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#endif

#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPREVIEW_HPP_
#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
#endif

#ifndef _COM_SUN_STAR_BEANS_STRINGPAIR_HPP_
#include <com/sun/star/beans/StringPair.hpp>
#endif

#ifndef _SALGTKPICKER_HXX_
#include "SalGtkPicker.hxx"
#endif

#include <memory>

#ifndef _RTL_USTRING_H_
#include <rtl/ustring.hxx>
#endif

#include <list>

//----------------------------------------------------------
// Implementation class for the XFilePicker Interface
//----------------------------------------------------------

//----------------------------------------------------------
// forward declarations
//----------------------------------------------------------

using namespace rtl;

struct FilterEntry;
struct ElementEntry_Impl;

typedef ::std::list < FilterEntry >     FilterList;
typedef ::std::list < ElementEntry_Impl >   ElementList;
typedef ::com::sun::star::beans::StringPair UnoFilterEntry;
typedef ::com::sun::star::uno::Sequence< UnoFilterEntry >   UnoFilterList;  // can be transported more effectively

//----------------------------------------------------------
// class declaration
//----------------------------------------------------------

class SalGtkFilePicker :
        public SalGtkPicker,
    public cppu::WeakComponentImplHelper10<
        ::com::sun::star::ui::dialogs::XFilterManager,
        ::com::sun::star::ui::dialogs::XFilterGroupManager,
        ::com::sun::star::ui::dialogs::XFilePickerControlAccess,
        ::com::sun::star::ui::dialogs::XFilePickerNotifier,
        ::com::sun::star::ui::dialogs::XFilePreview,
        ::com::sun::star::ui::dialogs::XFilePicker2,
    ::com::sun::star::lang::XInitialization,
        ::com::sun::star::util::XCancellable,
    ::com::sun::star::lang::XEventListener,
    ::com::sun::star::lang::XServiceInfo >
{
    public:

        // constructor
        SalGtkFilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceMgr );

        //------------------------------------------------------------------------------------
        // XFilePickerNotifier
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL addFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
            throw( ::com::sun::star::uno::RuntimeException );
        virtual void SAL_CALL removeFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
            throw( ::com::sun::star::uno::RuntimeException );

        //------------------------------------------------------------------------------------
        // XExecutableDialog functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
            throw( ::com::sun::star::uno::RuntimeException );

        virtual sal_Int16 SAL_CALL execute(  )
            throw( ::com::sun::star::uno::RuntimeException );

        //------------------------------------------------------------------------------------
        // XFilePicker functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode )
            throw( ::com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL setDefaultName( const ::rtl::OUString& aName )
            throw( ::com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL setDisplayDirectory( const ::rtl::OUString& aDirectory )
            throw( com::sun::star::lang::IllegalArgumentException,
                ::com::sun::star::uno::RuntimeException );

        virtual ::rtl::OUString SAL_CALL getDisplayDirectory(  )
            throw( ::com::sun::star::uno::RuntimeException );

        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles(  )
            throw( ::com::sun::star::uno::RuntimeException );

         //------------------------------------------------------------------------------------
        // XFilePicker2 functions
        //------------------------------------------------------------------------------------

        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedFiles()
                throw (::com::sun::star::uno::RuntimeException);

        //------------------------------------------------------------------------------------
        // XFilterManager functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL appendFilter( const ::rtl::OUString& aTitle, const ::rtl::OUString& aFilter )
            throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL setCurrentFilter( const ::rtl::OUString& aTitle )
            throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );

        virtual ::rtl::OUString SAL_CALL getCurrentFilter(  )
            throw( ::com::sun::star::uno::RuntimeException );

        //------------------------------------------------------------------------------------
        // XFilterGroupManager functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL appendFilterGroup( const ::rtl::OUString& sGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aFilters )
                throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);

        //------------------------------------------------------------------------------------
        // XFilePickerControlAccess functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any& aValue )
                throw (::com::sun::star::uno::RuntimeException);

        virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction )
                throw (::com::sun::star::uno::RuntimeException);

        virtual void SAL_CALL enableControl( sal_Int16 nControlId, sal_Bool bEnable )
            throw(::com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL setLabel( sal_Int16 nControlId, const ::rtl::OUString& aLabel )
            throw (::com::sun::star::uno::RuntimeException);

        virtual ::rtl::OUString SAL_CALL getLabel( sal_Int16 nControlId )
            throw (::com::sun::star::uno::RuntimeException);

        //------------------------------------------------
        // XFilePreview
        //------------------------------------------------

        virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats(  )
            throw (::com::sun::star::uno::RuntimeException);

        virtual sal_Int32 SAL_CALL getTargetColorDepth(  )
            throw (::com::sun::star::uno::RuntimeException);

        virtual sal_Int32 SAL_CALL getAvailableWidth(  )
            throw (::com::sun::star::uno::RuntimeException);

        virtual sal_Int32 SAL_CALL getAvailableHeight(  )
            throw (::com::sun::star::uno::RuntimeException);

        virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage )
            throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState )
            throw (::com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL getShowState(  )
            throw (::com::sun::star::uno::RuntimeException);

        //------------------------------------------------
        // XInitialization
        //------------------------------------------------

        virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
            throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

        //------------------------------------------------
        // XCancellable
        //------------------------------------------------

        virtual void SAL_CALL cancel( )
            throw( ::com::sun::star::uno::RuntimeException );

        //------------------------------------------------
        // XEventListener
        //------------------------------------------------

        using cppu::WeakComponentImplHelperBase::disposing;
        virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent )
            throw(::com::sun::star::uno::RuntimeException);

        //------------------------------------------------
        // XServiceInfo
        //------------------------------------------------

        virtual ::rtl::OUString SAL_CALL getImplementationName(  )
            throw(::com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
            throw(::com::sun::star::uno::RuntimeException);

        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
            throw(::com::sun::star::uno::RuntimeException);

        //------------------------------------------------------------------------------------
        // FilePicker Event functions
        //------------------------------------------------------------------------------------

        void SAL_CALL fileSelectionChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
        void SAL_CALL directoryChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
        rtl::OUString SAL_CALL helpRequested( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ) const;
        void SAL_CALL controlStateChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );

    private:
        // prevent copy and assignment
        SalGtkFilePicker( const SalGtkFilePicker& );
        SalGtkFilePicker& operator=( const SalGtkFilePicker& );

        sal_Bool FilterNameExists( const ::rtl::OUString& rTitle );
        sal_Bool FilterNameExists( const UnoFilterList& _rGroupedFilters );

        void ensureFilterList( const ::rtl::OUString& _rInitialCurrentFilter );

        // to instanciate own services
        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceMgr;

    private:
        ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >
            m_xListener;
        ::rtl::OUString msPlayLabel;
        FilterList *m_pFilterList;
        GtkWidget  *m_pVBox;

        GtkWidget  *m_pFilterExpander;
        GtkWidget  *m_pFilterView;
        GtkListStore *m_pFilterStore;

        enum {
            AUTOEXTENSION,
            PASSWORD,
            FILTEROPTIONS,
            READONLY,
            LINK,
            PREVIEW,
            SELECTION,
            TOGGLE_LAST
              };

        GtkWidget  *m_pToggles[ TOGGLE_LAST ];

        bool mbToggleVisibility[TOGGLE_LAST];
        bool mbToggleChecked[TOGGLE_LAST];

        static const rtl::OString m_ToggleLabels[TOGGLE_LAST];

        enum {
            PLAY,
            BUTTON_LAST };

        GtkWidget  *m_pButtons[ BUTTON_LAST ];

        enum {
            VERSION,
            TEMPLATE,
            IMAGE_TEMPLATE,
            LIST_LAST
              };

        GtkWidget *m_pHBoxs[ LIST_LAST ];
        GtkWidget *m_pAligns[ LIST_LAST ];
        GtkWidget *m_pLists[ LIST_LAST ];
        GtkWidget *m_pListLabels[ LIST_LAST ];
        bool mbListVisibility[ LIST_LAST ];
        bool mbButtonVisibility[ BUTTON_LAST ];
        gulong mnHID_FolderChange;
        gulong mnHID_SelectionChange;

        ::rtl::OUString m_aCurrentFilter;

        bool bVersionWidthUnset;
        sal_Bool mbPreviewState;
        gulong mHID_Preview;
        GtkWidget* m_pPreview;
        sal_Int32 m_PreviewImageWidth;
        sal_Int32 m_PreviewImageHeight;

        GtkWidget  *getWidget( sal_Int16 nControlId, GType *pType = NULL);

        void SetCurFilter( const OUString& rFilter );
        void SetFilters();
        void UpdateFilterfromUI();

        void implChangeType( GtkTreeSelection *selection );
        int implAddFilter( const OUString& rFilter, const OUString& rType);
        int implAddFilterGroup( const OUString& rFilter,
                     const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair>& _rFilters );
        void updateCurrentFilterFromName(const gchar* filtername);
        void unselect_type();
        void InitialMapping();

        void HandleSetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction,
            const ::com::sun::star::uno::Any& rValue);
        ::com::sun::star::uno::Any HandleGetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction) const;

        static void expander_changed_cb( GtkExpander *expander, SalGtkFilePicker *pobjFP );
        static void preview_toggled_cb (GtkObject *cb, SalGtkFilePicker *pobjFP);
        static void filter_changed_cb (GtkFileChooser *file_chooser, GParamSpec *pspec, SalGtkFilePicker *pobjFP);
        static void type_changed_cb( GtkTreeSelection *selection, SalGtkFilePicker *pobjFP );
        static void folder_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
        static void selection_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
        static void update_preview_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
        static void dialog_mapped_cb(GtkWidget *widget, SalGtkFilePicker *pobjFP);
    public:
         virtual ~SalGtkFilePicker();

};
/* vi:set tabstop=4 shiftwidth=4 expandtab: */
#endif // _SALGTKFILEPICKER_HXX_
<commit_msg>INTEGRATION: CWS changefileheader (1.12.10); FILE MERGED 2008/04/01 15:17:02 thb 1.12.10.3: #i85898# Stripping all external header guards 2008/04/01 12:30:50 thb 1.12.10.2: #i85898# Stripping all external header guards 2008/03/31 13:13:16 rt 1.12.10.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: SalGtkFilePicker.hxx,v $
 * $Revision: 1.14 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SALGTKFILEPICKER_HXX_
#define _SALGTKFILEPICKER_HXX_

//_______________________________________________________________________________________________________________________
//  includes of other projects
//_______________________________________________________________________________________________________________________

#include <cppuhelper/compbase10.hxx>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
#include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
#include <com/sun/star/beans/StringPair.hpp>

#ifndef _SALGTKPICKER_HXX_
#include "SalGtkPicker.hxx"
#endif

#include <memory>

#ifndef _RTL_USTRING_H_
#include <rtl/ustring.hxx>
#endif

#include <list>

//----------------------------------------------------------
// Implementation class for the XFilePicker Interface
//----------------------------------------------------------

//----------------------------------------------------------
// forward declarations
//----------------------------------------------------------

using namespace rtl;

struct FilterEntry;
struct ElementEntry_Impl;

typedef ::std::list < FilterEntry >     FilterList;
typedef ::std::list < ElementEntry_Impl >   ElementList;
typedef ::com::sun::star::beans::StringPair UnoFilterEntry;
typedef ::com::sun::star::uno::Sequence< UnoFilterEntry >   UnoFilterList;  // can be transported more effectively

//----------------------------------------------------------
// class declaration
//----------------------------------------------------------

class SalGtkFilePicker :
        public SalGtkPicker,
    public cppu::WeakComponentImplHelper10<
        ::com::sun::star::ui::dialogs::XFilterManager,
        ::com::sun::star::ui::dialogs::XFilterGroupManager,
        ::com::sun::star::ui::dialogs::XFilePickerControlAccess,
        ::com::sun::star::ui::dialogs::XFilePickerNotifier,
        ::com::sun::star::ui::dialogs::XFilePreview,
        ::com::sun::star::ui::dialogs::XFilePicker2,
    ::com::sun::star::lang::XInitialization,
        ::com::sun::star::util::XCancellable,
    ::com::sun::star::lang::XEventListener,
    ::com::sun::star::lang::XServiceInfo >
{
    public:

        // constructor
        SalGtkFilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceMgr );

        //------------------------------------------------------------------------------------
        // XFilePickerNotifier
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL addFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
            throw( ::com::sun::star::uno::RuntimeException );
        virtual void SAL_CALL removeFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener )
            throw( ::com::sun::star::uno::RuntimeException );

        //------------------------------------------------------------------------------------
        // XExecutableDialog functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
            throw( ::com::sun::star::uno::RuntimeException );

        virtual sal_Int16 SAL_CALL execute(  )
            throw( ::com::sun::star::uno::RuntimeException );

        //------------------------------------------------------------------------------------
        // XFilePicker functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode )
            throw( ::com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL setDefaultName( const ::rtl::OUString& aName )
            throw( ::com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL setDisplayDirectory( const ::rtl::OUString& aDirectory )
            throw( com::sun::star::lang::IllegalArgumentException,
                ::com::sun::star::uno::RuntimeException );

        virtual ::rtl::OUString SAL_CALL getDisplayDirectory(  )
            throw( ::com::sun::star::uno::RuntimeException );

        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles(  )
            throw( ::com::sun::star::uno::RuntimeException );

         //------------------------------------------------------------------------------------
        // XFilePicker2 functions
        //------------------------------------------------------------------------------------

        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedFiles()
                throw (::com::sun::star::uno::RuntimeException);

        //------------------------------------------------------------------------------------
        // XFilterManager functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL appendFilter( const ::rtl::OUString& aTitle, const ::rtl::OUString& aFilter )
            throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL setCurrentFilter( const ::rtl::OUString& aTitle )
            throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );

        virtual ::rtl::OUString SAL_CALL getCurrentFilter(  )
            throw( ::com::sun::star::uno::RuntimeException );

        //------------------------------------------------------------------------------------
        // XFilterGroupManager functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL appendFilterGroup( const ::rtl::OUString& sGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aFilters )
                throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);

        //------------------------------------------------------------------------------------
        // XFilePickerControlAccess functions
        //------------------------------------------------------------------------------------

        virtual void SAL_CALL setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any& aValue )
                throw (::com::sun::star::uno::RuntimeException);

        virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction )
                throw (::com::sun::star::uno::RuntimeException);

        virtual void SAL_CALL enableControl( sal_Int16 nControlId, sal_Bool bEnable )
            throw(::com::sun::star::uno::RuntimeException );

        virtual void SAL_CALL setLabel( sal_Int16 nControlId, const ::rtl::OUString& aLabel )
            throw (::com::sun::star::uno::RuntimeException);

        virtual ::rtl::OUString SAL_CALL getLabel( sal_Int16 nControlId )
            throw (::com::sun::star::uno::RuntimeException);

        //------------------------------------------------
        // XFilePreview
        //------------------------------------------------

        virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats(  )
            throw (::com::sun::star::uno::RuntimeException);

        virtual sal_Int32 SAL_CALL getTargetColorDepth(  )
            throw (::com::sun::star::uno::RuntimeException);

        virtual sal_Int32 SAL_CALL getAvailableWidth(  )
            throw (::com::sun::star::uno::RuntimeException);

        virtual sal_Int32 SAL_CALL getAvailableHeight(  )
            throw (::com::sun::star::uno::RuntimeException);

        virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage )
            throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState )
            throw (::com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL getShowState(  )
            throw (::com::sun::star::uno::RuntimeException);

        //------------------------------------------------
        // XInitialization
        //------------------------------------------------

        virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
            throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

        //------------------------------------------------
        // XCancellable
        //------------------------------------------------

        virtual void SAL_CALL cancel( )
            throw( ::com::sun::star::uno::RuntimeException );

        //------------------------------------------------
        // XEventListener
        //------------------------------------------------

        using cppu::WeakComponentImplHelperBase::disposing;
        virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent )
            throw(::com::sun::star::uno::RuntimeException);

        //------------------------------------------------
        // XServiceInfo
        //------------------------------------------------

        virtual ::rtl::OUString SAL_CALL getImplementationName(  )
            throw(::com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
            throw(::com::sun::star::uno::RuntimeException);

        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
            throw(::com::sun::star::uno::RuntimeException);

        //------------------------------------------------------------------------------------
        // FilePicker Event functions
        //------------------------------------------------------------------------------------

        void SAL_CALL fileSelectionChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
        void SAL_CALL directoryChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );
        rtl::OUString SAL_CALL helpRequested( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ) const;
        void SAL_CALL controlStateChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent );

    private:
        // prevent copy and assignment
        SalGtkFilePicker( const SalGtkFilePicker& );
        SalGtkFilePicker& operator=( const SalGtkFilePicker& );

        sal_Bool FilterNameExists( const ::rtl::OUString& rTitle );
        sal_Bool FilterNameExists( const UnoFilterList& _rGroupedFilters );

        void ensureFilterList( const ::rtl::OUString& _rInitialCurrentFilter );

        // to instanciate own services
        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceMgr;

    private:
        ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >
            m_xListener;
        ::rtl::OUString msPlayLabel;
        FilterList *m_pFilterList;
        GtkWidget  *m_pVBox;

        GtkWidget  *m_pFilterExpander;
        GtkWidget  *m_pFilterView;
        GtkListStore *m_pFilterStore;

        enum {
            AUTOEXTENSION,
            PASSWORD,
            FILTEROPTIONS,
            READONLY,
            LINK,
            PREVIEW,
            SELECTION,
            TOGGLE_LAST
              };

        GtkWidget  *m_pToggles[ TOGGLE_LAST ];

        bool mbToggleVisibility[TOGGLE_LAST];
        bool mbToggleChecked[TOGGLE_LAST];

        static const rtl::OString m_ToggleLabels[TOGGLE_LAST];

        enum {
            PLAY,
            BUTTON_LAST };

        GtkWidget  *m_pButtons[ BUTTON_LAST ];

        enum {
            VERSION,
            TEMPLATE,
            IMAGE_TEMPLATE,
            LIST_LAST
              };

        GtkWidget *m_pHBoxs[ LIST_LAST ];
        GtkWidget *m_pAligns[ LIST_LAST ];
        GtkWidget *m_pLists[ LIST_LAST ];
        GtkWidget *m_pListLabels[ LIST_LAST ];
        bool mbListVisibility[ LIST_LAST ];
        bool mbButtonVisibility[ BUTTON_LAST ];
        gulong mnHID_FolderChange;
        gulong mnHID_SelectionChange;

        ::rtl::OUString m_aCurrentFilter;

        bool bVersionWidthUnset;
        sal_Bool mbPreviewState;
        gulong mHID_Preview;
        GtkWidget* m_pPreview;
        sal_Int32 m_PreviewImageWidth;
        sal_Int32 m_PreviewImageHeight;

        GtkWidget  *getWidget( sal_Int16 nControlId, GType *pType = NULL);

        void SetCurFilter( const OUString& rFilter );
        void SetFilters();
        void UpdateFilterfromUI();

        void implChangeType( GtkTreeSelection *selection );
        int implAddFilter( const OUString& rFilter, const OUString& rType);
        int implAddFilterGroup( const OUString& rFilter,
                     const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair>& _rFilters );
        void updateCurrentFilterFromName(const gchar* filtername);
        void unselect_type();
        void InitialMapping();

        void HandleSetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction,
            const ::com::sun::star::uno::Any& rValue);
        ::com::sun::star::uno::Any HandleGetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction) const;

        static void expander_changed_cb( GtkExpander *expander, SalGtkFilePicker *pobjFP );
        static void preview_toggled_cb (GtkObject *cb, SalGtkFilePicker *pobjFP);
        static void filter_changed_cb (GtkFileChooser *file_chooser, GParamSpec *pspec, SalGtkFilePicker *pobjFP);
        static void type_changed_cb( GtkTreeSelection *selection, SalGtkFilePicker *pobjFP );
        static void folder_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
        static void selection_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
        static void update_preview_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP);
        static void dialog_mapped_cb(GtkWidget *widget, SalGtkFilePicker *pobjFP);
    public:
         virtual ~SalGtkFilePicker();

};
/* vi:set tabstop=4 shiftwidth=4 expandtab: */
#endif // _SALGTKFILEPICKER_HXX_
<|endoftext|>


<commit_before><commit_msg>error -> warning<commit_after><|endoftext|>


<commit_before><commit_msg>TerarkCompositeIndexIterator: Add missing init<commit_after><|endoftext|>


<commit_before>/*
Implementation of a logic to iterated over k dimensional array.
*/

#include <iostream>

using namespace std;

void iterate(int d, int n, int size[], int res[]){
    //check exit condition
    if(d >= n){
        // Print out the result array
        for(int i = 0;i<n;++i){
            cout << res[i] << " ";
        }
        cout << endl;
    }else{
        //iterate over all values in the dimension d
        for(int i = 0; i < size[d]; ++i){
            res[d] = i;
            //recursively call the next dimension
            iterate(d+1,n,size,res);
        }
    }
}

int main(){
    int size[] = {2,4,2,3};
    int size_of_arr = 4;
    int res[size_of_arr];
    iterate(0,size_of_arr,size,res);
}
<commit_msg>Fixed a typo in comments in iterateKdim.cpp<commit_after>/*
Implementation of a logic to iterate over k dimensional array.
*/

#include <iostream>

using namespace std;

void iterate(int d, int n, int size[], int res[]){
    //check exit condition
    if(d >= n){
        // Print out the result array
        for(int i = 0;i<n;++i){
            cout << res[i] << " ";
        }
        cout << endl;
    }else{
        //iterate over all values in the dimension d
        for(int i = 0; i < size[d]; ++i){
            res[d] = i;
            //recursively call the next dimension
            iterate(d+1,n,size,res);
        }
    }
}

int main(){
    int size[] = {2,4,2,3};
    int size_of_arr = 4;
    int res[size_of_arr];
    iterate(0,size_of_arr,size,res);
}
<|endoftext|>


<commit_before>#include "opengl_helpers.h"
#include <SDL.h>
#include <sstream>
#include <iostream>

const char* SYNTAX =  "#ifndef GL_ES\n"
                      "#define lowp\n"
                      "#define mediump\n"
                      "#define highp\n"
                      "#endif\n"
                      "#define number float\n"
                      "#define Image sampler2D\n"
                      "#define extern uniform\n"
                      "#define Texel texture2D\n";
                      // "#pragma optionNV(strict on)\n";

const char* VERTEX_HEADER = "#define VERTEX\n"
                            "#define LOVE_PRECISE_GAMMA\n"
                            "\n"
                            "attribute vec4 VertexPosition;\n"
                            "attribute vec4 VertexTexCoord;\n"
                            "attribute vec4 VertexColor;\n"
                            "attribute vec4 ConstantColor;\n"
                            "\n"
                            "varying vec4 VaryingTexCoord;\n"
                            "varying vec4 VaryingColor;\n"
                            "\n"
                            "#ifdef GL_ES\n"
                            "uniform mediump float demoloop_PointSize;\n"
                            "#endif\n";

const char* VERTEX_FOOTER = "void main() {\n"
                            "VaryingTexCoord = VertexTexCoord;\n"
                            "VaryingColor = VertexColor * ConstantColor;\n"
                            // "VaryingColor = gammaCorrectColor(VertexColor) * ConstantColor;\n"
                            "#ifdef GL_ES\n"
                            "gl_PointSize = demoloop_PointSize;\n"
                            "#endif\n"
                            "gl_Position = position(TransformProjectionMatrix, ModelMatrix, VertexPosition);\n"
                            "}\n";

const char* FRAG_HEADER = "#define PIXEL\n"
                          "\n"
                          "#ifdef GL_ES\n"
                          "precision mediump float;\n"
                          "#endif\n"
                          "\n"
                          "varying mediump vec4 VaryingTexCoord;\n"
                          "varying mediump vec4 VaryingColor;\n"
                          "\n"
                          "#define love_Canvases gl_FragData\n"
                          "\n"
                          "uniform sampler2D _tex0_;\n";

const char* FRAG_FOOTER = "void main() {\n"
                          "// fix crashing issue in OSX when _tex0_ is unused within effect()\n"
                          "float dummy = Texel(_tex0_, vec2(.5)).r;\n"
                          "\n"
                          "// See Shader::checkSetScreenParams in Shader.cpp.\n"
                          "vec2 pixelcoord = vec2(gl_FragCoord.x, (gl_FragCoord.y * demoloop_ScreenSize.z) + demoloop_ScreenSize.w);\n"
                          "\n"
                          "gl_FragColor = effect(VaryingColor, _tex0_, VaryingTexCoord.st, pixelcoord);\n"
                          "}\n";

const char* UNIFORMS =  "\n"
                        "  // According to the GLSL ES 1.0 spec, uniform precision must match between stages,\n"
                        "  // but we can't guarantee that highp is always supported in fragment shaders...\n"
                        "  // We *really* don't want to use mediump for these in vertex shaders though.\n"
                        "  #if defined(VERTEX) || defined(GL_FRAGMENT_PRECISION_HIGH)\n"
                        "    #define DEMOLOOP_UNIFORM_PRECISION highp\n"
                        "  #else\n"
                        "    #define DEMOLOOP_UNIFORM_PRECISION mediump\n"
                        "  #endif\n"
                        "  uniform DEMOLOOP_UNIFORM_PRECISION mat4 TransformMatrix;\n"
                        "  uniform DEMOLOOP_UNIFORM_PRECISION mat4 ProjectionMatrix;\n"
                        "  uniform DEMOLOOP_UNIFORM_PRECISION mat4 TransformProjectionMatrix;\n"
                        "  uniform DEMOLOOP_UNIFORM_PRECISION mat4 ModelMatrix;\n"
                        "  uniform DEMOLOOP_UNIFORM_PRECISION mat3 NormalMatrix;\n"
                        "uniform mediump vec4 demoloop_ScreenSize;\n";

const char* getVersionPragma() {
  int profileMask;
  SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
  return profileMask == SDL_GL_CONTEXT_PROFILE_ES ? "#version 100\n" : "#version 120\n";
}

const char* getLinePragma() {
  int profileMask;
  SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
  return profileMask == SDL_GL_CONTEXT_PROFILE_ES ? "#line 1\n" : "#line 0\n";
}

std::string createVertexCode(const std::string &vertexShaderSource) {
  std::stringstream ss;
  ss << getVersionPragma() << SYNTAX << VERTEX_HEADER << UNIFORMS << getLinePragma() << vertexShaderSource << "\n" << VERTEX_FOOTER;
  return ss.str();
}

std::string createFragmentCode(const std::string &fragmentShaderSource) {
  std::stringstream ss;
  ss << getVersionPragma() << SYNTAX << FRAG_HEADER << UNIFORMS << getLinePragma() << fragmentShaderSource << "\n" << FRAG_FOOTER;
  return ss.str();
}

void printProgramLog(GLuint program) {
  if(glIsProgram(program)) {
    int infoLogLength = 0;
    int maxLength = infoLogLength;

    glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);

    char* infoLog = new char[ maxLength ];

    glGetProgramInfoLog(program, maxLength, &infoLogLength, infoLog);
    if(infoLogLength > 0) {

      std::cerr << infoLog << std::endl;
    }

    delete[] infoLog;
  } else {
    std::cerr << "Name " << program << " is not a program." << std::endl;
  }
}

void printShaderLog(GLuint shader) {
  if(glIsShader(shader)) {
    int infoLogLength = 0;
    int maxLength = infoLogLength;

    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);

    char* infoLog = new char[ maxLength ];

    glGetShaderInfoLog(shader, maxLength, &infoLogLength, infoLog);
    if(infoLogLength > 0) {
      std::cerr << infoLog << std::endl;
    }

    delete[] infoLog;
  }
  else {
    std::cerr << "Name " << shader << " is not a shader." << std::endl;
  }
}
<commit_msg>use c++11 string literals for shader construction<commit_after>#include "opengl_helpers.h"
#include <SDL.h>
#include <sstream>
#include <iostream>

const char* SYNTAX = R"===(
#ifndef GL_ES
#define lowp
#define mediump
#define highp
#endif
#define number float
#define Image sampler2D
#define extern uniform
#define Texel texture2D
// #pragma optionNV(strict on)
)===";

const char* VERTEX_HEADER = R"===(
#define VERTEX

attribute vec4 VertexPosition;
attribute vec4 VertexTexCoord;
attribute vec4 VertexColor;
attribute vec4 ConstantColor;

varying vec4 VaryingTexCoord;
varying vec4 VaryingColor;

#ifdef GL_ES
uniform mediump float demoloop_PointSize;
#endif
)===";

const char* VERTEX_FOOTER = R"===(
void main() {
  VaryingTexCoord = VertexTexCoord;
  VaryingColor = VertexColor * ConstantColor;

  #ifdef GL_ES
  gl_PointSize = demoloop_PointSize;
  #endif
  gl_Position = position(TransformProjectionMatrix, ModelMatrix, VertexPosition);
}
)===";

const char* FRAG_HEADER = R"===(
#define PIXEL

#ifdef GL_ES
precision mediump float;
#endif

varying mediump vec4 VaryingTexCoord;
varying mediump vec4 VaryingColor;

#define demoloop_Canvases gl_FragData

uniform sampler2D _tex0_;
)===";

const char* FRAG_FOOTER = R"===(
void main() {
  // fix crashing issue in OSX when _tex0_ is unused within effect()
  float dummy = Texel(_tex0_, vec2(.5)).r;

  // See Shader::checkSetScreenParams in Shader.cpp.
  vec2 pixelcoord = vec2(gl_FragCoord.x, (gl_FragCoord.y * demoloop_ScreenSize.z) + demoloop_ScreenSize.w);

  gl_FragColor = effect(VaryingColor, _tex0_, VaryingTexCoord.st, pixelcoord);
}
)===";

const char* UNIFORMS = R"===(
// According to the GLSL ES 1.0 spec, uniform precision must match between stages,
// but we can't guarantee that highp is always supported in fragment shaders...
// We *really* don't want to use mediump for these in vertex shaders though.
#if defined(VERTEX) || defined(GL_FRAGMENT_PRECISION_HIGH)
  #define DEMOLOOP_UNIFORM_PRECISION highp
#else
  #define DEMOLOOP_UNIFORM_PRECISION mediump
#endif
uniform DEMOLOOP_UNIFORM_PRECISION mat4 TransformMatrix;
uniform DEMOLOOP_UNIFORM_PRECISION mat4 ProjectionMatrix;
uniform DEMOLOOP_UNIFORM_PRECISION mat4 TransformProjectionMatrix;
uniform DEMOLOOP_UNIFORM_PRECISION mat4 ModelMatrix;
uniform DEMOLOOP_UNIFORM_PRECISION mat3 NormalMatrix;
uniform mediump vec4 demoloop_ScreenSize;
)===";

const char* getVersionPragma() {
  int profileMask;
  SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
  return profileMask == SDL_GL_CONTEXT_PROFILE_ES ? "#version 100\n" : "#version 120\n";
}

const char* getLinePragma() {
  int profileMask;
  SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
  return profileMask == SDL_GL_CONTEXT_PROFILE_ES ? "#line 1\n" : "#line 0\n";
}

std::string createVertexCode(const std::string &vertexShaderSource) {
  std::stringstream ss;
  ss << getVersionPragma() << SYNTAX << VERTEX_HEADER << UNIFORMS << getLinePragma() << vertexShaderSource << "\n" << VERTEX_FOOTER;
  return ss.str();
}

std::string createFragmentCode(const std::string &fragmentShaderSource) {
  std::stringstream ss;
  ss << getVersionPragma() << SYNTAX << FRAG_HEADER << UNIFORMS << getLinePragma() << fragmentShaderSource << "\n" << FRAG_FOOTER;
  return ss.str();
}

void printProgramLog(GLuint program) {
  if(glIsProgram(program)) {
    int infoLogLength = 0;
    int maxLength = infoLogLength;

    glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);

    char* infoLog = new char[ maxLength ];

    glGetProgramInfoLog(program, maxLength, &infoLogLength, infoLog);
    if(infoLogLength > 0) {

      std::cerr << infoLog << std::endl;
    }

    delete[] infoLog;
  } else {
    std::cerr << "Name " << program << " is not a program." << std::endl;
  }
}

void printShaderLog(GLuint shader) {
  if(glIsShader(shader)) {
    int infoLogLength = 0;
    int maxLength = infoLogLength;

    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);

    char* infoLog = new char[ maxLength ];

    glGetShaderInfoLog(shader, maxLength, &infoLogLength, infoLog);
    if(infoLogLength > 0) {
      std::cerr << infoLog << std::endl;
    }

    delete[] infoLog;
  }
  else {
    std::cerr << "Name " << shader << " is not a shader." << std::endl;
  }
}
<|endoftext|>


<commit_before>/***************************************************************************
 *   Copyright (C) 2004 by Sashmit Bhaduri                                 *
 *   smt@vfemail.net                                                       *
 *                                                                         *
 *   Licensed under GPL.                                                   *
 ***************************************************************************/

#include "articleviewer.h"
#include "viewer.h"
#include "feed.h"
#include "akregatorconfig.h"

#include <kapplication.h>
#include <klocale.h>
#include <kdebug.h>
#include <kglobalsettings.h>
#include <kstandarddirs.h>
#include <khtmlview.h>
#include <krun.h>
#include <kprocess.h>

#ifndef KDE_MAKE_VERSION
#define KDE_MAKE_VERSION( a,b,c ) (((a) << 16) | ((b) << 8) | (c))
#endif

#ifndef KDE_IS_VERSION
#define KDE_IS_VERSION(a,b,c) ( KDE_VERSION >= KDE_MAKE_VERSION(a,b,c) )
#endif

#if KDE_IS_VERSION(3,1,94)
#include <kshell.h>
#endif

#include <qdatetime.h>
#include <qvaluelist.h>
#include <qscrollview.h>
#include <qevent.h>

using namespace Akregator;

// from kmail::headerstyle.cpp
static inline QString directionOf(const QString &str)
{
    return str.isRightToLeft() ? "rtl" : "ltr" ;
}

int pointsToPixel(const QPaintDeviceMetrics &metrics, int pointSize)
{
    return ( pointSize * metrics.logicalDpiY() + 36 ) / 72 ;
}

ArticleViewer::ArticleViewer(QWidget *parent, const char *name)
    : Viewer(parent, name), m_metrics(widget())
{
    generateCSS();
}

void ArticleViewer::openDefault()
{
    openURL( ::locate( "data", "akregatorpart/welcome.html" ) );
}

void ArticleViewer::generateCSS()
{
    const QColorGroup & cg = QApplication::palette().active();
    m_htmlHead=QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
                        "<title></title>");
    m_htmlHead += QString (
    "\n")
    .arg(cg.background().light(108).name())
    .arg(cg.text().name());

}

void ArticleViewer::reload()
{
    generateCSS();
    begin( KURL( "file:"+KGlobal::dirs()->saveLocation("cache", "akregator/Media/") ) );
    write(m_htmlHead + m_currentText);
    end();
}

QString ArticleViewer::formatArticle(Feed *f, MyArticle a)
{
    QString text;
    text = QString("
\n").arg(QApplication::reverseLayout() ? "rtl" : "ltr");

    if (!a.title().isEmpty())
    {
        text += QString("
\n").arg(directionOf(a.title()));
        if (a.link().isValid())
            text += "";
        text += a.title();
        if (a.link().isValid())
            text += "";
        text += "
\n";
    }
    if (a.pubDate().isValid())
    {
        text += QString("").arg(directionOf(i18n("Date")));
        text += QString ("%1:").arg(i18n("Date"));
        text += "";
        text += KGlobal::locale()->formatDateTime(a.pubDate(), false, false)+"\n"; // TODO: might need RTL?
    }
    text += "
\n"; // end headerbox

    if (f && !f->image.isNull())
    {
        QString url=f->xmlUrl;
        text += QString("htmlUrl+"\">\n");
    }

    text += "
"+a.description();
    if (a.link().isValid())
    {
        if (!a.description().isNull())
            text += "
\n";
        text += "" + i18n( "Full Story" ) + "";
        if (!a.description().isNull())
            text += "
\n";
    }
    text += "
";
    return text;

}

void ArticleViewer::beginWriting()
{
    begin( KURL( "file:"+KGlobal::dirs()->saveLocation("cache", "akregator/Media/") ) );
    write(m_htmlHead);
}

void ArticleViewer::endWriting()
{
    m_currentText = m_currentText + "";
    write("");
    end();
}

void ArticleViewer::show(Feed *f, bool writeHeaders)
{
    QString art, text;

    if (writeHeaders)
    {
        begin( KURL( "file:"+KGlobal::dirs()->saveLocation("cache", "akregator/Media/") ) );
        write(m_htmlHead);
    }

    ArticleSequence::iterator it;
    for ( it = f->articles.begin(); it != f->articles.end(); ++it )
    {
        // we set f to 0 to not show feed image
        art="

"+formatArticle(0, *it)+"

";
        text += art;
        write(art);
    }

    if (writeHeaders)
    {
        m_currentText = text + "";
        write("");
        end();
    }
    else
    {
        m_currentText = m_currentText+text;
    }
}

void ArticleViewer::show(Feed *f, MyArticle a)
{
    begin( KURL( "file:"+KGlobal::dirs()->saveLocation("cache", "akregator/Media/") ) );

    QString text=formatArticle(f, a) +"";
    m_currentText=text;

    write(m_htmlHead + text);
    end();
}

/**
 * Display article in external browser.
 */
void ArticleViewer::displayInExternalBrowser(const KURL& url)
{
    if (!url.isValid()) return;
    if (Settings::externalBrowserUseKdeDefault())
        KRun::runURL(url, "text/html", false, false);
    else
    {
        QString cmd = Settings::externalBrowserCustomCommand();
        QString urlStr = url.url();
        cmd.replace(QRegExp("%u"), urlStr);
        KProcess *proc = new KProcess;
#if KDE_IS_VERSION(3,1,94)
        QStringList cmdAndArgs = KShell::splitArgs(cmd);
#else
        QStringList cmdAndArgs = QStringList::split(' ',cmd);
#endif
        *proc << cmdAndArgs;
//        This code will also work, but starts an extra shell process.
//        *proc << cmd;
//        proc->setUseShell(true);
          proc->start(KProcess::DontCare);
        delete proc;
    }
}

void ArticleViewer::slotOpenURLRequest(const KURL& url, const KParts::URLArgs& args)
{
   kdDebug() << "ArticleViewer: Open url request: " << url << endl;
   if(args.frameName == "_blank" && Settings::mMBBehaviour() == Settings::EnumMMBBehaviour::OpenInExternalBrowser)
       displayInExternalBrowser(url);
   else
       emit urlClicked(url);
}

void ArticleViewer::slotOpenLinkInternal()
{
    if(m_url.isEmpty()) return;
    emit urlClicked(m_url);
}

#include "articleviewer.moc"
<commit_msg>because we use kconfigxt, we need kdelibs >=3.2.0 anyways.<commit_after>/***************************************************************************
 *   Copyright (C) 2004 by Sashmit Bhaduri                                 *
 *   smt@vfemail.net                                                       *
 *                                                                         *
 *   Licensed under GPL.                                                   *
 ***************************************************************************/

#include "articleviewer.h"
#include "viewer.h"
#include "feed.h"
#include "akregatorconfig.h"

#include <kapplication.h>
#include <klocale.h>
#include <kdebug.h>
#include <kglobalsettings.h>
#include <kstandarddirs.h>
#include <khtmlview.h>
#include <krun.h>
#include <kprocess.h>
#include <kshell.h>

#include <qdatetime.h>
#include <qvaluelist.h>
#include <qscrollview.h>
#include <qevent.h>

using namespace Akregator;

// from kmail::headerstyle.cpp
static inline QString directionOf(const QString &str)
{
    return str.isRightToLeft() ? "rtl" : "ltr" ;
}

int pointsToPixel(const QPaintDeviceMetrics &metrics, int pointSize)
{
    return ( pointSize * metrics.logicalDpiY() + 36 ) / 72 ;
}

ArticleViewer::ArticleViewer(QWidget *parent, const char *name)
    : Viewer(parent, name), m_metrics(widget())
{
    generateCSS();
}

void ArticleViewer::openDefault()
{
    openURL( ::locate( "data", "akregatorpart/welcome.html" ) );
}

void ArticleViewer::generateCSS()
{
    const QColorGroup & cg = QApplication::palette().active();
    m_htmlHead=QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
                        "<title></title>");
    m_htmlHead += QString (
    "\n")
    .arg(cg.background().light(108).name())
    .arg(cg.text().name());

}

void ArticleViewer::reload()
{
    generateCSS();
    begin( KURL( "file:"+KGlobal::dirs()->saveLocation("cache", "akregator/Media/") ) );
    write(m_htmlHead + m_currentText);
    end();
}

QString ArticleViewer::formatArticle(Feed *f, MyArticle a)
{
    QString text;
    text = QString("
\n").arg(QApplication::reverseLayout() ? "rtl" : "ltr");

    if (!a.title().isEmpty())
    {
        text += QString("
\n").arg(directionOf(a.title()));
        if (a.link().isValid())
            text += "";
        text += a.title();
        if (a.link().isValid())
            text += "";
        text += "
\n";
    }
    if (a.pubDate().isValid())
    {
        text += QString("").arg(directionOf(i18n("Date")));
        text += QString ("%1:").arg(i18n("Date"));
        text += "";
        text += KGlobal::locale()->formatDateTime(a.pubDate(), false, false)+"\n"; // TODO: might need RTL?
    }
    text += "
\n"; // end headerbox

    if (f && !f->image.isNull())
    {
        QString url=f->xmlUrl;
        text += QString("htmlUrl+"\">\n");
    }

    text += "
"+a.description();
    if (a.link().isValid())
    {
        if (!a.description().isNull())
            text += "
\n";
        text += "" + i18n( "Full Story" ) + "";
        if (!a.description().isNull())
            text += "
\n";
    }
    text += "
";
    return text;

}

void ArticleViewer::beginWriting()
{
    begin( KURL( "file:"+KGlobal::dirs()->saveLocation("cache", "akregator/Media/") ) );
    write(m_htmlHead);
}

void ArticleViewer::endWriting()
{
    m_currentText = m_currentText + "";
    write("");
    end();
}

void ArticleViewer::show(Feed *f, bool writeHeaders)
{
    QString art, text;

    if (writeHeaders)
    {
        begin( KURL( "file:"+KGlobal::dirs()->saveLocation("cache", "akregator/Media/") ) );
        write(m_htmlHead);
    }

    ArticleSequence::iterator it;
    for ( it = f->articles.begin(); it != f->articles.end(); ++it )
    {
        // we set f to 0 to not show feed image
        art="

"+formatArticle(0, *it)+"

";
        text += art;
        write(art);
    }

    if (writeHeaders)
    {
        m_currentText = text + "";
        write("");
        end();
    }
    else
    {
        m_currentText = m_currentText+text;
    }
}

void ArticleViewer::show(Feed *f, MyArticle a)
{
    begin( KURL( "file:"+KGlobal::dirs()->saveLocation("cache", "akregator/Media/") ) );

    QString text=formatArticle(f, a) +"";
    m_currentText=text;

    write(m_htmlHead + text);
    end();
}

/**
 * Display article in external browser.
 */
void ArticleViewer::displayInExternalBrowser(const KURL& url)
{
    if (!url.isValid()) return;
    if (Settings::externalBrowserUseKdeDefault())
        KRun::runURL(url, "text/html", false, false);
    else
    {
        QString cmd = Settings::externalBrowserCustomCommand();
        QString urlStr = url.url();
        cmd.replace(QRegExp("%u"), urlStr);
        KProcess *proc = new KProcess;
        QStringList cmdAndArgs = KShell::splitArgs(cmd);
        *proc << cmdAndArgs;
//        This code will also work, but starts an extra shell process.
//        *proc << cmd;
//        proc->setUseShell(true);
          proc->start(KProcess::DontCare);
        delete proc;
    }
}

void ArticleViewer::slotOpenURLRequest(const KURL& url, const KParts::URLArgs& args)
{
   kdDebug() << "ArticleViewer: Open url request: " << url << endl;
   if(args.frameName == "_blank" && Settings::mMBBehaviour() == Settings::EnumMMBBehaviour::OpenInExternalBrowser)
       displayInExternalBrowser(url);
   else
       emit urlClicked(url);
}

void ArticleViewer::slotOpenLinkInternal()
{
    if(m_url.isEmpty()) return;
    emit urlClicked(m_url);
}

#include "articleviewer.moc"
<|endoftext|>