blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 4 201 | content_id stringlengths 40 40 | detected_licenses listlengths 0 85 | license_type stringclasses 2
values | repo_name stringlengths 7 100 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 260
values | visit_date timestamp[us] | revision_date timestamp[us] | committer_date timestamp[us] | github_id int64 11.4k 681M ⌀ | star_events_count int64 0 209k | fork_events_count int64 0 110k | gha_license_id stringclasses 17
values | gha_event_created_at timestamp[us] | gha_created_at timestamp[us] | gha_language stringclasses 80
values | src_encoding stringclasses 28
values | language stringclasses 1
value | is_vendor bool 1
class | is_generated bool 2
classes | length_bytes int64 8 9.86M | extension stringclasses 52
values | content stringlengths 8 9.86M | authors listlengths 1 1 | author stringlengths 0 119 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4d5a9117f680ffe25a66e3a6eaa51c21857183c5 | 37bffe9c92c9914de53aae2c6fe7d3b96027a841 | /table_setting_demo/src/multi_robot_network.cc | 4240dbc979df493813145b762e971ad6b9bf8a89 | [] | no_license | anima-unr/Distributed_Collaborative_Task_Tree_ubuntu-version-16.04 | f8ddca2f5cc36f55a94f7c3c305dc4d949741c5a | 49900ecd8b3d199851e8fc1505efadb89965ac56 | refs/heads/master | 2020-12-06T10:39:02.011615 | 2020-01-08T00:08:48 | 2020-01-08T00:08:48 | 232,440,353 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,559 | cc | /*
robotics-task-tree-eval
Copyright (C) 2015 Luke Fraser
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ros/ros.h>
#include <boost/thread/thread.hpp>
#include <boost/date_time.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <signal.h>
#include <vector>
#include <string>
#include <map>
#include "robotics_task_tree_eval/behavior.h"
#include "robotics_task_tree_msgs/node_types.h"
#include "table_setting_demo/table_object_behavior.h"
typedef std::vector<std::string> NodeParam;
// enum ROBOT {
// PR2=0,
// BAXTER=1
// } ;
void EndingFunc(int signal) {
printf("Closing Program...\n");
ros::shutdown();
}
int main(int argc, char *argv[]) {
ros::init(argc, argv, "behavior_network", ros::init_options::NoSigintHandler);
signal(SIGINT, EndingFunc);
ros::NodeHandle nh_("~");
task_net::Node ** network;
task_net::NodeId_t name_param;
std::vector<std::string> peers_param_str;
task_net::NodeList peers_param;
std::vector<std::string> children_param_str;
task_net::NodeList children_param;
task_net::NodeId_t parent_param;
NodeParam nodes;
std::string object;
std::string obj_name;
std::vector<float> neutral_object_pos;
std::vector<float> object_pos;
// get the robot
std::string Robot;
nh_.getParam("robot", Robot);
ROBOT robot_des;
if(Robot == "PR2") {
robot_des = PR2;
}
else {
robot_des = BAXTER;
}
if (nh_.getParam("NodeList", nodes)) {
printf("Tree Size: %lu\n", nodes.size());
}
else { printf("No nodeList params!!!\n");
}
network = new task_net::Node*[nodes.size()];
// Grab Node Attributes
std::string param_prefix = "Nodes/";
std::string param_ext_children = "children";
std::string param_ext_parent = "parent";
std::string param_ext_peers = "peers";
for(int i=0; i < nodes.size(); ++i) {
// Get name
name_param.topic = nodes[i];
// printf("name: %s\n", name_param.topic.c_str());
// only init the nodes for the correct robot!!!
int robot;
if (nh_.getParam((param_prefix + nodes[i] + "/mask/robot").c_str(), robot)) {
if(robot == robot_des) {
printf("Creating Task Node for:\n");
printf("\tname: %s\n", name_param.topic.c_str());
// get parent
if (nh_.getParam((param_prefix + nodes[i]
+ "/" + param_ext_parent).c_str(), parent_param.topic)) {
printf("Node: %s Parent: %s\n", nodes[i].c_str(), parent_param.topic.c_str());
}
// get children
children_param.clear();
if (nh_.getParam((param_prefix + nodes[i]
+ "/" + param_ext_children).c_str(), children_param_str)) {
for (int j = 0; j < children_param_str.size(); ++j) {
task_net::NodeId_t temp;
temp.topic = children_param_str[j];
temp.pub = NULL;
children_param.push_back(temp);
printf("Node: %s Child: %s\n", nodes[i].c_str(), temp.topic.c_str());
}
}
// get peers
peers_param.clear();
if (nh_.getParam((param_prefix + nodes[i]
+ "/" + param_ext_peers).c_str(), peers_param_str)) {
for (int j = 0; j < peers_param_str.size(); ++j) {
task_net::NodeId_t temp;
temp.topic = peers_param_str[j];
temp.pub = NULL;
peers_param.push_back(temp);
printf("Node: %s Peer: %s\n", nodes[i].c_str(), temp.topic.c_str());
}
}
// Create Node
task_net::State_t state;
task_net::Node * test;
int type;
if (nh_.getParam((param_prefix + nodes[i] + "/mask/type").c_str(), type)) {
// printf("Node: %s NodeType: %d\n", nodes[i].c_str(), type);
}
switch (type) {
case task_net::THEN:
network[i] = new task_net::ThenBehavior(name_param,
peers_param,
children_param,
parent_param,
state,
"N/A",
false);
// printf("\ttask_net::THEN %d\n",task_net::THEN);
break;
case task_net::OR:
network[i] = new task_net::OrBehavior(name_param,
peers_param,
children_param,
parent_param,
state,
"N/A",
false);
// printf("\ttask_net::OR %d\n",task_net::OR);
break;
case task_net::AND:
network[i] = new task_net::AndBehavior(name_param,
peers_param,
children_param,
parent_param,
state,
"N/A",
false);
// printf("\ttask_net::AND %d\n",task_net::AND);
break;
case task_net::BEHAVIOR:
// ROS_INFO("Children Size: %lu", children_param.size());
object = name_param.topic.c_str();
// get the name of the object of corresponding node:
nh_.getParam((param_prefix + nodes[i] + "/object").c_str(), obj_name);
// set up network for corresponding node:
ros::param::get(("/ObjectPositions/"+obj_name).c_str(), object_pos);
network[i] = new task_net::TableObject(name_param,
peers_param,
children_param,
parent_param,
state,
"/right_arm_mutex",
obj_name.c_str(),
object_pos,
neutral_object_pos,
false);
// network[i] = new task_net::DummyBehavior(name_param,
// peers_param,
// children_param,
// parent_param,
// state,
// false);
// printf("\ttask_net::PLACE %d\n",task_net::PLACE);
printf("/ObjectPositions/%s\n\n",obj_name.c_str());
break;
case task_net::ROOT:
default:
network[i] = NULL;
// printf("\ttask_net::ROOT %d\n",task_net::ROOT);
break;
}
}
// printf("MADE 5\n");
}
}
printf("MADE 6 - now spinning\n");
ros::spin();
return 0;
}
| [
"anima.csedu@gmail.com"
] | anima.csedu@gmail.com |
f2a97a5891931698012a4d7f09353de1c40b425c | 6fbcb603d86dd12c7f6a8e80beb78612c214b928 | /0427MFC2/0427MFC2/0427MFC2View.h | 5bb71814a3a5ca49ce1f44f18e546f763b366c6c | [] | no_license | balabala120/Test | 0aa903e9239f515936abfe1e82bbfa7676ba8ce7 | 3c6dff8650d6054861e5fbfad72063d2bf1e2788 | refs/heads/master | 2021-02-17T10:19:20.950855 | 2020-05-12T03:56:33 | 2020-05-12T03:56:33 | 245,087,451 | 1 | 0 | null | null | null | null | GB18030 | C++ | false | false | 1,293 | h |
// 0427MFC2View.h : CMy0427MFC2View 类的接口
//
#pragma once
class CMy0427MFC2View : public CView
{
protected: // 仅从序列化创建
CMy0427MFC2View();
DECLARE_DYNCREATE(CMy0427MFC2View)
// 特性
public:
CMy0427MFC2Doc* GetDocument() const;
// 操作
public:
CRect cr;
CPoint mouse;//记录鼠标按下的位置
int flag_mouse;//标记鼠标状态,1为按下,0为弹起。
// 重写
public:
virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
// 实现
public:
virtual ~CMy0427MFC2View();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// 生成的消息映射函数
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};
#ifndef _DEBUG // 0427MFC2View.cpp 中的调试版本
inline CMy0427MFC2Doc* CMy0427MFC2View::GetDocument() const
{ return reinterpret_cast<CMy0427MFC2Doc*>(m_pDocument); }
#endif
| [
"1804574837@qq.com"
] | 1804574837@qq.com |
05bacb05b96e5538938982fb3ae5a424d80b79dd | 4352b5c9e6719d762e6a80e7a7799630d819bca3 | /tutorials/eulerVortex.twitch/eulerVortex.cyclic.twitch.test.test/processor2/2.42/rho | 614afe321e4c9592cf8870c76acf3b39e2cba344 | [] | no_license | dashqua/epicProject | d6214b57c545110d08ad053e68bc095f1d4dc725 | 54afca50a61c20c541ef43e3d96408ef72f0bcbc | refs/heads/master | 2022-02-28T17:20:20.291864 | 2019-10-28T13:33:16 | 2019-10-28T13:33:16 | 184,294,390 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 44,044 | /*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "2.42";
object rho;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [1 -3 0 0 0 0 0];
internalField nonuniform List<scalar>
5625
(
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39999
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39999
1.39998
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39999
1.39998
1.39998
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39999
1.39998
1.39998
1.39997
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39999
1.39998
1.39998
1.39997
1.39996
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39998
1.39997
1.39996
1.39995
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39997
1.39996
1.39995
1.39994
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39997
1.39996
1.39996
1.39995
1.39994
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39997
1.39996
1.39995
1.39994
1.39993
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39997
1.39996
1.39995
1.39994
1.39993
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.39999
1.39998
1.39998
1.39997
1.39996
1.39995
1.39994
1.39994
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.39999
1.39999
1.39998
1.39997
1.39996
1.39995
1.39995
1.39995
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.4
1.39999
1.39998
1.39997
1.39997
1.39997
1.39997
1.39999
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40002
1.40002
1.40002
1.40002
1.40001
1.40001
1.4
1.4
1.39999
1.39999
1.39999
1.4
1.40002
1.40006
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40002
1.40002
1.40002
1.40002
1.40002
1.40002
1.40002
1.40001
1.40001
1.40001
1.40001
1.40003
1.40005
1.4001
1.40017
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40002
1.40003
1.40003
1.40003
1.40003
1.40003
1.40003
1.40003
1.40003
1.40003
1.40004
1.40005
1.40009
1.40014
1.40022
1.40034
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40002
1.40003
1.40003
1.40004
1.40004
1.40004
1.40004
1.40005
1.40005
1.40005
1.40006
1.40008
1.40012
1.40018
1.40027
1.4004
1.40058
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40002
1.40003
1.40004
1.40004
1.40005
1.40005
1.40006
1.40006
1.40007
1.40007
1.40009
1.40011
1.40015
1.40021
1.40031
1.40046
1.40066
1.40094
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40002
1.40003
1.40004
1.40004
1.40005
1.40006
1.40007
1.40007
1.40008
1.40009
1.40011
1.40013
1.40018
1.40024
1.40035
1.4005
1.40073
1.40103
1.40144
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40004
1.40005
1.40006
1.40007
1.40008
1.40009
1.40011
1.40013
1.40016
1.4002
1.40027
1.40038
1.40054
1.40077
1.4011
1.40155
1.40212
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40003
1.40004
1.40005
1.40006
1.40008
1.40009
1.4001
1.40012
1.40014
1.40017
1.40022
1.40029
1.4004
1.40056
1.4008
1.40114
1.40161
1.40224
1.40304
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40003
1.40004
1.40005
1.40006
1.40008
1.40009
1.40011
1.40013
1.40015
1.40019
1.40024
1.40031
1.40041
1.40057
1.40081
1.40116
1.40164
1.40229
1.40315
1.40424
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40006
1.40008
1.40009
1.40011
1.40013
1.40016
1.4002
1.40024
1.40031
1.40042
1.40057
1.40081
1.40115
1.40163
1.4023
1.40319
1.40434
1.40579
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40003
1.40005
1.40006
1.40007
1.40009
1.40011
1.40014
1.40016
1.4002
1.40025
1.40031
1.40041
1.40056
1.40078
1.40111
1.40158
1.40224
1.40315
1.40434
1.40586
1.40775
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40007
1.40009
1.40011
1.40013
1.40016
1.4002
1.40025
1.40031
1.4004
1.40054
1.40075
1.40105
1.4015
1.40214
1.40303
1.40423
1.40579
1.40777
1.41019
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40006
1.40008
1.4001
1.40012
1.40016
1.40019
1.40024
1.4003
1.40039
1.40052
1.4007
1.40098
1.4014
1.402
1.40286
1.40403
1.40559
1.4076
1.41012
1.41316
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40007
1.40009
1.40012
1.40015
1.40018
1.40023
1.40029
1.40037
1.40048
1.40065
1.40091
1.40128
1.40184
1.40263
1.40375
1.40526
1.40726
1.40982
1.41296
1.4167
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40006
1.40008
1.4001
1.40013
1.40017
1.40021
1.40027
1.40034
1.40045
1.4006
1.40082
1.40115
1.40165
1.40238
1.40341
1.40485
1.40678
1.4093
1.41247
1.41632
1.42083
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40007
1.40009
1.40012
1.40015
1.40019
1.40025
1.40032
1.40041
1.40054
1.40073
1.40103
1.40146
1.4021
1.40304
1.40436
1.40618
1.4086
1.41172
1.4156
1.42022
1.42552
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40006
1.40008
1.4001
1.40013
1.40017
1.40022
1.40028
1.40037
1.40048
1.40065
1.4009
1.40127
1.40183
1.40265
1.40384
1.40551
1.40777
1.41076
1.41456
1.41921
1.42464
1.43071
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40007
1.40009
1.40012
1.40015
1.4002
1.40025
1.40033
1.40043
1.40057
1.40078
1.40109
1.40157
1.40227
1.40331
1.4048
1.40686
1.40965
1.41328
1.41782
1.42328
1.42952
1.43627
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40007
1.4001
1.40013
1.40017
1.40022
1.40028
1.40037
1.40049
1.40067
1.40093
1.40132
1.40192
1.4028
1.40409
1.40592
1.40845
1.41182
1.41616
1.4215
1.42777
1.43474
1.44202
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40006
1.40008
1.40011
1.40014
1.40019
1.40025
1.40032
1.40042
1.40057
1.40078
1.40111
1.40159
1.40233
1.40342
1.405
1.40723
1.41028
1.4143
1.41939
1.42555
1.43259
1.44015
1.4477
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40004
1.40005
1.40006
1.40009
1.40012
1.40016
1.40021
1.40027
1.40036
1.40048
1.40065
1.40091
1.4013
1.4019
1.4028
1.40413
1.40604
1.40872
1.41235
1.41708
1.42296
1.42991
1.43761
1.44556
1.45305
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40005
1.40007
1.4001
1.40013
1.40017
1.40022
1.4003
1.4004
1.40054
1.40075
1.40106
1.40153
1.40226
1.40334
1.40494
1.40723
1.41041
1.41466
1.42013
1.4268
1.43447
1.44268
1.45072
1.45776
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40006
1.40008
1.4001
1.40014
1.40019
1.40024
1.40033
1.40044
1.4006
1.40085
1.40122
1.40179
1.40266
1.40396
1.40586
1.40856
1.41228
1.4172
1.42342
1.43084
1.43912
1.44759
1.45539
1.46159
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40006
1.40008
1.40011
1.40015
1.4002
1.40026
1.40036
1.40049
1.40067
1.40096
1.4014
1.40208
1.4031
1.40464
1.40688
1.41003
1.41433
1.41994
1.4269
1.435
1.44371
1.45217
1.45937
1.46434
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40006
1.40009
1.40012
1.40016
1.40021
1.40028
1.40038
1.40053
1.40075
1.40108
1.4016
1.40239
1.4036
1.40539
1.40799
1.41163
1.41653
1.42284
1.43051
1.43917
1.44809
1.45623
1.46248
1.46588
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40005
1.40006
1.40009
1.40012
1.40016
1.40022
1.4003
1.40041
1.40058
1.40083
1.40121
1.40181
1.40273
1.40413
1.40621
1.40919
1.41334
1.41886
1.42585
1.43415
1.44322
1.45212
1.45964
1.46461
1.46621
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40003
1.40005
1.40007
1.40009
1.40013
1.40017
1.40023
1.40032
1.40044
1.40063
1.40091
1.40135
1.40204
1.4031
1.40471
1.40708
1.41047
1.41514
1.42128
1.42892
1.43776
1.44706
1.45567
1.46228
1.46575
1.46537
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40004
1.40005
1.40007
1.40009
1.40013
1.40018
1.40024
1.40033
1.40047
1.40068
1.40099
1.4015
1.40228
1.40349
1.40532
1.40801
1.41182
1.41701
1.42376
1.43199
1.44124
1.45058
1.45867
1.46414
1.46592
1.46348
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40004
1.40005
1.40007
1.4001
1.40013
1.40018
1.40025
1.40035
1.4005
1.40072
1.40108
1.40165
1.40253
1.4039
1.40596
1.40897
1.4132
1.41892
1.42624
1.43499
1.44453
1.45371
1.46107
1.46522
1.46523
1.46072
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40004
1.40005
1.40007
1.4001
1.40013
1.40018
1.40025
1.40036
1.40052
1.40077
1.40117
1.4018
1.40279
1.40433
1.40662
1.40995
1.41461
1.42083
1.42869
1.43786
1.44755
1.45641
1.46287
1.4656
1.46379
1.45725
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40004
1.40005
1.40007
1.40009
1.40013
1.40018
1.40026
1.40037
1.40054
1.40082
1.40126
1.40196
1.40306
1.40475
1.40728
1.41093
1.41601
1.42271
1.43105
1.44057
1.45026
1.45865
1.4641
1.46535
1.46176
1.45328
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40004
1.40005
1.40007
1.40009
1.40013
1.40018
1.40026
1.40038
1.40056
1.40086
1.40134
1.40211
1.40332
1.40518
1.40794
1.41191
1.41738
1.42454
1.43329
1.44305
1.45264
1.46045
1.46482
1.4646
1.45929
1.44898
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40005
1.40006
1.40009
1.40013
1.40018
1.40026
1.40038
1.40058
1.4009
1.40142
1.40225
1.40357
1.40559
1.40858
1.41286
1.4187
1.42627
1.43538
1.4453
1.45468
1.46183
1.46511
1.46346
1.45654
1.44452
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40006
1.40009
1.40012
1.40017
1.40025
1.40038
1.40059
1.40093
1.40149
1.40239
1.40381
1.40598
1.40919
1.41375
1.41994
1.42787
1.43728
1.44728
1.4564
1.46285
1.46506
1.46206
1.45365
1.44007
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40006
1.40008
1.40011
1.40017
1.40025
1.40038
1.4006
1.40096
1.40155
1.40252
1.40403
1.40635
1.40975
1.41458
1.42109
1.42933
1.43897
1.44899
1.4578
1.46357
1.46477
1.46053
1.45076
1.43578
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40004
1.40005
1.40007
1.40011
1.40016
1.40024
1.40037
1.4006
1.40098
1.40161
1.40262
1.40423
1.40667
1.41026
1.41533
1.42211
1.43062
1.44044
1.45044
1.45892
1.46403
1.46431
1.45897
1.44799
1.43176
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40005
1.40007
1.4001
1.40014
1.40022
1.40036
1.40059
1.40099
1.40165
1.40271
1.4044
1.40696
1.41071
1.41597
1.42299
1.43173
1.44167
1.45163
1.4598
1.4643
1.46377
1.45748
1.44545
1.42814
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40004
1.40006
1.40008
1.40013
1.40021
1.40035
1.40058
1.40099
1.40167
1.40278
1.40453
1.40719
1.41107
1.41651
1.42372
1.43263
1.44268
1.45257
1.46045
1.46445
1.46322
1.45614
1.44325
1.42501
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40002
1.40003
1.40005
1.40007
1.40011
1.40019
1.40033
1.40057
1.40098
1.40168
1.40282
1.40462
1.40736
1.41135
1.41692
1.42429
1.43334
1.44344
1.45327
1.46093
1.46451
1.46272
1.45503
1.44145
1.42247
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40004
1.40006
1.4001
1.40017
1.40031
1.40055
1.40097
1.40168
1.40284
1.40468
1.40747
1.41154
1.41721
1.42468
1.43383
1.44397
1.45375
1.46124
1.46452
1.46233
1.45419
1.44013
1.42058
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40002
1.40003
1.40005
1.40008
1.40015
1.40028
1.40052
1.40094
1.40165
1.40283
1.40468
1.40751
1.41163
1.41736
1.42489
1.4341
1.44427
1.45401
1.46141
1.46452
1.46209
1.45366
1.43931
1.41942
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40003
1.40006
1.40013
1.40025
1.40048
1.4009
1.40161
1.40279
1.40465
1.40748
1.41162
1.41737
1.42492
1.43416
1.44434
1.45406
1.46144
1.46452
1.46202
1.45348
1.43903
1.419
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.40001
1.40004
1.4001
1.40022
1.40044
1.40085
1.40156
1.40272
1.40457
1.40739
1.41151
1.41724
1.42477
1.43399
1.44417
1.45392
1.46134
1.46452
1.46211
1.45365
1.43929
1.41935
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39999
1.4
1.40002
1.40008
1.40019
1.4004
1.40079
1.40148
1.40262
1.40445
1.40723
1.4113
1.41697
1.42444
1.43359
1.44377
1.45357
1.46111
1.46451
1.46237
1.45418
1.44009
1.42044
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39999
1.39998
1.39998
1.39998
1.4
1.40005
1.40015
1.40035
1.40073
1.4014
1.4025
1.40428
1.407
1.41099
1.41657
1.42393
1.43299
1.44313
1.45301
1.46074
1.46445
1.46276
1.45504
1.4414
1.42224
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39998
1.39997
1.39997
1.39998
1.40002
1.40011
1.4003
1.40066
1.4013
1.40236
1.40408
1.40671
1.4106
1.41604
1.42325
1.43218
1.44226
1.45222
1.46021
1.46435
1.46323
1.45618
1.44321
1.42472
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39997
1.39996
1.39995
1.39996
1.4
1.40008
1.40025
1.40058
1.40119
1.4022
1.40384
1.40638
1.41012
1.41538
1.42242
1.43116
1.44115
1.45119
1.4595
1.46415
1.46374
1.45753
1.44544
1.42783
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39997
1.39996
1.39995
1.39994
1.39995
1.39997
1.40004
1.4002
1.40051
1.40106
1.40202
1.40358
1.40599
1.40957
1.41463
1.42143
1.42996
1.43981
1.44991
1.45856
1.46383
1.46422
1.45899
1.44799
1.43148
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39997
1.39996
1.39994
1.39993
1.39993
1.39995
1.4
1.40015
1.40043
1.40094
1.40183
1.40329
1.40557
1.40896
1.41378
1.4203
1.42857
1.43825
1.44837
1.45736
1.46331
1.46463
1.46051
1.45074
1.43555
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39997
1.39995
1.39994
1.39992
1.39992
1.39992
1.39997
1.40009
1.40035
1.40082
1.40164
1.40299
1.40511
1.4083
1.41285
1.41907
1.42703
1.43647
1.44657
1.45587
1.46253
1.46488
1.46197
1.45358
1.43988
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.4
1.40001
1.40001
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39996
1.39995
1.39993
1.39991
1.3999
1.39991
1.39994
1.40004
1.40027
1.40069
1.40144
1.40268
1.40464
1.4076
1.41187
1.41773
1.42534
1.43449
1.44451
1.45408
1.46144
1.46488
1.4633
1.45639
1.44431
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39998
1.39998
1.39996
1.39995
1.39993
1.39991
1.39989
1.39989
1.39991
1.4
1.40019
1.40057
1.40124
1.40236
1.40416
1.40688
1.41085
1.41633
1.42353
1.43234
1.44219
1.45195
1.45997
1.46452
1.46438
1.45906
1.4487
)
;
boundaryField
{
emptyPatches_empt
{
type empty;
}
top_cyc
{
type cyclic;
}
bottom_cyc
{
type cyclic;
}
inlet_cyc
{
type cyclic;
}
outlet_cyc
{
type cyclic;
}
procBoundary2to0
{
type processor;
value nonuniform List<scalar>
75
(
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.4
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.4
1.4
1.4
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39997
1.39996
1.39994
1.39993
1.3999
1.39988
1.39987
1.39989
1.39996
1.40012
1.40045
1.40105
1.40206
1.40368
1.40616
1.4098
1.41488
1.42163
1.43003
1.43965
1.4495
1.4581
1.46374
1.46507
1.46146
1.45292
)
;
}
procBoundary2to0throughtop_cyc
{
type processorCyclic;
value nonuniform List<scalar>
75
(
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.4
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.40001
1.40001
1.40001
1.4
1.40001
1.40001
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
)
;
}
procBoundary2to3
{
type processor;
value nonuniform List<scalar>
75
(
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.4
1.39999
1.39999
1.39998
1.39998
1.39997
1.39996
1.39996
1.39995
1.39994
1.39993
1.39992
1.39993
1.39994
1.39997
1.40002
1.40012
1.40027
1.4005
1.40083
1.4013
1.40196
1.40285
1.40404
1.40558
1.40755
1.41003
1.41306
1.41671
1.42099
1.42588
1.43132
1.43716
1.44318
1.44911
1.45462
1.45937
1.46306
1.46544
1.4664
1.4659
1.46402
1.4609
1.45674
1.45175
1.44616
1.44016
1.43396
1.42775
1.42169
1.41594
1.41063
1.40588
1.40181
1.39849
1.396
1.39442
1.3938
1.39418
1.39555
1.39787
1.40109
1.40513
1.40991
1.41533
1.42122
1.42739
1.43366
)
;
}
procBoundary2to3throughinlet_cyc
{
type processorCyclic;
value nonuniform List<scalar>
75
(
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
1.40001
)
;
}
}
// ************************************************************************* //
| [
"tdg@debian"
] | tdg@debian | |
0732ba657433905437011ee1a1fd79900cede229 | b39a9829da71231d16c5ac18d5be29510054fbaf | /server/util.cpp | 72acd43e82c9fb2a253572de50ecffa35bc45e11 | [] | no_license | trojsten/proboj-2017-jesen | d140accd2d8889b5e5dc7f1adbbe06add039b6ad | bed8e66eb673f9acdf5ce5a051106e3fe57d3c2c | refs/heads/master | 2021-05-15T12:30:30.479349 | 2017-11-28T15:00:34 | 2017-11-28T15:00:34 | 108,453,908 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,594 | cpp | //universal proboj magic
#include <cstdio>
#include <ctime>
#include <cstring>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <sstream>
#include <atomic>
using namespace std;
#include "util.h"
static void (*cleanupFunkcia)();
static atomic<pid_t> hlavnyProces(0);
static atomic<bool> praveUkoncujem(false);
static void shutdownHandler (int signum) {
signal(signum, SIG_DFL);
if (getpid() == hlavnyProces && !praveUkoncujem) {
praveUkoncujem = true;
fprintf(stderr, "dostal som ukoncovaci signal %s\n", strsignal(signum));
if (cleanupFunkcia) {
fprintf(stderr, "volam cleanup funkciu\n");
cleanupFunkcia();
}
}
raise(signum);
}
static void sigchldHandler (int signum) {
// handler na reapovanie zombie procesov:
// jednoduchsie by bolo pouzit SA_NOCLDWAIT, ale potom system() nedokaze
// zistit exit codes. handlovat SIGCHLD je OK, lebo system() pocas svojho
// behu SIGCHLD blokuje, takze sa nestane, ze by sme exitcode odchytili
// odtialto pred tym, ako sa k nemu dostane on, apod.
int pid, status;
while ((pid = waitpid(-1, &status, WNOHANG)), (pid > 0)) { // WTF konštrukcia by Mišo Š.
if (WIFSIGNALED(status)) {
fprintf(stderr, "proces %d umrel na: %s\n", pid, strsignal(WTERMSIG(status)) );
}
}
}
void inicializujSignaly (void (*_cleanupFunkcia)()) {
hlavnyProces = getpid(); // vo forkoch nechceme volat cleanup funkciu
cleanupFunkcia = _cleanupFunkcia;
signal(SIGCHLD, sigchldHandler);
signal(SIGINT, shutdownHandler);
signal(SIGTERM, shutdownHandler);
signal(SIGHUP, shutdownHandler);
signal(SIGSEGV, shutdownHandler);
signal(SIGFPE, shutdownHandler);
signal(SIGPIPE, SIG_IGN);
}
#ifndef NELOGUJ
void logheader () {
struct timeval stv;
gettimeofday(&stv, NULL);
struct tm *stm = localtime(&stv.tv_sec);
if(stm == NULL) return;
fprintf(stderr, "[%02d:%02d:%02d.%03ld] ", stm->tm_hour, stm->tm_min, stm->tm_sec, stv.tv_usec/1000);
}
#endif
bool jeAdresar (string filename) {
struct stat st;
if (stat(filename.c_str(), &st)) return false;
return S_ISDIR(st.st_mode);
}
bool jeSubor (string filename) {
struct stat st;
if (stat(filename.c_str(), &st)) return false;
return S_ISREG(st.st_mode);
}
long long gettime () {
struct timeval tim;
gettimeofday(&tim, NULL);
return tim.tv_sec*1000LL + tim.tv_usec/1000LL;
}
string itos(int i) {
stringstream ss;
ss << i;
return ss.str();
}
| [
"davidb@ksp.sk"
] | davidb@ksp.sk |
5d7a5d5061e77429630d7f63c1e48b4cf048584c | 74e1adbfbff54f5f2d90560df426292f1c1b2fa3 | /src/core/Queue.cpp | 3939d5a002e51a8577285d9906d36262e9d85d69 | [
"BSD-3-Clause"
] | permissive | hyyh619/Oclgrind | ee704fc5d5311a9bcfeec65a016e13b73f93bf86 | 0a82d5e7d7a41159a9bbe28e7247104cfedad079 | refs/heads/master | 2021-01-14T08:32:01.362960 | 2015-10-10T23:49:33 | 2015-10-10T23:49:33 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,374 | cpp | // Queue.cpp (Oclgrind)
// Copyright (c) 2013-2015, James Price and Simon McIntosh-Smith,
// University of Bristol. All rights reserved.
//
// This program is provided under a three-clause BSD license. For full
// license terms please see the LICENSE file distributed with this
// source code.
#include "common.h"
#include <cassert>
#include "Context.h"
#include "KernelInvocation.h"
#include "Memory.h"
#include "Queue.h"
using namespace oclgrind;
using namespace std;
Queue::Queue(const Context *context)
: m_context(context)
{
}
Queue::~Queue()
{
}
Event::Event()
{
state = CL_QUEUED;
queueTime = now();
startTime = endTime = 0;
}
Event* Queue::enqueue(Command *cmd)
{
Event *event = new Event();
cmd->event = event;
m_queue.push(cmd);
return event;
}
void Queue::executeCopyBuffer(CopyCommand *cmd)
{
m_context->getGlobalMemory()->copy(cmd->dst, cmd->src, cmd->size);
}
void Queue::executeCopyBufferRect(CopyRectCommand *cmd)
{
// Perform copy
Memory *memory = m_context->getGlobalMemory();
for (unsigned z = 0; z < cmd->region[2]; z++)
{
for (unsigned y = 0; y < cmd->region[1]; y++)
{
// Compute addresses
size_t src =
cmd->src +
cmd->src_offset[0] +
y * cmd->src_offset[1] +
z * cmd->src_offset[2];
size_t dst =
cmd->dst +
cmd->dst_offset[0] +
y * cmd->dst_offset[1] +
z * cmd->dst_offset[2];
// Copy data
memory->copy(dst, src, cmd->region[0]);
}
}
}
void Queue::executeFillBuffer(FillBufferCommand *cmd)
{
Memory *memory = m_context->getGlobalMemory();
for (unsigned i = 0; i < cmd->size/cmd->pattern_size; i++)
{
memory->store(cmd->pattern,
cmd->address + i*cmd->pattern_size,
cmd->pattern_size);
}
}
void Queue::executeFillImage(FillImageCommand *cmd)
{
Memory *memory = m_context->getGlobalMemory();
for (unsigned z = 0; z < cmd->region[2]; z++)
{
for (unsigned y = 0; y < cmd->region[1]; y++)
{
for (unsigned x = 0; x < cmd->region[0]; x++)
{
size_t address = cmd->base
+ (cmd->origin[0] + x) * cmd->pixelSize
+ (cmd->origin[1] + y) * cmd->rowPitch
+ (cmd->origin[2] + z) * cmd->slicePitch;
memory->store(cmd->color, address, cmd->pixelSize);
}
}
}
}
void Queue::executeKernel(KernelCommand *cmd)
{
// Run kernel
KernelInvocation::run(m_context,
cmd->kernel,
cmd->work_dim,
cmd->globalOffset,
cmd->globalSize,
cmd->localSize);
}
void Queue::executeMap(MapCommand *cmd)
{
m_context->notifyMemoryMap(m_context->getGlobalMemory(),
cmd->address, cmd->offset, cmd->size, cmd->flags);
}
void Queue::executeNativeKernel(NativeKernelCommand *cmd)
{
// Run kernel
cmd->func(cmd->args);
}
void Queue::executeReadBuffer(BufferCommand *cmd)
{
m_context->getGlobalMemory()->load(cmd->ptr, cmd->address, cmd->size);
}
void Queue::executeReadBufferRect(BufferRectCommand *cmd)
{
Memory *memory = m_context->getGlobalMemory();
for (unsigned z = 0; z < cmd->region[2]; z++)
{
for (unsigned y = 0; y < cmd->region[1]; y++)
{
unsigned char *host =
cmd->ptr +
cmd->host_offset[0] +
y * cmd->host_offset[1] +
z * cmd->host_offset[2];
size_t buff =
cmd->address +
cmd->buffer_offset[0] +
y * cmd->buffer_offset[1] +
z * cmd->buffer_offset[2];
memory->load(host, buff, cmd->region[0]);
}
}
}
void Queue::executeUnmap(UnmapCommand *cmd)
{
m_context->notifyMemoryUnmap(m_context->getGlobalMemory(),
cmd->address, cmd->ptr);
}
void Queue::executeWriteBuffer(BufferCommand *cmd)
{
m_context->getGlobalMemory()->store(cmd->ptr, cmd->address, cmd->size);
}
void Queue::executeWriteBufferRect(BufferRectCommand *cmd)
{
// Perform write
Memory *memory = m_context->getGlobalMemory();
for (unsigned z = 0; z < cmd->region[2]; z++)
{
for (unsigned y = 0; y < cmd->region[1]; y++)
{
const unsigned char *host =
cmd->ptr +
cmd->host_offset[0] +
y * cmd->host_offset[1] +
z * cmd->host_offset[2];
size_t buff =
cmd->address +
cmd->buffer_offset[0] +
y * cmd->buffer_offset[1] +
z * cmd->buffer_offset[2];
memory->store(host, buff, cmd->region[0]);
}
}
}
bool Queue::isEmpty() const
{
return m_queue.empty();
}
Queue::Command* Queue::update()
{
if (m_queue.empty())
{
return NULL;
}
// Get next command
Command *cmd = m_queue.front();
// Check if all events in wait list have completed
while (!cmd->waitList.empty())
{
if (cmd->waitList.front()->state == CL_COMPLETE)
{
cmd->waitList.pop_front();
}
else if (cmd->waitList.front()->state < 0)
{
cmd->event->state = cmd->waitList.front()->state;
m_queue.pop();
return cmd;
}
else
{
return NULL;
}
}
cmd->event->startTime = now();
cmd->event->state = CL_RUNNING;
// Dispatch command
switch (cmd->type)
{
case COPY:
executeCopyBuffer((CopyCommand*)cmd);
break;
case COPY_RECT:
executeCopyBufferRect((CopyRectCommand*)cmd);
break;
case EMPTY:
break;
case FILL_BUFFER:
executeFillBuffer((FillBufferCommand*)cmd);
break;
case FILL_IMAGE:
executeFillImage((FillImageCommand*)cmd);
break;
case READ:
executeReadBuffer((BufferCommand*)cmd);
break;
case READ_RECT:
executeReadBufferRect((BufferRectCommand*)cmd);
break;
case KERNEL:
executeKernel((KernelCommand*)cmd);
break;
case MAP:
executeMap((MapCommand*)cmd);
break;
case NATIVE_KERNEL:
executeNativeKernel((NativeKernelCommand*)cmd);
break;
case UNMAP:
executeUnmap((UnmapCommand*)cmd);
break;
case WRITE:
executeWriteBuffer((BufferCommand*)cmd);
break;
case WRITE_RECT:
executeWriteBufferRect((BufferRectCommand*)cmd);
break;
default:
assert(false && "Unhandled command type in queue.");
}
cmd->event->endTime = now();
cmd->event->state = CL_COMPLETE;
// Remove command from queue and delete
m_queue.pop();
return cmd;
}
| [
"j.price@bristol.ac.uk"
] | j.price@bristol.ac.uk |
e96b02601d4697c4e245812ad6e9e680462671f2 | 18d2d69566d4c745a56deb37b364982b0340e6f4 | /flux/hook.cpp | 514909f34db10f8a647eca3b44ba324341524c6f | [
"MIT"
] | permissive | palaniyappanBala/Maxwell | 35e924bbc84e0e6c7a9af3b3419c3586e423b991 | e7d6ac557f615b64c8d5e649f84f1f0bb98bd7dd | refs/heads/master | 2021-06-06T01:21:39.411620 | 2016-10-20T14:28:16 | 2016-10-20T14:28:16 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,132 | cpp | #include <Windows.h>
#include "distorm\distorm.h"
#include "hook.h"
#ifdef _WIN64
#pragma comment(lib,"distorm\\distorm64.lib")
#else
#pragma comment(lib,"distorm\\distorm32.lib")
#endif
#ifdef _WIN64
void InstallHook(Hook * hook)
{
DWORD dwOld;
LPVOID trampAddr = NULL;
int trampSize = 0;
// allocate tramp buffer
trampAddr = VirtualAlloc(0, 37, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
unsigned __int64 trampAddrInt = (unsigned __int64)trampAddr;
memset(trampAddr, '\x90', 37);
// find target function
PVOID targetFunc = (PVOID)GetProcAddress(GetModuleHandle(hook->libName), hook->functionName);
if (targetFunc == 0)
return;
// distorm code
// How many instructions to allocate on stack.
#define MAX_INSTRUCTIONS 32
// Holds the result of the decoding.
_DecodeResult res;
// Default offset for buffer is 0.
_OffsetType offset = 0;
// Decoded instruction information - the Decode will write the results here.
_DecodedInst decodedInstructions[MAX_INSTRUCTIONS];
// decodedInstructionsCount indicates how many instructions were written to the result array.
unsigned int decodedInstructionsCount = 0;
// Default decoding mode is 32 bits.
_DecodeType dt = Decode64Bits;
// Decode the buffer at given offset (virtual address).
res = distorm_decode(offset, (const unsigned char*)targetFunc, 32, dt, decodedInstructions, MAX_INSTRUCTIONS, &decodedInstructionsCount);
if (res == DECRES_INPUTERR)
return;
unsigned int totalSize = 0;
for (unsigned int x = 0; x < decodedInstructionsCount; x++)
{
if (totalSize >= 12)
break;
totalSize += decodedInstructions[x].size;
}
// end distorm code
//log("Total size of tramp: %d", totalSize);
trampSize = totalSize;
hook->oldFunc = (void*)trampAddr;
unsigned __int64 targetFuncInt = (unsigned __int64)targetFunc;
//copy first x bytes of function to tramp
memcpy(trampAddr, targetFunc, totalSize);
//create a jump to original function+totalSize from tramp
trampAddrInt += totalSize;
memcpy((PVOID)trampAddrInt, "\x48\xb8", 2);
trampAddrInt += 2;
targetFuncInt += totalSize;
memcpy((PVOID)trampAddrInt, &targetFuncInt, 8);
trampAddrInt += 8;
memcpy((PVOID)trampAddrInt, "\xff\xe0", 2);
// trampoline has been constructed
//reset pointer
targetFuncInt = (unsigned __int64)targetFunc;
//set target function writeable, should probably set its old permissions for stealth
VirtualProtect((LPVOID)targetFunc, 37, PAGE_EXECUTE_READWRITE, &dwOld);
//intercept target function, send all calls to my function
unsigned __int64 myFuncInt = (unsigned __int64)hook->myFunc;
memcpy((PVOID)targetFuncInt, "\x48\xb8", 2);
targetFuncInt += 2;
memcpy((PVOID)targetFuncInt, &myFuncInt, 8);
targetFuncInt += 8;
memcpy((PVOID)targetFuncInt, "\xff\xe0", 2);
targetFuncInt += 2;
// fix memory protection for hooked function
VirtualProtect((LPVOID)targetFunc, 37, dwOld, &dwOld);
// hooking is now complete
}
#else
void InstallHook(Hook * hook)
{
DWORD dwOld;
LPVOID trampAddr = NULL;
int trampSize = 0;
// allocate tramp buffer
trampAddr = VirtualAlloc(0, 37, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
DWORD trampAddrPtr = (DWORD)trampAddr;
memset(trampAddr, '\x90', 37);
// find target function
PVOID targetFunc = (PVOID)GetProcAddress(GetModuleHandle(hook->libName), hook->functionName);
if (targetFunc == 0)
return;
// distorm code
// How many instructions to allocate on stack.
#define MAX_INSTRUCTIONS 32
// Holds the result of the decoding.
_DecodeResult res;
// Default offset for buffer is 0.
_OffsetType offset = 0;
// Decoded instruction information - the Decode will write the results here.
_DecodedInst decodedInstructions[MAX_INSTRUCTIONS];
// decodedInstructionsCount indicates how many instructions were written to the result array.
unsigned int decodedInstructionsCount = 0;
// Default decoding mode is 32 bits.
_DecodeType dt = Decode32Bits;
// Decode the buffer at given offset (virtual address).
res = distorm_decode(offset, (const unsigned char*)targetFunc, 32, dt, decodedInstructions, MAX_INSTRUCTIONS, &decodedInstructionsCount);
if (res == DECRES_INPUTERR)
return;
unsigned int totalSize = 0;
for (unsigned int x = 0; x < decodedInstructionsCount; x++)
{
if (totalSize >= 5)
break;
totalSize += decodedInstructions[x].size;
}
// end distorm code
//log("Total size of tramp: %d", totalSize);
trampSize = totalSize;
hook->oldFunc = (void*)trampAddr;
DWORD targetFuncPtr = (DWORD)targetFunc;
ULONG bytes = 20;
//set target function writeable
//if (strncmp(hook->funcName, "NtProtectVirtualMemory", sizeof("NtProtectVirtualMemory") -1) == 0)
VirtualProtect((LPVOID)targetFunc, 37, PAGE_EXECUTE_READWRITE, &dwOld);
//else
// Old_NtProtectVirtualMemory(GetCurrentProcess(), &targetFunc, &bytes, PAGE_EXECUTE_READWRITE, &dwOld);
//copy instructions of function to tramp
memcpy(trampAddr, targetFunc, totalSize);
//create a jump to original function+5 from tramp
trampAddrPtr += totalSize;
memcpy((PVOID)trampAddrPtr, "\xe9", 1);
// offset = destination - address of e9 - 5
int myOffset = (int)targetFuncPtr + totalSize - (int)trampAddrPtr - 5;
trampAddrPtr += 1;
memcpy((PVOID)trampAddrPtr, &myOffset, 4);
// trampoline has been constructed
//reset pointer
targetFuncPtr = (DWORD)targetFunc;
//intercept target function, send all calls to my function
DWORD myFuncPtr = (DWORD)hook->myFunc;
memcpy((PVOID)targetFuncPtr, "\xe9", 1);
// offset = destination - address of e9 - 5
myOffset = (int)myFuncPtr - (int)targetFuncPtr - 5;
targetFuncPtr += 1;
memcpy((PVOID)targetFuncPtr, &myOffset, 4);
// fix memory protection for hooked function
VirtualProtect((LPVOID)targetFunc, 37, dwOld, &dwOld);
}
#endif
| [
"jdesimone@endgame.com"
] | jdesimone@endgame.com |
e01ff0bc3d739cffeeb08241cefad16a81148a33 | d4e359096a0974630019bb31e03c45133af08b1f | /Lab9/IceCube.cpp | 0c96a7aaae738b6f7e29e07a73387af805957825 | [
"MIT"
] | permissive | devtedlee/CppStudyProjects | 0130b7bf948fcde0f081cba10c2323921ea58ccc | 65c7504773a332b32b473058b273fe1356d0b7b5 | refs/heads/master | 2023-02-08T13:16:41.031207 | 2021-01-02T14:52:39 | 2021-01-02T14:52:39 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 455 | cpp | #include "IceCube.h"
namespace lab9
{
IceCube::IceCube()
: mFrameCountToLive(0)
{
}
IceCube::~IceCube()
{
}
void IceCube::Initialize(unsigned int frameCountToLive)
{
mFrameCountToLive = frameCountToLive;
}
void IceCube::Reset()
{
mFrameCountToLive = 0;
}
void IceCube::Animate()
{
if (mFrameCountToLive == 0)
{
return;
}
mFrameCountToLive--;
}
bool IceCube::IsActive() const
{
return mFrameCountToLive > 0;
}
}
| [
"persisne@gmail.com"
] | persisne@gmail.com |
458e4710daa2917330e16e62bc15fa2fcb150887 | 8f2d0f2d3c8d93c300473f382ef8d1e790d6371f | /chrome/browser/ui/ash/desks_client_browsertest.cc | 1b1d15300245ed68050786279cc4a6f8435f7a1a | [
"BSD-3-Clause"
] | permissive | turbin/chromium | 4354dc645d296e4d0dea48de0d62fd0b302f3773 | 5a9be83657898af786ad32178129252c73996637 | refs/heads/main | 2023-08-19T05:11:16.921241 | 2021-09-15T08:56:25 | 2021-09-15T08:56:25 | 406,696,228 | 0 | 0 | BSD-3-Clause | 2021-09-15T09:27:08 | 2021-09-15T09:27:08 | null | UTF-8 | C++ | false | false | 41,353 | cc | // Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/desks_client.h"
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <string>
#include "ash/constants/ash_pref_names.h"
#include "ash/public/cpp/desk_template.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/wm/desks/desks_test_util.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/ash/login/login_manager_test.h"
#include "chrome/browser/ash/login/test/login_manager_mixin.h"
#include "chrome/browser/ash/login/ui/user_adding_screen.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_keep_alive_types.h"
#include "chrome/browser/profiles/scoped_profile_keep_alive.h"
#include "chrome/browser/ui/ash/desk_template_app_launch_handler.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/web_applications/system_web_app_ui_utils.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/system_web_apps/system_web_app_manager.h"
#include "chrome/browser/web_applications/system_web_apps/system_web_app_types.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/ui/base/window_state_type.h"
#include "components/app_restore/app_launch_info.h"
#include "components/app_restore/features.h"
#include "components/app_restore/full_restore_utils.h"
#include "components/app_restore/restore_data.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "content/public/test/browser_test.h"
#include "extensions/common/constants.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/display/screen.h"
#include "url/gurl.h"
using ::testing::_;
namespace {
constexpr int32_t kSettingsWindowId = 100;
constexpr char kExampleUrl1[] = "https://examples1.com";
constexpr char kExampleUrl2[] = "https://examples2.com";
constexpr char kExampleUrl3[] = "https://examples3.com";
constexpr char kYoutubeUrl[] = "https://www.youtube.com/";
Browser* FindBrowser(int32_t window_id) {
for (auto* browser : *BrowserList::GetInstance()) {
aura::Window* window = browser->window()->GetNativeWindow();
if (window->GetProperty(full_restore::kRestoreWindowIdKey) == window_id)
return browser;
}
return nullptr;
}
aura::Window* FindBrowserWindow(int32_t window_id) {
Browser* browser = FindBrowser(window_id);
return browser ? browser->window()->GetNativeWindow() : nullptr;
}
std::vector<GURL> GetURLsForBrowserWindow(Browser* browser) {
TabStripModel* tab_strip_model = browser->tab_strip_model();
std::vector<GURL> urls;
for (int i = 0; i < tab_strip_model->count(); ++i)
urls.push_back(tab_strip_model->GetWebContentsAt(i)->GetLastCommittedURL());
return urls;
}
std::unique_ptr<ash::DeskTemplate> CaptureActiveDeskAndSaveTemplate() {
base::RunLoop run_loop;
std::unique_ptr<ash::DeskTemplate> desk_template;
DesksClient::Get()->CaptureActiveDeskAndSaveTemplate(
base::BindLambdaForTesting(
[&](std::unique_ptr<ash::DeskTemplate> captured_desk_template,
std::string error_string) {
run_loop.Quit();
ASSERT_TRUE(captured_desk_template);
desk_template = std::move(captured_desk_template);
}));
run_loop.Run();
return desk_template;
}
void DeleteDeskTemplate(const base::GUID uuid) {
base::RunLoop run_loop;
DesksClient::Get()->DeleteDeskTemplate(
uuid.AsLowercaseString(),
base::BindLambdaForTesting(
[&](std::string error_string) { run_loop.Quit(); }));
run_loop.Run();
}
web_app::AppId CreateSettingsSystemWebApp(Profile* profile) {
web_app::WebAppProvider::GetForTest(profile)
->system_web_app_manager()
.InstallSystemAppsForTesting();
web_app::AppId settings_app_id = *web_app::GetAppIdForSystemWebApp(
profile, web_app::SystemAppType::SETTINGS);
apps::AppLaunchParams params(
settings_app_id, apps::mojom::LaunchContainer::kLaunchContainerWindow,
WindowOpenDisposition::NEW_WINDOW,
apps::mojom::AppLaunchSource::kSourceTest);
params.restore_id = kSettingsWindowId;
apps::AppServiceProxyFactory::GetForProfile(profile)
->BrowserAppLauncher()
->LaunchAppWithParams(std::move(params));
web_app::FlushSystemWebAppLaunchesForTesting(profile);
return settings_app_id;
}
class MockDeskTemplateAppLaunchHandler : public DeskTemplateAppLaunchHandler {
public:
explicit MockDeskTemplateAppLaunchHandler(Profile* profile)
: DeskTemplateAppLaunchHandler(profile) {}
MockDeskTemplateAppLaunchHandler(const MockDeskTemplateAppLaunchHandler&) =
delete;
MockDeskTemplateAppLaunchHandler& operator=(
const MockDeskTemplateAppLaunchHandler&) = delete;
~MockDeskTemplateAppLaunchHandler() override = default;
MOCK_METHOD(void,
LaunchSystemWebAppOrChromeApp,
(apps::mojom::AppType,
const std::string&,
const ::full_restore::RestoreData::LaunchList&),
(override));
};
} // namespace
// Scoped class that temporarily sets a new app launch handler for testing
// purposes.
class ScopedDeskClientAppLaunchHandlerSetter {
public:
explicit ScopedDeskClientAppLaunchHandlerSetter(
std::unique_ptr<DeskTemplateAppLaunchHandler> launch_handler) {
DCHECK_EQ(0, instance_count_);
++instance_count_;
DesksClient* desks_client = DesksClient::Get();
DCHECK(desks_client);
old_app_launch_handler_ = std::move(desks_client->app_launch_handler_);
desks_client->app_launch_handler_ = std::move(launch_handler);
}
ScopedDeskClientAppLaunchHandlerSetter(
const ScopedDeskClientAppLaunchHandlerSetter&) = delete;
ScopedDeskClientAppLaunchHandlerSetter& operator=(
const ScopedDeskClientAppLaunchHandlerSetter&) = delete;
~ScopedDeskClientAppLaunchHandlerSetter() {
DCHECK_EQ(1, instance_count_);
--instance_count_;
DesksClient* desks_client = DesksClient::Get();
DCHECK(desks_client);
desks_client->app_launch_handler_ = std::move(old_app_launch_handler_);
}
private:
// Variable to ensure we never have more than one instance of this object.
static int instance_count_;
// The old app launch handler prior to the object being created. May be
// nullptr.
std::unique_ptr<DeskTemplateAppLaunchHandler> old_app_launch_handler_;
};
int ScopedDeskClientAppLaunchHandlerSetter::instance_count_ = 0;
class DesksClientTest : public extensions::PlatformAppBrowserTest {
public:
DesksClientTest() {
// This feature depends on full restore feature, so need to enable it.
scoped_feature_list_.InitAndEnableFeature(
full_restore::features::kFullRestore);
}
~DesksClientTest() override = default;
void SetUpOnMainThread() override {
::full_restore::SetActiveProfilePath(profile()->GetPath());
extensions::PlatformAppBrowserTest::SetUpOnMainThread();
}
void SetTemplate(std::unique_ptr<ash::DeskTemplate> launch_template) {
DesksClient::Get()->launch_template_for_test_ = std::move(launch_template);
}
void LaunchTemplate(const base::GUID& uuid) {
ash::DeskSwitchAnimationWaiter waiter;
DesksClient::Get()->LaunchDeskTemplate(uuid.AsLowercaseString(),
base::DoNothing());
waiter.Wait();
}
void SetAndLaunchTemplate(std::unique_ptr<ash::DeskTemplate> desk_template) {
ash::DeskTemplate* desk_template_ptr = desk_template.get();
SetTemplate(std::move(desk_template));
LaunchTemplate(desk_template_ptr->uuid());
}
Browser* CreateBrowser(const std::vector<GURL>& urls,
absl::optional<int> active_url_index = absl::nullopt) {
Browser::CreateParams params(Browser::TYPE_NORMAL, profile(),
/*user_gesture=*/false);
Browser* browser = Browser::Create(params);
for (int i = 0; i < urls.size(); i++) {
chrome::AddTabAt(
browser, urls[i], /*index=*/-1,
/*foreground=*/!active_url_index || active_url_index.value() == i);
}
browser->window()->Show();
return browser;
}
Browser* InstallAndLaunchPWA(const GURL& start_url, bool launch_in_browser) {
auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info->start_url = start_url;
web_app_info->scope = start_url.GetWithoutFilename();
if (!launch_in_browser)
web_app_info->user_display_mode = blink::mojom::DisplayMode::kStandalone;
web_app_info->title = u"A Web App";
const web_app::AppId app_id =
web_app::test::InstallWebApp(profile(), std::move(web_app_info));
// Wait for app service to see the newly installed app.
auto* proxy = apps::AppServiceProxyFactory::GetForProfile(profile());
proxy->FlushMojoCallsForTesting();
return launch_in_browser
? web_app::LaunchBrowserForWebAppInTab(profile(), app_id)
: web_app::LaunchWebAppBrowserAndWait(profile(), app_id);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// Tests that a browser's urls can be captured correctly in the desk template.
IN_PROC_BROWSER_TEST_F(DesksClientTest, CaptureBrowserUrlsTest) {
// Create a new browser and add a few tabs to it.
Browser* browser = CreateBrowser({GURL(kExampleUrl1), GURL(kExampleUrl2)});
aura::Window* window = browser->window()->GetNativeWindow();
const int32_t browser_window_id =
window->GetProperty(::full_restore::kWindowIdKey);
// Get current tabs from browser.
std::vector<GURL> urls = GetURLsForBrowserWindow(browser);
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
const full_restore::RestoreData* restore_data =
desk_template->desk_restore_data();
const auto& app_id_to_launch_list = restore_data->app_id_to_launch_list();
EXPECT_EQ(app_id_to_launch_list.size(), 1u);
// Find |browser| window's app restore data.
auto iter = app_id_to_launch_list.find(extension_misc::kChromeAppId);
ASSERT_TRUE(iter != app_id_to_launch_list.end());
auto app_restore_data_iter = iter->second.find(browser_window_id);
ASSERT_TRUE(app_restore_data_iter != iter->second.end());
const auto& data = app_restore_data_iter->second;
// Check the urls are captured correctly in the |desk_template|.
EXPECT_EQ(data->urls.value(), urls);
}
// Tests that incognito browser windows will NOT be captured in the desk
// template.
IN_PROC_BROWSER_TEST_F(DesksClientTest, CaptureIncognitoBrowserTest) {
Browser* incognito_browser = CreateIncognitoBrowser();
chrome::AddTabAt(incognito_browser, GURL(kExampleUrl1), /*index=*/-1,
/*foreground=*/true);
chrome::AddTabAt(incognito_browser, GURL(kExampleUrl2), /*index=*/-1,
/*foreground=*/true);
incognito_browser->window()->Show();
aura::Window* window = incognito_browser->window()->GetNativeWindow();
const int32_t incognito_browser_window_id =
window->GetProperty(::full_restore::kWindowIdKey);
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
ASSERT_TRUE(desk_template);
const full_restore::RestoreData* restore_data =
desk_template->desk_restore_data();
const auto& app_id_to_launch_list = restore_data->app_id_to_launch_list();
EXPECT_EQ(app_id_to_launch_list.size(), 1u);
// Find |browser| window's app restore data.
auto iter = app_id_to_launch_list.find(extension_misc::kChromeAppId);
ASSERT_TRUE(iter != app_id_to_launch_list.end());
auto app_restore_data_iter = iter->second.find(incognito_browser_window_id);
// Created incognito window is NOT in restore list
ASSERT_TRUE(app_restore_data_iter == iter->second.end());
}
// Tests that browsers and chrome apps can be captured correctly in the desk
// template.
IN_PROC_BROWSER_TEST_F(DesksClientTest, CaptureActiveDeskAsTemplateTest) {
// Test that Singleton was properly initialized.
ASSERT_TRUE(DesksClient::Get());
// Change |browser|'s bounds.
const gfx::Rect browser_bounds = gfx::Rect(0, 0, 800, 200);
aura::Window* window = browser()->window()->GetNativeWindow();
window->SetBounds(browser_bounds);
// Make window visible on all desks.
window->SetProperty(aura::client::kVisibleOnAllWorkspacesKey, true);
const int32_t browser_window_id =
window->GetProperty(::full_restore::kWindowIdKey);
// Create the settings app, which is a system web app.
web_app::AppId settings_app_id =
CreateSettingsSystemWebApp(browser()->profile());
// Change the Settings app's bounds too.
const gfx::Rect settings_app_bounds = gfx::Rect(100, 100, 800, 300);
aura::Window* settings_window = FindBrowserWindow(kSettingsWindowId);
const int32_t settings_window_id =
settings_window->GetProperty(full_restore::kWindowIdKey);
ASSERT_TRUE(settings_window);
settings_window->SetBounds(settings_app_bounds);
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
// Test the default template's name is the current desk's name.
auto* desks_controller = ash::DesksController::Get();
EXPECT_EQ(
desk_template->template_name(),
desks_controller->GetDeskName(desks_controller->GetActiveDeskIndex()));
const full_restore::RestoreData* restore_data =
desk_template->desk_restore_data();
const auto& app_id_to_launch_list = restore_data->app_id_to_launch_list();
EXPECT_EQ(app_id_to_launch_list.size(), 2u);
// Find |browser| window's app restore data.
auto iter = app_id_to_launch_list.find(extension_misc::kChromeAppId);
ASSERT_TRUE(iter != app_id_to_launch_list.end());
auto app_restore_data_iter = iter->second.find(browser_window_id);
ASSERT_TRUE(app_restore_data_iter != iter->second.end());
const auto& data = app_restore_data_iter->second;
// Verify window info are correctly captured.
EXPECT_EQ(browser_bounds, data->current_bounds.value());
// `visible_on_all_workspaces` should have been reset even though
// the captured window has kVisibleOnAllWorkspacesKey key.
EXPECT_FALSE(data->visible_on_all_workspaces.has_value());
auto* screen = display::Screen::GetScreen();
EXPECT_EQ(screen->GetDisplayNearestWindow(window).id(),
data->display_id.value());
EXPECT_EQ(window->GetProperty(aura::client::kShowStateKey),
chromeos::ToWindowShowState(data->window_state_type.value()));
// We don't capture the window's desk_id as a template will always
// create in a new desk.
EXPECT_FALSE(data->desk_id.has_value());
// Find Setting app's app restore data.
auto iter2 = app_id_to_launch_list.find(settings_app_id);
ASSERT_TRUE(iter2 != app_id_to_launch_list.end());
auto app_restore_data_iter2 = iter2->second.find(settings_window_id);
ASSERT_TRUE(app_restore_data_iter2 != iter2->second.end());
const auto& data2 = app_restore_data_iter2->second;
EXPECT_EQ(
static_cast<int>(apps::mojom::LaunchContainer::kLaunchContainerWindow),
data2->container.value());
EXPECT_EQ(static_cast<int>(WindowOpenDisposition::NEW_WINDOW),
data2->disposition.value());
// Verify window info are correctly captured.
EXPECT_EQ(settings_app_bounds, data2->current_bounds.value());
EXPECT_FALSE(data2->visible_on_all_workspaces.has_value());
EXPECT_EQ(screen->GetDisplayNearestWindow(window).id(),
data->display_id.value());
EXPECT_EQ(window->GetProperty(aura::client::kShowStateKey),
chromeos::ToWindowShowState(data->window_state_type.value()));
EXPECT_EQ(window->GetProperty(aura::client::kShowStateKey),
chromeos::ToWindowShowState(data->window_state_type.value()));
EXPECT_FALSE(data2->desk_id.has_value());
}
// Tests that launching a desk template creates a desk with the given name.
IN_PROC_BROWSER_TEST_F(DesksClientTest, LaunchEmptyDeskTemplate) {
const base::GUID kDeskUuid = base::GUID::GenerateRandomV4();
const std::u16string kDeskName(u"Test Desk Name");
auto* desks_controller = ash::DesksController::Get();
ASSERT_EQ(0, desks_controller->GetActiveDeskIndex());
auto desk_template = std::make_unique<ash::DeskTemplate>(kDeskUuid);
desk_template->set_template_name(kDeskName);
SetAndLaunchTemplate(std::move(desk_template));
EXPECT_EQ(1, desks_controller->GetActiveDeskIndex());
EXPECT_EQ(kDeskName, desks_controller->GetDeskName(1));
// Verify that user prefs are updated with the correct desk names. This
// ensures that template created desk names are preserved on restart.
PrefService* primary_user_prefs =
ash::Shell::Get()->session_controller()->GetPrimaryUserPrefService();
ASSERT_TRUE(primary_user_prefs);
const base::ListValue* desks_names =
primary_user_prefs->GetList(ash::prefs::kDesksNamesList);
const auto& desks_names_list = desks_names->GetList();
EXPECT_EQ(2, desks_names->GetList().size());
EXPECT_EQ(base::UTF16ToUTF8(kDeskName), desks_names_list[1].GetString());
}
// Tests that launching the same desk template multiple times creates desks with
// different/incremented names.
IN_PROC_BROWSER_TEST_F(DesksClientTest, LaunchMultipleEmptyDeskTemplates) {
const base::GUID kDeskUuid = base::GUID::GenerateRandomV4();
const std::u16string kDeskName(u"Test Desk Name");
auto* desks_controller = ash::DesksController::Get();
ASSERT_EQ(0, desks_controller->GetActiveDeskIndex());
auto desk_template = std::make_unique<ash::DeskTemplate>(kDeskUuid);
desk_template->set_template_name(kDeskName);
SetTemplate(std::move(desk_template));
auto check_launch_template_desk_name =
[kDeskUuid, desks_controller, this](const std::u16string& desk_name) {
LaunchTemplate(kDeskUuid);
EXPECT_EQ(desk_name, desks_controller->GetDeskName(
desks_controller->GetActiveDeskIndex()));
};
// Launching a desk from the template creates a desk with the same name as the
// template.
check_launch_template_desk_name(kDeskName);
// Launch more desks from the template and verify that the newly created desks
// have unique names.
check_launch_template_desk_name(std::u16string(kDeskName).append(u" (1)"));
check_launch_template_desk_name(std::u16string(kDeskName).append(u" (2)"));
// Remove "Test Desk Name (1)", which means the next created desk from
// template will have that name. Then it will skip (2) since it already
// exists, and create the next desk with (3).
RemoveDesk(desks_controller->desks()[2].get());
check_launch_template_desk_name(std::u16string(kDeskName).append(u" (1)"));
check_launch_template_desk_name(std::u16string(kDeskName).append(u" (3)"));
// Same as above, but make sure that deleting the desk with the exact template
// name still functions the same by only filling in whatever name is
// available.
RemoveDesk(desks_controller->desks()[1].get());
check_launch_template_desk_name(kDeskName);
check_launch_template_desk_name(std::u16string(kDeskName).append(u" (4)"));
}
// Tests that launching a template that contains a system web app works as
// expected.
IN_PROC_BROWSER_TEST_F(DesksClientTest, LaunchTemplateWithSystemApp) {
ASSERT_TRUE(DesksClient::Get());
// Create the settings app, which is a system web app.
CreateSettingsSystemWebApp(browser()->profile());
aura::Window* settings_window = FindBrowserWindow(kSettingsWindowId);
ASSERT_TRUE(settings_window);
const std::u16string settings_title = settings_window->GetTitle();
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
// Close the settings window. We'll need to verify if it reopens later.
views::Widget* settings_widget =
views::Widget::GetWidgetForNativeWindow(settings_window);
settings_widget->CloseNow();
ASSERT_FALSE(FindBrowserWindow(kSettingsWindowId));
settings_window = nullptr;
auto* desks_controller = ash::DesksController::Get();
ASSERT_EQ(0, desks_controller->GetActiveDeskIndex());
// Set the template we created as the template we want to launch.
SetAndLaunchTemplate(std::move(desk_template));
// Verify that the settings window has been launched on the new desk (desk B).
// TODO(sammiequon): Right now the app just launches, so verify the title
// matches. We should verify the restore id and use
// `FindBrowserWindow(kSettingsWindowId)` once things are wired up properly.
EXPECT_EQ(1, desks_controller->GetActiveDeskIndex());
for (auto* browser : *BrowserList::GetInstance()) {
aura::Window* window = browser->window()->GetNativeWindow();
if (window->GetTitle() == settings_title) {
settings_window = window;
break;
}
}
ASSERT_TRUE(settings_window);
EXPECT_EQ(ash::Shell::GetContainer(settings_window->GetRootWindow(),
ash::kShellWindowId_DeskContainerB),
settings_window->parent());
}
// Tests that launching a template that contains a system web app will move the
// existing instance of the system web app to the current desk.
IN_PROC_BROWSER_TEST_F(DesksClientTest, LaunchTemplateWithSystemAppExisting) {
ASSERT_TRUE(DesksClient::Get());
Profile* profile = browser()->profile();
// Create the settings app, which is a system web app.
CreateSettingsSystemWebApp(profile);
aura::Window* settings_window = FindBrowserWindow(kSettingsWindowId);
ASSERT_TRUE(settings_window);
EXPECT_EQ(2u, BrowserList::GetInstance()->size());
base::RunLoop run_loop;
std::unique_ptr<ash::DeskTemplate> desk_template;
DesksClient::Get()->CaptureActiveDeskAndSaveTemplate(
base::BindLambdaForTesting(
[&](std::unique_ptr<ash::DeskTemplate> captured_desk_template,
std::string error_string) {
run_loop.Quit();
ASSERT_TRUE(captured_desk_template);
desk_template = std::move(captured_desk_template);
}));
run_loop.Run();
ash::DesksController* desks_controller = ash::DesksController::Get();
ASSERT_EQ(0, desks_controller->GetActiveDeskIndex());
// Set the template we created as the template we want to launch.
SetAndLaunchTemplate(std::move(desk_template));
// We launch a new browser window, but not a new settings app.
EXPECT_EQ(3u, BrowserList::GetInstance()->size());
EXPECT_TRUE(desks_controller->BelongsToActiveDesk(settings_window));
}
// Tests that launching a template that contains a chrome app works as expected.
IN_PROC_BROWSER_TEST_F(DesksClientTest, LaunchTemplateWithChromeApp) {
DesksClient* desks_client = DesksClient::Get();
ASSERT_TRUE(desks_client);
// Create a chrome app.
const extensions::Extension* extension =
LoadAndLaunchPlatformApp("launch", "Launched");
ASSERT_TRUE(extension);
const std::string extension_id = extension->id();
::full_restore::SaveAppLaunchInfo(
profile()->GetPath(),
std::make_unique<::full_restore::AppLaunchInfo>(
extension_id, apps::mojom::LaunchContainer::kLaunchContainerWindow,
WindowOpenDisposition::NEW_WINDOW, display::kDefaultDisplayId,
std::vector<base::FilePath>{}, nullptr));
extensions::AppWindow* app_window = CreateAppWindow(profile(), extension);
ASSERT_TRUE(app_window);
ASSERT_TRUE(GetFirstAppWindowForApp(extension_id));
// Capture the active desk, which contains the chrome app.
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
ASSERT_TRUE(desk_template);
// Close the chrome app window. We'll need to verify if it reopens later.
views::Widget* app_widget =
views::Widget::GetWidgetForNativeWindow(app_window->GetNativeWindow());
app_widget->CloseNow();
ASSERT_FALSE(GetFirstAppWindowForApp(extension_id));
ash::DesksController* desks_controller = ash::DesksController::Get();
ASSERT_EQ(0, desks_controller->GetActiveDeskIndex());
// `BrowserAppLauncher::LaunchAppWithParams()` does not launch the chrome app
// in tests, so here we set up a mock app launch handler and just verify a
// `LaunchSystemWebAppOrChromeApp()` call with the associated extension is
// seen.
auto mock_app_launch_handler =
std::make_unique<MockDeskTemplateAppLaunchHandler>(profile());
MockDeskTemplateAppLaunchHandler* mock_app_launch_handler_ptr =
mock_app_launch_handler.get();
ScopedDeskClientAppLaunchHandlerSetter scoped_launch_handler(
std::move(mock_app_launch_handler));
EXPECT_CALL(*mock_app_launch_handler_ptr,
LaunchSystemWebAppOrChromeApp(_, extension_id, _));
// Set the template we created as the template we want to launch.
SetAndLaunchTemplate(std::move(desk_template));
}
// Tests that launching a template that contains a browser window works as
// expected.
IN_PROC_BROWSER_TEST_F(DesksClientTest, LaunchTemplateWithBrowserWindow) {
ASSERT_TRUE(DesksClient::Get());
// Create a new browser and add a few tabs to it, and specify the active tab
// index.
const int browser_active_index = 1;
Browser* browser = CreateBrowser(
{GURL(kExampleUrl1), GURL(kExampleUrl2), GURL(kExampleUrl3)},
/*active_url_index=*/browser_active_index);
// Verify that the active tab is correct.
EXPECT_EQ(browser_active_index, browser->tab_strip_model()->active_index());
aura::Window* window = browser->window()->GetNativeWindow();
const int32_t browser_window_id =
window->GetProperty(full_restore::kWindowIdKey);
// Get current tabs from browser.
const std::vector<GURL> urls = GetURLsForBrowserWindow(browser);
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
ASSERT_TRUE(desk_template);
ash::DesksController* desks_controller = ash::DesksController::Get();
ASSERT_EQ(0, desks_controller->GetActiveDeskIndex());
// Set the template we created as the template we want to launch.
SetAndLaunchTemplate(std::move(desk_template));
// Verify that the browser was launched with the correct urls and active tab.
Browser* new_browser = FindBrowser(browser_window_id);
ASSERT_TRUE(new_browser);
EXPECT_EQ(urls, GetURLsForBrowserWindow(new_browser));
EXPECT_EQ(browser_active_index,
new_browser->tab_strip_model()->active_index());
// Verify that the browser window has been launched on the new desk (desk B).
EXPECT_EQ(1, desks_controller->GetActiveDeskIndex());
aura::Window* browser_window = new_browser->window()->GetNativeWindow();
ASSERT_TRUE(browser_window);
EXPECT_EQ(ash::Shell::GetContainer(browser_window->GetRootWindow(),
ash::kShellWindowId_DeskContainerB),
browser_window->parent());
}
// Tests that browser session restore isn't triggered when we launch a template
// that contains a browser window.
IN_PROC_BROWSER_TEST_F(DesksClientTest, PreventBrowserSessionRestoreTest) {
ASSERT_TRUE(DesksClient::Get());
// Do not exit from test or delete the Profile* when last browser is closed.
ScopedKeepAlive keep_alive(KeepAliveOrigin::BROWSER,
KeepAliveRestartOption::DISABLED);
ScopedProfileKeepAlive profile_keep_alive(
browser()->profile(), ProfileKeepAliveOrigin::kBrowserWindow);
// Enable session service.
SessionStartupPref pref(SessionStartupPref::LAST);
Profile* profile = browser()->profile();
SessionStartupPref::SetStartupPref(profile, pref);
const int expected_tab_count = 2;
chrome::AddTabAt(browser(), GURL(kExampleUrl2), /*index=*/-1,
/*foreground=*/true);
EXPECT_EQ(expected_tab_count, browser()->tab_strip_model()->count());
const int32_t browser_window_id =
browser()->window()->GetNativeWindow()->GetProperty(
::full_restore::kWindowIdKey);
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
ASSERT_TRUE(desk_template);
// Close the browser and verify that all browser windows are closed.
CloseBrowserSynchronously(browser());
EXPECT_EQ(0u, chrome::GetTotalBrowserCount());
// Set the template we created and launch the template.
SetAndLaunchTemplate(std::move(desk_template));
// Verify that the browser was launched with the correct number of tabs, and
// that browser session restore did not restore any windows/tabs.
Browser* new_browser = FindBrowser(browser_window_id);
ASSERT_TRUE(new_browser);
EXPECT_EQ(expected_tab_count, GetURLsForBrowserWindow(new_browser).size());
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
}
// Tests that the windows and tabs count histogram is recorded properly.
IN_PROC_BROWSER_TEST_F(DesksClientTest,
DeskTemplateWindowAndTabCountHistogram) {
ASSERT_TRUE(DesksClient::Get());
base::HistogramTester histogram_tester;
Profile* profile = browser()->profile();
// Create the settings app, which is a system web app.
CreateSettingsSystemWebApp(profile);
CreateBrowser({GURL(kExampleUrl1), GURL(kExampleUrl2)});
CreateBrowser({GURL(kExampleUrl1), GURL(kExampleUrl2), GURL(kExampleUrl3)});
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
ASSERT_TRUE(desk_template);
const full_restore::RestoreData* restore_data =
desk_template->desk_restore_data();
const auto& app_id_to_launch_list = restore_data->app_id_to_launch_list();
EXPECT_EQ(app_id_to_launch_list.size(), 2u);
constexpr char kWindowCountHistogramName[] = "Ash.DeskTemplate.WindowCount";
constexpr char kTabCountHistogramName[] = "Ash.DeskTemplate.TabCount";
constexpr char kWindowAndTabCountHistogramName[] =
"Ash.DeskTemplate.WindowAndTabCount";
// NOTE: there is an existing browser with 1 tab created by BrowserMain().
histogram_tester.ExpectBucketCount(kWindowCountHistogramName, 4, 1);
histogram_tester.ExpectBucketCount(kTabCountHistogramName, 6, 1);
histogram_tester.ExpectBucketCount(kWindowAndTabCountHistogramName, 7, 1);
}
// Tests that the launch from template histogram is recorded properly.
IN_PROC_BROWSER_TEST_F(DesksClientTest,
DeskTemplateLaunchFromTemplateHistogram) {
ASSERT_TRUE(DesksClient::Get());
base::HistogramTester histogram_tester;
// Create a new browser.
CreateBrowser({});
// Save the template.
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
ASSERT_TRUE(desk_template);
// Set the template we created as the template we want to launch.
ash::DeskTemplate* desk_template_ptr = desk_template.get();
SetTemplate(std::move(desk_template));
int launches = 5;
for (int i = 0; i < launches; i++)
LaunchTemplate(desk_template_ptr->uuid());
constexpr char kLaunchFromTemplateHistogramName[] =
"Ash.DeskTemplate.LaunchFromTemplate";
histogram_tester.ExpectTotalCount(kLaunchFromTemplateHistogramName, launches);
}
// Tests that the template count histogram is recorded properly.
IN_PROC_BROWSER_TEST_F(DesksClientTest,
DeskTemplateUserTemplateCountHistogram) {
ASSERT_TRUE(DesksClient::Get());
base::HistogramTester histogram_tester;
// Verify that all template saves and deletes are captured by the histogram.
CaptureActiveDeskAndSaveTemplate();
CaptureActiveDeskAndSaveTemplate();
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
DeleteDeskTemplate(desk_template->uuid());
CaptureActiveDeskAndSaveTemplate();
constexpr char kUserTemplateCountHistogramName[] =
"Ash.DeskTemplate.UserTemplateCount";
histogram_tester.ExpectBucketCount(kUserTemplateCountHistogramName, 1, 1);
histogram_tester.ExpectBucketCount(kUserTemplateCountHistogramName, 2, 2);
histogram_tester.ExpectBucketCount(kUserTemplateCountHistogramName, 3, 2);
}
// Tests that browser windows created from a template have the correct bounds
// and window state.
IN_PROC_BROWSER_TEST_F(DesksClientTest, BrowserWindowRestorationTest) {
ASSERT_TRUE(DesksClient::Get());
// Create a new browser and set its bounds.
Browser* browser_1 = CreateBrowser({GURL(kExampleUrl1), GURL(kExampleUrl2)});
const gfx::Rect browser_bounds_1 = gfx::Rect(100, 100, 600, 200);
aura::Window* window_1 = browser_1->window()->GetNativeWindow();
window_1->SetBounds(browser_bounds_1);
// Create a new minimized browser.
Browser* browser_2 = CreateBrowser({GURL(kExampleUrl1)});
const gfx::Rect browser_bounds_2 = gfx::Rect(150, 150, 500, 300);
aura::Window* window_2 = browser_2->window()->GetNativeWindow();
window_2->SetBounds(browser_bounds_2);
EXPECT_EQ(browser_bounds_2, window_2->bounds());
browser_2->window()->Minimize();
// Create a new maximized browser.
Browser* browser_3 = CreateBrowser({GURL(kExampleUrl1)});
browser_3->window()->Maximize();
EXPECT_EQ(browser_bounds_1, window_1->bounds());
EXPECT_EQ(browser_bounds_2, window_2->bounds());
ASSERT_TRUE(browser_2->window()->IsMinimized());
ASSERT_TRUE(browser_3->window()->IsMaximized());
const int32_t browser_window_id_1 =
window_1->GetProperty(::full_restore::kWindowIdKey);
const int32_t browser_window_id_2 =
window_2->GetProperty(::full_restore::kWindowIdKey);
const int32_t browser_window_id_3 =
browser_3->window()->GetNativeWindow()->GetProperty(
::full_restore::kWindowIdKey);
// Capture the active desk, which contains the two browser windows.
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
// Set the template and launch it.
SetAndLaunchTemplate(std::move(desk_template));
// Verify that the browser was launched with the correct bounds.
Browser* new_browser_1 = FindBrowser(browser_window_id_1);
ASSERT_TRUE(new_browser_1);
EXPECT_EQ(browser_bounds_1,
new_browser_1->window()->GetNativeWindow()->bounds());
// Verify that the browser was launched and minimized.
Browser* new_browser_2 = FindBrowser(browser_window_id_2);
ASSERT_TRUE(new_browser_2);
ASSERT_TRUE(new_browser_2->window()->IsMinimized());
EXPECT_EQ(browser_bounds_2,
new_browser_2->window()->GetNativeWindow()->bounds());
// Verify that the browser was launched and maximized.
Browser* new_browser_3 = FindBrowser(browser_window_id_3);
ASSERT_TRUE(new_browser_3);
ASSERT_TRUE(new_browser_3->window()->IsMaximized());
}
// Tests that saving and launching a template that contains a PWA works as
// expected.
IN_PROC_BROWSER_TEST_F(DesksClientTest, LaunchTemplateWithPWA) {
ASSERT_TRUE(DesksClient::Get());
Browser* pwa_browser =
InstallAndLaunchPWA(GURL(kExampleUrl1), /*launch_in_browser=*/false);
ASSERT_TRUE(pwa_browser->is_type_app());
aura::Window* pwa_window = pwa_browser->window()->GetNativeWindow();
const gfx::Rect pwa_bounds(50, 50, 500, 500);
pwa_window->SetBounds(pwa_bounds);
const int32_t pwa_window_id =
pwa_window->GetProperty(::full_restore::kWindowIdKey);
const std::string* app_name =
pwa_window->GetProperty(full_restore::kBrowserAppNameKey);
ASSERT_TRUE(app_name);
// Capture the active desk, which contains the PWA.
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
// Find |pwa_browser| window's app restore data.
const full_restore::RestoreData* restore_data =
desk_template->desk_restore_data();
const auto& app_id_to_launch_list = restore_data->app_id_to_launch_list();
EXPECT_EQ(app_id_to_launch_list.size(), 1u);
ASSERT_TRUE(restore_data->HasAppTypeBrowser());
auto iter = app_id_to_launch_list.find(extension_misc::kChromeAppId);
ASSERT_TRUE(iter != app_id_to_launch_list.end());
auto app_restore_data_iter = iter->second.find(pwa_window_id);
ASSERT_TRUE(app_restore_data_iter != iter->second.end());
const auto& data = app_restore_data_iter->second;
// Verify window info are correctly captured.
EXPECT_EQ(pwa_bounds, data->current_bounds.value());
ASSERT_TRUE(data->app_type_browser.has_value() &&
data->app_type_browser.value());
EXPECT_EQ(*app_name, *data->app_name);
// Set the template and launch it.
SetAndLaunchTemplate(std::move(desk_template));
// Verify that the PWA was launched correctly.
Browser* new_pwa_browser = FindBrowser(pwa_window_id);
ASSERT_TRUE(new_pwa_browser);
ASSERT_TRUE(new_pwa_browser->is_type_app());
aura::Window* new_browser_window =
new_pwa_browser->window()->GetNativeWindow();
EXPECT_NE(new_browser_window, pwa_window);
EXPECT_EQ(pwa_bounds, new_browser_window->bounds());
const std::string* new_app_name =
new_browser_window->GetProperty(full_restore::kBrowserAppNameKey);
ASSERT_TRUE(new_app_name);
EXPECT_EQ(*app_name, *new_app_name);
}
// Tests that saving and launching a template that contains a PWA in a browser
// window works as expected.
IN_PROC_BROWSER_TEST_F(DesksClientTest, LaunchTemplateWithPWAInBrowser) {
ASSERT_TRUE(DesksClient::Get());
Browser* pwa_browser =
InstallAndLaunchPWA(GURL(kYoutubeUrl), /*launch_in_browser=*/true);
aura::Window* pwa_window = pwa_browser->window()->GetNativeWindow();
const int32_t pwa_window_id =
pwa_window->GetProperty(::full_restore::kWindowIdKey);
// Capture the active desk, which contains the PWA.
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
// Test that |pwa_browser| restore data can be found.
const full_restore::RestoreData* restore_data =
desk_template->desk_restore_data();
const auto& app_id_to_launch_list = restore_data->app_id_to_launch_list();
EXPECT_EQ(app_id_to_launch_list.size(), 1u);
// Test that |pwa_browser|'s restore data is saved under the Chrome browser
// app id extension_misc::kChromeAppId, not Youtube app id
// extension_misc::kYoutubeAppId.
auto iter = app_id_to_launch_list.find(extension_misc::kChromeAppId);
ASSERT_TRUE(iter != app_id_to_launch_list.end());
auto app_restore_data_iter = iter->second.find(pwa_window_id);
ASSERT_TRUE(app_restore_data_iter != iter->second.end());
iter = app_id_to_launch_list.find(extension_misc::kYoutubeAppId);
EXPECT_FALSE(iter != app_id_to_launch_list.end());
}
class DesksClientMultiProfileTest : public chromeos::LoginManagerTest {
public:
DesksClientMultiProfileTest() : chromeos::LoginManagerTest() {
login_mixin_.AppendRegularUsers(2);
account_id1_ = login_mixin_.users()[0].account_id;
account_id2_ = login_mixin_.users()[1].account_id;
// This feature depends on full restore feature, so need to enable it.
scoped_feature_list_.InitAndEnableFeature(
full_restore::features::kFullRestore);
}
~DesksClientMultiProfileTest() override = default;
void SetUpOnMainThread() override {
chromeos::LoginManagerTest::SetUpOnMainThread();
LoginUser(account_id1_);
::full_restore::SetActiveProfilePath(
chromeos::ProfileHelper::Get()
->GetProfileByAccountId(account_id1_)
->GetPath());
}
protected:
base::test::ScopedFeatureList scoped_feature_list_;
ash::LoginManagerMixin login_mixin_{&mixin_host_};
AccountId account_id1_;
AccountId account_id2_;
};
IN_PROC_BROWSER_TEST_F(DesksClientMultiProfileTest, MultiProfileTest) {
CreateBrowser(
chromeos::ProfileHelper::Get()->GetProfileByAccountId(account_id1_));
// Capture the active desk, which contains the browser windows.
std::unique_ptr<ash::DeskTemplate> desk_template =
CaptureActiveDeskAndSaveTemplate();
const full_restore::RestoreData* restore_data =
desk_template->desk_restore_data();
const auto& app_id_to_launch_list = restore_data->app_id_to_launch_list();
EXPECT_EQ(app_id_to_launch_list.size(), 1u);
auto get_templates_size = []() {
base::RunLoop run_loop;
int templates_num = 0;
DesksClient::Get()->GetDeskTemplates(base::BindLambdaForTesting(
[&](const std::vector<ash::DeskTemplate*>& desk_templates,
std::string error_string) {
templates_num = desk_templates.size();
run_loop.Quit();
}));
run_loop.Run();
return templates_num;
};
EXPECT_EQ(get_templates_size(), 1);
// Now switch to |account_id2_|. Test that the captured desk template can't
// be accessed from |account_id2_|.
ash::UserAddingScreen::Get()->Start();
AddUser(account_id2_);
EXPECT_EQ(get_templates_size(), 0);
}
| [
"chromium-scoped@luci-project-accounts.iam.gserviceaccount.com"
] | chromium-scoped@luci-project-accounts.iam.gserviceaccount.com |
fb7afc1120a3849598d485a0c74a6a8417bab0fe | e80a3635b9d7c60718d2a38c14780104820b3881 | /Capstone/capstoneCode/capstoneCode/EntityMoveable.cpp | 0609ce9a540a6f557294fb7062309b3e40a3518f | [] | no_license | Erik-Raccy/Capstone-Project | 43714562c7277facc92e6182232540645622e805 | ac136f3f0c1a170dab18269d0764803d9fd39f6a | refs/heads/master | 2021-01-10T19:28:40.731569 | 2015-09-23T20:43:55 | 2015-09-23T20:43:55 | 43,025,347 | 1 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 1,402 | cpp | #include "EntityMoveable.h"
#include "C4Engine.h"
using namespace C4;
//Constructors
EntityMoveable::EntityMoveable() : EntityDamageable()
{
}
//Full constructor
EntityMoveable::EntityMoveable(EntityType _type, Point3D _location, float _health, float _maxHealth, float _fuel, float _maxFuel, float _scraps, EntityWeapon* _equippedWeapon, EntityArmor* _equippedArmor, char* _model) : EntityDamageable(_type, _location, _health, _maxHealth, _model)
{
fuel = _fuel;
mFuel = _maxFuel;
scraps = _scraps;
weapon = _equippedWeapon;
armor = _equippedArmor;
}
//Default armor and weapon constructor
EntityMoveable::EntityMoveable(EntityType _type, Point3D _location, float _health, float _maxHealth, float _fuel, float _maxFuel, float _scraps, char* _model) : EntityDamageable(_type, _location, _health, _maxHealth, _model)
{
fuel = _fuel;
mFuel = _maxFuel;
scraps = _scraps;
weapon = new EntityWeapon(kEntityWeapon, Point3D(NULL, NULL, NULL), WEAPON_NO_WEAPON_DAMAGE, WEAPON_NO_WEAPON_KNOCKBACK, WEAPON_NO_WEAPON_RANGE, nullptr, k_weaponNoWeapon);
armor = new EntityArmor(kEntityArmor, ARMOR_RUST_DEFENSE, Point3D(NULL, NULL, NULL), nullptr, k_ArmorRust);
}
EntityMoveable::~EntityMoveable()
{
}
//Inherited Methods
void EntityMoveable::OnDamaged()
{
EntityDamageable::OnDamaged();
}
void EntityMoveable::OnDeath()
{
EntityDamageable::OnDeath();
}
//
void EntityMoveable::Attack()
{
}
| [
"eng.johane@gmail.com"
] | eng.johane@gmail.com |
529b9098f364280ac7a6b0e1427ba43c86a0194e | 5dd36c9dc3e6169b7a22529a75f620e42da80ee1 | /00763. Partition Labels.cpp | e4fefb7dc7fae49ae42d940cd0a81e429e30c3c9 | [] | no_license | SanyaAttri/LeetCode | cdd6d3831f7a0f707285fd5bb9a5b11556efaa32 | d0cf03fcd6525ceeee231ba7efe40955eec4314d | refs/heads/master | 2022-12-24T20:58:20.040302 | 2020-10-10T11:12:27 | 2020-10-10T11:12:27 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,194 | cpp | //
// main.cpp
// LeetCode
//
// Created by 郭妙友 on 17/2/5.
// Copyright © 2017年 miaoyou.gmy. All rights reserved.
//
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <unordered_map>
using namespace std;
/**
763. Partition Labels
A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.
Example 1:
Input: S = "ababcbacadefegdehijhklij"
Output: [9,7,8]
Explanation:
The partition is "ababcbaca", "defegde", "hijhklij".
This is a partition so that each letter appears in at most one part.
A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits S into less parts.
Note:
S will have length in range [1, 500].
S will consist of lowercase letters ('a' to 'z') only.
*/
/**
116 / 116 test cases passed.
Status: Accepted
Runtime: 6 ms
*/
class Solution {
public:
vector<int> partitionLabels(string S) {
vector<int> ans;
vector<int> markUp(26,-1);
for(auto i = 0; i<S.size(); ++i){
if(i + 1 > markUp[S[i] - 'a']){
markUp[S[i] - 'a'] = i+1;
}
}
int tmpMax = 1;
for(auto i = 0; i<S.size(); ++i){
if(markUp[S[i] - 'a'] > tmpMax){
tmpMax = markUp[S[i] - 'a'];
}
if(i + 1 == tmpMax){
if(ans.empty()){
ans.push_back(tmpMax);
} else {
int sum = accumulate(ans.begin(), ans.end(), 0);
ans.push_back(tmpMax - sum);
}
}
}
return ans;
}
};
int main(){
Solution solve;
vector<int> ans = solve.partitionLabels("abacdefc");
for_each(ans.begin(), ans.end(), [](const int num){
cout<<num<<endl;
});
return 0;
}
| [
"1032419360@qq.com"
] | 1032419360@qq.com |
e3786dbf74c8eae35be62f210537f268eca36258 | d2e640d0131676e0d6f35135ab3474ff699f272b | /libs/ledger/include/ledger/chain/time_travelogue.hpp | 450497d0b0d14ec2d7e2edee886294a81fcfa339 | [
"Apache-2.0",
"LicenseRef-scancode-unknown",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | engineerkatie/ledger | dbb1e062c18db99a96b3d24252953d7103075b81 | 044d118994cfc53e749ce1d1ed22dad5723067b0 | refs/heads/master | 2020-07-24T00:23:13.572676 | 2019-12-09T09:19:20 | 2019-12-09T09:19:20 | 207,748,084 | 1 | 1 | Apache-2.0 | 2019-09-11T07:17:54 | 2019-09-11T07:17:54 | null | UTF-8 | C++ | false | false | 2,037 | hpp | #pragma once
//------------------------------------------------------------------------------
//
// Copyright 2018-2019 Fetch.AI Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//------------------------------------------------------------------------------
#include "chain/constants.hpp"
#include "core/serializers/base_types.hpp"
#include "ledger/chain/block.hpp"
namespace fetch {
namespace ledger {
/**
* Packet format used to convey heaviest chain for node sync.
*/
template <class B>
struct TimeTravelogue
{
using Block = B;
using BlockHash = Digest;
using Blocks = std::vector<Block>;
Blocks blocks;
BlockHash heaviest_hash;
};
} // namespace ledger
namespace serializers {
template <class B, class D>
struct MapSerializer<ledger::TimeTravelogue<B>, D>
{
using Type = ledger::TimeTravelogue<B>;
using DriverType = D;
static constexpr uint8_t BLOCKS = 1;
static constexpr uint8_t HEAVIEST_HASH = 2;
template <class Constructor>
static void Serialize(Constructor &map_constructor, Type const &travelogue)
{
auto map = map_constructor(2);
map.Append(BLOCKS, travelogue.blocks);
map.Append(HEAVIEST_HASH, travelogue.heaviest_hash);
}
template <class MapDeserializer>
static void Deserialize(MapDeserializer &map, Type &travelogue)
{
map.ExpectKeyGetValue(BLOCKS, travelogue.blocks);
map.ExpectKeyGetValue(HEAVIEST_HASH, travelogue.heaviest_hash);
}
};
} // namespace serializers
} // namespace fetch
| [
"nathan.cameron.hutton@gmail.com"
] | nathan.cameron.hutton@gmail.com |
f1f3ea376d25ed624738b2fc0d6b4f1201b9b447 | 7d13ea2ac1a16811a9828470cf572ea77553c339 | /src/main.cpp | fac92bc8aa71c104842f1e5cc46305e9cf1ecd4a | [
"MIT"
] | permissive | tcosmo/simcqca | e8f12d2ed28c471d98ba9416bc62ac0093931291 | 47dcbf439a9e6658d8e055f584372d096683a196 | refs/heads/master | 2022-11-19T19:17:39.801914 | 2020-07-20T22:10:41 | 2020-07-20T22:10:41 | 274,220,985 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 497 | cpp | #include "config.h"
#include "arguments.h"
#include "graphic_engine.h"
#include "world.h"
#include <cstdio>
int main(int argc, char *argv[]) {
Arguments arguments;
parseArguments(argc, argv, arguments);
World world(arguments.isSequential, arguments.inputType, arguments.inputStr,
arguments.constructCycleInLine, arguments.cycleBoth);
GraphicEngine graphicEngine(world, 800 * 1.5, 600 * 1.5,
arguments.isTikzEnabled);
graphicEngine.run();
} | [
"tristan.sterin@gmail.com"
] | tristan.sterin@gmail.com |
fbb2dd295a4cf09a2b9bde236574aef494a4d395 | 333b58a211c39f7142959040c2d60b69e6b20b47 | /Odyssey/Samurai/cmdQueue.cpp | 608c951957230c63247effff68b27855c4b9e958 | [] | no_license | JoeAltmaier/Odyssey | d6ef505ade8be3adafa3740f81ed8d03fba3dc1a | 121ea748881526b7787f9106133589c7bd4a9b6d | refs/heads/master | 2020-04-11T08:05:34.474250 | 2015-09-09T20:03:29 | 2015-09-09T20:03:29 | 42,187,845 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 706 | cpp | #include "SamuraiServer.h"
// add a command string to our current command strings queue
void node::enqueue()
{
node * tmp = head;
node * tmptail = tail;
if (! isEmpty())
{
tmptail->next = this;
tail = this;
}
else
{
tmp = this;
tmptail = this;
head = tmp;
tail = tmptail;
}
tail->next = NULL;
}
int node::dequeue()
{
node * tmp;
if (isEmpty())
return(-32);
else
{
tmp = head;
if (tmp->next == NULL)
{
head = NULL;
delete(tmp);
return(0);
}
head = tmp->next;
head->prev = NULL;
delete (tmp);
}
return (0);
}
bool node::isEmpty()
{
if (head == NULL)
return (true);
else
return (false);
}
| [
"joe.altmaier@sococo.com"
] | joe.altmaier@sococo.com |
968eca3437d0da838b92e11cb232bcdb693eb441 | 315fd47690450e7a0530bf4b3596cc9448c88929 | /aoj/13/1368.cpp | 353fae85911e3a2162db510abdf2c61b11952818 | [] | no_license | 1119-2916/competitive-programming | 8d59f2c3c36de719d665307fcaa138cc03845573 | 356b66d2f93bf6e28f04af8968e0f1f6ae4d7bae | refs/heads/master | 2021-06-08T14:33:14.620002 | 2020-04-26T14:01:44 | 2020-04-26T14:01:44 | 108,534,522 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,525 | cpp | #include <bits/stdc++.h>
using namespace std;
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
signed main()
{
vvi table(10, vi(10));
rep(i, 10) {
rep(j, 10) {
cin >> table[i][j];
}
}
int data[10][10][10][10];
rep(i, 10) {
rep(j, 10) {
rep(k, 10) {
rep(l, 10) {
data[i][j][k][l] =
table[table[table[table[0][i]][j]][k]][l];
}
}
}
}
int ret = 0;
rep(i, 10) {
rep(j, 10) {
rep(k, 10) {
rep(l, 10) {
bool fl = false;
rep(n, 10) {
if (i == n) {
continue;
} else if (!table[data[n][j][k][l]]
[data[i][j][k][l]]) {
fl = true;
}
}
rep(n, 10) {
if (j == n) {
continue;
} else if (!table[data[i][n][k][l]]
[data[i][j][k][l]]) {
fl = true;
}
}
rep(n, 10) {
if (k == n) {
continue;
} else if (!table[data[i][j][n][l]]
[data[i][j][k][l]]) {
fl = true;
}
}
rep(n, 10) {
if (l == n) {
continue;
} else if (!table[data[i][j][k][n]]
[data[i][j][k][l]]) {
fl = true;
}
}
rep(n, 10) {
if (data[i][j][k][l] == n) {
continue;
} else if (!table[data[i][j][k][l]][n]) {
fl = true;
}
}
if (!table[data[j][i][k][l]][data[i][j][k][l]]
&& i != j) {
fl = true;
}
if (!table[data[i][k][j][l]][data[i][j][k][l]]
&& k != j) {
fl = true;
}
if (!table[data[i][j][l][k]][data[i][j][k][l]]
&& k != l) {
fl = true;
}
if (!table[data[i][j][k][data[i][j][k][l]]][l]
&& l != data[i][j][k][l]) {
fl = true;
}
if (fl) {
ret++;
}
}
}
}
}
cout << ret << endl;
return 0;
}
| [
"ti11192916@gmail.com"
] | ti11192916@gmail.com |
f584abdcf7278e104458668bcbb92206a2cb2ccc | 5cd21f9c4909a0882191c5436c4e88de05fa57f9 | /include/examples/AGN/AGNClumpy/PAGNClumpySimulationTeam.hpp | be05257265736d942e67fb71df1048ff31a81b2e | [] | no_license | melazzini/physapi | 4cf79e898ab9ad9171710d667f51ec4c270f130e | 1557e4a82a9152725f6707e6fe452ef83dddef6d | refs/heads/master | 2023-03-10T21:41:20.301768 | 2021-02-23T19:02:07 | 2021-02-23T19:02:07 | 313,977,382 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,380 | hpp | #pragma once
#include"PAGNSimulationTeamB.hpp"
#include"PAGNClumpyStructureModelB.hpp"
#include"PAGNSimulationMng.hpp"
#include"PAGNFormula.hpp"
#include<optional>
#include"PAGNClumpyCloudFinderGPU.hpp"
#include"PAGNClumpyCloudFinder.hpp"
namespace agn
{
class PAGNClumpySimulationTeam : public PAGNSimulationTeamB
{
public:
PAGNClumpySimulationTeam(
const std::shared_ptr<PAGNStructureModelB> structureModel,
const std::shared_ptr<PVernerTable1> vernerTable1,
const std::shared_ptr<PVernerTable2> vernerTable2,
const std::shared_ptr<PFluorescenceTable> fluorescenceTable,
const std::shared_ptr<PAbundanceTable> abundances,
phys_size id, phys_float numOfPhotons, phys_float n_e, phys_float T_e,
const std::shared_ptr<PAGNFormula> agnformula,
const std::shared_ptr<PAGNInitSpectrumDirectionFilter> initSpectrumDirFilter);
private:
const PAGNClumpyStructureModelB& m_structureModel;
std::optional<phys_size> m_cloudIndex; // last cloud index, for efficiency
PSphere m_cloud;
#ifdef PHYSAPI_USE_GPU
PAGNClumpyCloudFinderGPU m_cloudFinder;
#else
PAGNClumpyCloudFinder m_cloudFinder;
#endif // PHYSAPI_USE_GPU
protected:
// move the photon inside the agn internal structure and get the distance to
// closest external boundary
virtual std::optional<phys_float> distanceToBoundary(PSimplePhoton& photon)override;
};
}// namespace agn | [
"francisco.melazzini@physics.msu.ru"
] | francisco.melazzini@physics.msu.ru |
c4e6cf312b6640cddbb329d2c0c56780add908ab | 5ce3b27bf43030a41291bb16aadbd303380c4b07 | /palmos/dictate/Diploma/Diploma/pdb.h | cd93321b26160c0af86ca40dec23e9852ab5d0af | [
"MIT"
] | permissive | m-schofield-ia/Portfolio | 96feed6b892462b1bcbdc521aafec17bc990ed3a | a2fb9f0e096d829ad7928c3cefa870dccc2cff38 | refs/heads/master | 2021-05-17T16:16:12.083200 | 2019-04-12T05:18:46 | 2019-04-12T05:18:46 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,839 | h | #pragma once
#using <mscorlib.dll>
namespace Diploma
{
using namespace System;
using namespace System::IO;
using namespace System::Windows::Forms;
public __gc class PDB
{
private:
String *fileName;
char *pdbData;
Score **scores;
int scoresCnt;
System::Void ErrorBox(String *h, String *b)
{
#pragma push_macro("MessageBox")
#undef MessageBox
MessageBox::Show(b, h, MessageBoxButtons::OK, MessageBoxIcon::Error);
#pragma pop_macro("MessageBox")
}
unsigned long ntohl(unsigned long n)
{
return (((n&0xFF)<<24)+((n&0xFF00)<<8)+((n&0xFF0000)>>8)+((n&0xFF000000)>>24));
}
unsigned short ntohs(unsigned short n)
{
return ((n>>8)|(n<<8));
}
public:
PDB(String *f)
{
fileName=f;
pdbData=NULL;
scores=NULL;
scoresCnt=0;
}
// Deallocate everything
void Done()
{
int i;
if (scores) {
for (i=0; scores[i]; i++)
free(scores[i]);
free(scores);
}
if (pdbData) {
delete pdbData;
pdbData=NULL;
}
}
// Load the pdb file and create scores array
bool Load()
{
FileStream *iStream=NULL;
BinaryReader *bReader=NULL;
bool ret=false;
try {
int hIdx=78, i;
unsigned long u32;
unsigned char buffer __gc[];
iStream=new FileStream(fileName, FileMode::Open, FileAccess::Read);
bReader=new BinaryReader(iStream);
iStream->Seek(60, SeekOrigin::Begin);
u32=bReader->ReadUInt32();
if (u32!='ATAD') // DATA reversed
throw new Exception("DATA block not found.");
u32=bReader->ReadUInt32();
if (u32!='TcId') // dIcT reversed
throw new Exception("dIcT block not found.");
iStream->Seek(76, SeekOrigin::Begin);
scoresCnt=(int)(ntohs(bReader->ReadUInt16()));
if ((scores=(Score **)calloc(sizeof(Score *)*(scoresCnt+1), 1))==NULL)
throw new Exception("Out of memory.");
for (i=0; i<scoresCnt; i++) {
Score *s;
if ((scores[i]=(Score *)calloc(sizeof(Score), 1))==NULL)
throw new Exception("Out of memory.");
iStream->Seek(hIdx, SeekOrigin::Begin);
hIdx+=8;
u32=ntohl(bReader->ReadUInt32());
iStream->Seek(u32, SeekOrigin::Begin);
buffer=bReader->ReadBytes(sizeof(Score));
System::Runtime::InteropServices::Marshal::Copy(buffer, 0, scores[i], sizeof(Score));
s=scores[i];
s->round=ntohs(s->round);
s->score=ntohs(s->score);
s->year=ntohs(s->year);
s->month=ntohs(s->month);
s->day=ntohs(s->day);
}
scores[scoresCnt]=NULL;
ret=true;
} catch (Exception *ex) {
ErrorBox("Cannot load Score file.", ex->Message);
} __finally {
if (bReader)
bReader->Close();
}
return ret;
}
// Get number of scores
int GetCount(void)
{
return scoresCnt;
}
// Get score
Score *GetScore(int idx)
{
return scores[idx];
}
};
} | [
"brian@schau.dk"
] | brian@schau.dk |
9a02506dd5ed6a32e8a52f45c6275eac5a807c76 | 5b4da825e536f570a464ae9f5d7f377fc16e12b7 | /externals/wasm-compiler/llvm/lib/Transforms/Scalar/LoopDeletion.cpp | cca75a365024c4c14b7a4cc5558b560f1847e41c | [
"BSD-3-Clause",
"Apache-2.0",
"MIT",
"NCSA"
] | permissive | JaminChan/eos_win | 9ecb3fe7d1fbb52340e7b8df42b2d3d6695930a6 | c03e57151cfe152d0d3120abb13226f4df74f37e | refs/heads/master | 2020-03-24T20:38:49.539494 | 2018-09-06T10:13:16 | 2018-09-06T10:13:16 | 142,989,586 | 0 | 0 | MIT | 2018-09-04T06:49:10 | 2018-07-31T09:02:44 | C++ | UTF-8 | C++ | false | false | 10,098 | cpp | //===- LoopDeletion.cpp - Dead Loop Deletion Pass ---------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Dead Loop Deletion Pass. This pass is responsible
// for eliminating loops with non-infinite computable trip counts that have no
// side effects or volatile instructions, and do not contribute to the
// computation of the function's return value.
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Scalar/LoopDeletion.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/IR/Dominators.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
using namespace llvm;
#define DEBUG_TYPE "loop-delete"
STATISTIC(NumDeleted, "Number of loops deleted");
/// isLoopDead - Determined if a loop is dead. This assumes that we've already
/// checked for unique exit and exiting blocks, and that the code is in LCSSA
/// form.
bool LoopDeletionPass::isLoopDead(Loop *L, ScalarEvolution &SE,
SmallVectorImpl<BasicBlock *> &exitingBlocks,
SmallVectorImpl<BasicBlock *> &exitBlocks,
bool &Changed, BasicBlock *Preheader) {
BasicBlock *exitBlock = exitBlocks[0];
// Make sure that all PHI entries coming from the loop are loop invariant.
// Because the code is in LCSSA form, any values used outside of the loop
// must pass through a PHI in the exit block, meaning that this check is
// sufficient to guarantee that no loop-variant values are used outside
// of the loop.
BasicBlock::iterator BI = exitBlock->begin();
bool AllEntriesInvariant = true;
bool AllOutgoingValuesSame = true;
while (PHINode *P = dyn_cast<PHINode>(BI)) {
Value *incoming = P->getIncomingValueForBlock(exitingBlocks[0]);
// Make sure all exiting blocks produce the same incoming value for the exit
// block. If there are different incoming values for different exiting
// blocks, then it is impossible to statically determine which value should
// be used.
AllOutgoingValuesSame =
all_of(makeArrayRef(exitingBlocks).slice(1), [&](BasicBlock *BB) {
return incoming == P->getIncomingValueForBlock(BB);
});
if (!AllOutgoingValuesSame)
break;
if (Instruction *I = dyn_cast<Instruction>(incoming))
if (!L->makeLoopInvariant(I, Changed, Preheader->getTerminator())) {
AllEntriesInvariant = false;
break;
}
++BI;
}
if (Changed)
SE.forgetLoopDispositions(L);
if (!AllEntriesInvariant || !AllOutgoingValuesSame)
return false;
// Make sure that no instructions in the block have potential side-effects.
// This includes instructions that could write to memory, and loads that are
// marked volatile. This could be made more aggressive by using aliasing
// information to identify readonly and readnone calls.
for (Loop::block_iterator LI = L->block_begin(), LE = L->block_end();
LI != LE; ++LI) {
for (Instruction &I : **LI) {
if (I.mayHaveSideEffects())
return false;
}
}
return true;
}
/// Remove dead loops, by which we mean loops that do not impact the observable
/// behavior of the program other than finite running time. Note we do ensure
/// that this never remove a loop that might be infinite, as doing so could
/// change the halting/non-halting nature of a program. NOTE: This entire
/// process relies pretty heavily on LoopSimplify and LCSSA in order to make
/// various safety checks work.
bool LoopDeletionPass::runImpl(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
LoopInfo &loopInfo) {
assert(L->isLCSSAForm(DT) && "Expected LCSSA!");
// We can only remove the loop if there is a preheader that we can
// branch from after removing it.
BasicBlock *preheader = L->getLoopPreheader();
if (!preheader)
return false;
// If LoopSimplify form is not available, stay out of trouble.
if (!L->hasDedicatedExits())
return false;
// We can't remove loops that contain subloops. If the subloops were dead,
// they would already have been removed in earlier executions of this pass.
if (L->begin() != L->end())
return false;
SmallVector<BasicBlock *, 4> exitingBlocks;
L->getExitingBlocks(exitingBlocks);
SmallVector<BasicBlock *, 4> exitBlocks;
L->getUniqueExitBlocks(exitBlocks);
// We require that the loop only have a single exit block. Otherwise, we'd
// be in the situation of needing to be able to solve statically which exit
// block will be branched to, or trying to preserve the branching logic in
// a loop invariant manner.
if (exitBlocks.size() != 1)
return false;
// Finally, we have to check that the loop really is dead.
bool Changed = false;
if (!isLoopDead(L, SE, exitingBlocks, exitBlocks, Changed, preheader))
return Changed;
// Don't remove loops for which we can't solve the trip count.
// They could be infinite, in which case we'd be changing program behavior.
const SCEV *S = SE.getMaxBackedgeTakenCount(L);
if (isa<SCEVCouldNotCompute>(S))
return Changed;
// Now that we know the removal is safe, remove the loop by changing the
// branch from the preheader to go to the single exit block.
BasicBlock *exitBlock = exitBlocks[0];
// Because we're deleting a large chunk of code at once, the sequence in which
// we remove things is very important to avoid invalidation issues. Don't
// mess with this unless you have good reason and know what you're doing.
// Tell ScalarEvolution that the loop is deleted. Do this before
// deleting the loop so that ScalarEvolution can look at the loop
// to determine what it needs to clean up.
SE.forgetLoop(L);
// Connect the preheader directly to the exit block.
TerminatorInst *TI = preheader->getTerminator();
TI->replaceUsesOfWith(L->getHeader(), exitBlock);
// Rewrite phis in the exit block to get their inputs from
// the preheader instead of the exiting block.
BasicBlock *exitingBlock = exitingBlocks[0];
BasicBlock::iterator BI = exitBlock->begin();
while (PHINode *P = dyn_cast<PHINode>(BI)) {
int j = P->getBasicBlockIndex(exitingBlock);
assert(j >= 0 && "Can't find exiting block in exit block's phi node!");
P->setIncomingBlock(j, preheader);
for (unsigned i = 1; i < exitingBlocks.size(); ++i)
P->removeIncomingValue(exitingBlocks[i]);
++BI;
}
// Update the dominator tree and remove the instructions and blocks that will
// be deleted from the reference counting scheme.
SmallVector<DomTreeNode*, 8> ChildNodes;
for (Loop::block_iterator LI = L->block_begin(), LE = L->block_end();
LI != LE; ++LI) {
// Move all of the block's children to be children of the preheader, which
// allows us to remove the domtree entry for the block.
ChildNodes.insert(ChildNodes.begin(), DT[*LI]->begin(), DT[*LI]->end());
for (DomTreeNode *ChildNode : ChildNodes) {
DT.changeImmediateDominator(ChildNode, DT[preheader]);
}
ChildNodes.clear();
DT.eraseNode(*LI);
// Remove the block from the reference counting scheme, so that we can
// delete it freely later.
(*LI)->dropAllReferences();
}
// Erase the instructions and the blocks without having to worry
// about ordering because we already dropped the references.
// NOTE: This iteration is safe because erasing the block does not remove its
// entry from the loop's block list. We do that in the next section.
for (Loop::block_iterator LI = L->block_begin(), LE = L->block_end();
LI != LE; ++LI)
(*LI)->eraseFromParent();
// Finally, the blocks from loopinfo. This has to happen late because
// otherwise our loop iterators won't work.
SmallPtrSet<BasicBlock *, 8> blocks;
blocks.insert(L->block_begin(), L->block_end());
for (BasicBlock *BB : blocks)
loopInfo.removeBlock(BB);
// The last step is to update LoopInfo now that we've eliminated this loop.
loopInfo.markAsRemoved(L);
Changed = true;
++NumDeleted;
return Changed;
}
PreservedAnalyses LoopDeletionPass::run(Loop &L, LoopAnalysisManager &AM,
LoopStandardAnalysisResults &AR,
LPMUpdater &) {
bool Changed = runImpl(&L, AR.DT, AR.SE, AR.LI);
if (!Changed)
return PreservedAnalyses::all();
return getLoopPassPreservedAnalyses();
}
namespace {
class LoopDeletionLegacyPass : public LoopPass {
public:
static char ID; // Pass ID, replacement for typeid
LoopDeletionLegacyPass() : LoopPass(ID) {
initializeLoopDeletionLegacyPassPass(*PassRegistry::getPassRegistry());
}
// Possibly eliminate loop L if it is dead.
bool runOnLoop(Loop *L, LPPassManager &) override;
void getAnalysisUsage(AnalysisUsage &AU) const override {
getLoopAnalysisUsage(AU);
}
};
}
char LoopDeletionLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(LoopDeletionLegacyPass, "loop-deletion",
"Delete dead loops", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopPass)
INITIALIZE_PASS_END(LoopDeletionLegacyPass, "loop-deletion",
"Delete dead loops", false, false)
Pass *llvm::createLoopDeletionPass() { return new LoopDeletionLegacyPass(); }
bool LoopDeletionLegacyPass::runOnLoop(Loop *L, LPPassManager &) {
if (skipLoop(L))
return false;
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
LoopInfo &loopInfo = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
LoopDeletionPass Impl;
return Impl.runImpl(L, DT, SE, loopInfo);
}
| [
"349683504@qq.com"
] | 349683504@qq.com |
93e18785e6b81322d8cd5c9203e3af3eb211818f | 297a04269bdf6ed79de338cdc752233092532158 | /Duvansky/граф.cpp | ae40aabaefc1ced4532a9c742ea754da8ced2bec | [] | no_license | tapoton/PLT_2017_2sem_2c_4gr | 347cbfd3c0a4b4ec7eb5f8ef86c9edcbf2ac768b | 703b123a768fc7ceb6e3e61c64abf742ed62fbf0 | refs/heads/master | 2020-05-26T17:19:24.192801 | 2017-10-04T07:04:06 | 2017-10-04T07:04:06 | 82,483,628 | 8 | 26 | null | 2017-10-31T18:54:18 | 2017-02-19T19:25:53 | C++ | UTF-8 | C++ | false | false | 1,305 | cpp | #include <iostream>
using namespace std;
void proc (int v,int** a,int n)//procedura poiska posledovatelnosti vershin
{
int** b=a;
for(int i=0;i<n;i++)
{
if(b[v][i]==1)
{
b[v][i]=0;
b[i][v]=0;
proc(i,b,n);
}
}
cout<<v;
}
bool svyaz(int** a, int n)//proverka na svyznost
{
for(int i=0;i<n;i++)
{
bool k=false;
for(int j=0;j<n;j++)
if(a[i][j]==1) { k=true;break;}
if(!k) return false;
}
}
int kol_nechet(int** a, int n)//kolichestvo vershin s nechetnoy stepeniyu
{
int k=0;
for(int i=0;i<n;i++)
{ int s=0;
for(int j=0;j<n;j++)
s+=a[i][j];
if(s%2!=0) k++;
}
return k;
}
int necnet_versh(int**a,int n)//vidaet vershinu s nechetnoy stepeniyu
{
for(int i=0;i<n;i++)
{
int s=0;
for(int j=0;j<n;j++)
s+=a[i][j];
if(s%2!=0) return i;
}
}
void main()
{ int n;
cout<<"vvedite kolichestvo vershin grafa"<<endl;
cin>>n;
int** a= new int*[n];
for(int i=0;i<n;i++)
a[i]=new int[n];
cout<<"vvedite matricu smezhnosti grapha,numeraciya vershin s 0"<<endl;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
if(svyaz(a,n)&&kol_nechet(a,n)<=2)
{
if(kol_nechet(a,n)==0) proc(0,a,n);
else proc(necnet_versh(a,n),a,n);
}
else cout<<"graph nevozmozhno narisovat ne otryvaya ruki";
system("pause");
} | [
"maxim8-97@mail.ru"
] | maxim8-97@mail.ru |
c473105b0730b07d352acac8ad7102bb0e9bf15f | e9a7976b607c8ee363a9c05f6267dd82d22e6b6f | /src/Engine/TextureLoader.cpp | 9cc98c300d625c41a0ee749a9f9a66ae408a73a2 | [
"MIT"
] | permissive | vladnazar0v/SimEngine | d24c92cd5f2e8490cf852da6ef919ecaffda2ef3 | b33c08ba5211666ab62f205ac6ef9ead3a68f660 | refs/heads/master | 2022-06-23T01:18:39.986730 | 2019-12-21T18:15:02 | 2019-12-21T18:15:02 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,210 | cpp | #include <Engine/TextureLoader.hpp>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
TextureLoader::TextureLoader(){
}
TextureLoader::~TextureLoader(){
}
GLuint TextureLoader::getTextureID(std:: string texFileName){
int width, height, channels;
stbi_uc* image = stbi_load(texFileName.c_str(), &width, &height,
&channels, STBI_rgb);
GLuint mtexture;
// load texture
glGenTextures(1, &mtexture);
glBindTexture(GL_TEXTURE_2D, mtexture);
// Set texture wrapping
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// Set texture filtering parameters (2 options)
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // 1
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // 2
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
stbi_image_free(image);
return mtexture;
} | [
"vladnazarov2@gmail.com"
] | vladnazarov2@gmail.com |
f13eebb938922ba3252d1c94efaa8abeacd199a4 | 561c7c4fec88c72c837d4345814182e743cd0767 | /HW12/task1/KMP.cpp | 7d93ab6cba18936a12a771b65bdb8a333d0f57de | [
"MIT"
] | permissive | Diana-Govorova/SPbSU-SemesterI | 6aaa9f9d356ac12c8194a19f5104438a2fb087af | de35292d8ac52e74e126d2a40073fbd3db55a2f4 | refs/heads/master | 2021-05-21T01:39:03.870735 | 2020-05-08T12:03:10 | 2020-05-08T12:03:10 | 252,489,532 | 0 | 0 | MIT | 2020-04-28T16:55:04 | 2020-04-02T15:10:53 | C++ | UTF-8 | C++ | false | false | 966 | cpp | #include <stdio.h>
#include <string.h>
int algoritmKMP(char* string, char* sample, char* delimiter)
{
int lengthOfSample = strlen(sample);
int lengthOfString = strlen(string);
int lengthOfDelimiter = strlen(delimiter);
const int commonLength = lengthOfDelimiter + lengthOfSample + lengthOfString +1;
char* commonSrting = new char[commonLength] {};
int arrayOfPrefix[2003]{};
strcat(commonSrting, sample);
strcat(commonSrting, delimiter);
strcat(commonSrting, string);
arrayOfPrefix[0] = 0;
for (int i = 1; i < commonLength; i++)
{
int j = arrayOfPrefix[i - 1];
while ((j > 0) && (commonSrting[i] != commonSrting[j]))
{
j = arrayOfPrefix[j - 1];
}
if (commonSrting[i] == commonSrting[j])
{
j++;
}
arrayOfPrefix[i] = j;
}
int answer = 0;
delete[] commonSrting;
for (int i = 0; i < commonLength; i++)
{
if (arrayOfPrefix[i] == lengthOfSample)
{
answer = i - 2 * lengthOfSample + 1;
return answer;
}
}
return -1;
}
| [
"diana.govorova2001@gmail.com"
] | diana.govorova2001@gmail.com |
2dae2ff322548da4f698895191fe3b57340b9b34 | 315fd47690450e7a0530bf4b3596cc9448c88929 | /univ/wupc/19/b.cpp | 82ec5a98cb5bde3804b6507ae96623a020110a14 | [] | no_license | 1119-2916/competitive-programming | 8d59f2c3c36de719d665307fcaa138cc03845573 | 356b66d2f93bf6e28f04af8968e0f1f6ae4d7bae | refs/heads/master | 2021-06-08T14:33:14.620002 | 2020-04-26T14:01:44 | 2020-04-26T14:01:44 | 108,534,522 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,974 | cpp | #include <bits/stdc++.h>
using namespace std;
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)
int dxy[5] = {0, 1, 0, -1, 0};
// cmd
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int2(h, w);
bool fl = false, ffl = true;
vvi data(h, vi(w));
rep(i, h) {
rep(j, w) {
cin >> data[i][j];
if (data[i][j] == 5) fl = true;
if (data[i][j]) ffl = false;
}
}
if (ffl) {
std::cout << "Yes 0" << std::endl;
return 0;
}
if (!fl) {
std::cout << "No" << std::endl;
return 0;
}
if (h == 1) {
int ans = INF;
rep(i, w) {
if (data[h-1][i] == 5) {
int ret = 0, yui = 0;
rep(j, i) {
yui = max(yui, data[h-1][j]);
}
if (yui == 9) {
ret += 3;
} else if (yui == 8) {
ret += 2;
} else if (yui == 7) {
ret += 1;
} else if (yui == 6) {
ret += 1;
}
yui = 0;
for (int j = i+1; j < w; j++) {
yui = max(yui, data[h-1][j]);
}
if (yui == 9) {
ret += 3;
} else if (yui == 8) {
ret += 2;
} else if (yui == 7) {
ret += 1;
} else if (yui == 6) {
ret += 1;
}
ans = min(ans, ret + 1);
}
}
std::cout << "Yes " << ans << std::endl;
} else if (w == 1) {
int ans = INF;
rep(i, h) {
if (data[i][w-1] == 5) {
int ret = 0, yui = 0;
rep(j, i) {
yui = max(yui, data[j][w-1]);
}
if (yui == 9) {
ret += 3;
} else if (yui == 8) {
ret += 2;
} else if (yui == 7) {
ret += 1;
} else if (yui == 6) {
ret += 1;
}
yui = 0;
for (int j = i+1; j < h; j++) {
yui = max(yui, data[j][w-1]);
}
if (yui == 9) {
ret += 3;
} else if (yui == 8) {
ret += 2;
} else if (yui == 7) {
ret += 1;
} else if (yui == 6) {
ret += 1;
}
ans = min(ans, ret + 1);
}
}
std::cout << "Yes " << ans << std::endl;
} else {
int ret = 0, ans = 0;
rep(i, h) {
rep(j, w) {
ret = max(ret, data[i][j]);
}
}
if (ret == 9) {
ans += 3;
} else if (ret == 8) {
ans += 2;
} else if (ret == 7) {
ans += 1;
} else if (ret == 6) {
ans += 1;
}
std::cout << "Yes " << ans + 1 << std::endl;
}
return 0;
}
| [
"ti11192916@gmail.com"
] | ti11192916@gmail.com |
1cfb2eabac1860039d776928a938783acc66c38f | d25e3e8208751a92610782c37226809ace76d13b | /Plugins/KanbanBoard/KanbanPageView.h | 148f978640d1183a69bfc47d1fa7c26e5ebde727 | [] | no_license | StefanoLusardi/Kanban | 94589bcf6d7b78a59f54c037e4650704a708561b | 4819bee20b4f05312524d1b1c3006b3aeadb7977 | refs/heads/master | 2020-04-07T13:59:32.045313 | 2020-03-15T17:28:50 | 2020-03-15T17:28:50 | 158,430,001 | 16 | 3 | null | null | null | null | UTF-8 | C++ | false | false | 1,945 | h | #pragma once
#include <QWidget>
class Model;
class QSplitter;
class KanbanItemModel;
class KanbanColumnView;
class QItemSelectionModel;
namespace Ui { class KanbanPageView; }
class KanbanPageView : public QWidget
{
Q_OBJECT
public:
KanbanPageView(const QString& pageName, KanbanItemModel* model, QWidget *parent = Q_NULLPTR);
~KanbanPageView();
void loadConfig(const QJsonObject& pageConfig);
void saveConfig(QJsonArray& config) const;
QString getPageName() const;
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
void dropEvent(QDropEvent *event) override;
public slots:
void onCreateKanban(const QString& page);
void onRenameKanban(const QString& page);
void onDeleteKanban(const QString& page);
void onCreateColumn(const QString& page);
void onRenameColumn(const QString& page);
void onDeleteColumn(const QString& page);
private slots:
void onDeleteColumnView(const QString& deletedColumnName);
void onAddColumnViewKanban(const QString& columnName);
void onKanbanSelected(const QString& columnSenderName, const QStringList& kanbanTextList);
private:
Ui::KanbanPageView *ui;
QString mPageName;
KanbanItemModel* mKanbanModel;
QItemSelectionModel* mSelectionKanbanModel;
std::vector<KanbanColumnView*> mColumnViews;
QSplitter *mSplitterColumnViews;
QString mSelectedColumnName;
QStringList getColumnViewNames() const;
void setModel(KanbanItemModel* kanbanModel);
void setSelectedColumnView(const QString& selectedColumnName);
void createColumn(const QString& columnName, const QColor& columnColor, bool isCollapsed = false);
void createKanban(const QString& text, const QColor& color, const QString& columnName);// const;
std::vector<KanbanColumnView*>::iterator findColumn(const QString& columnName);
};
| [
"lusardi.stefano@gmail.com"
] | lusardi.stefano@gmail.com |
5d5c055af1bd8b959ee07099be21fe13a678f235 | c0d2712a308fe2c61e86b53e74a122ea6d5a4f01 | /libym_logic/src/cnfdd/UniOp.cc | 83fccd554d2af0393ca084e316b448f727254d29 | [] | no_license | yusuke-matsunaga/ymtools | 1b6d1d40c9c509786873ff1ac4230afef17e21e7 | 82dc54c009b26cba9f3a5f6c652c3be76ccd33e4 | refs/heads/master | 2020-12-24T08:49:50.628839 | 2015-11-13T16:43:00 | 2015-11-13T16:43:00 | 31,797,792 | 1 | 1 | null | 2015-07-06T14:29:01 | 2015-03-07T02:08:27 | C++ | UTF-8 | C++ | false | false | 841 | cc |
/// @file UniOp.cc
/// @brief UniOp の実装ファイル
/// @author Yusuke Matsunaga (松永 裕介)
///
/// Copyright (C) 2005-2012, 2014 Yusuke Matsunaga
/// All rights reserved.
#include "UniOp.h"
BEGIN_NAMESPACE_YM_CNFDD
//////////////////////////////////////////////////////////////////////
// クラス UniOp
//////////////////////////////////////////////////////////////////////
// @brief コンストラクタ
// @param[in] mgr マネージャ
// @param[in] name テーブル名
UniOp::UniOp(CNFddMgrImpl& mgr,
const char* name) :
Op(mgr),
mCompTbl(mgr, name)
{
}
// @brief デストラクタ
UniOp::~UniOp()
{
}
// @brief 次の GC で回収されるノードに関連した情報を削除する.
void
UniOp::sweep()
{
if ( mCompTbl.used_num() > 0 ) {
mCompTbl.sweep();
}
}
END_NAMESPACE_YM_CNFDD
| [
"yusuke_matsunaga@ieee.org"
] | yusuke_matsunaga@ieee.org |
fd73676d4888adff3977129731bec7bbd46d0499 | d2f4e8999683a8f36d82bda5862761f01ea7d1f9 | /MyWeChatServer_Linux/ClientTest.cpp | bb5e4b5b65a704d59e03b9813bc7a44aeb941661 | [] | no_license | Kevinhe136/MyWeChatServer_Linux | f3fc1dc2b0d2a75cde063de495da651ee6dfdd5c | 06cca879ff5cbfb76050e04e77f6b13eed0f0e29 | refs/heads/master | 2021-01-20T10:04:40.479073 | 2017-08-31T01:01:43 | 2017-08-31T01:01:43 | 101,621,226 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,232 | cpp | #include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<iostream>
#include<errno.h>
#include<netinet/in.h>
using namespace std;
class clientTest
{
private:
sockaddr_in ClientAddr;
int ClientFd;
public:
clientTest();
~clientTest();
void initialClient();
void stopConnection();
void sendMsg(string msg);
};
int main(void)
{
int ClientFd;
sockaddr_in ClientAddr;
ClientAddr.sin_family=AF_INET;
ClientAddr.sin_addr.s_addr=htons(INADDR_ANY);
ClientAddr.sin_port=htons(0);
ClientFd=socket(AF_INET,SOCK_STREAM,0);
if(Client==-1)
{
cout<<"Client socket created falied!!"<<errno<<endl;
return 0;
}
if(bind(ClientFd,(struct sockaddr*)&ClientAddr,sizeof(ClientAddr))==-1)
{
cout<<"bind Client address failed!!"<<errno<<endl;
return 0;
}
int ServerFd;
sockaddr_in ServerAddr;
ServerAddr.sin_family=AF_INET;
if(inet_aton("192.168.1.112",&ServerAddr.sin_addr)==0)
{
cout<<"server IPAddress error!!"<<endl;
return 0;
}
ServerAddr.sin_port=6000;
socklen_t ServerLen=sizeof(ServerAddr);
if(connect(ClientFd,(struct sockaddr*)&ServerAddr,ServerLen)==-1)
{
cout<<"can't connect to server!!"<<endl;
return 0;
}
char *buffer="Hello, My Server!!";
send(ClientFd,buffer,18,0);
}
| [
"kevinhe136@163.com"
] | kevinhe136@163.com |
9e36048e5a46add416fee1d5c6f4cf24fe9f1ebf | 539d3918edf7d4955876725e04278f7ae55c921d | /OldOpenCLVST/Source/ReverbSimulator_SharedCode/PluginProcessor.cpp | c1d0bdf521c80dcf4d2cf687ca038651e2ac6c32 | [] | no_license | sondrehav/master | 8103160b2a2a0497cef56ea3098510cc66713b09 | 7dd20cc4014194d2cfe38a50f58c002eeaf1eb82 | refs/heads/master | 2020-06-05T07:34:53.009093 | 2019-06-17T14:27:02 | 2019-06-17T14:27:02 | 192,360,856 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,942 | cpp | /*
==============================================================================
This file was auto-generated!
It contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <thread>
//==============================================================================
ReverbSimulatorAudioProcessor::ReverbSimulatorAudioProcessor()
: AudioProcessor (BusesProperties()
.withInput ("Input", AudioChannelSet::stereo(), true)
.withOutput ("Output", AudioChannelSet::stereo(), true)),
state(*this, nullptr)
{
state.state = ValueTree(String("ReverbSimulator"));
}
ReverbSimulatorAudioProcessor::~ReverbSimulatorAudioProcessor()
{
}
//==============================================================================
const String ReverbSimulatorAudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool ReverbSimulatorAudioProcessor::acceptsMidi() const
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool ReverbSimulatorAudioProcessor::producesMidi() const
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
bool ReverbSimulatorAudioProcessor::isMidiEffect() const
{
#if JucePlugin_IsMidiEffect
return true;
#else
return false;
#endif
}
double ReverbSimulatorAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int ReverbSimulatorAudioProcessor::getNumPrograms()
{
return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
// so this should be at least 1, even if you're not really implementing programs.
}
int ReverbSimulatorAudioProcessor::getCurrentProgram()
{
return 0;
}
void ReverbSimulatorAudioProcessor::setCurrentProgram (int index)
{
}
const String ReverbSimulatorAudioProcessor::getProgramName (int index)
{
return {};
}
void ReverbSimulatorAudioProcessor::changeProgramName (int index, const String& newName)
{
}
//==============================================================================
void ReverbSimulatorAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
// Use this method as the place to do any pre-playback
// initialisation that you need..
}
void ReverbSimulatorAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool ReverbSimulatorAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
#if JucePlugin_IsMidiEffect
ignoreUnused (layouts);
return true;
#else
// This is the place where you check if the layout is supported.
// In this template code we only support mono or stereo.
if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
return false;
// This checks if the input layout matches the output layout
#if ! JucePlugin_IsSynth
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
#endif
return true;
#endif
}
#endif
void ReverbSimulatorAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
{
ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
// In case we have more outputs than inputs, this code clears any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
// This is here to avoid people getting screaming feedback
// when they first compile a plugin, but obviously you don't need to keep
// this code if your algorithm always overwrites all the output channels.
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
// This is the place where you'd normally do the guts of your plugin's
// audio processing...
// Make sure to reset the state if your inner loop is processing
// the samples and the outer loop is handling the channels.
// Alternatively, you can process the samples with the channels
// interleaved by keeping the same state.
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer (channel);
// ..do something to the data...
}
}
//==============================================================================
bool ReverbSimulatorAudioProcessor::hasEditor() const
{
return true; // (change this to false if you choose to not supply an editor)
}
AudioProcessorEditor* ReverbSimulatorAudioProcessor::createEditor()
{
return new ReverbSimulatorAudioProcessorEditor (*this);
}
//==============================================================================
void ReverbSimulatorAudioProcessor::getStateInformation (MemoryBlock& destData)
{
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.
}
void ReverbSimulatorAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
}
//==============================================================================
// This creates new instances of the plugin..
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new ReverbSimulatorAudioProcessor();
}
| [
"sondre.havellen@gmail.com"
] | sondre.havellen@gmail.com |
3029bc18bb8de96176d6b78a5b468304c43c7c43 | ab1c643f224197ca8c44ebd562953f0984df321e | /pchealth/helpctr/shell/namespace/protocolroot.cpp | 78df835014b96003999020a577b60f75d44aca50 | [] | no_license | KernelPanic-OpenSource/Win2K3_NT_admin | e162e0452fb2067f0675745f2273d5c569798709 | d36e522f16bd866384bec440517f954a1a5c4a4d | refs/heads/master | 2023-04-12T13:25:45.807158 | 2021-04-13T16:33:59 | 2021-04-13T16:33:59 | 357,613,696 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 44,012 | cpp | /******************************************************************************
Copyright (c) 1999 Microsoft Corporation
Module Name:
ProtocolRoot.cpp
Abstract:
This file contains the implementation of the CPAData class, which is
used to specify a single problem area
Revision History:
Davide Massarenti (Dmassare) 07/05/99
created
******************************************************************************/
#include "stdafx.h"
#include <Debug.h>
/////////////////////////////////////////////////////////////////////////////
// BINDSTATUS_FINDINGRESOURCE 01
// BINDSTATUS_CONNECTING 02
// BINDSTATUS_REDIRECTING 03
// BINDSTATUS_BEGINDOWNLOADDATA 04
// BINDSTATUS_DOWNLOADINGDATA 05
// BINDSTATUS_ENDDOWNLOADDATA 06
// BINDSTATUS_BEGINDOWNLOADCOMPONENTS 07
// BINDSTATUS_INSTALLINGCOMPONENTS 08
// BINDSTATUS_ENDDOWNLOADCOMPONENTS 09
// BINDSTATUS_USINGCACHEDCOPY 10
// BINDSTATUS_SENDINGREQUEST 11
// BINDSTATUS_CLASSIDAVAILABLE 12
// BINDSTATUS_MIMETYPEAVAILABLE 13
// BINDSTATUS_CACHEFILENAMEAVAILABLE 14
// BINDSTATUS_BEGINSYNCOPERATION 15
// BINDSTATUS_ENDSYNCOPERATION 16
// BINDSTATUS_BEGINUPLOADDATA 17
// BINDSTATUS_UPLOADINGDATA 18
// BINDSTATUS_ENDUPLOADDATA 19
// BINDSTATUS_PROTOCOLCLASSID 20
// BINDSTATUS_ENCODING 21
// BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE 22
// BINDSTATUS_CLASSINSTALLLOCATION 23
// BINDSTATUS_DECODING 24
// BINDSTATUS_LOADINGMIMEHANDLER 25
// BINDSTATUS_CONTENTDISPOSITIONATTACH 26
// BINDSTATUS_FILTERREPORTMIMETYPE 27
// BINDSTATUS_CLSIDCANINSTANTIATE 28
// BINDSTATUS_DLLNAMEAVAILABLE 29
// BINDSTATUS_DIRECTBIND 30
// BINDSTATUS_RAWMIMETYPE 31
// BINDSTATUS_PROXYDETECTING 32
/////////////////////////////////////////////////////////////////////////////
static const WCHAR c_szContent [] = L"Content Type";
static const WCHAR c_szSystem [] = L"hcp://system/";
static const WCHAR c_szHelp [] = L"hcp://help/";
static const WCHAR c_szRoot [] = L"hcp://";
static const WCHAR c_szSharedCSS[] = L"hcp://system/css/shared.css";
static const WCHAR c_szSystemDir [] = HC_HELPSET_SUB_SYSTEM L"\\";
static const WCHAR c_szSystemOEMDir[] = HC_HELPSET_SUB_SYSTEM_OEM L"\\";
static const WCHAR c_szVendorDir [] = HC_HELPSET_SUB_VENDORS L"\\";
typedef struct
{
LPCWSTR szPrefix;
int iPrefix;
LPCWSTR szRealSubDir;
bool fRelocate;
bool fCSS;
bool fSkipIfMissing;
} Lookup_Virtual_To_Real;
static const Lookup_Virtual_To_Real c_lookup[] =
{
{ c_szSharedCSS, MAXSTRLEN(c_szSharedCSS), NULL , false, true , true },
{ c_szHelp , MAXSTRLEN(c_szHelp ), NULL , true , false, false },
///////////////////////////////////////////////////////////////////////////////////
{ c_szSystem , MAXSTRLEN(c_szSystem ), c_szSystemOEMDir, true , false, true }, // First try the OEM directory...
{ c_szSystem , MAXSTRLEN(c_szSystem ), c_szSystemDir , true , false, true },
{ c_szRoot , MAXSTRLEN(c_szRoot ), c_szVendorDir , true , false, true },
///////////////////////////////////////////////////////////////////////////////////
{ c_szSystem , MAXSTRLEN(c_szSystem ), c_szSystemOEMDir, false, false, true }, // First try the OEM directory...
{ c_szSystem , MAXSTRLEN(c_szSystem ), c_szSystemDir , false, false, false },
{ c_szRoot , MAXSTRLEN(c_szRoot ), c_szVendorDir , false, false, false }
};
typedef struct
{
LPCWSTR szExt;
LPCWSTR szMIME;
} Lookup_Ext_To_Mime;
static const Lookup_Ext_To_Mime c_lookupMIME[] =
{
{ L".htm" , L"text/html" },
{ L".html", L"text/html" },
{ L".css" , L"text/css" },
{ L".xml" , L"text/xml" },
{ L".js" , L"application/x-javascript" },
{ L".gif" , L"image/gif" },
{ L".jpg" , L"image/jpeg" },
{ L".bmp" , L"image/bmp" },
};
/////////////////////////////////////////////////////////////////////////////
HRESULT GetMimeFromExt( LPCWSTR pszExt ,
LPWSTR pszMime ,
DWORD cchMime )
{
__HCP_FUNC_ENTRY("::GetMimeFromExt");
HRESULT hr;
MPC::wstring szMime;
bool fFound;
hr = MPC::RegKey_Value_Read( szMime, fFound, pszExt, c_szContent, HKEY_CLASSES_ROOT );
if(SUCCEEDED(hr) && fFound)
{
StringCchCopyW( pszMime, cchMime, szMime.c_str() );
}
else
{
pszMime[0] = L'\0';
for(int i=0; i<ARRAYSIZE(c_lookupMIME); i++)
{
if(!MPC::StrICmp( c_lookupMIME[i].szExt, pszExt ))
{
StringCchCopyW( pszMime, cchMime, c_lookupMIME[i].szMIME );
break;
}
}
}
__HCP_FUNC_EXIT(S_OK);
}
static LPCWSTR UnescapeFileName( CComBSTR& bstrFile ,
LPCWSTR szUrl )
{
WCHAR* rgTmpLarge;
WCHAR rgTmpSmall[MAX_PATH+1];
DWORD dwSize = MAX_PATH;
if(::InternetCanonicalizeUrlW( szUrl, rgTmpSmall, &dwSize, ICU_DECODE | ICU_NO_ENCODE ))
{
bstrFile = rgTmpSmall;
}
else
{
rgTmpLarge = new WCHAR[dwSize+1];
if(rgTmpLarge)
{
if(::InternetCanonicalizeUrlW( szUrl, rgTmpLarge, &dwSize, ICU_DECODE | ICU_NO_ENCODE ))
{
bstrFile = rgTmpLarge;
}
delete [] rgTmpLarge;
}
}
return bstrFile;
}
/////////////////////////////////////////////////////////////////////////////
#ifdef DEBUG_PROTOCOLLEAK
#include <Debug.h>
DEBUG_ProtocolLeak::DEBUG_ProtocolLeak()
{
m_num = 0;
m_numOut = 0;
m_numStart = 0;
m_numComplete = 0;
}
DEBUG_ProtocolLeak::~DEBUG_ProtocolLeak()
{
Iter it;
for(it=m_set.begin(); it != m_set.end(); it++)
{
CHCPProtocol* ptr = *it;
bool fGot = m_setStart .count( ptr ) != 0;
bool fDone = m_setComplete.count( ptr ) != 0;
DebugLog( L"Protocol Leakage: %08x %s %s %s\n", ptr, fGot ? L"STARTED" : L"NOT STARTED", fDone ? L"DONE" : L"RECEIVING", ptr->m_bstrUrlComplete );
}
}
void DEBUG_ProtocolLeak::Add( CHCPProtocol* ptr )
{
DebugLog( L"Protocol Leakage: %08x CREATED %s\n", ptr, ptr->m_bstrUrlComplete );
if(m_set.count( ptr ) != 0)
{
DebugBreak();
}
m_set.insert( ptr ); m_numOut++; m_num++;
}
void DEBUG_ProtocolLeak::Del( CHCPProtocol* ptr )
{
DebugLog( L"Protocol Leakage: %08x RELEASED %s\n", ptr, ptr->m_bstrUrlComplete );
if(m_setStart.erase( ptr ) == 1)
{
m_numStart += 0x10000;
}
if(m_setComplete.erase( ptr ) == 1)
{
m_numComplete += 0x10000;
}
if(m_set.erase( ptr ) == 1)
{
m_numOut--;
}
else
{
DebugBreak();
}
}
void DEBUG_ProtocolLeak::CheckStart( CHCPProtocol* ptr )
{
DebugLog( L"Protocol Leakage: %08x STARTED %s\n", ptr, ptr->m_bstrUrlComplete );
if(m_setStart.count( ptr ) != 0)
{
DebugBreak();
}
m_setStart.insert( ptr ); m_numStart++;
}
void DEBUG_ProtocolLeak::Completed( CHCPProtocol* ptr )
{
DebugLog( L"Protocol Leakage: %08x DONE %s\n", ptr, ptr->m_bstrUrlComplete );
m_setComplete.insert( ptr ); m_numComplete++;
}
static DEBUG_ProtocolLeak leaker;
#endif
CHCPProtocol::CHCPProtocol()
{
#ifdef DEBUG_PROTOCOLLEAK
leaker.Add( this );
#endif
__HCP_FUNC_ENTRY("CHCPProtocol::CHCPProtocol");
m_fDone = false; // bool m_fDone;
m_fReportResult = false; // bool m_fReportResult;
//
m_cbAvailableSize = 0; // DWORD m_cbAvailableSize;
m_cbTotalSize = 0; // DWORD m_cbTotalSize;
//
// CComPtr<IStream> m_pstrmRead;
// CComPtr<IStream> m_pstrmWrite;
//
// CComPtr<IInternetProtocolSink> m_pIProtSink;
// CComPtr<IInternetBindInfo> m_pIBindInfo;
m_grfSTI = 0; // DWORD m_grfSTI;
// BINDINFO m_bindinfo;
m_bindf = 0; // DWORD m_bindf;
//
// CComBSTR m_bstrUrlComplete;
// CComBSTR m_bstrUrlRedirected;
m_pDownloader = NULL; // InnerDownloader* m_pDownloader;
//
m_fRedirected = false; // bool m_fRedirected;
m_fCSS = false; // bool m_fCSS;
m_fBypass = false; // bool m_fBypass;
//
// CComPtr<IInternetProtocol> m_ipiBypass;
//
// CComBSTR m_bstrMimeType;
m_dwContentLength = 0; // DWORD m_dwContentLength;
//
m_hCache = NULL; // HANDLE m_hCache;
m_szCacheFileName[0] = 0; // WCHAR m_szCacheFileName[MAX_PATH];
memset( &m_bindinfo, 0, sizeof( m_bindinfo ) );
m_bindinfo.cbSize = sizeof( m_bindinfo );
}
CHCPProtocol::~CHCPProtocol()
{
#ifdef DEBUG_PROTOCOLLEAK
leaker.Del( this );
#endif
__HCP_FUNC_ENTRY("CHCPProtocol::~CHCPProtocol");
Shutdown();
}
////////////////////////////////////////////////////////////////////////////////
bool CHCPProtocol::OpenCacheEntry()
{
__HCP_FUNC_ENTRY("CHCPProtocol::OpenCacheEntry");
bool fRes = false;
LPCWSTR szUrl = m_bstrUrlComplete;
LPCWSTR szExt;
if((szExt = wcsrchr( szUrl, '.' ))) szExt++;
CloseCacheEntry( true );
if(::CreateUrlCacheEntryW( szUrl, 0, szExt, m_szCacheFileName, 0) )
{
if(m_szCacheFileName[0])
{
m_hCache = ::CreateFileW( m_szCacheFileName ,
GENERIC_WRITE ,
FILE_SHARE_WRITE | FILE_SHARE_READ, NULL,
CREATE_ALWAYS ,
FILE_ATTRIBUTE_NORMAL , NULL);
if(m_hCache == INVALID_HANDLE_VALUE)
{
m_hCache = NULL;
}
else
{
fRes = true;
}
}
}
__HCP_FUNC_EXIT(fRes);
}
void CHCPProtocol::WriteCacheEntry( /*[in]*/ void *pv ,
/*[in]*/ ULONG cbRead )
{
if(m_hCache && cbRead)
{
DWORD cbWritten;
if(::WriteFile( m_hCache, pv, cbRead, &cbWritten, NULL ) == FALSE || cbRead != cbWritten)
{
CloseCacheEntry( true );
}
}
}
void CHCPProtocol::CloseCacheEntry( /*[in]*/ bool fDelete )
{
if(m_hCache)
{
::CloseHandle( m_hCache ); m_hCache = NULL;
if(fDelete)
{
::DeleteUrlCacheEntryW( m_bstrUrlComplete );
}
else
{
WCHAR szHeader[256];
FILETIME ftZero = { 0, 0 };
StringCchPrintfW( szHeader, ARRAYSIZE(szHeader), L"HTTP/1.0 200 OK \r\n Content-Length: %d \r\n Content-Type: %s \r\n\r\n", m_dwContentLength, (BSTR)m_bstrMimeType );
::CommitUrlCacheEntryW( m_bstrUrlComplete, m_szCacheFileName,
ftZero, ftZero, NORMAL_CACHE_ENTRY,
szHeader, wcslen( szHeader ), NULL, 0 );
}
}
}
////////////////////////////////////////////////////////////////////////////////
HRESULT CHCPProtocol::InnerReportProgress( /*[in]*/ ULONG ulStatusCode ,
/*[in]*/ LPCWSTR szStatusText )
{
__HCP_FUNC_ENTRY("CHCPProtocol::InnerReportProgress");
HRESULT hr;
if(m_pIProtSink)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, m_pIProtSink->ReportProgress( ulStatusCode, szStatusText ));
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::InnerReportData( /*[in]*/ DWORD grfBSCF ,
/*[in]*/ ULONG ulProgress ,
/*[in]*/ ULONG ulProgressMax )
{
__HCP_FUNC_ENTRY("CHCPProtocol::InnerReportData");
HRESULT hr;
if(m_pIProtSink)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, m_pIProtSink->ReportData( grfBSCF, ulProgress, ulProgressMax ));
}
//
// On the last data notification, also send a ReportResult.
//
if(grfBSCF & BSCF_LASTDATANOTIFICATION)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportResult( S_OK, 0, 0 ));
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::InnerReportResult( /*[in]*/ HRESULT hrResult ,
/*[in]*/ DWORD dwError ,
/*[in]*/ LPCWSTR szResult )
{
__HCP_FUNC_ENTRY("CHCPProtocol::InnerReportResult");
HRESULT hr;
if(m_fReportResult == false)
{
m_fReportResult = true;
#ifdef DEBUG_PROTOCOLLEAK
leaker.Completed( this );
#endif
DEBUG_AppendPerf( DEBUG_PERF_PROTOCOL, L"CHCPProtocol::InnerReportResult : %s", SAFEBSTR( m_bstrUrlComplete ) );
if(m_pIProtSink)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, m_pIProtSink->ReportResult( hrResult, dwError, szResult ));
}
//
// Release the references to the ProtSink and BindInfo objects, but not the references to the streams.
//
Shutdown( false );
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
////////////////////////////////////////////////////////////////////////////////
void CHCPProtocol::Shutdown( /*[in]*/ bool fAll )
{
__HCP_FUNC_ENTRY("CHCPProtocol::Shutdown");
m_pIBindInfo.Release();
m_pIProtSink.Release();
CloseCacheEntry( true );
if(m_pDownloader)
{
m_pDownloader->Release();
m_pDownloader = NULL;
}
if(fAll)
{
m_pstrmRead .Release();
m_pstrmWrite.Release();
// Release BINDINFO contents
::ReleaseBindInfo( &m_bindinfo );
}
}
/////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHCPProtocol::Start( /*[in]*/ LPCWSTR szUrl ,
/*[in]*/ IInternetProtocolSink *pIProtSink ,
/*[in]*/ IInternetBindInfo *pIBindInfo ,
/*[in]*/ DWORD grfSTI ,
/*[in]*/ HANDLE_PTR dwReserved )
{
#ifdef DEBUG_PROTOCOLLEAK
leaker.CheckStart( this );
#endif
__HCP_FUNC_ENTRY("CHCPProtocol::Start");
HRESULT hr;
DEBUG_AppendPerf( DEBUG_PERF_PROTOCOL, L"CHCPProtocol::Start : %s", szUrl );
//
// Initialize variables for new download.
//
Shutdown();
m_fDone = false;
m_cbAvailableSize = 0;
m_cbTotalSize = 0;
m_pIProtSink = pIProtSink;
m_pIBindInfo = pIBindInfo;
m_grfSTI = grfSTI;
m_bstrUrlComplete = (LPCOLESTR)NULL;
m_bstrUrlRedirected = (LPCOLESTR)NULL;
//
// Get URLMoniker BINDINFO structure from IInternetBindInfo
//
m_bindinfo.cbSize = sizeof( m_bindinfo );
if(pIBindInfo)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, pIBindInfo->GetBindInfo( &m_bindf, &m_bindinfo ));
}
// Parse URL and store results inside
hr = DoParse( szUrl );
if(grfSTI & PI_PARSE_URL)
{
if(FAILED(hr))
{
__MPC_SET_ERROR_AND_EXIT(hr, S_FALSE);
}
else
{
__MPC_SET_ERROR_AND_EXIT(hr, S_OK);
}
}
if(FAILED(hr)) __MPC_FUNC_LEAVE;
// TODO: We could always spawn a worker thread to be more truly asynchronous.
// Rather than complicate this code as multithreading scenarios tend to do,
// we do everything on the main apartment thread and only pretend to be
// working on a secondary thread if we get PI_FORCE_ASYNC
if(!(grfSTI & PI_FORCE_ASYNC))
{
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind());
}
else // Wait for Continue to DoBind()
{
PROTOCOLDATA protdata;
hr = E_PENDING;
protdata.grfFlags = PI_FORCE_ASYNC;
protdata.dwState = 1;
protdata.pData = NULL;
protdata.cbData = 0;
// TODO: Actually, we should spawn a new worker thread and have it do the
// bind process, then when done, it could use Switch / Continue to
// pass data back to the apartment thread
if(m_pIProtSink)
{
m_pIProtSink->Switch( &protdata );
}
else
{
__MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
}
}
__HCP_FUNC_CLEANUP;
if(FAILED(hr))
{
(void)InnerReportResult( hr, 0, 0 );
}
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::Continue( /*[in]*/ PROTOCOLDATA *pStateInfo )
{
__HCP_FUNC_ENTRY("CHCPProtocol::Continue");
HRESULT hr;
if(m_fBypass)
{
__MPC_SET_ERROR_AND_EXIT(hr, m_ipiBypass->Continue( pStateInfo ));
}
// We're faking what it would be like to have a worker thread
// communicating with the apartment thread
// If we really did spawn off a worker thread, we should do the
// bind there, and just use Switch/Continue to echo UI data back
// to this thread
if(pStateInfo->dwState == 1)
{
__MPC_SET_ERROR_AND_EXIT(hr, DoBind());
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::Abort( /*[in]*/ HRESULT hrReason ,
/*[in]*/ DWORD dwOptions )
{
__HCP_FUNC_ENTRY("CHCPProtocol::Abort");
HRESULT hr = E_FAIL;
if(m_fBypass)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, m_ipiBypass->Abort( hrReason, dwOptions ));
}
// Stop our own internal download process
// TODO: If we call Abort too early on the Binding object,
// this won't abort the download. (Too early is OnStartBinding
// or before.) We won't bother checking, though, for clarity.
// TODO: Make sure we set m_pDownloader to NULL when the
// downloader object is destructed or finished.
if(m_pDownloader)
{
m_pDownloader->Abort();
}
if(SUCCEEDED(hrReason)) // Possibly Abort could get called with 0?
{
hrReason = E_ABORT;
}
// Notify Sink of abort
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportResult( hrReason, 0, 0 ));
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::Terminate( /*[in]*/ DWORD dwOptions )
{
__HCP_FUNC_ENTRY("CHCPProtocol::Terminate");
HRESULT hr;
if(m_fBypass)
{
(void)m_ipiBypass->Terminate( dwOptions );
}
hr = S_OK;
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::Suspend()
{
__HCP_FUNC_ENTRY("CHCPProtocol::Suspend");
if(m_fBypass)
{
(void)m_ipiBypass->Suspend();
}
__HCP_FUNC_EXIT(E_NOTIMPL);
}
STDMETHODIMP CHCPProtocol::Resume()
{
__HCP_FUNC_ENTRY("CHCPProtocol::Resume");
if(m_fBypass)
{
(void)m_ipiBypass->Resume();
}
__HCP_FUNC_EXIT(E_NOTIMPL);
}
// IInternetProtocol methods
STDMETHODIMP CHCPProtocol::Read( /*[in] */ void *pv ,
/*[in] */ ULONG cb ,
/*[out]*/ ULONG *pcbRead )
{
__HCP_FUNC_ENTRY("CHCPProtocol::Read");
HRESULT hr = S_OK;
DEBUG_AppendPerf( DEBUG_PERF_PROTOCOL_READ, L"CHCPProtocolRoot::Read : Enter %s %d", SAFEBSTR( m_bstrUrlComplete ), (int)cb );
if(m_fBypass)
{
__MPC_SET_ERROR_AND_EXIT(hr, m_ipiBypass->Read( pv, cb, pcbRead ));
}
if(m_pstrmRead == 0)
{
__MPC_SET_ERROR_AND_EXIT(hr, S_FALSE); // We've hit the end of the road, jack
}
// One might expect URLMON to Read only the amount of data that we specified we have.
// However, it actually reads in blocks and will go far beyond the data we have
// specified unless we slap it around a little.
// We must only return S_FALSE when we have hit the absolute end of the stream
// If we think there is more data coming down the wire, then we return E_PENDING
// here. Even if we return S_OK and no data, URLMON will still think we've hit
// the end of the stream.
// ASSERTION: End of data means we've received BSCF_LASTDATANOTIFICATION
__MPC_EXIT_IF_METHOD_FAILS(hr, m_pstrmRead->Read( pv, cb, pcbRead ));
if(hr == S_FALSE)
{
CloseCacheEntry( false );
__MPC_SET_ERROR_AND_EXIT(hr, S_FALSE); // We've hit the end of the road, jack
}
else if(*pcbRead == 0)
{
if(m_fDone)
{
CloseCacheEntry( false );
__MPC_SET_ERROR_AND_EXIT(hr, S_FALSE); // We've hit the end of the road, jack
}
else
{
__MPC_SET_ERROR_AND_EXIT(hr, E_PENDING);
}
}
else
{
WriteCacheEntry( pv, *pcbRead );
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::Seek( /*[in] */ LARGE_INTEGER dlibMove ,
/*[in] */ DWORD dwOrigin ,
/*[out]*/ ULARGE_INTEGER *plibNewPosition )
{
__HCP_FUNC_ENTRY("CHCPProtocol::Seek");
if(m_fBypass)
{
(void)m_ipiBypass->Seek( dlibMove, dwOrigin, plibNewPosition );
}
__HCP_FUNC_EXIT(E_NOTIMPL);
}
STDMETHODIMP CHCPProtocol::LockRequest( /*[in]*/ DWORD dwOptions )
{
__HCP_FUNC_ENTRY("CHCPProtocol::LockRequest");
if(m_fBypass)
{
(void)m_ipiBypass->LockRequest( dwOptions );
}
__HCP_FUNC_EXIT(S_OK);
}
STDMETHODIMP CHCPProtocol::UnlockRequest()
{
__HCP_FUNC_ENTRY("CHCPProtocol::UnlockRequest");
if(m_fBypass)
{
(void)m_ipiBypass->UnlockRequest();
}
//
// Release all the pointers to objects.
//
Shutdown();
__HCP_FUNC_EXIT(S_OK);
}
////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CHCPProtocol::QueryOption( DWORD dwOption, LPVOID pBuffer, DWORD *pcbBuf )
{
__HCP_FUNC_ENTRY( "CHCPProtocol::QueryOption" );
HRESULT hr;
if(dwOption == INTERNET_OPTION_REQUEST_FLAGS && *pcbBuf == sizeof(DWORD))
{
*((DWORD*)pBuffer) = INTERNET_REQFLAG_FROM_CACHE;
hr = S_OK;
}
else
{
hr = E_NOTIMPL;
}
__HCP_FUNC_EXIT(hr);
}
/////////////////////////////////////////////////////////////////////////////
bool CHCPProtocol::IsHCPRedirection( /*[in]*/ LPCWSTR szURL )
{
__HCP_FUNC_ENTRY("CHCPProtocol::IsHCPRedirection");
CComBSTR bstrURLCopy;
LPCWSTR szURLCopy = ::UnescapeFileName( bstrURLCopy, szURL ); if(!szURLCopy) return false;
// Check if hcp://system/ or hcp://help/
if ( !_wcsnicmp( szURLCopy, c_szSystem, wcslen(c_szSystem)) ||
!_wcsnicmp( szURLCopy, c_szHelp, wcslen(c_szHelp)) )
{
return false;
}
// Not hcp://system/ or hcp://help/, check if it's hcp://<vendor>/
bool bRedir = true;
for(int i=0; i<2; i++)
{
// Extract vendor name
LPCWSTR szVendor = szURLCopy + wcslen(c_szRoot);
LPCWSTR szVendorEnd = wcschr(szVendor, L'/');
int nVendorLen = szVendorEnd ? szVendorEnd - szVendor : wcslen(szVendor);
// Construct vendor dir
MPC::wstring strDir = i == 0 ? CHCPProtocolEnvironment::s_GLOBAL->System() : HC_HELPSET_ROOT;
strDir += c_szVendorDir;
MPC::SubstituteEnvVariables( strDir );
strDir.append(szVendor, nVendorLen);
if (MPC::FileSystemObject::IsDirectory(strDir.c_str()))
{
// Is a valid vendor dir, no redirection
bRedir = false;
break;
}
}
return bRedir;
}
/////////////////////////////////////////////////////////////////////////////
HRESULT CHCPProtocol::DoParse( /*[in]*/ LPCWSTR szURL )
{
__HCP_FUNC_ENTRY("CHCPProtocol::DoParse");
HRESULT hr;
CComBSTR bstrURLCopy;
LPCWSTR szURLCopy;
LPWSTR szQuery;
LPCWSTR szRedirect;
bool fHCP;
m_bstrUrlComplete = szURL;
m_bstrUrlRedirected = (LPCOLESTR)NULL;
fHCP = CHCPProtocolInfo::LookForHCP( szURL, m_fRedirected, szRedirect );
m_fRedirected = false; // redirection should never happen here
if(m_fRedirected)
{
m_bstrUrlRedirected = szRedirect;
}
else
{
const Lookup_Virtual_To_Real* ptr;
int i;
MPC::wstring strDir;
LPOLESTR szTmp;
szURLCopy = ::UnescapeFileName( bstrURLCopy, szURL ); if(!szURLCopy) __MPC_SET_ERROR_AND_EXIT(hr, E_OUTOFMEMORY);
//
// Remove the query part of the URL.
//
if(szQuery = wcschr( szURLCopy, L'?' ))
{
szQuery[0] = 0;
}
//
// Do the mapping between virtual paths and real ones.
//
for(ptr=c_lookup, i=0; i<ARRAYSIZE(c_lookup); i++, ptr++)
{
if(!_wcsnicmp( szURLCopy, ptr->szPrefix, ptr->iPrefix ))
{
if(ptr->fCSS)
{
m_bstrUrlRedirected = szURL;
m_fCSS = true;
break;
}
if(!ptr->szRealSubDir)
{
strDir = ptr->fRelocate ? CHCPProtocolEnvironment::s_GLOBAL->HelpLocation() : HC_HELPSVC_HELPFILES_DEFAULT;
strDir += L"\\";
}
else
{
strDir = ptr->fRelocate ? CHCPProtocolEnvironment::s_GLOBAL->System() : HC_HELPSET_ROOT;
strDir += ptr->szRealSubDir;
}
MPC::SubstituteEnvVariables( strDir );
m_bstrUrlRedirected = strDir.c_str();
m_bstrUrlRedirected += &szURLCopy[ ptr->iPrefix ];
//
// Convert the slashes to backslashes.
//
while((szTmp = wcschr( m_bstrUrlRedirected, L'/' ))) szTmp[0] = L'\\';
//
// Remove any trailing slash.
//
while((szTmp = wcsrchr( m_bstrUrlRedirected, L'/' )) && szTmp[1] == 0) szTmp[0] = 0;
while((szTmp = wcsrchr( m_bstrUrlRedirected, L'\\' )) && szTmp[1] == 0) szTmp[0] = 0;
CHCPProtocolEnvironment::s_GLOBAL->ReformatURL( m_bstrUrlRedirected );
if(ptr->fSkipIfMissing && MPC::FileSystemObject::IsFile( m_bstrUrlRedirected ) == false) continue;
break;
}
}
}
if(!m_bstrUrlRedirected) __MPC_SET_ERROR_AND_EXIT(hr, E_OUTOFMEMORY);
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::DoBind()
{
__HCP_FUNC_ENTRY("CHCPProtocol::DoBind");
HRESULT hr;
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportProgress( BINDSTATUS_FINDINGRESOURCE, SAFEBSTR( m_bstrUrlRedirected ) ));
if(m_fRedirected)
{
if(MPC::MSITS::IsCHM( SAFEBSTR( m_bstrUrlRedirected ) ))
{
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_Redirect_MSITS());
}
else
{
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_Redirect_UrlMoniker());
}
}
else if(m_fCSS)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_CSS());
}
else
{
MPC::wstring szPage = SAFEBSTR(m_bstrUrlRedirected);
MPC::FileSystemObject fso = szPage.c_str();
bool fFound;
bool fIsAFile;
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_Exists( fso, fFound, fIsAFile ));
if(fFound && fIsAFile)
{
//
// The file exists, so load its content.
//
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_File());
}
else
{
//
// The file, as is, doesn't exist, so try to find a .chm on the path.
//
while(1)
{
MPC::wstring szParent;
MPC::wstring szCHM;
__MPC_EXIT_IF_METHOD_FAILS(hr, fso.get_Parent( szParent ));
if(szParent.length() == 0)
{
//
// No parent, so exit with error.
//
__MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
}
//
// Point the FileSystemObject to its parent.
//
fso = szParent.c_str();
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_Exists( fso, fFound, fIsAFile ));
//
// Parent exists, so it cannot exist a .CHM file. Exit with error.
//
if(fFound)
{
__MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
}
//
// Add the .CHM extension and look for it.
//
szCHM = szParent; szCHM.append( L".chm" );
fso = szCHM.c_str();
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_Exists( fso, fFound, fIsAFile ));
//
// No .CHM file, recurse up to the root.
//
if(fFound == false)
{
continue;
}
//
// The .CHM is not a file, exit with error.
//
if(fIsAFile == false)
{
__MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
}
//
// Found, so redirect to the proper protocol.
//
szCHM = L"ms-its:";
szCHM.append( szParent );
szCHM.append( L".chm" );
if(szParent.length() < szPage.length())
{
LPWSTR szBuf = new WCHAR[szPage.length()+1];
if(szBuf)
{
LPWSTR szTmp;
StringCchCopyW( szBuf, szPage.length()+1, szPage.c_str() );
//
// Convert the backslashes to slashes.
//
while(szTmp = wcschr( szBuf, L'\\' )) szTmp[0] = L'/';
szCHM.append( L"::" );
szCHM.append( &szBuf[szParent.length()] );
delete [] szBuf;
}
}
m_bstrUrlRedirected = szCHM.c_str();
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_Redirect_MSITS());
break;
}
}
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::DoBind_Exists( /*[in] */ MPC::FileSystemObject& fso ,
/*[out]*/ bool& fFound ,
/*[out]*/ bool& fIsAFile )
{
__HCP_FUNC_ENTRY("CHCPProtocol::DoBind_Exists");
HRESULT hr;
if(fso.Exists())
{
fFound = true;
fIsAFile = fso.IsFile();
}
else
{
fFound = false;
fIsAFile = false;
}
hr = S_OK;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::DoBind_Redirect_UrlMoniker()
{
__HCP_FUNC_ENTRY("CHCPProtocol::DoBind_Redirect_UrlMoniker");
HRESULT hr;
//
// Create the stream used to receive downloaded data.
//
::CreateStreamOnHGlobal( NULL, TRUE, &m_pstrmWrite );
if(m_pstrmWrite == NULL)
{
__MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
}
//
// Create the downloader object.
//
if(SUCCEEDED(hr = m_pDownloader->CreateInstance( &m_pDownloader )))
{
m_pDownloader->AddRef();
if(FAILED(hr = m_pDownloader->StartAsyncDownload( this, m_bstrUrlRedirected, NULL, FALSE )))
{
if(hr != E_PENDING) __MPC_FUNC_LEAVE;
}
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::DoBind_Redirect_MSITS()
{
__HCP_FUNC_ENTRY("CHCPProtocol::DoBind_Redirect_MSITS");
HRESULT hr;
CComBSTR bstrStorageName;
CComBSTR bstrFilePath;
LPCWSTR szExt;
WCHAR rgMime[MAX_PATH];
if(MPC::MSITS::IsCHM( SAFEBSTR( m_bstrUrlRedirected ), &bstrStorageName, &bstrFilePath ) == false)
{
__MPC_SET_ERROR_AND_EXIT(hr, E_FAIL);
}
//
// Try to find the Mime Type for this file.
//
if((szExt = wcsrchr( bstrFilePath, L'.' )))
{
::GetMimeFromExt( szExt, rgMime, MAX_PATH-1 );
}
else
{
rgMime[0] = 0;
}
//
// Extract the file from the CHM.
//
__MPC_EXIT_IF_METHOD_FAILS(hr, MPC::MSITS::OpenAsStream( bstrStorageName, bstrFilePath, &m_pstrmRead ));
//
// Signal the Protocol Sink that data is available.
//
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_ReturnData( /*fCloneStream*/false, szExt ? rgMime : NULL ));
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::DoBind_CSS()
{
__HCP_FUNC_ENTRY("CHCPProtocol::DoBind_CSS");
HRESULT hr;
LPCWSTR szExt;
WCHAR rgMime[256];
//
// Try to find the Mime Type for this file.
//
if((szExt = wcsrchr( m_bstrUrlComplete, L'.' )))
{
::GetMimeFromExt( szExt, rgMime, 255 );
}
__MPC_EXIT_IF_METHOD_FAILS(hr, CHCPProtocolEnvironment::s_GLOBAL->GetCSS( m_pstrmRead ));
//
// Signal the Protocol Sink that data is available.
//
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_ReturnData( /*fCloneStream*/false, szExt ? rgMime : NULL ));
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::DoBind_File()
{
__HCP_FUNC_ENTRY("CHCPProtocol::DoBind_File");
HRESULT hr;
CComPtr<MPC::FileStream> pStm;
LPCWSTR szFile = m_bstrUrlRedirected;
LPCWSTR szExt = 0;
WCHAR rgMime[256];
//
// Try to find the Mime Type for this file.
//
{
WCHAR szFullPath[MAX_PATH + 1];
LPWSTR szFilePart;
// Get the canonical file name. (BUG 542663)
DWORD dwLen = ::GetFullPathNameW(szFile, MAX_PATH, szFullPath, &szFilePart);
if (dwLen != 0 && dwLen <= MAX_PATH)
{
// Succeed, parse the file part.
if((szExt = wcsrchr( szFilePart, L'.' )))
{
::GetMimeFromExt( szExt, rgMime, 255 );
}
}
}
//
// Create the file stream.
//
__MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pStm ));
__MPC_EXIT_IF_METHOD_FAILS(hr, pStm->InitForRead ( szFile ));
__MPC_EXIT_IF_METHOD_FAILS(hr, pStm->QueryInterface( IID_IStream, (void**)&m_pstrmRead ));
//
// Signal the Protocol Sink that data is available.
//
__MPC_EXIT_IF_METHOD_FAILS(hr, DoBind_ReturnData( /*fCloneStream*/false, szExt ? rgMime : NULL ));
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
HRESULT CHCPProtocol::DoBind_ReturnData( /*[in]*/ bool fCloneStream ,
/*[in]*/ LPCWSTR szMimeType )
{
__HCP_FUNC_ENTRY("CHCPProtocol::DoBind_ReturnData");
HRESULT hr;
STATSTG statstg;
m_fDone = true;
if(fCloneStream)
{
LARGE_INTEGER li;
//
// Clone the stream, so that we can hand it back to the ProtSink for data reading.
//
__MPC_EXIT_IF_METHOD_FAILS(hr, m_pstrmWrite->Clone( &m_pstrmRead ));
//
// Reset stream to beginning.
//
li.LowPart = 0;
li.HighPart = 0;
__MPC_EXIT_IF_METHOD_FAILS(hr, m_pstrmRead->Seek( li, STREAM_SEEK_SET, NULL ));
}
(void)m_pstrmRead->Stat( &statstg, STATFLAG_NONAME );
m_bstrMimeType = szMimeType;
m_dwContentLength = statstg.cbSize.LowPart;
//
// Create an entry in the cache, if required.
//
if(m_bindf & BINDF_NEEDFILE)
{
(void)OpenCacheEntry();
}
if(szMimeType)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportProgress( BINDSTATUS_MIMETYPEAVAILABLE, szMimeType ));
}
if(m_hCache)
{
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportProgress( BINDSTATUS_CACHEFILENAMEAVAILABLE, m_szCacheFileName ));
}
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportData( BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE,
statstg.cbSize.LowPart ,
statstg.cbSize.LowPart ));
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//
// Implementation of the ISimpleBindStatusCallback interface.
//
STDMETHODIMP CHCPProtocol::ForwardQueryInterface( /*[in] */ REFIID riid ,
/*[out]*/ void** ppv )
{
__HCP_FUNC_ENTRY("CHCPProtocol::ForwardQueryInterface");
HRESULT hr = E_NOINTERFACE;
*ppv = NULL;
if(IsEqualIID( riid, IID_IHttpNegotiate))
{
CComQIPtr<IServiceProvider> pProv;
pProv = m_pIProtSink;
if(pProv)
{
if(SUCCEEDED(pProv->QueryService( riid, riid, ppv )))
{
__MPC_SET_ERROR_AND_EXIT(hr, S_OK);
}
}
pProv = m_pIBindInfo;
if(pProv)
{
if(SUCCEEDED(pProv->QueryService( riid, riid, ppv )))
{
__MPC_SET_ERROR_AND_EXIT(hr, S_OK);
}
}
}
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::GetBindInfo( /*[out]*/ BINDINFO *pbindInfo )
{
__HCP_FUNC_ENTRY("CHCPProtocol::GetBindInfo");
HRESULT hr = ::CopyBindInfo( &m_bindinfo, pbindInfo );
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::PreBindMoniker( /*[in]*/ IBindCtx* pBindCtx ,
/*[in]*/ IMoniker* pMoniker )
{
__HCP_FUNC_ENTRY("CHCPProtocol::PreBindMoniker");
__HCP_FUNC_EXIT(S_OK);
}
STDMETHODIMP CHCPProtocol::OnProgress( /*[in]*/ ULONG ulProgress ,
/*[in]*/ ULONG ulProgressMax,
/*[in]*/ ULONG ulStatusCode ,
/*[in]*/ LPCWSTR szStatusText )
{
__HCP_FUNC_ENTRY("CHCPProtocol::OnProgress");
HRESULT hr;
switch(ulStatusCode)
{
case BINDSTATUS_BEGINDOWNLOADDATA:
// ulProgressMax represents the total size of the download
// When talking HTTP, this is determined by the CONTENT_LENGTH header
// If this header is missing or wrong, we're missing or wrong
m_cbTotalSize = ulProgressMax;
break;
case BINDSTATUS_MIMETYPEAVAILABLE :
case BINDSTATUS_FINDINGRESOURCE :
case BINDSTATUS_CONNECTING :
case BINDSTATUS_SENDINGREQUEST :
case BINDSTATUS_CACHEFILENAMEAVAILABLE:
case BINDSTATUS_REDIRECTING :
case BINDSTATUS_USINGCACHEDCOPY :
case BINDSTATUS_CLASSIDAVAILABLE :
case BINDSTATUS_LOADINGMIMEHANDLER :
// only pass on these notifications:
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportProgress( ulStatusCode, szStatusText ));
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::OnData( /*[in]*/ CHCPBindStatusCallback* pbsc ,
/*[in]*/ BYTE* pBytes ,
/*[in]*/ DWORD dwSize ,
/*[in]*/ DWORD grfBSCF ,
/*[in]*/ FORMATETC* pformatetc ,
/*[in]*/ STGMEDIUM* pstgmed )
{
__HCP_FUNC_ENTRY("CHCPProtocol::OnData");
HRESULT hr;
ULONG cbWritten;
//
// To handle an error, we just report result that we failed and terminate the download object
//
if(FAILED(hr = m_pstrmWrite->Write( pBytes, dwSize, &cbWritten )))
{
// Our own Abort handles this just nicely
Abort( hr, 0 ); __MPC_FUNC_LEAVE;
}
m_cbAvailableSize += cbWritten;
if(grfBSCF & BSCF_FIRSTDATANOTIFICATION)
{
LARGE_INTEGER li;
// We need two concurrent seek pointers to the same stream
// because we'll be writing to the stream at the end while
// we're trying to read from the beginning
__MPC_EXIT_IF_METHOD_FAILS(hr, m_pstrmWrite->Clone( &m_pstrmRead ));
// reset stream to beginning
li.LowPart = 0;
li.HighPart = 0;
__MPC_EXIT_IF_METHOD_FAILS(hr, m_pstrmRead->Seek( li, STREAM_SEEK_SET, NULL ));
}
// We've got all the data, signal complete
if(grfBSCF & BSCF_LASTDATANOTIFICATION)
{
// We need to remember if we've received LASTDATANOTIFICATION yet
m_fDone = true;
// We only need to do ReportResult if we fail somehow -
// DATAFULLYAVAILABLE is signal enough that we succeeded
// NOT NEEDED: m_pIProtSink->ReportResult(S_OK, 0, NULL);
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportData( BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE,
m_cbAvailableSize ,
m_cbAvailableSize ));
}
else
{
// Report our progress accurately using our byte count
// of what we've read versus the total known download size
// We know the total amount to read, the total read so far, and
// the total written. The problem is that we can't know the total
// amount that will be written in the end. So we estimate at
// 1.5 * Total size and if we overrun, we just start adding some
// extra to the end
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportData( grfBSCF, m_cbAvailableSize, m_cbTotalSize ));
}
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
STDMETHODIMP CHCPProtocol::OnBindingFailure( /*[in]*/ HRESULT hr ,
/*[in]*/ LPCWSTR szError )
{
__HCP_FUNC_ENTRY("CHCPProtocol::OnBindingFailure");
//
// Inform protocol-sink that we've failed to download the data for some reason.
//
__MPC_EXIT_IF_METHOD_FAILS(hr, InnerReportResult( hr, 0, szError ));
hr = S_OK;
__HCP_FUNC_CLEANUP;
__HCP_FUNC_EXIT(hr);
}
| [
"polarisdp@gmail.com"
] | polarisdp@gmail.com |
0c909049584ae76c3818caeb9f49afe3dc5c9a98 | cef4db2d526089a3800f3b03dab79731be8378d7 | /jianzhioffer_me/05_Replace_Black.cpp | 4b149cc0b4e8e85fd0a7ff33262558fa207840fa | [] | no_license | likohank/mianshiti_2018 | cf848679281a81fbdb7ecd5230fdb42b8605606d | 132467b9a90b069aa6d7e28b43622fef684215b7 | refs/heads/master | 2022-11-15T06:49:42.333912 | 2020-07-07T12:30:17 | 2020-07-07T12:30:17 | 277,810,441 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 863 | cpp | #include<cstdio>
#include<cstring>
void ReplaceBlack(char string[],int length)
{
if(string==nullptr || length<0)
return;
int originalLength = 0;
int numberOfBlack = 0;
int i = 0;
while(string[i]!='\0')
{
++originalLength;
if( string[i] == ' ')
++numberOfBlack;
++i;
}
int newLength = originalLength + numberOfBlack*2;
if (newLength>length)
return;
int indexOfOriginal = originalLength;
int indexOfNew = newLength;
while(indexOfOriginal>0 && indexOfNew>indexOfOriginal)
{
if (string[indexOfOriginal]!=' ')
{
string[indexOfNew--] = string[indexOfOriginal];
}
else
{
string[indexOfNew--] = 'C';
string[indexOfNew--] = '2';
string[indexOfNew--] = '%';
}
--indexOfOriginal;
}
}
int main()
{
char test[50] = {'\n'};
strcpy(test,"We are Family!");
ReplaceBlack(test,50);
printf("%s\n",test);
return 0;
}
| [
"likang216651@sogou-inc.com"
] | likang216651@sogou-inc.com |
6cdc6b836f0e3d0c506706eb13de0b31991a69e0 | c4b93130d58399380197db6a456e724947dfed4a | /sorting/03.insert.cpp | 8c8c18b44911384969123aa850f6947843f8a053 | [
"MIT"
] | permissive | chryoung/algorithm | ffa4ceb01f4e01f4a88aa61de8b8274ee3ac3f1f | 0dafc17a15fa08d7ffcde5cc8a947bd3892ac5b4 | refs/heads/master | 2020-11-29T20:45:20.916423 | 2017-07-19T03:05:04 | 2017-07-19T03:05:04 | 96,657,299 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,118 | cpp | #include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cstdlib>
template<typename T>
void InsertSort(std::vector<T>& vec)
{
int minIndex = 0;
// i stands for number of sorted elments.
for (int i = 0; i < vec.size() - 1; ++i) {
int j = i + 1;
for (int scanIndex = 0; scanIndex < j; ++scanIndex) {
if (vec[scanIndex] > vec[j]) {
T hold = vec[j];
int moveIndex = j;
for (; moveIndex > scanIndex; --moveIndex) {
vec[moveIndex] = vec[moveIndex - 1];
}
vec[moveIndex] = hold;
break;
}
}
}
}
template<typename T>
void PrintVec(const std::vector<T>& vec)
{
for (size_t i = 0; i < vec.size(); ++i) {
std::cout << vec[i] << " ";
}
std::cout << "\b\n";
}
int main (void)
{
using namespace std;
srand(time(0));
vector<int> testA;
for (int i = 0; i < 10; ++i) {
testA.push_back(rand() % 100);
}
PrintVec(testA);
InsertSort(testA);
PrintVec(testA);
}
| [
"cygitmail@gmail.com"
] | cygitmail@gmail.com |
b372ae6976fc49ef08735be3e3cf0af3b1326d19 | f2be44e105787f049d92338bb0eb2bd01b51cd8f | /graph.hpp | 37f36e78f9b47742f7f07841443f9663377931a1 | [] | no_license | bentherien/cppUtilities | 3c466aa120ac30d6d364abd4edf04b00953a67ab | 3206b0fd06af3debb75582eda6877fae6e258802 | refs/heads/master | 2020-04-09T01:07:33.912139 | 2019-09-24T02:16:20 | 2019-09-24T02:16:20 | 159,892,685 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 640 | hpp | #ifndef ArrayList_hpp
#define ArrayList_hpp
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
template<typename T > class graph
{
public:
graph();
~graph();
T graph_getElemetAtIndex(int index);
T graph_removeElementAtIndex(int index);
void graph_display();
inline T** graph_getMatrix();
inline int graph_getSize();
bool graph_edgeExists(int indexOne, int indexTwo);
void graph_addEdge(int indexOne, int indexTwo);
void graph_addNode(T element);
private:
int size, endIndex;
T** matrix;
};
#endif | [
"benjamintherien@yahoo.ca"
] | benjamintherien@yahoo.ca |
4cde35725c3a5d211a2b60ad073e5f4905ac2201 | 9875073000f7e81b08ff459831469d293c2800e0 | /CODEFORCES/R1_C.cpp | 3620228b56324160314fc9c0d74b005f4c9af797 | [] | no_license | Minato1803/Code_Competition | 47b31cf5eefbd38d4519b034f55f58ca700c05d4 | 21e893c8e9a457f095aa9fbbf8dd439a516cbc4d | refs/heads/master | 2023-02-17T04:52:31.070539 | 2021-01-20T11:41:30 | 2021-01-20T11:41:30 | 161,519,880 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 473 | cpp | #include <iostream>
using namespace std;
long long dem(string a, long long i)
{ long long c=0;
for(long long j=i;j<a.length();j++){
if(a[i]==a[j]){
c+=1;}
}
return ((c-1)*(c)/2);
}
bool kt(string a, long long i)
{
for(long long j=0;j<i;j++){
if(a[i]==a[j]){ return 0;}
}
return 1;
}
int main()
{
string a;
cin>>a;
long long count=0;
for(long long i=0;i<a.length();i++){
if(kt(a,i)==1){
count+=dem(a,i);
}
}
cout<<count;
return 0;
}
| [
"nguyenduckhai.otaku@gmail.com"
] | nguyenduckhai.otaku@gmail.com |
d246446b515eb192167a990df9e8abc9c73b4aa1 | 376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb | /wm/waimea/patches/patch-src_Window.cc | d31af5276d03168ca1ee7816c7c1ef415bbed045 | [] | no_license | NetBSD/pkgsrc | a0732c023519650ef821ab89c23ab6ab59e25bdb | d042034ec4896cc5b47ed6f2e5b8802d9bc5c556 | refs/heads/trunk | 2023-09-01T07:40:12.138283 | 2023-09-01T05:25:19 | 2023-09-01T05:25:19 | 88,439,572 | 321 | 138 | null | 2023-07-12T22:34:14 | 2017-04-16T20:04:15 | null | UTF-8 | C++ | false | false | 781 | cc | $NetBSD: patch-src_Window.cc,v 1.1 2011/12/21 13:02:10 wiz Exp $
Avoid conflict with list<>.
--- src/Window.cc.orig 2002-11-06 11:55:10.000000000 +0000
+++ src/Window.cc
@@ -280,13 +280,13 @@ list <WaAction *> *WaWindow::GetActionLi
if (classhint) {
if (classhint->res_name &&
(*it)->name->Match(classhint->res_name))
- return &((*it)->list);
+ return &((*it)->rlist);
else if (classhint->res_class &&
(*it)->cl->Match(classhint->res_class))
- return &((*it)->list);
+ return &((*it)->rlist);
}
if ((*it)->title->Match(name))
- return &((*it)->list);
+ return &((*it)->rlist);
}
return NULL;
}
| [
"wiz@pkgsrc.org"
] | wiz@pkgsrc.org |
ba9583f9540a56d60238d2fa7b61f13f65cdcac7 | b6607ecc11e389cc56ee4966293de9e2e0aca491 | /codeforces.com/Contests/281 div 2/E/E.cpp | 454ff0bf6a86c54c177e308c660bb9cf4d0c0d38 | [] | no_license | BekzhanKassenov/olymp | ec31cefee36d2afe40eeead5c2c516f9bf92e66d | e3013095a4f88fb614abb8ac9ba532c5e955a32e | refs/heads/master | 2022-09-21T10:07:10.232514 | 2021-11-01T16:40:24 | 2021-11-01T16:40:24 | 39,900,971 | 5 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,725 | cpp | /****************************************
** Solution by Bekzhan Kassenov **
****************************************/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2000 * 1000 * 1000;
template <typename T>
inline T sqr(T n) {
return n * n;
}
long long t, a, b;
long long ans;
bool check(long long n, long long a) {
while (n % a == 0) {
n /= a;
}
return n == 1;
}
vector <long long> convert(long long num, long long base) {
vector <long long> result;
while (num > 0) {
result.push_back(num % base);
num /= base;
}
return result;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
#endif
scanf("%I64d%I64d%I64d", &t, &a, &b);
if (t != 1) {
if (a == b) {
ans++;
}
if (a != 1 && convert(a, t) == convert(b, a)) {
ans++;
}
} else {
if (a == 1) {
if (b == 1) {
puts("inf");
return 0;
}
ans = 0;
} else {
vector <long long> temp(convert(b, a));
long long sum = 0;
for (size_t i = 0; i < temp.size(); i++) {
sum += temp[i];
}
if (sum == a) {
ans = 1;
}
if (b >= a && check(b, a)) {
ans++;
}
}
}
printf("%I64d\n", ans);
return 0;
}
| [
"bekzhan.kassenov@nu.edu.kz"
] | bekzhan.kassenov@nu.edu.kz |
8130ad4671111f091a25f8f9aa76f2a57bf511c2 | d6258ae3c0fd9f36efdd859a2c93ab489da2aa9b | /fulldocset/add/codesnippet/CPP/e6c3d0c9-aed2-4364-946f-_1.cpp | 0607b6dc63e7457ab0f2008e97a0928712c1cb33 | [
"CC-BY-4.0",
"MIT"
] | permissive | OpenLocalizationTestOrg/ECMA2YamlTestRepo2 | ca4d3821767bba558336b2ef2d2a40aa100d67f6 | 9a577bbd8ead778fd4723fbdbce691e69b3b14d4 | refs/heads/master | 2020-05-26T22:12:47.034527 | 2017-03-07T07:07:15 | 2017-03-07T07:07:15 | 82,508,764 | 1 | 0 | null | 2017-02-28T02:14:26 | 2017-02-20T02:36:59 | Visual Basic | UTF-8 | C++ | false | false | 693 | cpp | private:
void SetBlendTriangularShapeExample( PaintEventArgs^ e )
{
// Create a LinearGradientBrush.
Rectangle myRect = Rectangle(20,20,200,100);
LinearGradientBrush^ myLGBrush = gcnew LinearGradientBrush( myRect,Color::Blue,Color::Red,0.0f,true );
// Draw an ellipse to the screen using the LinearGradientBrush.
e->Graphics->FillEllipse( myLGBrush, myRect );
// Create a triangular shaped brush with the peak at the center
// of the drawing area.
myLGBrush->SetBlendTriangularShape( .5f, 1.0f );
// Use the triangular brush to draw a second ellipse.
myRect.Y = 150;
e->Graphics->FillEllipse( myLGBrush, myRect );
} | [
"tianzh@microsoft.com"
] | tianzh@microsoft.com |
3255a0dd5cee263af8a90d6670937696a4faa215 | 47ff8543c73dab22c7854d9571dfc8d5f467ee8c | /BOJ/3425/3425.cpp | 58915bcbc9864f7a3c2f87ab0b8559ebc2d1bcdd | [] | no_license | eldsg/BOJ | 4bb0c93dc60783da151e685530fa9a511df3a141 | 6bd15e36d69ce1fcf208d193d5e9067de9bb405e | refs/heads/master | 2020-04-16T02:18:55.808362 | 2017-11-28T11:02:37 | 2017-11-28T11:02:37 | 55,879,791 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,416 | cpp | #include <bits/stdc++.h>
using namespace std;
#define MAX 1000000000
vector<pair<int, int> > a;
stack<int> aa;
int proc(int b){
bool error;
long long k, kk;
aa.push(b);
int size = a.size();
for(int i = 0; i < size; i++){
error = false;
//printf("%d\n", aa.top());
switch(a[i].first){
case 0:
if(abs(a[i].second) > MAX) error = true;
else aa.push(a[i].second);
break;
case 1:
if(aa.empty()) error = true;
else aa.pop();
break;
case 2:
if(aa.empty()) error = true;
else{
k = aa.top();
aa.pop();
aa.push(-k);
}
break;
case 3:
if(aa.empty()) error = true;
else{
k = aa.top();
aa.push(k);
}
break;
case 4:
if(aa.size() < 2) error = true;
else{
k = aa.top();
aa.pop();
kk = aa.top();
aa.pop();
aa.push(k);
aa.push(kk);
}
break;
case 5:
if(aa.size() < 2) error = true;
else{
k = aa.top();
aa.pop();
kk = aa.top();
aa.pop();
if(abs(k+kk) > MAX) error = true;
else aa.push(k+kk);
}
break;
case 6:
if(aa.size() < 2) error = true;
else{
k = aa.top();
aa.pop();
kk = aa.top();
aa.pop();
if(abs(kk-k) > MAX) error = true;
else aa.push(kk-k);
}
break;
case 7:
if(aa.size() < 2) error = true;
else{
k = aa.top();
aa.pop();
kk = aa.top();
aa.pop();
long long tmp = k*kk;
if(abs(tmp) > MAX) error = true;
else aa.push(tmp);
}
break;
case 8:
if(aa.size() < 2) error = true;
else{
k = aa.top();
aa.pop();
kk = aa.top();
aa.pop();
if(k == 0) error = true;
else{
aa.push(kk/k);
}
}
break;
case 9:
if(aa.size() < 2) error = true;
else{
k = aa.top();
aa.pop();
kk = aa.top();
aa.pop();
if(k == 0) error = true;
else{
aa.push(kk%k);
}
}
break;
}
if(error) return -1;
}
if(aa.size() == 1) return 0;
else return -1;
}
//0 1 2 3 4 5 6 7 8 9
//num x, pop, inv, dup, swp, add, sub, mul, div, mod
int main(){
char s[10];
int k, kk;
while(1){
scanf("%s", s);
//printf("%s\n", s);
if(s[0] == 'Q' && s[1] == 'U') break;
else if(s[0] == 'E' && s[1] == 'N'){
scanf(" %d", &k);
/*
for(int i = 0; i < a.size(); i++){
printf("%d %d\n", a[i].first, a[i].second);
}
*/
for(int i = 0; i < k; i++){
scanf(" %d", &kk);
int ret = proc(kk);
if(ret == -1) printf("ERROR\n");
else if(ret == 0) printf("%d\n", aa.top());
while(!aa.empty()){
aa.pop();
}
}
printf("\n");
a.clear();
}
else{
if(s[0] == 'N' && s[1] == 'U'){
scanf(" %d", &k);
a.push_back({0, k});
}
else if(s[0] == 'P' && s[1] == 'O'){
a.push_back({1, -1});
}
else if(s[0] == 'I' && s[1] == 'N'){
a.push_back({2, -1});
}
else if(s[0] == 'D' && s[1] == 'U'){
a.push_back({3, -1});
}
else if(s[0] == 'S' && s[1] == 'W'){
a.push_back({4, -1});
}
else if(s[0] == 'A' && s[1] == 'D'){
a.push_back({5, -1});
}
else if(s[0] == 'S' && s[1] == 'U'){
a.push_back({6, -1});
}
else if(s[0] == 'M' && s[1] == 'U'){
a.push_back({7, -1});
}
else if(s[0] == 'D' && s[1] == 'I'){
a.push_back({8, -1});
}
else if(s[0] == 'M' && s[1] == 'O'){
a.push_back({9, -1});
}
}
}
} | [
"kgm0219@gmail.com"
] | kgm0219@gmail.com |
429156beb1d83a43b68858b2f95f2b2a4f7b0669 | c6152183b744b01d161fb0f1e4ab1dd19cb6d5b0 | /src/meta.hpp | 4c8c1832fd4feb267a6f8f01fe03e0bb640b0db1 | [] | no_license | spito/dp | d006610f1ab6a3dbfdfb797545bccafbf5306e08 | 81ab9c007e4654b7af331ebd034c54c71bf58cc9 | refs/heads/master | 2021-01-10T03:41:26.969018 | 2016-02-15T20:59:12 | 2016-02-15T20:59:12 | 44,930,829 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 916 | hpp | #include <string>
#include <vector>
#include <brick-net.h>
#ifndef META_H
#define META_H
enum class Command {
Start,
Status,
Shutdown,
ForceShutdown,
ForceReset,
Restart,
Daemon,
Run,
};
enum class Algorithm {
None,
LoadShared,
LoadDedicated,
LongLoadShared,
LongLoadDedicated,
PingShared,
PingDedicated,
LongPingShared,
LongPingDedicated,
Table,
};
using MetaBlock = std::pair< std::unique_ptr< char[] >, size_t >;
struct Meta {
Command command;
Algorithm algorithm;
int threads;
int workLoad;
int selection;
bool detach;
std::string port;
std::string logFile;
std::vector< std::string > hosts;
Meta( int, char **, bool = false );
Meta( char *, size_t );
MetaBlock block() const;
private:
void hostFile( char * );
};
#endif
| [
"jiri.weiser@gmail.com"
] | jiri.weiser@gmail.com |
51b506263ffeac3a289ee70000adb47d23bd31d4 | c4e93e5e88b9a38fb1b5e4a398810c9e165df80f | /jobs/source/JobExecutionsChangedSubscriptionRequest.cpp | 02a886d9f5321ab4e9055407668d24f398b885de | [
"Apache-2.0"
] | permissive | aws/aws-iot-device-sdk-cpp-v2 | c7c441024e19a24d3ebf4cc9f05c2ed15a4c2b89 | 1ddf4ab749155abe195acab9f9505791a93b9b45 | refs/heads/main | 2023-09-03T15:05:45.057875 | 2023-09-01T20:33:54 | 2023-09-01T20:33:54 | 157,451,948 | 148 | 108 | Apache-2.0 | 2023-09-01T20:33:56 | 2018-11-13T21:51:08 | C++ | UTF-8 | C++ | false | false | 1,121 | cpp | /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*
* This file is generated
*/
#include <aws/iotjobs/JobExecutionsChangedSubscriptionRequest.h>
namespace Aws
{
namespace Iotjobs
{
void JobExecutionsChangedSubscriptionRequest::LoadFromObject(
JobExecutionsChangedSubscriptionRequest &val,
const Aws::Crt::JsonView &doc)
{
(void)val;
(void)doc;
}
void JobExecutionsChangedSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const
{
(void)object;
}
JobExecutionsChangedSubscriptionRequest::JobExecutionsChangedSubscriptionRequest(const Crt::JsonView &doc)
{
LoadFromObject(*this, doc);
}
JobExecutionsChangedSubscriptionRequest &JobExecutionsChangedSubscriptionRequest::operator=(
const Crt::JsonView &doc)
{
*this = JobExecutionsChangedSubscriptionRequest(doc);
return *this;
}
} // namespace Iotjobs
} // namespace Aws
| [
"noreply@github.com"
] | noreply@github.com |
49fdaeb72b3ec6623a664b2140cfd71e626e25c2 | 9d33e09e74975a05e0ce82e5eb3fe5a191419944 | /src/net/Acceptor.h | ce3aa7a500b5713f6a6bfe9e754d83bd5506c7b6 | [
"MIT"
] | permissive | lineCode/Dalin | 7c897cc602b2a2c310c9e180add962bdada1fe3a | 7be1601403f7f2233848b160cf284f9f6b8ba643 | refs/heads/master | 2021-01-22T00:51:31.486733 | 2017-09-02T08:16:18 | 2017-09-02T08:16:18 | 102,194,548 | 1 | 2 | null | 2017-09-02T12:20:03 | 2017-09-02T12:20:03 | null | UTF-8 | C++ | false | false | 829 | h | //
// Acceptor.h
//
// Copyright (c) 2017 Jiawei Feng
//
#ifndef ACCEPTOR_H
#define ACCEPTOR_H
#include "Socket.h"
#include "Channel.h"
namespace Dalin {
namespace Net {
class EventLoop;
class InetAddress;
// Acceptor of incoming TCP connections.
class Acceptor : Noncopyable {
public:
typedef std::function<void (int sockfd, const InetAddress&)> NewConnectionCallback;
Acceptor(EventLoop *loop, const InetAddress &listenAddr);
void setNewConnectionCallback(const NewConnectionCallback &cb)
{
newConnectionCallback_ = cb;
}
bool listenning() const { return listenning_; }
void listen();
private:
void handleRead();
EventLoop *loop_;
Socket acceptSocket_;
Channel acceptChannel_;
NewConnectionCallback newConnectionCallback_;
bool listenning_;
};
}
}
#endif
| [
"leohotfn@gmail.com"
] | leohotfn@gmail.com |
f07b939a1528dc3a8a4cb189af30716490c8cd69 | c68c88d8bcaf91806a5326e12c79fddd8ad26a8b | /Results/client/src/core.h | 912e799cb9f58f904035248dfcc8fffff40fb8ed | [] | no_license | dilin993/MultiCameraPeopleTrackingSystem1-0-UDP | d5138c9e21a570b7f5f70a3c41f73920fff974ac | c481eedf218b982070ccf75719c1e0b574559c3c | refs/heads/master | 2021-09-04T19:16:22.767868 | 2018-01-21T16:15:58 | 2018-01-21T16:15:58 | 111,350,368 | 1 | 1 | null | 2018-01-15T12:55:49 | 2017-11-20T02:06:02 | C++ | UTF-8 | C++ | false | false | 634 | h | #include <iostream>
#include <cmath>
#include <cfloat>
#include <string.h>
using namespace std;
#define WIDTH 320
#define HEIGHT 240
#define IMG_SIZE WIDTH*HEIGHT
#define K 2 // no of gaussian mxitures
#define BGM_SIZE IMG_SIZE*K
#define PARTS 120
typedef float data_t;
//typedef ap_fixed<32,16> data_t;
void bgsub(uint8_t frame_in[IMG_SIZE],
uint8_t frame_out[IMG_SIZE],
bool init,
data_t bgmodel[4*BGM_SIZE]);
void process(uint8_t frame_in[IMG_SIZE/PARTS],
uint8_t frame_out[IMG_SIZE/PARTS],
float bgmodel[4*BGM_SIZE/PARTS],
const data_t learningRate);
| [
"dilin.dampahalage@gmail.com"
] | dilin.dampahalage@gmail.com |
2a4311e7a3cecc7d368223d5cebfa07c32cb810c | 6fb925b90ccfe8ce4565b1a87d34ca197c2780f8 | /src/ofApp.h | 3888c3abc876f5d7ee4850d11c695eb74793c86d | [] | no_license | Yaciner/kinect-interactive-target-game | a624713b6b0c93151a92bbcc0fc9665f0b8b28a8 | 4b5583fa55cfae8803973d0b287ddf51c70fbf4b | refs/heads/master | 2021-09-03T10:14:46.922313 | 2018-01-08T09:46:49 | 2018-01-08T09:46:49 | 112,448,574 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,179 | h | #pragma once
#include "ofMain.h"
#include "ofxKinect.h"
#include "ofxXmlSettings.h"
#include "ofxGui.h"
#include <vector>
//#include "ofxSocketIO.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void startTimer(int currentLevel);
void doStuff();
void startVideo();
/* - methods - */
void drawPointCloud();
void saveState();
void loadState();
/* - global variables - */
float targetSize, xPos, yPos;
int numPointsInRegion, scaleFactorHoop;
bool showmsg = false;
bool debugMode = true;
bool roundStarted = false;
void onConnection();
string food[15] = {"brocolli", "burger", "ei", "fruitmand", "garnaal", "hotdog", "ijs", "kers", "kip", "koekjes", "pizza", "popcorn", "snoep", "steak", "zalm"};
/* - instances - */
// ofxSocketIO socketIO;
ofxKinect kinect;
ofEasyCam easyCam;
ofMesh pointCloud;
// ofSoundPlayer scoreSound;
void bindEvents();
void resetScreen();
void gotEvent(std::string& name);
ofxPanel gui;
ofxXmlSettings state;
ofxFloatSlider kinectDistanceSlider;
ofxFloatSlider kinectZSlider;
ofxFloatSlider kinectAngleSlider;
ofxFloatSlider kinectSphereZSlider;
ofxLabel statusLabel;
ofxLabel hostNameLabel;
ofxButton savebtn;
ofxButton loadbtn;
bool isConnected;
ofImage img;
int imageWidth;
int imageHeight;
ofTexture texture;
std::string status;
ofSoundPlayer yay_sound, oh_sound, soundtrack_sound;
ofVideoPlayer bg_anim;
ofVideoPlayer brocolli_anim, pizza_anim, burger_anim, ei_anim, fruitmand_anim, garnaal_anim, hotdog_anim, ijs_anim, kers_anim, kip_anim, koekjes_anim, popcorn_anim, snoep_anim, steak_anim, zalm_anim;
ofVideoPlayer start_anim, end_anim;
//ofxLabel scoreLabel;
ofTrueTypeFont font;
//ofRectangle timerRectangle;
float startTime;
bool timerEnd;
};
| [
"redjalay@gmail.com"
] | redjalay@gmail.com |
1b36c9e7ba1c4968ab94a6cb9679a1ee6e26f7e8 | 31f394c1b90ca58d7ef2285d838e76aac8c1cce7 | /maze/main.cpp | d0c345229c1bcbca0d01452009674bbf03b4bead | [] | no_license | cchanzl/Misc-exercises | cd248667c15534b242b688a4c83c9bae3350ae1f | a85e996db93691ddbe25c31b341810ef9e5a29cb | refs/heads/master | 2023-02-17T23:05:44.765136 | 2021-01-11T13:03:35 | 2021-01-11T13:03:35 | 324,282,143 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,662 | cpp | #include <iostream>
#include <cassert>
#include "maze.h"
using namespace std;
int main() {
/* this section illustrates the use of the pre-supplied functions */
cout << "============== Pre-supplied functions ==================" << endl << endl;
char **maze;
int height, width;
cout << "Loading simple maze...";
/* loads the maze from the file "simple.txt" and sets height and width */
maze = load_maze("simple.txt", height, width);
assert(maze);
cout << " done (height = " << height << ", width = " << width << ")." << endl << endl;
cout << "Printing simple maze:" << endl;
/* prints the maze with row and column numbers */
print_maze(maze,height,width);
cout << endl;
cout << "====================== Question 1 ======================" << endl << endl;
int row = 0, column = 0;
cout << "Finding the entrance:" << endl;
find_marker('>', maze, height, width, row, column);
cout << "The entrance is at row " << row << " column " << column << endl << endl;
cout << "Finding the exit:" << endl;
find_marker('X', maze, height, width, row, column);
cout << "The exit is at row " << row << " column " << column << endl << endl;
cout << "====================== Question 2 ======================" << endl << endl;
cout << "The move sequence 'EEEEESEENN' is ";
if (!valid_solution("EEEEESEENN", maze, height, width))
cout << "NOT ";
cout << "a solution to the maze" << endl << endl;
cout << "The move sequence 'EEEEEEEESSSSSS' is ";
if (!valid_solution("EEEEEEEESSSSSS", maze, height, width))
cout << "NOT ";
cout << "a solution to the maze" << endl << endl;
cout << "The move sequence 'ESSSSSSEEEEEEE' is ";
if (!valid_solution("ESSSSSSEEEEEEE", maze, height, width))
cout << "NOT ";
cout << "a solution to the maze" << endl << endl;
cout << "====================== Question 3 ======================" << endl << endl;
// an easy example with a known solution
cout << "A path through the maze from '>' to 'X' is: " << endl;
cout << find_path(maze, height, width, '>', 'X') << endl << endl;
cout << "The path is shown below: " << endl;
print_maze(maze, height, width);
cout << endl;
deallocate_2D_array(maze, height);
// an impossible example - should return "no solution"
maze = load_maze("simple.txt", height, width);
assert(maze);
cout << "A path through the maze from '>' to 'U' is: " << endl;
cout << find_path(maze, height, width, '>', 'U') << endl << endl;
deallocate_2D_array(maze, height);
cout << "=================== Bonus Question =====================" << endl << endl;
/*
// find the path from the entrance to the middle of the Hatfield House maze
maze = load_maze("hatfield.txt", height, width);
assert(maze);
cout << "And now the Hatfield House maze:" << endl;
print_maze(maze, height, width);
cout << endl;
cout << "A path through the maze from '>' to 'M' is: " << endl;
cout << find_path(maze, height, width, '>', 'M') << endl << endl;
cout << "The path is shown below: " << endl;
print_maze(maze, height, width);
cout << endl;
deallocate_2D_array(maze, height);
*/
// find the path from the middle to the exit of the Hatfield House maze
maze = load_maze("hatfield.txt", height, width);
assert(maze);
cout << "A path through the maze from 'M' to 'X' is: " << endl;
cout << find_path(maze, height, width, 'M', 'X') << endl << endl;
cout << "The path is shown below: " << endl;
print_maze(maze, height, width);
cout << endl;
deallocate_2D_array(maze, height);
cout << "======================= The End ========================" << endl << endl;
return 0;
}
| [
"zc620@sprite22.doc.ic.ac.uk"
] | zc620@sprite22.doc.ic.ac.uk |
c66bc1d099e8a1561086079cce9bfb912eb85703 | 5ede0e0fd1668416fc74fc5a3c997547b7708abc | /include/converters.hpp | 2d6835df9d974c19bd3ef98cb13a4603815c7c25 | [] | no_license | ethanfine/ia | d1f8671177cacb4bc351d5257e65c8cc05e6732d | 134ff030939fc3286545d7f58cc20cbfbc5547fa | refs/heads/develop | 2020-04-06T05:09:13.466507 | 2015-12-08T19:19:16 | 2015-12-08T19:19:16 | 47,472,684 | 0 | 0 | null | 2015-12-05T21:05:43 | 2015-12-05T21:05:42 | null | UTF-8 | C++ | false | false | 397 | hpp | #ifndef CONVERTERS_H
#define CONVERTERS_H
#include <string>
//TODO "Converters" seems like a weird file separation - this should be put in the utils file...
std::string to_str(const int IN);
int to_int(const std::string& in);
//Intended for enum class Values, to retrieve the underlying type (e.g. int)
template <typename T>
typename std::underlying_type<T>::type to_underlying(T t);
#endif
| [
"m.tornq@gmail.com"
] | m.tornq@gmail.com |
30b741ee4fdbc5c57f56268b68260d9e8b043e11 | 641fa8341d8c436ad24945bcbf8e7d7d1dd7dbb2 | /content/browser/media/session/audio_focus_delegate_default.cc | b1ae90f503ff1e4c494ddb01554849ec926ad240 | [
"BSD-3-Clause"
] | permissive | massnetwork/mass-browser | 7de0dfc541cbac00ffa7308541394bac1e945b76 | 67526da9358734698c067b7775be491423884339 | refs/heads/master | 2022-12-07T09:01:31.027715 | 2017-01-19T14:29:18 | 2017-01-19T14:29:18 | 73,799,690 | 4 | 4 | BSD-3-Clause | 2022-11-26T11:53:23 | 2016-11-15T09:49:29 | null | UTF-8 | C++ | false | false | 2,057 | cc | // Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/media/session/audio_focus_delegate.h"
#include "base/command_line.h"
#include "content/browser/media/session/audio_focus_manager.h"
#include "media/base/media_switches.h"
namespace content {
using AudioFocusType = AudioFocusManager::AudioFocusType;
namespace {
// AudioFocusDelegateDefault is the default implementation of
// AudioFocusDelegate which only handles audio focus between WebContents.
class AudioFocusDelegateDefault : public AudioFocusDelegate {
public:
explicit AudioFocusDelegateDefault(MediaSessionImpl* media_session);
~AudioFocusDelegateDefault() override;
// AudioFocusDelegate implementation.
bool RequestAudioFocus(
AudioFocusManager::AudioFocusType audio_focus_type) override;
void AbandonAudioFocus() override;
private:
// Weak pointer because |this| is owned by |media_session_|.
MediaSessionImpl* media_session_;
};
} // anonymous namespace
AudioFocusDelegateDefault::AudioFocusDelegateDefault(
MediaSessionImpl* media_session)
: media_session_(media_session) {}
AudioFocusDelegateDefault::~AudioFocusDelegateDefault() = default;
bool AudioFocusDelegateDefault::RequestAudioFocus(
AudioFocusManager::AudioFocusType audio_focus_type) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableDefaultMediaSession)) {
return true;
}
AudioFocusManager::GetInstance()->RequestAudioFocus(media_session_,
audio_focus_type);
return true;
}
void AudioFocusDelegateDefault::AbandonAudioFocus() {
AudioFocusManager::GetInstance()->AbandonAudioFocus(media_session_);
}
// static
std::unique_ptr<AudioFocusDelegate> AudioFocusDelegate::Create(
MediaSessionImpl* media_session) {
return std::unique_ptr<AudioFocusDelegate>(
new AudioFocusDelegateDefault(media_session));
}
} // namespace content
| [
"xElvis89x@gmail.com"
] | xElvis89x@gmail.com |
c24bf94b70660b90d885d1b6c589e793f87362d8 | e6ae6070d3053ca1e4ff958c719a8cf5dfcd6b9b | /del_v1.cpp | 441670ace286ed8aec50139a1251a6692aa9c476 | [] | no_license | Arti14/Competitive-Programming | 31d246d34581599219ffb7e23a3372f02fc6dfa6 | de42977b6cce39bb480d3cf90c1781d806be3b56 | refs/heads/master | 2021-01-25T07:34:29.240567 | 2015-05-08T07:07:10 | 2015-05-08T07:07:10 | 35,263,950 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,681 | cpp | #include<iostream>
#include<conio.h>
using namespace std;
struct tree
{int data;
tree *left;
tree *right;
};
tree *mainroot;
void insert(tree *root, int val)
{
if(mainroot ==NULL)
{
tree *n1= new tree;
n1->data = val;
n1->left=n1->right=NULL;
mainroot=n1;
}
else if(val<=root->data)
{
if(root->left==NULL)
{
tree *n1= new tree;
n1->data = val;
n1->left=n1->right=NULL;
root->left=n1;
}
else
{
insert(root->left,val);
}
}
else
{
if(root->right==NULL)
{
tree *n1=new tree;
n1->data=val;
n1->left=n1->right=NULL;
root->right=n1;
}
else
{
insert(root->right,val);
}
}
}
void inorder(tree *root)
{
if(root==NULL)
{
return;
}
inorder(root->left );
cout<<root->data<<endl;
inorder(root->right);
}
int lar_bst(tree *n)
{
n=n->left;
while(n->right!=NULL)
{
n=n->right;
}
return n->data;
}
void deletion(tree *root, int del)
{
if(root==NULL)
{
cout<<"key not found";
}
else if(root->data==del)
{
if(root->left==NULL&&root->right==NULL)
{
root=NULL;
delete root;
}
else if(root->left==NULL)
{
tree *temp =new tree ;
temp=root;
root=root->right;
temp=NULL;
delete temp;
}
else if(root->right==NULL)
{
tree *temp =new tree ;
temp=root;
root=root->left;
temp=NULL;
delete temp;
}
else
{
int largest;
largest=lar_bst(root);
root->data=largest;
deletion(root->left,largest);
}
}
else if(root->data>del)
{
if(root->left->data==del)
{
tree *temp = new tree ;
temp=root;
root=root->left;
if(root->left==NULL&&root->right==NULL)
{
root=NULL;
delete root;
}
else if(root->left==NULL)
{
temp->left=root->right;
root=NULL;
delete root;
}
else if(root->right==NULL)
{
temp->left=root->left;
root=NULL;
delete root;
}
else
{
int largest;
largest=lar_bst(root);
root->data=largest;
deletion(root->left,largest);
}
}
else deletion(root->left,del);
}
else
{
if(root->right->data==del)
{
tree *temp =new tree ;
temp=root;
root=root->right;
if(root->left==NULL&&root->right==NULL)
{
root=NULL;
delete root;
}
else if(root->left==NULL)
{
temp->left=root->right;
root=NULL;
delete root;
}
else if(root->right==NULL)
{
temp->left=root->left;
root=NULL;
delete root;
}
else
{
int largest;
largest=lar_bst(root);
root->data=largest;
deletion(root->left,largest);
}
}
else deletion(root->right,del);
}
}
int main()
{
mainroot=NULL;
int n;
int val;
int del;
cout<<"enter how many nodes u want in the tree"<<endl;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>val;
insert(mainroot,val);
}
cout<<"inorder traversal"<<endl;
inorder(mainroot);
cout<<"enter which node you want to delete"<<endl;
cin>>del;
deletion(mainroot,del);
cout<<"inorder traversal after deletion is "<<endl;
inorder(mainroot);
system("pause");
return 0;
}
| [
"rt@rt-VGN-CS14G-B.(none)"
] | rt@rt-VGN-CS14G-B.(none) |
775540d25ac7bf0596114f77bb4b20cb4d3b5af7 | 349fe789ab1e4e46aae6812cf60ada9423c0b632 | /Interface/IDMSprNomImage.h | 435d1894837ded14e22ea5e79e9ac6cfbd0ddb8a | [] | no_license | presscad/ERP | a6acdaeb97b3a53f776677c3a585ca860d4de980 | 18ecc6c8664ed7fc3f01397d587cce91fc3ac78b | refs/heads/master | 2020-08-22T05:24:15.449666 | 2019-07-12T12:59:13 | 2019-07-12T12:59:13 | 216,326,440 | 1 | 0 | null | 2019-10-20T07:52:26 | 2019-10-20T07:52:26 | null | UTF-8 | C++ | false | false | 7,789 | h | #ifndef UIDMSprNomImageH
#define UIDMSprNomImageH
#include "IMainInterface.h"
#include "UGlobalConstant.h"
#include "FIBDatabase.hpp"
#include "FIBDataSet.hpp"
#include "FIBQuery.hpp"
#include "pFIBDatabase.hpp"
#include "pFIBDataSet.hpp"
#include "pFIBQuery.hpp"
#include <Classes.hpp>
class __declspec(uuid(Global_IID_IDMSprNomImage)) IDMSprNomImage : public IMainInterface
{
public:
__property TDataSource * DataSourceTable = {read = get_DataSourceTable , write = set_DataSourceTable};
virtual TDataSource * get_DataSourceTable(void)=0;
virtual void set_DataSourceTable(TDataSource * DataSourceTable)=0;
__property TDataSource * DataSourceElement = {read = get_DataSourceElement , write = set_DataSourceElement};
virtual TDataSource * get_DataSourceElement(void)=0;
virtual void set_DataSourceElement(TDataSource * DataSourceElement)=0;
__property TpFIBDataSet * Table = {read = get_Table , write = set_Table};
virtual TpFIBDataSet * get_Table(void)=0;
virtual void set_Table(TpFIBDataSet * Table)=0;
__property TpFIBDataSet * Element = {read = get_Element , write = set_Element};
virtual TpFIBDataSet * get_Element(void)=0;
virtual void set_Element(TpFIBDataSet * Element)=0;
__property TpFIBTransaction * IBTr = {read = get_IBTr , write = set_IBTr};
virtual TpFIBTransaction * get_IBTr(void)=0;
virtual void set_IBTr(TpFIBTransaction * IBTr)=0;
__property TpFIBTransaction * IBTrUpdate = {read = get_IBTrUpdate , write = set_IBTrUpdate};
virtual TpFIBTransaction * get_IBTrUpdate(void)=0;
virtual void set_IBTrUpdate(TpFIBTransaction * IBTrUpdate)=0;
__property TFIBLargeIntField * TableID_SNOMIMAGE = {read = get_TableID_SNOMIMAGE , write = set_TableID_SNOMIMAGE};
virtual TFIBLargeIntField * get_TableID_SNOMIMAGE(void)=0;
virtual void set_TableID_SNOMIMAGE(TFIBLargeIntField * TableID_SNOMIMAGE)=0;
__property TFIBLargeIntField * TableIDBASE_SNOMIMAGE = {read = get_TableIDBASE_SNOMIMAGE , write = set_TableIDBASE_SNOMIMAGE};
virtual TFIBLargeIntField * get_TableIDBASE_SNOMIMAGE(void)=0;
virtual void set_TableIDBASE_SNOMIMAGE(TFIBLargeIntField * TableIDBASE_SNOMIMAGE)=0;
__property TFIBWideStringField * TableGID_SNOMIMAGE = {read = get_TableGID_SNOMIMAGE , write = set_TableGID_SNOMIMAGE};
virtual TFIBWideStringField * get_TableGID_SNOMIMAGE(void)=0;
virtual void set_TableGID_SNOMIMAGE(TFIBWideStringField * TableGID_SNOMIMAGE)=0;
__property TFIBLargeIntField * TableIDVIDIMAGE_SNOMIMAGE = {read = get_TableIDVIDIMAGE_SNOMIMAGE , write = set_TableIDVIDIMAGE_SNOMIMAGE};
virtual TFIBLargeIntField * get_TableIDVIDIMAGE_SNOMIMAGE(void)=0;
virtual void set_TableIDVIDIMAGE_SNOMIMAGE(TFIBLargeIntField * TableIDVIDIMAGE_SNOMIMAGE)=0;
__property TFIBLargeIntField * TableIDNOM_SNOMIMAGE = {read = get_TableIDNOM_SNOMIMAGE , write = set_TableIDNOM_SNOMIMAGE};
virtual TFIBLargeIntField * get_TableIDNOM_SNOMIMAGE(void)=0;
virtual void set_TableIDNOM_SNOMIMAGE(TFIBLargeIntField * TableIDNOM_SNOMIMAGE)=0;
__property TFIBWideStringField * TableNAME_SNOMIMAGE = {read = get_TableNAME_SNOMIMAGE , write = set_TableNAME_SNOMIMAGE};
virtual TFIBWideStringField * get_TableNAME_SNOMIMAGE(void)=0;
virtual void set_TableNAME_SNOMIMAGE(TFIBWideStringField * TableNAME_SNOMIMAGE)=0;
__property TFIBBlobField * TableBODY_SNOMIMAGE = {read = get_TableBODY_SNOMIMAGE , write = set_TableBODY_SNOMIMAGE};
virtual TFIBBlobField * get_TableBODY_SNOMIMAGE(void)=0;
virtual void set_TableBODY_SNOMIMAGE(TFIBBlobField * TableBODY_SNOMIMAGE)=0;
__property TFIBBlobField * TableBODY_SMALL_SNOMIMAGE = {read = get_TableBODY_SMALL_SNOMIMAGE , write = set_TableBODY_SMALL_SNOMIMAGE};
virtual TFIBBlobField * get_TableBODY_SMALL_SNOMIMAGE(void)=0;
virtual void set_TableBODY_SMALL_SNOMIMAGE(TFIBBlobField * TableBODY_SMALL_SNOMIMAGE)=0;
__property TFIBLargeIntField * ElementID_SNOMIMAGE = {read = get_ElementID_SNOMIMAGE , write = set_ElementID_SNOMIMAGE};
virtual TFIBLargeIntField * get_ElementID_SNOMIMAGE(void)=0;
virtual void set_ElementID_SNOMIMAGE(TFIBLargeIntField * ElementID_SNOMIMAGE)=0;
__property TFIBLargeIntField * ElementIDBASE_SNOMIMAGE = {read = get_ElementIDBASE_SNOMIMAGE , write = set_ElementIDBASE_SNOMIMAGE};
virtual TFIBLargeIntField * get_ElementIDBASE_SNOMIMAGE(void)=0;
virtual void set_ElementIDBASE_SNOMIMAGE(TFIBLargeIntField * ElementIDBASE_SNOMIMAGE)=0;
__property TFIBWideStringField * ElementGID_SNOMIMAGE = {read = get_ElementGID_SNOMIMAGE , write = set_ElementGID_SNOMIMAGE};
virtual TFIBWideStringField * get_ElementGID_SNOMIMAGE(void)=0;
virtual void set_ElementGID_SNOMIMAGE(TFIBWideStringField * ElementGID_SNOMIMAGE)=0;
__property TFIBLargeIntField * ElementIDVIDIMAGE_SNOMIMAGE = {read = get_ElementIDVIDIMAGE_SNOMIMAGE , write = set_ElementIDVIDIMAGE_SNOMIMAGE};
virtual TFIBLargeIntField * get_ElementIDVIDIMAGE_SNOMIMAGE(void)=0;
virtual void set_ElementIDVIDIMAGE_SNOMIMAGE(TFIBLargeIntField * ElementIDVIDIMAGE_SNOMIMAGE)=0;
__property TFIBLargeIntField * ElementIDNOM_SNOMIMAGE = {read = get_ElementIDNOM_SNOMIMAGE , write = set_ElementIDNOM_SNOMIMAGE};
virtual TFIBLargeIntField * get_ElementIDNOM_SNOMIMAGE(void)=0;
virtual void set_ElementIDNOM_SNOMIMAGE(TFIBLargeIntField * ElementIDNOM_SNOMIMAGE)=0;
__property TFIBWideStringField * ElementNAME_SNOMIMAGE = {read = get_ElementNAME_SNOMIMAGE , write = set_ElementNAME_SNOMIMAGE};
virtual TFIBWideStringField * get_ElementNAME_SNOMIMAGE(void)=0;
virtual void set_ElementNAME_SNOMIMAGE(TFIBWideStringField * ElementNAME_SNOMIMAGE)=0;
__property TFIBBlobField * ElementBODY_SNOMIMAGE = {read = get_ElementBODY_SNOMIMAGE , write = set_ElementBODY_SNOMIMAGE};
virtual TFIBBlobField * get_ElementBODY_SNOMIMAGE(void)=0;
virtual void set_ElementBODY_SNOMIMAGE(TFIBBlobField * ElementBODY_SNOMIMAGE)=0;
__property TFIBBlobField * ElementBODY_SMALL_SNOMIMAGE = {read = get_ElementBODY_SMALL_SNOMIMAGE , write = set_ElementBODY_SMALL_SNOMIMAGE};
virtual TFIBBlobField * get_ElementBODY_SMALL_SNOMIMAGE(void)=0;
virtual void set_ElementBODY_SMALL_SNOMIMAGE(TFIBBlobField * ElementBODY_SMALL_SNOMIMAGE)=0;
__property TFIBWideStringField * TableNAME_SVIDIMAGE = {read = get_TableNAME_SVIDIMAGE , write = set_TableNAME_SVIDIMAGE};
virtual TFIBWideStringField * get_TableNAME_SVIDIMAGE(void)=0;
virtual void set_TableNAME_SVIDIMAGE(TFIBWideStringField * TableNAME_SVIDIMAGE)=0;
__property TFIBWideStringField * ElementNAME_SVIDIMAGE = {read = get_ElementNAME_SVIDIMAGE , write = set_ElementNAME_SVIDIMAGE};
virtual TFIBWideStringField * get_ElementNAME_SVIDIMAGE(void)=0;
virtual void set_ElementNAME_SVIDIMAGE(TFIBWideStringField * ElementNAME_SVIDIMAGE)=0;
__property TFIBIntegerField * TableINDEX_SNOMIMAGE = {read = get_TableINDEX_SNOMIMAGE , write = set_TableINDEX_SNOMIMAGE};
virtual TFIBIntegerField * get_TableINDEX_SNOMIMAGE(void)=0;
virtual void set_TableINDEX_SNOMIMAGE(TFIBIntegerField * TableINDEX_SNOMIMAGE)=0;
__property TFIBIntegerField * ElementINDEX_SNOMIMAGE = {read = get_ElementINDEX_SNOMIMAGE , write = set_ElementINDEX_SNOMIMAGE};
virtual TFIBIntegerField * get_ElementINDEX_SNOMIMAGE(void)=0;
virtual void set_ElementINDEX_SNOMIMAGE(TFIBIntegerField * ElementINDEX_SNOMIMAGE)=0;
__property __int64 IdElement = {read = get_IdElement , write = set_IdElement};
virtual __int64 get_IdElement(void)=0;
virtual void set_IdElement(__int64 IdElement)=0;
virtual void OpenTable(__int64 id_nom)=0;
virtual int OpenElement(__int64 id )=0;
virtual bool NewElement(__int64 id_nom)=0;
virtual bool SaveElement(void)=0;
virtual bool DeleteElement(__int64 id)=0;
};
#define IID_IDMSprNomImage __uuidof(IDMSprNomImage)
#endif
| [
"sasha@kaserv.ru"
] | sasha@kaserv.ru |
cb4c1cfc1d76eeac6af822fb590d1483991b90e4 | cb68eec0d3e4a4dd2a02bdf9eb7f62468a2704d4 | /Variables/main.cpp | 1479dd2a07f949f2c3bbf098f83ccd30f31f114e | [] | no_license | zomawia/IntroToCPP | 3533317d0c8fc4b902c525f08591d85b1587bac4 | a2004e9ae99b5714832fd6ce3ba4387b00b11994 | refs/heads/master | 2020-04-18T10:27:03.285531 | 2017-01-31T23:48:49 | 2017-01-31T23:48:49 | 66,312,234 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 218 | cpp | #include <iostream>
int main()
{
printf("Hello World! \n");
//std::cout << std::endl;
float valueOneD;
valueOneD = ((20+1)/2-2.0)/(23+3)*0.2;
std::cout << "d: " << valueOneD << std::endl;
getchar();
}
| [
"zomawai.sailo@SEA-1A7525"
] | zomawai.sailo@SEA-1A7525 |
82b17ab3f02d6027f90ec992363f0d79142c11cc | 5832f65747e6142d1b8de9d46aa507092782aafc | /timus/1756.cpp | 45a2b054b6f696adc3b47900c71ff0b7c8b28fd3 | [] | no_license | subhashreddykallam/Competitive-Programming | 64cc42c5b23c03536187a1bb54e2b2ed82ee7844 | 973b66b4eb81352b98409ca52fa3aa75c28d8b6f | refs/heads/master | 2022-05-28T21:07:43.012922 | 2020-05-05T20:34:20 | 2020-05-05T20:34:20 | 226,814,369 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 454 | cpp | # include<bits/stdc++.h>
# include<unordered_map>
# include<unordered_set>
//# include<prettyprint.hpp>
using namespace std;
# define ll long long
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll m, d1, d2; cin >> m >> d1 >> d2;
ll total = (m*d1)/d2;
ll rem = (m*d1)%d2;
vector<ll> ans(d2, total);
for(ll i = 0; i < rem; i++) ans[i]++;
for(auto i:ans) cout << i << " ";
cout << endl;
return 0;
} | [
"42376739+Storm1seven@users.noreply.github.com"
] | 42376739+Storm1seven@users.noreply.github.com |
84fa95d4548f9d041631fd5816ea73dee1433edd | ff4c468d81a593b55a3ab11832c50d37d7f99c79 | /src/rpcmining.cpp | bd1c4dd6c720c684b6323bddfe71537d470835ad | [
"MIT"
] | permissive | ipteam/ipcoin | 2106e07fb26a053c37d6d760cc8fcbcab9f2b646 | 0aec46ece6ef68721fa952ab0970c938966e2d70 | refs/heads/master | 2020-06-04T12:41:47.354530 | 2014-07-24T13:57:06 | 2014-07-24T13:57:06 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 19,453 | cpp | // Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "main.h"
#include "db.h"
#include "txdb.h"
#include "init.h"
#include "miner.h"
#include "bitcoinrpc.h"
using namespace json_spirit;
using namespace std;
extern unsigned int nTargetSpacing;
Value getsubsidy(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"getsubsidy [nTarget]\n"
"Returns proof-of-work subsidy value for the specified value of target.");
unsigned int nBits = 0;
if (params.size() != 0)
{
CBigNum bnTarget(uint256(params[0].get_str()));
nBits = bnTarget.GetCompact();
}
else
{
nBits = GetNextTargetRequired(pindexBest, false);
}
return (uint64_t)GetProofOfWorkReward(0);
}
Value getmininginfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getmininginfo\n"
"Returns an object containing mining-related information.");
uint64_t nMinWeight = 0, nMaxWeight = 0, nWeight = 0;
pwalletMain->GetStakeWeight(*pwalletMain, nMinWeight, nMaxWeight, nWeight);
Object obj, diff, weight;
obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx));
diff.push_back(Pair("proof-of-work", GetDifficulty()));
diff.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true))));
diff.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval));
obj.push_back(Pair("difficulty", diff));
obj.push_back(Pair("blockvalue", (uint64_t)GetProofOfWorkReward(0)));
obj.push_back(Pair("netmhashps", GetPoWMHashPS()));
obj.push_back(Pair("netstakeweight", GetPoSKernelPS()));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
weight.push_back(Pair("minimum", (uint64_t)nMinWeight));
weight.push_back(Pair("maximum", (uint64_t)nMaxWeight));
weight.push_back(Pair("combined", (uint64_t)nWeight));
obj.push_back(Pair("stakeweight", weight));
obj.push_back(Pair("stakeinterest", (uint64_t)COIN_YEAR_REWARD));
obj.push_back(Pair("testnet", fTestNet));
return obj;
}
Value getstakinginfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getstakinginfo\n"
"Returns an object containing staking-related information.");
uint64_t nMinWeight = 0, nMaxWeight = 0, nWeight = 0;
pwalletMain->GetStakeWeight(*pwalletMain, nMinWeight, nMaxWeight, nWeight);
uint64_t nNetworkWeight = GetPoSKernelPS();
bool staking = nLastCoinStakeSearchInterval && nWeight;
int nExpectedTime = staking ? (nTargetSpacing * nNetworkWeight / nWeight) : -1;
Object obj;
obj.push_back(Pair("enabled", GetBoolArg("-staking", true)));
obj.push_back(Pair("staking", staking));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
obj.push_back(Pair("difficulty", GetDifficulty(GetLastBlockIndex(pindexBest, true))));
obj.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval));
obj.push_back(Pair("weight", (uint64_t)nWeight));
obj.push_back(Pair("netstakeweight", (uint64_t)nNetworkWeight));
obj.push_back(Pair("expectedtime", nExpectedTime));
return obj;
}
Value getworkex(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)
throw runtime_error(
"getworkex [data, coinbase]\n"
"If [data, coinbase] is not specified, returns extended work data.\n"
);
if (vNodes.empty())
throw JSONRPCError(-9, "IPcoin is not connected!");
if (IsInitialBlockDownload())
throw JSONRPCError(-10, "IPcoin is downloading blocks...");
if (pindexBest->nHeight >= LAST_POW_BLOCK)
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
static mapNewBlock_t mapNewBlock;
static vector<CBlock*> vNewBlock;
static CReserveKey reservekey(pwalletMain);
if (params.size() == 0)
{
// Update block
static unsigned int nTransactionsUpdatedLast;
static CBlockIndex* pindexPrev;
static int64_t nStart;
static CBlock* pblock;
if (pindexPrev != pindexBest ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
{
if (pindexPrev != pindexBest)
{
// Deallocate old blocks since they're obsolete now
mapNewBlock.clear();
BOOST_FOREACH(CBlock* pblock, vNewBlock)
delete pblock;
vNewBlock.clear();
}
nTransactionsUpdatedLast = nTransactionsUpdated;
pindexPrev = pindexBest;
nStart = GetTime();
// Create new block
pblock = CreateNewBlock(pwalletMain);
if (!pblock)
throw JSONRPCError(-7, "Out of memory");
vNewBlock.push_back(pblock);
}
// Update nTime
pblock->nTime = max(pindexPrev->GetPastTimeLimit()+1, GetAdjustedTime());
pblock->nNonce = 0;
// Update nExtraNonce
static unsigned int nExtraNonce = 0;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
// Save
mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig);
// Prebuild hash buffers
char pmidstate[32];
char pdata[128];
char phash1[64];
FormatHashBuffers(pblock, pmidstate, pdata, phash1);
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
CTransaction coinbaseTx = pblock->vtx[0];
std::vector<uint256> merkle = pblock->GetMerkleBranch(0);
Object result;
result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata))));
result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget))));
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << coinbaseTx;
result.push_back(Pair("coinbase", HexStr(ssTx.begin(), ssTx.end())));
Array merkle_arr;
BOOST_FOREACH(uint256 merkleh, merkle) {
merkle_arr.push_back(HexStr(BEGIN(merkleh), END(merkleh)));
}
result.push_back(Pair("merkle", merkle_arr));
return result;
}
else
{
// Parse parameters
vector<unsigned char> vchData = ParseHex(params[0].get_str());
vector<unsigned char> coinbase;
if(params.size() == 2)
coinbase = ParseHex(params[1].get_str());
if (vchData.size() != 128)
throw JSONRPCError(-8, "Invalid parameter");
CBlock* pdata = (CBlock*)&vchData[0];
// Byte reverse
for (int i = 0; i < 128/4; i++)
((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]);
// Get saved block
if (!mapNewBlock.count(pdata->hashMerkleRoot))
return false;
CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first;
pblock->nTime = pdata->nTime;
pblock->nNonce = pdata->nNonce;
if(coinbase.size() == 0)
pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
else
CDataStream(coinbase, SER_NETWORK, PROTOCOL_VERSION) >> pblock->vtx[0]; // FIXME - HACK!
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
return CheckWork(pblock, *pwalletMain, reservekey);
}
}
Value getwork(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"getwork [data]\n"
"If [data] is not specified, returns formatted hash data to work on:\n"
" \"midstate\" : precomputed hash state after hashing the first half of the data (DEPRECATED)\n" // deprecated
" \"data\" : block data\n"
" \"hash1\" : formatted hash buffer for second hash (DEPRECATED)\n" // deprecated
" \"target\" : little endian hash target\n"
"If [data] is specified, tries to solve the block and returns true if it was successful.");
if (vNodes.empty())
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "IPcoin is not connected!");
if (IsInitialBlockDownload())
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "IPcoin is downloading blocks...");
if (pindexBest->nHeight >= LAST_POW_BLOCK)
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
static mapNewBlock_t mapNewBlock; // FIXME: thread safety
static vector<CBlock*> vNewBlock;
static CReserveKey reservekey(pwalletMain);
if (params.size() == 0)
{
// Update block
static unsigned int nTransactionsUpdatedLast;
static CBlockIndex* pindexPrev;
static int64_t nStart;
static CBlock* pblock;
if (pindexPrev != pindexBest ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
{
if (pindexPrev != pindexBest)
{
// Deallocate old blocks since they're obsolete now
mapNewBlock.clear();
BOOST_FOREACH(CBlock* pblock, vNewBlock)
delete pblock;
vNewBlock.clear();
}
// Clear pindexPrev so future getworks make a new block, despite any failures from here on
pindexPrev = NULL;
// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = nTransactionsUpdated;
CBlockIndex* pindexPrevNew = pindexBest;
nStart = GetTime();
// Create new block
pblock = CreateNewBlock(pwalletMain);
if (!pblock)
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
vNewBlock.push_back(pblock);
// Need to update only after we know CreateNewBlock succeeded
pindexPrev = pindexPrevNew;
}
// Update nTime
pblock->UpdateTime(pindexPrev);
pblock->nNonce = 0;
// Update nExtraNonce
static unsigned int nExtraNonce = 0;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
// Save
mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig);
// Pre-build hash buffers
char pmidstate[32];
char pdata[128];
char phash1[64];
FormatHashBuffers(pblock, pmidstate, pdata, phash1);
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
Object result;
result.push_back(Pair("midstate", HexStr(BEGIN(pmidstate), END(pmidstate)))); // deprecated
result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata))));
result.push_back(Pair("hash1", HexStr(BEGIN(phash1), END(phash1)))); // deprecated
result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget))));
return result;
}
else
{
// Parse parameters
vector<unsigned char> vchData = ParseHex(params[0].get_str());
if (vchData.size() != 128)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
CBlock* pdata = (CBlock*)&vchData[0];
// Byte reverse
for (int i = 0; i < 128/4; i++)
((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]);
// Get saved block
if (!mapNewBlock.count(pdata->hashMerkleRoot))
return false;
CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first;
pblock->nTime = pdata->nTime;
pblock->nNonce = pdata->nNonce;
pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
return CheckWork(pblock, *pwalletMain, reservekey);
}
}
Value getblocktemplate(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"getblocktemplate [params]\n"
"Returns data needed to construct a block to work on:\n"
" \"version\" : block version\n"
" \"previousblockhash\" : hash of current highest block\n"
" \"transactions\" : contents of non-coinbase transactions that should be included in the next block\n"
" \"coinbaseaux\" : data that should be included in coinbase\n"
" \"coinbasevalue\" : maximum allowable input to coinbase transaction, including the generation award and transaction fees\n"
" \"target\" : hash target\n"
" \"mintime\" : minimum timestamp appropriate for next block\n"
" \"curtime\" : current timestamp\n"
" \"mutable\" : list of ways the block template may be changed\n"
" \"noncerange\" : range of valid nonces\n"
" \"sigoplimit\" : limit of sigops in blocks\n"
" \"sizelimit\" : limit of block size\n"
" \"bits\" : compressed target of next block\n"
" \"height\" : height of the next block\n"
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.");
std::string strMode = "template";
if (params.size() > 0)
{
const Object& oparam = params[0].get_obj();
const Value& modeval = find_value(oparam, "mode");
if (modeval.type() == str_type)
strMode = modeval.get_str();
else if (modeval.type() == null_type)
{
/* Do nothing */
}
else
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
}
if (strMode != "template")
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
if (vNodes.empty())
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "IPcoin is not connected!");
if (IsInitialBlockDownload())
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "IPcoin is downloading blocks...");
if (pindexBest->nHeight >= LAST_POW_BLOCK)
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
static CReserveKey reservekey(pwalletMain);
// Update block
static unsigned int nTransactionsUpdatedLast;
static CBlockIndex* pindexPrev;
static int64_t nStart;
static CBlock* pblock;
if (pindexPrev != pindexBest ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
{
// Clear pindexPrev so future calls make a new block, despite any failures from here on
pindexPrev = NULL;
// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = nTransactionsUpdated;
CBlockIndex* pindexPrevNew = pindexBest;
nStart = GetTime();
// Create new block
if(pblock)
{
delete pblock;
pblock = NULL;
}
pblock = CreateNewBlock(pwalletMain);
if (!pblock)
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
// Need to update only after we know CreateNewBlock succeeded
pindexPrev = pindexPrevNew;
}
// Update nTime
pblock->UpdateTime(pindexPrev);
pblock->nNonce = 0;
Array transactions;
map<uint256, int64_t> setTxIndex;
int i = 0;
CTxDB txdb("r");
BOOST_FOREACH (CTransaction& tx, pblock->vtx)
{
uint256 txHash = tx.GetHash();
setTxIndex[txHash] = i++;
if (tx.IsCoinBase() || tx.IsCoinStake())
continue;
Object entry;
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << tx;
entry.push_back(Pair("data", HexStr(ssTx.begin(), ssTx.end())));
entry.push_back(Pair("hash", txHash.GetHex()));
MapPrevTx mapInputs;
map<uint256, CTxIndex> mapUnused;
bool fInvalid = false;
if (tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
{
entry.push_back(Pair("fee", (int64_t)(tx.GetValueIn(mapInputs) - tx.GetValueOut())));
Array deps;
BOOST_FOREACH (MapPrevTx::value_type& inp, mapInputs)
{
if (setTxIndex.count(inp.first))
deps.push_back(setTxIndex[inp.first]);
}
entry.push_back(Pair("depends", deps));
int64_t nSigOps = tx.GetLegacySigOpCount();
nSigOps += tx.GetP2SHSigOpCount(mapInputs);
entry.push_back(Pair("sigops", nSigOps));
}
transactions.push_back(entry);
}
Object aux;
aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
static Array aMutable;
if (aMutable.empty())
{
aMutable.push_back("time");
aMutable.push_back("transactions");
aMutable.push_back("prevblock");
}
Object result;
result.push_back(Pair("version", pblock->nVersion));
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
result.push_back(Pair("transactions", transactions));
result.push_back(Pair("coinbaseaux", aux));
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
result.push_back(Pair("target", hashTarget.GetHex()));
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetPastTimeLimit()+1));
result.push_back(Pair("mutable", aMutable));
result.push_back(Pair("noncerange", "00000000ffffffff"));
result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
result.push_back(Pair("curtime", (int64_t)pblock->nTime));
result.push_back(Pair("bits", HexBits(pblock->nBits)));
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
return result;
}
Value submitblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"submitblock <hex data> [optional-params-obj]\n"
"[optional-params-obj] parameter is currently ignored.\n"
"Attempts to submit new block to network.\n"
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.");
vector<unsigned char> blockData(ParseHex(params[0].get_str()));
CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
CBlock block;
try {
ssBlock >> block;
}
catch (std::exception &e) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
}
bool fAccepted = ProcessBlock(NULL, &block);
if (!fAccepted)
return "rejected";
return Value::null;
}
| [
"ipcoindev@gmail.com"
] | ipcoindev@gmail.com |
1806a1ccbf680a3baba5056c1899446446a30a13 | d70ade0b8f6d5b6195b5f999f20589b4a6290183 | /Void1.cpp | e2a3d000dd4c321db97cf594f29146fbd6e4499a | [] | no_license | slumey2/Slumey2 | c082a33734db253fca1a42a6ebd80f498b8c829b | 6b1cf883a08560772370da867c82367446b75178 | refs/heads/master | 2021-01-22T12:02:33.367840 | 2014-05-24T10:02:24 | 2014-05-24T10:02:24 | 20,125,248 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 197 | cpp | #include <stdio.h>
int main(){
int i;
for (i = 0; i < 10; i++){
printf("Hello World\n");
}
<<<<<<< HEAD
return 0;
=======
return 0;
>>>>>>> f38c57acceb2604c0955a2dd34081183435d2696
}
| [
"slumey2_ty@yahoo.co.jp"
] | slumey2_ty@yahoo.co.jp |
ed92cfa9a923d839770afb435eae63a1973ce99a | eb175fc1ce65bc157d1ccf150bb331e895d6a6ad | /engine_openGL/source/parserz/geometry_parser.hpp | c279832cd29353e4988eeb6a58c3c9184a2bd54f | [] | no_license | zeplaz/razerz | e49f912838447e7032abfad0e2c6dcc8e23fa16b | 5198443f0dbbd1bf7676a579c17cd6ab830ab87a | refs/heads/master | 2021-09-15T15:41:09.700114 | 2021-08-25T18:41:42 | 2021-08-25T18:41:42 | 247,567,023 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,561 | hpp | #pragma once
#include "parserlib.hpp"
struct mesh_vertex
{
glm::vec3 v_position;
glm::vec3 v_normal;
glm::vec2 v_textcord;
glm::vec4 v_tangent;
bool operator<(const mesh_vertex that) const{
return memcmp((void*)this, (void*)&that, sizeof(mesh_vertex))>0;}
friend std::ostream & operator << (std::ostream &out, const mesh_vertex &c);
};
typedef struct parsed_paket_type
{
std::vector<glm::vec3> vertices;
std::vector<glm::vec3> normals;
std::vector<glm::vec2> uvs;
parsed_paket_type(std::vector<glm::vec3> in_vertices,
std::vector<glm::vec3> in_normals,
std::vector<glm::vec2> in_uvs)
{
std::vector<glm::vec3> vertices =in_vertices;
std::vector<glm::vec3> normals =in_normals;
std::vector<glm::vec2> uvs =in_uvs;
}
}parsed_paket;
class wavefornt_parser2
{
private :
std::vector<unsigned int> vertexIndices, uvIndices, normalIndices;
public :
void cleanup_paket(parsed_paket* in_pak)
{
in_pak->vertices.clear();
in_pak->uvs.clear();
in_pak->normals.clear();
delete in_pak;
}
parsed_paket* gen_parse_parket(std::vector < glm::vec3 > & in_vertices,
std::vector < glm::vec3 > & in_normals,
std::vector < glm::vec2 > & in_uvs)
{
parsed_paket* temp_pak = new parsed_paket(in_vertices,in_normals,in_uvs);
return temp_pak;
}
std::pair<std::shared_ptr<std::vector<mesh_vertex>>,std::shared_ptr<std::vector<unsigned int>>> read_file(std::string path)
{
std::vector< glm::vec3 > temp_vertices;
std::vector< glm::vec2 > temp_uvs;
std::vector< glm::vec3 > temp_normals;
std::shared_ptr<std::vector<mesh_vertex>> mesh_v_prt = std::make_shared<std::vector<mesh_vertex>>();
FILE* file = fopen(path.c_str(),"r");
if(file == NULL)
{
printf("failto openfile \n");
fclose(file);
return std::make_pair(nullptr,nullptr);
}
else
{
while(1)
{
char line_header[255];
int res = fscanf(file,"%s",line_header);
if(res == EOF)
break;
if(strcmp(line_header, "v") ==0)
{
glm::vec3 vertex;
fscanf(file,"%f %f %f\n", &vertex.x, &vertex.y, &vertex.z );
temp_vertices.push_back(vertex);
}
else if( strcmp( line_header, "vt" ) == 0 )
{
glm::vec2 uv;
fscanf(file, "%f %f\n", &uv.x, &uv.y );
temp_uvs.push_back(uv);
}
else if ( strcmp( line_header, "vn" ) == 0 )
{
glm::vec3 normal;
fscanf(file, "%f %f %f\n", &normal.x, &normal.y, &normal.z );
temp_normals.push_back(normal);
}
else if ( strcmp( line_header, "f" ) == 0 )
{
std::string vertex1, vertex2, vertex3;
unsigned int vertexIndex[3], uvIndex[3], normalIndex[3];
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2] );
if (matches != 9)
{
printf("File can't be read by our simple parser : ( Try exporting with other options\n");
return std::make_pair(nullptr,nullptr);
}
vertexIndices.push_back(vertexIndex[0]);
vertexIndices.push_back(vertexIndex[1]);
vertexIndices.push_back(vertexIndex[2]);
uvIndices.push_back(uvIndex[0]);
uvIndices.push_back(uvIndex[1]);
uvIndices.push_back(uvIndex[2]);
normalIndices.push_back(normalIndex[0]);
normalIndices.push_back(normalIndex[1]);
normalIndices.push_back(normalIndex[2]);
}
}
fclose(file);
for(unsigned int i=0; i< vertexIndices.size();i++)
{
mesh_vertex t_mv;
unsigned int vertexIndex_current = vertexIndices[i];
unsigned int IndicesIndex_current = uvIndices[i];
unsigned int normalIndex_current = normalIndices[i];
glm::vec3 vertex = temp_vertices[ vertexIndex_current-1 ];
glm::vec3 normz = temp_normals[normalIndex_current-1];
glm::vec2 uvz = temp_uvs[IndicesIndex_current-1];
t_mv.v_position =vertex;
t_mv.v_normal =normz;
t_mv.v_textcord = uvz;
mesh_v_prt->push_back(t_mv);
}
}
std::shared_ptr<std::vector<unsigned int>> mesh_v_indices = std::make_shared<std::vector<unsigned int>>(vertexIndices);
std::pair<std::shared_ptr<std::vector<mesh_vertex>>,std::shared_ptr<std::vector<unsigned int>>> vertex_pair_data = make_pair(mesh_v_prt,mesh_v_indices);
return vertex_pair_data;
}
};
| [
"life.in.the.vivid.dream@gmail.com"
] | life.in.the.vivid.dream@gmail.com |
ec03e2aeea622ea76e199018147ad3fd63a7bbd6 | 866d50fef896ec6bdc4c0883af487cb2cd54a934 | /PrestoClient.cpp | 95ee396eb4c9dd921c4300338c6438c17fe79781 | [] | no_license | trieck/presto-odbc | 26e7af904003fd6e0226d9f9ac992601d4ee087f | 77337efc42c6a68cb89ed7b0d91b69032ba2a13b | refs/heads/master | 2016-09-16T00:06:34.587488 | 2015-05-18T01:42:57 | 2015-05-18T01:42:57 | 34,946,059 | 1 | 0 | null | 2015-05-02T11:56:58 | 2015-05-02T11:56:58 | null | UTF-8 | C++ | false | false | 570 | cpp | #include "stdafx.h"
#include "PrestoClient.h"
#include "StatementClient.h"
///////////////////////////////////////////////////////////////////////////////
PrestoClient::PrestoClient()
{
}
///////////////////////////////////////////////////////////////////////////////
PrestoClient::~PrestoClient()
{
}
///////////////////////////////////////////////////////////////////////////////
StatementClientPtr PrestoClient::query(const Session& session,
const wstring& query)
{
StatementClientPtr stmt = StatementClient::makeClient(session, query);
return stmt;
}
| [
"trieck@gmail.com"
] | trieck@gmail.com |
fdac2c331a3cc85d54c168af3c6e1f95318434b9 | b92769dda6c8b7e9bf79c48df810a702bfdf872f | /7.Functions/7.18.fun_ptr.cpp | 1cf2bc68e19b41c754a149741efd8d2edca2031e | [
"MIT"
] | permissive | HuangStomach/Cpp-primer-plus | 4276e0a24887ef6d48f202107b7b4c448230cd20 | c8b2b90f10057e72da3ab570da7cc39220c88f70 | refs/heads/master | 2021-06-25T07:22:15.405581 | 2021-02-28T06:55:23 | 2021-02-28T06:55:23 | 209,192,905 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 601 | cpp | #include <iostream>
using namespace std;
double betsy(int);
double pam(int);
void estimate(int lines, double (*pt)(int));
int main(int argc, char const *argv[]) {
int code;
cout << "Lines? ";
cin >> code;
cout << "Betsy's estimate:\n";
estimate(code, betsy);
cout << "Pam:\n";
estimate(code, pam);
return 0;
}
double betsy(int lns) {
return 0.05 * lns;
}
double pam(int lns) {
return 0.03 * lns + 0.0004 * lns * lns;
}
void estimate(int lines, double (*pf)(int)) {
cout << lines << " lines will take ";
cout << (*pf)(lines) << " hour(s)" << endl;
} | [
"nxmbest@qq.com"
] | nxmbest@qq.com |
f7427d67961548b0e8797e9433cf1bf36530d3a3 | a5a16bed617be48c2b04f2b9bdba9e494fe9fef4 | /utils/LineBuffer.cpp | dff009b7096a835a9057977dab3c6ae9eb9867f8 | [] | no_license | ruanbo1003/DistLog | 9a07c0c0e7e6380949c8082cc1beed69db670303 | c136db8742143079f12184088682782f275a4fd2 | refs/heads/master | 2021-06-27T02:39:02.737142 | 2017-09-12T11:47:57 | 2017-09-12T11:47:57 | 103,148,165 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,382 | cpp | /*
* LineBuffer.cpp
*
* Author: ruanbo
*/
#include "LineBuffer.hpp"
#include <string.h>
LineBuffer::LineBuffer()
{
char* buff = (char*)malloc(DEF_LINE_BUFF_SIZE);
std::fill_n(buff, DEF_LINE_BUFF_SIZE, 0);
_buff_size = DEF_LINE_BUFF_SIZE;
_buff = std::tr1::shared_ptr<char>(buff, my_free);
}
LineBuffer::~LineBuffer()
{
}
void LineBuffer::my_free(void *data)
{
free(data);
}
void LineBuffer::append_size(size_t need_size)
{
size_t new_size = 0;
if(need_size == 0)
{
if(_buff_size >= 1024 * 512)
{
new_size = _buff_size + 1024 * 4;
}
else
{
new_size = _buff_size * 2;
}
}
else
{
new_size = _buff_size;
while(true)
{
if(new_size < need_size)
{
new_size = new_size * 2;
}
else
{
break;
}
}
}
char* new_buff = (char*)malloc(new_size);
std::fill_n(new_buff, new_size, 0);
std::copy(_buff.get(), _buff.get()+_buff_size, new_buff);
_buff_size = new_size;
_buff.reset(new_buff, my_free);
}
void LineBuffer::clean_data()
{
std::fill_n(_buff.get(), _buff_size, 0);
}
size_t LineBuffer::buff_size()
{
return _buff_size;
}
char* LineBuffer::data()
{
return _buff.get();
}
| [
"ruanbo@localhost.localdomain"
] | ruanbo@localhost.localdomain |
e8e570820540ccb5aeb186ccc96f53accec3c51a | 16fa0c00570948261e7af541cd0b5d7396f609fe | /Server/Writer.hpp | 6386ab37ebeb2cc4a40de764cdc3c7317578cc25 | [] | no_license | theonenottaken/E-commerce-with-Cpp | 12ba3ed1e455d905ec3f81ef705328cd0fe40af2 | 4d814161e778353badcdea27fc973184d2a70c02 | refs/heads/master | 2020-03-25T02:56:27.591354 | 2018-08-13T15:06:07 | 2018-08-13T15:06:07 | 143,314,564 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,355 | hpp |
/*******************************************************************************************
* Student Name: Caleb Shere
* Exercise Name: Targil 5
* File Description: Writer.hpp
*******************************************************************************************/
#ifndef Writer_hpp
#define Writer_hpp
#include <iostream>
#include "Professional.hpp"
class Writer : public Professional {
public:
/********************************************************************************
* Makes a new writer with the given information.
********************************************************************************/
Writer(const std::string& id, const std::string& name, const std::string& job,
const std::string& age, const std::string& gender)
: Professional(id, name, job, age, gender) { }
/********************************************************************************
* Destructor
********************************************************************************/
~Writer() {}
/********************************************************************************
* Returns the name and specific job description of this writer.
********************************************************************************/
std::string print();
};
#endif /* Writer_hpp */
| [
"theonenottaken@gmail.com"
] | theonenottaken@gmail.com |
b56ac51cc78f5f054e6ec2f28df6edc8b10ed0fa | f2a0beb0272926443df688631fa1617ec268acc5 | /OpenGL3D Game/Ai Movement.h | e471d4952895c7dfb116857cc77ee22c238fef89 | [
"MIT"
] | permissive | TheSandstorm/Networking | cf920c69785813c5ab806cd23302f6684c78aa41 | ec4bfaa815523b5a0d4a6e448645505d664a894f | refs/heads/master | 2020-06-05T16:48:47.418819 | 2019-06-18T07:19:55 | 2019-06-18T07:19:55 | 192,487,390 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 750 | h | #pragma once
#include "Object.h"
class AiMove {
public:
static glm::vec3 Seek(glm::vec3 _ObjPos, glm::vec3 _ObjVelocity, glm::vec3 _Target);
static glm::vec3 Seek(glm::vec3 _ObjPos, glm::vec3 _ObjVelocity, glm::vec3 _Target, float _MaxSpeed, float MaxForce);
static glm::vec3 Pursue(glm::vec3 _ObjPos, glm::vec3 _ObjVelocity, glm::vec3 _TargetPos, glm::vec3 _TargetVelocity);
static glm::vec3 Wander(glm::vec3 _ObjPos, glm::vec3 _ObjVelocity, float _MaxSpeed, float _MaxForce);
private:
static glm::vec3 Limit(glm::vec3 _Vec, float _MaxForce);
static glm::vec3 Location;
static glm::vec3 Velocity;
static glm::vec3 Acceleration;
static float MaxSpeed;
static float MaxForce;
static float ApproachDistance;
static float WanderRadius;
}; | [
"41430338+TheSandstorm@users.noreply.github.com"
] | 41430338+TheSandstorm@users.noreply.github.com |
a1d72333f2c8a7ce44c4bdbcd3731523cadef846 | 8d1cbc47d576ecd58e74abc288e85afa4261df9e | /POJ/3368/15352743_AC_610ms_8800kB.cpp | 6cc38c6eeea3ebc679d740361c7ae024fd90d75c | [] | no_license | KevinMcblack/My_ACM | f7b5b2836f6bc50cf7e3b09c1ac150b85bec2249 | e2e119bf66e16fcaaf6f2e99d27a37fdc43a0b05 | refs/heads/master | 2021-01-16T03:03:38.807814 | 2020-05-27T01:37:54 | 2020-05-27T01:37:54 | 242,954,735 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,215 | cpp | #include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 100017;
int num[maxn], f[maxn], MAX[maxn][20];
int n;
int rmq_max(int l, int r)
{
if (l > r)
return 0;
int k = log((double)(r - l + 1)) / log(2.0);
return max(MAX[l][k], MAX[r - (1 << k) + 1][k]);
}
void init()
{
for (int i = 1; i <= n; i++)
{
MAX[i][0] = f[i];
}
int k = log((double)(n + 1)) / log(2.0);
for (int i = 1; i <= k; i++)
{
for (int j = 1; j + (1 << i) - 1 <= n; j++)
{
MAX[j][i] = max(MAX[j][i - 1], MAX[j + (1 << (i - 1))][i - 1]);
}
}
}
int main()
{
int a, b, q;
while (scanf("%d", &n) && n)
{
scanf("%d", &q);
for (int i = 1; i <= n; i++)
{
scanf("%d", &num[i]);
}
//sort(num + 1, num + n + 1);
f[1] = 1;
for (int i = 2; i <= n; i++)
{
if (num[i] == num[i - 1])
{
f[i] = f[i - 1] + 1;
}
else
{
f[i] = 1;
}
}
init();
for (int i = 1; i <= q; i++)
{
scanf("%d%d", &a, &b);
int t = a;
while (t <= b && num[t] == num[t - 1])
{
t++;
}
int cnt = rmq_max(t, b);
int ans = max(t - a, cnt);
printf("%d\n", ans);
}
}
return 0;
}
/*
10 3
-1 -1 1 2 1 1 1 10 10 10
2 3
1 10
5 10
*/
| [
"970017280@qq.com"
] | 970017280@qq.com |
a57dd7dda1ef956be3b0f78d55ab5e47563f6f9b | 59e29ed9cb3a9bbc71c3053659f68ec9447c701c | /exception.cpp | 9a28ca89926275f7939d0bd137af35bcf7643fc7 | [] | no_license | PhilippParis/BusinessManager | 1cb4c69c48f727546167131eefd9c0ab0594b29f | 1b4df542987b42fa0b3d127c6b62a53e0b83b399 | refs/heads/master | 2016-09-02T01:50:29.300577 | 2015-09-15T15:53:24 | 2015-09-15T15:53:24 | 40,710,858 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 400 | cpp | #include "exception.h"
Exception::Exception(Exception *e)
: m_msg(e->what()),
m_parent(e)
{
}
Exception::Exception(QString msg)
: m_msg(msg)
{
}
Exception::~Exception()
{
if(m_parent != nullptr) {
delete m_parent;
}
}
const char *Exception::what() const noexcept
{
return m_msg.toStdString().c_str();
}
Exception *Exception::parent() const
{
return m_parent;
}
| [
"paris.philipp@gmail.com"
] | paris.philipp@gmail.com |
24bc27b07e50135f3d54fa2b00137aed06835c9c | 1d394377f84a5f0a8b054f1cca1bc29098f4633a | /Polymorphism W08/18127222_W08_10/Ex02_18127222/Saver.h | 5a10e942d7be7c84bec0e73f045baf6a5a2b27cd | [] | no_license | ThienStylemen/Phuong-Phap-Lap-Trinh-Huong-Doi-Tuong-CPlusPlus-HCMUS | 447ef0363a0243dc8ece6819d477085cf908d949 | b96335150ed6ae0a10c1103f2086a664a5a2412c | refs/heads/master | 2022-04-06T12:48:50.084348 | 2020-01-26T06:38:52 | 2020-01-26T06:38:52 | 236,276,357 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 359 | h | #pragma once
#include"Game.h"
#include"Gate.h"
class Saver{
private:
int IQ;
static int money;
static int power;
public:
Saver CreateInformationForSaver();
bool IQisHigherThanDemand(int IQDemand);
bool isEnoughPower(int powerDemand);
bool isEnoughMoney(int moneyDemand);
Saver(int IQ, int money, int power);
Saver();
~Saver();
};
| [
"thienstylemen@gmail.com"
] | thienstylemen@gmail.com |
8dfb83baf6f658480502fbd99a45c342dd483659 | 8e5684077635ad9bef653e598df0c929627ee274 | /QT/TcpServerClient/TcpServerClient/Tcp/Connection/connection.cpp | eb69b25ede8142fa14b05416b205bca848046b8c | [] | no_license | SeidC/GitRepoProjects | 380d693bae1eb6243b1018faca2d423e4965faea | f6994ffb7436ccd1ef6d8c496c946cf4ba3639e6 | refs/heads/master | 2020-04-04T06:20:57.837912 | 2016-11-09T19:52:32 | 2016-11-09T19:52:32 | 48,891,046 | 0 | 0 | null | 2016-01-06T14:26:47 | 2016-01-01T22:16:53 | QML | UTF-8 | C++ | false | false | 91 | cpp | #include "connection.h"
Connection::Connection(QObject *parent) : QTcpSocket(parent)
{
}
| [
"none"
] | none |
b6b94e65f40af90cc983922886903e99f4ebec1a | 7f1cac8e20f7492e6336590a95f8e75444732272 | /utils/kenlm/lm/model.cc | 7800cc315cf8ebae840350d825ad90f1e4ab22e1 | [] | no_license | JohannesW11K/deepspeech-demo | 88443cea7a829ec8e09b6fbd383e6a989e5fb01a | 93ff82824ae12b4366128ea5645f1ef9b25c3266 | refs/heads/master | 2021-01-05T06:05:32.515508 | 2020-02-16T15:14:29 | 2020-02-16T15:14:29 | 240,908,437 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 130 | cc | version https://git-lfs.github.com/spec/v1
oid sha256:50f642df62d9a474dff7959b3ef5b449634d061ba87be8969316d7d4a48bac73
size 16268
| [
"beiserjohannes@gmail.com"
] | beiserjohannes@gmail.com |
1b8faa8604d39686f42afdcdafe92b28ad3be2a3 | 41ebce298b25849a3ecbc4484b4f0f48b79864ab | /tools/caffe.cpp | 4dc6e05c1623377c3bf9783151e2c974b8c20c0d | [
"BSD-3-Clause",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"LicenseRef-scancode-generic-cla"
] | permissive | Seaball/crfasrnn_newercaffe | c0335d9e30c509033171f791bd4882b19d8b02f9 | 8859ffa9f29450794d9b48e8f545292186629c37 | refs/heads/master | 2020-06-21T23:39:24.494871 | 2016-11-27T04:15:46 | 2016-11-27T04:15:46 | 74,832,952 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 13,838 | cpp | #ifdef WITH_PYTHON_LAYER
#include "boost/python.hpp"
namespace bp = boost::python;
#endif
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include "boost/algorithm/string.hpp"
#include "caffe/caffe.hpp"
#include "caffe/util/signal_handler.h"
using caffe::Blob;
using caffe::Caffe;
using caffe::Net;
using caffe::Layer;
using caffe::Solver;
using caffe::shared_ptr;
using caffe::string;
using caffe::Timer;
using caffe::vector;
using std::ostringstream;
DEFINE_string(gpu, "",
"Optional; run in GPU mode on given device IDs separated by ','."
"Use '-gpu all' to run on all available GPUs. The effective training "
"batch size is multiplied by the number of devices.");
DEFINE_string(solver, "",
"The solver definition protocol buffer text file.");
DEFINE_string(model, "",
"The model definition protocol buffer text file.");
DEFINE_string(snapshot, "",
"Optional; the snapshot solver state to resume training.");
DEFINE_string(weights, "",
"Optional; the pretrained weights to initialize finetuning, "
"separated by ','. Cannot be set simultaneously with snapshot.");
DEFINE_string(image, "",
"the path of the image which should be predicted.");//Seaball
DEFINE_string(label, "",
"the path of the label which corresponding to the image to be predicted.");//Seaball
DEFINE_int32(iterations, 50,
"The number of iterations to run.");
DEFINE_string(sigint_effect, "stop",
"Optional; action to take when a SIGINT signal is received: "
"snapshot, stop or none.");
DEFINE_string(sighup_effect, "snapshot",
"Optional; action to take when a SIGHUP signal is received: "
"snapshot, stop or none.");
// A simple registry for caffe commands.
typedef int (*BrewFunction)();
typedef std::map<caffe::string, BrewFunction> BrewMap;
BrewMap g_brew_map;
#define RegisterBrewFunction(func) \
namespace { \
class __Registerer_##func { \
public: /* NOLINT */ \
__Registerer_##func() { \
g_brew_map[#func] = &func; \
} \
}; \
__Registerer_##func g_registerer_##func; \
}
static BrewFunction GetBrewFunction(const caffe::string& name) {
if (g_brew_map.count(name)) {
return g_brew_map[name];
} else {
LOG(ERROR) << "Available caffe actions:";
for (BrewMap::iterator it = g_brew_map.begin();
it != g_brew_map.end(); ++it) {
LOG(ERROR) << "\t" << it->first;
}
LOG(FATAL) << "Unknown action: " << name;
return NULL; // not reachable, just to suppress old compiler warnings.
}
}
// Parse GPU ids or use all available devices
static void get_gpus(vector<int>* gpus) {
if (FLAGS_gpu == "all") {
int count = 0;
#ifndef CPU_ONLY
CUDA_CHECK(cudaGetDeviceCount(&count));
#else
NO_GPU;
#endif
for (int i = 0; i < count; ++i) {
gpus->push_back(i);
}
} else if (FLAGS_gpu.size()) {
vector<string> strings;
boost::split(strings, FLAGS_gpu, boost::is_any_of(","));
for (int i = 0; i < strings.size(); ++i) {
gpus->push_back(boost::lexical_cast<int>(strings[i]));
}
} else {
CHECK_EQ(gpus->size(), 0);
}
}
// caffe commands to call by
// caffe <command> <args>
//
// To add a command, define a function "int command()" and register it with
// RegisterBrewFunction(action);
// Device Query: show diagnostic information for a GPU device.
int device_query() {
LOG(INFO) << "Querying GPUs " << FLAGS_gpu;
vector<int> gpus;
get_gpus(&gpus);
for (int i = 0; i < gpus.size(); ++i) {
caffe::Caffe::SetDevice(gpus[i]);
caffe::Caffe::DeviceQuery();
}
return 0;
}
RegisterBrewFunction(device_query);
// Load the weights from the specified caffemodel(s) into the train and
// test nets.
void CopyLayers(caffe::Solver<float>* solver, const std::string& model_list) {
std::vector<std::string> model_names;
boost::split(model_names, model_list, boost::is_any_of(",") );
for (int i = 0; i < model_names.size(); ++i) {
LOG(INFO) << "Finetuning from " << model_names[i];
solver->net()->CopyTrainedLayersFrom(model_names[i]);
for (int j = 0; j < solver->test_nets().size(); ++j) {
solver->test_nets()[j]->CopyTrainedLayersFrom(model_names[i]);
}
}
}
// Translate the signal effect the user specified on the command-line to the
// corresponding enumeration.
caffe::SolverAction::Enum GetRequestedAction(
const std::string& flag_value) {
if (flag_value == "stop") {
return caffe::SolverAction::STOP;
}
if (flag_value == "snapshot") {
return caffe::SolverAction::SNAPSHOT;
}
if (flag_value == "none") {
return caffe::SolverAction::NONE;
}
LOG(FATAL) << "Invalid signal effect \""<< flag_value << "\" was specified";
}
// Train / Finetune a model.
int train() {
CHECK_GT(FLAGS_solver.size(), 0) << "Need a solver definition to train.";
CHECK(!FLAGS_snapshot.size() || !FLAGS_weights.size())
<< "Give a snapshot to resume training or weights to finetune "
"but not both.";
caffe::SolverParameter solver_param;
caffe::ReadSolverParamsFromTextFileOrDie(FLAGS_solver, &solver_param);
// If the gpus flag is not provided, allow the mode and device to be set
// in the solver prototxt.
if (FLAGS_gpu.size() == 0
&& solver_param.solver_mode() == caffe::SolverParameter_SolverMode_GPU) {
if (solver_param.has_device_id()) {
FLAGS_gpu = "" +
boost::lexical_cast<string>(solver_param.device_id());
} else { // Set default GPU if unspecified
FLAGS_gpu = "" + boost::lexical_cast<string>(0);
}
}
vector<int> gpus;
get_gpus(&gpus);
if (gpus.size() == 0) {
LOG(INFO) << "Use CPU.";
Caffe::set_mode(Caffe::CPU);
} else {
ostringstream s;
for (int i = 0; i < gpus.size(); ++i) {
s << (i ? ", " : "") << gpus[i];
}
LOG(INFO) << "Using GPUs " << s.str();
#ifndef CPU_ONLY
cudaDeviceProp device_prop;
for (int i = 0; i < gpus.size(); ++i) {
cudaGetDeviceProperties(&device_prop, gpus[i]);
LOG(INFO) << "GPU " << gpus[i] << ": " << device_prop.name;
}
#endif
solver_param.set_device_id(gpus[0]);
Caffe::SetDevice(gpus[0]);
Caffe::set_mode(Caffe::GPU);
Caffe::set_solver_count(gpus.size());
}
caffe::SignalHandler signal_handler(
GetRequestedAction(FLAGS_sigint_effect),
GetRequestedAction(FLAGS_sighup_effect));
shared_ptr<caffe::Solver<float> >
solver(caffe::SolverRegistry<float>::CreateSolver(solver_param));
solver->SetActionFunction(signal_handler.GetActionFunction());
if (FLAGS_snapshot.size()) {
LOG(INFO) << "Resuming from " << FLAGS_snapshot;
solver->Restore(FLAGS_snapshot.c_str());
} else if (FLAGS_weights.size()) {
CopyLayers(solver.get(), FLAGS_weights);
}
if (gpus.size() > 1) {
caffe::P2PSync<float> sync(solver, NULL, solver->param());
sync.Run(gpus);
} else {
LOG(INFO) << "Starting Optimization";
solver->Solve();
}
LOG(INFO) << "Optimization Done.";
return 0;
}
RegisterBrewFunction(train);
// Test: score a model.
int test() {
CHECK_GT(FLAGS_model.size(), 0) << "Need a model definition to score.";
CHECK_GT(FLAGS_weights.size(), 0) << "Need model weights to score.";
// Set device id and mode
vector<int> gpus;
get_gpus(&gpus);
if (gpus.size() != 0) {
LOG(INFO) << "Use GPU with device ID " << gpus[0];
#ifndef CPU_ONLY
cudaDeviceProp device_prop;
cudaGetDeviceProperties(&device_prop, gpus[0]);
LOG(INFO) << "GPU device name: " << device_prop.name;
#endif
Caffe::SetDevice(gpus[0]);
Caffe::set_mode(Caffe::GPU);
} else {
LOG(INFO) << "Use CPU.";
Caffe::set_mode(Caffe::CPU);
}
// Instantiate the caffe net.
Net<float> caffe_net(FLAGS_model, caffe::TEST);
caffe_net.CopyTrainedLayersFrom(FLAGS_weights);
LOG(INFO) << "Running for " << FLAGS_iterations << " iterations.";
vector<int> test_score_output_id;
vector<float> test_score;
float loss = 0;
for (int i = 0; i < FLAGS_iterations; ++i) {
float iter_loss;
const vector<Blob<float>*>& result =
caffe_net.Forward(&iter_loss);
loss += iter_loss;
int idx = 0;
for (int j = 0; j < result.size(); ++j) {
const float* result_vec = result[j]->cpu_data();
for (int k = 0; k < result[j]->count(); ++k, ++idx) {
const float score = result_vec[k];
if (i == 0) {
test_score.push_back(score);
test_score_output_id.push_back(j);
} else {
test_score[idx] += score;
}
const std::string& output_name = caffe_net.blob_names()[
caffe_net.output_blob_indices()[j]];
LOG(INFO) << "Batch " << i << ", " << output_name << " = " << score;
}
}
}
loss /= FLAGS_iterations;
LOG(INFO) << "Loss: " << loss;
for (int i = 0; i < test_score.size(); ++i) {
const std::string& output_name = caffe_net.blob_names()[
caffe_net.output_blob_indices()[test_score_output_id[i]]];
const float loss_weight = caffe_net.blob_loss_weights()[
caffe_net.output_blob_indices()[test_score_output_id[i]]];
std::ostringstream loss_msg_stream;
const float mean_score = test_score[i] / FLAGS_iterations;
if (loss_weight) {
loss_msg_stream << " (* " << loss_weight
<< " = " << loss_weight * mean_score << " loss)";
}
LOG(INFO) << output_name << " = " << mean_score << loss_msg_stream.str();
}
return 0;
}
RegisterBrewFunction(test);
// Time: benchmark the execution time of a model.
int time() {
CHECK_GT(FLAGS_model.size(), 0) << "Need a model definition to time.";
// Set device id and mode
vector<int> gpus;
get_gpus(&gpus);
if (gpus.size() != 0) {
LOG(INFO) << "Use GPU with device ID " << gpus[0];
Caffe::SetDevice(gpus[0]);
Caffe::set_mode(Caffe::GPU);
} else {
LOG(INFO) << "Use CPU.";
Caffe::set_mode(Caffe::CPU);
}
// Instantiate the caffe net.
Net<float> caffe_net(FLAGS_model, caffe::TRAIN);
// Do a clean forward and backward pass, so that memory allocation are done
// and future iterations will be more stable.
LOG(INFO) << "Performing Forward";
// Note that for the speed benchmark, we will assume that the network does
// not take any input blobs.
float initial_loss;
caffe_net.Forward(&initial_loss);
LOG(INFO) << "Initial loss: " << initial_loss;
LOG(INFO) << "Performing Backward";
caffe_net.Backward();
const vector<shared_ptr<Layer<float> > >& layers = caffe_net.layers();
const vector<vector<Blob<float>*> >& bottom_vecs = caffe_net.bottom_vecs();
const vector<vector<Blob<float>*> >& top_vecs = caffe_net.top_vecs();
const vector<vector<bool> >& bottom_need_backward =
caffe_net.bottom_need_backward();
LOG(INFO) << "*** Benchmark begins ***";
LOG(INFO) << "Testing for " << FLAGS_iterations << " iterations.";
Timer total_timer;
total_timer.Start();
Timer forward_timer;
Timer backward_timer;
Timer timer;
std::vector<double> forward_time_per_layer(layers.size(), 0.0);
std::vector<double> backward_time_per_layer(layers.size(), 0.0);
double forward_time = 0.0;
double backward_time = 0.0;
for (int j = 0; j < FLAGS_iterations; ++j) {
Timer iter_timer;
iter_timer.Start();
forward_timer.Start();
for (int i = 0; i < layers.size(); ++i) {
timer.Start();
layers[i]->Forward(bottom_vecs[i], top_vecs[i]);
forward_time_per_layer[i] += timer.MicroSeconds();
}
forward_time += forward_timer.MicroSeconds();
backward_timer.Start();
for (int i = layers.size() - 1; i >= 0; --i) {
timer.Start();
layers[i]->Backward(top_vecs[i], bottom_need_backward[i],
bottom_vecs[i]);
backward_time_per_layer[i] += timer.MicroSeconds();
}
backward_time += backward_timer.MicroSeconds();
LOG(INFO) << "Iteration: " << j + 1 << " forward-backward time: "
<< iter_timer.MilliSeconds() << " ms.";
}
LOG(INFO) << "Average time per layer: ";
for (int i = 0; i < layers.size(); ++i) {
const caffe::string& layername = layers[i]->layer_param().name();
LOG(INFO) << std::setfill(' ') << std::setw(10) << layername <<
"\tforward: " << forward_time_per_layer[i] / 1000 /
FLAGS_iterations << " ms.";
LOG(INFO) << std::setfill(' ') << std::setw(10) << layername <<
"\tbackward: " << backward_time_per_layer[i] / 1000 /
FLAGS_iterations << " ms.";
}
total_timer.Stop();
LOG(INFO) << "Average Forward pass: " << forward_time / 1000 /
FLAGS_iterations << " ms.";
LOG(INFO) << "Average Backward pass: " << backward_time / 1000 /
FLAGS_iterations << " ms.";
LOG(INFO) << "Average Forward-Backward: " << total_timer.MilliSeconds() /
FLAGS_iterations << " ms.";
LOG(INFO) << "Total Time: " << total_timer.MilliSeconds() << " ms.";
LOG(INFO) << "*** Benchmark ends ***";
return 0;
}
RegisterBrewFunction(time);
int main(int argc, char** argv) {
// Print output to stderr (while still logging).
FLAGS_alsologtostderr = 1;
// Set version
gflags::SetVersionString(AS_STRING(CAFFE_VERSION));
// Usage message.
gflags::SetUsageMessage("command line brew\n"
"usage: caffe <command> <args>\n\n"
"commands:\n"
" train train or finetune a model\n"
" test score a model\n"
" device_query show GPU diagnostic information\n"
" time benchmark model execution time");
// Run tool or show usage.
caffe::GlobalInit(&argc, &argv);
if (argc == 2) {
#ifdef WITH_PYTHON_LAYER
try {
#endif
return GetBrewFunction(caffe::string(argv[1]))();
#ifdef WITH_PYTHON_LAYER
} catch (bp::error_already_set) {
PyErr_Print();
return 1;
}
#endif
} else {
gflags::ShowUsageWithFlagsRestrict(argv[0], "tools/caffe");
}
}
| [
"yuhuilee0022@163.com"
] | yuhuilee0022@163.com |
73e59bd0434d6c34347ff5700d4a532538ee687d | a4af01c8cc247020675dd8e71dd32edd76e6266c | /zfractionCorrection/ZFraction.h | 7e5d14f22f45190240a22f775968bf4ef9ee33f2 | [] | no_license | arnaud355/Cplusplus | cdd29556307c8edf7792182e2ae6b41621d87b75 | db184acf6e02140cb0b4dc47666bbb2fc345b194 | refs/heads/master | 2022-12-15T20:34:24.467558 | 2020-09-15T09:27:50 | 2020-09-15T09:27:50 | 295,678,224 | 0 | 0 | null | null | null | null | ISO-8859-1 | C++ | false | false | 2,210 | h | #ifndef DEF_FRACTION
#define DEF_FRACTION
#include <iostream>
class ZFraction
{
public:
//Constructeurs
/*
ZFraction(int num = 0, int den = 1);
*/
ZFraction(int num, int den);
ZFraction(int nombre);
ZFraction();
int numerateur();
int denominateur();
double conversionDecimale();
int getZfracNum() const;
int getZfracDeno() const;
//Affichage
void affiche(std::ostream& flux) const;
//Opérateurs arithmétiques
ZFraction& operator+=(ZFraction const& autre);
ZFraction& operator*=(ZFraction const& autre);
ZFraction& operator/=(ZFraction const& autre);
ZFraction& operator-=(ZFraction const& autre);
//Méthodes de comparaison
bool estEgal(ZFraction const& autre) const;
bool estPlusPetitQue(ZFraction const& autre) const;
private:
int m_numerateur; //Le numérateur de la fraction
int m_denominateur; //Le dénominateur de la fraction
double m_matnum;
double m_matdeno;
// Simplifie une fraction
void simplifie();
};
//Opérateur d'injection dans un flux
std::ostream& operator<<(std::ostream& flux, ZFraction const& fraction);
//Opérateurs arithmétiques
ZFraction operator+(ZFraction const& a, ZFraction const& b);
ZFraction operator*(ZFraction const& a, ZFraction const& b);
ZFraction operator/(ZFraction const& a, ZFraction const& b);
ZFraction operator-(ZFraction const& a, ZFraction const& b);
//Opérateurs de comparaison
bool operator==(ZFraction const& a, ZFraction const& b);
bool operator!=(ZFraction const& a, ZFraction const& b);
bool operator<(ZFraction const& a, ZFraction const& b);
bool operator>(ZFraction const& a, ZFraction const& b);
bool operator>=(ZFraction const& a, ZFraction const& b);
bool operator<=(ZFraction const& a, ZFraction const& b);
//Calcul du pgcd
int pgcd(int a, int b);
int getZfracMathNum(ZFraction const& fraction);
int getZfracMathDeno(ZFraction const& fraction);
class ZFractmath {
public:
void afficherMath() const;
void getNumberAbs(ZFraction const& fraction);
void getNumberPow(ZFraction const& fraction);
void getNumberSqrt(ZFraction const& fraction);
private:
double m_matnum;
double m_matdeno;
};
#endif
| [
"arnaud.baleh@avanade.com"
] | arnaud.baleh@avanade.com |
c3f31a8f94e8ba83acd98b941877a2790e8c662c | 0a6a43b691996499230276055523eb895da6ffec | /.history/main_20190117024725.cpp | b0f442ae64ad2e894d9ba801a0e7ca7a13b9c477 | [] | no_license | SoundRabbit/voice-changer | 362890a6e0ef1dda37c1666b946879fc12125370 | e5a5d64426fc072504477ae30c96e8e293a07a52 | refs/heads/master | 2020-03-27T09:49:50.340212 | 2019-01-16T17:55:04 | 2019-01-16T17:55:04 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,588 | cpp | #include "overlapAdd/overlapAdd.hpp"
#include "spectrum/spectrum.hpp"
#include "wavFile/wavFile.cpp"
#include "windowFunction/windowFunction.hpp"
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
int main(){
using namespace std;
cout << "ファイル名 (please input file name) >" << flush;
std::string fn;
cin >> fn;
// wavファイル読み込み(16bit・モノラル・リニアPCMのみ対応)
WavFile wav;
if(!wav.load(fn)){
cout << "error at file input" << endl;
return 0;
}
constexpr int windowWidth = 4096;
int testCounter = 0;
// 入力波に窓関数をかけて、再合成。
overlapAdd<double>(
wav.data.begin(), wav.data.end(), // 処理範囲
windowWidth, // 窓幅
WindowFunction::rect, // 窓関数の種類
[&](auto sampleBegin, auto sampleEnd){ // 窓関数がかかった波形への処理内容
Spectrum<windowWidth> originalSpectrum(sampleBegin);
// LPFをかける
{
Spectrum<windowWidth / 2> lpfBuffer(originalSpectrum.toArray().begin());
for(int i=lpfBuffer.size()/2; i<lpfBuffer.size(); i++){
lpfBuffer.set(i, 0);
}
array<double, windowWidth / 2> lpfSpectrum;
lpfBuffer(lpfSpectrum.begin());
for(int i=0; i<lpfSpectrum.size(); i++){
originalSpectrum.set(i, lpfSpectrum[i]);
}
}
originalSpectrum(sampleBegin);
},
[](double x)->double{
return WindowFunction::sine(x)*WindowFunction::sine(x);
}
);
wav.save(fn+"-out.wav");
} | [
"neu1neu9neu9neu9neu@gmail.com"
] | neu1neu9neu9neu9neu@gmail.com |
b6e82e63cfb120b3211a6e45f12ccf45739d7c5c | 8e54aa86943b8b68dd9cc1e38330f44a186bb572 | /binary-tree-level-order-traversal-ii.cpp | 1ccfc05920995c6220b122b8ee07ed307bd12cdc | [] | no_license | vkoppu9/Leetcode | 8672b62e95f3362322fa8d8843a6f7378d1c3eb5 | 7680ba2c692ec3d9ef1b15e74686a055d7a6e7e4 | refs/heads/master | 2023-07-13T08:26:53.270507 | 2021-08-24T02:44:34 | 2021-08-24T02:44:34 | 270,016,249 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,256 | cpp | /*
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
For example:
Given binary tree [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its bottom-up level order traversal as:
[
[15,7],
[9,20],
[3]
]
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<vector<int>> levelOrderBottom(TreeNode* root) {
vector<vector<int>> res;
queue<TreeNode *> q;
if(root == NULL)
return res;
q.push(root);
while(!q.empty()) {
int s = q.size();
vector<int> temp;
for(int i = 1; i <= s; i++) {
TreeNode *curr = q.front();
if(curr->left)
q.push(curr->left);
if(curr->right)
q.push(curr->right);
temp.push_back(curr->val);
q.pop();
}
res.push_back(temp);
}
reverse(res.begin(), res.end());
return res;
}
}; | [
"kvnr621@gmail.com"
] | kvnr621@gmail.com |
f24d06330093cc322274868032c944afdc515096 | 452c6d1c2cca5144972977a0ae50a5b72d695c28 | /juggler.cpp | 924d0554856bf313dfe02eebb22b913b304baf7d | [] | no_license | tanya9020/APS2020 | 0a9707e639df6ff69608146c99d4d29388e69d60 | c24b1dae0376042ad222f8b633671ea6784122b4 | refs/heads/master | 2020-12-21T16:27:09.037561 | 2020-04-28T15:02:34 | 2020-04-28T15:02:34 | 236,489,165 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 369 | cpp | #include <iostream>
#include <bits/stdc++.h>
using namespace std;
void juggler(int n)
{
int a=n;
cout<<a<<" ";
while(a!=1)
{
int b=0;
if(a%2==0)
b=floor(sqrt(a));
else
b=floor(sqrt(a)*sqrt(a)*sqrt(a));
cout<<b<<" ";
a=b;
}
}
int main() {
int n;
cin>>n;
juggler(n);
return 0;
}
| [
"noreply@github.com"
] | noreply@github.com |
51c04e2ed770a1aa3443677134e4d659186aef1d | 63d228991f880b4fc41bd10506efe71e6049be73 | /C/salut.cpp | c4b7d26f61445aebb53bf770c6adaa7eb61ddde0 | [] | no_license | anghene/LAB | 4c10bb85d474d99739a08ab6c1466a41f64d565e | 225f91a5ccd04b140f67ef3e9fee17789249ed5b | refs/heads/master | 2021-01-10T21:05:02.823835 | 2018-04-15T21:31:27 | 2018-04-15T21:31:27 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 61 | cpp | #include <stdio.h>
main ()
{
printf("salut");
return 0;
}
| [
"vlad.anghene@gmail.com"
] | vlad.anghene@gmail.com |
a1a0bcf8617e9732c16ee04762711475056a859b | d9f6c8aab1aea97eb5c0eb45a1f7c8bc2cafdba8 | /robot/Log/TCPstreambuf.h | ea22cbda24a7f8767969d96118599c3ba72bb373 | [] | no_license | clubrobot/team-2015 | 1551e37475678f91b63e234896db8663806a5eb4 | c6ba0624db3a204cbfa629f1c2cb4cf8a44a6d71 | refs/heads/master | 2020-04-10T03:56:05.136148 | 2016-09-13T16:54:14 | 2016-09-13T16:54:14 | 68,121,449 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 724 | h | /*
* TCPstreambuf.h
*
* Created on: 23 févr. 2016
* Author: gab
*/
#ifndef LOG_TCPSTREAMBUF_H_
#define LOG_TCPSTREAMBUF_H_
#include <streambuf>
#include <vector>
#include "robot-comlib/Socket/Server/TCPServer.h"
class TCPstreambuf : public std::streambuf {
public:
enum Channel {INFO='A', DEBUG='B', WARNING='C', ERROR='D'};
TCPstreambuf(TCPServer& server, Channel channel);
virtual ~TCPstreambuf();
protected:
virtual int overflow(int c);
virtual int sync();
bool sendToClients();
std::vector<char> mbuffer;
TCPServer& mserver;
Channel mchannel;
private:
TCPstreambuf(const TCPstreambuf& streambuf);
TCPstreambuf& operator=(const TCPstreambuf& streambuf);
};
#endif /* LOG_TCPSTREAMBUF_H_ */
| [
"darmet.ulysse@gmail.com"
] | darmet.ulysse@gmail.com |
b56ce93507c0eeb7af03195ee53c758c9fa56886 | e42bc36aa465a0c6be29e62716a5b9f779d77ea7 | /JVMCore/java/ConstantDouble.cpp | 8b5e902ad00f7bed70a84f033eba072b763e5550 | [] | no_license | weilinchina/JVM | 92d086f0cdc82c7b6005905d76b4f0e80debec04 | 382107b31d18b69bc830004c9e4b436b2692f288 | refs/heads/master | 2020-04-24T22:58:05.439478 | 2012-12-08T09:42:17 | 2012-12-08T09:42:17 | 7,033,280 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 2,098 | cpp | /**=============================================================================
** Copyright (C) 2011- WEILin beijing.
** =============================================================================
**
** This document contains proprietary information belonging to gemalto.
** Technologies. Passing on and copying of this document, use and communication
** of its contents is not permitted without prior written authorisation.
**
** =============================================================================
** Information :
** Project : JVMCore $
** File Name : ConstantDouble.cpp $
** Created on : Nov 15, 2012 $
** Time : 5:05:16 PM $
** Author : liwei $
** ============================================================================
** Contents: This is a header/source file which includes all the functions prototypes
** and data types, implementations.
**
** =========================================================================================== */
#include "ConstantDouble.h"
#include "JVMUtility.h"
namespace diamon_jvm
{
ConstantDouble::ConstantDouble() : ConstantValue()
{
this->constantValueType_ = CONSTANT_VALUE_TYPE_DOUBLE;
this->high_bytes_ = 0;
this->low_bytes_ = 0;
}
ConstantDouble::~ConstantDouble()
{
// TODO Auto-generated destructor stub
}
JVM_U4 ConstantDouble::getHighBytes() const
{
return high_bytes_;
}
JVM_U4 ConstantDouble::getLowBytes() const
{
return low_bytes_;
}
bool ConstantDouble::marshal(Stream &stream)
{
size_t size = stream.readBytes((JVM_BYTE *)&this->high_bytes_, sizeof(this->high_bytes_));
if(size != sizeof(this->high_bytes_))
{
ERROR("read high_bytes of ConstantDouble failed!");
return false;
}
this->high_bytes_ = swap_JVM_U4(this->high_bytes_);
size = stream.readBytes((JVM_BYTE *)&this->low_bytes_, sizeof(this->low_bytes_));
if(size != sizeof(this->low_bytes_))
{
ERROR("read low_bytes of ConstantDouble failed!");
return false;
}
this->low_bytes_ = swap_JVM_U4(this->low_bytes_);
return true;
}
} /* namespace diamon_jvm */
| [
"liwei@home"
] | liwei@home |
aa90580d5b306b42ef928dc95c0a8a46a0a9ccdb | 061ec857397672734af13cae867f9e2fcefbb9d3 | /task29.cpp | cf4df52bd5068b7883a352361a24fe80e85be285 | [] | no_license | Alua001/practice | f8c3dffc54f77b14833ee15a5ffd7657d00f9cea | d743e1bc4fea059831ea0b0bcacc3b785682014b | refs/heads/master | 2020-09-13T03:25:02.933964 | 2019-11-23T11:26:28 | 2019-11-23T11:26:28 | 222,643,239 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 193 | cpp | 29) #include<iostream>
#include<cmath>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
a = a + b;
b = a - b;
a = a - b;
cout << a << " " << b << endl;
return 0;
}
| [
"noreply@github.com"
] | noreply@github.com |
06a7b2d0f638e78e0c1d88ef0ff52d03fe83ec02 | bbcda48854d6890ad029d5973e011d4784d248d2 | /trunk/win/Source/Includes/QtIncludes/src/xmlpatterns/api/qabstractxmlreceiver.h | 60da73ff0e0ef8830695de12cf8497b51999f8e1 | [
"MIT",
"curl",
"LGPL-2.1-or-later",
"BSD-3-Clause",
"BSL-1.0",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"LGPL-2.1-only",
"Zlib",
"LicenseRef-scancode-unknown",
"LicenseRef-scancode-unknown-license-reference",
"MS-LPL"
] | permissive | dyzmapl/BumpTop | 9c396f876e6a9ace1099b3b32e45612a388943ff | 1329ea41411c7368516b942d19add694af3d602f | refs/heads/master | 2020-12-20T22:42:55.100473 | 2020-01-25T21:00:08 | 2020-01-25T21:00:08 | 236,229,087 | 0 | 0 | Apache-2.0 | 2020-01-25T20:58:59 | 2020-01-25T20:58:58 | null | UTF-8 | C++ | false | false | 3,619 | h | /****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtXmlPatterns module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QABSTRACTXMLRECEIVER_H
#define QABSTRACTXMLRECEIVER_H
#include <QtCore/QVariant>
#include <QtCore/QScopedPointer>
#include <QtXmlPatterns/QXmlNodeModelIndex>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(XmlPatterns)
class QAbstractXmlReceiverPrivate;
class QXmlName;
namespace QPatternist
{
class Item;
}
class Q_XMLPATTERNS_EXPORT QAbstractXmlReceiver
{
public:
QAbstractXmlReceiver();
virtual ~QAbstractXmlReceiver();
virtual void startElement(const QXmlName &name) = 0;
virtual void endElement() = 0;
virtual void attribute(const QXmlName &name,
const QStringRef &value) = 0;
virtual void comment(const QString &value) = 0;
virtual void characters(const QStringRef &value) = 0;
virtual void startDocument() = 0;
virtual void endDocument() = 0;
virtual void processingInstruction(const QXmlName &target,
const QString &value) = 0;
virtual void atomicValue(const QVariant &value) = 0;
virtual void namespaceBinding(const QXmlName &name) = 0;
virtual void startOfSequence() = 0;
virtual void endOfSequence() = 0;
/* The members below are internal, not part of the public API, and
* unsupported. Using them leads to undefined behavior. */
virtual void whitespaceOnly(const QStringRef &value);
virtual void item(const QPatternist::Item &item);
protected:
QAbstractXmlReceiver(QAbstractXmlReceiverPrivate *d);
QScopedPointer<QAbstractXmlReceiverPrivate> d_ptr;
void sendAsNode(const QPatternist::Item &outputItem);
private:
template<const QXmlNodeModelIndex::Axis axis>
void sendFromAxis(const QXmlNodeModelIndex &node);
Q_DISABLE_COPY(QAbstractXmlReceiver)
};
QT_END_NAMESPACE
QT_END_HEADER
#endif
| [
"anandx@google.com"
] | anandx@google.com |
bb814de98a0095bdc16be29326da8e40d8538a2c | 7ecc50d22ad5907dae34377443455c4f605c61e9 | /src/run.cc | 0b24f674e6a93fc7e285d55311c915cfd3daa88b | [] | no_license | chen5864647/HttpAttack | 120236efe3c6ea30a50c0e7866bb7820a6ef878a | 1d37afffa6776410d27dba580128913103fba4c2 | refs/heads/master | 2020-05-23T04:02:44.080405 | 2019-05-14T14:25:42 | 2019-05-14T14:25:42 | 186,628,402 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,315 | cc | #include <boost/asio.hpp>
#include <array>
#include <string>
#include <iostream>
#include "threadpool.hpp"
std::string url;
std::string http;
std::array<char, 9192> buffer;
char datar[39];
void read_handler(const boost::system::error_code &ec,
size_t bytes_transferred,
boost::asio::ip::tcp::socket &sock) {
if (!ec) {
std::cout << std::string(buffer.data(), bytes_transferred) << std::endl;
sock.async_read_some(boost::asio::buffer(buffer), read_handler);
}
else
std::cerr << "There is something wrong with the read" << std::endl;
}
void connect_handler(const boost::system::error_code &ec,
boost::asio::ip::tcp::socket &sock) {
if (!ec) {
boost::asio::write(sock, boost::asio::buffer(datar));
auto read_handler_bind = std::bind(read_handler, std::placeholders::_1, std::placeholders::_2, sock);
sock.async_read_some(boost::asio::buffer(buffer), read_handler_bind);
}
else
std::cerr << "There is something wrong with the connect" << std::endl;
}
void resolve_handler(const boost::system::error_code &ec,
boost::asio::ip::tcp::resolver::iterator it,
boost::asio::ip::tcp::socket &sock) {
if (!ec) {
auto connect_handler_bind = std::bind(connect_handler, std::placeholders::_1, sock);
sock.async_connect(*it, connect_handler_bind);
}
}
inline
void funnc(boost::asio::io_service &io_service,
boost::asio::ip::tcp::resolver &resolver,
boost::asio::ip::tcp::socket &sock,
boost::asio::ip::tcp::resolver::query &query) {
auto resolver_handler_bind = std::bind(resolve_handler, std::placeholders::_1, std::placeholders::_2, sock);
resolver.async_resolve(query, resolver_handler_bind);
}
void func() {
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::socket sock(io_service);
boost::asio::deadline_timer timer(io_service, boost::posix_time::seconds(1));
boost::asio::ip::tcp::resolver::query query(url.c_str(), "80");
timer.async_wait(funnc);
io_service.run();
}
void work() {
ThreadPool pool(1000);
while (true)
pool.enqueue(func);
} | [
"noreply@github.com"
] | noreply@github.com |
9f24f42f52f07e2e992e738e4d949125c2b89865 | 090243cf699213f32f870baf2902eb4211f825d6 | /cf/624A.cpp | b9c50e60fcbea7ba099ca5e13a7b7bab58393b17 | [] | no_license | zhu-he/ACM-Source | 0d4d0ac0668b569846b12297e7ed4abbb1c16571 | 02e3322e50336063d0d2dad37b2761ecb3d4e380 | refs/heads/master | 2021-06-07T18:27:19.702607 | 2016-07-10T09:20:48 | 2016-07-10T09:20:48 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 152 | cpp | #include <cstdio>
int main()
{
int d, L, v1, v2;
scanf("%d %d %d %d", &d, &L, &v1, &v2);
printf("%.10f\n", 1.0 * (L - d) / (v1 + v2));
return 0;
}
| [
"841815229@qq.com"
] | 841815229@qq.com |
d113e96a198589563a0887bd002fe7a0f65324f7 | f3a729d3588f6c31975d44b37f1b3a29c01db3cd | /39H.cpp | 2490cb6f00243904f9f0536b7c279d37a5c115df | [] | no_license | yongwhan/codeforces | 887e7cca0b47aa2ba65b1133300c63a808a15590 | aa8fa27ca1a07fcb7f9dac5b1ce908b7bfcd49e2 | refs/heads/master | 2020-11-28T01:47:52.239077 | 2019-12-23T04:16:29 | 2019-12-23T04:16:29 | 229,671,486 | 0 | 0 | null | 2019-12-23T04:05:28 | 2019-12-23T03:43:38 | C++ | UTF-8 | C++ | false | false | 408 | cpp | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
void eval(int x, int n) {
string ret;
while(x)
ret=char('0'+x%n)+ret, x/=n;
cout << ret;
}
int main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int n; cin>>n;
for (int i=1; i<n; i++) {
for (int j=1; j<n; j++) {
if(j>1) cout << " ";
eval(i*j,n);
}
cout << endl;
}
return 0;
}
| [
"yongwhan@yongwhan-macbookpro.roam.corp.google.com"
] | yongwhan@yongwhan-macbookpro.roam.corp.google.com |
38fac01b02f3f8fc51ddb36bf8e1e5ac37d558d2 | e2524e525c23928a6a82ad0deab106cd51d9b4bb | /src/rpc/client.cpp | e648b2db561b9c8893f9adb498e49518ccf8707b | [
"MIT"
] | permissive | wasilij525/PUTIN | 8dc4b90580aa666a58bcf8f24ce5f3ca5d9b4bc2 | c6b5a026f4ef63b644666e7f2397a52cbf83ce66 | refs/heads/master | 2020-04-10T00:37:34.021295 | 2018-12-06T17:20:32 | 2018-12-06T17:20:32 | 160,046,627 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,062 | cpp | // Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
// Copyright (c) 2014-2015 The Dash developers
// Copyright (c) 2015-2017 The PIVX developers
// Copyright (c) 2017-2018 The putin & Bitfineon developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "rpc/client.h"
#include "rpc/protocol.h"
#include "ui_interface.h"
#include "util.h"
#include <set>
#include <stdint.h>
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <univalue.h>
using namespace std;
class CRPCConvertParam
{
public:
std::string methodName; //! method whose params want conversion
int paramIdx; //! 0-based idx of param to convert
};
// ***TODO***
static const CRPCConvertParam vRPCConvertParams[] =
{
{"stop", 0},
{"setmocktime", 0},
{"getaddednodeinfo", 0},
{"setgenerate", 0},
{"setgenerate", 1},
{"getnetworkhashps", 0},
{"getnetworkhashps", 1},
{"sendtoaddress", 1},
{"sendtoaddressix", 1},
{"settxfee", 0},
{"getreceivedbyaddress", 1},
{"getreceivedbyaccount", 1},
{"listreceivedbyaddress", 0},
{"listreceivedbyaddress", 1},
{"listreceivedbyaddress", 2},
{"listreceivedbyaccount", 0},
{"listreceivedbyaccount", 1},
{"listreceivedbyaccount", 2},
{"getbalance", 1},
{"getbalance", 2},
{"getblockhash", 0},
{"move", 2},
{"move", 3},
{"sendfrom", 2},
{"sendfrom", 3},
{"listtransactions", 1},
{"listtransactions", 2},
{"listtransactions", 3},
{"listaccounts", 0},
{"listaccounts", 1},
{"walletpassphrase", 1},
{"walletpassphrase", 2},
{"getblocktemplate", 0},
{"listsinceblock", 1},
{"listsinceblock", 2},
{"sendmany", 1},
{"sendmany", 2},
{"addmultisigaddress", 0},
{"addmultisigaddress", 1},
{"createmultisig", 0},
{"createmultisig", 1},
{"listunspent", 0},
{"listunspent", 1},
{"listunspent", 2},
{"listunspent", 3},
{"getblock", 1},
{"getblockheader", 1},
{"gettransaction", 1},
{"getrawtransaction", 1},
{"createrawtransaction", 0},
{"createrawtransaction", 1},
{"signrawtransaction", 1},
{"signrawtransaction", 2},
{"sendrawtransaction", 1},
{"sendrawtransaction", 2},
{"gettxout", 1},
{"gettxout", 2},
{"lockunspent", 0},
{"lockunspent", 1},
{"importprivkey", 2},
{"importaddress", 2},
{"verifychain", 0},
{"verifychain", 1},
{"keypoolrefill", 0},
{"getrawmempool", 0},
{"estimatefee", 0},
{"estimatepriority", 0},
{"prioritisetransaction", 1},
{"prioritisetransaction", 2},
{"setban", 2},
{"setban", 3},
{"spork", 1},
{"mnbudget", 3},
{"mnbudget", 4},
{"mnbudget", 6},
{"mnbudget", 8},
{"preparebudget", 2},
{"preparebudget", 3},
{"preparebudget", 5},
{"submitbudget", 2},
{"submitbudget", 3},
{"submitbudget", 5},
{"submitbudget", 7},
// disabled until removal of the legacy 'masternode' command
//{"startmasternode", 1},
{"mnvoteraw", 1},
{"mnvoteraw", 4},
{"reservebalance", 0},
{"reservebalance", 1},
{"setstakesplitthreshold", 0},
{"autocombinerewards", 0},
{"autocombinerewards", 1},
{"getzerocoinbalance", 0},
{"listmintedzerocoins", 0},
{"listspentzerocoins", 0},
{"listzerocoinamounts", 0},
{"mintzerocoin", 0},
{"mintzerocoin", 1},
{"spendzerocoin", 0},
{"spendzerocoin", 1},
{"spendzerocoin", 2},
{"spendzerocoin", 3},
{"importzerocoins", 0},
{"exportzerocoins", 0},
{"exportzerocoins", 1},
{"resetmintzerocoin", 0},
{"getspentzerocoinamount", 1},
{"generatemintlist", 0},
{"generatemintlist", 1},
{"searchdzXPTN", 0},
{"searchdzXPTN", 1},
{"searchdzXPTN", 2},
{"getaccumulatorvalues", 0},
{"getfeeinfo", 0}
};
class CRPCConvertTable
{
private:
std::set<std::pair<std::string, int> > members;
public:
CRPCConvertTable();
bool convert(const std::string& method, int idx)
{
return (members.count(std::make_pair(method, idx)) > 0);
}
};
CRPCConvertTable::CRPCConvertTable()
{
const unsigned int n_elem =
(sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
for (unsigned int i = 0; i < n_elem; i++) {
members.insert(std::make_pair(vRPCConvertParams[i].methodName,
vRPCConvertParams[i].paramIdx));
}
}
static CRPCConvertTable rpcCvtTable;
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
* as well as objects and arrays.
*/
UniValue ParseNonRFCJSONValue(const std::string& strVal)
{
UniValue jVal;
if (!jVal.read(std::string("[")+strVal+std::string("]")) ||
!jVal.isArray() || jVal.size()!=1)
throw runtime_error(string("Error parsing JSON:")+strVal);
return jVal[0];
}
/** Convert strings to command-specific RPC representation */
UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
{
UniValue params(UniValue::VARR);
for (unsigned int idx = 0; idx < strParams.size(); idx++) {
const std::string& strVal = strParams[idx];
if (!rpcCvtTable.convert(strMethod, idx)) {
// insert string value directly
params.push_back(strVal);
} else {
// parse string as JSON, insert bool/number/object/etc. value
params.push_back(ParseNonRFCJSONValue(strVal));
}
}
return params;
}
| [
"45534349+wasilij525@users.noreply.github.com"
] | 45534349+wasilij525@users.noreply.github.com |
94048c96b95bfaad89889a7086ccade52eb27992 | c69ae7db746ac8402db12d3b800eca17d8d65b14 | /Plugins/VoxelFree/Source/VoxelGraph/Private/VoxelNodes/VoxelTextureSamplerNode.cpp | 35ed59f521e3673ef538bb9b8ced4849d41c747d | [
"MIT"
] | permissive | kutselabskii/VR-homework | 9152d97b0f1e6a544434c9fb7b526e49d80aa3be | 4e5d0a15664aa67501d293a11e4d4560947f386f | refs/heads/master | 2023-02-27T07:51:40.098431 | 2021-02-05T12:13:13 | 2021-02-06T09:09:32 | 295,722,640 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,412 | cpp | // Copyright 2020 Phyronnaz
#include "VoxelNodes/VoxelTextureSamplerNode.h"
#include "VoxelGraphGenerator.h"
#include "VoxelGraphErrorReporter.h"
#include "NodeFunctions/VoxelNodeFunctions.h"
#include "Engine/Texture2D.h"
UVoxelNode_TextureSampler::UVoxelNode_TextureSampler()
{
SetInputs(
{ "X", EC::Float, "Coordinate between 0 and texture width" },
{ "Y", EC::Float, "Coordinate between 0 and texture height" });
SetOutputs(
{ "R", EC::Float, "Red between 0 and 1" },
{ "G", EC::Float, "Green between 0 and 1" },
{ "B", EC::Float, "Blue between 0 and 1" },
{ "A", EC::Float, "Alpha between 0 and 1" });
}
EVoxelPinCategory UVoxelNode_TextureSampler::GetInputPinCategory(int32 PinIndex) const
{
return bBilinearInterpolation ? EC::Float : EC::Int;
}
FText UVoxelNode_TextureSampler::GetTitle() const
{
return FText::Format(VOXEL_LOCTEXT("Texture: {0}"), Super::GetTitle());
}
void UVoxelNode_TextureSampler::LogErrors(FVoxelGraphErrorReporter& ErrorReporter)
{
Super::LogErrors(ErrorReporter);
FString Error;
if (!FVoxelTextureHelpers::CanCreateFromTexture(Texture, Error))
{
ErrorReporter.AddMessageToNode(this, Error, EVoxelGraphNodeMessageType::Error);
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
UVoxelNode_VoxelTextureSampler::UVoxelNode_VoxelTextureSampler()
{
SetInputs(
{"X", EC::Float, "Coordinate between 0 and texture width"},
{"Y", EC::Float, "Coordinate between 0 and texture height"});
SetOutputs(EC::Float);
}
EVoxelPinCategory UVoxelNode_VoxelTextureSampler::GetInputPinCategory(int32 PinIndex) const
{
return bBilinearInterpolation ? EC::Float : EC::Int;
}
FText UVoxelNode_VoxelTextureSampler::GetTitle() const
{
return FText::Format(VOXEL_LOCTEXT("Voxel Texture: {0}"), Super::GetTitle());
}
#if WITH_EDITOR
void UVoxelNode_VoxelTextureSampler::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if (PropertyChangedEvent.Property &&
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_STATIC(UVoxelNode_TextureSampler, bBilinearInterpolation) &&
GraphNode &&
Graph)
{
GraphNode->ReconstructNode();
Graph->CompileVoxelNodesFromGraphNodes();
}
}
#endif | [
"osutanfirst@gmail.com"
] | osutanfirst@gmail.com |
9efbcde443ae9f4eb735d684453c7c32f82d9090 | 1affee41c600b845a6f2bc27c02a7f38b72194ad | /Algorithm/ACM/feizhai.cpp | a9fd31c03990179187564ce431f5e0a3d456ef8c | [] | no_license | PascalZh/Practice | f33702a0e5d04737943e35ed3a02d29165123634 | 6ba455b18404cc25f275043ff277edafe626b237 | refs/heads/master | 2022-06-01T02:55:04.886150 | 2022-05-14T04:54:32 | 2022-05-14T04:54:32 | 107,367,122 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 467 | cpp | #include<iostream>
int max(int x, int y)
{
return x > y?x:y;
}
int beibao(int *m, int size, int w)
{
int ret;
if (size == 0)
return 0;
if (m[0] <= w)
ret = max(beibao(m+1, size-1, w), beibao(m+1, size-1, w-m[0]) + m[0]);
else
ret = beibao(m+1, size-1, w);
return ret;
}
int main()
{
int w, n;
using namespace std;
cin >> w;
cin >> n;
int *m = new int[n];
for (int i = 0; i < n; i++)
cin >> m[i];
cout << w - beibao(m, n, w);
delete[] m;
}
| [
"1315521905@qq.com"
] | 1315521905@qq.com |
1eb71d33619a484bc84388971d92630754183e46 | 190a4e3f7ea2b58dbcf4bb394cea328cdb5322a7 | /src/wren/TextureRtt.hpp | 0ed3e86185f615a085f9e67e0406703e7617e2a3 | [
"Apache-2.0"
] | permissive | congleetea/webots | e4bb1ec369572467cad3e6f036880aabc7a3d3c4 | f7bf0cb385842478c5635e29db8e25689d3d0c65 | refs/heads/master | 2022-12-23T19:12:18.468134 | 2020-09-28T08:30:23 | 2020-09-28T08:30:23 | 299,242,767 | 1 | 0 | Apache-2.0 | 2020-09-28T08:34:28 | 2020-09-28T08:34:28 | null | UTF-8 | C++ | false | false | 1,510 | hpp | // Copyright 1996-2020 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef TEXTURE_RTT_HPP
#define TEXTURE_RTT_HPP
#include "Texture.hpp"
namespace wren {
// Texture which can be used to back a framebuffer.
class TextureRtt : public Texture {
public:
// Encapsulate memory management
static TextureRtt *createTextureRtt() { return new TextureRtt(); }
static TextureRtt *copyTextureRtt(const TextureRtt *original);
WrTextureType type() const override { return WR_TEXTURE_TYPE_RTT; }
unsigned int glName() const override { return mGlName; }
// Needs to be called by the using framebuffer during prepareGl
void prepareGl() override;
void initializeData(bool enabled) { mInitializeData = enabled; }
void setGlName(unsigned int glName) override { mGlName = glName; }
protected:
TextureRtt();
virtual ~TextureRtt() {}
unsigned int mGlName;
bool mInitializeData;
};
} // namespace wren
#endif // TEXTURE_RTT_HPP
| [
"David.Mansolino@cyberbotics.com"
] | David.Mansolino@cyberbotics.com |
622ed5ed66dd3d11a723c173f4ffa06251deb0d5 | 8abbd2548195c0b5b42a86b68c960f26f66a3c46 | /test/util.hpp | a956ef8aedaf86f8138725d92387d5e473b39aaa | [
"BSD-3-Clause"
] | permissive | knowthyselfcn/tinype | 12ba67698fae91307a449e9b8784ae360b06825f | de289d45fca89a4ba964ae2577ac9d82784fadd0 | refs/heads/master | 2021-05-31T18:51:26.449129 | 2016-06-04T08:02:48 | 2016-06-04T08:02:48 | 58,025,221 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,712 | hpp | /*
* Vulkan Samples
*
* Copyright (C) 2015-2016 Valve Corporation
* Copyright (C) 2015-2016 LunarG, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef TINYPE_UTIL_H
#define TINYPE_UTIL_H
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#define GLM_FORCE_RADIANS
#include "glm/glm.hpp"
#include <glm/gtc/matrix_transform.hpp>
#ifdef _WIN32
#pragma comment(linker, "/subsystem:console")
#define WIN32_LEAN_AND_MEAN
#define VK_USE_PLATFORM_WIN32_KHR
#define NOMINMAX /* Don't let Windows define min() or max() */
#define APP_NAME_STR_LEN 80
#else // _WIN32
#define VK_USE_PLATFORM_XCB_KHR
#include <unistd.h>
#endif // _WIN32
#include <vulkan/vulkan.h>
#include "vulkan/vk_sdk_platform.h"
/* Number of descriptor sets needs to be the same at alloc, */
/* pipeline layout creation, and descriptor set layout creation */
#define NUM_DESCRIPTOR_SETS 1
/* Number of samples needs to be the same at image creation, */
/* renderpass creation and pipeline creation. */
#define NUM_SAMPLES VK_SAMPLE_COUNT_1_BIT
/* Number of viewports and number of scissors have to be the same */
/* at pipeline creation and in any call to set them dynamically */
/* They also have to be the same as each other */
#define NUM_VIEWPORTS 1
#define NUM_SCISSORS NUM_VIEWPORTS
/* Amount of time, in nanoseconds, to wait for a command buffer to complete */
#define FENCE_TIMEOUT 100000000
#define GET_INSTANCE_PROC_ADDR(inst, entrypoint) \
{ \
info.fp##entrypoint = \
(PFN_vk##entrypoint)vkGetInstanceProcAddr(inst, "vk" #entrypoint); \
if (info.fp##entrypoint == NULL) { \
std::cout << "vkGetDeviceProcAddr failed to find vk" #entrypoint; \
exit(-1); \
} \
}
#define GET_DEVICE_PROC_ADDR(dev, entrypoint) \
{ \
info.fp##entrypoint = \
(PFN_vk##entrypoint)vkGetDeviceProcAddr(dev, "vk" #entrypoint); \
if (info.fp##entrypoint == NULL) { \
std::cout << "vkGetDeviceProcAddr failed to find vk" #entrypoint; \
exit(-1); \
} \
}
#if defined(NDEBUG) && defined(__GNUC__)
#define U_ASSERT_ONLY __attribute__((unused))
#else
#define U_ASSERT_ONLY
#endif
std::string get_base_data_dir();
std::string get_data_dir(std::string filename);
/*
* structure to track all objects related to a texture.
*/
struct texture_object {
VkSampler sampler;
VkImage image;
VkImageLayout imageLayout;
VkDeviceMemory mem;
VkImageView view;
int32_t tex_width, tex_height;
};
/*
* Keep each of our swap chain buffers' image, command buffer and view in one
* spot
*/
typedef struct _swap_chain_buffers {
VkImage image;
VkImageView view;
} swap_chain_buffer;
/*
* A layer can expose extensions, keep track of those
* extensions here.
*/
typedef struct {
VkLayerProperties properties;
std::vector<VkExtensionProperties> extensions;
} layer_properties;
/*
* Structure for tracking information used / created / modified
* by utility functions.
*/
struct sample_info {
#ifdef _WIN32
#define APP_NAME_STR_LEN 80
HINSTANCE connection; // hInstance - Windows Instance
char name[APP_NAME_STR_LEN]; // Name to put on the window/icon
HWND window; // hWnd - window handle
#else // _WIN32
xcb_connection_t *connection;
xcb_screen_t *screen;
xcb_window_t window;
xcb_intern_atom_reply_t *atom_wm_delete_window;
#endif // _WIN32
VkSurfaceKHR surface;
bool prepared;
bool use_staging_buffer;
std::vector<const char *> instance_layer_names;
std::vector<const char *> instance_extension_names;
std::vector<layer_properties> instance_layer_properties;
std::vector<VkExtensionProperties> instance_extension_properties;
VkInstance inst;
std::vector<const char *> device_layer_names;
std::vector<const char *> device_extension_names;
std::vector<layer_properties> device_layer_properties;
std::vector<VkExtensionProperties> device_extension_properties;
std::vector<VkPhysicalDevice> gpus;
VkDevice device;
VkQueue queue;
uint32_t graphics_queue_family_index;
VkPhysicalDeviceProperties gpu_props;
std::vector<VkQueueFamilyProperties> queue_props;
VkPhysicalDeviceMemoryProperties memory_properties;
VkFramebuffer *framebuffers;
int width, height;
VkFormat format;
uint32_t swapchainImageCount;
VkSwapchainKHR swap_chain;
std::vector<swap_chain_buffer> buffers;
VkSemaphore presentCompleteSemaphore;
VkCommandPool cmd_pool;
struct {
VkFormat format;
VkImage image;
VkDeviceMemory mem;
VkImageView view;
} depth;
std::vector<struct texture_object> textures;
struct {
VkBuffer buf;
VkDeviceMemory mem;
VkDescriptorBufferInfo buffer_info;
} uniform_data;
struct {
VkDescriptorImageInfo image_info;
} texture_data;
VkDeviceMemory stagingMemory;
VkImage stagingImage;
struct {
VkBuffer buf;
VkDeviceMemory mem;
VkDescriptorBufferInfo buffer_info;
} vertex_buffer;
VkVertexInputBindingDescription vi_binding;
VkVertexInputAttributeDescription vi_attribs[2];
glm::mat4 Projection;
glm::mat4 View;
glm::mat4 Model;
glm::mat4 MVP;
VkCommandBuffer cmd; // Buffer for initialization commands
VkPipelineLayout pipeline_layout;
std::vector<VkDescriptorSetLayout> desc_layout;
VkPipelineCache pipelineCache;
VkRenderPass render_pass;
VkPipeline pipeline;
VkPipelineShaderStageCreateInfo shaderStages[2];
VkDescriptorPool desc_pool;
std::vector<VkDescriptorSet> desc_set;
PFN_vkCreateDebugReportCallbackEXT dbgCreateDebugReportCallback;
PFN_vkDestroyDebugReportCallbackEXT dbgDestroyDebugReportCallback;
PFN_vkDebugReportMessageEXT dbgBreakCallback;
std::vector<VkDebugReportCallbackEXT> debug_report_callbacks;
uint32_t current_buffer;
uint32_t queue_count;
VkViewport viewport;
VkRect2D scissor;
};
bool memory_type_from_properties(struct sample_info &info, uint32_t typeBits,
VkFlags requirements_mask,
uint32_t *typeIndex);
void set_image_layout(struct sample_info &demo, VkImage image,
VkImageAspectFlags aspectMask,
VkImageLayout old_image_layout,
VkImageLayout new_image_layout);
bool read_ppm(char const *const filename, int &width, int &height,
uint64_t rowPitch, unsigned char *dataPtr);
void extract_version(uint32_t version, uint32_t &major, uint32_t &minor,
uint32_t &patch);
bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *pshader,
std::vector<unsigned int> &spirv);
void init_glslang();
void finalize_glslang();
void wait_seconds(int seconds);
void print_UUID(uint8_t *pipelineCacheUUID);
typedef unsigned long long timestamp_t;
timestamp_t get_milliseconds();
// Main entry point of samples
int sample_main();
#endif | [
"cloudqiu1110@gmail.com"
] | cloudqiu1110@gmail.com |
dae70eb48900f47d0d6edc9447f07deb079e7e7f | f9f5701233b37f9a989edf80e2ffa45e7ccf6dd3 | /src/public/inc/pmod/library/interfaces/multi_source_viewmodel_class.h | 84fba6d13b0e9f115d62bd615bcd023a83d495c0 | [
"MIT"
] | permissive | microsoft/pmod | a8ee4eb8d4d94fec80c9248b95fab788adfb54ff | b2a17fc56df6acad96d5605e1fca325a99bfdde8 | refs/heads/master | 2023-08-14T08:24:47.023636 | 2022-08-31T23:18:49 | 2022-08-31T23:18:49 | 93,698,252 | 35 | 8 | NOASSERTION | 2022-08-30T09:39:50 | 2017-06-08T02:15:04 | C++ | UTF-8 | C++ | false | false | 1,599 | h | /***
* Copyright (C) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
*
* File:multi_source_viewmodel_class.h
****/
#pragma once
#include <pmod/pmod_api.h>
#include <pmod/interfaces/observable_object.h>
#include "observable_object_class.h"
#include "viewmodel_class.h"
#include "source_model_delegate.h"
#include "../pmod_lib_api.h"
namespace pmod
{
namespace library
{
BEGIN_DECLARE_INTERFACE(IMultiSourceViewModelDelegate, ISourceBaseModelDelegateBase<IPropertyChangedEventHandler>, PMOD_LIB_API)
STDMETHOD(OnSourcePropertyChanged)(_In_ IObservableObject *pSource, _In_ UINT32 propertyId, _In_ foundation::IInspectable *oldValue, _In_ foundation::IInspectable *newValue) = 0;
END_DECLARE_INTERFACE()
struct MultiSourceViewModelCreateParameters :
public _MultiSourceViewModelCreateParametersBase
<
ObservableObjectCreateParameters,
IMultiSourceViewModelDelegate,
ViewModelOptions,
IObservableObject
>
{
};
BEGIN_DECLARE_INTERFACE(IMultiSourceViewModelClassFactory, foundation::IUnknown, PMOD_LIB_API)
STDMETHOD(CreateMultiSourceViewModelInstance)(
_In_ const MultiSourceViewModelCreateParameters *pModelImpl,
_In_opt_ foundation::IInspectable *pOuter,
_Outptr_ foundation::IInspectable **ppNewInstance) = 0;
END_DECLARE_INTERFACE()
}
}
| [
"rodrigov@microsoft.com"
] | rodrigov@microsoft.com |
2b5bfe6fc250307de64a5ac49c9c767ca91f4240 | 092237674abcb399129d17aa1c25377a42e94e9d | /hacker-rank/max-sum-subarray.cpp | 55b3391386266a633740d17d5ddc7712c5d40d35 | [] | no_license | strncat/competitive-programming | aa4879b9efe422c5bdc7af973a93d05831d0f162 | 988c6e1ecb5e33609f710ea82f149547ed3b8d10 | refs/heads/master | 2021-07-25T03:17:31.442962 | 2020-05-26T04:05:49 | 2020-05-26T04:05:49 | 21,086,298 | 3 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 724 | cpp | //
// Hacker Rank
// Max-Sum-Subarray
//
// Created by Fatima B on 1/20/16.
// Copyright © 2016 Fatima B. All rights reserved.
//
#include <iostream>
#include <math.h>
#include <string.h>
#include <limits.h>
int max_subarray(int *a, int n) {
int current_sum = 0;
int max = INT_MIN;
for (int i = 0; i < n; i++) {
current_sum += a[i];
if (current_sum < 0 || a[i] == 0) {
current_sum = 0;
}
if (max < current_sum) {
max = current_sum;
}
}
return max;
}
int main() {
int n, a[100001];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
printf("%d\n", max_subarray(a, n));
return 0;
}
| [
"strncat"
] | strncat |
d01be1b0381fe50bec06183408c6587cf9edb12c | 50b903f38124e1f13325d739322d37699fca1d6a | /src/v8/src/diagnostics/x64/disasm-x64.cc | 92d4e154fe3c4d9643a68215e8ccc2e1e96ed999 | [
"BSD-3-Clause",
"Apache-2.0",
"SunPro",
"bzip2-1.0.6"
] | permissive | snomile/quic_simple_server | 5c12bd12ef533a4cacdbadd74e95a2988f137f1b | d5091c7ccc44b26cf888e70a9cf110d24fd5c603 | refs/heads/master | 2022-11-06T09:04:16.929915 | 2021-01-08T02:06:42 | 2021-01-08T02:06:42 | 243,030,915 | 0 | 4 | null | 2022-10-18T04:50:13 | 2020-02-25T15:15:34 | null | UTF-8 | C++ | false | false | 103,339 | cc | // Copyright 2011 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <cassert>
#include <cinttypes>
#include <cstdarg>
#include <cstdio>
#if V8_TARGET_ARCH_X64
#include "src/base/compiler-specific.h"
#include "src/base/lazy-instance.h"
#include "src/base/memory.h"
#include "src/base/v8-fallthrough.h"
#include "src/codegen/x64/register-x64.h"
#include "src/codegen/x64/sse-instr.h"
#include "src/diagnostics/disasm.h"
#include "src/utils/utils.h"
namespace disasm {
enum OperandType {
UNSET_OP_ORDER = 0,
// Operand size decides between 16, 32 and 64 bit operands.
REG_OPER_OP_ORDER = 1, // Register destination, operand source.
OPER_REG_OP_ORDER = 2, // Operand destination, register source.
// Fixed 8-bit operands.
BYTE_SIZE_OPERAND_FLAG = 4,
BYTE_REG_OPER_OP_ORDER = REG_OPER_OP_ORDER | BYTE_SIZE_OPERAND_FLAG,
BYTE_OPER_REG_OP_ORDER = OPER_REG_OP_ORDER | BYTE_SIZE_OPERAND_FLAG
};
//------------------------------------------------------------------
// Tables
//------------------------------------------------------------------
struct ByteMnemonic {
int b; // -1 terminates, otherwise must be in range (0..255)
OperandType op_order_;
const char* mnem;
};
static const ByteMnemonic two_operands_instr[] = {
{0x00, BYTE_OPER_REG_OP_ORDER, "add"},
{0x01, OPER_REG_OP_ORDER, "add"},
{0x02, BYTE_REG_OPER_OP_ORDER, "add"},
{0x03, REG_OPER_OP_ORDER, "add"},
{0x08, BYTE_OPER_REG_OP_ORDER, "or"},
{0x09, OPER_REG_OP_ORDER, "or"},
{0x0A, BYTE_REG_OPER_OP_ORDER, "or"},
{0x0B, REG_OPER_OP_ORDER, "or"},
{0x10, BYTE_OPER_REG_OP_ORDER, "adc"},
{0x11, OPER_REG_OP_ORDER, "adc"},
{0x12, BYTE_REG_OPER_OP_ORDER, "adc"},
{0x13, REG_OPER_OP_ORDER, "adc"},
{0x18, BYTE_OPER_REG_OP_ORDER, "sbb"},
{0x19, OPER_REG_OP_ORDER, "sbb"},
{0x1A, BYTE_REG_OPER_OP_ORDER, "sbb"},
{0x1B, REG_OPER_OP_ORDER, "sbb"},
{0x20, BYTE_OPER_REG_OP_ORDER, "and"},
{0x21, OPER_REG_OP_ORDER, "and"},
{0x22, BYTE_REG_OPER_OP_ORDER, "and"},
{0x23, REG_OPER_OP_ORDER, "and"},
{0x28, BYTE_OPER_REG_OP_ORDER, "sub"},
{0x29, OPER_REG_OP_ORDER, "sub"},
{0x2A, BYTE_REG_OPER_OP_ORDER, "sub"},
{0x2B, REG_OPER_OP_ORDER, "sub"},
{0x30, BYTE_OPER_REG_OP_ORDER, "xor"},
{0x31, OPER_REG_OP_ORDER, "xor"},
{0x32, BYTE_REG_OPER_OP_ORDER, "xor"},
{0x33, REG_OPER_OP_ORDER, "xor"},
{0x38, BYTE_OPER_REG_OP_ORDER, "cmp"},
{0x39, OPER_REG_OP_ORDER, "cmp"},
{0x3A, BYTE_REG_OPER_OP_ORDER, "cmp"},
{0x3B, REG_OPER_OP_ORDER, "cmp"},
{0x63, REG_OPER_OP_ORDER, "movsxl"},
{0x84, BYTE_REG_OPER_OP_ORDER, "test"},
{0x85, REG_OPER_OP_ORDER, "test"},
{0x86, BYTE_REG_OPER_OP_ORDER, "xchg"},
{0x87, REG_OPER_OP_ORDER, "xchg"},
{0x88, BYTE_OPER_REG_OP_ORDER, "mov"},
{0x89, OPER_REG_OP_ORDER, "mov"},
{0x8A, BYTE_REG_OPER_OP_ORDER, "mov"},
{0x8B, REG_OPER_OP_ORDER, "mov"},
{0x8D, REG_OPER_OP_ORDER, "lea"},
{-1, UNSET_OP_ORDER, ""}};
static const ByteMnemonic zero_operands_instr[] = {
{0xC3, UNSET_OP_ORDER, "ret"}, {0xC9, UNSET_OP_ORDER, "leave"},
{0xF4, UNSET_OP_ORDER, "hlt"}, {0xFC, UNSET_OP_ORDER, "cld"},
{0xCC, UNSET_OP_ORDER, "int3"}, {0x60, UNSET_OP_ORDER, "pushad"},
{0x61, UNSET_OP_ORDER, "popad"}, {0x9C, UNSET_OP_ORDER, "pushfd"},
{0x9D, UNSET_OP_ORDER, "popfd"}, {0x9E, UNSET_OP_ORDER, "sahf"},
{0x99, UNSET_OP_ORDER, "cdq"}, {0x9B, UNSET_OP_ORDER, "fwait"},
{0xAB, UNSET_OP_ORDER, "stos"}, {0xA4, UNSET_OP_ORDER, "movs"},
{0xA5, UNSET_OP_ORDER, "movs"}, {0xA6, UNSET_OP_ORDER, "cmps"},
{0xA7, UNSET_OP_ORDER, "cmps"}, {-1, UNSET_OP_ORDER, ""}};
static const ByteMnemonic call_jump_instr[] = {{0xE8, UNSET_OP_ORDER, "call"},
{0xE9, UNSET_OP_ORDER, "jmp"},
{-1, UNSET_OP_ORDER, ""}};
static const ByteMnemonic short_immediate_instr[] = {
{0x05, UNSET_OP_ORDER, "add"}, {0x0D, UNSET_OP_ORDER, "or"},
{0x15, UNSET_OP_ORDER, "adc"}, {0x1D, UNSET_OP_ORDER, "sbb"},
{0x25, UNSET_OP_ORDER, "and"}, {0x2D, UNSET_OP_ORDER, "sub"},
{0x35, UNSET_OP_ORDER, "xor"}, {0x3D, UNSET_OP_ORDER, "cmp"},
{-1, UNSET_OP_ORDER, ""}};
static const char* const conditional_code_suffix[] = {
"o", "no", "c", "nc", "z", "nz", "na", "a",
"s", "ns", "pe", "po", "l", "ge", "le", "g"};
enum InstructionType {
NO_INSTR,
ZERO_OPERANDS_INSTR,
TWO_OPERANDS_INSTR,
JUMP_CONDITIONAL_SHORT_INSTR,
REGISTER_INSTR,
PUSHPOP_INSTR, // Has implicit 64-bit operand size.
MOVE_REG_INSTR,
CALL_JUMP_INSTR,
SHORT_IMMEDIATE_INSTR
};
enum Prefixes {
ESCAPE_PREFIX = 0x0F,
OPERAND_SIZE_OVERRIDE_PREFIX = 0x66,
ADDRESS_SIZE_OVERRIDE_PREFIX = 0x67,
VEX3_PREFIX = 0xC4,
VEX2_PREFIX = 0xC5,
LOCK_PREFIX = 0xF0,
REPNE_PREFIX = 0xF2,
REP_PREFIX = 0xF3,
REPEQ_PREFIX = REP_PREFIX
};
struct InstructionDesc {
const char* mnem;
InstructionType type;
OperandType op_order_;
bool byte_size_operation; // Fixed 8-bit operation.
};
class InstructionTable {
public:
InstructionTable();
const InstructionDesc& Get(byte x) const { return instructions_[x]; }
private:
InstructionDesc instructions_[256];
void Clear();
void Init();
void CopyTable(const ByteMnemonic bm[], InstructionType type);
void SetTableRange(InstructionType type, byte start, byte end, bool byte_size,
const char* mnem);
void AddJumpConditionalShort();
};
InstructionTable::InstructionTable() {
Clear();
Init();
}
void InstructionTable::Clear() {
for (int i = 0; i < 256; i++) {
instructions_[i].mnem = "(bad)";
instructions_[i].type = NO_INSTR;
instructions_[i].op_order_ = UNSET_OP_ORDER;
instructions_[i].byte_size_operation = false;
}
}
void InstructionTable::Init() {
CopyTable(two_operands_instr, TWO_OPERANDS_INSTR);
CopyTable(zero_operands_instr, ZERO_OPERANDS_INSTR);
CopyTable(call_jump_instr, CALL_JUMP_INSTR);
CopyTable(short_immediate_instr, SHORT_IMMEDIATE_INSTR);
AddJumpConditionalShort();
SetTableRange(PUSHPOP_INSTR, 0x50, 0x57, false, "push");
SetTableRange(PUSHPOP_INSTR, 0x58, 0x5F, false, "pop");
SetTableRange(MOVE_REG_INSTR, 0xB8, 0xBF, false, "mov");
}
void InstructionTable::CopyTable(const ByteMnemonic bm[],
InstructionType type) {
for (int i = 0; bm[i].b >= 0; i++) {
InstructionDesc* id = &instructions_[bm[i].b];
id->mnem = bm[i].mnem;
OperandType op_order = bm[i].op_order_;
id->op_order_ =
static_cast<OperandType>(op_order & ~BYTE_SIZE_OPERAND_FLAG);
DCHECK_EQ(NO_INSTR, id->type); // Information not already entered
id->type = type;
id->byte_size_operation = ((op_order & BYTE_SIZE_OPERAND_FLAG) != 0);
}
}
void InstructionTable::SetTableRange(InstructionType type, byte start, byte end,
bool byte_size, const char* mnem) {
for (byte b = start; b <= end; b++) {
InstructionDesc* id = &instructions_[b];
DCHECK_EQ(NO_INSTR, id->type); // Information not already entered
id->mnem = mnem;
id->type = type;
id->byte_size_operation = byte_size;
}
}
void InstructionTable::AddJumpConditionalShort() {
for (byte b = 0x70; b <= 0x7F; b++) {
InstructionDesc* id = &instructions_[b];
DCHECK_EQ(NO_INSTR, id->type); // Information not already entered
id->mnem = nullptr; // Computed depending on condition code.
id->type = JUMP_CONDITIONAL_SHORT_INSTR;
}
}
namespace {
DEFINE_LAZY_LEAKY_OBJECT_GETTER(InstructionTable, GetInstructionTable)
}
static const InstructionDesc cmov_instructions[16] = {
{"cmovo", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovno", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovc", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovnc", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovz", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovnz", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovna", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmova", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovs", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovns", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovpe", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovpo", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovl", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovge", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovle", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false},
{"cmovg", TWO_OPERANDS_INSTR, REG_OPER_OP_ORDER, false}};
namespace {
int8_t Imm8(const uint8_t* data) {
return *reinterpret_cast<const int8_t*>(data);
}
uint8_t Imm8_U(const uint8_t* data) {
return *reinterpret_cast<const uint8_t*>(data);
}
int16_t Imm16(const uint8_t* data) {
return v8::base::ReadUnalignedValue<int16_t>(
reinterpret_cast<v8::internal::Address>(data));
}
uint16_t Imm16_U(const uint8_t* data) {
return v8::base::ReadUnalignedValue<uint16_t>(
reinterpret_cast<v8::internal::Address>(data));
}
int32_t Imm32(const uint8_t* data) {
return v8::base::ReadUnalignedValue<int32_t>(
reinterpret_cast<v8::internal::Address>(data));
}
uint32_t Imm32_U(const uint8_t* data) {
return v8::base::ReadUnalignedValue<uint32_t>(
reinterpret_cast<v8::internal::Address>(data));
}
int64_t Imm64(const uint8_t* data) {
return v8::base::ReadUnalignedValue<int64_t>(
reinterpret_cast<v8::internal::Address>(data));
}
} // namespace
//------------------------------------------------------------------------------
// DisassemblerX64 implementation.
// A new DisassemblerX64 object is created to disassemble each instruction.
// The object can only disassemble a single instruction.
class DisassemblerX64 {
public:
DisassemblerX64(const NameConverter& converter,
Disassembler::UnimplementedOpcodeAction unimplemented_action)
: converter_(converter),
tmp_buffer_pos_(0),
abort_on_unimplemented_(unimplemented_action ==
Disassembler::kAbortOnUnimplementedOpcode),
rex_(0),
operand_size_(0),
group_1_prefix_(0),
vex_byte0_(0),
vex_byte1_(0),
vex_byte2_(0),
byte_size_operand_(false),
instruction_table_(GetInstructionTable()) {
tmp_buffer_[0] = '\0';
}
// Writes one disassembled instruction into 'buffer' (0-terminated).
// Returns the length of the disassembled machine instruction in bytes.
int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction);
private:
enum OperandSize {
OPERAND_BYTE_SIZE = 0,
OPERAND_WORD_SIZE = 1,
OPERAND_DOUBLEWORD_SIZE = 2,
OPERAND_QUADWORD_SIZE = 3
};
const NameConverter& converter_;
v8::internal::EmbeddedVector<char, 128> tmp_buffer_;
unsigned int tmp_buffer_pos_;
bool abort_on_unimplemented_;
// Prefixes parsed
byte rex_;
byte operand_size_; // 0x66 or (if no group 3 prefix is present) 0x0.
byte group_1_prefix_; // 0xF2, 0xF3, or (if no group 1 prefix is present) 0.
byte vex_byte0_; // 0xC4 or 0xC5
byte vex_byte1_;
byte vex_byte2_; // only for 3 bytes vex prefix
// Byte size operand override.
bool byte_size_operand_;
const InstructionTable* const instruction_table_;
void setRex(byte rex) {
DCHECK_EQ(0x40, rex & 0xF0);
rex_ = rex;
}
bool rex() { return rex_ != 0; }
bool rex_b() { return (rex_ & 0x01) != 0; }
// Actual number of base register given the low bits and the rex.b state.
int base_reg(int low_bits) { return low_bits | ((rex_ & 0x01) << 3); }
bool rex_x() { return (rex_ & 0x02) != 0; }
bool rex_r() { return (rex_ & 0x04) != 0; }
bool rex_w() { return (rex_ & 0x08) != 0; }
bool vex_w() {
DCHECK(vex_byte0_ == VEX3_PREFIX || vex_byte0_ == VEX2_PREFIX);
return vex_byte0_ == VEX3_PREFIX ? (vex_byte2_ & 0x80) != 0 : false;
}
bool vex_128() {
DCHECK(vex_byte0_ == VEX3_PREFIX || vex_byte0_ == VEX2_PREFIX);
byte checked = vex_byte0_ == VEX3_PREFIX ? vex_byte2_ : vex_byte1_;
return (checked & 4) == 0;
}
bool vex_none() {
DCHECK(vex_byte0_ == VEX3_PREFIX || vex_byte0_ == VEX2_PREFIX);
byte checked = vex_byte0_ == VEX3_PREFIX ? vex_byte2_ : vex_byte1_;
return (checked & 3) == 0;
}
bool vex_66() {
DCHECK(vex_byte0_ == VEX3_PREFIX || vex_byte0_ == VEX2_PREFIX);
byte checked = vex_byte0_ == VEX3_PREFIX ? vex_byte2_ : vex_byte1_;
return (checked & 3) == 1;
}
bool vex_f3() {
DCHECK(vex_byte0_ == VEX3_PREFIX || vex_byte0_ == VEX2_PREFIX);
byte checked = vex_byte0_ == VEX3_PREFIX ? vex_byte2_ : vex_byte1_;
return (checked & 3) == 2;
}
bool vex_f2() {
DCHECK(vex_byte0_ == VEX3_PREFIX || vex_byte0_ == VEX2_PREFIX);
byte checked = vex_byte0_ == VEX3_PREFIX ? vex_byte2_ : vex_byte1_;
return (checked & 3) == 3;
}
bool vex_0f() {
if (vex_byte0_ == VEX2_PREFIX) return true;
return (vex_byte1_ & 3) == 1;
}
bool vex_0f38() {
if (vex_byte0_ == VEX2_PREFIX) return false;
return (vex_byte1_ & 3) == 2;
}
bool vex_0f3a() {
if (vex_byte0_ == VEX2_PREFIX) return false;
return (vex_byte1_ & 3) == 3;
}
int vex_vreg() {
DCHECK(vex_byte0_ == VEX3_PREFIX || vex_byte0_ == VEX2_PREFIX);
byte checked = vex_byte0_ == VEX3_PREFIX ? vex_byte2_ : vex_byte1_;
return ~(checked >> 3) & 0xF;
}
OperandSize operand_size() {
if (byte_size_operand_) return OPERAND_BYTE_SIZE;
if (rex_w()) return OPERAND_QUADWORD_SIZE;
if (operand_size_ != 0) return OPERAND_WORD_SIZE;
return OPERAND_DOUBLEWORD_SIZE;
}
char operand_size_code() { return "bwlq"[operand_size()]; }
char float_size_code() { return "sd"[rex_w()]; }
const char* NameOfCPURegister(int reg) const {
return converter_.NameOfCPURegister(reg);
}
const char* NameOfByteCPURegister(int reg) const {
return converter_.NameOfByteCPURegister(reg);
}
const char* NameOfXMMRegister(int reg) const {
return converter_.NameOfXMMRegister(reg);
}
const char* NameOfAddress(byte* addr) const {
return converter_.NameOfAddress(addr);
}
// Disassembler helper functions.
void get_modrm(byte data, int* mod, int* regop, int* rm) {
*mod = (data >> 6) & 3;
*regop = ((data & 0x38) >> 3) | (rex_r() ? 8 : 0);
*rm = (data & 7) | (rex_b() ? 8 : 0);
}
void get_sib(byte data, int* scale, int* index, int* base) {
*scale = (data >> 6) & 3;
*index = ((data >> 3) & 7) | (rex_x() ? 8 : 0);
*base = (data & 7) | (rex_b() ? 8 : 0);
}
using RegisterNameMapping = const char* (DisassemblerX64::*)(int reg) const;
void TryAppendRootRelativeName(int offset);
int PrintRightOperandHelper(byte* modrmp, RegisterNameMapping register_name);
int PrintRightOperand(byte* modrmp);
int PrintRightByteOperand(byte* modrmp);
int PrintRightXMMOperand(byte* modrmp);
int PrintOperands(const char* mnem, OperandType op_order, byte* data);
int PrintImmediate(byte* data, OperandSize size);
int PrintImmediateOp(byte* data);
const char* TwoByteMnemonic(byte opcode);
int TwoByteOpcodeInstruction(byte* data);
int F6F7Instruction(byte* data);
int ShiftInstruction(byte* data);
int JumpShort(byte* data);
int JumpConditional(byte* data);
int JumpConditionalShort(byte* data);
int SetCC(byte* data);
int FPUInstruction(byte* data);
int MemoryFPUInstruction(int escape_opcode, int regop, byte* modrm_start);
int RegisterFPUInstruction(int escape_opcode, byte modrm_byte);
int AVXInstruction(byte* data);
PRINTF_FORMAT(2, 3) void AppendToBuffer(const char* format, ...);
void UnimplementedInstruction() {
if (abort_on_unimplemented_) {
FATAL("'Unimplemented Instruction'");
} else {
AppendToBuffer("'Unimplemented Instruction'");
}
}
};
void DisassemblerX64::AppendToBuffer(const char* format, ...) {
v8::internal::Vector<char> buf = tmp_buffer_ + tmp_buffer_pos_;
va_list args;
va_start(args, format);
int result = v8::internal::VSNPrintF(buf, format, args);
va_end(args);
tmp_buffer_pos_ += result;
}
void DisassemblerX64::TryAppendRootRelativeName(int offset) {
const char* maybe_name = converter_.RootRelativeName(offset);
if (maybe_name != nullptr) AppendToBuffer(" (%s)", maybe_name);
}
int DisassemblerX64::PrintRightOperandHelper(
byte* modrmp, RegisterNameMapping direct_register_name) {
int mod, regop, rm;
get_modrm(*modrmp, &mod, ®op, &rm);
RegisterNameMapping register_name =
(mod == 3) ? direct_register_name : &DisassemblerX64::NameOfCPURegister;
switch (mod) {
case 0:
if ((rm & 7) == 5) {
AppendToBuffer("[rip+0x%x]", Imm32(modrmp + 1));
return 5;
} else if ((rm & 7) == 4) {
// Codes for SIB byte.
byte sib = *(modrmp + 1);
int scale, index, base;
get_sib(sib, &scale, &index, &base);
if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) {
// index == rsp means no index. Only use sib byte with no index for
// rsp and r12 base.
AppendToBuffer("[%s]", NameOfCPURegister(base));
return 2;
} else if (base == 5) {
// base == rbp means no base register (when mod == 0).
int32_t disp = Imm32(modrmp + 2);
AppendToBuffer("[%s*%d%s0x%x]", NameOfCPURegister(index), 1 << scale,
disp < 0 ? "-" : "+", disp < 0 ? -disp : disp);
return 6;
} else if (index != 4 && base != 5) {
// [base+index*scale]
AppendToBuffer("[%s+%s*%d]", NameOfCPURegister(base),
NameOfCPURegister(index), 1 << scale);
return 2;
} else {
UnimplementedInstruction();
return 1;
}
} else {
AppendToBuffer("[%s]", NameOfCPURegister(rm));
return 1;
}
break;
case 1: // fall through
case 2:
if ((rm & 7) == 4) {
byte sib = *(modrmp + 1);
int scale, index, base;
get_sib(sib, &scale, &index, &base);
int disp = (mod == 2) ? Imm32(modrmp + 2) : Imm8(modrmp + 2);
if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) {
AppendToBuffer("[%s%s0x%x]", NameOfCPURegister(base),
disp < 0 ? "-" : "+", disp < 0 ? -disp : disp);
} else {
AppendToBuffer("[%s+%s*%d%s0x%x]", NameOfCPURegister(base),
NameOfCPURegister(index), 1 << scale,
disp < 0 ? "-" : "+", disp < 0 ? -disp : disp);
}
return mod == 2 ? 6 : 3;
} else {
// No sib.
int disp = (mod == 2) ? Imm32(modrmp + 1) : Imm8(modrmp + 1);
AppendToBuffer("[%s%s0x%x]", NameOfCPURegister(rm),
disp < 0 ? "-" : "+", disp < 0 ? -disp : disp);
if (rm == i::kRootRegister.code()) {
// For root-relative accesses, try to append a description.
TryAppendRootRelativeName(disp);
}
return (mod == 2) ? 5 : 2;
}
break;
case 3:
AppendToBuffer("%s", (this->*register_name)(rm));
return 1;
default:
UnimplementedInstruction();
return 1;
}
UNREACHABLE();
}
int DisassemblerX64::PrintImmediate(byte* data, OperandSize size) {
int64_t value;
int count;
switch (size) {
case OPERAND_BYTE_SIZE:
value = *data;
count = 1;
break;
case OPERAND_WORD_SIZE:
value = Imm16(data);
count = 2;
break;
case OPERAND_DOUBLEWORD_SIZE:
value = Imm32_U(data);
count = 4;
break;
case OPERAND_QUADWORD_SIZE:
value = Imm32(data);
count = 4;
break;
default:
UNREACHABLE();
}
AppendToBuffer("%" PRIx64, value);
return count;
}
int DisassemblerX64::PrintRightOperand(byte* modrmp) {
return PrintRightOperandHelper(modrmp, &DisassemblerX64::NameOfCPURegister);
}
int DisassemblerX64::PrintRightByteOperand(byte* modrmp) {
return PrintRightOperandHelper(modrmp,
&DisassemblerX64::NameOfByteCPURegister);
}
int DisassemblerX64::PrintRightXMMOperand(byte* modrmp) {
return PrintRightOperandHelper(modrmp, &DisassemblerX64::NameOfXMMRegister);
}
// Returns number of bytes used including the current *data.
// Writes instruction's mnemonic, left and right operands to 'tmp_buffer_'.
int DisassemblerX64::PrintOperands(const char* mnem, OperandType op_order,
byte* data) {
byte modrm = *data;
int mod, regop, rm;
get_modrm(modrm, &mod, ®op, &rm);
int advance = 0;
const char* register_name = byte_size_operand_ ? NameOfByteCPURegister(regop)
: NameOfCPURegister(regop);
switch (op_order) {
case REG_OPER_OP_ORDER: {
AppendToBuffer("%s%c %s,", mnem, operand_size_code(), register_name);
advance = byte_size_operand_ ? PrintRightByteOperand(data)
: PrintRightOperand(data);
break;
}
case OPER_REG_OP_ORDER: {
AppendToBuffer("%s%c ", mnem, operand_size_code());
advance = byte_size_operand_ ? PrintRightByteOperand(data)
: PrintRightOperand(data);
AppendToBuffer(",%s", register_name);
break;
}
default:
UNREACHABLE();
}
return advance;
}
// Returns number of bytes used by machine instruction, including *data byte.
// Writes immediate instructions to 'tmp_buffer_'.
int DisassemblerX64::PrintImmediateOp(byte* data) {
bool byte_size_immediate = (*data & 0x02) != 0;
byte modrm = *(data + 1);
int mod, regop, rm;
get_modrm(modrm, &mod, ®op, &rm);
const char* mnem = "Imm???";
switch (regop) {
case 0:
mnem = "add";
break;
case 1:
mnem = "or";
break;
case 2:
mnem = "adc";
break;
case 3:
mnem = "sbb";
break;
case 4:
mnem = "and";
break;
case 5:
mnem = "sub";
break;
case 6:
mnem = "xor";
break;
case 7:
mnem = "cmp";
break;
default:
UnimplementedInstruction();
}
AppendToBuffer("%s%c ", mnem, operand_size_code());
int count = PrintRightOperand(data + 1);
AppendToBuffer(",0x");
OperandSize immediate_size =
byte_size_immediate ? OPERAND_BYTE_SIZE : operand_size();
count += PrintImmediate(data + 1 + count, immediate_size);
return 1 + count;
}
// Returns number of bytes used, including *data.
int DisassemblerX64::F6F7Instruction(byte* data) {
DCHECK(*data == 0xF7 || *data == 0xF6);
byte modrm = *(data + 1);
int mod, regop, rm;
get_modrm(modrm, &mod, ®op, &rm);
if (regop != 0) {
const char* mnem = nullptr;
switch (regop) {
case 2:
mnem = "not";
break;
case 3:
mnem = "neg";
break;
case 4:
mnem = "mul";
break;
case 5:
mnem = "imul";
break;
case 6:
mnem = "div";
break;
case 7:
mnem = "idiv";
break;
default:
UnimplementedInstruction();
}
if (mod == 3) {
AppendToBuffer("%s%c %s", mnem, operand_size_code(),
NameOfCPURegister(rm));
return 2;
} else if (mod == 1) {
AppendToBuffer("%s%c ", mnem, operand_size_code());
int count = PrintRightOperand(data + 1); // Use name of 64-bit register.
return 1 + count;
} else {
UnimplementedInstruction();
return 2;
}
} else if (regop == 0) {
AppendToBuffer("test%c ", operand_size_code());
int count = PrintRightOperand(data + 1); // Use name of 64-bit register.
AppendToBuffer(",0x");
count += PrintImmediate(data + 1 + count, operand_size());
return 1 + count;
} else {
UnimplementedInstruction();
return 2;
}
}
int DisassemblerX64::ShiftInstruction(byte* data) {
byte op = *data & (~1);
int count = 1;
if (op != 0xD0 && op != 0xD2 && op != 0xC0) {
UnimplementedInstruction();
return count;
}
// Print mneumonic.
{
byte modrm = *(data + count);
int mod, regop, rm;
get_modrm(modrm, &mod, ®op, &rm);
regop &= 0x7; // The REX.R bit does not affect the operation.
const char* mnem = nullptr;
switch (regop) {
case 0:
mnem = "rol";
break;
case 1:
mnem = "ror";
break;
case 2:
mnem = "rcl";
break;
case 3:
mnem = "rcr";
break;
case 4:
mnem = "shl";
break;
case 5:
mnem = "shr";
break;
case 7:
mnem = "sar";
break;
default:
UnimplementedInstruction();
return count + 1;
}
DCHECK_NOT_NULL(mnem);
AppendToBuffer("%s%c ", mnem, operand_size_code());
}
count += PrintRightOperand(data + count);
if (op == 0xD2) {
AppendToBuffer(", cl");
} else {
int imm8 = -1;
if (op == 0xD0) {
imm8 = 1;
} else {
DCHECK_EQ(0xC0, op);
imm8 = *(data + count);
count++;
}
AppendToBuffer(", %d", imm8);
}
return count;
}
// Returns number of bytes used, including *data.
int DisassemblerX64::JumpShort(byte* data) {
DCHECK_EQ(0xEB, *data);
byte b = *(data + 1);
byte* dest = data + static_cast<int8_t>(b) + 2;
AppendToBuffer("jmp %s", NameOfAddress(dest));
return 2;
}
// Returns number of bytes used, including *data.
int DisassemblerX64::JumpConditional(byte* data) {
DCHECK_EQ(0x0F, *data);
byte cond = *(data + 1) & 0x0F;
byte* dest = data + Imm32(data + 2) + 6;
const char* mnem = conditional_code_suffix[cond];
AppendToBuffer("j%s %s", mnem, NameOfAddress(dest));
return 6; // includes 0x0F
}
// Returns number of bytes used, including *data.
int DisassemblerX64::JumpConditionalShort(byte* data) {
byte cond = *data & 0x0F;
byte b = *(data + 1);
byte* dest = data + static_cast<int8_t>(b) + 2;
const char* mnem = conditional_code_suffix[cond];
AppendToBuffer("j%s %s", mnem, NameOfAddress(dest));
return 2;
}
// Returns number of bytes used, including *data.
int DisassemblerX64::SetCC(byte* data) {
DCHECK_EQ(0x0F, *data);
byte cond = *(data + 1) & 0x0F;
const char* mnem = conditional_code_suffix[cond];
AppendToBuffer("set%s%c ", mnem, operand_size_code());
PrintRightByteOperand(data + 2);
return 3; // includes 0x0F
}
const char* sf_str[4] = {"", "rl", "ra", "ll"};
int DisassemblerX64::AVXInstruction(byte* data) {
byte opcode = *data;
byte* current = data + 1;
if (vex_66() && vex_0f38()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0x18:
AppendToBuffer("vbroadcastss %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x99:
AppendToBuffer("vfmadd132s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xA9:
AppendToBuffer("vfmadd213s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xB8:
AppendToBuffer("vfmadd231p%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xB9:
AppendToBuffer("vfmadd231s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x9B:
AppendToBuffer("vfmsub132s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xAB:
AppendToBuffer("vfmsub213s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xBB:
AppendToBuffer("vfmsub231s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xBC:
AppendToBuffer("vfnmadd231p%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x9D:
AppendToBuffer("vfnmadd132s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xAD:
AppendToBuffer("vfnmadd213s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xBD:
AppendToBuffer("vfnmadd231s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x9F:
AppendToBuffer("vfnmsub132s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xAF:
AppendToBuffer("vfnmsub213s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xBF:
AppendToBuffer("vfnmsub231s%c %s,%s,", float_size_code(),
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xF7:
AppendToBuffer("shlx%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
AppendToBuffer(",%s", NameOfCPURegister(vvvv));
break;
#define DECLARE_SSE_AVX_DIS_CASE(instruction, notUsed1, notUsed2, notUsed3, \
opcode) \
case 0x##opcode: { \
AppendToBuffer("v" #instruction " %s,%s,", NameOfXMMRegister(regop), \
NameOfXMMRegister(vvvv)); \
current += PrintRightXMMOperand(current); \
break; \
}
SSSE3_INSTRUCTION_LIST(DECLARE_SSE_AVX_DIS_CASE)
SSE4_INSTRUCTION_LIST(DECLARE_SSE_AVX_DIS_CASE)
SSE4_2_INSTRUCTION_LIST(DECLARE_SSE_AVX_DIS_CASE)
#undef DECLARE_SSE_AVX_DIS_CASE
#define DECLARE_SSE_PMOV_AVX_DIS_CASE(instruction, notUsed1, notUsed2, \
notUsed3, opcode) \
case 0x##opcode: { \
AppendToBuffer("v" #instruction " %s,", NameOfXMMRegister(regop)); \
current += PrintRightXMMOperand(current); \
break; \
}
SSE4_PMOV_INSTRUCTION_LIST(DECLARE_SSE_PMOV_AVX_DIS_CASE)
#undef DECLARE_SSE_PMOV_AVX_DIS_CASE
default:
UnimplementedInstruction();
}
} else if (vex_66() && vex_0f3a()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0x0A:
AppendToBuffer("vroundss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x0B:
AppendToBuffer("vroundsd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x0E:
AppendToBuffer("vpblendw %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x0F:
AppendToBuffer("vpalignr %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x14:
AppendToBuffer("vpextrb ");
current += PrintRightByteOperand(current);
AppendToBuffer(",%s,0x%x,", NameOfXMMRegister(regop), *current++);
break;
case 0x15:
AppendToBuffer("vpextrw ");
current += PrintRightOperand(current);
AppendToBuffer(",%s,0x%x,", NameOfXMMRegister(regop), *current++);
break;
case 0x16:
AppendToBuffer("vpextr%c ", rex_w() ? 'q' : 'd');
current += PrintRightOperand(current);
AppendToBuffer(",%s,0x%x,", NameOfXMMRegister(regop), *current++);
break;
case 0x17:
AppendToBuffer("vextractps ");
current += PrintRightOperand(current);
AppendToBuffer(",%s,0x%x,", NameOfXMMRegister(regop), *current++);
break;
case 0x20:
AppendToBuffer("vpinsrb %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightByteOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x21:
AppendToBuffer("vinsertps %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x22:
AppendToBuffer("vpinsr%c %s,%s,", rex_w() ? 'q' : 'd',
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x4B: {
AppendToBuffer("vblendvpd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister((*current++) >> 4));
break;
}
default:
UnimplementedInstruction();
}
} else if (vex_f3() && vex_0f()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0x10:
AppendToBuffer("vmovss %s,", NameOfXMMRegister(regop));
if (mod == 3) {
AppendToBuffer("%s,", NameOfXMMRegister(vvvv));
}
current += PrintRightXMMOperand(current);
break;
case 0x11:
AppendToBuffer("vmovss ");
current += PrintRightXMMOperand(current);
if (mod == 3) {
AppendToBuffer(",%s", NameOfXMMRegister(vvvv));
}
AppendToBuffer(",%s", NameOfXMMRegister(regop));
break;
case 0x2A:
AppendToBuffer("%s %s,%s,", vex_w() ? "vcvtqsi2ss" : "vcvtlsi2ss",
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightOperand(current);
break;
case 0x2C:
AppendToBuffer("vcvttss2si%s %s,", vex_w() ? "q" : "",
NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x51:
AppendToBuffer("vsqrtss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x58:
AppendToBuffer("vaddss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x59:
AppendToBuffer("vmulss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5A:
AppendToBuffer("vcvtss2sd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5C:
AppendToBuffer("vsubss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5D:
AppendToBuffer("vminss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5E:
AppendToBuffer("vdivss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5F:
AppendToBuffer("vmaxss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x6F:
AppendToBuffer("vmovdqu %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x7F:
AppendToBuffer("vmovdqu ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
break;
default:
UnimplementedInstruction();
}
} else if (vex_f2() && vex_0f()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0x10:
AppendToBuffer("vmovsd %s,", NameOfXMMRegister(regop));
if (mod == 3) {
AppendToBuffer("%s,", NameOfXMMRegister(vvvv));
}
current += PrintRightXMMOperand(current);
break;
case 0x11:
AppendToBuffer("vmovsd ");
current += PrintRightXMMOperand(current);
if (mod == 3) {
AppendToBuffer(",%s", NameOfXMMRegister(vvvv));
}
AppendToBuffer(",%s", NameOfXMMRegister(regop));
break;
case 0x12:
AppendToBuffer("vmovddup %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x2A:
AppendToBuffer("%s %s,%s,", vex_w() ? "vcvtqsi2sd" : "vcvtlsi2sd",
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightOperand(current);
break;
case 0x2C:
AppendToBuffer("vcvttsd2si%s %s,", vex_w() ? "q" : "",
NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x2D:
AppendToBuffer("vcvtsd2si%s %s,", vex_w() ? "q" : "",
NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x51:
AppendToBuffer("vsqrtsd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x58:
AppendToBuffer("vaddsd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x59:
AppendToBuffer("vmulsd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5A:
AppendToBuffer("vcvtsd2ss %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5C:
AppendToBuffer("vsubsd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5D:
AppendToBuffer("vminsd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5E:
AppendToBuffer("vdivsd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x5F:
AppendToBuffer("vmaxsd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0xF0:
AppendToBuffer("vlddqu %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x70:
AppendToBuffer("vpshuflw %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x7C:
AppendToBuffer("vhaddps %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
default:
UnimplementedInstruction();
}
} else if (vex_none() && vex_0f38()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
const char* mnem = "?";
switch (opcode) {
case 0xF2:
AppendToBuffer("andn%c %s,%s,", operand_size_code(),
NameOfCPURegister(regop), NameOfCPURegister(vvvv));
current += PrintRightOperand(current);
break;
case 0xF5:
AppendToBuffer("bzhi%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
AppendToBuffer(",%s", NameOfCPURegister(vvvv));
break;
case 0xF7:
AppendToBuffer("bextr%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
AppendToBuffer(",%s", NameOfCPURegister(vvvv));
break;
case 0xF3:
switch (regop) {
case 1:
mnem = "blsr";
break;
case 2:
mnem = "blsmsk";
break;
case 3:
mnem = "blsi";
break;
default:
UnimplementedInstruction();
}
AppendToBuffer("%s%c %s,", mnem, operand_size_code(),
NameOfCPURegister(vvvv));
current += PrintRightOperand(current);
mnem = "?";
break;
default:
UnimplementedInstruction();
}
} else if (vex_f2() && vex_0f38()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0xF5:
AppendToBuffer("pdep%c %s,%s,", operand_size_code(),
NameOfCPURegister(regop), NameOfCPURegister(vvvv));
current += PrintRightOperand(current);
break;
case 0xF6:
AppendToBuffer("mulx%c %s,%s,", operand_size_code(),
NameOfCPURegister(regop), NameOfCPURegister(vvvv));
current += PrintRightOperand(current);
break;
case 0xF7:
AppendToBuffer("shrx%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
AppendToBuffer(",%s", NameOfCPURegister(vvvv));
break;
default:
UnimplementedInstruction();
}
} else if (vex_f3() && vex_0f38()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0xF5:
AppendToBuffer("pext%c %s,%s,", operand_size_code(),
NameOfCPURegister(regop), NameOfCPURegister(vvvv));
current += PrintRightOperand(current);
break;
case 0xF7:
AppendToBuffer("sarx%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
AppendToBuffer(",%s", NameOfCPURegister(vvvv));
break;
default:
UnimplementedInstruction();
}
} else if (vex_f2() && vex_0f3a()) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0xF0:
AppendToBuffer("rorx%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
switch (operand_size()) {
case OPERAND_DOUBLEWORD_SIZE:
AppendToBuffer(",%d", *current & 0x1F);
break;
case OPERAND_QUADWORD_SIZE:
AppendToBuffer(",%d", *current & 0x3F);
break;
default:
UnimplementedInstruction();
}
current += 1;
break;
default:
UnimplementedInstruction();
}
} else if (vex_none() && vex_0f()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0x10:
AppendToBuffer("vmovups %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x11:
AppendToBuffer("vmovups ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
break;
case 0x16:
AppendToBuffer("vmovlhps %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x28:
AppendToBuffer("vmovaps %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x29:
AppendToBuffer("vmovaps ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
break;
case 0x2E:
AppendToBuffer("vucomiss %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x50:
AppendToBuffer("vmovmskps %s,", NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x51:
case 0x52:
case 0x53: {
const char* const pseudo_op[] = {"vsqrtps", "vrsqrtps", "vrcpps"};
AppendToBuffer("%s %s,", pseudo_op[opcode - 0x51],
NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
}
case 0x5A:
case 0x5B: {
const char* const pseudo_op[] = {"vcvtps2pd", "vcvtdq2ps"};
AppendToBuffer("%s %s,", pseudo_op[opcode - 0x5A],
NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
}
case 0x54:
case 0x55:
case 0x56:
case 0x57:
case 0x58:
case 0x59:
case 0x5C:
case 0x5D:
case 0x5E:
case 0x5F: {
const char* const pseudo_op[] = {
"vandps", "vandnps", "vorps", "vxorps", "vaddps", "vmulps",
"", "", "vsubps", "vminps", "vdivps", "vmaxps",
};
AppendToBuffer("%s %s,%s,", pseudo_op[opcode - 0x54],
NameOfXMMRegister(regop), NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
}
case 0xC2: {
AppendToBuffer("vcmpps %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
const char* const pseudo_op[] = {"eq", "lt", "le", "unord",
"neq", "nlt", "nle", "ord"};
AppendToBuffer(", (%s)", pseudo_op[*current]);
current += 1;
break;
}
case 0xC6: {
AppendToBuffer("vshufps %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
}
default:
UnimplementedInstruction();
}
} else if (vex_66() && vex_0f()) {
int mod, regop, rm, vvvv = vex_vreg();
get_modrm(*current, &mod, ®op, &rm);
switch (opcode) {
case 0x10:
AppendToBuffer("vmovupd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x11:
AppendToBuffer("vmovupd ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
break;
case 0x28:
AppendToBuffer("vmovapd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x29:
AppendToBuffer("vmovapd ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
break;
case 0x2E:
AppendToBuffer("vucomisd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x50:
AppendToBuffer("vmovmskpd %s,", NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
break;
case 0x54:
AppendToBuffer("vandpd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x56:
AppendToBuffer("vorpd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x57:
AppendToBuffer("vxorpd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
break;
case 0x6E:
AppendToBuffer("vmov%c %s,", vex_w() ? 'q' : 'd',
NameOfXMMRegister(regop));
current += PrintRightOperand(current);
break;
case 0x70:
AppendToBuffer("vpshufd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0x71:
AppendToBuffer("vps%sw %s,", sf_str[regop / 2],
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",%u", *current++);
break;
case 0x72:
AppendToBuffer("vps%sd %s,", sf_str[regop / 2],
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",%u", *current++);
break;
case 0x73:
AppendToBuffer("vps%sq %s,", sf_str[regop / 2],
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
AppendToBuffer(",%u", *current++);
break;
case 0x7E:
AppendToBuffer("vmov%c ", vex_w() ? 'q' : 'd');
current += PrintRightOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
break;
case 0xC2: {
AppendToBuffer("vcmppd %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightXMMOperand(current);
const char* const pseudo_op[] = {"eq", "lt", "le", "unord",
"neq", "nlt", "nle", "ord"};
AppendToBuffer(", (%s)", pseudo_op[*current]);
current += 1;
break;
}
case 0xC4:
AppendToBuffer("vpinsrw %s,%s,", NameOfXMMRegister(regop),
NameOfXMMRegister(vvvv));
current += PrintRightOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
case 0xC5:
AppendToBuffer("vpextrw %s,", NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current++);
break;
#define DECLARE_SSE_AVX_DIS_CASE(instruction, notUsed1, notUsed2, opcode) \
case 0x##opcode: { \
AppendToBuffer("v" #instruction " %s,%s,", NameOfXMMRegister(regop), \
NameOfXMMRegister(vvvv)); \
current += PrintRightXMMOperand(current); \
break; \
}
SSE2_INSTRUCTION_LIST(DECLARE_SSE_AVX_DIS_CASE)
#undef DECLARE_SSE_AVX_DIS_CASE
default:
UnimplementedInstruction();
}
} else {
UnimplementedInstruction();
}
return static_cast<int>(current - data);
}
// Returns number of bytes used, including *data.
int DisassemblerX64::FPUInstruction(byte* data) {
byte escape_opcode = *data;
DCHECK_EQ(0xD8, escape_opcode & 0xF8);
byte modrm_byte = *(data + 1);
if (modrm_byte >= 0xC0) {
return RegisterFPUInstruction(escape_opcode, modrm_byte);
} else {
return MemoryFPUInstruction(escape_opcode, modrm_byte, data + 1);
}
}
int DisassemblerX64::MemoryFPUInstruction(int escape_opcode, int modrm_byte,
byte* modrm_start) {
const char* mnem = "?";
int regop = (modrm_byte >> 3) & 0x7; // reg/op field of modrm byte.
switch (escape_opcode) {
case 0xD9:
switch (regop) {
case 0:
mnem = "fld_s";
break;
case 3:
mnem = "fstp_s";
break;
case 7:
mnem = "fstcw";
break;
default:
UnimplementedInstruction();
}
break;
case 0xDB:
switch (regop) {
case 0:
mnem = "fild_s";
break;
case 1:
mnem = "fisttp_s";
break;
case 2:
mnem = "fist_s";
break;
case 3:
mnem = "fistp_s";
break;
default:
UnimplementedInstruction();
}
break;
case 0xDD:
switch (regop) {
case 0:
mnem = "fld_d";
break;
case 3:
mnem = "fstp_d";
break;
default:
UnimplementedInstruction();
}
break;
case 0xDF:
switch (regop) {
case 5:
mnem = "fild_d";
break;
case 7:
mnem = "fistp_d";
break;
default:
UnimplementedInstruction();
}
break;
default:
UnimplementedInstruction();
}
AppendToBuffer("%s ", mnem);
int count = PrintRightOperand(modrm_start);
return count + 1;
}
int DisassemblerX64::RegisterFPUInstruction(int escape_opcode,
byte modrm_byte) {
bool has_register = false; // Is the FPU register encoded in modrm_byte?
const char* mnem = "?";
switch (escape_opcode) {
case 0xD8:
UnimplementedInstruction();
break;
case 0xD9:
switch (modrm_byte & 0xF8) {
case 0xC0:
mnem = "fld";
has_register = true;
break;
case 0xC8:
mnem = "fxch";
has_register = true;
break;
default:
switch (modrm_byte) {
case 0xE0:
mnem = "fchs";
break;
case 0xE1:
mnem = "fabs";
break;
case 0xE3:
mnem = "fninit";
break;
case 0xE4:
mnem = "ftst";
break;
case 0xE8:
mnem = "fld1";
break;
case 0xEB:
mnem = "fldpi";
break;
case 0xED:
mnem = "fldln2";
break;
case 0xEE:
mnem = "fldz";
break;
case 0xF0:
mnem = "f2xm1";
break;
case 0xF1:
mnem = "fyl2x";
break;
case 0xF2:
mnem = "fptan";
break;
case 0xF5:
mnem = "fprem1";
break;
case 0xF7:
mnem = "fincstp";
break;
case 0xF8:
mnem = "fprem";
break;
case 0xFC:
mnem = "frndint";
break;
case 0xFD:
mnem = "fscale";
break;
case 0xFE:
mnem = "fsin";
break;
case 0xFF:
mnem = "fcos";
break;
default:
UnimplementedInstruction();
}
}
break;
case 0xDA:
if (modrm_byte == 0xE9) {
mnem = "fucompp";
} else {
UnimplementedInstruction();
}
break;
case 0xDB:
if ((modrm_byte & 0xF8) == 0xE8) {
mnem = "fucomi";
has_register = true;
} else if (modrm_byte == 0xE2) {
mnem = "fclex";
} else if (modrm_byte == 0xE3) {
mnem = "fninit";
} else {
UnimplementedInstruction();
}
break;
case 0xDC:
has_register = true;
switch (modrm_byte & 0xF8) {
case 0xC0:
mnem = "fadd";
break;
case 0xE8:
mnem = "fsub";
break;
case 0xC8:
mnem = "fmul";
break;
case 0xF8:
mnem = "fdiv";
break;
default:
UnimplementedInstruction();
}
break;
case 0xDD:
has_register = true;
switch (modrm_byte & 0xF8) {
case 0xC0:
mnem = "ffree";
break;
case 0xD8:
mnem = "fstp";
break;
default:
UnimplementedInstruction();
}
break;
case 0xDE:
if (modrm_byte == 0xD9) {
mnem = "fcompp";
} else {
has_register = true;
switch (modrm_byte & 0xF8) {
case 0xC0:
mnem = "faddp";
break;
case 0xE8:
mnem = "fsubp";
break;
case 0xC8:
mnem = "fmulp";
break;
case 0xF8:
mnem = "fdivp";
break;
default:
UnimplementedInstruction();
}
}
break;
case 0xDF:
if (modrm_byte == 0xE0) {
mnem = "fnstsw_ax";
} else if ((modrm_byte & 0xF8) == 0xE8) {
mnem = "fucomip";
has_register = true;
}
break;
default:
UnimplementedInstruction();
}
if (has_register) {
AppendToBuffer("%s st%d", mnem, modrm_byte & 0x7);
} else {
AppendToBuffer("%s", mnem);
}
return 2;
}
// Handle all two-byte opcodes, which start with 0x0F.
// These instructions may be affected by an 0x66, 0xF2, or 0xF3 prefix.
// We do not use any three-byte opcodes, which start with 0x0F38 or 0x0F3A.
int DisassemblerX64::TwoByteOpcodeInstruction(byte* data) {
byte opcode = *(data + 1);
byte* current = data + 2;
// At return, "current" points to the start of the next instruction.
const char* mnemonic = TwoByteMnemonic(opcode);
if (operand_size_ == 0x66) {
// 0x66 0x0F prefix.
int mod, regop, rm;
if (opcode == 0x38) {
byte third_byte = *current;
current = data + 3;
get_modrm(*current, &mod, ®op, &rm);
switch (third_byte) {
case 0x15: {
AppendToBuffer("blendvpd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",<xmm0>");
break;
}
#define SSE34_DIS_CASE(instruction, notUsed1, notUsed2, notUsed3, opcode) \
case 0x##opcode: { \
AppendToBuffer(#instruction " %s,", NameOfXMMRegister(regop)); \
current += PrintRightXMMOperand(current); \
break; \
}
SSSE3_INSTRUCTION_LIST(SSE34_DIS_CASE)
SSE4_INSTRUCTION_LIST(SSE34_DIS_CASE)
SSE4_PMOV_INSTRUCTION_LIST(SSE34_DIS_CASE)
SSE4_2_INSTRUCTION_LIST(SSE34_DIS_CASE)
#undef SSE34_DIS_CASE
default:
UnimplementedInstruction();
}
} else if (opcode == 0x3A) {
byte third_byte = *current;
current = data + 3;
if (third_byte == 0x17) {
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("extractps "); // reg/m32, xmm, imm8
current += PrintRightOperand(current);
AppendToBuffer(",%s,%d", NameOfXMMRegister(regop), (*current) & 3);
current += 1;
} else if (third_byte == 0x0A) {
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("roundss %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", (*current) & 3);
current += 1;
} else if (third_byte == 0x0B) {
get_modrm(*current, &mod, ®op, &rm);
// roundsd xmm, xmm/m64, imm8
AppendToBuffer("roundsd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", (*current) & 3);
current += 1;
} else if (third_byte == 0x0E) {
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("pblendw %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current);
current += 1;
} else if (third_byte == 0x0F) {
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("palignr %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", (*current));
current += 1;
} else if (third_byte == 0x14) {
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("pextrb "); // reg/m32, xmm, imm8
current += PrintRightOperand(current);
AppendToBuffer(",%s,%d", NameOfXMMRegister(regop), (*current) & 3);
current += 1;
} else if (third_byte == 0x15) {
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("pextrw "); // reg/m32, xmm, imm8
current += PrintRightOperand(current);
AppendToBuffer(",%s,%d", NameOfXMMRegister(regop), (*current) & 7);
current += 1;
} else if (third_byte == 0x16) {
get_modrm(*current, &mod, ®op, &rm);
// reg/m32/reg/m64, xmm, imm8
AppendToBuffer("pextr%c ", rex_w() ? 'q' : 'd');
current += PrintRightOperand(current);
AppendToBuffer(",%s,%d", NameOfXMMRegister(regop), (*current) & 3);
current += 1;
} else if (third_byte == 0x20) {
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("pinsrb "); // xmm, reg/m32, imm8
AppendToBuffer(" %s,", NameOfXMMRegister(regop));
current += PrintRightOperand(current);
AppendToBuffer(",%d", (*current) & 3);
current += 1;
} else if (third_byte == 0x21) {
get_modrm(*current, &mod, ®op, &rm);
// insertps xmm, xmm/m32, imm8
AppendToBuffer("insertps %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", (*current));
current += 1;
} else if (third_byte == 0x22) {
get_modrm(*current, &mod, ®op, &rm);
// xmm, reg/m32/reg/m64, imm8
AppendToBuffer("pinsr%c ", rex_w() ? 'q' : 'd');
AppendToBuffer(" %s,", NameOfXMMRegister(regop));
current += PrintRightOperand(current);
AppendToBuffer(",%d", (*current) & 3);
current += 1;
} else {
UnimplementedInstruction();
}
} else if (opcode == 0xC1) {
current += PrintOperands("xadd", OPER_REG_OP_ORDER, current);
} else {
get_modrm(*current, &mod, ®op, &rm);
if (opcode == 0x1F) {
current++;
if (rm == 4) { // SIB byte present.
current++;
}
if (mod == 1) { // Byte displacement.
current += 1;
} else if (mod == 2) { // 32-bit displacement.
current += 4;
} // else no immediate displacement.
AppendToBuffer("nop");
} else if (opcode == 0x10) {
AppendToBuffer("movupd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x11) {
AppendToBuffer("movupd ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else if (opcode == 0x28) {
AppendToBuffer("movapd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x29) {
AppendToBuffer("movapd ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else if (opcode == 0x6E) {
AppendToBuffer("mov%c %s,", rex_w() ? 'q' : 'd',
NameOfXMMRegister(regop));
current += PrintRightOperand(current);
} else if (opcode == 0x6F) {
AppendToBuffer("movdqa %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x7E) {
AppendToBuffer("mov%c ", rex_w() ? 'q' : 'd');
current += PrintRightOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else if (opcode == 0x7F) {
AppendToBuffer("movdqa ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else if (opcode == 0xD6) {
AppendToBuffer("movq ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else if (opcode == 0x50) {
AppendToBuffer("movmskpd %s,", NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x70) {
AppendToBuffer("pshufd %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(",0x%x", *current);
current += 1;
} else if (opcode == 0x71) {
current += 1;
AppendToBuffer("ps%sw %s,%d", sf_str[regop / 2], NameOfXMMRegister(rm),
*current & 0x7F);
current += 1;
} else if (opcode == 0x72) {
current += 1;
AppendToBuffer("ps%sd %s,%d", sf_str[regop / 2], NameOfXMMRegister(rm),
*current & 0x7F);
current += 1;
} else if (opcode == 0x73) {
current += 1;
AppendToBuffer("ps%sq %s,%d", sf_str[regop / 2], NameOfXMMRegister(rm),
*current & 0x7F);
current += 1;
} else if (opcode == 0xB1) {
current += PrintOperands("cmpxchg", OPER_REG_OP_ORDER, current);
} else if (opcode == 0xC4) {
AppendToBuffer("pinsrw %s,", NameOfXMMRegister(regop));
current += PrintRightOperand(current);
AppendToBuffer(",0x%x", (*current) & 7);
current += 1;
} else {
const char* mnemonic;
if (opcode == 0x51) {
mnemonic = "sqrtpd";
} else if (opcode == 0x54) {
mnemonic = "andpd";
} else if (opcode == 0x55) {
mnemonic = "andnpd";
} else if (opcode == 0x56) {
mnemonic = "orpd";
} else if (opcode == 0x57) {
mnemonic = "xorpd";
} else if (opcode == 0x58) {
mnemonic = "addpd";
} else if (opcode == 0x59) {
mnemonic = "mulpd";
} else if (opcode == 0x5B) {
mnemonic = "cvtps2dq";
} else if (opcode == 0x5C) {
mnemonic = "subpd";
} else if (opcode == 0x5D) {
mnemonic = "minpd";
} else if (opcode == 0x5E) {
mnemonic = "divpd";
} else if (opcode == 0x5F) {
mnemonic = "maxpd";
} else if (opcode == 0x60) {
mnemonic = "punpcklbw";
} else if (opcode == 0x61) {
mnemonic = "punpcklwd";
} else if (opcode == 0x62) {
mnemonic = "punpckldq";
} else if (opcode == 0x63) {
mnemonic = "packsswb";
} else if (opcode == 0x64) {
mnemonic = "pcmpgtb";
} else if (opcode == 0x65) {
mnemonic = "pcmpgtw";
} else if (opcode == 0x66) {
mnemonic = "pcmpgtd";
} else if (opcode == 0x67) {
mnemonic = "packuswb";
} else if (opcode == 0x68) {
mnemonic = "punpckhbw";
} else if (opcode == 0x69) {
mnemonic = "punpckhwd";
} else if (opcode == 0x6A) {
mnemonic = "punpckhdq";
} else if (opcode == 0x6B) {
mnemonic = "packssdw";
} else if (opcode == 0x6C) {
mnemonic = "punpcklqdq";
} else if (opcode == 0x6D) {
mnemonic = "punpckhqdq";
} else if (opcode == 0x2E) {
mnemonic = "ucomisd";
} else if (opcode == 0x2F) {
mnemonic = "comisd";
} else if (opcode == 0x74) {
mnemonic = "pcmpeqb";
} else if (opcode == 0x75) {
mnemonic = "pcmpeqw";
} else if (opcode == 0x76) {
mnemonic = "pcmpeqd";
} else if (opcode == 0xC2) {
mnemonic = "cmppd";
} else if (opcode == 0xD1) {
mnemonic = "psrlw";
} else if (opcode == 0xD2) {
mnemonic = "psrld";
} else if (opcode == 0xD3) {
mnemonic = "psrlq";
} else if (opcode == 0xD4) {
mnemonic = "paddq";
} else if (opcode == 0xD5) {
mnemonic = "pmullw";
} else if (opcode == 0xD7) {
mnemonic = "pmovmskb";
} else if (opcode == 0xD8) {
mnemonic = "psubusb";
} else if (opcode == 0xD9) {
mnemonic = "psubusw";
} else if (opcode == 0xDA) {
mnemonic = "pminub";
} else if (opcode == 0xDB) {
mnemonic = "pand";
} else if (opcode == 0xDC) {
mnemonic = "paddusb";
} else if (opcode == 0xDD) {
mnemonic = "paddusw";
} else if (opcode == 0xDE) {
mnemonic = "pmaxub";
} else if (opcode == 0xE0) {
mnemonic = "pavgb";
} else if (opcode == 0xE1) {
mnemonic = "psraw";
} else if (opcode == 0xE2) {
mnemonic = "psrad";
} else if (opcode == 0xE3) {
mnemonic = "pavgw";
} else if (opcode == 0xE8) {
mnemonic = "psubsb";
} else if (opcode == 0xE9) {
mnemonic = "psubsw";
} else if (opcode == 0xEA) {
mnemonic = "pminsw";
} else if (opcode == 0xEB) {
mnemonic = "por";
} else if (opcode == 0xEC) {
mnemonic = "paddsb";
} else if (opcode == 0xED) {
mnemonic = "paddsw";
} else if (opcode == 0xEE) {
mnemonic = "pmaxsw";
} else if (opcode == 0xEF) {
mnemonic = "pxor";
} else if (opcode == 0xF1) {
mnemonic = "psllw";
} else if (opcode == 0xF2) {
mnemonic = "pslld";
} else if (opcode == 0xF3) {
mnemonic = "psllq";
} else if (opcode == 0xF4) {
mnemonic = "pmuludq";
} else if (opcode == 0xF8) {
mnemonic = "psubb";
} else if (opcode == 0xF9) {
mnemonic = "psubw";
} else if (opcode == 0xFA) {
mnemonic = "psubd";
} else if (opcode == 0xFB) {
mnemonic = "psubq";
} else if (opcode == 0xFC) {
mnemonic = "paddb";
} else if (opcode == 0xFD) {
mnemonic = "paddw";
} else if (opcode == 0xFE) {
mnemonic = "paddd";
} else {
UnimplementedInstruction();
}
AppendToBuffer("%s %s,", mnemonic, NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
if (opcode == 0xC2) {
const char* const pseudo_op[] = {"eq", "lt", "le", "unord",
"neq", "nlt", "nle", "ord"};
AppendToBuffer(", (%s)", pseudo_op[*current]);
current += 1;
}
}
}
} else if (group_1_prefix_ == 0xF2) {
// Beginning of instructions with prefix 0xF2.
if (opcode == 0x11 || opcode == 0x10) {
// MOVSD: Move scalar double-precision fp to/from/between XMM registers.
AppendToBuffer("movsd ");
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
if (opcode == 0x11) {
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else {
AppendToBuffer("%s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
}
} else if (opcode == 0x12) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movddup %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x2A) {
// CVTSI2SD: integer to XMM double conversion.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("%s %s,", mnemonic, NameOfXMMRegister(regop));
current += PrintRightOperand(current);
} else if (opcode == 0x2C) {
// CVTTSD2SI:
// Convert with truncation scalar double-precision FP to integer.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("cvttsd2si%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x2D) {
// CVTSD2SI: Convert scalar double-precision FP to integer.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("cvtsd2si%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x5B) {
// CVTTPS2DQ: Convert packed single-precision FP values to packed signed
// doubleword integer values
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("cvttps2dq%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
} else if ((opcode & 0xF8) == 0x58 || opcode == 0x51) {
// XMM arithmetic. Mnemonic was retrieved at the start of this function.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("%s %s,", mnemonic, NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x70) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("pshuflw %s, ", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(", %d", (*current) & 7);
current += 1;
} else if (opcode == 0xC2) {
// Intel manual 2A, Table 3-18.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
const char* const pseudo_op[] = {"cmpeqsd", "cmpltsd", "cmplesd",
"cmpunordsd", "cmpneqsd", "cmpnltsd",
"cmpnlesd", "cmpordsd"};
AppendToBuffer("%s %s,%s", pseudo_op[current[1]],
NameOfXMMRegister(regop), NameOfXMMRegister(rm));
current += 2;
} else if (opcode == 0xF0) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("lddqu %s,", NameOfXMMRegister(regop));
current += PrintRightOperand(current);
} else if (opcode == 0x7C) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("haddps %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else {
UnimplementedInstruction();
}
} else if (group_1_prefix_ == 0xF3) {
// Instructions with prefix 0xF3.
if (opcode == 0x11 || opcode == 0x10) {
// MOVSS: Move scalar double-precision fp to/from/between XMM registers.
AppendToBuffer("movss ");
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
if (opcode == 0x11) {
current += PrintRightOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else {
AppendToBuffer("%s,", NameOfXMMRegister(regop));
current += PrintRightOperand(current);
}
} else if (opcode == 0x2A) {
// CVTSI2SS: integer to XMM single conversion.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("%s %s,", mnemonic, NameOfXMMRegister(regop));
current += PrintRightOperand(current);
} else if (opcode == 0x2C) {
// CVTTSS2SI:
// Convert with truncation scalar single-precision FP to dword integer.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("cvttss2si%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x70) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("pshufhw %s, ", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(", %d", (*current) & 7);
current += 1;
} else if (opcode == 0x6F) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movdqu %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x7E) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movq %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x7F) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movdqu ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else if ((opcode & 0xF8) == 0x58 || opcode == 0x51) {
// XMM arithmetic. Mnemonic was retrieved at the start of this function.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("%s %s,", mnemonic, NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0xB8) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("popcnt%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
} else if (opcode == 0xBC) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("tzcnt%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
} else if (opcode == 0xBD) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("lzcnt%c %s,", operand_size_code(),
NameOfCPURegister(regop));
current += PrintRightOperand(current);
} else if (opcode == 0xC2) {
// Intel manual 2A, Table 3-18.
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
const char* const pseudo_op[] = {"cmpeqss", "cmpltss", "cmpless",
"cmpunordss", "cmpneqss", "cmpnltss",
"cmpnless", "cmpordss"};
AppendToBuffer("%s %s,%s", pseudo_op[current[1]],
NameOfXMMRegister(regop), NameOfXMMRegister(rm));
current += 2;
} else {
UnimplementedInstruction();
}
} else if (opcode == 0x10 || opcode == 0x11) {
// movups xmm, xmm/m128
// movups xmm/m128, xmm
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movups ");
if (opcode == 0x11) {
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else {
AppendToBuffer("%s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
}
} else if (opcode == 0x16) {
// movlhps xmm1, xmm2
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movlhps %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x1F) {
// NOP
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
current++;
if (rm == 4) { // SIB byte present.
current++;
}
if (mod == 1) { // Byte displacement.
current += 1;
} else if (mod == 2) { // 32-bit displacement.
current += 4;
} // else no immediate displacement.
AppendToBuffer("nop");
} else if (opcode == 0x28) {
// movaps xmm, xmm/m128
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movaps %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0x29) {
// movaps xmm/m128, xmm
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movaps ");
current += PrintRightXMMOperand(current);
AppendToBuffer(",%s", NameOfXMMRegister(regop));
} else if (opcode == 0x2E) {
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("ucomiss %s,", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0xA2) {
// CPUID
AppendToBuffer("%s", mnemonic);
} else if ((opcode & 0xF0) == 0x40) {
// CMOVcc: conditional move.
int condition = opcode & 0x0F;
const InstructionDesc& idesc = cmov_instructions[condition];
byte_size_operand_ = idesc.byte_size_operation;
current += PrintOperands(idesc.mnem, idesc.op_order_, current);
} else if (opcode >= 0x51 && opcode <= 0x5F) {
const char* const pseudo_op[] = {
"sqrtps", "rsqrtps", "rcpps", "andps", "andnps",
"orps", "xorps", "addps", "mulps", "cvtps2pd",
"cvtdq2ps", "subps", "minps", "divps", "maxps",
};
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("%s %s,", pseudo_op[opcode - 0x51],
NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
} else if (opcode == 0xC0) {
byte_size_operand_ = true;
current += PrintOperands("xadd", OPER_REG_OP_ORDER, current);
} else if (opcode == 0xC1) {
current += PrintOperands("xadd", OPER_REG_OP_ORDER, current);
} else if (opcode == 0xC2) {
// cmpps xmm, xmm/m128, imm8
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
const char* const pseudo_op[] = {"eq", "lt", "le", "unord",
"neq", "nlt", "nle", "ord"};
AppendToBuffer("cmpps %s, ", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(", %s", pseudo_op[*current]);
current += 1;
} else if (opcode == 0xC6) {
// shufps xmm, xmm/m128, imm8
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("shufps %s, ", NameOfXMMRegister(regop));
current += PrintRightXMMOperand(current);
AppendToBuffer(", %d", (*current) & 3);
current += 1;
} else if (opcode >= 0xC8 && opcode <= 0xCF) {
// bswap
int reg = (opcode - 0xC8) | (rex_r() ? 8 : 0);
AppendToBuffer("bswap%c %s", operand_size_code(), NameOfCPURegister(reg));
} else if (opcode == 0x50) {
// movmskps reg, xmm
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("movmskps %s,", NameOfCPURegister(regop));
current += PrintRightXMMOperand(current);
} else if ((opcode & 0xF0) == 0x80) {
// Jcc: Conditional jump (branch).
current = data + JumpConditional(data);
} else if (opcode == 0xBE || opcode == 0xBF || opcode == 0xB6 ||
opcode == 0xB7 || opcode == 0xAF) {
// Size-extending moves, IMUL.
current += PrintOperands(mnemonic, REG_OPER_OP_ORDER, current);
} else if ((opcode & 0xF0) == 0x90) {
// SETcc: Set byte on condition. Needs pointer to beginning of instruction.
current = data + SetCC(data);
} else if (opcode == 0xA3 || opcode == 0xA5 || opcode == 0xAB ||
opcode == 0xAD) {
// BT (bit test), SHLD, BTS (bit test and set),
// SHRD (double-precision shift)
AppendToBuffer("%s ", mnemonic);
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
current += PrintRightOperand(current);
if (opcode == 0xAB) {
AppendToBuffer(",%s", NameOfCPURegister(regop));
} else {
AppendToBuffer(",%s,cl", NameOfCPURegister(regop));
}
} else if (opcode == 0xBA) {
// BTS / BTR (bit test and set/reset) with immediate
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
mnemonic = regop == 5 ? "bts" : regop == 6 ? "btr" : "?";
AppendToBuffer("%s ", mnemonic);
current += PrintRightOperand(current);
AppendToBuffer(",%d", *current++);
} else if (opcode == 0xB8 || opcode == 0xBC || opcode == 0xBD) {
// POPCNT, CTZ, CLZ.
AppendToBuffer("%s%c ", mnemonic, operand_size_code());
int mod, regop, rm;
get_modrm(*current, &mod, ®op, &rm);
AppendToBuffer("%s,", NameOfCPURegister(regop));
current += PrintRightOperand(current);
} else if (opcode == 0x0B) {
AppendToBuffer("ud2");
} else if (opcode == 0xB0 || opcode == 0xB1) {
// CMPXCHG.
if (opcode == 0xB0) {
byte_size_operand_ = true;
}
current += PrintOperands(mnemonic, OPER_REG_OP_ORDER, current);
} else if (opcode == 0xAE && (data[2] & 0xF8) == 0xF0) {
AppendToBuffer("mfence");
current = data + 3;
} else if (opcode == 0xAE && (data[2] & 0xF8) == 0xE8) {
AppendToBuffer("lfence");
current = data + 3;
} else {
UnimplementedInstruction();
}
return static_cast<int>(current - data);
}
// Mnemonics for two-byte opcode instructions starting with 0x0F.
// The argument is the second byte of the two-byte opcode.
// Returns nullptr if the instruction is not handled here.
const char* DisassemblerX64::TwoByteMnemonic(byte opcode) {
if (opcode >= 0xC8 && opcode <= 0xCF) return "bswap";
switch (opcode) {
case 0x1F:
return "nop";
case 0x2A: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "cvtsi2sd" : "cvtsi2ss";
case 0x51: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "sqrtsd" : "sqrtss";
case 0x58: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "addsd" : "addss";
case 0x59: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "mulsd" : "mulss";
case 0x5A: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "cvtsd2ss" : "cvtss2sd";
case 0x5B: // F2/F3 prefix.
return "cvttps2dq";
case 0x5D: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "minsd" : "minss";
case 0x5C: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "subsd" : "subss";
case 0x5E: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "divsd" : "divss";
case 0x5F: // F2/F3 prefix.
return (group_1_prefix_ == 0xF2) ? "maxsd" : "maxss";
case 0xA2:
return "cpuid";
case 0xA3:
return "bt";
case 0xA5:
return "shld";
case 0xAB:
return "bts";
case 0xAD:
return "shrd";
case 0xAF:
return "imul";
case 0xB0:
case 0xB1:
return "cmpxchg";
case 0xB6:
return "movzxb";
case 0xB7:
return "movzxw";
case 0xBC:
return "bsf";
case 0xBD:
return "bsr";
case 0xBE:
return "movsxb";
case 0xBF:
return "movsxw";
default:
return nullptr;
}
}
// Disassembles the instruction at instr, and writes it into out_buffer.
int DisassemblerX64::InstructionDecode(v8::internal::Vector<char> out_buffer,
byte* instr) {
tmp_buffer_pos_ = 0; // starting to write as position 0
byte* data = instr;
bool processed = true; // Will be set to false if the current instruction
// is not in 'instructions' table.
byte current;
// Scan for prefixes.
while (true) {
current = *data;
if (current == OPERAND_SIZE_OVERRIDE_PREFIX) { // Group 3 prefix.
operand_size_ = current;
} else if ((current & 0xF0) == 0x40) { // REX prefix.
setRex(current);
if (rex_w()) AppendToBuffer("REX.W ");
} else if ((current & 0xFE) == 0xF2) { // Group 1 prefix (0xF2 or 0xF3).
group_1_prefix_ = current;
} else if (current == LOCK_PREFIX) {
AppendToBuffer("lock ");
} else if (current == VEX3_PREFIX) {
vex_byte0_ = current;
vex_byte1_ = *(data + 1);
vex_byte2_ = *(data + 2);
setRex(0x40 | (~(vex_byte1_ >> 5) & 7) | ((vex_byte2_ >> 4) & 8));
data += 3;
break; // Vex is the last prefix.
} else if (current == VEX2_PREFIX) {
vex_byte0_ = current;
vex_byte1_ = *(data + 1);
setRex(0x40 | (~(vex_byte1_ >> 5) & 4));
data += 2;
break; // Vex is the last prefix.
} else { // Not a prefix - an opcode.
break;
}
data++;
}
// Decode AVX instructions.
if (vex_byte0_ != 0) {
processed = true;
data += AVXInstruction(data);
} else {
const InstructionDesc& idesc = instruction_table_->Get(current);
byte_size_operand_ = idesc.byte_size_operation;
switch (idesc.type) {
case ZERO_OPERANDS_INSTR:
if ((current >= 0xA4 && current <= 0xA7) ||
(current >= 0xAA && current <= 0xAD)) {
// String move or compare operations.
if (group_1_prefix_ == REP_PREFIX) {
// REP.
AppendToBuffer("rep ");
}
AppendToBuffer("%s%c", idesc.mnem, operand_size_code());
} else {
AppendToBuffer("%s%c", idesc.mnem, operand_size_code());
}
data++;
break;
case TWO_OPERANDS_INSTR:
data++;
data += PrintOperands(idesc.mnem, idesc.op_order_, data);
break;
case JUMP_CONDITIONAL_SHORT_INSTR:
data += JumpConditionalShort(data);
break;
case REGISTER_INSTR:
AppendToBuffer("%s%c %s", idesc.mnem, operand_size_code(),
NameOfCPURegister(base_reg(current & 0x07)));
data++;
break;
case PUSHPOP_INSTR:
AppendToBuffer("%s %s", idesc.mnem,
NameOfCPURegister(base_reg(current & 0x07)));
data++;
break;
case MOVE_REG_INSTR: {
byte* addr = nullptr;
switch (operand_size()) {
case OPERAND_WORD_SIZE:
addr = reinterpret_cast<byte*>(Imm16(data + 1));
data += 3;
break;
case OPERAND_DOUBLEWORD_SIZE:
addr = reinterpret_cast<byte*>(Imm32_U(data + 1));
data += 5;
break;
case OPERAND_QUADWORD_SIZE:
addr = reinterpret_cast<byte*>(Imm64(data + 1));
data += 9;
break;
default:
UNREACHABLE();
}
AppendToBuffer("mov%c %s,%s", operand_size_code(),
NameOfCPURegister(base_reg(current & 0x07)),
NameOfAddress(addr));
break;
}
case CALL_JUMP_INSTR: {
byte* addr = data + Imm32(data + 1) + 5;
AppendToBuffer("%s %s", idesc.mnem, NameOfAddress(addr));
data += 5;
break;
}
case SHORT_IMMEDIATE_INSTR: {
int32_t imm;
if (operand_size() == OPERAND_WORD_SIZE) {
imm = Imm16(data + 1);
data += 3;
} else {
imm = Imm32(data + 1);
data += 5;
}
AppendToBuffer("%s rax,0x%x", idesc.mnem, imm);
break;
}
case NO_INSTR:
processed = false;
break;
default:
UNIMPLEMENTED(); // This type is not implemented.
}
}
// The first byte didn't match any of the simple opcodes, so we
// need to do special processing on it.
if (!processed) {
switch (*data) {
case 0xC2:
AppendToBuffer("ret 0x%x", Imm16_U(data + 1));
data += 3;
break;
case 0x69: // fall through
case 0x6B: {
int count = 1;
count += PrintOperands("imul", REG_OPER_OP_ORDER, data + count);
AppendToBuffer(",0x");
if (*data == 0x69) {
count += PrintImmediate(data + count, operand_size());
} else {
count += PrintImmediate(data + count, OPERAND_BYTE_SIZE);
}
data += count;
break;
}
case 0x81: // fall through
case 0x83: // 0x81 with sign extension bit set
data += PrintImmediateOp(data);
break;
case 0x0F:
data += TwoByteOpcodeInstruction(data);
break;
case 0x8F: {
data++;
int mod, regop, rm;
get_modrm(*data, &mod, ®op, &rm);
if (regop == 0) {
AppendToBuffer("pop ");
data += PrintRightOperand(data);
}
} break;
case 0xFF: {
data++;
int mod, regop, rm;
get_modrm(*data, &mod, ®op, &rm);
const char* mnem = nullptr;
switch (regop) {
case 0:
mnem = "inc";
break;
case 1:
mnem = "dec";
break;
case 2:
mnem = "call";
break;
case 4:
mnem = "jmp";
break;
case 6:
mnem = "push";
break;
default:
mnem = "???";
}
if (regop <= 1) {
AppendToBuffer("%s%c ", mnem, operand_size_code());
} else {
AppendToBuffer("%s ", mnem);
}
data += PrintRightOperand(data);
} break;
case 0xC7: // imm32, fall through
case 0xC6: // imm8
{
bool is_byte = *data == 0xC6;
data++;
if (is_byte) {
AppendToBuffer("movb ");
data += PrintRightByteOperand(data);
int32_t imm = *data;
AppendToBuffer(",0x%x", imm);
data++;
} else {
AppendToBuffer("mov%c ", operand_size_code());
data += PrintRightOperand(data);
if (operand_size() == OPERAND_WORD_SIZE) {
AppendToBuffer(",0x%x", Imm16(data));
data += 2;
} else {
AppendToBuffer(",0x%x", Imm32(data));
data += 4;
}
}
} break;
case 0x80: {
data++;
AppendToBuffer("cmpb ");
data += PrintRightByteOperand(data);
int32_t imm = *data;
AppendToBuffer(",0x%x", imm);
data++;
} break;
case 0x88: // 8bit, fall through
case 0x89: // 32bit
{
bool is_byte = *data == 0x88;
int mod, regop, rm;
data++;
get_modrm(*data, &mod, ®op, &rm);
if (is_byte) {
AppendToBuffer("movb ");
data += PrintRightByteOperand(data);
AppendToBuffer(",%s", NameOfByteCPURegister(regop));
} else {
AppendToBuffer("mov%c ", operand_size_code());
data += PrintRightOperand(data);
AppendToBuffer(",%s", NameOfCPURegister(regop));
}
} break;
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97: {
int reg = (*data & 0x7) | (rex_b() ? 8 : 0);
if (group_1_prefix_ == 0xF3 && *data == 0x90) {
AppendToBuffer("pause");
} else if (reg == 0) {
AppendToBuffer("nop"); // Common name for xchg rax,rax.
} else {
AppendToBuffer("xchg%c rax,%s", operand_size_code(),
NameOfCPURegister(reg));
}
data++;
} break;
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: {
// mov reg8,imm8 or mov reg32,imm32
byte opcode = *data;
data++;
bool is_32bit = (opcode >= 0xB8);
int reg = (opcode & 0x7) | (rex_b() ? 8 : 0);
if (is_32bit) {
AppendToBuffer("mov%c %s,", operand_size_code(),
NameOfCPURegister(reg));
data += PrintImmediate(data, OPERAND_DOUBLEWORD_SIZE);
} else {
AppendToBuffer("movb %s,", NameOfByteCPURegister(reg));
data += PrintImmediate(data, OPERAND_BYTE_SIZE);
}
break;
}
case 0xFE: {
data++;
int mod, regop, rm;
get_modrm(*data, &mod, ®op, &rm);
if (regop == 1) {
AppendToBuffer("decb ");
data += PrintRightByteOperand(data);
} else {
UnimplementedInstruction();
}
break;
}
case 0x68:
AppendToBuffer("push 0x%x", Imm32(data + 1));
data += 5;
break;
case 0x6A:
AppendToBuffer("push 0x%x", Imm8(data + 1));
data += 2;
break;
case 0xA1: // Fall through.
case 0xA3:
switch (operand_size()) {
case OPERAND_DOUBLEWORD_SIZE: {
const char* memory_location =
NameOfAddress(reinterpret_cast<byte*>(Imm32(data + 1)));
if (*data == 0xA1) { // Opcode 0xA1
AppendToBuffer("movzxlq rax,(%s)", memory_location);
} else { // Opcode 0xA3
AppendToBuffer("movzxlq (%s),rax", memory_location);
}
data += 5;
break;
}
case OPERAND_QUADWORD_SIZE: {
// New x64 instruction mov rax,(imm_64).
const char* memory_location =
NameOfAddress(reinterpret_cast<byte*>(Imm64(data + 1)));
if (*data == 0xA1) { // Opcode 0xA1
AppendToBuffer("movq rax,(%s)", memory_location);
} else { // Opcode 0xA3
AppendToBuffer("movq (%s),rax", memory_location);
}
data += 9;
break;
}
default:
UnimplementedInstruction();
data += 2;
}
break;
case 0xA8:
AppendToBuffer("test al,0x%x", Imm8_U(data + 1));
data += 2;
break;
case 0xA9: {
int64_t value = 0;
switch (operand_size()) {
case OPERAND_WORD_SIZE:
value = Imm16_U(data + 1);
data += 3;
break;
case OPERAND_DOUBLEWORD_SIZE:
value = Imm32_U(data + 1);
data += 5;
break;
case OPERAND_QUADWORD_SIZE:
value = Imm32(data + 1);
data += 5;
break;
default:
UNREACHABLE();
}
AppendToBuffer("test%c rax,0x%" PRIx64, operand_size_code(), value);
break;
}
case 0xD1: // fall through
case 0xD3: // fall through
case 0xC1:
data += ShiftInstruction(data);
break;
case 0xD0: // fall through
case 0xD2: // fall through
case 0xC0:
byte_size_operand_ = true;
data += ShiftInstruction(data);
break;
case 0xD9: // fall through
case 0xDA: // fall through
case 0xDB: // fall through
case 0xDC: // fall through
case 0xDD: // fall through
case 0xDE: // fall through
case 0xDF:
data += FPUInstruction(data);
break;
case 0xEB:
data += JumpShort(data);
break;
case 0xF6:
byte_size_operand_ = true;
V8_FALLTHROUGH;
case 0xF7:
data += F6F7Instruction(data);
break;
case 0x3C:
AppendToBuffer("cmp al,0x%x", Imm8(data + 1));
data += 2;
break;
default:
UnimplementedInstruction();
data += 1;
}
} // !processed
if (tmp_buffer_pos_ < sizeof tmp_buffer_) {
tmp_buffer_[tmp_buffer_pos_] = '\0';
}
int instr_len = static_cast<int>(data - instr);
DCHECK_GT(instr_len, 0); // Ensure progress.
int outp = 0;
// Instruction bytes.
for (byte* bp = instr; bp < data; bp++) {
outp += v8::internal::SNPrintF(out_buffer + outp, "%02x", *bp);
}
for (int i = 6 - instr_len; i >= 0; i--) {
outp += v8::internal::SNPrintF(out_buffer + outp, " ");
}
outp += v8::internal::SNPrintF(out_buffer + outp, " %s", tmp_buffer_.begin());
return instr_len;
}
//------------------------------------------------------------------------------
static const char* const cpu_regs[16] = {
"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"};
static const char* const byte_cpu_regs[16] = {
"al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
"r8l", "r9l", "r10l", "r11l", "r12l", "r13l", "r14l", "r15l"};
static const char* const xmm_regs[16] = {
"xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
"xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"};
const char* NameConverter::NameOfAddress(byte* addr) const {
v8::internal::SNPrintF(tmp_buffer_, "%p", static_cast<void*>(addr));
return tmp_buffer_.begin();
}
const char* NameConverter::NameOfConstant(byte* addr) const {
return NameOfAddress(addr);
}
const char* NameConverter::NameOfCPURegister(int reg) const {
if (0 <= reg && reg < 16) return cpu_regs[reg];
return "noreg";
}
const char* NameConverter::NameOfByteCPURegister(int reg) const {
if (0 <= reg && reg < 16) return byte_cpu_regs[reg];
return "noreg";
}
const char* NameConverter::NameOfXMMRegister(int reg) const {
if (0 <= reg && reg < 16) return xmm_regs[reg];
return "noxmmreg";
}
const char* NameConverter::NameInCode(byte* addr) const {
// X64 does not embed debug strings at the moment.
UNREACHABLE();
}
//------------------------------------------------------------------------------
int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer,
byte* instruction) {
DisassemblerX64 d(converter_, unimplemented_opcode_action());
return d.InstructionDecode(buffer, instruction);
}
// The X64 assembler does not use constant pools.
int Disassembler::ConstantPoolSizeAt(byte* instruction) { return -1; }
void Disassembler::Disassemble(FILE* f, byte* begin, byte* end,
UnimplementedOpcodeAction unimplemented_action) {
NameConverter converter;
Disassembler d(converter, unimplemented_action);
for (byte* pc = begin; pc < end;) {
v8::internal::EmbeddedVector<char, 128> buffer;
buffer[0] = '\0';
byte* prev_pc = pc;
pc += d.InstructionDecode(buffer, pc);
fprintf(f, "%p", static_cast<void*>(prev_pc));
fprintf(f, " ");
for (byte* bp = prev_pc; bp < pc; bp++) {
fprintf(f, "%02x", *bp);
}
for (int i = 6 - static_cast<int>(pc - prev_pc); i >= 0; i--) {
fprintf(f, " ");
}
fprintf(f, " %s\n", buffer.begin());
}
}
} // namespace disasm
#endif // V8_TARGET_ARCH_X64
| [
"snomile@me.com"
] | snomile@me.com |
2248902715e2ab9a8369bc951de127a4a19a6325 | fc5b17582261cba8d2fb8f96de9dae4189a17dab | /TacticsEngine/Component_Base.h | c21bfd1916e45d08bf7d9b10b40d28889b22beb6 | [] | no_license | lobster22221/tacticsPC2 | ad2fce83b28299a89982fd1c8883e10a6e3ad2f8 | c3adafb42cea08fae3c1c187cd0fdc36d6a23deb | refs/heads/master | 2021-09-01T18:15:21.632034 | 2017-12-21T14:33:22 | 2017-12-21T14:33:22 | 114,460,206 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 111 | h | #pragma once
namespace ECS
{
class Component_Base
{
public:
Component_Base();
~Component_Base();
};
}
| [
"lobster22221@yahoo.com"
] | lobster22221@yahoo.com |
4b580680ce238ae554aa239974f54bf6ba8e304b | 7b7a3f9e0cac33661b19bdfcb99283f64a455a13 | /Engine/dll/Assimp/include/BoostWorkaround/boost/tuple/tuple.hpp | 49dcb519717d3f856f138e508f5591676a3a9a06 | [] | no_license | grimtraveller/fluxengine | 62bc0169d90bfe656d70e68615186bd60ab561b0 | 8c967eca99c2ce92ca4186a9ca00c2a9b70033cd | refs/heads/master | 2021-01-10T10:58:56.217357 | 2009-09-01T15:07:05 | 2009-09-01T15:07:05 | 55,775,414 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 7,882 | hpp | // A very small replacement for boost::tuple
// (c) Alexander Gessler, 2008
#ifndef BOOST_TUPLE_INCLUDED
#define BOOST_TUPLE_INCLUDED
namespace boost {
namespace detail {
// Represents an empty tuple slot (up to 5 supported)
struct nulltype {};
// For readable error messages
struct tuple_component_idx_out_of_bounds;
// To share some code for the const/nonconst versions of the getters
template <bool b, typename T>
struct ConstIf {
typedef T t;
};
template <typename T>
struct ConstIf<true,T> {
typedef const T t;
};
template <typename, unsigned, typename, bool, unsigned>
struct value_getter;
template <typename T, unsigned NIDX, typename TNEXT >
struct list_elem_base {
// Store template parameters
typedef TNEXT next_type;
typedef T type;
static const unsigned nidx = NIDX;
};
// Represents an element in the tuple component list
template <typename T, unsigned NIDX, typename TNEXT >
struct list_elem : list_elem_base<T,NIDX,TNEXT>{
// Real members
T me;
TNEXT next;
// Get the value of a specific tuple element
template <unsigned N>
T& get () {
value_getter <T,NIDX,TNEXT,false,N> s;
return s(*this);
}
// Get the value of a specific tuple element
template <unsigned N>
const T& get () const {
value_getter <T,NIDX,TNEXT,true,N> s;
return s(*this);
}
// Assign a value to the tuple element
template <typename T2, typename TNEXT2> /* requires convertible(T2,T) */
list_elem& operator = (const list_elem<T2,NIDX,TNEXT2>& other) {
me = (T)other.me;
next = other.next;
return *this;
}
// Recursively compare two elements
bool operator == (const list_elem& s) const {
return (me == s.me && next == s.next);
}
};
// Represents a non-used tuple element - the very last element processed
template <typename TNEXT, unsigned NIDX >
struct list_elem<nulltype,NIDX,TNEXT> : list_elem_base<nulltype,NIDX,TNEXT> {
template <unsigned N, bool IS_CONST = true> struct value_getter {
/* just dummy members to produce readable error messages */
tuple_component_idx_out_of_bounds operator () (typename ConstIf<IS_CONST,list_elem>::t& me);
};
template <unsigned N> struct type_getter {
/* just dummy members to produce readable error messages */
typedef tuple_component_idx_out_of_bounds type;
};
// dummy
list_elem& operator = (const list_elem& other) {
return *this;
}
// dummy
bool operator == (const list_elem& other) {
return true;
}
};
// Represents the absolute end of the list
typedef list_elem<nulltype,0,int> list_end;
// Helper obtain to query the value of a tuple element
// NOTE: Could be a nested class, but afaik it's non-standard and at least
// MSVC isn't able to evaluate the partial specialization correctly.
template <typename T, unsigned NIDX, typename TNEXT, bool IS_CONST, unsigned N>
struct value_getter {
// calling list_elem
typedef list_elem<T,NIDX,TNEXT> outer_elem;
// typedef for the getter for next element
typedef value_getter<typename TNEXT::type,NIDX+1,typename TNEXT::next_type,
IS_CONST, N> next_value_getter;
typename ConstIf<IS_CONST,T>::t& operator () (typename ConstIf<IS_CONST,outer_elem >::t& me) {
next_value_getter s;
return s(me.next);
}
};
template <typename T, unsigned NIDX, typename TNEXT, bool IS_CONST>
struct value_getter <T,NIDX,TNEXT,IS_CONST,NIDX> {
typedef list_elem<T,NIDX,TNEXT> outer_elem;
typename ConstIf<IS_CONST,T>::t& operator () (typename ConstIf<IS_CONST,outer_elem >::t& me) {
return me.me;
}
};
// Helper to obtain the type of a tuple element
template <typename T, unsigned NIDX, typename TNEXT, unsigned N /*= 0*/>
struct type_getter {
typedef type_getter<typename TNEXT::type,NIDX+1,typename TNEXT::next_type,N> next_elem_getter;
typedef typename next_elem_getter::type type;
};
template <typename T, unsigned NIDX, typename TNEXT >
struct type_getter <T,NIDX,TNEXT,NIDX> {
typedef T type;
};
};
// A very minimal implementation for up to 5 elements
template <typename T0 = detail::nulltype,
typename T1 = detail::nulltype,
typename T2 = detail::nulltype,
typename T3 = detail::nulltype,
typename T4 = detail::nulltype>
class tuple {
friend class tuple;
private:
typedef detail::list_elem<T0,0,
detail::list_elem<T1,1,
detail::list_elem<T2,2,
detail::list_elem<T3,3,
detail::list_elem<T4,4,
detail::list_end > > > > > very_long;
very_long m;
public:
// Get a specific tuple element
template <unsigned N>
typename detail::type_getter<T0,0,typename very_long::next_type, N>::type& get () {
return m.get<N>();
}
// ... and the const version
template <unsigned N>
typename const detail::type_getter<T0,0,typename very_long::next_type, N>::type& get () const {
return m.get<N>();
}
// assignment operator
tuple& operator= (const tuple& other) {
m = other.m;
return *this;
}
// comparison operators
bool operator== (const tuple& other) const {
return m == other.m;
}
// ... and the other way round
bool operator!= (const tuple& other) const {
return !(m == other.m);
}
// cast to another tuple - all single elements must be convertible
template < typename T0, typename T1,typename T2,
typename T3, typename T4>
operator tuple <T0,T1,T2,T3,T4> () {
tuple <T0,T1,T2,T3,T4> s;
s.m = m;
return s;
}
};
// Another way to access an element ...
template <unsigned N,typename T0,typename T1,typename T2,typename T3,typename T4>
inline typename tuple<T0,T1,T2,T3,T4>::very_long::type_getter<N>::type& get (
tuple<T0,T1,T2,T3,T4>& m) {
return m.get<N>();
}
// ... and the const version
template <unsigned N,typename T0,typename T1,typename T2,typename T3,typename T4>
inline const typename tuple<T0,T1,T2,T3,T4>::very_long::type_getter<N>::type& get (
const tuple<T0,T1,T2,T3,T4>& m) {
return m.get<N>();
}
// Constructs a tuple with 5 elements
template <typename T0,typename T1,typename T2,typename T3,typename T4>
inline tuple <T0,T1,T2,T3,T4> make_tuple (const T0& t0,
const T1& t1,const T2& t2,const T3& t3,const T4& t4) {
tuple <T0,T1,T2,T3,T4> t;
t.get<0>() = t0;
t.get<1>() = t1;
t.get<2>() = t2;
t.get<3>() = t3;
t.get<4>() = t4;
return t;
}
// Constructs a tuple with 4 elements
template <typename T0,typename T1,typename T2,typename T3>
inline tuple <T0,T1,T2,T3> make_tuple (const T0& t0,
const T1& t1,const T2& t2,const T3& t3) {
tuple <T0,T1,T2,T3> t;
t.get<0>() = t0;
t.get<1>() = t1;
t.get<2>() = t2;
t.get<3>() = t3;
return t;
}
// Constructs a tuple with 3 elements
template <typename T0,typename T1,typename T2>
inline tuple <T0,T1,T2> make_tuple (const T0& t0,
const T1& t1,const T2& t2) {
tuple <T0,T1,T2> t;
t.get<0>() = t0;
t.get<1>() = t1;
t.get<2>() = t2;
return t;
}
// Constructs a tuple with 2 elements (fucking idiot, use std::pair instead!)
template <typename T0,typename T1>
inline tuple <T0,T1> make_tuple (const T0& t0,
const T1& t1) {
tuple <T0,T1> t;
t.get<0>() = t0;
t.get<1>() = t1;
return t;
}
// Constructs a tuple with 1 elements (no comment ...)
template <typename T0>
inline tuple <T0> make_tuple (const T0& t0) {
tuple <T0> t;
t.get<0>() = t0;
return t;
}
// Constructs a tuple with 0 elements (ehm? Try http://www.promillerechner.net)
inline tuple <> make_tuple () {
tuple <> t;
return t;
}
};
#endif | [
"marvin.kicha@e13029a8-578f-11de-8abc-d1c337b90d21"
] | marvin.kicha@e13029a8-578f-11de-8abc-d1c337b90d21 |
cf1e1ae5a6e8017fc8306b472d6dcc02e80ff44f | 608d046e508a09af717d7cbef64e1ad06550df41 | /inst04/entity.h | c47e563c4b1a6eb904d55e7373dac3f91571da9e | [
"BSD-2-Clause",
"BSD-3-Clause"
] | permissive | spacebruce/Inst.04 | 164ad587e6227ca17bbf411242f413eea4b10585 | 693eef3fbf52b496d2854bfc154f453313648158 | refs/heads/master | 2021-06-16T23:27:51.707899 | 2017-05-06T00:20:52 | 2017-05-06T00:20:52 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 644 | h | #pragma once
#include "pokitto.h"
#include "ardutils\Collections.h"
#include "types.h"
class Entity
{
private:
uint8_t type; //Fix later
Point16 position = Point16();
public:
Entity(void) {}
Entity(Point16 position)
{
this->position = position;
}
Point16 getPosition()
{
return position;
}
int16_t GetX() { return position.x; }
int16_t GetY() { return position.y; }
void setPosition(Point16 position)
{
this->position = position;
}
void setPosition(int16_t x,int16_t y)
{
this->position.x = x;
this->position.y = y;
}
};
| [
"noel.abercrombie@hotmail.com"
] | noel.abercrombie@hotmail.com |
2be437c842cfea57ed88744c03925180acd95c17 | debe1c0fbb03a88da943fcdfd7661dd31b756cfc | /src/codeSets/interpreterSet/base/ZoneIntraConnectParser.cpp | c718f856b7276002d666c2a725b776e5eb9e6468 | [] | no_license | pnnl/eom | 93e2396aad4df8653bec1db3eed705e036984bbc | 9ec5eb8ab050b755898d06760f918f649ab85db5 | refs/heads/master | 2021-08-08T04:51:15.798420 | 2021-06-29T18:19:50 | 2021-06-29T18:19:50 | 137,411,396 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 2,680 | cpp | #include "ZoneIntraConnectParser.hpp"
#include "exceptions/Exception.hpp"
#include "FileControl.hpp"
using std::string;
using std::vector;
using std::cerr;
using std::endl;
namespace interpreter {
ZoneIntraConnectParser::ZoneIntraConnectParser(
const string & fileName,
vector<BalanceAuthParams> & baParam,
vector<vector<vector <Connection> > > & zoneIntraBAConnect,
SimulationInfo & simulationInfo
) :
ModelParser(fileName),
baParam(baParam),
zoneIntraBAConnect(zoneIntraBAConnect)
{
// account for zoneIntraConnect.csv header (3 lines);
nLines -= 3;
setModels(simulationInfo);
};
ZoneIntraConnectParser::~ZoneIntraConnectParser() {
}
void ZoneIntraConnectParser::readZoneConnections(vector<Connection> &connections) {
current = skipCharacter(current, ','); // skips zone number
// get capacity
for (size_t zoneToIndex = 0; zoneToIndex < connections.size(); zoneToIndex++) {
FLOAT capacity = getFloat(',');
connections[zoneToIndex].connectTo = zoneToIndex;
if (capacity > POWER_EPS){ // only need lines for connected zones
connections[zoneToIndex].lineCapacity = capacity;
} else {
connections[zoneToIndex].lineCapacity = 0.0;
}
}
// get ptdf
current = skipCharacter(current, ','); // skip blank
current = skipCharacter(current, ','); // skip zone number
for (size_t zoneToIndex = 0; zoneToIndex < connections.size(); zoneToIndex++) {
FLOAT ptdf = getFloat(",\n",zoneToIndex+1 < connections.size());
if (POWER_EPS < ptdf) { // only need lines for connected zones
connections[zoneToIndex].ptdf = ptdf;
} else {
connections[zoneToIndex].ptdf = 0.0;
}
}
}
void ZoneIntraConnectParser::setModels(SimulationInfo & info) {
resetParser();
try {
for (size_t baIndex = 0; baIndex < baParam.size(); baIndex++) {
BalanceAuthParams &ba = baParam[baIndex];
current = skipLine(current); // BA header
current = skipLine(current); // Data header
current = skipLine(current); // Zone header
vector<vector<Connection> > connectionTableForBA(ba.nZones, vector<Connection>(ba.nZones));
for (size_t zoneFromIndex = 0; zoneFromIndex < ba.nZones; zoneFromIndex++) {
vector<Connection> & connectionListForZone = connectionTableForBA[zoneFromIndex];
readZoneConnections(connectionListForZone);
current = skipLine(current); // BA header
}
zoneIntraBAConnect.push_back(connectionTableForBA);
}
} catch (Exception &) {
cerr << "ERROR (" << utility::FileControl::getFileName(__FILE__) << ":" << __LINE__ << "): failed to parse BA model" << endl;
throw;
}
}
} /* end of NAMESPACE */
| [
"xke@pnnl.gov"
] | xke@pnnl.gov |
83a8eb99c70f5c4401881df514f67aa582e68aa4 | cf8ddfc720bf6451c4ef4fa01684327431db1919 | /SDK/ARKSurvivalEvolved_DinoColorSet_Trope_classes.hpp | ee43e590005da15f167bee8900184d72a056e383 | [
"MIT"
] | permissive | git-Charlie/ARK-SDK | 75337684b11e7b9f668da1f15e8054052a3b600f | c38ca9925309516b2093ad8c3a70ed9489e1d573 | refs/heads/master | 2023-06-20T06:30:33.550123 | 2021-07-11T13:41:45 | 2021-07-11T13:41:45 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 770 | hpp | #pragma once
// ARKSurvivalEvolved (329.9) SDK
#ifdef _MSC_VER
#pragma pack(push, 0x8)
#endif
#include "ARKSurvivalEvolved_DinoColorSet_Trope_structs.hpp"
namespace sdk
{
//---------------------------------------------------------------------------
//Classes
//---------------------------------------------------------------------------
// BlueprintGeneratedClass DinoColorSet_Trope.DinoColorSet_Trope_C
// 0x0000 (0x0268 - 0x0268)
class UDinoColorSet_Trope_C : public UPrimalColorSet
{
public:
static UClass* StaticClass()
{
static auto ptr = UObject::FindClass("BlueprintGeneratedClass DinoColorSet_Trope.DinoColorSet_Trope_C");
return ptr;
}
void ExecuteUbergraph_DinoColorSet_Trope(int EntryPoint);
};
}
#ifdef _MSC_VER
#pragma pack(pop)
#endif
| [
"sergey.2bite@gmail.com"
] | sergey.2bite@gmail.com |
91da605ef70a89ac1c504a7ca6e527e456c08c5b | 0eff74b05b60098333ad66cf801bdd93becc9ea4 | /second/download/httpd/gumtree/httpd_repos_function_2576_httpd-2.0.44.cpp | 422fa1fa6909341379d0e098e2859d825e79c617 | [] | no_license | niuxu18/logTracker-old | 97543445ea7e414ed40bdc681239365d33418975 | f2b060f13a0295387fe02187543db124916eb446 | refs/heads/master | 2021-09-13T21:39:37.686481 | 2017-12-11T03:36:34 | 2017-12-11T03:36:34 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 322 | cpp | static
int entity9(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_LITERAL:
state->handler = declClose;
return XML_ROLE_ENTITY_SYSTEM_ID;
}
return common(state, tok);
} | [
"993273596@qq.com"
] | 993273596@qq.com |
175d0ec8c0323e2d8f53dc5b083fa466e28c7b24 | cfdc4c190ad1cb4b513a2fd4b4c0f9119ae445df | /src/chemnetworks.h | b765fce60126c0770de29204354e1f1671dc0829 | [] | no_license | tzhouwsu/ChemNetworks | 50e4ec4652bb92d9d0f02d42206455099e7b4199 | f9f4d21026f7ad397ce71b8a6c3ea255edb06041 | refs/heads/master | 2021-09-07T01:18:10.217781 | 2018-02-14T21:10:07 | 2018-02-14T21:10:07 | 104,523,188 | 1 | 1 | null | 2017-09-22T22:16:18 | 2017-09-22T22:16:18 | null | UTF-8 | C++ | false | false | 1,026 | h | /*************************************************
* chemnetworks.h *
* *
* Author: Abdullah Ozkanlar *
* abdullah.ozkanlar@wsu.edu *
* *
* A. Clark Research Lab, Chemistry Department *
* Washington State University, Pullman/WA 99164 *
*************************************************/
#ifndef CHEMNETWORKS_H
#define CHEMNETWORKS_H
#include <stdio.h>
namespace CN_NS {
class ChemNetwork {
public :
ChemNetwork() {};
virtual ~ChemNetwork() {};
virtual void input_read(int, char * []) {};
virtual void input_process(int, char * []) {};
virtual void read_xyz_all(char *[]) {};
virtual void read_xyz_solvent1(char[]) {};
virtual void load_xyz_solvent1(int, char**, double*) {};
virtual void process_config(char * []) {};
virtual void deallocate() {};
};
}
#endif // CHEMNETWORKS_H
| [
"tiecheng.zhou@email.wsu.edu"
] | tiecheng.zhou@email.wsu.edu |
5e09621296659b7fa6a2c2ba8e8afa59fad15a0d | e31e68de5f756fb65a5364bb2e37fceb98c257f5 | /week_9_linked_list/List.h | 34d4f0602096ba9d0224f248c282b79d1f77211a | [] | no_license | iantonov99/OOP-FMI-2021 | 2a1eaa70303b5561983115efcceea62fe50578e9 | eccb585cabd69a39968f72847a336beb5d971a79 | refs/heads/main | 2023-05-25T18:28:17.019174 | 2021-06-09T15:33:14 | 2021-06-09T15:33:14 | 340,973,141 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,816 | h | #pragma once
#include <iostream>
template<typename T>
struct ListNode {
T data;
ListNode<T>* next;
ListNode(T _data, ListNode<T>* _next = nullptr) : data(_data) {
next = _next;
};
};
template<typename T>
class List {
private:
ListNode<T>* start;
ListNode<T>* end;
void destroy();
void copy(const List& other);
public:
List();
List(const List& other);
List<T>& operator=(const List& other);
~List();
void addEl(T element);
void print() const;
};
template<typename T>
inline void List<T>::destroy()
{
while (start)
{
ListNode<T>* temp = start;
start = start->next;
delete temp;
}
}
template<typename T>
inline void List<T>::copy(const List& other)
{
if (other.start == nullptr)
{
return;
}
start = new ListNode<T>(other.start->data);
end = start;
ListNode<T>* current = other.start->next;
while (current)
{
addEl(current->data);
current = current->next;
}
}
template<typename T>
inline List<T>::List()
{
start = end = nullptr;
}
template<typename T>
inline List<T>::List(const List& other)
{
copy(other);
}
template<typename T>
inline List<T>& List<T>::operator=(const List& other)
{
if (this != &other)
{
destroy();
copy(other);
}
return *this;
}
template<typename T>
inline List<T>::~List()
{
destroy();
}
template<typename T>
inline void List<T>::addEl(T element)
{
if (end == nullptr)
{
start = end = new ListNode<T>(element);
}
else
{
ListNode<T>* newEl = new ListNode<T>(element);
end->next = newEl;
end = newEl;
}
}
template<typename T>
inline void List<T>::print() const
{
ListNode<T>* current = start;
while (current != nullptr)
{
std::cout << current->data;
std::cout << " -> ";
current = current->next;
}
}
| [
"noreply@github.com"
] | noreply@github.com |
1cf66aea89776c5ec006ffcb3ecb4524331c26a6 | df0aa2858051d24f6808c57f1f5037c91d1996bc | /REVERSE.CPP | f4d70231c3497232a09a0969fcd12bde0627d3c9 | [] | no_license | kapoorkhushal/CPlusPlus--Programs | 0d1a814c66c4a3269b261d32b88c85729f04d061 | e8cfc1f0cebb770751d99ddcddc5adf1f702ef54 | refs/heads/master | 2022-09-14T18:10:05.320503 | 2019-12-21T18:16:28 | 2019-12-21T18:16:28 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 243 | cpp | #include<iostream.h>
#include<conio.h>
void main()
{
int n,reverse=0;
cout<<"Enter an integer : ";
cin>>n;
while(n!=0)
{
int remainder=n%10;
reverse=reverse*10+remainder;
n=n/10;
}
cout<<"REVERSED NUMBER : "<<reverse;
getch();
} | [
"noreply@github.com"
] | noreply@github.com |
3d190e3b4eb9d8456984e6a9ca75a6cdb108dccc | 1bed10351039b1c53508a8d1822f0df22e210695 | /src/jit/impl/internal_graph.cpp | b99af829f4b1db4b4987c1167843038cd94996f7 | [
"LicenseRef-scancode-generic-cla",
"Apache-2.0"
] | permissive | chyelang/MegEngine | 2a39857c5e0db4845b27d3c9e49f2de97f1d38d7 | 4cb7fa8e28cbe7fd23c000e4657300f1db0726ae | refs/heads/master | 2023-08-19T12:08:27.596823 | 2021-10-13T02:51:04 | 2021-10-13T03:19:30 | 250,149,702 | 0 | 0 | NOASSERTION | 2020-03-26T03:14:37 | 2020-03-26T03:14:36 | null | UTF-8 | C++ | false | false | 11,568 | cpp | /**
* \file src/jit/impl/internal_graph.cpp
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
*
* Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#include "megbrain/gopt/framework.h"
#include "megbrain/jit/executor_opr.h"
#include "megbrain/opr/tensor_manip.h"
#include "megbrain/serialization/opr_shallow_copy.h"
#if MGB_JIT
using namespace mgb;
using namespace jit;
using namespace cg;
using namespace gopt;
namespace {
void recursive_replace(
ThinHashMap<VarNode*, VarNode*>& old2new, OperatorNodeBase* opr) {
VarNodeArray rewritten_inputs;
for (auto inp : opr->input()) {
if (!old2new.count(inp))
recursive_replace(old2new, inp->owner_opr());
rewritten_inputs.push_back(old2new[inp]);
}
auto new_opr =
serialization::copy_opr_shallow(*opr, rewritten_inputs, opr->config());
for (size_t i = 0; i < opr->output().size(); ++i) {
if (!opr->output(i)->contain_flag(VarNode::Flag::VOLATILE_CONTENT)) {
old2new[opr->output(i)] = new_opr->output(i);
}
}
}
InternalGraphPtr expand_executor_opr(const InternalGraphPtr& prev_igraph) {
bool has_jit_executor = false;
SymbolVarArray endpoints{SymbolVar{prev_igraph->output()}};
SubGraph sub_graph{endpoints};
SubGraph::Rewriter rewriter{&sub_graph};
auto on_opr = [&](OperatorNodeBase* opr) {
if (auto jit_exctor = try_cast_as_op<JITExecutor>(opr)) {
has_jit_executor = true;
auto& igraph = jit_exctor->internal_graph();
mgb_assert(igraph.output());
ThinHashMap<VarNode*, VarNode*> old2new;
for (size_t i = 0; i < opr->input().size(); ++i) {
auto inp = rewriter.get_var(opr->input(i));
auto ph = igraph.placeholders().at(i)->output(0);
auto iter = old2new.emplace(ph, inp);
if (!iter.second) {
mgb_assert(iter.first->second == inp);
}
}
recursive_replace(old2new, igraph.output()->owner_opr());
rewriter.replace_var(
opr->output(0), old2new[igraph.output()],
mgb_cstr_log("update internal graph"));
} else {
rewriter.auto_replace_outputs(opr);
}
};
sub_graph.iter(on_opr);
if (!has_jit_executor)
return prev_igraph;
rewriter.apply_inplace();
return std::make_shared<InternalGraph>(
rewriter.get_var(prev_igraph->output()),
rewriter.get_var(prev_igraph->shape_infer()),
rewriter.get_var(prev_igraph->value_infer()), prev_igraph->placeholders());
}
} // namespace
InternalGraphGenerator::InternalGraphGenerator(cg::OperatorNodeBase* opr)
: m_output{opr->output(0)} {
add_opr(opr);
}
VarNode* InternalGraphGenerator::replace_graph_by_placeholder() {
ThinHashMap<VarNode*, VarNode*> old2new;
auto cpu_default = CompNode::default_cpu();
auto igraph_copy_opr_shallow =
[cpu_default](OperatorNodeBase* opr, const VarNodeArray& inputs) {
OperatorNodeConfig config = opr->config();
// reset instance_id.
config.reset_instance_id();
if (auto imm = gopt::try_cast_as_op<opr::ImmutableTensor>(opr)) {
HostTensorND hval{cpu_default};
hval.copy_from(imm->value()).sync();
return opr::ImmutableTensor::make(*opr->owner_graph(), hval).node();
}
auto new_opr = serialization::copy_opr_shallow(*opr, inputs, config);
return new_opr->output(0);
};
m_orig_inps.clear();
m_placeholders.clear();
VarNodeArray new_inp;
ThinHashSet<cg::OperatorNodeBase*> graph_input_opr_set;
for (auto i : m_graph_input_set)
graph_input_opr_set.insert(i->owner_opr());
auto on_opr = [&](cg::OperatorNodeBase* opr) {
bool any_output_in_internal_graph = false;
for (auto nd : opr->output()) {
// skip the varnode that is not part of the internal graph, it could
// happen when opr is the graph_input's owner_opr
if (nd->contain_flag(VarNode::Flag::VOLATILE_CONTENT) ||
!m_var_dep_type.count(nd) ||
(graph_input_opr_set.count(opr) && !m_graph_input_set.count(nd)))
continue;
any_output_in_internal_graph = true;
auto dep_type = m_var_dep_type.at(nd);
dep_type &= ~DepType::VALUE_ALLOW_EMPTY;
bool is_shape_input = dep_type == DepType::HOST_VALUE;
mgb_assert(
is_shape_input || dep_type == DepType::DEV_VALUE,
"unhandled dep type: %d", static_cast<int>(dep_type));
VarNode* new_nd;
if (m_graph_input_set.count(nd)) {
using IT = JITPlaceholder::InpType;
new_nd = JITPlaceholder::make(
nd, m_input_idx++,
is_shape_input ? IT::HOST_VALUE_FOR_SHAPE
: IT::DEV_VALUE)
.node();
m_orig_inps.push_back(nd);
m_placeholders.push_back(new_nd);
} else {
mgb_assert(!is_shape_input);
mgb_assert(m_opr_set.count(opr));
new_inp.clear();
for (auto i : opr->input()) {
new_inp.push_back(old2new.at(i));
}
new_nd = igraph_copy_opr_shallow(nd->owner_opr(), new_inp);
}
mgb_assert(new_nd->comp_node() == cpu_default);
old2new[nd] = new_nd;
}
mgb_assert(
any_output_in_internal_graph,
"at least one output should be in the internal graph.");
};
cg::DepOprIter iter{on_opr};
for (auto i : m_graph_input_set) {
for (auto j : i->owner_opr()->input()) {
if (!graph_input_opr_set.count(j->owner_opr()) &&
!m_opr_set.count(j->owner_opr())) {
iter.set_visited(j->owner_opr());
}
}
}
iter.add(m_output);
return old2new.at(m_output);
}
InternalGraphPtr InternalGraphGenerator::generate() {
m_input_idx = 0;
auto new_nd = replace_graph_by_placeholder();
auto igraph = std::make_shared<InternalGraph>(
new_nd, m_output, m_output, to_placeholder_opr_arr(m_placeholders));
return expand_executor_opr(igraph);
}
size_t InternalGraphGenerator::get_cnt_input_if_add(cg::OperatorNodeBase* opr) const {
// minus 1 first because this opr should be removed from subgraph's input
size_t new_cnt_input = m_graph_input_set.size() - 1;
for (auto inp : opr->input()) {
if (m_graph_input_set.count(inp) == 0)
new_cnt_input += 1;
}
return new_cnt_input;
}
void InternalGraphGenerator::add_opr(cg::OperatorNodeBase* opr) {
if (m_opr_set.count(opr)) {
// ignore duplicated oprs (which occur in tests)
return;
}
if (opr->input().empty()) {
mgb_assert(
opr->same_type<opr::ImmutableTensor>(),
"should not add net source opr %s{%s}", opr->cname(),
opr->dyn_typeinfo()->name);
}
// currently only single-output opr is supported; ensure it here
for (size_t i = 1; i < opr->output().size(); ++i) {
mgb_assert(opr->output()[i]->contain_flag(VarNode::Flag::VOLATILE_CONTENT));
}
if (!m_opr_set.empty()) {
auto nr_remove = m_graph_input_set.erase(opr->output(0));
mgb_assert(nr_remove == 1, "opr output not added");
} else {
// opr_set is empty, so this is the endpoint opr
m_var_dep_type[opr->output(0)] = DepType::DEV_VALUE;
}
m_opr_set.insert(opr);
for (auto inp : opr->input()) {
m_graph_input_set.insert(inp);
}
for (auto&& i : opr->node_prop().dep_map()) {
DepType dt = i.second & ~DepType::VALUE_ALLOW_EMPTY;
mgb_assert(
dt == DepType::DEV_VALUE || dt == DepType::HOST_VALUE,
"unsupported dep type: opr %s{%s} on input %s dt=%d", opr->cname(),
opr->dyn_typeinfo()->name, i.first->cname(), static_cast<int>(dt));
m_var_dep_type[i.first] |= i.second;
}
if (opr->same_type<opr::Reduce>()) {
if (!has_reduce()) {
m_before_reduce_shape = opr->input(0)->shape();
m_feature_bits |= JITFeatureBits::REDUCE;
}
mgb_assert(opr->input(0)->shape().eq_shape(m_before_reduce_shape));
find_reduce_opr_deps(opr);
}
if (opr->same_type<opr::Dimshuffle>()) {
m_feature_bits |= JITFeatureBits::DIMSHUFFLE;
find_oprs_depended_by_dimshuffle(opr);
}
if (opr->same_type<mgb::jit::JITExecutor>()) {
auto jit = &opr->cast_final<mgb::jit::JITExecutor>();
if (jit->has_reduce()) {
if (!has_reduce()) {
m_before_reduce_shape = jit->broadcasted_input_shape();
m_feature_bits |= JITFeatureBits::REDUCE;
}
mgb_assert(jit->broadcasted_input_shape().eq_shape(m_before_reduce_shape));
find_reduce_opr_deps(opr);
}
if (jit->has_dimshuffle()) {
m_feature_bits |= JITFeatureBits::REDUCE;
find_oprs_depended_by_dimshuffle(opr);
}
}
}
void InternalGraphGenerator::find_reduce_opr_deps(cg::OperatorNodeBase* opr) {
mgb_assert(
opr->same_type<opr::Reduce>() ||
(opr->same_type<jit::JITExecutor>() &&
try_cast_as_op<jit::JITExecutor>(opr)->has_reduce()));
VarNode* nd = opr->output(0);
auto cb = [this, &nd](cg::OperatorNodeBase* opr) {
m_reduce_out_var_deps[nd].insert(opr);
};
cg::DepOprIter{cb}.add(opr);
}
void InternalGraphGenerator::find_oprs_depended_by_dimshuffle(
cg::OperatorNodeBase* dimshuffle) {
mgb_assert(
dimshuffle->same_type<opr::Dimshuffle>() ||
(dimshuffle->same_type<jit::JITExecutor>() &&
try_cast_as_op<jit::JITExecutor>(dimshuffle)->has_dimshuffle()));
auto cb = [this, dimshuffle](cg::OperatorNodeBase* opr) {
if (!m_oprs_depended_by_dimshuffle.count(opr)) {
// No dimshuffle depend on the opr.
mgb_assert(!m_oprs_depended_by_dimshuffle.count(dimshuffle));
m_oprs_depended_by_dimshuffle[opr] = dimshuffle;
} else {
// Already be depended by dimshuffle.
if (m_oprs_depended_by_dimshuffle.count(dimshuffle) &&
m_oprs_depended_by_dimshuffle.at(opr) ==
m_oprs_depended_by_dimshuffle.at(dimshuffle)) {
m_oprs_depended_by_dimshuffle[opr] = dimshuffle;
}
}
};
cg::DepOprIter{cb}.add(dimshuffle);
}
PlaceholderArray InternalGraphGenerator::to_placeholder_opr_arr(
const VarNodeArray& vars) {
PlaceholderArray ret(vars.size());
for (size_t i = 0; i < vars.size(); ++i) {
ret[i] = &vars[i]->owner_opr()->cast_final_safe<JITPlaceholder>();
}
return ret;
}
#endif // MGB_JIT
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
| [
"megengine@megvii.com"
] | megengine@megvii.com |
6f81c1a5cad1d0c235a391e9acc57c521190d724 | 87955ec8a20c3d3ee98ebce458956d57c972ed31 | /src/keepass.cpp | 71e540733ac5f354263823dde4d2ff3a78f683d9 | [
"MIT"
] | permissive | FullStackDeveloper2020/Hashshare | e7d8cdcff778ee127e01d092231c5080515ae4c2 | e4e5893183994382c1490356d158ee3dfc9f200e | refs/heads/master | 2020-12-26T12:06:11.529510 | 2020-01-31T19:48:36 | 2020-01-31T19:48:36 | 237,503,888 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 21,906 | cpp | // Copyright (c) 2014-2018 The Dash Core developers
// Copyright (c) 2018-2019 The PACGlobal developers
// Copyright (c) 2019 The HashShare Coin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "keepass.h"
#include "wallet/crypter.h"
#include "clientversion.h"
#include "protocol.h"
#include "random.h"
#include "rpc/protocol.h"
// Necessary to prevent compile errors due to forward declaration of
//CScript in serialize.h (included from crypter.h)
#include "script/script.h"
#include "script/standard.h"
#include "util.h"
#include "utilstrencodings.h"
#include <event2/event.h>
#include <event2/http.h>
#include <event2/buffer.h>
#include <event2/keyvalq_struct.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/buffer.h>
#include "support/cleanse.h" // for OPENSSL_cleanse()
const char* CKeePassIntegrator::KEEPASS_HTTP_HOST = "localhost";
CKeePassIntegrator keePassInt;
// Base64 decoding with secure memory allocation
SecureString DecodeBase64Secure(const SecureString& sInput)
{
SecureString output;
// Init openssl BIO with base64 filter and memory input
BIO *b64, *mem;
b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer
mem = BIO_new_mem_buf((void *) &sInput[0], sInput.size());
BIO_push(b64, mem);
// Prepare buffer to receive decoded data
if(sInput.size() % 4 != 0) {
throw std::runtime_error("Input length should be a multiple of 4");
}
size_t nMaxLen = sInput.size() / 4 * 3; // upper bound, guaranteed divisible by 4
output.resize(nMaxLen);
// Decode the string
size_t nLen;
nLen = BIO_read(b64, (void *) &output[0], sInput.size());
output.resize(nLen);
// Free memory
BIO_free_all(b64);
return output;
}
// Base64 encoding with secure memory allocation
SecureString EncodeBase64Secure(const SecureString& sInput)
{
// Init openssl BIO with base64 filter and memory output
BIO *b64, *mem;
b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); // No newlines in output
mem = BIO_new(BIO_s_mem());
BIO_push(b64, mem);
// Decode the string
BIO_write(b64, &sInput[0], sInput.size());
(void) BIO_flush(b64);
// Create output variable from buffer mem ptr
BUF_MEM *bptr;
BIO_get_mem_ptr(b64, &bptr);
SecureString output(bptr->data, bptr->length);
// Cleanse secure data buffer from memory
memory_cleanse((void *) bptr->data, bptr->length);
// Free memory
BIO_free_all(b64);
return output;
}
CKeePassIntegrator::CKeePassIntegrator()
:sKeyBase64(" "), sKey(" "), sUrl(" ") // Prevent LockedPageManagerBase complaints
{
sKeyBase64.clear(); // Prevent LockedPageManagerBase complaints
sKey.clear(); // Prevent LockedPageManagerBase complaints
sUrl.clear(); // Prevent LockedPageManagerBase complaints
bIsActive = false;
nPort = DEFAULT_KEEPASS_HTTP_PORT;
}
// Initialze from application context
void CKeePassIntegrator::init()
{
bIsActive = GetBoolArg("-keepass", false);
nPort = GetArg("-keepassport", DEFAULT_KEEPASS_HTTP_PORT);
sKeyBase64 = SecureString(GetArg("-keepasskey", "").c_str());
strKeePassId = GetArg("-keepassid", "");
strKeePassEntryName = GetArg("-keepassname", "");
// Convert key if available
if(sKeyBase64.size() > 0)
{
sKey = DecodeBase64Secure(sKeyBase64);
}
// Construct url if available
if(strKeePassEntryName.size() > 0)
{
sUrl = SecureString("http://");
sUrl += SecureString(strKeePassEntryName.c_str());
sUrl += SecureString("/");
//sSubmitUrl = "http://";
//sSubmitUrl += SecureString(strKeePassEntryName.c_str());
}
}
void CKeePassIntegrator::CKeePassRequest::addStrParameter(const std::string& strName, const std::string& strValue)
{
requestObj.push_back(Pair(strName, strValue));
}
void CKeePassIntegrator::CKeePassRequest::addStrParameter(const std::string& strName, const SecureString& sValue)
{
std::string sCipherValue;
if(!EncryptAES256(sKey, sValue, strIV, sCipherValue))
{
throw std::runtime_error("Unable to encrypt Verifier");
}
addStrParameter(strName, EncodeBase64(sCipherValue));
}
std::string CKeePassIntegrator::CKeePassRequest::getJson()
{
return requestObj.write();
}
void CKeePassIntegrator::CKeePassRequest::init()
{
SecureString sIVSecure = generateRandomKey(KEEPASS_CRYPTO_BLOCK_SIZE);
strIV = std::string(&sIVSecure[0], sIVSecure.size());
// Generate Nonce, Verifier and RequestType
SecureString sNonceBase64Secure = EncodeBase64Secure(sIVSecure);
addStrParameter("Nonce", std::string(&sNonceBase64Secure[0], sNonceBase64Secure.size())); // Plain
addStrParameter("Verifier", sNonceBase64Secure); // Encoded
addStrParameter("RequestType", strType);
}
void CKeePassIntegrator::CKeePassResponse::parseResponse(const std::string& strResponse)
{
UniValue responseValue;
if(!responseValue.read(strResponse))
{
throw std::runtime_error("Unable to parse KeePassHttp response");
}
responseObj = responseValue;
// retrieve main values
bSuccess = responseObj["Success"].get_bool();
strType = getStr("RequestType");
strIV = DecodeBase64(getStr("Nonce"));
}
std::string CKeePassIntegrator::CKeePassResponse::getStr(const std::string& strName)
{
return responseObj[strName].get_str();
}
SecureString CKeePassIntegrator::CKeePassResponse::getSecureStr(const std::string& strName)
{
std::string strValueBase64Encrypted(responseObj[strName].get_str());
SecureString sValue;
try
{
sValue = decrypt(strValueBase64Encrypted);
}
catch (std::exception &e)
{
std::string strError = "Exception occured while decrypting ";
strError += strName + ": " + e.what();
throw std::runtime_error(strError);
}
return sValue;
}
SecureString CKeePassIntegrator::CKeePassResponse::decrypt(const std::string& strValueBase64Encrypted)
{
std::string strValueEncrypted = DecodeBase64(strValueBase64Encrypted);
SecureString sValue;
if(!DecryptAES256(sKey, strValueEncrypted, strIV, sValue))
{
throw std::runtime_error("Unable to decrypt value.");
}
return sValue;
}
std::vector<CKeePassIntegrator::CKeePassEntry> CKeePassIntegrator::CKeePassResponse::getEntries()
{
std::vector<CKeePassEntry> vEntries;
UniValue aEntries = responseObj["Entries"].get_array();
for(size_t i = 0; i < aEntries.size(); i++)
{
SecureString sEntryUuid(decrypt(aEntries[i]["Uuid"].get_str().c_str()));
SecureString sEntryName(decrypt(aEntries[i]["Name"].get_str().c_str()));
SecureString sEntryLogin(decrypt(aEntries[i]["Login"].get_str().c_str()));
SecureString sEntryPassword(decrypt(aEntries[i]["Password"].get_str().c_str()));
CKeePassEntry entry(sEntryUuid, sEntryName, sEntryLogin, sEntryPassword);
vEntries.push_back(entry);
}
return vEntries;
}
SecureString CKeePassIntegrator::generateRandomKey(size_t nSize)
{
// Generates random key
SecureString sKey;
sKey.resize(nSize);
GetStrongRandBytes((unsigned char *) &sKey[0], nSize);
return sKey;
}
// Construct POST body for RPC JSON call
std::string CKeePassIntegrator::constructHTTPPost(const std::string& strMsg, const std::map<std::string,std::string>& mapRequestHeaders)
{
std::ostringstream streamOut;
streamOut << "POST / HTTP/1.1\r\n"
<< "User-Agent: hashsharecoin-json-rpc/" << FormatFullVersion() << "\r\n"
<< "Host: localhost\r\n"
<< "Content-Type: application/json\r\n"
<< "Content-Length: " << strMsg.size() << "\r\n"
<< "Connection: close\r\n"
<< "Accept: application/json\r\n";
for (const auto& item : mapRequestHeaders)
streamOut << item.first << ": " << item.second << "\r\n";
streamOut << "\r\n" << strMsg;
return streamOut.str();
}
/** Reply structure for request_done to fill in */
struct HTTPReply
{
int nStatus;
std::string strBody;
};
static void http_request_done(struct evhttp_request *req, void *ctx)
{
HTTPReply *reply = static_cast<HTTPReply*>(ctx);
if (req == NULL) {
/* If req is NULL, it means an error occurred while connecting, but
* I'm not sure how to find out which one. We also don't really care.
*/
reply->nStatus = 0;
return;
}
reply->nStatus = evhttp_request_get_response_code(req);
struct evbuffer *buf = evhttp_request_get_input_buffer(req);
if (buf)
{
size_t size = evbuffer_get_length(buf);
const char *data = (const char*)evbuffer_pullup(buf, size);
if (data)
reply->strBody = std::string(data, size);
evbuffer_drain(buf, size);
}
}
// Send RPC message to KeePassHttp
void CKeePassIntegrator::doHTTPPost(const std::string& sRequest, int& nStatusRet, std::string& strResponseRet)
{
// // Prepare communication
// boost::asio::io_service io_service;
// // Get a list of endpoints corresponding to the server name.
// tcp::resolver resolver(io_service);
// tcp::resolver::query query(KEEPASS_HTTP_HOST, boost::lexical_cast<std::string>(nPort));
// tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
// tcp::resolver::iterator end;
// // Try each endpoint until we successfully establish a connection.
// tcp::socket socket(io_service);
// boost::system::error_code error = boost::asio::error::host_not_found;
// while (error && endpoint_iterator != end)
// {
// socket.close();
// socket.connect(*endpoint_iterator++, error);
// }
// if(error)
// {
// throw boost::system::system_error(error);
// }
// Create event base
struct event_base *base = event_base_new(); // TODO RAII
if (!base)
throw std::runtime_error("cannot create event_base");
// Synchronously look up hostname
struct evhttp_connection *evcon = evhttp_connection_base_new(base, NULL, KEEPASS_HTTP_HOST, DEFAULT_KEEPASS_HTTP_PORT); // TODO RAII
if (evcon == NULL)
throw std::runtime_error("create connection failed");
evhttp_connection_set_timeout(evcon, KEEPASS_HTTP_CONNECT_TIMEOUT);
// Form the request.
// std::map<std::string, std::string> mapRequestHeaders;
// std::string strPost = constructHTTPPost(sRequest, mapRequestHeaders);
HTTPReply response;
struct evhttp_request *req = evhttp_request_new(http_request_done, (void*)&response); // TODO RAII
if (req == NULL)
throw std::runtime_error("create http request failed");
struct evkeyvalq *output_headers = evhttp_request_get_output_headers(req);
assert(output_headers);
// s << "POST / HTTP/1.1\r\n"
evhttp_add_header(output_headers, "User-Agent", ("hashsharecoin-json-rpc/" + FormatFullVersion()).c_str());
evhttp_add_header(output_headers, "Host", KEEPASS_HTTP_HOST);
evhttp_add_header(output_headers, "Accept", "application/json");
evhttp_add_header(output_headers, "Content-Type", "application/json");
// evhttp_add_header(output_headers, "Content-Length", itostr(strMsg.size()).c_str());
evhttp_add_header(output_headers, "Connection", "close");
// Logging of actual post data disabled as to not write passphrase in debug.log. Only enable temporarily when needed
//LogPrint("keepass", "CKeePassIntegrator::doHTTPPost -- send POST data: %s\n", strPost);
LogPrint("keepass", "CKeePassIntegrator::doHTTPPost -- send POST data\n");
// boost::asio::streambuf request;
// std::ostream request_stream(&request);
// request_stream << strPost;
// // Send the request.
// boost::asio::write(socket, request);
// LogPrint("keepass", "CKeePassIntegrator::doHTTPPost -- request written\n");
// // Read the response status line. The response streambuf will automatically
// // grow to accommodate the entire line. The growth may be limited by passing
// // a maximum size to the streambuf constructor.
// boost::asio::streambuf response;
// boost::asio::read_until(socket, response, "\r\n");
// LogPrint("keepass", "CKeePassIntegrator::doHTTPPost -- request status line read\n");
// // Receive HTTP reply status
// int nProto = 0;
// std::istream response_stream(&response);
// nStatus = ReadHTTPStatus(response_stream, nProto);
// Attach request data
// std::string sRequest = JSONRPCRequest(strMethod, params, 1);
struct evbuffer * output_buffer = evhttp_request_get_output_buffer(req);
assert(output_buffer);
evbuffer_add(output_buffer, sRequest.data(), sRequest.size());
int r = evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/");
if (r != 0) {
evhttp_connection_free(evcon);
event_base_free(base);
throw std::runtime_error("send http request failed");
}
event_base_dispatch(base);
evhttp_connection_free(evcon);
event_base_free(base);
// LogPrint("keepass", "CKeePassIntegrator::doHTTPPost -- reading response body start\n");
// // Read until EOF, writing data to output as we go.
// while (boost::asio::read(socket, response, boost::asio::transfer_at_least(1), error))
// {
// if (error != boost::asio::error::eof)
// {
// if (error != 0)
// { // 0 is success
// throw boost::system::system_error(error);
// }
// }
// }
// LogPrint("keepass", "CKeePassIntegrator::doHTTPPost -- reading response body end\n");
//
// // Receive HTTP reply message headers and body
// std::map<std::string, std::string> mapHeaders;
// ReadHTTPMessage(response_stream, mapHeaders, strResponse, nProto, std::numeric_limits<size_t>::max());
// LogPrint("keepass", "CKeePassIntegrator::doHTTPPost -- Processed body\n");
nStatusRet = response.nStatus;
if (response.nStatus == 0)
throw std::runtime_error("couldn't connect to server");
else if (response.nStatus >= 400 && response.nStatus != HTTP_BAD_REQUEST && response.nStatus != HTTP_NOT_FOUND && response.nStatus != HTTP_INTERNAL_SERVER_ERROR)
throw std::runtime_error(strprintf("server returned HTTP error %d", response.nStatus));
else if (response.strBody.empty())
throw std::runtime_error("no response from server");
// Parse reply
UniValue valReply(UniValue::VSTR);
if (!valReply.read(response.strBody))
throw std::runtime_error("couldn't parse reply from server");
const UniValue& reply = valReply.get_obj();
if (reply.empty())
throw std::runtime_error("expected reply to have result, error and id properties");
strResponseRet = valReply.get_str();
}
void CKeePassIntegrator::rpcTestAssociation(bool bTriggerUnlock)
{
CKeePassRequest request(sKey, "test-associate");
request.addStrParameter("TriggerUnlock", std::string(bTriggerUnlock ? "true" : "false"));
int nStatus;
std::string strResponse;
doHTTPPost(request.getJson(), nStatus, strResponse);
LogPrint("keepass", "CKeePassIntegrator::rpcTestAssociation -- send result: status: %d response: %s\n", nStatus, strResponse);
}
std::vector<CKeePassIntegrator::CKeePassEntry> CKeePassIntegrator::rpcGetLogins()
{
// Convert key format
SecureString sKey = DecodeBase64Secure(sKeyBase64);
CKeePassRequest request(sKey, "get-logins");
request.addStrParameter("addStrParameter", std::string("true"));
request.addStrParameter("TriggerUnlock", std::string("true"));
request.addStrParameter("Id", strKeePassId);
request.addStrParameter("Url", sUrl);
int nStatus;
std::string strResponse;
doHTTPPost(request.getJson(), nStatus, strResponse);
// Logging of actual response data disabled as to not write passphrase in debug.log. Only enable temporarily when needed
//LogPrint("keepass", "CKeePassIntegrator::rpcGetLogins -- send result: status: %d response: %s\n", nStatus, strResponse);
LogPrint("keepass", "CKeePassIntegrator::rpcGetLogins -- send result: status: %d\n", nStatus);
if(nStatus != 200)
{
std::string strError = "Error returned by KeePassHttp: HTTP code ";
strError += itostr(nStatus);
strError += " - Response: ";
strError += " response: [";
strError += strResponse;
strError += "]";
throw std::runtime_error(strError);
}
// Parse the response
CKeePassResponse response(sKey, strResponse);
if(!response.getSuccess())
{
std::string strError = "KeePassHttp returned failure status";
throw std::runtime_error(strError);
}
return response.getEntries();
}
void CKeePassIntegrator::rpcSetLogin(const SecureString& sWalletPass, const SecureString& sEntryId)
{
// Convert key format
SecureString sKey = DecodeBase64Secure(sKeyBase64);
CKeePassRequest request(sKey, "set-login");
request.addStrParameter("Id", strKeePassId);
request.addStrParameter("Url", sUrl);
LogPrint("keepass", "CKeePassIntegrator::rpcSetLogin -- send Url: %s\n", sUrl);
//request.addStrParameter("SubmitUrl", sSubmitUrl); // Is used to construct the entry title
request.addStrParameter("Login", SecureString("hashsharecoin"));
request.addStrParameter("Password", sWalletPass);
if(sEntryId.size() != 0)
{
request.addStrParameter("Uuid", sEntryId); // Update existing
}
int nStatus;
std::string strResponse;
doHTTPPost(request.getJson(), nStatus, strResponse);
LogPrint("keepass", "CKeePassIntegrator::rpcSetLogin -- send result: status: %d response: %s\n", nStatus, strResponse);
if(nStatus != 200)
{
std::string strError = "Error returned: HTTP code ";
strError += itostr(nStatus);
strError += " - Response: ";
strError += " response: [";
strError += strResponse;
strError += "]";
throw std::runtime_error(strError);
}
// Parse the response
CKeePassResponse response(sKey, strResponse);
if(!response.getSuccess())
{
throw std::runtime_error("KeePassHttp returned failure status");
}
}
SecureString CKeePassIntegrator::generateKeePassKey()
{
SecureString sKey = generateRandomKey(KEEPASS_CRYPTO_KEY_SIZE);
SecureString sKeyBase64 = EncodeBase64Secure(sKey);
return sKeyBase64;
}
void CKeePassIntegrator::rpcAssociate(std::string& strIdRet, SecureString& sKeyBase64Ret)
{
sKey = generateRandomKey(KEEPASS_CRYPTO_KEY_SIZE);
CKeePassRequest request(sKey, "associate");
sKeyBase64Ret = EncodeBase64Secure(sKey);
request.addStrParameter("Key", std::string(&sKeyBase64Ret[0], sKeyBase64Ret.size()));
int nStatus;
std::string strResponse;
doHTTPPost(request.getJson(), nStatus, strResponse);
LogPrint("keepass", "CKeePassIntegrator::rpcAssociate -- send result: status: %d response: %s\n", nStatus, strResponse);
if(nStatus != 200)
{
std::string strError = "Error returned: HTTP code ";
strError += itostr(nStatus);
strError += " - Response: ";
strError += " response: [";
strError += strResponse;
strError += "]";
throw std::runtime_error(strError);
}
// Parse the response
CKeePassResponse response(sKey, strResponse);
if(!response.getSuccess())
{
throw std::runtime_error("KeePassHttp returned failure status");
}
// If we got here, we were successful. Return the information
strIdRet = response.getStr("Id");
}
// Retrieve wallet passphrase from KeePass
SecureString CKeePassIntegrator::retrievePassphrase()
{
// Check we have all required information
if(sKey.size() == 0)
{
throw std::runtime_error("keepasskey parameter is not defined. Please specify the configuration parameter.");
}
if(strKeePassId.size() == 0)
{
throw std::runtime_error("keepassid parameter is not defined. Please specify the configuration parameter.");
}
if(strKeePassEntryName == "")
{
throw std::runtime_error("keepassname parameter is not defined. Please specify the configuration parameter.");
}
// Retrieve matching logins from KeePass
std::vector<CKeePassIntegrator::CKeePassEntry> vecEntries = rpcGetLogins();
// Only accept one unique match
if(vecEntries.size() == 0)
{
throw std::runtime_error("KeePassHttp returned 0 matches, please verify the keepassurl setting.");
}
if(vecEntries.size() > 1)
{
throw std::runtime_error("KeePassHttp returned multiple matches, bailing out.");
}
return vecEntries[0].getPassword();
}
// Update wallet passphrase in keepass
void CKeePassIntegrator::updatePassphrase(const SecureString& sWalletPassphrase)
{
// Check we have all required information
if(sKey.size() == 0)
{
throw std::runtime_error("keepasskey parameter is not defined. Please specify the configuration parameter.");
}
if(strKeePassId.size() == 0)
{
throw std::runtime_error("keepassid parameter is not defined. Please specify the configuration parameter.");
}
if(strKeePassEntryName == "")
{
throw std::runtime_error("keepassname parameter is not defined. Please specify the configuration parameter.");
}
SecureString sEntryId("");
std::string strError;
// Lookup existing entry
std::vector<CKeePassIntegrator::CKeePassEntry> vecEntries = rpcGetLogins();
if(vecEntries.size() > 1)
{
throw std::runtime_error("KeePassHttp returned multiple matches, bailing out.");
}
if(vecEntries.size() == 1)
{
sEntryId = vecEntries[0].getUuid();
}
// Update wallet passphrase in KeePass
rpcSetLogin(sWalletPassphrase, sEntryId);
}
| [
"59161578+hashshare@users.noreply.github.com"
] | 59161578+hashshare@users.noreply.github.com |
9dcf7036565c6e032fd48eb92866bed8b9fbdaed | 4c239f7e65343bc0a5e017306c2a69b06d17dd0a | /Physics/include/Engine/Physics/Mesh/TriangleMesh.h | 18f3188a7a256d95216d4db67a5e99b947cf1189 | [] | no_license | idrol/GameEngine | 5334882f7af68d761412bc9a3f5c0c8b7d253811 | 3c0e6a3499fcd493b9ce456b09114f519212efc5 | refs/heads/master | 2021-03-26T06:06:20.818275 | 2020-03-16T11:23:57 | 2020-03-16T11:23:57 | 247,678,347 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 526 | h | #pragma once
#include <Engine/Physics/PhysicsAPI.h>
#include <GLM/glm.hpp>
class btTriangleMesh;
namespace Engine::Physics {
class PHYSICS_API TriangleMesh {
public:
TriangleMesh();
virtual ~TriangleMesh();
// WARNING removeDuplicateVertices is very slow for large meshes
void AddTriangle(glm::vec3 vertex0, glm::vec3 vertex1, glm::vec3 vertex2, bool removeDuplicateVertices = false);
// Internal function
btTriangleMesh* GetInternalTriangleMesh();
private:
btTriangleMesh* internalTriangleMesh;
};
} | [
"adriangrannas@hotmail.com"
] | adriangrannas@hotmail.com |
131fb7c10c2038334dc148b3d612d7fb22c16538 | 5f1983917e9d76f47a51db6e10cf739ff8d70982 | /Code/Lib/sfmVisualiser.h | 456ecadc8d1890647f52daf7c9ae1fddd8b6d4f1 | [
"BSD-3-Clause"
] | permissive | SandroMoszczynski/Pedestrian-Simulator | f00a042815fa9fbbf68ae9afc2c1cbd8f4371d68 | 9838e21ac663f557b7969161dee061086effdabd | refs/heads/master | 2023-03-28T08:14:29.717102 | 2021-03-25T10:30:47 | 2021-03-25T10:30:47 | 255,349,216 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,117 | h | /*=============================================================================
PHAS0100ASSIGNMENT2: PHAS0100 Assignment 2 Social Force Model
Copyright (c) University College London (UCL). All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
See LICENSE.txt in the top level directory for details.
VTK based viewer for Social Force Model simulation: 12 Apr 2020
Author: Jim Dobson
See Code/CommandLineApps/sfmVisualiserDemo.cpp for example usage.
=============================================================================*/
#ifndef sfmVisualiser_h
#define sfmVisualiser_h
#include <vector>
#include <vtkSmartPointer.h>
#include "sfmBasicTypes.h"
class vtkContextView;
class vtkChartXY;
class vtkTable;
class vtkPlot;
//! Single namespace for all code in this package
namespace sfm {
/**
* \class Visualiser
* \brief VTK based visualiser class
* \ingroup utilities
*/
class Visualiser {
public:
Visualiser(unsigned int n_pedestrians = 0,
double world_x = POS2D_XWRAP, double world_y = POS2D_YWRAP,
double window_scale = 40.0);
~Visualiser();
void CreateWorld(unsigned int n_pedestrians,
double width_x, double width_y);
bool SetPedestrian(unsigned int i,
double xpos, double ypos,
double xspeed, double yspeed);
void UpdateScene();
void SetWindowSize(double scale); // Adjust window size (pixels/meter), requires CreateWorld to take effect
void SetMarkerSize(double scale); // Adjust base marker size in pixels
private:
void CreateTables();
vtkSmartPointer<vtkContextView> m_view;
vtkSmartPointer<vtkChartXY> m_chart;
std::vector<vtkSmartPointer<vtkTable> > m_tables;
std::vector<vtkSmartPointer<vtkPlot> > m_points;
int m_n_pedestrians;
double m_world_x, m_world_y;
double m_window_scale; // Scale size of window, arbitrary units
double m_marker_scale; // Scale marker size, arbitrary units
}; // end class Visualiser
} // end namespace
#endif
| [
"sandromarcus@hotmail.co.uk"
] | sandromarcus@hotmail.co.uk |
bbeb6558881009a5c1b71863209eaecde42e77dc | 74efb2861fd72a037512374b79647000dc3ca83e | /mini-projects/mini_stl/iterator.h | 2f62b7ab3bbeb6a6eec0d00f95fb22e36b60c31d | [] | no_license | Xlgd/learn-cpp | d29e83aabc696cd0a61793fa885c339aac01d094 | 046c6b16cedd0c020430ef0168ee5e12629d755d | refs/heads/master | 2021-11-27T21:56:41.887764 | 2021-08-19T07:42:37 | 2021-08-19T07:42:37 | 249,366,924 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 102 | h | #ifndef __ITERATOR__
#define __ITERATOR__
namespace ministl
{
} // namespace ministl
#endif | [
"1120496618@qq.com"
] | 1120496618@qq.com |
1bef83e51539eee4c1772cd527a6de2e26ea6a84 | 93bb87f91e55d55dc2f9bf78b914e6290c3a17be | /src/analysis/RegisterAnalysis.h | 61a177c4b4c2effd66a9abdd916b16382834ae3f | [
"MIT"
] | permissive | doe300/VC4C | 5bbde383fb1230af42f72bd20accb84418b8b7fa | 3d89be8692ae20b8f712e9d2bc45b6998dac8259 | refs/heads/master | 2023-06-07T06:25:07.948224 | 2023-05-30T09:42:15 | 2023-05-30T16:11:04 | 106,166,771 | 123 | 38 | MIT | 2023-05-30T16:11:05 | 2017-10-08T10:11:39 | C | UTF-8 | C++ | false | false | 1,630 | h | /*
* Author: doe300
*
* See the file "LICENSE" for the full license governing this code.
*/
#ifndef VC4C_REGISTER_ANALYSIS
#define VC4C_REGISTER_ANALYSIS
#include "Analysis.h"
#include "../intermediate/IntermediateInstruction.h"
#include "../performance.h"
#include <bitset>
namespace vc4c
{
namespace analysis
{
using UsedElements = FastMap<const Local*, std::bitset<NATIVE_VECTOR_SIZE>>;
/*
* Tracks locals which are read conditionally to determine the used elements
*/
using ConditionalUsages = FastMap<const Local*, ConditionCode>;
/*
* Analyses the SIMD elements used for each local.
*
* The information obtained from this analysis can be used e.g. to combine multiple locals into different
* elements of the same registers.
*/
class UsedElementsAnalysis : public LocalAnalysis<AnalysisDirection::BACKWARD, UsedElements, ConditionalUsages>
{
public:
explicit UsedElementsAnalysis();
static std::string to_string(const UsedElements& registerElements);
private:
/*
* For every instruction, following will be done:
* - the read SIMD elements are added to the values
* - any local write clears the register usage
*/
static UsedElements analyzeUsedSIMDElements(const intermediate::IntermediateInstruction* inst,
const UsedElements& nextValues, ConditionalUsages& cache);
};
} // namespace analysis
} // namespace vc4c
#endif /* VC4C_REGISTER_ANALYSIS */
| [
"stadeldani@web.de"
] | stadeldani@web.de |
d0bec285c8fa7ad4863de76e36f7a64bba4d8c29 | 89ce4e6016d7558797a5dfb272e35692917761e1 | /example/tests.cpp | 421090eebd2f0186bb9d6b0f8beaf1c11a5019c3 | [
"MIT"
] | permissive | M4xi1m3/nbtpp | 123a7ab699435372cdcf69964f8b6ba6b03fd3fd | dfb69f2d4b52d60f54c1132047ae4a86816a5dd4 | refs/heads/master | 2023-03-19T11:08:10.441371 | 2021-03-09T21:07:56 | 2021-03-09T21:08:27 | 319,009,201 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 592 | cpp | #include <iostream>
#include <fstream>
#include "nbtpp/tag.hpp"
#include "nbtpp/nbt.hpp"
#include "nbtpp/nbtexception.hpp"
#include "stde/streams/gzip.hpp"
using namespace nbtpp;
using namespace stde;
int main(int argc, char** argv) {
// std::ifstream f("tests/hell.mcr");
// f.seekg(0x2005);
// std::ifstream f("tests/hello_world.nbt");
std::ifstream f("tests/bigtest.nbt", std::ifstream::binary);
nbtpp::nbt n(f);
n.debug();
/*
std::ofstream fo("test.nbt");
n.save_file(fo);
*/
// std::cout << +n.getCompressionMethod() << std::endl;
}
| [
"M4x1me@protonmail.com"
] | M4x1me@protonmail.com |
3baa793edd9127cedb065b01d62c0493285e6da6 | 6a490538337cfe74591110d1454186a4e2064fc4 | /HelloWord/assert/main.cpp | a1855a76bf430247b1c620aa7ba88fdef885126d | [] | no_license | MoonSupport/LatinCPP | 03beb72617c8c38865e60a675e4d81cdb23f9f40 | 23551cf00352ec5e2c4ef4767486fe4dc59b3e57 | refs/heads/master | 2020-12-01T09:58:16.232960 | 2020-03-08T13:50:16 | 2020-03-08T13:50:16 | 230,604,783 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 379 | cpp | //
// main.cpp
// assert
//
// Created by 문지원 on 18/01/2020.
// Copyright © 2020 문지원. All rights reserved.
//
#include <iostream>
#include <cassert>
int main(int argc, const char * argv[]) {
int a = 5;
const int ix = 5;
static_assert(ix >= 5, "5 이상이여야 함");
static_assert(ix < 5, "5 미만이여야 함");
return 0;
}
| [
"jiwon3346@naver.com"
] | jiwon3346@naver.com |
0df402b9a9333195fb5ea22a12482fc4df797c59 | 8b9a264d527bfa780cbc24dde5b8cd5a3b0febac | /Internet-of-Things/Lab 5/lab5arduino/lab5arduino.ino | e31761a487046608c22e35c36fc3d017894f79cc | [] | no_license | cgoulart35/UML-CS-COURSES | 52b986b6bf4df723c3c691776d1f3aa5f1fcf280 | bc9b56e2e487aaaf3c0e661847759801e058b9a3 | refs/heads/master | 2022-11-28T13:59:59.189261 | 2020-08-14T20:15:58 | 2020-08-14T20:15:58 | 287,615,454 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,651 | ino | #include <ESP8266WiFi.h>
#include <PubSubClient.h>
// WiFi/MQTT parameters
#define WLAN_SSID "FILL THIS IN"
#define WLAN_PASS "FILL THIS IN"
#define BROKER_IP "FILL THIS IN"
#define LED 5
int lightstate;
WiFiClient client;
PubSubClient mqttclient(client);
void callback (char* topic, byte* payload, unsigned int length) {
Serial.println(topic);
Serial.write(payload, length); //print incoming messages
Serial.println("");
payload[length] = '\0'; // add null terminator to byte payload so we can treat it as a string
if (strcmp(topic, "/led/arduino") == 0){
if (strcmp((char *)payload, "on") == 0){
digitalWrite(LED, HIGH);
} else if (strcmp((char *)payload, "off") == 0){
digitalWrite(LED, LOW);
}
}
}
void setup() {
Serial.begin(115200);
// connect to wifi
WiFi.mode(WIFI_STA);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println(F("WiFi connected"));
Serial.println(F("IP address: "));
Serial.println(WiFi.localIP());
// connect to mqtt server
mqttclient.setServer(BROKER_IP, 1883);
mqttclient.setCallback(callback);
connect();
pinMode(LED, OUTPUT);
}
void loop() {
if (!mqttclient.connected()) { //commented this out; for some reasom it kept decreasing button responsiveness & performance.
connect(); //maybe it keeps trying to reconnect? No wifi issues...
}
mqttclient.loop();
// put your main code here, to run repeatedly:
//vars to keep track of time
static const unsigned long REFRESH_INTERVAL = 1000; // ms
static unsigned long lastRefreshTime = 0;
//if time between now and last update is more than time interval
if(millis() - lastRefreshTime >= REFRESH_INTERVAL)
{
lastRefreshTime += REFRESH_INTERVAL;
lightstate = analogRead(A0);
Serial.println(lightstate);
char lightstateStr[4];
itoa(lightstate, lightstateStr, 10);
mqttclient.publish("/lightstate", lightstateStr, false);
}
}
void connect() {
while (WiFi.status() != WL_CONNECTED) {
Serial.println(F("Wifi issue"));
delay(3000);
}
Serial.print(F("Connecting to MQTT server... "));
while(!mqttclient.connected()) {
if (mqttclient.connect(WiFi.macAddress().c_str())) {
Serial.println(F("MQTT server Connected!"));
mqttclient.subscribe("/led/arduino");
} else {
Serial.print(F("MQTT server connection failed! rc="));
Serial.print(mqttclient.state());
Serial.println("try again in 10 seconds");
// Wait 5 seconds before retrying
delay(20000);
}
}
}
| [
"cgoulart35@gmail.com"
] | cgoulart35@gmail.com |
7377663cbaea0a80b862f0e925ea695a0cd83864 | f9420ecedae1c6a4ca331c1630f7c459f4c6d9bc | /Semester1/Homework9/Task1/hash.cpp | 96a55524f24cd1c625ba156800df84cc3b77a9c1 | [] | no_license | alexander-podshiblov/HomeTasks_Programming | 6b45a1d43f546a5c938d9524255d3d56002f5325 | 6e3714d9d10d13e79bd3b8387584cccc01ac4cab | refs/heads/master | 2020-06-02T16:13:29.506306 | 2014-08-12T13:22:57 | 2014-08-12T13:22:57 | 3,526,316 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 934 | cpp | #include "stdafx.h"
#include <string.h>
struct Word
{
char s[250];
int repeats;
Word *next;
};
Word *createWord(char *s)
{
Word *tmp = new Word;
strcpy(tmp->s, s);
tmp->repeats = 1;
tmp->next = NULL;
return tmp;
}
Word **createArray(const int lengthArray)
{
Word **m = new Word *[lengthArray];
for(int i = 0; i < lengthArray; i++)
m[i] = NULL;
return m;
}
unsigned int hashFunc(char *s, const int lengthArray)
{
const int p = 59;
unsigned long long pPower = 1;
unsigned long long hash = 0;
int n = strlen(s);
for (int i = 0; i < n; i++)
{
hash = hash + s[i] * pPower;
pPower = pPower * p;
}
return hash % lengthArray;
}
void delChain(Word *tmp)
{
if (tmp->next == NULL)
{
delete tmp->next;
tmp->next = NULL;
}
else
delChain(tmp->next);
}
void clear(Word **m, const int lengthArray)
{
for (int i = 0; i < lengthArray; i++)
{
if (m[i] != NULL)
{
delChain(m[i]);
}
delete m[i];
}
} | [
"alexander.podshiblov@gmail.com"
] | alexander.podshiblov@gmail.com |
199f3869e914134ef7a0bad7e5cacbe8ef0a8871 | 30959305ec58f419dc586960cd79619238756d44 | /structure.cpp | dc0e3bac6d2e1c99d5ab318819e30f84698671a7 | [] | no_license | shaileshm24/CPP-Practice | ad7340a2944709f95914655ec0d48d8c6ae4b3d1 | c369b52c9d6e90c811d3a37a850197a2cfc6be4f | refs/heads/master | 2023-04-19T07:30:14.089478 | 2021-05-05T12:12:24 | 2021-05-05T12:12:24 | 364,564,390 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,406 | cpp | #include <iostream>
#include <iomanip>
#include <cstdio>
//===========without typedef===========
// struct student{
// int sid;
// const char* name;
// float marks;
// };
// int main(){
// struct student s1;
//=========creating json object============
// s1={
// sid:1,
// name:"shailesh",
// marks:87.23,
// };
//=========without json object============
// s1.sid=1;
// s1.name="shailesh";
// s1.marks=87.23;
// std::cout<<s1.sid<<std::endl<<s1.name<<std::endl<<s1.marks;
// return 0;
// }
//===========with typedef===========
typedef struct student
{
int sid;
const char *name;
float marks;
} stud;
int main()
{
stud s1;
s1 = {
sid : 1,
name : "shailesh",
marks : 87.23f,
};
// ======without absolute value========
std::cout << std::endl
<< "Without using abs function from csdtio library but using setprecision manipulator" << std::endl;
std::cout << s1.sid << std::endl
<< s1.name << std::endl
<< std::setprecision(9) << s1.marks <<" "<<sizeof(s1.marks)<< std::endl;
// ======with absolute value========
std::cout << std::endl
<< "Using abs function from csdtio library" << std::endl;
std::cout << s1.sid << std::endl
<< s1.name << std::endl
<< abs(s1.marks);
return 0;
} | [
"shaileshmali97@gmail.com"
] | shaileshmali97@gmail.com |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.