Re: [Quickfix-developers] Field name to number conversion
Brought to you by:
orenmnero
|
From: Mike G. <mg...@co...> - 2008-08-30 16:47:38
|
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/ |