Exemple #1
0
static void to_str(string& str, T &i){
    strm.clear();
    strm<<i;
    return strm.str();
}
Exemple #2
0
 std::string ToString() const
 { return _stream.str(); }
Exemple #3
0
static std::string Print(std::stringstream &os, const T &first, Ts... args) {
    os << first;
    Print(os, args...);
    return os.str();
}
Exemple #4
0
#include "XmlRpcMethods.h"
#include "Log.h"
#include "TapiConn.h"

using namespace XmlRpc;

XmlRpc::MultithreadXmlRpcServer *theServer = NULL;


XML_RPC_METHOD_IMPLEMENT(Logging_ON, "1st arg string line_extension, 2nd arg string user_extension")
{
	xBEGIN
	std::string line_extension;
	std::string user_extension;
	
	std::stringstream ss;
	params.write(ss);
	theLog->Debug(ss.str());
	
	if(params.getType() == XmlRpcValue::TypeArray && params[0].getType() == XmlRpcValue::TypeStruct)
	{
		line_extension = std::string(params[0]["line_extension"]);
		user_extension = std::string(params[0]["user_extension"]);
	}
	else
	{
		line_extension = std::string(params[0]);
		user_extension = std::string(params[1]);
	}
	theLog->Default(std::string("Received command: Logging_ON, ") + line_extension + ", " + user_extension);
	theTapiConn->Logging_ON(line_extension, user_extension);
  #if WRITE_TEC
  std::stringstream file_name_tec;
  file_name_tec <<result_file_name << "_"<< t_step<< ".tec" ;
  tec.write_equation_systems (file_name_tec.str(),equation_systems);
  std::cout<<"Wrote "<< file_name_tec.str() <<std::endl;
  #endif

    std::stringstream file_name;
    file_name << equation_systems.parameters.get<std::string>("result_file_name");
    file_name << std::setw(2) << std::setfill('0') << t_step;
    file_name << ".e-s.";
    file_name << std::setw(3) << std::setfill('0') << t_step;
		//exo.write_timestep(file_name.str(), equation_systems,t_step+1,time); 
		exo.write_timestep(file_name.str(), equation_systems,t_step+1,t_step); 
    std::cout<<"exodus "<< file_name.str() <<std::endl;
		exo.write_element_data(equation_systems);
   
  tree.write_tree(equation_systems);
Exemple #6
0
 void Flush() { sstream.flush(); }
Exemple #7
0
	void Emitter::PostWriteIntegralType(const std::stringstream& str)
	{
		m_stream << str.str();
		PostAtomicWrite();
	}
 *
*/
/**
 * @file printf_verilog_generator_n.cpp
 * @brief Snippet for the printf dynamimc generator when a multiple bus architecture is considered.
 *
 * @author Fabrizio Ferrandi <*****@*****.**>
 * $Revision$
 * $Date$
 * Last modified by $Author$
 *
*/
std::string fsm;
std::string case_statement;

std::stringstream _npString;
_npString<<(std::max(_np,2));
std::string selector_dimension=_npString.str();

std::stringstream _np1String;
_np1String<<(std::max(_np-1, 1));
std::string selector_left=_np1String.str();

int selector=1;
for(int i=0;i<_np;i++){
   std::stringstream _selector_string;
   _selector_string<<selector;
   std::stringstream _index_string;
   _index_string<<(i+1);
   case_statement+="            "+selector_dimension+"'d"+_selector_string.str()+":\n             begin\n               data1="+_p[i].name+";\n               data1_size=BITSIZE_in"+_index_string.str()+";\n             end\n";
   selector*=2;
Exemple #9
0
void localStat(float v, char const *n)
{
    localFlush_ << n << statSuffix_ << " " << localTime_ << " " << v << "\n";
    toHandle_.push_back(localFlush_.str());
    localFlush_.str("");
}
Exemple #10
0
bool DBInsert::addRow(std::stringstream& row)
{
	bool ret = addRow(row.str());
	row.str("");
	return ret;
}
modification::texception::texception(const std::stringstream& message_stream)
	: message(message_stream.str())
{
}
Exemple #12
0
int main()
{    
    Person person(PersonId("1"), FirstName("John"), LastName("Smith"), Address("Sea"), Birthday("Easter"), Children({PersonId("2"), PersonId("3")}));
    std::cout << "Person: " << person << std::endl;
    std::cout << ss.str() << std::endl;
}
void RSReflectionBase::write(const std::stringstream &t) {
  mText.push_back(mIndent + t.str());
}
Exemple #14
0
static void EmitIfNotEmpty (std::stringstream& out, const std::stringstream& str)
{
	if (str.str().size())
		out << str.str() << "\n";
}
Exemple #15
0
 void Put(char c) { sstream.put(c); }
Exemple #16
0
void test_()
{
    std::string const src("abcdefg");

    {
        g_ss.str("");
        std::stringstream& ss = oven::adapted_to<std::stringstream&>( copy(src, stream_writer(g_ss)) );
        BOOST_CHECK( equals(g_ss.str(), src) );
        BOOST_CHECK( pstade::egg::is_same(ss, g_ss) );
    }
    {
        g_ss.str("");
        std::stringstream& ss = oven::adapted_to<std::stringstream&>( copy(src, stream_writer(g_ss, ",")) );
        BOOST_CHECK( equals(g_ss.str(), std::string("a,b,c,d,e,f,g")) );
        BOOST_CHECK( pstade::egg::is_same(ss, g_ss) );
    }
#if 0 // seems not to be able to support reference type as 'to_base' target.
    {
        std::wstring rng(L"aabbbcccdddeffg");
        std::stringstream& ss = oven::unique_copy(rng, utf8_encoder |= stream_writer(g_ss))|to_base;
        BOOST_CHECK( pstade::egg::is_same(ss, g_ss) );
    }
#endif
    {
        g_ss.str("");
        copy(src, streambuf_writer(g_ss));
        BOOST_CHECK( equals(g_ss.str(), src) );
    }
    {
        g_ss.str("");
        copy(src, streambuf_writer(g_ss.rdbuf()));
        BOOST_CHECK( equals(g_ss.str(), src) );
    }
    {
        g_ss.str("");
        std::stringstream& ss = oven::adapted_to<std::stringstream&>( copy(src, std_stream_writer(g_ss)) );
        BOOST_CHECK( equals(g_ss.str(), src) );
        BOOST_CHECK( pstade::egg::is_same(ss, g_ss) );
    }
    {
        g_ss.str("");
        std::stringstream& ss = oven::adapted_to<std::stringstream&>( copy(src, std_stream_writer(g_ss, ",")) );
        BOOST_CHECK( equals(g_ss.str(), std::string("a,b,c,d,e,f,g,")) );
        BOOST_CHECK( pstade::egg::is_same(ss, g_ss) );
    }
    {
        g_ss.str("");
        test::output_iterator( stream_writer(g_ss), 'a' );
        test::output_iterator( streambuf_writer(g_ss.rdbuf()), 'a' );
        test::output_iterator( std_stream_writer(g_ss), 'a' );
        test::output_iterator( stream_writer(g_ss, ","), 'a' );
        test::output_iterator( std_stream_writer(g_ss, ","), 'a' );
    }
}
Exemple #17
0
 void PutN(char c, size_t n) { for (size_t i = 0; i < n; ++i) sstream.put(c); }
#include "iostream"
#include "catch_with_main.hpp"
#include "rational.hpp"
#include <iomanip>

TEST_CASE( "constructor, two_parameters" ){
   rational v( 3, 4 );
   std::stringstream s;
   s << v;
   REQUIRE( s.str() == "[3/4]" );   
}

TEST_CASE( "equality, equal" ){
   rational v( 1, 2 );
   REQUIRE( v == rational( 1, 2 ) ); 
}

TEST_CASE( "equality, unequal" ){
   rational v( 1, 2 );
   REQUIRE( ! ( v == rational( 1, 3 )) ); 
}

TEST_CASE( "constructor, two_parameters; reduction" ){
   rational v( 10, 2 );
   REQUIRE( v == rational( 5, 1 ) ); 
}

TEST_CASE( "constructor, one parameter" ){
   rational v( 6 );
   REQUIRE( v == rational( 6, 1 ) );   
}
void Dirichlet_LIMSolver2D::debugOutput(std::stringstream& info)
{
  std::cout << "LP: " << info.str() << "\n"; 
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TableData RifEclipseUserDataParserTools::tableDataFromText(std::stringstream& streamData, std::vector<std::string>* errorText)
{
    TableData emptyTable;

    std::string origin = "";
    std::string dateFormat = "";
    std::string startDate = "";

    std::string firstLine;
    std::getline(streamData, firstLine);

    while (isLineSkippable(firstLine) || keywordParser(firstLine, origin, dateFormat, startDate))
    {
        if (!streamData.good())
        {
            // End of file
            return emptyTable;
        }

        std::getline(streamData, firstLine);
    }

    std::vector<std::string> quantityNames = splitLineAndRemoveComments(firstLine);
    size_t columnCount = quantityNames.size();

    if (columnCount == 0)
    {
        if (errorText) errorText->push_back("No quantities detected in table");

        return emptyTable;
    }

    std::vector< std::vector< std::string > > allHeaderRows;

    {
        std::stringstream::pos_type posAtStartOfFirstLine = streamData.tellg();

        std::string secondLine;
        std::getline(streamData, firstLine);

        std::stringstream::pos_type posAtStartOfSecondLine = streamData.tellg();
        std::getline(streamData, secondLine);

        bool header = true;
        while (header)
        {
            if (isValidTableData(columnCount, firstLine) &&
                isValidTableData(columnCount, secondLine))
            {
                header = false;
                break;
            }
            else
            {
                std::vector<std::string> words = splitLineAndRemoveComments(firstLine);
                if (words.size() > 0)
                {
                    allHeaderRows.push_back(words);
                }
            }

            posAtStartOfFirstLine = posAtStartOfSecondLine;
            firstLine = secondLine;

            posAtStartOfSecondLine = streamData.tellg();
            std::getline(streamData, secondLine);

            if (!streamData.good())
            {
                header = false;
            }
        }

        streamData.seekg(posAtStartOfFirstLine);
    }

    std::vector<std::string> unitNames;
    std::vector<double> scaleFactors;
    std::vector< std::vector< std::string > > headerRows;

    for (const auto& rowWords : allHeaderRows)
    {
        bool excludeFromHeader = false;

        if (rowWords.size() == columnCount)
        {
            if (unitNames.size() == 0)
            {
                for (const std::string& word : rowWords)
                {
                    if (hasTimeUnit(word))
                    {
                        unitNames = rowWords;
                        excludeFromHeader = true;
                    }
                }
            }

            if (scaleFactors.size() == 0)
            {
                std::vector<double> values;

                if (hasOnlyValidDoubleValues(rowWords, &values))
                {
                    scaleFactors = values;
                    excludeFromHeader = true;
                }
            }
        }

        if (!excludeFromHeader)
        {
            headerRows.push_back(rowWords);
        }
    }

    if (columnCount != unitNames.size())
    {
        if (errorText) errorText->push_back("Number of quantities is different from number of units");

        return emptyTable;
    }


    std::vector<Column> columnInfos;

    // Create string vectors for each column
    {
        std::vector<std::string> parserErrors;
        std::vector<std::vector<std::string>> tableHeaderText = RifEclipseUserDataKeywordTools::buildColumnHeaderText(quantityNames, headerRows, &parserErrors);
        if (parserErrors.size() > 0)
        {
            if (errorText) errorText->insert(errorText->end(), parserErrors.begin(), parserErrors.end());
            
            return emptyTable;
        }


        // For each column header, create rif adress and date time
        for (size_t i = 0; i < tableHeaderText.size(); i++)
        {
            auto columnText = tableHeaderText[i];
            if (columnText.size() == 0)
            {
                if (errorText) errorText->push_back("Detected column with no content");
                continue;
            }

            std::string quantity = columnText[0];
            std::string unit = unitNames[i];

            std::vector<std::string> columnHeader;

            if (columnText.size() > 1) columnHeader.insert(columnHeader.begin(), columnText.begin() + 1, columnText.end());

            RifEclipseSummaryAddress adr = RifEclipseUserDataKeywordTools::makeAndFillAddress(quantity, columnHeader);

            Column ci = Column::createColumnInfoFromRsmData(quantity, unit, adr);

            columnInfos.push_back(ci);
        }
    }

    return TableData(origin, startDate, columnInfos);
}
Exemple #21
0
	void Emitter::PostWriteStreamable(const std::stringstream& str)
	{
		m_stream << str.str();
		PostAtomicWrite();
	}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RifEclipseUserDataParserTools::findValidHeaderLines(std::stringstream& streamData)
{
    std::vector<std::string> headerLines;

    std::stringstream::pos_type posAtTableDataStart = streamData.tellg();

    size_t columnCount = 0;
    std::string line;
    bool continueParsing = true;
    bool hasStepType = false;
    size_t minimunRequiredExtraHeaderLines = 0;

    while (continueParsing)
    {
        posAtTableDataStart = streamData.tellg();

        if (!std::getline(streamData, line))
        {
            continueParsing = false;
        }
        else
        {
            if (!RifEclipseUserDataParserTools::isLineSkippable(line))
            {
                auto words = RifEclipseUserDataParserTools::splitLineAndRemoveComments(line);

                if (!hasStepType)
                {
                    for (size_t i = 0; i < words.size(); i++)
                    {
                        if (RifEclipseUserDataKeywordTools::isStepType(words[i]))
                        {
                            hasStepType = true;
                        }
                    }
                }

                if (isUnitText(line))
                {
                    minimunRequiredExtraHeaderLines += 1;
                }

                if (isScalingText(line))
                {
                    minimunRequiredExtraHeaderLines += 1;
                }

                if (columnCount == 0)
                {
                    // Fist line with valid header data defines the number of columns

                    columnCount = words.size();

                    minimunRequiredExtraHeaderLines = RifEclipseUserDataKeywordTools::computeRequiredHeaderLineCount(words);

                    headerLines.push_back(line);
                }
                else if (headerLines.size() < minimunRequiredExtraHeaderLines)
                {
                    headerLines.push_back(line);
                }
                else
                {
                    std::vector<double> doubleValues = RifEclipseUserDataParserTools::splitLineToDoubles(line);

                    if (doubleValues.size() < columnCount && words.size() < columnCount)
                    {
                        if (hasStepType && (words.size() + 1 == columnCount))
                        {
                            continueParsing = false;
                        }
                        else
                        {
                            // Consider a line with double values less than column count as a table header
                            headerLines.push_back(line);
                        }
                    }
                    else
                    {
                        continueParsing = false;
                    }
                }
            }
        }
    }

    streamData.seekg(posAtTableDataStart);

    return headerLines;
}
Exemple #23
0
// Helper Function because lazy
void Increment(SGD::Point& pos, std::stringstream& display, int multi = 1)
{
		pos.y += 35.0f * multi;
		display.str(std::string());
}
void MpuReader::run()
{
    //連線藍芽
    #ifndef USE_WIRE_CONNECTION
        blue_connector = new cwz_c_blue();
        int result = blue_connector->connect(this->stopFlag);
        if(result == 1)//如果成功連線
            emit connectionCreated();
    #endif

    //********************************************************//
    //							變數宣告
    //********************************************************//
    //Handle Serial Buffer
    const int incomming_buf_len = 2048;
    char incomingData[incomming_buf_len] = "";			// don't forget to pre-allocate memory
    int dataLength = 256;
    const int bSize = 10000;
    char buffer[bSize] = "";
    int bLen = 0;

    //Decode information from buffer string
    int count = 0;
    int flag = -1; //-1等於上次是不合法結束的情況
    int accl[3]; // x, y, z
    int gyro[3]; // x, y, z
    float gravity[3];
    float quatern[4];
    int buttons[2];
    int period;

    //中位值濾波
    int MFLen = 5;   //濾波器長度為5
    int **Accls = allcIntDArray(MFLen, 3);
    int **Gyros = allcIntDArray(MFLen, 3);
    int MFCount = 0; // 只用於前五次, 確認filter的data set是不是被裝滿了, 裝滿了才開始濾波

    //Symbol record
    //SymbolRecorder SR = SymbolRecorder();

    //fileNameSStream << racketFilePath << date_string << "_" << type_string << "_" << person_string << "_" << racket_file_count << ".txt";

    //********************************************************//
    //					連接Com port並確認連線
    //********************************************************//
    #ifdef USE_WIRE_CONNECTION
        std::cout << "Arduino with GY521 board and chip MPU6050!" << std::endl;
        char *COM_NUM = "COM5";
        Serial* SP = new Serial(COM_NUM);    // adjust as needed
        if (SP->IsConnected()){
            emit connectionCreated();
            std::cout << "We're connected" << std::endl;
        }else{
            stopFlag = true;
        }
        //read few set of data until it's getting stable
        waitUntilSerialStable(SP, incomingData, dataLength);

        std::cout << "Data should be stable, start to read MPU6050" << std::endl;
    #else
        blue_connector->send("Start to read mpu6050 data from bluetooth.\n");
    #endif

    while(!stopFlag){
        #ifdef USE_WIRE_CONNECTION
            if(!SP->IsConnected()){
                std::cout << "Failed to read " << COM_NUM << " Mpu6050 reader is off." << std::endl;
                emit readingEnded();
                break;
            }
            if( !readSerialIntoBuffer(SP, incomingData, dataLength, readResult, bLen, bSize, buffer) )
                continue;//If no valid serial data are read or buffer overflow, skip this round
        #else
            dataLength = blue_connector->receive(incomingData, incomming_buf_len);
            if(dataLength > 0){//有收到東西
                incomingData[dataLength] = '\0';
                strcpy_s(&buffer[bLen], bSize, incomingData);
                bLen += dataLength;
            }
        #endif
        //decode mpu6050 data from buffer str, take off processed part from buffer
        strcpy_s(buffer, bSize, getAccelAndGyro(&count, &flag, &bLen, buffer, accl, gyro, quatern, buttons, &period, bSize));

        //   每一組合法數值為 (acclX,acclY,acclZ,gyroX,gyroY,gyroZ,quatern1,quatern2,quatern3,quatern4,buttonRight,buttonLeft,readperiod)
        if( flag != GETAANDG_NEW_VALID_DATA )
            continue;//尚未讀到整組完整資料 不處理 繼續讀

        SHORT downKeyState = GetAsyncKeyState( VK_DOWN );
        //std::cout << "gravity: " << gravity[0] << ", " << gravity[1] << ", " << gravity[2] << std::endl;
        if( writeRawToFile )
        {//按ctrl鍵
            std::cout << "period: " << period << std::endl;

            if( ( 1 << 16 ) & downKeyState ){
                //writeAcclAndGyroAndGravity(fileNameSStream.str().c_str(), accl, gyro, gravity, 1);
                writeMpu6050RawToFile(fileNameSStream.str().c_str(), accl, gyro, quatern, period, 1);
                //std::cout << "Down Key State: " << 1 << std::endl;
            }else{
                //writeAcclAndGyroAndGravity(fileNameSStream.str().c_str(), accl, gyro, gravity, 0);
                writeMpu6050RawToFile(fileNameSStream.str().c_str(), accl, gyro, quatern, period, 0);
                //std::cout << "Down Key State: " << 0 << std::endl;
            }
        }

        //********************************************************//
        //				處理加速度計與陀螺儀Raw Data
        //********************************************************//
        //get gravity
        QtoGravity(quatern, gravity);
        //std::cout << "Gyro: " << gyro[0] << "," << gyro[1] << "," << gyro[2] << std::endl;
        //去重力
        removeGravity(accl, gravity);

        double total_q = sqrt(gravity[0]*gravity[0] + gravity[1]*gravity[1] + gravity[2]*gravity[2]);

        this->my_glwidget->setNewZ(gravity[0], gravity[1], gravity[2]);

        //check if gravity value is invalid
        if( total_q >= 1.1 ){
            std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
            std::cout << "total_q: " << total_q << std::endl;
            std::cout << "Wrong gravity ............................................" << std::endl;
            std::cout << "quatern: " << quatern[0] << "," << quatern[1] << "," << quatern[2] << "," << quatern[3] << std::endl;
            std::cout << "gravity: " << gravity[0] << "," << gravity[1] << "," << gravity[2] << std::endl;
            std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
            system("PAUSE");

        }

        //Median Filter(中位值濾波)
        agMedianFilter(Accls, Gyros, accl, gyro, MFCount, MFLen, true, true); //是否做濾波 accl=true gyro=true
    }
#ifdef USE_WIRE_CONNECTION
    SP->~Serial();
#else
    blue_connector->disconnect();
#endif
    //釋放中位值濾波使用的記憶體空間
    freeIntDArray(Accls, MFLen);
    freeIntDArray(Gyros, MFLen);
}
//string domainid,deviceid,loginfo,logdata,logconfpath;
int alarmSubscribeBloodPressure(string  domainid,string deviceid,int sysmin,int sysmax,int dismin,int dismax,int pulsemin,int pulsemax,string loginfo,string logdata,string logconfpath)
{
	 sysmin = 90;
	 sysmax = 140;
	 dismin = 60;
	 dismax = 90;
	 pulsemin = 60;
	 pulsemax = 90;
	
	


	 /*Initializing SimpleDDS library*/
	 DataService *simpledds;
	 BloodPressureTypeSupport_var typesupport;
    	 DataReader_ptr content_reader;
    	 BloodPressureDataReader_var bpReader;
    	 ReturnCode_t status;
	 int i=0;
         
	 /*Setting QoS Properties for Topic*/
	 DDS::TopicQos tQos;
	 getQos(tQos);

	 simpledds = new OpenSpliceDataService(tQos,loginfo,logconfpath);
	 typesupport = new BloodPressureTypeSupport();
         simpledds->logger->info(" Blood Pressure Alarm Subscriber Started %s" ,deviceid.c_str());
	 /*Creating content Filtered Subscriber*/
	 StringSeq sSeqExpr;
         sSeqExpr.length(0);
	 content_reader = simpledds->filteredSubscribe(typesupport, deviceid ,devid , deviceid,sSeqExpr);

    	 bpReader = BloodPressureDataReader::_narrow(content_reader);
   	 BloodPressureSeq  bpList;
     	 SampleInfoSeq     infoSeq;

	 simpledds->logger->info("Blood Pressure alarm Subscriber for %s",deviceid.c_str());
simpledds->logger->info("Format: DOMAIN_ID, DEVICE_ID, MEASURED_TIME, SYSTOLIC(LEVEL), DIASTOLIC(LEVEL), PULSERATE(LEVEL)");
	 while (1) 
	 {
         	status = bpReader->take(
            	bpList,
            	infoSeq,
            	LENGTH_UNLIMITED,
            	ANY_SAMPLE_STATE,
           	ANY_VIEW_STATE,
            	ANY_INSTANCE_STATE);
         	checkStatus(status, "take");
          	if (status == RETCODE_NO_DATA) 
		{
          		continue;
          	}
		for (i = 0; i < bpList.length(); i++) 
		{
			
			if(infoSeq[i].valid_data)
			{
			if (bpList[i].systolicPressure < sysmin || bpList[i].systolicPressure > sysmax || bpList[i].diastolicPressure < dismin || bpList[i].diastolicPressure > dismax || bpList[i].pulseRatePerMinute < pulsemin || bpList[i].pulseRatePerMinute > pulsemax)
			{
				prtemp <<bpList[i].deviceDomain<<COMMA<<bpList[i].deviceID<<COMMA;
				prtemp <<bpList[i].timeOfMeasurement<<COMMA<<alarmString(bpList[i].systolicPressure,sysmin,sysmax);
				prtemp <<COMMA<<alarmString(bpList[i].diastolicPressure,dismin,dismax)<<COMMA;
				prtemp <<alarmString(bpList[i].pulseRatePerMinute,pulsemin,pulsemax);
				simpledds->logger->info(prtemp.str().c_str());
				prtemp.str(CLEAN);
			}
			
			}
		}
		status = bpReader->return_loan(bpList, infoSeq);
        	checkStatus(status, "return_loan");
	 	
    	}
	simpledds->logger->info("Blood Pressure alarm Subscriber Ends");	
        /* We're done.  Delete everything */
        simpledds->deleteReader(content_reader);
        delete simpledds;
        return 0;


}
Exemple #26
0
    map[distance] = i;
  }

  // Distances are stored in a list in ascending order.
  QList<double> distances = map.keys();

  // The first element in the list therefore has the shortest distance.
  double shortestDistance = distances[0];
  size_t nearestPointIndex = map[shortestDistance];

  // Obtains the x and y coordinates of the closest data point, ready to be displayed.
  double nearestPointXCoord = mwd->x(nearestPointIndex);
  double nearestPointYCoord = mwd->y(nearestPointIndex);
  double errorOfNearestPoint = mwd->e(nearestPointIndex);

  std::stringstream precisionValueX;
  precisionValueX.precision(6);
  precisionValueX << nearestPointXCoord;
  m_xPosSigFigs = precisionValueX.str();

  std::stringstream precisionValueY;
  precisionValueY.precision(6);
  precisionValueY << nearestPointYCoord;
  m_yPosSigFigs = precisionValueY.str();

  std::stringstream error;
  error.precision(6);
  error << errorOfNearestPoint;
  std::string errorSigFigs = error.str();

  m_dataCoords = "(" + m_xPosSigFigs + ", " + m_yPosSigFigs + ")";
Exemple #27
0
std::ostream& debug() {
	if (debugActive) return std::cerr;
	nullOut.str(std::string());
	return nullOut;
}
void
DumpStringStream(std::stringstream& ss)
{
    std::cerr << ss.str() << std::endl;
}
//string domainid,deviceid,loginfo,logdata,logconfpath;
int echoSubscribeBloodPressure(string domainid,string deviceid,string loginfo,string logdata,string logconfpath)
{

	

	 /*Initializing SimpleDDS library*/
	 DataService *simpledds;
	 BloodPressureTypeSupport_var typesupport;
    	 DataReader_ptr content_reader;
    	 BloodPressureDataReader_var bpReader;
    	 ReturnCode_t status;
	 int i=0;
	
	 /*Setting QoS Properties for Topic*/
	 DDS::TopicQos tQos;
	 getQos(tQos);
         tQos.durability_service.history_depth= 1024;

	 /*Initializing Subscriber and DataWriter*/
	 simpledds = new OpenSpliceDataService(tQos,loginfo,logconfpath);
	 typesupport = new BloodPressureTypeSupport();
    	 simpledds->logger->info(" Blood Pressure Subscriber Started %s" ,deviceid.c_str());
	 /*Creating content Filtered Subscriber*/
	 StringSeq sSeqExpr;
         sSeqExpr.length(0);
	 content_reader = simpledds->filteredSubscribe(typesupport, deviceid ,devid , deviceid,sSeqExpr);
	
	 bpReader = BloodPressureDataReader::_narrow(content_reader);
   	 BloodPressureSeq  bpList;
     	 SampleInfoSeq     infoSeq;
	 
	 simpledds->logger->info("Blood Pressure Subscriber For %s",deviceid.c_str());
	 simpledds->logger->info("Format: DOMAIN_ID, DEVICE_ID, MEASURED_TIME, SYSTOLIC, DIASTOLIC, PULSERATE");
	 /*Receiving Data from DDS */
	 while (1) 
	 {
         	status = bpReader->take(
            	bpList,
            	infoSeq,
            	LENGTH_UNLIMITED,
            	ANY_SAMPLE_STATE,
           	ANY_VIEW_STATE,
            	ANY_INSTANCE_STATE);
         	checkStatus(status, "take");

          	if (status == RETCODE_NO_DATA) 
		{
          		continue;
          	}

          	for (i = 0; i < bpList.length(); i++) 
	  	{
			
			if(infoSeq[i].valid_data)
			{
			prtemp <<bpList[i].deviceDomain<<COMMA;
		        prtemp <<bpList[i].deviceID <<COMMA<<bpList[i].timeOfMeasurement<<COMMA<< bpList[i].systolicPressure;
			prtemp <<COMMA<<bpList[i].diastolicPressure<<COMMA<<bpList[i].pulseRatePerMinute;
			 simpledds->logger->info(prtemp.str().c_str());
			prtemp.str(CLEAN);
			}
	  	}
		status = bpReader->return_loan(bpList, infoSeq);
       		checkStatus(status, "return_loan");
       
    	}

        /* We're done.  Delete everything */
	simpledds->logger->info("Blood Pressure Subscriber Ends");	
        simpledds->deleteReader(content_reader);
        delete simpledds;
        return 0;


}
Exemple #30
0
	virtual void Run()
	{
		Given("an output stream and output", [&]()
		{
			m_actualOutput.str("");
			m_output = std::unique_ptr<ut11::out::StdOutput>(new ut11::out::StdOutput(m_actualOutput));
		});
		When("begin and end without running any tests", [&]()
		{
			m_output->Begin();
			m_output->Finish(10, 7);
		});
		Then("the output is as expected", [&]()
		{
			AssertThat(m_actualOutput.str(), ut11::Is::EqualTo("\nFinished!\nRan: 10\nSucceeded: 7\n"));
		});

		When("running a test fixture with just a Then", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginThen("then");
			m_output->EndThen("then");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 1);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			auto endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\t\t\tThen: then \n\nFinished!\nRan: 1\nSucceeded: 1\n"));
		});

		When("running two test fixtures with just a Then", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginThen("then");
			m_output->EndThen("then");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->BeginFixture("fixture2");
			m_output->BeginTest();
			m_output->BeginThen("then2");
			m_output->EndThen("then2");
			m_output->EndTest();
			m_output->EndFixture("fixture2");
			m_output->Finish(2, 2);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			auto endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			startOfTime = stringVal.find('[');
			endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\t\t\tThen: then \nFixture: fixture2\n\t\t\tThen: then2 \n\nFinished!\nRan: 2\nSucceeded: 2\n"));
		});

		When("running a test fixture with just a When and Then", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then");
			m_output->EndThen("then");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 1);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			auto endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\t\tWhen: when\n\t\t\tThen: then \n\nFinished!\nRan: 1\nSucceeded: 1\n"));
		});

		When("running a test fixture with a Given When and Then", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then");
			m_output->EndThen("then");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 1);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			auto endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\t\tWhen: when\n\t\t\tThen: then \n\nFinished!\nRan: 1\nSucceeded: 1\n"));
		});

		When("running a test fixture with a Given When Then Finally", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then");
			m_output->EndThen("then");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 1);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			auto endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\t\tWhen: when\n\t\t\tThen: then \n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 1\n"));
		});

		When("running a test fixture with multiple tests with a Given When Then Finally where the Given and Whens repeat", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then");
			m_output->EndThen("then");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then2");
			m_output->EndThen("then2");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 1);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			auto endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			startOfTime = stringVal.find('[');
			endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\t\tWhen: when\n\t\t\tThen: then \n\t\t\tThen: then2 \n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 1\n"));
		});

		When("running a test fixture with a When Then Finally", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then");
			m_output->EndThen("then");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 1);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			auto endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\t\tWhen: when\n\t\t\tThen: then \n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 1\n"));
		});

		When("running a test fixture with a Then Finally", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginThen("then");
			m_output->EndThen("then");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 1);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			auto endOfTime = stringVal.find(']');
			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\t\t\tThen: then \n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 1\n"));
		});

		When("running a test fixture with a Given When Then Finally and the Then fails with an std::exception", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then");
			m_output->OnError(std::runtime_error("error"));
			m_output->EndThen("then");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 0);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			startOfTime = stringVal.substr(startOfTime + 1).find('[') + startOfTime;

			auto endOfTime = stringVal.find(']');
			endOfTime = stringVal.substr(endOfTime + 1).find(']') + endOfTime + 1;

			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\t\tWhen: when\n\t\t\tThen: then\n\tFailed: std::exception was thrown [what(): error]\n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 0\n"));
		});

		When("running a test fixture with a Given When Then Finally and the Then fails with an unknown error", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then");
			m_output->OnUnknownError();
			m_output->EndThen("then");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 0);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			startOfTime = stringVal.substr(startOfTime + 1).find('[') + startOfTime;

			auto endOfTime = stringVal.find(']');
			endOfTime = stringVal.substr(endOfTime + 1).find(']') + endOfTime + 1;

			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\t\tWhen: when\n\t\t\tThen: then\n\tFailed: Unknown Error\n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 0\n"));
		});

		When("running a test fixture with a Given When Then Finally and the Then fails", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginWhen("when");
			m_output->EndWhen("then");
			m_output->BeginThen("then");
			m_output->OnError(10, "file", "error");
			m_output->EndThen("then");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 0);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			startOfTime = stringVal.substr(startOfTime + 1).find('[') + startOfTime;

			auto endOfTime = stringVal.find(']');
			endOfTime = stringVal.substr(endOfTime + 1).find(']') + endOfTime + 1;

			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\t\tWhen: when\n\t\t\tThen: then\n\tFailed: [10:file] error\n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 0\n"));
		});


		When("running a test fixture with a Given When Finally and the When fails", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginWhen("when");
			m_output->OnError(10, "file", "error");
			m_output->EndWhen("then");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 0);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			startOfTime = stringVal.substr(startOfTime + 1).find('[') + startOfTime;

			auto endOfTime = stringVal.find(']');
			endOfTime = stringVal.substr(endOfTime + 1).find(']') + endOfTime + 1;

			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\t\tWhen: when\n\tFailed: [10:file] error\n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 0\n"));
		});


		When("running a test fixture with a Given Finally and the Given fails", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->OnError(10, "file", "error");
			m_output->EndGiven("given");
			m_output->BeginFinally("finally");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 0);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			startOfTime = stringVal.substr(startOfTime + 1).find('[') + startOfTime;

			auto endOfTime = stringVal.find(']');
			endOfTime = stringVal.substr(endOfTime + 1).find(']') + endOfTime + 1;

			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\tFailed: [10:file] error\n\tFinally: finally\n\nFinished!\nRan: 1\nSucceeded: 0\n"));
		});

		When("running a test fixture with a Given Finally and the Finally fails", [&]()
		{
			m_output->Begin();
			m_output->BeginFixture("fixture");
			m_output->BeginTest();
			m_output->BeginGiven("given");
			m_output->EndGiven("given");
			m_output->BeginFinally("finally");
			m_output->OnError(10, "file", "error");
			m_output->EndFinally("finally");
			m_output->EndTest();
			m_output->EndFixture("fixture");
			m_output->Finish(1, 0);
		});
		Then("the output is as expected", [&]()
		{
			auto stringVal = m_actualOutput.str();
			auto startOfTime = stringVal.find('[');
			startOfTime = stringVal.substr(startOfTime + 1).find('[') + startOfTime;

			auto endOfTime = stringVal.find(']');
			endOfTime = stringVal.substr(endOfTime + 1).find(']') + endOfTime + 1;

			stringVal = stringVal.erase(startOfTime, endOfTime - startOfTime + 1);

			AssertThat(stringVal, ut11::Is::EqualTo("Fixture: fixture\n\tGiven: given\n\tFinally: finally\n\tFailed: [10:file] error\n\nFinished!\nRan: 1\nSucceeded: 0\n"));
		});
	}