<commit_before>#include "decoder.h"

#include <iostream>

#include <ctime>

Nan::Persistent<v8::Function> Decoder::constructor;

NAN_MODULE_INIT(Decoder::Init) {
  v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
  tpl->SetClassName(Nan::New("Decoder").ToLocalChecked());
  tpl->InstanceTemplate()->SetInternalFieldCount(1);

  Nan::SetPrototypeMethod(tpl, "unpackStream", UnpackStream);
  Nan::SetPrototypeMethod(tpl, "printas", Printas);
  /*Debug - start*/
  /*Debug - end*/

  constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
  Nan::Set(target, Nan::New("Decoder").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
}

NAN_METHOD(Decoder::New) {
  if (info.IsConstructCall()) {
    Decoder *obj = new Decoder();
    obj->Wrap(info.This());
    info.GetReturnValue().Set(info.This());
  } else {
    const int argc = 1;
    v8::Local<v8::Value> argv[argc] = {info[0]};
    v8::Local<v8::Function> cons = Nan::New(constructor);
    info.GetReturnValue().Set(cons->NewInstance(argc, argv));
  }
}

NAN_METHOD(Decoder::UnpackStream) {
    Decoder* obj = Nan::ObjectWrap::Unwrap<Decoder>(info.This());
    char* buff = (char*) node::Buffer::Data(info[0]->ToObject());
    size_t size = node::Buffer::Length(info[0]);

    size_t count = 0;
    size_t num_populated = 0;
    RingBuffer* ring = obj->getRingbuffer();

    std::clock_t start = std::clock();
    do {
        ring->doRollback();
        num_populated = ring->populate(buff + num_populated, size - num_populated);
        obj->oneStep();
        if(count > size) {
          std::cout << "we have problems "  << num_populated << " " << size<< std::endl;
          ring->printStats();
        }
        count++;
    }while(num_populated < size);
    std::clock_t end = std::clock();
    std::cout << "took: " << double(end-start)/CLOCKS_PER_SEC << " seconds" << std::endl;
    //obj->printMemoryState();
}

NAN_METHOD(Decoder::Printas) {
  Decoder* obj = Nan::ObjectWrap::Unwrap<Decoder>(info.This());
  obj->printMemoryState();
}<commit_msg>Fixed the deprecated NewInstance warning<commit_after>#include "decoder.h"

#include <iostream>

#include <ctime>

Nan::Persistent<v8::Function> Decoder::constructor;

NAN_MODULE_INIT(Decoder::Init) {
  v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
  tpl->SetClassName(Nan::New("Decoder").ToLocalChecked());
  tpl->InstanceTemplate()->SetInternalFieldCount(1);

  Nan::SetPrototypeMethod(tpl, "unpackStream", UnpackStream);
  Nan::SetPrototypeMethod(tpl, "printas", Printas);
  /*Debug - start*/
  /*Debug - end*/

  constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
  Nan::Set(target, Nan::New("Decoder").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
}

NAN_METHOD(Decoder::New) {
  if (info.IsConstructCall()) {
    Decoder *obj = new Decoder();
    obj->Wrap(info.This());
    info.GetReturnValue().Set(info.This());
  } else {
    const int argc = 1;
    v8::Local<v8::Value> argv[argc] = {info[0]};
    v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
    info.GetReturnValue().Set(Nan::NewInstance(cons,argc, argv).ToLocalChecked());
  }
}

NAN_METHOD(Decoder::UnpackStream) {
    Decoder* obj = Nan::ObjectWrap::Unwrap<Decoder>(info.This());
    char* buff = (char*) node::Buffer::Data(info[0]->ToObject());
    size_t size = node::Buffer::Length(info[0]);

    size_t count = 0;
    size_t num_populated = 0;
    RingBuffer* ring = obj->getRingbuffer();

    std::clock_t start = std::clock();
    do {
        ring->doRollback();
        num_populated = ring->populate(buff + num_populated, size - num_populated);
        obj->oneStep();
        if(count > size) {
          std::cout << "we have problems "  << num_populated << " " << size<< std::endl;
          ring->printStats();
        }
        count++;
    }while(num_populated < size);
    std::clock_t end = std::clock();
    std::cout << "took: " << double(end-start)/CLOCKS_PER_SEC << " seconds" << std::endl;
    //obj->printMemoryState();
}

NAN_METHOD(Decoder::Printas) {
  Decoder* obj = Nan::ObjectWrap::Unwrap<Decoder>(info.This());
  obj->printMemoryState();
}<|endoftext|>


<commit_before>#include <gtest/gtest.h>
#include <fstream>
#include <vector>
#include <string>
#include "stego-crypt-lib/bmp_manip.h"

TEST(StegStub, oneEqualsone) {
  int one = 1;
  EXPECT_EQ(1, one);
}

TEST(BMPTests, BMPValidation) {
  std::ifstream ifs("test.png", std::ios::binary);
  std::string bmp;
  ifs >> bmp;
  EXPECT_EQ(true, is_bmp_valid(bmp));
}
<commit_msg>Fixed file not found error in test<commit_after>#include <gtest/gtest.h>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include "stego-crypt-lib/bmp_manip.h"

TEST(StegStub, oneEqualsone) {
  int one = 1;
  EXPECT_EQ(1, one);
}

TEST(BMPTests, BMPValidation) {
  std::ifstream ifs("test/stego-crypt/test.bmp");
  std::ostringstream ost;
  ost << ifs.rdbuf();
  std::string bmp(ost.str());
  EXPECT_EQ(true, is_bmp_valid(bmp));
}
<|endoftext|>


<commit_before>// StaticTest.h

#include "stdafx.h"

#include "StaticTest.h"

#include "PhysicalQuantities.h"
#include "NamedQuantities.h"
#include "SIUnits.h"
#include "Constants.h"

using namespace PhysicalQuantities;

namespace PhysicalQuantitiesTest {
public ref class staticTest {
  public:
  double test() {
    Dimensionless z = 42;
    Dimensionless y = 75;
    Dimensionless aoeu = z * y;
    Mass m = 5.0 * Kilogram;
    Speed v = 1.2 * (Metre / Second);
    v += 43 * (Metre / Second);
    v *= 5.2;
    v /= 0.7;
    Dimensionless x = 3.0;
    Dimensionless xx = 5 * x;
    Momentum p = m * v;
    Mass M = 5.0 * m;
    Energy E = Dimensionless(.5) * m * v * v;
    Force F = 1000.0 * Newton;
    double numberOfKelvins
      = ((9.8 * Kelvin - 12 * Joule / BoltzmannConstant) / (1.0 * Kelvin)).Value();
    Dimensionless N = 1e23;
    Volume V = 5 * (Metre * Metre * Metre) + 2 * Litre;
    Temperature T = 3 * Kelvin;
    Pressure P = N * BoltzmannConstant * T / V;
    MomentOfInertia I = 1 * Metre * Metre * 4 * Kilogram / (Radian * Radian);
    AngularMomentum L = I * (4 * (Radian / Second));
    return (m / (1 * Kilogram) + E / (1 * Joule) + P / (1 * Pascal)).Value()
      + numberOfKelvins;
  }
};
}<commit_msg>using<commit_after>// StaticTest.h

#include "stdafx.h"

#include "StaticTest.h"

#include "PhysicalQuantities.h"
#include "NamedQuantities.h"
#include "SIUnits.h"
#include "Constants.h"
namespace PhysicalQuantitiesTest {
using namespace PhysicalQuantities;
public ref class staticTest {
  public:
  double test() {
    Dimensionless z = 42;
    Dimensionless y = 75;
    Dimensionless aoeu = z * y;
    Mass m = 5.0 * Kilogram;
    Speed v = 1.2 * (Metre / Second);
    v += 43 * (Metre / Second);
    v *= 5.2;
    v /= 0.7;
    Dimensionless x = 3.0;
    Dimensionless xx = 5 * x;
    Momentum p = m * v;
    Mass M = 5.0 * m;
    Energy E = Dimensionless(.5) * m * v * v;
    Force F = 1000.0 * Newton;
    double numberOfKelvins
      = ((9.8 * Kelvin - 12 * Joule / BoltzmannConstant) / (1.0 * Kelvin)).Value();
    Dimensionless N = 1e23;
    Volume V = 5 * (Metre * Metre * Metre) + 2 * Litre;
    Temperature T = 3 * Kelvin;
    Pressure P = N * BoltzmannConstant * T / V;
    MomentOfInertia I = 1 * Metre * Metre * 4 * Kilogram / (Radian * Radian);
    AngularMomentum L = I * (4 * (Radian / Second));
    return (m / (1 * Kilogram) + E / (1 * Joule) + P / (1 * Pascal)).Value()
      + numberOfKelvins;
  }
};
}<|endoftext|>


<commit_before>#include "BaseCommand.hh"
#include <string>

using namespace std;
class test : public BaseCommand //runs test
{
    private:
        string str;
        char type;
    public:
        test(char type, string str);
        ~test() {};
        bool children() { return false;};
        int exec();
};

BaseCommand* parse(string str); // correctly evaluates parentheses
<commit_msg>Delete Tests.hh<commit_after><|endoftext|>


<commit_before>//
// Created by dar on 11/25/15.
//

#include "Map.h"
#include <core/map/entity/EntityPlayer.h>
#include <core/map/entity/EntityFather.h>
#include <core/LevelContext.h>

Map::~Map() {
    for (Chunk *chunk : this->chunks) {
        delete chunk;
    }
    for (Entity *entity : this->entities) {
        delete entity;
    }
    this->chunks.clear();
    this->entities.clear();
}

Block *Map::getBlock(int x, int y) {
    //TODO !
    return nullptr;
}

void Map::update(double deltaTime) {
    this->worldTime += deltaTime;

    for (Entity *entity : this->entities) {
        entity->update(deltaTime);
    }
}

void Map::saveEntities(LevelContext &levelContext) {
    std::string filePath = this->fileName + "-entities";
#ifdef __ANDROID__
    filePath = "/sdcard/c003/" + filePath;
#endif // __ANDROID__
    std::ofstream myfile;
    myfile.open(filePath);
    if (myfile.is_open()) {
        for (int i = 0; i < this->getEntities().size(); i++) {
            Entity *e = this->getEntities().at(i);
            myfile << levelContext.getEntityManager().saveEntity(e);
            if (i != this->getEntities().size() - 1) {
                myfile << "\n";
            }
        }
        myfile.close();
    }
}<commit_msg>Implemented Map::getBlock(int, int)<commit_after>//
// Created by dar on 11/25/15.
//

#include "Map.h"
#include <core/map/entity/EntityPlayer.h>
#include <core/map/entity/EntityFather.h>
#include <core/LevelContext.h>

Map::~Map() {
    for (Chunk *chunk : this->chunks) {
        delete chunk;
    }
    for (Entity *entity : this->entities) {
        delete entity;
    }
    this->chunks.clear();
    this->entities.clear();
}

Block *Map::getBlock(int x, int y) {
    int chx = x / Chunk::size;
    int chy = y / Chunk::size;
    int chunksNumX = (int) ceil((double) width / Chunk::size);
    Chunk &ch = *this->chunks.at(chy * chunksNumX + chx);
    return ch.getBlocks()[(y - chy * Chunk::size) * Chunk::size + x - chx];
}

void Map::update(double deltaTime) {
    this->worldTime += deltaTime;

    for (Entity *entity : this->entities) {
        entity->update(deltaTime);
    }
}

void Map::saveEntities(LevelContext &levelContext) {
    std::string filePath = this->fileName + "-entities";
#ifdef __ANDROID__
    filePath = "/sdcard/c003/" + filePath;
#endif // __ANDROID__
    std::ofstream myfile;
    myfile.open(filePath);
    if (myfile.is_open()) {
        for (int i = 0; i < this->getEntities().size(); i++) {
            Entity *e = this->getEntities().at(i);
            myfile << levelContext.getEntityManager().saveEntity(e);
            if (i != this->getEntities().size() - 1) {
                myfile << "\n";
            }
        }
        myfile.close();
    }
}<|endoftext|>


<commit_before>/*
 * This file is open source software, licensed to you under the terms
 * of the Apache License, Version 2.0 (the "License").  See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership.  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.
 */

/*
 * Copyright (C) 2015 Cloudius Systems, Ltd.
 */

#pragma once

/// \mainpage
///
/// Seastar is a high performance C++ application framework for high
/// concurrency server applications.
///
/// Please see:
///   - \ref future-module Documentation on futures and promises, which are
///          the seastar building blocks.
///   - \ref future-util Utililty functions for working with futures
///   - \ref memory-module Memory management
///   - \ref networking-module TCP/IP networking
///   - \ref thread-module Support for traditional threaded execution

#include "sstring.hh"
#include "future.hh"

// iostream.hh
template <class CharType> class input_stream;
template <class CharType> class output_stream;

// reactor.hh
class server_socket;
class connected_socket;
class socket_address;
class listen_options;

// file.hh
class file;
enum class open_flags;

// Networking API

/// \defgroup networking-module Networking
///
/// Seastar provides a simple networking API, backed by two
/// TCP/IP stacks: the POSIX stack, utilizing the kernel's
/// BSD socket APIs, and the native stack, implement fully
/// within seastar and able to drive network cards directly.
/// The native stack supports zero-copy on both transmit
/// and receive, and is implemented using seastar's high
/// performance, lockless sharded design.  The network stack
/// can be selected with the \c --network-stack command-line
/// parameter.

/// \addtogroup networking-module
/// @{

/// Listen for connections on a given port
///
/// Starts listening on a given address for incoming connections.
///
/// \param sa socket address to listen on
///
/// \return \ref server_socket object ready to accept connections.
///
/// \see listen(socket_address sa, listen_options opts)
server_socket listen(socket_address sa);

/// Listen for connections on a given port
///
/// Starts listening on a given address for incoming connections.
///
/// \param sa socket address to listen on
/// \param opts options controlling the listen operation
///
/// \return \ref server_socket object ready to accept connections.
///
/// \see listen(socket_address sa)
server_socket listen(socket_address sa, listen_options opts);

/// Establishes a connection to a given address
///
/// Attempts to connect to the given address.
///
/// \param sa socket address to connect to
///
/// \return a \ref connected_socket object, or an exception
future<connected_socket> connect(socket_address sa);

/// @}

// File API
future<file> open_file_dma(sstring name, open_flags flags);
future<file> open_directory(sstring name);
future<> make_directory(sstring name);
future<> remove_file(sstring pathname);

<commit_msg>doc: prevent -- from becoming an emdash<commit_after>/*
 * This file is open source software, licensed to you under the terms
 * of the Apache License, Version 2.0 (the "License").  See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership.  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.
 */

/*
 * Copyright (C) 2015 Cloudius Systems, Ltd.
 */

#pragma once

/// \mainpage
///
/// Seastar is a high performance C++ application framework for high
/// concurrency server applications.
///
/// Please see:
///   - \ref future-module Documentation on futures and promises, which are
///          the seastar building blocks.
///   - \ref future-util Utililty functions for working with futures
///   - \ref memory-module Memory management
///   - \ref networking-module TCP/IP networking
///   - \ref thread-module Support for traditional threaded execution

#include "sstring.hh"
#include "future.hh"

// iostream.hh
template <class CharType> class input_stream;
template <class CharType> class output_stream;

// reactor.hh
class server_socket;
class connected_socket;
class socket_address;
class listen_options;

// file.hh
class file;
enum class open_flags;

// Networking API

/// \defgroup networking-module Networking
///
/// Seastar provides a simple networking API, backed by two
/// TCP/IP stacks: the POSIX stack, utilizing the kernel's
/// BSD socket APIs, and the native stack, implement fully
/// within seastar and able to drive network cards directly.
/// The native stack supports zero-copy on both transmit
/// and receive, and is implemented using seastar's high
/// performance, lockless sharded design.  The network stack
/// can be selected with the \c \--network-stack command-line
/// parameter.

/// \addtogroup networking-module
/// @{

/// Listen for connections on a given port
///
/// Starts listening on a given address for incoming connections.
///
/// \param sa socket address to listen on
///
/// \return \ref server_socket object ready to accept connections.
///
/// \see listen(socket_address sa, listen_options opts)
server_socket listen(socket_address sa);

/// Listen for connections on a given port
///
/// Starts listening on a given address for incoming connections.
///
/// \param sa socket address to listen on
/// \param opts options controlling the listen operation
///
/// \return \ref server_socket object ready to accept connections.
///
/// \see listen(socket_address sa)
server_socket listen(socket_address sa, listen_options opts);

/// Establishes a connection to a given address
///
/// Attempts to connect to the given address.
///
/// \param sa socket address to connect to
///
/// \return a \ref connected_socket object, or an exception
future<connected_socket> connect(socket_address sa);

/// @}

// File API
future<file> open_file_dma(sstring name, open_flags flags);
future<file> open_directory(sstring name);
future<> make_directory(sstring name);
future<> remove_file(sstring pathname);

<|endoftext|>


<commit_before>/****************************************************************************
**
** Copyright (C) Qxt Foundation. Some rights reserved.
**
** This file is part of the QxtCore module of the Qxt library.
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of the Common Public License, version 1.0, as published by
** IBM.
**
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
** FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the CPL along with this file.
** See the LICENSE file and the cpl1.0.txt file included with the source
** distribution for more information. If you did not receive a copy of the
** license, contact the Qxt Foundation.
**
** <http://libqxt.org>  <foundation@libqxt.org>
**
****************************************************************************/

/**
\class QxtFifo QxtFifo

\ingroup QxtCore

\brief Simple Loopback QIODevice

read and write to the same object \n
emits a readyRead Signal. \n
usefull for loopback tests where QBuffer does not work.

\code
QxtFifo fifo;
 QTextStream (&fifo)<<QString("foo");
 QString a;
 QTextStream(&fifo)>>a;
 qDebug()<<a;
\endcode

*/

/**

\fn  QxtFifo::QxtFifo(QObject * parent=0);
constructs a new QxtFifo

\fn  virtual bool QxtFifo::isSequential () const;
\reimp

\fn virtual qint64 QxtFifo::bytesAvailable () const;
\reimp

\fn     virtual qint64 QxtFifo::readData ( char * data, qint64 maxSize );
\reimp

\fn     virtual qint64 QxtFifo::writeData ( const char * data, qint64 maxSize );
\reimp

*/

#include "qxtfifo.h"
#include <string.h>
#include <limits.h>
#include <QDebug>
#include <QQueue>
#include <qatomic.h>
//#include <qbasicatomic.h>

struct QxtFifoNode
{
    QxtFifoNode(const char* data, int size) : content(data, size)
    {
        next = NULL;
    }

    QByteArray content;
    QBasicAtomicPointer<QxtFifoNode> next;
};

class QxtFifoPrivate : public QxtPrivate<QxtFifo>
{
public:
    QXT_DECLARE_PUBLIC(QxtFifo);
    QxtFifoPrivate()
    {
        head = tail = new QxtFifoNode(NULL, 0);
        available = 0;
    }

    QBasicAtomicPointer<QxtFifoNode> head, tail;
    QBasicAtomic available;
};

QxtFifo::QxtFifo(QObject *parent) : QIODevice(parent)
{
    QXT_INIT_PRIVATE(QxtFifo);
    setOpenMode(QIODevice::ReadWrite);
}

qint64 QxtFifo::readData(char * data, qint64 maxSize)
{
    int bytes = qxt_d().available, step;
    if (!bytes) return 0;
    if (bytes > maxSize) bytes = maxSize;
    int written = bytes;
    char* writePos = data;
    QxtFifoNode* node;
    while (bytes > 0)
    {
        node = qxt_d().head;
        step = node->content.size();
        if (step >= bytes)
        {
            int rem = step - bytes;
            memcpy(writePos, node->content.constData(), bytes);
            step = bytes;
            node->content = node->content.right(rem);
        }
        else
        {
            memcpy(writePos, node->content.constData(), step);
            qxt_d().head.exchange(node->next);
            delete node;
            node = qxt_d().head;
        }
        writePos += step;
        bytes -= step;
    }
    qxt_d().available.exchange(-written);
    return written;
}

qint64 QxtFifo::writeData(const char * data, qint64 maxSize)
{
    if (maxSize > 0)
    {
        if (maxSize > INT_MAX) maxSize = INT_MAX; // qint64 could easily exceed QAtomicInt, so let's play it safe
        QxtFifoNode* newData = new QxtFifoNode(data, maxSize);
        qxt_d().tail->next.exchange(newData);
        qxt_d().tail.exchange(newData);
        qxt_d().available.exchange(maxSize);
        QMetaObject::invokeMethod(this, "bytesWritten", Qt::QueuedConnection, Q_ARG(qint64, maxSize));
        QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
    }
    return maxSize;
}

bool QxtFifo::isSequential() const
{
    return true;
}

qint64 QxtFifo::bytesAvailable() const
{
    return qxt_d().available;
}

void QxtFifo::clear()
{
    qxt_d().available.exchange(0);
    qxt_d().tail.exchange(qxt_d().head);
    QxtFifoNode* node = qxt_d().head->next.exchange(NULL);
    while (node && node->next)
    {
        QxtFifoNode* next = node->next.exchange(NULL);
        delete node;
        node = next;
    }
    qxt_d().head->content = QByteArray();
}
<commit_msg>version checks<commit_after>/****************************************************************************
**
** Copyright (C) Qxt Foundation. Some rights reserved.
**
** This file is part of the QxtCore module of the Qxt library.
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of the Common Public License, version 1.0, as published by
** IBM.
**
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
** FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the CPL along with this file.
** See the LICENSE file and the cpl1.0.txt file included with the source
** distribution for more information. If you did not receive a copy of the
** license, contact the Qxt Foundation.
**
** <http://libqxt.org>  <foundation@libqxt.org>
**
****************************************************************************/

/**
\class QxtFifo QxtFifo

\ingroup QxtCore

\brief Simple Loopback QIODevice

read and write to the same object \n
emits a readyRead Signal. \n
usefull for loopback tests where QBuffer does not work.

\code
QxtFifo fifo;
 QTextStream (&fifo)<<QString("foo");
 QString a;
 QTextStream(&fifo)>>a;
 qDebug()<<a;
\endcode

*/

/**

\fn  QxtFifo::QxtFifo(QObject * parent=0);
constructs a new QxtFifo

\fn  virtual bool QxtFifo::isSequential () const;
\reimp

\fn virtual qint64 QxtFifo::bytesAvailable () const;
\reimp

\fn     virtual qint64 QxtFifo::readData ( char * data, qint64 maxSize );
\reimp

\fn     virtual qint64 QxtFifo::writeData ( const char * data, qint64 maxSize );
\reimp

*/

#include "qxtfifo.h"
#include <string.h>
#include <limits.h>
#include <QDebug>
#include <QQueue>

#if QT_VERSION >= 0x040400
#include <qbasicatomic.h>
typedef QBasicAtomicInt QBasicAtomic;
#define QXT_EXCHANGE fetchAndStoreOrdered
#else
#include <qatomic.h>
#define QXT_EXCHANGE exchange
#endif

struct QxtFifoNode
{
    QxtFifoNode(const char* data, int size) : content(data, size)
    {
        next = NULL;
    }

    QByteArray content;
    QBasicAtomicPointer<QxtFifoNode> next;
};

class QxtFifoPrivate : public QxtPrivate<QxtFifo>
{
public:
    QXT_DECLARE_PUBLIC(QxtFifo);
    QxtFifoPrivate()
    {
        head = tail = new QxtFifoNode(NULL, 0);
        available = 0;
    }

    QBasicAtomicPointer<QxtFifoNode> head, tail;
    QBasicAtomic available;
};

QxtFifo::QxtFifo(QObject *parent) : QIODevice(parent)
{
    QXT_INIT_PRIVATE(QxtFifo);
    setOpenMode(QIODevice::ReadWrite);
}

qint64 QxtFifo::readData(char * data, qint64 maxSize)
{
    int bytes = qxt_d().available, step;
    if (!bytes) return 0;
    if (bytes > maxSize) bytes = maxSize;
    int written = bytes;
    char* writePos = data;
    QxtFifoNode* node;
    while (bytes > 0)
    {
        node = qxt_d().head;
        step = node->content.size();
        if (step >= bytes)
        {
            int rem = step - bytes;
            memcpy(writePos, node->content.constData(), bytes);
            step = bytes;
            node->content = node->content.right(rem);
        }
        else
        {
            memcpy(writePos, node->content.constData(), step);
            qxt_d().head.QXT_EXCHANGE(node->next);
            delete node;
            node = qxt_d().head;
        }
        writePos += step;
        bytes -= step;
    }
    qxt_d().available.QXT_EXCHANGE(-written);
    return written;
}

qint64 QxtFifo::writeData(const char * data, qint64 maxSize)
{
    if (maxSize > 0)
    {
        if (maxSize > INT_MAX) maxSize = INT_MAX; // qint64 could easily exceed QAtomicInt, so let's play it safe
        QxtFifoNode* newData = new QxtFifoNode(data, maxSize);
        qxt_d().tail->next.QXT_EXCHANGE(newData);
        qxt_d().tail.QXT_EXCHANGE(newData);
        qxt_d().available.QXT_EXCHANGE(maxSize);
        QMetaObject::invokeMethod(this, "bytesWritten", Qt::QueuedConnection, Q_ARG(qint64, maxSize));
        QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
    }
    return maxSize;
}

bool QxtFifo::isSequential() const
{
    return true;
}

qint64 QxtFifo::bytesAvailable() const
{
    return qxt_d().available;
}

void QxtFifo::clear()
{
    qxt_d().available.QXT_EXCHANGE(0);
    qxt_d().tail.QXT_EXCHANGE(qxt_d().head);
    QxtFifoNode* node = qxt_d().head->next.QXT_EXCHANGE(NULL);
    while (node && node->next)
    {
        QxtFifoNode* next = node->next.QXT_EXCHANGE(NULL);
        delete node;
        node = next;
    }
    qxt_d().head->content = QByteArray();
}
<|endoftext|>


<commit_before>#include "TTModular.h"

#include <iostream>
#include <string>

// A class for our application
class DemoApp {

public:

    DemoApp(){};
    ~DemoApp(){};

    // This application is divided into four main functions
    void Setup();
    void Export();
    void Execute(std::string command);
    void Quit();

private:

    // Declare the application manager, our application and another one
    TTObject mApplicationManager;
    TTObject mApplicationDemo;
    TTObject mApplicationRemote;

    // Declare protocol units to use
    TTObject mProtocolMinuit;
    TTObject mProtocolWebSocket;

public:

    // Declare publicly all datas of our application to retreive them from the callback function
    TTObject mDataDemoParameter;     // a parameter is relative to the state of our application
    TTObject mDataDemoMessage;       // a message is a kind of command to send to our application
    TTObject mDataDemoReturn;        // a return is a kind of notification sent by our application

    // Be friend with the callback function
    friend TTErr DemoAppDataReturnValueCallback(const TTValue& baton, const TTValue& v);
};

// Callback function to get data's value back
TTErr DemoAppDataReturnValueCallback(const TTValue& baton, const TTValue& v);

int
main(int argc, char **argv)
{
    DemoApp app;

    TTLogMessage("\n*** Start of Jamoma Modular demonstration ***\n");

    app.Setup();

    // read command from console
    do {
        TTLogMessage("\nType a command : \n");

        std::string s;
        std::getline(std::cin, s);

        // quit the application
        if (!s.compare("quit")) {

            app.Quit();

            TTLogMessage("\n*** End of Jamoma Modular demonstration ***\n");
            return EXIT_SUCCESS;
        }
        // dump informations about the application
        else if (!s.compare("export")) {

             app.Export();
        }
        // parse a command and execute it
        else {

            app.Execute(s);
        }
    }
    while (YES);
}

void
DemoApp::Setup()
{
    TTValue     args, v, out, none;
    TTAddress   address;
    TTErr       err;

    TTLogMessage("\n*** Initialisation of Modular environnement ***\n");
    /////////////////////////////////////////////////////////////////////

    // Init the Modular library (passing the folder path where all the dylibs are)
    TTModularInit("/usr/local/jamoma");

    // Create an application manager
    mApplicationManager = TTObject("ApplicationManager");

    TTLogMessage("\n*** Creation of myDemoApp and myRemoteApp applications ***\n");
    ////////////////////////////////////////////////////////////////////////////////

    // Create a local application called "demo" and get it back
    err = mApplicationManager.send("ApplicationInstantiateLocal", "DemoApp", out);

    if (err) {
        TTLogError("Error : can't create myDemoApp application \n");
        return;
    }
    else
        mApplicationDemo = out[0];

    // Create a distant application called "i-score" and get it back
    err = mApplicationManager.send("ApplicationInstantiateDistant", "telecommande", out);

    if (err) {
        TTLogError("Error : can't create myRemoteApp application \n");
        return;
    }
    else
        mApplicationRemote = out[0];

    // Get registered application names
    mApplicationManager.get("applicationNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);
        TTLogMessage("%s application is well registered into the application manager \n", name.c_str());
    }

//    TTLogMessage("\n*** Enable Minuit communication ***\n");
//    ////////////////////////////////////////////////////////////////////////
//
//    // Create a Minuit protocol unit
//    err = mApplicationManager.send("ProtocolInstantiate", "Minuit", out);
//
//    if (err) {
//        TTLogError("Error : can't create Minuit protocol unit \n");
//        return;
//    }
//    else
//        mProtocolMinuit = out[0];
//
//    // Get Minuit Protocol attribute names and types
//    mProtocolMinuit.get("parameterNames", out);
//    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
//        TTSymbol name = TTElement(*it);
//        TTSymbol type = mProtocolMinuit.attributeType(name);
//        TTLogMessage("Minuit %s parameter is a %s \n", name.c_str(), type.c_str());
//    }
//
//    // Register myDemoApp and myRemoteApp to the Minuit protocol
//    mProtocolMinuit.send("ApplicationRegister", "demo", out);
//    mProtocolMinuit.send("ApplicationRegister", "i-score", out);
//
//    // Select myDemoApp to set its protocol parameters
//    mProtocolMinuit.send("ApplicationSelect", "demo", out);
//    mProtocolMinuit.set("port", 9998);
//    mProtocolMinuit.set("ip", "127.0.0.1");
//
//    // Select myRemoteApp to set its protocol parameters
//    mProtocolMinuit.send("ApplicationSelect", "i-score", out);
//    mProtocolMinuit.set("port", 13579);
//    mProtocolMinuit.set("ip", "127.0.0.1");
//
//    // Get Minuit parameters for each registered application
//    mProtocolMinuit.get("applicationNames", out);
//    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
//        TTSymbol name = TTElement(*it);
//
//        mProtocolMinuit.send("ApplicationSelect", name, out);
//        TTLogMessage("Minuit setup for %s application : \n", name.c_str());
//
//        mProtocolMinuit.get("ip", v);
//        TTSymbol ip = v[0];
//        TTLogMessage("- ip = %s \n", ip.c_str());
//
//        mProtocolMinuit.get("port", v);
//        TTUInt16 port = v[0];
//        TTLogMessage("- port = %d \n", port);
//    }
//
//    // Enable Minuit communication
//    mProtocolMinuit.send("Run");

    TTLogMessage("\n*** Enable WebSocket communication ***\n");
    ////////////////////////////////////////////////////////////////////////

    // Create a WebSocket protocol unit
    err = mApplicationManager.send("ProtocolInstantiate", "WebSocket", out);

    if (err) {
        TTLogError("Error : can't create WebSocket protocol unit \n");
        return;
    }
    else
        mProtocolWebSocket = out[0];

    // Get WebSocket Protocol attribute names and types
    mProtocolWebSocket.get("parameterNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);
        TTLogMessage("WebSocket::%s is a %s \n", name.c_str(), mProtocolWebSocket.attributeType(name).c_str());
    }

    // Register myDemoApp and myRemoteApp to the WebSocket protocol
    mProtocolWebSocket.send("ApplicationRegister", "DemoApp", out);
    mProtocolWebSocket.send("ApplicationRegister", "telecommande", out);

    // Select myDemoApp to set its protocol parameters
    mProtocolWebSocket.send("ApplicationSelect", "DemoApp", out);
    mProtocolWebSocket.set("port", 9001);
    mProtocolWebSocket.set("ip", "127.0.0.1");

    // Select myRemoteApp to set its protocol parameters
    mProtocolWebSocket.send("ApplicationSelect", "telecommande", out);
    mProtocolWebSocket.set("port", 9000);
    mProtocolWebSocket.set("ip", "127.0.0.1");

    // Enable WebSocket communication
    mProtocolWebSocket.send("Run");

    TTLogMessage("\n*** Current Protocol Setup ***\n");
    // Get protocol names
    mApplicationManager.get("protocolNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);
        TTLogMessage("%s protocol is well registered into the application manager \n", name.c_str());
    }

	TTLogMessage("\n*** Creation of myDemoApp datas ***\n");
    /////////////////////////////////////////////////////////

    // Create a parameter data and set its callback function and baton and some attributes
    mDataDemoParameter = TTObject("Data", "parameter");

    // Setup the callback mechanism to get the value back
    args = TTValue(TTPtr(this), mDataDemoParameter);
    mDataDemoParameter.set("baton", args);
    mDataDemoParameter.set("function", TTPtr(&DemoAppDataReturnValueCallback));

    // Setup the data attributes depending of its use inside the application
    mDataDemoParameter.set("type", "decimal");
    mDataDemoParameter.set("rangeBounds", TTValue(-1., 1.));
    mDataDemoParameter.set("rangeClipmode", "both");
    mDataDemoParameter.set("rampDrive", "System");
    mDataDemoParameter.set("description", "this parameter is useful for demo purpose");

    // Register the parameter data into myDemoApp at an address
    args = TTValue("/myParameter", mDataDemoParameter);
    err = mApplicationDemo.send("ObjectRegister", args, out);

    if (err)
        TTLogError("Error : can't register data at /myParameter address \n");

    else {
        address = out[0];
        TTLogMessage("\n /myParameter : effective registration address is %s \n", address.c_str());
    }

    // Create a message data and set its callback function and baton and some attributes
    mDataDemoMessage = TTObject("Data", "message");

    // Setup the callback mechanism to get the value back
    args = TTValue(TTPtr(this), mDataDemoMessage);
    mDataDemoMessage.set("baton", args);
    mDataDemoMessage.set("function", TTPtr(&DemoAppDataReturnValueCallback));

    // Setup the data attributes depending of its use inside the application
    mDataDemoMessage.set("type", "none");
    mDataDemoMessage.set("description", "this message is useful for demo purpose");

    // Register the message data into myDemoApp at an address
    args = TTValue("/myMessage", mDataDemoMessage);
    mApplicationDemo.send("ObjectRegister", args, out);

    if (err)
        TTLogError("Error : can't register data at /myMessage address \n");

    else {
        address = out[0];
        TTLogMessage("\n /myMessage : effective registration address is %s \n", address.c_str());
    }

    // Create a return data and set its callback function and baton and some attributes
    mDataDemoReturn = TTObject("Data", "return");

    // Setup the callback mechanism to get the value back
    args = TTValue(TTPtr(this), mDataDemoReturn);
    mDataDemoReturn.set("baton", args);
    mDataDemoReturn.set("function", TTPtr(&DemoAppDataReturnValueCallback));

    // Setup the data attributes depending of its use inside the application
    mDataDemoReturn.set("type", "integer");
    mDataDemoReturn.set("description", "this return is useful for demo purpose");

    // Register the return data into myDemoApp at an address
    args = TTValue("/myReturn", mDataDemoReturn);
    mApplicationDemo.send("ObjectRegister", args, out);

    if (err)
        TTLogError("Error : can't register data at /myReturn address \n");

    else {
        address = out[0];
        TTLogMessage("\n /myReturn : effective registration address is %s \n", address.c_str());
    }
}

void
DemoApp::Export()
{
    TTValue     out;
    TTObject    xmlHandler("XmlHandler");

    // export the namespace of myDemoApp
    xmlHandler.set("object", mApplicationDemo);
    xmlHandler.send("Write", "./myDemoApp.xml", out);
}

void
DemoApp::Execute(std::string command)
{
    // parse the command : address value
    TTValue out, v = TTString(command);
    v.fromString();

    // Send the command to the object at the given address
    mApplicationDemo.send("ObjectSend", v, out);
}

void
DemoApp::Quit()
{
    TTValue out;

    TTLogMessage("\n*** Release myDemoApp datas ***\n");
    /////////////////////////////////////////////////////

    // Unregister the parameter
    if ( mApplicationDemo.send("ObjectUnregister", "/myParameter", out))
        TTLogError("Error : can't unregister data at /myParameter address \n");

    // Unregister the message
    if (mApplicationDemo.send("ObjectUnregister", "/myMessage", out))
        TTLogError("Error : can't unregister data at /myMessage address \n");

    // Unregister the return
    if (mApplicationDemo.send("ObjectUnregister", "/myReturn", out))
        TTLogError("Error : can't unregister data at /myReturn address \n");

    TTLogMessage("\n*** Release protocols ***\n");
    ///////////////////////////////////////////////

    mApplicationManager.send("ProtocolRelease", "Minuit", out);
    mApplicationManager.send("ProtocolRelease", "WebSocket", out);

    TTLogMessage("\n*** Release applications ***\n");
    //////////////////////////////////////////////////

    mApplicationManager.send("ApplicationRelease", "telecommande", out);
    mApplicationManager.send("ApplicationRelease", "DemoApp", out);
}

TTErr
DemoAppDataReturnValueCallback(const TTValue& baton, const TTValue& value)
{
    DemoApp*    demoApp = (DemoApp*)TTPtr(baton[0]);
    TTObject    anObject = baton[1];

	// Reteive which data has been updated
    if (anObject.instance() == demoApp->mDataDemoParameter.instance()) {

        // print the returned value
        TTLogMessage("/myParameter has been updated to %s \n", value.toString().data());
        return kTTErrNone;
    }

    if (anObject.instance() == demoApp->mDataDemoMessage.instance()) {

        // print the returned value
        TTLogMessage("/myMessage has been updated to %s \n", value.toString().data());
        return kTTErrNone;
    }

    if (anObject.instance() == demoApp->mDataDemoReturn.instance()) {

        // print the returned value
        TTLogMessage("/myReturn has been updated to %s \n", value.toString().data());
        return kTTErrNone;
    }

    return kTTErrGeneric;
}<commit_msg>DemoApp : instanciate WebSocket protocol<commit_after>#include "TTModular.h"

#include <iostream>
#include <string>

// A class for our application
class DemoApp {

public:

    DemoApp(){};
    ~DemoApp(){};

    // This application is divided into four main functions
    void Setup();
    void Export();
    void Execute(std::string command);
    void Quit();

private:

    // Declare the application manager, our application and another one
    TTObject mApplicationManager;
    TTObject mApplicationDemo;
    TTObject mApplicationRemote;

    // Declare protocol units to use
    TTObject mProtocolMinuit;
    TTObject mProtocolWebSocket;

public:

    // Declare publicly all datas of our application to retreive them from the callback function
    TTObject mDataDemoParameter;     // a parameter is relative to the state of our application
    TTObject mDataDemoMessage;       // a message is a kind of command to send to our application
    TTObject mDataDemoReturn;        // a return is a kind of notification sent by our application

    // Be friend with the callback function
    friend TTErr DemoAppDataReturnValueCallback(const TTValue& baton, const TTValue& v);
};

// Callback function to get data's value back
TTErr DemoAppDataReturnValueCallback(const TTValue& baton, const TTValue& v);

int
main(int argc, char **argv)
{
    DemoApp app;

    TTLogMessage("\n*** Start of Jamoma Modular demonstration ***\n");

    app.Setup();

    // read command from console
    do {
        TTLogMessage("\nType a command : \n");

        std::string s;
        std::getline(std::cin, s);

        // quit the application
        if (!s.compare("quit")) {

            app.Quit();

            TTLogMessage("\n*** End of Jamoma Modular demonstration ***\n");
            return EXIT_SUCCESS;
        }
        // dump informations about the application
        else if (!s.compare("export")) {

            app.Export();
        }
        // parse a command and execute it
        else {

            app.Execute(s);
        }
    }
    while (YES);
}

void
DemoApp::Setup()
{
    TTValue     args, v, out, none;
    TTAddress   address;
    TTErr       err;

    TTLogMessage("\n*** Initialisation of Modular environnement ***\n");
    /////////////////////////////////////////////////////////////////////

    // Init the Modular library (passing the folder path where all the dylibs are)
    TTModularInit("/usr/local/jamoma");

    // Create an application manager
    mApplicationManager = TTObject("ApplicationManager");

    TTLogMessage("\n*** Creation of myDemoApp and myRemoteApp applications ***\n");
    ////////////////////////////////////////////////////////////////////////////////

    // Create a local application called "demo" and get it back
    err = mApplicationManager.send("ApplicationInstantiateLocal", "demo", out);

    if (err) {
        TTLogError("Error : can't create myDemoApp application \n");
        return;
    }
    else
        mApplicationDemo = out[0];

    // Create a distant application called "i-score" and get it back
    err = mApplicationManager.send("ApplicationInstantiateDistant", "i-score", out);

    if (err) {
        TTLogError("Error : can't create myRemoteApp application \n");
        return;
    }
    else
        mApplicationRemote = out[0];

    // Get registered application names
    mApplicationManager.get("applicationNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);
        TTLogMessage("%s application is well registered into the application manager \n", name.c_str());
    }

    TTLogMessage("\n*** Enable Minuit communication ***\n");
    ////////////////////////////////////////////////////////////////////////

    // Create a Minuit protocol unit
    err = mApplicationManager.send("ProtocolInstantiate", "Minuit", out);

    if (err) {
        TTLogError("Error : can't create Minuit protocol unit \n");
        return;
    }
    else
        mProtocolMinuit = out[0];

    // Get Minuit Protocol attribute names and types
    mProtocolMinuit.get("parameterNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);
        TTSymbol type = mProtocolMinuit.attributeType(name);
        TTLogMessage("Minuit %s parameter is a %s \n", name.c_str(), type.c_str());
    }

    // Register myDemoApp and myRemoteApp to the Minuit protocol
    mProtocolMinuit.send("ApplicationRegister", "demo", out);
    mProtocolMinuit.send("ApplicationRegister", "i-score", out);

    // Select myDemoApp to set its protocol parameters
    mProtocolMinuit.send("ApplicationSelect", "demo", out);
    mProtocolMinuit.set("port", 9998);
    mProtocolMinuit.set("ip", "127.0.0.1");

    // Select myRemoteApp to set its protocol parameters
    mProtocolMinuit.send("ApplicationSelect", "i-score", out);
    mProtocolMinuit.set("port", 13579);
    mProtocolMinuit.set("ip", "127.0.0.1");

    // Get Minuit parameters for each registered application
    mProtocolMinuit.get("applicationNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);

        mProtocolMinuit.send("ApplicationSelect", name, out);
        TTLogMessage("Minuit setup for %s application : \n", name.c_str());

        mProtocolMinuit.get("ip", v);
        TTSymbol ip = v[0];
        TTLogMessage("- ip = %s \n", ip.c_str());

        mProtocolMinuit.get("port", v);
        TTUInt16 port = v[0];
        TTLogMessage("- port = %d \n", port);
    }

    // Enable Minuit communication
    mProtocolMinuit.send("Run");

    TTLogMessage("\n*** Enable WebSocket communication ***\n");
    ////////////////////////////////////////////////////////////////////////

    // Create a WebSocket protocol unit
    err = mApplicationManager.send("ProtocolInstantiate", "WebSocket", out);

    if (err) {
        TTLogError("Error : can't create WebSocket protocol unit \n");
        return;
    }
    else
        mProtocolWebSocket = out[0];

    // Get WebSocket Protocol attribute names and types
    mProtocolWebSocket.get("parameterNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);
        TTLogMessage("WebSocket %s parameter is a %s \n", name.c_str(), mProtocolWebSocket.attributeType(name).c_str());
    }

    // Register myDemoApp and myRemoteApp to the WebSocket protocol
    mProtocolWebSocket.send("ApplicationRegister", "demo", out);

    // No need to register remote app for now because WebSocket plugin is only a server,
    // remote clients have to instanciate the connection, and clients connection informations are stored internally
//    mProtocolWebSocket.send("ApplicationRegister", "i-score", out);

    // Select myDemoApp to set its protocol parameters
    mProtocolWebSocket.send("ApplicationSelect", "demo", out);
    mProtocolWebSocket.set("port", 9001);
    mProtocolWebSocket.set("ip", "127.0.0.1");

    // Select myRemoteApp to set its protocol parameters : no need because WebSocket plugin is only a server,
    // remote clients have to instanciate the connection, and clients connection informations are stored internally
//    mProtocolWebSocket.send("ApplicationSelect", "i-score", out);
//    mProtocolWebSocket.set("???", none);

    // Get WebSocket parameters for each registered application
    mProtocolWebSocket.get("applicationNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);

        mProtocolWebSocket.send("ApplicationSelect", name, out);
        TTLogMessage("WebSocket setup for %s application : \n", name.c_str());

        mProtocolWebSocket.get("ip", v);
        TTSymbol ip = v[0];
        TTLogMessage("- ip = %s \n", ip.c_str());

        mProtocolWebSocket.get("port", v);
        TTUInt16 port = v[0];
        TTLogMessage("- port = %d \n", port);
    }

    // Enable WebSocket communication
    mProtocolWebSocket.send("Run");

    TTLogMessage("\n*** Current Protocol Setup ***\n");
    // Get protocol names
    mApplicationManager.get("protocolNames", out);
    for (TTElementIter it = out.begin() ; it != out.end() ; it++) {
        TTSymbol name = TTElement(*it);
        TTLogMessage("%s protocol is well registered into the application manager \n", name.c_str());
    }

	TTLogMessage("\n*** Creation of myDemoApp datas ***\n");
    /////////////////////////////////////////////////////////

    // Create a parameter data and set its callback function and baton and some attributes
    mDataDemoParameter = TTObject("Data", "parameter");

    // Setup the callback mechanism to get the value back
    args = TTValue(TTPtr(this), mDataDemoParameter);
    mDataDemoParameter.set("baton", args);
    mDataDemoParameter.set("function", TTPtr(&DemoAppDataReturnValueCallback));

    // Setup the data attributes depending of its use inside the application
    mDataDemoParameter.set("type", "decimal");
    mDataDemoParameter.set("rangeBounds", TTValue(-1., 1.));
    mDataDemoParameter.set("rangeClipmode", "both");
    mDataDemoParameter.set("rampDrive", "System");
    mDataDemoParameter.set("description", "this parameter is useful for demo purpose");

    // Register the parameter data into myDemoApp at an address
    args = TTValue("/myParameter", mDataDemoParameter);
    err = mApplicationDemo.send("ObjectRegister", args, out);

    if (err)
        TTLogError("Error : can't register data at /myParameter address \n");

    else {
        address = out[0];
        TTLogMessage("\n /myParameter : effective registration address is %s \n", address.c_str());
    }

    // Create a message data and set its callback function and baton and some attributes
    mDataDemoMessage = TTObject("Data", "message");

    // Setup the callback mechanism to get the value back
    args = TTValue(TTPtr(this), mDataDemoMessage);
    mDataDemoMessage.set("baton", args);
    mDataDemoMessage.set("function", TTPtr(&DemoAppDataReturnValueCallback));

    // Setup the data attributes depending of its use inside the application
    mDataDemoMessage.set("type", "none");
    mDataDemoMessage.set("description", "this message is useful for demo purpose");

    // Register the message data into myDemoApp at an address
    args = TTValue("/myMessage", mDataDemoMessage);
    mApplicationDemo.send("ObjectRegister", args, out);

    if (err)
        TTLogError("Error : can't register data at /myMessage address \n");

    else {
        address = out[0];
        TTLogMessage("\n /myMessage : effective registration address is %s \n", address.c_str());
    }

    // Create a return data and set its callback function and baton and some attributes
    mDataDemoReturn = TTObject("Data", "return");

    // Setup the callback mechanism to get the value back
    args = TTValue(TTPtr(this), mDataDemoReturn);
    mDataDemoReturn.set("baton", args);
    mDataDemoReturn.set("function", TTPtr(&DemoAppDataReturnValueCallback));

    // Setup the data attributes depending of its use inside the application
    mDataDemoReturn.set("type", "integer");
    mDataDemoReturn.set("description", "this return is useful for demo purpose");

    // Register the return data into myDemoApp at an address
    args = TTValue("/myReturn", mDataDemoReturn);
    mApplicationDemo.send("ObjectRegister", args, out);

    if (err)
        TTLogError("Error : can't register data at /myReturn address \n");

    else {
        address = out[0];
        TTLogMessage("\n /myReturn : effective registration address is %s \n", address.c_str());
    }
}

void
DemoApp::Export()
{
    TTValue     out;
    TTObject    xmlHandler("XmlHandler");

    // export the namespace of myDemoApp
    xmlHandler.set("object", mApplicationDemo);
    xmlHandler.send("Write", "./myDemoApp.xml", out);
}

void
DemoApp::Execute(std::string command)
{
    // parse the command : address value
    TTValue out, v = TTString(command);
    v.fromString();

    // Send the command to the object at the given address
    mApplicationDemo.send("ObjectSend", v, out);
}

void
DemoApp::Quit()
{
    TTValue out;

    TTLogMessage("\n*** Release myDemoApp datas ***\n");
    /////////////////////////////////////////////////////

    // Unregister the parameter
    if ( mApplicationDemo.send("ObjectUnregister", "/myParameter", out))
        TTLogError("Error : can't unregister data at /myParameter address \n");

    // Unregister the message
    if (mApplicationDemo.send("ObjectUnregister", "/myMessage", out))
        TTLogError("Error : can't unregister data at /myMessage address \n");

    // Unregister the return
    if (mApplicationDemo.send("ObjectUnregister", "/myReturn", out))
        TTLogError("Error : can't unregister data at /myReturn address \n");

    TTLogMessage("\n*** Release protocols ***\n");
    ///////////////////////////////////////////////

    mApplicationManager.send("ProtocolRelease", "Minuit", out);
    //mApplicationManager.send("ProtocolRelease", "WebSocket", out);

    TTLogMessage("\n*** Release applications ***\n");
    //////////////////////////////////////////////////

    mApplicationManager.send("ApplicationRelease", "i-score", out);
    mApplicationManager.send("ApplicationRelease", "demo", out);
}

TTErr
DemoAppDataReturnValueCallback(const TTValue& baton, const TTValue& value)
{
    DemoApp*    demoApp = (DemoApp*)TTPtr(baton[0]);
    TTObject    anObject = baton[1];

	// Reteive which data has been updated
    if (anObject.instance() == demoApp->mDataDemoParameter.instance()) {

        // print the returned value
        TTLogMessage("/myParameter has been updated to %s \n", value.toString().data());
        return kTTErrNone;
    }

    if (anObject.instance() == demoApp->mDataDemoMessage.instance()) {

        // print the returned value
        TTLogMessage("/myMessage has been updated to %s \n", value.toString().data());
        return kTTErrNone;
    }

    if (anObject.instance() == demoApp->mDataDemoReturn.instance()) {

        // print the returned value
        TTLogMessage("/myReturn has been updated to %s \n", value.toString().data());
        return kTTErrNone;
    }

    return kTTErrGeneric;
}<|endoftext|>


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

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2665
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1561407 by johtaylo@johtaylo-jtincrementor2-increment on 2018/05/30 03:00:07<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2666
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


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

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2703
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1586299 by chui@ocl-promo-incrementor on 2018/07/27 02:56:34<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2704
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


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

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3052
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 2040547 by chui@ocl-promo-incrementor on 2019/12/04 03:00:16<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3053
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


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

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3082
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 2060601 by chui@ocl-promo-incrementor on 2020/01/21 03:00:20<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3083
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>// Copyright (c) 2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <string>

#include "version.h"

// Name of client reported in the 'version' message. Report the same name
// for both bitcoind and bitcoin-qt, to make it harder for attackers to
// target servers or GUI users specifically.
const std::string CLIENT_NAME("Satoshi");

// Client version number
#define CLIENT_VERSION_SUFFIX   ""

// The following part of the code determines the CLIENT_BUILD variable.
// Several mechanisms are used for this:
// * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
//   generated by the build environment, possibly containing the output
//   of git-describe in a macro called BUILD_DESC
// * secondly, if this is an exported version of the code, GIT_ARCHIVE will
//   be defined (automatically using the export-subst git attribute), and
//   GIT_COMMIT will contain the commit id.
// * then, three options exist for determining CLIENT_BUILD:
//   * if BUILD_DESC is defined, use that literally (output of git-describe)
//   * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
//   * otherwise, use v[maj].[min].[rev].[build]-unk
// finally CLIENT_VERSION_SUFFIX is added

// First, include build.h if requested
#ifdef HAVE_BUILD_INFO
#    include "build.h"
#endif

// git will put "#define GIT_ARCHIVE 1" on the next line inside archives.
#define GIT_ARCHIVE 1
#ifdef GIT_ARCHIVE
#    define GIT_COMMIT_ID "6b2edb9"
#    define GIT_COMMIT_DATE "$Format:%cD"
#endif

#define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \
    "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit

#define BUILD_DESC_FROM_UNKNOWN(maj,min,rev,build) \
    "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk"

#ifndef BUILD_DESC
#    ifdef GIT_COMMIT_ID
#        define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
#    else
#        define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
#    endif
#endif

#ifndef BUILD_DATE
#    ifdef GIT_COMMIT_DATE
#        define BUILD_DATE GIT_COMMIT_DATE
#    else
#        define BUILD_DATE __DATE__ ", " __TIME__
#    endif
#endif

const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
const std::string CLIENT_DATE(BUILD_DATE);
<commit_msg>venom, file path test<commit_after>// Copyright (c) 2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <string>

#include "version.h"

// Name of client reported in the 'version' message. Report the same name
// for both bitcoind and bitcoin-qt, to make it harder for attackers to
// target servers or GUI users specifically.
const std::string CLIENT_NAME("Satoshi");

// Client version number
#define CLIENT_VERSION_SUFFIX   ""

// The following part of the code determines the CLIENT_BUILD variable.
// Several mechanisms are used for this:
// * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
//   generated by the build environment, possibly containing the output
//   of git-describe in a macro called BUILD_DESC
// * secondly, if this is an exported version of the code, GIT_ARCHIVE will
//   be defined (automatically using the export-subst git attribute), and
//   GIT_COMMIT will contain the commit id.
// * then, three options exist for determining CLIENT_BUILD:
//   * if BUILD_DESC is defined, use that literally (output of git-describe)
//   * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
//   * otherwise, use v[maj].[min].[rev].[build]-unk
// finally CLIENT_VERSION_SUFFIX is added

// First, include build.h if requested
#ifdef HAVE_BUILD_INFO
#    include "build.h"
#endif

// git will put "#define GIT_ARCHIVE 1" on the next line inside archives.
#define GIT_ARCHIVE 1
#ifdef GIT_ARCHIVE
#    define GIT_COMMIT_ID "72fc393"
#    define GIT_COMMIT_DATE "$Format:%cD"
#endif

#define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \
    "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit

#define BUILD_DESC_FROM_UNKNOWN(maj,min,rev,build) \
    "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk"

#ifndef BUILD_DESC
#    ifdef GIT_COMMIT_ID
#        define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
#    else
#        define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
#    endif
#endif

#ifndef BUILD_DATE
#    ifdef GIT_COMMIT_DATE
#        define BUILD_DATE GIT_COMMIT_DATE
#    else
#        define BUILD_DATE __DATE__ ", " __TIME__
#    endif
#endif

const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
const std::string CLIENT_DATE(BUILD_DATE);
<|endoftext|>


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

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2887
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1777295 by chui@ocl-promo-incrementor on 2019/05/02 03:00:03<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2888
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


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

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 2135
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1276475 by johtaylo@johtaylo-JTBUILDER03-increment on 2016/06/05 03:00:11<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 2136
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>// See copyright notice in file Copyright in the root directory of this archive.

#include "warped.h"
#include "../include/Process.h"
#include "../include/ProcessState.h"
#include "SimulationManager.h"
#include "StopWatch.h"
#include "IntVTime.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <time.h>
using namespace std;

Process::Process(unsigned int procNr, string &name, unsigned int nrOfOutputs,
                 vector<string> outputs, unsigned int stateSize, unsigned int numBalls,
                 distribution_t dist, double initCompGrain, double seed,
                 int hp/*=1*/, int hotspotNum/*=0*/):
  processNumber(procNr), myObjectName(name),  numberOfOutputs(nrOfOutputs),
  outputNames(outputs), sizeOfState(stateSize), numberOfTokens(numBalls),
  compGrain(initCompGrain), sourceDistribution(dist), first(seed), second(0.0),
    hotspotProb(hp), destLPMin(0), destLPMax(0), numLPs(0) {
}

Process::~Process() {
  deallocateState(getState());
};

void
Process::initialize() {
   for (int i = 0; i < outputNames.size(); i++) {
      SimulationObject* o = getObjectHandle(outputNames[i]);
      int simMgrId = o->getObjectID()->getSimulationManagerID();
      if(simMgrId >= outputHandles.size())
          outputHandles.resize(simMgrId + 1);
      outputHandles[simMgrId].push_back(o);
   }
   numLPs = outputHandles.size();
   if(getObjectID()->getSimulationManagerID() == 0)
       hotspotProb = 1;
   destLPMax = numLPs + hotspotProb - 2;

   ProcessState* myState = dynamic_cast<ProcessState *>( getState() );
   ASSERT(myState != NULL);

   delete myState->gen; // delete old copy
   myState->gen = new MLCG(processNumber, (processNumber + 1));
   for (int i = 0; i < myState->sizeOfStateData; i++) {
      myState->stateBulk[i] = '1';
   }

   // Process numbers have to be 0, 1, 2, ... to get a fully ordered
   // and sequenced set of event numbers in steps of 1.
   int eventNumberBase = numberOfTokens * processNumber;
   for(int i = 1; i <= numberOfTokens; i++ ) {
      IntVTime sendTime = dynamic_cast<const IntVTime&>(getSimulationTime());
      int ldelay = msgDelay();
      PHOLDEvent *event = new PHOLDEvent(sendTime, sendTime + 1 + ldelay, this, this);
      event->eventNumber = eventNumberBase + i;

      receiveEvent(event);
      myState->eventSent();
   }

}

void
Process::finalize(){
  SEVERITY severity = NOTE;

  ProcessState* myState = dynamic_cast<ProcessState*>(getState());
  ASSERT(myState != NULL);

  ostringstream oss;
  oss << "  Sent: " << myState->getNumSent() << " Received: " << myState->getNumReceived();

  string msg = myObjectName + oss.str() + "\n";
  cout << msg;
  reportError( msg, severity );
}

void
Process::executeProcess(){
   IntVTime sendTime = dynamic_cast<const IntVTime&>(getSimulationTime());

   ostringstream oss;
   oss << "obj" << processNumber << ".csv";
   ofstream f(oss.str().c_str(), ios_base::app);
   do {
      PHOLDEvent* recvEvent = (PHOLDEvent*) getEvent();

      if( recvEvent != NULL ){
         ProcessState* myState = (ProcessState *) getState();
         myState->eventReceived();

         // Generate the destination for the event.
         // probability distribution for the destination is uniform except for
         // the hotspot LP, which has hotspotProb times the probability of all
         // other destinations
         DiscreteUniform lpd = DiscreteUniform(0, destLPMax, myState->gen);
         int lp = static_cast<int>(lpd());
         if(lp > numLPs - 1)
             lp = 0;

         DiscreteUniform objd = DiscreteUniform(0, outputHandles[lp].size() - 1, myState->gen);
         int destObj = static_cast<int>(objd());

         SimulationObject *receiver = outputHandles[lp][destObj];

         f << receiver->getName() << endl;

         // Generate the delay between the send and receive times.
         int ldelay = msgDelay();
         IntVTime recvTime = sendTime + 1 + ldelay;

         PHOLDEvent* newRequest = new PHOLDEvent(sendTime, recvTime, this, receiver);

         newRequest->numberOfHops = recvEvent->numberOfHops + 1;
         newRequest->eventNumber = recvEvent->eventNumber;

         computationGrain();

         receiver->receiveEvent(newRequest);
         myState->eventSent();
      }
   } while(haveMoreEvents() == true); // end of while loop
}

int
Process::msgDelay() {

  double ldelay;

  ProcessState* myState = (ProcessState *) getState();

  switch(sourceDistribution){
  case UNIFORM :
    {
      Uniform uniform(first, second, myState->gen);
      ldelay = uniform();
      break;
    }
  case NORMAL :
    {
      Normal normal(first, second, myState->gen);
      ldelay = normal();
      break;
    }
  case BINOMIAL :
    {
      Binomial binomial((int)first, second, myState->gen);
      ldelay = binomial();
      break;
    }
  case POISSON :
    {
      Poisson poisson(first, myState->gen);
      ldelay = poisson();
      break;
    }
  case EXPONENTIAL :
    {
      NegativeExpntl expo(first, myState->gen);
      ldelay = expo();
      break;
    }
  case FIXED :
    ldelay = (int)first ;
    break;
  default :
    ldelay = 0;
    cerr << "Improper Distribution for a Source Object!!!" << "\n";
    break;
  }
  return ( (int) ldelay );

}

void
Process::computationGrain(){
  // Perform the designated number of double divisions.
  double x = 123731.1;
  for( unsigned int i = 0; i < compGrain; i++ ){
    x = x / 3.3;
  }

  // This is here to prevent the compiler from optimizing everything out.
  lastX = x;
}

State*
Process::allocateState() {
  return new ProcessState(sizeOfState);
}

void
Process::deallocateState(const State* state){
  delete state;
}

void
Process::reclaimEvent(const Event *event){
   delete event;
}

void
Process::reportError(const string&, SEVERITY){
}
<commit_msg>oops... accidentally checked in debug code that was making phold simulatino objects output to csv files...<commit_after>// See copyright notice in file Copyright in the root directory of this archive.

#include "warped.h"
#include "../include/Process.h"
#include "../include/ProcessState.h"
#include "SimulationManager.h"
#include "StopWatch.h"
#include "IntVTime.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <time.h>
using namespace std;

Process::Process(unsigned int procNr, string &name, unsigned int nrOfOutputs,
                 vector<string> outputs, unsigned int stateSize, unsigned int numBalls,
                 distribution_t dist, double initCompGrain, double seed,
                 int hp/*=1*/, int hotspotNum/*=0*/):
  processNumber(procNr), myObjectName(name),  numberOfOutputs(nrOfOutputs),
  outputNames(outputs), sizeOfState(stateSize), numberOfTokens(numBalls),
  compGrain(initCompGrain), sourceDistribution(dist), first(seed), second(0.0),
    hotspotProb(hp), destLPMin(0), destLPMax(0), numLPs(0) {
}

Process::~Process() {
  deallocateState(getState());
};

void
Process::initialize() {
   for (int i = 0; i < outputNames.size(); i++) {
      SimulationObject* o = getObjectHandle(outputNames[i]);
      int simMgrId = o->getObjectID()->getSimulationManagerID();
      if(simMgrId >= outputHandles.size())
          outputHandles.resize(simMgrId + 1);
      outputHandles[simMgrId].push_back(o);
   }
   numLPs = outputHandles.size();
   if(getObjectID()->getSimulationManagerID() == 0)
       hotspotProb = 1;
   destLPMax = numLPs + hotspotProb - 2;

   ProcessState* myState = dynamic_cast<ProcessState *>( getState() );
   ASSERT(myState != NULL);

   delete myState->gen; // delete old copy
   myState->gen = new MLCG(processNumber, (processNumber + 1));
   for (int i = 0; i < myState->sizeOfStateData; i++) {
      myState->stateBulk[i] = '1';
   }

   // Process numbers have to be 0, 1, 2, ... to get a fully ordered
   // and sequenced set of event numbers in steps of 1.
   int eventNumberBase = numberOfTokens * processNumber;
   for(int i = 1; i <= numberOfTokens; i++ ) {
      IntVTime sendTime = dynamic_cast<const IntVTime&>(getSimulationTime());
      int ldelay = msgDelay();
      PHOLDEvent *event = new PHOLDEvent(sendTime, sendTime + 1 + ldelay, this, this);
      event->eventNumber = eventNumberBase + i;

      receiveEvent(event);
      myState->eventSent();
   }

}

void
Process::finalize(){
  SEVERITY severity = NOTE;

  ProcessState* myState = dynamic_cast<ProcessState*>(getState());
  ASSERT(myState != NULL);

  ostringstream oss;
  oss << "  Sent: " << myState->getNumSent() << " Received: " << myState->getNumReceived();

  string msg = myObjectName + oss.str() + "\n";
  cout << msg;
  reportError( msg, severity );
}

void
Process::executeProcess(){
   IntVTime sendTime = dynamic_cast<const IntVTime&>(getSimulationTime());

   do {
      PHOLDEvent* recvEvent = (PHOLDEvent*) getEvent();

      if( recvEvent != NULL ){
         ProcessState* myState = (ProcessState *) getState();
         myState->eventReceived();

         // Generate the destination for the event.
         // probability distribution for the destination is uniform except for
         // the hotspot LP, which has hotspotProb times the probability of all
         // other destinations
         DiscreteUniform lpd = DiscreteUniform(0, destLPMax, myState->gen);
         int lp = static_cast<int>(lpd());
         if(lp > numLPs - 1)
             lp = 0;

         DiscreteUniform objd = DiscreteUniform(0, outputHandles[lp].size() - 1, myState->gen);
         int destObj = static_cast<int>(objd());

         SimulationObject *receiver = outputHandles[lp][destObj];

         // Generate the delay between the send and receive times.
         int ldelay = msgDelay();
         IntVTime recvTime = sendTime + 1 + ldelay;

         PHOLDEvent* newRequest = new PHOLDEvent(sendTime, recvTime, this, receiver);

         newRequest->numberOfHops = recvEvent->numberOfHops + 1;
         newRequest->eventNumber = recvEvent->eventNumber;

         computationGrain();

         receiver->receiveEvent(newRequest);
         myState->eventSent();
      }
   } while(haveMoreEvents() == true); // end of while loop
}

int
Process::msgDelay() {

  double ldelay;

  ProcessState* myState = (ProcessState *) getState();

  switch(sourceDistribution){
  case UNIFORM :
    {
      Uniform uniform(first, second, myState->gen);
      ldelay = uniform();
      break;
    }
  case NORMAL :
    {
      Normal normal(first, second, myState->gen);
      ldelay = normal();
      break;
    }
  case BINOMIAL :
    {
      Binomial binomial((int)first, second, myState->gen);
      ldelay = binomial();
      break;
    }
  case POISSON :
    {
      Poisson poisson(first, myState->gen);
      ldelay = poisson();
      break;
    }
  case EXPONENTIAL :
    {
      NegativeExpntl expo(first, myState->gen);
      ldelay = expo();
      break;
    }
  case FIXED :
    ldelay = (int)first ;
    break;
  default :
    ldelay = 0;
    cerr << "Improper Distribution for a Source Object!!!" << "\n";
    break;
  }
  return ( (int) ldelay );

}

void
Process::computationGrain(){
  // Perform the designated number of double divisions.
  double x = 123731.1;
  for( unsigned int i = 0; i < compGrain; i++ ){
    x = x / 3.3;
  }

  // This is here to prevent the compiler from optimizing everything out.
  lastX = x;
}

State*
Process::allocateState() {
  return new ProcessState(sizeOfState);
}

void
Process::deallocateState(const State* state){
  delete state;
}

void
Process::reclaimEvent(const Event *event){
   delete event;
}

void
Process::reportError(const string&, SEVERITY){
}
<|endoftext|>


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

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1978
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1222472 by johtaylo@johtaylo-JTBUILDER03-increment on 2015/12/19 03:00:11<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1979
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>/*
 This file is part of MMOServer. For more information, visit http://swganh.com

 Copyright (c) 2006 - 2010 The SWG:ANH Team

 MMOServer is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 MMOServer is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with MMOServer.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "anh/crc.h"

using namespace anh;

const uint32_t CRC_TABLE[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
    0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
    0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
    0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
    0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
    0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
    0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
    0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
    0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
    0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
    0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
    0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
    0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
    0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
    0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
    0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
    0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
    0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
    0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
    0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
    0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
    0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
    0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
    0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
    0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
    0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
    0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
    0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
    0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
    0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
    0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
    0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
    0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
    0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
    0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
    0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
    0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
    0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
    0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
    0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
    0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
    0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
    0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};

uint32_t anh::memcrc(const char* source_string, uint32_t length)
{
    uint32_t crc = 0xffffffff;  // starting seed
    for (uint32_t i = 0; i < length; ++i) {
        crc = CRC_TABLE[source_string[i] ^ (crc >> 24)] ^ (crc << 8);
    }

    return ~crc;
}

uint32_t anh::memcrc(const std::string& source_string)
{
    return memcrc(source_string.c_str(), source_string.length());
}

uint32_t anh::memcrc(const char* src_buffer, uint32_t length, uint32_t seed)
{
	uint32_t newCRC = 0, index = 0;

    newCRC = CRC_TABLE[(~seed) & 0xFF];
    newCRC ^= 0x00FFFFFF;
    index = (seed >> 8) ^ newCRC;
    newCRC = (newCRC >> 8) & 0x00FFFFFF;
    newCRC ^= CRC_TABLE[index & 0xFF];
    index = (seed >> 16) ^ newCRC;
    newCRC = (newCRC >> 8) & 0x00FFFFFF;
    newCRC ^= CRC_TABLE[index & 0xFF];
    index = (seed >> 24) ^ newCRC;
    newCRC = (newCRC >> 8) &0x00FFFFFF;
    newCRC ^= CRC_TABLE[index & 0xFF];

    for(uint32_t i = 0; i < length; i++ )
    {
        index = (src_buffer[i]) ^ newCRC;
        newCRC = (newCRC >> 8) & 0x00FFFFFF;
        newCRC ^= CRC_TABLE[index & 0xFF];
    }

    return ~newCRC;
}<commit_msg>Reverted crc table<commit_after>/*
 This file is part of MMOServer. For more information, visit http://swganh.com

 Copyright (c) 2006 - 2010 The SWG:ANH Team

 MMOServer is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 MMOServer is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with MMOServer.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "anh/crc.h"

using namespace anh;

const uint32_t CRC_TABLE[256] = {
    0x0000000,
    0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,
    0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6,
    0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD,
    0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 0x5F15ADAC,
    0x5BD4B01B, 0x569796C2, 0x52568B75, 0x6A1936C8, 0x6ED82B7F,
    0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3, 0x709F7B7A,
    0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039,
    0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58,
    0xBAEA46EF, 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033,
    0xA4AD16EA, 0xA06C0B5D, 0xD4326D90, 0xD0F37027, 0xDDB056FE,
    0xD9714B49, 0xC7361B4C, 0xC3F706FB, 0xCEB42022, 0xCA753D95,
    0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, 0xE13EF6F4,
    0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0,
    0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5,
    0x2AC12072, 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16,
    0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA, 0x7897AB07,
    0x7C56B6B0, 0x71159069, 0x75D48DDE, 0x6B93DDDB, 0x6F52C06C,
    0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08, 0x571D7DD1,
    0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,
    0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B,
    0xBB60ADFC, 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698,
    0x832F1041, 0x87EE0DF6, 0x99A95DF3, 0x9D684044, 0x902B669D,
    0x94EA7B2A, 0xE0B41DE7, 0xE4750050, 0xE9362689, 0xEDF73B3E,
    0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2, 0xC6BCF05F,
    0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34,
    0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80,
    0x644FC637, 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB,
    0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, 0x5C007B8A,
    0x58C1663D, 0x558240E4, 0x51435D53, 0x251D3B9E, 0x21DC2629,
    0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5, 0x3F9B762C,
    0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF,
    0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E,
    0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65,
    0xEBA91BBC, 0xEF68060B, 0xD727BBB6, 0xD3E6A601, 0xDEA580D8,
    0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, 0xC960EBB3,
    0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, 0xAE3AFBA2,
    0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71,
    0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74,
    0x857130C3, 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640,
    0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C, 0x7B827D21,
    0x7F436096, 0x7200464F, 0x76C15BF8, 0x68860BFD, 0x6C47164A,
    0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E, 0x18197087,
    0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,
    0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D,
    0x2056CD3A, 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE,
    0xCC2B1D17, 0xC8EA00A0, 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB,
    0xDBEE767C, 0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, 0xEEE2ED18,
    0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4, 0x89B8FD09,
    0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662,
    0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF,
    0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4,
};

uint32_t anh::memcrc(const char* source_string, uint32_t length)
{
    uint32_t crc = 0xffffffff;  // starting seed
    for (uint32_t i = 0; i < length; ++i) {
        crc = CRC_TABLE[source_string[i] ^ (crc >> 24)] ^ (crc << 8);
    }

    return ~crc;
}

uint32_t anh::memcrc(const std::string& source_string)
{
    return memcrc(source_string.c_str(), source_string.length());
}

uint32_t anh::memcrc(const char* src_buffer, uint32_t length, uint32_t seed)
{
	uint32_t newCRC = 0, index = 0;

    newCRC = CRC_TABLE[(~seed) & 0xFF];
    newCRC ^= 0x00FFFFFF;
    index = (seed >> 8) ^ newCRC;
    newCRC = (newCRC >> 8) & 0x00FFFFFF;
    newCRC ^= CRC_TABLE[index & 0xFF];
    index = (seed >> 16) ^ newCRC;
    newCRC = (newCRC >> 8) & 0x00FFFFFF;
    newCRC ^= CRC_TABLE[index & 0xFF];
    index = (seed >> 24) ^ newCRC;
    newCRC = (newCRC >> 8) &0x00FFFFFF;
    newCRC ^= CRC_TABLE[index & 0xFF];

    for(uint32_t i = 0; i < length; i++ )
    {
        index = (src_buffer[i]) ^ newCRC;
        newCRC = (newCRC >> 8) & 0x00FFFFFF;
        newCRC ^= CRC_TABLE[index & 0xFF];
    }

    return ~newCRC;
}<|endoftext|>