首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何对设置进行硬编码

如何对设置进行硬编码
EN

Stack Overflow用户
提问于 2012-11-20 02:11:47
回答 2查看 334关注 0票数 0

如何对发起方和接受方的设置进行硬编码,以便不需要外部设置文件?

这就是我到目前为止所尝试的:

代码语言:javascript
运行
复制
FIX::SessionSettings serverSettings;
FIX::Dictionary serverDictionary;

serverDictionary.setString("BeginString", "FIX.4.4");
serverDictionary.setString("UseDataDictionary", "Y");
serverDictionary.setString("DataDictionary", "../../../spec/FIX.4.4.xml");
serverDictionary.setString("SenderCompID", "SRVR");
serverDictionary.setString("TargetCompID", "CLNT");
serverDictionary.setString("SocketAcceptHost", "localhost");
serverDictionary.setLong("SocketAcceptPort", 2024);

FIX::SessionID serverSessionID;
serverSettings.set(serverSessionID, serverDictionary);

Server server; // Extends FIX::Application

FIX::FileStoreFactory serverStoreFactory("server/fileStore/");
FIX::FileLogFactory serverLogFactory("server/logs/");

FIX::SocketAcceptor acceptor(server, serverStoreFactory, serverSettings, serverLogFactory);

我认为我走在正确的道路上,但我得到了这个错误:Configuration failed: BeginString must be FIX.4.0 to FIX.4.4 or FIXT.1.1

有什么想法吗?

EN

回答 2

Stack Overflow用户

发布于 2012-11-20 02:16:42

它与"FIX.4.4“的值无关,它是关于setString的定义,即;

void Dictionary::setString( const std::string& key,const std::string& value )

它通过引用获取这些字符串,并将其传递给一个临时变量,当setString尝试访问该值时,该变量会被释放。因为你不能改变你需要做的函数定义;

代码语言:javascript
运行
复制
std::string key = "current key";
std::string value = "current value";
serverDictionary.setString(key, value);

对于所有setString调用,这样才能正常工作。至少对我来说,这会阻止我走这条路。

票数 1
EN

Stack Overflow用户

发布于 2012-11-21 02:27:32

经过很多努力,我终于把这件事做好了。以下是在接受器中硬编码设置的功能代码,也可以应用于启动器中:

代码语言:javascript
运行
复制
try {
    FIX::SessionSettings serverSettings;
    FIX::Dictionary serverDictionary;

    serverDictionary.setString("ConnectionType", "acceptor");
    serverDictionary.setString("DataDictionary", "FIX.4.4.xml");
    serverDictionary.setString("StartTime", "00:00:00");
    serverDictionary.setString("EndTime", "00:00:00");
    serverDictionary.setString("SocketAcceptHost", "localhost");
    serverDictionary.setString("SocketAcceptPort", "2024");

    FIX::SessionID serverSessionID("FIX.4.4", "SRVR", "CLNT");
    serverSettings.set(serverSessionID, serverDictionary);

    Server server;
    FIX::FileStoreFactory serverStoreFactory("server/fileStore/");
    FIX::FileLogFactory serverLogFactory("server/logs/");
    FIX::SocketAcceptor acceptor(server, serverStoreFactory, serverSettings, serverLogFactory);
    acceptor.start();
    // do something
    acceptor.stop();

    return 0;
} catch (FIX::ConfigError& e) {
    std::cout << e.what() << std::endl;
    return 1;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13459627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档