text:
// Copyright 2015-2017 Hans Dembinski
//
// 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)

#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/histogram/detail/relaxed_equal.hpp>
#include "std_ostream.hpp"

using namespace boost::histogram::detail;

int main() {
  struct Stateless {
  } a, b;

  struct Stateful {
    int state; // has state
  } c, d;

  struct HasEqual {
    int state;
    bool operator==(const HasEqual& rhs) const { return state == rhs.state; }
  } e{1}, f{1}, g{2};

  BOOST_TEST(relaxed_equal{}(a, b));
  BOOST_TEST_NOT(relaxed_equal{}(a, c));
  BOOST_TEST_NOT(relaxed_equal{}(c, d));
  BOOST_TEST(relaxed_equal{}(e, f));
  BOOST_TEST_NOT(relaxed_equal{}(e, g));

  return boost::report_errors();
}


text:
#include <iostream>
#include <string>
#include <armadillo>
#include <time.h>
#include "ga.h"
#include "simpleNN.h"

using namespace std;
using namespace arma;

///#define SIZEOF(_arr) (sizeof(_arr)/sizeof(_arr[0]))

using namespace arma;

int main(int argc,char** argv){  srand(time(NULL));

  rowvec myx= linspace<rowvec>(0.0,2*3.1516,100);
  rowvec mysin= sin(myx);

  int population = 100;

  int iMax = atoi(argv[1]);
  double temperature = 10.0;
  vec fitness=zeros<vec>(population);

  vec inp = ones<vec>(1);

  vec bestScore = 1000000*ones<vec>(1);

  int inpSize = inp.n_elem;
  int height = 2;
  int depth = 2;
  int outputSize = 1;
  int iMaxTemp = iMax;

  string runName = argv[2];

  mat inpWeights = ones<mat>(height,inpSize);
  cube weights = ones<cube>(height,height,depth);
  mat outWeights = ones<mat>(outputSize,height);

  vec inpBiases = ones<vec>(height);
  mat biases = ones<mat>(height,depth);
  vec outBiases = ones<vec>(outputSize);
  double totalMax = 10000;

  vec buffVec = sigmoid(inpWeights*inp + inpBiases);
  double reg = 0.000005;

  int outerMax = 10;

  mat DNAS=1 - 2*randu<mat>(fitness.n_elem, inpWeights.n_elem + weights.n_elem + outWeights.n_elem + inpBiases.n_elem + biases.n_elem + outBiases.n_elem);

  mat outputs = zeros<mat>(fitness.n_elem,outBiases.n_elem);
  vec outputsFinal = zeros<vec>(outBiases.n_elem);
  vec finalResult(myx.n_elem);

  double alpha = 10.0;
  double punish = 0;
  double bestFitt = 100000000;
  vec    finalWeights;
  int decTemp = 0;

  for(int outer=0; outer < outerMax; outer++){
   decTemp = 0;

    DNAS=1 - 2*randu<mat>(fitness.n_elem, inpWeights.n_elem + weights.n_elem + outWeights.n_elem + inpBiases.n_elem + biases.n_elem + outBiases.n_elem);
    temperature = 10.0;

    for(int i=0; i < iMaxTemp; i++){

//      temperature -= 10.0/ iMax;
      temperature = 10.0 * exp( - (double) decTemp / (double) iMax / 2.0);
      decTemp++;

      fitness=zeros<vec>(population);

      for(int xInt = 0; xInt < myx.n_elem; xInt++){

        inp(0) = myx(xInt);
        outputs = simpleNNmat(DNAS,inp, inpWeights, weights, outWeights, inpBiases, biases, outBiases);

        for(int f = 0; f < fitness.n_elem; f++){

          punish = sum(abs(outputs.row(f) - mysin(xInt))) + reg*sum(abs(DNAS.row(f))) ;
          fitness(f) = fitness(f) + punish ; // changeable

        }
      }

      DNAS = ga_eval(DNAS, fitness, alpha,0.000000000, temperature);
//      DNAS.save("DNASrerun.dat",raw_ascii);

      if(bestFitt > min(fitness)){

        cout << "hit: " << bestFitt/myx.n_elem <<endl;
        bestScore(0) = bestFitt/myx.n_elem;
        finalWeights = DNAS.row(index_min(fitness)).t();
        bestFitt = min(fitness);
        finalWeights.save("LastFinalWeights" + runName + ".save",raw_ascii);
        finalWeights.save("LastFinalWeightsBak.save",raw_ascii);
        bestScore.save("LastBestScore" + runName + ".save",raw_ascii);

        for(int i = 0; i < myx.n_elem; i++){

          inp(0) = myx(i);
          outputsFinal= simpleNNvec(finalWeights,inp, inpWeights, weights, outWeights, inpBiases, biases, outBiases);
          finalResult(i) = outputsFinal(0);

        }

        finalResult.save("sinDataFinal" + runName + ".dat",raw_ascii);
//        iMaxTemp = i + iMax;
          i = i - 10*outer - 1;

      }

      cout << i << " min fitness is: " << min(fitness)/myx.n_elem <<  " Temperature is: "<< temperature  << " C" << endl;

    }

  }

return 0;

}

ext: cpp


text:
#include "RecordApplicationGUI.hpp"

#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QTabWidget>
#include <QFileDialog>

#include <Eigen/Dense>

#include <FAST/Visualization/VertexRenderer/VertexRenderer.hpp>
#include "FAST/Visualization/ImageRenderer/ImageRenderer.hpp"
#include "FAST/Streamers/RealSenseStreamer.hpp"

namespace echobot {

RecordApplicationGUI::RecordApplicationGUI()
{
    mCameraInterface = CameraInterface::New();
    mUltrasoundInterface = UltrasoundInterface::New();

    setupUI();
    setupConnections();
}

void RecordApplicationGUI::setupConnections()
{
    QObject::connect(mConnectionWidget, &ConnectionWidget::cameraConnected, std::bind(&RecordApplicationGUI::connectToCamera, this));
    QObject::connect(mConnectionWidget, &ConnectionWidget::cameraDisconnected, std::bind(&RecordApplicationGUI::disconnectFromCamera, this));

    QObject::connect(mConnectionWidget, &ConnectionWidget::usConnected, std::bind(&RecordApplicationGUI::connectToUltrasound, this));
    QObject::connect(mConnectionWidget, &ConnectionWidget::usDisconnected, std::bind(&RecordApplicationGUI::disconnectFromUltrasound, this));

    QObject::connect(mRecordWidget, &RecordWidget::playbackStarted, this, &RecordApplicationGUI::playbackButtonSlot);
    QObject::connect(mRecordWidget, &RecordWidget::playbackStopped, this, &RecordApplicationGUI::stopPlaybackButtonSlot);
}

// Camera

void RecordApplicationGUI::connectToCamera() {
    stopComputationThread();
    removeAllRenderers();

    setupCameraVisualization();
    if(mUltrasoundStreaming){
        mUltrasoundInterface->connect();
        setupUltrasoundVisualization();
    }
    mCameraStreaming = true;

    reinitializeViews();
    startComputationThread();
}

void RecordApplicationGUI::disconnectFromCamera() {
    stopComputationThread();
    removeAllRenderers();

    if(mUltrasoundStreaming){
        mUltrasoundInterface->connect();
        setupUltrasoundVisualization();
    }
    mCameraStreaming = false;

    startComputationThread();
}

void RecordApplicationGUI::playbackButtonSlot()
{
    stopComputationThread();
    removeAllRenderers();

    setupUltrasoundVisualization();
    mUltrasoundStreaming = true;

    setupCameraVisualization();
    mCameraStreaming = true;

    reinitializeViews();
    startComputationThread();
}

void RecordApplicationGUI::stopPlaybackButtonSlot()
{
    mUltrasoundStreaming = false;
    this->stopStreaming();
}

void RecordApplicationGUI::setupCameraVisualization() {
    getView(0)->addRenderer(mCameraInterface->getImageRenderer());
    getView(1)->addRenderer(mCameraInterface->getDepthImageRenderer());
}

void RecordApplicationGUI::stopStreaming()
{
    stopComputationThread();
    removeAllRenderers();
    startComputationThread();
}

// Ultrasound
void RecordApplicationGUI::connectToUltrasound() {
    stopComputationThread();
    removeAllRenderers();
    setupUltrasoundVisualization();

    if(mCameraStreaming || mCameraPlayback){
        mCameraInterface->connect();
        setupCameraVisualization();
    }

    mUltrasoundStreaming = true;
    reinitializeViews();
    startComputationThread();
}

void RecordApplicationGUI::disconnectFromUltrasound() {
    stopComputationThread();
    removeAllRenderers();

    if(mCameraStreaming || mCameraPlayback){
        mCameraInterface->connect();
        setupCameraVisualization();
    }
    mUltrasoundStreaming = false;
    startComputationThread();
}

void RecordApplicationGUI::setupUltrasoundVisualization()
{
    getView(2)->addRenderer(mUltrasoundInterface->getImageRenderer());
}

// UI Setup

void RecordApplicationGUI::setupUI()
{
    View* view2D = createView();
    View* view3D = createView();
    View* viewUS = createView();

    setTitle("Record application");
    setWidth(1920);
    setHeight(1080);
    enableMaximized();

    viewUS->set2DMode();
    viewUS->setBackgroundColor(Color::White());
    viewUS->setFixedWidth(860);

    view3D->set2DMode();
    view3D->setBackgroundColor(Color::White());
    view3D->setFixedWidth(540);
    //view3D->setLookAt(Vector3f(0, -500, -500), Vector3f(0, 0, 1000), Vector3f(0, -1, 0), 500, 5000);

    view2D->set2DMode();
    view2D->setBackgroundColor(Color::White());
    view2D->setFixedWidth(540);

    QVBoxLayout* menuLayout = new QVBoxLayout;
    menuLayout->setAlignment(Qt::AlignTop);
    int menuWidth = 480;

    // Title label
    QLabel* title = new QLabel;
    title->setText("
Record application
");
    menuLayout->addWidget(title, 0, Qt::AlignTop);

    mConnectionWidget = new ConnectionWidget(menuWidth);
    mConnectionWidget->addInterface(mUltrasoundInterface);
    mConnectionWidget->addInterface(mCameraInterface);
    menuLayout->addWidget(mConnectionWidget, 0, Qt::AlignTop);

    mRecordWidget = new RecordWidget(mCameraInterface, mUltrasoundInterface, menuWidth, 400);
    menuLayout->addWidget(mRecordWidget, 0, Qt::AlignTop);
    menuLayout->addStretch();

    // Quit button
    QPushButton* quitButton = new QPushButton;
    quitButton->setText("Quit (q)");
    quitButton->setStyleSheet("QPushButton { background-color: red; color: white; }");
    QObject::connect(quitButton, &QPushButton::clicked, std::bind(&Window::stop, this));
    menuLayout->addWidget(quitButton,0,Qt::AlignBottom);

    QHBoxLayout* layout = new QHBoxLayout;
    layout->addLayout(menuLayout);
    layout->addWidget(viewUS);

    QWidget* imageWidget = new QWidget;
    QVBoxLayout* vLayout = new QVBoxLayout;
    imageWidget->setLayout(vLayout);
    vLayout->addWidget(view2D);
    vLayout->addWidget(view3D);

    layout->addWidget(imageWidget);
    mWidget->setLayout(layout);
}

}

max_stars_repo_name: SINTEFMedtek/EchoBot

max_issues_repo_name: SINTEFMedtek/EchoBot

max_forks_repo_name: SINTEFMedtek/EchoBot


text:
/*
 * @COPYRIGHT@
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE
 */

// typeout/value/fptr.hpp

/** // doc: typeout/value/fptr.hpp {{{
 * \file typeout/value/fptr.hpp
 * \todo Write documentation
 */ // }}}
#ifndef TYPEOUT_TVALUE_FPTR_HPP_INCLUDED
#define TYPEOUT_TVALUE_FPTR_HPP_INCLUDED

#include <typeout/value/info.hpp>
#include <typeout/type/fptr.hpp>

#include <map>
#include <string>

#include <boost/preprocessor/stringize.hpp>
/** // doc: TYPEOUT_REG_FPTR_AS(fptr,name) {{{
 * \todo Write documentation
 */ // }}}
#define TYPEOUT_REG_FPTR_AS(fptr,name) \
  ::typeout::_value::reg_fptr(fptr,name)

/** // doc: TYPEOUT_REG_FPTR(name) {{{
 * \todo Write documentation
 */ // }}}
#define TYPEOUT_REG_FPTR(fptr) \
  TYPEOUT_REG_FPTR_AS(fptr,BOOST_PP_STRINGIZE(fptr))

namespace typeout {
namespace _value {

template <typename T, typename... Args>
struct info<T(*)(Args...)>
{
  typedef T(*type)(Args...);
  typedef std::string name_type;

  static std::map<type, name_type>& instances()
  {
    static std::map<type,name_type> _instances;
    return _instances;
  }

  template <class Ostream>
  static Ostream& write_resolved(Ostream& os, type f)
  {
    auto it = instances().find(f);
    if(it == instances().end())
      _type::info<type>::write(os << "(") << ")"
        << reinterpret_cast<void*>(reinterpret_cast<std::uintptr_t>(f));
    else
      os << it->second;
    return os;
  }

  template <class Ostream>
  static Ostream& write(Ostream& os, type f)
  { return write_resolved(os,f); }
private:
  static std::map<type,name_type> _instances;
};

template<typename T, typename...Args>
void reg_fptr(T(*fptr)(Args...), std::string const& name)
{
  typedef info<T(*)(Args...)> X;
  X::instances().insert(std::make_pair(fptr,name));
}

} /* namespace _value */
} /* namespace typeout */

#endif /* TYPEOUT_TVALUE_FPTR_HPP_INCLUDED */
// vim: set expandtab tabstop=2 shiftwidth=2:
// vim: set foldmethod=marker foldcolumn=4:

ext: hpp

max_stars_repo_name: ptomulik/typeout

max_issues_repo_name: ptomulik/typeout

max_forks_repo_name: ptomulik/typeout


text:
#include <list>
#include <sstream>

#include <boost/thread/mutex.hpp>

#include "flame/base.h"
#include "flame/util.h"

namespace {
// This mutex guards the global Machine::p_state_infos
typedef boost::mutex info_mutex_t;
info_mutex_t info_mutex;
}

StateBase::~StateBase() {}

StateBase::StateBase(const Config& c)
    :next_elem(0)
    ,pos(0e0)
    ,retreat(false)
    ,pyptr(0)
{}

StateBase::StateBase(const StateBase& o, clone_tag)
    :next_elem(0)
    ,pos(o.pos)
    ,retreat(false)
    ,pyptr(0)
{}

void StateBase::assign(const StateBase& other)
{
    pos = other.pos;
}

bool StateBase::getArray(unsigned idx, ArrayInfo& Info)
{
    unsigned I=0;
    if(idx==I++) {
        Info.name = "next_elem";
        Info.ndim = 0;
        Info.type = ArrayInfo::Sizet;
        Info.ptr = &next_elem;
        return true;
    } else if(idx==I++) {
        Info.name = "pos";
        Info.ptr = &pos;
        Info.type = ArrayInfo::Double;
        Info.ndim = 0;
        return true;
    }
    return false;
}

ElementVoid::ElementVoid(const Config& conf)
    :name(conf.get<std::string>("name"))
    ,index(0)
    ,length(conf.get<double>("L",0.0))
    ,p_observe(NULL)
    ,p_conf(conf)
{}

ElementVoid::~ElementVoid()
{
    delete p_observe;
}

void ElementVoid::show(std::ostream& strm, int level) const
{
    strm<<"Element "<<index<<": "<<name<<" ("<<type_name()<<")\n";
}

void ElementVoid::assign(const ElementVoid *other)
{
    p_conf = other->p_conf;
    length = other->length;
    *const_cast<std::string*>(&name) = other->name;
    *const_cast<size_t*>(&index) = other->index;
}

Machine::Machine(const Config& c)
    :p_elements()
    ,p_trace(NULL)
    ,p_conf(c)
    ,p_info()
{
    std::string type(c.get<std::string>("sim_type"));
    p_simtype = type;
    FLAME_LOG(INFO)<<"Constructing Machine w/ sim_type='"<<type<<'\'';

    info_mutex_t::scoped_lock G(info_mutex);

    p_state_infos_t::iterator it = p_state_infos.find(type);
    if(it==p_state_infos.end()) {
        std::ostringstream msg;
        msg<<"Unsupport sim_type '"<<type<<"'";
        throw key_error(msg.str());
    }

    p_info = it->second;

    typedef Config::vector_t elements_t;
    elements_t Es(c.get<elements_t>("elements"));

    p_elements_t result;
    p_lookup_t result_l, result_t;
    result.reserve(Es.size());

    size_t idx=0;
    for(elements_t::iterator it=Es.begin(), end=Es.end(); it!=end; ++it)
    {
        const Config& EC = *it;

        const std::string& etype(EC.get<std::string>("type"));

        state_info::elements_t::iterator eit = p_info.elements.find(etype);
        if(eit==p_info.elements.end())
            throw key_error(etype);

        element_builder_t* builder = eit->second;

        ElementVoid *E;
        try{
            E = builder->build(EC);
        }catch(key_error& e){
            std::ostringstream strm;
            strm<<"Error while initializing element "<<idx<<" '"<<EC.get<std::string>("name", "<invalid>")
               <<"' : missing required parameter '"<<e.what()<<"'";
            throw key_error(strm.str());

        }catch(std::exception& e){
            std::ostringstream strm;
            strm<<"Error while constructing element "<<idx<<" '"<<EC.get<std::string>("name", "<invalid>")
               <<"' : "<<typeid(e).name()<<" : "<<e.what();
            throw std::runtime_error(strm.str());
        }

        if(E->type_name()!=etype) {
            std::ostringstream strm;
            strm<<"Element type inconsistent "<<etype<<" "<<E->type_name();
            throw std::logic_error(strm.str());
        }

        *const_cast<size_t*>(&E->index) = idx++; // ugly

        result.push_back(E);
        result_l.insert(std::make_pair(LookupKey(E->name, E->index), E));
        result_t.insert(std::make_pair(LookupKey(etype, E->index), E));
    }

    G.unlock();

    p_elements.swap(result);
    p_lookup.swap(result_l);
    p_lookup_type.swap(result_t);
    FLAME_LOG(DEBUG)<<"Complete constructing Machine w/ sim_type='"<<type<<'\'';
}

Machine::~Machine()
{
    for(p_elements_t::iterator it=p_elements.begin(), end=p_elements.end(); it!=end; ++it)
    {
        delete *it;
    }
}

void
Machine::propagate(StateBase* S, size_t start, int max) const
{
    const size_t nelem = p_elements.size();

    S->next_elem = start;
    S->retreat = std::signbit(max);

    for(int i=0; S->next_elem<nelem && i<abs(max); i++)
    {
        size_t n = S->next_elem;
        ElementVoid* E = p_elements[n];
        if(S->retreat) {
            S->next_elem--;
        } else {
            S->next_elem++;
        }
        E->advance(*S);

        if(E->p_observe)
            E->p_observe->view(E, S);
        if(p_trace)
            (*p_trace) << "After ["<< n<< "] " << E->name << " " << *S << "\n";
    }
}

StateBase*
Machine::allocState(const Config &c) const
{
    return (*p_info.builder)(c);
}

void Machine::reconfigure(size_t idx, const Config& c)
{
    if(idx>=p_elements.size())
        throw std::invalid_argument("element index out of range");

    const std::string& etype(c.get<std::string>("type"));

    state_info::elements_t::iterator eit = p_info.elements.find(etype);
    if(eit==p_info.elements.end())
        throw key_error(etype);

    element_builder_t *builder = eit->second;

    builder->rebuild(p_elements[idx], c, idx);
}

Machine::p_state_infos_t Machine::p_state_infos;

void Machine::p_registerState(const char *name, state_builder_t b)
{
    info_mutex_t::scoped_lock G(info_mutex);
    if(p_state_infos.find(name)!=p_state_infos.end()) {
        std::ostringstream strm;
        strm<<"attempt to register already registered sim_type=\""<<name<<"\"";
        throw std::logic_error(strm.str());
    }
    state_info I;
    I.name = name;
    I.builder = b;
    p_state_infos[name] = I;
}

void Machine::p_registerElement(const std::string& sname, const char *ename, element_builder_t *b)
{
    info_mutex_t::scoped_lock G(info_mutex);
    p_state_infos_t::iterator it = p_state_infos.find(sname);
    if(it==p_state_infos.end()) {
        std::ostringstream strm;
        strm<<"can't add element \""<<ename<<"\" for unknown sim_type=\""<<sname<<"\"";
        throw std::logic_error(strm.str());
    }
    state_info& I = it->second;
    if(I.elements.find(ename)!=I.elements.end()) {
        std::ostringstream strm;
        strm<<"element type \""<<ename<<"\" has already been registered for "
              "sim_type=\""<<sname<<"\"";
        throw std::logic_error(strm.str());
    }
    I.elements[ename] = b;
}

void Machine::registeryCleanup()
{
    info_mutex_t::scoped_lock G(info_mutex);

    for(p_state_infos_t::iterator it=p_state_infos.begin(), end=p_state_infos.end();
        it!=end; ++it)
    {
        state_info::elements_t::iterator it2, end2;
        for(it2=it->second.elements.begin(), end2=it->second.elements.end(); it2!=end2; ++it2)
        {
            delete it2->second;
        }
    }
    p_state_infos.clear();
}

std::ostream& operator<<(std::ostream& strm, const Machine& m)
{
    strm<<"sim_type: "<<m.p_info.name<<"\n#Elements: "<<m.p_elements.size()<<"\n";
    for(Machine::p_elements_t::const_iterator it=m.p_elements.begin(),
        end=m.p_elements.end(); it!=end; ++it)
    {
        (*it)->show(strm, 0);
    }
    return strm;
}

namespace {
struct Logcerr : public Machine::Logger
{
    virtual ~Logcerr() {}
    virtual void log(const Machine::LogRecord &r) override final
    {
        std::string msg(r.strm.str());
        std::cerr<<r.fname<<':'<<r.lnum<<" : "<<msg;
        if(msg.empty() || msg[msg.size()-1]!='\n')
            std::cerr.put('\n');
    }
    static Logcerr singleton;
    static void noopdtor(Logcerr*) {}
};
Logcerr Logcerr::singleton;
}

int Machine::log_detail = FLAME_WARN;
boost::shared_ptr<Machine::Logger> Machine::p_logger(&Logcerr::singleton, Logcerr::noopdtor);

void Machine::set_logger(const boost::shared_ptr<Logger> &p)
{
    boost::shared_ptr<Logger> temp(p);
    if(!temp)
        temp.reset(&Logcerr::singleton, Logcerr::noopdtor);
    {
        info_mutex_t::scoped_lock G(info_mutex);
        p_logger.swap(temp);
    }
}

Machine::LogRecord::~LogRecord()
{
    boost::shared_ptr<Logger> logger;
    {
        info_mutex_t::scoped_lock G(info_mutex);
        logger = p_logger;
    }
    logger->log(*this);
}

max_stars_repo_name: PierreSchnizer/FLAME

max_issues_repo_name: PierreSchnizer/FLAME

max_forks_repo_name: PierreSchnizer/FLAME


text:
/*=============================================================================
    Copyright (c) 2001-2007 Joel de Guzman
    Copyright (c) 2015 John Fletcher

    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)
==============================================================================*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

#include <boost/phoenix/core/limits.hpp>

#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/tuple.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/function.hpp>
#include <boost/phoenix/fusion.hpp>
#include <boost/phoenix/scope.hpp>

#include <typeinfo>

namespace fusion = boost::fusion;
namespace mpl = boost::mpl;

int
main()
{
    using boost::phoenix::let;
    using boost::phoenix::val;
    using boost::phoenix::arg_names::_1;
    using boost::phoenix::arg_names::_2;
    using boost::phoenix::local_names::_a;
    using boost::phoenix::local_names::_b;
    /*
    {
        // show that we can return a local from an outer scope
        int y = 0;
        int x = (let(_a = 1)[let(_b = _1)[ _a ]])(y);

        BOOST_TEST(x == 1);
    }
    {
        // show that we can return a local from an inner scope
        int y = 1;
        int x = (let(_a = 0)[let(_b = _1)[ _b ]])(y);

        BOOST_TEST(x == 1);
    }
    {
        // show that we can return a local from an outer scope
        //int y = 0;
        int x = (let(_a = 1)[let(_b = _a)[ _a ]])();

        BOOST_TEST(x == 1);
    }
    {
        // show that we can return a local from an inner scope
        //int y = 0;
        int x = (let(_a = 1)[let(_b = _a)[ _b ]])();

        BOOST_TEST(x == 1);
    }
    {
        // show that we can return a local from an outer scope
        int y = 1;
        int x = (let(_a = _1)[let(_b = _a)[ _a ]])(y);

        BOOST_TEST(x == 1);
    }
    {
        // show that we can return a local from an inner scope
        int y = 1;
        int x = (let(_a = _1)[let(_b = _a)[ _b ]])(y);

        BOOST_TEST(x == 1);
    }
    */
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Be very careful. Some of these cases give a silly answer
    // with clang 3.4 with C++03 and work for C++11.
    // gcc 4.8.2 seems O.K. both ways. Oh dear.
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    /*{
    int y = 0;
    int x = (let(_a = 1, _b = 2)[let(_b = _a)[ _a ]])(y);
    //std::cout << x << " P1A "; //clang - empty memory
        BOOST_TEST(x == 1);
  }
  {
    int y = 0;
    int x = (let(_a = 1, _b = 2)[let(_b = _a)[ _b ]])(y);
    //std::cout << x << " P1B "; //clang - 42 value- one step better
        BOOST_TEST(x == 1);
  }
  {
    int y = 0;
    int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _a ]])(y);
    //std::cout << x << " P2A "; //clang - 42 value - one step better
        BOOST_TEST(x == 1);
  }*/
  {
    int y = 0;
#if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 50000) && __OPTIMIZE__
    //int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _b ]])(y);
#else
    int x = (let(_a = val(1), _b = val(2))[let(_b = _a)[ _b ]])(y);
    //std::cout << x << " P2B "; //clang - 42 value - one step better
        BOOST_TEST(x == 1);
#endif
  }
  {
    int y = 1;
    int x = (let(_a = _1, _b = val(2))[let(_b = _a)[ _a ]])(y);
    //std::cout << x << " P3 "; //clang - OK - one step better still
        BOOST_TEST(x == 1);
  }

  {
    int y = 0;
#if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 50000) && __OPTIMIZE__
    int z = 2;
    int x = (let(_a = _1, _b = _2)[let(_b = _1)[ _a ]])(y,z);
#else
    int x = (let(_a = 1, _b = 2)[let(_b = _1)[ _a ]])(y);
#endif
    //    std::cout << x << " Q "; // clang 4201472
        BOOST_TEST(x == 1);
  }

    return boost::report_errors();
}


text:
/*=============================================================================
  Copyright (c) 2010-2016 Bolero MURAKAMI
  https://github.com/bolero-MURAKAMI/Sprig

  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)
=============================================================================*/
#ifndef SPRIG_TYPE_TRAITS_IS_FUSION_VECTOR_HPP
#define SPRIG_TYPE_TRAITS_IS_FUSION_VECTOR_HPP

#include <sprig/config/config.hpp>

#ifdef SPRIG_USING_PRAGMA_ONCE
#	pragma once
#endif	// #ifdef SPRIG_USING_PRAGMA_ONCE

#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/is_sequence.hpp>
#include <boost/fusion/include/value_at.hpp>
#include <boost/fusion/include/size.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/utility/enable_if.hpp>

namespace sprig {
	namespace is_fusion_vector_detail {
		//
		// optional_size
		//
		template<typename T>
		struct optional_size
			: public boost::mpl::eval_if<
				boost::fusion::traits::is_sequence<T>,
				boost::fusion::result_of::size<T>,
				boost::mpl::int_<-1>
			>::type
		{};
		//
		// optional_value_at_c
		//
		template<typename T, int N>
		struct optional_value_at_c
			: public boost::mpl::eval_if_c<
				(optional_size<T>::value > N),
				boost::fusion::result_of::value_at_c<T, N>,
				boost::mpl::identity<void>
			>
		{};
	}	// namespace is_fusion_vector_detail
	//
	// is_fusion_vector0
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector0
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector0<
		T,
		typename boost::enable_if<
			boost::is_same<
				T,
				boost::fusion::vector0<>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
	//
	// is_fusion_vector1
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector1
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector1<
		T,
		typename boost::enable_if<
			boost::is_same<
				T,
				boost::fusion::vector1<
					typename is_fusion_vector_detail::optional_value_at_c<T, 0>::type
				>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
	//
	// is_fusion_vector2
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector2
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector2<
		T,
		typename boost::enable_if<
			boost::is_same<
				T,
				boost::fusion::vector2<
					typename is_fusion_vector_detail::optional_value_at_c<T, 0>::type,
					typename is_fusion_vector_detail::optional_value_at_c<T, 1>::type
				>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
	//
	// is_fusion_vector3
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector3
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector3<
		T,
		typename boost::enable_if<
			boost::is_same<
				T,
				boost::fusion::vector3<
					typename is_fusion_vector_detail::optional_value_at_c<T, 0>::type,
					typename is_fusion_vector_detail::optional_value_at_c<T, 1>::type,
					typename is_fusion_vector_detail::optional_value_at_c<T, 2>::type
				>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
	//
	// is_fusion_vector_0
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector_0
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector_0<
		T,
		typename boost::enable_if<
			boost::mpl::and_<
				boost::mpl::bool_<is_fusion_vector_detail::optional_size<T>::value == 0>,
				boost::is_same<
					T,
					boost::fusion::vector<>
				>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
	//
	// is_fusion_vector_1
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector_1
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector_1<
		T,
		typename boost::enable_if<
			boost::mpl::and_<
				boost::mpl::bool_<is_fusion_vector_detail::optional_size<T>::value == 1>,
				boost::is_same<
					T,
					boost::fusion::vector<
						typename is_fusion_vector_detail::optional_value_at_c<T, 0>::type
					>
				>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
	//
	// is_fusion_vector_2
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector_2
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector_2<
		T,
		typename boost::enable_if<
			boost::mpl::and_<
				boost::mpl::bool_<is_fusion_vector_detail::optional_size<T>::value == 2>,
				boost::is_same<
					T,
					boost::fusion::vector<
						typename is_fusion_vector_detail::optional_value_at_c<T, 0>::type,
						typename is_fusion_vector_detail::optional_value_at_c<T, 1>::type
					>
				>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
	//
	// is_fusion_vector_3
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector_3
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector_3<
		T,
		typename boost::enable_if<
			boost::mpl::and_<
				boost::mpl::bool_<is_fusion_vector_detail::optional_size<T>::value == 3>,
				boost::is_same<
					T,
					boost::fusion::vector<
						typename is_fusion_vector_detail::optional_value_at_c<T, 0>::type,
						typename is_fusion_vector_detail::optional_value_at_c<T, 1>::type,
						typename is_fusion_vector_detail::optional_value_at_c<T, 2>::type
					>
				>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
	//
	// is_fusion_vector
	//
	template<typename T, typename Enable = void>
	struct is_fusion_vector
		: public boost::mpl::false_
	{};
	template<typename T>
	struct is_fusion_vector<
		T,
		typename boost::enable_if<
			boost::mpl::or_<
				is_fusion_vector_0<T>,
				is_fusion_vector_1<T>,
				is_fusion_vector_2<T>,
				is_fusion_vector_3<T>
			>
		>::type
	>
		: public boost::mpl::true_
	{};
}	// namespace sprig

#endif	// #ifndef SPRIG_TYPE_TRAITS_IS_FUSION_VECTOR_HPP

max_stars_repo_name: bolero-MURAKAMI/Sprig

max_issues_repo_name: bolero-MURAKAMI/Sprig

max_forks_repo_name: bolero-MURAKAMI/Sprig


text:
/*
 * Copyright 2021 Assured Information Security, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <introvirt/core/memory/guest_ptr.hh>
#include <introvirt/windows/kernel/nt/syscall/types/system_information/SYSTEM_PROCESS_INFORMATION.hh>

#include <boost/io/ios_state.hpp>

namespace introvirt {
namespace windows {
namespace nt {

namespace structs {

template <typename PtrType>
struct _VM_COUNTERS {
    PtrType PeakVirtualSize;
    PtrType VirtualSize;
    uint32_t PageFaultCount;
    PtrType PeakWorkingSetSize;
    PtrType WorkingSetSize;
    PtrType QuotaPeakPagedPoolUsage;
    PtrType QuotaPagedPoolUsage;
    PtrType QuotaPeakNonPagedPoolUsage;
    PtrType QuotaNonPagedPoolUsage;
    PtrType PagefileUsage;
    PtrType PeakPagefileUsage;
    PtrType PrivatePageCount;
};

} // namespace structs

template <typename PtrType>
class VM_COUNTERS_IMPL final : public VM_COUNTERS {
  public:
    uint64_t PeakVirtualSize() const override { return this->ptr_->PeakVirtualSize; }
    void PeakVirtualSize(uint64_t PeakVirtualSize) override {
        this->ptr_->PeakVirtualSize = PeakVirtualSize;
    }

    uint64_t VirtualSize() const override { return this->ptr_->VirtualSize; }
    void VirtualSize(uint64_t VirtualSize) override { this->ptr_->VirtualSize = VirtualSize; }

    uint32_t PageFaultCount() const override { return this->ptr_->PageFaultCount; }
    void PageFaultCount(uint32_t PageFaultCount) override {
        this->ptr_->PageFaultCount = PageFaultCount;
    }

    uint64_t PeakWorkingSetSize() const override { return this->ptr_->PeakWorkingSetSize; }
    void PeakWorkingSetSize(uint64_t PeakWorkingSetSize) override {
        this->ptr_->PeakWorkingSetSize = PeakWorkingSetSize;
    }

    uint64_t WorkingSetSize() const override { return this->ptr_->WorkingSetSize; }
    void WorkingSetSize(uint64_t WorkingSetSize) override {
        this->ptr_->WorkingSetSize = WorkingSetSize;
    }

    uint64_t QuotaPeakPagedPoolUsage() const override {
        return this->ptr_->QuotaPeakPagedPoolUsage;
    }
    void QuotaPeakPagedPoolUsage(uint64_t QuotaPeakPagedPoolUsage) override {
        this->ptr_->QuotaPeakPagedPoolUsage = QuotaPeakPagedPoolUsage;
    }

    uint64_t QuotaPagedPoolUsage() const override { return this->ptr_->QuotaPagedPoolUsage; }
    void QuotaPagedPoolUsage(uint64_t QuotaPagedPoolUsage) override {
        this->ptr_->QuotaPagedPoolUsage = QuotaPagedPoolUsage;
    }

    uint64_t QuotaPeakNonPagedPoolUsage() const override {
        return this->ptr_->QuotaPeakNonPagedPoolUsage;
    }
    void QuotaPeakNonPagedPoolUsage(uint64_t QuotaPeakNonPagedPoolUsage) override {
        this->ptr_->QuotaPeakNonPagedPoolUsage = QuotaPeakNonPagedPoolUsage;
    }

    uint64_t QuotaNonPagedPoolUsage() const override { return this->ptr_->QuotaNonPagedPoolUsage; }
    void QuotaNonPagedPoolUsage(uint64_t QuotaNonPagedPoolUsage) override {
        this->ptr_->QuotaNonPagedPoolUsage = QuotaNonPagedPoolUsage;
    }

    uint64_t PagefileUsage() const override { return this->ptr_->PagefileUsage; }
    void PagefileUsage(uint64_t PagefileUsage) override {
        this->ptr_->PagefileUsage = PagefileUsage;
    }

    uint64_t PeakPagefileUsage() const override { return this->ptr_->PeakPagefileUsage; }
    void PeakPagefileUsage(uint64_t PeakPagefileUsage) override {
        this->ptr_->PeakPagefileUsage = PeakPagefileUsage;
    }

    uint64_t PrivatePageCount() const override { return this->ptr_->PrivatePageCount; }
    void PrivatePageCount(uint64_t PrivatePageCount) override {
        this->ptr_->PrivatePageCount = PrivatePageCount;
    }

    virtual void write(std::ostream& os, const std::string& linePrefix = "") const override {
        boost::io::ios_flags_saver ifs(os);
        os << std::dec;
        os << linePrefix << "PeakVirtualSize: " << PeakVirtualSize() << '\n';
        os << linePrefix << "VirtualSize: " << VirtualSize() << '\n';
        os << linePrefix << "PageFaultCount: " << PageFaultCount() << '\n';
        os << linePrefix << "PeakWorkingSetSize: " << PeakWorkingSetSize() << '\n';
        os << linePrefix << "WorkingSetSize: " << WorkingSetSize() << '\n';
        os << linePrefix << "QuotaPeakPagedPoolUsage: " << QuotaPeakPagedPoolUsage() << '\n';
        os << linePrefix << "QuotaPagedPoolUsage: " << QuotaPagedPoolUsage() << '\n';
        os << linePrefix << "QuotaPeakNonPagedPoolUsage: " << QuotaPeakNonPagedPoolUsage() << '\n';
        os << linePrefix << "QuotaNonPagedPoolUsage: " << QuotaNonPagedPoolUsage() << '\n';
        os << linePrefix << "PagefileUsage: " << PagefileUsage() << '\n';
        os << linePrefix << "PeakPagefileUsage: " << PeakPagefileUsage() << '\n';
        os << linePrefix << "PrivatePageCount: " << PrivatePageCount() << '\n';
    }

    virtual Json::Value json() const override {
        Json::Value result;
        result["PeakVirtualSize"] = PeakVirtualSize();
        result["VirtualSize"] = VirtualSize();
        result["PageFaultCount"] = PageFaultCount();
        result["PeakWorkingSetSize"] = PeakWorkingSetSize();
        result["WorkingSetSize"] = WorkingSetSize();
        result["QuotaPeakPagedPoolUsage"] = QuotaPeakPagedPoolUsage();
        result["QuotaPagedPoolUsage"] = QuotaPagedPoolUsage();
        result["QuotaPeakNonPagedPoolUsage"] = QuotaPeakNonPagedPoolUsage();
        result["QuotaNonPagedPoolUsage"] = QuotaNonPagedPoolUsage();
        result["PagefileUsage"] = PagefileUsage();
        result["PeakPagefileUsage"] = PeakPagefileUsage();
        result["PrivatePageCount"] = PrivatePageCount();
        return result;
    }

    guest_ptr<void> ptr() const override { return ptr_; }

    VM_COUNTERS_IMPL(const guest_ptr<void>& ptr) : ptr_(ptr) {}

  private:
    guest_ptr<structs::_VM_COUNTERS<PtrType>> ptr_;
};

} // namespace nt
} // namespace windows
} // namespace introvirt

ext: hh

max_stars_repo_name: IntroVirt/IntroVirt

max_issues_repo_name: IntroVirt/IntroVirt

max_forks_repo_name: IntroVirt/IntroVirt


text:
/*=============================================================================
    Copyright (c) 2006 Tobias Schwinger
    Copyright (c) 2002-2006 Hartmut Kaiser
    http://spirit.sourceforge.net/

    Use, modification and distribution is subject to 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(BOOST_SPIRIT_POSITION_ITERATOR_FWD_HPP)
#define BOOST_SPIRIT_POSITION_ITERATOR_FWD_HPP

#include <string>
#include <boost/detail/iterator.hpp> // for boost::detail::iterator_traits
#include <boost/spirit/core/nil.hpp>

namespace boost { namespace spirit {

    template <typename String = std::string>
    struct file_position_base;

    typedef file_position_base<std::string> file_position;

    template <typename String = std::string>
    struct file_position_without_column_base;

    typedef file_position_without_column_base<std::string> file_position_without_column;

    template <
        typename ForwardIteratorT,
        typename PositionT = file_position_base<
            std::basic_string<
                typename boost::detail::iterator_traits<ForwardIteratorT>::value_type
            >
        >,
        typename SelfT = nil_t
    >
    class position_iterator;

    template
    <
        typename ForwardIteratorT,
        typename PositionT = file_position_base<
            std::basic_string<
                typename boost::detail::iterator_traits<ForwardIteratorT>::value_type
            >
        >
    >
    class position_iterator2;

    template <typename PositionT> class position_policy;

}} // namespace boost::spirit

#endif

max_stars_repo_name: dstrigl/mcotf

max_issues_repo_name: dstrigl/mcotf

max_forks_repo_name: dstrigl/mcotf


text:
//
// Copyright 2010-2012,2014 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#ifndef INCLUDED_UHD_USRP_MULTI_USRP_HPP
#define INCLUDED_UHD_USRP_MULTI_USRP_HPP

//define API capabilities for compile time detection of new features
#define UHD_USRP_MULTI_USRP_REF_SOURCES_API
#define UHD_USRP_MULTI_USRP_GET_RATES_API
#define UHD_USRP_MULTI_USRP_FRONTEND_CAL_API
#define UHD_USRP_MULTI_USRP_COMMAND_TIME_API
#define UHD_USRP_MULTI_USRP_BW_RANGE_API
#define UHD_USRP_MULTI_USRP_USER_REGS_API
#define UHD_USRP_MULTI_USRP_GET_USRP_INFO_API

#include <uhd/config.hpp>
#include <uhd/device.hpp>
#include <uhd/deprecated.hpp>
#include <uhd/types/ranges.hpp>
#include <uhd/types/stream_cmd.hpp>
#include <uhd/types/tune_request.hpp>
#include <uhd/types/tune_result.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/usrp/subdev_spec.hpp>
#include <uhd/usrp/dboard_iface.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <complex>
#include <string>
#include <vector>

namespace uhd{ namespace usrp{

/*!
 * The Multi-USRP device class:
 *
 * This class facilitates ease-of-use for most use-case scenarios.
 * The wrapper provides convenience functions to tune the devices,
 * set the dboard gains, antennas, filters, and other properties.
 * This class can be used to interface with a single USRP with
 * one or more channels, or multiple USRPs in a homogeneous setup.
 * All members take an optional parameter for board number or channel number.
 * In the single device, single channel case, these parameters can be unspecified.
 *
 * When using a single device with multiple channels:
 *  - Channel mapping is determined by the frontend specifications
 *  - All channels share a common RX sample rate
 *  - All channels share a common TX sample rate
 *
 * When using multiple devices in a configuration:
 *  - Channel mapping is determined by the device address arguments
 *  - All boards share a common RX sample rate
 *  - All boards share a common TX sample rate
 *  - All boards share a common RX frontend specification size
 *  - All boards share a common TX frontend specification size
 *  - All boards must have synchronized times (see the set_time_*() calls)
 *
 * Example to setup channel mapping for multiple devices:
 * <pre>
 *
 * //create a multi_usrp with two boards in the configuration
 * device_addr_t dev_addr;
 * dev_addr["addr0"] = "192.168.10.2"
 * dev_addr["addr1"] = "192.168.10.3";
 * multi_usrp::sptr dev = multi_usrp::make(dev_addr);
 *
 * //set the board on 10.2 to use the A RX frontend (RX channel 0)
 * dev->set_rx_subdev_spec("A:A", 0);
 *
 * //set the board on 10.3 to use the B RX frontend (RX channel 1)
 * dev->set_rx_subdev_spec("A:B", 1);
 *
 * //set both boards to use the AB TX frontend (TX channels 0 and 1)
 * dev->set_tx_subdev_spec("A:AB", multi_usrp::ALL_MBOARDS);
 *
 * //now that all the channels are mapped, continue with configuration...
 *
 * </pre>
 */
class UHD_API multi_usrp : boost::noncopyable{
public:
    typedef boost::shared_ptr<multi_usrp> sptr;

    virtual ~multi_usrp(void) = 0;

    //! A wildcard motherboard index
    static const size_t ALL_MBOARDS = size_t(~0);

    //! A wildcard channel index
    static const size_t ALL_CHANS = size_t(~0);

    //! A wildcard gain element name
    static const std::string ALL_GAINS;

    /*!
     * Make a new multi usrp from the device address.
     * \param dev_addr the device address
     * \return a new single usrp object
     */
    static sptr make(const device_addr_t &dev_addr);

    /*!
     * Get the underlying device object.
     * This is needed to get access to the streaming API and properties.
     * \return the device object within this single usrp
     */
    virtual device::sptr get_device(void) = 0;

    //! Convenience method to get a RX streamer. See also uhd::device::get_rx_stream().
    virtual rx_streamer::sptr get_rx_stream(const stream_args_t &args) = 0;

    //! Convenience method to get a TX streamer. See also uhd::device::get_rx_stream().
    virtual tx_streamer::sptr get_tx_stream(const stream_args_t &args) = 0;

    /*!
     * Returns identifying information about this USRP's configuration.
     * Returns motherboard ID, name, and serial.
     * Returns daughterboard RX ID, subdev name and spec, serial, and antenna.
     * \param chan channel index 0 to N-1
     * \return RX info
     */
    virtual dict<std::string, std::string> get_usrp_rx_info(size_t chan = 0) = 0;

    /*!
     * Returns identifying information about this USRP's configuration.
     * Returns motherboard ID, name, and serial.
     * Returns daughterboard TX ID, subdev name and spec, serial, and antenna.
     * \param chan channel index 0 to N-1
     * \return TX info
     */
     virtual dict<std::string, std::string> get_usrp_tx_info(size_t chan = 0) = 0;

    /*******************************************************************
     * Mboard methods
     ******************************************************************/

    /*!
     * Set the master clock rate.
     * This controls the rate of the clock that feeds the FPGA DSP.
     * On some devices, this re-tunes the clock to the specified rate.
     * If the specified rate is not available, this method will throw.
     * On other devices, this method notifies the software of the rate,
     * but requires the the user has made the necessary hardware change.
     * \param rate the new master clock rate in Hz
     * \param mboard the motherboard index 0 to M-1
     */
    virtual void set_master_clock_rate(double rate, size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Get the master clock rate.
     * \param mboard the motherboard index 0 to M-1
     * \return the master clock rate in Hz.
     */
    virtual double get_master_clock_rate(size_t mboard = 0) = 0;

    /*!
     * Get a printable summary for this USRP configuration.
     * \return a printable string
     */
    virtual std::string get_pp_string(void) = 0;

    /*!
     * Get canonical name for this USRP motherboard.
     * \param mboard which motherboard to query
     * \return a string representing the name
     */
    virtual std::string get_mboard_name(size_t mboard = 0) = 0;

    /*!
     * Get the current time in the usrp time registers.
     * \param mboard which motherboard to query
     * \return a timespec representing current usrp time
     */
    virtual time_spec_t get_time_now(size_t mboard = 0) = 0;

    /*!
     * Get the time when the last pps pulse occured.
     * \param mboard which motherboard to query
     * \return a timespec representing the last pps
     */
    virtual time_spec_t get_time_last_pps(size_t mboard = 0) = 0;

    /*!
     * Sets the time registers on the usrp immediately.
     *
     * If only one MIMO master is present in your configuration, set_time_now is
     * safe to use because the slave's time automatically follows the master's time.
     * Otherwise, this call cannot set the time synchronously across multiple devices.
     * Please use the set_time_next_pps or set_time_unknown_pps calls with a PPS signal.
     *
     * \param time_spec the time to latch into the usrp device
     * \param mboard the motherboard index 0 to M-1
     */
    virtual void set_time_now(const time_spec_t &time_spec, size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Set the time registers on the usrp at the next pps tick.
     * The values will not be latched in until the pulse occurs.
     * It is recommended that the user sleep(1) after calling to ensure
     * that the time registers will be in a known state prior to use.
     *
     * Note: Because this call sets the time on the "next" pps,
     * the seconds in the time spec should be current seconds + 1.
     *
     * \param time_spec the time to latch into the usrp device
     * \param mboard the motherboard index 0 to M-1
     */
    virtual void set_time_next_pps(const time_spec_t &time_spec, size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Synchronize the times across all motherboards in this configuration.
     * Use this method to sync the times when the edge of the PPS is unknown.
     *
     * Ex: Host machine is not attached to serial port of GPSDO
     * and can therefore not query the GPSDO for the PPS edge.
     *
     * This is a 2-step process, and will take at most 2 seconds to complete.
     * Upon completion, the times will be synchronized to the time provided.
     *
     * - Step1: wait for the last pps time to transition to catch the edge
     * - Step2: set the time at the next pps (synchronous for all boards)
     *
     * \param time_spec the time to latch at the next pps after catching the edge
     */
    virtual void set_time_unknown_pps(const time_spec_t &time_spec) = 0;

    /*!
     * Are the times across all motherboards in this configuration synchronized?
     * Checks that all time registers are approximately close but not exact,
     * given that the RTT may varying for a control packet transaction.
     * \return true when all motherboards time registers are in sync
     */
    virtual bool get_time_synchronized(void) = 0;

    /*!
     * Set the time at which the control commands will take effect.
     *
     * A timed command will back-pressure all subsequent timed commands,
     * assuming that the subsequent commands occur within the time-window.
     * If the time spec is late, the command will be activated upon arrival.
     *
     * \param time_spec the time at which the next command will activate
     * \param mboard which motherboard to set the config
     */
    virtual void set_command_time(const uhd::time_spec_t &time_spec, size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Clear the command time so future commands are sent ASAP.
     *
     * \param mboard which motherboard to set the config
     */
    virtual void clear_command_time(size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Issue a stream command to the usrp device.
     * This tells the usrp to send samples into the host.
     * See the documentation for stream_cmd_t for more info.
     *
     * With multiple devices, the first stream command in a chain of commands
     * should have a time spec in the near future and stream_now = false;
     * to ensure that the packets can be aligned by their time specs.
     *
     * \param stream_cmd the stream command to issue
     * \param chan the channel index 0 to N-1
     */
    virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd, size_t chan = ALL_CHANS) = 0;

    /*!
     * Set the clock configuration for the usrp device.
     * DEPRECATED in favor of set time and clock source calls.
     * This tells the usrp how to get a 10MHz reference and PPS clock.
     * See the documentation for clock_config_t for more info.
     * \param clock_config the clock configuration to set
     * \param mboard which motherboard to set the config
     */
    virtual void set_clock_config(const clock_config_t &clock_config, size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Set the time source for the usrp device.
     * This sets the method of time synchronization,
     * typically a pulse per second or an encoded time.
     * Typical options for source: external, MIMO.
     * \param source a string representing the time source
     * \param mboard which motherboard to set the config
     */
    virtual void set_time_source(const std::string &source, const size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Get the currently set time source.
     * \param mboard which motherboard to get the config
     * \return the string representing the time source
     */
    virtual std::string get_time_source(const size_t mboard) = 0;

    /*!
     * Get a list of possible time sources.
     * \param mboard which motherboard to get the list
     * \return a vector of strings for possible settings
     */
    virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;

    /*!
     * Set the clock source for the usrp device.
     * This sets the source for a 10 MHz reference clock.
     * Typical options for source: internal, external, MIMO.
     * \param source a string representing the clock source
     * \param mboard which motherboard to set the config
     */
    virtual void set_clock_source(const std::string &source, const size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Get the currently set clock source.
     * \param mboard which motherboard to get the config
     * \return the string representing the clock source
     */
    virtual std::string get_clock_source(const size_t mboard) = 0;

    /*!
     * Get a list of possible clock sources.
     * \param mboard which motherboard to get the list
     * \return a vector of strings for possible settings
     */
    virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;

    /*!
     * Send the clock source to an output connector.
     * This call is only applicable on devices with reference outputs.
     * By default, the reference output will be enabled for ease of use.
     * This call may be used to enable or disable the output.
     * \param enb true to output the clock source.
     * \param mboard which motherboard to set
     */
    virtual void set_clock_source_out(const bool enb, const size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Send the time source to an output connector.
     * This call is only applicable on devices with PPS outputs.
     * By default, the PPS output will be enabled for ease of use.
     * This call may be used to enable or disable the output.
     * \param enb true to output the time source.
     * \param mboard which motherboard to set
     */
    virtual void set_time_source_out(const bool enb, const size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Get the number of USRP motherboards in this configuration.
     */
    virtual size_t get_num_mboards(void) = 0;

    /*!
     * Get a motherboard sensor value.
     * \param name the name of the sensor
     * \param mboard the motherboard index 0 to M-1
     * \return a sensor value object
     */
    virtual sensor_value_t get_mboard_sensor(const std::string &name, size_t mboard = 0) = 0;

    /*!
     * Get a list of possible motherboard sensor names.
     * \param mboard the motherboard index 0 to M-1
     * \return a vector of sensor names
     */
    virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;

    /*!
     * Perform write on the user configuration register bus. These only exist if
     * the user has implemented custom setting registers in the device FPGA.
     * \param addr 8-bit register address
     * \param data 32-bit register value
     * \param mboard which motherboard to set the user register
     */
    virtual void set_user_register(const boost::uint8_t addr, const boost::uint32_t data, size_t mboard = ALL_MBOARDS) = 0;

    /*******************************************************************
     * RX methods
     ******************************************************************/
    /*!
     * Set the RX frontend specification:
     * The subdev spec maps a physical part of a daughter-board to a channel number.
     * Set the subdev spec before calling into any methods with a channel number.
     * The subdev spec must be the same size across all motherboards.
     * \param spec the new frontend specification
     * \param mboard the motherboard index 0 to M-1
     */
    virtual void set_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec, size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Get the RX frontend specification.
     * \param mboard the motherboard index 0 to M-1
     * \return the frontend specification in use
     */
    virtual uhd::usrp::subdev_spec_t get_rx_subdev_spec(size_t mboard = 0) = 0;

    /*!
     * Get the number of RX channels in this configuration.
     * This is the number of USRPs times the number of RX channels per board,
     * where the number of RX channels per board is homogeneous among all USRPs.
     */
    virtual size_t get_rx_num_channels(void) = 0;

    /*!
     * Get the name of the RX frontend.
     * \param chan the channel index 0 to N-1
     * \return the frontend name
     */
    virtual std::string get_rx_subdev_name(size_t chan = 0) = 0;

    /*!
     * Set the RX sample rate.
     * \param rate the rate in Sps
     * \param chan the channel index 0 to N-1
     */
    virtual void set_rx_rate(double rate, size_t chan = ALL_CHANS) = 0;

    /*!
     * Gets the RX sample rate.
     * \param chan the channel index 0 to N-1
     * \return the rate in Sps
     */
    virtual double get_rx_rate(size_t chan = 0) = 0;

    /*!
     * Get a range of possible RX rates.
     * \param chan the channel index 0 to N-1
     * \return the meta range of rates
     */
    virtual meta_range_t get_rx_rates(size_t chan = 0) = 0;

    /*!
     * Set the RX center frequency.
     * \param tune_request tune request instructions
     * \param chan the channel index 0 to N-1
     * \return a tune result object
     */
    virtual tune_result_t set_rx_freq(
        const tune_request_t &tune_request, size_t chan = 0
    ) = 0;

    /*!
     * Get the RX center frequency.
     * \param chan the channel index 0 to N-1
     * \return the frequency in Hz
     */
    virtual double get_rx_freq(size_t chan = 0) = 0;

    /*!
     * Get the RX center frequency range.
     * This range includes the overall tunable range of the RX chain,
     * including frontend chain and digital down conversion chain.
     * This tunable limit does not include the baseband bandwidth;
     * users should assume that the actual range is +/- samp_rate/2.
     * \param chan the channel index 0 to N-1
     * \return a frequency range object
     */
    virtual freq_range_t get_rx_freq_range(size_t chan = 0) = 0;

    /*!
     * Get the center frequency range of the RF frontend.
     * \param chan the channel index 0 to N-1
     * \return a frequency range object
     */
    virtual freq_range_t get_fe_rx_freq_range(size_t chan = 0) = 0;

    /*!
     * Set the RX gain value for the specified gain element.
     * For an empty name, distribute across all gain elements.
     * \param gain the gain in dB
     * \param name the name of the gain element
     * \param chan the channel index 0 to N-1
     */
    virtual void set_rx_gain(double gain, const std::string &name, size_t chan = 0) = 0;

    //! A convenience wrapper for setting overall RX gain
    void set_rx_gain(double gain, size_t chan = 0){
        return this->set_rx_gain(gain, ALL_GAINS, chan);
    }

    /*!
     * Get the RX gain value for the specified gain element.
     * For an empty name, sum across all gain elements.
     * \param name the name of the gain element
     * \param chan the channel index 0 to N-1
     * \return the gain in dB
     */
    virtual double get_rx_gain(const std::string &name, size_t chan = 0) = 0;

    //! A convenience wrapper for getting overall RX gain
    double get_rx_gain(size_t chan = 0){
        return this->get_rx_gain(ALL_GAINS, chan);
    }

    /*!
     * Get the RX gain range for the specified gain element.
     * For an empty name, calculate the overall gain range.
     * \param name the name of the gain element
     * \param chan the channel index 0 to N-1
     * \return a gain range object
     */
    virtual gain_range_t get_rx_gain_range(const std::string &name, size_t chan = 0) = 0;

    //! A convenience wrapper for getting overall RX gain range
    gain_range_t get_rx_gain_range(size_t chan = 0){
        return this->get_rx_gain_range(ALL_GAINS, chan);
    }

    /*!
     * Get the names of the gain elements in the RX chain.
     * Gain elements are ordered from antenna to FPGA.
     * \param chan the channel index 0 to N-1
     * \return a vector of gain element names
     */
    virtual std::vector<std::string> get_rx_gain_names(size_t chan = 0) = 0;

    /*!
     * Select the RX antenna on the frontend.
     * \param ant the antenna name
     * \param chan the channel index 0 to N-1
     */
    virtual void set_rx_antenna(const std::string &ant, size_t chan = 0) = 0;

    /*!
     * Get the selected RX antenna on the frontend.
     * \param chan the channel index 0 to N-1
     * \return the antenna name
     */
    virtual std::string get_rx_antenna(size_t chan = 0) = 0;

    /*!
     * Get a list of possible RX antennas on the frontend.
     * \param chan the channel index 0 to N-1
     * \return a vector of antenna names
     */
    virtual std::vector<std::string> get_rx_antennas(size_t chan = 0) = 0;

    /*!
     * Set the RX bandwidth on the frontend.
     * \param bandwidth the bandwidth in Hz
     * \param chan the channel index 0 to N-1
     */
    virtual void set_rx_bandwidth(double bandwidth, size_t chan = 0) = 0;

    /*!
     * Get the RX bandwidth on the frontend.
     * \param chan the channel index 0 to N-1
     * \return the bandwidth in Hz
     */
    virtual double get_rx_bandwidth(size_t chan = 0) = 0;

    /*!
     * Get the range of the possible RX bandwidth settings.
     * \param chan the channel index 0 to N-1
     * \return a range of bandwidths in Hz
     */
    virtual meta_range_t get_rx_bandwidth_range(size_t chan = 0) = 0;

    /*!
     * Get the dboard interface object for the RX frontend.
     * The dboard interface gives access to GPIOs, SPI, I2C, low-speed ADC and DAC.
     * Use at your own risk!
     * \param chan the channel index 0 to N-1
     * \return the dboard interface sptr
     */
    virtual dboard_iface::sptr get_rx_dboard_iface(size_t chan = 0) = 0;

    /*!
     * Get an RX frontend sensor value.
     * \param name the name of the sensor
     * \param chan the channel index 0 to N-1
     * \return a sensor value object
     */
    virtual sensor_value_t get_rx_sensor(const std::string &name, size_t chan = 0) = 0;

    /*!
     * Get a list of possible RX frontend sensor names.
     * \param chan the channel index 0 to N-1
     * \return a vector of sensor names
     */
    virtual std::vector<std::string> get_rx_sensor_names(size_t chan = 0) = 0;

    /*!
     * Enable/disable the automatic RX DC offset correction.
     * The automatic correction subtracts out the long-run average.
     *
     * When disabled, the averaging option operation is halted.
     * Once halted, the average value will be held constant
     * until the user re-enables the automatic correction
     * or overrides the value by manually setting the offset.
     *
     * \param enb true to enable automatic DC offset correction
     * \param chan the channel index 0 to N-1
     */
    virtual void set_rx_dc_offset(const bool enb, size_t chan = ALL_CHANS) = 0;

    /*!
     * Set a constant RX DC offset value.
     * The value is complex to control both I and Q.
     * Only set this when automatic correction is disabled.
     * \param offset the dc offset (1.0 is full-scale)
     * \param chan the channel index 0 to N-1
     */
    virtual void set_rx_dc_offset(const std::complex<double> &offset, size_t chan = ALL_CHANS) = 0;

    /*!
     * Set the RX frontend IQ imbalance correction.
     * Use this to adjust the magnitude and phase of I and Q.
     *
     * \param correction the complex correction (1.0 is full-scale)
     * \param chan the channel index 0 to N-1
     */
    virtual void set_rx_iq_balance(const std::complex<double> &correction, size_t chan = ALL_CHANS) = 0;

    /*******************************************************************
     * TX methods
     ******************************************************************/
    /*!
     * Set the TX frontend specification:
     * The subdev spec maps a physical part of a daughter-board to a channel number.
     * Set the subdev spec before calling into any methods with a channel number.
     * The subdev spec must be the same size across all motherboards.
     * \param spec the new frontend specification
     * \param mboard the motherboard index 0 to M-1
     */
    virtual void set_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec, size_t mboard = ALL_MBOARDS) = 0;

    /*!
     * Get the TX frontend specification.
     * \param mboard the motherboard index 0 to M-1
     * \return the frontend specification in use
     */
    virtual uhd::usrp::subdev_spec_t get_tx_subdev_spec(size_t mboard = 0) = 0;

    /*!
     * Get the number of TX channels in this configuration.
     * This is the number of USRPs times the number of TX channels per board,
     * where the number of TX channels per board is homogeneous among all USRPs.
     */
    virtual size_t get_tx_num_channels(void) = 0;

    /*!
     * Get the name of the TX frontend.
     * \param chan the channel index 0 to N-1
     * \return the frontend name
     */
    virtual std::string get_tx_subdev_name(size_t chan = 0) = 0;

    /*!
     * Set the TX sample rate.
     * \param rate the rate in Sps
     * \param chan the channel index 0 to N-1
     */
    virtual void set_tx_rate(double rate, size_t chan = ALL_CHANS) = 0;

    /*!
     * Gets the TX sample rate.
     * \param chan the channel index 0 to N-1
     * \return the rate in Sps
     */
    virtual double get_tx_rate(size_t chan = 0) = 0;

    /*!
     * Get a range of possible TX rates.
     * \param chan the channel index 0 to N-1
     * \return the meta range of rates
     */
    virtual meta_range_t get_tx_rates(size_t chan = 0) = 0;

    /*!
     * Set the TX center frequency.
     * \param tune_request tune request instructions
     * \param chan the channel index 0 to N-1
     * \return a tune result object
     */
    virtual tune_result_t set_tx_freq(
        const tune_request_t &tune_request, size_t chan = 0
    ) = 0;

    /*!
     * Get the TX center frequency.
     * \param chan the channel index 0 to N-1
     * \return the frequency in Hz
     */
    virtual double get_tx_freq(size_t chan = 0) = 0;

    /*!
     * Get the TX center frequency range.
     * This range includes the overall tunable range of the TX chain,
     * including frontend chain and digital up conversion chain.
     * This tunable limit does not include the baseband bandwidth;
     * users should assume that the actual range is +/- samp_rate/2.
     * \param chan the channel index 0 to N-1
     * \return a frequency range object
     */
    virtual freq_range_t get_tx_freq_range(size_t chan = 0) = 0;

    /*!
     * Get the center frequency range of the TX frontend.
     * \param chan the channel index 0 to N-1
     * \return a frequency range object
     */
    virtual freq_range_t get_fe_tx_freq_range(size_t chan = 0) = 0;

    /*!
     * Set the TX gain value for the specified gain element.
     * For an empty name, distribute across all gain elements.
     * \param gain the gain in dB
     * \param name the name of the gain element
     * \param chan the channel index 0 to N-1
     */
    virtual void set_tx_gain(double gain, const std::string &name, size_t chan = 0) = 0;

    //! A convenience wrapper for setting overall TX gain
    void set_tx_gain(double gain, size_t chan = 0){
        return this->set_tx_gain(gain, ALL_GAINS, chan);
    }

    /*!
     * Get the TX gain value for the specified gain element.
     * For an empty name, sum across all gain elements.
     * \param name the name of the gain element
     * \param chan the channel index 0 to N-1
     * \return the gain in dB
     */
    virtual double get_tx_gain(const std::string &name, size_t chan = 0) = 0;

    //! A convenience wrapper for getting overall TX gain
    double get_tx_gain(size_t chan = 0){
        return this->get_tx_gain(ALL_GAINS, chan);
    }

    /*!
     * Get the TX gain range for the specified gain element.
     * For an empty name, calculate the overall gain range.
     * \param name the name of the gain element
     * \param chan the channel index 0 to N-1
     * \return a gain range object
     */
    virtual gain_range_t get_tx_gain_range(const std::string &name, size_t chan = 0) = 0;

    //! A convenience wrapper for getting overall TX gain range
    gain_range_t get_tx_gain_range(size_t chan = 0){
        return this->get_tx_gain_range(ALL_GAINS, chan);
    }

    /*!
     * Get the names of the gain elements in the TX chain.
     * Gain elements are ordered from antenna to FPGA.
     * \param chan the channel index 0 to N-1
     * \return a vector of gain element names
     */
    virtual std::vector<std::string> get_tx_gain_names(size_t chan = 0) = 0;

    /*!
     * Select the TX antenna on the frontend.
     * \param ant the antenna name
     * \param chan the channel index 0 to N-1
     */
    virtual void set_tx_antenna(const std::string &ant, size_t chan = 0) = 0;

    /*!
     * Get the selected TX antenna on the frontend.
     * \param chan the channel index 0 to N-1
     * \return the antenna name
     */
    virtual std::string get_tx_antenna(size_t chan = 0) = 0;

    /*!
     * Get a list of possible TX antennas on the frontend.
     * \param chan the channel index 0 to N-1
     * \return a vector of antenna names
     */
    virtual std::vector<std::string> get_tx_antennas(size_t chan = 0) = 0;

    /*!
     * Set the TX bandwidth on the frontend.
     * \param bandwidth the bandwidth in Hz
     * \param chan the channel index 0 to N-1
     */
    virtual void set_tx_bandwidth(double bandwidth, size_t chan = 0) = 0;

    /*!
     * Get the TX bandwidth on the frontend.
     * \param chan the channel index 0 to N-1
     * \return the bandwidth in Hz
     */
    virtual double get_tx_bandwidth(size_t chan = 0) = 0;

    /*!
     * Get the range of the possible TX bandwidth settings.
     * \param chan the channel index 0 to N-1
     * \return a range of bandwidths in Hz
     */
    virtual meta_range_t get_tx_bandwidth_range(size_t chan = 0) = 0;

    /*!
     * Get the dboard interface object for the TX frontend.
     * The dboard interface gives access to GPIOs, SPI, I2C, low-speed ADC and DAC.
     * Use at your own risk!
     * \param chan the channel index 0 to N-1
     * \return the dboard interface sptr
     */
    virtual dboard_iface::sptr get_tx_dboard_iface(size_t chan = 0) = 0;

    /*!
     * Get an TX frontend sensor value.
     * \param name the name of the sensor
     * \param chan the channel index 0 to N-1
     * \return a sensor value object
     */
    virtual sensor_value_t get_tx_sensor(const std::string &name, size_t chan = 0) = 0;

    /*!
     * Get a list of possible TX frontend sensor names.
     * \param chan the channel index 0 to N-1
     * \return a vector of sensor names
     */
    virtual std::vector<std::string> get_tx_sensor_names(size_t chan = 0) = 0;

    /*!
     * Set a constant TX DC offset value.
     * The value is complex to control both I and Q.
     * \param offset the dc offset (1.0 is full-scale)
     * \param chan the channel index 0 to N-1
     */
    virtual void set_tx_dc_offset(const std::complex<double> &offset, size_t chan = ALL_CHANS) = 0;

    /*!
     * Set the TX frontend IQ imbalance correction.
     * Use this to adjust the magnitude and phase of I and Q.
     *
     * \param correction the complex correction (1.0 is full-scale)
     * \param chan the channel index 0 to N-1
     */
    virtual void set_tx_iq_balance(const std::complex<double> &correction, size_t chan = ALL_CHANS) = 0;

    /*******************************************************************
     * GPIO methods
     ******************************************************************/

    /*!
     * Enumerate gpio banks on the specified device.
     * \param mboard the motherboard index 0 to M-1
     * \return a list of string for each bank name
     */
    virtual std::vector<std::string> get_gpio_banks(const size_t mboard) = 0;

    /*!
     * Set a GPIO attribute on a particular GPIO bank.
     * Possible attribute names:
     *  - CTRL - 1 for ATR mode 0 for GPIO mode
     *  - DDR - 1 for output 0 for input
     *  - OUT - GPIO output level (not ATR mode)
     *  - ATR_0X - ATR idle state
     *  - ATR_RX - ATR receive only state
     *  - ATR_TX - ATR transmit only state
     *  - ATR_XX - ATR full duplex state
     * \param bank the name of a GPIO bank
     * \param attr the name of a GPIO attribute
     * \param value the new value for this GPIO bank
     * \param mask the bit mask to effect which pins are changed
     * \param mboard the motherboard index 0 to M-1
     */
    virtual void set_gpio_attr(const std::string &bank, const std::string &attr, const boost::uint32_t value, const boost::uint32_t mask = 0xffffffff, const size_t mboard = 0) = 0;

    /*!
     * Get a GPIO attribute on a particular GPIO bank.
     * Possible attribute names:
     *  - CTRL - 1 for ATR mode 0 for GPIO mode
     *  - DDR - 1 for output 0 for input
     *  - OUT - GPIO output level (not ATR mode)
     *  - ATR_0X - ATR idle state
     *  - ATR_RX - ATR receive only state
     *  - ATR_TX - ATR transmit only state
     *  - ATR_XX - ATR full duplex state
     *  - READBACK - readback input GPIOs
     * \param bank the name of a GPIO bank
     * \param attr the name of a GPIO attribute
     * \param mboard the motherboard index 0 to M-1
     * \return the value set for this attribute
     */
    virtual boost::uint32_t get_gpio_attr(const std::string &bank, const std::string &attr, const size_t mboard = 0) = 0;

};

}}

#endif /* INCLUDED_UHD_USRP_MULTI_USRP_HPP */

max_stars_repo_name: cityscapesc/specobs

max_issues_repo_name: cityscapesc/specobs

max_forks_repo_name: cityscapesc/specobs


text:
// Copyright 2004-2008 Facebook. All Rights Reserved.
//
// See Canonical Style Document at:
//
//   http://www.dev.facebook.com/intern/wiki/index.php/CppStyle
//
// See additional comments in: fbcode/cppstyle/ExampleCode.h
//
// Note the #include order: First our related .h file, then C-style stdlib
// includes, C++ includes, boost includes, then fbcode/ includes in quotes
// ("").
//
// @author Mark Rabkin (mrabkin@facebook.com)

#include "cppstyle/CodeExample.h"

#include <stdio.h>
#include <ctype.h>

#include <functional>

#include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp>

#include "common/base/Base.h"
#include "common/base/Hash.h"
#include "common/time/Time.h"

namespace facebook { namespace example {

const string kCmDefaultKey = "hi";   // default key for complicated map
const pair<double, string> kCmDefaultVal = make_pair(1.5, "hi!11");

// ---------------------------------------------------------------------
// class ExampleClass
// ---------------------------------------------------------------------

// This additional comment is not in the javadoc style, as it's supposed to
// describe more concrete implementation details.  Any comments that may be
// useful to the class API "customer" (as opposed to someone who might modify
// this class) should instead be in JavaDoc style in ExampleCode.h.
ExampleClass::ExampleClass(int counterValue)
    : counterValue_(counterValue),
      name_("blah") {
  // add a default value to the complicated map
  complicatedMap_.insert(
    make_pair(kCmDefaultKey, kCmDefaultVal));

  for (ComplicatedMap::iterator it = complicatedMap_.begin();
       it != complicatedMap_.end(); ++it) {
    ComplicatedMap::value_type& val = (*it);
    valueList_.push_back(static_cast<int64_t>(val.second.first));
  }

  FOR_EACH(it, valueList_) {
    // TODO(mrabkin): this is useless code, fix it (but not really since this
    // is an example :P)
    int64_t val = (*it);
    val *= 2;
  }
}

const vector<int64_t>&
ExampleClass::funcWithManyArgs(int64_t count,
                               EnumType value,
                               const string& name,
                               const vector<string>& list,
                               const vector<string>* maybeList,
                               vector<double>* outVector) {
  // -------------------------------------------------------------------------
  // The body of this function is used to demonstrate common code constructs so
  // that the indentation, braces, and spacing styles for them are immediately
  // apparent.
  // -------------------------------------------------------------------------

  // This section demonstrates different kinds of if() blocks, including
  // long/short if() blocks, complicated if() expressions, and validity
  // checks on pointer/handle variables.

  if (count < 0) {
    ++count;
  } else if (count == 0) {
    --count;
  } else {
    count *= 2;
  }

  if (complicatedMap_.find(name) != complicatedMap_.end() &&
      complicatedMap_.size() > 10 &&
      (count < 0 || count > 5)) {
    valueList_.push_back(count);
  }

  if (!name.empty()) {
    count += name.size();
  }

  boost::scoped_ptr<int> scopedPtr;
  int* realPtr = NULL;
  if (!scopedPtr && !realPtr) {
    scopedPtr.reset(new int(10));
  }

  if (realPtr == NULL && scopedPtr.get() != NULL) {
    realPtr = scopedPtr.get();
  }

  // This section demonstrates looping constructs.
  for (vector<string>::const_iterator it = list.begin();
       it != list.end(); ++it) {
    count += it->size();
  }

  FOR_EACH(it, list) {
    count += it->size();
  }

  int i = 10;
  while (i > 0) {
    --i;
  }

  do {
   ++i;
  } while (i <= 10);

  // This section demonstrates formatting for basic expressions, operators, and
  // initializations.

  string s("startvalue");
  size_t someSize = sizeof(*realPtr);
  int val = count / 2;
  count = (count + val) & ((val << 3) + count * val);

  // Example of use of nested scope to limit lifetime of a mutex guard,
  // scoped ptr, or some other class with a non-trivial destructor.
  {
    scoped_ptr<int> ptr(new int(10));
    *ptr += 10;
  }

  return valueList_;
}

/* static */
ExampleClass* ExampleClass::getInstance() {
  return new ExampleClass();
}

} } // !namespace facebook::example

max_stars_repo_name: facebookarchive/ie-toolbar

max_issues_repo_name: facebookarchive/ie-toolbar

max_forks_repo_name: facebookarchive/ie-toolbar


text:
// Author(s): Jeroen van der Wulp
// Copyright: see the accompanying file COPYING or copy at
// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
//
// 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)
//
/// \file command_line_interface_test.cpp

#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#include <boost/test/included/unit_test.hpp>

#include "mcrl2/utilities/command_line_interface.h"

using namespace ::mcrl2::utilities;

enum streamable_enum {
    foo,
    bar
};

std::istream& operator>>(std::istream& in, streamable_enum& out)
{
  std::string word;
  in >> word;
  if (word == "foo")
  {
    out = foo;
  }
  else
  if (word == "bar")
  {
    out = bar;
  }
  else
  {
    in.setstate(std::ios_base::failbit);
  }
  return in;
}

std::ostream& operator<<(std::ostream& out, const streamable_enum& in)
{
  switch (in)
  {
  case foo:
    return out << "foo";
  case bar:
    return out << "bar";
  }
  return out << "invalid_streamable_enum";
}

BOOST_AUTO_TEST_CASE(border_invalid)
{
  interface_description test_interface("test", "TEST", "Kilroy", "[OPTIONS]... [PATH]", "whatis", "description");

  // Empty command line
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, ""));
  char    c = '\0';
  char*   pc = &c;
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, 0, &pc));
  wchar_t  w = L'\0';
  wchar_t* pw = &w;
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, 0, &pw));
}

BOOST_AUTO_TEST_CASE(parsing)
{
  interface_description test_interface("test", "TEST", "Kilroy", "[OPTIONS]... [PATH]", "whatis", "description");

  // Valid option -h
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -v"));
  // Repeated options --help options
  BOOST_CHECK_THROW(command_line_parser(test_interface, "test --verbose -v -v"), std::runtime_error);
  // Invalid combination of short options
  BOOST_CHECK_THROW(command_line_parser(test_interface, "test -ve"), std::runtime_error);

  // Duplicate long option without argument
  BOOST_CHECK_THROW(test_interface.add_option("verbose","An option"), std::logic_error);
  // Duplicate long option with short option and without argument
  BOOST_CHECK_THROW(test_interface.add_option("verbose", "An option", 'h'), std::logic_error);
  // Duplicate long option with short option and with optional argument
  BOOST_CHECK_THROW(test_interface.add_option("verbose",make_mandatory_argument("STR"), "An option", 'v'), std::logic_error);
  // Duplicate long option with short option and with optional argument
  BOOST_CHECK_THROW(test_interface.add_option("verbose",make_optional_argument("STR", "XxXxX"), "An option", 'v'), std::logic_error);

  test_interface.add_option("mandatory", make_mandatory_argument("STR"), "option with mandatory argument", 'm');
  // Missing mandatory argument for option --mandatory
  BOOST_CHECK_THROW(command_line_parser(test_interface, "test --mandatory"), std::runtime_error);
  // Valid option with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test --mandatory=test"));
  // Valid option with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -m=test"));
  // Valid option with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -m test"));
  // Valid short option v followed by option m with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -vm=test"));

  test_interface.add_option("optional", make_optional_argument("STR", "*XxXxX*"), "option with optional argument", 'o');
  // Missing mandatory argument for option --mandatory
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test --optional"));
  // Valid option with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test --optional=test"));
  // Valid option with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -otest"));
  // Valid option without argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -o test"));
  // Valid short option v followed by option m with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -vmtest"));
}

BOOST_AUTO_TEST_CASE(conformance)
{
  interface_description test_interface("test", "TEST", "Kilroy", "[OPTIONS]... [PATH]", "whatis", "description");

  // Valid options -v, --verbose
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -v"));
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test --verbose"));
  // Valid options -q, --quiet
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -q"));
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test --quiet"));
  // Valid options -d, --debug
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -d"));
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test --debug"));

  // Check conversion with wide characters
  wchar_t const* arguments[] = { L"test", L"--debug", L"--verbose=2" } ;

  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, 2, arguments));
  BOOST_CHECK_THROW(command_line_parser(test_interface, 3, arguments), std::runtime_error);
}

BOOST_AUTO_TEST_CASE(custom_types)
{
  auto arg = make_enum_argument<streamable_enum>("argument");
  arg.add_value_desc(foo, "Self-explanatory.");
  arg.add_value_desc(bar, "Also self-explanatory.", true);
  interface_description test_interface("test", "TEST", "Kilroy", "[OPTIONS]... [PATH]", "whatis", "description");
  test_interface.add_option("argument", arg, "either foo or bar.", 'a');

  // Missing mandatory argument for option --rewriter
  BOOST_CHECK_THROW(command_line_parser(test_interface, "test --argument"), std::runtime_error);
  // Valid rewriter option with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test --argument=foo"));
  // Valid rewriter option with valid argument
  BOOST_CHECK_NO_THROW(command_line_parser(test_interface, "test -afoo"));
  // Valid rewriter option with invalid argument
  BOOST_CHECK_THROW(command_line_parser(test_interface, "test --argument=baz"), std::runtime_error);
}

inline std::string const& first_of(command_line_parser const& p, std::string const& option)
{
  return p.options.equal_range(option).first->second;
}

inline std::string const& last_of(command_line_parser const& p, std::string const& option)
{
  command_line_parser::option_map::const_iterator i(p.options.equal_range(option).second);

  return (--i)->second;
}

BOOST_AUTO_TEST_CASE(result_browsing)
{
  interface_description test_interface("test", "TEST", "Kilroy", "[OPTIONS]... [PATH]", "whatis", "description");

  // disable check for duplicate options
  test_interface.add_option("cli-testing-no-duplicate-option-checking", "");

  {
    command_line_parser parser(test_interface, "test -v --debug -d --verbose");

    BOOST_CHECK(parser.options.size() == 4);
    BOOST_CHECK(parser.options.count("verbose") == 2);
    BOOST_CHECK(first_of(parser, "verbose").empty());
    BOOST_CHECK(last_of(parser, "verbose").empty());
    BOOST_CHECK_THROW(parser.option_argument("verbose"), std::logic_error);
    BOOST_CHECK(parser.options.count("debug") == 2);
    BOOST_CHECK(first_of(parser, "debug").empty());
    BOOST_CHECK(last_of(parser, "debug").empty());
    BOOST_CHECK(parser.options.count("quiet") == 0);
    BOOST_CHECK(parser.arguments.size() == 0);
  }

  {
    command_line_parser parser(test_interface, "test /bin/ls -v \\or\\more:1234567890|,<>.:;[]}{+-_=~!@#$%^&*()");

    BOOST_CHECK(parser.options.size() == 1);
    BOOST_CHECK(first_of(parser, "verbose").empty());
    BOOST_CHECK(parser.arguments.size() == 2);
    BOOST_CHECK(parser.arguments[0] == "/bin/ls");
    BOOST_CHECK(parser.arguments[1] == "\\or\\more:1234567890|,<>.:;[]}{+-_=~!@#$%^&*()");
  }

  test_interface.add_option("mandatory", make_mandatory_argument("STR"), "option with mandatory argument", 'm');
  test_interface.add_option("optional", make_optional_argument("STR", "4321"), "option with optional argument", 'o');

  {
    command_line_parser parser(test_interface, "test --mandatory=BLA --optional=1234 -vo -vmALB");

    BOOST_CHECK(parser.options.size() == 6);
    BOOST_CHECK(first_of(parser, "mandatory") != last_of(parser, "mandatory"));
    BOOST_CHECK((first_of(parser, "mandatory") == "BLA" && last_of(parser, "mandatory") == "ALB") ||
                (first_of(parser, "mandatory") == "ALB" && last_of(parser, "mandatory") == "BLA"));
    BOOST_CHECK((first_of(parser, "optional") == "4321" && last_of(parser, "optional") == "1234") ||
                (first_of(parser, "optional") == "1234" && last_of(parser, "optional") == "4321"));
    BOOST_CHECK(parser.option_argument_as< int >("optional") == 1234 ||
                parser.option_argument_as< int >("optional") == 4321);
    BOOST_CHECK(parser.arguments.size() == 0);
  }
  {
    command_line_parser parser(test_interface, "test -m BLA -o 1234");

    BOOST_CHECK(first_of(parser, "mandatory") == "BLA");
    BOOST_CHECK(parser.option_argument_as< int >("optional") == 4321);
    BOOST_CHECK(parser.arguments.size() == 1);
  }
}