<commit_before>#include "Module.h"

#include <fstream>

#include "CodeGen_C.h"
#include "CodeGen_Internal.h"
#include "Debug.h"
#include "LLVM_Headers.h"
#include "LLVM_Output.h"
#include "LLVM_Runtime_Linker.h"
#include "Outputs.h"
#include "StmtToHtml.h"

namespace Halide {
using Halide::Internal::debug;

namespace Internal {

struct ModuleContents {
    mutable RefCount ref_count;
    std::string name;
    Target target;
    std::vector<Buffer> buffers;
    std::vector<Internal::LoweredFunc> functions;
};

template<>
EXPORT RefCount &ref_count<ModuleContents>(const ModuleContents *f) {
    return f->ref_count;
}

template<>
EXPORT void destroy<ModuleContents>(const ModuleContents *f) {
    delete f;
}

}  // namespace Internal

Module::Module(const std::string &name, const Target &target) :
    contents(new Internal::ModuleContents) {
    contents->name = name;
    contents->target = target;
}

const Target &Module::target() const {
    return contents->target;
}

const std::string &Module::name() const {
    return contents->name;
}

const std::vector<Buffer> &Module::buffers() const {
    return contents->buffers;
}

const std::vector<Internal::LoweredFunc> &Module::functions() const {
    return contents->functions;
}

void Module::append(const Buffer &buffer) {
    contents->buffers.push_back(buffer);
}

void Module::append(const Internal::LoweredFunc &function) {
    contents->functions.push_back(function);
}

Module link_modules(const std::string &name, const std::vector<Module> &modules) {
    Module output(name, modules.front().target());

    for (size_t i = 0; i < modules.size(); i++) {
        const Module &input = modules[i];

        if (output.target() != input.target()) {
            user_error << "Mismatched targets in modules to link ("
                       << output.name() << ", " << output.target().to_string()
                       << "), ("
                       << input.name() << ", " << input.target().to_string() << ")\n";
        }

        // TODO(dsharlet): Check for naming collisions, maybe rename
        // internal linkage declarations in the case of collision.
        for (const auto &b : input.buffers()) {
            output.append(b);
        }
        for (const auto &f : input.functions()) {
            output.append(f);
        }
    }

    return output;
}

void Module::compile(const Outputs &output_files) const {
    if (!output_files.object_name.empty() || !output_files.assembly_name.empty() ||
        !output_files.bitcode_name.empty() || !output_files.llvm_assembly_name.empty() ||
        !output_files.static_library_name.empty()) {
        llvm::LLVMContext context;
        std::unique_ptr<llvm::Module> llvm_module(compile_module_to_llvm_module(*this, context));

        if (!output_files.object_name.empty() || !output_files.static_library_name.empty()) {
            // We must always generate the object files here, either because they are
            // needed directly, or as temporary inputs to create a static library.
            // If they are just temporary inputs, we delete them when we're done,
            // to minimize the cruft left laying around in build products directory.
            std::unique_ptr<Internal::TemporaryFile> temp_file;

            std::string object_name = output_files.object_name;
            if (object_name.empty()) {
                const char* ext = target().os == Target::Windows && !target().has_feature(Target::MinGW) ? ".obj" : ".o";
                temp_file.reset(new Internal::TemporaryFile(Internal::base_name(output_files.static_library_name, '/'), ext));
                object_name = temp_file->pathname();
            }

            {
                auto out = make_raw_fd_ostream(object_name);
                if (target().arch == Target::PNaCl) {
                    compile_llvm_module_to_llvm_bitcode(*llvm_module, *out);
                } else {
                    compile_llvm_module_to_object(*llvm_module, *out);
                }
                out->flush();
            }

            if (!output_files.static_library_name.empty()) {
                Target base_target(target().os, target().arch, target().bits);
            }
        }
        if (!output_files.assembly_name.empty()) {
            auto out = make_raw_fd_ostream(output_files.assembly_name);
            if (target().arch == Target::PNaCl) {
                compile_llvm_module_to_llvm_assembly(*llvm_module, *out);
            } else {
                compile_llvm_module_to_assembly(*llvm_module, *out);
            }
        }
        if (!output_files.bitcode_name.empty()) {
            auto out = make_raw_fd_ostream(output_files.bitcode_name);
            compile_llvm_module_to_llvm_bitcode(*llvm_module, *out);
        }
        if (!output_files.llvm_assembly_name.empty()) {
            auto out = make_raw_fd_ostream(output_files.llvm_assembly_name);
            compile_llvm_module_to_llvm_assembly(*llvm_module, *out);
        }
    }
    if (!output_files.c_header_name.empty()) {
        Internal::CodeGen_C cg(file,
                               target().has_feature(Target::CPlusPlusMangling) ?
                               Internal::CodeGen_C::CPlusPlusHeader : Internal::CodeGen_C::CHeader,
                               output_files.c_header_name);
        cg.compile(*this);
    }
    if (!output_files.c_source_name.empty()) {
        Internal::CodeGen_C cg(file,
                               target().has_feature(Target::CPlusPlusMangling) ?
                               Internal::CodeGen_C::CPlusPlusImplementation : Internal::CodeGen_C::CImplementation);
        cg.compile(*this);
    }
    if (!output_files.stmt_name.empty()) {
        file << *this;
    }
    if (!output_files.stmt_html_name.empty()) {
        Internal::print_to_html(output_files.stmt_html_name, *this);
    }
}

    Module empty("standalone_runtime", t.without_feature(Target::NoRuntime).without_feature(Target::JIT));
    // For runtime, it only makes sense to output object files or static_library, so ignore
    // everything else.
}

void compile_standalone_runtime(const std::string &object_filename, Target t) {
    compile_standalone_runtime(Outputs().object(object_filename), t);
}

}
<commit_msg>Fix previous commit<commit_after>#include "Module.h"

#include <fstream>

#include "CodeGen_C.h"
#include "CodeGen_Internal.h"
#include "Debug.h"
#include "LLVM_Headers.h"
#include "LLVM_Output.h"
#include "LLVM_Runtime_Linker.h"
#include "Outputs.h"
#include "StmtToHtml.h"

using Halide::Internal::debug;

namespace Halide {
namespace Internal {

struct ModuleContents {
    mutable RefCount ref_count;
    std::string name;
    Target target;
    std::vector<Buffer> buffers;
    std::vector<Internal::LoweredFunc> functions;
};

template<>
EXPORT RefCount &ref_count<ModuleContents>(const ModuleContents *f) {
    return f->ref_count;
}

template<>
EXPORT void destroy<ModuleContents>(const ModuleContents *f) {
    delete f;
}

}  // namespace Internal

Module::Module(const std::string &name, const Target &target) :
    contents(new Internal::ModuleContents) {
    contents->name = name;
    contents->target = target;
}

const Target &Module::target() const {
    return contents->target;
}

const std::string &Module::name() const {
    return contents->name;
}

const std::vector<Buffer> &Module::buffers() const {
    return contents->buffers;
}

const std::vector<Internal::LoweredFunc> &Module::functions() const {
    return contents->functions;
}

void Module::append(const Buffer &buffer) {
    contents->buffers.push_back(buffer);
}

void Module::append(const Internal::LoweredFunc &function) {
    contents->functions.push_back(function);
}

Module link_modules(const std::string &name, const std::vector<Module> &modules) {
    Module output(name, modules.front().target());

    for (size_t i = 0; i < modules.size(); i++) {
        const Module &input = modules[i];

        if (output.target() != input.target()) {
            user_error << "Mismatched targets in modules to link ("
                       << output.name() << ", " << output.target().to_string()
                       << "), ("
                       << input.name() << ", " << input.target().to_string() << ")\n";
        }

        // TODO(dsharlet): Check for naming collisions, maybe rename
        // internal linkage declarations in the case of collision.
        for (const auto &b : input.buffers()) {
            output.append(b);
        }
        for (const auto &f : input.functions()) {
            output.append(f);
        }
    }

    return output;
}

void Module::compile(const Outputs &output_files) const {
    if (!output_files.object_name.empty() || !output_files.assembly_name.empty() ||
        !output_files.bitcode_name.empty() || !output_files.llvm_assembly_name.empty() ||
        !output_files.static_library_name.empty()) {
        llvm::LLVMContext context;
        std::unique_ptr<llvm::Module> llvm_module(compile_module_to_llvm_module(*this, context));

        if (!output_files.object_name.empty() || !output_files.static_library_name.empty()) {
            // We must always generate the object files here, either because they are
            // needed directly, or as temporary inputs to create a static library.
            // If they are just temporary inputs, we delete them when we're done,
            // to minimize the cruft left laying around in build products directory.
            std::unique_ptr<Internal::TemporaryFile> temp_file;

            std::string object_name = output_files.object_name;
            if (object_name.empty()) {
                const char* ext = target().os == Target::Windows && !target().has_feature(Target::MinGW) ? ".obj" : ".o";
                temp_file.reset(new Internal::TemporaryFile(Internal::base_name(output_files.static_library_name, '/'), ext));
                object_name = temp_file->pathname();
            }

            {
                debug(1) << "Module.compile(): object_name " << object_name << "\n";
                auto out = make_raw_fd_ostream(object_name);
                if (target().arch == Target::PNaCl) {
                    compile_llvm_module_to_llvm_bitcode(*llvm_module, *out);
                } else {
                    compile_llvm_module_to_object(*llvm_module, *out);
                }
                out->flush();
            }

            if (!output_files.static_library_name.empty()) {
                debug(1) << "Module.compile(): static_library_name " << output_files.static_library_name << "\n";
                Target base_target(target().os, target().arch, target().bits);
                create_static_library({object_name}, base_target, output_files.static_library_name);
            }
        }
        if (!output_files.assembly_name.empty()) {
            debug(1) << "Module.compile(): assembly_name " << output_files.assembly_name << "\n";
            auto out = make_raw_fd_ostream(output_files.assembly_name);
            if (target().arch == Target::PNaCl) {
                compile_llvm_module_to_llvm_assembly(*llvm_module, *out);
            } else {
                compile_llvm_module_to_assembly(*llvm_module, *out);
            }
        }
        if (!output_files.bitcode_name.empty()) {
            debug(1) << "Module.compile(): bitcode_name " << output_files.bitcode_name << "\n";
            auto out = make_raw_fd_ostream(output_files.bitcode_name);
            compile_llvm_module_to_llvm_bitcode(*llvm_module, *out);
        }
        if (!output_files.llvm_assembly_name.empty()) {
            debug(1) << "Module.compile(): llvm_assembly_name " << output_files.llvm_assembly_name << "\n";
            auto out = make_raw_fd_ostream(output_files.llvm_assembly_name);
            compile_llvm_module_to_llvm_assembly(*llvm_module, *out);
        }
    }
    if (!output_files.c_header_name.empty()) {
        debug(1) << "Module.compile(): c_header_name " << output_files.c_header_name << "\n";
        std::ofstream file(output_files.c_header_name);
        Internal::CodeGen_C cg(file,
                               target().has_feature(Target::CPlusPlusMangling) ?
                               Internal::CodeGen_C::CPlusPlusHeader : Internal::CodeGen_C::CHeader,
                               output_files.c_header_name);
        cg.compile(*this);
    }
    if (!output_files.c_source_name.empty()) {
        debug(1) << "Module.compile(): c_source_name " << output_files.c_source_name << "\n";
        std::ofstream file(output_files.c_source_name);
        Internal::CodeGen_C cg(file,
                               target().has_feature(Target::CPlusPlusMangling) ?
                               Internal::CodeGen_C::CPlusPlusImplementation : Internal::CodeGen_C::CImplementation);
        cg.compile(*this);
    }
    if (!output_files.stmt_name.empty()) {
        debug(1) << "Module.compile(): stmt_name " << output_files.stmt_name << "\n";
        std::ofstream file(output_files.stmt_name);
        file << *this;
    }
    if (!output_files.stmt_html_name.empty()) {
        debug(1) << "Module.compile(): stmt_html_name " << output_files.stmt_html_name << "\n";
        Internal::print_to_html(output_files.stmt_html_name, *this);
    }
}

Outputs compile_standalone_runtime(const Outputs &output_files, Target t) {
    Module empty("standalone_runtime", t.without_feature(Target::NoRuntime).without_feature(Target::JIT));
    // For runtime, it only makes sense to output object files or static_library, so ignore
    // everything else.
    Outputs actual_outputs = Outputs().object(output_files.object_name).static_library(output_files.static_library_name);
    empty.compile(actual_outputs);
    return actual_outputs;
}

void compile_standalone_runtime(const std::string &object_filename, Target t) {
    compile_standalone_runtime(Outputs().object(object_filename), t);
}

}  // namespace Halide
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: cfrstd.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 17:24:32 $
 *
 *  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
 *
 ************************************************************************/

#include <precomp.h>
#include <cfrstd.hxx>

// NOT FULLY DEFINED SERVICES

/*                      CSS Styles
                        ----------

Colors:
-   light background color              #eeeeff
-   dark background color               #ccccff
-   self in navibar background color    #2222ad

Fonts:
-   page title              20, bold, Arial
-   navibar main            12, bold, Arial
-   navibar sub              8, Arial, kapitlchen
-   attrtable title line     8, bold, Arial, kapitlchen
-   attrtable value line     8, Arial kapitlchen

-   namespace chain         13, bold
-   table title             13, bold
-   template line           13

-   member paragraph title  12, bold

-   docu paragraph title    11, bold
-   standard text           11

-   hierarchy               11, monospace

classes:

    td.title                page title
    h3                      table title
    h4                      member paragraph title

    td.nmain                navigation main bar
    td.nsub                 navigation sub bar
    a.nmain                 links in navigation main bar
    a.nsub                  links in navigation sub bar

    td.attr1                attribute table head line
    td.attr2                attribute table value line

    p.namechain             namespace chain in head of pages
    p.tpl                   template line in head of pages

    pre.doc                 preformatted docu
    pre.hierarchy           class bases hierarchy graphic

    dl.syntax               function- or variable-declaration field
    a.syntax                link in function- or variable-declaration field

    p.dt                    docu paragraph title
    dl.dt                   docu paragraph title

    p                       standard text
    dl                      standard text
    dd                      standard text
*/

#define CRLF "\n"

namespace
{
const char * const C_sStdStyle =
    "/*See bottom of file for explanations.*/"CRLF
    CRLF
    "body { background-color:#ffffff; }"CRLF
    CRLF
    "h3             { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "p, dt, dd, pre { font-size:11pt;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "pre            { font-family:monospace; }"CRLF
    CRLF
    "table.lightbg  { background-color:#eeeeff; }"CRLF
    "table.subtitle { margin-top:6pt; margin-bottom:6pt; }"CRLF
    CRLF
    "td             {                     font-size:11pt; }"CRLF
    "td.title       { font-family: Arial; font-size:19pt; font-weight:bold;"CRLF
    "                 line-height:30pt;   background-color:#ccccff; text-align:center; }"CRLF
    "td.subtitle    { font-family: Arial; font-size:13pt;"CRLF
    "                 line-height:20pt;   background-color:#ccccff; }"CRLF
    "td.crosstitle  {                     font-size:12pt; font-weight:bold;"CRLF
    "                 line-height:15pt;   background-color:#eeeeff; }"CRLF
    "td.imdetail    { width:100%;         background-color:#eeeeff; }"CRLF
    CRLF
    "td.imsum_left  { width:30%;  }"CRLF
    "td.imsum_right { width:70%;  }"CRLF
    CRLF
    "td.navimain, a.navimain"CRLF
    "                   { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold; }"CRLF
    "td.navimainself    { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold;"CRLF
    "                     color:#ffffff; background-color:#2222ad; }"CRLF
    "td.navimainnone    { text-align:center; font-family: Arial; font-size:12pt; }"CRLF
    "td.navisub, a.navisub"CRLF
    "                   { text-align:center; font-family: Arial; font-size:9pt; font-variant:small-caps; }"CRLF
    "td.navimain, td.navisub"CRLF
    "                   { padding-left:7pt; padding-right:7pt; }"CRLF
    CRLF
    "a.membertitle  { font-size:12pt; font-weight:bold; line-height:18pt; }"CRLF
    "a.navimain, a.navisub  { color:#000000; }"CRLF
    ".dt            { font-weight:bold; }"CRLF
    ".namechain     { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:6pt; }"CRLF
    ;

const char * const C_sCssExplanations =
    "/* Explanation of CSS classes:"CRLF
    CRLF
    "table.lightbg      Background of navigation bar."CRLF
    ".navimain          Text in main navigation bar."CRLF
    ".navisub           Text in lower navigation bar."CRLF
    "td.navimainself    Cell in main navigation bar with \"selected\" shadow: You are here."CRLF
    "td.navimainnone    Cell in main navigation bar with no link."CRLF
    CRLF
    ".namechain         Line with current module path."CRLF
    CRLF
    "td.crosstitle      Comment box for bases (base interfaces etc.)"CRLF
    "td.imsum_left      Left part of such boxes."CRLF
    "td.imsum_right     Right part of such boxes."CRLF
    CRLF
    "td.title           Main title of the page like \"interface XYz\""CRLF
    ".subtitle          Tables, and head cells of those, which list members"CRLF
    "                   like \"method summary\" and \"method details\"."CRLF
    CRLF
    "td.imdetail        Background table of method's detail description."CRLF
    "a.membertitle      Method name (as jump label) in method's detail"CRLF
    "                   description."CRLF
    "*/"CRLF
    ;
}   // anonymous namespace

StdFrame::StdFrame()
    :   sDevelopersGuideHtmlRoot(),
        bSimpleLinks(false)
{
}

DYN Html_Image *
StdFrame::LogoSrc() const
{
    return 0;

//    return  new Html_Image( "logodot-blu.gif",
//                            "109",
//                            "54",
//                            "RIGHT",
//                            "0",
//                            "OpenOffice" );

}

const char *
StdFrame::LogoLink() const
{
    return "";
//  return "http://www.sun.com";
//  return "http://www.openoffice.org";
}

const char *
StdFrame::CopyrightText() const
{
    return "Copyright © 2003 Sun Microsystems, Inc.";

//  return "Copyright © 2002 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, CA 94303 USA.";
//  return "Copyright 2001 OpenOffice.org Foundation. All Rights Reserved.";
}

const char *
StdFrame::CssStyle() const
{
    return C_sStdStyle;
}

const char *
StdFrame::CssStylesExplanation() const
{
    return C_sCssExplanations;
}

const char *
StdFrame::DevelopersGuideHtmlRoot() const
{
    return sDevelopersGuideHtmlRoot;
}

bool
StdFrame::SimpleLinks() const
{
    return bSimpleLinks;
}

void
StdFrame::Set_DevelopersGuideHtmlRoot( const String & i_directory )
{
    if (NOT i_directory.empty())
    {
        if (i_directory.char_at(i_directory.length()-1) == '/')
        {
            sDevelopersGuideHtmlRoot.assign(i_directory,i_directory.length()-1);
            return;
        }
    }
    sDevelopersGuideHtmlRoot = i_directory;
}

void
StdFrame::Set_SimpleLinks()
{
    bSimpleLinks = true;
}
<commit_msg>INTEGRATION: CWS rt13 (1.8.8); FILE MERGED 2005/12/08 10:05:37 np 1.8.8.5: #i58717# 2005/12/07 17:37:06 np 1.8.8.4: #i58717# 2005/12/07 17:23:58 np 1.8.8.3: #i58717# 2005/12/05 16:55:16 np 1.8.8.2: #i58717# 2005/12/05 16:49:25 np 1.8.8.1: #i58717#<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: cfrstd.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: rt $ $Date: 2005-12-14 15:32:23 $
 *
 *  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
 *
 ************************************************************************/

#include <precomp.h>
#include <cfrstd.hxx>

// NOT FULLY DEFINED SERVICES

/*                      CSS Styles
                        ----------

Colors:
-   light background color              #eeeeff
-   dark background color               #ccccff
-   self in navibar background color    #2222ad

Fonts:
-   page title              20, bold, Arial
-   navibar main            12, bold, Arial
-   navibar sub              8, Arial, kapitlchen
-   attrtable title line     8, bold, Arial, kapitlchen
-   attrtable value line     8, Arial kapitlchen

-   namespace chain         13, bold
-   table title             13, bold
-   template line           13

-   member paragraph title  12, bold

-   docu paragraph title    11, bold
-   standard text           11

-   hierarchy               11, monospace

classes:

    td.title                page title
    h3                      table title
    h4                      member paragraph title

    td.nmain                navigation main bar
    td.nsub                 navigation sub bar
    a.nmain                 links in navigation main bar
    a.nsub                  links in navigation sub bar

    td.attr1                attribute table head line
    td.attr2                attribute table value line

    p.namechain             namespace chain in head of pages
    p.tpl                   template line in head of pages

    pre.doc                 preformatted docu
    pre.hierarchy           class bases hierarchy graphic

    dl.syntax               function- or variable-declaration field
    a.syntax                link in function- or variable-declaration field

    p.dt                    docu paragraph title
    dl.dt                   docu paragraph title

    p                       standard text
    dl                      standard text
    dd                      standard text
*/

#define CRLF "\n"

namespace
{

bool            bUse_OOoFrameDiv = true;

//***************   These are used for IDL currently only!   ********************

const char * const C_sStdStyle =
    "/*See bottom of file for explanations.*/"CRLF
    CRLF
    "body { background-color:#ffffff; }"CRLF
    CRLF
    "h3             { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "p, dt, dd, pre { font-size:11pt;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "pre            { font-family:monospace; }"CRLF
    CRLF
    "table.navimain { background-color:#eeeeff; }"CRLF
    "table.subtitle { margin-top:6pt; margin-bottom:6pt; }"CRLF
    CRLF
    "td             {                     font-size:11pt; }"CRLF
    "td.title       { font-family: Arial; font-size:19pt; font-weight:bold;"CRLF
    "                 line-height:30pt;   background-color:#ccccff; text-align:center; }"CRLF
    "td.subtitle    { font-family: Arial; font-size:13pt;"CRLF
    "                 line-height:20pt;   background-color:#ccccff; }"CRLF
    "td.crosstitle  {                     font-size:12pt; font-weight:bold;"CRLF
    "                 line-height:15pt;   background-color:#eeeeff; }"CRLF
    "td.imdetail    { width:100%;         background-color:#eeeeff; }"CRLF
    CRLF
    "td.imsum_left  { width:30%;  }"CRLF
    "td.imsum_right { width:70%;  }"CRLF
    CRLF
    "td.navimain, a.navimain"CRLF
    "                   { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold; }"CRLF
    "td.navimainself    { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold;"CRLF
    "                     color:#ffffff; background-color:#2222ad; }"CRLF
    "td.navimainnone    { text-align:center; font-family: Arial; font-size:12pt; }"CRLF
    "td.navisub, a.navisub"CRLF
    "                   { text-align:center; font-family: Arial; font-size:9pt; font-variant:small-caps; }"CRLF
    "td.navimain, td.navisub"CRLF
    "                   { padding-left:7pt; padding-right:7pt; }"CRLF
    CRLF
    "a.membertitle  { font-size:12pt; font-weight:bold; line-height:18pt; }"CRLF
    "a.navimain, a.navisub  { color:#000000; }"CRLF
    ".dt            { font-weight:bold; }"CRLF
    ".namechain     { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:6pt; }"CRLF
    ;

const char * const C_sCssExplanations =
    "/* Explanation of CSS classes:"CRLF
    CRLF
    ".navimain          Text in main navigation bar."CRLF
    ".navisub           Text in lower navigation bar."CRLF
    "td.navimainself    Cell in main navigation bar with \"selected\" shadow: You are here."CRLF
    "td.navimainnone    Cell in main navigation bar with no link."CRLF
    CRLF
    ".namechain         Line with current module path."CRLF
    CRLF
    "td.crosstitle      Comment box for bases (base interfaces etc.)"CRLF
    "td.imsum_left      Left part of such boxes."CRLF
    "td.imsum_right     Right part of such boxes."CRLF
    CRLF
    "td.title           Main title of the page like \"interface XYz\""CRLF
    ".subtitle          Tables, and head cells of those, which list members"CRLF
    "                   like \"method summary\" and \"method details\"."CRLF
    CRLF
    "td.imdetail        Background table of method's detail description."CRLF
    "a.membertitle      Method name (as jump label) in method's detail"CRLF
    "                   description."CRLF
    "*/"CRLF
    ;

const char * const C_sStdStyle_withDivFrame =
    "/*See bottom of file for explanations.*/"CRLF
    CRLF
    "body { background-color:#ffffff; }"CRLF
    CRLF
    "#adc-idlref h3 { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "#adc-idlref p, #adc-idlref dt, #adc-idlref dd, #adc-idlref pre"CRLF
    "               { font-size:11pt;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "#adc-idlref pre    { font-family:monospace; }"CRLF
    CRLF
    "#adc-idlref table.navimain { background-color:#eeeeff; }"CRLF
    "#adc-idlref table.subtitle { margin-top:6pt; margin-bottom:6pt; }"CRLF
    CRLF
    "#adc-idlref td             { font-size:11pt; }"CRLF
    "#adc-idlref td.title       { font-family: Arial; font-size:19pt; font-weight:bold;"CRLF
    "                             line-height:30pt;   background-color:#ccccff; text-align:center; }"CRLF
    "#adc-idlref td.subtitle    { font-family: Arial; font-size:13pt;"CRLF
    "                             line-height:20pt;   background-color:#ccccff; }"CRLF
    "#adc-idlref td.crosstitle  { font-size:12pt; font-weight:bold;"CRLF
    "                             line-height:15pt;   background-color:#eeeeff; }"CRLF
    "#adc-idlref td.imdetail    { width:100%;         background-color:#eeeeff; }"CRLF
    CRLF
    "#adc-idlref td.imsum_left  { width:30%;  }"CRLF
    "#adc-idlref td.imsum_right { width:70%;  }"CRLF
    CRLF
    "#adc-idlref td.navimain, #adc-idlref a.navimain"CRLF
    "                   { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold; }"CRLF
    "#adc-idlref td.navimainself    { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold;"CRLF
    "                                 color:#ffffff; background-color:#2222ad; }"CRLF
    "#adc-idlref td.navimainnone    { text-align:center; font-family: Arial; font-size:12pt; }"CRLF
    "#adc-idlref td.navisub, #adc-idlref a.navisub"CRLF
    "                   { text-align:center; font-family: Arial; font-size:9pt; font-variant:small-caps; }"CRLF
    "#adc-idlref td.navimain, #adc-idlref td.navisub"CRLF
    "                   { padding-left:7pt; padding-right:7pt; }"CRLF
    CRLF
    "#adc-idlref a.membertitle  { font-size:12pt; font-weight:bold; line-height:18pt; }"CRLF
    "#adc-idlref a.navimain, #adc-idlref a.navisub  { color:#000000; }"CRLF
    "#adc-idlref .dt            { font-weight:bold; }"CRLF
    "#adc-idlref .namechain     { font-size:13pt; font-weight:bold;"CRLF
    "                             margin-top:3pt; margin-bottom:6pt; }"CRLF
    ""CRLF
    "#adc-idlref table { empty-cells:show; }"CRLF
    ""CRLF
    "#adc-idlref .childlist td, "CRLF
    "#adc-idlref .commentedlinks td, "CRLF
    "#adc-idlref .memberlist td, "CRLF
    "#adc-idlref .subtitle td, "CRLF
    "#adc-idlref .crosstitle td  { border: .1pt solid #000000; }"CRLF
    ""CRLF
    "#adc-idlref .flag-table td { border: .1pt solid #cccccc; } "CRLF
    ""CRLF
    "#adc-idlref .title-table td, "CRLF
    "#adc-idlref .table-in-method td, "CRLF
    "#adc-idlref .table-in-data td, "CRLF
    "#adc-idlref .navimain td, "CRLF
    "#adc-idlref .navisub td, "CRLF
    "#adc-idlref .expl-table td, "CRLF
    "#adc-idlref .param-table td  { border: none; }"CRLF
    ;

}   // anonymous namespace

StdFrame::StdFrame()
    :   sDevelopersGuideHtmlRoot(),
        bSimpleLinks(false)
{
}

DYN Html_Image *
StdFrame::LogoSrc() const
{
    return 0;

//    return  new Html_Image( "logodot-blu.gif",
//                            "109",
//                            "54",
//                            "RIGHT",
//                            "0",
//                            "OpenOffice" );

}

const char *
StdFrame::LogoLink() const
{
    return "";
//  return "http://www.sun.com";
//  return "http://www.openoffice.org";
}

const char *
StdFrame::CopyrightText() const
{
    return "Copyright © 2003 Sun Microsystems, Inc.";

//  return "Copyright © 2002 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, CA 94303 USA.";
//  return "Copyright 2001 OpenOffice.org Foundation. All Rights Reserved.";
}

const char *
StdFrame::CssStyle() const
{
    if (bUse_OOoFrameDiv)
        return C_sStdStyle_withDivFrame;
    else
        return C_sStdStyle;
}

const char *
StdFrame::CssStylesExplanation() const
{
    return C_sCssExplanations;
}

const char *
StdFrame::DevelopersGuideHtmlRoot() const
{
    return sDevelopersGuideHtmlRoot;
}

bool
StdFrame::SimpleLinks() const
{
    return bSimpleLinks;
}

void
StdFrame::Set_DevelopersGuideHtmlRoot( const String & i_directory )
{
    if (NOT i_directory.empty())
    {
        if (i_directory.char_at(i_directory.length()-1) == '/')
        {
            sDevelopersGuideHtmlRoot.assign(i_directory,i_directory.length()-1);
            return;
        }
    }
    sDevelopersGuideHtmlRoot = i_directory;
}

void
StdFrame::Set_SimpleLinks()
{
    bSimpleLinks = true;
}
<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * 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.
 *
 ************************************************************************/

#include <precomp.h>
#include <cfrstd.hxx>

// NOT FULLY DEFINED SERVICES
#include <time.h>

/*                      CSS Styles
                        ----------

Colors:
-   light background color              #eeeeff
-   dark background color               #ccccff
-   self in navibar background color    #2222ad

Fonts:
-   page title              20, bold, Arial
-   navibar main            12, bold, Arial
-   navibar sub              8, Arial, kapitlchen
-   attrtable title line     8, bold, Arial, kapitlchen
-   attrtable value line     8, Arial kapitlchen

-   namespace chain         13, bold
-   table title             13, bold
-   template line           13

-   member paragraph title  12, bold

-   docu paragraph title    11, bold
-   standard text           11

-   hierarchy               11, monospace

classes:

    td.title                page title
    h3                      table title
    h4                      member paragraph title

    td.nmain                navigation main bar
    td.nsub                 navigation sub bar
    a.nmain                 links in navigation main bar
    a.nsub                  links in navigation sub bar

    td.attr1                attribute table head line
    td.attr2                attribute table value line

    p.namechain             namespace chain in head of pages
    p.tpl                   template line in head of pages

    pre.doc                 preformatted docu
    pre.hierarchy           class bases hierarchy graphic

    dl.syntax               function- or variable-declaration field
    a.syntax                link in function- or variable-declaration field

    p.dt                    docu paragraph title
    dl.dt                   docu paragraph title

    p                       standard text
    dl                      standard text
    dd                      standard text
*/

#define CRLF "\n"

namespace
{

bool            bUse_OOoFrameDiv = true;

//***************   These are used for IDL currently only!   ********************

const char * const C_sStdStyle =
    "/*See bottom of file for explanations.*/"CRLF
    CRLF
    "body { background-color:#ffffff; }"CRLF
    CRLF
    "h3             { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "p, dt, dd, pre { font-size:11pt;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "pre            { font-family:monospace; }"CRLF
    CRLF
    "table.navimain { background-color:#eeeeff; }"CRLF
    "table.subtitle { margin-top:6pt; margin-bottom:6pt; }"CRLF
    CRLF
    "td             {                     font-size:11pt; }"CRLF
    "td.title       { font-family: Arial; font-size:19pt; font-weight:bold;"CRLF
    "                 line-height:30pt;   background-color:#ccccff; text-align:center; }"CRLF
    "td.subtitle    { font-family: Arial; font-size:13pt;"CRLF
    "                 line-height:20pt;   background-color:#ccccff; }"CRLF
    "td.crosstitle  {                     font-size:12pt; font-weight:bold;"CRLF
    "                 line-height:15pt;   background-color:#eeeeff; }"CRLF
    "td.imdetail    { width:100%;         background-color:#eeeeff; }"CRLF
    CRLF
    "td.imsum_left  { width:30%;  }"CRLF
    "td.imsum_right { width:70%;  }"CRLF
    CRLF
    "td.navimain, a.navimain"CRLF
    "                   { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold; }"CRLF
    "td.navimainself    { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold;"CRLF
    "                     color:#ffffff; background-color:#2222ad; }"CRLF
    "td.navimainnone    { text-align:center; font-family: Arial; font-size:12pt; }"CRLF
    "td.navisub, a.navisub"CRLF
    "                   { text-align:center; font-family: Arial; font-size:9pt; font-variant:small-caps; }"CRLF
    "td.navimain, td.navisub"CRLF
    "                   { padding-left:7pt; padding-right:7pt; }"CRLF
    CRLF
    "a.membertitle  { font-size:12pt; font-weight:bold; line-height:18pt; }"CRLF
    "a.navimain, a.navisub  { color:#000000; }"CRLF
    ".dt            { font-weight:bold; }"CRLF
    ".namechain     { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:6pt; }"CRLF
    ".title2        { font-size:13pt; font-style:italic; font-weight:bold; text-align:left; }"CRLF
    ;

const char * const C_sCssExplanations =
    "/* Explanation of CSS classes:"CRLF
    CRLF
    ".navimain          Text in main navigation bar."CRLF
    ".navisub           Text in lower navigation bar."CRLF
    "td.navimainself    Cell in main navigation bar with \"selected\" shadow: You are here."CRLF
    "td.navimainnone    Cell in main navigation bar with no link."CRLF
    CRLF
    ".namechain         Line with current module path."CRLF
    CRLF
    "td.crosstitle      Comment box for bases (base interfaces etc.)"CRLF
    "td.imsum_left      Left part of such boxes."CRLF
    "td.imsum_right     Right part of such boxes."CRLF
    CRLF
    "td.title           Main title of the page like \"interface XYz\""CRLF
    ".subtitle          Tables, and head cells of those, which list members"CRLF
    "                   like \"method summary\" and \"method details\"."CRLF
    CRLF
    "td.imdetail        Background table of method's detail description."CRLF
    "a.membertitle      Method name (as jump label) in method's detail"CRLF
    "                   description."CRLF
    ".title2            smaller font prefixes to page titles"CRLF
    "*/"CRLF
    ;

const char * const C_sStdStyle_withDivFrame =
    "/*See bottom of file for explanations.*/"CRLF
    CRLF
    "body { background-color:#ffffff; }"CRLF
    CRLF
    "#adc-idlref h3 { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "#adc-idlref p, #adc-idlref dt, #adc-idlref dd, #adc-idlref pre"CRLF
    "               { font-size:11pt;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "#adc-idlref pre    { font-family:monospace; }"CRLF
    CRLF
    "#adc-idlref table.navimain { background-color:#eeeeff; }"CRLF
    "#adc-idlref table.subtitle { margin-top:6pt; margin-bottom:6pt; }"CRLF
    CRLF
    "#adc-idlref td             { font-size:11pt; }"CRLF
    "#adc-idlref td.title       { font-family: Arial; font-size:19pt; font-weight:bold;"CRLF
    "                             line-height:30pt;   background-color:#ccccff; text-align:center; }"CRLF
    "#adc-idlref td.subtitle    { font-family: Arial; font-size:13pt;"CRLF
    "                             line-height:20pt;   background-color:#ccccff; }"CRLF
    "#adc-idlref td.crosstitle  { font-size:12pt; font-weight:bold;"CRLF
    "                             line-height:15pt;   background-color:#eeeeff; }"CRLF
    "#adc-idlref td.imdetail    { width:100%;         background-color:#eeeeff; }"CRLF
    CRLF
    "#adc-idlref td.imsum_left  { width:30%;  }"CRLF
    "#adc-idlref td.imsum_right { width:70%;  }"CRLF
    CRLF
    "#adc-idlref td.navimain, #adc-idlref a.navimain"CRLF
    "                   { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold; }"CRLF
    "#adc-idlref td.navimainself    { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold;"CRLF
    "                                 color:#ffffff; background-color:#2222ad; }"CRLF
    "#adc-idlref td.navimainnone    { text-align:center; font-family: Arial; font-size:12pt; }"CRLF
    "#adc-idlref td.navisub, #adc-idlref a.navisub"CRLF
    "                   { text-align:center; font-family: Arial; font-size:9pt; font-variant:small-caps; }"CRLF
    "#adc-idlref td.navimain, #adc-idlref td.navisub"CRLF
    "                   { padding-left:7pt; padding-right:7pt; }"CRLF
    CRLF
    "#adc-idlref a.membertitle  { font-size:12pt; font-weight:bold; line-height:18pt; }"CRLF
    "#adc-idlref a.navimain, #adc-idlref a.navisub  { color:#000000; }"CRLF
    "#adc-idlref .dt            { font-weight:bold; }"CRLF
    "#adc-idlref .namechain     { font-size:13pt; font-weight:bold;"CRLF
    "                             margin-top:3pt; margin-bottom:6pt; }"CRLF
    "#adc-idlref .title2        { font-size:13pt; font-style:italic; font-weight:bold; text-align:left; }"CRLF
    ""CRLF
    "#adc-idlref table { empty-cells:show; }"CRLF
    ""CRLF
    "#adc-idlref .childlist td, "CRLF
    "#adc-idlref .commentedlinks td, "CRLF
    "#adc-idlref .memberlist td, "CRLF
    "#adc-idlref .subtitle td, "CRLF
    "#adc-idlref .crosstitle td  { border: .1pt solid #000000; }"CRLF
    ""CRLF
    "#adc-idlref .flag-table td { border: .1pt solid #cccccc; } "CRLF
    ""CRLF
    "#adc-idlref .title-table td, "CRLF
    "#adc-idlref .table-in-method td, "CRLF
    "#adc-idlref .table-in-data td, "CRLF
    "#adc-idlref .navimain td, "CRLF
    "#adc-idlref .navisub td, "CRLF
    "#adc-idlref .expl-table td, "CRLF
    "#adc-idlref .param-table td  { border: none; }"CRLF
    ;

}   // anonymous namespace

StdFrame::StdFrame()
    :   sDevelopersGuideHtmlRoot(),
        bSimpleLinks(false)
{
}

DYN Html_Image *
StdFrame::LogoSrc() const
{
    return 0;

//    return  new Html_Image( "logodot-blu.gif",
//                            "109",
//                            "54",
//                            "RIGHT",
//                            "0",
//                            "OpenOffice" );

}

const char *
StdFrame::LogoLink() const
{
    return "";
//  return "http://www.sun.com";
//  return "http://www.openoffice.org";
}

String              MakeCopyRight();

const char *
StdFrame::CopyrightText() const
{
    static String sCopyRight_( MakeCopyRight() );
    return sCopyRight_.c_str();
}

const char *
StdFrame::CssStyle() const
{
    if (bUse_OOoFrameDiv)
        return C_sStdStyle_withDivFrame;
    else
        return C_sStdStyle;
}

const char *
StdFrame::CssStylesExplanation() const
{
    return C_sCssExplanations;
}

const char *
StdFrame::DevelopersGuideHtmlRoot() const
{
    return sDevelopersGuideHtmlRoot;
}

bool
StdFrame::SimpleLinks() const
{
    return bSimpleLinks;
}

void
StdFrame::Set_DevelopersGuideHtmlRoot( const String & i_directory )
{
    if (NOT i_directory.empty())
    {
        if (i_directory.char_at(i_directory.length()-1) == '/')
        {
            sDevelopersGuideHtmlRoot.assign(i_directory,i_directory.length()-1);
            return;
        }
    }
    sDevelopersGuideHtmlRoot = i_directory;
}

void
StdFrame::Set_SimpleLinks()
{
    bSimpleLinks = true;
}

String
MakeCopyRight()
{
    StreamStr cr(700);
    time_t
        gt;
    time(&gt);
    tm *
        plt = localtime(&gt);
    int year = 1900 + plt->tm_year;

    cr  << "LibreOffice is copyright © 2000, "
	<< year
	<< ", LibreOffice contributors and/or their affiliates. All rights reserved.
"
	<< "
LibreOffice is derived from OpenOffice.org. OpenOffice.org is copyright © 2000, 2011 Oracle and/or its affiliates. All rights reserved.
"
	<< "
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.";
    return String(cr.c_str());

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>translated German comment<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * 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.
 *
 ************************************************************************/

#include <precomp.h>
#include <cfrstd.hxx>

// NOT FULLY DEFINED SERVICES
#include <time.h>

/*                      CSS Styles
                        ----------

Colors:
-   light background color              #eeeeff
-   dark background color               #ccccff
-   self in navibar background color    #2222ad

Fonts:
-   page title              20, bold, Arial
-   navibar main            12, bold, Arial
-   navibar sub              8, Arial, small caps
-   attrtable title line     8, bold, Arial, small caps
-   attrtable value line     8, Arial small caps

-   namespace chain         13, bold
-   table title             13, bold
-   template line           13

-   member paragraph title  12, bold

-   docu paragraph title    11, bold
-   standard text           11

-   hierarchy               11, monospace

classes:

    td.title                page title
    h3                      table title
    h4                      member paragraph title

    td.nmain                navigation main bar
    td.nsub                 navigation sub bar
    a.nmain                 links in navigation main bar
    a.nsub                  links in navigation sub bar

    td.attr1                attribute table head line
    td.attr2                attribute table value line

    p.namechain             namespace chain in head of pages
    p.tpl                   template line in head of pages

    pre.doc                 preformatted docu
    pre.hierarchy           class bases hierarchy graphic

    dl.syntax               function- or variable-declaration field
    a.syntax                link in function- or variable-declaration field

    p.dt                    docu paragraph title
    dl.dt                   docu paragraph title

    p                       standard text
    dl                      standard text
    dd                      standard text
*/

#define CRLF "\n"

namespace
{

bool            bUse_OOoFrameDiv = true;

//***************   These are used for IDL currently only!   ********************

const char * const C_sStdStyle =
    "/*See bottom of file for explanations.*/"CRLF
    CRLF
    "body { background-color:#ffffff; }"CRLF
    CRLF
    "h3             { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "p, dt, dd, pre { font-size:11pt;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "pre            { font-family:monospace; }"CRLF
    CRLF
    "table.navimain { background-color:#eeeeff; }"CRLF
    "table.subtitle { margin-top:6pt; margin-bottom:6pt; }"CRLF
    CRLF
    "td             {                     font-size:11pt; }"CRLF
    "td.title       { font-family: Arial; font-size:19pt; font-weight:bold;"CRLF
    "                 line-height:30pt;   background-color:#ccccff; text-align:center; }"CRLF
    "td.subtitle    { font-family: Arial; font-size:13pt;"CRLF
    "                 line-height:20pt;   background-color:#ccccff; }"CRLF
    "td.crosstitle  {                     font-size:12pt; font-weight:bold;"CRLF
    "                 line-height:15pt;   background-color:#eeeeff; }"CRLF
    "td.imdetail    { width:100%;         background-color:#eeeeff; }"CRLF
    CRLF
    "td.imsum_left  { width:30%;  }"CRLF
    "td.imsum_right { width:70%;  }"CRLF
    CRLF
    "td.navimain, a.navimain"CRLF
    "                   { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold; }"CRLF
    "td.navimainself    { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold;"CRLF
    "                     color:#ffffff; background-color:#2222ad; }"CRLF
    "td.navimainnone    { text-align:center; font-family: Arial; font-size:12pt; }"CRLF
    "td.navisub, a.navisub"CRLF
    "                   { text-align:center; font-family: Arial; font-size:9pt; font-variant:small-caps; }"CRLF
    "td.navimain, td.navisub"CRLF
    "                   { padding-left:7pt; padding-right:7pt; }"CRLF
    CRLF
    "a.membertitle  { font-size:12pt; font-weight:bold; line-height:18pt; }"CRLF
    "a.navimain, a.navisub  { color:#000000; }"CRLF
    ".dt            { font-weight:bold; }"CRLF
    ".namechain     { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:6pt; }"CRLF
    ".title2        { font-size:13pt; font-style:italic; font-weight:bold; text-align:left; }"CRLF
    ;

const char * const C_sCssExplanations =
    "/* Explanation of CSS classes:"CRLF
    CRLF
    ".navimain          Text in main navigation bar."CRLF
    ".navisub           Text in lower navigation bar."CRLF
    "td.navimainself    Cell in main navigation bar with \"selected\" shadow: You are here."CRLF
    "td.navimainnone    Cell in main navigation bar with no link."CRLF
    CRLF
    ".namechain         Line with current module path."CRLF
    CRLF
    "td.crosstitle      Comment box for bases (base interfaces etc.)"CRLF
    "td.imsum_left      Left part of such boxes."CRLF
    "td.imsum_right     Right part of such boxes."CRLF
    CRLF
    "td.title           Main title of the page like \"interface XYz\""CRLF
    ".subtitle          Tables, and head cells of those, which list members"CRLF
    "                   like \"method summary\" and \"method details\"."CRLF
    CRLF
    "td.imdetail        Background table of method's detail description."CRLF
    "a.membertitle      Method name (as jump label) in method's detail"CRLF
    "                   description."CRLF
    ".title2            smaller font prefixes to page titles"CRLF
    "*/"CRLF
    ;

const char * const C_sStdStyle_withDivFrame =
    "/*See bottom of file for explanations.*/"CRLF
    CRLF
    "body { background-color:#ffffff; }"CRLF
    CRLF
    "#adc-idlref h3 { font-size:13pt; font-weight:bold;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "#adc-idlref p, #adc-idlref dt, #adc-idlref dd, #adc-idlref pre"CRLF
    "               { font-size:11pt;"CRLF
    "                 margin-top:3pt; margin-bottom:1pt; }"CRLF
    "#adc-idlref pre    { font-family:monospace; }"CRLF
    CRLF
    "#adc-idlref table.navimain { background-color:#eeeeff; }"CRLF
    "#adc-idlref table.subtitle { margin-top:6pt; margin-bottom:6pt; }"CRLF
    CRLF
    "#adc-idlref td             { font-size:11pt; }"CRLF
    "#adc-idlref td.title       { font-family: Arial; font-size:19pt; font-weight:bold;"CRLF
    "                             line-height:30pt;   background-color:#ccccff; text-align:center; }"CRLF
    "#adc-idlref td.subtitle    { font-family: Arial; font-size:13pt;"CRLF
    "                             line-height:20pt;   background-color:#ccccff; }"CRLF
    "#adc-idlref td.crosstitle  { font-size:12pt; font-weight:bold;"CRLF
    "                             line-height:15pt;   background-color:#eeeeff; }"CRLF
    "#adc-idlref td.imdetail    { width:100%;         background-color:#eeeeff; }"CRLF
    CRLF
    "#adc-idlref td.imsum_left  { width:30%;  }"CRLF
    "#adc-idlref td.imsum_right { width:70%;  }"CRLF
    CRLF
    "#adc-idlref td.navimain, #adc-idlref a.navimain"CRLF
    "                   { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold; }"CRLF
    "#adc-idlref td.navimainself    { text-align:center; font-family: Arial; font-size:12pt; font-weight:bold;"CRLF
    "                                 color:#ffffff; background-color:#2222ad; }"CRLF
    "#adc-idlref td.navimainnone    { text-align:center; font-family: Arial; font-size:12pt; }"CRLF
    "#adc-idlref td.navisub, #adc-idlref a.navisub"CRLF
    "                   { text-align:center; font-family: Arial; font-size:9pt; font-variant:small-caps; }"CRLF
    "#adc-idlref td.navimain, #adc-idlref td.navisub"CRLF
    "                   { padding-left:7pt; padding-right:7pt; }"CRLF
    CRLF
    "#adc-idlref a.membertitle  { font-size:12pt; font-weight:bold; line-height:18pt; }"CRLF
    "#adc-idlref a.navimain, #adc-idlref a.navisub  { color:#000000; }"CRLF
    "#adc-idlref .dt            { font-weight:bold; }"CRLF
    "#adc-idlref .namechain     { font-size:13pt; font-weight:bold;"CRLF
    "                             margin-top:3pt; margin-bottom:6pt; }"CRLF
    "#adc-idlref .title2        { font-size:13pt; font-style:italic; font-weight:bold; text-align:left; }"CRLF
    ""CRLF
    "#adc-idlref table { empty-cells:show; }"CRLF
    ""CRLF
    "#adc-idlref .childlist td, "CRLF
    "#adc-idlref .commentedlinks td, "CRLF
    "#adc-idlref .memberlist td, "CRLF
    "#adc-idlref .subtitle td, "CRLF
    "#adc-idlref .crosstitle td  { border: .1pt solid #000000; }"CRLF
    ""CRLF
    "#adc-idlref .flag-table td { border: .1pt solid #cccccc; } "CRLF
    ""CRLF
    "#adc-idlref .title-table td, "CRLF
    "#adc-idlref .table-in-method td, "CRLF
    "#adc-idlref .table-in-data td, "CRLF
    "#adc-idlref .navimain td, "CRLF
    "#adc-idlref .navisub td, "CRLF
    "#adc-idlref .expl-table td, "CRLF
    "#adc-idlref .param-table td  { border: none; }"CRLF
    ;

}   // anonymous namespace

StdFrame::StdFrame()
    :   sDevelopersGuideHtmlRoot(),
        bSimpleLinks(false)
{
}

DYN Html_Image *
StdFrame::LogoSrc() const
{
    return 0;

//    return  new Html_Image( "logodot-blu.gif",
//                            "109",
//                            "54",
//                            "RIGHT",
//                            "0",
//                            "OpenOffice" );

}

const char *
StdFrame::LogoLink() const
{
    return "";
//  return "http://www.sun.com";
//  return "http://www.openoffice.org";
}

String              MakeCopyRight();

const char *
StdFrame::CopyrightText() const
{
    static String sCopyRight_( MakeCopyRight() );
    return sCopyRight_.c_str();
}

const char *
StdFrame::CssStyle() const
{
    if (bUse_OOoFrameDiv)
        return C_sStdStyle_withDivFrame;
    else
        return C_sStdStyle;
}

const char *
StdFrame::CssStylesExplanation() const
{
    return C_sCssExplanations;
}

const char *
StdFrame::DevelopersGuideHtmlRoot() const
{
    return sDevelopersGuideHtmlRoot;
}

bool
StdFrame::SimpleLinks() const
{
    return bSimpleLinks;
}

void
StdFrame::Set_DevelopersGuideHtmlRoot( const String & i_directory )
{
    if (NOT i_directory.empty())
    {
        if (i_directory.char_at(i_directory.length()-1) == '/')
        {
            sDevelopersGuideHtmlRoot.assign(i_directory,i_directory.length()-1);
            return;
        }
    }
    sDevelopersGuideHtmlRoot = i_directory;
}

void
StdFrame::Set_SimpleLinks()
{
    bSimpleLinks = true;
}

String
MakeCopyRight()
{
    StreamStr cr(700);
    time_t
        gt;
    time(&gt);
    tm *
        plt = localtime(&gt);
    int year = 1900 + plt->tm_year;

    cr  << "LibreOffice is copyright © 2000, "
	<< year
	<< ", LibreOffice contributors and/or their affiliates. All rights reserved.
"
	<< "
LibreOffice is derived from OpenOffice.org. OpenOffice.org is copyright © 2000, 2011 Oracle and/or its affiliates. All rights reserved.
"
	<< "
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.";
    return String(cr.c_str());

}

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


<commit_before><commit_msg>Gui: fix ExpLineEdit::apply()<commit_after><|endoftext|>


<commit_before>
#include "ImageSource.h"

#include "tis_logging.h"

using namespace tis_imaging;

ImageSource::ImageSource ()
    : current_status(PIPELINE_UNDEFINED), n_buffers(10)
{}

ImageSource::~ImageSource ()
{
    device->release_buffers();
}

bool ImageSource::setStatus (const PIPELINE_STATUS& status)
{
    current_status = status;

    if (current_status == PIPELINE_PLAYING)
    {

        device->initialize_buffers(buffers);
        device->setSink(shared_from_this());

        //tis_log(TIS_LOG_ERROR, "Source changed to state PLAYING");
        if ( device->start_stream())
        {
            tis_log(TIS_LOG_DEBUG, "PLAYING....");
        }
        else
        {
            tis_log(TIS_LOG_ERROR, "Unable to start stream from device.");
            return false;
        }

    }
    else if (current_status == PIPELINE_STOPPED)
    {
        tis_log(TIS_LOG_ERROR, "Source changed to state STOPPED");
        device->stop_stream();
    }

    return true;
}

PIPELINE_STATUS ImageSource::getStatus () const
{
    return current_status;
}

bool ImageSource::setDevice (std::shared_ptr<DeviceInterface> dev)
{
    //tis_log(TIS_LOG_DEBUG, "Received device to use as source.");

    if (current_status == PIPELINE_PAUSED || current_status == PIPELINE_PLAYING)
    {
        return false;
    }

    device = dev;
    this->initialize_buffers();

    //tis_log(TIS_LOG_INFO, "Giving %d buffers to initialize in device", buffers.size());

    if (buffers.empty())
    {
        tis_log(TIS_LOG_ERROR, "Have no Buffers to work with");
        return false;
    }

    return true;
}

bool ImageSource::setVideoFormat (const VideoFormat&)
{

}

VideoFormat ImageSource::getVideoFormat () const
{
    return device->getActiveVideoFormat();
}

void ImageSource::pushImage (std::shared_ptr<MemoryBuffer> buffer)
{

    // tis_log(TIS_LOG_INFO, "received buffer");

    pipeline.lock()->pushImage(buffer);
}

void ImageSource::initialize_buffers ()
{
    // TODO:
    struct video_format format = {};

    format.fourcc = V4L2_PIX_FMT_GREY;
    format.width = 1920;
    format.height = 1080;
    format.binning = 0;
    format.framerate = 0.1;

    int bit_depth = img::getBitsPerPixel(format.fourcc);

    for (unsigned int i = 0; i < this->n_buffers; ++i)
    {
        struct image_buffer b = {};

        b.pData = NULL;
        b.length = format.width * format.height * bit_depth;
        b.format = format;
        b.pitch = format.width * bit_depth;

        auto ptr = std::make_shared<MemoryBuffer>(MemoryBuffer(b));

        this->buffers.push_back(ptr);
    }
}

bool ImageSource::setSink (std::shared_ptr<SinkInterface> sink)
{
    this->pipeline = sink;

    return true;
}
<commit_msg>Prevented crash on pipeline loss<commit_after>
#include "ImageSource.h"

#include "tis_logging.h"

using namespace tis_imaging;

ImageSource::ImageSource ()
    : current_status(PIPELINE_UNDEFINED), n_buffers(10)
{}

ImageSource::~ImageSource ()
{
    device->release_buffers();
}

bool ImageSource::setStatus (const PIPELINE_STATUS& status)
{
    current_status = status;

    if (current_status == PIPELINE_PLAYING)
    {

        device->initialize_buffers(buffers);
        device->setSink(shared_from_this());

        //tis_log(TIS_LOG_ERROR, "Source changed to state PLAYING");
        if ( device->start_stream())
        {
            tis_log(TIS_LOG_DEBUG, "PLAYING....");
        }
        else
        {
            tis_log(TIS_LOG_ERROR, "Unable to start stream from device.");
            return false;
        }

    }
    else if (current_status == PIPELINE_STOPPED)
    {
        tis_log(TIS_LOG_ERROR, "Source changed to state STOPPED");
        device->stop_stream();
    }

    return true;
}

PIPELINE_STATUS ImageSource::getStatus () const
{
    return current_status;
}

bool ImageSource::setDevice (std::shared_ptr<DeviceInterface> dev)
{
    //tis_log(TIS_LOG_DEBUG, "Received device to use as source.");

    if (current_status == PIPELINE_PAUSED || current_status == PIPELINE_PLAYING)
    {
        return false;
    }

    device = dev;
    this->initialize_buffers();

    //tis_log(TIS_LOG_INFO, "Giving %d buffers to initialize in device", buffers.size());

    if (buffers.empty())
    {
        tis_log(TIS_LOG_ERROR, "Have no Buffers to work with");
        return false;
    }

    return true;
}

bool ImageSource::setVideoFormat (const VideoFormat&)
{

}

VideoFormat ImageSource::getVideoFormat () const
{
    return device->getActiveVideoFormat();
}

void ImageSource::pushImage (std::shared_ptr<MemoryBuffer> buffer)
{

    // tis_log(TIS_LOG_INFO, "received buffer");

    if (!pipeline.expired())
        pipeline.lock()->pushImage(buffer);
    else
        tis_log(TIS_LOG_ERROR, "Pipeline over expiration date.");
}

void ImageSource::initialize_buffers ()
{
    // TODO:
    struct video_format format = {};

    format.fourcc = V4L2_PIX_FMT_GREY;
    format.width = 1920;
    format.height = 1080;
    format.binning = 0;
    format.framerate = 0.1;

    int bit_depth = img::getBitsPerPixel(format.fourcc);

    for (unsigned int i = 0; i < this->n_buffers; ++i)
    {
        struct image_buffer b = {};

        b.pData = NULL;
        b.length = format.width * format.height * bit_depth;
        b.format = format;
        b.pitch = format.width * bit_depth;

        auto ptr = std::make_shared<MemoryBuffer>(MemoryBuffer(b));

        this->buffers.push_back(ptr);
    }
}

bool ImageSource::setSink (std::shared_ptr<SinkInterface> sink)
{
    this->pipeline = sink;

    return true;
}
<|endoftext|>


<commit_before>#include "main.h"
#include "Plugin.h"
#include "dlfcn.h"
#include "header.h"

typedef void (*init_imagestack_plugin)(map<string, Operation *> &);

void Plugin::parse(vector<string> args) {
    void *handle = dlopen(args[0].c_str(), RTLD_LAZY);
    assert(handle, "Could not open %s as a shared library\n", args[0].c_str());

    void *function = dlsym(handle, "init_imagestack_plugin");
    assert(function, "Could not find symbol init_imagestack_plugin (with C linkage) in %s\n", args[0].c_str());

    // Pass control to the shared library to inject crap into the operation map
    ((init_imagestack_plugin)function)(operationMap);
}

void Plugin::help() {
    pprintf("-plugin loads a shared object that can add new operations to"
            " ImageStack. It does this by calling the function"
            " init_imagestack_plugin, which should exist in the shared object with"
            " C linkage. To this function it passes the ImageStack operation map,"
            " into which the plugin may inject new operations.\n\n"
            "Usage: ImageStack -plugin foo.so -foo 1 2 3\n");
}

#include "footer.h"
<commit_msg>More helpful error message on plugin load failure<commit_after>#include "main.h"
#include "Plugin.h"
#include "dlfcn.h"
#include "header.h"

typedef void (*init_imagestack_plugin)(map<string, Operation *> &);

void Plugin::parse(vector<string> args) {
    void *handle = dlopen(args[0].c_str(), RTLD_LAZY);
    assert(handle, "Could not open %s as a shared library: %s\n", args[0].c_str(), dlerror());

    void *function = dlsym(handle, "init_imagestack_plugin");
    assert(function, "Could not find symbol init_imagestack_plugin (with C linkage) in %s\n", args[0].c_str());

    // Pass control to the shared library to inject crap into the operation map
    ((init_imagestack_plugin)function)(operationMap);
}

void Plugin::help() {
    pprintf("-plugin loads a shared object that can add new operations to"
            " ImageStack. It does this by calling the function"
            " init_imagestack_plugin, which should exist in the shared object with"
            " C linkage. To this function it passes the ImageStack operation map,"
            " into which the plugin may inject new operations.\n\n"
            "Usage: ImageStack -plugin foo.so -foo 1 2 3\n");
}

#include "footer.h"
<|endoftext|>


<commit_before>/**
 * @author See Contributors.txt for code contributors and overview of BadgerDB.
 *
 * @section LICENSE
 * Copyright (c) 2012 Database Group, Computer Sciences Department, University of Wisconsin-Madison.
 */

#include <memory>
#include <iostream>
#include "buffer.h"
#include "exceptions/buffer_exceeded_exception.h"
#include "exceptions/page_not_pinned_exception.h"
#include "exceptions/page_pinned_exception.h"
#include "exceptions/bad_buffer_exception.h"
#include "exceptions/hash_not_found_exception.h"

namespace badgerdb {

BufMgr::BufMgr(std::uint32_t bufs)
	: numBufs(bufs) {
	bufDescTable = new BufDesc[bufs];

  for (FrameId i = 0; i < bufs; i++)
  {
  	bufDescTable[i].frameNo = i;
  	bufDescTable[i].valid = false;
  }

  bufPool = new Page[bufs];

	int htsize = ((((int) (bufs * 1.2))*2)/2)+1;
  hashTable = new BufHashTbl (htsize);  // allocate the buffer hash table

  clockHand = bufs - 1;
}

	/**
   	 * Destructor of BufMgr class
	 */
BufMgr::~BufMgr() {
	// Flushes out all dirty pages
	for (FrameId i=0; i<numBufs; i++)
		if(bufDescTable[i].valid == true && bufDescTable[i].dirty == true)
			flushFile(bufDescTable[i].file);

	// Deallocates the buffer pool and the BufDesc table.
	delete[] bufDescTable;
	delete[] bufPool;
	delete hashTable;
}

	/**
   * Advance clock to next frame in the buffer pool
	 */
void BufMgr::advanceClock()
{
	clockHand = (clockHand+1) % numBufs;
}

	/**
	 * Allocate a free frame.
	 *
	 * @param frame   	Frame reference, frame ID of allocated frame returned via this variable
	 * @throws BufferExceededException If no such buffer is found which can be allocated
	 */
void BufMgr::allocBuf(FrameId & frame)
{
	// Remember the start point and pass.
	// All frame is pinned if two passed be made.
	FrameId flag = clockHand;
	int pass = 0;
	while(pass < 2) {
		advanceClock();
		if (clockHand == flag) pass++;
		// If this frame is unused, return this page.
		if (bufDescTable[clockHand].valid == false) {
			frame = clockHand;
			return;
		}
		// If this page is recently used, clear the ref bit, continue.
		if (bufDescTable[clockHand].refbit == true) {
			bufDescTable[clockHand].refbit = false;
			flag = clockHand;
			continue;
		}
		// If this page is pinned, continue to next.
		if (bufDescTable[clockHand].pinCnt > 0) {
			continue;
		}
		// This frame is selected, clean this frame.
		if (bufDescTable[clockHand].dirty == true) {
			bufDescTable[clockHand].file->writePage(bufPool[clockHand]);
		}
		// Remove the appropriate entry from the hash table.
		hashTable->remove(bufDescTable[clockHand].file,bufDescTable[clockHand].pageNo);
		bufDescTable[clockHand].Clear();
		frame = clockHand;
		return;
	}
	// If the buffer is full.
	throw BufferExceededException();
}

	/**
	 * Reads the given page from the file into a frame and returns the pointer to page.
	 * If the requested page is already present in the buffer pool pointer to that frame is returned
	 * otherwise a new frame is allocated from the buffer pool for reading the page.
	 *
	 * @param file   	File object
	 * @param PageNo  Page number in the file to be read
	 * @param page  	Reference to page pointer. Used to fetch the Page object in which requested page from file is read in.
	 */
void BufMgr::readPage(File* file, const PageId pageNo, Page*& page)
{
	FrameId tmpFrameId;
	try{
		// Page is in the buffer pool.
		hashTable->lookup(file, pageNo, tmpFrameId);
		bufDescTable[tmpFrameId].pinCnt ++;
	}catch (HashNotFoundException e){
		// Page is not in the buffer pool.
		// Allocate a buffer frame. Read the page from disk.
		// Insert the page into the hashtable. Set the frame.
		allocBuf(tmpFrameId);
		bufPool[tmpFrameId] = file->readPage(pageNo);
		hashTable->insert(file, pageNo, tmpFrameId);
		bufDescTable[tmpFrameId].Set(file, pageNo);
	}
	bufDescTable[tmpFrameId].refbit = true;
	// Return a pointer to the frame containing the page.
	page = &bufPool[tmpFrameId];
}

	/**
	 * Unpin a page from memory since it is no longer required for it to remain in memory.
	 *
	 * @param file   	File object
	 * @param PageNo  Page number
	 * @param dirty		True if the page to be unpinned needs to be marked dirty
   * @throws  PageNotPinnedException If the page is not already pinned
	 */
void BufMgr::unPinPage(File* file, const PageId pageNo, const bool dirty)
{
	FrameId tmpFrameId;

	try{
		hashTable->lookup(file, pageNo, tmpFrameId);
	}catch (HashNotFoundException e){
		// Does nothing if page is not found in the hash table lookup.
		return;
	}

	// Throws PAGENOTPINNED if the pin count is already 0.
	if(bufDescTable[tmpFrameId].pinCnt == 0)
		throw PageNotPinnedException(file->filename(), pageNo, tmpFrameId);
	bufDescTable[tmpFrameId].pinCnt--;
	if(dirty) bufDescTable[tmpFrameId].dirty = true;	//if dirty == true, sets the dirty bit.
}

	/**
	 * Writes out all dirty pages of the file to disk.
	 * All the frames assigned to the file need to be unpinned from buffer pool before this function can be successfully called.
	 * Otherwise Error returned.
	 *
	 * @param file   	File object
   * @throws  PagePinnedException If any page of the file is pinned in the buffer pool
   * @throws BadBufferException If any frame allocated to the file is found to be invalid
	 */
void BufMgr::flushFile(const File* file)
{
	//Throws PagePinnedException if some page of the file is pinned.
	//Throws BadBufferException if an invalid page belonging to the file is encountered.
	for (FrameId i=0;i<numBufs;i++)
		if(bufDescTable[i].file == file) {
			if (bufDescTable[i].valid == false)
				throw BadBufferException(i, bufDescTable[i].dirty, bufDescTable[i].valid, bufDescTable[i].refbit);
			if (bufDescTable[i].pinCnt > 0)
				throw PagePinnedException(file->filename(), bufDescTable[i].pageNo, i);
		}

	// Scan bufTable for pages belonging to the file.
	// If the page is dirty, call file->writePage() to flush the page to disk
	// and then set the dirty bit for the page to false.
	// Remove the page from the hashtable (whether the page is clean or dirty.
	// Invoke the Clear() method of BufDesc for the page frame.
	for (FrameId i=0; i<numBufs; i++)
		if(bufDescTable[i].file == file){
			if(bufDescTable[i].dirty == true){
				bufDescTable[i].file->writePage(bufPool[i]);
				bufDescTable[i].dirty = false;
			}
			hashTable->remove(file,bufDescTable[i].pageNo);
			bufDescTable[i].Clear();
		}
}

	/**
	 * Allocates a new, empty page in the file and returns the Page object.
	 * The newly allocated page is also assigned a frame in the buffer pool.
	 *
	 * @param file   	File object
	 * @param PageNo  Page number. The number assigned to the page in the file is returned via this reference.
	 * @param page  	Reference to page pointer. The newly allocated in-memory Page object is returned via this reference.
	 */
void BufMgr::allocPage(File* file, PageId &pageNo, Page*& page)
{
	FrameId tmpFrameId;
	// Allocate an empty page in the specified file and obtain a buffer pool.
	PageId NewPage = file->allocatePage().page_number();
	allocBuf(tmpFrameId);

	// Set the hash table and frame.
	bufPool[tmpFrameId] = file->readPage(NewPage);
	hashTable->insert(file, NewPage, tmpFrameId);
	bufDescTable[tmpFrameId].Set(file, NewPage);

	pageNo = NewPage;
	page = &bufPool[tmpFrameId];
}

	/**
	 * Delete page from file and also from buffer pool if present.
	 * Since the page is entirely deleted from file, its unnecessary to see if the page is dirty.
	 *
	 * @param file   	File object
	 * @param PageNo  Page number
	 */
void BufMgr::disposePage(File* file, const PageId PageNo)
{
	FrameId tmpFrameId;
	try{
		// Makes sure that if the page to be deleted is allocated a frame in the buffer pool, that frame
		// is freed and correspondingly entry from hash table is also removed.
		hashTable->lookup(file, PageNo, tmpFrameId);
		bufDescTable[tmpFrameId].Clear();
		hashTable->remove(file,PageNo);
	}catch (HashNotFoundException e){
		// Page not in buffer pool, just delete.
	}

	file->deletePage(PageNo);

}

void BufMgr::printSelf(void)
{
  BufDesc* tmpbuf;
	int validFrames = 0;

  for (std::uint32_t i = 0; i < numBufs; i++)
	{
  	tmpbuf = &(bufDescTable[i]);
		std::cout << "FrameNo:" << i << " ";
		tmpbuf->Print();

  	if (tmpbuf->valid == true)
    	validFrames++;
  }

	std::cout << "Total Number of Valid Frames:" << validFrames << "\n";
}

}
<commit_msg>11/14 final<commit_after>/**
 * @author See Contributors.txt for code contributors and overview of BadgerDB.
 *
 * @section LICENSE
 * Copyright (c) 2012 Database Group, Computer Sciences Department, University of Wisconsin-Madison.
 */

#include <memory>
#include <iostream>
#include "buffer.h"
#include "exceptions/buffer_exceeded_exception.h"
#include "exceptions/page_not_pinned_exception.h"
#include "exceptions/page_pinned_exception.h"
#include "exceptions/bad_buffer_exception.h"
#include "exceptions/hash_not_found_exception.h"

namespace badgerdb {

BufMgr::BufMgr(std::uint32_t bufs)
	: numBufs(bufs) {
	bufDescTable = new BufDesc[bufs];

  for (FrameId i = 0; i < bufs; i++)
  {
  	bufDescTable[i].frameNo = i;
  	bufDescTable[i].valid = false;
  }

  bufPool = new Page[bufs];

	int htsize = ((((int) (bufs * 1.2))*2)/2)+1;
  hashTable = new BufHashTbl (htsize);  // allocate the buffer hash table

  clockHand = bufs - 1;
}

	/**
   	 * Destructor of BufMgr class
	 */
BufMgr::~BufMgr() {
	// Flushes out all dirty pages
	for (FrameId i=0; i<numBufs; i++)
		if(bufDescTable[i].valid == true && bufDescTable[i].dirty == true)
			flushFile(bufDescTable[i].file);

	// Deallocates the buffer pool and the BufDesc table.
	delete[] bufDescTable;
	delete[] bufPool;
	delete hashTable;
}

	/**
   * Advance clock to next frame in the buffer pool
	 */
void BufMgr::advanceClock()
{
	clockHand = (clockHand+1) % numBufs;
}

	/**
	 * Allocate a free frame.
	 *
	 * @param frame   	Frame reference, frame ID of allocated frame returned via this variable
	 * @throws BufferExceededException If no such buffer is found which can be allocated
	 */
void BufMgr::allocBuf(FrameId & frame)
{
	// Remember the start point and pass.
	// All frame is pinned if two passed be made.
	FrameId flag = clockHand;
	int pass = 0;
	while(pass < 2) {
		advanceClock();
		if (clockHand == flag) pass++;
		// If this frame is unused, return this page.
		if (bufDescTable[clockHand].valid == false) {
			frame = clockHand;
			return;
		}
		// If this page is recently used, clear the ref bit, continue.
		if (bufDescTable[clockHand].refbit == true) {
			bufDescTable[clockHand].refbit = false;
			continue;
		}
		// If this page is pinned, continue to next.
		if (bufDescTable[clockHand].pinCnt > 0) {
			continue;
		}
		// This frame is selected, clean this frame.
		if (bufDescTable[clockHand].dirty == true) {
			bufDescTable[clockHand].file->writePage(bufPool[clockHand]);
		}
		// Remove the appropriate entry from the hash table.
		hashTable->remove(bufDescTable[clockHand].file,bufDescTable[clockHand].pageNo);
		bufDescTable[clockHand].Clear();
		frame = clockHand;
		return;
	}
	// If the buffer is full.
	throw BufferExceededException();
}

	/**
	 * Reads the given page from the file into a frame and returns the pointer to page.
	 * If the requested page is already present in the buffer pool pointer to that frame is returned
	 * otherwise a new frame is allocated from the buffer pool for reading the page.
	 *
	 * @param file   	File object
	 * @param PageNo  Page number in the file to be read
	 * @param page  	Reference to page pointer. Used to fetch the Page object in which requested page from file is read in.
	 */
void BufMgr::readPage(File* file, const PageId pageNo, Page*& page)
{
	FrameId tmpFrameId;
	try{
		// Page is in the buffer pool.
		hashTable->lookup(file, pageNo, tmpFrameId);
		bufDescTable[tmpFrameId].pinCnt ++;
	}catch (HashNotFoundException e){
		// Page is not in the buffer pool.
		// Allocate a buffer frame. Read the page from disk.
		// Insert the page into the hashtable. Set the frame.
		allocBuf(tmpFrameId);
		bufPool[tmpFrameId] = file->readPage(pageNo);
		hashTable->insert(file, pageNo, tmpFrameId);
		bufDescTable[tmpFrameId].Set(file, pageNo);
	}
	bufDescTable[tmpFrameId].refbit = true;
	// Return a pointer to the frame containing the page.
	page = &bufPool[tmpFrameId];
}

	/**
	 * Unpin a page from memory since it is no longer required for it to remain in memory.
	 *
	 * @param file   	File object
	 * @param PageNo  Page number
	 * @param dirty		True if the page to be unpinned needs to be marked dirty
   * @throws  PageNotPinnedException If the page is not already pinned
	 */
void BufMgr::unPinPage(File* file, const PageId pageNo, const bool dirty)
{
	FrameId tmpFrameId;

	try{
		hashTable->lookup(file, pageNo, tmpFrameId);
	}catch (HashNotFoundException e){
		// Does nothing if page is not found in the hash table lookup.
		return;
	}

	// Throws PAGENOTPINNED if the pin count is already 0.
	if(bufDescTable[tmpFrameId].pinCnt == 0)
		throw PageNotPinnedException(file->filename(), pageNo, tmpFrameId);
	bufDescTable[tmpFrameId].pinCnt--;
	if(dirty) bufDescTable[tmpFrameId].dirty = true;	//if dirty == true, sets the dirty bit.
}

	/**
	 * Writes out all dirty pages of the file to disk.
	 * All the frames assigned to the file need to be unpinned from buffer pool before this function can be successfully called.
	 * Otherwise Error returned.
	 *
	 * @param file   	File object
   * @throws  PagePinnedException If any page of the file is pinned in the buffer pool
   * @throws BadBufferException If any frame allocated to the file is found to be invalid
	 */
void BufMgr::flushFile(const File* file)
{
	//Throws PagePinnedException if some page of the file is pinned.
	//Throws BadBufferException if an invalid page belonging to the file is encountered.
	for (FrameId i=0;i<numBufs;i++)
		if(bufDescTable[i].file == file) {
			if (bufDescTable[i].valid == false)
				throw BadBufferException(i, bufDescTable[i].dirty, bufDescTable[i].valid, bufDescTable[i].refbit);
			if (bufDescTable[i].pinCnt > 0)
				throw PagePinnedException(file->filename(), bufDescTable[i].pageNo, i);
		}

	// Scan bufTable for pages belonging to the file.
	// If the page is dirty, call file->writePage() to flush the page to disk
	// and then set the dirty bit for the page to false.
	// Remove the page from the hashtable (whether the page is clean or dirty.
	// Invoke the Clear() method of BufDesc for the page frame.
	for (FrameId i=0; i<numBufs; i++)
		if(bufDescTable[i].file == file){
			if(bufDescTable[i].dirty == true){
				bufDescTable[i].file->writePage(bufPool[i]);
				bufDescTable[i].dirty = false;
			}
			hashTable->remove(file,bufDescTable[i].pageNo);
			bufDescTable[i].Clear();
		}
}

	/**
	 * Allocates a new, empty page in the file and returns the Page object.
	 * The newly allocated page is also assigned a frame in the buffer pool.
	 *
	 * @param file   	File object
	 * @param PageNo  Page number. The number assigned to the page in the file is returned via this reference.
	 * @param page  	Reference to page pointer. The newly allocated in-memory Page object is returned via this reference.
	 */
void BufMgr::allocPage(File* file, PageId &pageNo, Page*& page)
{
	FrameId tmpFrameId;
	// Allocate an empty page in the specified file and obtain a buffer pool.
	PageId NewPage = file->allocatePage().page_number();
	allocBuf(tmpFrameId);

	// Set the hash table and frame.
	bufPool[tmpFrameId] = file->readPage(NewPage);
	hashTable->insert(file, NewPage, tmpFrameId);
	bufDescTable[tmpFrameId].Set(file, NewPage);

	pageNo = NewPage;
	page = &bufPool[tmpFrameId];
}

	/**
	 * Delete page from file and also from buffer pool if present.
	 * Since the page is entirely deleted from file, its unnecessary to see if the page is dirty.
	 *
	 * @param file   	File object
	 * @param PageNo  Page number
	 */
void BufMgr::disposePage(File* file, const PageId PageNo)
{
	FrameId tmpFrameId;
	try{
		// Makes sure that if the page to be deleted is allocated a frame in the buffer pool, that frame
		// is freed and correspondingly entry from hash table is also removed.
		hashTable->lookup(file, PageNo, tmpFrameId);
		bufDescTable[tmpFrameId].Clear();
		hashTable->remove(file,PageNo);
	}catch (HashNotFoundException e){
		// Page not in buffer pool, just delete.
	}

	file->deletePage(PageNo);

}

void BufMgr::printSelf(void)
{
  BufDesc* tmpbuf;
	int validFrames = 0;

  for (std::uint32_t i = 0; i < numBufs; i++)
	{
  	tmpbuf = &(bufDescTable[i]);
		std::cout << "FrameNo:" << i << " ";
		tmpbuf->Print();

  	if (tmpbuf->valid == true)
    	validFrames++;
  }

	std::cout << "Total Number of Valid Frames:" << validFrames << "\n";
}

}
<|endoftext|>