// Copyright (C) 2010-2016  MarketFactory, Inc. All Rights Reserved.
//================================================================================
//   This file is auto-generated; DO NOT EDIT!
//================================================================================

#include <API/Clients/CPP/Proto/OrderType.h>

#include <iostream>
#include <cassert>
#include <stdexcept>
#include <string.h>
#include <sstream>

namespace MFAPI {

using namespace std;

// OrderType {

    bool OrderType::_initialized = false;

    const char* OrderType::Name = "OrderType";

    const unsigned int OrderType::_maxValue = 9;
    const unsigned int OrderType::_nbValues = 8;

    const char* OrderType::_names[9];
    unsigned char OrderType::_toIndex[9];
    OrderType::Type OrderType::_fromIndex[8];

    void OrderType::initializeEnum()
    {
        const char* dummy = 0;
        std::fill_n(_names, 9, dummy);
        _names[MARKET] = "MARKET";
        _names[LIMIT] = "LIMIT";
        _names[STOP] = "STOP";
        _names[STOPLIMIT] = "STOPLIMIT";
        _names[MARKETLIMIT] = "MARKETLIMIT";
        _names[PREVIOUSLY_QUOTED] = "PREVIOUSLY_QUOTED";
        _names[VWAP_SWEEP] = "VWAP_SWEEP";
        _names[PREVIOUSLY_QUOTED_AMT_TIER] = "PREVIOUSLY_QUOTED_AMT_TIER";

        unsigned char idx = 0;
        _toIndex[OrderType::MARKET] = idx;
        _fromIndex[idx] = OrderType::MARKET;
        idx++;
        _toIndex[OrderType::LIMIT] = idx;
        _fromIndex[idx] = OrderType::LIMIT;
        idx++;
        _toIndex[OrderType::STOP] = idx;
        _fromIndex[idx] = OrderType::STOP;
        idx++;
        _toIndex[OrderType::STOPLIMIT] = idx;
        _fromIndex[idx] = OrderType::STOPLIMIT;
        idx++;
        _toIndex[OrderType::MARKETLIMIT] = idx;
        _fromIndex[idx] = OrderType::MARKETLIMIT;
        idx++;
        _toIndex[OrderType::PREVIOUSLY_QUOTED] = idx;
        _fromIndex[idx] = OrderType::PREVIOUSLY_QUOTED;
        idx++;
        _toIndex[OrderType::VWAP_SWEEP] = idx;
        _fromIndex[idx] = OrderType::VWAP_SWEEP;
        idx++;
        _toIndex[OrderType::PREVIOUSLY_QUOTED_AMT_TIER] = idx;
        _fromIndex[idx] = OrderType::PREVIOUSLY_QUOTED_AMT_TIER;
        idx++;

        _initialized = true;
    }

    void OrderType::finalizeEnum()
    {
    }

    bool OrderType::isValid( unsigned char iv )
    {
        assert(_initialized);
        return OrderType::_names[iv] != 0;
    }

    unsigned char OrderType::toValue( OrderType::Type iv )
    {
        return static_cast<unsigned char>(iv);
    }

    OrderType::Type OrderType::fromValue( unsigned char iv )
    {
        if ( !isValid(iv) ) {
            std::ostringstream oss;
            oss << "Invalid value for OrderType: " << iv << std::ends;
            throw std::invalid_argument(oss.str().c_str());
        }
        return Type(iv);
    }

    const char* OrderType::toString( unsigned char iv )
    {
        assert(_initialized);
        return OrderType::_names[iv];
    }

    OrderType::Type OrderType::fromString( const char* s )
    {
        assert(_initialized);
        if ( s == 0 ) {
            throw std::invalid_argument("Empty string for converting to enum OrderType.");
        }
        for ( int ii = 0; ii < 9; ++ii ) {
            if ( _names[ii] != 0 && strcmp(s, _names[ii]) == 0 ) {
                return Type(ii);
            }
        }
        std::ostringstream oss;
        oss << "Invalid string '" << s << "' for converting to enum OrderType." << std::ends;
        throw std::invalid_argument(oss.str().c_str());
    }

    unsigned char OrderType::toIndex( Type en )
    {
        return _toIndex[en];
    }

    OrderType::Type OrderType::fromIndex( unsigned char index )
    {
        return _fromIndex[index];
    }

    std::ostream& operator<<( std::ostream& os, OrderType::Type en )
    {
        os << OrderType::toString(en);
        return os;
    }

// }
} // MFAPI

/*
Brought to you by
/opt/atlassian/bamboo-agent/xml-data/build-dir/GAT-GWY-B3/Messaging/main.py --root /opt/atlassian/bamboo-agent/xml-data/build-dir/GAT-GWY-B3 --commit-date 2016-12-06T18:11:31.205-05:00 --revision 19c07f7ab2ea0612a19fbcabdd4a54e242830e7d --branch master --generated_directory /opt/atlassian/bamboo-agent/xml-data/build-dir/GAT-GWY-B3/build/rh7_3.13.0/release/intel64/generated/Python -o /opt/atlassian/bamboo-agent/xml-data/build-dir/GAT-GWY-B3/build/rh7_3.13.0/release/intel64/generated/API/Clients/CPP/Proto -i /opt/atlassian/bamboo-agent/xml-data/build-dir/GAT-GWY-B3/Messaging/MFProtocol --namespace=MFAPI cppapi /opt/atlassian/bamboo-agent/xml-data/build-dir/GAT-GWY-B3/Messaging/MFProtocol.proto.3130 /opt/atlassian/bamboo-agent/xml-data/build-dir/GAT-GWY-B3/Messaging/MFObsolete.proto.3130 
*/
