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

#include "AeronArchive.h"

using namespace aeron;
using namespace aeron::archive::client;

AeronArchive::AsyncConnect::AsyncConnect(
    Context_t &context,
    std::shared_ptr<Aeron> aeron,
    std::int64_t subscriptionId,
    std::int64_t publicationId,
    const long long deadlineNs) :
    m_nanoClock(systemNanoClock),
    m_ctx(std::unique_ptr<Context_t>(new Context_t(context))),
    m_aeron(std::move(aeron)),
    m_subscriptionId(subscriptionId),
    m_publicationId(publicationId),
    m_deadlineNs(deadlineNs)
{
}

std::shared_ptr<AeronArchive> AeronArchive::AsyncConnect::poll()
{
    if (m_nanoClock() > m_deadlineNs)
    {
        throw TimeoutException(
            "Archive connect timeout: correlationId=" + std::to_string(m_correlationId) +
            " step=" + std::to_string(m_step),
            SOURCEINFO);
    }

    if (!m_subscription)
    {
        m_subscription = m_aeron->findSubscription(m_subscriptionId);
    }

    if (!m_controlResponsePoller && m_subscription)
    {
        m_controlResponsePoller = std::unique_ptr<ControlResponsePoller>(new ControlResponsePoller(m_subscription));
    }

    if (!m_publication)
    {
        m_publication = m_aeron->findExclusivePublication(m_publicationId);
    }

    if (!m_archiveProxy && m_publication)
    {
        m_archiveProxy = std::unique_ptr<ArchiveProxy>(new ArchiveProxy(m_publication));
    }

    if (0 == m_step && m_archiveProxy)
    {
        if (!m_archiveProxy->publication()->isConnected())
        {
            return std::shared_ptr<AeronArchive>();
        }

        m_step = 1;
    }

    if (1 == m_step)
    {
        m_correlationId = m_aeron->nextCorrelationId();

        m_step = 2;
    }

    if (2 == m_step)
    {
        std::string controlResponseChannel = m_subscription->tryResolveChannelEndpointPort();
        if (controlResponseChannel.empty())
        {
            return std::shared_ptr<AeronArchive>();
        }

        auto encodedCredentials = m_ctx->credentialsSupplier().m_encodedCredentials();

        if (!m_archiveProxy->tryConnect(
            controlResponseChannel,m_ctx->controlResponseStreamId(), encodedCredentials, m_correlationId))
        {
            m_ctx->credentialsSupplier().m_onFree(encodedCredentials);
            return std::shared_ptr<AeronArchive>();
        }

        m_ctx->credentialsSupplier().m_onFree(encodedCredentials);

        m_step = 3;
    }

    if (3 == m_step && m_controlResponsePoller)
    {
        if (!m_subscription->isConnected())
        {
            return std::shared_ptr<AeronArchive>();
        }

        m_step = 4;
    }

    if (6 == m_step && m_controlResponsePoller)
    {
        if (!m_archiveProxy->tryChallengeResponse(
            m_encodedCredentialsFromChallenge, m_correlationId, m_challengeControlSessionId))
        {
            return std::shared_ptr<AeronArchive>();
        }

        m_ctx->credentialsSupplier().m_onFree(m_encodedCredentialsFromChallenge);
        m_encodedCredentialsFromChallenge.first = nullptr;
        m_encodedCredentialsFromChallenge.second = 0;

        m_step = 7;
    }

    if (m_controlResponsePoller)
    {
        m_controlResponsePoller->poll();

        if (m_controlResponsePoller->isPollComplete() && m_controlResponsePoller->correlationId() == m_correlationId)
        {
            const std::int64_t sessionId = m_controlResponsePoller->controlSessionId();

            if (m_controlResponsePoller->wasChallenged())
            {
                m_encodedCredentialsFromChallenge = m_ctx->credentialsSupplier().m_onChallenge(
                    m_controlResponsePoller->encodedChallenge());

                m_correlationId = m_aeron->nextCorrelationId();
                m_challengeControlSessionId = sessionId;

                m_step = 6;
            }
            else
            {
                if (!m_controlResponsePoller->isCodeOk())
                {
                    if (m_controlResponsePoller->isCodeError())
                    {
                        m_archiveProxy->closeSession(sessionId);

                        throw ArchiveException(
                            static_cast<std::int32_t>(m_controlResponsePoller->relevantId()),
                            "error: " + m_controlResponsePoller->errorMessage(),
                            SOURCEINFO);
                    }

                    throw ArchiveException(
                        "unexpected response: code=" + std::to_string(m_controlResponsePoller->codeValue()),
                        SOURCEINFO);
                }

                m_archiveProxy->keepAlive(m_controlResponsePoller->correlationId(), sessionId);

                std::unique_ptr<RecordingDescriptorPoller> recordingDescriptorPoller(
                    new RecordingDescriptorPoller(m_subscription, m_ctx->errorHandler(), sessionId));
                std::unique_ptr<RecordingSubscriptionDescriptorPoller> recordingSubscriptionDescriptorPoller(
                    new RecordingSubscriptionDescriptorPoller(m_subscription, m_ctx->errorHandler(), sessionId));

                return std::make_shared<AeronArchive>(
                    std::move(m_ctx),
                    std::move(m_archiveProxy),
                    std::move(m_controlResponsePoller),
                    std::move(recordingDescriptorPoller),
                    std::move(recordingSubscriptionDescriptorPoller),
                    m_aeron,
                    sessionId);
            }
        }
    }

    return std::shared_ptr<AeronArchive>();
}

AeronArchive::AeronArchive(
    std::unique_ptr<Context_t> ctx,
    std::unique_ptr<ArchiveProxy> archiveProxy,
    std::unique_ptr<ControlResponsePoller> controlResponsePoller,
    std::unique_ptr<RecordingDescriptorPoller> recordingDescriptorPoller,
    std::unique_ptr<RecordingSubscriptionDescriptorPoller> recordingSubscriptionDescriptorPoller,
    std::shared_ptr<Aeron> aeron,
    std::int64_t controlSessionId) :
    m_ctx(std::move(ctx)),
    m_archiveProxy(std::move(archiveProxy)),
    m_controlResponsePoller(std::move(controlResponsePoller)),
    m_recordingDescriptorPoller(std::move(recordingDescriptorPoller)),
    m_recordingSubscriptionDescriptorPoller(std::move(recordingSubscriptionDescriptorPoller)),
    m_aeron(std::move(aeron)),
    m_nanoClock(systemNanoClock),
    m_controlSessionId(controlSessionId),
    m_messageTimeoutNs(m_ctx->messageTimeoutNs())
{
}

AeronArchive::~AeronArchive()
{
    if (m_archiveProxy->publication()->isConnected())
    {
        m_archiveProxy->closeSession(m_controlSessionId);
    }
}

std::shared_ptr<AeronArchive::AsyncConnect> AeronArchive::asyncConnect(AeronArchive::Context_t &ctx)
{
    ctx.conclude();

    const long long deadlineNs = systemNanoClock() + ctx.messageTimeoutNs();
    std::shared_ptr<Aeron> aeron = ctx.aeron();
    const std::int64_t subscriptionId = aeron->addSubscription(
        ctx.controlResponseChannel(), ctx.controlResponseStreamId());
    const std::int64_t publicationId = aeron->addExclusivePublication(
        ctx.controlRequestChannel(), ctx.controlRequestStreamId());

    return std::make_shared<AeronArchive::AsyncConnect>(ctx, aeron, subscriptionId, publicationId, deadlineNs);
}

std::string AeronArchive::version()
{
    return std::string("aeron version " AERON_VERSION_TXT " built " __DATE__ " " __TIME__);
}
<commit_msg>[C++] Simplify state machine for connect to archive.<commit_after>/*
 * Copyright 2014-2020 Real Logic Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "AeronArchive.h"

using namespace aeron;
using namespace aeron::archive::client;

AeronArchive::AsyncConnect::AsyncConnect(
    Context_t &context,
    std::shared_ptr<Aeron> aeron,
    std::int64_t subscriptionId,
    std::int64_t publicationId,
    const long long deadlineNs) :
    m_nanoClock(systemNanoClock),
    m_ctx(std::unique_ptr<Context_t>(new Context_t(context))),
    m_aeron(std::move(aeron)),
    m_subscriptionId(subscriptionId),
    m_publicationId(publicationId),
    m_deadlineNs(deadlineNs)
{
}

std::shared_ptr<AeronArchive> AeronArchive::AsyncConnect::poll()
{
    if (m_nanoClock() > m_deadlineNs)
    {
        throw TimeoutException(
            "Archive connect timeout: correlationId=" + std::to_string(m_correlationId) +
            " step=" + std::to_string(m_step),
            SOURCEINFO);
    }

    if (!m_subscription)
    {
        m_subscription = m_aeron->findSubscription(m_subscriptionId);
    }

    if (!m_controlResponsePoller && m_subscription)
    {
        m_controlResponsePoller = std::unique_ptr<ControlResponsePoller>(new ControlResponsePoller(m_subscription));
    }

    if (!m_publication)
    {
        m_publication = m_aeron->findExclusivePublication(m_publicationId);
    }

    if (!m_archiveProxy && m_publication)
    {
        m_archiveProxy = std::unique_ptr<ArchiveProxy>(new ArchiveProxy(m_publication));
    }

    if (0 == m_step && m_archiveProxy)
    {
        if (!m_archiveProxy->publication()->isConnected())
        {
            return std::shared_ptr<AeronArchive>();
        }

        m_step = 1;
    }

    if (1 == m_step)
    {
        std::string controlResponseChannel = m_subscription->tryResolveChannelEndpointPort();
        if (controlResponseChannel.empty())
        {
            return std::shared_ptr<AeronArchive>();
        }

        auto encodedCredentials = m_ctx->credentialsSupplier().m_encodedCredentials();
        m_correlationId = m_aeron->nextCorrelationId();

        if (!m_archiveProxy->tryConnect(
            controlResponseChannel,m_ctx->controlResponseStreamId(), encodedCredentials, m_correlationId))
        {
            m_ctx->credentialsSupplier().m_onFree(encodedCredentials);
            return std::shared_ptr<AeronArchive>();
        }

        m_ctx->credentialsSupplier().m_onFree(encodedCredentials);
        m_step = 2;
    }

    if (2 == m_step && m_controlResponsePoller)
    {
        if (!m_subscription->isConnected())
        {
            return std::shared_ptr<AeronArchive>();
        }

        m_step = 3;
    }

    if (5 == m_step && m_controlResponsePoller)
    {
        if (!m_archiveProxy->tryChallengeResponse(
            m_encodedCredentialsFromChallenge, m_correlationId, m_challengeControlSessionId))
        {
            return std::shared_ptr<AeronArchive>();
        }

        m_ctx->credentialsSupplier().m_onFree(m_encodedCredentialsFromChallenge);
        m_encodedCredentialsFromChallenge.first = nullptr;
        m_encodedCredentialsFromChallenge.second = 0;
        m_step = 6;
    }

    if (m_controlResponsePoller)
    {
        m_controlResponsePoller->poll();

        if (m_controlResponsePoller->isPollComplete() && m_controlResponsePoller->correlationId() == m_correlationId)
        {
            const std::int64_t sessionId = m_controlResponsePoller->controlSessionId();

            if (m_controlResponsePoller->wasChallenged())
            {
                m_encodedCredentialsFromChallenge = m_ctx->credentialsSupplier().m_onChallenge(
                    m_controlResponsePoller->encodedChallenge());

                m_correlationId = m_aeron->nextCorrelationId();
                m_challengeControlSessionId = sessionId;
                m_step = 5;
            }
            else
            {
                if (!m_controlResponsePoller->isCodeOk())
                {
                    if (m_controlResponsePoller->isCodeError())
                    {
                        m_archiveProxy->closeSession(sessionId);

                        throw ArchiveException(
                            static_cast<std::int32_t>(m_controlResponsePoller->relevantId()),
                            "error: " + m_controlResponsePoller->errorMessage(),
                            SOURCEINFO);
                    }

                    throw ArchiveException(
                        "unexpected response: code=" + std::to_string(m_controlResponsePoller->codeValue()),
                        SOURCEINFO);
                }

                m_archiveProxy->keepAlive(aeron::NULL_VALUE, sessionId);

                std::unique_ptr<RecordingDescriptorPoller> recordingDescriptorPoller(
                    new RecordingDescriptorPoller(m_subscription, m_ctx->errorHandler(), sessionId));
                std::unique_ptr<RecordingSubscriptionDescriptorPoller> recordingSubscriptionDescriptorPoller(
                    new RecordingSubscriptionDescriptorPoller(m_subscription, m_ctx->errorHandler(), sessionId));

                return std::make_shared<AeronArchive>(
                    std::move(m_ctx),
                    std::move(m_archiveProxy),
                    std::move(m_controlResponsePoller),
                    std::move(recordingDescriptorPoller),
                    std::move(recordingSubscriptionDescriptorPoller),
                    m_aeron,
                    sessionId);
            }
        }
    }

    return std::shared_ptr<AeronArchive>();
}

AeronArchive::AeronArchive(
    std::unique_ptr<Context_t> ctx,
    std::unique_ptr<ArchiveProxy> archiveProxy,
    std::unique_ptr<ControlResponsePoller> controlResponsePoller,
    std::unique_ptr<RecordingDescriptorPoller> recordingDescriptorPoller,
    std::unique_ptr<RecordingSubscriptionDescriptorPoller> recordingSubscriptionDescriptorPoller,
    std::shared_ptr<Aeron> aeron,
    std::int64_t controlSessionId) :
    m_ctx(std::move(ctx)),
    m_archiveProxy(std::move(archiveProxy)),
    m_controlResponsePoller(std::move(controlResponsePoller)),
    m_recordingDescriptorPoller(std::move(recordingDescriptorPoller)),
    m_recordingSubscriptionDescriptorPoller(std::move(recordingSubscriptionDescriptorPoller)),
    m_aeron(std::move(aeron)),
    m_nanoClock(systemNanoClock),
    m_controlSessionId(controlSessionId),
    m_messageTimeoutNs(m_ctx->messageTimeoutNs())
{
}

AeronArchive::~AeronArchive()
{
    if (m_archiveProxy->publication()->isConnected())
    {
        m_archiveProxy->closeSession(m_controlSessionId);
    }
}

std::shared_ptr<AeronArchive::AsyncConnect> AeronArchive::asyncConnect(AeronArchive::Context_t &ctx)
{
    ctx.conclude();

    const long long deadlineNs = systemNanoClock() + ctx.messageTimeoutNs();
    std::shared_ptr<Aeron> aeron = ctx.aeron();
    const std::int64_t subscriptionId = aeron->addSubscription(
        ctx.controlResponseChannel(), ctx.controlResponseStreamId());
    const std::int64_t publicationId = aeron->addExclusivePublication(
        ctx.controlRequestChannel(), ctx.controlRequestStreamId());

    return std::make_shared<AeronArchive::AsyncConnect>(ctx, aeron, subscriptionId, publicationId, deadlineNs);
}

std::string AeronArchive::version()
{
    return std::string("aeron version " AERON_VERSION_TXT " built " __DATE__ " " __TIME__);
}
<|endoftext|>


<commit_before>#include <stan/math/rev/scal.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/rev/scal/util.hpp>
#include <limits>

TEST(MathFunctions, is_any_nan_variadic_rev) {
  using stan::math::is_any_nan;

  double dbl_inf = std::numeric_limits<double>::infinity();
  double dbl_nan = std::numeric_limits<double>::quiet_NaN();

  AVAR var_nan(dbl_nan);
  AVAR var_inf(dbl_inf);

  AVAR a = 7.0;
  AVAR b = 2.0;

  EXPECT_TRUE(is_any_nan(var_nan, b, 6, 5.0));
  EXPECT_TRUE(is_any_nan(var_nan, var_inf, 6, 5.0));
  EXPECT_TRUE(is_any_nan(dbl_nan, a, b, 6, 5.0));

  EXPECT_FALSE(is_any_nan(dbl_inf, b, 6, var_inf));
  EXPECT_FALSE(is_any_nan(a, b, 6, 7.0));
}
<commit_msg>Fix includes for AVAR typedef.<commit_after>#include <stan/math/rev/scal.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/rev/scal/util.hpp>
#include <test/unit/math/rev/scal/fun/util.hpp>
#include <limits>

TEST(MathFunctions, is_any_nan_variadic_rev) {
  using stan::math::is_any_nan;

  double dbl_inf = std::numeric_limits<double>::infinity();
  double dbl_nan = std::numeric_limits<double>::quiet_NaN();

  AVAR var_nan(dbl_nan);
  AVAR var_inf(dbl_inf);

  AVAR a = 7.0;
  AVAR b = 2.0;

  EXPECT_TRUE(is_any_nan(var_nan, b, 6, 5.0));
  EXPECT_TRUE(is_any_nan(var_nan, var_inf, 6, 5.0));
  EXPECT_TRUE(is_any_nan(dbl_nan, a, b, 6, 5.0));

  EXPECT_FALSE(is_any_nan(dbl_inf, b, 6, var_inf));
  EXPECT_FALSE(is_any_nan(a, b, 6, 7.0));
}
<|endoftext|>


<commit_before>/**
 *  @file NASA9poly_test
 *       test problem for NASA 9 coefficient formulation
 */

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;

#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))

/*****************************************************************/
/*****************************************************************/

#include "Cantera.h"
#include "transport.h"
#include "IdealGasMix.h"

#include "kernel/TransportFactory.h"

using namespace Cantera;

void printDbl(double val) {
  if (fabs(val) < 5.0E-17) {
    cout << " nil";
  } else {
    cout << val;
  }
}

int main(int argc, char** argv) {

  try {

    IdealGasMix g("gasNASA9.xml", "gri30_mix");
    int nsp = g.nSpecies();
    double pres = 1.0E5;
    vector_fp Xset(nsp, 0.0);
    Xset[0] =  0.5 ;
    Xset[1] =  0.5;

    g.setState_TPX(1500.0, pres, DATA_PTR(Xset));

    vector_fp cp_R(nsp, 0.0);
    g.getCp_R(DATA_PTR(cp_R));

    vector_fp Gvalues(nsp, 0.0);

    printf("Comparisons of H2 calculated via several equivalent classes:\n");
    printf("1500 K and 1 atm:\n");
    printf("         NasaThermo   Nasa9   Nasa9_4reg \n");
    printf("  cp/R: %11.6g %11.6g %11.6g\n", cp_R[0], cp_R[1], cp_R[2]);

    vector_fp H_RT(nsp, 0.0);
    g.getEnthalpy_RT(DATA_PTR(H_RT));

    printf("  H/RT: %11.6g %11.6g %11.6g\n", H_RT[0], H_RT[1], H_RT[2]);

    vector_fp S_R(nsp, 0.0);
    g.getEntropy_R(DATA_PTR(S_R));
    printf("  S/R: %11.6g %11.6g %11.6g\n", S_R[0], S_R[1], S_R[2]);

   Transport * tran = newTransportMgr("Mix", &g);

    // MultiTransport * tranMix = dynamic_cast<MultiTransport *>(tran);
    printf("Viscoscity and thermal Cond vs. T\n");
    for ( int k = 0; k < 40; k++) {
      double T1 = 400. + 200. * k;
      g.setState_TPX(T1, pres, DATA_PTR(Xset));
      g.getPureGibbs(DATA_PTR(Gvalues));
      //printf("     --  %13g %13.5g %13.5g %13.5g %13.5g \n",
      //	     Gvalues[0],  Gvalues[1],  Gvalues[2],
      //	     Gvalues[3],  Gvalues[4]);
      double visc = tran->viscosity();
      double cond = tran->thermalConductivity();
      printf("    %13g %13.5g %13.5g\n", T1, visc, cond);
    }

  }
  catch (CanteraError) {
    showErrors(cout);
  }

  return 0;
}
/***********************************************************/
<commit_msg>Added using namespace command.<commit_after>/**
 *  @file NASA9poly_test
 *       test problem for NASA 9 coefficient formulation
 */

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;

#define MAX(x,y) (( (x) > (y) ) ? (x) : (y))

/*****************************************************************/
/*****************************************************************/

#include "Cantera.h"
#include "transport.h"
#include "IdealGasMix.h"

#include "kernel/TransportFactory.h"

using namespace Cantera;
using namespace Cantera_CXX;

void printDbl(double val) {
  if (fabs(val) < 5.0E-17) {
    cout << " nil";
  } else {
    cout << val;
  }
}

int main(int argc, char** argv) {

  try {

    IdealGasMix g("gasNASA9.xml", "gri30_mix");
    int nsp = g.nSpecies();
    double pres = 1.0E5;
    vector_fp Xset(nsp, 0.0);
    Xset[0] =  0.5 ;
    Xset[1] =  0.5;

    g.setState_TPX(1500.0, pres, DATA_PTR(Xset));

    vector_fp cp_R(nsp, 0.0);
    g.getCp_R(DATA_PTR(cp_R));

    vector_fp Gvalues(nsp, 0.0);

    printf("Comparisons of H2 calculated via several equivalent classes:\n");
    printf("1500 K and 1 atm:\n");
    printf("         NasaThermo   Nasa9   Nasa9_4reg \n");
    printf("  cp/R: %11.6g %11.6g %11.6g\n", cp_R[0], cp_R[1], cp_R[2]);

    vector_fp H_RT(nsp, 0.0);
    g.getEnthalpy_RT(DATA_PTR(H_RT));

    printf("  H/RT: %11.6g %11.6g %11.6g\n", H_RT[0], H_RT[1], H_RT[2]);

    vector_fp S_R(nsp, 0.0);
    g.getEntropy_R(DATA_PTR(S_R));
    printf("  S/R: %11.6g %11.6g %11.6g\n", S_R[0], S_R[1], S_R[2]);

   Transport * tran = newTransportMgr("Mix", &g);

    // MultiTransport * tranMix = dynamic_cast<MultiTransport *>(tran);
    printf("Viscoscity and thermal Cond vs. T\n");
    for ( int k = 0; k < 40; k++) {
      double T1 = 400. + 200. * k;
      g.setState_TPX(T1, pres, DATA_PTR(Xset));
      g.getPureGibbs(DATA_PTR(Gvalues));
      //printf("     --  %13g %13.5g %13.5g %13.5g %13.5g \n",
      //	     Gvalues[0],  Gvalues[1],  Gvalues[2],
      //	     Gvalues[3],  Gvalues[4]);
      double visc = tran->viscosity();
      double cond = tran->thermalConductivity();
      printf("    %13g %13.5g %13.5g\n", T1, visc, cond);
    }

  }
  catch (CanteraError) {
    showErrors(cout);
  }

  return 0;
}
/***********************************************************/
<|endoftext|>


<commit_before>/*
***************************************
*   Asylum3D @ 2014-12-30
***************************************
*/

#include "../../asylum.hpp"

#define FRT_BIAS    -1.0f

static const mat4x4_t s_no_trans =
{
    1.0f, 0.0f, 0.0f, 0.0f,
    0.0f, 1.0f, 0.0f, 0.0f,
    0.0f, 0.0f, 1.0f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f,
};

void crhack3d9_commit_fixed (asy::crh3d9_main* main, const asy::tree_l<asy::commit_pipe>* pipe);

/*************************/
/* CrHack3D9 Effect Node */
/*************************/
struct crhack3d9_node
{
    asy::atree_unit<asy::commit_pipe>*  ptr;

    /* ========= */
    void free () {}
};

/*************************/
/* CrHack3D9 Main Object */
/*************************/
struct crhack3d9_main
{
    asy::crh3d9_main                main;
    asy::map_acs<asy::crh3d9_texr>  texs;
    asy::map_acs<asy::object_base>  base;
    asy::map_acs<asy::object_inst>  inst;
    asy::map_acs<crhack3d9_node>    node;
    asy::tree_l<asy::commit_pipe>   pipe;

    void (*commit) (asy::crh3d9_main* main, const asy::tree_l<asy::commit_pipe>* pipe);

    sCAMERA     cam;
    sFRUSTUM    frt;
};

/* ==================================== */
CR_API crh3d9_t crhack3d9_init (HWND hwnd)
{
    sDX9_HDLE   hdle;

#if defined(ASY_USE_STATIC)
    hdle.call = d3d9call_get();
#else
    sbin_t      sbin;
    nopfunc_t   func;

    sbin = sbin_testA("GFX3_D3D9.dll");
    if (sbin == NULL) {
        sbin = sbin_loadA("GFX3_D3D9.dll");
        if (sbin == NULL)
            return (NULL);
    }
    func = sbin_exportT(sbin, "d3d9call_get", nopfunc_t);
    if (func == NULL)
        return (NULL);
    hdle.call = (const sD3D9_CALL*)func();
#endif
    hdle.hwnd = hwnd;

    crhack3d9_main* rett;

    rett = struct_new(crhack3d9_main);
    if (rett == NULL)
        return (NULL);
    if (!rett->main.init(&hdle, 90.0f, FALSE, 0, 0, D3DFMT_UNKNOWN,
                        D3DFMT_D24X8, TRUE, D3DMULTISAMPLE_NONE)) {
        if (!rett->main.init(&hdle, 90.0f, FALSE, 0, 0, D3DFMT_UNKNOWN,
                            D3DFMT_D16, TRUE, D3DMULTISAMPLE_NONE))
            goto _failure1;
    }
    if (!rett->texs.init())
        goto _failure2;
    if (!rett->base.init())
        goto _failure3;
    if (!rett->inst.init())
        goto _failure4;
    if (!rett->node.init())
        goto _failure5;
    rett->main.set_camera(&rett->cam);
    rett->main.get_frustum(&rett->frt, FRT_BIAS);
    mem_set(&rett->pipe, 0, sizeof(rett->pipe));
    rett->commit = crhack3d9_commit_fixed;
    return ((crh3d9_t)rett);

_failure5:
    rett->inst.free();
_failure4:
    rett->base.free();
_failure3:
    rett->texs.free();
_failure2:
    rett->main.free();
_failure1:
    mem_free(rett);
    return (NULL);
}

/* ====================================== */
CR_API void crhack3d9_kill (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    if (real->pipe.size() != 0)
        real->pipe.free();
    real->node.free();
    real->inst.free();
    real->base.free();
    real->texs.free();
    real->main.free();
    mem_free(render);
}

/* ======================================= */
CR_API bool crhack3d9_reset (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    if (!real->main.reset())
        return (false);

    size_t              num;
    asy::crh3d9_texr*   tex;

    num = real->texs.size();
    tex = real->texs.data();
    for (size_t idx = 0; idx < num; idx++) {
        if (!tex[idx].reset())
            return (false);
    }
    return (true);
}

/* ======================================== */
CR_API void crhack3d9_commit (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    real->commit(&real->main, &real->pipe);
}

/* Asylum Namespace */
namespace asy {

/**************************/
/* CrHack3D9 Render Clear */
/**************************/
class crhack3d9_render_clear : public asylum
{
public:
    /* ================================= */
    bool doit (void* ctx, commit_pipe* obj)
    {
        CR_NOUSE(ctx);
        obj->stuffz.clear();
        return (true);
    }

    /* ================================= */
    void back (void* ctx, commit_pipe* obj)
    {
        CR_NOUSE(ctx);
        CR_NOUSE(obj);
    }
};

}   /* namespace */

/* ======================================= */
CR_API void crhack3d9_clean (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    real->pipe.trav_bfs<asy::crhack3d9_render_clear>(NULL);
}

/* ======================================== */
CR_API void crhack3d9_update (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    real->main.get_call()->tran_upd_view(real->main.get_tran());
    real->main.get_frustum(&real->frt, FRT_BIAS);
}

/* ====================================== */
CR_API void crhack3d9_show (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    real->main.draw_show();
}

/* ======================================================== */
CR_API bool crhack3d9_mode (crh3d9_t render, const char* mode)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    if (mode == NULL || strcmp(mode, "fixed") == 0) {
        real->commit = crhack3d9_commit_fixed;
        return (true);
    }
    return (false);
}

/* ===================================================== */
CR_API asy::crh3d9_main* crhack3d9_device (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (&real->main);
}

/* ============================================ */
CR_API sCAMERA* crhack3d9_camera (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (&real->cam);
}

/* ============================================== */
CR_API size_t crhack3d9_inst_count (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (real->inst.size());
}

/* ======================================================== */
CR_API asy::object_inst* crhack3d9_inst_list (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (real->inst.data());
}

/* ========================================================================= */
CR_API asy::object_inst* crhack3d9_inst_get (crh3d9_t render, const char* name)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (real->inst.get(name));
}

/* ====================================================================== */
CR_API bool crhack3d9_inst_visable (crh3d9_t render, asy::object_inst* inst)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    if (inst->type == INST_TYPE_STATIC) {
        if (!frustum_aabb(&real->frt, &inst->bound.aabb))
            return (false);
    }
    else {
        if (!frustum_ball(&real->frt, &inst->bound.ball))
            return (false);
    }
    return (true);
}

/* ========================================================================= */
CR_API asy::commit_pipe* crhack3d9_pipe_get (crh3d9_t render, const char* name)
{
    crhack3d9_node* node;
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    node = real->node.get(name);
    if (node == NULL || node->ptr == NULL)
        return (NULL);
    return (&node->ptr->user);
}

/* ===================================================================================== */
CR_API bool crhack3d9_pipe_add (asy::commit_pipe* pipe, asy::object_inst* inst, size_t idx)
{
    asy::commit_unit    unit;

    unit.inst = inst;
    unit.unit = inst->base->list.get(idx);
    if (pipe->stuffz.append(&unit) == NULL)
        return (false);
    return (true);
}

/* ======================================================================= */
CR_API asy::commit_pipe* crhack3d9_effect (crh3d9_t render, const char* name,
                                        const char* uppe, asy::IEffect* effect)
{
    crhack3d9_node      node;
    crhack3d9_node*     nnew;
    crhack3d9_node*     find;
    crhack3d9_main*     real;
    asy::commit_pipe    pipe;

    node.ptr = NULL;
    real = (crhack3d9_main*)render;
    nnew = real->node.insert(name, &node);
    if (nnew == NULL)
        return (NULL);
    pipe.effect = effect;
    pipe.stuffz.init();
    if (real->pipe.size() == 0) {
        if (!real->pipe.init(&pipe))
            return (NULL);
        nnew->ptr = real->pipe.root();
    }
    else {
        find = real->node.get(uppe);
        if (find == NULL || find->ptr == NULL)
            return (NULL);
        nnew->ptr = real->pipe.append(find->ptr, &pipe);
        if (nnew->ptr == NULL)
            return (NULL);
    }
    if (effect != NULL)
        effect->add_ref();
    return (&nnew->ptr->user);
}

/* ============================================================ */
CR_API bool crhack3d9_instance (crh3d9_t render, const char* name,
                                const char* base, const vec3d_t* rote,
                                const vec3d_t* move, const vec3d_t* scale)
{
    crhack3d9_main*     real;
    asy::object_inst    inst;

    real = (crhack3d9_main*)render;
    inst.base = real->base.get(base);
    if (inst.base == NULL)
        return (false);
    if (name[0] == '$') {
        scale = NULL;
        inst.type = INST_TYPE_DYNAMIC;
    }
    else {
        inst.type = INST_TYPE_STATIC;
    }
    if (inst.base->tran != NULL) {
        inst.base->tran(&inst, (void*)(real->main.get_call()), rote, move, scale);
    }
    else {
        if (inst.type == INST_TYPE_STATIC) {
            mem_cpy(&inst.bound.aabb, &inst.base->aabb, sizeof(sAABB));
            if (move != NULL) {
                for (int idx = 0; idx < 8; idx++) {
                    inst.bound.aabb.v[idx].x += move->x;
                    inst.bound.aabb.v[idx].y += move->y;
                    inst.bound.aabb.v[idx].z += move->z;
                }
            }
        }
        else {
            mem_cpy(&inst.bound.ball, &inst.base->ball, sizeof(sSPHERE));
            if (move != NULL) {
                inst.bound.ball.center.x += move->x;
                inst.bound.ball.center.y += move->y;
                inst.bound.ball.center.z += move->z;
            }
        }
        mem_cpy(&inst.tran, &s_no_trans, sizeof(mat4x4_t));
    }
    if (real->inst.insert(name, &inst) == NULL)
        return (false);
    return (true);
}

/* ============================================================= */
CR_API bool crhack3d9_wavefront (crh3d9_t render, const char* name,
                    const ansi_t* obj, const ansi_t* mtl, bool_t swap_yz,
                                bool_t neg_z, const char* type)
{
    sWAVEFRONT          mesh;
    crhack3d9_main*     real;
    asy::crh3d9_texr    texr;
    asy::object_base    base;

    if (!wfront_obj_load(&mesh, obj, swap_yz, neg_z))
        return (false);
    if (!wfront_mtl_load(&mesh, mtl))
        goto _failure;
    real = (crhack3d9_main*)render;
    if (type == NULL || strcmp(type, "fixed") == 0) {
        for (leng_t idx = 0; idx < mesh.n_m; idx++) {
            const char* str = mesh.p_m[idx].map_kd;
            if (str == NULL)
                continue;
            if (!texr.init(&real->main, str, 1))
                goto _failure;
            if (real->texs.insert(str, &texr) == NULL) {
                texr.free();
                goto _failure;
            }
        }
        if (!create_crh3d9_base_wf(&base, &mesh, create_crh3d9_attr_wf_fixed,
                        create_crh3d9_mesh_wf_ss, &real->texs, &real->main))
            goto _failure;
    }
    else {
        goto _failure;
    }
    if (real->base.insert(name, &base) == NULL) {
        base.free();
        goto _failure;
    }
    return (true);

_failure:
    wfront_obj_free(&mesh);
    return (false);
}
<commit_msg>Asylum: 补上物体平移变换<commit_after>/*
***************************************
*   Asylum3D @ 2014-12-30
***************************************
*/

#include "../../asylum.hpp"

#define FRT_BIAS    -1.0f

static const mat4x4_t s_no_trans =
{
    1.0f, 0.0f, 0.0f, 0.0f,
    0.0f, 1.0f, 0.0f, 0.0f,
    0.0f, 0.0f, 1.0f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f,
};

void crhack3d9_commit_fixed (asy::crh3d9_main* main, const asy::tree_l<asy::commit_pipe>* pipe);

/*************************/
/* CrHack3D9 Effect Node */
/*************************/
struct crhack3d9_node
{
    asy::atree_unit<asy::commit_pipe>*  ptr;

    /* ========= */
    void free () {}
};

/*************************/
/* CrHack3D9 Main Object */
/*************************/
struct crhack3d9_main
{
    asy::crh3d9_main                main;
    asy::map_acs<asy::crh3d9_texr>  texs;
    asy::map_acs<asy::object_base>  base;
    asy::map_acs<asy::object_inst>  inst;
    asy::map_acs<crhack3d9_node>    node;
    asy::tree_l<asy::commit_pipe>   pipe;

    void (*commit) (asy::crh3d9_main* main, const asy::tree_l<asy::commit_pipe>* pipe);

    sCAMERA     cam;
    sFRUSTUM    frt;
};

/* ==================================== */
CR_API crh3d9_t crhack3d9_init (HWND hwnd)
{
    sDX9_HDLE   hdle;

#if defined(ASY_USE_STATIC)
    hdle.call = d3d9call_get();
#else
    sbin_t      sbin;
    nopfunc_t   func;

    sbin = sbin_testA("GFX3_D3D9.dll");
    if (sbin == NULL) {
        sbin = sbin_loadA("GFX3_D3D9.dll");
        if (sbin == NULL)
            return (NULL);
    }
    func = sbin_exportT(sbin, "d3d9call_get", nopfunc_t);
    if (func == NULL)
        return (NULL);
    hdle.call = (const sD3D9_CALL*)func();
#endif
    hdle.hwnd = hwnd;

    crhack3d9_main* rett;

    rett = struct_new(crhack3d9_main);
    if (rett == NULL)
        return (NULL);
    if (!rett->main.init(&hdle, 90.0f, FALSE, 0, 0, D3DFMT_UNKNOWN,
                        D3DFMT_D24X8, TRUE, D3DMULTISAMPLE_NONE)) {
        if (!rett->main.init(&hdle, 90.0f, FALSE, 0, 0, D3DFMT_UNKNOWN,
                            D3DFMT_D16, TRUE, D3DMULTISAMPLE_NONE))
            goto _failure1;
    }
    if (!rett->texs.init())
        goto _failure2;
    if (!rett->base.init())
        goto _failure3;
    if (!rett->inst.init())
        goto _failure4;
    if (!rett->node.init())
        goto _failure5;
    rett->main.set_camera(&rett->cam);
    rett->main.get_frustum(&rett->frt, FRT_BIAS);
    mem_set(&rett->pipe, 0, sizeof(rett->pipe));
    rett->commit = crhack3d9_commit_fixed;
    return ((crh3d9_t)rett);

_failure5:
    rett->inst.free();
_failure4:
    rett->base.free();
_failure3:
    rett->texs.free();
_failure2:
    rett->main.free();
_failure1:
    mem_free(rett);
    return (NULL);
}

/* ====================================== */
CR_API void crhack3d9_kill (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    if (real->pipe.size() != 0)
        real->pipe.free();
    real->node.free();
    real->inst.free();
    real->base.free();
    real->texs.free();
    real->main.free();
    mem_free(render);
}

/* ======================================= */
CR_API bool crhack3d9_reset (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    if (!real->main.reset())
        return (false);

    size_t              num;
    asy::crh3d9_texr*   tex;

    num = real->texs.size();
    tex = real->texs.data();
    for (size_t idx = 0; idx < num; idx++) {
        if (!tex[idx].reset())
            return (false);
    }
    return (true);
}

/* ======================================== */
CR_API void crhack3d9_commit (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    real->commit(&real->main, &real->pipe);
}

/* Asylum Namespace */
namespace asy {

/**************************/
/* CrHack3D9 Render Clear */
/**************************/
class crhack3d9_render_clear : public asylum
{
public:
    /* ================================= */
    bool doit (void* ctx, commit_pipe* obj)
    {
        CR_NOUSE(ctx);
        obj->stuffz.clear();
        return (true);
    }

    /* ================================= */
    void back (void* ctx, commit_pipe* obj)
    {
        CR_NOUSE(ctx);
        CR_NOUSE(obj);
    }
};

}   /* namespace */

/* ======================================= */
CR_API void crhack3d9_clean (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    real->pipe.trav_bfs<asy::crhack3d9_render_clear>(NULL);
}

/* ======================================== */
CR_API void crhack3d9_update (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    real->main.get_call()->tran_upd_view(real->main.get_tran());
    real->main.get_frustum(&real->frt, FRT_BIAS);
}

/* ====================================== */
CR_API void crhack3d9_show (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    real->main.draw_show();
}

/* ======================================================== */
CR_API bool crhack3d9_mode (crh3d9_t render, const char* mode)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    if (mode == NULL || strcmp(mode, "fixed") == 0) {
        real->commit = crhack3d9_commit_fixed;
        return (true);
    }
    return (false);
}

/* ===================================================== */
CR_API asy::crh3d9_main* crhack3d9_device (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (&real->main);
}

/* ============================================ */
CR_API sCAMERA* crhack3d9_camera (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (&real->cam);
}

/* ============================================== */
CR_API size_t crhack3d9_inst_count (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (real->inst.size());
}

/* ======================================================== */
CR_API asy::object_inst* crhack3d9_inst_list (crh3d9_t render)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (real->inst.data());
}

/* ========================================================================= */
CR_API asy::object_inst* crhack3d9_inst_get (crh3d9_t render, const char* name)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    return (real->inst.get(name));
}

/* ====================================================================== */
CR_API bool crhack3d9_inst_visable (crh3d9_t render, asy::object_inst* inst)
{
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    if (inst->type == INST_TYPE_STATIC) {
        if (!frustum_aabb(&real->frt, &inst->bound.aabb))
            return (false);
    }
    else {
        if (!frustum_ball(&real->frt, &inst->bound.ball))
            return (false);
    }
    return (true);
}

/* ========================================================================= */
CR_API asy::commit_pipe* crhack3d9_pipe_get (crh3d9_t render, const char* name)
{
    crhack3d9_node* node;
    crhack3d9_main* real;

    real = (crhack3d9_main*)render;
    node = real->node.get(name);
    if (node == NULL || node->ptr == NULL)
        return (NULL);
    return (&node->ptr->user);
}

/* ===================================================================================== */
CR_API bool crhack3d9_pipe_add (asy::commit_pipe* pipe, asy::object_inst* inst, size_t idx)
{
    asy::commit_unit    unit;

    unit.inst = inst;
    unit.unit = inst->base->list.get(idx);
    if (pipe->stuffz.append(&unit) == NULL)
        return (false);
    return (true);
}

/* ======================================================================= */
CR_API asy::commit_pipe* crhack3d9_effect (crh3d9_t render, const char* name,
                                        const char* uppe, asy::IEffect* effect)
{
    crhack3d9_node      node;
    crhack3d9_node*     nnew;
    crhack3d9_node*     find;
    crhack3d9_main*     real;
    asy::commit_pipe    pipe;

    node.ptr = NULL;
    real = (crhack3d9_main*)render;
    nnew = real->node.insert(name, &node);
    if (nnew == NULL)
        return (NULL);
    pipe.effect = effect;
    pipe.stuffz.init();
    if (real->pipe.size() == 0) {
        if (!real->pipe.init(&pipe))
            return (NULL);
        nnew->ptr = real->pipe.root();
    }
    else {
        find = real->node.get(uppe);
        if (find == NULL || find->ptr == NULL)
            return (NULL);
        nnew->ptr = real->pipe.append(find->ptr, &pipe);
        if (nnew->ptr == NULL)
            return (NULL);
    }
    if (effect != NULL)
        effect->add_ref();
    return (&nnew->ptr->user);
}

/* ============================================================ */
CR_API bool crhack3d9_instance (crh3d9_t render, const char* name,
                                const char* base, const vec3d_t* rote,
                                const vec3d_t* move, const vec3d_t* scale)
{
    crhack3d9_main*     real;
    asy::object_inst    inst;

    real = (crhack3d9_main*)render;
    inst.base = real->base.get(base);
    if (inst.base == NULL)
        return (false);
    if (name[0] == '$') {
        scale = NULL;
        inst.type = INST_TYPE_DYNAMIC;
    }
    else {
        inst.type = INST_TYPE_STATIC;
    }
    if (inst.base->tran != NULL) {
        inst.base->tran(&inst, (void*)(real->main.get_call()), rote, move, scale);
    }
    else {
        if (inst.type == INST_TYPE_STATIC) {
            mem_cpy(&inst.bound.aabb, &inst.base->aabb, sizeof(sAABB));
            if (move != NULL) {
                for (int idx = 0; idx < 8; idx++) {
                    inst.bound.aabb.v[idx].x += move->x;
                    inst.bound.aabb.v[idx].y += move->y;
                    inst.bound.aabb.v[idx].z += move->z;
                }
            }
        }
        else {
            mem_cpy(&inst.bound.ball, &inst.base->ball, sizeof(sSPHERE));
            if (move != NULL) {
                inst.bound.ball.center.x += move->x;
                inst.bound.ball.center.y += move->y;
                inst.bound.ball.center.z += move->z;
            }
        }
        mem_cpy(&inst.tran, &s_no_trans, sizeof(mat4x4_t));
        if (move != NULL) {
            inst.tran[12] = move->x;
            inst.tran[13] = move->y;
            inst.tran[14] = move->z;
        }
    }
    if (real->inst.insert(name, &inst) == NULL)
        return (false);
    return (true);
}

/* ============================================================= */
CR_API bool crhack3d9_wavefront (crh3d9_t render, const char* name,
                    const ansi_t* obj, const ansi_t* mtl, bool_t swap_yz,
                                bool_t neg_z, const char* type)
{
    sWAVEFRONT          mesh;
    crhack3d9_main*     real;
    asy::crh3d9_texr    texr;
    asy::object_base    base;

    if (!wfront_obj_load(&mesh, obj, swap_yz, neg_z))
        return (false);
    if (!wfront_mtl_load(&mesh, mtl))
        goto _failure;
    real = (crhack3d9_main*)render;
    if (type == NULL || strcmp(type, "fixed") == 0) {
        for (leng_t idx = 0; idx < mesh.n_m; idx++) {
            const char* str = mesh.p_m[idx].map_kd;
            if (str == NULL)
                continue;
            if (!texr.init(&real->main, str, 1))
                goto _failure;
            if (real->texs.insert(str, &texr) == NULL) {
                texr.free();
                goto _failure;
            }
        }
        if (!create_crh3d9_base_wf(&base, &mesh, create_crh3d9_attr_wf_fixed,
                        create_crh3d9_mesh_wf_ss, &real->texs, &real->main))
            goto _failure;
    }
    else {
        goto _failure;
    }
    if (real->base.insert(name, &base) == NULL) {
        base.free();
        goto _failure;
    }
    return (true);

_failure:
    wfront_obj_free(&mesh);
    return (false);
}
<|endoftext|>


<commit_before>#ifndef STAN_MATH_FWD_FUN_QUAD_FORM_HPP
#define STAN_MATH_FWD_FUN_QUAD_FORM_HPP

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/dot_product.hpp>
#include <stan/math/fwd/fun/multiply.hpp>

namespace stan {
namespace math {

/**
 * Return the quadratic form \f$ B^T A B \f$.
 *
 * Symmetry of the resulting matrix is not guaranteed due to numerical
 * precision.
 *
 * @tparam Ta type of elements in the square matrix
 * @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
 * @tparam Ca number of columns in the square matrix, can be Eigen::Dynamic
 * @tparam Tb type of elements in the second matrix
 * @tparam Rb number of rows in the second matrix, can be Eigen::Dynamic
 * @tparam Cb number of columns in the second matrix, can be Eigen::Dynamic
 *
 * @param A square matrix
 * @param B second matrix
 * @return The quadratic form, which is a symmetric matrix of size Cb.
 * @throws std::invalid_argument if A is not square, or if A cannot be
 * multiplied by B
 */
template <typename Ta, int Ra, int Ca, typename Tb, int Rb, int Cb,
          require_any_fvar_t<Ta, Tb>...>
inline Eigen::Matrix<return_type_t<Ta, Tb>, Cb, Cb> quad_form(
    const Eigen::Matrix<Ta, Ra, Ca>& A, const Eigen::Matrix<Tb, Rb, Cb>& B) {
  check_square("quad_form", "A", A);
  check_multiplicable("quad_form", "A", A, "B", B);
  return multiply(transpose(B), multiply(A, B));
}

/**
 * Return the quadratic form \f$ B^T A B \f$.
 *
 * @tparam Ta type of elements in the square matrix
 * @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
 * @tparam Ca number of columns in the square matrix, can be Eigen::Dynamic
 * @tparam Tb type of elements in the vector
 * @tparam Rb number of rows in the vector, can be Eigen::Dynamic
 *
 * @param A square matrix
 * @param B vector
 * @return The quadratic form (a scalar).
 * @throws std::invalid_argument if A is not square, or if A cannot be
 * multiplied by B
 */
template <typename Ta, int Ra, int Ca, typename Tb, int Rb,
          require_any_fvar_t<Ta, Tb>...>
inline return_type_t<Ta, Tb> quad_form(const Eigen::Matrix<Ta, Ra, Ca>& A,
                                       const Eigen::Matrix<Tb, Rb, 1>& B) {
  check_square("quad_form", "A", A);
  check_multiplicable("quad_form", "A", A, "B", B);
  return dot_product(B, multiply(A, B));
}

}  // namespace math
}  // namespace stan

#endif
<commit_msg>fix the header on develop<commit_after>#ifndef STAN_MATH_FWD_FUN_QUAD_FORM_HPP
#define STAN_MATH_FWD_FUN_QUAD_FORM_HPP

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/fun/multiply.hpp>
#include <stan/math/prim/fun/dot_product.hpp>

namespace stan {
namespace math {

/**
 * Return the quadratic form \f$ B^T A B \f$.
 *
 * Symmetry of the resulting matrix is not guaranteed due to numerical
 * precision.
 *
 * @tparam Ta type of elements in the square matrix
 * @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
 * @tparam Ca number of columns in the square matrix, can be Eigen::Dynamic
 * @tparam Tb type of elements in the second matrix
 * @tparam Rb number of rows in the second matrix, can be Eigen::Dynamic
 * @tparam Cb number of columns in the second matrix, can be Eigen::Dynamic
 *
 * @param A square matrix
 * @param B second matrix
 * @return The quadratic form, which is a symmetric matrix of size Cb.
 * @throws std::invalid_argument if A is not square, or if A cannot be
 * multiplied by B
 */
template <typename Ta, int Ra, int Ca, typename Tb, int Rb, int Cb,
          require_any_fvar_t<Ta, Tb>...>
inline Eigen::Matrix<return_type_t<Ta, Tb>, Cb, Cb> quad_form(
    const Eigen::Matrix<Ta, Ra, Ca>& A, const Eigen::Matrix<Tb, Rb, Cb>& B) {
  check_square("quad_form", "A", A);
  check_multiplicable("quad_form", "A", A, "B", B);
  return multiply(transpose(B), multiply(A, B));
}

/**
 * Return the quadratic form \f$ B^T A B \f$.
 *
 * @tparam Ta type of elements in the square matrix
 * @tparam Ra number of rows in the square matrix, can be Eigen::Dynamic
 * @tparam Ca number of columns in the square matrix, can be Eigen::Dynamic
 * @tparam Tb type of elements in the vector
 * @tparam Rb number of rows in the vector, can be Eigen::Dynamic
 *
 * @param A square matrix
 * @param B vector
 * @return The quadratic form (a scalar).
 * @throws std::invalid_argument if A is not square, or if A cannot be
 * multiplied by B
 */
template <typename Ta, int Ra, int Ca, typename Tb, int Rb,
          require_any_fvar_t<Ta, Tb>...>
inline return_type_t<Ta, Tb> quad_form(const Eigen::Matrix<Ta, Ra, Ca>& A,
                                       const Eigen::Matrix<Tb, Rb, 1>& B) {
  check_square("quad_form", "A", A);
  check_multiplicable("quad_form", "A", A, "B", B);
  return dot_product(B, multiply(A, B));
}

}  // namespace math
}  // namespace stan

#endif
<|endoftext|>


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

#include "iceoryx_utils/cxx/types.hpp"

#include <functional>
#include <new> // needed for placement new in the construct_value member function
#include <utility>

namespace iox
{
namespace cxx
{
/// @brief Helper struct which is used to signal an empty optional.
///         It is equivalent to no value.
struct nullopt_t
{
};

/// @brief Optional implementation from the C++17 standard with C++11. The
///         interface is analog to the C++17 standard and it can be used in
///         factory functions which can fail.
///
/// @code
///     #include "iceoryx_utils/cxx/optional.hpp"
///
///     cxx::optional<void*> SomeFactory() {
///         void *memory = malloc(1234);
///         if ( memory == nullptr )
///             return cxx::nullopt_t();
///         else
///             return cxx::make_optional<void*>(memory);
///     }
///
///     int main() {
///         auto var = SomeFactory();
///         // never forget the has_value call before working with an optional
///         if ( var.has_value() ) {
///             // do stuff with var
///         }
///     }
/// @endcode
template <typename T>
class optional
{
  public:
    /// @brief Creates an optional which has no value. If you access such an
    ///         optional via .value() or the arrow operator the behavior is
    ///         undefined.
    optional() noexcept;

    /// @brief Creates an optional which has no value. If you access such an
    ///         optional via .value() or the arrow operator the behavior is
    ///         undefined.
    optional(const nullopt_t&) noexcept;

    /// @brief Creates an optional by forwarding value to the constructor of
    ///         T. This optional has a value.
    /// @param[in] value rvalue of type T which will be moved into the optional
    optional(T&& value) noexcept;

    /// @brief The destructor will call the destructor of T if a value is set.
    ~optional() noexcept;

    /// @brief Constructs a value with the copy constructor if rhs has a value.
    ///         Otherwise it contains no value.
    /// @param[in] rhs source of the copy
    optional(const optional& rhs) noexcept;

    /// @brief Constructs a value with the move constructor if rhs has a value.
    ///         Otherwise it contains no value.
    /// @param[in] rhs source of the move
    optional(optional&& rhs) noexcept;

    /// @brief Copies an optional. If the optional has a value then the copy
    ///         assignment of that value is called. If the optional has no
    ///         value a new value is constructed with the copy constructor.
    /// @param[in] rhs source of the copy
    /// @return reference to the current optional
    optional& operator=(const optional& rhs) noexcept;

    /// @brief Moves an optional. If the optional has a value then the move
    ///         assignment of that value is called. If the optional has no
    ///         value a new value is constructed with the move constructor.
    /// @param[in] rhs source of the move
    /// @return reference to the current optional
    optional& operator=(optional&& rhs) noexcept;

    /// @brief If the optionals have values it compares these values by using
    ///         their comparision operator.
    /// @param[in] rhs value to which this optional should be compared to
    /// @return true if the contained values are equal, otherwise false
    constexpr bool operator==(const optional<T>& rhs) const noexcept;

    /// @brief Comparision with nullopt_t for easier unset optional comparision
    /// @return true if the optional is unset, otherwise false
    constexpr bool operator==(const nullopt_t&) const noexcept;

    /// @brief If the optionals have values it compares these values by using
    ///         their comparision operator.
    /// @param[in] rhs value to which this optional should be compared to
    /// @return true if the contained values are not equal, otherwise false
    constexpr bool operator!=(const optional<T>& rhs) const noexcept;

    /// @brief Comparision with nullopt_t for easier unset optional comparision
    /// @return true if the optional is set, otherwise false
    constexpr bool operator!=(const nullopt_t&) const noexcept;

    /// @brief Direct assignment of the underlying value. If the optional has no
    ///         value then a new T is constructed by forwarding the assignment to
    ///         T's constructor.
    ///        If the optional has a value the assignment operator of T is called.
    /// @param[in] value value to assign to the underlying optional value
    /// @return reference to the current optional
    template <typename U = T>
    typename std::enable_if<!std::is_same<U, optional<T>&>::value, optional>::type& operator=(U&& value) noexcept;

    /// @brief Returns a pointer to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return pointer of type const T to the underlying type
    const T* operator->() const noexcept;

    /// @brief Returns a reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return reference of type const T to the underlying type
    const T& operator*() const noexcept;

    /// @brief Returns a pointer to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return pointer of type T to the underlying type
    T* operator->() noexcept;

    /// @brief Returns a reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return reference of type T to the underlying type
    T& operator*() noexcept;

    /// @brief Will return true if the optional contains a value, otherwise false.
    /// @return true if optional contains a value, otherwise false
    constexpr explicit operator bool() const noexcept;

    /// @brief Will return true if the optional contains a value, otherwise false.
    /// @return true if optional contains a value, otherwise false
    constexpr bool has_value() const noexcept;

    /// @brief A new element is constructed by forwarding the arguments to the
    ///         constructor of T.
    ///         If the optional has a value then the destructor of T is called.
    /// @param[in] perfectly forwards args to the constructor of T to perform a placement
    ///             new
    /// @return reference to the underlying type
    template <typename... Targs>
    T& emplace(Targs&&... args) noexcept;

    /// @brief Calls the destructor of T if the optional has a value.
    ///         If the optional has no value, nothing happens. After that call
    ///         the optional has no more value.
    void reset() noexcept;

    /// @brief Returns a reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return reference to the underlying type
    T& value() & noexcept;

    /// @brief Returns a const reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return const reference to the underlying type
    const T& value() const & noexcept;

    /// @brief Returns a rvalue reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return rvalue reference to the underlying type
    T&& value() && noexcept;

    /// @brief Returns a const rvalue reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return const rvalue reference to the underlying type
    const T&& value() const && noexcept;

    /// @brief If the optional contains a value a copy of that value is returned,
    ///         otherwise the default_value is returned.
    /// @return copy of the underlying type if the optional has a value otherwise
    ///         a copy of default_value
    template <typename U>
    constexpr T value_or(U&& default_value) const noexcept;

    /// @brief calls the provided callable with the optional value as arguments
    ///         if the optional contains a value
    /// @param[in] callable which has T as argument
    /// @return reference to this
    optional& and_then(const std::function<void(T&)>& callable) noexcept;

    /// @brief calls the provided callable with the optional value as arguments
    ///         if the optional contains a value
    /// @param[in] callable which has T as argument
    /// @return reference to this
    const optional& and_then(const std::function<void(const T&)>& callable) const noexcept;

    /// @brief calls the provided callable if the optional does not contain a value
    /// @param[in] callable
    /// @return reference to this
    optional& or_else(const std::function<void()>& callable) noexcept;

    /// @brief calls the provided callable if the optional does not contain a value
    /// @param[in] callable
    /// @return reference to this
    const optional& or_else(const std::function<void()>& callable) const noexcept;

  private:
    alignas(alignof(T)) byte_t m_data[sizeof(T)];
    bool m_hasValue{false};

  private:
    template <typename... Targs>
    void construct_value(Targs&&... args) noexcept;
    void destruct_value() noexcept;
};

/// @brief Creates an optional which contains a value by forwarding the arguments
///         to the constructor of T.
/// @param[in] args arguments which will be perfectly forwarded to the constructor
///             of T
/// @return optional which contains T constructed with args
template <typename OptionalBaseType, typename... Targs>
optional<OptionalBaseType> make_optional(Targs&&... args) noexcept;
} // namespace cxx
} // namespace iox

#include "iceoryx_utils/internal/cxx/optional.inl"

#endif // IOX_UTILS_CXX_OPTIONAL_HPP
<commit_msg>iox-#132 adding constexpr nullopt according to the C++17 standard<commit_after>// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef IOX_UTILS_CXX_OPTIONAL_HPP
#define IOX_UTILS_CXX_OPTIONAL_HPP

#include "iceoryx_utils/cxx/types.hpp"

#include <functional>
#include <new> // needed for placement new in the construct_value member function
#include <utility>

namespace iox
{
namespace cxx
{
/// @brief Helper struct which is used to signal an empty optional.
///         It is equivalent to no value.
struct nullopt_t
{
};
constexpr nullopt_t nullopt = nullopt_t();

/// @brief Optional implementation from the C++17 standard with C++11. The
///         interface is analog to the C++17 standard and it can be used in
///         factory functions which can fail.
///
/// @code
///     #include "iceoryx_utils/cxx/optional.hpp"
///
///     cxx::optional<void*> SomeFactory() {
///         void *memory = malloc(1234);
///         if ( memory == nullptr )
///             return cxx::nullopt_t();
///         else
///             return cxx::make_optional<void*>(memory);
///     }
///
///     int main() {
///         auto var = SomeFactory();
///         // never forget the has_value call before working with an optional
///         if ( var.has_value() ) {
///             // do stuff with var
///         }
///     }
/// @endcode
template <typename T>
class optional
{
  public:
    /// @brief Creates an optional which has no value. If you access such an
    ///         optional via .value() or the arrow operator the behavior is
    ///         undefined.
    optional() noexcept;

    /// @brief Creates an optional which has no value. If you access such an
    ///         optional via .value() or the arrow operator the behavior is
    ///         undefined.
    optional(const nullopt_t&) noexcept;

    /// @brief Creates an optional by forwarding value to the constructor of
    ///         T. This optional has a value.
    /// @param[in] value rvalue of type T which will be moved into the optional
    optional(T&& value) noexcept;

    /// @brief The destructor will call the destructor of T if a value is set.
    ~optional() noexcept;

    /// @brief Constructs a value with the copy constructor if rhs has a value.
    ///         Otherwise it contains no value.
    /// @param[in] rhs source of the copy
    optional(const optional& rhs) noexcept;

    /// @brief Constructs a value with the move constructor if rhs has a value.
    ///         Otherwise it contains no value.
    /// @param[in] rhs source of the move
    optional(optional&& rhs) noexcept;

    /// @brief Copies an optional. If the optional has a value then the copy
    ///         assignment of that value is called. If the optional has no
    ///         value a new value is constructed with the copy constructor.
    /// @param[in] rhs source of the copy
    /// @return reference to the current optional
    optional& operator=(const optional& rhs) noexcept;

    /// @brief Moves an optional. If the optional has a value then the move
    ///         assignment of that value is called. If the optional has no
    ///         value a new value is constructed with the move constructor.
    /// @param[in] rhs source of the move
    /// @return reference to the current optional
    optional& operator=(optional&& rhs) noexcept;

    /// @brief If the optionals have values it compares these values by using
    ///         their comparision operator.
    /// @param[in] rhs value to which this optional should be compared to
    /// @return true if the contained values are equal, otherwise false
    constexpr bool operator==(const optional<T>& rhs) const noexcept;

    /// @brief Comparision with nullopt_t for easier unset optional comparision
    /// @return true if the optional is unset, otherwise false
    constexpr bool operator==(const nullopt_t&) const noexcept;

    /// @brief If the optionals have values it compares these values by using
    ///         their comparision operator.
    /// @param[in] rhs value to which this optional should be compared to
    /// @return true if the contained values are not equal, otherwise false
    constexpr bool operator!=(const optional<T>& rhs) const noexcept;

    /// @brief Comparision with nullopt_t for easier unset optional comparision
    /// @return true if the optional is set, otherwise false
    constexpr bool operator!=(const nullopt_t&) const noexcept;

    /// @brief Direct assignment of the underlying value. If the optional has no
    ///         value then a new T is constructed by forwarding the assignment to
    ///         T's constructor.
    ///        If the optional has a value the assignment operator of T is called.
    /// @param[in] value value to assign to the underlying optional value
    /// @return reference to the current optional
    template <typename U = T>
    typename std::enable_if<!std::is_same<U, optional<T>&>::value, optional>::type& operator=(U&& value) noexcept;

    /// @brief Returns a pointer to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return pointer of type const T to the underlying type
    const T* operator->() const noexcept;

    /// @brief Returns a reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return reference of type const T to the underlying type
    const T& operator*() const noexcept;

    /// @brief Returns a pointer to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return pointer of type T to the underlying type
    T* operator->() noexcept;

    /// @brief Returns a reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return reference of type T to the underlying type
    T& operator*() noexcept;

    /// @brief Will return true if the optional contains a value, otherwise false.
    /// @return true if optional contains a value, otherwise false
    constexpr explicit operator bool() const noexcept;

    /// @brief Will return true if the optional contains a value, otherwise false.
    /// @return true if optional contains a value, otherwise false
    constexpr bool has_value() const noexcept;

    /// @brief A new element is constructed by forwarding the arguments to the
    ///         constructor of T.
    ///         If the optional has a value then the destructor of T is called.
    /// @param[in] perfectly forwards args to the constructor of T to perform a placement
    ///             new
    /// @return reference to the underlying type
    template <typename... Targs>
    T& emplace(Targs&&... args) noexcept;

    /// @brief Calls the destructor of T if the optional has a value.
    ///         If the optional has no value, nothing happens. After that call
    ///         the optional has no more value.
    void reset() noexcept;

    /// @brief Returns a reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return reference to the underlying type
    T& value() & noexcept;

    /// @brief Returns a const reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return const reference to the underlying type
    const T& value() const& noexcept;

    /// @brief Returns a rvalue reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return rvalue reference to the underlying type
    T&& value() && noexcept;

    /// @brief Returns a const rvalue reference to the underlying value. If the optional has no
    ///         value the behavior is undefined. You need to verify that the
    ///         optional has a value by calling has_value() before using it.
    /// @return const rvalue reference to the underlying type
    const T&& value() const&& noexcept;

    /// @brief If the optional contains a value a copy of that value is returned,
    ///         otherwise the default_value is returned.
    /// @return copy of the underlying type if the optional has a value otherwise
    ///         a copy of default_value
    template <typename U>
    constexpr T value_or(U&& default_value) const noexcept;

    /// @brief calls the provided callable with the optional value as arguments
    ///         if the optional contains a value
    /// @param[in] callable which has T as argument
    /// @return reference to this
    optional& and_then(const std::function<void(T&)>& callable) noexcept;

    /// @brief calls the provided callable with the optional value as arguments
    ///         if the optional contains a value
    /// @param[in] callable which has T as argument
    /// @return reference to this
    const optional& and_then(const std::function<void(const T&)>& callable) const noexcept;

    /// @brief calls the provided callable if the optional does not contain a value
    /// @param[in] callable
    /// @return reference to this
    optional& or_else(const std::function<void()>& callable) noexcept;

    /// @brief calls the provided callable if the optional does not contain a value
    /// @param[in] callable
    /// @return reference to this
    const optional& or_else(const std::function<void()>& callable) const noexcept;

  private:
    alignas(alignof(T)) byte_t m_data[sizeof(T)];
    bool m_hasValue{false};

  private:
    template <typename... Targs>
    void construct_value(Targs&&... args) noexcept;
    void destruct_value() noexcept;
};

/// @brief Creates an optional which contains a value by forwarding the arguments
///         to the constructor of T.
/// @param[in] args arguments which will be perfectly forwarded to the constructor
///             of T
/// @return optional which contains T constructed with args
template <typename OptionalBaseType, typename... Targs>
optional<OptionalBaseType> make_optional(Targs&&... args) noexcept;
} // namespace cxx
} // namespace iox

#include "iceoryx_utils/internal/cxx/optional.inl"

#endif // IOX_UTILS_CXX_OPTIONAL_HPP
<|endoftext|>


<commit_before>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4      *
*                (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* This library is free software; you can redistribute it and/or modify it     *
* under the terms of the GNU Lesser General Public License as published by    *
* the Free Software Foundation; either version 2.1 of the License, or (at     *
* your option) any later version.                                             *
*                                                                             *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details.                                                           *
*                                                                             *
* You should have received a copy of the GNU Lesser General Public License    *
* along with this library; if not, write to the Free Software Foundation,     *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
*******************************************************************************
*                               SOFA :: Modules                               *
*                                                                             *
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: contact@sofa-framework.org                             *
******************************************************************************/
#include <sofa/component/forcefield/FastTetrahedralCorotationalForceField.inl>
#include <sofa/core/ObjectFactory.h>
#include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
#include <sofa/defaulttype/Vec3Types.h>

namespace sofa
{

namespace component
{

namespace forcefield
{

using namespace sofa::defaulttype;

SOFA_DECL_CLASS(FastTetrahedralCorotationalForceField)

using namespace sofa::defaulttype;

// Register in the Factory
int FastTetrahedralCorotationalForceFieldClass = core::RegisterObject("Fast Corotational Tetrahedral Mesh")
#ifndef SOFA_FLOAT
        .add< FastTetrahedralCorotationalForceField<Vec3dTypes> >()
#endif
#ifndef SOFA_DOUBLE
        .add< FastTetrahedralCorotationalForceField<Vec3fTypes> >()
#endif
        ;

#ifndef SOFA_FLOAT
template class  FastTetrahedralCorotationalForceField<Vec3dTypes>;
#endif
#ifndef SOFA_DOUBLE
template class  FastTetrahedralCorotationalForceField<Vec3fTypes>;
#endif

} // namespace forcefield

} // namespace Components

} // namespace Sofa

<commit_msg>r5714/sofa-dev : FIX: forget macro for windows dll export.<commit_after>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4      *
*                (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* This library is free software; you can redistribute it and/or modify it     *
* under the terms of the GNU Lesser General Public License as published by    *
* the Free Software Foundation; either version 2.1 of the License, or (at     *
* your option) any later version.                                             *
*                                                                             *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details.                                                           *
*                                                                             *
* You should have received a copy of the GNU Lesser General Public License    *
* along with this library; if not, write to the Free Software Foundation,     *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
*******************************************************************************
*                               SOFA :: Modules                               *
*                                                                             *
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: contact@sofa-framework.org                             *
******************************************************************************/
#include <sofa/component/forcefield/FastTetrahedralCorotationalForceField.inl>
#include <sofa/core/ObjectFactory.h>
#include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
#include <sofa/defaulttype/Vec3Types.h>

namespace sofa
{

namespace component
{

namespace forcefield
{

using namespace sofa::defaulttype;

SOFA_DECL_CLASS(FastTetrahedralCorotationalForceField)

using namespace sofa::defaulttype;

// Register in the Factory
int FastTetrahedralCorotationalForceFieldClass = core::RegisterObject("Fast Corotational Tetrahedral Mesh")
#ifndef SOFA_FLOAT
        .add< FastTetrahedralCorotationalForceField<Vec3dTypes> >()
#endif
#ifndef SOFA_DOUBLE
        .add< FastTetrahedralCorotationalForceField<Vec3fTypes> >()
#endif
        ;

#ifndef SOFA_FLOAT
template class SOFA_COMPONENT_FORCEFIELD_API FastTetrahedralCorotationalForceField<Vec3dTypes>;
#endif
#ifndef SOFA_DOUBLE
template class SOFA_COMPONENT_FORCEFIELD_API FastTetrahedralCorotationalForceField<Vec3fTypes>;
#endif

} // namespace forcefield

} // namespace Components

} // namespace Sofa

<|endoftext|>