text:
#include <guillotine/typed_message.h>

#include <typeinfo>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/lexical_cast.hpp>

using std::string;
using std::list;

namespace guillotine {
    namespace typed {

        template <typename T>
        bool fillf ( T &dest, const yaml::message &m,
                const string &field, bool opt = false) {
            parse_error pe;
            if (m[field].empty()) {
                if (opt) {
                    return false;
                } else {
                    pe.msg.reason = error::bad_field;
                    pe.msg.field_name = field;
                    pe.msg.info = string("required field missing in message ") + m.name();
                    throw pe;
                }
            }
            try {
                dest = boost::lexical_cast<T> (
                        boost::any_cast<string> (
                            m[field].value()));
            } catch ( std::exception &e ) {
                pe.msg.reason = error::bad_field;
                pe.msg.field_name = field;
                pe.msg.info = string("incorrect field type (expected ") + typeid(T()).name() +
                    string(") in field ") + field + string(" of message ") + m.name();
                throw pe;
            }
            return true;
        }

        template <typename T>
        bool fillf ( list<T> &dest, const yaml::message &m,
                const string &field, bool opt = false ) {
            const string *s;
            const list<yaml::node> *ss;
            parse_error pe;
            if (m[field].empty()) {
                if (opt) {
                    return false;
                } else {
                    pe.msg.reason = error::bad_field;
                    pe.msg.field_name = field;
                    pe.msg.info = string("required field missing in message ") + m.name();
                    throw pe;
                }
            }
            try {
                if ( (s = boost::any_cast<T>(&(m[field].value()))) ) {
                    dest.push_back(boost::lexical_cast<T>(*s));
                } else if ( (ss = boost::any_cast<list<yaml::node> >(&(m[field].value()))) ) {
                    for (list<yaml::node>::const_iterator i = ss->begin(); i != ss->end(); ++i)
                        dest.push_back(boost::lexical_cast<T>(i->as<string>()));
                }
            }
            catch ( std::exception &e ) {
                pe.msg.reason = error::bad_field;
                pe.msg.field_name = field;
                pe.msg.info = string("incorrect field type in message ") + m.name();
                throw pe;
            }
            return true;
        }

        message get_message ( const yaml::message &raw, int clientId ) {
            parse_error pe;

            if (raw.name().empty()) {
                pe.msg.reason = error::bad_message;
                pe.msg.info = "No message type specified";
                throw pe;
            }

            if (raw.name() == "connect") {
                connect c;
                fillf(c.account, raw, "account");
                fillf(c.name, raw, "name", true);
                fillf(c.password, raw, "password", true);
                fillf(c.listenToBcast, raw, "listenToBcast", true)? NULL : c.listenToBcast = 0;
                c.clientId = clientId;
                return message(c);
            }

            if (raw.name() == "trade") {
                trade t;
                fillf(t.symbol, raw, "symbol");
                fillf(t.aggr, raw, "aggr");
                if (!fillf(t.orderID, raw, "orderID", true)) {
                  t.orderID = -1;
                }
                fillf(t.qty, raw, "qty");
                if (!fillf(t.short_mark, raw, "short-mark", true)) {
                  t.short_mark = trade::unknown;
                }
                t.clientId = clientId;
                return message(t);
            }

            if (raw.name() == "stop") {
                stop s;
                s.all = !fillf(s.symbols, raw, "symbol", true);
                s.clientId = clientId;
                return message(s);
            }

            if (raw.name() == "halt") {
                halt s;
                s.all = !fillf(s.symbols, raw, "symbol", true);
                s.clientId = clientId;
                return message(s);
            }

            if (raw.name() == "resume") {
                resume s;
                s.all = !fillf(s.symbols, raw, "symbol", true);
                s.clientId = clientId;
                return message(s);
            }

            if (raw.name() == "status") {
                status s;
                s.all = !fillf(s.symbols, raw, "symbol", true);
                s.clientId = clientId;
                return message(s);
            }

            if (raw.name() == "server") {
                server s;
                fillf(s.name, raw, "name");
                fillf(s.symbols, raw, "symbol");
                s.clientId = clientId;
                return message(s);
            }

            if (raw.name() == "fill") {
                fill s;

                string tmstr, liqstr;
                fillf(tmstr, raw, "time");
                fillf(liqstr, raw, "liquidity", true);
                size_t dot = tmstr.find('.');
                try {
                    int sec = 0, usec = 0;
                    sec = boost::lexical_cast<int>(tmstr.substr(0, dot));
                    if (dot != string::npos)
                        usec = boost::lexical_cast<int>(tmstr.substr(dot+1, tmstr.size()));
                    s.time_sec = sec;
                    s.time_usec = usec;
                } catch (...) {
                    parse_error pe;
                    pe.msg.reason = error::bad_field;
                    pe.msg.field_name = "time";
                    pe.msg.info = string("required field missing in message fill");
                    throw pe;
                }

                if      (liqstr == "A") s.liquidity = fill::add;
                else if (liqstr == "R") s.liquidity = fill::remove;
                     else s.liquidity = fill::other;

                long orderID = -1;
                fillf(orderID, raw, "orderID", true);
                s.orderID = orderID;
                string strat = "U";
                fillf(strat, raw, "strat", true);
                s.strat = strat;
                fillf(s.symbol, raw, "symbol");
                fillf(s.exchange, raw, "exchange");
                fillf(s.qtyLeft, raw, "qtyLeft");
                fillf(s.fill_size, raw, "fill-size");
                fillf(s.fill_price, raw, "fill-price");
                s.clientId = clientId;

                return message(s);
            }

            if (raw.name() == "info") {
                info s;
                string tmstr;
                fillf(tmstr, raw, "time");
                size_t dot = tmstr.find('.');
                try {
                    int sec = 0, usec = 0;
                    sec = boost::lexical_cast<int>(tmstr.substr(0, dot));
                    if (dot != string::npos)
                        usec = boost::lexical_cast<int>(tmstr.substr(dot+1, tmstr.size()));
                    s.time_sec = sec;
                    s.time_usec = usec;
                } catch (...) {
                    parse_error pe;
                    pe.msg.reason = error::bad_field;
                    pe.msg.field_name = "time";
                    pe.msg.info = string("required field missing in message info");
                    throw pe;
                }
                fillf(s.symbol, raw, "symbol");
                fillf(s.position, raw, "position");
                fillf(s.qtyLeft, raw, "qtyLeft");
                fillf(s.locates, raw, "locates");
                fillf(s.aggr, raw, "aggr");
                fillf(s.halt, raw, "halt");
                if (!fillf(s.bid, raw, "bid", true)) s.bid = 0.0;
                if (!fillf(s.ask, raw, "ask", true)) s.ask = 0.0;
                if (!fillf(s.bidsz, raw, "bid-size", true)) s.bidsz = 0;
                if (!fillf(s.asksz, raw, "ask-size", true)) s.asksz = 0;
                s.clientId = clientId;

                return message(s);
            }

            if (raw.name() == "error") {
                error s;
                fillf(s.info, raw, "info", true);

                string e;
                fillf(e, raw, "error");
                if (e == "bad-field") {
                    s.reason = error::bad_field;
                    fillf(s.field_name, raw, "field");
                }
                if (e == "unknown-symbol") {
                    s.reason = error::unknown_symbol;
                    fillf(s.symbol, raw, "symbol");
                }
                if (e == "limit-reached") {
                    s.reason = error::limit;
                    fillf(s.symbol, raw, "symbol");
                }
                if (e == "exec-halted") {
                    s.reason = error::halt;
                    fillf(s.symbol, raw, "symbol");
                }
                if (e == "server-down") {
                    s.reason = error::server;
                }
                if (e == "bad-message") {
                    s.reason = error::bad_message;
                }

                s.clientId = clientId;

                return message(s);
            }

            pe.msg.reason = error::bad_message;
            pe.msg.info = "Unknown message type " + raw.name();
            throw pe;
        }

        template <typename T>
        struct any_fn : public std::unary_function<const T &, yaml::node> {
            yaml::node operator()(const T &t) const {
                return yaml::node(boost::lexical_cast<string>(t), false);
            }
        };
        template <typename iter>
        struct any_iterator {
            typedef boost::transform_iterator<any_fn<typename iter::value_type>, iter> type;
        };
        template <typename iter>
        typename any_iterator<iter>::type
        make_any_iter ( const iter &it ) {
                return typename any_iterator<iter>::type(it);
        }

        struct to_raw : public boost::static_visitor<yaml::message> {
            void fillf ( yaml::message &m, const string &f, const char * t ) const {
                fillf(m, f, string(t));
            }
            template <typename T>
            void fillf( yaml::message &m, const string &f, const list<T> &ts ) const {
                m.insert(std::make_pair(f,
                           yaml::node(yaml::node_list(make_any_iter(ts.begin()), make_any_iter(ts.end())), false)));
            }
            template <typename T>
            void fillf( yaml::message &m, const string &f, const T &t ) const {
                m.insert(std::make_pair(f, yaml::node(boost::lexical_cast<string>(t), false)));
            }
            void fillf( yaml::message &m, const string &f, const double &d ) const {
                char buf[20];
                snprintf(buf, 19, "%.3f", d);
                buf[19] = 0;
                m.insert(std::make_pair(f, yaml::node(string(buf), false)));
            }

            yaml::message operator() ( const connect &s ) const {
                yaml::message m("connect");
                fillf(m, "account", s.account);
                fillf(m, "name", s.name);
                fillf(m, "password", s.password);
                return m;
            }
            yaml::message operator() ( const trade &s ) const {
                yaml::message m("trade");
                fillf(m, "symbol", s.symbol);
                fillf(m, "aggr", s.aggr);
                fillf(m, "orderID", s.orderID);
                fillf(m, "qty", s.qty);
                fillf(m, "short-mark", s.short_mark);
                return m;
            }
            yaml::message operator() ( const halt &s ) const {
                yaml::message m("halt");
                if (!s.all) {
                    fillf(m, "symbol", s.symbols);
                }
                return m;
            }
            yaml::message operator() ( const stop &s ) const {
                yaml::message m("stop");
                if (!s.all) {
                    fillf(m, "symbol", s.symbols);
                }
                return m;
            }
            yaml::message operator() ( const resume &s ) const {
                yaml::message m("resume");
                if (!s.all) {
                    fillf(m, "symbol", s.symbols);
                }
                return m;
            }
            yaml::message operator() ( const status &s ) const {
                yaml::message m("status");
                if (!s.all) {
                    fillf(m, "symbol", s.symbols);
                }
                return m;
            }
            yaml::message operator() ( const server &s ) const {
                yaml::message m("server");
                fillf(m, "name", s.name);
                fillf(m, "symbol", s.symbols);
                return m;
            }
            yaml::message operator() ( const fill &s ) const {
                char tmbuf[19];
                yaml::message m("fill");

                snprintf(tmbuf, 19, "%d.%06d", s.time_sec, s.time_usec);
                fillf(m, "symbol", s.symbol);
                fillf(m, "exchange", s.exchange);
                fillf(m, "time", string(tmbuf));
                fillf(m, "qtyLeft", s.qtyLeft);
                fillf(m, "orderID", s.orderID);
                fillf(m, "strat", s.strat);
                fillf(m, "fill-size", s.fill_size);
                fillf(m, "fill-price", s.fill_price);
                switch(s.liquidity) {
                    case fill::add:    fillf(m, "liquidity", "A"); break;
                    case fill::remove: fillf(m, "liquidity", "R"); break;
                    case fill::other:  fillf(m, "liquidity", "O"); break;
                }
                return m;
            }
            yaml::message operator() ( const info &s ) const {
                char tmbuf[19];
                yaml::message m("info");

                snprintf(tmbuf, 19, "%d.%06d", s.time_sec, s.time_usec);
                fillf(m, "symbol", s.symbol);
                fillf(m, "time", string(tmbuf));
                fillf(m, "position", s.position);
                fillf(m, "qtyLeft", s.qtyLeft);
                fillf(m, "locates", s.locates);
                fillf(m, "aggr", s.aggr);
                fillf(m, "halt", s.halt);
                fillf(m, "bid-size", s.bidsz);
                fillf(m, "ask-size", s.asksz);
                fillf(m, "bid", s.bid);
                fillf(m, "ask", s.ask);
                return m;
            }

            yaml::message operator() ( const error &s ) const {
                yaml::message m("error");
                switch (s.reason) {
                    case error::bad_field:
                        fillf(m, "error", "bad-field");
                        fillf(m, "field", s.field_name);
                        break;
                    case error::unknown_symbol:
                        fillf(m, "error", "unknown-symbol");
                        fillf(m, "symbol", s.symbol);
                        break;
                    case error::limit:
                        fillf(m, "error", "limit-reached");
                        fillf(m, "symbol", s.symbol);
                        break;
                    case error::halt:
                        fillf(m, "error", "exec-halted");
                        fillf(m, "symbol", s.symbol);
                        break;
                    case error::bad_message:
                        fillf(m, "error", "bad-message");
                        fillf(m, "message-name", s.message_name);
                        break;
                    case error::server:
                        fillf(m, "error", "server-down");
                        break;
                    case error::unshortable:
                        fillf(m, "error", "unshortable");
                        fillf(m, "symbol", s.symbol);
                }
                fillf(m, "reason", s.info);
                return m;
            }
        };

        struct to_string : public boost::static_visitor<std::string> {
            mutable std::ostringstream ss;
            to_string ( const std::string &pfx ) : ss(pfx) { }
            to_string ( )  { }
            to_string ( const to_string &to ) { } //XXX

            std::string operator() ( const connect &s ) const {
                ss << "Connect  " << s.account;
                if (s.name.empty()) ss << " anonymous client.";
                else ss << " \"" << s.name << "\"";
                if (s.password.empty()) ss << " no password";
                else ss << " password supplied.";
                if (s.listenToBcast > 0) ss << "Client listens to broadcast.";
                else ss << "Client does not listen to broadcast.";

                return ss.str();
            }

            std::string operator() ( const trade &s ) const {
              	ss << "Trade    " << "qty " << s.qty << " " << s.symbol << " at aggr " << s.aggr;
                if (s.short_mark != trade::unknown) {
                    ss << " marked ";
                    switch (s.short_mark) {
                        case trade::long_sell:  ss << "long "; break;
                        case trade::short_sell: ss << "short "; break;
                    }
                }
                ss << " (orderID = " << s.orderID << ").";
                return ss.str();
            }

            std::string operator() ( const stop &s ) const {
                ss << "Stop     ";
                if (s.all) ss << "(all symbols).";
                else {
                    ss << " [";
                    std::copy(s.symbols.begin(), s.symbols.end(), std::ostream_iterator<string>(ss, " "));
                    ss << "].";
                }
                return ss.str();
            }

            std::string operator() ( const halt &s ) const {
                ss << "Halt     ";
                if (s.all) ss << "(all symbols).";
                else {
                    ss << " [";
                    std::copy(s.symbols.begin(), s.symbols.end(), std::ostream_iterator<string>(ss, " "));
                    ss << "].";
                }
                return ss.str();
            }
            std::string operator() ( const resume &s ) const {
                ss << "Resume   ";
                if (s.all) ss << "(all symbols).";
                else {
                    ss << " [";
                    std::copy(s.symbols.begin(), s.symbols.end(), std::ostream_iterator<string>(ss, " "));
                    ss << "].";
                }
                return ss.str();
            }
            std::string operator() ( const status &s ) const {
                ss << "Status   ";
                if (s.all) ss << "(all symbols).";
                else {
                    ss << " [";
                    std::copy(s.symbols.begin(), s.symbols.end(), std::ostream_iterator<string>(ss, " "));
                    ss << "].";
                }
                return ss.str();
            }
            std::string operator() ( const server &s ) const {
                ss << "Server   " << s.name << ".";
                return ss.str();
            }

            std::string operator() ( const fill &s ) const {
                ss << "Fill     " << s.symbol << " ";
                switch (s.liquidity) {
                    case fill::add:    ss << "A "; break;
                    case fill::remove: ss << "R "; break;
                    case fill::other:  ss << "O "; break;
                }
                ss << s.fill_size << " @" << s.fill_price
                   << " on " << s.exchange
                   << " qtyLeft: " << s.qtyLeft
                   << " (orderID = " << s.orderID << ")"
                   << " strat: " << s.strat;
                return ss.str();
            }
            std::string operator() ( const info &s ) const {
                ss << "Info     " << s.symbol << " "
                   << s.position << " [l:" << s.locates << "] "
                   << " aggr: " << s.aggr << " qtyLeft: " << s.qtyLeft
                   << ", halt: " << s.halt
                   << " [" << s.bidsz << "x" << s.bid << " | "
                   << s.ask << "x" << s.asksz << "]";
                return ss.str();
            }
            std::string operator() ( const error &s ) const {
                ss << "Error    ";
                switch (s.reason) {
                    case error::bad_field: ss << "bad field " << s.field_name; break;
                    case error::unknown_symbol: ss << "unknown symbol " << s.symbol; break;
                    case error::limit: ss << "limit " << s.symbol; break;
                    case error::halt: ss << "halt " << s.symbol; break;
                    case error::bad_message: ss << "bad message " << s.message_name; break;
                    case error::server: ss << "server"; break;
                    case error::unshortable: ss<< "unshortable "; break;
                };
                ss << s.info;
                return ss.str();
            }
        };

        struct to_req : public boost::static_visitor<request> {
            request operator() ( const connect &s ) const { return request(s); }
            request operator() ( const trade &s ) const { return request(s); }
            request operator() ( const stop &s ) const { return request(s); }
            request operator() ( const halt &s ) const { return request(s); }
            request operator() ( const resume &s ) const { return request(s); }
            request operator() ( const status &s ) const { return request(s); }
            request operator() ( const server &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "server";
                pe.msg.info = std::string("message type 'server' not expected here.");
                throw pe;
            }
            request operator() ( const fill &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "fill";
                pe.msg.info = std::string("message type 'fill' not expected here.");
                throw pe;
            }
            request operator() ( const info &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "info";
                pe.msg.info = std::string("message type 'info' not expected here.");
                throw pe;
            }
            request operator() ( const error &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "error";
                pe.msg.info = std::string("message type 'error' not expected here.");
                throw pe;
            }
        };
        struct to_rsp : public boost::static_visitor<response> {
            response operator() ( const server &s ) const { return response(s); }
            response operator() ( const fill &s ) const { return response(s); }
            response operator() ( const info &s ) const { return response(s); }
            response operator() ( const error &s ) const { return response(s); }
            response operator() ( const connect &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "connect";
                pe.msg.info = std::string("message type 'connect' not expected here.");
                throw pe;
            }
            response operator() ( const trade &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "trade";
                pe.msg.info = std::string("message type 'trade' not expected here.");
                throw pe;
            }
            response operator() ( const stop &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "stop";
                pe.msg.info = std::string("message type 'stop' not expected here.");
                throw pe;
            }
            response operator() ( const halt &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "halt";
                pe.msg.info = std::string("message type 'halt' not expected here.");
                throw pe;
            }
            response operator() ( const resume &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "resume";
                pe.msg.info = std::string("message type 'resume' not expected here.");
                throw pe;
            }
            response operator() ( const status &s ) const {
                parse_error pe;
                pe.msg.reason = error::bad_message;
                pe.msg.message_name = "status";
                pe.msg.info = std::string("message type 'status' not expected here.");
                throw pe;
            }
        };

        struct relevant : public boost::static_visitor<std::pair<bool, int> > {
        protected:
        	int targetClientId;
        	bool targetListenToBcast;
        public:
        	relevant(int targetClientId, bool targetListenToBcast): targetClientId(targetClientId), targetListenToBcast(targetListenToBcast) {
        	}

        	std::pair<bool, int> operator() ( const server &s ) const { return std::make_pair(targetClientId == s.clientId, s.clientId); }
        	std::pair<bool, int> operator() ( const fill &s ) const { return std::make_pair(targetClientId == s.clientId || targetListenToBcast, s.clientId); }
        	std::pair<bool, int> operator() ( const info &s ) const { return std::make_pair(targetClientId == s.clientId, s.clientId); }
        	std::pair<bool, int> operator() ( const error &s ) const { return std::make_pair(targetClientId == s.clientId, s.clientId); }
        };

        request get_request  ( const message &m ) { return boost::apply_visitor(to_req(), m); }
        response get_response ( const message &m ) { return boost::apply_visitor(to_rsp(), m); }
        yaml::message put_message ( const message &m ) { return boost::apply_visitor(to_raw(), m); }
// GVNOTE: Removing the following put_message functions, because they are essentially the same as
// the above put_message(message) function, and message encompasses both request and response
//        yaml::message put_message ( const request &m ) { return boost::apply_visitor(to_raw(), m); }
//        yaml::message put_message ( const response &m ) { return boost::apply_visitor(to_raw(), m); }
        std::string show ( const message &m ) { return boost::apply_visitor(to_string(), m); }
        std::string show ( const request &m ) { return boost::apply_visitor(to_string(), m); }
        std::string show ( const response &m ) { return boost::apply_visitor(to_string(), m); }
        std::pair<bool, int> isRelevant(int targetClientId, bool targetListenToBcast, const response &m) { return boost::apply_visitor(relevant(targetClientId, targetListenToBcast), m); }
    }
}

max_stars_repo_name: CodeApprenticeRai/newt

max_issues_repo_name: CodeApprenticeRai/newt

max_forks_repo_name: CodeApprenticeRai/newt


text: #include <boost/mpl/aux_/preprocessed/bcc/unpack_args.hpp>

ext: hpp

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
// -*- coding: utf-8 -*-
// Copyright (C) 2012 Rosen Diankov <rosen.diankov@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#include "plugindefs.h"

#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>

class IdealVelocityController : public ControllerBase
{
public:
    IdealVelocityController(EnvironmentBasePtr penv, std::istream& sinput) : ControllerBase(penv)
    {
        __description = ":Interface Authors: Rosen Diankov\n\nIdeal Velocity controller.";
    }

    virtual bool Init(RobotBasePtr robot, const std::vector<int>& dofindices, int nControlTransformation)
    {
        _probot = robot;
        _dofindices = dofindices;
        if( nControlTransformation ) {
            RAVELOG_WARN("odevelocity controller cannot control transformation\n");
        }
        Reset(0);
        return true;
    }

    virtual void Reset(int options)
    {
//        if( !!_probot ) {
//            EnvironmentMutex::scoped_lock lock(GetEnv()->GetMutex());
//            //_probot->GetDOFVelocities(_vPreviousVelocities,_dofindices);
//        }
        _bVelocityMode = false;
    }

    virtual const std::vector<int>& GetControlDOFIndices() const {
        return _dofindices;
    }
    virtual int IsControlTransformation() const {
        return 0;
    }

    virtual bool SetDesired(const std::vector<OpenRAVE::dReal>& values, TransformConstPtr trans) {
        OPENRAVE_ASSERT_OP(values.size(),==,_dofindices.size());
        EnvironmentMutex::scoped_lock lock(GetEnv()->GetMutex());

        _vDesiredVelocities = values;
        std::vector<dReal> vallvelocities;
        _probot->GetDOFVelocities(vallvelocities);
        for(size_t i = 0; i < _dofindices.size(); ++i) {
            vallvelocities.at(_dofindices[i]) = _vDesiredVelocities.at(i);
        }
        _probot->SetDOFVelocities(vallvelocities);
        _bVelocityMode = true;
        return true;
    }
    virtual bool SetPath(TrajectoryBaseConstPtr ptraj) {
        return false;
    }
    virtual void SimulationStep(OpenRAVE::dReal fTimeElapsed) {
        if( _bVelocityMode ) {
            std::vector<dReal> vallvelocities;
            _probot->GetDOFVelocities(vallvelocities);
            for(size_t i = 0; i < _dofindices.size(); ++i) {
                vallvelocities.at(_dofindices[i]) = _vDesiredVelocities.at(i);
            }

            vector<dReal> vprevvalues;
            _probot->GetDOFValues(vprevvalues,_dofindices);
            for(size_t i = 0; i < _dofindices.size(); ++i) {
                vprevvalues[i] += fTimeElapsed*_vDesiredVelocities[i];
            }
            _probot->SetDOFValues(vprevvalues,true,_dofindices);
            _probot->SetDOFVelocities(vallvelocities); // set after SetDOFValues in order to get correct link velocities
        }
    }
    virtual bool IsDone() {
        return !_bVelocityMode;
    }
    virtual OpenRAVE::dReal GetTime() const {
        return 0;
    }
    virtual RobotBasePtr GetRobot() const {
        return _probot;
    }

protected:
    RobotBasePtr _probot;
    std::vector<int> _dofindices;
    std::vector<dReal> _vDesiredVelocities; //, _vPreviousVelocities;
    bool _bVelocityMode;
    OpenRAVE::UserDataPtr _torquechangedhandle;
};

ControllerBasePtr CreateIdealVelocityController(EnvironmentBasePtr penv, std::istream& sinput)
{
    return ControllerBasePtr(new IdealVelocityController(penv,sinput));
}

ext: cpp

max_issues_repo_name: jdsika/holy

max_forks_repo_name: jdsika/holy


text:
#include <boost/python/module.hpp>

namespace cctbx { namespace dmtbx { namespace boost_python {

  void wrap_triplet_generator();
  void wrap_triplet_phase_relation();

namespace {

  void init_module()
  {
    wrap_triplet_generator();
    wrap_triplet_phase_relation();
  }

} // namespace <anonymous>
}}} // namespace cctbx::dmtbx::boost_python

BOOST_PYTHON_MODULE(cctbx_dmtbx_ext)
{
  cctbx::dmtbx::boost_python::init_module();
}


text:
/*=============================================================================
    Copyright (c) 2001-2011 Joel de Guzman

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(FUSION_SET_LIMITS_09162005_1103)
#define FUSION_SET_LIMITS_09162005_1103

#include <boost/fusion/support/config.hpp>
#include <boost/fusion/container/vector/limits.hpp>

#if !defined(FUSION_MAX_SET_SIZE)
# define FUSION_MAX_SET_SIZE FUSION_MAX_VECTOR_SIZE
#else
# if FUSION_MAX_SET_SIZE < 3
#   undef FUSION_MAX_SET_SIZE
#   if (FUSION_MAX_VECTOR_SIZE > 10)
#       define FUSION_MAX_SET_SIZE 10
#   else
#       define FUSION_MAX_SET_SIZE FUSION_MAX_VECTOR_SIZE
#   endif
# endif
#endif

#define FUSION_MAX_SET_SIZE_STR BOOST_PP_STRINGIZE(BOOST_FUSION_PP_ROUND_UP(FUSION_MAX_SET_SIZE))

#endif

max_stars_repo_name: rudylee/expo

max_issues_repo_name: rudylee/expo

max_forks_repo_name: rudylee/expo


text:
// chebyshev.cpp: evaulation of Chebyshev polynomials for filter design
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <hprblas>

// define a true 256-bit IEEE floating point type
constexpr size_t bits_in_octand = 113 + 128;
using cpp_bin_float_octand = boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<bits_in_octand, boost::multiprecision::backends::digit_base_2, void, boost::int16_t, -16382, 16383>, boost::multiprecision::expression_template_option::et_off>;
// define the floating point types (single, double, quad, octand)
using sp = boost::multiprecision::cpp_bin_float_single;
using dp = boost::multiprecision::cpp_bin_float_double;
using qp = boost::multiprecision::cpp_bin_float_quad;
using op = cpp_bin_float_octand;

// generate the Chebyshev nodes in the interval (-1, 1)
template<typename Vector>
void chebyshev_nodes(Vector& args, Vector& v) {
	typedef typename Vector::value_type value_type;
	size_t nrOfNodes = size(args);
	if (size(v) != size(args)) {
		std::cerr << "chebyshev_nodes: vectors must be the same size\n";
		return;
	}
	value_type pi = value_type(3.14159265358979323846);  // TODO: this is limited to native type accuracy
	for (size_t k = 1; k <= nrOfNodes; ++k) {
		value_type numerator = (2 * k - 1) * pi;
		value_type denominator = 2 * nrOfNodes;
		value_type arg = numerator / denominator; // better would be to use cospi arguments, so we side step radian round-off
		args[k] =arg;
		v[k] = cos(arg);
	}
}

template<typename Vector>
void dumpPair(const Vector& args, const Vector& nodes) {
	for (size_t i = 0; i < size(args) && i < size(nodes); ++i) {
		std::cout << args[i] << " : " << nodes[i] << std::endl;
	}
}

template<typename Scalar>
std::ostream& operator<<(std::ostream& ostr, const std::vector<Scalar>& vec) {
	ostr << "[ ";
	for (auto v : vec) {
		ostr << v << " ";
	}
	ostr << "]";
	return ostr;
}

int main(int argc, char** argv)
try {
	using namespace sw::universal;

	using Real = double; // qp;
	mtl::vec::dense_vector<Real> args(10), nodes(10);
	chebyshev_nodes(args, nodes);
	std::cout << std::setprecision(std::numeric_limits<Real>::digits10);
	dumpPair(args, nodes);

	mtl::vec::cos(args);

	std::cout << nodes << std::endl;

	return EXIT_SUCCESS;
}
catch (char const* msg) {
	std::cerr << msg << std::endl;
	return EXIT_FAILURE;
}
catch (const sw::universal::posit_arithmetic_exception& err) {
	std::cerr << "Uncaught posit arithmetic exception: " << err.what() << std::endl;
	return EXIT_FAILURE;
}
catch (const sw::universal::quire_exception& err) {
	std::cerr << "Uncaught quire exception: " << err.what() << std::endl;
	return EXIT_FAILURE;
}
catch (const sw::universal::posit_internal_exception& err) {
	std::cerr << "Uncaught posit internal exception: " << err.what() << std::endl;
	return EXIT_FAILURE;
}
catch (std::runtime_error& err) {
	std::cerr << err.what() << std::endl;
	return EXIT_FAILURE;
}
catch (...) {
	std::cerr << "Caught unknown exception" << std::endl;
	return EXIT_FAILURE;
}

/*
 BOOST implementation of operator<<() for cpp_bin_float backend

 class number {
 ...
   //
   // String conversion functions:
   //
   std::string str(std::streamsize digits = 0, std::ios_base::fmtflags f = std::ios_base::fmtflags(0))const
   {
	  return m_backend.str(digits, f);
   }
   template<class Archive>
   void serialize(Archive & ar, const unsigned int version)
   {
   ar & m_backend;
   }
...
}

template <class Backend, expression_template_option ExpressionTemplates>
inline std::ostream& operator << (std::ostream& os, const number<Backend, ExpressionTemplates>& r)
{
	std::streamsize d = os.precision();
	std::string s = r.str(d, os.flags());
	std::streamsize ss = os.width();
	if (ss > static_cast<std::streamsize>(s.size()))
	{
		char fill = os.fill();
		if ((os.flags() & std::ios_base::left) == std::ios_base::left)
			s.append(static_cast<std::string::size_type>(ss - s.size()), fill);
		else
			s.insert(static_cast<std::string::size_type>(0), static_cast<std::string::size_type>(ss - s.size()), fill);
	}
	return os << s;
}

 template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
std::string cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::str(std::streamsize dig, std::ios_base::fmtflags f) const
{
   if(dig == 0)
	  dig = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::max_digits10;

   bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
   bool fixed = !scientific && (f & std::ios_base::fixed);

   std::string s;

   if(exponent() <= cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent)
   {
	  // How far to left-shift in order to demormalise the mantissa:
	  boost::intmax_t shift = (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - exponent() - 1;
	  boost::intmax_t digits_wanted = static_cast<int>(dig);
	  boost::intmax_t base10_exp = exponent() >= 0 ? static_cast<boost::intmax_t>(std::floor(0.30103 * exponent())) : static_cast<boost::intmax_t>(std::ceil(0.30103 * exponent()));
	  //
	  // For fixed formatting we want /dig/ digits after the decimal point,
	  // so if the exponent is zero, allowing for the one digit before the
	  // decimal point, we want 1 + dig digits etc.
	  //
	  if(fixed)
		 digits_wanted += 1 + base10_exp;
	  if(scientific)
		 digits_wanted += 1;
	  if(digits_wanted < -1)
	  {
		 // Fixed precision, no significant digits, and nothing to round!
		 s = "0";
		 if(sign())
			s.insert(static_cast<std::string::size_type>(0), 1, '-');
		 boost::multiprecision::detail::format_float_string(s, base10_exp, dig, f, true);
		 return s;
	  }
	  //
	  // power10 is the base10 exponent we need to multiply/divide by in order
	  // to convert our denormalised number to an integer with the right number of digits:
	  //
	  boost::intmax_t power10 = digits_wanted - base10_exp - 1;
	  //
	  // If we calculate 5^power10 rather than 10^power10 we need to move
	  // 2^power10 into /shift/
	  //
	  shift -= power10;
	  cpp_int i;
	  int roundup = 0; // 0=no rounding, 1=tie, 2=up
	  static const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT;
	  //
	  // Set our working precision - this is heuristic based, we want
	  // a value as small as possible > cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count to avoid large computations
	  // and excessive memory usage, but we also want to avoid having to
	  // up the computation and start again at a higher precision.
	  // So we round cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count up to the nearest whole number of limbs, and add
	  // one limb for good measure.  This works very well for small exponents,
	  // but for larger exponents we add a few extra limbs to max_bits:
	  //
#ifdef BOOST_MP_STRESS_IO
	  boost::intmax_t max_bits = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count + 32;
#else
	  boost::intmax_t max_bits = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count + ((cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count % limb_bits) ? (limb_bits - cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count % limb_bits) : 0) + limb_bits;
	  if(power10)
		 max_bits += (msb(boost::multiprecision::detail::abs(power10)) / 8) * limb_bits;
#endif
	  do
	  {
		 boost::int64_t error = 0;
		 boost::intmax_t calc_exp = 0;
		 //
		 // Our integer result is: bits() * 2^-shift * 5^power10
		 //
		 i = bits();
		 if(shift < 0)
		 {
			if(power10 >= 0)
			{
			   // We go straight to the answer with all integer arithmetic,
			   // the result is always exact and never needs rounding:
			   BOOST_ASSERT(power10 <= (boost::intmax_t)INT_MAX);
			   i <<= -shift;
			   if(power10)
				  i *= pow(cpp_int(5), static_cast<unsigned>(power10));
			}
			else if(power10 < 0)
			{
			   cpp_int d;
			   calc_exp = boost::multiprecision::cpp_bf_io_detail::restricted_pow(d, cpp_int(5), -power10, max_bits, error);
			   shift += calc_exp;
			   BOOST_ASSERT(shift < 0); // Must still be true!
			   i <<= -shift;
			   cpp_int r;
			   divide_qr(i, d, i, r);
			   roundup = boost::multiprecision::cpp_bf_io_detail::get_round_mode(r, d, error, i);
			   if(roundup < 0)
			   {
#ifdef BOOST_MP_STRESS_IO
				  max_bits += 32;
#else
				  max_bits *= 2;
#endif
				  shift = (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - exponent() - 1 - power10;
				  continue;
			   }
			}
		 }
		 else
		 {
			//
			// Our integer is bits() * 2^-shift * 10^power10
			//
			if(power10 > 0)
			{
			   if(power10)
			   {
				  cpp_int t;
				  calc_exp = boost::multiprecision::cpp_bf_io_detail::restricted_pow(t, cpp_int(5), power10, max_bits, error);
				  calc_exp += boost::multiprecision::cpp_bf_io_detail::restricted_multiply(i, i, t, max_bits, error);
				  shift -= calc_exp;
			   }
			   if((shift < 0) || ((shift == 0) && error))
			   {
				  // We only get here if we were asked for a crazy number of decimal digits -
				  // more than are present in a 2^max_bits number.
#ifdef BOOST_MP_STRESS_IO
				  max_bits += 32;
#else
				  max_bits *= 2;
#endif
				  shift = (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - exponent() - 1 - power10;
				  continue;
			   }
			   if(shift)
			   {
				  roundup = boost::multiprecision::cpp_bf_io_detail::get_round_mode(i, shift - 1, error);
				  if(roundup < 0)
				  {
#ifdef BOOST_MP_STRESS_IO
					 max_bits += 32;
#else
					 max_bits *= 2;
#endif
					 shift = (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - exponent() - 1 - power10;
					 continue;
				  }
				  i >>= shift;
			   }
			}
			else
			{
			   // We're right shifting, *and* dividing by 5^-power10,
			   // so 5^-power10 can never be that large or we'd simply
			   // get zero as a result, and that case is already handled above:
			   cpp_int r;
			   BOOST_ASSERT(-power10 < INT_MAX);
			   cpp_int d = pow(cpp_int(5), static_cast<unsigned>(-power10));
			   d <<= shift;
			   divide_qr(i, d, i, r);
			   r <<= 1;
			   int c = r.compare(d);
			   roundup = c < 0 ? 0 : c == 0 ? 1 : 2;
			}
		 }
		 s = i.str(0, std::ios_base::fmtflags(0));
		 //
		 // Check if we got the right number of digits, this
		 // is really a test of whether we calculated the
		 // decimal exponent correctly:
		 //
		 boost::intmax_t digits_got = i ? static_cast<boost::intmax_t>(s.size()) : 0;
		 if(digits_got != digits_wanted)
		 {
			base10_exp += digits_got - digits_wanted;
			if(fixed)
			   digits_wanted = digits_got;  // strange but true.
			power10 = digits_wanted - base10_exp - 1;
			shift = (int)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - exponent() - 1 - power10;
			if(fixed)
			   break;
			roundup = 0;
		 }
		 else
			break;
	  }
	  while(true);
	  //
	  // Check whether we need to round up: note that we could equally round up
	  // the integer /i/ above, but since we need to perform the rounding *after*
	  // the conversion to a string and the digit count check, we might as well
	  // do it here:
	  //
	  if((roundup == 2) || ((roundup == 1) && ((s[s.size() - 1] - '0') & 1)))
	  {
		 boost::multiprecision::detail::round_string_up_at(s, static_cast<int>(s.size() - 1), base10_exp);
	  }

	  if(sign())
		 s.insert(static_cast<std::string::size_type>(0), 1, '-');

	  boost::multiprecision::detail::format_float_string(s, base10_exp, dig, f, false);
   }
   else
   {
	  switch(exponent())
	  {
	  case exponent_zero:
		 s = sign() ? "-0" : f & std::ios_base::showpos ? "+0" : "0";
		 boost::multiprecision::detail::format_float_string(s, 0, dig, f, true);
		 break;
	  case exponent_nan:
		 s = "nan";
		 break;
	  case exponent_infinity:
		 s = sign() ? "-inf" : f & std::ios_base::showpos ? "+inf" : "inf";
		 break;
	  }
   }
   return s;
}
 */

max_stars_repo_name: stillwater-sc/hpr-blas

max_issues_repo_name: stillwater-sc/hpr-blas

max_forks_repo_name: stillwater-sc/hpr-blas


text:
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
//    names, trademarks, service marks, or product names of the Licensor
//    and its affiliates, except as required to comply with Section 4(c) of
//    the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#include "pxr/imaging/hd/shaderParam.h"

#include "pxr/imaging/glf/glew.h"

#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/vec2d.h"

#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/vec3d.h"

#include "pxr/base/gf/vec4f.h"
#include "pxr/base/gf/vec4d.h"

#include "pxr/base/gf/matrix4f.h"
#include "pxr/base/gf/matrix4d.h"

#include "pxr/base/tf/staticTokens.h"
#include "pxr/base/tf/envSetting.h"

#include <boost/functional/hash.hpp>

PXR_NAMESPACE_OPEN_SCOPE

TF_DEFINE_PRIVATE_TOKENS(
    _tokens,
    ((_bool, "bool"))
    ((_float, "float"))
    (vec2)
    (vec3)
    (vec4)
    (mat4)
    ((_double, "double"))
    (dvec2)
    (dvec3)
    (dvec4)
    (dmat4)
    ((_int, "int"))
    (ivec2)
    (ivec3)
    (ivec4)
);

HdShaderParam::HdShaderParam(TfToken const& name,
                             VtValue const& fallbackValue,
                             SdfPath const& connection,
                             TfTokenVector const& samplerCoords,
                             bool isPtex)
    : _name(name)
    , _fallbackValue(fallbackValue)
    , _connection(connection)
    , _samplerCoords(samplerCoords)
    , _isPtex(isPtex)
{
    /*NOTHING*/
}

HdShaderParam::~HdShaderParam()
{
    /*NOTHING*/
}

/* static */
size_t
HdShaderParam::ComputeHash(HdShaderParamVector const &params)
{
    size_t hash = 0;
    TF_FOR_ALL(paramIt, params) {
        boost::hash_combine(hash, paramIt->GetName().Hash());
        boost::hash_combine(hash, paramIt->GetConnection().GetHash());
        TF_FOR_ALL(coordIt, paramIt->GetSamplerCoordinates()) {
            boost::hash_combine(hash, coordIt->Hash());
        }
        boost::hash_combine(hash, paramIt->IsPtex());
    }
    return hash;
}

// XXX: Copied from VtBufferSource
// -------------------------------------------------------------------------- //
// Convert runtime element type into GL component and element type enums.
struct _GLDataType {
    _GLDataType(int componentType, int elementType)
        : componentType(componentType)
        , elementType(elementType) { }
    int componentType;
    int elementType;
};

static
_GLDataType _GetGLType(VtValue const& value)
{
    if (value.IsHolding<char>())
        return _GLDataType(GL_BYTE, GL_BYTE);
    else if (value.IsHolding<short>())
        return _GLDataType(GL_SHORT, GL_SHORT);
    else if (value.IsHolding<unsigned short>())
        return _GLDataType(GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT);
    else if (value.IsHolding<int>())
        return _GLDataType(GL_INT, GL_INT);
    else if (value.IsHolding<GfVec2i>())
        return _GLDataType(GL_INT, GL_INT_VEC2);
    else if (value.IsHolding<GfVec3i>())
        return _GLDataType(GL_INT, GL_INT_VEC3);
    else if (value.IsHolding<GfVec4i>())
        return _GLDataType(GL_INT, GL_INT_VEC4);
    else if (value.IsHolding<unsigned int>())
        return _GLDataType(GL_UNSIGNED_INT, GL_UNSIGNED_INT);
    else if (value.IsHolding<float>())
        return _GLDataType(GL_FLOAT, GL_FLOAT);
    else if (value.IsHolding<GfVec2f>())
        return _GLDataType(GL_FLOAT, GL_FLOAT_VEC2);
    else if (value.IsHolding<GfVec3f>())
        return _GLDataType(GL_FLOAT, GL_FLOAT_VEC3);
    else if (value.IsHolding<GfVec4f>())
        return _GLDataType(GL_FLOAT, GL_FLOAT_VEC4);
    else if (value.IsHolding<double>())
        return _GLDataType(GL_DOUBLE, GL_DOUBLE);
    else if (value.IsHolding<GfVec2d>())
        return _GLDataType(GL_DOUBLE, GL_DOUBLE_VEC2);
    else if (value.IsHolding<GfVec3d>())
        return _GLDataType(GL_DOUBLE, GL_DOUBLE_VEC3);
    else if (value.IsHolding<GfVec4d>())
        return _GLDataType(GL_DOUBLE, GL_DOUBLE_VEC4);
    else if (value.IsHolding<GfMatrix4f>())
        return _GLDataType(GL_FLOAT, GL_FLOAT_MAT4);
    else if (value.IsHolding<GfMatrix4d>())
        return _GLDataType(GL_DOUBLE, GL_DOUBLE_MAT4);
    else if (value.IsHolding<bool>())
        return _GLDataType(GL_BOOL, GL_BOOL);
    else
        TF_CODING_ERROR("Unknown type held by VtValue in ShaderParam");

    return _GLDataType(0, 0);
}

static
TfToken _GetGLTypeName(GLenum elementType)
{
    if (elementType == GL_FLOAT) {
        return _tokens->_float;
    } else if (elementType == GL_FLOAT_VEC2) {
        return _tokens->vec2;
    } else if (elementType == GL_FLOAT_VEC3) {
        return _tokens->vec3;
    } else if (elementType == GL_FLOAT_VEC4) {
        return _tokens->vec4;
    } else if (elementType == GL_DOUBLE) {
        return _tokens->_double;
    } else if (elementType == GL_DOUBLE_VEC2) {
        return _tokens->dvec2;
    } else if (elementType == GL_DOUBLE_VEC3) {
        return _tokens->dvec3;
    } else if (elementType == GL_DOUBLE_VEC4) {
        return _tokens->dvec4;
    } else if (elementType == GL_FLOAT_MAT4) {
        return _tokens->mat4;
    } else if (elementType == GL_DOUBLE_MAT4) {
        return _tokens->dmat4;
    } else if (elementType == GL_INT) {
        return _tokens->_int;
    } else if (elementType == GL_INT_VEC2) {
        return _tokens->ivec2;
    } else if (elementType == GL_INT_VEC3) {
        return _tokens->ivec3;
    } else if (elementType == GL_INT_VEC4) {
        return _tokens->ivec4;
    } else if (elementType == GL_BOOL) {
        return _tokens->_bool;
    } else {
        TF_CODING_ERROR("unsupported type: 0x%x", elementType);
        return TfToken();
    }
}

// -------------------------------------------------------------------------- //

int
HdShaderParam::GetGLElementType() const
{
    return _GetGLType(GetFallbackValue()).elementType;
}

int
HdShaderParam::GetGLComponentType() const
{
    return _GetGLType(GetFallbackValue()).componentType;
}

TfToken
HdShaderParam::GetGLTypeName() const
{
    return _GetGLTypeName(GetGLElementType());
}

TfTokenVector const&
HdShaderParam::GetSamplerCoordinates() const
{
    // NOTE: could discover from texture connection.
    return _samplerCoords;
}

bool
HdShaderParam::IsPtex() const
{
    return _isPtex;
}

PXR_NAMESPACE_CLOSE_SCOPE

max_stars_repo_name: dalgos-adsk/USD

max_issues_repo_name: piscees/USD

max_forks_repo_name: piscees/USD