<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef WITHOUT_GPU_BACKEND

#include "top.hpp"
#include "os/os.hpp"
#include "device/device.hpp"
#include "rocsettings.hpp"
#include "device/rocm/rocglinterop.hpp"

namespace roc {

Settings::Settings() {
  // Initialize the HSA device default settings

  // Set this to true when we drop the flag
  doublePrecision_ = ::CL_KHR_FP64;
  pollCompletion_ = ENVVAR_HSA_POLL_KERNEL_COMPLETION;

  enableLocalMemory_ = HSA_LOCAL_MEMORY_ENABLE;
  enableImageHandle_ = true;

  maxWorkGroupSize_ = 1024;
  preferredWorkGroupSize_ = 256;

  maxWorkGroupSize2DX_ = 16;
  maxWorkGroupSize2DY_ = 16;
  maxWorkGroupSize3DX_ = 4;
  maxWorkGroupSize3DY_ = 4;
  maxWorkGroupSize3DZ_ = 4;

  kernargPoolSize_ = HSA_KERNARG_POOL_SIZE;
  signalPoolSize_ = HSA_SIGNAL_POOL_SIZE;

  // Determine if user is requesting Non-Coherent mode
  // for system memory. By default system memory is
  // operates or is programmed to be in Coherent mode.
  // Users can turn it off for hardware that does not
  // support this feature naturally
  char* nonCoherentMode = nullptr;
  nonCoherentMode = getenv("OPENCL_USE_NC_MEMORY_POLICY");
  enableNCMode_ = (nonCoherentMode) ? true : false;

  // Determine if user wishes to disable support for
  // partial dispatch. By default support for partial
  // dispatch is enabled. Users can turn it off for
  // devices that do not support this feature.
  //
  // @note Update appropriate field of device::Settings
  char* partialDispatch = nullptr;
  partialDispatch = getenv("OPENCL_DISABLE_PARTIAL_DISPATCH");
  enablePartialDispatch_ = (partialDispatch) ? false : true;
  partialDispatch_ = (partialDispatch) ? false : true;
  commandQueues_ = 100;  //!< Field value set to maximum number
                         //!< concurrent Virtual GPUs for ROCm backend

  // Disable image DMA by default (ROCM runtime doesn't support it)
  imageDMA_ = false;

  stagedXferRead_ = true;
  stagedXferWrite_ = true;
  stagedXferSize_ = GPU_STAGING_BUFFER_SIZE * Ki;

  // Initialize transfer buffer size to 1MB by default
  xferBufSize_ = 1024 * Ki;

  const static size_t MaxPinnedXferSize = 32;
  pinnedXferSize_ = std::min(GPU_PINNED_XFER_SIZE, MaxPinnedXferSize) * Mi;
  pinnedMinXferSize_ = std::min(GPU_PINNED_MIN_XFER_SIZE * Ki, pinnedXferSize_);

  // Don't support Denormals for single precision by default
  singleFpDenorm_ = false;
}

bool Settings::create(bool fullProfile, int gfxipVersion) {
  customHostAllocator_ = false;

  if (fullProfile) {
    pinnedXferSize_ = 0;
    stagedXferSize_ = 0;
    xferBufSize_ = 0;
  } else {
    pinnedXferSize_ = std::max(pinnedXferSize_, pinnedMinXferSize_);
    stagedXferSize_ = std::max(stagedXferSize_, pinnedMinXferSize_ + 4 * Ki);
  }

  // Enable extensions
  enableExtension(ClKhrByteAddressableStore);
  enableExtension(ClKhrGlobalInt32BaseAtomics);
  enableExtension(ClKhrGlobalInt32ExtendedAtomics);
  enableExtension(ClKhrLocalInt32BaseAtomics);
  enableExtension(ClKhrLocalInt32ExtendedAtomics);
  enableExtension(ClKhrInt64BaseAtomics);
  enableExtension(ClKhrInt64ExtendedAtomics);
  enableExtension(ClKhr3DImageWrites);
  enableExtension(ClAmdMediaOps);
  enableExtension(ClAmdMediaOps2);
  enableExtension(ClAMDLiquidFlash);
  if (MesaInterop::Supported()) {
    enableExtension(ClKhrGlSharing);
  }
  // Enable platform extension
  enableExtension(ClAmdDeviceAttributeQuery);

  // Enable KHR double precision extension
  enableExtension(ClKhrFp64);
#if !defined(WITH_LIGHTNING_COMPILER)
  // Also enable AMD double precision extension?
  enableExtension(ClAmdFp64);
#endif  // !defined(WITH_LIGHTNING_COMPILER)
  enableExtension(ClKhrSubGroups);
  enableExtension(ClKhrDepthImages);
  enableExtension(ClAmdCopyBufferP2P);
  enableExtension(ClKhrFp16);
  supportDepthsRGB_ = true;

#if defined(WITH_LIGHTNING_COMPILER)
  switch (gfxipVersion) {
    case 900:
      singleFpDenorm_ = true;
      break;
  }
#endif  // WITH_LIGHTNING_COMPILER

  // Override current device settings
  override();

  return true;
}

void Settings::override() {
  // Limit reported workgroup size
  if (GPU_MAX_WORKGROUP_SIZE != 0) {
    preferredWorkGroupSize_ = GPU_MAX_WORKGROUP_SIZE;
  }

  if (!flagIsDefault(GPU_MAX_COMMAND_QUEUES)) {
    commandQueues_ = GPU_MAX_COMMAND_QUEUES;
  }

  if (!flagIsDefault(GPU_IMAGE_DMA)) {
    commandQueues_ = GPU_IMAGE_DMA;
  }

  if (!flagIsDefault(GPU_XFER_BUFFER_SIZE)) {
    xferBufSize_ = GPU_XFER_BUFFER_SIZE * Ki;
  }

  if (!flagIsDefault(GPU_PINNED_MIN_XFER_SIZE)) {
    pinnedMinXferSize_ = std::min(GPU_PINNED_MIN_XFER_SIZE * Ki, pinnedXferSize_);
  }

  if (!flagIsDefault(AMD_GPU_FORCE_SINGLE_FP_DENORM)) {
    switch (AMD_GPU_FORCE_SINGLE_FP_DENORM) {
      case 0:
        singleFpDenorm_ = false;
        break;
      case 1:
        singleFpDenorm_ = true;
        break;
      default:
        break;
    }
  }
}

}  // namespace roc

#endif  // WITHOUT_GPU_BACKEND
<commit_msg>P4 to Git Change 1479658 by gandryey@gera-w8 on 2017/11/07 13:52:17<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef WITHOUT_GPU_BACKEND

#include "top.hpp"
#include "os/os.hpp"
#include "device/device.hpp"
#include "rocsettings.hpp"
#include "device/rocm/rocglinterop.hpp"

namespace roc {

Settings::Settings() {
  // Initialize the HSA device default settings

  // Set this to true when we drop the flag
  doublePrecision_ = ::CL_KHR_FP64;
  pollCompletion_ = ENVVAR_HSA_POLL_KERNEL_COMPLETION;

  enableLocalMemory_ = HSA_LOCAL_MEMORY_ENABLE;
  enableImageHandle_ = true;

  maxWorkGroupSize_ = 1024;
  preferredWorkGroupSize_ = 256;

  maxWorkGroupSize2DX_ = 16;
  maxWorkGroupSize2DY_ = 16;
  maxWorkGroupSize3DX_ = 4;
  maxWorkGroupSize3DY_ = 4;
  maxWorkGroupSize3DZ_ = 4;

  kernargPoolSize_ = HSA_KERNARG_POOL_SIZE;
  signalPoolSize_ = HSA_SIGNAL_POOL_SIZE;

  // Determine if user is requesting Non-Coherent mode
  // for system memory. By default system memory is
  // operates or is programmed to be in Coherent mode.
  // Users can turn it off for hardware that does not
  // support this feature naturally
  char* nonCoherentMode = nullptr;
  nonCoherentMode = getenv("OPENCL_USE_NC_MEMORY_POLICY");
  enableNCMode_ = (nonCoherentMode) ? true : false;

  // Determine if user wishes to disable support for
  // partial dispatch. By default support for partial
  // dispatch is enabled. Users can turn it off for
  // devices that do not support this feature.
  //
  // @note Update appropriate field of device::Settings
  char* partialDispatch = nullptr;
  partialDispatch = getenv("OPENCL_DISABLE_PARTIAL_DISPATCH");
  enablePartialDispatch_ = (partialDispatch) ? false : true;
  partialDispatch_ = (partialDispatch) ? false : true;
  commandQueues_ = 100;  //!< Field value set to maximum number
                         //!< concurrent Virtual GPUs for ROCm backend

  // Disable image DMA by default (ROCM runtime doesn't support it)
  imageDMA_ = false;

  stagedXferRead_ = true;
  stagedXferWrite_ = true;
  stagedXferSize_ = GPU_STAGING_BUFFER_SIZE * Ki;

  // Initialize transfer buffer size to 1MB by default
  xferBufSize_ = 1024 * Ki;

  const static size_t MaxPinnedXferSize = 32;
  pinnedXferSize_ = std::min(GPU_PINNED_XFER_SIZE, MaxPinnedXferSize) * Mi;
  pinnedMinXferSize_ = std::min(GPU_PINNED_MIN_XFER_SIZE * Ki, pinnedXferSize_);

  // Don't support Denormals for single precision by default
  singleFpDenorm_ = false;
}

bool Settings::create(bool fullProfile, int gfxipVersion) {
  customHostAllocator_ = false;

  if (fullProfile) {
    pinnedXferSize_ = 0;
    stagedXferSize_ = 0;
    xferBufSize_ = 0;
  } else {
    pinnedXferSize_ = std::max(pinnedXferSize_, pinnedMinXferSize_);
    stagedXferSize_ = std::max(stagedXferSize_, pinnedMinXferSize_ + 4 * Ki);
  }

  // Enable extensions
  enableExtension(ClKhrByteAddressableStore);
  enableExtension(ClKhrGlobalInt32BaseAtomics);
  enableExtension(ClKhrGlobalInt32ExtendedAtomics);
  enableExtension(ClKhrLocalInt32BaseAtomics);
  enableExtension(ClKhrLocalInt32ExtendedAtomics);
  enableExtension(ClKhrInt64BaseAtomics);
  enableExtension(ClKhrInt64ExtendedAtomics);
  enableExtension(ClKhr3DImageWrites);
  enableExtension(ClAmdMediaOps);
  enableExtension(ClAmdMediaOps2);
  if (MesaInterop::Supported()) {
    enableExtension(ClKhrGlSharing);
  }
  // Enable platform extension
  enableExtension(ClAmdDeviceAttributeQuery);

  // Enable KHR double precision extension
  enableExtension(ClKhrFp64);
#if !defined(WITH_LIGHTNING_COMPILER)
  // Also enable AMD double precision extension?
  enableExtension(ClAmdFp64);
#endif  // !defined(WITH_LIGHTNING_COMPILER)
  enableExtension(ClKhrSubGroups);
  enableExtension(ClKhrDepthImages);
  enableExtension(ClAmdCopyBufferP2P);
  enableExtension(ClKhrFp16);
  supportDepthsRGB_ = true;

#if defined(WITH_LIGHTNING_COMPILER)
  switch (gfxipVersion) {
    case 900:
      singleFpDenorm_ = true;
      break;
  }
#endif  // WITH_LIGHTNING_COMPILER

  // Override current device settings
  override();

  return true;
}

void Settings::override() {
  // Limit reported workgroup size
  if (GPU_MAX_WORKGROUP_SIZE != 0) {
    preferredWorkGroupSize_ = GPU_MAX_WORKGROUP_SIZE;
  }

  if (!flagIsDefault(GPU_MAX_COMMAND_QUEUES)) {
    commandQueues_ = GPU_MAX_COMMAND_QUEUES;
  }

  if (!flagIsDefault(GPU_IMAGE_DMA)) {
    commandQueues_ = GPU_IMAGE_DMA;
  }

  if (!flagIsDefault(GPU_XFER_BUFFER_SIZE)) {
    xferBufSize_ = GPU_XFER_BUFFER_SIZE * Ki;
  }

  if (!flagIsDefault(GPU_PINNED_MIN_XFER_SIZE)) {
    pinnedMinXferSize_ = std::min(GPU_PINNED_MIN_XFER_SIZE * Ki, pinnedXferSize_);
  }

  if (!flagIsDefault(AMD_GPU_FORCE_SINGLE_FP_DENORM)) {
    switch (AMD_GPU_FORCE_SINGLE_FP_DENORM) {
      case 0:
        singleFpDenorm_ = false;
        break;
      case 1:
        singleFpDenorm_ = true;
        break;
      default:
        break;
    }
  }
}

}  // namespace roc

#endif  // WITHOUT_GPU_BACKEND
<|endoftext|>


<commit_before>// Copyright © 2014, German Neuroinformatics Node (G-Node)
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted under the terms of the BSD License. See
// LICENSE file in the root of the Project.
//
// Author: Christian Kellner <kellner@bio.lmu.de>

#ifndef NIX_DATATYPE_H
#define NIX_DATATYPE_H

#include <cstdint>
#include <ostream>

#include <nix/Platform.hpp>

namespace nix {

/**
 * @brief Enumeration providing constants for all valid data types.
 *
 * Those data types are used by {@link nix::DataArray} and {@link nix::Property}
 * in order to indicate of what type the stored data of value is.
 */
NIXAPI enum class DataType {
    Bool,
    Char,
    Float,
    Double,
    Int8,
    Int16,
    Int32,
    Int64,
    UInt8,
    UInt16,
    UInt32,
    UInt64,
    String,
    Date,
    DateTime,

    Nothing = -1
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<typename T>
struct to_data_type {
    static const bool is_valid = false;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<bool> {
    static const bool is_valid = true;
    static const DataType value = DataType::Bool;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<char> {
    static const bool is_valid = true;
    static const DataType value = DataType::Char;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<float> {
    static const bool is_valid = true;
    static const DataType value = DataType::Float;
};

/**
 * @brief Determine if a type is a valid data type.
 *
 * @internal
 */
template<>
struct to_data_type<double> {
    static const bool is_valid = true;
    static const DataType value = DataType::Double;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<int8_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::Int8;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<uint8_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::UInt8;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<int16_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::Int16;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<uint16_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::UInt16;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<int32_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::Int32;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<uint32_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::UInt32;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<int64_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::Int64;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<uint64_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::UInt64;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<std::string> {
    static const bool is_valid = true;
    static const DataType value = DataType::String;
};

/**
 * @brief Determine the size of a data type.
 *
 * @param dtype         The data type.
 *
 * @return The size of the type.
 */
NIXAPI size_t data_type_to_size(DataType dtype);

/**
 * @brief Convert a data type into string representation.
 *
 * @param dtype         The data type.
 *
 * @return A human readable name for the given type.
 */
NIXAPI std::string data_type_to_string(DataType dtype);

/**
 * @brief Output operator for data type.
 *
 * Prints a human readable string representation of the
 * data type to an output stream.
 *
 * @param out           The output stream.
 * @param dtype         The data type to print.
 *
 * @return The output stream.
 */
NIXAPI std::ostream& operator<<(std::ostream &out, const DataType dtype);

} // nix::

#endif
<commit_msg>DataType: Add "Opaque" type<commit_after>// Copyright © 2014, German Neuroinformatics Node (G-Node)
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted under the terms of the BSD License. See
// LICENSE file in the root of the Project.
//
// Author: Christian Kellner <kellner@bio.lmu.de>

#ifndef NIX_DATATYPE_H
#define NIX_DATATYPE_H

#include <cstdint>
#include <ostream>

#include <nix/Platform.hpp>

namespace nix {

/**
 * @brief Enumeration providing constants for all valid data types.
 *
 * Those data types are used by {@link nix::DataArray} and {@link nix::Property}
 * in order to indicate of what type the stored data of value is.
 */
NIXAPI enum class DataType {
    Bool,
    Char,
    Float,
    Double,
    Int8,
    Int16,
    Int32,
    Int64,
    UInt8,
    UInt16,
    UInt32,
    UInt64,
    String,
    Date,
    DateTime,
    Opaque,

    Nothing = -1
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<typename T>
struct to_data_type {
    static const bool is_valid = false;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<bool> {
    static const bool is_valid = true;
    static const DataType value = DataType::Bool;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<char> {
    static const bool is_valid = true;
    static const DataType value = DataType::Char;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<float> {
    static const bool is_valid = true;
    static const DataType value = DataType::Float;
};

/**
 * @brief Determine if a type is a valid data type.
 *
 * @internal
 */
template<>
struct to_data_type<double> {
    static const bool is_valid = true;
    static const DataType value = DataType::Double;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<int8_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::Int8;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<uint8_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::UInt8;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<int16_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::Int16;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<uint16_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::UInt16;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<int32_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::Int32;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<uint32_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::UInt32;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<int64_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::Int64;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<uint64_t> {
    static const bool is_valid = true;
    static const DataType value = DataType::UInt64;
};

/**
 * @brief Determine if a type is a valid data type.
 */
template<>
struct to_data_type<std::string> {
    static const bool is_valid = true;
    static const DataType value = DataType::String;
};

/**
 * @brief Determine the size of a data type.
 *
 * @param dtype         The data type.
 *
 * @return The size of the type.
 */
NIXAPI size_t data_type_to_size(DataType dtype);

/**
 * @brief Convert a data type into string representation.
 *
 * @param dtype         The data type.
 *
 * @return A human readable name for the given type.
 */
NIXAPI std::string data_type_to_string(DataType dtype);

/**
 * @brief Output operator for data type.
 *
 * Prints a human readable string representation of the
 * data type to an output stream.
 *
 * @param out           The output stream.
 * @param dtype         The data type to print.
 *
 * @return The output stream.
 */
NIXAPI std::ostream& operator<<(std::ostream &out, const DataType dtype);

} // nix::

#endif
<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SVL_ITEMPROP_HXX
#define INCLUDED_SVL_ITEMPROP_HXX

#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/beans/PropertyState.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <cppuhelper/implbase1.hxx>
#include <svl/itemset.hxx>
#include <svl/svldllapi.h>
#include <vector>

struct SfxItemPropertyMapEntry
{
    OUString                            aName;
    sal_uInt16                          nWID;
    com::sun::star::uno::Type           aType;
    long                                nFlags;
    sal_uInt8                           nMemberId;

};

struct SfxItemPropertySimpleEntry
{
    sal_uInt16                          nWID;
    com::sun::star::uno::Type           aType;
    long                                nFlags;
    sal_uInt8                           nMemberId;

    SfxItemPropertySimpleEntry()
        : nWID( 0 )
        , nFlags( 0 )
        , nMemberId( 0 )
        {
        }

    SfxItemPropertySimpleEntry(sal_uInt16 _nWID, com::sun::star::uno::Type const & _rType,
                               long _nFlags, sal_uInt8 _nMemberId)
        : nWID(      _nWID )
        , aType(     _rType )
        , nFlags(    _nFlags )
        , nMemberId( _nMemberId )
        {
        }

    SfxItemPropertySimpleEntry( const SfxItemPropertyMapEntry* pMapEntry )
        : nWID( pMapEntry->nWID )
        , aType( pMapEntry->aType )
        , nFlags( pMapEntry->nFlags )
        , nMemberId( pMapEntry->nMemberId )
        {
        }

};
struct SfxItemPropertyNamedEntry : public SfxItemPropertySimpleEntry
{
    OUString sName;
    SfxItemPropertyNamedEntry( const OUString& rName, const SfxItemPropertySimpleEntry& rSimpleEntry)
        : SfxItemPropertySimpleEntry( rSimpleEntry )
        , sName( rName )
{
}

};
typedef std::vector< SfxItemPropertyNamedEntry > PropertyEntryVector_t;
class SfxItemPropertyMap_Impl;
class SVL_DLLPUBLIC SfxItemPropertyMap
{
    SfxItemPropertyMap_Impl* m_pImpl;
public:
    SfxItemPropertyMap( const SfxItemPropertyMapEntry* pEntries );
    SfxItemPropertyMap( const SfxItemPropertyMap& rSource );
    ~SfxItemPropertyMap();

    const SfxItemPropertySimpleEntry*  getByName( const OUString &rName ) const;
    com::sun::star::uno::Sequence< com::sun::star::beans::Property > getProperties() const;
    com::sun::star::beans::Property getPropertyByName( const OUString & rName ) const
        throw( ::com::sun::star::beans::UnknownPropertyException );
    bool hasPropertyByName( const OUString& rName ) const;

    void mergeProperties( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& rPropSeq );
    PropertyEntryVector_t getPropertyEntries() const;
    sal_uInt32 getSize() const;

};

class SVL_DLLPUBLIC SfxItemPropertySet
{
    SfxItemPropertyMap                                                              m_aMap;
    mutable com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo> m_xInfo;

public:
                            SfxItemPropertySet( const SfxItemPropertyMapEntry *pMap ) :
                                m_aMap(pMap) {}
                            virtual ~SfxItemPropertySet();

    void getPropertyValue( const SfxItemPropertySimpleEntry& rEntry,
                                          const SfxItemSet& rSet,
                                          com::sun::star::uno::Any& rAny) const
                                          throw(::com::sun::star::uno::RuntimeException);
    void getPropertyValue( const OUString &rName,
                                            const SfxItemSet& rSet,
                                            com::sun::star::uno::Any& rAny) const
                                            throw(::com::sun::star::uno::RuntimeException,
                                                    ::com::sun::star::beans::UnknownPropertyException);
    com::sun::star::uno::Any
        getPropertyValue( const OUString &rName,
                                            const SfxItemSet& rSet ) const
                                            throw(::com::sun::star::uno::RuntimeException,
                                                    ::com::sun::star::beans::UnknownPropertyException);
    void                setPropertyValue( const SfxItemPropertySimpleEntry& rEntry,
                                          const com::sun::star::uno::Any& aVal,
                                          SfxItemSet& rSet ) const
                                          throw(::com::sun::star::uno::RuntimeException,
                                                  com::sun::star::lang::IllegalArgumentException);
    void                  setPropertyValue( const OUString& rPropertyName,
                                            const com::sun::star::uno::Any& aVal,
                                            SfxItemSet& rSet ) const
                                            throw(::com::sun::star::uno::RuntimeException,
                                                    com::sun::star::lang::IllegalArgumentException,
                                                    ::com::sun::star::beans::UnknownPropertyException);

    com::sun::star::beans::PropertyState
        getPropertyState(const OUString& rName, const SfxItemSet& rSet)const
                                    throw(com::sun::star::beans::UnknownPropertyException);
    com::sun::star::beans::PropertyState
        getPropertyState(const SfxItemPropertySimpleEntry& rEntry, const SfxItemSet& rSet) const
                                    throw();

    com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo>
        getPropertySetInfo() const;
    const SfxItemPropertyMap& getPropertyMap() const {return m_aMap;}
};

struct SfxItemPropertySetInfo_Impl;
class SVL_DLLPUBLIC SfxItemPropertySetInfo : public
    cppu::WeakImplHelper1<com::sun::star::beans::XPropertySetInfo>
{
    SfxItemPropertySetInfo_Impl* m_pImpl;

public:
    SfxItemPropertySetInfo(const SfxItemPropertyMap &rMap );
    SfxItemPropertySetInfo(const SfxItemPropertyMapEntry *pEntries );
    virtual ~SfxItemPropertySetInfo();

    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL
        getProperties(  )
            throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual ::com::sun::star::beans::Property SAL_CALL
        getPropertyByName( const OUString& aName )
            throw(::com::sun::star::beans::UnknownPropertyException,
                    ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual sal_Bool SAL_CALL
        hasPropertyByName( const OUString& Name )
            throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

};

class SVL_DLLPUBLIC SfxExtItemPropertySetInfo: public cppu::WeakImplHelper1<com::sun::star::beans::XPropertySetInfo >
{
    SfxItemPropertyMap aExtMap;
public:
                            SfxExtItemPropertySetInfo(
                                const SfxItemPropertyMapEntry *pMap,
                                const com::sun::star::uno::Sequence<com::sun::star::beans::Property>& rPropSeq );
                            virtual ~SfxExtItemPropertySetInfo();

    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL
        getProperties(  )
            throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual ::com::sun::star::beans::Property SAL_CALL
        getPropertyByName( const OUString& aName )
            throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual sal_Bool SAL_CALL
        hasPropertyByName( const OUString& Name )
            throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>svl: document SfxItemPropertyMapEntry<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SVL_ITEMPROP_HXX
#define INCLUDED_SVL_ITEMPROP_HXX

#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/beans/PropertyState.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <cppuhelper/implbase1.hxx>
#include <svl/itemset.hxx>
#include <svl/svldllapi.h>
#include <vector>

/// map a property between beans::XPropertySet and SfxPoolItem
struct SfxItemPropertyMapEntry
{
    OUString                            aName; ///< name of property
    sal_uInt16                          nWID;  ///< WhichId of SfxPoolItem
    com::sun::star::uno::Type           aType; ///< UNO type of property
    /// flag bitmap, @see com::sun::star::beans::PropertyAttribute
    long                                nFlags;
    /// "member ID" to tell QueryValue/PutValue which property it is
    /// (when multiple properties map to the same nWID)
    sal_uInt8                           nMemberId;

};

struct SfxItemPropertySimpleEntry
{
    sal_uInt16                          nWID;
    com::sun::star::uno::Type           aType;
    long                                nFlags;
    sal_uInt8                           nMemberId;

    SfxItemPropertySimpleEntry()
        : nWID( 0 )
        , nFlags( 0 )
        , nMemberId( 0 )
        {
        }

    SfxItemPropertySimpleEntry(sal_uInt16 _nWID, com::sun::star::uno::Type const & _rType,
                               long _nFlags, sal_uInt8 _nMemberId)
        : nWID(      _nWID )
        , aType(     _rType )
        , nFlags(    _nFlags )
        , nMemberId( _nMemberId )
        {
        }

    SfxItemPropertySimpleEntry( const SfxItemPropertyMapEntry* pMapEntry )
        : nWID( pMapEntry->nWID )
        , aType( pMapEntry->aType )
        , nFlags( pMapEntry->nFlags )
        , nMemberId( pMapEntry->nMemberId )
        {
        }

};
struct SfxItemPropertyNamedEntry : public SfxItemPropertySimpleEntry
{
    OUString sName;
    SfxItemPropertyNamedEntry( const OUString& rName, const SfxItemPropertySimpleEntry& rSimpleEntry)
        : SfxItemPropertySimpleEntry( rSimpleEntry )
        , sName( rName )
{
}

};
typedef std::vector< SfxItemPropertyNamedEntry > PropertyEntryVector_t;
class SfxItemPropertyMap_Impl;
class SVL_DLLPUBLIC SfxItemPropertyMap
{
    SfxItemPropertyMap_Impl* m_pImpl;
public:
    SfxItemPropertyMap( const SfxItemPropertyMapEntry* pEntries );
    SfxItemPropertyMap( const SfxItemPropertyMap& rSource );
    ~SfxItemPropertyMap();

    const SfxItemPropertySimpleEntry*  getByName( const OUString &rName ) const;
    com::sun::star::uno::Sequence< com::sun::star::beans::Property > getProperties() const;
    com::sun::star::beans::Property getPropertyByName( const OUString & rName ) const
        throw( ::com::sun::star::beans::UnknownPropertyException );
    bool hasPropertyByName( const OUString& rName ) const;

    void mergeProperties( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& rPropSeq );
    PropertyEntryVector_t getPropertyEntries() const;
    sal_uInt32 getSize() const;

};

class SVL_DLLPUBLIC SfxItemPropertySet
{
    SfxItemPropertyMap                                                              m_aMap;
    mutable com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo> m_xInfo;

public:
                            SfxItemPropertySet( const SfxItemPropertyMapEntry *pMap ) :
                                m_aMap(pMap) {}
                            virtual ~SfxItemPropertySet();

    void getPropertyValue( const SfxItemPropertySimpleEntry& rEntry,
                                          const SfxItemSet& rSet,
                                          com::sun::star::uno::Any& rAny) const
                                          throw(::com::sun::star::uno::RuntimeException);
    void getPropertyValue( const OUString &rName,
                                            const SfxItemSet& rSet,
                                            com::sun::star::uno::Any& rAny) const
                                            throw(::com::sun::star::uno::RuntimeException,
                                                    ::com::sun::star::beans::UnknownPropertyException);
    com::sun::star::uno::Any
        getPropertyValue( const OUString &rName,
                                            const SfxItemSet& rSet ) const
                                            throw(::com::sun::star::uno::RuntimeException,
                                                    ::com::sun::star::beans::UnknownPropertyException);
    void                setPropertyValue( const SfxItemPropertySimpleEntry& rEntry,
                                          const com::sun::star::uno::Any& aVal,
                                          SfxItemSet& rSet ) const
                                          throw(::com::sun::star::uno::RuntimeException,
                                                  com::sun::star::lang::IllegalArgumentException);
    void                  setPropertyValue( const OUString& rPropertyName,
                                            const com::sun::star::uno::Any& aVal,
                                            SfxItemSet& rSet ) const
                                            throw(::com::sun::star::uno::RuntimeException,
                                                    com::sun::star::lang::IllegalArgumentException,
                                                    ::com::sun::star::beans::UnknownPropertyException);

    com::sun::star::beans::PropertyState
        getPropertyState(const OUString& rName, const SfxItemSet& rSet)const
                                    throw(com::sun::star::beans::UnknownPropertyException);
    com::sun::star::beans::PropertyState
        getPropertyState(const SfxItemPropertySimpleEntry& rEntry, const SfxItemSet& rSet) const
                                    throw();

    com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo>
        getPropertySetInfo() const;
    const SfxItemPropertyMap& getPropertyMap() const {return m_aMap;}
};

struct SfxItemPropertySetInfo_Impl;
class SVL_DLLPUBLIC SfxItemPropertySetInfo : public
    cppu::WeakImplHelper1<com::sun::star::beans::XPropertySetInfo>
{
    SfxItemPropertySetInfo_Impl* m_pImpl;

public:
    SfxItemPropertySetInfo(const SfxItemPropertyMap &rMap );
    SfxItemPropertySetInfo(const SfxItemPropertyMapEntry *pEntries );
    virtual ~SfxItemPropertySetInfo();

    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL
        getProperties(  )
            throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual ::com::sun::star::beans::Property SAL_CALL
        getPropertyByName( const OUString& aName )
            throw(::com::sun::star::beans::UnknownPropertyException,
                    ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual sal_Bool SAL_CALL
        hasPropertyByName( const OUString& Name )
            throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

};

class SVL_DLLPUBLIC SfxExtItemPropertySetInfo: public cppu::WeakImplHelper1<com::sun::star::beans::XPropertySetInfo >
{
    SfxItemPropertyMap aExtMap;
public:
                            SfxExtItemPropertySetInfo(
                                const SfxItemPropertyMapEntry *pMap,
                                const com::sun::star::uno::Sequence<com::sun::star::beans::Property>& rPropSeq );
                            virtual ~SfxExtItemPropertySetInfo();

    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL
        getProperties(  )
            throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual ::com::sun::star::beans::Property SAL_CALL
        getPropertyByName( const OUString& aName )
            throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual sal_Bool SAL_CALL
        hasPropertyByName( const OUString& Name )
            throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
};

#endif

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


<commit_before>// Copyright (c) 2015-2018 Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/sequences/

#ifndef TAOCPP_SEQUENCES_INCLUDE_FOLD_HPP
#define TAOCPP_SEQUENCES_INCLUDE_FOLD_HPP

#include <type_traits>

#include "integer_sequence.hpp"
#include "make_integer_sequence.hpp"
#include "select.hpp"

namespace tao
{
   namespace seq
   {
      namespace impl
      {
         template< template< typename U, U, U > class, typename, bool, typename T, T... >
         struct folder;

         template< template< typename U, U, U > class OP, std::size_t... Is, typename T, T... Ns >
         struct folder< OP, index_sequence< Is... >, false, T, Ns... >
         {
            using type = integer_sequence< T, OP< T, seq::select< 2 * Is, T, Ns... >::value, seq::select< 2 * Is + 1, T, Ns... >::value >::value... >;
         };

         template< template< typename U, U, U > class OP, std::size_t... Is, typename T, T N, T... Ns >
         struct folder< OP, index_sequence< Is... >, true, T, N, Ns... >
         {
            using type = integer_sequence< T, N, OP< T, seq::select< 2 * Is, T, Ns... >::value, seq::select< 2 * Is + 1, T, Ns... >::value >::value... >;
         };

      }  // namespace impl

      template< template< typename U, U, U > class, typename T, T... >
      struct fold;

      template< template< typename U, U, U > class OP, typename T, T N >
      struct fold< OP, T, N >
         : std::integral_constant< T, N >
      {
      };

      template< template< typename U, U, U > class OP, typename T, T... Ns >
      struct fold
         : fold< OP, typename impl::folder< OP, make_index_sequence< sizeof...( Ns ) / 2 >, sizeof...( Ns ) % 2 == 1, T, Ns... >::type >
      {
      };

      template< template< typename U, U, U > class OP, typename T, T... Ns >
      struct fold< OP, integer_sequence< T, Ns... > >
         : fold< OP, T, Ns... >
      {
      };

   }  // namespace seq

}  // namespace tao

#endif
<commit_msg>Add a layer to fix Clang problems<commit_after>// Copyright (c) 2015-2018 Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/sequences/

#ifndef TAOCPP_SEQUENCES_INCLUDE_FOLD_HPP
#define TAOCPP_SEQUENCES_INCLUDE_FOLD_HPP

#include <type_traits>

#include "integer_sequence.hpp"
#include "make_integer_sequence.hpp"
#include "select.hpp"

namespace tao
{
   namespace seq
   {
      namespace impl
      {
         template< template< typename U, U, U > class OP >
         struct folder
         {
            template< bool, typename, typename T, T... >
            struct sub;

            template< std::size_t... Is, typename T, T... Ns >
            struct sub< false, index_sequence< Is... >, T, Ns... >
            {
               using type = integer_sequence< T, OP< T, seq::select< 2 * Is, T, Ns... >::value, seq::select< 2 * Is + 1, T, Ns... >::value >::value... >;
            };

            template< std::size_t... Is, typename T, T N, T... Ns >
            struct sub< true, index_sequence< Is... >, T, N, Ns... >
            {
               using type = integer_sequence< T, N, OP< T, seq::select< 2 * Is, T, Ns... >::value, seq::select< 2 * Is + 1, T, Ns... >::value >::value... >;
            };
         };

      }  // namespace impl

      template< template< typename U, U, U > class, typename T, T... >
      struct fold;

      template< template< typename U, U, U > class OP, typename T, T N >
      struct fold< OP, T, N >
         : std::integral_constant< T, N >
      {
      };

      template< template< typename U, U, U > class OP, typename T, T... Ns >
      struct fold
         : fold< OP, typename impl::folder< OP >::template sub< sizeof...( Ns ) % 2 == 1, make_index_sequence< sizeof...( Ns ) / 2 >, T, Ns... >::type >
      {
      };

      template< template< typename U, U, U > class OP, typename T, T... Ns >
      struct fold< OP, integer_sequence< T, Ns... > >
         : fold< OP, T, Ns... >
      {
      };

   }  // namespace seq

}  // namespace tao

#endif
<|endoftext|>


<commit_before>#include "keilo.hpp"

namespace keilo {
	table::table(std::string table_name, std::string key) : name(std::move(table_name)), key(std::move(key)) { }

	table::table(std::string table_name, std::string key, std::list<record> instances) : name(std::move(table_name)),
	                                                                               key(std::move(key)),
	                                                                               records(std::move(instances)) {
	}

	table::table(const table& other) { *this = other; }

	table& table::operator=(const table& other) {
		this->name = other.name;
		this->key = other.key;
		for (const auto& record : other.records)
			this->records.emplace_back(record);

		return *this;
	}

	table table::join(table& other) {
		std::unique_lock<std::mutex> lock(this->mutex);
		auto joined_table{records};
		auto other_table{other.records};

		for (auto& origin_record : joined_table)
			for (auto& other_record : other_table)
				for (auto& other_instance : other_record.instances)
					if (key != other_instance.identifier &&
						other_record.key.value == origin_record.key.value)
						origin_record.instances.emplace_back(other_instance);

		return {get_name() + '+' + other.get_name(), key, joined_table};
	}

	std::list<record> table::select_record(const std::list<instance>& conditions) const {
		auto dump = records;
		auto selected = std::list<record>();

		for (;;) {
			auto it = std::find_if(dump.cbegin(), dump.cend(),
			                       [conditions](const record& record) {
				                       auto found = true;
				                       for (const auto& condition : conditions) {
					                       if (record.instances.cend() == std::find_if(
							                       record.instances.cbegin(), record.instances.cend(),
							                       [condition](const instance& instance) {
								                       return instance == condition;
							                       })
					                       ) {
						                       found = false;
						                       break;
					                       }
				                       }
				                       return found;
			                       }
			);
			if (it != dump.cend()) {
				selected.emplace_back(*it);
				dump.erase(it);
			}
			else
				break;
		}

		return selected;
	}

	result_t table::insert_record(const record& record) {
		std::unique_lock<std::mutex> lock(this->mutex);

		if (record.key.identifier != this->key)
			return result_t::key_not_exist;

		const auto val = record.key.value;

		const auto pos = std::find_if(records.cbegin(), records.cend(), [this, val](const keilo::record& record) {
			return record.instances.cend() != std::find_if(record.instances.cbegin(), record.instances.cend(),
			                                               [this, val](const instance& instance) {
				                                               return instance.identifier == key && instance.value ==
					                                               val;
			                                               });
		});

		if (pos != records.cend())
			return result_t::key_overlapped;

		records.insert(pos, record);

		return result_t::success;
	}

	result_t table::update_record(const std::list<instance>& conditions, const std::list<instance>& replacements) {
		std::unique_lock<std::mutex> lock(mutex);

		// find suitable records
		const auto to_update = select_record(conditions);

		if (to_update.empty())
			return result_t::cannot_find;

		// check duplication of instance of key if there is modifying of key
		const auto dup = std::find_if(replacements.cbegin(), replacements.cend(),
		                              [this](const instance& instance) { return instance.identifier == key; }
		);
		if (dup != replacements.cend())
			if (records.cend() != std::find_if(records.cbegin(), records.cend(),
			                                   [&dup](const record& record) { return record.key == *dup; })
			)
				return result_t::key_overlapped;

		for (const auto& replacement : replacements) {
			for (const auto& be_update : to_update) {
				auto rt = std::find_if(records.begin(), records.end(),
				                       [&be_update](const record& record) { return be_update.key == record.key; }
				);

				auto it = std::find_if(rt->instances.begin(), rt->instances.end(),
				                       [replacement](const instance& instance) {
					                       return replacement.identifier == instance.identifier;
				                       }
				);
				it->value = replacement.value;
			}
		}

		return result_t::success;
	}

	result_t table::remove_record(const std::list<instance>& conditions) {
		std::unique_lock<std::mutex> lock(mutex);

		const auto selected_records = this->select_record(conditions);

		// when program cannot find suitable records
		if (selected_records.empty())
			return result_t::cannot_find;

		for (const auto& selected_record : selected_records) {
			auto it = std::find_if(this->records.cbegin(), this->records.cend(),
			                       [&selected_record](const record& origin_record) {
				                       return selected_record.key.value == origin_record.key.value;
			                       }
			);
			if (it != this->records.cend()) {
				auto tmp = it;
				++tmp;
				records.erase(it);
				it = tmp;
			}
		}

		return result_t::success;
	}

	std::list<record> table::get_records() {
		std::unique_lock<std::mutex> lock(mutex);
		return records;
	}

	size_t table::count() {
		std::unique_lock<std::mutex> lock(mutex);
		return records.size();
	}

	std::string table::get_key() const { return key; }

	void table::sort(const bool& order) {
		records.sort([order](const record& a, const record& b) {
			return order ? a.key.value < b.key.value : a.key.value > b.key.value;
		});
	}

	void table::sort(const char* sort_key, const bool& order) {
		records.sort([sort_key, order](const record& a, const record& b) {
			const auto a_key = std::find_if(a.instances.begin(), a.instances.end(),
			                                [sort_key](const instance& instance) {
				                                return sort_key == instance.identifier;
			                                });
			const auto b_key = std::find_if(b.instances.begin(), b.instances.end(),
			                                [sort_key](const instance& instance) {
				                                return sort_key == instance.identifier;
			                                });
			return order ? a_key->value < b_key->value : a_key->value > b_key->value;
		});
	}

	std::string table::get_name() const { return name; }

	void table::set_name(std::string name) { this->name = std::move(name); }

}
<commit_msg>Update table.cpp<commit_after>#include "keilo.hpp"

namespace keilo {
	table::table(std::string table_name, std::string key) : name(std::move(table_name)), key(std::move(key)) { }

	table::table(std::string table_name, std::string key, std::list<record> instances) : name(std::move(table_name)),
	                                                                               key(std::move(key)),
	                                                                               records(std::move(instances)) {
	}

	table::table(const table& other) { *this = other; }

	table& table::operator=(const table& other) {
		this->name = other.name;
		this->key = other.key;
		for (const auto& record : other.records)
			this->records.emplace_back(record);

		return *this;
	}

	table table::join(table& other) {
		std::unique_lock<std::mutex> lock(this->mutex);
		auto joined_table{records};
		auto other_table{other.records};

		for (auto& origin_record : joined_table)
			for (auto& other_record : other_table)
				for (auto& other_instance : other_record.instances)
					if (key != other_instance.identifier &&
						other_record.key.value == origin_record.key.value)
						origin_record.instances.emplace_back(other_instance);

		return {get_name() + '+' + other.get_name(), key, joined_table};
	}

	std::list<record> table::select_record(const std::list<instance>& conditions) const {
		auto dump = records;
		auto selected = std::list<record>();

		for (;;) {
			auto it = std::find_if(dump.cbegin(), dump.cend(),
			                       [conditions](const record& record) {
				                       auto found = true;
				                       for (const auto& condition : conditions) {
					                       if (record.instances.cend() == std::find_if(
							                       record.instances.cbegin(), record.instances.cend(),
							                       [condition](const instance& instance) {
								                       return instance == condition;
							                       })
					                       ) {
						                       found = false;
						                       break;
					                       }
				                       }
				                       return found;
			                       }
			);
			if (it != dump.cend()) {
				selected.emplace_back(*it);
				dump.erase(it);
			}
			else
				break;
		}

		return selected;
	}

	result_t table::insert_record(const record& record) {
		std::unique_lock<std::mutex> lock(this->mutex);

		if (record.key.identifier != this->key)
			return result_t::key_not_exist;

		const auto val = record.key.value;

		const auto pos = std::find_if(records.cbegin(), records.cend(), [this, val](const keilo::record& record) {
			return record.instances.cend() != std::find_if(record.instances.cbegin(), record.instances.cend(),
			                                               [this, val](const instance& instance) {
				                                               return instance.identifier == key && instance.value ==
					                                               val;
			                                               });
		});

		if (pos != records.cend())
			return result_t::key_overlapped;

		records.insert(pos, record);

		return result_t::success;
	}

	result_t table::update_record(const std::list<instance>& conditions, const std::list<instance>& replacements) {
		std::unique_lock<std::mutex> lock(mutex);

		// find suitable records
		const auto to_update = select_record(conditions);

		if (to_update.empty())
			return result_t::cannot_find;

		// check duplication of instance of key if there is modifying of key
		const auto dup = std::find_if(replacements.cbegin(), replacements.cend(),
		                              [this](const instance& instance) { return instance.identifier == key; }
		);
		if (dup != replacements.cend())
			if (records.cend() != std::find_if(records.cbegin(), records.cend(),
			                                   [&dup](const record& record) { return record.key == *dup; })
			)
				return result_t::key_overlapped;

		for (const auto& replacement : replacements) {
			for (const auto& be_update : to_update) {
				auto rt = std::find_if(records.begin(), records.end(),
				                       [&be_update](const record& record) { return be_update.key == record.key; }
				);

				auto it = std::find_if(rt->instances.begin(), rt->instances.end(),
				                       [replacement](const instance& instance) {
					                       return replacement.identifier == instance.identifier;
				                       }
				);
				it->value = replacement.value;
			}
		}

		return result_t::success;
	}

	result_t table::remove_record(const std::list<instance>& conditions) {
		std::unique_lock<std::mutex> lock(mutex);

		const auto selected_records = this->select_record(conditions);

		// when program cannot find suitable records
		if (selected_records.empty())
			return result_t::cannot_find;

		for (const auto& selected_record : selected_records) {
			auto it = std::find_if(this->records.cbegin(), this->records.cend(),
			                       [&selected_record](const record& origin_record) {
				                       return selected_record.key.value == origin_record.key.value;
			                       }
			);
			if (it != this->records.cend()) {
				auto tmp = it;
				++tmp;
				records.erase(it);
				it = tmp;
			}
		}

		return result_t::success;
	}

	std::list<record> table::get_records() {
		std::unique_lock<std::mutex> lock(mutex);
		return records;
	}

	size_t table::count() {
		std::unique_lock<std::mutex> lock(mutex);
		return records.size();
	}

	std::string table::get_key() const { return key; }

	void table::sort(const bool& order) {
		records.sort([order](const record& a, const record& b) {
			return order ? a.key.value < b.key.value : a.key.value > b.key.value;
		});
	}

	void table::sort(const char* sort_key, const bool& order) {
		records.sort([sort_key, order](const record& a, const record& b) {
			const auto a_key = std::find_if(a.instances.begin(), a.instances.end(),
			                                [sort_key](const instance& instance) {
				                                return sort_key == instance.identifier;
			                                });
			const auto b_key = std::find_if(b.instances.begin(), b.instances.end(),
			                                [sort_key](const instance& instance) {
				                                return sort_key == instance.identifier;
			                                });
			return order ? a_key->value < b_key->value : a_key->value > b_key->value;
		});
	}

	std::string table::get_name() const { return name; }
}
<|endoftext|>


<commit_before><commit_msg>Reverted "Leak TypeDescriptor_Init_Impl to avoid problems at exit."<commit_after><|endoftext|>


<commit_before>#include "GAMEFLOW.H"

//#include "DRAW.H"

#include "../SPEC_PSX/FILE.H"
#include "../SPEC_PSX/MALLOC.H"

#include <stdint.h>
#include <string.h>

//Temp
#include <assert.h>

unsigned char gfGameMode;
unsigned char gfNumMips;
int scroll_pos;
char DEL_playingamefmv;
char num_fmvs;
char fmv_to_play[2];
unsigned short dels_cutseq_selector_flag;
unsigned short dels_cutseq_player;
char Chris_Menu;
unsigned char gfLegendTime;
unsigned char bDoCredits;
static unsigned char gfCutNumber;
unsigned char gfInitialiseGame;
long nframes;
unsigned char gfNumPickups;
unsigned char gfNumTakeaways;
char CanLoad;
struct GAMEFLOW* Gameflow;
unsigned short* gfStringOffset;
char* gfStringWad;
unsigned short* gfFilenameOffset;
char* gfFilenameWad;
unsigned char gfCurrentLevel;
unsigned char gfLevelComplete;
unsigned char gfRequiredStartPos;
unsigned short gfLevelFlags;
unsigned char gfLevelNames[40];
unsigned char gfResidentCut[4];
unsigned char gfResetHubDest;
char gfUVRotate;
char gfLayer1Vel;
char gfLayer2Vel;
struct CVECTOR gfLayer1Col;
struct CVECTOR gfLayer2Col;
unsigned long GameTimer;
//struct PHD_VECTOR gfLensFlare;
struct CVECTOR gfLensFlareColour;
unsigned char gfMirrorRoom;
unsigned char gfMips[8];
char title_controls_locked_out;
long gfScriptLen = 0;
unsigned char gfLegend;
unsigned char gfWadNames[40];
static unsigned short *gfScriptOffset;
static unsigned char *gfScriptWad;
static char* gfExtensions;
static int gfStatus;
static unsigned long OldSP;
unsigned char gfPickups[16];
unsigned char gfTakeaways[16];

void DoGameflow()//10F5C, 10FD8
{
	unsigned char *gf;
	unsigned char n;

	LoadGameflow();

#ifndef _DEBUG
	//0 = Eidos Logo FMV
	//1 = TRC Intro FMV
	S_PlayFMV(0);
	S_PlayFMV(1);
#endif

#if 1
	struct GAMEFLOW* v1 = Gameflow;

	num_fmvs = 0;
	fmv_to_play[0] = 0;
	fmv_to_play[1] = 0;

	//? Since when did gf flags store the current level?
	//FIXME!
	int v0 = *(int*)v1;
	v0 >>= 2;
	v0 &= 1;
	v0 = v0 < 1 ? 1 : 0;

	gfCurrentLevel = v0;

	//Current level's script offset
	unsigned short* scriptOffsetPtr = gfScriptOffset + (gfCurrentLevel & 0xFF);

	unsigned int s0 = 0x000A0000;//?
	unsigned char* sequenceCommand = gfScriptWad + *scriptOffsetPtr;

	while (1)//?
	{
		int op = *sequenceCommand - 0x80;
		sequenceCommand++;
		switch (op)
		{
		case 2://IB = 113D8, 11488
			gfLevelFlags = (sequenceCommand[0] | (sequenceCommand[1] << 8));
			DoTitle(sequenceCommand[2], sequenceCommand[3]);//a3[2]unconfirmed
			break;
		case 3://11048
			break;
		case 5://112B8
			gfResidentCut[0] = *sequenceCommand;
			sequenceCommand += 1;
			break;
		case 6://112CC
			gfResidentCut[1] = *sequenceCommand;
			sequenceCommand += 1;
			break;
		case 7:
			gfResidentCut[2] = *sequenceCommand;
			sequenceCommand += 1;
			break;
		case 8://112F4
			gfResidentCut[3] = *sequenceCommand;
			sequenceCommand += 1;
			break;
		case 9://1107C
		{
			int a2 = 10;//?
			int a1 = 10;//?

			///LightningRGB[0] = *sequenceCommand;
			///LightningRGBs[0] = *sequenceCommand;
			gfLayer2Col.r = *sequenceCommand;
			sequenceCommand += 1;

#ifdef _DEBUG
			//internal beta is 0x2E
			//GameTimer = 0x2E;
#endif
			///LightningRGB[1] = *sequenceCommand;//*a3++;?
			///LightningRGBs[1] = *sequenceCommand;//*a3++;?
			gfLayer2Col.g = *sequenceCommand;//*a3++;?
			sequenceCommand += 1;

			GameTimer = 44;
			///GlobalRoomNumber = *sequenceCommand;
			///GLOBAL_gunflash_meshptr = *sequenceCommand;
			gfLayer1Col.cd = *sequenceCommand;
			sequenceCommand += 1;

			gfLayer1Vel = *sequenceCommand;
			sequenceCommand += 1;
			break;
		}
		default://11550
			assert(1);
			break;
		}
	}

#endif

	dump_game_malloc();
}

void LoadGameflow()//102E0, 102B0
{
	int len = FILE_Length("SCRIPT.DAT");
	unsigned char* s = game_malloc(len);
	FILE_Load("SCRIPT.DAT", s);

	Gameflow = (struct GAMEFLOW*)s;
	s += sizeof(struct GAMEFLOW);

	gfExtensions = s;
	s += 0x28;

	gfFilenameOffset = s;
	s += Gameflow->nFileNames * sizeof(unsigned short);

	gfFilenameWad = s;
	s += Gameflow->FileNameLen;

	gfScriptOffset = s;
	s += Gameflow->nLevels * sizeof(unsigned short);

	gfScriptLen = len;
	gfScriptWad = s;
	s += Gameflow->ScriptLen;

	//Align
	gfStringOffset = (char*)((uintptr_t)(s + 3) & (uintptr_t)-4);

	int i = 0;

#ifdef CORE_UNSAFE
	//This is original code, unsafe (if no lang loc files exist on disk)
	while (FILE_Length(s) == -1)
	{
		//Null terminated
		s += strlen(s) + 1;
		i++;
	}
#else
	//Safer code (no inf loop).
	for (i = 0; i < 8; i++)
	{
		if (FILE_Length(s) != -1)
		{
			break;
		}

		//Null terminated
		s += strlen(s) + 1;
	}
#endif

	Gameflow->Language = i;

	FILE_Load(s, gfStringOffset);

	struct STRINGHEADER sh;
	memcpy(&sh, gfStringOffset, sizeof(struct STRINGHEADER));
	memcpy(gfStringOffset, gfStringOffset + (sizeof(struct STRINGHEADER) / sizeof(unsigned short)), (sh.nStrings + sh.nPSXStrings) * sizeof(unsigned short));

#ifdef _DEBUG
	//Internal Beta
	//memcpy(gfStringOffset + (sh.nStrings + sh.nPSXStrings), gfStringOffset + 317, sh.StringWadLen + sh.PSXStringWadLen);
	memcpy(gfStringOffset + (sh.nStrings + sh.nPSXStrings), gfStringOffset + 315, sh.StringWadLen + sh.PSXStringWadLen);
#else
	memcpy(gfStringOffset + (sh.nStrings + sh.nPSXStrings), gfStringOffset + 315, sh.StringWadLen + sh.PSXStringWadLen);
#endif

	if (sh.nStrings + sh.nPSXStrings != 0)
	{
		unsigned char* stringPtr = gfStringOffset + sh.nStrings + sh.nPSXStrings;

		for (i = 0; i < sh.nStrings + sh.nPSXStrings; i++)
		{
			int stringLength = (gfStringOffset[i + 1] - gfStringOffset[i]) - 1;
			if (stringLength > 0)
			{
				for (int j = 0; j < stringLength; j++)
				{
					stringPtr[j] ^= 0xA5;
				}
			}

			stringPtr += stringLength + 1;
		}
	}

	if (Gameflow->nLevels != 0)
	{
		unsigned char* sequenceCommand = gfScriptWad;
		for (i = 0; i < Gameflow->nLevels; i++)
		{
			int endOfSequence = 0;

			while (!endOfSequence)
			{
				unsigned char op = *sequenceCommand - 0x80;
				sequenceCommand++;

				switch (op)
				{
				case 0:
					sequenceCommand += 1;
					break;
				case 1:
					gfLevelNames[i] = *sequenceCommand;
					sequenceCommand += 5;
					break;
				case 2:
				case 9:
				case 10:
					sequenceCommand += 4;
					break;
				case 3:
					endOfSequence = 1;
					break;
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 11:
				case 12:
				case 16:
				case 17:
					sequenceCommand += 1;
					break;
				case 13:
					sequenceCommand += 9;
					break;
				case 14:
					sequenceCommand += 5;
					break;
				case 15:
					sequenceCommand += 3;
					break;
				case 18:
				case 19:
				case 20:
				case 21:
				case 22:
				case 23:
				case 24:
				case 25:
				case 26:
				case 27:
				case 28:
				case 29:
				case 30:
				case 31:
				case 32:
				case 33:
				case 34:
				case 35:
				case 36:
				case 37:
				case 38:
				case 39:
				case 40:
				case 41:
				case 42:
				case 43:
				case 44:
				case 45:
				case 46:
				case 47:
				case 48:
				case 49:
				case 50:
				case 51:
				case 52:
				case 53:
				case 54:
				case 55:
				case 56:
				case 57:
				case 58:
				case 59:
				case 60:
				case 61:
				case 62:
				case 63:
				case 64:
				case 65:
				case 66:
				case 67:
				case 68:
				case 69:
				case 70:
				case 71:
				case 72:
				case 73:
				case 74:
				case 75:
				case 76:
				case 77:
				case 78:
				case 79:
				case 80:
				case 81:
				case 82:
				case 83:
				case 84:
				case 85:
				case 86:
				case 87:
				case 88:
				case 89:
				case 90:
					sequenceCommand += 2;
					break;
				default:
					sequenceCommand += 2;
					break;
				}
			}
		}
	}
}

void QuickControlPhase()
{
}

void DoTitle(unsigned char Name, unsigned char Audio)//10604, 105C4
{
}

void DoLevel(unsigned char Name, unsigned char Audio)
{
}<commit_msg>Fix: type mis-match errors. GAMEFLOW.C<commit_after>#include "GAMEFLOW.H"

//#include "DRAW.H"
//#include "NEWINV2.H"
//#include "SAVEGAME.H"
//#include "TOMB4FX.H"

//#include "../SPEC_PSX/CD.H"
#include "../SPEC_PSX/FILE.H"
#include "../SPEC_PSX/MALLOC.H"
#//include "../SPEC_PSX/ROOMLOAD.H"

#include <stdint.h>
#include <string.h>

//Temp
#include "../SPEC_PSX/LOAD_LEV.H"
#include <assert.h>

unsigned char gfGameMode;
unsigned char gfNumMips;
int scroll_pos;
char DEL_playingamefmv;
char num_fmvs;
char fmv_to_play[2];
unsigned short dels_cutseq_selector_flag;
unsigned short dels_cutseq_player;
char Chris_Menu;
unsigned char gfLegendTime;
unsigned char bDoCredits;
static unsigned char gfCutNumber;
unsigned char gfInitialiseGame;
long nframes;
unsigned char gfNumPickups;
unsigned char gfNumTakeaways;
char CanLoad;
struct GAMEFLOW* Gameflow;
unsigned short* gfStringOffset;
char* gfStringWad;
unsigned short* gfFilenameOffset;
char* gfFilenameWad;
unsigned char gfCurrentLevel;
unsigned char gfLevelComplete;
unsigned char gfRequiredStartPos;
unsigned short gfLevelFlags;
unsigned char gfLevelNames[40];
unsigned char gfResidentCut[4];
unsigned char gfResetHubDest;
char gfUVRotate;
char gfLayer1Vel;
char gfLayer2Vel;
struct CVECTOR gfLayer1Col;
struct CVECTOR gfLayer2Col;
unsigned long GameTimer;
//struct PHD_VECTOR gfLensFlare;
struct CVECTOR gfLensFlareColour;
unsigned char gfMirrorRoom;
unsigned char gfMips[8];
char title_controls_locked_out;
long gfScriptLen = 0;
unsigned char gfLegend;
unsigned char gfWadNames[40];
static unsigned short *gfScriptOffset;
static unsigned char *gfScriptWad;
static char* gfExtensions;
static int gfStatus;
static unsigned long OldSP;
unsigned char gfPickups[16];
unsigned char gfTakeaways[16];

void DoGameflow()//10F5C, 10FD8
{
	unsigned char *gf;
	unsigned char n;

	LoadGameflow();

#ifdef PSX
	//0 = Eidos Logo FMV
	//1 = TRC Intro FMV
	S_PlayFMV(0);
	S_PlayFMV(1);
#endif

#if 1
	struct GAMEFLOW* v1 = Gameflow;

	num_fmvs = 0;
	fmv_to_play[0] = 0;
	fmv_to_play[1] = 0;

	//? Since when did gf flags store the current level?
	//FIXME!
	int v0 = *(int*)v1;
	v0 >>= 2;
	v0 &= 1;
	v0 = v0 < 1 ? 1 : 0;

	gfCurrentLevel = v0;

	//Current level's script offset
	unsigned short* scriptOffsetPtr = gfScriptOffset + (gfCurrentLevel & 0xFF);

	unsigned int s0 = 0x000A0000;//?
	unsigned char* sequenceCommand = gfScriptWad + *scriptOffsetPtr;

	while (1)//?
	{
		int op = *sequenceCommand - 0x80;
		sequenceCommand++;
		switch (op)
		{
		case 2://IB = 113D8, 11488
			gfLevelFlags = (sequenceCommand[0] | (sequenceCommand[1] << 8));
			DoTitle(sequenceCommand[2], sequenceCommand[3]);//a3[2]unconfirmed
			break;
		case 3://11048
			break;
		case 5://112B8
			gfResidentCut[0] = *sequenceCommand;
			sequenceCommand += 1;
			break;
		case 6://112CC
			gfResidentCut[1] = *sequenceCommand;
			sequenceCommand += 1;
			break;
		case 7:
			gfResidentCut[2] = *sequenceCommand;
			sequenceCommand += 1;
			break;
		case 8://112F4
			gfResidentCut[3] = *sequenceCommand;
			sequenceCommand += 1;
			break;
		case 9://1107C
		{
			int a2 = 10;//?
			int a1 = 10;//?

		///	LightningRGB[0] = *sequenceCommand;
		///	LightningRGBs[0] = *sequenceCommand;
			gfLayer2Col.r = *sequenceCommand;
			sequenceCommand += 1;

#ifdef _DEBUG
			//internal beta is 0x2E
			//GameTimer = 0x2E;
#endif
		///	LightningRGB[1] = *sequenceCommand;//*a3++;?
		///	LightningRGBs[1] = *sequenceCommand;//*a3++;?
			gfLayer2Col.g = *sequenceCommand;//*a3++;?
			sequenceCommand += 1;

			GameTimer = 44;
		///	GlobalRoomNumber = *sequenceCommand;
			//			GLOBAL_gunflash_meshptr = *sequenceCommand;
			gfLayer1Col.cd = *sequenceCommand;
			sequenceCommand += 1;

			gfLayer1Vel = *sequenceCommand;
			sequenceCommand += 1;
			break;
		}
		default://11550
			assert(1);
			break;
		}
	}

#endif

	dump_game_malloc();
}

void LoadGameflow()//102E0, 102B0
{
	int len = FILE_Length("SCRIPT.DAT");
	char* s = game_malloc(len);
	FILE_Load("SCRIPT.DAT", s);

	Gameflow = (struct GAMEFLOW*)s;
	s += sizeof(struct GAMEFLOW);

	gfExtensions = s;
	s += 0x28;

	gfFilenameOffset = (unsigned short*)s;
	s += Gameflow->nFileNames * sizeof(unsigned short);

	gfFilenameWad = s;
	s += Gameflow->FileNameLen;

	gfScriptOffset = (unsigned short*)s;
	s += Gameflow->nLevels * sizeof(unsigned short);

	gfScriptLen = len;
	gfScriptWad = (unsigned char*)s;
	s += Gameflow->ScriptLen;

	//Align
	gfStringOffset = (unsigned short*)(char*)((uintptr_t)(s + 3) & (uintptr_t)-4);

	int i = 0;

#ifdef CORE_UNSAFE
	//This is original code, unsafe (if no lang loc files exist on disk)
	while (FILE_Length(s) == -1)
	{
		//Null terminated
		s += strlen(s) + 1;
		i++;
	}
#else
	//Safer code (no inf loop).
	for (i = 0; i < 8; i++)
	{
		if (FILE_Length((char*)s) != -1)
		{
			break;
		}

		//Null terminated
		s += strlen((char*)s) + 1;
	}
#endif

	Gameflow->Language = i;

	FILE_Load((char*)s, gfStringOffset);

	struct STRINGHEADER sh;
	memcpy(&sh, gfStringOffset, sizeof(struct STRINGHEADER));
	memcpy(gfStringOffset, gfStringOffset + (sizeof(struct STRINGHEADER) / sizeof(unsigned short)), (sh.nStrings + sh.nPSXStrings) * sizeof(unsigned short));

#ifdef _DEBUG
	//Internal Beta
	//memcpy(gfStringOffset + (sh.nStrings + sh.nPSXStrings), gfStringOffset + 317, sh.StringWadLen + sh.PSXStringWadLen);
	memcpy(gfStringOffset + (sh.nStrings + sh.nPSXStrings), gfStringOffset + 315, sh.StringWadLen + sh.PSXStringWadLen);
#else
	memcpy(gfStringOffset + (sh.nStrings + sh.nPSXStrings), gfStringOffset + 315, sh.StringWadLen + sh.PSXStringWadLen);
#endif

	if (sh.nStrings + sh.nPSXStrings != 0)
	{
		unsigned char* stringPtr = (unsigned char*)(gfStringOffset + sh.nStrings + sh.nPSXStrings);//s?

		for (i = 0; i < sh.nStrings + sh.nPSXStrings; i++)
		{
			int stringLength = (gfStringOffset[i + 1] - gfStringOffset[i]) - 1;
			if (stringLength > 0)
			{
				for (int j = 0; j < stringLength; j++)
				{
					stringPtr[j] ^= 0xA5;
				}
			}

			stringPtr += stringLength + 1;
		}
	}

	if (Gameflow->nLevels != 0)
	{
		unsigned char* sequenceCommand = gfScriptWad;
		for (i = 0; i < Gameflow->nLevels; i++)
		{
			int endOfSequence = 0;

			while (!endOfSequence)
			{
				unsigned char op = *sequenceCommand - 0x80;
				sequenceCommand++;

				switch (op)
				{
				case 0:
					sequenceCommand += 1;
					break;
				case 1:
					gfLevelNames[i] = *sequenceCommand;
					sequenceCommand += 5;
					break;
				case 2:
				case 9:
				case 10:
					sequenceCommand += 4;
					break;
				case 3:
					endOfSequence = 1;
					break;
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 11:
				case 12:
				case 16:
				case 17:
					sequenceCommand += 1;
					break;
				case 13:
					sequenceCommand += 9;
					break;
				case 14:
					sequenceCommand += 5;
					break;
				case 15:
					sequenceCommand += 3;
					break;
				case 18:
				case 19:
				case 20:
				case 21:
				case 22:
				case 23:
				case 24:
				case 25:
				case 26:
				case 27:
				case 28:
				case 29:
				case 30:
				case 31:
				case 32:
				case 33:
				case 34:
				case 35:
				case 36:
				case 37:
				case 38:
				case 39:
				case 40:
				case 41:
				case 42:
				case 43:
				case 44:
				case 45:
				case 46:
				case 47:
				case 48:
				case 49:
				case 50:
				case 51:
				case 52:
				case 53:
				case 54:
				case 55:
				case 56:
				case 57:
				case 58:
				case 59:
				case 60:
				case 61:
				case 62:
				case 63:
				case 64:
				case 65:
				case 66:
				case 67:
				case 68:
				case 69:
				case 70:
				case 71:
				case 72:
				case 73:
				case 74:
				case 75:
				case 76:
				case 77:
				case 78:
				case 79:
				case 80:
				case 81:
				case 82:
				case 83:
				case 84:
				case 85:
				case 86:
				case 87:
				case 88:
				case 89:
				case 90:
					sequenceCommand += 2;
					break;
				default:
					sequenceCommand += 2;
					break;
				}
			}
		}
	}
}

void QuickControlPhase()
{
}

void DoTitle(unsigned char Name, unsigned char Audio)//10604, 105C4
{
}

void DoLevel(unsigned char Name, unsigned char Audio)
{
}
<|endoftext|>


<commit_before>#include "LARA2GUN.H"

#include "SPECIFIC.H"
#include "LARA.H"
#include "LARAFIRE.H"
#ifdef PC_VERSION
#include "GAME.H"
#else
#include "SETUP.H"
#endif
#include "DRAW.H"
#include "OBJECTS.H"
#include "EFFECTS.H"
#include "SOUND.H"

static struct PISTOL_DEF PistolTable[4] =
{
	{ LARA, 0, 0, 0, 0 },
	{ PISTOLS_ANIM, 4, 5, 0xD, 0x18 },
	{ REVOLVER_ANIM , 7, 8, 0xF, 0x1D },
	{ UZI_ANIM, 4, 5, 0xD, 0x18 }
};

void AnimatePistols(int weapon_type)
{
	UNIMPLEMENTED();
}

void PistolHandler(int weapon_type)
{
	UNIMPLEMENTED();
}

void undraw_pistol_mesh_right(int weapon_type)//44968(<), 44DCC(<) (F)
{
	WeaponObject(weapon_type);
	lara.mesh_ptrs[LM_RHAND] = meshes[objects[LARA].mesh_index + 2 * LM_RHAND];
	switch (weapon_type)
	{
	case WEAPON_PISTOLS:
		lara.holster = LARA_HOLSTERS_PISTOLS;
		break;
	case WEAPON_REVOLVER:
		lara.holster = LARA_HOLSTERS_REVOLVER;
		break;
	case WEAPON_UZI:
		lara.holster = LARA_HOLSTERS_UZIS;
		break;
	}
}

void undraw_pistol_mesh_left(int weapon_type)//448F0(<), 44D54(<) (F)
{
	if(weapon_type != WEAPON_REVOLVER)
	{
		WeaponObject(weapon_type);
		lara.mesh_ptrs[LM_LHAND] = meshes[objects[LARA].mesh_index + 2 * LM_LHAND];
		switch (weapon_type)
		{
		case WEAPON_PISTOLS:
			lara.holster = LARA_HOLSTERS_PISTOLS;
			break;
		case WEAPON_UZI:
			lara.holster = LARA_HOLSTERS_UZIS;
			break;
		}
	}
}

void draw_pistol_meshes(int weapon_type)// (F)
{
	lara.holster = LARA_HOLSTERS;
	lara.mesh_ptrs[LM_RHAND] = meshes[objects[WeaponObjectMesh(weapon_type)].mesh_index + 2 * LM_RHAND];

	if (weapon_type != WEAPON_REVOLVER)
	{
		lara.mesh_ptrs[LM_LHAND] = meshes[objects[WeaponObjectMesh(weapon_type)].mesh_index + 2 * LM_LHAND];
	}
}

void ready_pistols(int weapon_type)// (F)
{
	lara.gun_status = LG_READY;
	lara.left_arm.z_rot = 0;
	lara.left_arm.y_rot = 0;
	lara.left_arm.x_rot = 0;
	lara.right_arm.z_rot = 0;
	lara.right_arm.y_rot = 0;
	lara.right_arm.x_rot = 0;
	lara.right_arm.frame_number = 0;
	lara.left_arm.frame_number = 0;
	lara.target = 0;
	lara.right_arm.lock = 0;
	lara.left_arm.lock = 0;
	lara.right_arm.frame_base = lara.left_arm.frame_base = objects[WeaponObject(weapon_type)].frame_base;
}

void undraw_pistols(int weapon_type)//
{
	UNIMPLEMENTED();
}

void draw_pistols(int weapon_type)//443B4, 44818 (F)
{
	struct PISTOL_DEF* p = &PistolTable[lara.gun_type];//$a1
	short ani = lara.left_arm.frame_number + 1;//$s1

	//a3 = p->Draw1Anim

	//v0 = p->RecoilAnim
	if (ani < p->Draw1Anim || p->RecoilAnim - 1 < ani)
	{
		//loc_44420
		ani = p->Draw1Anim;
	}
	else
	{

		//loc_44428
		if (ani == p->Draw2Anim)
		{
			draw_pistol_meshes(weapon_type);
			//a1 = lara_item
			//a0 = 6
			//a2 = 0;
			SoundEffect(SFX_LARA_HOLSTER_DRAW, &lara_item->pos, 0);
			//s0 = &lara.right_arm.frame_base
		}//loc_44460
		else if (ani == p->RecoilAnim - 1)
		{
			ready_pistols(weapon_type);
			ani = 0;
		}
	}

	set_arm_info(&lara.right_arm, ani);
	set_arm_info(&lara.left_arm, ani);
}

void set_arm_info(struct lara_arm* arm/*a3*/, int frame/*a1*/)//44308 (F)
{
	struct PISTOL_DEF* def = &PistolTable[lara.gun_type];//$a2
	int anim_base = objects[def->ObjectNum].anim_index;//$a0

	if (def->Draw1Anim != 0)
	{
		arm->anim_number = anim_base;
		//j loc_44388
	}
	else
	{
		//loc_44358
		if (frame >= def->Draw2Anim)
		{
			if (frame >= def->RecoilAnim)
			{
				//loc_44384
				arm->anim_number = anim_base + 3;
			}
			else
			{
				//loc_44384
				arm->anim_number = anim_base + 2;
			}
		}
		else
		{
			//loc_44384
			arm->anim_number = anim_base + 1;
		}
	}

	arm->frame_number = frame;
	arm->frame_base = anims[arm->anim_number].frame_ptr;
}
<commit_msg>[Game]: Correct set_arm_info.<commit_after>#include "LARA2GUN.H"

#include "SPECIFIC.H"
#include "LARA.H"
#include "LARAFIRE.H"
#ifdef PC_VERSION
#include "GAME.H"
#else
#include "SETUP.H"
#endif
#include "DRAW.H"
#include "OBJECTS.H"
#include "EFFECTS.H"
#include "SOUND.H"

static struct PISTOL_DEF PistolTable[4] =
{
	{ LARA, 0, 0, 0, 0 },
	{ PISTOLS_ANIM, 4, 5, 0xD, 0x18 },
	{ REVOLVER_ANIM , 7, 8, 0xF, 0x1D },
	{ UZI_ANIM, 4, 5, 0xD, 0x18 }
};

void AnimatePistols(int weapon_type)
{
	UNIMPLEMENTED();
}

void PistolHandler(int weapon_type)
{
	UNIMPLEMENTED();
}

void undraw_pistol_mesh_right(int weapon_type)//44968(<), 44DCC(<) (F)
{
	WeaponObject(weapon_type);
	lara.mesh_ptrs[LM_RHAND] = meshes[objects[LARA].mesh_index + 2 * LM_RHAND];
	switch (weapon_type)
	{
	case WEAPON_PISTOLS:
		lara.holster = LARA_HOLSTERS_PISTOLS;
		break;
	case WEAPON_REVOLVER:
		lara.holster = LARA_HOLSTERS_REVOLVER;
		break;
	case WEAPON_UZI:
		lara.holster = LARA_HOLSTERS_UZIS;
		break;
	}
}

void undraw_pistol_mesh_left(int weapon_type)//448F0(<), 44D54(<) (F)
{
	if(weapon_type != WEAPON_REVOLVER)
	{
		WeaponObject(weapon_type);
		lara.mesh_ptrs[LM_LHAND] = meshes[objects[LARA].mesh_index + 2 * LM_LHAND];
		switch (weapon_type)
		{
		case WEAPON_PISTOLS:
			lara.holster = LARA_HOLSTERS_PISTOLS;
			break;
		case WEAPON_UZI:
			lara.holster = LARA_HOLSTERS_UZIS;
			break;
		}
	}
}

void draw_pistol_meshes(int weapon_type)// (F)
{
	lara.holster = LARA_HOLSTERS;
	lara.mesh_ptrs[LM_RHAND] = meshes[objects[WeaponObjectMesh(weapon_type)].mesh_index + 2 * LM_RHAND];

	if (weapon_type != WEAPON_REVOLVER)
	{
		lara.mesh_ptrs[LM_LHAND] = meshes[objects[WeaponObjectMesh(weapon_type)].mesh_index + 2 * LM_LHAND];
	}
}

void ready_pistols(int weapon_type)// (F)
{
	lara.gun_status = LG_READY;
	lara.left_arm.z_rot = 0;
	lara.left_arm.y_rot = 0;
	lara.left_arm.x_rot = 0;
	lara.right_arm.z_rot = 0;
	lara.right_arm.y_rot = 0;
	lara.right_arm.x_rot = 0;
	lara.right_arm.frame_number = 0;
	lara.left_arm.frame_number = 0;
	lara.target = 0;
	lara.right_arm.lock = 0;
	lara.left_arm.lock = 0;
	lara.right_arm.frame_base = lara.left_arm.frame_base = objects[WeaponObject(weapon_type)].frame_base;
}

void undraw_pistols(int weapon_type)//
{
	UNIMPLEMENTED();
}

void draw_pistols(int weapon_type)//443B4, 44818 (F)
{
	struct PISTOL_DEF* p = &PistolTable[lara.gun_type];//$a1
	short ani = lara.left_arm.frame_number + 1;//$s1

	//a3 = p->Draw1Anim

	//v0 = p->RecoilAnim
	if (ani < p->Draw1Anim || p->RecoilAnim - 1 < ani)
	{
		//loc_44420
		ani = p->Draw1Anim;
	}
	else
	{

		//loc_44428
		if (ani == p->Draw2Anim)
		{
			draw_pistol_meshes(weapon_type);
			//a1 = lara_item
			//a0 = 6
			//a2 = 0;
			SoundEffect(SFX_LARA_HOLSTER_DRAW, &lara_item->pos, 0);
			//s0 = &lara.right_arm.frame_base
		}//loc_44460
		else if (ani == p->RecoilAnim - 1)
		{
			ready_pistols(weapon_type);
			ani = 0;
		}
	}

	set_arm_info(&lara.right_arm, ani);
	set_arm_info(&lara.left_arm, ani);
}

void set_arm_info(struct lara_arm* arm/*a3*/, int frame/*a1*/)//44308, 4476C (F)
{
	struct PISTOL_DEF* def = &PistolTable[lara.gun_type];//$a2
	int anim_base = objects[def->ObjectNum].anim_index;//$a0

	if (frame < def->Draw1Anim)
	{
		arm->anim_number = anim_base;
		//j loc_44388
	}
	else
	{
		//loc_44358
		if (frame >= def->Draw2Anim)
		{
			if (frame >= def->RecoilAnim)
			{
				//loc_44384
				arm->anim_number = anim_base + 3;
			}
			else
			{
				//loc_44384
				arm->anim_number = anim_base + 2;
			}
		}
		else
		{
			//loc_44384
			arm->anim_number = anim_base + 1;
		}
	}

	arm->frame_number = frame;
	arm->frame_base = anims[arm->anim_number].frame_ptr;
}
<|endoftext|>


<commit_before><commit_msg>Crasher fix. Check for NULL.<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: xiformula.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: vg $ $Date: 2007-02-27 12:26:44 $
 *
 *  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 "precompiled_sc.hxx"

#ifndef SC_XIFORMULA_HXX
#include "xiformula.hxx"
#endif

#ifndef SC_RANGELST_HXX
#include "rangelst.hxx"
#endif

#ifndef SC_XISTREAM_HXX
#include "xistream.hxx"
#endif

#include "excform.hxx"

// Formula compiler ===========================================================

/** Implementation class of the export formula compiler. */
class XclImpFmlaCompImpl : protected XclImpRoot, protected XclTokenArrayHelper
{
public:
    explicit            XclImpFmlaCompImpl( const XclImpRoot& rRoot );

    /** Creates a range list from the passed Excel token array. */
    void                CreateRangeList(
                            ScRangeList& rScRanges, XclFormulaType eType,
                            const XclTokenArray& rXclTokArr, XclImpStream& rStrm );

    // ------------------------------------------------------------------------
private:
    XclFunctionProvider maFuncProv;     /// Excel function data provider.
    const XclBiff       meBiff;         /// Cached BIFF version to save GetBiff() calls.
};

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

XclImpFmlaCompImpl::XclImpFmlaCompImpl( const XclImpRoot& rRoot ) :
    XclImpRoot( rRoot ),
    maFuncProv( rRoot ),
    meBiff( rRoot.GetBiff() )
{
}

void XclImpFmlaCompImpl::CreateRangeList(
        ScRangeList& rScRanges, XclFormulaType /*eType*/,
        const XclTokenArray& rXclTokArr, XclImpStream& /*rStrm*/ )
{
    rScRanges.RemoveAll();

    //! evil hack, using old formula import :-)
    if( !rXclTokArr.Empty() )
    {
        SvMemoryStream aMemStrm;
        aMemStrm << EXC_ID_EOF << rXclTokArr.GetSize();
        aMemStrm.Write( rXclTokArr.GetData(), rXclTokArr.GetSize() );
        XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
        aFmlaStrm.StartNextRecord();
        GetOldFmlaConverter().GetAbsRefs( rScRanges, aFmlaStrm, aFmlaStrm.GetRecSize() );
    }
}

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

XclImpFormulaCompiler::XclImpFormulaCompiler( const XclImpRoot& rRoot ) :
    XclImpRoot( rRoot ),
    mxImpl( new XclImpFmlaCompImpl( rRoot ) )
{
}

XclImpFormulaCompiler::~XclImpFormulaCompiler()
{
}

void XclImpFormulaCompiler::CreateRangeList(
        ScRangeList& rScRanges, XclFormulaType eType,
        const XclTokenArray& rXclTokArr, XclImpStream& rStrm )
{
    mxImpl->CreateRangeList( rScRanges, eType, rXclTokArr, rStrm );
}

// ============================================================================

<commit_msg>INTEGRATION: CWS changefileheader (1.4.328); FILE MERGED 2008/04/01 12:36:12 thb 1.4.328.2: #i85898# Stripping all external header guards 2008/03/31 17:14:32 rt 1.4.328.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: xiformula.cxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#include "precompiled_sc.hxx"
#include "xiformula.hxx"
#include "rangelst.hxx"
#include "xistream.hxx"

#include "excform.hxx"

// Formula compiler ===========================================================

/** Implementation class of the export formula compiler. */
class XclImpFmlaCompImpl : protected XclImpRoot, protected XclTokenArrayHelper
{
public:
    explicit            XclImpFmlaCompImpl( const XclImpRoot& rRoot );

    /** Creates a range list from the passed Excel token array. */
    void                CreateRangeList(
                            ScRangeList& rScRanges, XclFormulaType eType,
                            const XclTokenArray& rXclTokArr, XclImpStream& rStrm );

    // ------------------------------------------------------------------------
private:
    XclFunctionProvider maFuncProv;     /// Excel function data provider.
    const XclBiff       meBiff;         /// Cached BIFF version to save GetBiff() calls.
};

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

XclImpFmlaCompImpl::XclImpFmlaCompImpl( const XclImpRoot& rRoot ) :
    XclImpRoot( rRoot ),
    maFuncProv( rRoot ),
    meBiff( rRoot.GetBiff() )
{
}

void XclImpFmlaCompImpl::CreateRangeList(
        ScRangeList& rScRanges, XclFormulaType /*eType*/,
        const XclTokenArray& rXclTokArr, XclImpStream& /*rStrm*/ )
{
    rScRanges.RemoveAll();

    //! evil hack, using old formula import :-)
    if( !rXclTokArr.Empty() )
    {
        SvMemoryStream aMemStrm;
        aMemStrm << EXC_ID_EOF << rXclTokArr.GetSize();
        aMemStrm.Write( rXclTokArr.GetData(), rXclTokArr.GetSize() );
        XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
        aFmlaStrm.StartNextRecord();
        GetOldFmlaConverter().GetAbsRefs( rScRanges, aFmlaStrm, aFmlaStrm.GetRecSize() );
    }
}

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

XclImpFormulaCompiler::XclImpFormulaCompiler( const XclImpRoot& rRoot ) :
    XclImpRoot( rRoot ),
    mxImpl( new XclImpFmlaCompImpl( rRoot ) )
{
}

XclImpFormulaCompiler::~XclImpFormulaCompiler()
{
}

void XclImpFormulaCompiler::CreateRangeList(
        ScRangeList& rScRanges, XclFormulaType eType,
        const XclTokenArray& rXclTokArr, XclImpStream& rStrm )
{
    mxImpl->CreateRangeList( rScRanges, eType, rXclTokArr, rStrm );
}

// ============================================================================

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: scfobj.cxx,v $
 *
 *  $Revision: 1.12 $
 *
 *  last change: $Author: ihi $ $Date: 2006-11-14 15:48:43 $
 *
 *  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_sc.hxx"

#ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDOBJECT_HPP_
#include <com/sun/star/embed/XEmbeddedObject.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_XVISUALOBJECT_HPP_
#include <com/sun/star/embed/XVisualObject.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_ASPECTS_HPP_
#include <com/sun/star/embed/Aspects.hpp>
#endif

using namespace com::sun::star;

// INCLUDE ---------------------------------------------------------------

#include <svtools/moduleoptions.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdpage.hxx>
#include <sfx2/objsh.hxx>
#include <sot/storage.hxx>
#include <sch/schdll.hxx>
#include <sch/memchrt.hxx>
#include <sfx2/app.hxx>
#include <sot/clsids.hxx>
#ifndef SC_ADDRESS_HXX
#include "address.hxx"
#endif

#include "scfobj.hxx"
#include "document.hxx"
#include "drwlayer.hxx"
#include "chartarr.hxx"

// STATIC DATA -----------------------------------------------------------

//==================================================================

void Sc10InsertObject::InsertChart( ScDocument* pDoc, SCTAB nDestTab, const Rectangle& rRect,
                                SCTAB nSrcTab, USHORT nX1, USHORT nY1, USHORT nX2, USHORT nY2 )
{
    //  wenn Chart nicht installiert ist, darf nicht auf SCH_MOD zugegriffen werden!
    if ( !SvtModuleOptions().IsChart() )
        return;

    ::rtl::OUString aName;
    uno::Reference < embed::XEmbeddedObject > xObj = pDoc->GetDocumentShell()->
            GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aName );
    if ( xObj.is() )
    {
        SdrOle2Obj* pSdrOle2Obj = new SdrOle2Obj( ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ), aName, rRect );

        ScDrawLayer* pModel = pDoc->GetDrawLayer();
        if (!pModel)
        {
            pDoc->InitDrawLayer();
            pModel = pDoc->GetDrawLayer();
            DBG_ASSERT(pModel,"Draw Layer ?");
        }

        SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nDestTab));
        DBG_ASSERT(pPage,"Page ?");
        pPage->InsertObject(pSdrOle2Obj);

        pSdrOle2Obj->SetLogicRect(rRect);               // erst nach InsertObject !!!
        awt::Size aSz;
        aSz.Width = rRect.GetSize().Width();
        aSz.Height = rRect.GetSize().Height();
        xObj->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, aSz );

            // hier kann das Chart noch nicht mit Daten gefuettert werden,
            // weil die Formeln noch nicht berechnet sind.
            // Deshalb in die ChartCollection, die Daten werden dann im
            // Sc10Import dtor geholt.

        ScChartCollection* pColl = pDoc->GetChartCollection();
        pColl->Insert( new ScChartArray( pDoc, nSrcTab, static_cast<SCCOL>(nX1), static_cast<SCROW>(nY1), static_cast<SCCOL>(nX2), static_cast<SCROW>(nY2), aName ) );
    }
}

<commit_msg>INTEGRATION: CWS chart2mst3 (1.11.4); FILE MERGED 2006/11/24 18:20:48 bm 1.11.4.2: RESYNC: (1.11-1.12); FILE MERGED 2006/11/20 18:37:34 nn 1.11.4.1: #i71250# removed unused include<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: scfobj.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: vg $ $Date: 2007-05-22 20:00:46 $
 *
 *  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_sc.hxx"

#ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDOBJECT_HPP_
#include <com/sun/star/embed/XEmbeddedObject.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_XVISUALOBJECT_HPP_
#include <com/sun/star/embed/XVisualObject.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_ASPECTS_HPP_
#include <com/sun/star/embed/Aspects.hpp>
#endif

using namespace com::sun::star;

// INCLUDE ---------------------------------------------------------------

#include <svtools/moduleoptions.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdpage.hxx>
#include <sfx2/objsh.hxx>
#include <sot/storage.hxx>
#include <sfx2/app.hxx>
#include <sot/clsids.hxx>
#ifndef SC_ADDRESS_HXX
#include "address.hxx"
#endif

#include "scfobj.hxx"
#include "document.hxx"
#include "drwlayer.hxx"
#include "chartarr.hxx"

// STATIC DATA -----------------------------------------------------------

//==================================================================

void Sc10InsertObject::InsertChart( ScDocument* pDoc, SCTAB nDestTab, const Rectangle& rRect,
                                SCTAB nSrcTab, USHORT nX1, USHORT nY1, USHORT nX2, USHORT nY2 )
{
    //  wenn Chart nicht installiert ist, darf nicht auf SCH_MOD zugegriffen werden!
    if ( !SvtModuleOptions().IsChart() )
        return;

    ::rtl::OUString aName;
    uno::Reference < embed::XEmbeddedObject > xObj = pDoc->GetDocumentShell()->
            GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aName );
    if ( xObj.is() )
    {
        SdrOle2Obj* pSdrOle2Obj = new SdrOle2Obj( ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ), aName, rRect );

        ScDrawLayer* pModel = pDoc->GetDrawLayer();
        if (!pModel)
        {
            pDoc->InitDrawLayer();
            pModel = pDoc->GetDrawLayer();
            DBG_ASSERT(pModel,"Draw Layer ?");
        }

        SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nDestTab));
        DBG_ASSERT(pPage,"Page ?");
        pPage->InsertObject(pSdrOle2Obj);

        pSdrOle2Obj->SetLogicRect(rRect);               // erst nach InsertObject !!!
        awt::Size aSz;
        aSz.Width = rRect.GetSize().Width();
        aSz.Height = rRect.GetSize().Height();
        xObj->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, aSz );

            // hier kann das Chart noch nicht mit Daten gefuettert werden,
            // weil die Formeln noch nicht berechnet sind.
            // Deshalb in die ChartCollection, die Daten werden dann im
            // Sc10Import dtor geholt.

        ScChartCollection* pColl = pDoc->GetChartCollection();
        pColl->Insert( new ScChartArray( pDoc, nSrcTab, static_cast<SCCOL>(nX1), static_cast<SCROW>(nY1), static_cast<SCCOL>(nX2), static_cast<SCROW>(nY2), aName ) );
    }
}

<|endoftext|>