text:
#include <iostream>
#include <sstream>
#include <thread>
#include <string>
#include <vector>
#include <boost/crc.hpp>
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Float64.h>
#include <sensor_msgs/NavSatFix.h>
#include <geometry_msgs/Point.h>
#include "nmea_ros_driver/GPSRPY.h"
#include "nmea_ros_driver/GPSPoint.h"
#include "nmea_ros_driver/XXGGA.h"
#include "nmea_ros_driver/XXGSA.h"
#include "nmea_ros_driver/XXGSV.h"
#include "nmea_ros_driver/XXRMC.h"
#include "nmea_ros_driver/XXVTG.h"
#include "nmea_ros_driver/XXGLL.h"
#include "nmea_ros_driver/NTR.h"
#include "nmea_ros_driver/PJK.h"
#include "nmea_ros_driver/TRA.h"
#include "nmea_ros_driver/HEADINGA.h"
#include "nmea_ros_driver/BESTPOSA.h"

class NmeaMsgAnalyzeNode
{
public:
  NmeaMsgAnalyzeNode(ros::NodeHandle nh, ros::NodeHandle private_nh);
  ~NmeaMsgAnalyzeNode(){};

private:
  ros::NodeHandle nh_, private_nh_;
  bool enable_custom_;
  bool enable_gga_, enable_gsa_, enable_gsv_, enable_rmc_, enable_vtg_, enable_gll_;
  ros::Publisher gga_pub_, gsa_pub_, gsv_pub_, rmc_pub_, vtg_pub_, gll_pub_;
  ros::Publisher ntr_pub_, pjk_pub_, tra_pub_, headinga_pub_, bestposa_pub_;
  std::string frame_id_;
  std::string nmea_topic_name_;
  ros::Publisher fixed_msg_pub_;
  ros::Publisher gps_point_pub_;
  ros::Publisher gps_rpy_pub_;
  ros::Subscriber nmea_msg_sub_;

  const std::map<std::string, uint8_t> nmea_msg_type_ = {
      {"GGA", 1},
      {"GSA", 2},
      {"GSV", 3},
      {"RMC", 4},
      {"VTG", 5},
      {"GLL", 6},
  };
  //nmea message
  bool procGGA(const std::vector<std::string> msg_list);
  bool procGSA(const std::vector<std::string> msg_list);
  bool procGSV(const std::vector<std::string> msg_list);
  bool procRMC(const std::vector<std::string> msg_list);
  bool procVTG(const std::vector<std::string> msg_list);
  bool procGLL(const std::vector<std::string> msg_list);
  //custom message
  bool procNTR(const std::vector<std::string> msg_list);
  bool procPJK(const std::vector<std::string> msg_list);
  bool procTRA(const std::vector<std::string> msg_list);
  bool procHEADINGA(const std::vector<std::string> msg_list);
  bool procBESTPOSA(const std::vector<std::string> msg_list);

  void NmeaMsgCallBack(const std_msgs::String::ConstPtr &msg);

  std::vector<std::string> SplitNmeaMsg(const std::string msg);
  std::vector<std::string> SplitCustomMsg(const std::string msg);

  bool CheckNmeaMsgSum(const std::string msg);
  bool CheckCRC32Sum(const std::string msg);
  uint32_t Hex2Int(const char *str, const uint8_t len)
  {
    int val = 0;
    for (uint8_t i = 0; i < len; i++)
    {
      val = val * 16;
      //char a = str[i];
      if (str[i] >= 'A' && str[i] <= 'F')
        val += str[i] - 'A' + 10;
      else if (str[i] >= 'a' && str[i] <= 'f')
        val += str[i] - 'a' + 10;
      else
        val += str[i] - '0';
    }
    return val;
  }
  template <class Type>
  Type stringToNum(const std::string &str)
  {
    std::istringstream iss(str);
    Type num;
    iss >> num;
    return num;
  }
};

NmeaMsgAnalyzeNode::NmeaMsgAnalyzeNode(ros::NodeHandle nh, ros::NodeHandle private_nh)
    : nh_(nh), private_nh_(private_nh)
{
  //get ros param
  private_nh_.param<std::string>("frame_id", frame_id_, "gps_link");
  private_nh_.param<std::string>("nmea_topic_name", nmea_topic_name_, "nmea_msg");
  private_nh_.param<bool>("enable_custom", enable_custom_, false);
  private_nh_.param<bool>("enable_gga", enable_gga_, false);
  private_nh_.param<bool>("enable_gsa", enable_gsa_, false);
  private_nh_.param<bool>("enable_gsv", enable_gsv_, false);
  private_nh_.param<bool>("enable_rmc", enable_rmc_, false);
  private_nh_.param<bool>("enable_vtg", enable_vtg_, false);
  private_nh_.param<bool>("enable_gll", enable_gll_, false);

  //init Publisher and Subscriber
  if (enable_gga_)
  {
   gga_pub_ = nh_.advertise<nmea_ros_driver::XXGGA>("/gps/nmea/XXGGA", 5);
  }
  if (enable_gsa_)
  {
   gsa_pub_ = nh_.advertise<nmea_ros_driver::XXGSA>("/gps/nmea/XXGSA", 5);
  }
  if (enable_gsv_)
  {
   gsv_pub_ = nh_.advertise<nmea_ros_driver::XXGSV>("/gps/nmea/XXGSV", 5);
  }
  if (enable_rmc_)
  {
   rmc_pub_ = nh_.advertise<nmea_ros_driver::XXRMC>("/gps/nmea/XXRMC", 5);
  }
  if (enable_vtg_)
  {
   vtg_pub_ = nh_.advertise<nmea_ros_driver::XXVTG>("/gps/nmea/XXVTG", 5);
  }
  if (enable_gll_)
  {
   gll_pub_ = nh_.advertise<nmea_ros_driver::XXGLL>("/gps/nmea/XXGLL", 5);
  }
  if (enable_custom_)
  {
    ntr_pub_ = nh_.advertise<nmea_ros_driver::NTR>("/gps/custom/NTR", 5);
    pjk_pub_ = nh_.advertise<nmea_ros_driver::PJK>("/gps/custom/PJK", 5);
    tra_pub_ = nh_.advertise<nmea_ros_driver::TRA>("/gps/custom/TRA", 5);
    headinga_pub_ = nh_.advertise<nmea_ros_driver::HEADINGA>("/gps/custom/HEADINGA", 5);
    bestposa_pub_ = nh_.advertise<nmea_ros_driver::BESTPOSA>("/gps/custom/BESTPOSA", 5);
  }

  fixed_msg_pub_ = nh_.advertise<sensor_msgs::NavSatFix>("/gps/fixed", 5);
  gps_rpy_pub_ = nh_.advertise<nmea_ros_driver::GPSRPY>("/gps/rpy", 5);
  gps_point_pub_ = nh_.advertise<nmea_ros_driver::GPSPoint>("/gps/point", 5);
  nmea_msg_sub_ = nh_.subscribe(nmea_topic_name_, 5, &NmeaMsgAnalyzeNode::NmeaMsgCallBack, this);
  //sleep
  std::this_thread::sleep_for(std::chrono::milliseconds(200));
}

bool NmeaMsgAnalyzeNode::CheckNmeaMsgSum(const std::string msg)
{
  int sum = 0;
  int sum_msg = 0;
  for (size_t i = 1; i < msg.length(); i++)
  {
    if (i == 1)
    {
      sum = msg[i];
      continue;
    }
    else if (msg[i] != '*')
    {
      sum ^= msg[i];
      continue;
    }
    else
    {
      sum_msg = Hex2Int(&msg[i + 1], 2);
      break;
    }
  }

  //ROS_INFO_STREAM("sum:" << sum << "\t" << "sum_msg:" << sum_msg);

  if (sum == sum_msg)
    return true;
  else
    return false;
}
bool NmeaMsgAnalyzeNode::CheckCRC32Sum(const std::string msg)
{
  uint32_t length = 0;
  uint32_t msg_crc = 0x00;
  for (size_t i = 1; i < msg.length(); i++)
  {
    if (msg[i] == '*')
    {
      msg_crc = Hex2Int(&msg[i + 1], 8);
      length = i - 1;
      break;
    }
  }

  boost::crc_32_type crc32;
  crc32.process_bytes(msg.substr(1).data(), length);

  //std::string std = "HEADINGA,COM1,0,60.0,UNKNOWN,1408,113980.800,00000000,0000,1114;COLD_START,NONE,0.000000000,0.000000000,0.000000000,0.000000000,180.000000000,90.000000000,\"AAAA\",0,0,0,0,0,0,0,0";
  //crc32.process_bytes(std.data(), std.length());
  //msg_crc = 0xfb829747;

  //ROS_INFO_STREAM("crc:" << crc32.checksum() << "\t" << "crc_msg:" << msg_crc);

  if (msg_crc == crc32.checksum())
    return true;
  else
    return true;
}
std::vector<std::string> NmeaMsgAnalyzeNode::SplitNmeaMsg(const std::string msg)
{
  std::string str;
  std::vector<std::string> msg_list;
  for (size_t i = 1; i < msg.length(); i++)
  {
    if (msg[i] == ',')
    {
      msg_list.push_back(str);
      str.clear();
      continue;
    }
    else if (msg[i] == '*')
    {
      msg_list.push_back(str);
      str.clear();
      break;
    }
    else
    {
      str += msg[i];
      continue;
    }
  }

  return msg_list;
}
std::vector<std::string> NmeaMsgAnalyzeNode::SplitCustomMsg(const std::string msg)
{
  std::string str;
  std::vector<std::string> msg_list;
  for (size_t i = 1; i < msg.length(); i++)
  {
    if (msg[i] == ',' || msg[i] == ';')
    {
      msg_list.push_back(str);
      str.clear();
      continue;
    }
    else if (msg[i] == '*')
    {
      msg_list.push_back(str);
      str.clear();
      break;
    }
    else
    {
      str += msg[i];
      continue;
    }
  }
  return msg_list;
}
void NmeaMsgAnalyzeNode::NmeaMsgCallBack(const std_msgs::String::ConstPtr &msg)
{
  if (msg->data[0] == '$') //NMEA-0183 message type
  {
    if (CheckNmeaMsgSum(msg->data))
    {
      std::vector<std::string> msg_list = SplitNmeaMsg(msg->data);
      //ROS_INFO_STREAM(msg_list[0]);
      auto it = nmea_msg_type_.find(msg_list[0].substr(2));
      if (it != nmea_msg_type_.end()) //nmea message type
      {
        switch (it->second)
        {
        case 1: //GGA
          procGGA(msg_list);
          break;
        case 2: //GSA
          procGSA(msg_list);
          break;
        case 3: //GSV
          procGSV(msg_list);
          break;
        case 4: //RMC
          procRMC(msg_list);
          break;
        case 5: //VTG
          procVTG(msg_list);
          break;
        case 6: //GLL
          procGLL(msg_list);
          break;
        default:
          break;
        }
      }
      else  //custom message type
      {
        if (msg_list[0].substr(0, 2) == "NTR")
        {
          procNTR(msg_list);
        }
        else if (msg_list[0].substr(0, 2) == "TRA")
        {
          procTRA(msg_list);
        }
        else if (msg_list[0] == "PTNL")
        {
          procPJK(msg_list);
        }
        else
        {
          ROS_WARN_STREAM("unknown message type!! msg:" << msg->data);
        }
      }
    }
    else
    {
      ROS_WARN_STREAM("nmea msg check sum error!! msg:" << msg->data);
    }
  }
  else if (msg->data[0] == '#') //custom message type
  {
    if (CheckCRC32Sum(msg->data))
    {
      std::vector<std::string> msg_list = SplitCustomMsg(msg->data);
      if (msg_list[0] == "HEADINGA")
      {
        procHEADINGA(msg_list);
      }
      else if (msg_list[0] == "BESTPOSA")
      {
        procBESTPOSA(msg_list);
      }
      else
      {
        ROS_WARN_STREAM("unknown message type!! msg:" << msg->data);
      }
    }
    else
    {
      ROS_WARN_STREAM("custom msg check sum error!! msg:" << msg->data);
    }
  }
  else //unknown message type
  {
    ROS_WARN_STREAM("unknown message type!! msg:" << msg->data);
  }
}
bool NmeaMsgAnalyzeNode::procGGA(const std::vector<std::string> msg_list)
{
  sensor_msgs::NavSatFix nav_msg;
  nav_msg.header.stamp = ros::Time::now();
  nav_msg.header.frame_id = frame_id_;

  nav_msg.status.status = stringToNum<int>(msg_list[6]);
  nav_msg.status.service = nav_msg.status.SERVICE_GPS;

  if (msg_list[3] == "N")
  {
    nav_msg.latitude = stringToNum<int>(msg_list[2].substr(0, 2)) + stringToNum<double>(msg_list[2].substr(2)) / 60.0;
  }
  else
  {
    nav_msg.latitude = -1.0 * (stringToNum<int>(msg_list[2].substr(0, 2)) + stringToNum<double>(msg_list[2].substr(2)) / 60.0);
  }

  if (msg_list[5] == "E")
  {
    nav_msg.longitude = stringToNum<int>(msg_list[4].substr(0, 3)) + stringToNum<double>(msg_list[4].substr(3)) / 60.0;
  }
  else
  {
    nav_msg.longitude = -1.0 * (stringToNum<int>(msg_list[4].substr(0, 3)) + stringToNum<double>(msg_list[4].substr(3)) / 60.0);
  }

  nav_msg.altitude = stringToNum<double>(msg_list[9]);

  double hdop = stringToNum<double>(msg_list[8]);

  double default_epe_quality = 0.0;

  switch (nav_msg.status.status)
  {
  case -1:
    default_epe_quality = 1000000.0;
    nav_msg.position_covariance_type = nav_msg.COVARIANCE_TYPE_UNKNOWN;
    break;
  case 0:
    default_epe_quality = 1000000.0;
    nav_msg.position_covariance_type = nav_msg.COVARIANCE_TYPE_UNKNOWN;
    break;
  case 1:
    default_epe_quality = 4.0;
    nav_msg.position_covariance_type = nav_msg.COVARIANCE_TYPE_APPROXIMATED;
    break;
  case 2:
    default_epe_quality = 0.1;
    nav_msg.position_covariance_type = nav_msg.COVARIANCE_TYPE_APPROXIMATED;
    break;
  case 4:
    default_epe_quality = 0.02;
    nav_msg.position_covariance_type = nav_msg.COVARIANCE_TYPE_APPROXIMATED;
    break;
  case 5:
    default_epe_quality = 4.0;
    nav_msg.position_covariance_type = nav_msg.COVARIANCE_TYPE_APPROXIMATED;
    break;
  default:
    default_epe_quality = 1000000.0;
    nav_msg.position_covariance_type = nav_msg.COVARIANCE_TYPE_UNKNOWN;
    break;
  }

  nav_msg.position_covariance[0] = pow((hdop * default_epe_quality), 2);
  nav_msg.position_covariance[4] = pow((hdop * default_epe_quality), 2);
  nav_msg.position_covariance[8] = pow((4.0 * hdop * default_epe_quality), 2);

  fixed_msg_pub_.publish(nav_msg);

  nmea_ros_driver::XXGGA gga;
  //TODO

  if (enable_gga_)
  {
    gga_pub_.publish(gga);
  }
}
bool NmeaMsgAnalyzeNode::procGSA(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::XXGSA gsa;
  //TODO

  if (enable_gsa_)
  {
    gsa_pub_.publish(gsa);
  }
}
bool NmeaMsgAnalyzeNode::procGSV(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::XXGSV gsv;
  //TODO

  if (enable_gsv_)
  {
    gsv_pub_.publish(gsv);
  }
}
bool NmeaMsgAnalyzeNode::procRMC(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::XXRMC rmc;
  //TODO

  if (enable_rmc_)
  {
    rmc_pub_.publish(rmc);
  }
}
bool NmeaMsgAnalyzeNode::procVTG(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::XXVTG vtg;
  //TODO

  if (enable_vtg_)
  {
    vtg_pub_.publish(vtg);
  }
}
bool NmeaMsgAnalyzeNode::procGLL(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::XXGLL gll;
  //TODO

  if (enable_gll_)
  {
    gll_pub_.publish(gll);
  }
}
bool NmeaMsgAnalyzeNode::procNTR(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::NTR ntr;
  //TODO

  if (enable_custom_)
  {
    ntr_pub_.publish(ntr);
  }
}
bool NmeaMsgAnalyzeNode::procPJK(const std::vector<std::string> msg_list)
{
  double x = std::stod(msg_list[4]);
  double y = std::stod(msg_list[6]);
  double z = std::stod(msg_list[11].substr(3));

  nmea_ros_driver::GPSPoint msg;
  msg.header.stamp = ros::Time::now();
  msg.header.frame_id = frame_id_;
  msg.x = x;
  msg.y = y;
  msg.z = z;

  gps_point_pub_.publish(msg);
  //std::cout << "x:" << msg_list[4].substr(1) << "\t" << "y:" << msg_list[6].substr(1) << std::endl;
  // ROS_INFO_STREAM("X:" << x << "\t" << "Y:" << y);
  //ROS_INFO("%lf %lf", x, y);

  nmea_ros_driver::PJK pjk;
  //TODO

  if (enable_custom_)
  {
    pjk_pub_.publish(pjk);
  }
}
bool NmeaMsgAnalyzeNode::procTRA(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::TRA tra;
  //TODO

  if (enable_custom_)
  {
    tra_pub_.publish(tra);
  }
}
bool NmeaMsgAnalyzeNode::procHEADINGA(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::GPSRPY msg;
  msg.header.stamp = ros::Time::now();
  msg.header.frame_id = frame_id_;
  msg.r = 0.0;
  msg.p = stringToNum<double>(msg_list[14]);
  msg.y = stringToNum<double>(msg_list[13]);
  gps_rpy_pub_.publish(msg);

  nmea_ros_driver::HEADINGA headinga;
  //TODO

  if (enable_custom_)
  {
    headinga_pub_.publish(headinga);
  }
}
bool NmeaMsgAnalyzeNode::procBESTPOSA(const std::vector<std::string> msg_list)
{
  nmea_ros_driver::BESTPOSA bestposa;
  //TODO

  if (enable_custom_)
  {
    bestposa_pub_.publish(bestposa);
  }
}

int main(int argc, char *argv[])
{
  ros::init(argc, argv, "nmea_msg_analyze");
  ros::NodeHandle nh, private_nh("~");

  NmeaMsgAnalyzeNode nd(nh, private_nh);

  ros::spin();

  ROS_INFO("All finish");

  return 0;
}


text:
/*
 *
 * Copyright (c) 2004
 * John Maddock
 *
 * Use, modification and distribution are 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)
 *
 */

 /*
  *   LOCATION:    see http://www.boost.org for most recent version.
  *   FILE         regex_raw_buffer.cpp
  *   VERSION      see <boost/version.hpp>
  *   DESCRIPTION: Member functions for class raw_storage.
  */

#define BOOST_REGEX_SOURCE
#include <boost/config.hpp>
#include <memory>
#include <cstring>
#include <boost/assert.hpp>
#include <boost/regex/v4/regex_raw_buffer.hpp>

#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
   using ::memcpy;
   using ::memmove;
}
#endif

namespace boost{ namespace re_detail{

void BOOST_REGEX_CALL raw_storage::resize(size_type n)
{
   size_type newsize = start ? last - start : 1024;
   while(newsize < n)
      newsize *= 2;
   size_type datasize = end - start;
   // extend newsize to WORD/DWORD boundary:
   newsize = (newsize + padding_mask) & ~(padding_mask);

   // allocate and copy data:
   pointer ptr = static_cast<pointer>(::operator new(newsize));
   BOOST_REGEX_NOEH_ASSERT(ptr)
   if(start)
      std::memcpy(ptr, start, datasize);

   // get rid of old buffer:
   ::operator delete(start);

   // and set up pointers:
   start = ptr;
   end = ptr + datasize;
   last = ptr + newsize;
}

void* BOOST_REGEX_CALL raw_storage::insert(size_type pos, size_type n)
{
   BOOST_ASSERT(pos <= size_type(end - start));
   if(size_type(last - end) < n)
      resize(n + (end - start));
   void* result = start + pos;
   std::memmove(start + pos + n, start + pos, (end - start) - pos);
   end += n;
   return result;
}

}} // namespaces

ext: cpp

max_stars_repo_name: JamesLinus/poedit

max_issues_repo_name: JamesLinus/poedit

max_forks_repo_name: JamesLinus/poedit


text:
#include "derivebinaryfeat.h"
#include <math.h>
#include <fstream>
#include <boost/lexical_cast.hpp>

cBinaryFeat::cBinaryFeat(sTrainData* data, sParams* params)
{
	m_TrainData = data;
	m_Params = params;
}

cv::Mat_<int> cBinaryFeat::DerivBinaryfeat(sRandomForest *randf, int stage)
{
	if (!randf || !randf->__RF){
		cv::Mat_<int> mat;
		return mat;
	}

	sRF** rf = randf->__RF;

	cv::Mat_<double>* __feats;
	cv::Mat_<double>* __threshs;
	cv::Mat_<int>*    __isleaf;
	cv::Mat_<int>*    __cnodes;

	try{
		__feats   = new cv::Mat_<double>[m_TrainData->__numlandmarks];
		__threshs = new cv::Mat_<double>[m_TrainData->__numlandmarks];
		__isleaf  = new cv::Mat_<int>[m_TrainData->__numlandmarks];
		__cnodes  = new cv::Mat_<int>[m_TrainData->__numlandmarks];
	}catch (std::exception e){
		std::cout << e.what() << std::endl;
	}

	for (int l=0; l < m_TrainData->__numlandmarks; l++){
		int num_rfnodes = 0;

		for (int t = 0; t < m_Params->__max_numtrees; t++){
			num_rfnodes += rf[l][t].__num_nodes;
		}

		int low = 0, high = 0;

		__feats[l] = cv::Mat::zeros(num_rfnodes, 4, CV_64FC1);
		__threshs[l] = cv::Mat::zeros(num_rfnodes, 1, CV_64FC1);
		__isleaf[l] = cv::Mat::zeros(num_rfnodes, 1, CV_32SC1);
		__cnodes[l] = cv::Mat::zeros(num_rfnodes, 2, CV_32SC1);

		for (int t = 0; t < m_Params->__max_numtrees; t++){
			high = low + m_Params->__max_nodes;
			rf[l][t].__feat.copyTo(__feats[l].rowRange(low,high));
			rf[l][t].__thresh.copyTo(__threshs[l].rowRange(low, high));
			rf[l][t].__isleafnode.copyTo(__isleaf[l].rowRange(low, high));
			rf[l][t].__cnodes.copyTo(__cnodes[l].rowRange(low, high));
			low = high;
		}

	}

	cv::Mat_<int> binfeatures;

	for (int i=0; i < m_TrainData->__dbsizes; i++){
		cv::Mat_<int>* binfeature_lmarks = new cv::Mat_<int>[m_TrainData->__numlandmarks];
		cv::Mat_<int>  num_leafnodes = cv::Mat::zeros(1, m_TrainData->__numlandmarks, CV_32SC1);

		for (int l =0; l < m_TrainData->__numlandmarks; l++){
			binfeature_lmarks[l] = __lbf_fast(rf[l], __feats[l], __threshs[l], __isleaf[l], __cnodes[l], &(m_TrainData->__data[i]), stage,l);
			num_leafnodes(0, l) = binfeature_lmarks[l].cols;
		}

		int num_cols = (int)cv::sum(num_leafnodes).val[0];

		cv::Mat_<int> binfeature_alllmarks = cv::Mat::zeros(1, num_cols, CV_32SC1);
		int low = 0, high = 0;

		for (int l = 0; l < m_TrainData->__numlandmarks; l++){
			high = low + binfeature_lmarks[l].cols;
			binfeature_lmarks[l].copyTo(binfeature_alllmarks.colRange(low, high));
			low = high;
		}
		binfeatures.push_back(binfeature_alllmarks);

		delete[] binfeature_lmarks;
	}

	delete[] __feats;
	delete[] __threshs;
	delete[] __isleaf;
	delete[] __cnodes;

	return binfeatures;
}

cv::Mat_<int> cBinaryFeat::__lbf_fast(const sRF*rf, const cv::Mat_<double>&feat, const cv::Mat_<double>&threshs, \
	const cv::Mat_<int>& isleaf, const cv::Mat_<int>& cnode, const sData* data, int stage, int landID)
{
	if (!data || !rf){
		cv::Mat_<int> m;
		return m;
	}

	int width  = data->__width;
	int height = data->__height;

	cv::Mat_<double> anglepairs  = feat.colRange(0, 2);
	cv::Mat_<double> radiuspairs = feat.colRange(2, 4);

	cv::Mat_<double> pixel_a_x_imgcoord,pixel_a_y_imgcoord,pixel_b_x_imgcoord, pixel_b_y_imgcoord;

	cv::Mat_<double> angles_cos = cv::Mat::zeros(anglepairs.rows, 2, CV_64FC1);
	cv::Mat_<double> angles_sin = cv::Mat::zeros(anglepairs.rows, 2, CV_64FC1);

	for (int i = 0; i < radiuspairs.rows; i++){
		angles_cos(i, 0) = cos(anglepairs(i, 0));
		angles_cos(i, 1) = cos(anglepairs(i, 1));
		angles_sin(i, 0) = sin(anglepairs(i, 0));
		angles_sin(i, 1) = sin(anglepairs(i, 1));
	}

	cv::multiply(angles_cos.col(0), radiuspairs.col(0), pixel_a_x_imgcoord);
	cv::multiply(angles_sin.col(0), radiuspairs.col(0), pixel_a_y_imgcoord);
	pixel_a_x_imgcoord *= (m_Params->__max_raio_radius[stage] * data->__intermediate_bboxes[stage].width);
	pixel_a_y_imgcoord *= (m_Params->__max_raio_radius[stage] * data->__intermediate_bboxes[stage].height);

	cv::multiply(angles_cos.col(1), radiuspairs.col(1), pixel_b_x_imgcoord);
	cv::multiply(angles_sin.col(1), radiuspairs.col(1), pixel_b_y_imgcoord);
	pixel_b_x_imgcoord *= (m_Params->__max_raio_radius[stage] * data->__intermediate_bboxes[stage].width);
	pixel_b_y_imgcoord *= (m_Params->__max_raio_radius[stage] * data->__intermediate_bboxes[stage].height);

	//pixel_a_x_imgcoord = pixel_a_x_imgcoord * data->__tf2meanshape.at<double>(0, 0) + pixel_a_y_imgcoord * data->__tf2meanshape.at<double>(0, 1) + data->__tf2meanshape.at<double>(0, 2);
	//pixel_a_y_imgcoord = pixel_a_x_imgcoord * data->__tf2meanshape.at<double>(1, 0) + pixel_a_y_imgcoord * data->__tf2meanshape.at<double>(1, 1) + data->__tf2meanshape.at<double>(1, 2);

	//pixel_b_x_imgcoord = pixel_b_x_imgcoord * data->__tf2meanshape.at<double>(0, 0) + pixel_b_y_imgcoord * data->__tf2meanshape.at<double>(0, 1) + data->__tf2meanshape.at<double>(0, 2);
	//pixel_b_y_imgcoord = pixel_b_x_imgcoord * data->__tf2meanshape.at<double>(1, 0) + pixel_b_y_imgcoord * data->__tf2meanshape.at<double>(1, 1) + data->__tf2meanshape.at<double>(1, 2);

	cv::Mat_<double> pixel_a_x, pixel_a_y, pixel_b_x, pixel_b_y;

	pixel_a_x = pixel_a_x_imgcoord + data->__intermediate_shapes[stage](landID,0);
	pixel_a_y = pixel_a_y_imgcoord + data->__intermediate_shapes[stage](landID,1);

	pixel_b_x = pixel_b_x_imgcoord + data->__intermediate_shapes[stage](landID, 0);
	pixel_b_y = pixel_b_y_imgcoord + data->__intermediate_shapes[stage](landID, 1);

	cv::Mat_<double> pdfeats = cv::Mat::zeros(pixel_a_x.rows, 1, CV_64FC1);

	for (int k = 0; k < pixel_a_x.rows; k++){
		int a_x = (int)(pixel_a_x(k, 0) + 0.5);
		int a_y = (int)(pixel_a_y(k, 0) + 0.5);
		int b_x = (int)(pixel_b_x(k, 0) + 0.5);
		int b_y = (int)(pixel_b_y(k, 0) + 0.5);

		a_x = MAX(0, MIN(a_x, width - 1));
		a_y = MAX(0, MIN(a_y, height - 1));
		b_x = MAX(0, MIN(b_x, width - 1));
		b_y = MAX(0, MIN(b_y, height - 1));

		double pixel_v_a = data->__img_gray(cv::Point(a_x, a_y));
		double pixel_v_b = data->__img_gray(cv::Point(b_x, b_y));

		pdfeats(k, 0) = pixel_v_a - pixel_v_b;
	}

	cv::Mat_<int> cind = cv::Mat::zeros(pdfeats.rows, 1, CV_32SC1);

	for (int i = 0; i < cind.rows; i++){
		if (pdfeats(i, 0) >= threshs(i,0)){
			cind(i, 0) = 1;
		}else{
			cind(i, 0) = 0;
		}
	}

	cv::Mat_<int> binfeature = cv::Mat::zeros(1,(int)cv::sum(isleaf).val[0],CV_32SC1);

	int cumnum_nodes = 0;
	int cumnum_leafnodes = 0;

	for (int t=0;  t < m_Params->__max_numtrees; t++){
		int num_nodes = rf[t].__num_nodes;
		int id_cnode = 0;
		while (1){
			if (isleaf(id_cnode + cumnum_nodes)){
				binfeature(0, cumnum_leafnodes + __getindex(rf[t].__id_leafnodes, id_cnode)) = 1;
				cumnum_nodes     = cumnum_nodes + num_nodes;
				cumnum_leafnodes = cumnum_leafnodes + rf[t].__num_leafnodes;
				break;
			}
			id_cnode = cnode(cumnum_nodes + id_cnode, cind(cumnum_nodes + id_cnode,0));
		}
	}
	return binfeature;
}

int cBinaryFeat::__getindex(const cv::Mat_<int>&src, int val)
{
	for (int i =0; i < src.rows; i++){
		if (src(i, 0) == val){
			return i;
		}
	}
	return -1;
}

max_stars_repo_name: MichaelXin/face-alignment-cpp

max_issues_repo_name: MichaelXin/face-alignment-cpp

max_forks_repo_name: jwyang/face-alignment-cpp


text:
//
// Created by Michał Dziewulski on 14.01.2018.
//
#ifndef WIN32
#  define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE GraphIsomorphismTests
#include <boost/test/unit_test.hpp>

ext: cc

max_stars_repo_name: mDevv/GraphIsomorphism

max_issues_repo_name: mDevv/GraphIsomorphism

max_forks_repo_name: mDevv/GraphIsomorphism


text:
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2006 Klaus Spanderen

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <quantlib-dev@lists.sf.net>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 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 license for more details.
*/

#ifndef quantlib_test_linear_least_squares_regression_hpp
#define quantlib_test_linear_least_squares_regression_hpp

#include <boost/test/unit_test.hpp>

/* remember to document new and/or updated tests in the Doxygen
   comment block of the corresponding class */

class LinearLeastSquaresRegressionTest {
  public:
    static void testRegression();
    static void testMultiDimRegression();
    static void test1dLinearRegression();
    static boost::unit_test_framework::test_suite* suite();
};

/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2006 Klaus Spanderen
 Copyright (C) 2010 Slava Mazur

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <quantlib-dev@lists.sf.net>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 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 license for more details.
*/

#include "utilities.hpp"
#include <ql/math/functional.hpp>
#include <ql/math/randomnumbers/rngtraits.hpp>
#include <ql/math/linearleastsquaresregression.hpp>
#if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4))
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif
#include <boost/bind.hpp>
#include <boost/circular_buffer.hpp>
#if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4))
#pragma GCC diagnostic pop
#endif

using namespace QuantLib;
using namespace boost::unit_test_framework;

void LinearLeastSquaresRegressionTest::testRegression() {

    BOOST_TEST_MESSAGE("Testing linear least-squares regression...");

    SavedSettings backup;

    const Real tolerance = 0.05;

    const Size nr=100000;
    PseudoRandom::rng_type rng(PseudoRandom::urng_type(1234u));

    std::vector<boost::function1<Real, Real> > v;
    v.push_back(constant<Real, Real>(1.0));
    v.push_back(QuantLib::identity<Real>());
    v.push_back(square<Real>());
    v.push_back(std::ptr_fun<Real, Real>(std::sin));

    std::vector<boost::function1<Real, Real> > w(v);
    w.push_back(square<Real>());

    for (Size k=0; k<3; ++k) {
        Size i;
        const Real a[] = {rng.next().value,
            rng.next().value,
            rng.next().value,
            rng.next().value};

        std::vector<Real> x(nr), y(nr);
        for (i=0; i<nr; ++i) {
            x[i] = rng.next().value;

            // regression in y = a_1 + a_2*x + a_3*x^2 + a_4*sin(x) + eps
            y[i] =  a[0]*v[0](x[i]) + a[1]*v[1](x[i]) + a[2]*v[2](x[i])
                + a[3]*v[3](x[i]) + rng.next().value;
        }

        LinearRegression m(x, y, v);

        for (i=0; i<v.size(); ++i) {
            if (m.standardErrors()[i] > tolerance) {
                BOOST_ERROR("Failed to reproduce linear regression coef."
                    << "\n    error:     " << m.standardErrors()[i]
                << "\n    tolerance: " << tolerance);
            }
            if (std::fabs(m.coefficients()[i]-a[i]) > 3*m.standardErrors()[i]) {
                BOOST_ERROR("Failed to reproduce linear regression coef."
                    << "\n    calculated: " << m.coefficients()[i]
                << "\n    error:      " << m.standardErrors()[i]
                << "\n    expected:   " << a[i]);
            }
        }

        m = LinearRegression(x, y, w);

        const Real ma[] = {m.coefficients()[0], m.coefficients()[1],
            m.coefficients()[2]+m.coefficients()[4],
            m.coefficients()[3]};
        const Real err[] = {m.standardErrors()[0], m.standardErrors()[1],
            std::sqrt( m.standardErrors()[2]*m.standardErrors()[2]
        +m.standardErrors()[4]*m.standardErrors()[4]),
            m.standardErrors()[3]};
        for (i=0; i<v.size(); ++i) {
            if (std::fabs(ma[i] - a[i]) > 3*err[i]) {
                BOOST_ERROR("Failed to reproduce linear regression coef."
                    << "\n    calculated: " << ma[i]
                << "\n    error:      " << err[i]
                << "\n    expected:   " << a[i]);
            }
        }
    }
}

namespace {
    Real f(const Array& a, Size i) {
        return a[i];
    }
}

void LinearLeastSquaresRegressionTest::testMultiDimRegression() {

    BOOST_TEST_MESSAGE(
        "Testing multi-dimensional linear least-squares regression...");

    SavedSettings backup;

    const Size nr=100000;
    const Size dims = 4;
    const Real tolerance = 0.01;
    PseudoRandom::rng_type rng(PseudoRandom::urng_type(1234u));

    std::vector<boost::function1<Real, Array> > v;
    v.push_back(constant<Array, Real>(1.0));
    for (Size i=0; i < dims; ++i) {
        v.push_back(boost::bind(f, _1, i));
    }

    Array coeff(v.size());
    for (Size i=0; i < v.size(); ++i) {
        coeff[i] = rng.next().value;
    }

    std::vector<Real> y(nr, 0.0);
    std::vector<Array> x(nr, Array(dims));
    for (Size i=0; i < nr; ++i) {
        for (Size j=0; j < dims; ++j) {
            x[i][j] = rng.next().value;
        }

        for (Size j=0; j < v.size(); ++j) {
            y[i] += coeff[j]*v[j](x[i]);
        }
        y[i] += rng.next().value;
    }

    LinearRegression m(x, y, v);

    for (Size i=0; i < v.size(); ++i) {
        if (m.standardErrors()[i] > tolerance) {
            BOOST_ERROR("Failed to reproduce linear regression coef."
                << "\n    error:     " << m.standardErrors()[i]
            << "\n    tolerance: " << tolerance);
        }

        if (std::fabs(m.coefficients()[i]-coeff[i]) > 3*tolerance) {
            BOOST_ERROR("Failed to reproduce linear regression coef."
                << "\n    calculated: " << m.coefficients()[i]
            << "\n    error:      " << m.standardErrors()[i]
            << "\n    expected:   " << coeff[i]);
        }
    }

    // much simpler
    LinearRegression m1(x, y, Real(1.0));

    for (Size i=0; i < m1.dim(); ++i) {
        if (m1.standardErrors()[i] > tolerance) {
            BOOST_ERROR("Failed to reproduce linear regression coef."
                << "\n    error:     " << m1.standardErrors()[i]
            << "\n    tolerance: " << tolerance);
        }

        if (std::fabs(m1.coefficients()[i]-coeff[i]) > 3*tolerance) {
            BOOST_ERROR("Failed to reproduce linear regression coef."
                << "\n    calculated: " << m1.coefficients()[i]
            << "\n    error:      " << m1.standardErrors()[i]
            << "\n    expected:   " << coeff[i]);
        }
    }
}

void LinearLeastSquaresRegressionTest::test1dLinearRegression() {

    BOOST_TEST_MESSAGE("Testing 1D simple linear least-squares regression...");

    /* Example taken from the QuantLib-User list, see posting
    * Multiple linear regression/weighted regression, Boris Skorodumov */

    SavedSettings backup;

    std::vector<Real> x(9),y(9);
    x[0]=2.4; x[1]=1.8; x[2]=2.5; x[3]=3.0;
    x[4]=2.1; x[5]=1.2; x[6]=2.0; x[7]=2.7; x[8]=3.6;

    y[0]=7.8; y[1]=5.5; y[2]=8.0; y[3]=9.0;
    y[4]=6.5; y[5]=4.0; y[6]=6.3; y[7]=8.4; y[8]=10.2;

    std::vector<boost::function1<Real, Real> > v;
    v.push_back(constant<Real, Real>(1.0));
    v.push_back(QuantLib::identity<Real>());

    LinearRegression m(x, y);

    const Real tol = 0.0002;
    const Real coeffExpected[]  = { 0.9448, 2.6853 };
    const Real errorsExpected[] = { 0.3654, 0.1487 };

    for (Size i=0; i < 2; ++i) {
        if (std::fabs(m.standardErrors()[i]-errorsExpected[i]) > tol) {
            BOOST_ERROR("Failed to reproduce linear regression standard errors"
                << "\n    calculated: " << m.standardErrors()[i]
            << "\n    expected:   " << errorsExpected[i]
            << "\n    tolerance:  " << tol);
        }

        if (std::fabs(m.coefficients()[i]-coeffExpected[i]) > tol) {
            BOOST_ERROR("Failed to reproduce linear regression coef."
                << "\n    calculated: " << m.coefficients()[i]
            << "\n    expected:   " << coeffExpected[i]
            << "\n    tolerance:  " << tol);
        }
    }

    // an alternative container type
    boost::circular_buffer<Real> cx(x.begin(), x.end()), cy(y.begin(), y.end());
    LinearRegression m1(cx, cy);

    for (Size i=0; i < 2; ++i) {
        if (std::fabs(m1.standardErrors()[i]-errorsExpected[i]) > tol) {
            BOOST_ERROR("Failed to reproduce linear regression standard errors"
                << "\n    calculated: " << m1.standardErrors()[i]
            << "\n    expected:   " << errorsExpected[i]
            << "\n    tolerance:  " << tol);
        }

        if (std::fabs(m1.coefficients()[i]-coeffExpected[i]) > tol) {
            BOOST_ERROR("Failed to reproduce linear regression coef."
                << "\n    calculated: " << m1.coefficients()[i]
            << "\n    expected:   " << coeffExpected[i]
            << "\n    tolerance:  " << tol);
        }
    }
}

test_suite* LinearLeastSquaresRegressionTest::suite() {
    test_suite* suite =
        BOOST_TEST_SUITE("linear least squares regression tests");
    suite->add(QUANTLIB_TEST_CASE(
        &LinearLeastSquaresRegressionTest::testRegression));
    suite->add(QUANTLIB_TEST_CASE(
        &LinearLeastSquaresRegressionTest::testMultiDimRegression));
    suite->add(QUANTLIB_TEST_CASE(
        &LinearLeastSquaresRegressionTest::test1dLinearRegression));
    return suite;
}

#endif

ext: hpp

max_stars_repo_name: markxio/Quantuccia

max_issues_repo_name: markxio/Quantuccia

max_forks_repo_name: markxio/Quantuccia


text:
//
// Dashboard.hpp
//

#pragma once

#include <boost/property_tree/json_parser.hpp>
#include "Base.hpp"
#include "../ManagerHeader.hpp"
#include "../ManagerAccessor.hpp"
#include "../ResourceManager.hpp"
#include "../ui/UISuper.hpp"

using namespace boost::property_tree;

namespace scene {

class Dashboard : public Base {
    public:
        Dashboard(const ManagerAccessorPtr& manager_accessor,
			const BasePtr& background_scene);
        ~Dashboard();
        void Begin();
        void Update();
		void ProcessInput(InputManager*);
        void Draw();
        void End();

    private:
        ManagerAccessorPtr manager_accessor_;
        ConfigManagerPtr config_manager_;
        CardManagerPtr card_manager_;
        AccountManagerPtr account_manager_;
        WindowManagerPtr window_manager_;

		BasePtr background_scene_;

        int start_count_;
        int end_count_;

		int bg_alpha_;
		Rect base_rect_;
		std::array<ImageHandlePtr,4> base_image_handle_;
		std::array<ImageHandlePtr,3> tab_base_image_handle_;

	private:
		static const int TAB_BLOCK_HEIGHT;
		static const int TAB_BLOCK_WIDTH;
};

}


text:
// ------------------------------------------------------------------
// pion-net: a C++ framework for building lightweight HTTP interfaces
// ------------------------------------------------------------------
// Copyright (C) 2007-2008 Atomic Labs, Inc.  (http://www.atomiclabs.com)
//
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
//

#ifndef __PION_HTTPREQUEST_HEADER__
#define __PION_HTTPREQUEST_HEADER__

#include <boost/shared_ptr.hpp>
#include <pion/PionConfig.hpp>
#include <pion/net/HTTPMessage.hpp>
#include <pion/net/PionUser.hpp>

namespace pion {	// begin namespace pion
namespace net {		// begin namespace net (Pion Network Library)

///
/// HTTPRequest: container for HTTP request information
///
class HTTPRequest
	: public HTTPMessage
{
public:

	/**
	 * constructs a new HTTPRequest object
	 *
	 * @param resource the HTTP resource to request
	 */
	HTTPRequest(const std::string& resource)
		: m_method(REQUEST_METHOD_GET), m_resource(resource) {}

	/// constructs a new HTTPRequest object (default constructor)
	HTTPRequest(void) : m_method(REQUEST_METHOD_GET) {}

	/// virtual destructor
	virtual ~HTTPRequest() {}

	/// clears all request data
	virtual void clear(void) {
		HTTPMessage::clear();
		m_method.erase();
		m_resource.erase();
		m_original_resource.erase();
		m_query_string.erase();
		m_query_params.clear();
		m_user_record.reset();
	}

	/// the content length of the message can never be implied for requests
	virtual bool isContentLengthImplied(void) const { return false; }

	/// returns the request method (i.e. GET, POST, PUT)
	inline const std::string& getMethod(void) const { return m_method; }

	/// returns the resource uri-stem to be delivered (possibly the result of a redirect)
	inline const std::string& getResource(void) const { return m_resource; }

	/// returns the resource uri-stem originally requested
	inline const std::string& getOriginalResource(void) const { return m_original_resource; }

	/// returns the uri-query or query string requested
	inline const std::string& getQueryString(void) const { return m_query_string; }

	/// returns a value for the query key if any are defined; otherwise, an empty string
	inline const std::string& getQuery(const std::string& key) const {
		return getValue(m_query_params, key);
	}

	/// returns the query parameters
	inline QueryParams& getQueryParams(void) {
		return m_query_params;
	}

	/// returns true if at least one value for the query key is defined
	inline bool hasQuery(const std::string& key) const {
		return(m_query_params.find(key) != m_query_params.end());
	}

	/// sets the HTTP request method (i.e. GET, POST, PUT)
	inline void setMethod(const std::string& str) {
		m_method = str;
		clearFirstLine();
	}

	/// sets the resource or uri-stem originally requested
	inline void setResource(const std::string& str) {
		m_resource = m_original_resource = str;
		clearFirstLine();
	}

	/// changes the resource or uri-stem to be delivered (called as the result of a redirect)
	inline void changeResource(const std::string& str) { m_resource = str; }

	/// sets the uri-query or query string requested
	inline void setQueryString(const std::string& str) {
		m_query_string = str;
		clearFirstLine();
	}

	/// adds a value for the query key
	inline void addQuery(const std::string& key, const std::string& value) {
		m_query_params.insert(std::make_pair(key, value));
	}

	/// changes the value of a query key
	inline void changeQuery(const std::string& key, const std::string& value) {
		changeValue(m_query_params, key, value);
	}

	/// removes all values for a query key
	inline void deleteQuery(const std::string& key) {
		deleteValue(m_query_params, key);
	}

	/// use the query parameters to build a query string for the request
	inline void useQueryParamsForQueryString(void) {
		setQueryString(make_query_string(m_query_params));
	}

	/// use the query parameters to build POST content for the request
	inline void useQueryParamsForPostContent(void) {
		std::string post_content(make_query_string(m_query_params));
		setContentLength(post_content.size());
		char *ptr = createContentBuffer();	// null-terminates buffer
		if (! post_content.empty())
			memcpy(ptr, post_content.c_str(), post_content.size());
		setMethod(REQUEST_METHOD_POST);
		setContentType(CONTENT_TYPE_URLENCODED);
	}

	/// add content (for POST) from string
	inline void setContent(const std::string &value) {
		setContentLength(value.size());
		char *ptr = createContentBuffer();
		if (! value.empty())
			memcpy(ptr, value.c_str(), value.size());
	}

	/// sets the user record for HTTP request after authentication
	inline void setUser(PionUserPtr user) { m_user_record = user; }

	/// get the user record for HTTP request after authentication
	inline PionUserPtr getUser() const { return m_user_record; }

protected:

	/// updates the string containing the first line for the HTTP message
	virtual void updateFirstLine(void) const {
		// start out with the request method
		m_first_line = m_method;
		m_first_line += ' ';
		// append the resource requested
		m_first_line += m_resource;
		if (! m_query_string.empty()) {
			// append query string if not empty
			m_first_line += '?';
			m_first_line += m_query_string;
		}
		m_first_line += ' ';
		// append HTTP version
		m_first_line += getVersionString();
	}

private:

	/// request method (GET, POST, PUT, etc.)
	std::string						m_method;

	/// name of the resource or uri-stem to be delivered
	std::string						m_resource;

	/// name of the resource or uri-stem originally requested
	std::string						m_original_resource;

	/// query string portion of the URI
	std::string						m_query_string;

	/// HTTP query parameters parsed from the request line and post content
	QueryParams						m_query_params;

	/// pointer to PionUser record if this request had been authenticated
	PionUserPtr						m_user_record;
};

/// data type for a HTTP request pointer
typedef boost::shared_ptr<HTTPRequest>		HTTPRequestPtr;

}	// end namespace net
}	// end namespace pion

#endif

max_stars_repo_name: marshallmcmullen/pion

max_issues_repo_name: marshallmcmullen/pion

max_forks_repo_name: marshallmcmullen/pion


text:
/**
 * Copyright Soramitsu Co., Ltd. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */
#ifndef IROHA_HEXUTILS_HPP
#define IROHA_HEXUTILS_HPP

#include <ciso646>
#include <iomanip>
#include <sstream>
#include <string>

#include <boost/optional.hpp>

namespace iroha {

  /**
   * Convert string of raw bytes to printable hex string
   * @param str - raw bytes string to convert
   * @return - converted hex string
   */
  inline std::string bytestringToHexstring(const std::string &str) {
    std::stringstream ss;
    ss << std::hex << std::setfill('0');
    for (const auto &c : str) {
      ss << std::setw(2) << (static_cast<int>(c) & 0xff);
    }
    return ss.str();
  }

  /**
   * Convert printable hex string to string of raw bytes
   * @param str - hex string to convert
   * @return - raw bytes converted string or boost::noneif provided string
   * was not a correct hex string
   */
  inline boost::optional<std::string> hexstringToBytestring(
      const std::string &str) {
    if (str.empty() or str.size() % 2 != 0) {
      return boost::none;
    }
    std::string result(str.size() / 2, 0);
    for (size_t i = 0; i < result.length(); ++i) {
      std::string byte = str.substr(i * 2, 2);
      size_t pos = 0;  // processed characters count
      try {
        result.at(i) =
            static_cast<std::string::value_type>(std::stoul(byte, &pos, 16));
      } catch (const std::invalid_argument &) {
        return boost::none;
      } catch (const std::out_of_range &) {
        return boost::none;
      }
      if (pos != byte.size()) {
        return boost::none;
      }
    }
    return result;
  }

}  // namespace iroha

#endif  // IROHA_HEXUTILS_HPP

max_stars_repo_name: artyom-yurin/iroha-archive

max_issues_repo_name: artyom-yurin/iroha-archive

max_forks_repo_name: artyom-yurin/iroha-archive