Message.h

Go to the documentation of this file.
00001 /*
00002 * (c) Onix Solutions.
00003 */
00004 
00005 #ifndef Message_h
00006 #define Message_h
00007 
00008 #include <iosfwd>
00009 #include <string>
00010 
00011 #include "FIXEngineDefines.h"
00012 #include "EngineException.h"
00013 #include "Session.h"
00014 #include "FIXEngine.h"
00015 
00016 namespace FIXForge{
00017 namespace FIX{
00018 
00019 namespace FAST_1_1{
00020     class Encoder;
00021     class Decoder;
00022 };
00023 
00024 class FF_API Group;
00025 
00026 /// FIX Message.
00027 class FF_API Message{
00028 public: 
00029     /// Validation options.
00030     enum ValidationOptions
00031     {
00032         CHECK_LENGTH = 2,
00033         CHECK_CHECK_SUM = 4
00034     };
00035 
00036     /// Constructs the FIX message object from the native (tag=value) representation.
00037     Message(const std::string& nativeFixMessage);
00038 
00039     /**
00040      * Constructs the FIX message object from the native (tag=value) representation.
00041      *
00042      * @param nativeFixMessage The native (raw) FIX message in the 'tag=value' format.
00043      * @param validationOptions Several ValidationOptions values can be joined using '|'.
00044      */
00045     Message(const std::string& nativeFixMessage, int validationOptions);
00046 
00047     /// Constructor
00048     Message(const std::string& type, Version version);
00049 
00050     /// Constructor
00051     Message(const char* type, Version version);
00052 
00053     /// Copy Constructor.
00054     Message(const Message& msg);
00055 
00056     /// Destructor.
00057     ~Message();
00058 
00059     bool operator == (const Message& rh);
00060     bool operator != (const Message& rh);
00061 
00062     friend FF_API std::ostream& operator<< (std::ostream& os, const Message& msg);
00063 
00064     /// Updates the BodyLength (9) and CheckSum (10) fields.
00065     void updateCheckSum();
00066     
00067     /// Returns 'true' if the message contains the field with the given tag, otherwise - 'false'.
00068     bool contain(int tag) const;
00069 
00070     /// Returns the field value as a string.
00071     const std::string& get(int tag) const;
00072 
00073     /**
00074      * Returns the field value as a floating-point number.
00075      *
00076      * @warning Return 0 if the field value is absent.
00077      */
00078     double getDouble(int tag) const;
00079 
00080     /**
00081      * Returns the repeating group. 
00082      *
00083      * @param numberOfInstancesTag Tag number of the field that defines the number of instances in this repeating group (the NoXXX field). 
00084      *
00085      * @warning To avoid memory leaks call Group::release() when the Group object is not used anymore.
00086      */
00087     Group* getGroup(int numberOfInstancesTag) const;        
00088 
00089     /**
00090      * Returns the field value as an integer.
00091      * 
00092      * @warning Return 0 if the field value is absent.
00093      */
00094     int getInteger(int tag) const;      
00095 
00096     /// Returns the assigned value used to identify firm sending message (SenderCompID (49) field value).   
00097     const std::string& getSenderCompID() const;
00098 
00099     /// Returns the message sequence number (the MsgSeqNum (tag=34) field value).
00100     int getSeqNum() const;  
00101 
00102     /// Returns the assigned value used to identify receiving firm (TargetCompID(56) field value).
00103     const std::string& getTargetCompID() const;
00104 
00105     /// Returns the message type (MsgType(35) field value).
00106     const std::string& getType() const;     
00107 
00108     /// Returns the Financial Interface eXchange (FIX) protocol version.
00109     Version getVersion() const;
00110 
00111     /// Returns true if the given flag is present and it equals to "Y", otherwise false.
00112     bool hasFlag(int tag) const;
00113 
00114     /// Removes the field.
00115     bool remove(int tag);
00116 
00117     /// Sets the integer field value.
00118     bool set(int tag, int value);
00119 
00120     /// Sets the double field value.
00121     bool set(int tag, double value);
00122 
00123     /// Sets the string field value.
00124     bool set(int tag, const std::string& value);
00125 
00126     /**
00127     * Sets the given flag to "Y" or "N".
00128     *
00129     * @return "true" if the flag had value before, otherwise "false" (the flag was inserted into the message).
00130     */
00131     void setFlag(int tag, bool value);
00132 
00133     /**
00134      * Creates a new repeating group or changes the number of instances in the existing repeatign group. 
00135      *
00136      * @param numberOfInstancesTag Tag number of the field that defines the number of instances in this repeating group (the NoXXX field). 
00137      *
00138      * @param numberOfIntances Number of instances in the repeating group. 
00139      */
00140     Group* setGroup(int numberOfInstancesTag, int numberOfIntances);  
00141         
00142     /// Sets the assigned value used to identify firm sending message (SenderCompID (49) field value).  
00143     void setSenderCompID(const std::string& value);
00144 
00145     /// Sets the message sequence number (the MsgSeqNum (tag=34) field value).
00146     void setSeqNum(int value);      
00147 
00148     /// Sets the assigned value used to identify receiving firm (TargetCompID(56) field value).
00149     void setTargetCompID(const std::string& value);
00150     
00151     /// Returns the &lt;tag&gt;=&lt;value&gt; string representation of the message using the standard FIX delimiter ('0x01').
00152     const std::string& toString() const;
00153 
00154     /// Returns the &lt;tag&gt;=&lt;value&gt; string representation of the message using the given delimiter.
00155     const std::string& toString(char delimiter) const;
00156 
00157     /// Format of the message string representation.
00158     enum FORMAT{
00159         TAG_NUMBER = 1,
00160         TAG_NAME = 2
00161     };
00162 
00163     /**
00164      * Returns the &lt;tag&gt;=&lt;value&gt; string representation of the message using the given format and delimiter.
00165      *
00166      * @param format Format of the string representation, several FORMAT values could be joined using logical 'or' operator.
00167      * @param delimiter Fields delimiter.
00168      *
00169      * @see FORMAT
00170      */ 
00171     const std::string& toString(int format, char delimiter = ' ') const;
00172     
00173     /// Validates the message.
00174     void validate() const;
00175 
00176 private:            
00177     Message(void* native, bool isOwner = false);    
00178     Message& operator = (const Message&);
00179 
00180     void init(const char* type, Version version);
00181 
00182     struct Impl;
00183     Impl* impl_;
00184 
00185     void* native_;
00186 
00187     friend class Session;
00188     friend struct Session::Impl;
00189     friend struct Engine::Impl; 
00190     friend class FAST_1_1::Encoder;
00191     friend class FAST_1_1::Decoder; 
00192 };
00193 
00194 }};
00195 
00196 #endif

Generated on Thu Sep 25 18:51:45 2008 for FIXForge C++ FIX Engine by  doxygen 1.5.2