Exemplo n.º 1
0
TEST(HitTests, Formatter)
{
  RenderCase cases[] = {
      {"[format]line_length=100[]",
       "foo='line longer than 20 characters'",
       "foo = 'line longer than 20 characters'",
       0},
      {"[format]line_length=20[]",
       "foo='line longer than 20 characters'",
       "foo = 'line longer '\n      'than 20 '\n      'characters'",
       0},
      {"[format]canonical_section_markers=true[]", "[./foo][../]", "[foo]\n[]", 0},
      {"[format]canonical_section_markers=false[]", "[./foo][../]", "[./foo]\n[../]", 0},
      {"[format]indent_string='    '[]", "[foo]bar=42[]", "[foo]\n    bar = 42\n[]", 0},
      {"[format]indent_string='      '[]", "[foo]bar=42[]", "[foo]\n      bar = 42\n[]", 0},
  };

  for (size_t i = 0; i < sizeof(cases) / sizeof(RenderCase); i++)
  {
    auto test = cases[i];
    std::string got;
    try
    {
      hit::Formatter fmter("STYLE", test.name);
      got = fmter.format("TESTCASE", test.input);
    }
    catch (std::exception & err)
    {
      FAIL() << "case " << i + 1 << " FAIL (" << test.name << "): unexpected error: " << err.what();
    }
    EXPECT_EQ(test.output, got) << "case " << i + 1 << " FAIL (" << test.name << ")";
  }
}
Exemplo n.º 2
0
	int db_createPlayerInfo(Connection *conn, const PlayerInfo *info)
	{
		boost::format fmter("insert into g_user(user_name,user_pwd,level,gender,role_id,scene_id,x,y) values('%s','%s',%d,%d,%d,%d,%d,%d)");
		fmter % info->user_name;
		fmter % info->user_pwd;
		fmter % info->level;
		fmter % (int)info->gender;
		fmter % info->role_id;
		fmter % info->scene_id;
		fmter % info->x;
		fmter % info->y;
		
		std::string sql = boost::str(fmter);
		int ret = 0;
		
		Statement *stmt = conn->createStatement();
		try
		{
			ret = stmt->executeUpdate(sql.c_str());
		}
		catch (sql::SQLException &e)
		{
			sLog.outError("[db_createPlayerInfo] sql error :%s errorCode: %d", e.what(), e.getErrorCode());
		}
	
		delete stmt;
		return ret;
	}
Exemplo n.º 3
0
int GLFWEngine::InitWindow(WindowSettings& w)
{

	if (!glfwInit())
		throw;

	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, w.OpenGLVersionMajor);
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, w.OpenGLVersionMinor);

	glfwOpenWindowHint(GLFW_OPENGL_CORE_PROFILE, 0);
	glfwOpenWindowHint(GLFW_OPENGL_COMPAT_PROFILE, 1);

	if (w.CoreProfile)
	{
		glfwOpenWindowHint(GLFW_OPENGL_CORE_PROFILE, 1);
		glfwOpenWindowHint(GLFW_OPENGL_COMPAT_PROFILE, 0);
	}

	int windowType = w.Fullscreen ? GLFW_FULLSCREEN: GLFW_WINDOW;

	int err = glfwOpenWindow(w.Width, w.Height, w.RedBits, w.GreenBits, w.BlueBits, w.AlphaBits, w.DepthBits, w.StencilBits, windowType);

	if (w.Title == "")
	{
		boost::format fmter("OpenGL %1%.%2% Context, %3% mode");
		int glMinor, glMajor;
		char modeString[] = "Compatibility";
		glMinor = glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR);
		glMajor = glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR);		
		if (glfwGetWindowParam(GLFW_OPENGL_CORE_PROFILE))
			sprintf(modeString, "Core");
		fmter % glMajor % glMinor % modeString;
		w.Title = fmter.str();
	}
	glfwSetWindowTitle(w.Title.c_str());

	*currentSettings = w;
	glewExperimental = true;
	GLenum glewErr = glewInit();
	if (glewErr != GLEW_OK)
	{
		printf("Glew Error: %s\n", glewGetErrorString(glewErr));
		return 1;
	}

	static int val = (int)__glewBindBuffer;
	static int* loc = (int*)&__glewBindBuffer;
	return err;
}
Exemplo n.º 4
0
void wx_vote::do_task(boost::property_tree::ptree& pt, std::string& result)
{
    target_count = pt.get<int>("votes_cnt");
    std::string vote_url = pt.get<std::string>("url");
    boost::format fmter(kvote_ret_fmt);

    if (wx_account_mgr::get().get_idle_not_vote_count(vote_url) < target_count)
    {
        fmter % pt.get<int>("task_id")
            % pt.get<int>("task_cmd")
            % -1
            % 0
            % "There's no too many accounts.";
        result = fmter.str();
        return;
    }

    boost::thread_group threads;
    for (auto c : device_mgr::get().get_devices_pro_copy())
    {
        if (c.second.status != DEVICE_STATUS_ONLINE_IDLE)
            continue;

        boost::shared_ptr<wx_vote_session> wx_vote_ses(new wx_vote_session(c.first, SCRIPT_PORT, pt, this));
        threads.create_thread(boost::bind(&wx_vote_session::start, wx_vote_ses));
    }

    threads.join_all();

    fmter % pt.get<int>("task_id")
        % pt.get<int>("task_cmd")
        % 0
        % success_count
        % "ok";
    result = fmter.str();
    success_count = 0;
}
Exemplo n.º 5
0
 str str::operator%(types::array<T, N> const &a) const
 {
   boost::format fmter(*data);
   fmt(fmter, a, utils::int_<N>());
   return fmter.str();
 }
Exemplo n.º 6
0
 types::str str::operator%(std::tuple<A...> const &a) const
 {
   boost::format fmter(*data);
   fmt(fmter, a, utils::int_<sizeof...(A)>());
   return fmter.str();
 }
Exemplo n.º 7
0
int main(int ac, char* av[])
{	
	int use_video;					// Use camera or directory
	std::string publisher_mode;		// (tcp://*:8666) 
	std::string image_dir;			// Image directory used if input is directory
	std::string image_extension;	// Image type (.jpg, .tif, .bmp, .png)
	int debugMode;					// Display image 
	int equalizeHist;				// Use the histogram equalization
	std::string ROI;				// ROI applied to the image sent

	try
	{
		// Parse program options
		// Parse program options...
		po::options_description desc("Allowed options");
		desc.add_options()
            ("help,h", "produce help message")
			("Publisher_mode,p",  po::value<std::string>(&publisher_mode)->default_value("tcp://*:8666"), "UDP server port")
			("video,v",  po::value<int>(&use_video)->default_value(0), "Use camera flag") 
			("debug,g",  po::value<int>(&debugMode)->default_value(0), "Debug mode") 
			("equalize,q",  po::value<int>(&equalizeHist)->default_value(0), "Equalize histogram")
			("ROI,r", po::value<std::string>(&ROI)->default_value(""),"Apply ROI on image sent.")
			("directory,d", po::value<std::string>(&image_dir)->default_value("."),"Image directory.")
			("extension,e", po::value<std::string>(&image_extension)->default_value(".jpg"),"Image extension.")
        ;
		po::variables_map vm;        
        po::store(po::parse_command_line(ac, av, desc), vm);
        po::notify(vm);

		if (vm.count("help")) 
		{
			std::cout << desc << std::endl;
            return 1;
        }
		if (vm.count("video")) 
		{            
			std::cout << "Video mode set to " << vm["video"].as<int>() << std::endl;
        }
		if (vm.count("Publisher_mode")) 
		{            
			std::cout << "Publisher mode set to " << vm["Publisher_mode"].as<std::string>() << std::endl;
        }
		if (vm.count("directory"))
        {            
			std::cout << "Image directory: " << vm["directory"].as<std::string>() << std::endl;			
        }
		if (vm.count("extension"))
        {            
			std::cout << "Image extension: " << vm["extension"].as<std::string>() << std::endl;			
        }

		// Initialize ImageFactory
		ImageFactory imFactory(use_video,image_dir,image_extension,debugMode,ROI,equalizeHist);

		// Initialize ImageGather (prepare images to be sent)
		ImageGather  imgGather(imFactory);
		
		// Initialize ZMQ
		zmq::context_t context (1);

		// Get socket to publish 
		zmq::socket_t publisher (context, ZMQ_PUB);

		// Bind the socket to some port (TCP,or IPC)
		publisher.bind(publisher_mode.c_str());			
		
		while(1)
		{						
			// Get image to be sent
			GenericImage image;
			imgGather.prepareImage(image);						
			
			// Create message content
			boost::format fmter("%05d ");									// Format string 5 = 000005
			fmter % image.getHeader().length();
			std::string headerSize = fmter.str();
			std::string completeHeader = headerSize + image.getHeader();			

			// Create a message			
			zmq::message_t message(completeHeader.length() + image.getSize() + 1);			

			// Copy image header
			memcpy((char*) message.data(), completeHeader.c_str(), completeHeader.length());	
			
			// Copy image content
			char *postHeader = (char*) message.data();
			postHeader += completeHeader.length() + 1;			
			memcpy((char*)postHeader,image.getImageBuffer(), image.getSize()); 
			
			// Broadcast this message
			publisher.send(message);			
		}
	}
	catch(std::exception &e)
	{		
		std::cerr << e.what() << std::endl;
	}
	std::cout << "Image broadcast closing" << std::endl;

	return 0;
}