<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: RelationController.hxx,v $
 *
 *  $Revision: 1.16 $
 *
 *  last change: $Author: obo $ $Date: 2006-07-10 15:28:51 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef DBAUI_RELATIONCONTROLLER_HXX
#define DBAUI_RELATIONCONTROLLER_HXX

#ifndef DBAUI_JOINCONTROLLER_HXX
#include "JoinController.hxx"
#endif
#ifndef DBAUI_RELATIONDESIGNVIEW_HXX
#include "RelationDesignView.hxx"
#endif

class VCLXWindow;
namespace dbaui
{
    class OTableConnectionData;
    class OTableWindowData;
    class OAddTableDlg;
    class OTableFieldDesc;
    class OTableWindow;
    class ORelationController : public OJoinController
    {
        ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >    m_xTables;
        sal_Bool    m_bRelationsPossible;
    protected:
        // all the features which should be handled by this class
        virtual void            describeSupportedFeatures();
        // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
        virtual FeatureState    GetState(sal_uInt16 nId) const;
        // execute a feature
        virtual void            Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);

        ORelationDesignView*    getRelationView() { return static_cast<ORelationDesignView*>(m_pView); }
        void loadData();
        sal_Bool existsTable(const ::rtl::OUString& _rComposedTableName) const;

        // load the window positions out of the datasource
        void loadLayoutInformation();
        void loadTableData(const ::com::sun::star::uno::Any& _aTable);
    public:
        ORelationController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);

        ~ORelationController();
        // temp
        void SaveTabWinsPosSize( OJoinTableView::OTableWindowMap* pTabWinList, long nOffsetX, long nOffsetY );

        virtual sal_Bool Construct(Window* pParent);

        // XServiceInfo
        virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
        // need by registration
        static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
                SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);

        // OJoinController overridables
        virtual bool allowViews() const;
        virtual bool allowQueries() const;

    protected:
        virtual OTableWindowData* createTableWindowData();
        // ask the user if the design should be saved when it is modified
        virtual short saveModified();
        virtual void reset();
        virtual void impl_initialize();
        virtual void updateTitle();
    };
}
#endif // DBAUI_RELATIONCONTROLLER_HXX

<commit_msg>INTEGRATION: CWS dba24b (1.16.172); FILE MERGED 2007/08/16 06:14:43 oj 1.16.172.1: #i56898# clean up of the class structure<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: RelationController.hxx,v $
 *
 *  $Revision: 1.17 $
 *
 *  last change: $Author: hr $ $Date: 2007-11-01 15:17:45 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef DBAUI_RELATIONCONTROLLER_HXX
#define DBAUI_RELATIONCONTROLLER_HXX

#ifndef DBAUI_JOINCONTROLLER_HXX
#include "JoinController.hxx"
#endif
#ifndef DBAUI_RELATIONDESIGNVIEW_HXX
#include "RelationDesignView.hxx"
#endif

class VCLXWindow;
namespace dbaui
{
    class OTableConnectionData;
    class OTableWindowData;
    class OAddTableDlg;
    class OTableFieldDesc;
    class OTableWindow;
    class ORelationController : public OJoinController
    {
        ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >    m_xTables;
        sal_Bool    m_bRelationsPossible;
    protected:
        // all the features which should be handled by this class
        virtual void            describeSupportedFeatures();
        // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
        virtual FeatureState    GetState(sal_uInt16 nId) const;
        // execute a feature
        virtual void            Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);

        ORelationDesignView*    getRelationView() { return static_cast<ORelationDesignView*>(m_pView); }
        void loadData();
        TTableWindowData::value_type existsTable(const ::rtl::OUString& _rComposedTableName) const;

        // load the window positions out of the datasource
        void loadLayoutInformation();
        void loadTableData(const ::com::sun::star::uno::Any& _aTable);
    public:
        ORelationController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);

        ~ORelationController();
        // temp
        void SaveTabWinsPosSize( OJoinTableView::OTableWindowMap* pTabWinList, long nOffsetX, long nOffsetY );

        virtual sal_Bool Construct(Window* pParent);

        // XServiceInfo
        virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
        // need by registration
        static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
                SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);

        // OJoinController overridables
        virtual bool allowViews() const;
        virtual bool allowQueries() const;

    protected:
        // ask the user if the design should be saved when it is modified
        virtual short saveModified();
        virtual void reset();
        virtual void impl_initialize();
        virtual void updateTitle();
    };
}
#endif // DBAUI_RELATIONCONTROLLER_HXX

<|endoftext|>


<commit_before>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "core/framework/murmurhash3.h"

// Original source: https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
//-----------------------------------------------------------------------------
// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.

// Note - The x86 and x64 versions do _not_ produce the same results, as the
// algorithms are optimized for their respective platforms. You can still
// compile and run any of them on any platform, but your performance with the
// non-native version will be less than optimal.

/* Modifications Copyright (c) Microsoft. */

//-----------------------------------------------------------------------------
// Platform-specific functions and macros

// Microsoft Visual Studio

#if defined(_MSC_VER)

#define FORCE_INLINE __forceinline

#include <stdlib.h>

#define ROTL32(x, y) _rotl(x, y)
#define ROTL64(x, y) _rotl64(x, y)

#define BIG_CONSTANT(x) (x)

// Other compilers

#else  // defined(_MSC_VER)

#define FORCE_INLINE inline __attribute__((always_inline))

inline uint32_t rotl32(uint32_t x, int8_t r) {
  return (x << r) | (x >> (32 - r));
}

inline uint64_t rotl64(uint64_t x, int8_t r) {
  return (x << r) | (x >> (64 - r));
}

#define ROTL32(x, y) rotl32(x, y)
#define ROTL64(x, y) rotl64(x, y)

#define BIG_CONSTANT(x) (x##LLU)

#endif  // !defined(_MSC_VER)
#include <cstddef>
//-----------------------------------------------------------------------------
// Block read - if your platform needs to do endian-swapping or can only
// handle aligned reads, do the conversion here

FORCE_INLINE uint32_t getblock32(const uint32_t* p, int i) {
  return p[i];
}

FORCE_INLINE uint64_t getblock64(const uint64_t* p, int i) {
  return p[i];
}

//-----------------------------------------------------------------------------
// Finalization mix - force all bits of a hash block to avalanche

FORCE_INLINE constexpr uint32_t fmix32(uint32_t h) {
  h ^= h >> 16;
  h *= 0x85ebca6b;
  h ^= h >> 13;
  h *= 0xc2b2ae35;
  h ^= h >> 16;

  return h;
}

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

FORCE_INLINE constexpr uint64_t fmix64(uint64_t k) {
  k ^= k >> 33;
  k *= BIG_CONSTANT(0xff51afd7ed558ccd);
  k ^= k >> 33;
  k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
  k ^= k >> 33;

  return k;
}

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

namespace onnxruntime {
void MurmurHash3::x86_32(const void* key, int len,
                         uint32_t seed, void* out) {
  const uint8_t* data = (const uint8_t*)key;
  const int nblocks = len / 4;

  uint32_t h1 = seed;

  constexpr uint32_t c1 = 0xcc9e2d51;
  constexpr uint32_t c2 = 0x1b873593;

  //----------
  // body

  const uint32_t* blocks = (const uint32_t*)(data + static_cast<ptrdiff_t>(nblocks) * 4);

  for (int i = -nblocks; i; i++) {
    uint32_t k1 = getblock32(blocks, i);

    k1 *= c1;
    k1 = ROTL32(k1, 15);
    k1 *= c2;

    h1 ^= k1;
    h1 = ROTL32(h1, 13);
    h1 = h1 * 5 + 0xe6546b64;
  }

  //----------
  // tail

  const uint8_t* tail = (const uint8_t*)(data + static_cast<ptrdiff_t>(nblocks) * 4);

  uint32_t k1 = 0;

  switch (len & 3) {
    case 3:
      k1 ^= tail[2] << 16;
      [[fallthrough]];
    case 2:
      k1 ^= tail[1] << 8;
      [[fallthrough]];
    case 1:
      k1 ^= tail[0];
      k1 *= c1;
      k1 = ROTL32(k1, 15);
      k1 *= c2;
      h1 ^= k1;
  };

  //----------
  // finalization

  h1 ^= len;

  h1 = fmix32(h1);

  *(uint32_t*)out = h1;
}

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

void MurmurHash3::x86_128(const void* key, int len, uint32_t seed, void* out) {
  const uint8_t* data = (const uint8_t*)key;
  const int nblocks = len / 16;

  uint32_t h1 = seed;
  uint32_t h2 = seed;
  uint32_t h3 = seed;
  uint32_t h4 = seed;

  constexpr uint32_t c1 = 0x239b961b;
  constexpr uint32_t c2 = 0xab0e9789;
  constexpr uint32_t c3 = 0x38b34ae5;
  constexpr uint32_t c4 = 0xa1e38b93;

  //----------
  // body

  const uint32_t* blocks = (const uint32_t*)(data + static_cast<ptrdiff_t>(nblocks) * 16);

  for (int i = -nblocks; i; i++) {
    uint32_t k1 = getblock32(blocks, i * 4 + 0);
    uint32_t k2 = getblock32(blocks, i * 4 + 1);
    uint32_t k3 = getblock32(blocks, i * 4 + 2);
    uint32_t k4 = getblock32(blocks, i * 4 + 3);

    k1 *= c1;
    k1 = ROTL32(k1, 15);
    k1 *= c2;
    h1 ^= k1;

    h1 = ROTL32(h1, 19);
    h1 += h2;
    h1 = h1 * 5 + 0x561ccd1b;

    k2 *= c2;
    k2 = ROTL32(k2, 16);
    k2 *= c3;
    h2 ^= k2;

    h2 = ROTL32(h2, 17);
    h2 += h3;
    h2 = h2 * 5 + 0x0bcaa747;

    k3 *= c3;
    k3 = ROTL32(k3, 17);
    k3 *= c4;
    h3 ^= k3;

    h3 = ROTL32(h3, 15);
    h3 += h4;
    h3 = h3 * 5 + 0x96cd1c35;

    k4 *= c4;
    k4 = ROTL32(k4, 18);
    k4 *= c1;
    h4 ^= k4;

    h4 = ROTL32(h4, 13);
    h4 += h1;
    h4 = h4 * 5 + 0x32ac3b17;
  }

  //----------
  // tail

  const uint8_t* tail = (const uint8_t*)(data + static_cast<ptrdiff_t>(nblocks) * 16);

  uint32_t k1 = 0;
  uint32_t k2 = 0;
  uint32_t k3 = 0;
  uint32_t k4 = 0;

  switch (len & 15) {
    case 15:
      k4 ^= tail[14] << 16;
      [[fallthrough]];
    case 14:
      k4 ^= tail[13] << 8;
      [[fallthrough]];
    case 13:
      k4 ^= tail[12] << 0;
      k4 *= c4;
      k4 = ROTL32(k4, 18);
      k4 *= c1;
      h4 ^= k4;
      [[fallthrough]];
    case 12:
      k3 ^= tail[11] << 24;
      [[fallthrough]];
    case 11:
      k3 ^= tail[10] << 16;
      [[fallthrough]];
    case 10:
      k3 ^= tail[9] << 8;
      [[fallthrough]];
    case 9:
      k3 ^= tail[8] << 0;
      k3 *= c3;
      k3 = ROTL32(k3, 17);
      k3 *= c4;
      h3 ^= k3;
      [[fallthrough]];
    case 8:
      k2 ^= tail[7] << 24;
      [[fallthrough]];
    case 7:
      k2 ^= tail[6] << 16;
      [[fallthrough]];
    case 6:
      k2 ^= tail[5] << 8;
      [[fallthrough]];
    case 5:
      k2 ^= tail[4] << 0;
      k2 *= c2;
      k2 = ROTL32(k2, 16);
      k2 *= c3;
      h2 ^= k2;
      [[fallthrough]];
    case 4:
      k1 ^= tail[3] << 24;
      [[fallthrough]];
    case 3:
      k1 ^= tail[2] << 16;
      [[fallthrough]];
    case 2:
      k1 ^= tail[1] << 8;
      [[fallthrough]];
    case 1:
      k1 ^= tail[0] << 0;
      k1 *= c1;
      k1 = ROTL32(k1, 15);
      k1 *= c2;
      h1 ^= k1;
  };

  //----------
  // finalization

  h1 ^= len;
  h2 ^= len;
  h3 ^= len;
  h4 ^= len;

  h1 += h2;
  h1 += h3;
  h1 += h4;
  h2 += h1;
  h3 += h1;
  h4 += h1;

  h1 = fmix32(h1);
  h2 = fmix32(h2);
  h3 = fmix32(h3);
  h4 = fmix32(h4);

  h1 += h2;
  h1 += h3;
  h1 += h4;
  h2 += h1;
  h3 += h1;
  h4 += h1;

  ((uint32_t*)out)[0] = h1;
  ((uint32_t*)out)[1] = h2;
  ((uint32_t*)out)[2] = h3;
  ((uint32_t*)out)[3] = h4;
}

}  // namespace onnxruntime
<commit_msg>Add big endian support to murmurhash3 (#12549)<commit_after>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "core/framework/murmurhash3.h"

// Original source: https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
//-----------------------------------------------------------------------------
// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.

// Note - The x86 and x64 versions do _not_ produce the same results, as the
// algorithms are optimized for their respective platforms. You can still
// compile and run any of them on any platform, but your performance with the
// non-native version will be less than optimal.

/* Modifications Copyright (c) Microsoft. */

#include "core/framework/endian.h"

//-----------------------------------------------------------------------------
// Platform-specific functions and macros

// Microsoft Visual Studio

#if defined(_MSC_VER)

#define FORCE_INLINE __forceinline

#include <stdlib.h>

#define ROTL32(x, y) _rotl(x, y)
#define ROTL64(x, y) _rotl64(x, y)

#define BIG_CONSTANT(x) (x)

// Other compilers

#else  // defined(_MSC_VER)

#define FORCE_INLINE inline __attribute__((always_inline))

inline uint32_t rotl32(uint32_t x, int8_t r) {
  return (x << r) | (x >> (32 - r));
}

inline uint64_t rotl64(uint64_t x, int8_t r) {
  return (x << r) | (x >> (64 - r));
}

#define ROTL32(x, y) rotl32(x, y)
#define ROTL64(x, y) rotl64(x, y)

#define BIG_CONSTANT(x) (x##LLU)

#endif  // !defined(_MSC_VER)
#include <cstddef>
//-----------------------------------------------------------------------------
// Block read - on little-endian machines this is a single load,
// while on big-endian or unknown machines the byte accesses should
// still get optimized into the most efficient instruction.
//
// Changes to support big-endian from https://github.com/explosion/murmurhash/pull/27/
// were manually applied to original murmurhash3 source code.
FORCE_INLINE uint32_t getblock32(const uint32_t* p, int i) {
  if constexpr (onnxruntime::endian::native == onnxruntime::endian::little) {
    return p[i];
  } else {
    const uint8_t* c = (const uint8_t*)&p[i];
    return (uint32_t)c[0] |
           (uint32_t)c[1] << 8 |
           (uint32_t)c[2] << 16 |
           (uint32_t)c[3] << 24;
  }
}

FORCE_INLINE uint64_t getblock64(const uint64_t* p, int i) {
  if constexpr (onnxruntime::endian::native == onnxruntime::endian::little) {
    return p[i];
  } else {
    const uint8_t* c = (const uint8_t*)&p[i];
    return (uint64_t)c[0] |
           (uint64_t)c[1] << 8 |
           (uint64_t)c[2] << 16 |
           (uint64_t)c[3] << 24 |
           (uint64_t)c[4] << 32 |
           (uint64_t)c[5] << 40 |
           (uint64_t)c[6] << 48 |
           (uint64_t)c[7] << 56;
  }
}

//-----------------------------------------------------------------------------
// Finalization mix - force all bits of a hash block to avalanche

FORCE_INLINE constexpr uint32_t fmix32(uint32_t h) {
  h ^= h >> 16;
  h *= 0x85ebca6b;
  h ^= h >> 13;
  h *= 0xc2b2ae35;
  h ^= h >> 16;

  return h;
}

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

FORCE_INLINE constexpr uint64_t fmix64(uint64_t k) {
  k ^= k >> 33;
  k *= BIG_CONSTANT(0xff51afd7ed558ccd);
  k ^= k >> 33;
  k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
  k ^= k >> 33;

  return k;
}

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

namespace onnxruntime {
void MurmurHash3::x86_32(const void* key, int len,
                         uint32_t seed, void* out) {
  const uint8_t* data = (const uint8_t*)key;
  const int nblocks = len / 4;

  uint32_t h1 = seed;

  constexpr uint32_t c1 = 0xcc9e2d51;
  constexpr uint32_t c2 = 0x1b873593;

  //----------
  // body

  const uint32_t* blocks = (const uint32_t*)(data + static_cast<ptrdiff_t>(nblocks) * 4);

  for (int i = -nblocks; i; i++) {
    uint32_t k1 = getblock32(blocks, i);

    k1 *= c1;
    k1 = ROTL32(k1, 15);
    k1 *= c2;

    h1 ^= k1;
    h1 = ROTL32(h1, 13);
    h1 = h1 * 5 + 0xe6546b64;
  }

  //----------
  // tail

  const uint8_t* tail = (const uint8_t*)(data + static_cast<ptrdiff_t>(nblocks) * 4);

  uint32_t k1 = 0;

  switch (len & 3) {
    case 3:
      k1 ^= tail[2] << 16;
      [[fallthrough]];
    case 2:
      k1 ^= tail[1] << 8;
      [[fallthrough]];
    case 1:
      k1 ^= tail[0];
      k1 *= c1;
      k1 = ROTL32(k1, 15);
      k1 *= c2;
      h1 ^= k1;
  };

  //----------
  // finalization

  h1 ^= len;

  h1 = fmix32(h1);

  *(uint32_t*)out = h1;
}

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

void MurmurHash3::x86_128(const void* key, int len, uint32_t seed, void* out) {
  const uint8_t* data = (const uint8_t*)key;
  const int nblocks = len / 16;

  uint32_t h1 = seed;
  uint32_t h2 = seed;
  uint32_t h3 = seed;
  uint32_t h4 = seed;

  constexpr uint32_t c1 = 0x239b961b;
  constexpr uint32_t c2 = 0xab0e9789;
  constexpr uint32_t c3 = 0x38b34ae5;
  constexpr uint32_t c4 = 0xa1e38b93;

  //----------
  // body

  const uint32_t* blocks = (const uint32_t*)(data + static_cast<ptrdiff_t>(nblocks) * 16);

  for (int i = -nblocks; i; i++) {
    uint32_t k1 = getblock32(blocks, i * 4 + 0);
    uint32_t k2 = getblock32(blocks, i * 4 + 1);
    uint32_t k3 = getblock32(blocks, i * 4 + 2);
    uint32_t k4 = getblock32(blocks, i * 4 + 3);

    k1 *= c1;
    k1 = ROTL32(k1, 15);
    k1 *= c2;
    h1 ^= k1;

    h1 = ROTL32(h1, 19);
    h1 += h2;
    h1 = h1 * 5 + 0x561ccd1b;

    k2 *= c2;
    k2 = ROTL32(k2, 16);
    k2 *= c3;
    h2 ^= k2;

    h2 = ROTL32(h2, 17);
    h2 += h3;
    h2 = h2 * 5 + 0x0bcaa747;

    k3 *= c3;
    k3 = ROTL32(k3, 17);
    k3 *= c4;
    h3 ^= k3;

    h3 = ROTL32(h3, 15);
    h3 += h4;
    h3 = h3 * 5 + 0x96cd1c35;

    k4 *= c4;
    k4 = ROTL32(k4, 18);
    k4 *= c1;
    h4 ^= k4;

    h4 = ROTL32(h4, 13);
    h4 += h1;
    h4 = h4 * 5 + 0x32ac3b17;
  }

  //----------
  // tail

  const uint8_t* tail = (const uint8_t*)(data + static_cast<ptrdiff_t>(nblocks) * 16);

  uint32_t k1 = 0;
  uint32_t k2 = 0;
  uint32_t k3 = 0;
  uint32_t k4 = 0;

  switch (len & 15) {
    case 15:
      k4 ^= tail[14] << 16;
      [[fallthrough]];
    case 14:
      k4 ^= tail[13] << 8;
      [[fallthrough]];
    case 13:
      k4 ^= tail[12] << 0;
      k4 *= c4;
      k4 = ROTL32(k4, 18);
      k4 *= c1;
      h4 ^= k4;
      [[fallthrough]];
    case 12:
      k3 ^= tail[11] << 24;
      [[fallthrough]];
    case 11:
      k3 ^= tail[10] << 16;
      [[fallthrough]];
    case 10:
      k3 ^= tail[9] << 8;
      [[fallthrough]];
    case 9:
      k3 ^= tail[8] << 0;
      k3 *= c3;
      k3 = ROTL32(k3, 17);
      k3 *= c4;
      h3 ^= k3;
      [[fallthrough]];
    case 8:
      k2 ^= tail[7] << 24;
      [[fallthrough]];
    case 7:
      k2 ^= tail[6] << 16;
      [[fallthrough]];
    case 6:
      k2 ^= tail[5] << 8;
      [[fallthrough]];
    case 5:
      k2 ^= tail[4] << 0;
      k2 *= c2;
      k2 = ROTL32(k2, 16);
      k2 *= c3;
      h2 ^= k2;
      [[fallthrough]];
    case 4:
      k1 ^= tail[3] << 24;
      [[fallthrough]];
    case 3:
      k1 ^= tail[2] << 16;
      [[fallthrough]];
    case 2:
      k1 ^= tail[1] << 8;
      [[fallthrough]];
    case 1:
      k1 ^= tail[0] << 0;
      k1 *= c1;
      k1 = ROTL32(k1, 15);
      k1 *= c2;
      h1 ^= k1;
  };

  //----------
  // finalization

  h1 ^= len;
  h2 ^= len;
  h3 ^= len;
  h4 ^= len;

  h1 += h2;
  h1 += h3;
  h1 += h4;
  h2 += h1;
  h3 += h1;
  h4 += h1;

  h1 = fmix32(h1);
  h2 = fmix32(h2);
  h3 = fmix32(h3);
  h4 = fmix32(h4);

  h1 += h2;
  h1 += h3;
  h1 += h4;
  h2 += h1;
  h3 += h1;
  h4 += h1;

  ((uint32_t*)out)[0] = h1;
  ((uint32_t*)out)[1] = h2;
  ((uint32_t*)out)[2] = h3;
  ((uint32_t*)out)[3] = h4;
}

}  // namespace onnxruntime
<|endoftext|>


<commit_before>/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"
#include "sk_tool_utils.h"

#include "SkSurface.h"

#if SK_SUPPORT_GPU

#include "SkImage_Gpu.h"

static const int kNumMatrices = 6;
static const int kImageSize = 128;
static const int kLabelSize = 32;
static const int kNumLabels = 4;

static const int kCellSize = kImageSize+2*kLabelSize;
static const int kGMWidth  = kNumMatrices*kCellSize;
static const int kGMHeight = 2*kCellSize;

static const SkPoint kPoints[kNumLabels] = {
    {          0, kImageSize },     // kLL
    { kImageSize, kImageSize },     // kLR
    {          0,          0 },     // kUL
    { kImageSize,          0 },     // kUR
};

static const SkMatrix kUVMatrices[kNumMatrices] = {
    SkMatrix::MakeAll( 0, -1, 1,
                      -1,  0, 1,
                       0,  0, 1),
    SkMatrix::MakeAll( 1,  0, 0,
                       0, -1, 1,
                       0,  0, 1),
    // flip x
    SkMatrix::MakeAll(-1,  0, 1,
                       0,  1, 0,
                       0,  0, 1),
    SkMatrix::MakeAll( 0,  1, 0,
                      -1,  0, 1,
                       0,  0, 1),
    // flip both x & y == rotate 180
    SkMatrix::MakeAll(-1,  0, 1,
                       0, -1, 1,
                       0,  0, 1),
    // identity
    SkMatrix::MakeAll(1,  0, 0,
                      0,  1, 0,
                      0,  0, 1)
};

// Create a fixed size text label like "LL" or "LR".
static sk_sp<SkImage> make_text_image(GrContext* context, const char* text, SkColor color) {
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setTextSize(32);
    paint.setColor(color);

    SkRect bounds;
    paint.measureText(text, strlen(text), &bounds);
    const SkMatrix mat = SkMatrix::MakeRectToRect(bounds, SkRect::MakeWH(kLabelSize, kLabelSize),
                                                  SkMatrix::kFill_ScaleToFit);

    const SkImageInfo ii = SkImageInfo::MakeN32Premul(kLabelSize, kLabelSize);
    sk_sp<SkSurface> surf = SkSurface::MakeRaster(ii);

    SkCanvas* canvas = surf->getCanvas();

    canvas->clear(SK_ColorWHITE);
    canvas->concat(mat);
    canvas->drawText(text, strlen(text), 0, 0, paint);

    sk_sp<SkImage> image = surf->makeImageSnapshot();

    return image->makeTextureImage(context, nullptr);
}

static SkColor swap_red_and_blue(SkColor c) {
    return SkColorSetRGB(SkColorGetB(c), SkColorGetG(c), SkColorGetR(c));
}

// Create an image with each corner marked w/ "LL", "LR", etc., with the origin either bottom-left
// or top-left.
static sk_sp<SkImage> make_image(GrContext* context, const SkTArray<sk_sp<SkImage>>& labels,
                                 bool bottomLeftOrigin) {
    SkASSERT(kNumLabels == labels.count());

    SkImageInfo ii = SkImageInfo::Make(kImageSize, kImageSize,
                                       kN32_SkColorType, kOpaque_SkAlphaType);
    SkBitmap bm;
    bm.allocPixels(ii);
    SkCanvas canvas(bm);

    canvas.clear(SK_ColorWHITE);
    for (int i = 0; i < kNumLabels; ++i) {
        canvas.drawImage(labels[i],
                         0.0 != kPoints[i].fX ? kPoints[i].fX-kLabelSize : 0,
                         0.0 != kPoints[i].fY ? kPoints[i].fY-kLabelSize : 0);
    }

    GrSurfaceDesc desc;
    desc.fOrigin = kTopLeft_GrSurfaceOrigin;
    desc.fWidth = kImageSize;
    desc.fHeight = kImageSize;
    desc.fConfig = kRGBA_8888_GrPixelConfig;

    if (bottomLeftOrigin) {
        // Note that Ganesh will flip the data when it is uploaded
        desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
    }

    if (kN32_SkColorType == kBGRA_8888_SkColorType) {
        // We're playing a game here and uploading N32 data into an RGB dest. We might have
        // to swap red & blue to compensate.
        for (int y = 0; y < bm.height(); ++y) {
            uint32_t *sl = bm.getAddr32(0, y);
            for (int x = 0; x < bm.width(); ++x) {
                sl[x] = swap_red_and_blue(sl[x]);
            }
        }
    }

    sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
                                                               desc, SkBudgeted::kYes,
                                                               bm.getPixels(), bm.rowBytes());
    if (!proxy) {
        return nullptr;
    }

    return sk_make_sp<SkImage_Gpu>(context, kNeedNewImageUniqueID, kOpaque_SkAlphaType,
                                   std::move(proxy), nullptr, SkBudgeted::kYes);
}

// Here we're converting from a matrix that is intended for UVs to a matrix that is intended
// for rect geometry used for a drawImage call. They are, in some sense, inverses of each
// other but we also need a scale to map from the [0..1] uv range to the actual size of
// image.
static bool UVMatToGeomMatForImage(SkMatrix* geomMat, const SkMatrix& uvMat) {
    SkMatrix tmp = uvMat;
    tmp.preScale(1.0f/kImageSize, 1.0f/kImageSize);
    tmp.postScale(kImageSize, kImageSize);

    return tmp.invert(geomMat);
}

// This GM exercises drawImage with a set of matrices that use an unusual amount of flips and
// rotates.
class FlippityGM : public skiagm::GM {
public:
    FlippityGM() {
        this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
    }

protected:

    SkString onShortName() override {
        return SkString("flippity");
    }

    SkISize onISize() override {
        return SkISize::Make(kGMWidth, kGMHeight);
    }

    // Draw the reference image and the four corner labels in the matrix's coordinate space
    void drawImageWithMatrixAndLabels(SkCanvas* canvas, SkImage* image, int matIndex) {
        SkMatrix imageGeomMat;
        SkAssertResult(UVMatToGeomMatForImage(&imageGeomMat, kUVMatrices[matIndex]));

        canvas->save();
            canvas->concat(imageGeomMat);

            // draw the reference image
            canvas->drawImage(image, 0, 0);

            // draw the labels
            for (int i = 0; i < kNumLabels; ++i) {
                canvas->drawImage(fLabels[i],
                                    0.0f == kPoints[i].fX ? -kLabelSize : kPoints[i].fX,
                                    0.0f == kPoints[i].fY ? -kLabelSize : kPoints[i].fY);
            }
        canvas->restore();
    }

    void makeLabels(GrContext* context) {
        static const char* kLabelText[kNumLabels] = { "LL", "LR", "UL", "UR" };

        static const SkColor kLabelColors[kNumLabels] = {
            SK_ColorRED,
            SK_ColorGREEN,
            SK_ColorBLUE,
            SK_ColorCYAN
        };

        SkASSERT(!fLabels.count());
        for (int i = 0; i < kNumLabels; ++i) {
            fLabels.push_back(make_text_image(context, kLabelText[i], kLabelColors[i]));
        }
        SkASSERT(kNumLabels == fLabels.count());
    }

    void onDraw(SkCanvas* canvas) override {
        GrContext* context = canvas->getGrContext();
        if (!context) {
            skiagm::GM::DrawGpuOnlyMessage(canvas);
            return;
        }

        this->makeLabels(context);

        // Top row gets TL image
        {
            sk_sp<SkImage> referenceImage = make_image(context, fLabels, false);

            canvas->save();
                canvas->translate(kLabelSize, kLabelSize);

                for (int i = 0; i < kNumMatrices; ++i) {
                    this->drawImageWithMatrixAndLabels(canvas, referenceImage.get(), i);
                    canvas->translate(kImageSize+2*kLabelSize, 0);
                }
            canvas->restore();
        }

        // Bottom row gets BL image
        {
            sk_sp<SkImage> referenceImage = make_image(context, fLabels, true);

            canvas->save();
                canvas->translate(kLabelSize, kImageSize+3*kLabelSize);

                for (int i = 0; i < kNumMatrices; ++i) {
                    this->drawImageWithMatrixAndLabels(canvas, referenceImage.get(), i);
                    canvas->translate(kCellSize, 0);
                }
            canvas->restore();
        }

        // separator grid
        canvas->drawLine(0, kCellSize, kGMWidth, kCellSize, SkPaint());
        for (int i = 0; i < kNumMatrices; ++i) {
            canvas->drawLine(i * kCellSize, 0, i * kCellSize, kGMHeight, SkPaint());
        }
    }

private:
    SkTArray<sk_sp<SkImage>> fLabels;

    typedef GM INHERITED;
};

DEF_GM(return new FlippityGM;)

#endif
<commit_msg>Update the texture flip GM to include subsets & scales<commit_after>/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"
#include "sk_tool_utils.h"

#include "SkSurface.h"

#if SK_SUPPORT_GPU

#include "SkImage_Gpu.h"

static const int kNumMatrices = 6;
static const int kImageSize = 128;
static const int kLabelSize = 32;
static const int kNumLabels = 4;
static const int kInset = 16;

static const int kCellSize = kImageSize+2*kLabelSize;
static const int kGMWidth  = kNumMatrices*kCellSize;
static const int kGMHeight = 4*kCellSize;

static const SkPoint kPoints[kNumLabels] = {
    {          0, kImageSize },     // LL
    { kImageSize, kImageSize },     // LR
    {          0,          0 },     // UL
    { kImageSize,          0 },     // UR
};

static const SkMatrix kUVMatrices[kNumMatrices] = {
    SkMatrix::MakeAll( 0, -1, 1,
                      -1,  0, 1,
                       0,  0, 1),
    SkMatrix::MakeAll( 1,  0, 0,
                       0, -1, 1,
                       0,  0, 1),
    // flip x
    SkMatrix::MakeAll(-1,  0, 1,
                       0,  1, 0,
                       0,  0, 1),
    SkMatrix::MakeAll( 0,  1, 0,
                      -1,  0, 1,
                       0,  0, 1),
    // flip both x & y == rotate 180
    SkMatrix::MakeAll(-1,  0, 1,
                       0, -1, 1,
                       0,  0, 1),
    // identity
    SkMatrix::MakeAll(1,  0, 0,
                      0,  1, 0,
                      0,  0, 1)
};

// Create a fixed size text label like "LL" or "LR".
static sk_sp<SkImage> make_text_image(GrContext* context, const char* text, SkColor color) {
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setTextSize(32);
    paint.setColor(color);

    SkRect bounds;
    paint.measureText(text, strlen(text), &bounds);
    const SkMatrix mat = SkMatrix::MakeRectToRect(bounds, SkRect::MakeWH(kLabelSize, kLabelSize),
                                                  SkMatrix::kFill_ScaleToFit);

    const SkImageInfo ii = SkImageInfo::MakeN32Premul(kLabelSize, kLabelSize);
    sk_sp<SkSurface> surf = SkSurface::MakeRaster(ii);

    SkCanvas* canvas = surf->getCanvas();

    canvas->clear(SK_ColorWHITE);
    canvas->concat(mat);
    canvas->drawText(text, strlen(text), 0, 0, paint);

    sk_sp<SkImage> image = surf->makeImageSnapshot();

    return image->makeTextureImage(context, nullptr);
}

static SkColor swap_red_and_blue(SkColor c) {
    return SkColorSetRGB(SkColorGetB(c), SkColorGetG(c), SkColorGetR(c));
}

// Create an image with each corner marked w/ "LL", "LR", etc., with the origin either bottom-left
// or top-left.
static sk_sp<SkImage> make_reference_image(GrContext* context,
                                           const SkTArray<sk_sp<SkImage>>& labels,
                                           bool bottomLeftOrigin) {
    SkASSERT(kNumLabels == labels.count());

    SkImageInfo ii = SkImageInfo::Make(kImageSize, kImageSize,
                                       kN32_SkColorType, kOpaque_SkAlphaType);
    SkBitmap bm;
    bm.allocPixels(ii);
    SkCanvas canvas(bm);

    canvas.clear(SK_ColorWHITE);
    for (int i = 0; i < kNumLabels; ++i) {
        canvas.drawImage(labels[i],
                         0.0 != kPoints[i].fX ? kPoints[i].fX-kLabelSize-kInset : kInset,
                         0.0 != kPoints[i].fY ? kPoints[i].fY-kLabelSize-kInset : kInset);
    }

    GrSurfaceDesc desc;
    desc.fOrigin = kTopLeft_GrSurfaceOrigin;
    desc.fWidth = kImageSize;
    desc.fHeight = kImageSize;
    desc.fConfig = kRGBA_8888_GrPixelConfig;

    if (bottomLeftOrigin) {
        // Note that Ganesh will flip the data when it is uploaded
        desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
    }

    if (kN32_SkColorType == kBGRA_8888_SkColorType) {
        // We're playing a game here and uploading N32 data into an RGB dest. We might have
        // to swap red & blue to compensate.
        for (int y = 0; y < bm.height(); ++y) {
            uint32_t *sl = bm.getAddr32(0, y);
            for (int x = 0; x < bm.width(); ++x) {
                sl[x] = swap_red_and_blue(sl[x]);
            }
        }
    }

    sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeDeferred(context->resourceProvider(),
                                                               desc, SkBudgeted::kYes,
                                                               bm.getPixels(), bm.rowBytes());
    if (!proxy) {
        return nullptr;
    }

    return sk_make_sp<SkImage_Gpu>(context, kNeedNewImageUniqueID, kOpaque_SkAlphaType,
                                   std::move(proxy), nullptr, SkBudgeted::kYes);
}

// Here we're converting from a matrix that is intended for UVs to a matrix that is intended
// for rect geometry used for a drawImage call. They are, in some sense, inverses of each
// other but we also need a scale to map from the [0..1] uv range to the actual size of
// image.
static bool UVMatToGeomMatForImage(SkMatrix* geomMat, const SkMatrix& uvMat) {

    const SkMatrix yFlip = SkMatrix::MakeAll(1, 0, 0, 0, -1, 1, 0, 0, 1);

    SkMatrix tmp = uvMat;
    tmp.preConcat(yFlip);
    tmp.preScale(1.0f/kImageSize, 1.0f/kImageSize);

    tmp.postConcat(yFlip);
    tmp.postScale(kImageSize, kImageSize);

    return tmp.invert(geomMat);
}

// This GM exercises drawImage with a set of matrices that use an unusual amount of flips and
// rotates.
class FlippityGM : public skiagm::GM {
public:
    FlippityGM() {
        this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
    }

protected:

    SkString onShortName() override {
        return SkString("flippity");
    }

    SkISize onISize() override {
        return SkISize::Make(kGMWidth, kGMHeight);
    }

    // Draw the reference image and the four corner labels in the matrix's coordinate space
    void drawImageWithMatrixAndLabels(SkCanvas* canvas, SkImage* image, int matIndex,
                                      bool drawSubset, bool drawScaled) {
        static const SkRect kSubsets[kNumMatrices] = {
            SkRect::MakeXYWH(kInset, 0, kImageSize-kInset, kImageSize),
            SkRect::MakeXYWH(0, kInset, kImageSize, kImageSize-kInset),
            SkRect::MakeXYWH(0, 0, kImageSize-kInset, kImageSize),
            SkRect::MakeXYWH(0, 0, kImageSize, kImageSize-kInset),
            SkRect::MakeXYWH(kInset/2, kInset/2, kImageSize-kInset, kImageSize-kInset),
            SkRect::MakeXYWH(kInset, kInset, kImageSize-2*kInset, kImageSize-2*kInset),
        };

        SkMatrix imageGeomMat;
        SkAssertResult(UVMatToGeomMatForImage(&imageGeomMat, kUVMatrices[matIndex]));

        canvas->save();

            // draw the reference image
            canvas->concat(imageGeomMat);
            if (drawSubset) {
                canvas->drawImageRect(image, kSubsets[matIndex],
                                      drawScaled ? SkRect::MakeWH(kImageSize, kImageSize)
                                                 : kSubsets[matIndex],
                                      nullptr, SkCanvas::kFast_SrcRectConstraint);
            } else {
                canvas->drawImage(image, 0, 0);
            }

            // draw the labels
            for (int i = 0; i < kNumLabels; ++i) {
                canvas->drawImage(fLabels[i],
                                    0.0f == kPoints[i].fX ? -kLabelSize : kPoints[i].fX,
                                    0.0f == kPoints[i].fY ? -kLabelSize : kPoints[i].fY);
            }
        canvas->restore();
    }

    void drawRow(GrContext* context, SkCanvas* canvas,
                 bool bottomLeftImage, bool drawSubset, bool drawScaled) {

        sk_sp<SkImage> referenceImage = make_reference_image(context, fLabels, bottomLeftImage);

        canvas->save();
            canvas->translate(kLabelSize, kLabelSize);

            for (int i = 0; i < kNumMatrices; ++i) {
                this->drawImageWithMatrixAndLabels(canvas, referenceImage.get(), i,
                                                   drawSubset, drawScaled);
                canvas->translate(kCellSize, 0);
            }
        canvas->restore();
    }

    void makeLabels(GrContext* context) {
        static const char* kLabelText[kNumLabels] = { "LL", "LR", "UL", "UR" };

        static const SkColor kLabelColors[kNumLabels] = {
            SK_ColorRED,
            SK_ColorGREEN,
            SK_ColorBLUE,
            SK_ColorCYAN
        };

        SkASSERT(!fLabels.count());
        for (int i = 0; i < kNumLabels; ++i) {
            fLabels.push_back(make_text_image(context, kLabelText[i], kLabelColors[i]));
        }
        SkASSERT(kNumLabels == fLabels.count());
    }

    void onDraw(SkCanvas* canvas) override {
        GrContext* context = canvas->getGrContext();
        if (!context) {
            skiagm::GM::DrawGpuOnlyMessage(canvas);
            return;
        }

        this->makeLabels(context);

        // Top row gets TL image
        this->drawRow(context, canvas, false, false, false);

        canvas->translate(0, kCellSize);

        // Bottom row gets BL image
        this->drawRow(context, canvas, true, false, false);

        canvas->translate(0, kCellSize);

        // Third row gets subsets of BL images
        this->drawRow(context, canvas, true, true, false);

        canvas->translate(0, kCellSize);

        // Fourth row gets scaled subsets of BL images
        this->drawRow(context, canvas, true, true, true);

        // separator grid
        canvas->drawLine(0, kCellSize, kGMWidth, kCellSize, SkPaint());
        for (int i = 0; i < kNumMatrices; ++i) {
            canvas->drawLine(i * kCellSize, 0, i * kCellSize, kGMHeight, SkPaint());
        }
    }

private:
    SkTArray<sk_sp<SkImage>> fLabels;

    typedef GM INHERITED;
};

DEF_GM(return new FlippityGM;)

#endif
<|endoftext|>


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

#include "Kernel.h"

namespace rtos {

uint64_t Kernel::get_ms_count()
{
    return 20;
}
}
<commit_msg>Add Kernel::impl::get_tick_count() stub<commit_after>/*
 * Copyright (c) , Arm Limited and affiliates.
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Kernel.h"

namespace rtos {

uint64_t Kernel::get_ms_count()
{
    return impl::get_tick_count();

}
uint64_t Kernel::impl::get_tick_count()
{
    return 20;
}
}
<|endoftext|>


<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

//
// Wrapper for MEVSIM generator.
// It is using TMevSim to comunicate with fortarn code
//
//
// Sylwester Radomski <radomski@if.pw.edu.pl>
//

//#include "TSystem.h"
//#include "TUnixSystem.h"
#include "TParticle.h"
#include "TMevSim.h"

#include "AliGenMevSim.h"
#include "AliRun.h"

static TRandom * sRandom;

ClassImp(AliGenMevSim)

//____________________________________________________________________________
AliGenMevSim::AliGenMevSim() : AliGenerator(-1)
{
  //
  // Standard creator
  //

  fConfig = new AliMevSimConfig();
  fMevSim = new TMevSim();
  sRandom = fRandom;

}
//____________________________________________________________________________
AliGenMevSim::AliGenMevSim(AliMevSimConfig *config): AliGenerator(-1) {

  fConfig = config;
  fMevSim = new TMevSim();
  sRandom = fRandom;
}

//____________________________________________________________________________
AliGenMevSim::~AliGenMevSim()
{
  //
  // Standard destructor
  //
  if (fMevSim) delete fMevSim;
}
//____________________________________________________________________________
void AliGenMevSim::SetConfig(AliMevSimConfig *config) {

  fConfig = config;
}
//____________________________________________________________________________
void AliGenMevSim::AddParticleType(AliMevSimParticle *type) {

  fMevSim->AddPartTypeParams((TMevSimPartTypeParams*)type);
}
//____________________________________________________________________________
void AliGenMevSim::Init()
{
  //
  // Generator initialisation method
  //

  // fill data from AliMevSimConfig;

  TMevSim *mevsim = fMevSim;

  // geometry & momentum cut

  if (TestBit(kPtRange))  mevsim->SetPtCutRange(fPtMin, fPtMax);

  if (TestBit(kPhiRange)) // from radians to 0 - 360 deg
    mevsim->SetPhiCutRange( fPhiMin * 180 / TMath::Pi() , fPhiMax * 180 / TMath::Pi() );

  if (TestBit(kThetaRange)) // from theta to eta
  {
    mevsim->SetEtaCutRange( -TMath::Log( TMath::Tan(fThetaMax/2)) , -TMath::Log( TMath::Tan(fThetaMin/2)) );
  }

  // mevsim specyfic parameters

  mevsim->SetModelType(fConfig->GetModelType());
  Int_t ctrl; Float_t psiRMean = 0; Float_t psiRStDev = 0;
  fConfig->GetRectPlane(ctrl,psiRMean,psiRStDev);
  mevsim->SetReacPlaneCntrl(ctrl);
  mevsim->SetPsiRParams(psiRMean, psiRStDev);
  Float_t mean; Float_t stDev;
  fConfig->GetMultFac(mean,stDev);
  mevsim->SetMultFacParams(mean,stDev);
  // mevsim initialisation

  mevsim->Initialize();
}

//____________________________________________________________________________
void AliGenMevSim::Generate()
{
  //
  // Read the formatted output file and load the particles
  // Temporary solution
  //

  Int_t i;

  PDG_t pdg;
  Float_t orgin[3] = {0,0,0};
  Float_t polar[3] = {0,0,0};
  Float_t p[3] = {1,1,1};
  Float_t time = 0;

  const Int_t parent = -1;
  Int_t id;

  // vertexing

  VertexInternal();

  orgin[0] = fVertex[0];
  orgin[1] = fVertex[1];
  orgin[2] = fVertex[2];

  cout << "Vertex ";
  for (i =0; i<3; i++)
    cout << orgin[i] << "\t";
  cout << endl;

  Int_t nParticles = 0;

  TClonesArray *particles = new TClonesArray("TParticle");
  TParticle *particle;

  fMevSim->GenerateEvent();
  fNpart= fMevSim->ImportParticles(particles,"");

  cout << "Found " << fNpart << " particles ..." << endl;
  nParticles = fNpart;

  for (i=0; i<nParticles; i++) {

    particle = (TParticle*) (*particles)[i];

    pdg = (PDG_t) particle->GetPdgCode();
    p[0] = particle->Px();
    p[1] = particle->Py();
    p[2] = particle->Pz();

    PushTrack(fTrackIt, parent, pdg, p, orgin, polar, time, kPPrimary, id);

  }

  particles->Clear();
  if (particles) delete particles;
}
//____________________________________________________________________________
//____________________________________________________________________________

#ifndef WIN32
# define ran ran_
# define type_of_call
#else
# define ran RAN
# define type_of_call _stdcall
#endif

extern "C" Float_t type_of_call ran(Int_t &)
{
  return sRandom->Rndm();
}

//____________________________________________________________________________
<commit_msg>Missing include<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

//
// Wrapper for MEVSIM generator.
// It is using TMevSim to comunicate with fortarn code
//
//
// Sylwester Radomski <radomski@if.pw.edu.pl>
//

#include <Riostream.h>

//#include "TSystem.h"
//#include "TUnixSystem.h"
#include "TParticle.h"
#include "TMevSim.h"

#include "AliGenMevSim.h"
#include "AliRun.h"

static TRandom * sRandom;

ClassImp(AliGenMevSim)

//____________________________________________________________________________
AliGenMevSim::AliGenMevSim() : AliGenerator(-1)
{
  //
  // Standard creator
  //

  fConfig = new AliMevSimConfig();
  fMevSim = new TMevSim();
  sRandom = fRandom;

}
//____________________________________________________________________________
AliGenMevSim::AliGenMevSim(AliMevSimConfig *config): AliGenerator(-1) {

  fConfig = config;
  fMevSim = new TMevSim();
  sRandom = fRandom;
}

//____________________________________________________________________________
AliGenMevSim::~AliGenMevSim()
{
  //
  // Standard destructor
  //
  if (fMevSim) delete fMevSim;
}
//____________________________________________________________________________
void AliGenMevSim::SetConfig(AliMevSimConfig *config) {

  fConfig = config;
}
//____________________________________________________________________________
void AliGenMevSim::AddParticleType(AliMevSimParticle *type) {

  fMevSim->AddPartTypeParams((TMevSimPartTypeParams*)type);
}
//____________________________________________________________________________
void AliGenMevSim::Init()
{
  //
  // Generator initialisation method
  //

  // fill data from AliMevSimConfig;

  TMevSim *mevsim = fMevSim;

  // geometry & momentum cut

  if (TestBit(kPtRange))  mevsim->SetPtCutRange(fPtMin, fPtMax);

  if (TestBit(kPhiRange)) // from radians to 0 - 360 deg
    mevsim->SetPhiCutRange( fPhiMin * 180 / TMath::Pi() , fPhiMax * 180 / TMath::Pi() );

  if (TestBit(kThetaRange)) // from theta to eta
  {
    mevsim->SetEtaCutRange( -TMath::Log( TMath::Tan(fThetaMax/2)) , -TMath::Log( TMath::Tan(fThetaMin/2)) );
  }

  // mevsim specyfic parameters

  mevsim->SetModelType(fConfig->GetModelType());
  Int_t ctrl; Float_t psiRMean = 0; Float_t psiRStDev = 0;
  fConfig->GetRectPlane(ctrl,psiRMean,psiRStDev);
  mevsim->SetReacPlaneCntrl(ctrl);
  mevsim->SetPsiRParams(psiRMean, psiRStDev);
  Float_t mean; Float_t stDev;
  fConfig->GetMultFac(mean,stDev);
  mevsim->SetMultFacParams(mean,stDev);
  // mevsim initialisation

  mevsim->Initialize();
}

//____________________________________________________________________________
void AliGenMevSim::Generate()
{
  //
  // Read the formatted output file and load the particles
  // Temporary solution
  //

  Int_t i;

  PDG_t pdg;
  Float_t orgin[3] = {0,0,0};
  Float_t polar[3] = {0,0,0};
  Float_t p[3] = {1,1,1};
  Float_t time = 0;

  const Int_t parent = -1;
  Int_t id;

  // vertexing

  VertexInternal();

  orgin[0] = fVertex[0];
  orgin[1] = fVertex[1];
  orgin[2] = fVertex[2];

  cout << "Vertex ";
  for (i =0; i<3; i++)
    cout << orgin[i] << "\t";
  cout << endl;

  Int_t nParticles = 0;

  TClonesArray *particles = new TClonesArray("TParticle");
  TParticle *particle;

  fMevSim->GenerateEvent();
  fNpart= fMevSim->ImportParticles(particles,"");

  cout << "Found " << fNpart << " particles ..." << endl;
  nParticles = fNpart;

  for (i=0; i<nParticles; i++) {

    particle = (TParticle*) (*particles)[i];

    pdg = (PDG_t) particle->GetPdgCode();
    p[0] = particle->Px();
    p[1] = particle->Py();
    p[2] = particle->Pz();

    PushTrack(fTrackIt, parent, pdg, p, orgin, polar, time, kPPrimary, id);

  }

  particles->Clear();
  if (particles) delete particles;
}
//____________________________________________________________________________
//____________________________________________________________________________

#ifndef WIN32
# define ran ran_
# define type_of_call
#else
# define ran RAN
# define type_of_call _stdcall
#endif

extern "C" Float_t type_of_call ran(Int_t &)
{
  return sRandom->Rndm();
}

//____________________________________________________________________________
<|endoftext|>


<commit_before>#include "trainmonitor.h"
#include <QFile>
#include <QDir>
#include <QTextStream>
#include <QThread>

TrainMonitor::TrainMonitor()
{
#pragma message("[MKJ] Clean up when everything is done")
#pragma message("[MKJ] Look for things that would be useful in a log")

}

TrainMonitor::~TrainMonitor()
{

}

void TrainMonitor::do_run() {
    qDebug() << "do_run()";
    generateSectionList();
}

void TrainMonitor::do_handleOccupancy(QString section, bool state)
{
    qDebug() << "do_handleOccupancy entered";
    qDebug() << "New Occupancy Data at Monitor:" << section << " State:" << state;
	Section monitoredSection = retrieveSections(section);
	monitoredSection.setOccupancy(state);
    //if (state) Monitor(monitoredSection);
    if (state) Monitor(section);
}

void TrainMonitor::Monitor(QString section)
{
    qDebug() << "Monitor()";
    qDebug() << endl << endl << "Mike's debug";

    for (auto section : sectionPairs)
    {
        qDebug() << "last section is: " << section.first << " current section is:" << section.second << endl;
    }

    qDebug() << endl << endl;
#pragma message("[MKJ] Will nextSection1 be enough padding for a crash scenario?")
        //Section monitorSection = es.path.getNextSection1();

    Section currentSection = retrieveSections(section);
    qDebug() << "Starting monitor ....." << endl;
    switch (currentSection.getNumOfConns())
    {
        case 1:		// Endpoint case
        {
            updateSingleConnList(currentSection);
            qDebug() << "entered endpoint monitor" << endl;
            endpointMonitor(currentSection);
            break;
        }
        case 2:		// Straight case
        {
            updateDoubleConnList(currentSection);
            qDebug() << "entered straight monitor" << endl;
            straightMonitor(currentSection);
            break;
        }
        case 3:		// Switch case
        {
            updateTripleConnList(currentSection);
            qDebug() << "entered switch monitor" << endl;
            switchMonitor(currentSection);
            break;
        }
        case 4:		// Crossover case
        {
            updateQuadConnList(currentSection);
            qDebug() << "entered crossover monitor" << endl;
            //crossoverMonitor(currentSection);
            break;
        }
        default:
        {
            qFatal("Invalid track type");
            break;
        }
    }
}

void TrainMonitor::endpointMonitor(Section sec)
{
    qDebug() << "endpointMonitor()";
	// Shutdown the section since the means the train is headed
    // towards the end of the track
    for (auto section : sectionPairs)
    {
        if (sec.getNode() == section.second)
        {
            if(section.first != "")
            {
                qDebug() << "Shutting off section " << section.second;
                Section shutdownSection = retrieveSections(section.second);
                QStringList shutdownList = shutdownSection.getNode().split("-");
                emit sectionOff(shutdownList[0].toInt(),shutdownList[1].toInt());
            }
        }
    }
}

void TrainMonitor::straightMonitor(Section sec)
{
    qDebug() << "straightMonitor()" << sec.getNode();
    QString nextSection;
    bool found = false;

    for (auto section : sectionPairs)
    {

        qDebug() << sec.getNode() << " sec.second is:" << section.second << endl;
        if(sec.getNode() == section.second)
        {
            nextSection = getNextStraightSection(
                        retrieveSections(section.first), retrieveSections(section.second));
            found = true;
        }
    }

   /* if(!found)
    {
        qDebug() << "Shit didn't work homie!!!";
    }*/

    for(auto section : sectionPairs)
    {
        if(nextSection == section.second)
        {
            //emit trackOff();
            qDebug() << "Shutting off section " << section.second;
            Section shutdownSection = retrieveSections(section.second);
            emit sectionOff(shutdownSection.getBoardNum(),shutdownSection.getSection());
        }
    }
}

void TrainMonitor::switchMonitor(Section sec)
{
    qDebug() << "switchMonitor()";
    QString monitorSection;
    QString nextSection;
    for (auto section : sectionPairs)
    {
        if(sec.getNode() == section.second)
        {
            nextSection = getNextStraightSection(
                        retrieveSections(section.first), retrieveSections(section.second));
        }

        /*if(nextSection != "")
        {
            switch (retrieveSections(nextSection).getNumOfConns())
            {
                case 1: {
                    //emit trackOff();
                    qDebug() << "Shutting off section " << section.second;
                    Section shutdownSection = retrieveSections(nextSection);
                    QStringList shutdownList = shutdownSection.getNode().split("-");
                    emit sectionOff(shutdownList[0].toInt(),shutdownList[1].toInt());

                    break;
                } case 2: {
                    monitorSection = getNextStraightSection(
                                retrieveSections(section.first), retrieveSections(nextSection));
                    break;
                } case 3: {
                    monitorSection = getNextStraightSection(
                                retrieveSections(section.second), retrieveSections(nextSection));
                    break;
                } case 4:
                    // TODO
                    break;
            }
        }*/
    }

    for (auto section : sectionPairs)
    {
//        if(section.second == monitorSection)
        if(section.second == nextSection)
        {
            //emit trackOff();
            qDebug() << "Shutting off section " << section.second;
            Section shutdownSection = retrieveSections(section.second);
            QStringList shutdownList = shutdownSection.getNode().split("-");
            emit sectionOff(shutdownList[0].toInt(),shutdownList[1].toInt());
        }
    }
}

//void TrainMonitor::crossoverMonitor(Section sec, engineSection es)
//{

//}

Section TrainMonitor::retrieveSections(QString section)
{
    qDebug() << "retrieveSections() " << section;
	Section newSection;
	//int NotFoundIndex;

	bool found = false;
	for (Section it : m_sectionList)
	{
		if (it.getNode() == section)
		{
			newSection = it;
			found = true;
			break;
		}
	}

	if (!found)
	{
        qDebug() << "Invalid section:" << section << ", Are you sure the section exists?" << section;
	}

	return newSection;
}

void TrainMonitor::generateSectionList()
{
    qDebug() << "generateSectionList()";
#pragma message("[MKJ] Do we want to move this to a central location?")
    qDebug() << "Testing file input";
	QString filename = QDir::currentPath().append("/Sections.txt");
	QFile infile(filename);
	if (!infile.open(QIODevice::ReadOnly | QIODevice::Text)) {

		qFatal("Cannot find input file: %s", filename.toLatin1().constData());
		return;
	}

	QTextStream in(&infile);
	QString node;
	int numOfConns;
    QString conn1, conn2, conn3;
    int ltNum; bool thrownLeft;

	while (!in.atEnd())
	{

        QStringList splitString = in.readLine().split(",");
        node = splitString[0];
        qDebug() << "node:" << node;
        numOfConns = splitString[1].toInt();
        conn1 = splitString[2];
        conn2 = splitString[3];
        conn3 = splitString[4];
        ltNum = splitString[5].toInt();
        thrownLeft = (splitString[6] == "false")? false : true;

        Section sec = Section(node, numOfConns, conn1, conn2,
            conn3, ltNum, thrownLeft);
        QStringList shutdownList = node.split("-");
        sec.setBoardNum(shutdownList[0].toInt());
        sec.setSection(shutdownList[1].toInt());
        qDebug() << "TRACK SECTION:" << QString::number(sec.getBoardNum()) << "-" << QString::number(sec.getSection()) << " CONN1:" << conn1 << ", CONN2:" << conn2;

		m_sectionList.append(sec);
	}
	infile.close();
}

void TrainMonitor::handle_serialOpened()
{
    qDebug() << "handle_serialOpened()";
    int switches = 0;
    for (Section  sec : m_sectionList)
    {
        if (sec.getNumOfConns() ==  3)
        {
            switches++;
            emit throwTurnout(sec.getLtNum());
            emit sectionOff(sec.getBoardNum(),sec.getSection());
            QThread::msleep(250);
        }
    }

    qDebug() << switches << " switches have be initialized";
    emit printSectionsOn();
}

Section TrainMonitor::findNextSection(Section previousSection,
	Section currentSection)
{
    qDebug() << "findNextSection()";
	Section nextSection;
	Section temp;

	if (previousSection.getNode() != "" && currentSection.getNode() != "")
	{
		switch (currentSection.getNumOfConns())
		{
		case 1:
		{
			// The next section will be a null string
			break;
		}
		case 2:
		case 4:
		{
			// The next section will be the only other choice other
			// than the previous section (straight section) or conn1
			// or conn2 (crossover)
			if (currentSection.getConn1() == previousSection.getNode())
			{
				nextSection = retrieveSections(
					currentSection.getConn2());
			}
			else
			{
				nextSection = retrieveSections(
					currentSection.getConn1());
			}
			break;
		}
		case 3:
		{
			if (currentSection.getConn1() == previousSection.getNode())
			{
                if (currentSection.getThrownLeft())	// configured left
				{
					nextSection = retrieveSections(
						currentSection.getConn2());
				}
				else
				{
					nextSection = retrieveSections(
						currentSection.getConn3());
				}
			}
			else
			{
				nextSection = retrieveSections(
					currentSection.getConn1());
			}
		}
		}
	}
	else
	{
		// One or both of the track sections are null. Therefore, the next
		// section will be null too
	}

	return nextSection;
}

/// Updates to an endpoint.....fix comment later
void TrainMonitor::updateSingleConnList(Section current)
{
    qDebug() << "updateSingleConnList()";
    bool found = false;
    for(auto sec : sectionPairs)
    {
        if (sec.second == current.getConn1())
        {
            sec.first = sec.second;
            sec.second = current.getNode();
            found = true;
        }
    }

    if(!found)
    {
        qDebug() << "Section " << current.getNode() << " not found, adding to list" << endl;
        /// TODO
        std::pair<QString, QString> secPair=
                std::make_pair<QString, QString>("", current.getNode());
        sectionPairs.push_back(secPair);
    }
}

/// Updates strait aways.....
void TrainMonitor::updateDoubleConnList(Section current)
{
    qDebug() << "updateDoubleConnList()";
    bool found = false;
    for(auto sec : sectionPairs)
    {
        if (sec.second == current.getConn1() ||
                sec.second == current.getConn2())
        {
            sec.first = sec.second;
            sec.second = current.getNode();
            found = true;
        }
    }

    if(!found)
    {
        qDebug() << "Section " << current.getNode() << " not found, adding to list" << endl;
        /// TODO
        if(sectionPairs.count() == 0)
        {
            std::pair<QString, QString> secPair=
                    std::make_pair<QString, QString>("", current.getNode());
            sectionPairs.push_back(secPair);
        }
        else if (current.getConn1() == "")
        {
            std::pair<QString, QString> secPair=
                    std::make_pair<QString, QString>(current.getConn1(), current.getNode());
            sectionPairs.push_back(secPair);
        }
        else
        {
            std::pair<QString, QString> secPair=
                    std::make_pair<QString, QString>(current.getConn2(), current.getNode());
            sectionPairs.push_back(secPair);
        }
    }
}

/// Updates switches.....
void TrainMonitor::updateTripleConnList(Section current)
{
    qDebug() << "updateTripleConnList()";
    bool found = false;
    for(auto sec : sectionPairs)
    {
        if (sec.second == current.getConn1() ||
                sec.second == current.getConn2() ||
                sec.second == current.getConn3())
        {
            sec.first = sec.second;
            sec.second = current.getNode();
            found = true;
        }
    }

    if(!found)
        if(!found)
        {
            qDebug() << "Section " << current.getNode() << " not found, adding to list" << endl;
            /// TODO
            std::pair<QString, QString> secPair =
                     std::make_pair<QString, QString>("", current.getNode());
            sectionPairs.push_back(secPair);
        }
}

/// Updates Crossovers....
void TrainMonitor::updateQuadConnList(Section current)
{
    qDebug() << "updateQuadConnList()";
    // TODO
}

QString TrainMonitor::getNextStraightSection(Section previous, Section current)
{
    qDebug() << "getNextStraightSection()";
    QString nextSection;
    if(previous.getNode() == current.getConn1())
    {
        nextSection = current.getConn2();
    }
    else
    {
        nextSection = current.getConn1();
    }

    return nextSection;
}

QString TrainMonitor::getNextSwitchSection(Section previous, Section current)
{
    qDebug() << "getNextSwitchSection()";
    QString nextSection;

    if(previous.getNode() == current.getConn2() ||
            previous.getNode() == current.getConn3())
    {
        nextSection = current.getConn1();
    }
    else
    {
        if(!current.getThrownLeft())
        {
            if(current.getThrown())
            {
                nextSection = current.getConn3();
            }
            else
            {
                nextSection = current.getConn2();
            }
        }
        else
        {
            if(current.getThrown())
            {
                nextSection = current.getConn2();
            }
            else
            {
                nextSection = current.getConn3();
            }
        }
    }

    return nextSection;
}

void TrainMonitor::do_handleSwitch(int LT, bool closed)
{
    qDebug() << "do_handleSwitch() entered";

    for(auto section : m_sectionList)
    {
        if(section.getLtNum() == LT)
        {
            if(closed)
            {
                section.setThrown(false);
            }
            else
            {
                section.setThrown(true);
            }
        }
    }
}
<commit_msg>A lot more debug within TrainMonitor<commit_after>#include "trainmonitor.h"
#include <QFile>
#include <QDir>
#include <QTextStream>
#include <QThread>

TrainMonitor::TrainMonitor()
{
#pragma message("[MKJ] Clean up when everything is done")
#pragma message("[MKJ] Look for things that would be useful in a log")

}

TrainMonitor::~TrainMonitor()
{

}

void TrainMonitor::do_run() {
    qDebug() << "do_run()";
    generateSectionList();
}

void TrainMonitor::do_handleOccupancy(QString section, bool state)
{
    qDebug() << "do_handleOccupancy entered";
    qDebug() << "New Occupancy Data at Monitor:" << section << " State:" << state;
	Section monitoredSection = retrieveSections(section);
	monitoredSection.setOccupancy(state);
    //if (state) Monitor(monitoredSection);
    if (state) Monitor(section);
}

void TrainMonitor::Monitor(QString section)
{
    qDebug() << "Monitor()";
    qDebug() << endl << endl << "Mike's debug";

    for (auto section : sectionPairs)
    {
        qDebug() << "last section is: " << section.first << " current section is:" << section.second << endl;
    }

    qDebug() << endl << endl;
#pragma message("[MKJ] Will nextSection1 be enough padding for a crash scenario?")
        //Section monitorSection = es.path.getNextSection1();

    Section currentSection = retrieveSections(section);
    qDebug() << "Starting monitor ....." << endl;
    switch (currentSection.getNumOfConns())
    {
        case 1:		// Endpoint case
        {
            updateSingleConnList(currentSection);
            qDebug() << "entered endpoint monitor" << endl;
            endpointMonitor(currentSection);
            break;
        }
        case 2:		// Straight case
        {
            updateDoubleConnList(currentSection);
            qDebug() << "entered straight monitor" << endl;
            straightMonitor(currentSection);
            break;
        }
        case 3:		// Switch case
        {
            updateTripleConnList(currentSection);
            qDebug() << "entered switch monitor" << endl;
            switchMonitor(currentSection);
            break;
        }
        case 4:		// Crossover case
        {
            updateQuadConnList(currentSection);
            qDebug() << "entered crossover monitor" << endl;
            //crossoverMonitor(currentSection);
            break;
        }
        default:
        {
            qFatal("Invalid track type");
            break;
        }
    }
}

void TrainMonitor::endpointMonitor(Section sec)
{
    qDebug() << "endpointMonitor()";
	// Shutdown the section since the means the train is headed
    // towards the end of the track
    for (auto section : sectionPairs)
    {
        if (sec.getNode() == section.second)
        {
            if(section.first != "")
            {
                qDebug() << "Shutting off section " << section.second;
                Section shutdownSection = retrieveSections(section.second);
                QStringList shutdownList = shutdownSection.getNode().split("-");
                emit sectionOff(shutdownList[0].toInt(),shutdownList[1].toInt());
            }
        }
    }
}

void TrainMonitor::straightMonitor(Section sec)
{
    qDebug() << "straightMonitor()" << sec.getNode();
    QString nextSection;
    bool found = false;

    for (auto section : sectionPairs)
    {

        qDebug() << sec.getNode() << " sec.second is:" << section.second << endl;
        if(sec.getNode() == section.second)
        {
            nextSection = getNextStraightSection(
                        retrieveSections(section.first), retrieveSections(section.second));
            found = true;
        }
    }

   /* if(!found)
    {
        qDebug() << "Shit didn't work homie!!!";
    }*/

    for(auto section : sectionPairs)
    {
        if(nextSection == section.second)
        {
            //emit trackOff();
            qDebug() << "Shutting off section " << section.second;
            Section shutdownSection = retrieveSections(section.second);
            emit sectionOff(shutdownSection.getBoardNum(),shutdownSection.getSection());
        }
    }
}

void TrainMonitor::switchMonitor(Section sec)
{
    qDebug() << "switchMonitor()";
    QString monitorSection;
    QString nextSection;
    for (auto section : sectionPairs)
    {
        if(sec.getNode() == section.second)
        {
            nextSection = getNextStraightSection(
                        retrieveSections(section.first), retrieveSections(section.second));
        }

        /*if(nextSection != "")
        {
            switch (retrieveSections(nextSection).getNumOfConns())
            {
                case 1: {
                    //emit trackOff();
                    qDebug() << "Shutting off section " << section.second;
                    Section shutdownSection = retrieveSections(nextSection);
                    QStringList shutdownList = shutdownSection.getNode().split("-");
                    emit sectionOff(shutdownList[0].toInt(),shutdownList[1].toInt());

                    break;
                } case 2: {
                    monitorSection = getNextStraightSection(
                                retrieveSections(section.first), retrieveSections(nextSection));
                    break;
                } case 3: {
                    monitorSection = getNextStraightSection(
                                retrieveSections(section.second), retrieveSections(nextSection));
                    break;
                } case 4:
                    // TODO
                    break;
            }
        }*/
    }

    for (auto section : sectionPairs)
    {
//        if(section.second == monitorSection)
        if(section.second == nextSection)
        {
            //emit trackOff();
            qDebug() << "Shutting off section " << section.second;
            Section shutdownSection = retrieveSections(section.second);
            QStringList shutdownList = shutdownSection.getNode().split("-");
            emit sectionOff(shutdownList[0].toInt(),shutdownList[1].toInt());
        }
    }
}

//void TrainMonitor::crossoverMonitor(Section sec, engineSection es)
//{

//}

Section TrainMonitor::retrieveSections(QString section)
{
    qDebug() << "retrieveSections() " << section;
	Section newSection;
	//int NotFoundIndex;

	bool found = false;
	for (Section it : m_sectionList)
	{
		if (it.getNode() == section)
		{
			newSection = it;
			found = true;
			break;
		}
	}

	if (!found)
	{
        qDebug() << "Invalid section:" << section << ", Are you sure the section exists?" << section;
	}

	return newSection;
}

void TrainMonitor::generateSectionList()
{
    qDebug() << "generateSectionList()";
#pragma message("[MKJ] Do we want to move this to a central location?")
    qDebug() << "Testing file input";
	QString filename = QDir::currentPath().append("/Sections.txt");
	QFile infile(filename);
	if (!infile.open(QIODevice::ReadOnly | QIODevice::Text)) {

		qFatal("Cannot find input file: %s", filename.toLatin1().constData());
		return;
	}

	QTextStream in(&infile);
	QString node;
	int numOfConns;
    QString conn1, conn2, conn3;
    int ltNum; bool thrownLeft;

	while (!in.atEnd())
	{

        QStringList splitString = in.readLine().split(",");
        node = splitString[0];
        qDebug() << "node:" << node;
        numOfConns = splitString[1].toInt();
        conn1 = splitString[2];
        conn2 = splitString[3];
        conn3 = splitString[4];
        ltNum = splitString[5].toInt();
        thrownLeft = (splitString[6] == "false")? false : true;

        Section sec = Section(node, numOfConns, conn1, conn2,
            conn3, ltNum, thrownLeft);
        QStringList shutdownList = node.split("-");
        sec.setBoardNum(shutdownList[0].toInt());
        sec.setSection(shutdownList[1].toInt());
        qDebug() << "TRACK SECTION:" << QString::number(sec.getBoardNum()) << "-" << QString::number(sec.getSection()) << " CONN1:" << conn1 << ", CONN2:" << conn2;

		m_sectionList.append(sec);
	}
	infile.close();
}

void TrainMonitor::handle_serialOpened()
{
    qDebug() << "handle_serialOpened()";
    int switches = 0;
    for (Section  sec : m_sectionList)
    {
        if (sec.getNumOfConns() ==  3)
        {
            switches++;
            emit throwTurnout(sec.getLtNum());
            emit sectionOff(sec.getBoardNum(),sec.getSection());
            QThread::msleep(250);
        }
    }

    qDebug() << switches << " switches have be initialized";
    emit printSectionsOn();
}

Section TrainMonitor::findNextSection(Section previousSection,
	Section currentSection)
{
    qDebug() << "findNextSection()";
	Section nextSection;
	Section temp;

	if (previousSection.getNode() != "" && currentSection.getNode() != "")
	{
		switch (currentSection.getNumOfConns())
		{
		case 1:
		{
			// The next section will be a null string
			break;
		}
		case 2:
		case 4:
		{
			// The next section will be the only other choice other
			// than the previous section (straight section) or conn1
			// or conn2 (crossover)
			if (currentSection.getConn1() == previousSection.getNode())
			{
				nextSection = retrieveSections(
					currentSection.getConn2());
			}
			else
			{
				nextSection = retrieveSections(
					currentSection.getConn1());
			}
			break;
		}
		case 3:
		{
			if (currentSection.getConn1() == previousSection.getNode())
			{
                if (currentSection.getThrownLeft())	// configured left
				{
					nextSection = retrieveSections(
						currentSection.getConn2());
				}
				else
				{
					nextSection = retrieveSections(
						currentSection.getConn3());
				}
			}
			else
			{
				nextSection = retrieveSections(
					currentSection.getConn1());
			}
		}
		}
	}
	else
	{
		// One or both of the track sections are null. Therefore, the next
		// section will be null too
	}

	return nextSection;
}

/// Updates to an endpoint.....fix comment later
void TrainMonitor::updateSingleConnList(Section current)
{
    qDebug() << "updateSingleConnList()";
    bool found = false;
    for(auto sec : sectionPairs)
    {
        if (sec.second == current.getConn1())
        {
            sec.first = sec.second;
            sec.second = current.getNode();
            found = true;
        }
    }

    if(!found)
    {
        qDebug() << "Section " << current.getNode() << " not found, adding to list" << endl;
        /// TODO
        std::pair<QString, QString> secPair=
                std::make_pair<QString, QString>("", current.getNode());
        sectionPairs.push_back(secPair);
    }
}

/// Updates strait aways.....
void TrainMonitor::updateDoubleConnList(Section current)
{
    qDebug() << "updateDoubleConnList()";
    bool found = false;
    for(auto sec : sectionPairs)
    {
        qDebug() << "current.conn1 = '" << current.getConn1() << "'\tcurrent.conn2 = '" << current.getConn2() << "'";
        if (sec.second == current.getConn1() ||
                sec.second == current.getConn2())
        {
            sec.first = sec.second;
            sec.second = current.getNode();
            found = true;
        }
    }

    if(!found)
    {
        qDebug() << "Section " << current.getNode() << " not found, adding to list" << endl;
        /// TODO
        if(sectionPairs.count() == 0)
        {
            std::pair<QString, QString> secPair=
                    std::make_pair<QString, QString>("", current.getNode());
            sectionPairs.push_back(secPair);
        }
        else if (current.getConn1() == "")
        {
            std::pair<QString, QString> secPair=
                    std::make_pair<QString, QString>(current.getConn1(), current.getNode());
            sectionPairs.push_back(secPair);
        }
        else
        {
            std::pair<QString, QString> secPair=
                    std::make_pair<QString, QString>(current.getConn2(), current.getNode());
            sectionPairs.push_back(secPair);
        }
    }
}

/// Updates switches.....
void TrainMonitor::updateTripleConnList(Section current)
{
    qDebug() << "updateTripleConnList()";
    bool found = false;
    for(auto sec : sectionPairs)
    {
        if (sec.second == current.getConn1() ||
                sec.second == current.getConn2() ||
                sec.second == current.getConn3())
        {
            sec.first = sec.second;
            sec.second = current.getNode();
            found = true;
        }
    }

    if(!found)
        if(!found)
        {
            qDebug() << "Section " << current.getNode() << " not found, adding to list" << endl;
            /// TODO
            std::pair<QString, QString> secPair =
                     std::make_pair<QString, QString>("", current.getNode());
            sectionPairs.push_back(secPair);
        }
}

/// Updates Crossovers....
void TrainMonitor::updateQuadConnList(Section current)
{
    qDebug() << "updateQuadConnList()";
    // TODO
}

QString TrainMonitor::getNextStraightSection(Section previous, Section current)
{
    qDebug() << "getNextStraightSection()";
    QString nextSection;
    if(previous.getNode() == current.getConn1())
    {
        nextSection = current.getConn2();
    }
    else
    {
        nextSection = current.getConn1();
    }

    return nextSection;
}

QString TrainMonitor::getNextSwitchSection(Section previous, Section current)
{
    qDebug() << "getNextSwitchSection()";
    QString nextSection;

    if(previous.getNode() == current.getConn2() ||
            previous.getNode() == current.getConn3())
    {
        nextSection = current.getConn1();
    }
    else
    {
        if(!current.getThrownLeft())
        {
            if(current.getThrown())
            {
                nextSection = current.getConn3();
            }
            else
            {
                nextSection = current.getConn2();
            }
        }
        else
        {
            if(current.getThrown())
            {
                nextSection = current.getConn2();
            }
            else
            {
                nextSection = current.getConn3();
            }
        }
    }

    return nextSection;
}

void TrainMonitor::do_handleSwitch(int LT, bool closed)
{
    qDebug() << "do_handleSwitch() entered";

    for(auto section : m_sectionList)
    {
        if(section.getLtNum() == LT)
        {
            if(closed)
            {
                section.setThrown(false);
            }
            else
            {
                section.setThrown(true);
            }
        }
    }
}
<|endoftext|>


<commit_before>/*=========================================================================
 *
 *  Copyright The University of North Carolina at Chapel Hill
 *  All rights reserved.
 *
 *  Licensed under the MADAI Software License. You may obtain a copy of
 *  this license at
 *
 *         https://madai-public.cs.unc.edu/visualization/software-license/
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#include "LangevinSampler.h"

#include <cassert>
#include <algorithm>
#include <cmath>

namespace madai {

LangevinSampler
::LangevinSampler() :
  Sampler(),
  m_TimeStep( 1.0e-2 ),
  m_MeanTime( 1 ),
  m_KickStrength( 1 ),
  m_DragCoefficient( 1.0e-2 ),
  m_MassScale( 1 )
{
}

LangevinSampler
::~LangevinSampler()
{
}

void
LangevinSampler
::Initialize( const Model * model )
{
  assert( model != NULL );
  m_Model = model;

  Sampler::Initialize( model );

  // Random initial starting point
  const std::vector< Parameter > & params = m_Model->GetParameters();
  for ( unsigned int i = 0; i < m_Model->GetNumberOfParameters(); i++ ) {
    const Distribution * priorDist = params[i].GetPriorDistribution();
    m_CurrentParameters[i] = priorDist->GetSample(m_Random);
    m_CurrentVelocities.push_back(0.0);
  }

  m_TimeBeforeNextKick = m_Random.Gaussian( m_MeanTime, m_MeanTime / 10.0 );
}

Sample
LangevinSampler
::NextSample()
{
  Model * m = const_cast< Model * >(m_Model);
  double TimeLeft = m_TimeStep;

  unsigned int numberOfActiveParameters = this->GetNumberOfActiveParameters();

  assert( std::count( m_ActiveParameterIndices.begin(),
                      m_ActiveParameterIndices.end(), true )
          == numberOfActiveParameters);

  // Get the gradient of the Log Likelihood at the current point
  std::vector< double > Gradient;
  m->GetScalarAndGradientOutputs(
    m_CurrentParameters, m_ActiveParameterIndices,
    m_CurrentOutputs, Gradient );

  // Get loglikelihood at the current parameters
  double LogLikelihood;
  m->GetScalarOutputsAndLogLikelihood(
    m_CurrentParameters, m_CurrentOutputs, LogLikelihood );
  // Check for NaN
  assert( LogLikelihood == LogLikelihood );

  std::vector< double > Accel = Gradient;
  for ( unsigned int i = 0; i < Accel.size(); i++ ) {
    Accel[i] -= m_DragCoefficient * m_CurrentVelocities[i];
    Accel[i] /= m_MassScale;
  }
  if ( m_TimeBeforeNextKick < m_TimeStep ) { // Check if kick happens
    // Take step up to m_TimeBeforeNextKick
    for ( unsigned int i = 0; i < m_CurrentParameters.size(); i++ ) {
      m_CurrentParameters[i] += m_CurrentVelocities[i] * m_TimeBeforeNextKick;
      m_CurrentParameters[i] += 0.5 * Accel[i] * m_TimeBeforeNextKick * m_TimeBeforeNextKick;
      m_CurrentVelocities[i] += Accel[i] * m_TimeBeforeNextKick;
    }
    // Get m_CurrentVelocities.size() number of random numbers
    double r[m_CurrentVelocities.size()];
    double temp = 0;
    for ( unsigned int i = 0; i < m_CurrentVelocities.size(); i++ ) {
      r[i] = m_Random.Uniform( -1, 1 );
      temp += r[i] * r[i];
    }
    temp = sqrt( temp );
    temp /= m_KickStrength;
    for ( unsigned int i = 0; i < m_CurrentVelocities.size(); i++ ) {
     m_CurrentVelocities[i] += r[i] / temp;
     Accel[i] -= m_DragCoefficient * r[i] / temp;
    }
    TimeLeft -= m_TimeBeforeNextKick;
    m_TimeBeforeNextKick += m_Random.Gaussian( m_MeanTime, m_MeanTime / 10.0 );
  }

  for ( unsigned int i = 0; i < m_CurrentParameters.size(); i++ ) {
    m_CurrentParameters[i] += m_CurrentVelocities[i] * TimeLeft;
    m_CurrentParameters[i] += 0.5 * Accel[i] * TimeLeft * TimeLeft;
    m_CurrentVelocities[i] += Accel[i] * TimeLeft;
  }

  m_TimeBeforeNextKick -= m_TimeStep;

  return Sample( m_CurrentParameters,
                 m_CurrentOutputs,
                 LogLikelihood );

}

void LangevinSampler
::SetTimeStep( double TimeStep )
{
  m_TimeStep = TimeStep;
}

void LangevinSampler
::SetKickStrength( double KickStrength )
{
  m_KickStrength = KickStrength;
}

void LangevinSampler
::SetMeanTimeBetweenKicks( double MeanTime )
{
  m_MeanTime = MeanTime;
}

void LangevinSampler
::SetDragCoefficient( double DragCoefficient )
{
  m_DragCoefficient = DragCoefficient;
}

void LangevinSampler
::SetMassScale( double MassScale )
{
  m_MassScale = MassScale;
}

Sampler::ErrorType
LangevinSampler
::SetVelocity( const std::string & parameterName, double Velocity )
{
  unsigned int parameterIndex = this->GetParameterIndex( parameterName );

  if ( parameterIndex == static_cast< unsigned int >( -1 ) ) {
    return INVALID_PARAMETER_INDEX_ERROR;
  }

  m_CurrentVelocities[parameterIndex] = Velocity;

  return NO_ERROR;
}

} // end namespace madai
<commit_msg>Fix pedantic warnings in LangevinSampler<commit_after>/*=========================================================================
 *
 *  Copyright The University of North Carolina at Chapel Hill
 *  All rights reserved.
 *
 *  Licensed under the MADAI Software License. You may obtain a copy of
 *  this license at
 *
 *         https://madai-public.cs.unc.edu/visualization/software-license/
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#include "LangevinSampler.h"

#include <cassert>
#include <algorithm>
#include <cmath>

namespace madai {

LangevinSampler
::LangevinSampler() :
  Sampler(),
  m_TimeStep( 1.0e-2 ),
  m_MeanTime( 1 ),
  m_KickStrength( 1 ),
  m_DragCoefficient( 1.0e-2 ),
  m_MassScale( 1 )
{
}

LangevinSampler
::~LangevinSampler()
{
}

void
LangevinSampler
::Initialize( const Model * model )
{
  assert( model != NULL );
  m_Model = model;

  Sampler::Initialize( model );

  // Random initial starting point
  const std::vector< Parameter > & params = m_Model->GetParameters();
  for ( unsigned int i = 0; i < m_Model->GetNumberOfParameters(); i++ ) {
    const Distribution * priorDist = params[i].GetPriorDistribution();
    m_CurrentParameters[i] = priorDist->GetSample(m_Random);
    m_CurrentVelocities.push_back(0.0);
  }

  m_TimeBeforeNextKick = m_Random.Gaussian( m_MeanTime, m_MeanTime / 10.0 );
}

Sample
LangevinSampler
::NextSample()
{
  Model * m = const_cast< Model * >(m_Model);
  double TimeLeft = m_TimeStep;

  unsigned int numberOfActiveParameters = this->GetNumberOfActiveParameters();

  assert( static_cast<unsigned int> (
              std::count( m_ActiveParameterIndices.begin(),
                          m_ActiveParameterIndices.end(), true ))
          == numberOfActiveParameters);

  // Get the gradient of the Log Likelihood at the current point
  std::vector< double > Gradient;
  m->GetScalarAndGradientOutputs(
    m_CurrentParameters, m_ActiveParameterIndices,
    m_CurrentOutputs, Gradient );

  // Get loglikelihood at the current parameters
  double LogLikelihood;
  m->GetScalarOutputsAndLogLikelihood(
    m_CurrentParameters, m_CurrentOutputs, LogLikelihood );
  // Check for NaN
  assert( LogLikelihood == LogLikelihood );

  std::vector< double > Accel = Gradient;
  for ( unsigned int i = 0; i < Accel.size(); i++ ) {
    Accel[i] -= m_DragCoefficient * m_CurrentVelocities[i];
    Accel[i] /= m_MassScale;
  }
  if ( m_TimeBeforeNextKick < m_TimeStep ) { // Check if kick happens
    // Take step up to m_TimeBeforeNextKick
    for ( unsigned int i = 0; i < m_CurrentParameters.size(); i++ ) {
      m_CurrentParameters[i] += m_CurrentVelocities[i] * m_TimeBeforeNextKick;
      m_CurrentParameters[i] += 0.5 * Accel[i] * m_TimeBeforeNextKick * m_TimeBeforeNextKick;
      m_CurrentVelocities[i] += Accel[i] * m_TimeBeforeNextKick;
    }
    // Get m_CurrentVelocities.size() number of random numbers
    std::vector< double > r(m_CurrentVelocities.size());
    double temp = 0;
    for ( unsigned int i = 0; i < m_CurrentVelocities.size(); i++ ) {
      r[i] = m_Random.Uniform( -1, 1 );
      temp += r[i] * r[i];
    }
    temp = sqrt( temp );
    temp /= m_KickStrength;
    for ( unsigned int i = 0; i < m_CurrentVelocities.size(); i++ ) {
     m_CurrentVelocities[i] += r[i] / temp;
     Accel[i] -= m_DragCoefficient * r[i] / temp;
    }
    TimeLeft -= m_TimeBeforeNextKick;
    m_TimeBeforeNextKick += m_Random.Gaussian( m_MeanTime, m_MeanTime / 10.0 );
  }

  for ( unsigned int i = 0; i < m_CurrentParameters.size(); i++ ) {
    m_CurrentParameters[i] += m_CurrentVelocities[i] * TimeLeft;
    m_CurrentParameters[i] += 0.5 * Accel[i] * TimeLeft * TimeLeft;
    m_CurrentVelocities[i] += Accel[i] * TimeLeft;
  }

  m_TimeBeforeNextKick -= m_TimeStep;

  return Sample( m_CurrentParameters,
                 m_CurrentOutputs,
                 LogLikelihood );

}

void LangevinSampler
::SetTimeStep( double TimeStep )
{
  m_TimeStep = TimeStep;
}

void LangevinSampler
::SetKickStrength( double KickStrength )
{
  m_KickStrength = KickStrength;
}

void LangevinSampler
::SetMeanTimeBetweenKicks( double MeanTime )
{
  m_MeanTime = MeanTime;
}

void LangevinSampler
::SetDragCoefficient( double DragCoefficient )
{
  m_DragCoefficient = DragCoefficient;
}

void LangevinSampler
::SetMassScale( double MassScale )
{
  m_MassScale = MassScale;
}

Sampler::ErrorType
LangevinSampler
::SetVelocity( const std::string & parameterName, double Velocity )
{
  unsigned int parameterIndex = this->GetParameterIndex( parameterName );

  if ( parameterIndex == static_cast< unsigned int >( -1 ) ) {
    return INVALID_PARAMETER_INDEX_ERROR;
  }

  m_CurrentVelocities[parameterIndex] = Velocity;

  return NO_ERROR;
}

} // end namespace madai
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: BColumn.hxx,v $
 *
 *  $Revision: 1.1.1.1 $
 *
 *  last change: $Author: hr $ $Date: 2000-09-18 16:14:24 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _CONNECTIVITY_ADABAS_COLUMN_HXX_
#define _CONNECTIVITY_ADABAS_COLUMN_HXX_

#ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_
#include "connectivity/sdbcx/VColumn.hxx"
#endif

namespace connectivity
{
    namespace adabas
    {
        class OAdabasColumn : public sdbcx::OColumn
        {
        public:
            OAdabasColumn();
            OAdabasColumn(const ::rtl::OUString& _Name,
                    const ::rtl::OUString& _TypeName,
                    const ::rtl::OUString& _DefaultValue,
                    sal_Int32       _IsNullable,
                    sal_Int32       _Precision,
                    sal_Int32       _Scale,
                    sal_Int32       _Type,
                    sal_Bool        _IsAutoIncrement);

        };
    }
}
#endif // _CONNECTIVITY_ADABAS_COLUMN_HXX_

<commit_msg>INTEGRATION: CWS ooo19126 (1.1.1.1.364); FILE MERGED 2005/09/05 17:24:52 rt 1.1.1.1.364.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: BColumn.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 06:41:53 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _CONNECTIVITY_ADABAS_COLUMN_HXX_
#define _CONNECTIVITY_ADABAS_COLUMN_HXX_

#ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_
#include "connectivity/sdbcx/VColumn.hxx"
#endif

namespace connectivity
{
    namespace adabas
    {
        class OAdabasColumn : public sdbcx::OColumn
        {
        public:
            OAdabasColumn();
            OAdabasColumn(const ::rtl::OUString& _Name,
                    const ::rtl::OUString& _TypeName,
                    const ::rtl::OUString& _DefaultValue,
                    sal_Int32       _IsNullable,
                    sal_Int32       _Precision,
                    sal_Int32       _Scale,
                    sal_Int32       _Type,
                    sal_Bool        _IsAutoIncrement);

        };
    }
}
#endif // _CONNECTIVITY_ADABAS_COLUMN_HXX_

<|endoftext|>