<commit_before>#include <sal/logger/file_sink.hpp>
#include <sal/logger/async_worker.hpp>
#include <sal/logger/worker.hpp>
#include <sal/logger/logger.hpp>
#include <sal/logger/common.test.hpp>
#include <sal/error.hpp>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <vector>

namespace {

#if __sal_os_windows

  #include <direct.h>
  #include <io.h>

  #define rmdir _rmdir

  const std::string permission_denied_dir = "C:/Windows";

  auto directory_listing (const std::string &path)
  {
    auto filespec = path + "/*";
    std::vector<std::string> result;

    struct ::_finddata_t file_info;
    auto h = ::_findfirst(filespec.c_str(), &file_info);
    if (h == -1)
    {
      return result;
    }

    do
    {
      auto name = std::string(file_info.name);
      if (name != "." && name != "..")
      {
        result.push_back(path + '\\' + name);
      }
    } while (::_findnext(h, &file_info) == 0);

    ::_findclose(h);

    return result;
  }

#else

  #include <dirent.h>
  #include <unistd.h>

  const std::string permission_denied_dir = "/";

  auto directory_listing (const std::string &path)
  {
    std::vector<std::string> result;
    if (auto dir = ::opendir(path.c_str()))
    {
      while (auto it = ::readdir(dir))
      {
        auto name = std::string(it->d_name);
        if (name != "." && name != "..")
        {
          result.push_back(path + '/' + name);
        }
      }
      ::closedir(dir);
    }
    return result;
  }

#endif

std::string read_file (const std::string &name)
{
  std::ifstream file(name);
  if (file.fail())
  {
    sal::throw_system_error(
      std::error_code(errno, std::system_category()),
      "read_file: ", name
    );
  }

  std::string line, content;
  while (std::getline(file, line))
  {
    content += line;
    content += '\n';
  }

  return content;
}

inline bool file_contains (const std::string &needle, const std::string &file)
{
  return read_file(file).find(needle) != std::string::npos;
}

template <typename Worker>
struct file_sink
  : public sal_test::with_type<Worker>
{
  const std::string test_logs = "test_logs";
  std::unique_ptr<Worker> worker_ = std::make_unique<Worker>();

  template <typename... Options>
  auto make_channel (Options &&...options)
  {
    auto sink = sal::logger::file("test",
      sal::logger::set_file_dir(test_logs),
      std::forward<Options>(options)...
    );
    auto channel_name = this->case_name;
    std::reverse(channel_name.begin(), channel_name.end());
    return worker_->make_channel(channel_name,
      sal::logger::set_channel_sink(sink)
    );
  }

  void stop_and_close_logs ()
  {
    worker_.reset();
  }

  auto log_files ()
  {
    return directory_listing(test_logs);
  }

  void SetUp () override
  {
    // remove test_logs before starting testing
    for (auto &file: directory_listing(test_logs))
    {
      std::remove(file.c_str());
    }
    ::rmdir(test_logs.c_str());
  }

  void TearDown () override
  {
    stop_and_close_logs();
    SetUp();
  }

};

TYPED_TEST_CASE_P(file_sink);

TYPED_TEST_P(file_sink, log)
{
  auto channel = this->make_channel();
  sal_log(channel) << this->case_name;
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  EXPECT_TRUE(file_contains(this->case_name, log_files[0]));
}

TYPED_TEST_P(file_sink, log_buffered)
{
  auto channel = this->make_channel(sal::logger::set_file_buffer_size_kb(1));
  sal_log(channel) << this->case_name;
  for (auto i = 0;  i != 10;  ++i)
  {
    // log 10 long messages to make sure we hit full buffer conditio
    sal_log(channel) << std::string(sal::logger::event_t::max_message_size/2, 'x');
  }
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  EXPECT_TRUE(file_contains(this->case_name, log_files[0]));
}

TYPED_TEST_P(file_sink, log_overflow)
{
  auto channel = this->make_channel();
  std::string overflowed_message(sal::logger::event_t::max_message_size, 'x');
  sal_log(channel) << this->case_name << ' ' << overflowed_message;
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  auto log_content = read_file(log_files[0]);

  EXPECT_NE(log_content.npos, log_content.find(this->case_name));
  EXPECT_EQ(log_content.npos, log_content.find(overflowed_message));
  EXPECT_NE(log_content.npos, log_content.find("<...>"));
}

TYPED_TEST_P(file_sink, local_time)
{
  auto channel = this->make_channel(sal::logger::set_file_utc_time(false));
  sal_log(channel) << this->case_name;
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  auto log_content = read_file(log_files[0]);

  // check for logged message
  EXPECT_NE(log_content.npos, log_content.find(this->case_name));

  //
  // check for timestamp (at beginning of line i.e. prepend '\n')
  //

  auto now = sal::now();
  auto tm = sal::local_time(now);
  char buf[64];

  // in current second
  snprintf(buf, sizeof(buf), "\n%02u:%02u:%02u",
    tm.tm_hour, tm.tm_min, tm.tm_sec
  );
  bool found = log_content.npos != log_content.find(std::string(buf));

  // if not found, then in previous second as well
  if (!found)
  {
    using namespace std::chrono_literals;
    tm = sal::local_time(now - 1s);
    snprintf(buf, sizeof(buf), "\n%02u:%02u:%02u",
      tm.tm_hour, tm.tm_min, tm.tm_sec
    );
    found = log_content.npos != log_content.find(std::string(buf));
  }

  EXPECT_TRUE(found);
}

TYPED_TEST_P(file_sink, utc_time)
{
  auto channel = this->make_channel(sal::logger::set_file_utc_time(true));
  sal_log(channel) << this->case_name;
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  auto log_content = read_file(log_files[0]);

  // check for logged message
  EXPECT_NE(log_content.npos, log_content.find(this->case_name));

  //
  // check for timestamp
  //

  auto now = sal::now();
  auto tm = sal::utc_time(now);
  char buf[64];

  // in current second
  snprintf(buf, sizeof(buf), "\n%02u:%02u:%02u",
    tm.tm_hour, tm.tm_min, tm.tm_sec
  );
  bool found = log_content.npos != log_content.find(std::string(buf));

  // if not found, then in previous second as well
  if (!found)
  {
    using namespace std::chrono_literals;
    tm = sal::utc_time(now - 1s);
    snprintf(buf, sizeof(buf), "\n%02u:%02u:%02u",
      tm.tm_hour, tm.tm_min, tm.tm_sec
    );
    found = log_content.npos != log_content.find(std::string(buf));
  }

  EXPECT_TRUE(found);
}

TYPED_TEST_P(file_sink, max_size)
{
  // here we use internal knowledge how to configure max log file size
  // (don't want to use public API with 1MB precision)

  auto channel = this->make_channel(
    sal::logger::__bits::file_max_size(1024)
  );
  for (auto i = 0;  i < 100;  ++i)
  {
    sal_log(channel) << this->case_name << '_' << (i + 1);
  }
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_LT(1U, log_files.size());
  EXPECT_TRUE(file_contains(this->case_name + "_1\n", log_files[0]));
  EXPECT_TRUE(file_contains(this->case_name + "_100\n", log_files.back()));
}

TYPED_TEST_P(file_sink, unprivileged_dir)
{
  EXPECT_THROW(
    this->make_channel(sal::logger::set_file_dir(permission_denied_dir)),
    std::system_error
  );
}

REGISTER_TYPED_TEST_CASE_P(file_sink,
  log,
  log_buffered,
  log_overflow,
  local_time,
  utc_time,
  max_size,
  unprivileged_dir
);

using worker_types = testing::Types<
  sal::logger::worker_t,
  sal::logger::async_worker_t
>;

INSTANTIATE_TYPED_TEST_CASE_P(logger, file_sink, worker_types);

} // namespace
<commit_msg>logger/test: order dir listing alphabetically for checking<commit_after>#include <sal/logger/file_sink.hpp>
#include <sal/logger/async_worker.hpp>
#include <sal/logger/worker.hpp>
#include <sal/logger/logger.hpp>
#include <sal/logger/common.test.hpp>
#include <sal/error.hpp>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <vector>

namespace {

#if __sal_os_windows

  #include <direct.h>
  #include <io.h>

  #define rmdir _rmdir

  const std::string permission_denied_dir = "C:/Windows";

  auto directory_listing (const std::string &path)
  {
    auto filespec = path + "/*";
    std::vector<std::string> result;

    struct ::_finddata_t file_info;
    auto h = ::_findfirst(filespec.c_str(), &file_info);
    if (h == -1)
    {
      return result;
    }

    do
    {
      auto name = std::string(file_info.name);
      if (name != "." && name != "..")
      {
        result.push_back(path + '\\' + name);
      }
    } while (::_findnext(h, &file_info) == 0);

    ::_findclose(h);

    std::sort(result.begin(), result.end());
    return result;
  }

#else

  #include <dirent.h>
  #include <unistd.h>

  const std::string permission_denied_dir = "/";

  auto directory_listing (const std::string &path)
  {
    std::vector<std::string> result;
    if (auto dir = ::opendir(path.c_str()))
    {
      while (auto it = ::readdir(dir))
      {
        auto name = std::string(it->d_name);
        if (name != "." && name != "..")
        {
          result.push_back(path + '/' + name);
        }
      }
      ::closedir(dir);
    }
    std::sort(result.begin(), result.end());
    return result;
  }

#endif

std::string read_file (const std::string &name)
{
  std::ifstream file(name);
  if (file.fail())
  {
    sal::throw_system_error(
      std::error_code(errno, std::system_category()),
      "read_file: ", name
    );
  }

  std::string line, content;
  while (std::getline(file, line))
  {
    content += line;
    content += '\n';
  }

  return content;
}

inline bool file_contains (const std::string &needle, const std::string &file)
{
  return read_file(file).find(needle) != std::string::npos;
}

template <typename Worker>
struct file_sink
  : public sal_test::with_type<Worker>
{
  const std::string test_logs = "test_logs";
  std::unique_ptr<Worker> worker_ = std::make_unique<Worker>();

  template <typename... Options>
  auto make_channel (Options &&...options)
  {
    auto sink = sal::logger::file("test",
      sal::logger::set_file_dir(test_logs),
      std::forward<Options>(options)...
    );
    auto channel_name = this->case_name;
    std::reverse(channel_name.begin(), channel_name.end());
    return worker_->make_channel(channel_name,
      sal::logger::set_channel_sink(sink)
    );
  }

  void stop_and_close_logs ()
  {
    worker_.reset();
  }

  auto log_files ()
  {
    return directory_listing(test_logs);
  }

  void SetUp () override
  {
    // remove test_logs before starting testing
    for (auto &file: directory_listing(test_logs))
    {
      std::remove(file.c_str());
    }
    ::rmdir(test_logs.c_str());
  }

  void TearDown () override
  {
    stop_and_close_logs();
    SetUp();
  }

};

TYPED_TEST_CASE_P(file_sink);

TYPED_TEST_P(file_sink, log)
{
  auto channel = this->make_channel();
  sal_log(channel) << this->case_name;
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  EXPECT_TRUE(file_contains(this->case_name, log_files[0]));
}

TYPED_TEST_P(file_sink, log_buffered)
{
  auto channel = this->make_channel(sal::logger::set_file_buffer_size_kb(1));
  sal_log(channel) << this->case_name;
  for (auto i = 0;  i != 10;  ++i)
  {
    // log 10 long messages to make sure we hit full buffer conditio
    sal_log(channel) << std::string(sal::logger::event_t::max_message_size/2, 'x');
  }
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  EXPECT_TRUE(file_contains(this->case_name, log_files[0]));
}

TYPED_TEST_P(file_sink, log_overflow)
{
  auto channel = this->make_channel();
  std::string overflowed_message(sal::logger::event_t::max_message_size, 'x');
  sal_log(channel) << this->case_name << ' ' << overflowed_message;
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  auto log_content = read_file(log_files[0]);

  EXPECT_NE(log_content.npos, log_content.find(this->case_name));
  EXPECT_EQ(log_content.npos, log_content.find(overflowed_message));
  EXPECT_NE(log_content.npos, log_content.find("<...>"));
}

TYPED_TEST_P(file_sink, local_time)
{
  auto channel = this->make_channel(sal::logger::set_file_utc_time(false));
  sal_log(channel) << this->case_name;
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  auto log_content = read_file(log_files[0]);

  // check for logged message
  EXPECT_NE(log_content.npos, log_content.find(this->case_name));

  //
  // check for timestamp (at beginning of line i.e. prepend '\n')
  //

  auto now = sal::now();
  auto tm = sal::local_time(now);
  char buf[64];

  // in current second
  snprintf(buf, sizeof(buf), "\n%02u:%02u:%02u",
    tm.tm_hour, tm.tm_min, tm.tm_sec
  );
  bool found = log_content.npos != log_content.find(std::string(buf));

  // if not found, then in previous second as well
  if (!found)
  {
    using namespace std::chrono_literals;
    tm = sal::local_time(now - 1s);
    snprintf(buf, sizeof(buf), "\n%02u:%02u:%02u",
      tm.tm_hour, tm.tm_min, tm.tm_sec
    );
    found = log_content.npos != log_content.find(std::string(buf));
  }

  EXPECT_TRUE(found);
}

TYPED_TEST_P(file_sink, utc_time)
{
  auto channel = this->make_channel(sal::logger::set_file_utc_time(true));
  sal_log(channel) << this->case_name;
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_EQ(1U, log_files.size());
  auto log_content = read_file(log_files[0]);

  // check for logged message
  EXPECT_NE(log_content.npos, log_content.find(this->case_name));

  //
  // check for timestamp
  //

  auto now = sal::now();
  auto tm = sal::utc_time(now);
  char buf[64];

  // in current second
  snprintf(buf, sizeof(buf), "\n%02u:%02u:%02u",
    tm.tm_hour, tm.tm_min, tm.tm_sec
  );
  bool found = log_content.npos != log_content.find(std::string(buf));

  // if not found, then in previous second as well
  if (!found)
  {
    using namespace std::chrono_literals;
    tm = sal::utc_time(now - 1s);
    snprintf(buf, sizeof(buf), "\n%02u:%02u:%02u",
      tm.tm_hour, tm.tm_min, tm.tm_sec
    );
    found = log_content.npos != log_content.find(std::string(buf));
  }

  EXPECT_TRUE(found);
}

TYPED_TEST_P(file_sink, max_size)
{
  // here we use internal knowledge how to configure max log file size
  // (don't want to use public API with 1MB precision)

  auto channel = this->make_channel(
    sal::logger::__bits::file_max_size(1024)
  );
  for (auto i = 0;  i < 100;  ++i)
  {
    sal_log(channel) << this->case_name << '_' << (i + 1);
  }
  this->stop_and_close_logs();

  auto log_files = this->log_files();
  EXPECT_LT(1U, log_files.size());
  EXPECT_TRUE(file_contains(this->case_name + "_1\n", log_files[0]));
  EXPECT_TRUE(file_contains(this->case_name + "_100\n", log_files.back()));
}

TYPED_TEST_P(file_sink, unprivileged_dir)
{
  EXPECT_THROW(
    this->make_channel(sal::logger::set_file_dir(permission_denied_dir)),
    std::system_error
  );
}

REGISTER_TYPED_TEST_CASE_P(file_sink,
  log,
  log_buffered,
  log_overflow,
  local_time,
  utc_time,
  max_size,
  unprivileged_dir
);

using worker_types = testing::Types<
  sal::logger::worker_t,
  sal::logger::async_worker_t
>;

INSTANTIATE_TYPED_TEST_CASE_P(logger, file_sink, worker_types);

} // namespace
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: qpro.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: vg $ $Date: 2007-02-27 12:35:10 $
 *
 *  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 SC_QPRO_HXX
#define SC_QPRO_HXX

#include <sal/config.h>
#include "filter.hxx"
#include "document.hxx"
#include "cell.hxx"

#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif

#include <tools/color.hxx>
#include "flttypes.hxx"
#include "ftools.hxx"
#include "qprostyle.hxx"
#include "biff.hxx"

// Stream wrapper class
class ScQProReader : public ScBiffReader
{
    public:
    bool recordsLeft();
    bool IsEndOfFile();
    void SetEof( bool bValue ){ mbEndOfFile = bValue; }
    bool nextRecord();
    sal_uInt16 getId() { return mnId; }
    sal_uInt16 getLength() { return mnLength; }
    void readString( String &rString, sal_uInt16 nLength );
    ScQProReader( SfxMedium &rMedium );
    ~ScQProReader(){ };
    FltError import( ScDocument *pDoc );
    FltError readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pStyle );
};
#endif

<commit_msg>INTEGRATION: CWS changefileheader (1.3.330); FILE MERGED 2008/04/01 15:30:16 thb 1.3.330.2: #i85898# Stripping all external header guards 2008/03/31 17:14:44 rt 1.3.330.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: qpro.hxx,v $
 * $Revision: 1.4 $
 *
 * 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 SC_QPRO_HXX
#define SC_QPRO_HXX

#include <sal/config.h>
#include "filter.hxx"
#include "document.hxx"
#include "cell.hxx"
#include <tools/string.hxx>

#include <tools/color.hxx>
#include "flttypes.hxx"
#include "ftools.hxx"
#include "qprostyle.hxx"
#include "biff.hxx"

// Stream wrapper class
class ScQProReader : public ScBiffReader
{
    public:
    bool recordsLeft();
    bool IsEndOfFile();
    void SetEof( bool bValue ){ mbEndOfFile = bValue; }
    bool nextRecord();
    sal_uInt16 getId() { return mnId; }
    sal_uInt16 getLength() { return mnLength; }
    void readString( String &rString, sal_uInt16 nLength );
    ScQProReader( SfxMedium &rMedium );
    ~ScQProReader(){ };
    FltError import( ScDocument *pDoc );
    FltError readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pStyle );
};
#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: drwtrans.hxx,v $
 *
 *  $Revision: 1.14 $
 *
 *  last change: $Author: rt $ $Date: 2007-07-06 12:28:33 $
 *
 *  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 SC_DRWTRANS_HXX
#define SC_DRWTRANS_HXX

#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx>
#endif

#ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDOBJECT_HPP_
#include <com/sun/star/embed/XEmbeddedObject.hxx>
#endif

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

//REMOVE    #ifndef _IPOBJ_HXX
//REMOVE    #include <so3/ipobj.hxx>
//REMOVE    #endif

#include <sfx2/objsh.hxx>

#ifndef SC_SCGLOB_HXX
#include "global.hxx"
#endif

class SdrModel;
class ScDocShell;
class INetBookmark;
class SdrObject;
class SdrView;
class ScDrawView;
class SdrOle2Obj;

class ScDrawTransferObj : public TransferableHelper
{
private:
    SdrModel*                       pModel;
    TransferableDataHelper          aOleData;
    TransferableObjectDescriptor    aObjDesc;
//REMOVE        SvEmbeddedObjectRef             aDocShellRef;
//REMOVE        SvEmbeddedObjectRef             aDrawPersistRef;
    SfxObjectShellRef               aDocShellRef;
    SfxObjectShellRef               aDrawPersistRef;

                                    // extracted from model in ctor:
    Size                            aSrcSize;
    INetBookmark*                   pBookmark;
    BOOL                            bGraphic;
    BOOL                            bGrIsBit;
    BOOL                            bOleObj;
                                    // source information for drag&drop:
                                    // (view is needed to handle drawing obejcts)
    SdrView*                        pDragSourceView;
    USHORT                          nDragSourceFlags;
    BOOL                            bDragWasInternal;

    sal_uInt32                      nSourceDocID;

    void                InitDocShell();
//REMOVE        SvInPlaceObjectRef  GetSingleObject();
    SdrOle2Obj* GetSingleObject();

public:
            ScDrawTransferObj( SdrModel* pClipModel, ScDocShell* pContainerShell,
                                const TransferableObjectDescriptor& rDesc );
    virtual ~ScDrawTransferObj();

    virtual void        AddSupportedFormats();
    virtual sal_Bool    GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
    virtual sal_Bool    WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
                                        const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
    virtual void        ObjectReleased();
    virtual void        DragFinished( sal_Int8 nDropAction );

    SdrModel*           GetModel()  { return pModel; }

    void                SetDrawPersist( const SfxObjectShellRef& rRef );
    void                SetDragSource( ScDrawView* pView );
    void                SetDragSourceObj( SdrObject* pObj, SCTAB nTab );
    void                SetDragSourceFlags( USHORT nFlags );
    void                SetDragWasInternal();

    SdrView*            GetDragSourceView()             { return pDragSourceView; }
    USHORT              GetDragSourceFlags() const      { return nDragSourceFlags; }

    void                SetSourceDocID( sal_uInt32 nVal )
                            { nSourceDocID = nVal; }
    sal_uInt32          GetSourceDocID() const      { return nSourceDocID; }

    static ScDrawTransferObj* GetOwnClipboard( Window* pUIWin );
    virtual sal_Int64 SAL_CALL getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( com::sun::star::uno::RuntimeException );
    static const com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
};

#endif

<commit_msg>INTEGRATION: CWS so3deadcorpses (1.14.78); FILE MERGED 2007/09/09 18:47:58 fs 1.14.78.1: #i81309# so3 is dead<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: drwtrans.hxx,v $
 *
 *  $Revision: 1.15 $
 *
 *  last change: $Author: vg $ $Date: 2007-10-23 14:45:36 $
 *
 *  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 SC_DRWTRANS_HXX
#define SC_DRWTRANS_HXX

#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx>
#endif

#ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDOBJECT_HPP_
#include <com/sun/star/embed/XEmbeddedObject.hxx>
#endif

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

#include <sfx2/objsh.hxx>

#ifndef SC_SCGLOB_HXX
#include "global.hxx"
#endif

class SdrModel;
class ScDocShell;
class INetBookmark;
class SdrObject;
class SdrView;
class ScDrawView;
class SdrOle2Obj;

class ScDrawTransferObj : public TransferableHelper
{
private:
    SdrModel*                       pModel;
    TransferableDataHelper          aOleData;
    TransferableObjectDescriptor    aObjDesc;
//REMOVE        SvEmbeddedObjectRef             aDocShellRef;
//REMOVE        SvEmbeddedObjectRef             aDrawPersistRef;
    SfxObjectShellRef               aDocShellRef;
    SfxObjectShellRef               aDrawPersistRef;

                                    // extracted from model in ctor:
    Size                            aSrcSize;
    INetBookmark*                   pBookmark;
    BOOL                            bGraphic;
    BOOL                            bGrIsBit;
    BOOL                            bOleObj;
                                    // source information for drag&drop:
                                    // (view is needed to handle drawing obejcts)
    SdrView*                        pDragSourceView;
    USHORT                          nDragSourceFlags;
    BOOL                            bDragWasInternal;

    sal_uInt32                      nSourceDocID;

    void                InitDocShell();
//REMOVE        SvInPlaceObjectRef  GetSingleObject();
    SdrOle2Obj* GetSingleObject();

public:
            ScDrawTransferObj( SdrModel* pClipModel, ScDocShell* pContainerShell,
                                const TransferableObjectDescriptor& rDesc );
    virtual ~ScDrawTransferObj();

    virtual void        AddSupportedFormats();
    virtual sal_Bool    GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
    virtual sal_Bool    WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
                                        const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
    virtual void        ObjectReleased();
    virtual void        DragFinished( sal_Int8 nDropAction );

    SdrModel*           GetModel()  { return pModel; }

    void                SetDrawPersist( const SfxObjectShellRef& rRef );
    void                SetDragSource( ScDrawView* pView );
    void                SetDragSourceObj( SdrObject* pObj, SCTAB nTab );
    void                SetDragSourceFlags( USHORT nFlags );
    void                SetDragWasInternal();

    SdrView*            GetDragSourceView()             { return pDragSourceView; }
    USHORT              GetDragSourceFlags() const      { return nDragSourceFlags; }

    void                SetSourceDocID( sal_uInt32 nVal )
                            { nSourceDocID = nVal; }
    sal_uInt32          GetSourceDocID() const      { return nSourceDocID; }

    static ScDrawTransferObj* GetOwnClipboard( Window* pUIWin );
    virtual sal_Int64 SAL_CALL getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( com::sun::star::uno::RuntimeException );
    static const com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
};

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: htmlex.hxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: hr $ $Date: 2005-09-23 10:44:20 $
 *
 *  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 _SD_HTMLEX_HXX
#define _SD_HTMLEX_HXX

#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
#endif

#ifndef _XPOLY_HXX
#include <svx/xpoly.hxx>
#endif
#ifndef _SV_GDIMTF_HXX //autogen
#include <vcl/gdimtf.hxx>
#endif
#ifndef _SFXITEMSET_HXX //autogen
#include <svtools/itemset.hxx>
#endif
#ifndef _SD_RESLTN_HXX
#include "resltn.hxx"       // enum PublishingResolution
#endif
#ifndef _SV_COLRDLG_HXX
#include <svtools/colrdlg.hxx>
#endif
#ifndef _EHDL_HXX //autogen
#include <svtools/ehdl.hxx>
#endif

#include "strings.hrc"

#ifndef SD_DRAW_DOC_SHELL_HXX
#include "DrawDocShell.hxx"
#endif

#ifndef SD_WINDOW_HXX
#include "Window.hxx"
#endif

#ifndef SD_VIEW_SHELL_HXX
#include "ViewShell.hxx"
#endif

#ifndef INC_ASSCLASS
#include "assclass.hxx"
#endif

#ifndef _SD_RESID_HXX
#include "sdresid.hxx"
#endif

#ifndef _SD_PUBDLG_HXX
#include "pubdlg.hxx"
#endif

#define NUM_BUTTONS 12

#define PUB_LOWRES_WIDTH    640
#define PUB_LOWRES_HEIGHT   480
#define PUB_MEDRES_WIDTH    800
#define PUB_MEDRES_HEIGHT   600
#define PUB_HIGHRES_WIDTH   1024
#define PUB_HIGHRES_HEIGHT  768

#define HtmlButtonThemaStr = "private://gallery/hidden/HtmlExportButtons";

class List;
class SfxProgress;
class SdrOutliner;
class SdPage;
class HtmlState;
class SdrTextObj;
class SdrPage;
class SdDrawDocument;

namespace sd {
class View;
}

class HtmlErrorContext : public ErrorContext
{
private:
    USHORT  m_nResId;
    String  m_aURL1;
    String  m_aURL2;

public:
                    HtmlErrorContext(Window *pWin=0);
                    ~HtmlErrorContext() {};

    virtual BOOL    GetString( ULONG nErrId, String& rCtxStr );

    void            SetContext( USHORT nResId );
    void            SetContext( USHORT nResId, const String& rURL );
    void            SetContext( USHORT nResId, const String& rURL1, const String& rURL2 );
};

// =====================================================================
// this class exports an Impress Document as a HTML Presentation
// =====================================================================
class HtmlExport
{
    String m_aPath;

    SdDrawDocument* pDoc;
    ::sd::DrawDocShell* pDocSh;

    HtmlErrorContext m_eEC;

    HtmlPublishMode m_eMode;
    SfxProgress* mpProgress;
    bool m_bImpress;
    USHORT m_nSdPageCount;
    USHORT m_nPagesWritten;
    bool m_bContentsPage;
    INT16 m_nButtonThema;
    UINT16 m_nWidthPixel;
    UINT16 m_nHeightPixel;
    PublishingFormat m_eFormat;
    bool m_bHeader;
    bool m_bNotes;
    bool m_bFrames;
    bool m_bKiosk;
//-/    bool m_bCreated;
    String m_aIndex;
    String m_aEMail;
    String m_aAuthor;
    String m_aHomePage;
    String m_aInfo;
    INT16 m_nCompression;
    String m_aDocFileName;
    String m_aFramePage;
    String m_DocTitle;
    bool m_bDownload;

    bool m_bAutoSlide;
    UINT32  m_nSlideDuration;
    bool m_bSlideSound;
    bool m_bEndless;

    bool m_bUserAttr;           // die folgenden Farben werden fuer das <body>
    Color m_aTextColor;         // tag genutzt, wenn m_bUserAttr true ist
    Color m_aBackColor;
    Color m_aLinkColor;
    Color m_aVLinkColor;
    Color m_aALinkColor;
    Color m_aFirstPageColor;
    bool m_bDocColors;

    String   m_aHTMLExtension;
    String** m_pHTMLFiles;
    String** m_pImageFiles;
    String** m_pPageNames;
    String** m_pTextFiles;

    String m_aExportPath;           // Das Ausgabeverzeichnes bzw. die URL
    String m_aIndexUrl;
    String m_aURLPath;
    String m_aCGIPath;
    PublishingScript m_eScript;

    const String m_aHTMLHeader;

    SdrTextObj* GetLayoutTextObject(SdrPage* pPage);

    void SetDocColors( SdPage* pPage = NULL );

    bool    CreateImagesForPresPages();
    bool    CreateHtmlTextForPresPages();
    bool    CreateHtmlForPresPages();
    bool    CreateContentPage();
    void    CreateFileNames();
    bool    CreateBitmaps();
    bool    CreateOutlinePages();
    bool    CreateFrames();
    bool    CreateNotesPages();
    bool    CreateNavBarFrames();

    bool    CreateASPScripts();
    bool    CreatePERLScripts();
    bool    CreateImageFileList();
    bool    CreateImageNumberFile();

    bool    checkForExistingFiles();
    bool    checkFileExists( ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xFileAccess, String const & aFileName );

    ULONG   CreateBitmap( ULONG nThemeId, INT16 nImage, const String& aName ) const;
    void    SmoothBitmap( BitmapEx& aBmp, Color aBackCol ) const;
    String getDocumentTitle();
    bool    SavePresentation();

    String  CreateLink( const String& aLink, const String& aText,
                        const String& aTarget = String()) const;
    String  CreateImage( const String& aImage, const String& aAltText, INT16 nWidth = -1, INT16 nHeight = -1 ) const;
    String  CreateNavBar( USHORT nSdPage, bool bIsText ) const;
    String  CreateBodyTag() const;

    String  ParagraphToHTMLString( SdrOutliner* pOutliner, ULONG nPara, const Color& rBackgroundColor );
    String  TextAttribToHTMLString( SfxItemSet* pSet, HtmlState* pState, const Color& rBackgroundColor );

    String  CreateTextForTitle( SdrOutliner* pOutliner, SdPage* pPage, const Color& rBackgroundColor );
    String  CreateTextForPage( SdrOutliner* pOutliner, SdPage* pPage, bool bHeadLine, const Color& rBackgroundColor );
    String  CreateTextForNotesPage( SdrOutliner* pOutliner, SdPage* pPage, bool bHeadLine, const Color& rBackgroundColor );

    String  CreateHTMLCircleArea( ULONG nRadius, ULONG nCenterX,
                                  ULONG nCenterY, const String& rHRef ) const;
    String  CreateHTMLPolygonArea( const XPolyPolygon& rXPolyPoly,
                                   Size aShift, double fFactor,
                                   const String& rHRef ) const;
    String  CreateHTMLRectArea( const Rectangle& rRect,
                                const String& rHRef ) const;

    String  CreatePageURL( USHORT nPgNum );

    String InsertSound( const String& rSoundFile );
    bool CopyFile( const String& rSourceFile, const String& rDestPath );
    bool CopyScript( const String& rPath, const String& rSource, const String& rDest, bool bUnix = false );

    void InitProgress( USHORT nProgrCount );
    void ResetProgress();

    String WriteMetaCharset() const;

    void InitExportParameters( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rParams);
    void ExportHtml();
    void ExportKiosk();
    void ExportWebCast();

    List aSpecialObjects;
    void HideSpecialObjects( SdPage* pPage );
    void ShowSpecialObjects();

    bool WriteHtml( const String& rFileName, bool bAddExtension, const String& rHtmlData );
    String GetButtonName( USHORT nButton ) const;

 public:
     HtmlExport( rtl::OUString aPath, const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rParams, SdDrawDocument* pExpDoc, ::sd::DrawDocShell* pDocShell );
    virtual ~HtmlExport();

    static String   ColorToHTMLString( Color aColor );
    static String   StringToHTMLString( const String& rString );
    static String   StringToURL( const String& rURL );
};

#endif // _SD_HTMLEX_HXX
<commit_msg>INTEGRATION: CWS aw024 (1.8.78); FILE MERGED 2005/11/18 14:18:58 aw 1.8.78.3: RESYNC: (1.9-1.10); FILE MERGED 2005/09/17 10:33:37 aw 1.8.78.2: RESYNC: (1.8-1.9); FILE MERGED 2005/05/12 16:46:20 aw 1.8.78.1: #i39529#<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: htmlex.hxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: ihi $ $Date: 2006-11-14 14:23:08 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SD_HTMLEX_HXX
#define _SD_HTMLEX_HXX

#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
#endif

#ifndef _SV_GDIMTF_HXX //autogen
#include <vcl/gdimtf.hxx>
#endif
#ifndef _SFXITEMSET_HXX //autogen
#include <svtools/itemset.hxx>
#endif
#ifndef _SD_RESLTN_HXX
#include "resltn.hxx"       // enum PublishingResolution
#endif
#ifndef _SV_COLRDLG_HXX
#include <svtools/colrdlg.hxx>
#endif
#ifndef _EHDL_HXX //autogen
#include <svtools/ehdl.hxx>
#endif

#include "strings.hrc"

#ifndef SD_DRAW_DOC_SHELL_HXX
#include "DrawDocShell.hxx"
#endif

#ifndef SD_WINDOW_HXX
#include "Window.hxx"
#endif

#ifndef SD_VIEW_SHELL_HXX
#include "ViewShell.hxx"
#endif

#ifndef INC_ASSCLASS
#include "assclass.hxx"
#endif

#ifndef _SD_RESID_HXX
#include "sdresid.hxx"
#endif

#ifndef _SD_PUBDLG_HXX
#include "pubdlg.hxx"
#endif

#define NUM_BUTTONS 12

#define PUB_LOWRES_WIDTH    640
#define PUB_LOWRES_HEIGHT   480
#define PUB_MEDRES_WIDTH    800
#define PUB_MEDRES_HEIGHT   600
#define PUB_HIGHRES_WIDTH   1024
#define PUB_HIGHRES_HEIGHT  768

#define HtmlButtonThemaStr = "private://gallery/hidden/HtmlExportButtons";

class List;
class SfxProgress;
class SdrOutliner;
class SdPage;
class HtmlState;
class SdrTextObj;
class SdrPage;
class SdDrawDocument;

namespace sd {
class View;
}

class HtmlErrorContext : public ErrorContext
{
private:
    USHORT  m_nResId;
    String  m_aURL1;
    String  m_aURL2;

public:
                    HtmlErrorContext(Window *pWin=0);
                    ~HtmlErrorContext() {};

    virtual BOOL    GetString( ULONG nErrId, String& rCtxStr );

    void            SetContext( USHORT nResId );
    void            SetContext( USHORT nResId, const String& rURL );
    void            SetContext( USHORT nResId, const String& rURL1, const String& rURL2 );
};

// =====================================================================
// this class exports an Impress Document as a HTML Presentation
// =====================================================================
class HtmlExport
{
    String m_aPath;

    SdDrawDocument* pDoc;
    ::sd::DrawDocShell* pDocSh;

    HtmlErrorContext m_eEC;

    HtmlPublishMode m_eMode;
    SfxProgress* mpProgress;
    bool m_bImpress;
    USHORT m_nSdPageCount;
    USHORT m_nPagesWritten;
    bool m_bContentsPage;
    INT16 m_nButtonThema;
    UINT16 m_nWidthPixel;
    UINT16 m_nHeightPixel;
    PublishingFormat m_eFormat;
    bool m_bHeader;
    bool m_bNotes;
    bool m_bFrames;
    bool m_bKiosk;
//-/    bool m_bCreated;
    String m_aIndex;
    String m_aEMail;
    String m_aAuthor;
    String m_aHomePage;
    String m_aInfo;
    INT16 m_nCompression;
    String m_aDocFileName;
    String m_aFramePage;
    String m_DocTitle;
    bool m_bDownload;

    bool m_bAutoSlide;
    UINT32  m_nSlideDuration;
    bool m_bSlideSound;
    bool m_bEndless;

    bool m_bUserAttr;           // die folgenden Farben werden fuer das <body>
    Color m_aTextColor;         // tag genutzt, wenn m_bUserAttr true ist
    Color m_aBackColor;
    Color m_aLinkColor;
    Color m_aVLinkColor;
    Color m_aALinkColor;
    Color m_aFirstPageColor;
    bool m_bDocColors;

    String   m_aHTMLExtension;
    String** m_pHTMLFiles;
    String** m_pImageFiles;
    String** m_pPageNames;
    String** m_pTextFiles;

    String m_aExportPath;           // Das Ausgabeverzeichnes bzw. die URL
    String m_aIndexUrl;
    String m_aURLPath;
    String m_aCGIPath;
    PublishingScript m_eScript;

    const String m_aHTMLHeader;

    SdrTextObj* GetLayoutTextObject(SdrPage* pPage);

    void SetDocColors( SdPage* pPage = NULL );

    bool    CreateImagesForPresPages();
    bool    CreateHtmlTextForPresPages();
    bool    CreateHtmlForPresPages();
    bool    CreateContentPage();
    void    CreateFileNames();
    bool    CreateBitmaps();
    bool    CreateOutlinePages();
    bool    CreateFrames();
    bool    CreateNotesPages();
    bool    CreateNavBarFrames();

    bool    CreateASPScripts();
    bool    CreatePERLScripts();
    bool    CreateImageFileList();
    bool    CreateImageNumberFile();

    bool    checkForExistingFiles();
    bool    checkFileExists( ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xFileAccess, String const & aFileName );

    ULONG   CreateBitmap( ULONG nThemeId, INT16 nImage, const String& aName ) const;
    void    SmoothBitmap( BitmapEx& aBmp, Color aBackCol ) const;
    String getDocumentTitle();
    bool    SavePresentation();

    String  CreateLink( const String& aLink, const String& aText,
                        const String& aTarget = String()) const;
    String  CreateImage( const String& aImage, const String& aAltText, INT16 nWidth = -1, INT16 nHeight = -1 ) const;
    String  CreateNavBar( USHORT nSdPage, bool bIsText ) const;
    String  CreateBodyTag() const;

    String  ParagraphToHTMLString( SdrOutliner* pOutliner, ULONG nPara, const Color& rBackgroundColor );
    String  TextAttribToHTMLString( SfxItemSet* pSet, HtmlState* pState, const Color& rBackgroundColor );

    String  CreateTextForTitle( SdrOutliner* pOutliner, SdPage* pPage, const Color& rBackgroundColor );
    String  CreateTextForPage( SdrOutliner* pOutliner, SdPage* pPage, bool bHeadLine, const Color& rBackgroundColor );
    String  CreateTextForNotesPage( SdrOutliner* pOutliner, SdPage* pPage, bool bHeadLine, const Color& rBackgroundColor );

    String  CreateHTMLCircleArea( ULONG nRadius, ULONG nCenterX,
                                  ULONG nCenterY, const String& rHRef ) const;
    String  CreateHTMLPolygonArea( const ::basegfx::B2DPolyPolygon& rPolyPoly, Size aShift, double fFactor, const String& rHRef ) const;
    String  CreateHTMLRectArea( const Rectangle& rRect,
                                const String& rHRef ) const;

    String  CreatePageURL( USHORT nPgNum );

    String InsertSound( const String& rSoundFile );
    bool CopyFile( const String& rSourceFile, const String& rDestPath );
    bool CopyScript( const String& rPath, const String& rSource, const String& rDest, bool bUnix = false );

    void InitProgress( USHORT nProgrCount );
    void ResetProgress();

    String WriteMetaCharset() const;

    void InitExportParameters( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rParams);
    void ExportHtml();
    void ExportKiosk();
    void ExportWebCast();

    List aSpecialObjects;
    void HideSpecialObjects( SdPage* pPage );
    void ShowSpecialObjects();

    bool WriteHtml( const String& rFileName, bool bAddExtension, const String& rHtmlData );
    String GetButtonName( USHORT nButton ) const;

 public:
     HtmlExport( rtl::OUString aPath, const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rParams, SdDrawDocument* pExpDoc, ::sd::DrawDocShell* pDocShell );
    virtual ~HtmlExport();

    static String   ColorToHTMLString( Color aColor );
    static String   StringToHTMLString( const String& rString );
    static String   StringToURL( const String& rURL );
};

#endif // _SD_HTMLEX_HXX
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unowcntr.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 06:56: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 _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
#include <com/sun/star/lang/XComponent.hpp>
#endif

#ifndef _LIST_HXX
#include <tools/list.hxx>
#endif

#include <unowcntr.hxx>

using namespace ::rtl;
using namespace ::com::sun::star;

DECLARE_LIST( WeakRefList, uno::WeakReference< uno::XInterface >* );

SvUnoWeakContainer::SvUnoWeakContainer() throw()
{
    mpList = new WeakRefList;
}

SvUnoWeakContainer::~SvUnoWeakContainer() throw()
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        delete mpList->Remove();
        pRef = mpList->GetCurObject();
    }
    delete mpList;
}

/** inserts the given ref into this container */
void SvUnoWeakContainer::insert( uno::WeakReference< uno::XInterface > xRef ) throw()
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  xTestRef( *pRef );
        if(! xTestRef.is() )
        {
            delete mpList->Remove();
            pRef = mpList->GetCurObject();
        }
        else
        {
            if( *pRef == xRef )
                return;

            pRef = mpList->Next();
        }
    }

    mpList->Insert( new uno::WeakReference< uno::XInterface >( xRef ) );
}

/** removes the given ref from this container */
void SvUnoWeakContainer::remove( uno::WeakReference< uno::XInterface > xRef ) throw()
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        uno::Reference< uno::XInterface > xTestRef( *pRef );
        if(!xTestRef.is())
        {
            delete mpList->Remove();
            pRef = mpList->GetCurObject();
        }
        else
        {
            if( *pRef == xRef )
            {
                delete mpList->Remove();
                break;
            }

            pRef = mpList->Next();
        }
    }
}

/** searches the container for a ref that returns true on the given
    search function
*/
sal_Bool SvUnoWeakContainer::findRef( uno::WeakReference< uno::XInterface >& rRef, void* pSearchData, weakref_searchfunc pSearchFunc )
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        uno::Reference< ::com::sun::star::uno::XInterface > xTestRef( *pRef );
        if(!xTestRef.is())
        {
            delete mpList->Remove();
            pRef = mpList->GetCurObject();
        }
        else
        {
            if( (*pSearchFunc)( *pRef, pSearchData ) )
            {
                rRef = *pRef;
                return sal_True;
            }

            pRef = mpList->Next();
        }
    }

    return sal_False;
}

void SvUnoWeakContainer::dispose()
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        uno::Reference< uno::XInterface > xTestRef( *pRef );
        if(xTestRef.is())
        {
            uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
            if( xComp.is() )
                xComp->dispose();
        }

        pRef = mpList->Next();
    }
}

<commit_msg>INTEGRATION: CWS pchfix02 (1.3.282); FILE MERGED 2006/09/01 17:37:32 kaib 1.3.282.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unowcntr.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 19:29:37 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"

#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
#include <com/sun/star/lang/XComponent.hpp>
#endif

#ifndef _LIST_HXX
#include <tools/list.hxx>
#endif

#include <unowcntr.hxx>

using namespace ::rtl;
using namespace ::com::sun::star;

DECLARE_LIST( WeakRefList, uno::WeakReference< uno::XInterface >* );

SvUnoWeakContainer::SvUnoWeakContainer() throw()
{
    mpList = new WeakRefList;
}

SvUnoWeakContainer::~SvUnoWeakContainer() throw()
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        delete mpList->Remove();
        pRef = mpList->GetCurObject();
    }
    delete mpList;
}

/** inserts the given ref into this container */
void SvUnoWeakContainer::insert( uno::WeakReference< uno::XInterface > xRef ) throw()
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  xTestRef( *pRef );
        if(! xTestRef.is() )
        {
            delete mpList->Remove();
            pRef = mpList->GetCurObject();
        }
        else
        {
            if( *pRef == xRef )
                return;

            pRef = mpList->Next();
        }
    }

    mpList->Insert( new uno::WeakReference< uno::XInterface >( xRef ) );
}

/** removes the given ref from this container */
void SvUnoWeakContainer::remove( uno::WeakReference< uno::XInterface > xRef ) throw()
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        uno::Reference< uno::XInterface > xTestRef( *pRef );
        if(!xTestRef.is())
        {
            delete mpList->Remove();
            pRef = mpList->GetCurObject();
        }
        else
        {
            if( *pRef == xRef )
            {
                delete mpList->Remove();
                break;
            }

            pRef = mpList->Next();
        }
    }
}

/** searches the container for a ref that returns true on the given
    search function
*/
sal_Bool SvUnoWeakContainer::findRef( uno::WeakReference< uno::XInterface >& rRef, void* pSearchData, weakref_searchfunc pSearchFunc )
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        uno::Reference< ::com::sun::star::uno::XInterface > xTestRef( *pRef );
        if(!xTestRef.is())
        {
            delete mpList->Remove();
            pRef = mpList->GetCurObject();
        }
        else
        {
            if( (*pSearchFunc)( *pRef, pSearchData ) )
            {
                rRef = *pRef;
                return sal_True;
            }

            pRef = mpList->Next();
        }
    }

    return sal_False;
}

void SvUnoWeakContainer::dispose()
{
    uno::WeakReference< uno::XInterface >* pRef = mpList->First();
    while( pRef )
    {
        uno::Reference< uno::XInterface > xTestRef( *pRef );
        if(xTestRef.is())
        {
            uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
            if( xComp.is() )
                xComp->dispose();
        }

        pRef = mpList->Next();
    }
}

<|endoftext|>


<commit_before><commit_msg>tinkering<commit_after><|endoftext|>


<commit_before>/*
 * Copyright (C) 2011
 * Alessio Sclocco <a.sclocco@vu.nl>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#define __CL_ENABLE_EXCEPTIONS
#include <CL/cl.hpp>
#include <string>
#include <cstring>
#include <fstream>
using std::string;
using std::ofstream;

#include <utils.hpp>
#include <Exceptions.hpp>
#include <Timer.hpp>
using isa::utils::toStringValue;
using isa::Exceptions::OpenCLError;
using isa::utils::Timer;

#ifndef CL_DATA_HPP
#define CL_DATA_HPP

namespace isa {

namespace OpenCL {

template< typename T > class CLData {
public:
	CLData(string name, bool deletePolicy = false);
	~CLData();

	inline string getName() const;

	// Allocation of host data
	void allocateHostData(T * data, size_t size);
	void allocateHostData(long long unsigned int nrElements);
	void deleteHostData();

	// Allocation of device data
	void allocateDeviceData(cl::Buffer * data, size_t size);
	void allocateDeviceData(long long unsigned int nrElements) throw (OpenCLError);
	void allocateDeviceData() throw (OpenCLError);
	void allocateSharedDeviceData() throw (OpenCLError);
	void deleteDeviceData();
	inline void setDeviceReadOnly();
	inline void setDeviceWriteOnly();

	// Memory transfers
	void copyHostToDevice(bool async = false) throw (OpenCLError);
	void copyDeviceToHost(bool async = false) throw (OpenCLError);
	void dumpDeviceToDisk() throw (OpenCLError);

	// OpenCL
	inline void setCLContext(cl::Context * context);
	inline void setCLQueue(cl::CommandQueue * queue);

	// Access host data
	inline T * getHostData();
	inline T * getHostDataAt(long long unsigned int startingPoint);
	inline void * getRawHostData();
	inline void * getRawHostDataAt(long long unsigned int startingPoint);
	inline size_t getHostDataSize() const;
	inline const T operator[](long long unsigned int item);
	inline const T getHostDataItem(long long unsigned int item);

	// Access device data
	inline cl::Buffer * getDeviceData();
	inline size_t getDeviceDataSize() const;

	// Timers
	inline Timer & getH2DTimer();
	inline Timer & getD2HTimer();

private:
	cl::Context * clContext;
	cl::CommandQueue * clQueue;
	Timer timerH2D;
	Timer timerD2H;

	bool deleteHost;
	bool deviceReadOnly;
	bool deviceWriteOnly;
	T * hostData;
	size_t hostDataSize;
	cl::Buffer * deviceData;
	size_t deviceDataSize;

	string name;
};

// Implementations

template< typename T > CLData< T >::CLData(string name, bool deletePolicy) : clContext(0), clQueue(0), timerH2D(Timer("H2D")), timerD2H(Timer("D2H")), deleteHost(deletePolicy), deviceReadOnly(false), deviceWriteOnly(false), hostData(0), hostDataSize(0), deviceData(0), deviceDataSize(0), name(name) {}

template< typename T > CLData< T >::~CLData() {
	deleteHostData();
	deleteDeviceData();
}

template< typename T > void CLData< T >::allocateHostData(T * data, size_t size) {
	deleteHostData();

	hostData = data;
	hostDataSize = size;
}

template< typename T > void CLData< T >::allocateHostData(long long unsigned int nrElements) {
	size_t newSize = nrElements * sizeof(T);

	if ( newSize != hostDataSize ) {
		deleteHostData();

		hostData = new T [nrElements];
		hostDataSize = newSize;
	}
	memset(getRawHostData(), 0, newSize);
}

template< typename T > void CLData< T >::deleteHostData() {
	if ( deleteHost && hostDataSize != 0 ) {
		delete [] hostData;
		hostData = 0;
		hostDataSize = 0;
	}
}

template< typename T > void CLData< T >::allocateDeviceData(cl::Buffer * data, size_t size) {
	deleteDeviceData();

	deviceData = data;
	deviceDataSize = size;
}

template< typename T > void CLData< T >::allocateDeviceData(long long unsigned int nrElements) throw (OpenCLError) {
	size_t newSize = nrElements * sizeof(T);
	if ( newSize != deviceDataSize ) {
		deleteDeviceData();

		try {
			if ( deviceReadOnly ) {
				deviceData = new cl::Buffer(*clContext, CL_MEM_READ_ONLY, newSize, NULL, NULL);
			} else if ( deviceWriteOnly ) {
				deviceData = new cl::Buffer(*clContext, CL_MEM_WRITE_ONLY, newSize, NULL, NULL);
			} else {
				deviceData = new cl::Buffer(*clContext, CL_MEM_READ_WRITE, newSize, NULL, NULL);
			}
		} catch ( cl::Error err ) {
			deviceDataSize = 0;
			throw  OpenCLError("Impossible to allocate " + name + " device memory: " + toStringValue< cl_int >(err.err()));
		}
		deviceDataSize = newSize;
	}
}

template< typename T > void CLData< T >::allocateDeviceData() throw (OpenCLError) {
	deleteDeviceData();

	try {
		if ( deviceReadOnly ) {
			deviceData = new cl::Buffer(*clContext, CL_MEM_READ_ONLY, hostDataSize, NULL, NULL);
		} else if ( deviceWriteOnly ) {
			deviceData = new cl::Buffer(*clContext, CL_MEM_WRITE_ONLY, hostDataSize, NULL, NULL);
		} else {
			deviceData = new cl::Buffer(*clContext, CL_MEM_READ_WRITE, hostDataSize, NULL, NULL);
		}
	} catch ( cl::Error err ) {
		deviceDataSize = 0;
		throw  OpenCLError("Impossible to allocate " + name + " device memory: " + toStringValue< cl_int >(err.err()));
	}
	deviceDataSize = hostDataSize;
}

template< typename T > void CLData< T >::allocateSharedDeviceData() throw (OpenCLError) {
	deleteDeviceData();

	try {
		if ( deviceReadOnly ) {
			deviceData = new cl::Buffer(*clContext, CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY, hostDataSize, getRawHostData(), NULL);
		} else if ( deviceWriteOnly ) {
			deviceData = new cl::Buffer(*clContext, CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY, hostDataSize, getRawHostData(), NULL);
		} else {
			deviceData = new cl::Buffer(*clContext, CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE, hostDataSize, getRawHostData(), NULL);
		}
	} catch ( cl::Error err ) {
		deviceDataSize = 0;
		throw  OpenCLError("Impossible to allocate " + name + " device memory: " + toStringValue< cl_int >(err.err()));
	}
	deviceDataSize = hostDataSize;
}

template< typename T > void CLData< T >::deleteDeviceData() {
	if ( deviceDataSize != 0 ) {
		delete deviceData;
		deviceData = 0;
		deviceDataSize = 0;
	}
}

template< typename T > inline void CLData< T >::setDeviceReadOnly() {
	deviceReadOnly = true;
	deviceWriteOnly = false;
}

template< typename T > inline void CLData< T >::setDeviceWriteOnly() {
	deviceWriteOnly = true;
	deviceReadOnly = false;
}

template< typename T > void CLData< T >::copyHostToDevice(bool async) throw (OpenCLError) {
	if ( hostDataSize != deviceDataSize ) {
		throw OpenCLError("Impossible to copy " + name + ": different memory sizes.");
	}

	if ( async ) {
		try {
			clQueue->enqueueWriteBuffer(*deviceData, CL_FALSE, 0, deviceDataSize, getRawHostData(), NULL, NULL);
		} catch ( cl::Error err ) {
			throw OpenCLError("Impossible to copy " + name + " to device: " + toStringValue< cl_int >(err.err()));
		}
	}
	else {
		cl::Event clEvent;

		try {
			timerH2D.start();
			clQueue->enqueueWriteBuffer(*deviceData, CL_TRUE, 0, deviceDataSize, getRawHostData(), NULL, &clEvent);
			clEvent.wait();
			timerH2D.stop();
		} catch ( cl::Error err ) {
			timerH2D.reset();
			throw OpenCLError("Impossible to copy " + name + " to device: " + toStringValue< cl_int >(err.err()));
		}
	}
}

template< typename T > void CLData< T >::copyDeviceToHost(bool async) throw (OpenCLError) {
	if ( hostDataSize != deviceDataSize ) {
		throw OpenCLError("Impossible to copy " + name + ": different memory sizes.");
	}

	if ( async ) {
		try {
			clQueue->enqueueReadBuffer(*deviceData, CL_FALSE, 0, hostDataSize, getRawHostData(), NULL, NULL);
		} catch ( cl::Error err ) {
			throw OpenCLError("Impossible to copy " + name + " to host: " + toStringValue< cl_int >(err.err()));
		}
	}
	else {
		cl::Event clEvent;

		try {
			timerD2H.start();
			clQueue->enqueueReadBuffer(*deviceData, CL_TRUE, 0, hostDataSize, getRawHostData(), NULL, &clEvent);
			clEvent.wait();
			timerD2H.stop();
		} catch ( cl::Error err ) {
			timerD2H.reset();
			throw OpenCLError("Impossible to copy " + name + " to host: " + toStringValue< cl_int >(err.err()));
		}
	}

}

template< typename T > void CLData< T >::dumpDeviceToDisk() throw (OpenCLError) {
	CLData< T > temp = CLData< T >("temp", true);

	temp.setCLContext(clContext);
	temp.setCLQueue(clQueue);
	temp.allocateHostData(hostDataSize / sizeof(T));
	temp.allocateDeviceData(deviceData, deviceDataSize);
	temp.copyDeviceToHost();

	ofstream oFile(("./" + name + ".bin").c_str(), ofstream::binary);
	oFile.write(reinterpret_cast< char * >(temp.getRawHostData()), temp.getHostDataSize());
	oFile.close();
}

template< typename T > inline void CLData< T >::setCLContext(cl::Context * context) {
	clContext = context;
}

template< typename T > inline void CLData< T >::setCLQueue(cl::CommandQueue * queue) {
	clQueue = queue;
}

template< typename T > inline T * CLData< T >::getHostData() {
	return hostData;
}

template< typename T > inline T * CLData< T >::getHostDataAt(long long unsigned int startingPoint) {
	return &(hostData[startingPoint]);
}

template< typename T > inline void * CLData< T >::getRawHostData() {
	return reinterpret_cast< void * >(hostData);
}

template< typename T > inline void * CLData< T >::getRawHostDataAt(long long unsigned int startingPoint) {
	return reinterpret_cast< void * >(&(hostData[startingPoint]));
}

template< typename T > inline size_t CLData< T >::getHostDataSize() const {
	return hostDataSize;
}

template< typename T > inline const T CLData< T >::operator[](long long unsigned int item) {
	return hostData[item];
}

template< typename T > inline const T CLData< T >::getHostDataItem(long long unsigned int item) {
	return hostData[item];
}

template< typename T > inline cl::Buffer * CLData< T >::getDeviceData() {
	return deviceData;
}

template< typename T > inline size_t CLData< T >::getDeviceDataSize() const {
	return deviceDataSize;
}

template< typename T > inline string CLData< T >::getName() const {
	return name;
}

template< typename T > inline Timer & CLData< T >::getH2DTimer() {
	return timerH2D;
}

template< typename T > inline Timer & CLData< T >::getD2HTimer() {
	return timerD2H;
}

} // OpenCL
} // isa

#endif // CL_DATA_HPP
<commit_msg>Data retrieval methods do not modify the object, so they can be marked as const.<commit_after>/*
 * Copyright (C) 2011
 * Alessio Sclocco <a.sclocco@vu.nl>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#define __CL_ENABLE_EXCEPTIONS
#include <CL/cl.hpp>
#include <string>
#include <cstring>
#include <fstream>
using std::string;
using std::ofstream;

#include <utils.hpp>
#include <Exceptions.hpp>
#include <Timer.hpp>
using isa::utils::toStringValue;
using isa::Exceptions::OpenCLError;
using isa::utils::Timer;

#ifndef CL_DATA_HPP
#define CL_DATA_HPP

namespace isa {

namespace OpenCL {

template< typename T > class CLData {
public:
	CLData(string name, bool deletePolicy = false);
	~CLData();

	inline string getName() const;

	// Allocation of host data
	void allocateHostData(T * data, size_t size);
	void allocateHostData(long long unsigned int nrElements);
	void deleteHostData();

	// Allocation of device data
	void allocateDeviceData(cl::Buffer * data, size_t size);
	void allocateDeviceData(long long unsigned int nrElements) throw (OpenCLError);
	void allocateDeviceData() throw (OpenCLError);
	void allocateSharedDeviceData() throw (OpenCLError);
	void deleteDeviceData();
	inline void setDeviceReadOnly();
	inline void setDeviceWriteOnly();

	// Memory transfers
	void copyHostToDevice(bool async = false) throw (OpenCLError);
	void copyDeviceToHost(bool async = false) throw (OpenCLError);
	void dumpDeviceToDisk() throw (OpenCLError);

	// OpenCL
	inline void setCLContext(cl::Context * context);
	inline void setCLQueue(cl::CommandQueue * queue);

	// Access host data
	inline T * getHostData();
	inline T * getHostDataAt(long long unsigned int startingPoint);
	inline void * getRawHostData();
	inline void * getRawHostDataAt(long long unsigned int startingPoint);
	inline size_t getHostDataSize() const;
	inline const T operator[](long long unsigned int item) const;
	inline const T getHostDataItem(long long unsigned int item) const;

	// Access device data
	inline cl::Buffer * getDeviceData();
	inline size_t getDeviceDataSize() const;

	// Timers
	inline Timer & getH2DTimer();
	inline Timer & getD2HTimer();

private:
	cl::Context * clContext;
	cl::CommandQueue * clQueue;
	Timer timerH2D;
	Timer timerD2H;

	bool deleteHost;
	bool deviceReadOnly;
	bool deviceWriteOnly;
	T * hostData;
	size_t hostDataSize;
	cl::Buffer * deviceData;
	size_t deviceDataSize;

	string name;
};

// Implementations

template< typename T > CLData< T >::CLData(string name, bool deletePolicy) : clContext(0), clQueue(0), timerH2D(Timer("H2D")), timerD2H(Timer("D2H")), deleteHost(deletePolicy), deviceReadOnly(false), deviceWriteOnly(false), hostData(0), hostDataSize(0), deviceData(0), deviceDataSize(0), name(name) {}

template< typename T > CLData< T >::~CLData() {
	deleteHostData();
	deleteDeviceData();
}

template< typename T > void CLData< T >::allocateHostData(T * data, size_t size) {
	deleteHostData();

	hostData = data;
	hostDataSize = size;
}

template< typename T > void CLData< T >::allocateHostData(long long unsigned int nrElements) {
	size_t newSize = nrElements * sizeof(T);

	if ( newSize != hostDataSize ) {
		deleteHostData();

		hostData = new T [nrElements];
		hostDataSize = newSize;
	}
	memset(getRawHostData(), 0, newSize);
}

template< typename T > void CLData< T >::deleteHostData() {
	if ( deleteHost && hostDataSize != 0 ) {
		delete [] hostData;
		hostData = 0;
		hostDataSize = 0;
	}
}

template< typename T > void CLData< T >::allocateDeviceData(cl::Buffer * data, size_t size) {
	deleteDeviceData();

	deviceData = data;
	deviceDataSize = size;
}

template< typename T > void CLData< T >::allocateDeviceData(long long unsigned int nrElements) throw (OpenCLError) {
	size_t newSize = nrElements * sizeof(T);
	if ( newSize != deviceDataSize ) {
		deleteDeviceData();

		try {
			if ( deviceReadOnly ) {
				deviceData = new cl::Buffer(*clContext, CL_MEM_READ_ONLY, newSize, NULL, NULL);
			} else if ( deviceWriteOnly ) {
				deviceData = new cl::Buffer(*clContext, CL_MEM_WRITE_ONLY, newSize, NULL, NULL);
			} else {
				deviceData = new cl::Buffer(*clContext, CL_MEM_READ_WRITE, newSize, NULL, NULL);
			}
		} catch ( cl::Error err ) {
			deviceDataSize = 0;
			throw  OpenCLError("Impossible to allocate " + name + " device memory: " + toStringValue< cl_int >(err.err()));
		}
		deviceDataSize = newSize;
	}
}

template< typename T > void CLData< T >::allocateDeviceData() throw (OpenCLError) {
	deleteDeviceData();

	try {
		if ( deviceReadOnly ) {
			deviceData = new cl::Buffer(*clContext, CL_MEM_READ_ONLY, hostDataSize, NULL, NULL);
		} else if ( deviceWriteOnly ) {
			deviceData = new cl::Buffer(*clContext, CL_MEM_WRITE_ONLY, hostDataSize, NULL, NULL);
		} else {
			deviceData = new cl::Buffer(*clContext, CL_MEM_READ_WRITE, hostDataSize, NULL, NULL);
		}
	} catch ( cl::Error err ) {
		deviceDataSize = 0;
		throw  OpenCLError("Impossible to allocate " + name + " device memory: " + toStringValue< cl_int >(err.err()));
	}
	deviceDataSize = hostDataSize;
}

template< typename T > void CLData< T >::allocateSharedDeviceData() throw (OpenCLError) {
	deleteDeviceData();

	try {
		if ( deviceReadOnly ) {
			deviceData = new cl::Buffer(*clContext, CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY, hostDataSize, getRawHostData(), NULL);
		} else if ( deviceWriteOnly ) {
			deviceData = new cl::Buffer(*clContext, CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY, hostDataSize, getRawHostData(), NULL);
		} else {
			deviceData = new cl::Buffer(*clContext, CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE, hostDataSize, getRawHostData(), NULL);
		}
	} catch ( cl::Error err ) {
		deviceDataSize = 0;
		throw  OpenCLError("Impossible to allocate " + name + " device memory: " + toStringValue< cl_int >(err.err()));
	}
	deviceDataSize = hostDataSize;
}

template< typename T > void CLData< T >::deleteDeviceData() {
	if ( deviceDataSize != 0 ) {
		delete deviceData;
		deviceData = 0;
		deviceDataSize = 0;
	}
}

template< typename T > inline void CLData< T >::setDeviceReadOnly() {
	deviceReadOnly = true;
	deviceWriteOnly = false;
}

template< typename T > inline void CLData< T >::setDeviceWriteOnly() {
	deviceWriteOnly = true;
	deviceReadOnly = false;
}

template< typename T > void CLData< T >::copyHostToDevice(bool async) throw (OpenCLError) {
	if ( hostDataSize != deviceDataSize ) {
		throw OpenCLError("Impossible to copy " + name + ": different memory sizes.");
	}

	if ( async ) {
		try {
			clQueue->enqueueWriteBuffer(*deviceData, CL_FALSE, 0, deviceDataSize, getRawHostData(), NULL, NULL);
		} catch ( cl::Error err ) {
			throw OpenCLError("Impossible to copy " + name + " to device: " + toStringValue< cl_int >(err.err()));
		}
	}
	else {
		cl::Event clEvent;

		try {
			timerH2D.start();
			clQueue->enqueueWriteBuffer(*deviceData, CL_TRUE, 0, deviceDataSize, getRawHostData(), NULL, &clEvent);
			clEvent.wait();
			timerH2D.stop();
		} catch ( cl::Error err ) {
			timerH2D.reset();
			throw OpenCLError("Impossible to copy " + name + " to device: " + toStringValue< cl_int >(err.err()));
		}
	}
}

template< typename T > void CLData< T >::copyDeviceToHost(bool async) throw (OpenCLError) {
	if ( hostDataSize != deviceDataSize ) {
		throw OpenCLError("Impossible to copy " + name + ": different memory sizes.");
	}

	if ( async ) {
		try {
			clQueue->enqueueReadBuffer(*deviceData, CL_FALSE, 0, hostDataSize, getRawHostData(), NULL, NULL);
		} catch ( cl::Error err ) {
			throw OpenCLError("Impossible to copy " + name + " to host: " + toStringValue< cl_int >(err.err()));
		}
	}
	else {
		cl::Event clEvent;

		try {
			timerD2H.start();
			clQueue->enqueueReadBuffer(*deviceData, CL_TRUE, 0, hostDataSize, getRawHostData(), NULL, &clEvent);
			clEvent.wait();
			timerD2H.stop();
		} catch ( cl::Error err ) {
			timerD2H.reset();
			throw OpenCLError("Impossible to copy " + name + " to host: " + toStringValue< cl_int >(err.err()));
		}
	}

}

template< typename T > void CLData< T >::dumpDeviceToDisk() throw (OpenCLError) {
	CLData< T > temp = CLData< T >("temp", true);

	temp.setCLContext(clContext);
	temp.setCLQueue(clQueue);
	temp.allocateHostData(hostDataSize / sizeof(T));
	temp.allocateDeviceData(deviceData, deviceDataSize);
	temp.copyDeviceToHost();

	ofstream oFile(("./" + name + ".bin").c_str(), ofstream::binary);
	oFile.write(reinterpret_cast< char * >(temp.getRawHostData()), temp.getHostDataSize());
	oFile.close();
}

template< typename T > inline void CLData< T >::setCLContext(cl::Context * context) {
	clContext = context;
}

template< typename T > inline void CLData< T >::setCLQueue(cl::CommandQueue * queue) {
	clQueue = queue;
}

template< typename T > inline T * CLData< T >::getHostData() {
	return hostData;
}

template< typename T > inline T * CLData< T >::getHostDataAt(long long unsigned int startingPoint) {
	return &(hostData[startingPoint]);
}

template< typename T > inline void * CLData< T >::getRawHostData() {
	return reinterpret_cast< void * >(hostData);
}

template< typename T > inline void * CLData< T >::getRawHostDataAt(long long unsigned int startingPoint) {
	return reinterpret_cast< void * >(&(hostData[startingPoint]));
}

template< typename T > inline size_t CLData< T >::getHostDataSize() const {
	return hostDataSize;
}

template< typename T > inline const T CLData< T >::operator[](long long unsigned int item) const {
	return hostData[item];
}

template< typename T > inline const T CLData< T >::getHostDataItem(long long unsigned int item) const {
	return hostData[item];
}

template< typename T > inline cl::Buffer * CLData< T >::getDeviceData() {
	return deviceData;
}

template< typename T > inline size_t CLData< T >::getDeviceDataSize() const {
	return deviceDataSize;
}

template< typename T > inline string CLData< T >::getName() const {
	return name;
}

template< typename T > inline Timer & CLData< T >::getH2DTimer() {
	return timerH2D;
}

template< typename T > inline Timer & CLData< T >::getD2HTimer() {
	return timerD2H;
}

} // OpenCL
} // isa

#endif // CL_DATA_HPP
<|endoftext|>


<commit_before>#define BOOST_TEST_MODULE
#include <boost/test/included/unit_test.hpp>

#include "test_servers.hpp"

static const char name[] = "Test Name";

typedef bluetoe::extend_server<
    small_temperature_service,
    bluetoe::server_name< name >
> named_temperature_service;

BOOST_AUTO_TEST_CASE( named_server )
{
    std::uint8_t buffer[ 100 ];
    named_temperature_service service;

    static const std::uint8_t expected_advertising[] = {
        0x02, 0x01, 0x06,
        0x0A, 0x09, 'T', 'e', 's', 't', ' ', 'N', 'a', 'm', 'e'
    };

    const std::size_t size = service.advertising_data( buffer, sizeof( buffer ) );

    BOOST_CHECK_EQUAL_COLLECTIONS( std::begin( buffer ), std::begin( buffer ) + size, std::begin( expected_advertising ), std::end( expected_advertising ) );
}

BOOST_AUTO_TEST_CASE( short_named_server )
{
    std::uint8_t buffer[ 10 ];
    named_temperature_service service;

    static const std::uint8_t expected_advertising[] = {
        0x02, 0x01, 0x06,
        0x06, 0x08, 'T', 'e', 's', 't', ' '
    };

    const std::size_t size = service.advertising_data( buffer, sizeof( buffer ) );

    BOOST_CHECK_EQUAL_COLLECTIONS( std::begin( buffer ), std::begin( buffer ) + size, std::begin( expected_advertising ), std::end( expected_advertising ) );
}

BOOST_AUTO_TEST_CASE( unnamed_server )
{
    std::uint8_t buffer[ 31 ];
    small_temperature_service service;

    static const std::uint8_t expected_advertising[] = {
        0x02, 0x01, 0x06
    };

    const std::size_t size = service.advertising_data( buffer, sizeof( buffer ) );

    BOOST_CHECK_EQUAL_COLLECTIONS( std::begin( buffer ), std::begin( buffer ) + size, std::begin( expected_advertising ), std::end( expected_advertising ) );
}
<commit_msg>change advertising tests to reflect the addition two zero bytes<commit_after>#define BOOST_TEST_MODULE
#include <boost/test/included/unit_test.hpp>

#include "test_servers.hpp"

static const char name[] = "Test Name";

typedef bluetoe::extend_server<
    small_temperature_service,
    bluetoe::server_name< name >
> named_temperature_service;

BOOST_FIXTURE_TEST_CASE( named_server, named_temperature_service )
{
    std::uint8_t buffer[ 100 ];

    static const std::uint8_t expected_advertising[] = {
        0x02, 0x01, 0x06,
        0x0A, 0x09, 'T', 'e', 's', 't', ' ', 'N', 'a', 'm', 'e',
        0x00, 0x00
    };

    const std::size_t size = advertising_data( buffer, sizeof( buffer ) );

    BOOST_CHECK_EQUAL_COLLECTIONS( std::begin( buffer ), std::begin( buffer ) + size, std::begin( expected_advertising ), std::end( expected_advertising ) );
}

BOOST_FIXTURE_TEST_CASE( short_named_server, named_temperature_service )
{
    std::uint8_t buffer[ 10 ];

    static const std::uint8_t expected_advertising[] = {
        0x02, 0x01, 0x06,
        0x06, 0x08, 'T', 'e', 's', 't', ' '
    };

    const std::size_t size = advertising_data( buffer, sizeof( buffer ) );
    BOOST_CHECK_EQUAL_COLLECTIONS( std::begin( buffer ), std::begin( buffer ) + size, std::begin( expected_advertising ), std::end( expected_advertising ) );
}

BOOST_FIXTURE_TEST_CASE( unnamed_server, small_temperature_service )
{
    std::uint8_t buffer[ 31 ];

    static const std::uint8_t expected_advertising[] = {
        0x02, 0x01, 0x06, 0x00, 0x00
    };

    const std::size_t size = advertising_data( buffer, sizeof( buffer ) );

    BOOST_CHECK_EQUAL_COLLECTIONS( std::begin( buffer ), std::begin( buffer ) + size, std::begin( expected_advertising ), std::end( expected_advertising ) );
}
<|endoftext|>


<commit_before>/***********************************************************************
    filename:   GL3Parameter.cpp
    created:    18th July 2013
    author:     Lukas Meindl
*************************************************************************/
/***************************************************************************
 *   Copyright (C) 2004 - 2013 Paul D Turner & The CEGUI Development Team
 *
 *   Permission is hereby granted, free of charge, to any person obtaining
 *   a copy of this software and associated documentation files (the
 *   "Software"), to deal in the Software without restriction, including
 *   without limitation the rights to use, copy, modify, merge, publish,
 *   distribute, sublicense, and/or sell copies of the Software, and to
 *   permit persons to whom the Software is furnished to do so, subject to
 *   the following conditions:
 *
 *   The above copyright notice and this permission notice shall be
 *   included in all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *   OTHER DEALINGS IN THE SOFTWARE.
 ***************************************************************************/

#include <GL/glew.h>
#include "CEGUI/RendererModules/OpenGL/GL3ShaderParameter.h"

#include "glm/glm.hpp"

// Start of CEGUI namespace section
namespace CEGUI
{
//----------------------------------------------------------------------------//
OpenGL3ShaderParameterFloat::OpenGL3ShaderParameterFloat(float parameterValue)
     : ShaderParameterFloat(parameterValue)
{
}

//----------------------------------------------------------------------------//
void OpenGL3ShaderParameterFloat::applyParameter(Shader* shader) const
{

}

//----------------------------------------------------------------------------//

} // End of  CEGUI namespace section

<commit_msg>FIX: Remove unused file<commit_after><|endoftext|>