qq_43096031 2021-05-16 11:01 采纳率: 100%
浏览 36
已采纳

帮我看看这个c++代码怎么用

导师给我发了一个文件夹,说是可以实现GEM通信的c++代码,但是没有使用说明。下图是其中一个cpp文件的所有内容。

#define BEE_BUILD_DLL

#include "BS2ItemHeader.h"
#include "BS2UInt4.h"
#include "BS2Stream.h"
#include "BS2Array.h"
#include "BS2Interpreter.h"

//-----------------------------------------------------------------------------
// Constructor/Destructor
//-----------------------------------------------------------------------------
BS2UInt4::BS2UInt4(const BS2UInt4& rhs) : BS2Atom(rhs)
{
    TRACE_FUNCTION(TRL_CONSTRUCT, "BS2UInt4::BS2UInt4");
    BS2Assert(rhs.m_t == ATOM_UINT4);
}

//-----------------------------------------------------------------------------
BS2UInt4::BS2UInt4(BYTE * data, size_t len)
{
    TRACE_FUNCTION(TRL_CONSTRUCT, "BS2UInt4::BS2UInt4");

    if (len >= sizeof(UINT))
    {
        this->setStreamData(data);
    }
    else
    {
        initNull();
    }
}

//-----------------------------------------------------------------------------
// Copy
//-----------------------------------------------------------------------------
const BS2UInt4& BS2UInt4::operator=(const BS2UInt4& rhs)
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::operator=");
    BS2Assert(m_t == ATOM_UINT4 && rhs.m_t == ATOM_UINT4);
    if (this == &rhs)
        return *this;
    this->copy((BS2Atom&)rhs);
    return *this;
}

//-----------------------------------------------------------------------------
const BS2UInt4& BS2UInt4::operator=(UINT data)
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::operator=");
    initv(data);
    return *this;
}

//-----------------------------------------------------------------------------
// set SECS-II data
//-----------------------------------------------------------------------------
void BS2UInt4::set(BS2IStream& buf)
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::set");

    BS2ItemHeader itemHeader;
    buf >> itemHeader;
    initv((UINT)0);      // set type, qty and size
    if (itemHeader.dataLength() == sizeof(UINT))
    {
        buf >> m._ui;
    }
    else
        m_q = 0;     // data is nothing
}

//-----------------------------------------------------------------------------
// set value from stream buf
//-----------------------------------------------------------------------------
void BS2UInt4::setStreamData(BYTE * buf)
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::setStreamData");

    initv((UINT)((*buf << 24) + (*(buf + 1) << 16) + (*(buf + 2) << 8) +
                 *(buf + 3)));
}

//-----------------------------------------------------------------------------
// get SECS-II data
//-----------------------------------------------------------------------------
void BS2UInt4::get(BS2OStream& buf) const
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::get");
    BS2Assert(m_t == ATOM_UINT4);

    int len = haveData() ? size() : 0;
    BS2ItemHeader itemHeader(ATOM_UINT4, 1, len);
    buf << itemHeader;
    if (len > 0)
        buf << m._ui;
}

//-----------------------------------------------------------------------------
// get value in stream buf
//-----------------------------------------------------------------------------
void BS2UInt4::getStreamData(BYTE * buf) const
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::getStreamData");
    if (! haveData())
        return;

    *(buf + 0) = (m._ui >> 24) & 0xFF;
    *(buf + 1) = (m._ui >> 16) & 0xFF;
    *(buf + 2) = (m._ui >> 8) & 0xFF;
    *(buf + 3) = m._ui & 0xFF;

}

//-----------------------------------------------------------------------------
// Factory
//-----------------------------------------------------------------------------
BS2Atom * BS2UInt4::factory(BYTE * data, size_t len) const
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::factory");
    if (len > sizeof(UINT))
    {
        BS2UInt4Array * clone = new BS2UInt4Array(data, len);
        return (BS2Atom *)clone;
    }
    else
    {
        BS2UInt4 * clone = new BS2UInt4(data, len);
        return (BS2Atom *)clone;
    }
}

//-----------------------------------------------------------------------------
BS2Atom * BS2UInt4::replicate() const
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::replicate");

    BS2UInt4 * replica = new BS2UInt4;
    *replica = *this;
    return (BS2Atom *)replica;
}

//-----------------------------------------------------------------------------
// IO Stream
//-----------------------------------------------------------------------------
BS2IStream& operator>>(BS2IStream& is, BS2UInt4& atom)
{
    TRACE_FUNCTION(TRL_LOW, "BS2IStream::operator>>(BS2UInt4&)");
    atom.set(is);
    return is;
}

BS2OStream& operator<<(BS2OStream& os, BS2UInt4& atom)
{
    TRACE_FUNCTION(TRL_LOW, "BS2OStream::operator<<(BS2UInt4&)");
    atom.get(os);
    return os;
}

//-----------------------------------------------------------------------------
// Print
//-----------------------------------------------------------------------------
void BS2UInt4::print(BS2InterpBase * interp) const
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::print");

    if (haveData())
        interp->printf(interp->print_xml() ? _TX(" %u ") : _TX(" %u"), m._ui);
    else
        interp->print(interp->print_xml() ? _TX(" ") : _TX(" {}"));
}

//-----------------------------------------------------------------------------
// Dump
//-----------------------------------------------------------------------------
void BS2UInt4::dump() const
{
    TRACE_FUNCTION(TRL_LOW, "BS2UInt4::dump");
    if (haveData())
        b_printf(_TX(" %u"), m._ui);
    else
        b_printf(_TX(" {}"));
}

//
// *** End of File ***

整个文件夹中还有

这么多文件……

 

没有使用说明,令人一头雾水,求帮忙看看具体使用方法。

还有什么信息需要补充的请在评论告诉我,我会第一时间回复。

  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2021-05-16 11:06
    关注

    你检索一下不是.h和.cpp后缀的文件。这个应该是个动态库源码吧,通过这个动态库你可以实现GEM通信。你只要找到动态库的输出函数,弄明白函数干啥的,参数是什么就行了。具体过程代码可以先不熟悉

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备