Re: [Quickfix-developers] Field name to number conversion
Brought to you by:
orenmnero
|
From: George H. <ge...@so...> - 2008-09-02 23:08:36
|
Mike,
After reading your message I felt like a neanderthal man watching the
space shuttle take off (and with the same level of understanding).
I did not even realize it could be done this way.
So, many thanks for this very cool piece of code.
This was my approach:
Given a file of Field names that I am interested in:
1 #
2 #
3 # @(#) $Id: system.tgs xxxx 2008-08-22 04:29:18Z svn $
4 # @(#) Test Field Tags
5 #
6 ClOrdID # 11
7 MsgType # 35
8 OrderQty # 38
9 OrdType # 40
10 Price # 44
11 Side # 54
12 Symbol # 55
I create a string-to-field number using XML reader against the Data
Dictionary.
This means that the Data Dictionary must be used.
In the code I do:
In global.h
//
// Simple class to keep track of names and tags
class Tags2Nums {
public:
std::string name;
int number;
std::string strNumber;
int header;
int trailer;
int required;
};
std::string lmsgstr;
//
// The vector below is used to keep track on the name <-> number
relationship
vector<Tags2Nums> tagVector;
In Application.cpp
for( unsigned int ui=0; ui < tagVector.size(); ui++ ) {
if( !tagVector[ui].header ) {
//
// Get the text of the message
lmsgstr = message.getField(tagVector[ui].number);
std::cerr << "\t" << tagVector[ui].name << ":" <<
"[" << tagVector[ui].number << "] " << lmsgstr <<
std::endl;
} else {
// Header tags are processed differently
printf("\tFound Header Tag\n");
}
}
Does this make sense or am I really on the wrong track here?
-George
On Aug 30, 2008, at 12:47 PM, Mike Gatny wrote:
> QuickFIX Documentation: http://www.quickfixengine.org/quickfix/doc/html/index.html
> QuickFIX Support: http://www.quickfixengine.org/services.html
>
> George,
>
> If I understand correctly, you need a lookup of field name (as string)
> -> field number (as int)?
>
> What about leveraging the code generator? I.e. create a stylesheet in
> the spec/ dir:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output method="text" encoding="UTF-8"/>
>
> <xsl:template match="text()"/>
>
> <xsl:template match="/">/* -*- C++ -*- */
> <xsl:copy-of select="document('COPYRIGHT.xml')"/>
> #ifndef FIX_FIELDNAMESTONUMBERS_H
> #define FIX_FIELDNAMESTONUMBERS_H
>
> #include <map>
> #include <string>
>
> class FieldNamesToNumbers
> {
> private:
> std::map<std::string,int> fieldNamesToNumbers_;
>
> public:
>
> int get(const std::string & fieldName)
> {
> return fieldNamesToNumbers_[fieldName];
> }
>
> FieldNamesToNumbers()
> {
> <xsl:apply-templates/>
> }
> };
>
> #endif
> </xsl:template>
> <xsl:template match="fields/field">
> fieldNamesToNumbers_["<xsl:value-of select="@name"/>"] =
> <xsl:value-of
> select="@number"/>;
> </xsl:template>
> </xsl:stylesheet>
>
> Run this command (or better yet, add it to spec/generate_c++.sh):
> xsltproc -o ../src/C++/FieldNamesToNumbers.h FieldNamesToNumbers.xsl
> FIX44.xml
>
> And in your code:
>
> #include <quickfix/FieldNamesToNumbers.h>
> FieldNamesToNumbers conv;
> /* ... */
> message.getField(conv.get(field_name_1_from_config_file));
> message.getField(conv.get(field_name_2_from_config_file));
>
> Now you'll always be up-to-date with the lastest data dictionary.
> Simply re-run the generator if it changes.
>
> --
> Mike Gatny
> Connamara Systems, LLC
> http://www.connamara.com/
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win
> great prizes
> Grand prize is a trip for two to an Open Source event anywhere in
> the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Quickfix-developers mailing list
> Qui...@li...
> https://lists.sourceforge.net/lists/listinfo/quickfix-developers
|