blob_id stringlengths 40 40 | language stringclasses 1 value | repo_name stringlengths 5 117 | path stringlengths 3 268 | src_encoding stringclasses 34 values | length_bytes int64 6 4.23M | score float64 2.52 5.19 | int_score int64 3 5 | detected_licenses listlengths 0 85 | license_type stringclasses 2 values | text stringlengths 13 4.23M | download_success bool 1 class |
|---|---|---|---|---|---|---|---|---|---|---|---|
db6938a8dd54b6fa00ecb91347ee208c2866472a | C++ | MohammedMaaz/cpp-programs | /sfml/scientific_calc/headers/styling.h | UTF-8 | 7,899 | 2.890625 | 3 | [] | no_license | #ifndef STYLING_H_INCLUDED
#define STYLING_H_INCLUDED
#include<SFML/Graphics.hpp>
#include<string>
class Button : public sf::Transformable
{
public:
//public data-members
//NOTE: Convention for data-members followed is that there first alphabet is capitalized
std::string ReturnValue;
bool IsClicked = false;
void setDimensions(float X1, float Y1, float X2, float Y2)
{
x1=X1; y1=Y1; x2=X2; y2=Y2;
//Drawing the button
Box.setSize(sf::Vector2f(x2-x1,y2-y1));
Box.setPosition(x1,y1);
}
void syncWithWindow(sf::RenderWindow* userWindow)
{
win = userWindow;
}
void setColor(short r, short g, short b, short a=255)
{
Clr = sf::Color(r,g,b,a);
Box.setFillColor(Clr);
}
void setTextFont(sf::Font &userFont)
{
font = userFont;
text.setFont(font);
}
void writeText(sf::String str)
{
text.setString(str);
textX = x1 + ( (x2-x1)-text.getLocalBounds().width )/2;
textY = y1 + ( (y2-y1)-text.getLocalBounds().height )/2;
text.setPosition(textX,textY);
boxStr = str;
}
void setTextOffset(float x, float y)
{
textX = textX + x;
textY = textY + y;
text.setPosition(textX,textY);
}
void setTextColor(short r, short g, short b, short a=255)
{
textClr = sf::Color(r,g,b,a);
text.setFillColor(textClr);
}
void setOutline(short r, short g, short b, short a=255, float width=1)
{
outlineClr = sf::Color(r,g,b,a);
outlineWidth = width;
Box.setOutlineColor(outlineClr);
Box.setOutlineThickness(outlineWidth);
}
bool isHovered()
{
if(win==nullptr)
return false;
sf::Vector2i mousePos = sf::Mouse::getPosition(*win);
if(mousePos.x>=x1 && mousePos.x<=x2 && mousePos.y>=y1 && mousePos.y<=y2)
return true;
else
return false;
}
void setHoverDimensions(float X1, float Y1, float X2, float Y2)
{
hoverDimensionsTrigger = true;
hoverX1=X1; hoverY1=Y1; hoverX2=X2; hoverY2=Y2;
}
void setHoverTextColor(short r, short g, short b, short a=255)
{
hoverTextClr = sf::Color(r,g,b,a);
hoverTextClrTrigger = true;
}
void setHoverColor(short r, short g, short b, short a=255, float time = 0)
{
hoverClr = sf::Color(r,g,b,a);
hoverClrTrigger = true;
if(time<=0)
{
rT = Clr.a;
startRTime = Clr.a;
startHTime = hoverClr.a;
hT = hoverClr.a;
}
else
transitionTime = time;
}
void writeHoverText(sf::String str)
{
text.setString(str);
hoverTextX = hoverX1 + ( (hoverX2-hoverX1)-text.getLocalBounds().width )/2;
hoverTextY = hoverY1 + ( (hoverY2-hoverY1)-text.getLocalBounds().height )/2;
hoverBoxStrTrigger = true;
hoverBoxStr = str;
}
void setHoverTextOffset(float x, float y)
{
hoverTextX = hoverTextX + x;
hoverTextY = hoverTextY + y;
}
void setHoverOutline(short r, short g, short b, short a=255, float width=1)
{
hoverOutlineClr = sf::Color(r,g,b,a);
hoverOutlineWidth = width;
hoverOutlineTrigger = true;
}
void trackClick(sf::Event& event)
{
if ( isClickable && ((this->isHovered() && event.type == sf::Event::MouseButtonPressed && event.mouseButton.button==sf::Mouse::Left) || (sf::Keyboard::isKeyPressed(clickKey))) )
{
realClick = true;
IsClicked = true;
sound.play();
}
else if( isClickable && ((this->isHovered() && event.type == sf::Event::MouseButtonReleased && event.mouseButton.button==sf::Mouse::Left) || (event.key.code==clickKey)) )
realClick = false;
}
void setClickable(bool val)
{
isClickable = val;
}
void setClickColor(short r, short g, short b, short a=255)
{
clickClr = sf::Color(r,g,b,a);
clickClrTrigger = true;
}
void setClickSound(sf::SoundBuffer &buffer)
{
soundBuffer = buffer;
sound.setBuffer(buffer);
}
void setClickDimensions(float X1, float Y1, float X2, float Y2)
{
clickX1 = X1; clickX2 = X2; clickY1 = Y1; clickY2 = Y2;
clickDeimensionsTrigger = true;
}
void Draw()
{
if(hoverDimensionsTrigger)
{
this->setDimensions(x1,y1,x2,y2);
if( this->isHovered())
{
Box.setSize(sf::Vector2f(hoverX2-hoverX1,hoverY2-hoverY1));
Box.setPosition(hoverX1,hoverY1);
}
}
if(hoverBoxStrTrigger)
{
text.setString(boxStr);
text.setPosition(textX,textY);
if(this->isHovered())
{
text.setString(hoverBoxStr);
text.setPosition(hoverTextX,hoverTextY);
}
}
if(hoverTextClrTrigger)
{
this->setTextColor(textClr.r,textClr.g,textClr.b,textClr.a);
if( this->isHovered() )
text.setFillColor(hoverTextClr);
}
if(hoverOutlineTrigger)
{
this->setOutline(outlineClr.r,outlineClr.g,outlineClr.b,outlineClr.a,outlineWidth);
if( this->isHovered() )
{
Box.setOutlineColor(hoverOutlineClr);
Box.setOutlineThickness(hoverOutlineWidth);
}
}
if(hoverClrTrigger)
{
if(this->isHovered())
{
rT=startRTime;
Box.setFillColor(sf::Color(hoverClr.r,hoverClr.g,hoverClr.b,hT));
if(hT<hoverClr.a)
hT+=transitionTime;
}
else
{
hT=startHTime;
Box.setFillColor(sf::Color(Clr.r,Clr.g,Clr.b,rT));
if(rT<hoverClr.a)
rT+=transitionTime;
}
}
if(clickDeimensionsTrigger)
{
if(!hoverDimensionsTrigger)
this->setDimensions(x1,y1,x2,y2);
if(realClick)
{
Box.setSize(sf::Vector2f(clickX2-clickX1,clickY2-clickY1));
Box.setPosition(clickX1,clickY1);
}
}
if(clickClrTrigger)
{
if(!hoverClrTrigger)
Box.setFillColor(Clr);
if(realClick)
Box.setFillColor(clickClr);
}
win->draw(Box);
win->draw(text);
IsClicked = false;
}
private:
sf::RenderWindow* win;
sf::Font font;
sf::SoundBuffer soundBuffer;
sf::Sound sound;
float x1,y1,x2,y2, hoverX1,hoverY1,hoverX2,hoverY2, clickX1,clickX2,clickY1,clickY2;
float textX, textY, hoverTextX,hoverTextY;
sf::String boxStr, hoverBoxStr;
sf::Color Clr, hoverClr, clickClr;
sf::Color textClr, hoverTextClr;
sf::Color outlineClr, hoverOutlineClr;
float outlineWidth, hoverOutlineWidth;
float transitionTime, hT = 30, rT = 30, startRTime=30, startHTime = 30;
sf::Keyboard::Key clickKey = sf::Keyboard::Return;
bool hoverDimensionsTrigger = false;
bool hoverClrTrigger = false;
bool hoverBoxStrTrigger = false;
bool hoverTextClrTrigger = false;
bool hoverOutlineTrigger = false;
bool clickClrTrigger = false;
bool isClickable = true;
bool realClick = false;
bool clickDeimensionsTrigger = false;
protected:
// To access the shape and text properties by the inherited/Daughter class
sf::RectangleShape Box; //to access the shape properties
sf::Text text; //to access the text such as obj.text.sfmlProp etc.
};
#endif // STYLING_H_INCLUDED
| true |
630b440557ba974079e48e8f36236a09ebe61c06 | C++ | H2rOver/H2RoverExamples | /IMU/IMUTest/IMUTest.ino | UTF-8 | 1,047 | 3.09375 | 3 | [
"MIT"
] | permissive |
/* Created By: Daniel Benusovich
Created On: 4 November 2017
Last Edited By: Daniel Benusovich
Last Edited On: 4 November 2017
*/
#include <IMU.h>
#include <MotorControl.h>
#include <PinDeclarations.h>
IMU thingy;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000);
/* The number passed in is the ID number for the sensor. It must be unique.
The IMU will attempt to calibrate itself by turning and stopping repeatedly. Please contact the creator of the library if the IMU does not calibrates after several cycles
*/
thingy.initialize(0);
}
void loop() {
// put your main code here, to run repeatedly:
//Declare a 16 bit int array of size three
// 16 bits to fully represent the numbers
// 3 indices for X Y and Z
int16_t array[3];
//Pass in the array for it to get populated
thingy.getXYZ(array);
//Read from the array! Easy day
Serial.print("X: ");
Serial.print(array[0], DEC);
Serial.print(" Y: ");
Serial.print(array[1], DEC);
Serial.print(" Z: ");
Serial.println(array[2], DEC);
}
| true |
4fa21345671c0243586665ad31006428cd7ed86b | C++ | eulphean/InteractiveTouch | /src/Connection.h | UTF-8 | 1,433 | 3.28125 | 3 | [] | no_license | // Author: Amay Kataria
// Date: 10/3/2017
// Description: Defines a Connection class that gets instantiated as soon as a new
// connection is observed. Every connection is represented by a successful completion
// of the circuit, which is indicated by a "keyPressed" event on the makey makey board.
#pragma once
#include "ofMain.h"
class Connection {
public:
// We always want our rectangles to begin at y = 0 and extrude from there.
const int defaultConnectionY = 0;
const int defaultConnectionWidth = 30;
const int defaultConnectionHeight = 40;
// Length and width of the rectangle.
ofVec2f dimensions;
// --------------------- Public methods ---------------------------------
Connection() {
}
Connection(int currentConnectionX);
// Copy constructor.
Connection(const Connection &con) {
position = con.position;
color = con.color;
dimensions = con.dimensions;
};
// Overload = operator.
Connection& operator=(const Connection &con) {
this -> position = con.position;
this -> color = con.color;
this -> dimensions = con.dimensions;
return *this;
}
// Destructor.
~Connection() {};
void update();
void draw();
void extendConnection(int radiusToBeAdded);
private:
// Connection variables to define visual state.
ofPoint position;
ofColor color;
};
| true |
15235a64445ec87c651ec6e2a1327db48190d7f9 | C++ | changsongzhu/leetcode | /C++/category/hash_table/358_h.cpp | UTF-8 | 1,466 | 3.671875 | 4 | [] | no_license | /**
358[H]. Rearrange String k Distance Apart
Given a non-empty string str and an integer k, rearrange the string such that the same characters are at least distance k from each other.
All input strings are given in lowercase letters. If it is not possible to rearrange the string, return an empty string "".
Example 1:
str = "aabbcc", k = 3
Result: "abcabc"
The same letters are at least distance 3 from each other.
Example 2:
str = "aaabc", k = 3
Answer: ""
It is not possible to rearrange the string.
Example 3:
str = "aaadbbcc", k = 2
Answer: "abacabcd"
Another possible answer is: "abcabcda"
The same letters are at least distance 2 from each other.
**/
class Solution {
public:
string rearrangeString(string str, int k) {
unordered_map<char, int> m;
priority_queue<pair<int, char>> q;
for(auto s:str) m[s]++;
for(auto it=m.begin();it!=m.end();it++) q.push_back({it.second, it->first});
string res="";
int len=str.size();
while(!q.empty())
{
vector<pair<int, char> > v;
int cnt=min(k, len);
for(int i=0;i<cnt;i++)
{
if(q.empty()) return "";
auto a=q.top();q.pop();
a.first--;
res.push_back(a.second);
if(a.first>0) v.push_back(a);
len--;
}
for(auto a:v) q.push_back(a);
}
return res;
}
};
| true |
54bb32fa548d38e0cfd973462432d3d5d64d186c | C++ | run921/STL | /containers_perfomance_test/containers_perfomance_test/containers_perfomance_test.cpp | GB18030 | 17,976 | 3.5 | 4 | [] | no_license | /********************************
*ܣSTL
*
*by ǿ
**********************************/
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<array>
#include<ctime>
#include<cstdlib> //qsort,bsearch,NULL
using namespace std;
long get_a_target_long() //һֵСrandصֵRAND_MAX
{
long target = 0;
cout << "target(0~" << RAND_MAX << "):";
cin >> target;
return target;
}
string get_a_target_string() //תΪַ
{
long target = 0;
char buf[10];
cout << "target(0~" << RAND_MAX << "):";
cin >> target;
snprintf(buf, 10, "%d", target);
return string(buf);
}
int compareLongs(const void* a, const void* b) //qsort()
{
return (*(long*)a - *(long*)b);
}
int compareString(const void* a, const void* b)
{
if (*(string*)a > * (string*)b)return 1;
if (*(string*)a == *(string*)b)return 0;
if (*(string*)a < *(string*)b)return -1;
}
//ArrayԣʹõQsort,Bsearch
namespace jj01{
void test_array()
{
cout << "\ntest_array()...............\n";
array<long, 10000> c;
clock_t timeStart = clock();
for (long i = 0; i < 10000; ++i)
{
c[i] = rand();
}
cout << "milli-seconds:" << (clock() - timeStart) << endl;
cout << "array.size()" << c.size() << endl;
cout << "array.front()" << c.front() << endl;
cout << "array.back()" << c.back() << endl;
cout << "array.data()" << c.data() << endl;
long target = get_a_target_long();
timeStart = clock();
qsort(c.data(), 10000, sizeof(long), compareLongs);
long* pItem = (long*)bsearch(&target, (c.data()), 10000, sizeof(long), compareLongs);
cout << "asort()+bsearch(),milli-seconds:" << (clock() - timeStart) << endl;
if (*pItem != NULL)
cout << "found," << *pItem << endl;
else
cout << "not found" << endl;
}
}
//vector
#include<vector>
#include<stdexcept>
#include<string>
#include<cstdlib> //abort()
#include<cstdio> //snprintf()
#include<iostream>
#include<ctime>
#include<algorithm>
namespace jj02
{
void test_vector(long& value)
{
cout << "\ntest_vector().........\n";
vector<string> c;
char buf[10];
clock_t timeStart = clock();
for (int i = 0; i < value; ++i)
{
//СܻᳬջС
try
{
snprintf(buf,10,"%d",rand());
c.push_back(string(buf));
}
catch (exception& p)
{
cout << "i=" << i << p.what() << endl;
abort();
}
cout << "milli-seconds:" << (clock()-timeStart) << endl;
cout << "vrctor.size()=" << c.size() << endl;
cout << "vector.front()" << c.front() << endl;
cout << "vector.back()" << c.back() << endl;
cout << "vector.data()" << c.data() << endl;
cout << "vector.capacity()" << c.capacity() << endl;
}
string target = get_a_target_string();
{
timeStart = clock();
auto pItem = ::find(c.begin(), c.end(), target); //ֱӲ
cout << "::find(), milli-seconds:" << timeStart - clock() << endl;
if (pItem != c.end)
cout << "found," << *pItem << endl;
else
cout << "not found" << endl;
{
timeStart = clock();
sort(c.begin(), c.end());
string* pItem = (string*)bsearch(&target, (c.data()), c.size(), sizeof(string), compareString); //ֲ
}
}
}
}
//˫listܲ
#include<list>
namespace jj03
{
void test_list(long& value)
{
cout << "\ntest_list().......\n";
list<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf,10,"%d",rand());
c.push_back(string(buf));
}
catch (exception& p)
{
cout << "i=" << i << " " << p.what() << endl;
abort();
}
}
//ʼӡlistϢ
cout << "milli-seconds:" << timeStart - clock() << endl;
cout << "list.size():" << c.size() << endl;
cout << "list.max_size():" << c.max_size() << endl;
cout << "list.front():" << c.front() << endl;
cout << "list.back():" << c.back() << endl;
//Բ
string target = get_a_target_string();
timeStart = clock();
auto pItem = ::find(c.begin(),c.end(),target);
cout << "::find(),milli-seconds:" << timeStart - clock() << endl;
if (pItem != c.end())
cout << "found," << *pItem << endl;
else
cout << "not found" << endl;
timeStart = clock();
c.sort();
cout << "c.sort(),milli-seconds:" << timeStart - clock() << endl;
}
}
//forward_listܲ
#include<forward_list>
namespace jj04
{
void test_forward_test(long& value)
{
cout << "\ntest_forward_list................\n";
forward_list<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf,10,"%d",rand());
c.push_front(string(buf));
}
catch (exception& p)
{
cout << "i:" << i << " " << p.what() << endl;
abort();
}
}
//Ϣ
cout << "milli-second:" << timeStart - clock() << endl;
cout << "forward_list.max_size()=" << c.max_size() << endl;
cout << "fordward_list.front()" << c.front() << endl;
string target = get_a_target_string();
timeStart = clock();
auto pItem = ::find(c.begin(),c.end(),target);
cout << "::find(),milli-seconds:" << timeStart - clock() << endl;
if (pItem != c.end())
cout << "found," << *pItem << endl;
else
cout << "not found" << endl;
timeStart = clock();
c.sort();
cout << "sort milli-seconds:" << timeStart - clock() << endl;
}
}
//dequeܲ
#include<deque>
namespace jj05
{
void test_deque(long& value)
{
cout << "\ntest_deque().......\n";
deque<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf, 10, "%d", rand());
c.push_back(string(buf));
}
catch (exception& p)
{
cout << "i:" << i << " " << p.what() << endl;
abort();
}
}
//Ϣ
cout << "milli-seconds:" << timeStart - clock() << endl;
cout << "deque.size():" << c.size() << endl;
cout << "deque.front():" << c.front() << endl;
cout << "deque.back():" << c.back() << endl;
cout << "deque.max_size():" << c.max_size() << endl;
string target = get_a_target_string();
timeStart = clock();
auto pItem = ::find(c.begin(), c.end(), target);
cout << "::find(),milli-seconds:" << timeStart - clock() << endl;
if (pItem != c.end())
cout << "found," << *pItem << endl;
else
cout << "not found!" << endl;
}
}
//ջstackܲԣstackdequeʵ֣
#include<stack>
namespace jj17
{
void test_stack(long& value)
{
cout << "\ntest_stack()...........\n";
stack<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf, 10, "%d", rand());
c.push(string(buf));
}
catch (exception& p)
{
cout << "i=" << i << " " << p.what() << endl;
abort();
}
}
cout << "milli-seconds:" << timeStart - clock() << endl;
cout << "stack.size():" << c.size() << endl;
cout << "stack.top():" << c.top() << endl;
c.pop();
cout << "stack.size():" << c.size() << endl;
cout << "stack.top():" << c.top() << endl;
}
}
//queueܲԣqueuedequeʵ֣
#include<queue>
namespace jj18
{
void test_queue(long& value)
{
cout << "\ntest_stack()...........\n";
queue<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf, 10, "%d", rand());
c.push(string(buf));
}
catch (exception & p)
{
cout << "i=" << i << " " << p.what() << endl;
abort();
}
}
cout << "milli-seconds:" << timeStart - clock() << endl;
cout << "queue.size():" << c.size() << endl;
cout << "queue.top():" << c.front() << endl;
cout << "queue.back():" << c.back() << endl;
c.pop();
cout << "queue.size():" << c.size() << endl;
cout << "queue.top():" << c.front() << endl;
cout << "queue.back():" << c.back() << endl;
}
}
//multisetܲԣʵ֣multiؼֱʾkeyظ
#include<set>
namespace jj06
{
void test_multiset(long &value)
{
cout << "\ntest_multiset()..................\n";
multiset<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf, 10, "%d", rand());
c.insert(string(buf));
}
catch (exception& p){
cout << "i=" << i << " " << p.what() << endl;
abort();
}
}
cout << "milli-seconds:" << (clock() - timeStart) << endl;
cout << "multiset.size()=" << c.size() << endl;
cout << "multiset.max_size()=" << c.max_size() << endl;
string target = get_a_target_string();
{
timeStart = clock();
auto pItem = ::find(c.begin(), c.end(), target); //c.find()ܶ
cout << "::find(),milli-seconds:" << (clock() - timeStart) << endl;
if (pItem != c.end())
cout << "found," << *pItem << endl;
else
cout << "not found!" << endl;
}
{
timeStart = clock();
auto pItem = c.find(target); //::find()ܶ
cout << "c.find(),milli-seconds:" << (clock() - timeStart) << endl;
if (pItem != c.end())
cout << "found," << *pItem << endl;
else
cout << "not found!" << endl;
}
}
}
//multimapܲԣ
#include <utility>
#include<map>
namespace jj07
{
void test_map(long& value)
{
cout << "\ntest_multimap()..................\n";
multimap<long,string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf, 10, "%d", rand());
//multimap[]insertion
c.insert(pair<long,string>(i,buf));
}
catch (exception & p)
{
cout << "i=" << i << " " << p.what() << endl;
abort();
}
}
cout << "milli-seconds:" << (clock() - timeStart) << endl;
cout << "multimap.size()=" << c.size() << endl;
cout << "multimap.max_size()=" << c.max_size() << endl;
string target = get_a_target_string();
{
timeStart = clock();
auto pItem = ::find(c.begin(), c.end(), target); //c.find()ܶ
cout << "::find(),milli-seconds:" << (clock() - timeStart) << endl;
if (pItem != c.end())
cout << "found," << *pItem << endl;
else
cout << "not found!" << endl;
}
{
timeStart = clock();
auto pItem = c.find(target); //::find()ܶ
cout << "c.find(),milli-seconds:" << (clock() - timeStart) << endl;
if (pItem != c.end())
cout << "found," << (*pItem).second << endl;
else
cout << "not found!" << endl;
}
}
}
//unordered_multimapܲ(hashtable)
#include<unordered_set>
namespace jj08
{
void test_unordered_multimap(long& value)
{
cout << "\ntest_unordered_multimap()............";
unordered_multimap<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf, 10, "%d", buf);
c.insert(string(buf));
}
catch (exception& p)
{
cout << "i=" << i << " " << p.what() << endl;
abort();
}
}
cout << "milli-seconds:" << (clock() - timeStart) << endl;
cout << "unordered_multimap.size()=" << c.size() << endl;
cout << "unordered_multimap.max_size()=" << c.max_size() << endl;
cout << "unordered_multimap.bucket_count()=" << c.bucket_count() << endl;
cout << "unordered_multimap.load_factor()=" << c.load_factor() << endl;
cout << "unordered_multimap.max_load_factor()=" << c.max_load_factor() << endl;
cout << "unordered_multimap.max_bucket_count()=" << c.max_bucket_count() << endl;
for (unsigned i = 0; i < 20; ++i)
{
cout << "bucket #" << i << " has " << c.bucket_size(i) << " elements.\n";
}
string target = get_a_target_string();
{
timeStart = clock();
auto pItem = ::find(c.begin, c.end(), target); //c.find()ܶ
cout << "::find(),milli-second:" << timeStart - clock() << endl;
if (pItem != c.end())
cout << "found," << *pItem << endl;
else
cout << "not found!" << endl;
}
{
timeStart = clock();
auto pItem = c.find(c.begin, c.end(), target); //c.find()ܶ
cout << "c.find(),milli-second:" << timeStart - clock() << endl;
if (pItem != c.end())
cout << "found," << *pItem << endl;
else
cout << "not found!" << endl;
}
}
}
//unordered_multimapܲ(hashtable)
#include<unordered_map>
namespace jj09
{
void test_unordered_multimap(long& value)
{
cout << "\ntest_unordered_multimap()............";
unordered_multimap<long,string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf, 10, "%d", buf);
c.insert(pair<long,string>(i,buf));
}
catch (exception & p)
{
cout << "i=" << i << " " << p.what() << endl;
abort();
}
}
cout << "milli-seconds:" << (clock() - timeStart) << endl;
cout << "unordered_multimap.size()=" << c.size() << endl;
cout << "unordered_multimap.max_size()=" << c.max_size() << endl;
for (unsigned i = 0; i < 20; ++i)
{
cout << "bucket #" << i << " has " << c.bucket_size(i) << " elements.\n";
}
string target = get_a_target_string();
{
timeStart = clock();
auto pItem = c.find(c.begin, c.end(), target); //c.find()ܶ
cout << "c.find(),milli-second:" << timeStart - clock() << endl;
if (pItem != c.end())
cout << "found," << (*pItem).second() << endl;
else
cout << "not found!" << endl;
}
}
}
//set
namespace jj13
{
void test_set(long& value)
{
cout << "\ntest_set().............\n";
set<string> c;
char buf[10];
clock_t timeStart = clock();
for (long i = 0; i < value; ++i)
{
try
{
snprintf(buf, 10, "%d", rand());
c.insert(string(buf));
}
catch (exception& p)
{
cout << "i=" << i << " " << p.what() << endl;
abort();
}
}
cout << "milli-second:" << (clock() - timeStart) << endl;
cout << "set.size()=" << c.size() << endl;
cout << "set.max_size()" << c.max_size() << endl;
string target = get_a_target_string();
{
timeStart = clock();
auto pItem = ::find(c.begin(), c.end(), target); //c.find()ܶ
cout << "::find(),milli-seconds:" << (clock() - timeStart) << endl;
if (pItem != c.end())
cout << "found, " << *pItem << endl;
else
cout << "not found!" <<endl;
}
{
timeStart = clock();
auto pItem = c.find(target);
cout << "c.find(),milli-seconds:" << (clock() - timeStart) << endl;
if (pItem != c.end())
cout << "found, " << *pItem << endl;
else
cout << "not found!" << endl;
}
}
}
int main()
{
system("pause");
return EXIT_SUCCESS;
} | true |
bb0c2334673a8470a882de39080abe20b3037fb9 | C++ | ioqoo/PS | /Samsung Academy/day4/2904.cpp | UTF-8 | 893 | 2.578125 | 3 | [] | no_license | #include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
using namespace std;
bool sieve[MAX];
vector<int> primes;
int nums[100];
int N;
int prime_cnt[100][1001];
void decomp(int order, int n){
int curr = n;
while(curr != 1){
for (int p: primes){
if (curr % p == 0) {
curr /= p;
prime_cnt[order][p]++;
break;
}
}
}
return;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
for (int i=2;i<=1000;i++){
if (!sieve[i]) {
sieve[i] = true;
primes.push_back(i);
for (int j=2;i*j<=MAX;j++){
sieve[i*j] = true;
}
}
}
scanf("%d", &N);
for (int i=0;i<N;i++){
scanf("%d", &nums[i]);
}
for (int i=0;i<N;i++){
decomp(i, nums[i]);
}
for (int i=0;i<N;i++){
for (int j=1;j<=10;j++){
printf("%d ", prime_cnt[i][j]);
}
printf("\n");
}
printf("\n");
return 0;
}
| true |
cceeb567418d072d18059f850d31e4318a01fcbe | C++ | PhantomLimb/OpenWorkshopEditor | /Util.hpp | UTF-8 | 1,022 | 2.953125 | 3 | [] | no_license | #ifndef UTIL_HPP
#define UTIL_HPP
#include <string>
#include <vector>
#include <fstream>
#include <cstring>
using namespace std;
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef signed short int sint16;
typedef unsigned long int uint32;
class Util
{
public:
static void string_split(string p_input, string p_delim, vector<string> & p_vec);
static string string_strip(string p_input, string p_delim);
static int string_to_int(string p_string);
static unsigned int string_to_uint(string p_string);
static uint16 read_uint8(fstream & p_file, bool do_print = false);
static uint16 read_uint16(fstream & p_file, bool do_print = false);
static uint32 read_uint32(fstream & p_file, bool do_print = false);
static string read_string(fstream & p_file, bool do_print = false, const int p_size=512, char p_delim='\0');
static sint16 read_sint16(fstream & p_file, bool do_print = false);
static void clear_buffer(char * buffer, int size);
};
#endif // UTIL_HPP
| true |
cba4dc5a236cd372241234a0b99abfdbc042f269 | C++ | FireFoxPlus/LeetCode | /LeetCode/valid skudo.cpp | UTF-8 | 1,143 | 3.046875 | 3 | [] | no_license | #include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
bool isValidSudoku(vector<vector<char> > &board) {
static bool row[9][9];
static bool col[9][9];
static bool box[9][9];
for(int i = 0; i < 9; i++)
for(int j = 0; j < 9; j++)
{
row[i][j] = false;
box[i][j] = false;
col[i][j] = false;
}
if(row[0][0])
cout<<"true";
for(int i = 0; i < board.size(); i++)
{
vector<char> tmp = board[i];
for(int j = 0; j < 9; j++)
{
if(tmp[j] != '.')
{
if(tmp[j] < '0' || tmp[j] > '9')
return false;
if(!row[i][tmp[j] - '1'] && !col[j][tmp[j] - '1']
&& !box[(i / 3) * 3 + j / 3][tmp[j] - '1'])
{
row[i][tmp[j] - '1'] = true;
col[j][tmp[j] - '1'] = true;
box[(i / 3) * 3 + j / 3][tmp[j] - '1'] = true;
}
else
return false;
}
}
}
return true;
}
};
| true |
a3cd13c836f1fe11b0e004bbc00166d3d126034d | C++ | YogeshSakhalkar/C-plus-plus-language | /constrctor example1/constrctor example1/Source.cpp | UTF-8 | 580 | 3.546875 | 4 | [] | no_license | #include<iostream>
using namespace std;
class complex
{
int image;
int real;
public:
void setImage(int i)
{
this->image=i;
}
void setReal(int r)
{
this->real=r;
}
int getImage()
{
return image;
}
int getReal()
{
return real;
}
void display()
{
cout<<" "<<getImage()<<"\t"<<getReal()<<"\n\n";
}
complex()
{
cout<<"constructor \n";
this->real=0;
this->image=0;
}
};
void main()
{
int i,r;
complex c1,c2;
c2.display();
cout<<"enter the real \n";
cin>>r;
cout<<"enter the image \n";
cin>>i;
c1.setImage(i);
c1.setReal(r);
c1.display();
} | true |
f0b0bde9cebb67bd5882b867cc81c5603de4e536 | C++ | koolguru/CodingPractice | /Leetcode/LargestValueFromTree.cpp | UTF-8 | 1,228 | 3.484375 | 3 | [] | no_license | // Solution for LC # 515: Find the largest value in each tree row
/**
* 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<int> largestValues(TreeNode* root) {
vector<int> results;
if(root == NULL) {
return results;
}
queue<TreeNode*> queue;
queue.push(root);
int levelSize = 1;
int currentMax = std::numeric_limits<int>::min();;
while(!queue.empty()) {
TreeNode* front = queue.front();
queue.pop();
levelSize--;
if(front->left != NULL) {
queue.push(front->left);
}
if(front->right != NULL) {
queue.push(front->right);
}
if(front->val > currentMax) {
currentMax = front->val;
}
if(levelSize == 0) {
levelSize = queue.size();
results.push_back(currentMax);
currentMax = std::numeric_limits<int>::min();;
}
}
return results;
}
};
| true |
e9b95c31b648da95bf08c672ed981a4338102456 | C++ | kyuue/homework-1 | /Homework-1-part2/Homework-1-part2/Homework-1-part2.cpp | UTF-8 | 1,737 | 3.625 | 4 | [] | no_license | // Homework-1-part2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
void duzUcgen(int deger)
{
for (int tryCount = 0; tryCount < 3; tryCount++)
{
if (deger < 3 || deger > 15 || deger % 2 == 0)
{
std::cout << "boyut> ";
std::cin >> deger;
continue;
}
int floorCount = (deger + 1) / 2;
for (int i = 1; i <= floorCount; i++)
{
int spaceCount = floorCount - i;
for (int j = 0; j < spaceCount; j++)
std::cout << " ";
int asteriskCount = i * 2 - 1; // current floor * 2 - 1
for (int j = 0; j < asteriskCount; j++)
std::cout << "*";
std::cout << std::endl;
}
break;
}
}
void tersUcgen(int deger)
{
int tryCount = 3;
while (tryCount-- > 0)
{
if (deger < 3 || deger > 15 || deger % 2 == 0)
{
std::cout << "boyut> ";
std::cin >> deger;
continue;
}
int floorCount = (deger + 1) / 2, i = floorCount;
while (i >= 1)
{
int spaceCount = floorCount - i;
while (spaceCount-- > 0)
std::cout << " ";
int asteriskCount = i * 2 - 1; // current floor * 2 - 1
while (asteriskCount-- > 0)
std::cout << "*";
std::cout << std::endl;
i--;
}
break;
}
}
bool elmas(int deger)
{
if (deger < 5 || deger > 15 || deger % 2 == 0) return false;
duzUcgen(deger);
tersUcgen(deger);
return true;
}
void test(int tryCount)
{
if (tryCount <= 0) return;
int deger;
std::cout << "boyut> ";
std::cin >> deger;
if (!elmas(deger))
test(tryCount - 1);
}
int main()
{
duzUcgen(NULL);
//tersUcgen(NULL);
//test(3);
return 0;
} | true |
fc8b077ae4e43e8498ef5e544b1c27055f5ede3e | C++ | floki2020/Cplus | /Chapter/2.7/4.cpp | UTF-8 | 320 | 3.4375 | 3 | [] | no_license | #include <iostream>
using namespace std;
int MyConvert(int num);
int main()
{
/* code */
int num;
cout<<"Please enter a Celsius value:";
cin>>num;
int result= MyConvert(num);
cout<<num<<" degress Celsius is "<<result<<" degrees Fahrenheit."<<endl;
return 0;
}
int MyConvert(int num)
{
return 1.8*num+32.0;
}
| true |
f7f31db69760ef49aad2bfa8e60622cb3b87d3fc | C++ | SlickHackz/famous-problems-cpp-solutions | /06 Array/Source Files/Z_others/FindDuplicatesinaRangeinArray.cpp | UTF-8 | 409 | 3.609375 | 4 | [] | no_license | #include<iostream>
using namespace std;
void printDuplicates(int arr[],int n)
{
for(int i=0 ; i<=n-1 ; i++)
{
if(arr[abs(arr[i])] >= 0)
arr[abs(arr[i])] = -1*arr[abs(arr[i])] ;
else
cout<<"One of the repeating elements is : "<<abs(arr[i])<<endl;
}
}
int main()
{
int arr[] = {1, 2, 3, 1, 3, 0, 2, 3,3,0};
int n = sizeof(arr)/sizeof(arr[0]);
printDuplicates(arr,n);
cin.get();
return 0;
} | true |
8e6a7b475d00fc4f16b466474211702bac173b7e | C++ | esolera/juego_gato | /hls_project/src/game_session.cpp | UTF-8 | 3,741 | 3.265625 | 3 | [] | no_license | #include <stdio.h>
#include <iostream>
//Variables Globales
int Board[3][3]={{0,0,0},{0,0,0},{0,0,0}};
bool jugador_out;
int posicion;
bool valido;
//Funcion para saber el turno del jugador
bool Check_jugador(){
int jugadas=0;
for ( int i = 0; i < 3; i = i + 1 ){
for ( int j = 0; j < 3; j = j + 1 ){
if(Board[i][j]!=0){
jugadas=jugadas+1;
}
}
}
if(jugadas%2 == 0){
jugador_out=true;
}
else{
jugador_out=false;
}
}
bool Valid_move(){
if(posicion<=2){
if(Board[0][posicion]!=0){
valido=false;
}
else{
valido=true;
}
}
else if(posicion<=5){
if(Board[1][posicion-3]!=0){
valido=false;
}
else{
valido=true;
}
}
else if(posicion<=8){
if(Board[2][posicion-6]!=0){
valido=false;
}
else{
valido=true;
}
}
else {
valido=false;
}
}
int update_State(int posicion, bool jugador) {
int jugador_value;
if (jugador) {
jugador_value = 1;
}
else {
jugador_value = 2;
}
if(posicion <=2) {
Board[0][posicion] = jugador_value;
}
else if(posicion <= 5){
Board[1][posicion-3] = jugador_value;
}
else if(posicion <= 8){
Board[2][posicion-6] = jugador_value;
}
return 0;
}
bool ganador(){
for ( int i = 0; i < 3; i = i + 1 ){
if(((Board[i][0] && Board[i][1] && Board[i][2])==1) || ((Board[i][0] && Board[i][1] && Board[i][2])==2) || ((Board[0][i] && Board[1][i] && Board[2][i])==1) || ((Board[0][i] && Board[1][i] && Board[2][i])==2)){
return true;
}
}
if(((Board[0][0]*Board[1][1]*Board[2][2])==1) || ((Board[0][0]*Board[1][1]*Board[2][2])==8) || ((Board[0][2]*Board[1][1]*Board[2][0])==8) || ((Board[0][2]*Board[1][1]*Board[2][0])==1)){
return true;
}
else{
return false;
}
}
bool empate(){
for (int i = 0; i < 3; i = i + 1) {
for (int j = 0; i < 3; i = i + 1) {
if(Board[i][j]) {
return false;
}
}
}
return true;
}
/* Prueba Valid_move *//*
int main(int argc, char const *argv[]) {
std::cin >> posicion;
Valid_move();
printf("%d\n",valido);
return 0;
}
*/
//Prueba fucnion ganador
/*
int main(int argc, char const *argv[]) {
for (int a = 0; a < 3; a = a + 1 ){
for (int b = 0; b < 3; b = b + 1 ){
Board[a][b]=1;
std::cout << Board[0][0] << Board[0][1] << Board[0][2] << '\n';
std::cout << Board[1][0] << Board[1][1] << Board[1][2] << '\n';
std::cout << Board[2][0] << Board[2][1] << Board[2][2] << '\n';
std::cout << ganador() << '\n';
if(b==2){
Board[a][0]=0;
Board[a][1]=0;
Board[a][2]=0;
}
}
}
for (int a = 0; a < 3; a = a + 1 ){
for (int b = 0; b < 3; b = b + 1 ){
Board[b][a]=1;
std::cout << Board[0][0] << Board[0][1] << Board[0][2] << '\n';
std::cout << Board[1][0] << Board[1][1] << Board[1][2] << '\n';
std::cout << Board[2][0] << Board[2][1] << Board[2][2] << '\n';
std::cout << ganador() << '\n';
if(b==2){
Board[0][a]=0;
Board[1][a]=0;
Board[2][a]=0;
}
}
}
Board[0][0]=1;
Board[1][1]=1;
Board[2][2]=1;
std::cout << Board[0][0] << Board[0][1] << Board[0][2] << '\n';
std::cout << Board[1][0] << Board[1][1] << Board[1][2] << '\n';
std::cout << Board[2][0] << Board[2][1] << Board[2][2] << '\n';
std::cout << ganador() << '\n';
Board[0][0]=0;
Board[1][1]=0;
Board[2][2]=0;
Board[0][2]=1;
Board[1][1]=1;
Board[2][0]=1;
std::cout << Board[0][0] << Board[0][1] << Board[0][2] << '\n';
std::cout << Board[1][0] << Board[1][1] << Board[1][2] << '\n';
std::cout << Board[2][0] << Board[2][1] << Board[2][2] << '\n';
std::cout << ganador() << '\n';
Board[0][2]=0;
Board[1][1]=0;
Board[2][0]=0;
return 0;
}
*/
| true |
264636228ca96bfcb1eab3187558d2243b828472 | C++ | Watanai1245/study | /butterfly.cpp | UTF-8 | 1,318 | 3.390625 | 3 | [] | no_license | #include <stdio.h>
struct number {
int x[10];
int i;
int j;
}num, row, star, space;
void moretriangle (int n)
{
for(row.i=1 ; row.i<=n-1 && row.i>0 ; row.i++)
{
for(star.j=1 ; star.j<=row.i && star.j>0 ; star.j++)
{
printf("* ");
}
for(space.j=1 ; space.j<(2*n)-(row.i*2) && space.j>0 ; space.j++)
{
printf(" ");
}
for(star.j=1 ; star.j<=(n*2)-1 && star.j>0 ; star.j++)
{
printf("* ");
if(star.j == row.i) break;
}
printf("\n");
}
}
void triangle (int n)
{
for(row.i=1 ; row.i<=(2*n)-1 && row.i>0 ; row.i++)
{
printf("* ");
}
printf("\n");
}
void lasstriangle (int n)
{
for(row.i=1 ; row.i<=n-1 && row.i>0 ; row.i++)
{
for(star.j=n-1 ; star.j>=row.i ; star.j--)
{
printf("* ");
}
for(space.j=1 ; space.j<row.i*2 && space.j>0 ; space.j++)
{
printf(" ");
}
for(star.j=n-1 ; star.j>0 ; star.j--)
{
printf("* ");
if(star.j==row.i) break;
}
printf("\n");
}
}
int main()
{
scanf("%d",&num.x[1]);
moretriangle(num.x[1]);
triangle (num.x[1]);
lasstriangle (num.x[1]);
return 0;
}
| true |
5c90bcb83457f89b5093bf44a2be1ea7959ab67a | C++ | Tduderocks/PracticeProblems | /Ch_5/Ch5_Ex5.cpp | UTF-8 | 720 | 3.5 | 4 | [] | no_license | // Chapter 5 ex 5 a,b: works:) c: added to Library :) and d:tested :) works done :)
#include <iostream>
using namespace std;
void DisplayFormatted(int n, int width)
/*Displays the value of n left-aligned in a field of size width.
Post: Value displayed left-aligned in a field of size Width*/
{
cout.setf(ios::left);
cout.width(width);
cout << n << endl;
}
void DisplayFormatted(double x, int widthOfDouble, int decimalPoints)
//
{
cout.setf(ios::fixed);
cout.precision(decimalPoints);
cout.setf(ios::left);
cout.width(widthOfDouble);
cout << x << endl;
}
int main()
// Calls Display Formatted n and x
{
DisplayFormatted(6753,10);
DisplayFormatted(14.7898,10,0);
return(0);
} | true |
2f9e528611d9ca639748c9625040733a800b0bd8 | C++ | CHandPY/EngineCpp_2d | /Engine/Engine/src/core/Input.cpp | UTF-8 | 2,172 | 2.765625 | 3 | [] | no_license | #include "Input.h"
#include <iostream>
int Input::events[LAST_EVENT_BOUND];
int Input::events_started[LAST_EVENT_BOUND];
int Input::events_stopped[LAST_EVENT_BOUND];
int Input::DX = 0, Input::DY = 0, Input::MX = 0, Input::MY = 0;
bool Input::m_grab = false;
int Input::event(int id) {
return events[id];
}
int Input::eventStarted(int id) {
return events_started[id];
}
int Input::eventStopped(int id) {
return events_stopped[id];
}
int Input::getMX() {
return MX;
}
int Input::getMY() {
return MY;
}
int Input::getMDX() {
return DX;
}
int Input::getMDY() {
return DY;
}
void Input::update() {
//resset the key buffers that need resetting.
memset(events_started, 0, sizeof(events));
memset(events_stopped, 0, sizeof(events));
events[MOUSE_WHEEL_UP] = 0;
events[MOUSE_WHEEL_DOWN] = 0;
DX = 0;
DY = 0;
glfwPollEvents();
}
void Input::mouseGrab(bool grab) {
m_grab = grab;
if (grab)
Window::setCursorMode(GLFW_CURSOR_DISABLED);
else
Window::setCursorMode(GLFW_CURSOR_NORMAL);
}
void Input::key_callback(GLFWwindow * window, int key, int scancode, int action, int mods) {
if (key == UNKNOWN_EVENT) return;
if (action == PRESS) {
events[key] = 1;
events_started[key] = 1;
}
if (action == RELEASE) {
events[key] = 0;
events_stopped[key] = 1;
}
if (action == REPEAT) {
}
}
void Input::mouse_callback(GLFWwindow * window, int button, int action, int mods) {
if (button == UNKNOWN_EVENT) return;
button += MOUSE_1;
if (action == PRESS) {
events[button] = 1;
events_started[button] = 1;
}
if (action == RELEASE) {
events[button] = 0;
events_stopped[button] = 1;
}
if (action == REPEAT) {
}
}
void Input::scroll_callback(GLFWwindow * window, double xoffset, double yoffset) {
if (yoffset > 0) {
events_started[MOUSE_WHEEL_UP] = (int)yoffset;
events[MOUSE_WHEEL_UP] = (int)yoffset;
} else {
events_started[MOUSE_WHEEL_DOWN] = (int)yoffset;
events[MOUSE_WHEEL_DOWN] = (int)yoffset;
}
}
void Input::m_pos_callback(GLFWwindow * window, double xpos, double ypos) {
DX = (int) xpos - MX;
DY = (int) ypos - MY;
MX = (int) xpos;
MY = (int) ypos;
}
bool Input::mouseGrabed() {
return m_grab;
}
| true |
ef30ae2e1f39ad7b39774b64cf62b748239b968a | C++ | Souly9/DX12-Utah-Teapot | /Combustion/Wrappers/Camera/Camera.cpp | UTF-8 | 2,695 | 2.71875 | 3 | [] | no_license | #include <stdafx.h>
#include "Camera.h"
Camera::Camera()
{
}
Camera::Camera(float fov, float zNear, float zFar, float aspectRatio,
DirectX::XMVECTOR pos,
DirectX::XMVECTOR rot)
: m_FoV(fov),
m_zNear(zNear),
m_zFar(zFar),
m_AspectRatio(aspectRatio)
{
m_pData = (AlignedCameraData*)_aligned_malloc(sizeof(AlignedCameraData), 16);
m_pData->m_position = pos;
m_pData->m_rotationQuat = rot;
DirectX::XMStoreFloat3(&m_positionFloat, m_pData->m_position);
}
Camera::~Camera()
{
_aligned_free(m_pData);
}
void Camera::UpdateMatrices()
{
//m_pData->m_viewMatrix = DirectX::XMMatrixLookAtLH(DirectX::XMVectorSet(0, 0, -50, 1), DirectX::XMVectorSet(0, 0, 10, 1), DirectX::XMVectorSet(0, 1, 0, 0));
if(m_needsUpdate)
{
m_pData->m_projMatrix = DirectX::XMMatrixPerspectiveFovLH(DirectX::XMConvertToRadians(m_FoV), m_AspectRatio, 0.1f, 100.0f);;
m_pData->m_viewProjMatrix = DirectX::XMMatrixMultiply(m_pData->m_viewMatrix, m_pData->m_projMatrix);
}
}
void Camera::LookAt(DirectX::FXMVECTOR pos, DirectX::FXMVECTOR target, DirectX::FXMVECTOR upDirection)
{
using namespace DirectX;
DirectX::FXMVECTOR zAxis = DirectX::XMVector3Normalize(target - pos);
DirectX::FXMVECTOR xAxis = DirectX::XMVector3Normalize(
DirectX::XMVector3Cross(upDirection, zAxis));
DirectX::FXMVECTOR yAxis = DirectX::XMVector3Cross(zAxis, xAxis);
DirectX::FXMVECTOR zeroVec = DirectX::FXMVECTOR{0,0,0,1};
DirectX::FXMMATRIX orientationMatrix{xAxis, yAxis, zAxis, zeroVec};
DirectX::FXMMATRIX translationMatrix{1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
-pos.m128_f32[0], -pos.m128_f32[1], -pos.m128_f32[2], 1};
m_pData->m_viewMatrix = DirectX::XMMatrixMultiply(translationMatrix, orientationMatrix);
//m_pData->m_viewMatrix = DirectX::XMMatrixLookAtLH(pos, target, upDirection);
m_needsUpdate = true;
}
void Camera::Translate(DirectX::FXMVECTOR newPos)
{
m_pData->m_position = DirectX::XMVectorAdd(m_pData->m_position, newPos);
}
DirectX::XMMATRIX Camera::GetViewMatrix() const
{
return m_pData->m_viewMatrix;
}
DirectX::XMMATRIX Camera::GetProjectionMatrix() const
{
return m_pData->m_projMatrix;
}
DirectX::XMMATRIX Camera::GetViewProjectionMatrix() const
{
return m_pData->m_viewProjMatrix;
}
void Camera::set_FoV(float fov)
{
m_FoV = fov;
}
void Camera::SetPositions(DirectX::FXMVECTOR position)
{
m_pData->m_position = position;
}
DirectX::XMFLOAT3 Camera::GetPosition() const
{
DirectX::XMFLOAT3 pos;
DirectX::XMStoreFloat3(&pos, m_pData->m_position);
return pos;
}
void Camera::SetRotation(DirectX::FXMVECTOR rotation)
{
m_pData->m_rotationQuat = rotation;
}
DirectX::XMVECTOR Camera::GetRotation() const
{
return m_pData->m_rotationQuat;
}
| true |
1b94e90506938360fd599af70bcc0915cdb78cea | C++ | lo1cgsan/rok202021 | /2A_1/cpp/T7_p8_1.cpp | UTF-8 | 289 | 2.9375 | 3 | [] | no_license | /*
* T7_p8_1.cpp
*
*/
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char **argv)
{
float st, rad;
st = 0.0;
do {
rad = st * M_PI/180;
cout << "cos(" << st << ") = "
<< cos(rad) << endl;
st += 10.0;
} while (st != 100);
return 0;
}
| true |
5451d38258fd9970e3a82d2d22c67567c329a680 | C++ | JstD/HackerRank | /Algorithm/non_divisible_subset.cpp | UTF-8 | 845 | 3.1875 | 3 | [] | no_license | #include <bits/stdc++.h>
using namespace std;
string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);
/*
* Complete the 'nonDivisibleSubset' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER k
* 2. INTEGER_ARRAY s
*/
int nonDivisibleSubset(int k, vector<int> s) {
vector<int> aux(k);
int max_point = 0;
for(int i =0;i<s.size();i++){
aux[s[i]%k]++;
}
int count =0;
for(int i=1;i<(k+1)/2;i++){
if(aux[i]>=aux[k-i])
count += aux[i];
else{
count+=aux[k-i];
}
}
if(aux[0]>0)
count +=1;
if(k/2*2==k && aux[k/2]>0)
count++;
return count;
}
int main(){
cout<<nonDivisibleSubset(4,{19,10,12,10,24,25,22});
}
| true |
7dfb4bb9bc12a6baab0f547ec042790147e5f6b6 | C++ | TamasSzep/Framework | /Source/Common/Core/DataStructures/SimpleTypeUnorderedVector.hpp | UTF-8 | 11,126 | 3.359375 | 3 | [] | no_license | // Core/DataStructures/SimpleTypeUnorderedVector.hpp
#pragma once
#include <Core/DataStructures/SimpleTypeVector.hpp>
#include <Core/SimpleBinarySerialization.hpp>
#include <map>
namespace Core
{
template <typename T, typename SizeType = size_t>
class SimpleTypeUnorderedVector
{
enum class State : unsigned char
{
Valid, Invalid, End
};
SimpleTypeVector<T, SizeType> m_Data;
SimpleTypeVector<State, SizeType> m_State;
SimpleTypeVector<SizeType, SizeType> m_UnusedIndices;
SizeType m_CountElements;
inline const T* GetLastElementPointer() const
{
assert(m_CountElements > 0);
auto lastElementIndex = m_Data.GetSize() - 1;
auto pData = m_Data.GetArray() + lastElementIndex;
auto pState = m_State.GetArray() + lastElementIndex;
while (*pState == State::Invalid)
{
--pData;
--pState;
}
return pData;
}
inline SizeType CreateElementAtTheEnd()
{
assert(!m_State.IsEmpty());
auto index = m_Data.GetSize();
m_Data.PushBackPlaceHolder();
m_State.GetLastElement() = State::Valid;
m_State.PushBack(State::End);
return index;
}
public:
SimpleTypeUnorderedVector()
: m_CountElements(0)
{
m_State.PushBack(State::End);
}
// Initializes vector using a begin and an end iterator.
// Indices are the integer numbers of the range [0, N-1], if the iterator encounter N elements.
// If the number of the elements is unknown use the GetSize function
// to figure out the index interval.
template <typename Iterator>
SimpleTypeUnorderedVector(Iterator& begin, Iterator& end)
: m_CountElements(0)
{
for (; begin != end; ++begin)
{
m_Data.PushBack(*begin);
m_State.PushBack(State::Valid);
m_CountElements++;
}
m_State.PushBack(State::End);
}
inline SizeType GetSize() const
{
return m_CountElements;
}
inline T* GetArray()
{
return m_Data.GetArray();
}
inline const T* GetArray() const
{
return m_Data.GetArray();
}
inline bool IsEmpty() const
{
return (m_CountElements == 0);
}
inline const T& operator[](SizeType index) const
{
assert(m_State[index] == State::Valid);
return m_Data[index];
}
inline T& operator[](SizeType index)
{
assert(m_State[index] == State::Valid);
return m_Data[index];
}
inline SizeType Add()
{
++m_CountElements;
if (m_UnusedIndices.IsEmpty())
{
return CreateElementAtTheEnd();
}
else
{
auto index = m_UnusedIndices.PopBackReturn();
m_State[index] = State::Valid;
return index;
}
}
inline SizeType Add(const T& element)
{
SizeType index = Add();
m_Data[index] = element;
return index;
}
inline SizeType AddToTheEnd()
{
++m_CountElements;
return CreateElementAtTheEnd();
}
inline SizeType AddToTheEnd(const T& element)
{
SizeType index = AddToTheEnd();
m_Data[index] = element;
return index;
}
inline void Remove(SizeType index)
{
assert(m_CountElements > 0 && m_State[index] == State::Valid);
--m_CountElements;
m_State[index] = State::Invalid;
m_UnusedIndices.PushBack(index);
}
inline void SetByte(unsigned char value)
{
m_Data.SetByte(value);
}
inline void Clear()
{
m_Data.Clear();
m_State.Clear();
m_UnusedIndices.Clear();
m_State.PushBack(State::End);
m_CountElements = 0;
}
inline SizeType GetCountUnusedElements() const
{
return m_UnusedIndices.GetSize();
}
inline std::map<SizeType, SizeType> ShrinkToFit(bool isShrinkingUnderlyingVectors = true)
{
std::map<SizeType, SizeType> indexMap;
SizeType arraySize = static_cast<SizeType>(m_Data.GetSize());
SizeType targetIndex = 0;
for (SizeType sourceIndex = 0; sourceIndex < arraySize; ++sourceIndex)
{
if (m_State[sourceIndex] == State::Valid)
{
m_Data[targetIndex] = std::move(m_Data[sourceIndex]);
indexMap[sourceIndex] = targetIndex;
targetIndex++;
}
}
m_State.Clear();
m_State.PushBack(State::Valid, targetIndex);
m_State.PushBack(State::End);
m_UnusedIndices.Clear();
if (isShrinkingUnderlyingVectors)
{
m_State.ShrinkToFit();
m_Data.ShrinkToFit();
}
return indexMap;
}
inline const T& GetLastElement() const
{
return *GetLastElementPointer();
}
inline T& GetLastElement()
{
return const_cast<T&>(*GetLastElementPointer());
}
inline SizeType GetLastElementIndex() const
{
return static_cast<SizeType>(GetLastElementPointer() - m_Data.GetArray());
}
template <typename U>
class TIterator
{
U* m_PData;
const State* m_PState;
public:
TIterator(U* pData, const State* pState)
: m_PData(pData)
, m_PState(pState)
{
while (*m_PState == State::Invalid) // State should be either Valid or End.
{
++m_PData;
++m_PState;
}
}
inline bool operator==(TIterator& other) const
{
return (m_PData == other.m_PData);
}
inline bool operator!=(TIterator& other) const
{
return (m_PData != other.m_PData);
}
inline bool operator<(TIterator& other) const
{
return (m_PData < other.m_PData);
}
inline TIterator& operator++()
{
assert(*m_PState != State::End);
do
{
++m_PData;
++m_PState;
} while (*m_PState == State::Invalid); // State should be either Valid or End.
return *this;
}
inline U& operator*() const
{
return *m_PData;
}
inline U* operator->() const
{
return m_PData;
}
inline U* GetDataPtr() const
{
return m_PData;
}
};
using Iterator = TIterator<T>;
using ConstIterator = TIterator<const T>;
private:
template <typename TIt, typename TData>
static inline TIt _GetBeginIterator(TData& data, const SimpleTypeVector<State, SizeType>& state)
{
return TIt(data.GetArray(), state.GetArray());
}
template <typename TIt, typename TData>
static inline TIt _GetEndIterator(TData& data, const SimpleTypeVector<State, SizeType>& state)
{
SizeType arraySize = data.GetSize();
return TIt(data.GetArray() + arraySize, state.GetArray() + arraySize);
}
template <typename TIt>
inline SizeType _ToIndex(const TIt& it) const
{
return static_cast<SizeType>(it.GetDataPtr() - m_Data.GetArray());
}
public:
inline Iterator GetBeginIterator()
{
return _GetBeginIterator<Iterator>(m_Data, m_State);
}
inline ConstIterator GetBeginConstIterator() const
{
return _GetBeginIterator<ConstIterator>(m_Data, m_State);
}
inline Iterator GetEndIterator()
{
return _GetEndIterator<Iterator>(m_Data, m_State);
}
inline ConstIterator GetEndConstIterator() const
{
return _GetEndIterator<ConstIterator>(m_Data, m_State);
}
inline SizeType ToIndex(const Iterator& it) const
{
return _ToIndex(it);
}
inline SizeType ToIndex(const ConstIterator& it) const
{
return _ToIndex(it);
}
bool Contains(const T& element) const
{
auto pData = m_Data.GetArray();
auto pState = m_State.GetArray();
do
{
while (*pState == State::Invalid)
{
++pData;
++pState;
}
if (*pState == State::End)
{
break;
}
if (*pData == element)
{
return true;
}
++pData;
++pState;
} while (true);
return false;
}
inline void ToSimpleTypeVector(SimpleTypeVector<T, SizeType>& result) const
{
result.ClearAndReserve(m_CountElements);
auto pData = m_Data.GetArray();
auto pState = m_State.GetArray();
State state;
while ((state = *pState) != State::End)
{
if (state == State::Valid)
{
result.UnsafePushBack(*pData);
}
++pData;
++pState;
}
}
void SerializeSB(Core::ByteVector& bytes) const
{
Core::SerializeSB(bytes, m_Data);
Core::SerializeSB(bytes, m_State);
Core::SerializeSB(bytes, m_UnusedIndices);
Core::SerializeSB(bytes, m_CountElements);
}
void DeserializeSB(const unsigned char*& bytes)
{
Core::DeserializeSB(bytes, m_Data);
Core::DeserializeSB(bytes, m_State);
Core::DeserializeSB(bytes, m_UnusedIndices);
Core::DeserializeSB(bytes, m_CountElements);
}
};
template <typename T>
using SimpleTypeUnorderedVectorU = SimpleTypeUnorderedVector<T, unsigned>;
template <typename T, typename SizeType = size_t>
class SimpleTypeSet
{
SimpleTypeUnorderedVector<T, SizeType> m_Data;
std::map<T, SizeType> m_IndexMap;
public:
SimpleTypeSet()
{
}
inline SizeType GetSize() const
{
return m_Data.GetSize();
}
inline bool IsEmpty() const
{
return m_Data.IsEmpty();
}
inline unsigned Add(const T& value)
{
SizeType index = m_Data.Add(value);
m_IndexMap[value] = index;
return index;
}
inline void Remove(const T& value)
{
auto it = m_IndexMap.find(value);
assert(it != m_IndexMap.end());
m_Data.Remove(it->second);
m_IndexMap.erase(it);
}
inline void Clear()
{
m_Data.Clear();
m_IndexMap.clear();
}
inline bool IsContaining(const T& value, unsigned& index)
{
auto it = m_IndexMap.find(value);
if (it == m_IndexMap.end())
{
return false;
}
index = it->second;
return true;
}
inline const T& operator[](SizeType index) const
{
return m_Data[index];
}
inline T& operator[](SizeType index)
{
return m_Data[index];
}
inline typename SimpleTypeUnorderedVector<T>::Iterator GetBeginIterator()
{
return m_Data.GetBeginIterator();
}
inline typename SimpleTypeUnorderedVector<T>::Iterator GetEndIterator()
{
return m_Data.GetEndIterator();
}
};
template <typename T>
using SimpleTypeSetU = SimpleTypeSet<T, unsigned>;
template <typename KeyType, typename DataType, typename SizeType = size_t>
class SimpleTypeMap
{
SimpleTypeUnorderedVector<DataType, SizeType> m_Data;
std::map<KeyType, SizeType> m_IndexMap;
public:
SimpleTypeMap()
{
}
inline SizeType GetSize() const
{
return m_Data.GetSize();
}
inline bool IsEmpty() const
{
return m_Data.IsEmpty();
}
inline void Add(const KeyType& key, const DataType& data)
{
SizeType index = m_Data.Add(data);
m_IndexMap[key] = index;
}
inline void Remove(const KeyType& key)
{
auto it = m_IndexMap.find(key);
assert(it != m_IndexMap.end());
m_Data.Remove(it->second);
m_IndexMap.erase(it);
}
inline void Clear()
{
m_Data.Clear();
m_IndexMap.clear();
}
inline bool IsContaining(const KeyType& key)
{
return (m_IndexMap.find(key) != m_IndexMap.end());
}
inline typename SimpleTypeUnorderedVector<DataType>::Iterator GetDataBeginIterator()
{
return m_Data.GetBeginIterator();
}
inline typename SimpleTypeUnorderedVector<DataType>::Iterator GetDataEndIterator()
{
return m_Data.GetEndIterator();
}
inline DataType& Get(const KeyType& key)
{
return m_Data[m_IndexMap.find(key)->second];
}
inline const DataType& Get(const KeyType& key) const
{
return m_Data[m_IndexMap.find(key)->second];
}
inline DataType& operator[](const KeyType& key)
{
return Get(key);
}
inline const DataType& operator[](const KeyType& key) const
{
return Get(key);
}
};
}
| true |
845205d1d039e193436cb7f6f173d6d9dab4b93f | C++ | noname2048/code-test | /a.cpp | UTF-8 | 2,298 | 2.515625 | 3 | [] | no_license | #include <cassert>
#include <iostream>
#include <string>
#include <vector>
#define N 8
using namespace std;
bool used[N];
int position[N];
int record_for_activate = 0;
int record_prun_effectiveness = 0;
class ClassFactorial {
public:
ClassFactorial();
static vector<long> cache;
static int last_called_i;
static int limits_of_i;
static long f(int i) {
assert(last_called_i > 0);
assert(0 < i);
assert(i < limits_of_i);
long& ret = cache[i];
if (ret > 0)
return ret;
else {
while (last_called_i == i) {
last_called_i++;
if (last_called_i > 1) {
cache[last_called_i] =
cache[last_called_i - 1] * last_called_i;
assert(cache[last_called_i] > 0);
} else if (last_called_i == 0)
cache[last_called_i] = 0;
else if (last_called_i == 1)
cache[last_called_i] = 1;
}
return ret;
}
}
};
vector<long> ClassFactorial::cache = vector<long>(20, -1);
int ClassFactorial::last_called_i = -1;
int abs(int number) {
if (number < 0)
return -number;
else
return number;
}
int a_k(int number) {
assert(number <= N);
static vector<int> cache;
if (cache.size() < 0) {
cache = vector<int>(N, -1);
cache[0] = 1;
}
if (cache[number] < 0) {
cache[number] = cache[number] * (N - number + 1);
}
return ClassFactorial::f(N) / ClassFactorial::f(N - number);
}
void solve(int& n, vector<string>& condition) { ClassFactorial::f(0); };
void recur(int depth) {
if (depth >= N)
return;
else {
for (int i = 0; i < N; i++) {
if (used[i] == false) {
used[i] = true;
position[depth] = i;
recur(depth + 1);
used[i] = false;
position[depth] = -1;
}
record_for_activate += 1;
}
}
}
int main() {
fill_n(used, N, false);
fill_n(position, N, -1);
fill_n(&Factorial::cache[2], 18, -1);
printf("%d", A.a);
Factorial::cache[0] = 0;
vector<string> a;
solve(N, a);
return 0;
} | true |
8647b7506a03a7b0d89ba459d1beb0b7ef94e86c | C++ | stdstring/leetcode | /Algorithms/Tasks.1001.1500/1492.KthFactorOfN/solution.cpp | UTF-8 | 1,124 | 3.609375 | 4 | [
"MIT"
] | permissive | #include <vector>
#include "gtest/gtest.h"
namespace
{
class Solution
{
public:
[[nodiscard]] int kthFactor(int n, int k) const
{
std::vector<int> smallFactors;
std::vector<int> bigFactors;
int number = 1;
while (number * number <= n)
{
if (n % number == 0)
{
smallFactors.push_back(number);
int bigFactor = n / number;
if (bigFactor != number)
bigFactors.push_back(bigFactor);
}
++number;
}
const size_t factorNumber = k;
if ((smallFactors.size() + bigFactors.size()) < factorNumber)
return -1;
if (factorNumber <= smallFactors.size())
return smallFactors[factorNumber - 1];
return bigFactors[bigFactors.size() - (k - smallFactors.size())];
}
};
}
namespace KthFactorOfNTask
{
TEST(KthFactorOfNTaskTests, Examples)
{
const Solution solution;
ASSERT_EQ(3, solution.kthFactor(12, 3));
ASSERT_EQ(7, solution.kthFactor(7, 2));
ASSERT_EQ(-1, solution.kthFactor(4, 4));
}
} | true |
69270a400e44df2e7e94d3affb0dd6ba86a471f0 | C++ | harsh-malik-0803/Data-Structure-and-Algorithm | /recursion/checksorted.cpp | UTF-8 | 332 | 2.921875 | 3 | [] | no_license | #include<stdio.h>
bool is_sorted(int a[],int n){
if(n==0 || n==1){
return true ;
}
if (a[0]>a[1]){
return false;
}
bool issmaller_sorted=is_sorted(a+1,n-1);
return issmaller_sorted;
}
int main(){
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
int t=is_sorted(a,n);
printf("%d",t);
return 0;
} | true |
93d01ff877175088369940f41a65669bb360ea75 | C++ | leonardoqt/gcmc_data_analyser | /class.h | UTF-8 | 2,373 | 2.5625 | 3 | [] | no_license | #include <cstring>
#include <fstream>
#ifndef MY_CLASS
#define MY_CLASS
class vec;
class atom;
class cell;
class vec
{
private:
double x[3];
friend atom;
friend cell;
public:
void import(double *);
void clean(); // reset value to zero
vec operator+(const vec&);
vec operator-(const vec&);
vec operator*(const double&);
vec & operator=(const vec&);
vec & operator=(double*); // can replace import
double norm();
//debug
void print();
};
class atom
{
private:
std::string symbol;
int sym;
vec pos;
friend cell;
public:
atom & operator=(const atom&);
};
class cell
{
private:
// atom related
int num_atom;
int num_element;
atom * a_l; // atom list
std::string * e_l; // element list
int * num_neighbor;
int max_num_neighbor = 50;
atom ** neighbor_l; // neighbor list
double ** neighbor_dis;
// cell related
vec lattice[3];
double tot_energy;
// identifier
double **mean_bond_length; //between different element, can add height constrain
double **mean_coord_num_surf;
double *composition_surf;
double **mean_bond_vec_norm;
double **mean_bond_vec_z;
double gii; // global instability index, note that this is not transferrable when changeing the system
double bv;
double bvv;
// sdd of identifer
double **mean_bond_length_sdd;
double **mean_coord_num_surf_sdd;
double **mean_bond_vec_norm_sdd;
double **mean_bond_vec_z_sdd;
public:
// end of work
void clean();
//
void read_file(std::ifstream&);
void build_e_l(std::string*, int);
void find_neighbor(double); //distance between each two elements, could be matrix if necessary
void find_neighbor(double**); //distance between each two elements, could be matrix if necessary
// calculate identifier
void get_mean_bond_length();
void get_mean_coord_num_surf(double h_surf);
void get_composition_surf(double h_surf);
void get_mean_bond_vec_norm(double h_surf); // bond vec z included
void get_gii(double h_surf, std::string el1, std::string el2, double r0, double cc, double n_ox1, double n_ox2);
void get_bv(double h_surf, std::string el1, std::string el2, double r0, double cc);
void get_bvv(double h_surf, std::string el1, std::string el2, double r0, double cc);
// image
void generate_image(int nx, int ny, std::ofstream&, double *charge, double h_surf);
// print function
void print_all(std::ofstream&);
void print_all_sdd(std::ofstream&);
};
#endif
| true |
269678590cc9c86f6ca84af90f190169e1bbab0a | C++ | mchavaillaz/cplusplus | /qt_project/PaintMaze/camera.h | UTF-8 | 438 | 2.53125 | 3 | [] | no_license | #ifndef CAMERA_H
#define CAMERA_H
#include "angle3d.h"
class QVector3D;
class Camera
{
public:
Camera(QVector3D *p, Angle3D *a);
~Camera();
void view();
void setYaw(double yaw);
void setPitch(double pitch);
void setRoll(double roll);
void setP(QVector3D *point) { this->p = point; }
QVector3D* getPoint();
Angle3D* getAngle();
private:
Angle3D *a;
QVector3D *p;
};
#endif // CAMERA_H
| true |
4cbb7cb488ec3db9c915b1779f74e58b25e675a3 | C++ | chenyue0102/mytestchenyue | /testopengl/src/testspine/My/MyFrameBuffer.h | UTF-8 | 2,240 | 2.515625 | 3 | [] | no_license | #pragma once
#include <GL/glew.h>
#include "OpenGLESHelper.h"
#include <string>
#include <Windows.h>
static bool SaveBitmap(const char* pFileName, int width, int height, int biBitCount, const void* pBuf, int nBufLen)
{
if (nullptr == pFileName
|| 0 == width
|| 0 == height
|| !(biBitCount == 24 || biBitCount == 32 || biBitCount == 16)
|| nullptr == pBuf
|| nBufLen < ((width * height * biBitCount) / 8)
)
{
return false;
}
else
{
BITMAPFILEHEADER bfh = { 0 };
bfh.bfType = 'MB';
bfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + nBufLen;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
FILE* fp = fopen(pFileName, "wb");
fwrite(&bfh, 1, sizeof(bfh), fp);
BITMAPINFOHEADER bih = { 0 };
bih.biSize = sizeof(bih);
bih.biWidth = width;
bih.biHeight = height;
bih.biPlanes = 1;
bih.biBitCount = biBitCount;
bih.biCompression = BI_RGB;
fwrite(&bih, 1, sizeof(bih), fp);
fwrite(pBuf, 1, nBufLen, fp);
fclose(fp);
return true;
}
}
class MyFrameBuffer {
public:
MyFrameBuffer() {
glGenTextures(1, &mTexture); CHECKERR();
glBindTexture(GL_TEXTURE_2D, mTexture); CHECKERR();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 400, 400, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); CHECKERR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); CHECKERR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); CHECKERR();
glGenRenderbuffers(1, &mRenderBuffer); CHECKERR();
glBindRenderbuffer(GL_RENDERBUFFER, mRenderBuffer); CHECKERR();
glGenFramebuffers(1, &mFrameBuffer); CHECKERR();
}
~MyFrameBuffer() {
}
public:
void bind() {
glBindFramebuffer(GL_FRAMEBUFFER, mFrameBuffer); CHECKERR();
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTexture, 0); CHECKERR();
GLenum buffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, buffers); CHECKERR();
}
void save() {
glBindTexture(GL_TEXTURE_2D, mTexture); CHECKERR();
std::string tmpBuf;
tmpBuf.resize(400 * 400 * 3);
glGetTexImage(GL_TEXTURE_2D, 0, GL_BGR, GL_UNSIGNED_BYTE, &tmpBuf[0]); CHECKERR();
SaveBitmap("d:/1.bmp", 400, 400, 24, &tmpBuf[0], tmpBuf.size());
}
private:
GLuint mTexture;
GLuint mRenderBuffer;
GLuint mFrameBuffer;
};
| true |
297db50ddd428609c2a4b80d2d7adf62da128cf4 | C++ | gabsi26/GameBoyEmu | /gemu_tests/8_bit_alu_tests.cpp | UTF-8 | 72,745 | 2.546875 | 3 | [] | no_license | #include "pch.h"
#include "../GameBoyEmu/GZ80.h"
#include "../GameBoyEmu/memory.h"
using namespace GZ80;
class _8BitALUTests : public testing::Test
{
public:
GZ80::CPU cpu;
virtual void SetUp()
{
}
virtual void TearDown()
{
}
};
// ################## ADD #####################
TEST_F(_8BitALUTests, ADDAACanAddRegisterAToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x02);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAACanAddRegisterAToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AA);
cpu.regs->A = 0x08;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAACanAddRegisterAToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AA);
cpu.regs->A = 0xFF;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFE);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAACanAddRegisterAToRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AA);
cpu.regs->A = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDABCanAddRegisterBToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x02);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDABCanAddRegisterBToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AB);
cpu.regs->A = 0x08;
cpu.regs->B = 0x08;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDABCanAddRegisterBToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AB);
cpu.regs->A = 0xFF;
cpu.regs->B = 0xFF;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFE);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDABCanAddRegisterBToRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AB);
cpu.regs->A = 0x00;
cpu.regs->B = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAHLCanAddAddress_HL_ToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x02);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAHLCanAddAddress_HL_ToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AHL);
cpu.regs->A = 0x08;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x08);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAHLCanAddAddress_HL_ToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AHL);
cpu.regs->A = 0xFF;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0xFF);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFE);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAHLCanAddAddress_HL_ToRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AHL);
cpu.regs->A = 0x00;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x00);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAIMCanAddImmediateValueToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x02);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAIMCanAddImmediateValueToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AIM);
cpu.regs->A = 0x08;
cpu.mem->write_to_address(0x101, 0x08);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAIMCanAddImmediatValueToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AIM);
cpu.regs->A = 0xFF;
cpu.mem->write_to_address(0x101, 0xFF);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFE);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADDAIMCanAddImmediateValueToRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADD_AIM);
cpu.regs->A = 0x00;
cpu.mem->write_to_address(0x101, 0x00);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ##################### ADC #######################
TEST_F(_8BitALUTests, ADCAACanAddRegisterAToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x02);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAACanAddRegisterAPlusCarryToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x03);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAACanAddRegisterAToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AA);
cpu.regs->A = 0x08;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAACanAddRegisterAToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AA);
cpu.regs->A = 0xFF;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFE);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAACanAddRegisterAToRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AA);
cpu.regs->A = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAACanAddRegisterAPlusToRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AA);
cpu.regs->A = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCABCanAddRegisterBToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x02);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCABCanAddRegisterBPlusCarryToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x03);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCABCanAddRegisterBToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AB);
cpu.regs->A = 0x08;
cpu.regs->B = 0x08;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCABCanAddRegisterBPlusCarryToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AB);
cpu.regs->A = 0x08;
cpu.regs->B = 0x07;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCABCanAddRegisterBToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AB);
cpu.regs->A = 0xFF;
cpu.regs->B = 0xFF;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFE);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCABCanAddRegisterBPlusCarryToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AB);
cpu.regs->A = 0xFF;
cpu.regs->B = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCABCanAddRegisterBToRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AB);
cpu.regs->A = 0x00;
cpu.regs->B = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCABCanAddRegisterBPlusCarryToRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AB);
cpu.regs->A = 0x00;
cpu.regs->B = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAHLCanAddAddress_HL_ToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x02);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAHLCanAddAddress_HL_ToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AHL);
cpu.regs->A = 0x08;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x08);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAHLCanAddAddress_HL_ToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AHL);
cpu.regs->A = 0xFF;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0xFF);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFE);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAHLCanAddAddress_HL_ToRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AHL);
cpu.regs->A = 0x00;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x00);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAIMCanAddImmediateValueToRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x02);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAIMCanAddImmediateValueToRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AIM);
cpu.regs->A = 0x08;
cpu.mem->write_to_address(0x101, 0x08);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAIMCanAddImmediatValueToRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AIM);
cpu.regs->A = 0xFF;
cpu.mem->write_to_address(0x101, 0xFF);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFE);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ADCAIMCanAddImmediateValueToRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_ADC_AIM);
cpu.regs->A = 0x00;
cpu.mem->write_to_address(0x101, 0x00);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ############## SUB ##################
TEST_F(_8BitALUTests, SUBAACanSubtractRegisterAFromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBABCanSubtractRegisterBFromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBABCanSubtractRegisterBFromRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AB);
cpu.regs->A = 0x40;
cpu.regs->B = 0x04;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x3C);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBABCanSubtractRegisterBFromRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AB);
cpu.regs->A = 0x00;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBAHLCanSubtractAddress_HL_FromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x1);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBAHLCanSubtractAddress_HL_FromRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AHL);
cpu.regs->A = 0x40;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x04);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x3C);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBAHLCanSubtractAddress_HL_FromRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AHL);
cpu.regs->A = 0x00;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBAIMCanSubtractImmediateValueFromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x1);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBAIMCanSubtractImmediateValueFromRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AIM);
cpu.regs->A = 0x40;
cpu.mem->write_to_address(0x101, 0x04);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x3C);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SUBAIMCanSubtractImmediateValueFromRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SUB_AIM);
cpu.regs->A = 0x00;
cpu.mem->write_to_address(0x101, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ############## SBC ##################
TEST_F(_8BitALUTests, SBCAACanSubtractRegisterAFromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCAACanSubtractRegisterAPlusCarryFromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCABCanSubtractRegisterBFromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCABCanSubtractRegisterBPlusCarryFromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCABCanSubtractRegisterBFromRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AB);
cpu.regs->A = 0x40;
cpu.regs->B = 0x04;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x3C);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCABCanSubtractRegisterBPlusCarryFromRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AB);
cpu.regs->A = 0x44;
cpu.regs->B = 0x04;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x3F);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCABCanSubtractRegisterBFromRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AB);
cpu.regs->A = 0x00;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCAHLCanSubtractAddress_HL_FromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x1);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCAHLCanSubtractAddress_HL_FromRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AHL);
cpu.regs->A = 0x40;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x04);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x3C);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCAHLCanSubtractAddress_HL_FromRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AHL);
cpu.regs->A = 0x00;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCAIMCanSubtractImmediateValueFromRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x1);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCAIMCanSubtractImmediateValueFromRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AIM);
cpu.regs->A = 0x40;
cpu.mem->write_to_address(0x101, 0x04);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x3C);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, SBCAIMCanSubtractImmediateValueFromRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_SBC_AIM);
cpu.regs->A = 0x00;
cpu.mem->write_to_address(0x101, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ################ AND #################
TEST_F(_8BitALUTests, ANDAACanAndRegisterAWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_AND_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ANDAACanAndRegisterAWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_AND_AA);
cpu.regs->A = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ANDABCanAndRegisterBWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_AND_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ANDABCanAndRegisterBWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_AND_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x10;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ANDAHLCanAndRegisterHLWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_AND_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ANDAHLCanAndRegisterHLWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_AND_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x200;
cpu.mem->write_to_address(0x200, 0x10);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ANDAIMCanAndImmediateValueWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_AND_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ANDAIMCanAndImmediateValueWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_AND_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x10);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ################ OR #####################
TEST_F(_8BitALUTests, ORAACanOrRegisterAWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_OR_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ORAACanOrRegisterAWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_OR_AA);
cpu.regs->A = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ORABCanOrRegisterBWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_OR_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x10;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x11);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ORAHLCanOrRegisterHLWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_OR_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x10);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x11);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, ORAIMCanOrImmediateValueWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_OR_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x10);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x11);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ################ XOR #####################
TEST_F(_8BitALUTests, XORAACanXOrRegisterAWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_XOR_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, XORABCanXOrRegisterBWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_XOR_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x10;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x11);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, XORABCanXOrRegisterBWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_XOR_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, XORAHLCanXOrRegisterHLWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_XOR_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x10);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x11);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, XORAHLCanXOrRegisterHLWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_XOR_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, XORAIMCanXOrImmediateValueWithRegisterANonZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_XOR_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x10);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x11);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, XORAIMCanXOrImmediateValueWithRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_XOR_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 1;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ############### CP ##################
TEST_F(_8BitALUTests, CPAACanCompareRegisterAWithRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AA);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPABCanCompareRegisterBWithRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AB);
cpu.regs->A = 0x01;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPABCanCompareRegisterBWithRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AB);
cpu.regs->A = 0x40;
cpu.regs->B = 0x04;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x40);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPABCanCompareRegisterBWithRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AB);
cpu.regs->A = 0x00;
cpu.regs->B = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPAHLCanCompareAddress_HL_WithRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AHL);
cpu.regs->A = 0x01;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x1);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPAHLCanCompareAddress_HL_WithRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AHL);
cpu.regs->A = 0x40;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x04);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x40);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPAHLCanCompareAddress_HL_WithRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AHL);
cpu.regs->A = 0x00;
cpu.regs->HL = 0x0200;
cpu.mem->write_to_address(0x200, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPAIMCanCompareImmediateValueWithRegisterAWithCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AIM);
cpu.regs->A = 0x01;
cpu.mem->write_to_address(0x101, 0x1);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPAIMCanCompareImmediateValueWithRegisterAWithHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AIM);
cpu.regs->A = 0x40;
cpu.mem->write_to_address(0x101, 0x04);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x40);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_TRUE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, CPAIMCanCompareImmediateValueWithRegisterAWithoutCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_CP_AIM);
cpu.regs->A = 0x00;
cpu.mem->write_to_address(0x101, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 2;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x102 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ##################### INC ################
TEST_F(_8BitALUTests, INCRegisterCanIncreaseRegisterA)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_INC_A);
cpu.regs->A = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, INCRegisterCanIncreaseRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_INC_A);
cpu.regs->A = 0xFF;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, INCRegisterCanIncreaseRegisterAHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_INC_A);
cpu.regs->A = 0x0F;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, INCRegisterCanIncreaseAddress_HL_)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_INC_HL_);
cpu.regs->HL = 0x200;
cpu.mem->write_to_address(0x200, 0x00);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 3;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.mem->read_from_address(0x200), 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, INCRegisterCanIncreaseAddress_HL_Zero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_INC_HL_);
cpu.regs->HL = 0x200;
cpu.mem->write_to_address(0x200, 0xFF);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 3;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.mem->read_from_address(0x200), 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, INCRegisterCanIncreaseAddress_HL_HalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_INC_HL_);
cpu.regs->HL = 0x200;
cpu.mem->write_to_address(0x200, 0x0F);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 3;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.mem->read_from_address(0x200), 0x10);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_FALSE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
// ##################### DEC ################
TEST_F(_8BitALUTests, DECRegisterCanDecreaseRegisterAHalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_DEC_A);
cpu.regs->A = 0x02;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, DECRegisterCanDecreaseRegisterAZero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_DEC_A);
cpu.regs->A = 0x01;
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, DECRegisterCanDecreaseRegisterA)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_DEC_A);
cpu.regs->A = 0x00;
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 1;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.regs->A, 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, DECRegisterCanDecreaseAddress_HL_HalfCarry)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_DEC_HL_);
cpu.regs->HL = 0x200;
cpu.mem->write_to_address(0x200, 0x02);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 3;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.mem->read_from_address(0x200), 0x01);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, DECRegisterCanDecreaseAddress_HL_Zero)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_DEC_HL_);
cpu.regs->HL = 0x200;
cpu.mem->write_to_address(0x200, 0x01);
cpu.regs->pc = 0x100;
cpu.regs->zero = 0;
cpu.regs->negative = 1;
cpu.regs->carry = 0;
cpu.regs->half_carry = 0;
Byte expected_machine_cycles = 3;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.mem->read_from_address(0x200), 0x00);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_TRUE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_TRUE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
}
TEST_F(_8BitALUTests, DECRegisterCanDecreaseAddress_HL_)
{
// given
cpu.mem->write_to_address(0x100, CPU::INS_DEC_HL_);
cpu.regs->HL = 0x200;
cpu.mem->write_to_address(0x200, 0x00);
cpu.regs->pc = 0x100;
cpu.regs->zero = 1;
cpu.regs->negative = 0;
cpu.regs->carry = 0;
cpu.regs->half_carry = 1;
Byte expected_machine_cycles = 3;
// when
Byte opcode = cpu.fetch_byte(false);
cpu.execute(opcode, expected_machine_cycles);
// then
EXPECT_EQ(cpu.mem->read_from_address(0x200), 0xFF);
EXPECT_EQ(cpu.regs->pc, 0x101 + 1);
EXPECT_FALSE(cpu.regs->carry);
EXPECT_FALSE(cpu.regs->half_carry);
EXPECT_TRUE(cpu.regs->negative);
EXPECT_FALSE(cpu.regs->zero);
EXPECT_EQ(cpu.cycles->mc, expected_machine_cycles);
} | true |
33b0a316e69565d4d84b998eba32bbaa57acbd59 | C++ | MakGulati/elementalCplusplus | /templateEg.cpp | UTF-8 | 723 | 3.890625 | 4 | [] | no_license | #include<iostream>
using namespace std;
template <typename T> //tell the compiler we are using a template
T findSmaller(T input1,T input2);
int main()
{
int a = 54;
int b = 89;
float f1 = 7.8;
float f2 = 9.1;
char c1 = 'f';
char c2 = 'h';
string s1 = "Hello";
string s2 = "Bots are fun";
cout<<"\n Smaller integer : "<<findSmaller(a,b)<<"\n";
cout<<"\n Smaller float : "<<findSmaller(f1,f2)<<"\n";
cout<<"\n Smaller char : "<<findSmaller(c1,c2)<<"\n";
cout<<"\n Smaller string : "<<findSmaller(s1,s2)<<"\n";
return 0;
}
template <typename T>
T findSmaller(T input1,T input2)
{
if(input1 < input2)
return input1;
else
return input2;
}
| true |
af19f3e9b597c35e2c8f08f9744c33d05ae3b59d | C++ | mayfool/PersonnelArchives | /archivestablemodel.h | UTF-8 | 2,844 | 2.90625 | 3 | [] | no_license | /*功能说明
文件名称:archivestablemodel.h
作 者:马进
联系方式:
创建时间:2017.11.19
目 的:显示目录信息的视图的模型
功能描述:建立一个自定义结构的链表,填充从数据库中读取的目录信息,填充十大分类、空行等
约束条件:
*/
#ifndef ARCHIVESTABLEMODEL_H
#define ARCHIVESTABLEMODEL_H
#include <QAbstractTableModel>
#include <mainwindow.h>
class ArchivesTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit ArchivesTableModel(QObject *parent = 0);
//explicit ArchivesTableModel(QObject *parent,QString pid);
~ArchivesTableModel();
// Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Editable:
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
// Add data:
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
// Remove data:
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
private:
AccessDB *m_accdb;
//QSqlQueryModel* m_queryModel;
QSqlQuery *m_query;
QString m_pid;
int m_spaceRow;
//int m_list[4];
//QSqlTableModel* m_tableModel;
//自定义的数据结构,表中一行对应一个数据结构
struct tableModelStruct
{
int style1;//一级分类
int style2;//二级分类
int style3;//三级分类
int fArchives;//数据库中该条目录的序号
int type;//该行数据的分类,共4种。0:空行; 1:一级分类(十大分类);2:二级分类;3:目录信息;
QString fpaid;//数据库中人员编号
QString archive;//目录名称
QString remark;//备注
int year;
int month;
int day;
int page;//页数
};//结构体,从数据库中读取数据,提供给模型使用
QList <tableModelStruct*> m_archivesList;
void setTableModelStructZero(ArchivesTableModel::tableModelStruct *stru);//清空数据结构
};
#endif // ARCHIVESTABLEMODEL_H
| true |
a6fb43d851c606bcc5d63f73595f6c0c711b5769 | C++ | danielaparker/jsoncons | /include/jsoncons/detail/parse_number.hpp | UTF-8 | 36,253 | 2.609375 | 3 | [
"BSL-1.0",
"MIT",
"Apache-2.0"
] | permissive | // Copyright 2013-2023 Daniel Parker
// Distributed under the Boost license, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See https://github.com/danielaparker/jsoncons for latest version
#ifndef JSONCONS_DETAIL_PARSE_NUMBER_HPP
#define JSONCONS_DETAIL_PARSE_NUMBER_HPP
#include <system_error>
#include <stdexcept>
#include <string>
#include <vector>
#include <locale>
#include <string>
#include <limits> // std::numeric_limits
#include <type_traits> // std::enable_if
#include <exception>
#include <jsoncons/config/jsoncons_config.hpp>
#include <jsoncons/json_exception.hpp>
#include <cctype>
namespace jsoncons { namespace detail {
enum class to_integer_errc : uint8_t {success=0, overflow, invalid_digit, invalid_number};
class to_integer_error_category_impl
: public std::error_category
{
public:
const char* name() const noexcept override
{
return "jsoncons/to_integer_unchecked";
}
std::string message(int ev) const override
{
switch (static_cast<to_integer_errc>(ev))
{
case to_integer_errc::overflow:
return "Integer overflow";
case to_integer_errc::invalid_digit:
return "Invalid digit";
case to_integer_errc::invalid_number:
return "Invalid number";
default:
return "Unknown to_integer_unchecked error";
}
}
};
inline
const std::error_category& to_integer_error_category()
{
static to_integer_error_category_impl instance;
return instance;
}
inline
std::error_code make_error_code(to_integer_errc e)
{
return std::error_code(static_cast<int>(e),to_integer_error_category());
}
} // namespace detail
} // namespace jsoncons
namespace std {
template<>
struct is_error_code_enum<jsoncons::detail::to_integer_errc> : public true_type
{
};
}
namespace jsoncons { namespace detail {
template <class T,class CharT>
struct to_integer_result
{
const CharT* ptr;
to_integer_errc ec;
constexpr to_integer_result(const CharT* ptr_)
: ptr(ptr_), ec(to_integer_errc())
{
}
constexpr to_integer_result(const CharT* ptr_, to_integer_errc ec_)
: ptr(ptr_), ec(ec_)
{
}
to_integer_result(const to_integer_result&) = default;
to_integer_result& operator=(const to_integer_result&) = default;
constexpr explicit operator bool() const noexcept
{
return ec == to_integer_errc();
}
std::error_code error_code() const
{
return make_error_code(ec);
}
};
enum class integer_chars_format : uint8_t {decimal=1,hex};
enum class integer_chars_state {initial,minus,integer,binary,octal,decimal,base16};
template <class CharT>
bool is_base10(const CharT* s, std::size_t length)
{
integer_chars_state state = integer_chars_state::initial;
const CharT* end = s + length;
for (;s < end; ++s)
{
switch(state)
{
case integer_chars_state::initial:
{
switch(*s)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
state = integer_chars_state::decimal;
break;
case '-':
state = integer_chars_state::minus;
break;
default:
return false;
}
break;
}
case integer_chars_state::minus:
{
switch(*s)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
state = integer_chars_state::decimal;
break;
default:
return false;
}
break;
}
case integer_chars_state::decimal:
{
switch(*s)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
break;
default:
return false;
}
break;
}
default:
break;
}
}
return state == integer_chars_state::decimal ? true : false;
}
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && !extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
to_integer_decimal(const CharT* s, std::size_t length, T& n)
{
n = 0;
integer_chars_state state = integer_chars_state::initial;
const CharT* end = s + length;
while (s < end)
{
switch(state)
{
case integer_chars_state::initial:
{
switch(*s)
{
case '0':
if (++s == end)
{
return (++s == end) ? to_integer_result<T,CharT>(s) : to_integer_result<T, CharT>(s, to_integer_errc());
}
else
{
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': // Must be decimal
state = integer_chars_state::decimal;
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
break;
}
case integer_chars_state::decimal:
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_10 = max_value / 10;
for (; s < end; ++s)
{
T x = 0;
switch(*s)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
x = static_cast<T>(*s) - static_cast<T>('0');
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n > max_value_div_10)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 10;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
break;
}
default:
JSONCONS_UNREACHABLE();
break;
}
}
return (state == integer_chars_state::initial) ? to_integer_result<T,CharT>(s, to_integer_errc::invalid_number) : to_integer_result<T,CharT>(s, to_integer_errc());
}
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
to_integer_decimal(const CharT* s, std::size_t length, T& n)
{
n = 0;
if (length == 0)
{
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_number);
}
bool is_negative = *s == '-' ? true : false;
if (is_negative)
{
++s;
--length;
}
using U = typename extension_traits::make_unsigned<T>::type;
U u;
auto ru = to_integer_decimal(s, length, u);
if (ru.ec != to_integer_errc())
{
return to_integer_result<T,CharT>(ru.ptr, ru.ec);
}
if (is_negative)
{
if (u > static_cast<U>(-((extension_traits::integer_limits<T>::lowest)()+T(1))) + U(1))
{
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc::overflow);
}
else
{
n = static_cast<T>(U(0) - u);
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc());
}
}
else
{
if (u > static_cast<U>((extension_traits::integer_limits<T>::max)()))
{
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc::overflow);
}
else
{
n = static_cast<T>(u);
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc());
}
}
}
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && !extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
to_integer_base16(const CharT* s, std::size_t length, T& n)
{
n = 0;
integer_chars_state state = integer_chars_state::initial;
const CharT* end = s + length;
while (s < end)
{
switch(state)
{
case integer_chars_state::initial:
{
switch(*s)
{
case '0':
if (++s == end)
{
return (++s == end) ? to_integer_result<T,CharT>(s) : to_integer_result<T, CharT>(s, to_integer_errc());
}
else
{
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': // Must be base16
case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
state = integer_chars_state::base16;
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
break;
}
case integer_chars_state::base16:
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_16 = max_value / 16;
for (; s < end; ++s)
{
CharT c = *s;
T x = 0;
switch(*s)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
x = static_cast<T>(c - '0');
break;
case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
x = static_cast<T>(c - ('a' - 10));
break;
case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
x = static_cast<T>(c - ('A' - 10));
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n > max_value_div_16)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 16;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
break;
}
default:
JSONCONS_UNREACHABLE();
break;
}
}
return (state == integer_chars_state::initial) ? to_integer_result<T,CharT>(s, to_integer_errc::invalid_number) : to_integer_result<T,CharT>(s, to_integer_errc());
}
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
to_integer_base16(const CharT* s, std::size_t length, T& n)
{
n = 0;
if (length == 0)
{
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_number);
}
bool is_negative = *s == '-' ? true : false;
if (is_negative)
{
++s;
--length;
}
using U = typename extension_traits::make_unsigned<T>::type;
U u;
auto ru = to_integer_base16(s, length, u);
if (ru.ec != to_integer_errc())
{
return to_integer_result<T,CharT>(ru.ptr, ru.ec);
}
if (is_negative)
{
if (u > static_cast<U>(-((extension_traits::integer_limits<T>::lowest)()+T(1))) + U(1))
{
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc::overflow);
}
else
{
n = static_cast<T>(U(0) - u);
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc());
}
}
else
{
if (u > static_cast<U>((extension_traits::integer_limits<T>::max)()))
{
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc::overflow);
}
else
{
n = static_cast<T>(u);
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc());
}
}
}
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && !extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
to_integer(const CharT* s, std::size_t length, T& n)
{
n = 0;
integer_chars_state state = integer_chars_state::initial;
const CharT* end = s + length;
while (s < end)
{
switch(state)
{
case integer_chars_state::initial:
{
switch(*s)
{
case '0':
state = integer_chars_state::integer; // Could be binary, octal, hex
++s;
break;
case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9': // Must be decimal
state = integer_chars_state::decimal;
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
break;
}
case integer_chars_state::integer:
{
switch(*s)
{
case 'b':case 'B':
{
state = integer_chars_state::binary;
++s;
break;
}
case 'x':case 'X':
{
state = integer_chars_state::base16;
++s;
break;
}
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
{
state = integer_chars_state::octal;
break;
}
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
break;
}
case integer_chars_state::binary:
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_2 = max_value / 2;
for (; s < end; ++s)
{
T x = 0;
switch(*s)
{
case '0':case '1':
x = static_cast<T>(*s) - static_cast<T>('0');
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n > max_value_div_2)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 2;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
break;
}
case integer_chars_state::octal:
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_8 = max_value / 8;
for (; s < end; ++s)
{
T x = 0;
switch(*s)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':
x = static_cast<T>(*s) - static_cast<T>('0');
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n > max_value_div_8)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 8;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
break;
}
case integer_chars_state::decimal:
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_10 = max_value / 10;
for (; s < end; ++s)
{
T x = 0;
switch(*s)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
x = static_cast<T>(*s) - static_cast<T>('0');
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n > max_value_div_10)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 10;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
break;
}
case integer_chars_state::base16:
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_16 = max_value / 16;
for (; s < end; ++s)
{
CharT c = *s;
T x = 0;
switch (c)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
x = c - '0';
break;
case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
x = c - ('a' - 10);
break;
case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
x = c - ('A' - 10);
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n > max_value_div_16)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 16;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
break;
}
default:
JSONCONS_UNREACHABLE();
break;
}
}
return (state == integer_chars_state::initial) ? to_integer_result<T,CharT>(s, to_integer_errc::invalid_number) : to_integer_result<T,CharT>(s, to_integer_errc());
}
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
to_integer(const CharT* s, std::size_t length, T& n)
{
n = 0;
if (length == 0)
{
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_number);
}
bool is_negative = *s == '-' ? true : false;
if (is_negative)
{
++s;
--length;
}
using U = typename extension_traits::make_unsigned<T>::type;
U u;
auto ru = to_integer(s, length, u);
if (ru.ec != to_integer_errc())
{
return to_integer_result<T,CharT>(ru.ptr, ru.ec);
}
if (is_negative)
{
if (u > static_cast<U>(-((extension_traits::integer_limits<T>::lowest)()+T(1))) + U(1))
{
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc::overflow);
}
else
{
n = static_cast<T>(U(0) - u);
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc());
}
}
else
{
if (u > static_cast<U>((extension_traits::integer_limits<T>::max)()))
{
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc::overflow);
}
else
{
n = static_cast<T>(u);
return to_integer_result<T,CharT>(ru.ptr, to_integer_errc());
}
}
}
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized,to_integer_result<T,CharT>>::type
to_integer(const CharT* s, T& n)
{
return to_integer<T,CharT>(s, std::char_traits<CharT>::length(s), n);
}
// Precondition: s satisfies
// digit
// digit1-digits
// - digit
// - digit1-digits
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && !extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
to_integer_unchecked(const CharT* s, std::size_t length, T& n)
{
static_assert(extension_traits::integer_limits<T>::is_specialized, "Integer type not specialized");
JSONCONS_ASSERT(length > 0);
n = 0;
const CharT* end = s + length;
if (*s == '-')
{
static constexpr T min_value = (extension_traits::integer_limits<T>::lowest)();
static constexpr T min_value_div_10 = min_value / 10;
++s;
for (; s < end; ++s)
{
T x = (T)*s - (T)('0');
if (n < min_value_div_10)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 10;
if (n < min_value + x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n -= x;
}
}
else
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_10 = max_value / 10;
for (; s < end; ++s)
{
T x = static_cast<T>(*s) - static_cast<T>('0');
if (n > max_value_div_10)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 10;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
}
return to_integer_result<T,CharT>(s, to_integer_errc());
}
// Precondition: s satisfies
// digit
// digit1-digits
// - digit
// - digit1-digits
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
to_integer_unchecked(const CharT* s, std::size_t length, T& n)
{
static_assert(extension_traits::integer_limits<T>::is_specialized, "Integer type not specialized");
JSONCONS_ASSERT(length > 0);
n = 0;
const CharT* end = s + length;
if (*s == '-')
{
static constexpr T min_value = (extension_traits::integer_limits<T>::lowest)();
static constexpr T min_value_div_10 = min_value / 10;
++s;
for (; s < end; ++s)
{
T x = (T)*s - (T)('0');
if (n < min_value_div_10)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 10;
if (n < min_value + x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n -= x;
}
}
else
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_10 = max_value / 10;
for (; s < end; ++s)
{
T x = static_cast<T>(*s) - static_cast<T>('0');
if (n > max_value_div_10)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 10;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
}
return to_integer_result<T,CharT>(s, to_integer_errc());
}
// base16_to_integer
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
base16_to_integer(const CharT* s, std::size_t length, T& n)
{
static_assert(extension_traits::integer_limits<T>::is_specialized, "Integer type not specialized");
JSONCONS_ASSERT(length > 0);
n = 0;
const CharT* end = s + length;
if (*s == '-')
{
static constexpr T min_value = (extension_traits::integer_limits<T>::lowest)();
static constexpr T min_value_div_16 = min_value / 16;
++s;
for (; s < end; ++s)
{
CharT c = *s;
T x = 0;
switch (c)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
x = c - '0';
break;
case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
x = c - ('a' - 10);
break;
case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
x = c - ('A' - 10);
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n < min_value_div_16)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 16;
if (n < min_value + x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n -= x;
}
}
else
{
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_16 = max_value / 16;
for (; s < end; ++s)
{
CharT c = *s;
T x = 0;
switch (c)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
x = c - '0';
break;
case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
x = c - ('a' - 10);
break;
case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
x = c - ('A' - 10);
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n > max_value_div_16)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 16;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
}
return to_integer_result<T,CharT>(s, to_integer_errc());
}
template <class T, class CharT>
typename std::enable_if<extension_traits::integer_limits<T>::is_specialized && !extension_traits::integer_limits<T>::is_signed,to_integer_result<T,CharT>>::type
base16_to_integer(const CharT* s, std::size_t length, T& n)
{
static_assert(extension_traits::integer_limits<T>::is_specialized, "Integer type not specialized");
JSONCONS_ASSERT(length > 0);
n = 0;
const CharT* end = s + length;
static constexpr T max_value = (extension_traits::integer_limits<T>::max)();
static constexpr T max_value_div_16 = max_value / 16;
for (; s < end; ++s)
{
CharT c = *s;
T x = *s;
switch (c)
{
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
x = c - '0';
break;
case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
x = c - ('a' - 10);
break;
case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
x = c - ('A' - 10);
break;
default:
return to_integer_result<T,CharT>(s, to_integer_errc::invalid_digit);
}
if (n > max_value_div_16)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n = n * 16;
if (n > max_value - x)
{
return to_integer_result<T,CharT>(s, to_integer_errc::overflow);
}
n += x;
}
return to_integer_result<T,CharT>(s, to_integer_errc());
}
#if defined(JSONCONS_HAS_STD_FROM_CHARS) && JSONCONS_HAS_STD_FROM_CHARS
class chars_to
{
public:
char get_decimal_point() const
{
return '.';
}
template <class CharT>
typename std::enable_if<std::is_same<CharT,char>::value,double>::type
operator()(const CharT* s, std::size_t len) const
{
double val = 0;
const auto res = std::from_chars(s, s+len, val);
if (res.ec != std::errc())
{
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Convert chars to double failed"));
}
return val;
}
template <class CharT>
typename std::enable_if<std::is_same<CharT,wchar_t>::value,double>::type
operator()(const CharT* s, std::size_t len) const
{
std::string input(len,'0');
for (size_t i = 0; i < len; ++i)
{
input[i] = static_cast<char>(s[i]);
}
double val = 0;
const auto res = std::from_chars(input.data(), input.data() + len, val);
if (res.ec != std::errc())
{
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Convert chars to double failed"));
}
return val;
}
};
#elif defined(JSONCONS_HAS_MSC_STRTOD_L)
class chars_to
{
private:
_locale_t locale_;
public:
chars_to()
{
locale_ = _create_locale(LC_NUMERIC, "C");
}
~chars_to() noexcept
{
_free_locale(locale_);
}
chars_to(const chars_to&)
{
locale_ = _create_locale(LC_NUMERIC, "C");
}
chars_to& operator=(const chars_to&)
{
// Don't assign locale
return *this;
}
char get_decimal_point() const
{
return '.';
}
template <class CharT>
typename std::enable_if<std::is_same<CharT,char>::value,double>::type
operator()(const CharT* s, std::size_t) const
{
CharT *end = nullptr;
double val = _strtod_l(s, &end, locale_);
if (s == end)
{
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Convert string to double failed"));
}
return val;
}
template <class CharT>
typename std::enable_if<std::is_same<CharT,wchar_t>::value,double>::type
operator()(const CharT* s, std::size_t) const
{
CharT *end = nullptr;
double val = _wcstod_l(s, &end, locale_);
if (s == end)
{
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Convert string to double failed"));
}
return val;
}
};
#elif defined(JSONCONS_HAS_STRTOLD_L)
class chars_to
{
private:
locale_t locale_;
public:
chars_to()
{
locale_ = newlocale(LC_ALL_MASK, "C", (locale_t) 0);
}
~chars_to() noexcept
{
freelocale(locale_);
}
chars_to(const chars_to&)
{
locale_ = newlocale(LC_ALL_MASK, "C", (locale_t) 0);
}
chars_to& operator=(const chars_to&)
{
return *this;
}
char get_decimal_point() const
{
return '.';
}
template <class CharT>
typename std::enable_if<std::is_same<CharT,char>::value,double>::type
operator()(const CharT* s, std::size_t) const
{
char *end = nullptr;
double val = strtold_l(s, &end, locale_);
if (s == end)
{
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Convert string to double failed"));
}
return val;
}
template <class CharT>
typename std::enable_if<std::is_same<CharT,wchar_t>::value,double>::type
operator()(const CharT* s, std::size_t) const
{
CharT *end = nullptr;
double val = wcstold_l(s, &end, locale_);
if (s == end)
{
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Convert string to double failed"));
}
return val;
}
};
#else
class chars_to
{
private:
std::vector<char> buffer_;
char decimal_point_;
public:
chars_to()
: buffer_()
{
struct lconv * lc = localeconv();
if (lc != nullptr && lc->decimal_point[0] != 0)
{
decimal_point_ = lc->decimal_point[0];
}
else
{
decimal_point_ = '.';
}
buffer_.reserve(100);
}
chars_to(const chars_to&) = default;
chars_to& operator=(const chars_to&) = default;
char get_decimal_point() const
{
return decimal_point_;
}
template <class CharT>
typename std::enable_if<std::is_same<CharT,char>::value,double>::type
operator()(const CharT* s, std::size_t /*length*/) const
{
CharT *end = nullptr;
double val = strtod(s, &end);
if (s == end)
{
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Convert string to double failed"));
}
return val;
}
template <class CharT>
typename std::enable_if<std::is_same<CharT,wchar_t>::value,double>::type
operator()(const CharT* s, std::size_t /*length*/) const
{
CharT *end = nullptr;
double val = wcstod(s, &end);
if (s == end)
{
JSONCONS_THROW(json_runtime_error<std::invalid_argument>("Convert string to double failed"));
}
return val;
}
};
#endif
}}
#endif
| true |
0b2b13bea689fcdc1ffe29a385692d95a3748f9e | C++ | FrankWork/LeetCode | /algorithm/two_pointer/167. Two Sum II - Input array is sorted.cc | UTF-8 | 749 | 3.484375 | 3 | [] | no_license | #include <iostream>
#include <vector>
using namespace std;
class Solution{
public:
vector<int> twoSum(vector<int>& a, int k){
/* 双指针
l 从左侧开始移动
r 从右侧开始移动
类似二分查找
*/
int n=a.size();
int l=0, r=n-1;
vector<int> res(2);
while(l<r){
int t=a[l]+a[r];
if(t==k){
res[0]=l+1;
res[1]=r+1;
break;
}else if(t<k)l++;
else r--;
}
return res;
}
};
main(){
Solution so;
vector<int> a{2, 7, 11, 15};
vector<int> res = so.twoSum(a, 9);
printf("%d %d\n", res[0], res[1]);
// cout << so.twoSum(a, 9) << endl;
} | true |
6661b7bbf927ade66e7b09f277e60ef0f0b0b2ec | C++ | ArshaShiri/Mandelbrot_Image | /Mandelbrot-Image/RGB.cpp | UTF-8 | 247 | 2.90625 | 3 | [] | no_license | #include "RGB.h"
RGB::RGB(double r, double g, double b) : red_(r), green_(g), blue_(b)
{}
RGB operator-(const RGB &first, const RGB &second)
{
return RGB(first.red_-second.red_, first.green_ - second.green_, first.blue_ - second.blue_);
}
| true |
ae35760fb9ed7bfee635ad715b8af7d9937a428b | C++ | homespring/Chip8-Emulator | /chip8.cpp | UTF-8 | 11,765 | 3 | 3 | [
"MIT"
] | permissive | #define _CRT_SECURE_NO_WARNINGS
#include "chip8.h"
#include "INIReader.h"
#include <iostream>
#include <fstream>
#include <iomanip> // cout hex value
#include <cstdlib> // srand
#include <ctime> // time
#include "elapsedtimer.h"
using namespace std;
Chip8::Chip8(std::string cfg_filepath)
{
INIReader cfg(cfg_filepath);
if (cfg.ParseError() == 0)
{
// tutaj mamy poprawnie wczytany plik konfiguracyjny
rom_path = cfg.Get("", "rom_path", rom_path);
pixel_size = static_cast<int>(cfg.GetInteger("", "pixel_size", pixel_size));
}
srand(static_cast<unsigned int>(time(nullptr)));
init_display();
init();
}
Chip8::~Chip8()
{
if (renderer)
SDL_DestroyRenderer(renderer);
if (win)
SDL_DestroyWindow(win);
SDL_Quit();
}
int Chip8::game_loop()
{
if (!video_ok)
{
cerr << "Couldn't initialize video! Quitting...\n";
getchar();
return -1;
}
if (!loaded)
{
cerr << "Game file not loaded! Quitting...\n";
getchar();
return -1;
}
cout << "\nStarting the game...\n\n";
WORD opcode = 0;
ElapsedTimer tim(1000 / 60);
while (alive)
{
opcode = fetch_opcode();
decode_opcode(opcode);
if (tim.elapsed())
{
draw();
decrement_timers();
read_keys();
tim.tic();
}
sdl_events();
SDL_Delay(2);
}
cout << "Game Over.\n";
return 0;
}
void Chip8::init()
{
// wyzerowanie pamieci przeznaczonej na gre
memset(game_memory, 0, ram_size);
// wyzerowanie rejestrow
memset(registers, 0, reg_size);
// wyzerowanie rejestru I
address_I = 0;
// ustawienie zmiennej program_counter na adres poczatku gry
program_counter = game_start_addr;
// czyscimy stos
while(!stack.empty())
stack.pop();
// czyscimy ekran
clear_display();
// resetujemy stan klawiatury
memset(key, 0, keys_number);
// zerujemy timery
delay_timer = 0;
sound_timer = 0;
// inicjalizujemy sprite'y cyfr w pamieci gry
init_digit_sprites();
// wczytujemy plik z gra
ifstream file(rom_path, ifstream::binary);
if (file)
{
cout << "Reading file " << rom_path << endl;
// wczytujemy rozmiar pliku
file.seekg(0, file.end);
const auto len = file.tellg();
file.seekg(0, file.beg);
cout << "File size is " << len << " bytes.\n";
if (len > (ram_size - game_start_addr))
{
cerr << "Game file is too big!\n";
loaded = false;
file.close();
return;
}
file.read((char*)&game_memory[game_start_addr], len);
if (file)
{
cout << "File loaded successfully.\n";
loaded = true;
}
else
{
cerr << "Error: loaded only " << file.gcount() << " bytes.\n";
loaded = false;
}
file.close();
}
else
{
cerr << "Can't read file " << rom_path << endl;
loaded = false;
}
}
void Chip8::init_digit_sprites()
{
int cur_addr = 0; // wypelniamy pamiec gry od samego poczatku
// "0"
digit_sprite_addr[0] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xF0;
// "1"
digit_sprite_addr[1] = cur_addr;
game_memory[cur_addr++] = 0x20;
game_memory[cur_addr++] = 0x60;
game_memory[cur_addr++] = 0x20;
game_memory[cur_addr++] = 0x20;
game_memory[cur_addr++] = 0x70;
// "2"
digit_sprite_addr[2] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x10;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0xF0;
// "3"
digit_sprite_addr[3] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x10;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x10;
game_memory[cur_addr++] = 0xF0;
// "4"
digit_sprite_addr[4] = cur_addr;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x10;
game_memory[cur_addr++] = 0x10;
// "5"
digit_sprite_addr[5] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x10;
game_memory[cur_addr++] = 0xF0;
// "6"
digit_sprite_addr[6] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xF0;
// "7"
digit_sprite_addr[7] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x10;
game_memory[cur_addr++] = 0x20;
game_memory[cur_addr++] = 0x40;
game_memory[cur_addr++] = 0x40;
// "8"
digit_sprite_addr[8] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xF0;
// "9"
digit_sprite_addr[9] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x10;
game_memory[cur_addr++] = 0xF0;
// "A"
digit_sprite_addr[0xA] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0x90;
// "B"
digit_sprite_addr[0xB] = cur_addr;
game_memory[cur_addr++] = 0xE0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xE0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xE0;
// "C"
digit_sprite_addr[0xC] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0xF0;
// "D"
digit_sprite_addr[0xD] = cur_addr;
game_memory[cur_addr++] = 0xE0;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0x90;
game_memory[cur_addr++] = 0xE0;
// "E"
digit_sprite_addr[0xE] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0xF0;
// "F"
digit_sprite_addr[0xF] = cur_addr;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0xF0;
game_memory[cur_addr++] = 0x80;
game_memory[cur_addr++] = 0x80;
}
void Chip8::init_display()
{
video_ok = false;
if (SDL_Init(SDL_INIT_VIDEO) != 0)
return;
win = SDL_CreateWindow(
"CHIP-8 Emulator",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
width * pixel_size,
height * pixel_size,
SDL_WINDOW_SHOWN);
if (!win)
{
cerr << "SDL_CreateWindow Error: " << SDL_GetError() << endl;
return;
}
renderer = SDL_CreateRenderer(
win,
-1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!renderer)
{
cerr << "SDL_CreateRenderer Error: " << SDL_GetError() << endl;
return;
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
video_ok = true;
}
void Chip8::clear_display()
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
screen[x][y] = 0;
}
}
}
void Chip8::draw()
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_Rect r;
r.w = pixel_size;
r.h = pixel_size;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
if (screen[x][y])
{
r.x = x * pixel_size;
r.y = y * pixel_size;
SDL_RenderFillRect(renderer, &r);
}
}
}
SDL_RenderPresent(renderer);
}
WORD Chip8::fetch_opcode()
{
WORD ret = game_memory[program_counter++] << 8;
ret |= game_memory[program_counter++];
return ret;
}
void Chip8::decode_opcode(const WORD& opcode)
{
switch (opcode & 0xF000)
{
case 0x0000:
{
switch (opcode & 0x00FF)
{
case 0x00E0: opcode_00E0(); break;
case 0x00EE: opcode_00EE(); break;
default:
cout << "Warning: unexpected opcode 0x" << hex << uppercase << opcode << dec << endl;
break;
}
}
break;
case 0x1000: opcode_1nnn(opcode); break;
case 0x2000: opcode_2nnn(opcode); break;
case 0x3000: opcode_3xkk(opcode); break;
case 0x4000: opcode_4xkk(opcode); break;
case 0x5000: opcode_5xy0(opcode); break;
case 0x6000: opcode_6xkk(opcode); break;
case 0x7000: opcode_7xkk(opcode); break;
case 0x8000:
{
switch (opcode & 0x000F)
{
case 0x0000: opcode_8xy0(opcode); break;
case 0x0001: opcode_8xy1(opcode); break;
case 0x0002: opcode_8xy2(opcode); break;
case 0x0003: opcode_8xy3(opcode); break;
case 0x0004: opcode_8xy4(opcode); break;
case 0x0005: opcode_8xy5(opcode); break;
case 0x0006: opcode_8xy6(opcode); break;
case 0x0007: opcode_8xy7(opcode); break;
case 0x000E: opcode_8xyE(opcode); break;
default:
cout << "Warning: unexpected opcode 0x" << hex << uppercase << opcode << dec << endl;
break;
}
}
break;
case 0x9000: opcode_9xy0(opcode); break;
case 0xA000: opcode_Annn(opcode); break;
case 0xB000: opcode_Bnnn(opcode); break;
case 0xC000: opcode_Cxkk(opcode); break;
case 0xD000: opcode_Dxyn(opcode); break;
case 0xE000:
{
switch (opcode & 0x00FF)
{
case 0x009E: opcode_Ex9E(opcode); break;
case 0x00A1: opcode_ExA1(opcode); break;
default:
cout << "Warning: unexpected opcode 0x" << hex << uppercase << opcode << dec << endl;
break;
}
}
break;
case 0xF000:
{
switch (opcode & 0x00FF)
{
case 0x0007: opcode_Fx07(opcode); break;
case 0x000A: opcode_Fx0A(opcode); break;
case 0x0015: opcode_Fx15(opcode); break;
case 0x0018: opcode_Fx18(opcode); break;
case 0x001E: opcode_Fx1E(opcode); break;
case 0x0029: opcode_Fx29(opcode); break;
case 0x0033: opcode_Fx33(opcode); break;
case 0x0055: opcode_Fx55(opcode); break;
case 0x0065: opcode_Fx65(opcode); break;
default:
cout << "Warning: unexpected opcode 0x" << hex << uppercase << opcode << dec << endl;
break;
}
}
break;
default:
cout << "Warning: unknown opcode 0x" << hex << uppercase << opcode << dec << endl;
break; // nieobslugiwany opcode
}
}
BYTE Chip8::wait_key()
{
while (alive)
{
read_keys();
for (BYTE i = 0; i < keys_number; i++)
{
if (key[i])
return i;
}
sdl_events();
SDL_Delay(50);
}
return 0x0;
}
void Chip8::decrement_timers()
{
if (delay_timer > 0)
delay_timer--;
if (sound_timer > 0)
sound_timer--;
}
void Chip8::read_keys()
{
const Uint8* kb = SDL_GetKeyboardState(nullptr);
key[0] = kb[SDL_SCANCODE_KP_0] ? 1 : 0;
key[1] = kb[SDL_SCANCODE_KP_1] ? 1 : 0;
key[2] = kb[SDL_SCANCODE_KP_2] ? 1 : 0;
key[3] = kb[SDL_SCANCODE_KP_3] ? 1 : 0;
key[4] = kb[SDL_SCANCODE_KP_4] ? 1 : 0;
key[5] = kb[SDL_SCANCODE_KP_5] ? 1 : 0;
key[6] = kb[SDL_SCANCODE_KP_6] ? 1 : 0;
key[7] = kb[SDL_SCANCODE_KP_7] ? 1 : 0;
key[8] = kb[SDL_SCANCODE_KP_8] ? 1 : 0;
key[9] = kb[SDL_SCANCODE_KP_9] ? 1 : 0;
key[0xA] = kb[SDL_SCANCODE_A] ? 1 : 0;
key[0xB] = kb[SDL_SCANCODE_B] ? 1 : 0;
key[0xC] = kb[SDL_SCANCODE_C] ? 1 : 0;
key[0xD] = kb[SDL_SCANCODE_D] ? 1 : 0;
key[0xE] = kb[SDL_SCANCODE_E] ? 1 : 0;
key[0xF] = kb[SDL_SCANCODE_F] ? 1 : 0;
alive = kb[SDL_SCANCODE_ESCAPE] ? false : true;
}
void Chip8::sdl_events()
{
static SDL_Event evt;
while (SDL_PollEvent(&evt))
{
switch (evt.type)
{
case SDL_QUIT:
alive = false;
break;
default:
break;
}
}
}
| true |
7bd9dd6db680d120edadac7b228484eee16955b0 | C++ | rgoliveira/USACO-tp | /solutions/section-1.1/friday.cpp | MacCentralEurope | 1,926 | 2.921875 | 3 | [] | no_license | /*
ID: ricardo39
PROG: friday
LANG: C++
*/
#include <iostream>
#include <fstream>
#define SAT 0x00
#define SUN 0x01
#define MON 0x02
#define TUE 0x03
#define WED 0x04
#define THU 0x05
#define FRI 0x06
#define JAN 0x11
#define FEB 0x12
#define MAR 0x13
#define APR 0x14
#define MAY 0x15
#define JUN 0x16
#define JUL 0x17
#define AUG 0x18
#define SEP 0x19
#define OUT 0x1a
#define NOV 0x1b
#define DEZ 0x1c
using namespace std;
int main() {
ofstream fout ( "friday.out" );
ifstream fin ( "friday.in" );
int yearstocalc;
fin >> yearstocalc;
int endyear = yearstocalc + 1900;
int y = 1900;
int m = JAN;
int d = 1;
int dayoftheweek = MON;
int count13s [ 7 ] = { 0, 0, 0, 0, 0, 0, 0 };
bool isLeap = false;
while ( y < endyear ) {
//cout << "n: " << yearstocalc << " | y: " << y << " | m: " << (m&0x0F) << " | d: " << d << endl;
if ( d == 13 ) {
count13s[ ( dayoftheweek ) % 7 ]++;
}
dayoftheweek = ( dayoftheweek + 1 ) % 7;
d++;
if ( d > 31 ) {
if ( m == DEZ ) {
y++;
m = JAN;
isLeap = ( y % 4 == 0 && y % 100 != 0 ) || ( y % 100 == 0 && y % 400 == 0 );
} else {
m++;
}
d = 1;
} else if ( d > 30 ) { // virada de ms em dia 30
if ( ( m == SEP ) || ( m == APR ) || ( m == JUN ) || ( m == NOV ) ) {
m++;
d = 1;
}
} else if ( ( d > 28 ) && ( m == FEB ) ) { // fevereiro
if ( ( d > 28 ) && ( !isLeap ) || ( d > 29 ) && ( isLeap ) ) {
m++;
d = 1;
}
}
}
fout << count13s[0] << " " << count13s[1] << " " << count13s[2] << " " << count13s[3] << " " << count13s[4] << " " << count13s[5] << " " << count13s[6] << endl;
return 0;
}
| true |
3370684b75291cd5f85c3c3262f18b43906530e4 | C++ | errord/libdstruct | /src/dsioformat.cpp | UTF-8 | 16,649 | 2.609375 | 3 | [] | no_license | #include "dsbase.h"
#include "dsioformat.h"
#include "dstruct.h"
using namespace dstruct;
void
iDStructIOFormat::reset()
{
mDSStream = "";
mStreamPos = 0;
mLinenum = 1;
mPath.clear();
}
void
iDStructIOFormat::setDStructStream(const string& dstream)
{
mDSStream = dstream;
}
string&
iDStructIOFormat::getDStructStream()
{
return mDSStream;
}
bool
iDStructIOFormat::isMultibyte(char c)
{
if ((unsigned char)c > 127)
return true;
return false;
}
void
iDStructIOFormat::multibyte(string& mb)
{
mb = "";
mb += mDSStream[mStreamPos];
mStreamPos++;
mb += mDSStream[mStreamPos];
}
void
iDStructIOFormat::addlineNum()
{
mLinenum++;
}
string
iDStructIOFormat::outLineNum(int offset = 0)
{
char buff[1024];
sprintf(buff, "%d", mLinenum + offset);
string m = "第";
m += buff;
m += "行,";
return m;
}
void
iDStructIOFormat::makePath(string& path)
{
vector<string>::iterator vectIter;
path = "";
for(vectIter = mPath.begin();
vectIter != mPath.end();
vectIter++)
{
path += *vectIter;
}
}
void
cDSIOTextFormat::enterLevel()
{
}
void
cDSIOTextFormat::exitLevel()
{
if (mPath.size() > 0)
mPath.pop_back();
}
void
cDSIOTextFormat::outHashKey(const string& key)
{
string path;
if (mPath.size() == 0)
path = key;
else
path = "." + key;
mPath.push_back(path);
}
void
cDSIOTextFormat::outArrayIndex(int index)
{
char buff[1024];
sprintf(buff, "%d", index);
string path = "[";
path += buff;
path += "]";
mPath.push_back(path);
}
void
cDSIOTextFormat::outValue(const string& value)
{
string path;
if (value == "")
return;
makePath(path);
path += " = ";
path += "\"";
path += value;
path += "\";";
path += "\n";
mDSStream += path;
}
void
cDSIOTextFormat::reset()
{
iDStructIOFormat::reset();
}
int
cDSIOTextFormat::inPathValue(string& path, string& value)
{
enum linestate
{
estart,
epath,
eequal,
evalue,
ecomm,
esemicolonprefix,
esemicolonpostfix,
eexit
};
string mb;
bool ismb;
linestate state = estart;
if (mStreamPos >= mDSStream.length())
return 2;
char c;
path = "";
value = "";
while(state != eexit)
{
if (mStreamPos >= mDSStream.length())
{
if (state != estart && state != ecomm)
{
cerr << outLineNum() << "没有结束符(;)" << endl;
return 0;
}
return 2;
}
c = mDSStream[mStreamPos];
if (c == '\r' && mDSStream[mStreamPos+1] == '\n')
{
mStreamPos++;
continue;
}
ismb = isMultibyte(c);
if (ismb == true)
multibyte(mb);
else if (c == '\r' || c == '\n')
addlineNum();
switch ( state )
{
case estart:
if (ismb == true)
state = epath;
else if (c == '#')
state = ecomm;
else if (c == '\r' || c == '\n')
state = estart;
else if (c == ' ' || c == '\t')
state = estart;
else
state = epath;
break;
case ecomm:
if (ismb == false &&
c == '\n')
state = estart;
break;
case epath:
if (ismb == false &&
c == '=')
state = eequal;
break;
case eequal:
if (ismb == false &&
c == '\"')
{
state = esemicolonprefix;
}
else if ( ! (ismb == false &&
(c == ' ' || c == '\t')))
{
cerr << outLineNum() << "等号右边只能是字符串" << endl;
return 0;
}
break;
case evalue:
if (isMultibyte(c) == false &&
c == '\"')
state = esemicolonpostfix;
break;
case esemicolonprefix:
if (isMultibyte(c) == false &&
c == '\"')
state = esemicolonpostfix;
else
state = evalue;
break;
case esemicolonpostfix:
if (c == ';')
{
state = eexit;
}
else
{
cerr << outLineNum(-1) << "错误的结束符号" << endl;
return 0;
}
}
if (ismb == true)
{
if (state == epath)
path += mb;
else if (state == evalue)
value += mb;
}
else
{
if (state == epath)
path += c;
else if (state == evalue)
value += c;
}
mStreamPos++;
}
return 1;
}
////////////////////////////////////////////
cXmlNode::cXmlNode()
{
reset();
};
cXmlNode::~cXmlNode(){};
inline void
cXmlNode::reset()
{
mNodeType = unknow;
mTagName = "";
mTagAttrMap.clear();
}
inline void
cXmlNode::setNodeType(xmlNodeType type)
{
mNodeType = type;
}
inline void
cXmlNode::setTagName(string& name)
{
mTagName = name;
}
inline void
cXmlNode::setAttr(string& name, string& value)
{
mTagAttrMap[name] = value;
}
inline xmlNodeType
cXmlNode::getNodeType()
{
return mNodeType;
}
inline string&
cXmlNode::getTagName()
{
return mTagName;
}
inline string
cXmlNode::getAttr(string& name)
{
return mTagAttrMap[name];
}
inline bool
cXmlNode::isAttrExist(string& name)
{
tagAttrMapIter mapIter;
mapIter = mTagAttrMap.find(name);
if (mapIter == mTagAttrMap.end())
return false;
return true;
}
////////////////////////////////////////////
cDSIOXmlFormat::cDSIOXmlFormat()
{
reset();
};
cDSIOXmlFormat::~cDSIOXmlFormat() {};
void
cDSIOXmlFormat::reset()
{
iDStructIOFormat::reset();
mXmlHead = "<?xml version=\"1.0\" encoding=\"GB2312\" ?>";
mDStructItem = "DStruct";
mItemLevel = 0;
mStreamPoint = NULL;
mFirstParse = true;
}
void
cDSIOXmlFormat::startLevel()
{
mDSStream = mXmlHead;
mDSStream += "\n\n";
mDSStream += "<";
mDSStream += mDStructItem;
mDSStream += ">\n";
}
void
cDSIOXmlFormat::endLevel()
{
mDSStream += "</";
mDSStream += mDStructItem;
mDSStream += ">\n";
}
void
cDSIOXmlFormat::makeItem(const string& key, const string& type)
{
mDSStream += makeIndent();
mDSStream += "<Item name=\"";
mDSStream += key;
mDSStream += "\" type=\"";
mDSStream += type;
mDSStream += "\">\n";
}
string
cDSIOXmlFormat::makeIndent()
{
int i;
string indent = "";
for(i = 0; i < mItemLevel; i++)
{
indent += "\t";
}
return indent;
}
void
cDSIOXmlFormat::enterLevel()
{
mItemLevel++;
}
void
cDSIOXmlFormat::exitLevel()
{
if (mItemLevel > 1)
{
mItemLevel--;
mDSStream += makeIndent();
mDSStream += "</Item>\n";
}
}
void
cDSIOXmlFormat::outHashKey(const string& key)
{
const string type = "key";
makeItem(key, type);
}
void
cDSIOXmlFormat::outArrayIndex(int index)
{
string type = "index";
char buff[1024];
string indexStr;
sprintf(buff, "%d", index);
indexStr = buff;
makeItem(indexStr, type);
}
void
cDSIOXmlFormat::outValue(const string& value)
{
if (value == "")
return;
mDSStream += makeIndent();
mDSStream += "<Value>";
mDSStream += value;
mDSStream += "</Value>\n";
}
int
cDSIOXmlFormat::inPathValue(string& path, string& value)
{
cXmlNode xmlNode;
string tagName = "";
path = "";
value = "";
if (mFirstParse == true)
{
nextXmlNode(xmlNode);
if (xmlNode.getNodeType() != declarationnode)
{
cerr << "错误XML声明节点" << endl;
return 0;
}
nextXmlNode(xmlNode);
if ( ! ((xmlNode.getNodeType() == node) &&
(xmlNode.getTagName() == "DStruct")) )
{
cerr << "XML文件格式错误" << endl;
return 0;
}
mFirstParse = false;
}
string name = "name";
string type = "type";
while (1)
{
if (nextXmlNode(xmlNode) == false)
{
cerr << outLineNum() << "无法获取标签" << endl;
return 0;
}
tagName = xmlNode.getTagName();
if (xmlNode.getNodeType() == endnode &&
tagName == "DStruct")
{
assert( mPath.size() == 0 );
return 2;
}
if (tagName == "Item")
{
if (xmlNode.getNodeType() == node)
{
string nameValue;
string typeValue;
string pathNode;
nameValue = xmlNode.getAttr(name);
typeValue = xmlNode.getAttr(type);
if (typeValue == "key")
{
if (mPath.size() == 0)
pathNode = nameValue;
else
pathNode = "." + nameValue;
mPath.push_back(pathNode);
}
else if (typeValue == "index")
{
pathNode = "[";
pathNode += nameValue;
pathNode += "]";
mPath.push_back(pathNode);
}
else
{
cerr << outLineNum() << "无法识别的属性:" << typeValue << endl;
return 0;
}
}
else
{
assert( mPath.size() > 0 );
mPath.pop_back();
}
}
else if (tagName == "Value")
{
xmlValue(value);
makePath(path);
nextXmlNode(xmlNode);
if (xmlNode.getNodeType() == endnode &&
xmlNode.getTagName() == "Value")
return 1;
cerr << outLineNum() << "没有以</Value>标签" << endl;
return 0;
}
else
{
cerr << outLineNum() << "无法识别的XML标签:" << tagName << endl;
return 0;
}
}
return 0;
}
bool
cDSIOXmlFormat::nextXmlNode(cXmlNode& xmlNode)
{
string mb;
bool ismb;
enum xmlstate
{
estart,
etags,
etage,
etag,
etagspace,
etagattrname,
etagattrequal,
etagattrvalue,
etagattrvaluee,
evalue,
ecomm
};
xmlstate state = estart;
xmlstate laststate = estart;
char c;
string tagName = "";
string tagAttrName = "";
string tagAttrValue = "";
xmlNode.reset();
while(state != etage)
{
if (mStreamPos >= mDSStream.length())
{
if (state != estart)
cerr << outLineNum() << "错误的结束" << endl;
return false;
}
c = mDSStream[mStreamPos];
ismb = isMultibyte(c);
if (ismb == true)
{
if (state != etag && state != etagattrname &&
state != etagattrvalue && state != evalue &&
state != ecomm)
{
cerr << outLineNum() << "不能识别的双字节字符" << endl;
return false;
}
multibyte(mb);
c = '\0';
}
else if (c == '\n')
{
addlineNum();
}
mStreamPos++;
switch( state )
{
case estart:
if (c == '<')
state = etags;
else
continue;
break;
case etags:
if (c == '?')
{
xmlNode.setNodeType(declarationnode);
}
else if (c == '/')
{
xmlNode.setNodeType(endnode);
}
else
{
xmlNode.setNodeType(node);
mStreamPos--;
}
state = etag;
break;
case etag:
if (c == '>')
{
laststate = etag;
state = etage;
xmlNode.setTagName(tagName);
}
else if (c == ' ' || c == '\t')
{
laststate = etag;
state = etagspace;
xmlNode.setTagName(tagName);
}
else
{
if (c == '\0')
tagName += mb;
else
tagName += c;
}
break;
case etagattrname:
if (c == '>')
{
cerr << outLineNum() << "没有=号及属性值" << endl;
return false;
}
else if (c == '=')
{
laststate = etagattrname;
state = etagattrequal;
if (xmlNode.isAttrExist(tagAttrName) == true)
{
cerr << outLineNum() << "重复的属性" << endl;
return false;
}
}
else if (c == ' ' || c == '\t')
{
laststate = etagattrname;
state = etagspace;
if (xmlNode.isAttrExist(tagAttrName) == true)
{
cerr << outLineNum() << "重复的属性" << endl;
return false;
}
}
else
{
if (c == '\0')
tagAttrName += mb;
else
tagAttrName += c;
}
break;
case etagattrequal:
if (c == '>')
{
cerr << outLineNum() << "没有属性值" << endl;
return false;
}
else if (c == ' ')
{
state = etagspace;
}
else if (c == '"')
{
state = etagattrvalue;
}
else
{
cerr << outLineNum() << "属性赋值时,此处只能出现做引号" << endl;
return false;
}
break;
case etagattrvalue:
if (c == '"')
{
state = etagattrvaluee;
xmlNode.setAttr(tagAttrName, tagAttrValue);
tagAttrName = "";
tagAttrValue = "";
}
else
{
if (c == '\0')
tagAttrValue += mb;
else
tagAttrValue += c;
}
break;
case etagattrvaluee:
if (c == '>')
{
state = etage;
}
else if (c == ' ' || c == '\t')
{
laststate = etagattrvaluee;
state = etagspace;
}
else
{
cerr << outLineNum() << "属性需要使用空格分隔" << endl;
return false;
}
break;
case etagspace:
if (c == ' ' || c == '\t')
continue;
switch ( laststate )
{
case etag:
if (c == '>')
{
state = etage;
continue;
}
state = etagattrname;
mStreamPos--;
break;
case etagattrname:
if (c == '=')
{
state = etagattrequal;
}
else
{
cerr << outLineNum() << "属性后面需要有\"=\"号" << endl;
return false;
}
break;
case etagattrequal:
if (c == '"')
{
state = etagattrvalue;
}
else
{
cerr << outLineNum() << "属性值需要从引号开始" << endl;
return false;
}
break;
case etagattrvaluee:
if (c == '?' && xmlNode.getNodeType() == declarationnode)
{
}
else if (c == '>')
{
state = etage;
}
else
{
state = etagattrname;
mStreamPos--;
}
break;
}
break;
}
}
return true;
}
void
cDSIOXmlFormat::xmlValue(string& value)
{
int state = 1;
char c;
string mb;
bool ismb;
value = "";
if (mStreamPos >= mDSStream.length())
return;
while ( state )
{
c = mDSStream[mStreamPos];
ismb = isMultibyte(c);
if (ismb == true)
{
multibyte(mb);
value += mb;
}
else if (c == '<')
{
return;
}
else
{
value += c;
}
mStreamPos++;
}
}
| true |
33b1c375b34dc3379c9917e7a6785660a9162706 | C++ | xtl-murphy/ZXDJRenderer | /component/Matrix.cpp | UTF-8 | 4,677 | 3.1875 | 3 | [] | no_license | //
// Created by murphy on 2019-06-26.
//
/**
* Matrix
* @version 1.0
* @since 1.0
* <p>
* Created by murphy at 2019-06-26 18:11
**/
#include "Matrix.hpp"
void matrix_add(Matrix *c, const Matrix *a, const Matrix *b)
{
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
c->m[i][j] = a->m[i][j] + b->m[i][j];
}
}
}
void matrix_sub(Matrix *c, const Matrix *a, const Matrix *b)
{
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
c->m[i][j] = a->m[i][j] - b->m[i][j];
}
}
}
void matrix_mul(Matrix *c, const Matrix *a, const Matrix *b)
{
Matrix z;
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
z.m[j][i] = (a->m[j][0] * b->m[0][i]) +
(a->m[j][1] * b->m[1][i]) +
(a->m[j][2] * b->m[2][i]) +
(a->m[j][3] * b->m[3][i]);
}
}
c[0] = z;
}
void matrix_scale(Matrix *c, const Matrix *a, float f)
{
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++)
c->m[i][j] = a->m[i][j] * f;
}
}
void matrix_apply(Vector *y, const Vector *x, const Matrix *m)
{
float X = x->x, Y = x->y, Z = x->z, W = x->w;
y->x = X * m->m[0][0] + Y * m->m[1][0] + Z * m->m[2][0] + W * m->m[3][0];
y->y = X * m->m[0][1] + Y * m->m[1][1] + Z * m->m[2][1] + W * m->m[3][1];
y->z = X * m->m[0][2] + Y * m->m[1][2] + Z * m->m[2][2] + W * m->m[3][2];
y->w = X * m->m[0][3] + Y * m->m[1][3] + Z * m->m[2][3] + W * m->m[3][3];
}
void matrix_set_identity(Matrix *m) {
m->m[0][0] = m->m[1][1] = m->m[2][2] = m->m[3][3] = 1.0f;
m->m[0][1] = m->m[0][2] = m->m[0][3] = 0.0f;
m->m[1][0] = m->m[1][2] = m->m[1][3] = 0.0f;
m->m[2][0] = m->m[2][1] = m->m[2][3] = 0.0f;
m->m[3][0] = m->m[3][1] = m->m[3][2] = 0.0f;
}
void matrix_set_zero(Matrix *m) {
m->m[0][0] = m->m[0][1] = m->m[0][2] = m->m[0][3] = 0.0f;
m->m[1][0] = m->m[1][1] = m->m[1][2] = m->m[1][3] = 0.0f;
m->m[2][0] = m->m[2][1] = m->m[2][2] = m->m[2][3] = 0.0f;
m->m[3][0] = m->m[3][1] = m->m[3][2] = m->m[3][3] = 0.0f;
}
void matrix_set_translate(Matrix *m, float x, float y, float z) {
matrix_set_identity(m);
m->m[3][0] = x;
m->m[3][1] = y;
m->m[3][2] = z;
}
void matrix_set_scale(Matrix *m, float x, float y, float z) {
matrix_set_identity(m);
m->m[0][0] = x;
m->m[1][1] = y;
m->m[2][2] = z;
}
void matrix_set_rotate(Matrix *m, float x, float y, float z, float theta) {
float qsin = sin(theta * 0.5f);
float qcos = cos(theta * 0.5f);
Vector vec = { x, y, z, 1.0f };
float w = qcos;
vector_normalize(&vec);
x = vec.x * qsin;
y = vec.y * qsin;
z = vec.z * qsin;
m->m[0][0] = 1 - 2 * y * y - 2 * z * z;
m->m[1][0] = 2 * x * y - 2 * w * z;
m->m[2][0] = 2 * x * z + 2 * w * y;
m->m[0][1] = 2 * x * y + 2 * w * z;
m->m[1][1] = 1 - 2 * x * x - 2 * z * z;
m->m[2][1] = 2 * y * z - 2 * w * x;
m->m[0][2] = 2 * x * z - 2 * w * y;
m->m[1][2] = 2 * y * z + 2 * w * x;
m->m[2][2] = 1 - 2 * x * x - 2 * y * y;
m->m[0][3] = m->m[1][3] = m->m[2][3] = 0.0f;
m->m[3][0] = m->m[3][1] = m->m[3][2] = 0.0f;
m->m[3][3] = 1.0f;
}
void matrix_set_lookat(Matrix *m, const Vector *eye, const Vector *at, const Vector *up)
{
Vector xaxis, yaxis, zaxis;
//叉乘的结果是得到两个向量的垂直向量
//得到Z轴向量
vector_sub(&zaxis, at, eye);
vector_normalize(&zaxis);
//Y轴单位向量与Z轴叉乘得到X轴向量
vector_crossproduct(&xaxis, up, &zaxis);
vector_normalize(&xaxis);
//有了X 和 Z 叉乘就能得到Y向量
vector_crossproduct(&yaxis, &zaxis, &xaxis);
//由此得到摄像机位置
//下方的点乘处理是把摄像机平移到其所在位置
m->m[0][0] = xaxis.x;
m->m[1][0] = xaxis.y;
m->m[2][0] = xaxis.z;
m->m[3][0] = -vector_dotproduct(&xaxis, eye);
m->m[0][1] = yaxis.x;
m->m[1][1] = yaxis.y;
m->m[2][1] = yaxis.z;
m->m[3][1] = -vector_dotproduct(&yaxis, eye);
m->m[0][2] = zaxis.x;
m->m[1][2] = zaxis.y;
m->m[2][2] = zaxis.z;
m->m[3][2] = -vector_dotproduct(&zaxis, eye);
m->m[0][3] = m->m[1][3] = m->m[2][3] = 0.0f;
m->m[3][3] = 1.0f;
}
void matrix_set_perspective(Matrix *m, float fovy, float aspect, float zn, float zf)
{
float fax = 1.0f / tan(fovy * 0.5f);
matrix_set_zero(m);
m->m[0][0] = (fax / aspect);
m->m[1][1] = (fax);
m->m[2][2] = zf / (zf - zn);
m->m[3][2] = - zn * zf / (zf - zn);
m->m[2][3] = 1;
} | true |
9142b90e816d20ce1e5e162f6464ca3691d0fffa | C++ | yossich6/System-Programing-SPL---Ass1 | /include/cyberexpert.h | UTF-8 | 919 | 2.625 | 3 | [] | no_license | #ifndef CYBER_EXPERT
#define CYBER_EXPERT
#include <iostream>
#include <string>
#include <vector>
#include "../include/cyberpc.h"
class CyberExpert
{
private:
const std::string cyber_expert_name_;
const int cyber_expert_work_time_;
const int cyber_expert_rest_time_;
const int cyber_expert_efficiency_;
CyberExpert();
// Prevent the use of an empty constructor
// Add your own variables here
public:
int work_time_counter;
int rest_time_counter;
CyberExpert(std::string cyber_expert_name_, int cyber_expert_work_time_, int cyber_expert_rest_time_, int cyber_expert_efficiency_);
void Clean(CyberPC & cyber_pc);
const std::string get_cyber_expert_name_();
const int get_cyber_expert_work_time_();
const int get_cyber_expert_rest_time_();
const int get_cyber_expert_efficiency_();
//CyberExpert& operator=(CyberExpert exp);
};
#endif
| true |
57fc0f6d3f048c56c15e8316d8bfd10f9ff9641f | C++ | andy199310/posd_hw1 | /HW1/Command/DeleteCommand.h | UTF-8 | 717 | 2.59375 | 3 | [] | no_license | //
// Created by Green on 2016/12/5.
//
#ifndef POSD_HW1_DELETECOMMAND_H
#define POSD_HW1_DELETECOMMAND_H
#include "../Application.h"
#include "Command.h"
class DeleteCommand : public Command{
private:
Application *_application;
std::map<std::string, Media*> _mediaMap;
Media* _deleteTarget;
std::vector<std::string> _parentVector;
public:
DeleteCommand(Application *application);
public:
virtual void execute(std::string command) override;
virtual bool checkValid(std::string command) override;
virtual bool needUndo() override;
virtual void undo() override;
virtual void redo() override;
virtual Command *clone() override;
};
#endif //POSD_HW1_DELETECOMMAND_H
| true |
4f147efd08d9c545c151be51938c286d07aaa588 | C++ | charmdong/Algorithm_solutions_2019 | /Baekjoon/BJ2156_repeat.cpp | UTF-8 | 555 | 2.796875 | 3 | [] | no_license | #include <iostream>
#include <algorithm>
using namespace std;
int wine[10001];
int dp[10001];
int solution(int n);
int main()
{
int n;
cin >> n;
for(int i=0; i<n; i++) {
cin >> wine[i + 1];
}
cout << solution(n) << endl;
return 0;
}
int solution(int n)
{
dp[1] = wine[1];
dp[2] = wine[1] + wine[2];
for(int index = 3; index <= n; index++) {
dp[index] = max(dp[index - 2], dp[index - 3] + wine[index - 1]) + wine[index];
dp[index] = max(dp[index - 1], dp[index]);
}
return dp[n];
} | true |
961ec6afa2405da86e786d776eaba36e07471cac | C++ | janhuang6/Cplusplus-ImageProcessing | /worklist/worklistserver/timer.cc | UTF-8 | 3,679 | 2.75 | 3 | [] | no_license | /*
* file: timer.cc
* purpose: Implementation of the timer class
* Modified from book "Unix System Programming Using C++"
* created: 30-Nov-03
* property of: Philips Nuclear Medicine, ADAC Laboratories
*
* revision history:
* 30-Nov-03 Jiantao Huang initial version
*/
#include "timer.h"
#include "acquire/mesg.h"
/* constructor: setup a timer */
Timer::Timer(int signo, SIGFUNC action, int timer_tag, clock_t sys_clock)
{
_status = 0;
struct sigaction sigv;
sigemptyset(&sigv.sa_mask);
sigv.sa_flags = SA_SIGINFO;
sigv.sa_sigaction = action;
if (sigaction( signo, &sigv, 0) == -1)
{ ::Message( MALARM, toEndUser | toService | MLoverall, "sigaction failed");
_status = errno;
}
else
{
struct sigevent sigx;
memset(&sigx, 0, sizeof(struct sigevent));
sigx.sigev_notify = SIGEV_SIGNAL;
sigx.sigev_signo = signo;
sigx.sigev_value.sival_int = timer_tag;
if (timer_create( sys_clock, &sigx, &_timerID)==-1)
{ ::Message( MALARM, toEndUser | toService | MLoverall, "timer_create failed");
_status = errno;
}
}
}
/* destructor: discard a timer */
Timer::~Timer() throw()
{
if(_status == 0)
{
stop();
if(timer_delete( _timerID) == -1)
::Message( MALARM, toEndUser | toService | MLoverall, "timer_delete failed");
}
}
/* Check timer _status */
int Timer::operator!()
{
return _status? 1:0;
}
/* setup a relative time timer */
int Timer::run(long start_sec, long start_nsec, long reload_sec, long reload_nsec)
{
if(_status)
return -1;
_val.it_value.tv_sec = start_sec;
_val.it_value.tv_nsec = start_nsec;
_val.it_interval.tv_sec = reload_sec;
_val.it_interval.tv_nsec = reload_nsec;
if (timer_settime( _timerID, 0, &_val, 0) == -1)
{
::Message( MALARM, toEndUser | toService | MLoverall, "timer_settime failed");
_status = errno;
return -1;
}
return 0;
}
/* setup an absolute time timer */
int Timer::run(time_t start_time, long reload_sec, long reload_nsec)
{
if(_status)
return -1;
_val.it_value.tv_sec = start_time;
_val.it_value.tv_nsec = 0;
_val.it_interval.tv_sec = reload_sec;
_val.it_interval.tv_nsec = reload_nsec;
if (timer_settime( _timerID, TIMER_ABSTIME, &_val, 0) == -1)
{
::Message( MALARM, toEndUser | toService | MLoverall, "timer_settime failed");
_status = errno;
return -1;
}
return 0;
}
/* Stop a timer from running */
int Timer::stop()
{
if(_status)
return -1;
_val.it_value.tv_sec = 0;
_val.it_value.tv_nsec = 0;
_val.it_interval.tv_sec = 0;
_val.it_interval.tv_nsec = 0;
if (timer_settime( _timerID, 0, &_val, 0) == -1)
{
::Message( MALARM, toEndUser | toService | MLoverall, "timer_settime failed");
_status = errno;
return -1;
}
return 0;
}
/* Get timer overrun statistic */
int Timer::overrun()
{
if(_status)
return -1;
return timer_getoverrun( _timerID);
}
/* Get timer remaining time to expiration */
int Timer::values( long& sec, long& nsec)
{
if(_status)
return -1;
if(timer_gettime( _timerID, &_val ) == -1)
{
::Message( MALARM, toEndUser | toService | MLoverall, "timer_gettime failed");
_status = errno;
return -1;
}
sec = _val.it_value.tv_sec;
nsec = _val.it_value.tv_nsec;
return 0;
}
/* Overload << operator for timer objects */
ostream& operator<<( ostream& os, Timer& obj)
{
long sec, nsec;
obj.values( sec, nsec );
double tval = sec+((double)nsec/1000000000.0);
os << "time left: " << tval << std::endl;
::Message( MALARM, toEndUser | toService | MLoverall, "time left: %f\n", tval);
return os;
}
| true |
f8868658f05ed4d05d4b3a04b6858d51d915f47a | C++ | PkuRainBow/leetcode_locked_problems | /Closest-Binary-Search-Tree-Value.cpp | UTF-8 | 596 | 3.203125 | 3 | [] | no_license | //
// Created by pianocoder on 16/5/8.
//
/**
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.
Note:
Given target value is a floating point.
You are guaranteed to have only one unique value in the BST that is closest to the target.
**/
#include <vector>
#include <string>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
class Solution {
public:
int closestValue(TreeNode* root, double target) {
}
}; | true |
d5c1cd45295551f430bfcdf21a42fde509207493 | C++ | PhoenixGS/Solutions | /Luogu/3379.cpp | UTF-8 | 1,565 | 2.5625 | 3 | [] | no_license | #include <cstdio>
#include <algorithm>
long long read()
{
char last = '+', ch = getchar();
while (ch < '0' || ch > '9') last = ch, ch = getchar();
long long tmp = 0;
while (ch >= '0' && ch <= '9') tmp = tmp * 10 + ch - 48, ch = getchar();
if (last == '-') tmp = -tmp;
return tmp;
}
const int _n = 500000 + 10;
int n, m, root;
int edgenum;
int vet[2 * _n], nextx[2 * _n], head[_n];
int fa[_n], size[_n], deep[_n];
int top[_n];
void add(int u, int v)
{
edgenum++;
vet[edgenum] = v;
nextx[edgenum] = head[u];
head[u] = edgenum;
}
void dfs(int u, int father)
{
fa[u] = father;
size[u] = 1;
for (int i = head[u]; i; i = nextx[i])
{
int v = vet[i];
if (v != father)
{
deep[v] = deep[u] + 1;
dfs(v, u);
size[u] += size[v];
}
}
}
void dfs2(int u, int father, int chain)
{
top[u] = chain;
int k = 0;
for (int i = head[u]; i; i = nextx[i])
{
int v = vet[i];
if (v != father && size[v] > size[k])
{
k = v;
}
}
if (k)
{
dfs2(k, u, chain);
}
for (int i = head[u]; i; i = nextx[i])
{
int v = vet[i];
if (v != father && v != k)
{
dfs2(v, u, v);
}
}
}
int query(int x, int y)
{
while (top[x] != top[y])
{
if (deep[top[x]] < deep[top[y]])
{
std::swap(x, y);
}
x = fa[top[x]];
}
return deep[x] > deep[y] ? y : x;
}
int main()
{
scanf("%d%d%d", &n, &m, &root);
for (int i = 1; i < n; i++)
{
int u = read();
int v = read();
add(u, v);
add(v, u);
}
dfs(root, 0);
dfs2(root, 0, root);
while (m--)
{
int u = read();
int v = read();
printf("%d\n", query(u, v));
}
return 0;
}
| true |
2493fda5df48ee62914f88b741a7b319e435ac70 | C++ | Skywalker666666/visual_mapping | /voxblox-plusplus/voxblox/voxblox/include/voxblox/io/sdf_ply.h | UTF-8 | 8,021 | 2.546875 | 3 | [
"BSD-3-Clause",
"MIT"
] | permissive | #ifndef VOXBLOX_IO_SDF_PLY_H_
#define VOXBLOX_IO_SDF_PLY_H_
#include <algorithm>
#include <string>
#include "voxblox/core/layer.h"
#include "voxblox/io/mesh_ply.h"
#include "voxblox/mesh/mesh.h"
#include "voxblox/mesh/mesh_integrator.h"
#include "voxblox/mesh/mesh_layer.h"
namespace voxblox {
namespace io {
enum PlyOutputTypes {
// The full SDF colorized by the distance in each voxel.
kSdfColoredDistanceField,
// Output isosurface, i.e. the mesh for sdf voxel types.
kSdfIsosurface,
// Output isosurface, i.e. the mesh for sdf voxel types.
// Close vertices are connected and zero surface faces are removed.
kSdfIsosurfaceConnected
};
/**
* Convert a voxel to a colored point. The sdf_color_range determines the range
* that is covered by the rainbow colors. All absolute distance values that
* exceed this range will receive tha max/min color of the rainbow range. The
* sdf_max_value determines if a point is generated for this value or not. Only
* SDF values within this max value result in a colored point.
*/
template <typename VoxelType>
bool getColorFromVoxel(const VoxelType& voxel, const float sdf_color_range,
const float sdf_max_value, Color* color);
/**
* Convert a voxel to a colored point. The sdf_color_range determines the range
* that is covered by the rainbow colors. All absolute distance values that
* exceed this range will receive tha max/min color of the rainbow range. The
* sdf_max_value determines if a point is generated for this value or not. Only
* SDF values within this max value result in a colored point.
*/
template <>
bool getColorFromVoxel(const TsdfVoxel& voxel, const float sdf_color_range,
const float sdf_max_value, Color* color);
/**
* Convert a voxel to a colored point. The sdf_color_range determines the range
* that is covered by the rainbow colors. All absolute distance values that
* exceed this range will receive tha max/min color of the rainbow range. The
* sdf_max_value determines if a point is generated for this value or not. Only
* SDF values within this max value result in a colored point.
*/
template <>
bool getColorFromVoxel(const EsdfVoxel& voxel, const float sdf_color_range,
const float sdf_max_value, Color* color);
/**
* This function converts all voxels with positive weight/observed into points
* colored by a color map based on the SDF value. The parameter sdf_color_range
* is used to determine the range of the rainbow color map which is used to
* visualize the SDF values. If an SDF value is outside this range, it will be
* truncated to the limits of the range. sdf_max_value determines if a point is
* generated for this value or not. Only SDF values within this max value result
* in a colored point. If this threshold is set to a negative value, all points
* will be generated independent of the SDF value.
*/
template <typename VoxelType>
bool convertVoxelGridToPointCloud(const Layer<VoxelType>& layer,
const float sdf_color_range,
const float sdf_max_value,
voxblox::Mesh* point_cloud) {
CHECK_NOTNULL(point_cloud);
CHECK_GT(sdf_color_range, 0.0f);
BlockIndexList blocks;
layer.getAllAllocatedBlocks(&blocks);
// Iterate over all blocks.
for (const BlockIndex& index : blocks) {
// Iterate over all voxels in said blocks.
const Block<VoxelType>& block = layer.getBlockByIndex(index);
const int vps = block.voxels_per_side();
VoxelIndex voxel_index = VoxelIndex::Zero();
for (voxel_index.x() = 0; voxel_index.x() < vps; ++voxel_index.x()) {
for (voxel_index.y() = 0; voxel_index.y() < vps; ++voxel_index.y()) {
for (voxel_index.z() = 0; voxel_index.z() < vps; ++voxel_index.z()) {
const VoxelType& voxel = block.getVoxelByVoxelIndex(voxel_index);
// Get back the original coordinate of this voxel.
const Point coord =
block.computeCoordinatesFromVoxelIndex(voxel_index);
Color color;
if (getColorFromVoxel(voxel, sdf_color_range, sdf_max_value,
&color)) {
point_cloud->vertices.push_back(coord);
point_cloud->colors.push_back(color);
}
}
}
}
}
return point_cloud->size() > 0u;
}
template <typename VoxelType>
bool convertVoxelGridToPointCloud(const Layer<VoxelType>& layer,
const float sdf_color_range,
voxblox::Mesh* point_cloud) {
constexpr float kInvalidSdfMaxValue = -1.0f;
return convertVoxelGridToPointCloud<VoxelType>(
layer, sdf_color_range, kInvalidSdfMaxValue, point_cloud);
}
/**
* Converts the layer to a mesh by extracting its ISO surface using marching
* cubes. This function returns false if the mesh is empty. The mesh can either
* be extracted as a set of distinct triangles, or the function can try to
* connect all identical vertices to create a connected mesh.
*/
template <typename VoxelType>
bool convertLayerToMesh(
const Layer<VoxelType>& layer, const MeshIntegratorConfig& mesh_config,
voxblox::Mesh* mesh, const bool connected_mesh = true,
const FloatingPoint vertex_proximity_threshold = 1e-10) {
CHECK_NOTNULL(mesh);
MeshLayer mesh_layer(layer.block_size());
MeshIntegrator<VoxelType> mesh_integrator(mesh_config, layer, &mesh_layer);
// Generate mesh layer.
constexpr bool only_mesh_updated_blocks = false;
constexpr bool clear_updated_flag = false;
mesh_integrator.generateMesh(only_mesh_updated_blocks, clear_updated_flag);
// Extract mesh from mesh layer, either by simply concatenating all meshes
// (there is one per block) or by connecting them.
if (connected_mesh) {
mesh_layer.getConnectedMesh(mesh, vertex_proximity_threshold);
} else {
mesh_layer.getMesh(mesh);
}
return mesh->size() > 0u;
}
template <typename VoxelType>
bool convertLayerToMesh(
const Layer<VoxelType>& layer, voxblox::Mesh* mesh,
const bool connected_mesh = true,
const FloatingPoint vertex_proximity_threshold = 1e-10) {
MeshIntegratorConfig mesh_config;
return convertLayerToMesh(layer, mesh_config, mesh, connected_mesh,
vertex_proximity_threshold);
}
/**
* Output the layer to ply file. Depending on the ply output type, this either
* exports all voxel centers colored by th SDF values or extracts the ISO
* surface as mesh. The parameter sdf_color_range is used to color the points
* for modes that use an SDF-based point cloud coloring function.
*/
template <typename VoxelType>
bool outputLayerAsPly(const Layer<VoxelType>& layer,
const std::string& filename, PlyOutputTypes type,
const float sdf_color_range = 0.3f,
const float max_sdf_value_to_output = 0.3f) {
CHECK(!filename.empty());
switch (type) {
case PlyOutputTypes::kSdfColoredDistanceField: {
voxblox::Mesh point_cloud;
if (!convertVoxelGridToPointCloud(
layer, sdf_color_range, max_sdf_value_to_output, &point_cloud)) {
return false;
}
return outputMeshAsPly(filename, point_cloud);
}
case PlyOutputTypes::kSdfIsosurface: {
constexpr bool kConnectedMesh = false;
voxblox::Mesh mesh;
if (!convertLayerToMesh(layer, &mesh, kConnectedMesh)) {
return false;
}
return outputMeshAsPly(filename, mesh);
}
case PlyOutputTypes::kSdfIsosurfaceConnected: {
constexpr bool kConnectedMesh = true;
voxblox::Mesh mesh;
if (!convertLayerToMesh(layer, &mesh, kConnectedMesh)) {
return false;
}
return outputMeshAsPly(filename, mesh);
}
default:
LOG(FATAL) << "Unknown layer to ply output type: "
<< static_cast<int>(type);
}
return false;
}
} // namespace io
} // namespace voxblox
#endif // VOXBLOX_IO_SDF_PLY_H_
| true |
48477ff2c0417b505237eda107a5d3a527b29157 | C++ | XiyouLinuxGroup-2019-Summer/TeamF | /lhd/Solution/2-3.cc | UTF-8 | 537 | 3.171875 | 3 | [
"MIT"
] | permissive | #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iterator>
using namespace std;
class K
{
public:
void get()
{
cin >> A >> B;
sort(B.rbegin(),B.rend());
int j = 0 ;
for(size_t i = 0; i < A.size() ; i++)
{
if(B[j] > A[i] )
{
A[i] = B[j];
j++;
}
}
cout << A << endl;
}
private:
string A;
string B;
};
int main()
{
K a1;
a1.get();
return 0;
}
| true |
68cabaf91f4143b0150d64e6377e6e198e3c71e0 | C++ | jowie94/The-Simpsons-Arcade | /Engine/Scene.h | UTF-8 | 3,596 | 2.75 | 3 | [
"MIT"
] | permissive | #ifndef __SCENE_H__
#define __SCENE_H__
#include "Module.h"
#include "Entity.h"
#include <memory>
class Scene : public Module
{
public:
Scene(bool active) : Module(active)
{
xmin = xmax = zmin = zmax = 0;
}
virtual ~Scene() {}
void AddEntity(Entity* entity)
{
_entities.push_back(entity);
}
void RemoveEntity(Entity* entity)
{
_entities.remove(entity);
}
void AddPlayer(Entity* player)
{
//player->Position.y = 100; // TODO: Calculate correct position
_players.push_back(player);
}
void RemovePlayer(Entity* player)
{
_players.remove(player);
}
void PlayerList(std::list<Entity*>& players) const
{
players = _players;
}
void AddEnemy(Entity* enemy)
{
if (enemy->IsEnabled())
enemy->Start();
else
enemy->Enable();
_enemies.push_back(enemy);
}
void RemoveEnemy(Entity* enemy)
{
_enemies.remove(enemy);
}
bool Start() override
{
return StartAllEntities();
}
update_status PreUpdate() override
{
for (auto it = _entities.begin(); it != _entities.end(); ++it)
if ((*it)->IsEnabled())
(*it)->PreUpdate();
for (auto it = _players.begin(); it != _players.end(); ++it)
if ((*it)->IsEnabled())
(*it)->PreUpdate();
for (auto it = _enemies.begin(); it != _enemies.end(); ++it)
if ((*it)->IsEnabled())
(*it)->PreUpdate();
return UPDATE_CONTINUE;
}
update_status Update() override
{
for (auto it = _entities.begin(); it != _entities.end(); ++it)
if ((*it)->IsEnabled())
(*it)->Update();
for (auto it = _players.begin(); it != _players.end(); ++it)
if ((*it)->IsEnabled())
(*it)->Update();
for (auto it = _enemies.begin(); it != _enemies.end(); ++it)
if ((*it)->IsEnabled())
(*it)->Update();
return UPDATE_CONTINUE;
}
update_status PostUpdate() override
{
for (auto it = _entities.begin(); it != _entities.end(); ++it)
if ((*it)->IsEnabled())
(*it)->PostUpdate();
for (auto it = _players.begin(); it != _players.end(); ++it)
if ((*it)->IsEnabled())
(*it)->PostUpdate();
for (auto it = _enemies.begin(); it != _enemies.end(); ++it)
if ((*it)->IsEnabled())
(*it)->PostUpdate();
return UPDATE_CONTINUE;
}
bool CleanUp() override
{
for (auto it = _entities.begin(); it != _entities.end(); ++it)
{
(*it)->CleanUp();
RELEASE((*it));
}
_entities.clear();
for (auto it = _players.begin(); it != _players.end(); ++it)
{
(*it)->CleanUp();
RELEASE((*it));
}
_players.clear();
for (auto it = _enemies.begin(); it != _enemies.end(); ++it)
{
(*it)->CleanUp();
RELEASE((*it));
}
_players.clear();
return true;
}
virtual void SceneLimits(std::pair<int, int>& x, std::pair<int, int>& z) const
{
x = std::make_pair(xmin, xmax);
z = std::make_pair(zmin, zmax);
}
void EnemyDefeated()
{
++enemies_defeated;
}
virtual bool Finished() const
{
return false;
}
virtual bool GameOver() const
{
return false;
}
protected:
std::list<Entity*> _entities;
std::list<Entity*> _players;
std::list<Entity*> _enemies;
int xmin, xmax, zmin, zmax;
int enemies_defeated = 0;
private:
bool StartAllEntities() const
{
bool ret = true;
for (auto it = _entities.cbegin(); it != _entities.cend() && ret; ++it)
{
if ((*it)->IsEnabled())
ret = (*it)->Start();
}
for (auto it = _players.cbegin(); it != _players.cend() && ret; ++it)
{
if ((*it)->IsEnabled())
ret = (*it)->Start();
}
for (auto it = _enemies.cbegin(); it != _enemies.cend() && ret; ++it)
{
if ((*it)->IsEnabled())
ret = (*it)->Start();
}
return ret;
}
};
#endif // __SCENE_H__
| true |
88db5fbc19f59d72d5e815c707c4024ad9fd778c | C++ | knivey/weather | /FetchURL.cpp | UTF-8 | 769 | 2.90625 | 3 | [] | no_license | #include "FetchURL.hpp"
#include <cpprest/http_client.h>
std::tuple<bool, std::string> FetchURL(std::string url, web::uri_builder builder) {
std::string data;
try {
web::http::client::http_client_config config;
//Leading research shows my friends are unable to wait longer than 5 seconds
config.set_timeout(utility::seconds(5));
web::http::client::http_client client(url, config);
auto res = client.request(web::http::methods::GET, builder.to_string()).get();
//fmt::print("Received response status code: {}\n", res.status_code());
data = res.extract_string().get();
} catch (const std::exception &e) {
return std::make_tuple(true, e.what());
}
return std::make_tuple(false, data);
}
| true |
ab9dc08c505e8cfdbde5fdda4c2bd4257d0d0333 | C++ | emmacneil/euler | /051-100/093/main.cpp | UTF-8 | 3,393 | 3.5 | 4 | [] | no_license | /*
* Project Euler - Problem 93
* Arithmetic Expressions
*
* Assuming that 0 is not going to be one of our digits, we have 9 choose 4
* choices for a < b < c < d. There are 4! ways of arranging {a,b,c,d}. We have
* 4^3 choices for our operators {+,-,*,/}, and 5 ways of pairing our
* parentheses. In all, there are 967,680 different calculations to make here --
* within brute-force range.
*/
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const float EPS = 1.0e-7;
const int MAX_VAL = 6561;
char operators[4] = {'+', '-', '*', '/'};
bool found[MAX_VAL + 1];
int best = 0;
int result = 0;
// Stores f as a 'found' value if it is an integer
void store(float f)
{
if (f < 0)
return;
int n = rintf(f);
float fn = (float)n;
float d = f > fn ? f - fn : fn - f;
if (d < EPS)
{
found[n] = true;
}
}
// Applies the operator op to a and b. Note that although this doesn't check for
// divide by 0, it didn't prevent me from getting a correct solution :/
float sub(float a, float b, char op)
{
switch (op)
{
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
return a / b;
default:
return 0;
}
}
// Calculates all five ways of arranging the parentheses
void calc(float nums[4], char ops[3])
{
float a, b, c, d, x, y, z;
a = nums[0];
b = nums[1];
c = nums[2];
d = nums[3];
// (((a*b)*c)*d)
x = sub(a, b, ops[0]);
y = sub(x, c, ops[1]);
z = sub(y, d, ops[2]);
store(z);
// ((a*b)*(c*d))
x = sub(a, b, ops[0]);
y = sub(c, d, ops[2]);
z = sub(x, y, ops[1]);
store(z);
// ((a*(b*c))*d)
x = sub(b, c, ops[1]);
y = sub(a, x, ops[0]);
z = sub(y, d, ops[2]);
store(z);
// (a*((b*c)*d))
x = sub(b, c, ops[0]);
y = sub(x, d, ops[1]);
z = sub(a, y, ops[2]);
store(z);
// (a*(b*(c*d)))
x = sub(c, d, ops[2]);
y = sub(b, c, ops[1]);
z = sub(a, y, ops[0]);
store(z);
}
// Tries all combinations of operators {+,-,*,/}
void choose_operators(float nums[4])
{
char ops[3];
for (int i = 0; i < 4; i++)
{
ops[0] = operators[i];
for (int j = 0; j < 4; j++)
{
ops[1] = operators[j];
for (int k = 0; k < 4; k++)
{
ops[2] = operators[k];
calc(nums, ops);
}
}
}
}
// Tries all permutations of {a,b,c,d}
void permute_abcd(float nums[4])
{
do
{
choose_operators(nums);
} while(next_permutation(nums, nums+4));
}
// Reset the array of 'found' values. Calculates all the values that can be
// obtained by choosing operators and arranging the values a,b,c,d in nums[].
// Counts the number of consecutive 'found' values, recording the best results
// so far.
void solve(float nums[4])
{
for (int i = 0; i <= MAX_VAL; i++)
found[i] = false;
permute_abcd(nums);
int i = 1;
while (found[i++])
continue;
if (i > best)
{
best = i;
result = nums[0]*1000 + nums[1]*100 + nums[2]*10 + nums[3];
}
}
int main()
{
float nums[4];
// Try each choice of a, b, c, d.
for (int a = 1; a <= 6; a++)
{
nums[0] = (float)a;
for (int b = a + 1; b <= 7; b++)
{
nums[1] = (float)b;
for (int c = b + 1; c <= 8; c++)
{
nums[2] = (float)c;
for (int d = c + 1; d <= 9; d++)
{
nums[3] = (float)d;
solve(nums);
}
}
}
}
cout << result << endl;
return 0;
}
| true |
ef4eab916afce69ce3f6818f46ac491a9d58de63 | C++ | iuliabenyi/UBB-Labs | /Year 3/Sem1/PDP/Lab1/Lab1/Product.cpp | UTF-8 | 704 | 3.359375 | 3 | [] | no_license | #include "Product.h"
#include<iostream>
int Product::currProdID = 0;
Product::Product(int price, int quantity)
{
this->ID = this->currProdID++;
this->price = price;
this->initQuantity = quantity;
this->quantity = this->initQuantity;
}
int Product::getID() const
{
return this->ID;
}
int Product::getPrice() const
{
return this->price;
}
int Product::getQuantity() const {
return this->quantity;
}
int Product::buyQuantity(int quantity)
{
mtx.lock();
if (quantity <= this->quantity) {
std::cout << "\tBuying " << quantity << " products\n\n";
this->quantity -= quantity;
}
else {
mtx.unlock();
return 0;
}
mtx.unlock();
return this->price * quantity;
}
Product::~Product()
{
}
| true |
a09a4755d7850282b17ebbe06de2b9405eab2fd2 | C++ | Treekay/Learn-C-CPP | /Cpp-learing/2907 [Exception] Stack and Exception/Latest Submission/Stack.h | UTF-8 | 847 | 3.671875 | 4 | [] | no_license | const int MAX_LEN = 5;
template<class T>
class Stack{
public:
explicit Stack(){
for (int index = 0; index < 0; index++){
data[index] = 0;
}
stack_size = 0;
}
bool empty() const{
return stack_size;
}
int size() const{
return stack_size;
}
T& top(){
if (stack_size == 0) throw 1;
else return data[stack_size-1];
}
const T& top() const{
if (stack_size == 0) throw 1;
return data[stack_size-1];
}
void push(const T& x){
if (stack_size < MAX_LEN) data[stack_size++] = x;
else if (x > data[stack_size-1]) data[stack_size-1] = x;
}
void pop(){
if (stack_size == 0) throw 3.4;
else {
data[stack_size-1] = 0;
stack_size--;
}
}
private:
T data[MAX_LEN];
int stack_size;
}; | true |
b4d20382b268b830f0207d237e7ebf35c34f27dc | C++ | lennon2298/Mario-Clone | /Mario-Clone/src/main.cpp | UTF-8 | 2,558 | 2.578125 | 3 | [
"MIT"
] | permissive | #include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include <glm/glm.hpp>
#include "ResourceManager.h"
#include "Game.h"
unsigned int WIDTH = 800, HEIGHT = 600;
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
Game TryOut(WIDTH, HEIGHT);
int main() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
GLFWwindow* window = glfwCreateWindow(800, 600, "Test Window", nullptr, nullptr);
int screenWidth, screenHeight;
glfwGetFramebufferSize(window, &screenWidth, &screenHeight);
if (nullptr == window) {
std::cout << "Failed to initialize window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize Glad" << std::endl;
return -1;
}
glfwSetWindowAspectRatio(window, 8, 6);
glViewport(0, 0, screenWidth, screenHeight);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
TryOut.Init();
float deltaTime = 0.0f;
float lastFrame = 0.0f;
TryOut.SetState(GameState::GAME_ACTIVE);
while (!glfwWindowShouldClose(window)) {
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
glfwPollEvents();
TryOut.ProcessInput(deltaTime);
TryOut.Update(deltaTime);
glClearColor(0.015f, 0.611f, 0.847f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
TryOut.Render();
TryOut.Update(deltaTime);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
// when a user presses the escape key, we set the WindowShouldClose property to true, closing the application
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (key >= 0 && key < 1024)
{
if (action == GLFW_PRESS)
TryOut.SetKeyPress(key);
else if (action == GLFW_RELEASE)
TryOut.SetKeyRelease(key);
}
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
glfwSetWindowAspectRatio(window, 8, 6);
}
| true |
5cdee4bd2033dbabe5df681941e4fc8d5af93e85 | C++ | JoshuaHernandezAl/ProgrammingOldStuff | /Analisis/PolinomiosAN-master/Complejo.h | UTF-8 | 1,014 | 2.921875 | 3 | [] | no_license | #ifndef COMPLEJO_H
#define COMPLEJO_H
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
class Complejo{
private:
double real;
double imaginario;
public:
Complejo(void);
Complejo(float r, float i);
void pideDatos(void);
void muestraDatos(void);
double dameTuReal(void);
void modificaTuReal(double r);
double dameTuImaginario(void);
void modificaTuImaginario(double i);
Complejo operator=(Complejo A);
};
Complejo suma(Complejo A, Complejo B);
Complejo resta(Complejo A, Complejo B);
Complejo multiplica(Complejo A, Complejo B);
Complejo divide(Complejo A, Complejo B);
Complejo pow(Complejo A, int n);
double fabs(Complejo A);
istream& operator>>(istream& teclado, Complejo& Derecho);
ostream& operator<<(ostream& monitor, Complejo Derecho);
Complejo operator+(Complejo A, Complejo B);
Complejo operator-(Complejo A, Complejo B);
Complejo operator*(Complejo A, Complejo B);
Complejo operator/(Complejo A, Complejo B);
#endif // COMPLEJO_H
| true |
ed2d52f8b40f1401c3a9f67901fb009751445a6e | C++ | itsjustwinds/study-path | /HK3_2018-2019/CS163/W07/18125130_Ex02/Ex02_2.cpp | UTF-8 | 1,062 | 2.765625 | 3 | [] | no_license | /*
* Ex02_1.cpp
*
* Created on: Jul 10, 2019
* Author: huy
*/
#include"Ex02_2.h"
void input(int &n, int &begin, int &finish,int* &bef, int** &edge){
cin>>n>>begin>>finish;
edge=new int*[n];
for (int i=0;i<n;++i)
edge[i]=new int[n];
int u,v;
while(cin>>u){
cin>>v;
edge[u][v]=1;
}
bef=new int[n];
for (int i=0;i<n;++i)
bef[i]=-1;
}
void dfs(int &n,int &now,int &begin,int &finish,int* &bef, int** &edge,vector<int > &res){
if (now==finish){
int x=finish;
while(x!=begin){
res.push_back(x);
x=bef[x];
}
res.push_back(x);
return;
}
if (bef[finish]!=-1) return;
for (int i=0;i<n;++i){
if (bef[i]!=-1||edge[now][i]==0) continue;
bef[i]=now;
dfs(n,i,begin,finish,bef,edge,res);
}
}
void answer2(){
int n,begin,finish;
int *bef;
int **edge;
vector<int > res;
input(n,begin,finish,bef,edge);
dfs(n,begin,begin,finish,bef,edge,res);
for (int i=res.size()-1;i>=0;--i)
cout<<res[i]<<" ";
for (int i=0;i<n;++i){
delete[] edge[i];
edge[i]=NULL;
}
delete[] edge;
delete[] bef;
bef=NULL;
edge=NULL;
}
| true |
c6bef3b699744e48cd1d13ef24f13dcf1b93d306 | C++ | MasaokaKou/portfolio | /project/3portfolio(AttackOfMendako)/src/sceneGameClear.cpp | SHIFT_JIS | 4,057 | 2.546875 | 3 | [] | no_license | //---------------------------------------------------------------------------
//! @file sceneGameClear.cpp
//! @brief Q[vC̃V[̊Ǘ
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//! RXgN^
//---------------------------------------------------------------------------
SceneGameClear::SceneGameClear()
{
_text_x = WINDOW_W * 0.5f;
_text_y = WINDOW_H + 100;
_alpha[0] = 0;
_alpha[1] = 0;
_flag = false;
SetFontSize(20);
}
//---------------------------------------------------------------------------
//! fXgN^
//---------------------------------------------------------------------------
SceneGameClear::~SceneGameClear()
{
}
//---------------------------------------------------------------------------
//!
//! @retval true I ()
//! @retval false G[I (s)
//---------------------------------------------------------------------------
bool SceneGameClear::initialize()
{
_back_graph = LoadGraph("data/stage_select_back.png");
return true;
}
//---------------------------------------------------------------------------
//! XV
//---------------------------------------------------------------------------
void SceneGameClear::update()
{
SetFontSize(20);
//! Gh[XV
scrollEndRoll();
_alpha[0] += 5;
}
//---------------------------------------------------------------------------
//! `
//---------------------------------------------------------------------------
void SceneGameClear::render()
{
//! wi`
DrawRotaGraph(0, 0, 2.0f, 0, _back_graph, true);
SetDrawBlendMode(DX_BLENDMODE_ALPHA, _alpha[0]);
DrawBox(0, 0, WINDOW_W, WINDOW_H, BLACK, true);
SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
SetDrawBlendMode(DX_BLENDMODE_ALPHA, _alpha[1]);
DrawString(WINDOW_W * 0.5f - (5 * 21), WINDOW_H * 0.5f, "THANK YOU FOR PLAYING", WHITE, true);
SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
//! Gh[`
drawEndRoll();
}
//---------------------------------------------------------------------------
//!
//---------------------------------------------------------------------------
void SceneGameClear::finalize()
{
}
//---------------------------------------------------------------------------
//! Gh[`
//---------------------------------------------------------------------------
void SceneGameClear::drawEndRoll()
{
DrawString(_text_x - (5 * 14), _text_y, ":GAME PROJECT:", WHITE);
DrawString(_text_x - (5 * 10), _text_y + 40, "KO MASAOKA", WHITE);
DrawString(_text_x - (5 * 14), _text_y + 100, ":MODEL DESIGN:", WHITE);
DrawString(_text_x - (5 * 8), _text_y + 160, "`UNIT`", WHITE);
DrawString(_text_x - (5 * 11), _text_y + 200, "HANA MUTUDA", WHITE);
DrawString(_text_x - (5 * 9), _text_y + 260, "`ENEMY`", WHITE);
DrawString(_text_x - (5 * 8), _text_y + 300, "MATT ART", WHITE);
DrawString(_text_x - (5 * 20), _text_y + 340, "BY UNITY ASSET STORE", WHITE);
DrawString(_text_x - (5 * 17), _text_y + 400, "`MOTION DESIGN`", WHITE);
DrawString(_text_x - (5 * 10), _text_y + 440, "KO MASAOKA", WHITE);
DrawString(_text_x - (5 * 11), _text_y + 500, "`PROGRAM`", WHITE);
DrawString(_text_x - (5 * 10), _text_y + 540, "KO MASAOKA", WHITE);
}
//---------------------------------------------------------------------------
//! Gh[XV
//---------------------------------------------------------------------------
void SceneGameClear::scrollEndRoll()
{
_text_y -= 1;
if(_text_y + 560 < 0) {
_alpha[1] += 2;
if(_alpha[1] >= 255) {
_flag = true;
}
}
if(_flag) {
_alpha[1] -= 4;
if(_alpha[1] <= 0) {
Scene::sceneJump(new SceneGameTitle());
}
}
if(CheckHitKey(KEY_INPUT_SPACE)) {
_text_y -= 2;
}
}
| true |
4d9ea896ccc958b2515f4f39cee043afba4e53e1 | C++ | DenisEvteev/4_semester_mipt | /algorithms/merge_sort.cpp | UTF-8 | 2,080 | 3.71875 | 4 | [] | no_license | //
// Created by user on 01/04/2020.
//
#include <vector>
#include <iostream>
template <class T>
void merge_sort(std::vector<T>& res, size_t start, size_t end);
template <class T>
void merge(std::vector<T>& res, size_t start, size_t mid, size_t end);
int main()
{
std::vector<int> v(5000);
for(int i = 0; i < v.size(); ++i){
v[i] = std::rand();
}
/*This function should sort my vector with the increase order*/
merge_sort(v, 0, v.size() - 1);
for(int i = 0; i < v.size(); ++i){
std::cout << v[i] << std::endl;
}
return 0;
}
template <class T>
void merge_sort(std::vector<T>& res, size_t start, size_t end){
if(res.empty())
return;
if(start == end) // the case of a single element
return;
merge_sort(res, start, start + static_cast<size_t>( (end - start) / 2 ) );
merge_sort(res, start + static_cast<size_t>( (end - start) / 2 ) + 1, end);
merge(res, start, start + static_cast<size_t>( (end - start) / 2 ) + 1, end);
}
template<class T>
void merge(std::vector<T>& res, size_t start, size_t mid, size_t end){
/*Work with the situation when we have only two elements
* I will manage it in more easy way without allocating any additional memory for vectors*/
if( end == mid && (end - start == 1) )
{
if(res[start] > res[end])
std::swap(res[start], res[end]);
return;
}
std::vector<T> left, right;
typename std::vector<T>::iterator middle{res.begin() + mid};
std::copy( ( res.begin() + start ), middle, std::back_inserter(left)); // we are have filled the left vector with left part of res vector
std::copy(middle, ( res.begin() + end + 1 ) , std::back_inserter(right)); // we are have filled the right vector with right part of res vector
size_t count_left{0};
size_t count_right{0};
size_t ip{0};
size_t g_size{left.size() + right.size()};
while(ip < g_size)
{
if( count_right == right.size() || ( count_left != left.size() && left[count_left] <= right[count_right]))
{
res[start + ip] = left[count_left];
++count_left;
++ip;
continue;
}
res[start + ip] = right[count_right];
++ip;
++count_right;
}
}
| true |
264a805423dd27ff0fabff8970f5d112dda61f0f | C++ | akudrinsky/sorts | /include/graphics.hpp | UTF-8 | 1,296 | 2.921875 | 3 | [] | no_license | #pragma once
#include <SFML/Graphics.hpp>
#include "button.hpp"
#include "graph.hpp"
#include "usefulDefines.hpp"
#include <vector>
// Creates application for a program
void MakeApp();
// Basic interface for graphics, consists of buttons and graphs. TODO: more
// TODO: array of pointers to sf::Drawable
class application {
public:
// backgroundPath - path to background image.
application(const char* backgroundPath);
application() = delete;
NON_COPYBLE(application)
// checks all events and acts correspondly
void eventLoop();
// adds button to this application
// NOTE: move-semantics only, because only one application for program in assumed
void newButton(Button&& newButton);
// sets background
void setBackground(const char* backgroundPath);
// adds new element for this app.
void newElement(sf::Drawable& elem);
// searches for drawable element in this app.
sf::Drawable& searchElement(int index);
// quits from application.
void Quit();
private:
sf::RenderWindow window;
sf::Texture backgroundTexture;
sf::Sprite background;
std::vector<Button> buttons;
std::vector<sf::Drawable*> elems;
bool lostFocus;
void checkClick(int x_coord, int y_coord);
friend void MakeApp();
}; | true |
2e5268bf1e44b225d6f3818e89082e7139762b2c | C++ | Anatole-j/test_et_verification | /1_Software/Etape_7/src/main.cpp | UTF-8 | 591 | 2.625 | 3 | [] | no_license | #include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include <assert.h>
#include "pgcd.hpp"
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE( "cas normaux", "[pgcd]" ) {
SECTION( "A>B") {
REQUIRE( PGCD(135, 55) == 5 );
REQUIRE( PGCD(133, 97) == 1 );
}
/*SECTION( "A<B") {
REQUIRE( PGCD(100, 1000) == 101 );
REQUIRE( PGCD(70, 110) == 10 );
}
SECTION( "A=B" ){
REQUIRE(PGCD(33, 33) == 33);
}*/
}
/*TEST_CASE( "cas particuliers", "[pgcd]" ) {
REQUIRE( PGCD(0, 55) == 55 );
REQUIRE( PGCD(135, 0) == 135 );
}*/ | true |
f9782f52bf893c90620e851e42644b8cd8a931fc | C++ | chrissearle/teensy8x8matrix | /src/main.cpp | UTF-8 | 1,154 | 2.953125 | 3 | [] | no_license | #include <Arduino.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
int pinCS = 10;
int numberOfHorizontalDisplays = 1;
int numberOfVerticalDisplays = 1;
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
String tape = "Hello Philip ";
int wait = 50; // In milliseconds
int spacer = 1;
int width = 5 + spacer; // The font width is 5 pixels
// MOSI (11) -> DIN
// SCK (13)-> CLK
// SS (10) -> CS
void setup()
{
matrix.setIntensity(7);
matrix.setPosition(0, 0, 0);
matrix.setRotation(0, 1); // Rotate 90
}
void loop()
{
for (unsigned int i = 0; i < width * tape.length() + matrix.width() - 1 - spacer; i++)
{
matrix.fillScreen(LOW);
unsigned int letter = i / width;
int x = (matrix.width() - 1) - i % width;
int y = (matrix.height() - 8) / 2; // center the text vertically
while (x + width - spacer >= 0 && letter >= 0)
{
if (letter < tape.length())
{
matrix.drawChar(x, y, tape[letter], HIGH, LOW, 1);
}
letter--;
x -= width;
}
matrix.write(); // Send bitmap to display
delay(wait);
}
} | true |
0cd589fd637960ddab58ee869c7ef17638401135 | C++ | kkislay20/SPOJ | /hubululu.cpp | UTF-8 | 206 | 2.59375 | 3 | [] | no_license | #include <iostream>
using namespace std;
int main() {
int t;
long m,n;
cin>>t;
while(t--)
{
cin>>m>>n;
if(n==0)
cout<<"Airborne wins.\n";
else
cout<<"Pagfloyd wins.\n";
}
return 0;
}
| true |
b394aa592e4374c6942b3ac11a5cde017c1c3baa | C++ | Ignacio-Mosconi/Green-Nacho-Engine | /Green-Nacho-Engine/Legacy/Shape.h | UTF-8 | 869 | 2.703125 | 3 | [] | no_license | #pragma once
#include "Legacy/Entity.h"
namespace gn
{
class Material;
namespace legacy
{
/*
It consists of the base class for many of the entities that will be actually drawn to the screen.
*/
class ENGINE_DECL_SPEC Shape : public Entity
{
protected:
Material* _material;
float* _vertexBufferData;
float* _colorBufferData;
unsigned int _vertexBufferID;
unsigned int _colorBufferID;
virtual bool create(unsigned int vertexCount, float* colorBufferData = NULL);
virtual float* generateVertexBufferData() const = 0;
virtual float* generateColorBufferData(float* colorBufferData, unsigned int vertexCount) const;
public:
Shape(Renderer* renderer, Material* material);
virtual ~Shape();
virtual void dispose();
virtual void draw() const = 0;
inline Material* getMaterial() const { return _material; }
};
}
} | true |
ed656b702af240ecad7fe8d829b701945bcf83af | C++ | boonkey/BattleShips | /BattleShips/BattleShips/ThreadManager.cpp | UTF-8 | 10,587 | 2.859375 | 3 | [] | no_license |
#include "Match.h"
struct ResultData {
int wins = 0;
int losses = 0;
int pointsFor = 0;
int pointsAgnst = 0;
double winRate = 0; //winrate will only be calcualted after 1 match atlist was played so no need to warry about divByZero errors //% = Wins/(Wins+Losses)
ResultData() {}; //default constructor, with all 0
ResultData(int win, int lose, int pFor, int pAg) : wins(win), losses(lose), pointsFor(pFor), pointsAgnst(pAg) {};
ResultData operator+(ResultData A) {
wins = wins + A.wins;
losses = losses + A.losses;
pointsFor = pointsFor + A.pointsFor;
pointsAgnst = pointsAgnst + A.pointsAgnst;
winRate = (wins + losses) > 0 ? (wins / double((wins + losses)))*100 : 0;
return *this;
}
};
//each ResultData object will have the resualt of a single match
//a mutex prevent multi writing confilcts
class TeamScoreLine {
public:
vector<ResultData> ScoreLine;
vector<bool> ScoreLineReady;
size_t numberOfMatchs;
TeamScoreLine() {
numberOfMatchs = 0;
ScoreLine.size();
ScoreLineReady.size();
}; //default empty constructor, used just for easy vecotr init
TeamScoreLine(size_t numberOfMatchs_) {
numberOfMatchs = numberOfMatchs_;
for (unsigned int i = 0; i < numberOfMatchs; i++) {
ScoreLine.push_back(ResultData());
ScoreLineReady.push_back(false);
}
}
void writeNewScore(ResultData score) {
unsigned int i = 0;
while(i<numberOfMatchs){
if (!ScoreLineReady[i]) { //if score in round i is false then thats the round we need to put score in now.
break;
}
i += 1;
}
ScoreLine.insert(ScoreLine.begin() + i,score);
ScoreLineReady.insert(ScoreLineReady.begin() + i, true);
}
ResultData readRoundScore(size_t roundNumber) {
if (canReadTeamRound(roundNumber)){ //writing the score happans before the ready, so if ready exists and is true then score is ready.
return ScoreLine[roundNumber];
}
//if cant read
return ResultData(); //to avoid this return , call canReadRound first to be sure you read valid data
}
bool canReadTeamRound(size_t roundNumber) {
if ((ScoreLineReady[roundNumber] != NULL) && (ScoreLineReady[roundNumber])) {
return true;
} else {
return false;
}
}
};
struct MatchData {
string pathA, pathB;
Board board;
MatchData(string pathA_, string pathB_, Board board_) : pathA(pathA_), pathB(pathB_), board(board_) {};
};
class ThreadManager {
private:
size_t numberOfThreads;
vector<string> algoPaths;
vector<Board> boards;
vector<thread> vec_threads;
size_t numDays;
map<string, ResultData> scoreBoardSum;
public:
atomic<int> currTask = 0;
vector<string> teams;
vector<MatchData> tasks;
mutex wrmutex;
map<string, TeamScoreLine> scoreBoard;
mutex scoreBoardMutex;
condition_variable scoreBoardCond;
size_t numOfTasks;
bool canReadRound(size_t roundNumber) {
wrmutex.lock();
bool result = true;
if (scoreBoard.empty())
result = false;
for (map<string, TeamScoreLine>::iterator it = scoreBoard.begin(); it != scoreBoard.end(); ++it) {
if (!it->second.canReadTeamRound(roundNumber)) {
result = false;
}
}
wrmutex.unlock();
return result;
}
// caller of this function must first call canReadRound to be sure the round resuals are ready
void mergeScores(size_t roundNumber){
for (map<string, TeamScoreLine>::iterator it = scoreBoard.begin(); it != scoreBoard.end(); ++it) {
string teamName = it->first;
scoreBoardSum[teamName] = (scoreBoardSum[teamName]) + (it->second.readRoundScore(roundNumber));
}
}
ThreadManager(vector<string> algoPaths_, vector<Board> boards_, int NumberOfThreads_) : algoPaths(algoPaths_), boards(boards_), numberOfThreads(NumberOfThreads_), vec_threads(numberOfThreads) {
vector<string> allteams = algoPaths;
numOfTasks = allteams.size() * (allteams.size() - 1) * boards.size();
if (allteams.size() % 2 != 0) {
allteams.push_back("dummy"); // If odd number of teams add a dummy
}
size_t numTeams = allteams.size(); //TODO CHECK HERE FOR FAIL
numDays = (numTeams - 1); // Days needed to complete tournament once
size_t halfSize = (numTeams) / 2;
for (vector<string>::iterator teamsItr = allteams.begin() + 1; teamsItr != allteams.end(); ++teamsItr) {
string name = *teamsItr;
teams.push_back(*teamsItr);
}
size_t teamsSize = teams.size();
vector<MatchData> tempTasks;
for (vector<Board>::iterator boardItr = boards.begin(); boardItr != boards.end(); ++boardItr) {
for (unsigned int day = 0; day < numDays; day++) {
int teamIdx = day % teamsSize;
if ((teams[teamIdx].compare("dummy") == 0) || (allteams[0].compare("dummy") == 0)) {}
else {
tasks.push_back(MatchData(allteams[0], teams[teamIdx], *boardItr));
tempTasks.push_back(MatchData(allteams[0], teams[teamIdx], *boardItr));
}
for (unsigned int idx = 1; idx < halfSize; idx++) {
size_t firstTeam = (day + idx) % teamsSize;
size_t secondTeam = (day + teamsSize - idx) % teamsSize;
if ((teams[firstTeam].compare("dummy") == 0) || (teams[secondTeam].compare("dummy") == 0)) {
}
else {
tempTasks.push_back(MatchData(teams[firstTeam], teams[secondTeam], *boardItr));
tasks.push_back(MatchData(teams[firstTeam], teams[secondTeam], *boardItr));
}
}
}
}
//now make the switched sides:
for (vector<MatchData>::iterator tasksItr = tempTasks.begin(); tasksItr != tempTasks.end(); ++tasksItr) {
auto item = *tasksItr;
tasks.push_back(MatchData(item.pathB, item.pathA, item.board));
}
//build the scoreboard
//cout << "init the scoreboards with " << algoPaths.size() << " teams:" << endl;
for (unsigned int j = 0; j < algoPaths.size(); j++) {
scoreBoard.insert(pair<string, TeamScoreLine>(algoPaths[j], TeamScoreLine(numOfTasks)));
scoreBoardSum.insert(pair<string, ResultData>(algoPaths[j], ResultData()));
}
//cout << "Done , have " << tasks.size() << " tasks \n";
}
void printTeam(int place, string teamName) {
if (scoreBoardSum[teamName].winRate - int(scoreBoardSum[teamName].winRate) == 0) {
string s = std::to_string(int(scoreBoardSum[teamName].winRate));
printf("%d.\t%50s %8d %8d \t %-5s %8d \t%8d\n", place, teamName.substr(teamName.find_last_of('\\') + 1).c_str(), scoreBoardSum[teamName].wins, scoreBoardSum[teamName].losses, s.c_str(), scoreBoardSum[teamName].pointsFor, scoreBoardSum[teamName].pointsAgnst);
}
else {
char* str11 = "%.2f";
char str[100];
sprintf_s(str, str11, scoreBoardSum[teamName].winRate);
printf("%d.\t%50s %8d %8d \t %-5s %8d \t%8d\n", place, teamName.substr(teamName.find_last_of('\\') + 1).c_str(), scoreBoardSum[teamName].wins, scoreBoardSum[teamName].losses, str, scoreBoardSum[teamName].pointsFor, scoreBoardSum[teamName].pointsAgnst);
}
}
void runThreads() {
int id = 1;
//run threads
for (auto & t : vec_threads) {
t = thread(&ThreadManager::ThreadTaskRunning, this, id);
++id;
}
size_t numberOfRounds = 2* (algoPaths.size() - 1) * boards.size();
//manage the scoreboard
size_t waitngForRound = 0;
while (waitngForRound < numberOfRounds) {
if ( canReadRound(waitngForRound) ){ //round <waitngForRound> is done and we can read/print resualts
mergeScores(waitngForRound); //first marge the scores to the sum board
vector<pair<double, string>> sortingByWinRate; //create new map to sort the table by winRate
for (std::map<string, ResultData>::iterator it = scoreBoardSum.begin(); it != scoreBoardSum.end(); ++it) {
sortingByWinRate.push_back(pair<double, string>(it->second.winRate, it->first));
}
sort(sortingByWinRate.begin(), sortingByWinRate.end(), [](auto &left, auto &right) {
return left.first > right.first;
});
cout << "Round " << waitngForRound + 1 << "/" << numberOfRounds << endl;
printf("#\t%50s\tWins\tLosses\t %%\t Pts For Pts Against\n", "Team Name");
for (unsigned int p = 0; p < sortingByWinRate.size(); p++) {
printTeam(p + 1, sortingByWinRate[p].second);
}
waitngForRound += 1;
}
}
//wait for all to end
for (auto & t : vec_threads) {
t.join();
}
}
~ThreadManager() {};
void ThreadTaskRunning(int id) {
while (true) {
unsigned int taskToRun = atomic_fetch_add(&currTask, 1);
if (taskToRun >= numOfTasks) {
return;
}
auto coming_match = tasks[taskToRun];
pair<int, int> gameScore = run_thread_match(coming_match.pathA, coming_match.pathB, coming_match.board);
//set the ResultData
ResultData AResultData;
ResultData BResultData;
if (gameScore.first > gameScore.second) { //A won
AResultData = ResultData(1, 0, gameScore.first, gameScore.second);
BResultData = ResultData(0, 1, gameScore.second, gameScore.first);
} else if (gameScore.first < gameScore.second) { //B won
AResultData = ResultData(0, 1, gameScore.first, gameScore.second);
BResultData = ResultData(1, 0, gameScore.second, gameScore.first);
} else { //tie score - not sure how a game ends with tie but forum commented about this
AResultData = ResultData(0, 0, gameScore.first, gameScore.second);
BResultData = ResultData(0, 0, gameScore.second, gameScore.first);
}
wrmutex.lock();
scoreBoard[coming_match.pathA].writeNewScore(AResultData); //write players A score to the board
scoreBoard[coming_match.pathB].writeNewScore(BResultData); //write players B score to the board
wrmutex.unlock();
// done with this game , Ready to pick next task
}
cout << "thread " << id << " finished\n";
}
pair<int, int> run_thread_match(string playerAPath, string playerBPath, Board board) {
Match A(playerAPath, playerBPath, board);
auto score = A.runMatch();
return score;
}
};
int main(int argc, char* argv[]) {
string path = ".";
int num_of_threads = 4;
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--threads")) {
if (argc > i + 1) {
num_of_threads = atoi(argv[i + 1]);
i++;
}
else
return ERR_WRONG_NUM_OF_ARGS;
}
else
path = argv[i];
}
cout << path << endl;
vector<string> algoPaths_ = get_all_files_names_within_folder(path, "dll");
if (algoPaths_.size() < 2) {
for (auto &a : algoPaths_)
cout << a << endl;
return ERR_NUM_OF_ALGO;
}
vector<string> boardPaths_ = get_all_files_names_within_folder(path, "sboard");
vector<Board> boards;
for (auto &b : boardPaths_) {
boards.push_back(Board(b));
}
if (boards.size() < 1)
return ERR_NUM_OF_BOARDS;
printf("Number of legal players: %zu\nNumber of legal boards : %zu\n", algoPaths_.size(), boards.size());
ThreadManager tm( algoPaths_, boards ,num_of_threads);
tm.runThreads();
system("pause");
}
| true |
c3343013bb70dff9eb4615fd389d7052d1ccf23e | C++ | michalsobczyk/Portfolio | /C++/Michal_Sobczyk_Projekt/complexShape.cpp | UTF-8 | 307 | 3.078125 | 3 | [] | no_license | #include "complexShape.h"
ComplexShape::ComplexShape(Display* w) : Shape(w) {}
bool ComplexShape::add(Shape* o) {
if (shapes.size() == 5) {
return false;
}
shapes.push_back(o);
return true;
}
void ComplexShape::draw() {
for (unsigned int i = 0; i < shapes.size(); ++i) {
shapes[i]->draw();
}
}
| true |
0d9f9e14a01c39dd1f6b06b2d63d01a2da0c16e1 | C++ | daniel321/repoFacu | /tp/ConcuCalecita/common/memCompartida/MemCmpRaw.h | UTF-8 | 1,114 | 3.015625 | 3 | [] | no_license | #ifndef MEMCMPRAW_H_
#define MEMCMPRAW_H_
#include "../semaforos/Semaforo.h"
/**
* Clase que modela memoria compartida
* Nota importante, la clase funciona estilo smart pointer, si ningun proceso tiene referencia, se borra del OS
* Asi que tener cuidado con cosas del estilo crearla con un proceso y luego cerrar ese proceso
*/
class MemCmpRaw
{
private:
int shmId;
void* ptrDatos;
size_t tam;
int cantidadProcesosAdosados() const;
void crear ( const char* archivo,const char letra, const size_t tam );
void liberar ();
public:
MemCmpRaw ( const char*,const char letra, const size_t tam);
MemCmpRaw ( const MemCmpRaw& origen );
MemCmpRaw& operator= ( const MemCmpRaw& origen );
~MemCmpRaw();
/**
* Setea el valor del segmento de memoria a 0
*/
void reset();
/**
* Escribe sobre la mem compartida a partir del offset tam bytes de la data
*/
void escribir (const int offset, void * data, size_t tam);
/**
* Lee sobre la mem compartida a partir del offset tam bytes y los copia en dest.
*/
void leer (const int offset, void * dest, size_t tam) const;
};
#endif /* MEMCMPRAW_H_ */
| true |
e3e3d963c9ad6a76f5be643d04a4ccdc17d7f2c7 | C++ | omar-faruk01/Problem-Solving-Programming | /Lab 21/Lab 21.cpp | UTF-8 | 3,039 | 4.0625 | 4 | [] | no_license | //==========================================================
//
// Title: Matrix to Matrices!
// Course: CSC 1101
// Lab Number: 21
// Author: Omar Faruk
// Date: 12/1/2020
// Description:
// Creating an application taking two fixed Matrices and
// creating a 3rd matrix if columns in matrix 1 is identical to
// columns in matrix 2 by multiplying the two matrices.
//
//==========================================================
#include <cstdlib> // For several general-purpose functions
#include <fstream> // For file handling
#include <iomanip> // For formatted output
#include <iostream> // For cin, cout, and system
#include <string> // For string data type
using namespace std; // So "std::cout" may be abbreviated to "cout"
// Declare Constants
const int COLFMT1 = 6;
const int ROW_SIZE = 3, ROW_SIZE2 = 2;
const int COL_SIZE = 2, COL_SIZE2 = 3;
// Print 2D Array Functions for different sizes
void print2DArray1(string heading,
int arr[ROW_SIZE][COL_SIZE])
{
// Loop to print array numbers
cout << "\n" + heading << endl;
cout << endl;
for (int i = 0; i < ROW_SIZE; i++)
{
for (int j = 0; j < COL_SIZE; j++)
cout << setw(COLFMT1) << right << arr[i][j];
cout << endl;
}
}
void print2DArray2(string heading,
int arr[ROW_SIZE2][COL_SIZE2])
{
// Loop to print array numbers
cout << "\n" + heading << endl;
cout << endl;
for (int i = 0; i < ROW_SIZE2; i++)
{
for (int j = 0; j < COL_SIZE2; j++)
cout << setw(COLFMT1) << right << arr[i][j];
cout << endl;
}
}
void print2DArray3(string heading,
int arr[ROW_SIZE2][COL_SIZE])
{
// Loop to print array numbers
cout << "\n" + heading << endl;
cout << endl;
for (int i = 0; i < ROW_SIZE2; i++)
{
for (int j = 0; j < COL_SIZE; j++)
cout << setw(COLFMT1) << right << arr[i][j];
cout << endl;
}
}
int main()
{
// Declare constant
const int M = 2, N = 3, P = 3, Q = 2;
// Show application header
cout << "Welcome to Matrix to Matrices!" << endl;
cout << "--------------------------------" << endl << endl;
// Define Two Matrices
int arrMatrix1[M][N] =
{
{3, 4, 5},
{7, 8, 10}
};
int arrMatrix2[P][Q] =
{
{7, 8},
{2, 3},
{11, 12}
};
int arrMatrix3[2][2] =
{
{0, 0},
{0, 0},
};
// Multiply Matrices if matrix 1 and 2 value are same
if ( N != P)
{
cout << "\nNo columns and rows in corresponding matrix are the same" << endl;
}
else
{
for (int i = 0; i < M; i++)
{
for (int j = 0; j < Q; j++)
{
for (int k = 0; k < P; k++)
{
arrMatrix3[i][j] = arrMatrix3[i][j] + (arrMatrix1[i][k] * arrMatrix2[k][j]);
}
}
}
}
// Print Matrix Arrays
print2DArray2("The First Matrix (size: 2X3):", arrMatrix1);
print2DArray1("The Second Matrix (size: 3X2):", arrMatrix2);
print2DArray3("The Product of two matrices is :", arrMatrix3);
// Show application close
cout << "\nEnd of Matrix to Matrices!" << endl;
}
| true |
9a972f70edf5fe75d159153e7f3e6f3a8c27c24c | C++ | ekg/protobufstream | /test.cpp | UTF-8 | 913 | 2.671875 | 3 | [
"MIT"
] | permissive | #include <iostream>
#include "cpp/test.pb.h"
#include "stream.hpp"
using namespace google::protobuf;
using namespace test;
int main(void) {
Note note1;
note1.add_idea("a fun way to idea");
note1.add_idea("could this really be serialized");
Note note2;
note2.add_idea("yheaw");
note2.set_number(42);
std::ofstream pbsout("test.pbs");
pbs::Stream<Note> out(&pbsout);
out.write(note1);
out.write(note2);
out.close();
pbsout.close();
std::ifstream pbsin("test.pbs");
pbs::Stream<Note> in(&pbsin);
in.for_each([](Note& note) {
std::cout << "-------------------" << std::endl;
if (note.has_number()) {
std::cout << note.number() << std::endl;
}
for (int i = 0; i < note.idea_size(); ++i) {
std::cout << note.idea(i) << std::endl;
}
});
return 0;
}
| true |
efb0f356787c10ca963b23c212504baaa9119b61 | C++ | mcheese/cheesebase | /src/storage.cc | UTF-8 | 1,570 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | // Licensed under the Apache License 2.0 (see LICENSE file).
#include "storage.h"
namespace cheesebase {
Storage::Storage(const std::string& filename, OpenMode mode)
: cache_(filename, mode, k_default_cache_size / k_page_size) {}
PageRef<PageReadView> Storage::loadPage(PageNr page_nr) {
return cache_.readPage(page_nr);
}
namespace {
template <typename S>
void writeToSpan(const decltype(Write::data)& data, S target) {
if (data.type() == typeid(uint64_t)) {
Expects(ssizeof<uint64_t>() <= target.size());
bytesAsType<uint64_t>(target) = boost::get<uint64_t>(data);
} else {
auto& span = boost::get<gsl::span<const Byte>>(data);
Expects(span.size() <= target.size());
std::copy(span.begin(), span.end(), target.begin());
}
}
}
void Storage::storeWrite(Write write) {
auto p = cache_.writePage(write.addr.pageNr());
writeToSpan(write.data, p->subspan(write.addr.pageOffset()));
}
void Storage::storeWrite(std::vector<Write> transaction) {
// TODO: write to journal here
// sort the writes to minimize cache requests
std::sort(transaction.begin(), transaction.end(),
[](const Write& l, const Write& r) {
return l.addr.value < r.addr.value;
});
auto it = transaction.begin();
while (it != transaction.end()) {
auto nr = it->addr.pageNr();
auto ref = cache_.writePage(nr);
do {
writeToSpan(it->data, ref->subspan(it->addr.pageOffset()));
++it;
} while (it != transaction.end() && nr.value == it->addr.pageNr().value);
}
}
} // namespace cheesebase
| true |
a407baf4fb06796672a8347bf74cac5181d66e4e | C++ | saidul-islam98/Codeforces-Codes | /cAPS lOCK.cpp | UTF-8 | 1,439 | 2.921875 | 3 | [] | no_license | #include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
bool flag=false;
if(s.length()==1 && (s[0]>='A' && s[0]<='Z')){
s[0]=tolower(s[0]);
cout<<s;
}
else if(s.length()==1 && (s[0]>='a' && s[0]<='z')){
s[0]=toupper(s[0]);
cout<<s;
}
else{
if(s[0]>='A' && s[0]<='Z'){
for(int i=1;i<s.length();i++){
if(s[i]>='A' && s[i]<='Z'){
flag=true;
}
else{
flag=false;
break;
}
}
if(flag==false){
cout<<s;
}
else{
for(int i=0;i<s.length();i++){
s[i]=tolower(s[i]);
}
cout<<s;
}
}
else if(s[0]>='a' && s[0]<='z'){
for(int i=1;i<s.length();i++){
if(s[i]>='A' && s[i]<='Z'){
flag=true;
}
else{
flag=false;
break;
}
}
if(flag==false){
cout<<s;
}
else{
s[0]=toupper(s[0]);
for(int i=1;i<s.length();i++){
s[i]=tolower(s[i]);
}
cout<<s;
}
}
}
return 0;
}
| true |
0f85eaabf7feccd6c75518018ae73c8dfdcafc80 | C++ | sandeepkalra/utilities | /Phonebook.h | UTF-8 | 2,731 | 3.28125 | 3 | [
"MIT"
] | permissive | /* ----------------------------------------
* Author: Sandeep Kalra
* License: MIT License.
* Copyright(c) 2013 Sandeep.Kalra@gmail.com
*/
#ifndef __PHONEBOOK_H_
#define __PHONEBOOK_H_
#include <iostream>
#include <map>
#include <string>
using namespace std;
// ref: http://www.gotw.ca/gotw/029.htm
struct ci_char_traits : public char_traits<char>
// just inherit all the other functions
// that we don't need to override
{
static bool eq(char c1, char c2)
{
return toupper(c1) == toupper(c2);
}
static bool ne(char c1, char c2)
{
return toupper(c1) != toupper(c2);
}
static bool lt(char c1, char c2)
{
return toupper(c1) < toupper(c2);
}
static int compare(const char* s1,
const char* s2,
size_t n) {
return _memicmp(s1, s2, n); // Linux: memicmp ; Windows: _memicmp
}
static const char*
find(const char* s, int n, char a) {
while (n-- > 0 && toupper(*s) != toupper(a)) {
++s;
}
return s;
}
};
// this class does case-insensitive comparision
typedef basic_string <char, ci_char_traits> String;
//Note: This class is not thread-safe!
class CPhonebook {
map<String, String> entry;
bool overwrite_on_insert = false;
bool size_unlimited = false;
int max_sz = 100;
CPhonebook() = default;
public:
~CPhonebook() { entry.erase(begin(entry), end(entry)); }
CPhonebook(const CPhonebook&) = delete; // no copy allowed;
CPhonebook(CPhonebook&&) = delete; // no move allowed;
static CPhonebook& GetInstance() {
static CPhonebook instance;
return instance;
}
void SetPolicies(bool v_overwrite_on_insert = false, bool v_size_unlimited = false, int v_max_sz=100) {
// This function must be called at the start of usage of the CPhonebook, else may result in errors.
overwrite_on_insert = v_overwrite_on_insert;
size_unlimited = v_size_unlimited;
if (!size_unlimited) max_sz = v_max_sz;
}
bool Insert (const String &name, const String &phone_or_uri) {
auto i = entry.find(name);
if (overwrite_on_insert && i != entry.end() /* valid entry found */) {
i->second = phone_or_uri;
return true;
}
else if (i == entry.end()) {
if (!size_unlimited && entry.size() >= max_sz) return false; //full
entry.insert(pair<String, String>(name, phone_or_uri));
return true;
}
else return false;
}
bool Delete (const String &name) {
auto i = entry.find(name);
if (i == entry.end()) return false;
else
entry.erase(i);
return true;
}
bool lkup(bool by_name, const String &search, String &answer) {
for (auto i = entry.begin(); i != entry.end(); ++i)
{
if (by_name && i->first == search) { answer = i->second; return true; }
else if (!by_name && i->second == search) { answer = i->first; return true; }
}
return false;
}
};
#endif
| true |
c7f79932e7bc716bfc9a3eccc097ed5c9f2f2f1e | C++ | X3N0-Life-Form/Traveling-Salesman-Problem | /code/run/interval/StrategicMemory.h | UTF-8 | 899 | 2.90625 | 3 | [
"MIT"
] | permissive | /*
* File: StrategicMemory.h
* Author: etudiant
*
* Created on 18 juin 2014, 11:50
*/
#ifndef STRATEGICMEMORY_H
#define STRATEGICMEMORY_H
#include <list>
#include "Action.h"
/**
* Records things that happen in Strategy.
*/
class StrategicMemory {
private:
std::list<Action*> actionsConsidered;
public:
// Constructors / Destructor
StrategicMemory();
StrategicMemory(const StrategicMemory& orig);
virtual ~StrategicMemory();
// Getters / Setters / Adders
void addAction(Action* action);
// Advanced Getters
/**
* Calculates & returns the ratio between improving actions & degrading
* actions.
* @return #improving Neighbors / total # of Neighbors
*/
int getNumberOfGoodActions();
int getNumberOfBadActions();
double getGoodToBadRatio();
// Other Methods
void flushMemory();
};
#endif /* STRATEGICMEMORY_H */
| true |
6e0c627aacf54b35f8d504fcb1c3aabdc34fa03d | C++ | jameshi16/weather-alert | /weatherInfo/weatherStation.hpp | UTF-8 | 1,967 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | #ifndef WEATHERSTATION_H
#define WEATHERSTATION_H
#include <string>
#include "weatherInfo.hpp"
#include "../json.hpp"
#include "../contacter.hpp"
#define OPENWEATHERMAP_URL L"api.openweathermap.org" //open weather map's URL
#define OPENWEATHERMAP_VERSION L"2.5" //the version used for open weather map
/* Weather Station is a structure passed down to different window classes, which can be used to tell the weather. */
/* Weather Station caches the values that are used to call requestData(). The cache can be tempered with through set or getAPIKey, set or getLocation */
/** This is an extremely specialized struct and is made for this particular use case only. **/
struct WeatherStation {
WeatherStation()=default;
~WeatherStation()=default;
/** Gets/Sets for both APIKey and Location **/
void setAPIKey(std::wstring APIKey) {m_APIKey = APIKey;}
void setLocation(std::wstring Location) {m_Location = Location;}
void setAPIKey(std::string APIKey) {setAPIKey(std::wstring(APIKey.begin(), APIKey.end()));}
void setLocation(std::string Location) {setLocation(std::wstring(Location.begin(), Location.end()));}
std::wstring getAPIKey() const {return m_APIKey;}
std::wstring getLocation() const {return m_Location;}
/** The requestData function. Takes in a std::string, and converts it to std::wstring, before calling the std::wstring version of the function. **/
bool requestData(std::string APIKey, std::string Location);
bool requestData(std::wstring APIKey, std::wstring Location); //this function will request data, and store it in the underlying weather info.
bool requestData() noexcept(false); //requests data based on stored values.
WeatherInfo getWeatherInfo(); //gets a copy of the weatherinfo.
private:
/* Objects used to connect and store data acquired from the server */
Contacter contact;
JsonDecoder jd;
WeatherInfo wi;
std::wstring m_APIKey, m_Location;
};
#endif | true |
c20a61e868cabff9d3a5baac73ad915606ca4b07 | C++ | gts2030/cpps | /week4/problem7.cpp | UTF-8 | 808 | 4 | 4 | [] | no_license | #include <stack>
class MyQueue {
public:
std::stack<int> front;
std::stack<int> back;
/** Initialize your data structure here. */
MyQueue() {
}
/** Push element x to the back of queue. */
void push(int x) {
back.push(x);
}
/** Removes the element from in front of queue and returns that element. */
int pop() {
if (front.size() == 0) {
while (back.size()) {
front.push(back.top());
back.pop();
}
}
int result = front.top();
front.pop();
return result;
}
/** Get the front element. */
int peek() {
if (front.size() == 0) {
while (back.size()) {
front.push(back.top());
back.pop();
}
}
return front.top();
}
/** Returns whether the queue is empty. */
bool empty() {
if (front.size() + back.size() > 0) return false;
else return true;
}
}; | true |
f2a66c8aeea15310067c7077810c61b9a2a69003 | C++ | ayyse/ComputerGraphics | /WireCar/WireCar/main.cpp | IBM852 | 6,581 | 2.5625 | 3 | [
"MIT"
] | permissive | #include <iostream>
#include <GL/glut.h>
#include <GL/GL.h>
#include <GL/GLU.h>
#include <math.h>
#define PI 3.141592f
#define LEFT 1
#define RIGHT 2
float theta = PI / 2.0f - 0.4f;
float phi = 0.0f;
float distance = 40.0f;
float oldX, oldY;
int motionState;
float degree = 0;
int turn = 0;
GLfloat angle = 45.0f;
int delay = 1;
void timer(int value)
{
glutPostRedisplay();
glutTimerFunc(delay, timer, 0);
}
void init() {
glClearColor(0, 0, 0, 1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-500, 500, -500, 500, -500, 500);
glMatrixMode(GL_MODELVIEW);
}
void front()
{
glColor3f(1, 1, 1);
glPushMatrix();
glTranslatef(-450, -250, 0); // front face position
glScalef(0.01, 0.3, 0.85);
glutWireCube(600);
glPopMatrix();
}
void back()
{
glColor3f(1, 1, 1);
glPushMatrix();
glTranslatef(450, -250, 0); // back face position
glScalef(0.01, 0.3, 0.85); //
glutWireCube(600);
glPopMatrix();
}
void right()
{
glColor3f(1, 1, 1);
glPushMatrix();
glTranslatef(0, -250, -250); // right face position
glScalef(1.5, 0.3, 0.01);
glutWireCube(600);
glPopMatrix();
}
void left()
{
glColor3f(1, 1, 1);
glPushMatrix();
glTranslatef(0, -250, 250); //left face position
glScalef(1.5, 0.3, 0.01);
glutWireCube(600);
glPopMatrix();
}
void wheel(int x, int y, int z)
{
float th;
glColor3f(1, 1, 1);
int j;
for (j = 0; j < 10; j++)
{
glBegin(GL_LINES);
for (int i = 0; i < 360; i++) {
th = i * 3.142 / 180;
glVertex3f(x + 100 * cos(th), y + 100 * sin(th), z + j);
}
glEnd();
}
}
// line between two wheel
void wheelLine(int x, int y, int z)
{
glColor3f(1, 1, 1);
glBegin(GL_LINES);
// link between right and left wheels
glVertex3f(x, y, z);
glVertex3f(x, y, -z);
glEnd();
}
//steering wheel line
void line(int x, int y, int z)
{
glColor3f(1, 1, 1);
glPushMatrix();
glTranslatef(-420, -50, 0);
glRotatef(-5, 0, 0, 1);
glScalef(0.0, 1.0, 0.0);
glutWireCube(600);
glPopMatrix();
}
void steering(int x, int y, int z)
{
float th;
glColor3f(1, 1, 1);
int j;
for (j = 0; j < 10; j++)
{
glBegin(GL_LINES);
for (int i = 0; i < 360; i++) {
th = i * 3.142 / 180;
glVertex3f(x + 100 * cos(th), y + 100 * sin(th), z + j);
}
glEnd();
}
}
void streeringLine()
{
glColor3f(1, 1, 1);
// horizontal
glPushMatrix();
glTranslatef(-400, 250, 0);
glRotatef(90 + turn, 0, 1, 0);
glRotatef(90, 1, 0, 0);
glScalef(0.0, 1.0, 0.0);
glutWireCube(200); // steering diameter
glPopMatrix();
// vertical
glPushMatrix();
glTranslatef(-400, 250, 0);
glRotatef(90 + turn, 0, 1, 0);
glRotatef(90, 1, 0, 0);
glScalef(1.0, 0.0, 0.0);
glutWireCube(200);
glPopMatrix();
}
void frontLines()
{
glColor3f(1, 1, 1);
// front left wheel
glPushMatrix();
glTranslatef(-450, -350, 400); // center of front left wheel
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glScalef(1.0, 0.0, 0.0);
glutWireCube(200); // wheel diameter
glPopMatrix();
// front right wheel
glPushMatrix();
glTranslatef(-450, -350, -400); // center of front right wheel
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glScalef(1.0, 0.0, 0.0);
glutWireCube(200);
glPopMatrix();
angle += 1; // rotation speed
}
void backLines()
{
glColor3f(1, 1, 1);
// back left wheel
glPushMatrix();
glTranslatef(450, -350, 400); // center of back left wheel
glTranslatef(0.5f, 0.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glScalef(1.0, 0.0, 0.0);
glutWireCube(200);//ap
glPopMatrix();
// back right wheel
glPushMatrix();
glTranslatef(450, -350, -400); // center of back right wheel
glTranslatef(0.5f, 0.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glScalef(1.0, 0.0, 0.0);
glutWireCube(200);
glPopMatrix();
angle += 0.1;
}
void car()
{
// defined front, back, right and left functions in car function
front();
back();
left();
right();
// rotating front wheels
glPushMatrix();
glRotatef(degree, 0, 1, 0);
wheel(-450, -350, 400); // left front wheel
wheel(-450, -350, -400); // right front wheel
wheelLine(-460, -350, 400); // front line between two wheel
frontLines(); //front wheel lines
glPopMatrix();
wheel(450, -350, 400); // left back wheel
wheel(450, -350, -400); // right back wheel
wheelLine(460, -350, 400); // back line between two wheel
line(-450, 350, 0); // steering tall line
backLines(); // back wheel lines
glPushMatrix();
glRotatef(90, 0, 1, 0);
glRotatef(90, 1, 0, 0);
steering(0, -400, -250);
glPopMatrix();
streeringLine();
}
void mouse(int button, int state, int x, int y)
{
oldX = (float)x;
oldY = (float)y;
if (button == GLUT_LEFT_BUTTON) {
if (state == GLUT_DOWN) {
motionState = LEFT;
}
}
else if (button == GLUT_RIGHT_BUTTON) {
if (state == GLUT_DOWN) {
motionState = RIGHT;
}
}
}
void mouseMotion(int x, int y)
{
float deltaX = x - oldX;
float deltaY = y - oldY;
if (motionState == LEFT)
{
theta -= 0.01f * deltaY;
if (theta < 0.01f) theta = 0.01f;
else if (theta > PI / 2.0f - 0.01f) theta = PI / 2.0f - 0.01f;
phi += 0.01f * deltaX;
if (phi < 0) phi += 2 * PI;
else if (phi > 2 * PI) phi -= 2 * PI;
}
else if (motionState == RIGHT)
{
distance += 0.01f * deltaY;
}
oldX = (float)x;
oldY = (float)y;
glutPostRedisplay();
}
void turnRight(void) //s
{
glLoadIdentity();
degree += 0.05;
turn += 1;
}
void turnLeft(void) //a
{
glLoadIdentity();
degree -= 0.05;
turn -= 1;
}
void Keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'a': turnRight(); break;
case 's':turnLeft(); break;
}
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
float x = distance * sin(theta) * cos(phi);
float y = distance * cos(theta);
float z = distance * sin(theta) * sin(phi);
gluLookAt(x, y, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
// reduced the size of the car
glScalef(0.4, 0.4, 0.4);
car();
glutSwapBuffers();
glutPostRedisplay();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(0, 0);
glutInitWindowSize(500, 500);
glutCreateWindow("Wire Car");
init();
glutDisplayFunc(display);
glutMotionFunc(mouseMotion);
glutMouseFunc(mouse);
glutKeyboardFunc(Keyboard);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
} | true |
587de132f499d2f95004485fd04e18c3724cb323 | C++ | GhostsOfHiroshima/Glow-ESP | /External Heckle/ProcMem.h | UTF-8 | 3,272 | 2.84375 | 3 | [] | no_license |
#ifndef PROCMEM_H //If Not Defined
#define PROCMEM_H //Define Now
#define WIN32_LEAN_AND_MEAN //Excludes Headers We Wont Use (Increase Compile Time)
using namespace std;
class ProcMem {
protected:
//STORAGE
HANDLE hProcess;
DWORD dwPID, dwProtection, dwCaveAddress;
//MISC
BOOL bPOn, bIOn, bProt;
public:
//MISC FUNCTIONS
ProcMem( );
~ProcMem( );
int chSizeOfArray( char* chArray ); //Return Size Of External Char Array
int iSizeOfArray( int* iArray ); //Return Size Of External Int Array
bool iFind( int* iAry, int iVal ); //Return Boolean Value To Find A Value Inside An Int Array
#pragma region TEMPLATE MEMORY FUNCTIONS
//REMOVE READ/WRITE PROTECTION
template <class cData>
void Protection( DWORD dwAddress )
{
if ( !bProt )
VirtualProtectEx( hProcess, (LPVOID )dwAddress, sizeof( cData ), PAGE_EXECUTE_READWRITE, &dwProtection ); //Remove Read/Write Protection By Giving It New Permissions
else
VirtualProtectEx( hProcess, (LPVOID )dwAddress, sizeof( cData ), dwProtection, &dwProtection ); //Restore The Old Permissions After You Have Red The dwAddress
bProt = !bProt;
}
//READ MEMORY
template <class cData>
cData Read( DWORD dwAddress )
{
cData cRead; //Generic Variable To Store Data
ReadProcessMemory( hProcess, (LPVOID )dwAddress, &cRead, sizeof( cData ), NULL ); //Win API - Reads Data At Specified Location
return cRead; //Returns Value At Specified dwAddress
}
//READ MEMORY - Pointer
template <class cData>
cData Read( DWORD dwAddress, char* Offset, BOOL Type )
{
//Variables
int iSize = iSizeOfArray( Offset ) - 1; //Size Of *Array Of Offsets
dwAddress = Read<DWORD>( dwAddress ); //HEX VAL
//Loop Through Each Offset & Store Hex Value (Address)
for ( int i = 0; i < iSize; i++ )
dwAddress = Read<DWORD>( dwAddress + Offset[ i ] );
if ( !Type )
return dwAddress + Offset[ iSize ]; //FALSE - Return Address
else
return Read<cData>( dwAddress + Offset[ iSize ] ); //TRUE - Return Value
}
// WRITE MEMORY
template <class cData>
void Write( DWORD dwAddress, cData Value )
{
WriteProcessMemory( hProcess, (LPVOID )dwAddress, &Value, sizeof( cData ), NULL );
}
// WRITE MEMORY - Pointer
template <class cData>
void Write( DWORD dwAddress, char* Offset, cData Value )
{
Write<cData>( Read<cData>( dwAddress, Offset, false ), Value );
}
// Base read
template <typename TYPE>
TYPE RPM( LPVOID lpBaseAddress, SIZE_T nSize )
{
TYPE data = TYPE( );
ReadProcessMemory( hProcess, lpBaseAddress, &data, nSize, NULL );
return data;
}
// Base write
void WPM( LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize )
{
WriteProcessMemory( hProcess, lpBaseAddress, lpBuffer, nSize, NULL );
}
// MEMORY FUNCTION PROTOTYPES
virtual bool Process( char* ProcessName ); // Return Handle To The Process
virtual void Patch( DWORD dwAddress, char* chPatch_Bts, char* chDefault_Bts ); // Write Bytes To Specified Address
virtual void Inject( DWORD dwAddress, char* chInj_Bts, char* chDef_Bts, BOOL Type ); // Jump To A Codecave And Write Memory
virtual DWORD AOB_Scan( DWORD dwAddress, DWORD dwEnd, char* chPattern ); // Find A Byte Pattern
virtual bool Module( LPSTR ModuleName, DWORD& output ); // Return Module Base Address
#pragma endregion
};
#endif
| true |
2e64f3e27819d11430327788c91426a1d7ee4e7b | C++ | wjhan1993/hw11 | /hw11/array/test_array.cpp | UTF-8 | 1,022 | 3.296875 | 3 | [] | no_license | #include "array.h"
#include <cstdio>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int origin[10] = {-10,-8,-6,-4,-2,0,2,4,6,8};
Array arr(8,origin);
Array rtoo(5,1);
for(int i = 0; i < rtoo.size(); i++)
rtoo[i] = i * 2;
cout << "arr = " << arr << endl;
cout << "rtoo = " << rtoo << endl;
Array newArray;
newArray = rtoo;
cout << "newArray = " << newArray << endl;
// append three integers to newArray
newArray.append(1);
newArray.append(10);
newArray.append(15);
cout << "newArray size = " << newArray.size() << " and newArray = "\
<< newArray;
// copy constructor
Array newArraytoo(newArray);
newArraytoo[0] = -100;
cout << "newArraytoo = " << newArraytoo;
// overload of +
newArraytoo = newArray + arr;
cout << "After adding, newArraytoo = newArray + arr :" << newArray << endl;
// index out-bound
for(int i = -2; i < newArray.size(); i++){
printf(" arr[%d] = %d\n", i, arr[i]);
}
return(0);
}
| true |
c5cb627990ec1bcbc540ec9ab00812600b2bcbe5 | C++ | naveen-kummar/cruise_control_system | /2_source_code/cruise_control/ros/header/topic_info.h | UTF-8 | 1,382 | 3.15625 | 3 | [] | no_license | /*
* @file topic_info.h
* @brief This file define class for storing topic data information
*
* Declares and define functionality to retrive the topic information
* which is assigned while creating object of this class
*/
#ifndef CRUISE_CONTROL_ROS_HEADER_TOPIC_INFO_H
#define CRUISE_CONTROL_ROS_HEADER_TOPIC_INFO_H
#include <string>
#include <chrono>
namespace cruise_control
{
using namespace std::chrono_literals;
constexpr int kTopicBufferLength{10};
constexpr char kTopicAcceleration[]{"acceleration"};
constexpr char kTopicVehicleSpeed[]{"vehicle_speed"};
constexpr std::chrono::milliseconds kTopicPeriod{500ms};
constexpr std::chrono::seconds KThreadExecutionFrequency{1s};
class TopicInfo
{
public:
TopicInfo(const std::string name, const std::size_t size) :
topic_name_{ name }, queue_size_{ size }
{
}
~TopicInfo() = default;
TopicInfo(const TopicInfo&) = default;
TopicInfo& operator=(const TopicInfo&) = default;
TopicInfo(const TopicInfo&&) = delete;
TopicInfo& operator=(const TopicInfo&&) = delete;
inline std::string GetTopicName() const
{
return topic_name_;
}
inline std::size_t GetQueueSize() const
{
return queue_size_;
}
private:
std::string topic_name_;
std::size_t queue_size_;
};
} //namespace cruise_control
#endif // CRUISE_CONTROL_ROS_HEADER_TOPIC_INFO_H
| true |
12530ccbf2ec3662301c5535c1e8af144dba58aa | C++ | alecrisan/Quiz | /exception.h | UTF-8 | 331 | 2.859375 | 3 | [] | no_license | #ifndef EXCEPTION_H
#define EXCEPTION_H
#include <exception>
#include <string>
using namespace std;
class Exception: public exception
{
private:
string message;
public:
Exception(const string &mess): message(mess) {}
virtual const char* what()
{
return message.c_str();
}
};
#endif // EXCEPTION_H
| true |
c8cfed7cb9739b05e2cfddae7e9b519aa68b3259 | C++ | JaiVig/2D-Game-Engine | /GameProject1/MainGame.cpp | UTF-8 | 8,583 | 2.65625 | 3 | [] | no_license | #include "MainGame.h"
#include <SDL.h>
#include<iostream>
#include<Crusty/Crusty.h>
#include<Crusty/Error.h>
#include"Zombie.h"
#include<ctime>
#include<random>
const float HUMANSPEED = 1.0f;
const float ZOMBIESPEED = 3.0f;
const float PLAYERSPEED = 8.0f;
const float PI = 3.142857;
MainGame::MainGame() :_screenWidth(1920), _screenHeight(1080), gamestate(GameState::PLAY), _player(nullptr),_numHumansKilled(0),_numZombiesKilled(0)
{
// Empty
}
MainGame::~MainGame()
{
for (int i = 0; i < _levels.size(); i++)
{
delete _levels[i];
}
}
void MainGame::run() {
initSystems();
initLevel();
gameLoop();
}
void MainGame::initSystems() {
Crusty::init();
_window.create("Zombie Game", _screenWidth, _screenHeight, 0);
glClearColor(0.6f, 0.6f, 0.6f, 1.0f);
initShaders();
_camera.init(_screenWidth, _screenHeight);
_agentSpriteBatch.init();
}
void MainGame::initShaders() {
// Compile our color shader
_textureProgram.compileShaders("Shaders/textureShading.vert", "Shaders/textureShading.frag");
_textureProgram.addAttr("vertexPosition");
_textureProgram.addAttr("vertexColor");
_textureProgram.addAttr("vertexUV");
_textureProgram.linkShaders();
}
void MainGame::initLevel() {
_levels.push_back(new Level("Levels/level1.txt"));
_currentLevel = 0;
_player = new Player();
_player->init(PLAYERSPEED, _levels[_currentLevel]->getStartPlayerPos(), &_inputManager,&_camera,&_bullets);
_humans.push_back(_player);
std::mt19937 randomEngine;
randomEngine.seed(time(nullptr));
std::uniform_int_distribution<int>randX(2, _levels[_currentLevel]->getWidth() -2);
std::uniform_int_distribution<int>randY(2, _levels[_currentLevel]->getHeight() - 2);
//add all random humans
for (int i = 0; i < _levels[_currentLevel]->getNumHumans(); i++)
{
_humans.push_back(new Human);
glm::vec2 pos(randX(randomEngine) * TILE_WIDTH, randY(randomEngine) * TILE_WIDTH);
_humans.back()->init(HUMANSPEED,pos);
}
//add zombies
const std::vector<glm::vec2>& zombiePos = _levels[_currentLevel]->getStartZombiePos();
for (int i = 0; i < zombiePos.size(); i++)
{
_zombies.push_back(new Zombie);
_zombies.back()->init(ZOMBIESPEED, zombiePos[i]);
}
//setup Player Gun
const float BULLETSPEED = 20.0f;
_player->addGun(new Gun("Magnum", 20, 1, 0.01, BULLETSPEED,70.0f));
_player->addGun(new Gun("Shotgun",30, 12, 0.4f, BULLETSPEED, 20.0f));
_player->addGun(new Gun("MachineGun", 2, 1,0.07, BULLETSPEED, 18.0f));
}
void MainGame::gameLoop() {
while (gamestate == GameState::PLAY)
{
checkVictory();
_inputManager.update();
processInput();
updateAgents();
updateBullets();
_camera.setPosition(_player->getPosition());
_camera.update();
drawGame();
}
}
void MainGame::checkVictory()
{
//init the new level if we win
if (_zombies.empty())
{
std::printf("***You Win!***\n You killed %d humans and %d zombies. There are %d/%d humans remaining", _numHumansKilled,_numZombiesKilled, _humans.size()-1, _levels[_currentLevel]->getNumHumans());
Crusty::fatalError("");
}
}
void MainGame::updateAgents()
{
//update all humans
for (int i = 0;i < _humans.size(); i++)
{
_humans[i]->update(_levels[_currentLevel]->getLevelData(), _humans,_zombies);
}
//update zombies
for (int i = 0; i < _zombies.size(); i++)
{
_zombies[i]->update(_levels[_currentLevel]->getLevelData(), _humans, _zombies);
}
//Update human collision
for (int i = 0; i < _humans.size(); i++)
{
//collide with other humans
for (int j = i + 1; j < _humans.size(); j++)
{
_humans[i]->collideWithAgent(_humans[j]);
}
}
//update zombie collision
for (int i = 0; i < _zombies.size(); i++)
{ //collide with other zombies
for (int j = i + 1; j < _zombies.size(); j++)
{
_zombies[i]->collideWithAgent(_zombies[j]);
}
//collide with humans
for (int k = 1; k < _humans.size(); k++)
{
if (_zombies[i]->collideWithAgent(_humans[k]))
{
//add new zombie at same place
_zombies.push_back(new Zombie);
_zombies.back()->init(ZOMBIESPEED, _humans[k]->getPosition());
//delete the old human
delete _humans[k];
_humans[k] = _humans.back();
_humans.pop_back();
}
}
//collide with player
if(_zombies[i]->collideWithAgent(_player))
{
//Crusty::fatalError("game over");
}
}
}
void MainGame::updateBullets() {
//collide with level
for (int i = 0; i < _bullets.size(); )
{
if (_bullets[i].update(_levels[_currentLevel]->getLevelData()))
{
//bullet collided with wall
_bullets[i] = _bullets.back();
_bullets.pop_back();
}
else {
i++;
}
}
bool wasBulletRemoved;
//collide with humans and zombies
for (int i = 0; i < _bullets.size(); i++)
{
//loop through zombies
wasBulletRemoved = false;
for (int j = 0; j < _zombies.size();)
{
if (_bullets[i].collideWithAgent(_zombies[j]))
{
if (_zombies[j]->applyDamage(_bullets[i].getDamage()))
{
//if zombie dies, kill him
delete _zombies[j];
_zombies[j] = _zombies.back();
_zombies.pop_back();
_numZombiesKilled++;
}
else
{
j++;
}
_bullets[i] = _bullets.back();
_bullets.pop_back();
wasBulletRemoved = true;
i--;//make sure we dont skip a bullet
break; //since bullet died no need to loop through more zombies
}
else {
j++;
}
}
//loop through humans
if (wasBulletRemoved == false)
{
//starts from 1 to ignore collition with player
for (int k = 1; k < _humans.size();)
{
if (_bullets[i].collideWithAgent(_humans[k]))
{
//damage human. kill it if its health is zero
if (_humans[k]->applyDamage(_bullets[i].getDamage()))
{
//if zombie dies, kill him
delete _humans[k];
_humans[k] = _humans.back();
_humans.pop_back();
_numHumansKilled++;
}
else
{
k++;
}
_bullets[i] = _bullets.back();
_bullets.pop_back();
wasBulletRemoved = true;
i--;//make sure we dont skip a bullet
break; //since bullet died no need to loop through more zombies
}
else {
k++;
}
}
}
// next bullet
i++;
}
}
void MainGame::processInput() {
SDL_Event evnt;
const float CAMERASPEED = 10.0f;
const float CAMERAZOOM = 0.02f;
//Will keep looping until there are no more events to process
while (SDL_PollEvent(&evnt)) {
switch (evnt.type) {
case SDL_QUIT:
SDL_Quit();
exit(0);
break;
case SDL_MOUSEMOTION:
_inputManager.setMouseCoord(evnt.motion.x, evnt.motion.y);
break;
case SDL_KEYDOWN:
_inputManager.pressKey(evnt.key.keysym.sym);
break;
case SDL_KEYUP:
_inputManager.releaseKey(evnt.key.keysym.sym);
break;
case SDL_MOUSEBUTTONDOWN:
_inputManager.pressKey(evnt.button.button);
break;
case SDL_MOUSEBUTTONUP:
_inputManager.releaseKey(evnt.button.button);
break;
}
}
if (_inputManager.isKeyDown(SDLK_s))
{
_camera.setPosition(_camera.getPosition() + glm::vec2(0.0f, -CAMERASPEED));
}
if (_inputManager.isKeyDown(SDLK_w))
{
_camera.setPosition(_camera.getPosition() + glm::vec2(0.0f, CAMERASPEED));
}
if (_inputManager.isKeyDown(SDLK_a))
{
_camera.setPosition(_camera.getPosition() + glm::vec2(-CAMERASPEED, 0.0f));
}
if (_inputManager.isKeyDown(SDLK_d))
{
_camera.setPosition(_camera.getPosition() + glm::vec2(CAMERASPEED, 0.0f));
}
if (_inputManager.isKeyDown(SDLK_q))
{
_camera.setScale(_camera.getScale() + CAMERAZOOM);
}
if (_inputManager.isKeyDown(SDLK_e))
{
_camera.setScale(_camera.getScale() - CAMERAZOOM);
}
}
void MainGame::drawGame() {
// Set the base depth to 1.0
glClearDepth(1.0);
// Clear the color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_textureProgram.use();
//Draw code goes here
glActiveTexture(GL_TEXTURE0);
GLint textureUniform = _textureProgram.getUniformLocation("mySampler");
glUniform1i(textureUniform, 0);
glm::mat4 projectionMatrix = _camera.getCameraMat();
GLint pUniform = _textureProgram.getUniformLocation("transformationMatrix");
glUniformMatrix4fv(pUniform, 1, GL_FALSE, &projectionMatrix[0][0]);
_levels[_currentLevel]->draw();
//draw humans
_agentSpriteBatch.begin();
for (int i = 0; i < _humans.size(); i++)
{
_humans[i]->draw(_agentSpriteBatch);
}
//draw zombies
for (int i = 0; i < _zombies.size(); i++)
{
_zombies[i]->draw(_agentSpriteBatch);
}
//draw bullets
for (int i = 0; i < _bullets.size(); i++)
{
_bullets[i].draw(_agentSpriteBatch);
}
_agentSpriteBatch.end();
_agentSpriteBatch.renderBatch();
_textureProgram.unuse();
//Swap our buffer and draw everything to the screen!
_window.swapBuffers();
} | true |
19ea9b1085e804e433118f5c24fed50c52c2f20c | C++ | 1601062/AudioCoursework | /AudioCoursework/DigitalAudio/Game.cpp | UTF-8 | 10,835 | 2.78125 | 3 | [] | no_license | #include "Game.h"
#include <random>
#include <time.h>
using std::cerr;
void Game::die(const char* s) {
cerr << "Fatal: " << s << "\n";
cerr << "Current directory is:\n";
system("cd");
system("pause");
exit(1);
}
Game::Game(sf::RenderWindow* win, Input* in, bool* bWin) : window(win), input(in), bGameWon(bWin) {
//
bgTexture.loadFromFile("gfx/Background.png");
background.setTexture(bgTexture);
//
enemyTexture.loadFromFile("gfx/BadElf.png");
enemies_vector.push_back(new Enemy(sf::Vector2f(750, 750), sf::Vector2f(1.0f, 1.0f), &enemyTexture));
//
bulletTexture.loadFromFile("gfx/Bullet.png");
//
shootClock = new sf::Clock();
spawnClock = new sf::Clock();
//
AudioInit();
//
srand(time(NULL));
}
void Game::AudioInit() {
shoot_sfx = new Audio("sfx/shoot.wav");
hohoho_sfx = new Audio("sfx/hohoho.ogg");
elf_sfx_boom = new Audio("sfx/explosion.wav");
// Shoot effects
shoot_sfx->Normalize(); // First, let's normalize the sound to deal with any potential clipping
shoot_sfx->Amplify(1.0); // It's a bit loud still, so amplify by a factor of 0.75 to decrease volume
//shoot_sfx->Delay(3, 0.2, 0.5); // Delete comment to enable some echo - arguments control echo properties
// Elf explosion effects (part one)
hohoho_sfx->Normalize(); // Normalize for balanced audio.
hohoho_sfx->Delay(5, 0.5, 0.85);
// Elf explosion effects (part two)
elf_sfx_boom->Normalize(); // Normalize for balanced audio.
//
if (!music.openFromFile("sfx/jingle.ogg"))
die("loading failed");
music.play();
music.setLoop(true);
};
bool Game::update(float dt)
{
// God and test modes for marking or insanity - caution: don't turn off god mode in test mode:
HandleModes();
// Santa movement logic:
SantaMove();
// Santa firing logic:
HandleAttacks(0.1f);
// Enemy spawn logic:
HandleEnemies(spawnTime);
// Spawn timing logic - spawning time interval decreases until interval is 0.25 seconds between spawns (use test mode to speed things up):
if (spawnTime > 0.25f) {
spawnTime -= 0.0003;
}
// Win logic:
if (g_factor <= 0.15f && SantaInCentre()) {
music.pause(); // Pause the music.
hohoho_sfx->Play(); // Play the winning sound effect.
sf::sleep(sf::seconds(5)); // Pause for dramatic effect.
*bGameWon = true; // Set win bool to true!
}
// Returns true when santa is dead:
return bGameOver;
}
void Game::HandleModes()
{
// God mode stuff.
if (input->isKeyDown(sf::Keyboard::G) && !bGodMode) {
std::cout << "God mode enabled." << std::endl;
bGodMode = true;
sf::sleep(sf::milliseconds(500));
}
else if (input->isKeyDown(sf::Keyboard::G) && bGodMode) {
std::cout << "God mode disabled." << std::endl;
bGodMode = false;
sf::sleep(sf::milliseconds(500));
}
// Test mode stuff.
if (input->isKeyDown(sf::Keyboard::T) && !bTestMode) {
std::cout << "God mode enabled." << std::endl;
std::cout << "Test mode enabled." << std::endl;
bTestMode = true;
bGodMode = true;
spawnTime = 0.125f;
sf::sleep(sf::milliseconds(500));
}
else if (input->isKeyDown(sf::Keyboard::T) && bTestMode) {
std::cout << "Test mode disabled." << std::endl;
bTestMode = false;
spawnTime = 0.25f;
sf::sleep(sf::milliseconds(500));
}
}
bool Game::SantaInCentre() {
// Simple function for checking if Santa is in the centre of the screen.
return (Santa.getPosition().x < 335 && Santa.getPosition().x > 315 && Santa.getPosition().y < 335 && Santa.getPosition().y > 315);
}
void Game::HandleAttacks(float interval)
{
sf::Time t = shootClock->getElapsedTime();
if (t.asSeconds() > interval) {
// Get Santa position
sf::Vector2f santaPos = Santa.getPosition();
// Get Mouse position
sf::Vector2f mousePos = sf::Vector2f(input->getMouseX(), input->getMouseY());
// Create bullet direction
sf::Vector2f bulletDir = Normalize(mousePos - santaPos) * 10.0f;
// When left mouse is pressed:
if (input->getMouseLeft() == true) {
bullets_vector.push_back(new Bullet(santaPos, bulletDir, &bulletTexture)); // Shoot.
bullets_vector.back()->setScale(g_factor, g_factor);
shoot_sfx->Play(); // Shoot sound effect.
}
shootClock->restart();
}
// Delete off-screen bullets
for (int i = bullets_vector.size() - 1; i >= 0; i--) {
if (BulletLost(i)) {
bullets_vector.erase(bullets_vector.begin() + i);
}
}
// Update remaining bullets
for (int i = bullets_vector.size() - 1; i >= 0; --i) {
bullets_vector[i]->update();
}
}
sf::Vector2f Game::Normalize(sf::Vector2f targetVec)
{
// Simple function for normalizing a vector to be used for shooting directions etc...
float length = sqrt((targetVec.x * targetVec.x) + (targetVec.y * targetVec.y));
if (length != 0)
return sf::Vector2f(targetVec.x / length, targetVec.y / length);
else
return targetVec;
}
bool Game::BulletLost(int i)
{
// Simple function to check if bullet has left the screen.
return bullets_vector[i]->getPosition().x < -25.0f || bullets_vector[i]->getPosition().x > 675.0f || bullets_vector[i]->getPosition().y < -25.0f || bullets_vector[i]->getPosition().y > 675.0f;
}
void Game::HandleEnemies(float interval) {
sf::Time t = spawnClock->getElapsedTime();
if (t.asSeconds() > interval) {
// Create a spawn location outside walls
sf::Vector2f randomSpawnPoint = GetSpawnPoint();
// Get Santa position
sf::Vector2f santaPos = Santa.getPosition();
// Create enemy direction
sf::Vector2f enemyDir = Normalize(santaPos - randomSpawnPoint);
//
enemies_vector.push_back(new Enemy(randomSpawnPoint, (enemyDir * 2.5f), &enemyTexture));
enemies_vector.back()->setScale(g_factor, g_factor);
//
spawnClock->restart();
}
// Delete off-screen enemies
for (int i = enemies_vector.size() - 1; i >= 0; i--) {
if (EnemyLost(i)) {
enemies_vector.erase(enemies_vector.begin() + i);
}
}
// Update remaining enemies
for (int i = enemies_vector.size() - 1; i >= 0; --i) {
enemies_vector[i]->update(); // Update the game object first.
if (DetectCollision(&(GameObject)Santa, enemies_vector[i]) && !bGodMode) {
bGameOver = true; // If an enemy reaches Santa, game over!
}
for (int j = bullets_vector.size() - 1; j >= 0; j--) { // For all the bullets...
if (DetectCollision(enemies_vector[i], bullets_vector[j])) { // If any bullet collides with the current enemy:
elf_sfx_boom->Reset(); // Reset the sound or it will get quieter each time!
elf_sfx_boom->Amplify(0.5f); // Dial it down a little, sound is too loud.
float distance = CalculateDistance(&(GameObject)Santa, enemies_vector[i]); // Calculate the distance between Santa and his elf...
elf_sfx_boom->DistanceAttenuation(g_factor, 1); // Distance based attenuation.
elf_sfx_boom->Play(); // Boom
enemies_vector.erase(enemies_vector.begin() + i); // Destroy enemy.
j = 0; // End loop.
g_factor *= 0.99f;
Santa.setScale(g_factor, g_factor);
pitch_ *= 1.005f;
music.setPitch(pitch_);
std::cout << g_factor << std::endl;
}
}
}
}
sf::Vector2f Game::GetSpawnPoint()
{
// Function for selecting random spawn points for enemies.
int randomSide = rand() % 4; // 0 left, 1 up, 2 right, 3 down
float x = 0;
float y = 0;
switch (randomSide) {
case 0:
x = -200;
y = rand() % 850 + -200;
break;
case 1:
x = rand() % 850 + -200;
y = -200;
break;
case 2:
x = 850;
y = rand() % 850 + -200;
break;
case 3:
x = rand() % 850 + -200;
y = 850;
break;
}
return sf::Vector2f(x, y);
}
bool Game::EnemyLost(int i)
{
// Simple function for checking if enemy is off the screen.
return enemies_vector[i]->getPosition().x < -500.0f || enemies_vector[i]->getPosition().x > 1150.0f || enemies_vector[i]->getPosition().y < -500.0f || enemies_vector[i]->getPosition().y > 1150.0f;
}
void Game::SantaMove()
{
// Function handles all Santa movement.
float runmult = 1.0f;
if (input->isKeyDown(sf::Keyboard::LShift)) { // "Boost"
runmult = 2.5f;
}
sf::Vector2f inputVector{ 0.0f, 0.0f }; // Movement based on input vector
if (input->isKeyDown(sf::Keyboard::A) && !WallCheck(0, &(GameObject)Santa)) {
inputVector += sf::Vector2f(-2.0f * runmult, 0.0f);
}
if (input->isKeyDown(sf::Keyboard::D) && !WallCheck(2, &(GameObject)Santa)) {
inputVector += sf::Vector2f(2.0f * runmult, 0.0f);
}
if (input->isKeyDown(sf::Keyboard::S) && !WallCheck(3, &(GameObject)Santa)) {
inputVector += sf::Vector2f(0.0f, 2.0f * runmult);
}
if (input->isKeyDown(sf::Keyboard::W) && !WallCheck(1, &(GameObject)Santa)) {
inputVector += sf::Vector2f(0.0f, -2.0f * runmult);
}
Santa.setVelocity(inputVector);
Santa.update();
}
bool Game::WallCheck(int wall_num, GameObject* go) {
// Function for checking if an object is colliding with wall bounds.
switch (wall_num) {
case 0: //left
if (go->getPosition().x <= 0) {
return true;
}
else {
return false;
}
break;
case 1: //up
if (go->getPosition().y <= 0) {
return true;
}
else {
return false;
}
break;
case 2: //right
if (go->getPosition().x >= 650) {
return true;
}
else {
return false;
}
break;
case 3: //down
if (go->getPosition().y >= 650) {
return true;
}
else {
return false;
}
break;
}
}
void Game::render()
{
// Renders everything...
window->clear(sf::Color::Black);
window->draw(background);
window->draw(Santa);
for (int i = 0; i < bullets_vector.size(); i++) {
window->draw(*bullets_vector.at(i));
}
for (int i = 0; i < enemies_vector.size(); i++) {
window->draw(*enemies_vector.at(i));
}
window->display();
}
bool Game::DetectCollision(GameObject* go1, GameObject* go2)
{
// Bounding box based collision detection.
sf::FloatRect go1Bounds = go1->getLocalBounds();
sf::FloatRect go2Bounds = go2->getLocalBounds();
// Bounding box collision
if (go1->getPosition().x < go2->getPosition().x + go2Bounds.width/2 &&
go1->getPosition().x + go1Bounds.width/2 > go2->getPosition().x &&
go1->getPosition().y < go2->getPosition().y + go2Bounds.height/2 &&
go1->getPosition().y + go2Bounds.height/2 > go2->getPosition().y)
return true;
return false;
}
float Game::CalculateDistance(GameObject* go1, GameObject* go2) {
// Function for distance calculations.
float distance =
(abs(sqrt(((go1->getPosition().x - go2->getPosition().x) * (go1->getPosition().x - go2->getPosition().x))
+ ((go1->getPosition().y - go2->getPosition().y) * (go1->getPosition().y - go2->getPosition().y)))));
return distance;
} | true |
909e9e4dde187d35b10cc40e00cfd941faf398a5 | C++ | schmitzcj/Arduino-LightShow | /fade_up.ino | UTF-8 | 3,376 | 2.765625 | 3 | [
"MIT"
] | permissive | #include <FastLED.h>
#define LED_LOW 2
#define LED_MID 8
#define LED_TOP 10
#define NUM_LEDS 60
CRGB lowLED[NUM_LEDS];
CRGB midLED[NUM_LEDS];
CRGB topLED[NUM_LEDS];
//Vars
int delayAmt = 84;
int brightLvl = 255;
int stripCnt = 60;
//Counters
int countTop = 0;
int countMid = 0;
int countLow = 0;
bool cycleComplete = false;
bool boolInit = false;
void setup() {
delay(1500);
Serial.begin(9600);
FastLED.addLeds<WS2812B, LED_LOW, GRB>(lowLED, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<WS2812B, LED_MID, GRB>(midLED, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<WS2812B, LED_TOP, GRB>(topLED, NUM_LEDS).setCorrection(TypicalLEDStrip);
}
void loop() {
if (boolInit == false){
FastLED.setDither(0);
for (int intCount = 0; intCount < NUM_LEDS; intCount++) {
lowLED[intCount] = CRGB::Black;
midLED[intCount] = CRGB::Black;
topLED[intCount] = CRGB::Black;
}
boolInit = true;
}
cycleComplete = false;
pulseUp();
}
void pulseUp(){
do{
//Low LEDs start
if (countLow < brightLvl){
for (int intCount = 0; intCount < stripCnt; intCount++) {
lowLED[intCount] = CHSV(122, 173, countLow);
}
countLow++;
}
else if(countLow == brightLvl){
//Maintain on
for (int intCount = 0; intCount < stripCnt; intCount++) {
lowLED[intCount] = CHSV(122, 173, countLow);
}
}
//Mid LEDs start
if (countLow > delayAmt && countMid < brightLvl){
for (int intCount = 0; intCount < stripCnt; intCount++) {
midLED[intCount] = CHSV(152, 173, countMid);
}
countMid++;
}
else if(countMid == brightLvl){
//Maintain on
for (int intCount = 0; intCount < stripCnt; intCount++) {
midLED[intCount] = CHSV(152, 173, countMid);
}
}
else{
//Maintain off
for (int intCount = 0; intCount < stripCnt; intCount++) {
midLED[intCount] = CRGB::Black;
}
}
//Top LEDs start
if (countMid > delayAmt && countTop < brightLvl){
for (int intCount = 0; intCount < stripCnt; intCount++) {
topLED[intCount] = CHSV(216, 173, countTop);
}
countTop++;
}
else{
//Maintain off
for (int intCount = 0; intCount < stripCnt; intCount++) {
topLED[intCount] = CRGB::Black;
}
}
//Fade all LEDs when the top has reached brightness
if (countTop == brightLvl){
int intTime = 0;
while (intTime < 1500){
for (int intCount = 0; intCount < stripCnt; intCount++) {
lowLED[intCount] = CHSV(122, 173, brightLvl);
midLED[intCount]= CHSV(152, 173, brightLvl);
topLED[intCount] = CHSV(216, 173, brightLvl);
}
delay(1);
FastLED.show();
intTime++;
}
for (int intDimming = brightLvl; intDimming > 0; intDimming--) {
for (int intCount = 0; intCount < stripCnt; intCount++) {
lowLED[intCount] = CHSV(122, 173, intDimming);
midLED[intCount]= CHSV(152, 173, intDimming);
topLED[intCount] = CHSV(216, 173, intDimming);
}
delay(2);
FastLED.show();
}
countTop = 0;
countMid = 0;
countLow = 0;
cycleComplete = true;
}
delay(10);
FastLED.show();
}while (cycleComplete != true);
}
| true |
a96373e3dcc51b7d9b2d9086549336a14e39fbb1 | C++ | mingu950202/SmartHome_IoT | /TempHumid/TempHumid.ino | UTF-8 | 2,320 | 2.875 | 3 | [] | no_license | #include <DHT.h>
#include <DHT_U.h>
#define TEMP 2
#define DHTTYPE DHT22
int BlindPin = 8;
int AirconPin = 13;
int BoilerPin = 12;
int ReadUVintensityPin = A0;
int Fan1Pin = 3;
char AValue;
DHT temp(TEMP, DHTTYPE);
void setup() {
temp.begin();
Serial.begin(9600);
pinMode(AirconPin, OUTPUT);
pinMode(BoilerPin, OUTPUT);
pinMode(ReadUVintensityPin, INPUT);
pinMode(BlindPin, OUTPUT);
pinMode(Fan1Pin,OUTPUT);
}
void loop() {
float t = temp.readTemperature();
float h = temp.readHumidity();
int uvLevel = averageAnalogRead(ReadUVintensityPin);
float outputVoltage = 5.0 * uvLevel/1024;
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);
if(Serial.available())
{
AValue = Serial.read();
{
if ( AValue == '3') // 블라인드
{
digitalWrite(BlindPin,LOW);
}
else if ( AValue == '2')
{
digitalWrite(BlindPin,HIGH);
}
else if ( AValue == '5') // 에어컨
{
digitalWrite(AirconPin,HIGH);
}
else if ( AValue == '4')
{
digitalWrite(AirconPin,LOW);
}
else if ( AValue == '7') // 보일러
{
digitalWrite(BoilerPin,HIGH);
}
else if ( AValue == '6')
{
digitalWrite(BoilerPin,LOW);
}
else if ( AValue == '9') // 환풍기1
{
digitalWrite(Fan1Pin,HIGH);
}
else if ( AValue == '8')
{
digitalWrite(Fan1Pin,LOW);
}
else if ( AValue == 'x') // 전체종료
{
digitalWrite(AirconPin,LOW);
digitalWrite(BoilerPin,LOW);
digitalWrite(Fan1Pin,LOW);
}
}
}
Serial.print(t); // 온도
Serial.print(",");
Serial.print(h); // 습도
Serial.print(",");
Serial.println(uvIntensity); // 자외선
//Serial.print(",");
//Serial.println(d);
delay(3000);
}
int averageAnalogRead(int pinToRead)
{
byte numberOfReadings = 8;
unsigned int runningValue = 0;
for(int x = 0 ; x < numberOfReadings ; x++)
runningValue += analogRead(pinToRead);
runningValue /= numberOfReadings;
return(runningValue);
}
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return ((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min);
}
| true |
c9caa0c81027d5f9310ec7f073fbbbf9b9e1534a | C++ | KarolStryczek/Network_Project | /project_netsim/include/Report_Generation/SpecificTurnsReportNotifier.hpp | UTF-8 | 727 | 2.546875 | 3 | [] | no_license | // 4a_2: Stryczek (297457), Świerczek (297464), Śliwińska(297462)
//
// Created by Karolina on 05.01.2019.
//
#ifndef PROJECT_NETSIM_SPECIFICTURNSREPORTNOTIFIER_HPP
#define PROJECT_NETSIM_SPECIFICTURNSREPORTNOTIFIER_HPP
#include "IReportNotifier.hpp"
#include <set>
class SpecificTurnsReportNotifier: public IReportNotifier {
private:
std::set<Time> _turnsSet;
public:
explicit SpecificTurnsReportNotifier(std::set<Time> turnsSet): _turnsSet(std::move(turnsSet)) {};
bool shouldGenerateReport(Time time) const override;
std::set<Time> getTurnsSet() const { return _turnsSet; };
};
#endif //PROJECT_NETSIM_SPECIFICTURNSREPORTNOTIFIER_HPP
// 4a_2: Stryczek (297457), Świerczek (297464), Śliwińska(297462) | true |
d378d0c08d80638d8df0d87471f28b032d5ff875 | C++ | pelican/pelican-astro | /src/data/ModelVisibilityData.h | UTF-8 | 1,414 | 2.78125 | 3 | [] | no_license | #ifndef MODEL_VISIBILITYDATA_H_
#define MODEL_VISIBILITYDATA_H_
#include "data/VisibilityData.h"
#include "data/Source.h"
#include <vector>
/**
* @file ModelVisibilityData.h
*/
namespace pelican {
namespace astro {
/**
* @class ModelVisibilityData
*
* @brief
* Container class to hold visibilities for a model sky positions.
*
* @details
* Inherits the visibility data blob and adds information pertaining to the
* list of sources (in RA and Dec) used to construct the visibility set.
*/
class ModelVisibilityData : public VisibilityData
{
public:
/// Constructs an empty model visibility data blob.
ModelVisibilityData() : VisibilityData("ModelVisibilityData") {}
/// Constructs and resizes model visibility data blob.
ModelVisibilityData(const unsigned nAntennas,
const std::vector<unsigned>& channels,
const Polarisation polarisation)
: VisibilityData(nAntennas, channels, polarisation, "ModelVisibilityData") {}
~ModelVisibilityData() {}
public:
/// Returns vector of model sources.
std::vector<Source>& sources() { return _sources; }
/// Returns vector of model sources.
const std::vector<Source>& sources() const { return _sources; }
private:
std::vector<Source> _sources;
};
} // namespace astro
} // namespace pelican
#endif // MODEL_VISIBILITYDATA_H_
| true |
93524a5ffddc7398bcce55315610930a73f0cbb0 | C++ | aces/mni_surfreg | /surflib/surface_checking.hpp | UTF-8 | 3,392 | 2.84375 | 3 | [] | no_license | /*
Copyright Alan C. Evans
Professor of Neurology
McGill University
*/
#ifndef SURFLIB_SUBDIVIDED_ICOSAHEDRON_HPP
#define SURFLIB_SUBDIVIDED_ICOSAHEDRON_HPP
#include <cmath>
#include <exception>
#include <CGAL/circulator.h>
#include <CGAL/squared_distance_3.h>
namespace MNI {
/*! \brief Assert that surface geometry is sphere.
*
* Check that the 3-space location of each point of surface \a s
* lies on a sphere with centre at \a centre and radius \a radius
* (plus or minus \a tolerance).
*
* \throws std::runtime_error if some point is not within tolerance.
*/
template <class Surface_>
void assert_is_sphere_geometry( const Surface_& s,
const typename Surface_::Point_3&
centre = CGAL::ORIGIN,
double radius = 1.0,
double tolerance = 1e-4 )
{
typename Surface_::Vertex_const_iterator v = s.vertices_begin();
CGAL_For_all( v, s.vertices_end() ) {
double d2 = CGAL::to_double(CGAL::squared_distance( v->point(),
centre ));
if ( std::abs( std::sqrt(d2) - radius ) > tolerance )
throw std::runtime_error( "surface geometry is not sphere." );
}
}
/*! \brief Assert that surface is triangulated sphere.
*
* Check that the graph topology of the surface is a valid
* tesselation of a sphere. This routine will check that
* the surface
*
* - satisfies CGAL::Polyhedron_3::is_valid()
* - has no borders
* - satisfies Euler equation for genus 0
* - all facets are triangles
*
* \throws std::runtime_error if any check fails.
*/
template <class Surface_>
void assert_is_sphere_topology( const Surface_& s )
{
if (!s.is_valid())
throw std::runtime_error( "mesh is not valid" );
typename Surface_::Halfedge_const_iterator h = s.halfedges_begin();
CGAL_For_all( h, s.halfedges_end() ) {
if (h->is_border())
throw std::runtime_error( "mesh has a border" );
if ( h != h->next()->next()->next() )
throw std::runtime_error( "mesh has non-triangular facet" );
}
if ( s.size_of_vertices() - s.size_of_halfedges()/2 + s.size_of_facets()
!= 2 )
throw std::runtime_error( "mesh does not satisfy V-E+F=2" );
// This should be redundant, since we already know that each facet
// is a triangle and there are no borders.
if ( s.size_of_halfedges() != 3*s.size_of_facets() )
throw std::runtime_error( "mesh does not satisfy 2E = 3F" );
}
/*! \brief Compute size of coarsened mesh.
*
* \return size of vertex list for a 4-to-1 merging of facets.
*
* \pre Surface \p s must be a 1-to-4 refinement of a previous surface
* mesh.
*
* \throws std::runtime_error if precondition not met.
*/
template <class Surface_>
typename Surface_::size_type coarser_size_of_vertices( const Surface_& s )
{
/* Assume that the mesh is genus 0, so Euler's equation is E-V+F=2.
* Assume that it is maximally-triangulated, so 2E = 3F.
* Eliminate E, leaving F = 2V-4.
*
* Denote the original mesh as "1" and the refined mesh as "2",
* then we have F_2 = 4F_1, so
* 2 V_2 - 4 = 4( 2 V_1 - 4 ) ==> V_1 = (V_2 + 6) / 4
*/
// Smallest possible is refinement of tetrahedron, with 9 vertices.
if ( s.size_of_vertices() < 9 )
throw std::runtime_error( "mesh is too small" );
if ( (s.size_of_vertices() + 6) % 4 != 0 )
throw std::runtime_error( "mesh is not 1-to-4 facet refinement" );
return (s.size_of_vertices()+6)/4;
}
}
#endif
| true |
b9d2b51d725366f218fef6adabb6005347243922 | C++ | Velmisov/CS253_Intelligent_system | /four_in_a_row/main.cpp | UTF-8 | 1,851 | 3.03125 | 3 | [] | no_license | #include <iostream>
#include "position.h"
#include "solver.h"
using namespace std;
const int DEPTH = 9;
int main() {
//auto pos = new Position("44445252656655577373337767646");
auto pos = new Position("");
pos->show();
auto solver = new Solver();
int player;
do {
cout << "Choose number of player (1 or 2): ";
string buf;
cin >> buf;
if (buf == "1") {
player = 1;
break;
}
else if (buf == "2") {
player = 2;
break;
}
cout << "Retry" << endl;
} while (true);
while (pos->number_of_moves != BOARD_SIZE) {
int col;
if (pos->who_play_now() != player) {
clock_t FOR_CLOCK = clock();
auto res = solver->bestMove(DEPTH, *pos, pos->who_play_now());
cout << "Time spent: " << double(clock() - FOR_CLOCK) / CLOCKS_PER_SEC << " seconds" << endl;
cout << res.first + 1 << " " << res.second << endl;
col = res.first;
if (pos->is_winning_move(col)) {
pos->move(col);
pos->show();
cout << "Computer won ¯\\_(ツ)_/¯" << endl;
break;
}
}
else {
do {
cout << "Choose your column: ";
cin >> col;
--col;
if (pos->can_move(col)) {
break;
} else {
cout << "Invalid column! Try again!" << endl;
}
} while (true);
if (pos->is_winning_move(col)) {
pos->move(col);
pos->show();
cout << "You won!" << endl;
break;
}
}
pos->move(col);
pos->show();
}
return 0;
}
| true |
620081f6924b131d710b5971ee104ff806f47c0b | C++ | Nihav-Jain/The-Channeler | /TheChanneler/Source/TheChanneler/Analytics/AnalyticsModule.h | UTF-8 | 3,866 | 2.765625 | 3 | [] | no_license | #pragma once
#include "AnalyticsCommon.h"
#include "AnalyticsModule.generated.h"
class UAnalyticsSession;
/**
* The basic AnalyticsModule plugin class, a new plugin for analytics system should derive from this class
*/
UCLASS(Blueprintable, BlueprintType)
class THECHANNELER_API UAnalyticsModule : public UObject
{
GENERATED_BODY()
friend class UAnalytics;
public:
virtual ~UAnalyticsModule() = default;
/**
* Init this module, perform initialization
*/
virtual void Init() {};
/**
* CleanUp this module, perform clean up work
*/
virtual void CleanUp() {};
/**
* Activate this module
*/
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Activate the module"), Category = "Analytics")
virtual void Activate() { bIsEnabled = true; };
/**
* Deactivate this module
*/
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Deactive the module"), Category = "Analytics")
virtual void Deactivate() { bIsEnabled = false; };
/**
* On level switch event
* @param world the world
* @param level the level
* @param name the level name
*/
virtual void OnLevelChanged(UWorld * world, ULevel * level, const FString & name) {};
/**
* Update function for each Tick
* @param DeltaSeconds - time in seconds since last Tick call
*/
virtual void Update(float DeltaSeconds) {};
/**
* Write the log Name/Value into the common log
* @param section - the section name, use path format to do the nested section ex /sectionname1/sectionname2
* @param name - the name of the pair
* @param value - the value
* @return true if succeed, or failed if the name exists and overwrite is not specified
*/
bool LogNameValueToSection(const FString & section, const FString & name, const FString & value, bool overwrite = false);
/**
* Write the log Name/Value into the common log
* @param name the name of the pair
* @param value the value
* @return true if succeed, or failed if the name exists and overwrite is not specified
*/
bool LogNameValue(const FString & name, const FString & value, bool overwrite = false);
/**
* Get the module dependency path
* @return the path
*/
const FString & GetModuleDependencyPath() const { return DependencyPath;};
/**
* Get the module log path
* @return the path
*/
const FString & GetModuleLogPath() const { return LogPath;};
/**
* Get the module root path
* @return the path
*/
const FString & GetModuleRootPath() const { return RootPath; };
/**
* Get the session root path
* @return the path
*/
const FString & GetSessionRootPath() const;
/**
* Get the level name
* @return the name
*/
const FString & GetLevelName();
protected:
/**
* Add any external file dependency for packaging
* This function will not copy the file immediately into the folder, it only add to it the internal list
* It waits after Init() is called, then copy the all files at once
* @param absPath - the absolute path of the file
*/
void AddExternalDependency(const FString& absPath);
/**
* Exec a shell command, the external file dependency
* the working directory, default to the module dependency path
* This currently support *.py call, *.exe call, or shell open knowing file types
* The executable or files need to be packaged with AddExternalDependency() first
* Example:
* ShellExec(TEXT("test.py 3"));
* ShellExec(TEXT("AutoScreenshot.png"));
* Note: This is a non-blocking call
* @param cmd - the cmd
*/
void ShellExec(const FString& cmd) const;
UAnalyticsModule();
bool bIsEnabled;
/** Change to false to prevent the instace to be created*/
bool bShouldBeInitiated;
private:
void InitModule();
void PackageExternalDependency();
void SetAnalyticsSession(UAnalyticsSession* session) { AnalyticsSession = session; };
UAnalyticsSession* AnalyticsSession;
TArray<FString> ExternalDependencies;
FString RootPath;
FString LogPath;
FString DependencyPath;
}; | true |
efa9bd43aaba11f6c1748ed50e43992d714c9522 | C++ | L0mion/xkill-source | /xkill-architecture/ScoreComponent.cpp | UTF-8 | 9,014 | 2.53125 | 3 | [] | no_license | #include "ScoreComponent.h"
#include <xkill-utilities/AttributeManager.h>
#include <xkill-utilities/EventType.h>
#include <xkill-utilities/Timer.h>
#include <xkill-utilities/Converter.h>
ATTRIBUTES_DECLARE_ALL
#define SAFE_DELETE(x) {if(x != nullptr) delete x; x = nullptr;}
ScoreComponent::ScoreComponent()
{
ATTRIBUTES_INIT_ALL
SUBSCRIBE_TO_EVENT(this, EVENT_START_DEATHMATCH);
SUBSCRIBE_TO_EVENT(this, EVENT_END_DEATHMATCH);
SUBSCRIBE_TO_EVENT(this, EVENT_PLAYERDEATH);
executingPlayerIndex_ = -1;
schedulerTimer_ = nullptr;
cycleTimer_ = nullptr;
gameTimer_ = nullptr;
nullProcessExecuting_ = false;
executionMode_ = false;
}
ScoreComponent::~ScoreComponent()
{
SAFE_DELETE(schedulerTimer_);
SAFE_DELETE(cycleTimer_);
SAFE_DELETE(gameTimer_);
}
bool ScoreComponent::init()
{
SAFE_DELETE(schedulerTimer_);
SAFE_DELETE(cycleTimer_);
SAFE_DELETE(gameTimer_);
schedulerTimer_ = new Timer(SETTINGS->schedulerTime);
cycleTimer_ = new Timer(SETTINGS->cycleTime);
gameTimer_ = new Timer(SETTINGS->timeLimit);
if(SETTINGS->timeLimit < 0.001f)
{
gameTimer_->setActive(false);
gameTimer_->setStartTime(1.0f);
gameTimer_->resetTimer();
}
executionMode_ = false;
nullProcessExecuting_ = false;
executingPlayerIndex_ = -1;
return true;
}
void ScoreComponent::onEvent(Event* e)
{
switch(e->getType())
{
case EVENT_START_DEATHMATCH:
init();
break;
case EVENT_END_DEATHMATCH:
if(executionMode_)
{
SEND_EVENT(&Event(EVENT_PLAYER_DONE_EXECUTING));
}
else if(nullProcessExecuting_)
{
SEND_EVENT(&Event(EVENT_NULL_PROCESS_STOPPED_EXECUTING));
}
break;
case EVENT_PLAYERDEATH:
{
Event_PlayerDeath* epd = static_cast<Event_PlayerDeath*>(e);
if(epd->playerAttributeIndex == executingPlayerIndex_)
{
AttributePtr<Attribute_Player> ptr_player = itrPlayer.at(epd->playerAttributeIndex);
ptr_player->priority = 0;
stopExecutingPlayer();
}
}
break;
default:
break;
}
}
void ScoreComponent::onUpdate(float delta)
{
if(GET_STATE() == STATE_DEATHMATCH)
{
//if scheduler game mode
schedulerScoreCounting(delta);
//if death match game mode
//deathMatchScoreCounting(delta);
gameTimer_->update(delta);
SETTINGS->timeLeft = gameTimer_->getTimeLeft();
if(gameTimer_->hasTimerExpired())
{
SEND_EVENT(&Event(EVENT_GAMEOVER));
}
}
}
void ScoreComponent::schedulerScoreCounting(float delta)
{
if(executionMode_)
{
cycleTimer_->update(delta);
if(cycleTimer_->hasTimerExpired())
{
cycleTimer_->resetTimer();
handleExecutionMode(delta);
}
}
else
{
handleSchedulerMode(delta);
}
while(itrPlayer.hasNext())
{
if(itrPlayer.getNext()->cycles >= SETTINGS->cycleLimit)
{
SEND_EVENT(&Event(EVENT_GAMEOVER));
break;
}
}
}
void ScoreComponent::deathMatchScoreCounting(float delta)
{
while(itrPlayer.hasNext())
{
if(itrPlayer.getNext()->priority >= SETTINGS->cycleLimit)
{
SEND_EVENT(&Event(EVENT_GAMEOVER));
break;
}
}
}
void ScoreComponent::handleExecutionMode(float delta)
{
if(executingPlayerIndex_ == -1) // Shouldn't happen, but if it does then leave execution mode
{
DEBUGPRINT("Score component: Executing player doesn't exist.");
executionMode_ = false;
}
else
{
AttributePtr<Attribute_Player> executingPlayer = itrPlayer.at(executingPlayerIndex_);
if(priorityWhenSelectedForExecution > 0) // The player still has some priority so give it execution time
{
priorityWhenSelectedForExecution--;
executingPlayer->priority--;
executingPlayer->cycles++;
{Event_PostHudMessage e("", executingPlayer); e.setHtmlMessage("", "priority to cycles", "", "-1 priority +1 cycle"); SEND_EVENT(&e);}
SEND_EVENT(&Event_PlaySound(XKILL_Enums::Sound::SOUND_CYCLEGAINED));
}
else // The player doesn't have any priority left so leave execution mode
{
stopExecutingPlayer();
}
}
}
void ScoreComponent::handleSchedulerMode(float delta)
{
int topPlayerIndex = -1;
int topPriority = 0;
bool topPriorityIsTied = false;
int nrOfPlayersAlive = 0;
int lastManStanding = 0;
while(itrPlayer.hasNext()) // Loop through all players and find if anyone has top priority and if they are alive
{
AttributePtr<Attribute_Player> ptr_player = itrPlayer.getNext();
if(ptr_player->priority > topPriority) // Current player had higher priority than last top player
{
topPlayerIndex = itrPlayer.storageIndex();
topPriority = ptr_player->priority;
topPriorityIsTied = false;
}
else if(ptr_player->priority == topPriority) // Current player had the same priority as last top player
{
topPriorityIsTied = true;
}
if(!ptr_player->detectedAsDead && ptr_player->ptr_health->health > 0.0f)
{
nrOfPlayersAlive++;
lastManStanding = itrPlayer.storageIndex();
}
}
if(!nullProcessExecuting_)
{
schedulerTimer_->update(delta);
SETTINGS->timeUntilScheduling = schedulerTimer_->getTimeLeft();
if(schedulerTimer_->hasTimerExpired())
{
if(topPlayerIndex == -1) // All players had zero priority
{
{Event_PostHudMessage e("No players had any priority"); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setStyle(Event_PostHudMessage::STYLE_SUBTILE); SEND_EVENT(&e);}
activateNullProcess();
}
else if(topPriorityIsTied) // Two or more players are tied for the ammount of priority
{
{Event_PostHudMessage e("Two players had tied priority"); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setStyle(Event_PostHudMessage::STYLE_SUBTILE); SEND_EVENT(&e);}
activateNullProcess();
}
else // Execute the player with highest priority
{
executePlayer(topPlayerIndex);
}
}
}
if(nullProcessExecuting_)
{
if(nrOfPlayersAlive == 1 && SETTINGS->numPlayers !=1)
{
deactivateNullProcess();
AttributePtr<Attribute_Player> ptr_player = itrPlayer.at(lastManStanding);
int priorityReward = 4;
{Event_PostHudMessage e("", ptr_player); e.setHtmlMessage("You ", "survived", " the null process execution.", "+" + Converter::IntToStr(priorityReward) + " priority"); SEND_EVENT(&e);}
ptr_player->priority += priorityReward;
SEND_EVENT(&Event_SpawnPlayer(lastManStanding));
}
else if(nrOfPlayersAlive <= 0)
{
deactivateNullProcess();
}
}
}
void ScoreComponent::activateNullProcess()
{
schedulerTimer_->resetTimer();
nullProcessExecuting_ = true;
SEND_EVENT(&Event(EVENT_NULL_PROCESS_STARTED_EXECUTING));
SEND_EVENT(&Event_PlaySound(XKILL_Enums::Sound::SOUND_RUMBLE));
{Event_PostHudMessage e(""); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setHtmlMessage("","NullProcess", "is executing"); SEND_EVENT(&e);}
// Post hud message
//{Event_PostHudMessage e("<p align='center'><span style='font-size:15pt;'>NullProcess is executing</span><br><span style='color: rgba(255, 0, 0, 255); font-size:35pt;'>Punish them all</span></p>"); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setStyle(Event_PostHudMessage::STYLE_SUBTILE); SEND_EVENT(&e);}
//{Event_PostHudMessage e("Punish them all"); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setStyle(Event_PostHudMessage::STYLE_WARNING); SEND_EVENT(&e);}
}
void ScoreComponent::deactivateNullProcess()
{
nullProcessExecuting_ = false;
SEND_EVENT(&Event(EVENT_NULL_PROCESS_STOPPED_EXECUTING));
SEND_EVENT(&Event_StopSound(XKILL_Enums::Sound::SOUND_RUMBLE));
}
void ScoreComponent::executePlayer(int playerIndex)
{
executingPlayerIndex_ = playerIndex;
cycleTimer_->resetTimer();
executionMode_ = true;
AttributePtr<Attribute_Player> ptr_player = itrPlayer.at(executingPlayerIndex_);
ptr_player->executing = true;
ptr_player->ptr_health->health = ptr_player->ptr_health->maxHealth; //Restore player health
priorityWhenSelectedForExecution = ptr_player->priority;
DEBUGPRINT("Player with attribute index " << executingPlayerIndex_ << " is executing. Beware of his laserous eyes");
// Send event to notify other components that we're entering execution mode
SEND_EVENT(&Event_PlayerExecuting(executingPlayerIndex_));
SEND_EVENT(&Event_PlaySound(XKILL_Enums::Sound::SOUND_LASER, itrPlayer.ownerIdAt(playerIndex)));
// Post hud messages
{Event_PostHudMessage e("", ptr_player); e.setHtmlMessage("Chosen by Scheduler"); SEND_EVENT(&e);}
{Event_PostHudMessage e("", ptr_player); e.setHtmlMessage("Now running in", "Kernel Mode"); SEND_EVENT(&e);}
{Event_PostHudMessage e("", ptr_player); e.setColor(ptr_player->avatarColor); e.setHtmlMessage("", ptr_player->avatarName, "is executing"); e.receiver = Event_PostHudMessage::RECEIVER_ALL_BUT_SUBJECT; SEND_EVENT(&e);}
}
void ScoreComponent::stopExecutingPlayer()
{
AttributePtr<Attribute_Player> player = itrPlayer.at(executingPlayerIndex_);
player->executing = false;
SEND_EVENT(&Event_StopSound(XKILL_Enums::Sound::SOUND_LASER, itrPlayer.ownerIdAt(executingPlayerIndex_)));
executionMode_ = false;
executingPlayerIndex_ = -1;
schedulerTimer_->resetTimer();
// Send event to notify other components that we're leaving execution mode
SEND_EVENT(&Event(EVENT_PLAYER_DONE_EXECUTING));
}
| true |
ccee6c71f23fb676c67e4ad8a403eaeb9416d68f | C++ | hhzzk/cplus-practice | /example3-7/example.cpp | UTF-8 | 1,670 | 3.390625 | 3 | [] | no_license | /*************************************************************************
> File Name: example.cpp
> Author: king
> Mail: wangjinrui2013@gmail.com
> Created Time: 2014年11月18日 星期二 19时37分10秒
************************************************************************/
#include<iostream>
#include<string>
using namespace std;
class Namelist
{
public:
Namelist() { size = 0; p = 0; }
Namelist( const string[], int );
Namelist( const Namelist& );
void set( const string&, int );
void set( char*, int );
void dump() const;
private:
int size;
string* p;
void copyIntoP( const Namelist& );
};
Namelist::Namelist( const string s[], int si )
{
p = new string[ size = si ];
for ( int i = 0; i < size; i++ )
{
p[ i ] = s[ i ];
}
}
Namelist::Namelist( const Namelist& d )
{
p = 0;
copyIntoP( d );
}
void Namelist::copyIntoP( const Namelist& d)
{
delete[] p;
if( d.p != 0)
{
p = new string[ size = d.size ];
for( int i = 0; i < size; i++ )
{
p[ i ] = d.p[ i ];
}
}
else
{
p = 0;
size = 0;
}
}
void Namelist::set( const string& s, int i)
{
p[ i ] = s;
}
void Namelist::set( char* s, int i)
{
p[ i ] = s;
}
void Namelist::dump() const
{
for( int i = 0; i < size; i++ )
{
cout << p[ i ] ;
}
cout << '\n';
}
int main()
{
string list[] = { "Lab", "Husky", "Collie" };
Namelist d1( list, 3 );
d1.dump();
Namelist d2( d1 );
d2.dump();
d2.set( "Great Dane", 1 );
d2.dump();
d1.dump();
return 0;
}
| true |
52a09d0465acf05b69a4319642385f13a5f4f746 | C++ | DarthParth/EpollDemo | /Base2/src/PeerTracker.h | UTF-8 | 681 | 2.75 | 3 | [] | no_license | /*
* PeerTracker.h
*
* Created on: Dec 13, 2014
* Author: parth
*/
#ifndef PEERTRACKER_H_
#define PEERTRACKER_H_
#include <string>
#include <set>
class PeerTracker {
public:
void update(const std::set<std::string> &incoming) {
std::set<std::string> diff {};
_discoveredPeers.insert(incoming.begin(), incoming.end());
}
const std::set<std::string> &getPeers() {
return _discoveredPeers;
}
static PeerTracker& instance() {
if(!_instance) {
_instance = new PeerTracker {};
}
return *_instance;
}
PeerTracker() {}
~PeerTracker() {}
private:
static PeerTracker *_instance;
std::set<std::string> _discoveredPeers;
};
#endif /* PEERTRACKER_H_ */
| true |
1ae9c28423b2df8ee4ca80aafe593e68660c8e3d | C++ | emaldonadogamedev/CodeSamples | /3DGraphics/MeshRenderer/esteban.maldonado_CS300_4/CS300_Fall2016_framework_DirectX11/src/Keyboard.cpp | UTF-8 | 2,023 | 2.6875 | 3 | [] | no_license | #include "Keyboard.h"
#include "DXUtil.h"
Keyboard::Keyboard(LPDIRECTINPUT8 directInput) :m_directInput(directInput), m_device(nullptr)
{
}
Keyboard::~Keyboard()
{
if (m_device != nullptr)
{
m_device->Unacquire();
m_device->Release();
m_device = nullptr;
}
}
const unsigned char* const Keyboard::CurrentState() const
{
return m_currentState;
}
const unsigned char* const Keyboard::LastState() const
{
return m_lastState;
}
void Keyboard::Initialize()
{
HRESULT r;
HR(r = m_directInput->CreateDevice(GUID_SysKeyboard, &m_device, nullptr));
HR(r = m_device->SetDataFormat(&c_dfDIKeyboard));
HR(r = m_device->SetCooperativeLevel(m_windowHandle, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
m_device->Acquire();
}
void Keyboard::Update(const float dt)
{
if (m_device)
{
m_device->Acquire();
m_device->GetDeviceState(sizeof(m_currentState), (LPVOID)&m_currentState);
memcpy(m_lastState, m_currentState, sizeof(m_currentState));
//if (FAILED(m_device->GetDeviceState(sizeof(m_currentState), (LPVOID)m_currentState)))
//{
// // Try to reaqcuire the device
// if (SUCCEEDED(m_device->Acquire()))
// {
// m_device->GetDeviceState(sizeof(m_currentState), (LPVOID)m_currentState);
// }
//}
}
}
bool Keyboard::IsKeyUp(unsigned char key) const
{
return (m_currentState[key] & 0x80) == 0;
}
bool Keyboard::IsKeyDown(unsigned char key) const
{
return m_currentState[key] & 0x80 ;
}
bool Keyboard::WasKeyUp(unsigned char key) const
{
return (m_lastState[key] & 0x80) == 0;
}
bool Keyboard::WasKeyDown(unsigned char key) const
{
return (m_lastState[key] & 0x80) != 0;
}
bool Keyboard::WasKeyPressedThisFrame(unsigned char key) const
{
return (IsKeyDown(key) && WasKeyUp(key));
}
bool Keyboard::WasKeyReleasedThisFrame(unsigned char key) const
{
return (IsKeyUp(key) && WasKeyDown(key));
}
bool Keyboard::IsKeyHeldDown(unsigned char key) const
{
return (IsKeyDown(key) && WasKeyDown(key));
}
//const int Keyboard::KeyCount; | true |
8d926a2a64fe718dbbc3042a192c4e9b9554e69c | C++ | ngmgit/cpplove | /Linkedlist/main.cpp | UTF-8 | 483 | 3.359375 | 3 | [] | no_license | #include "LinkedList.h"
#include <initializer_list>
#include <iostream>
void print(int N) { std::cout << N << ' '; }
void multiplyBy10(Node *node) { node->value = node->value * 10;}
int main(int argc, char *argv[])
{
MyLinkedList l;
l.insert(10);
l.insert(20);
l.insert(30);
l.remove(12);
l.remove(20);
//advanced
l.insert({10, 20});
l.forEach(print);
l.forEach(multiplyBy10);
l.forEach(print);
l.reverse();
l.forEach(print);
} | true |
bc83f83fed73f18d3a8ddf2fe3cd5f4523f553ac | C++ | ffk0716/onnc | /include/onnc/Core/ObjectWriter.h | UTF-8 | 1,010 | 2.546875 | 3 | [] | permissive | //===- ObjectWriter.h -----------------------------------------------------===//
//
// The ONNC Project
//
// See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef ONNC_CORE_OBJECT_WRITER_H
#define ONNC_CORE_OBJECT_WRITER_H
#include <onnc/Support/OStream.h>
namespace onnc {
/** \class onnc::ObjectWriter
* \brief provides interfaces for dumping compiler output.
*
* Deep learning accelerators don't have common standard for the output
* file format. Some of them define their own format and some of them use
* just memory image as the output format. ObjectWriter tries to provide
* a common interface to encapsulate various formats in writing steps.
*/
class ObjectWriter
{
public:
ObjectWriter(OStream& pOS);
virtual ~ObjectWriter() = 0;
OStream& getStream() { return *m_pOS; }
void setStream(OStream& pOS) { m_pOS = &pOS; }
private:
OStream* m_pOS;
};
} // namespace of onnc
#endif
| true |
31c3ecee37984cc09b78eb8326bbc8c78dea5232 | C++ | madwax/OPHD | /OPHD/Things/Structures/MineFacility.h | UTF-8 | 1,727 | 2.59375 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #pragma once
#include "Structure.h"
#include "../../Mine.h"
/**
* Implements the Mine Facility.
*/
class MineFacility : public Structure
{
public:
using ExtensionCompleteSignal = NAS2D::Signal<MineFacility*>;
public:
MineFacility(Mine* mine);
void mine(Mine* mine) { mMine = mine; }
void maxDepth(int depth) { mMaxDepth = depth; }
bool extending() const;
bool canExtend() const;
void extend();
int digTimeRemaining() const;
int assignedTrucks() const { return mAssignedTrucks; }
int maxTruckCount() const { return mMaxTruckCount; }
void addTruck() { mAssignedTrucks = std::clamp(mAssignedTrucks + 1, 1, mMaxTruckCount); }
void removeTruck() { mAssignedTrucks = std::clamp(mAssignedTrucks - 1, 1, mMaxTruckCount); }
/**
* Gets a pointer to the mine the MineFacility manages.
*/
Mine* mine() { return mMine; }
ExtensionCompleteSignal::Source& extensionComplete() { return mExtensionComplete; }
protected:
friend class MapViewState;
void assignedTrucks(int count) { mAssignedTrucks = count; }
void digTimeRemaining(int count) { mDigTurnsRemaining = count; }
protected:
void think() override;
private:
MineFacility() = delete;
MineFacility(const MineFacility&) = delete;
MineFacility& operator=(const MineFacility&) = delete;
private:
void activated() override;
private:
int mMaxDepth = 0; /**< Maximum digging depth. */
int mDigTurnsRemaining = 0; /**< Turns remaining before extension is complete. */
int mAssignedTrucks = 1; /**< All mine facilities are built with at least one truck. */
int mMaxTruckCount = 10;
Mine* mMine = nullptr; /**< Mine that this facility manages. */
ExtensionCompleteSignal mExtensionComplete; /**< Called whenever an extension is completed. */
};
| true |
a7086aac7bc5f8747299b0355e23db13b9d4da84 | C++ | JayHoris/Cpp-Algorithm-Collection | /格式输出练习.cpp | GB18030 | 1,050 | 3.40625 | 3 | [] | no_license | #include<iostream>
#include<iomanip>//ʽΪsetͷcoutͷģsetͷ䶼Ҫiomanip
#include<string>
using namespace std;
//ʽɼ_ʵ2-1
void main()
{
cout << "2019113681ܴϽ" << endl; //ѧ
double a, b, c, aver;
string name, num; //
cout << "ѧź";
cin >> num >> name;
cout << "ſγɼ";
cin >> a>>b>>c; //Ϣ
cout << fixed;
cout.precision(2); //
aver = (a + b + c) / 3;
//setw(n)ĬҶ룬ʲsetioflags(ios::right)
cout << setw(13) << "ѧ" << setw(12) << "" << setw(12) << "ߵѧ" << setw(12) << "ͨ" << setw(12) << "ѧӢ" << endl
<< setw(13) << num << setw(12) << name << setw(12) << a << setw(12) << b << setw(12) << b << endl;
//ʽ
//һַʱռ
cout << "ͬѧſγƽɼΪ" << aver;
} | true |
175ef712f59d8fd068ae9731c38d44548bcc1807 | C++ | cbiasco/slime-apocalypse | /Headers/Sphere.hpp | UTF-8 | 678 | 2.796875 | 3 | [] | no_license | #ifndef SPHERE_H_GUARD
#define SPHERE_H_GUARD
#include "Object.hpp"
const GLdouble PI = 4.0*atan(1.0);
class Sphere : public Object {
public:
Sphere();
Sphere(float r, float x, float y, float z);
Sphere(float r);
Sphere(float r, glm::vec3 p);
virtual ~Sphere();
virtual void simulate(double dt) {};
virtual void simpleSimulate(double dt) {};
void constructStandardMesh(bool override = false);
void useStandardMesh();
void useCustomMesh();
static Mesh * standardMesh;
bool usingStandardMesh = true;
// may need to change from static const
static const int stacks = 10;
static const int slices = 10;
// params[0] is radius
};
#endif // SPHERE_H_GUARD | true |
d7fd909cee64e1fcc4e987f941bc2851102aec15 | C++ | mihabor2002/EVM | /Triangle.h | UTF-8 | 641 | 2.96875 | 3 | [] | no_license | #pragma once
#include "point.h"
#include <fstream>
//211-Borovikov-Mikhail-2021
class Triangle
{
private:
Point A, B, C;
int id;
int neighbouring_triangle_id;
public:
Triangle();
Triangle(Point a, Point b, Point c);
Triangle(const Triangle& T);
~Triangle() = default;
const Triangle& operator=(const Triangle& T);
Point get_A();
Point get_B();
Point get_C();
int get_id();
int get_neighbouring_triangle_id();
void assign_A(Point a);
void assign_B(Point b);
void assign_C(Point c);
void assign_id(int k);
void assing_neighbouring_triangle_id(int k);
void print_triangle(std::ofstream& file);
}; | true |
15da7103c88c39283df04fa7e9b9699bf13cea42 | C++ | Hana-Noorudheen/CPP_LAB | /telephone.cpp | UTF-8 | 1,684 | 3.015625 | 3 | [] | no_license | import java.io.*;
class post_evln {
private int max;
private int[] arr;
private int top;
private int a;
private int b;
private int r;
public post_evln(int s){
max=s;
arr= new int[max];
top=-1;
}
public void push(int item) {
top++;
arr[top]=item;
//arr[++top];
}
public int pop() {
int item = arr[top];
top--;
return item;
//return arr[top--];
}
public void evaluvation(char x)
{
if (x=='+'||x=='-'||x=='*'||x=='/'||x=='$')
{
a=pop();
b=pop();
switch(x)
{
case '+': push(b+a);
break;
case '-': push(b-a);
break;
case '*': push(b*a);
break;
case '/' : push(b/a);
break;
case '$' :push((int) Math. round(Math.pow(b, a)));
break;
}
}
else
{
int a=Integer.parseInt(String.valueOf(x));
push(a);
}
}
public static void main(String args[])throws IOException
{
String str;
int l,i,result;
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter the Postfix String");
// x = Integer.parseInt(in.readLine());
str=in.readLine();
l = str.length();
post_evln obj = new post_evln(l);
for(i=0;i<l;i++)
obj.evaluvation(str.charAt(i));
result = obj.pop();
System.out.println(result);
}
}
| true |
bad1062be8d5b0316e5af2446dfafa1534ee7bab | C++ | emilybache/Lift-Kata | /cpp/src/lift.h | UTF-8 | 1,818 | 3.109375 | 3 | [
"MIT"
] | permissive | #ifndef CPP_LIFT_H
#define CPP_LIFT_H
#include <string>
#include <utility>
#include <vector>
#include <set>
class Call {
public:
bool operator<(const Call &rhs) const { // Needed for std::inserter()
if (floor < rhs.floor)
return true;
if (rhs.floor < floor)
return false;
return direction < rhs.direction;
}
int floor;
enum Direction {
Up, Down
} direction;
Call(int floor, Direction direction) : floor(floor), direction(direction) {}
};
class LiftSystem;
class Lift {
private:
std::string _id;
int _floor;
bool _doors_open;
std::set<int> _requested_floors;
public:
Lift(std::string id, int floor, bool doors_open, std::set<int> requested_floors)
: _id(std::move(id)), _floor(floor), _doors_open(doors_open),
_requested_floors(std::move(requested_floors)) {}
friend std::string print_lifts(const LiftSystem &system);
};
class LiftSystem {
private:
std::vector<Lift> _lifts;
std::vector<int> _floors;
std::vector<Call> _calls;
public:
LiftSystem(std::vector<Lift> lifts,
std::vector<int> floors,
std::vector<Call> calls) :
_lifts(std::move(lifts)),
_floors(std::move(floors)),
_calls(std::move(calls)) {}
void tick() {
// TODO For the user to implement
}
const std::vector<Lift> &getLifts() const {
return _lifts;
}
std::vector<Lift> &getLifts() {
return _lifts;
}
const std::vector<Call> &getCalls() const {
return _calls;
}
std::vector<Call> &getCalls() {
return _calls;
}
friend std::string print_lifts(const LiftSystem &system);
};
std::string print_lifts(const LiftSystem &system);
#endif //CPP_LIFT_H
| true |
148835327190fcf17fdde30e5605f579927bb74c | C++ | panda-sheep/leetcode | /026_Remove_Duplicates_from_Sorted_Array/remove_dup.cc | UTF-8 | 708 | 3.921875 | 4 | [] | no_license | /**********************************************************************
Given a sorted array, remove the duplicates in place such that each element
appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place
with constant memory.
For example,
Given input array A = [1,1,2],
Your function should return length = 2, and A is now [1,2].
**********************************************************************/
/*
* Use idx+1 to record the next position to insert into.
*/
int removeDuplicates(int A[], int n) {
int idx = -1;
for (int i = 0; i < n; i++) {
if (idx < 0 || A[i] != A[idx]) {
A[++idx] = A[i];
}
}
return idx+1;
}
| true |
444856ac2c486dcc2b26b3674057928b236952f1 | C++ | ciechowoj/haste-format | /data_t.cpp | UTF-8 | 59,469 | 2.5625 | 3 | [
"MIT"
] | permissive | #include <haste/data_t.hpp>
#include <algorithm>
#include <cstdint>
#include <cstring>
namespace haste {
using namespace std;
using float8_t = uint8_t;
using float16_t = uint16_t;
using float32_t = float;
using float64_t = double;
typedef void (*datacpy_t)(void*, const void*, size_t);
inline size_t index(data_t dtype) {
return size_t(dtype) >> 16;
}
static void datacpy_unorm8_unorm8(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 1 * n);
}
static void datacpy_unorm8_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm8_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint8_t*)dst)[i] = uint8_t(((float8_t*)src)[i] * 255u);
}
}
static void datacpy_unorm8_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint8_t*)dst)[i] = uint8_t(((float16_t*)src)[i] * 255u);
}
}
static void datacpy_unorm8_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint8_t*)dst)[i] = uint8_t(((float32_t*)src)[i] * 255u);
}
}
static void datacpy_unorm8_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint8_t*)dst)[i] = uint8_t(((float64_t*)src)[i] * 255u);
}
}
static void datacpy_unorm16_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_unorm16(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 2 * n);
}
static void datacpy_unorm16_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm16_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint16_t*)dst)[i] = uint16_t(((float8_t*)src)[i] * 65535u);
}
}
static void datacpy_unorm16_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint16_t*)dst)[i] = uint16_t(((float16_t*)src)[i] * 65535u);
}
}
static void datacpy_unorm16_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint16_t*)dst)[i] = uint16_t(((float32_t*)src)[i] * 65535u);
}
}
static void datacpy_unorm16_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint16_t*)dst)[i] = uint16_t(((float64_t*)src)[i] * 65535u);
}
}
static void datacpy_unorm32_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_unorm32(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 4 * n);
}
static void datacpy_unorm32_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm32_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint32_t*)dst)[i] = uint32_t(((float8_t*)src)[i] * 4294967295u);
}
}
static void datacpy_unorm32_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint32_t*)dst)[i] = uint32_t(((float16_t*)src)[i] * 4294967295u);
}
}
static void datacpy_unorm32_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint32_t*)dst)[i] = uint32_t(((float32_t*)src)[i] * 4294967295u);
}
}
static void datacpy_unorm32_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint32_t*)dst)[i] = uint32_t(((float64_t*)src)[i] * 4294967295u);
}
}
static void datacpy_unorm64_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_unorm64(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 8 * n);
}
static void datacpy_unorm64_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_unorm64_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint64_t*)dst)[i] = uint64_t(((float8_t*)src)[i] * 18446744073709551615u);
}
}
static void datacpy_unorm64_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint64_t*)dst)[i] = uint64_t(((float16_t*)src)[i] * 18446744073709551615u);
}
}
static void datacpy_unorm64_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint64_t*)dst)[i] = uint64_t(((float32_t*)src)[i] * 18446744073709551615u);
}
}
static void datacpy_unorm64_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((uint64_t*)dst)[i] = uint64_t(((float64_t*)src)[i] * 18446744073709551615u);
}
}
static void datacpy_snorm8_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_snorm8(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 1 * n);
}
static void datacpy_snorm8_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm8_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_snorm16(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 2 * n);
}
static void datacpy_snorm16_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm16_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_snorm32(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 4 * n);
}
static void datacpy_snorm32_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm32_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_snorm64(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 8 * n);
}
static void datacpy_snorm64_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_snorm64_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_uint8(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 1 * n);
}
static void datacpy_uint8_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint8_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_uint16(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 2 * n);
}
static void datacpy_uint16_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint16_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_uint32(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 4 * n);
}
static void datacpy_uint32_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint32_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_uint64(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 8 * n);
}
static void datacpy_uint64_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_uint64_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_sint8(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 1 * n);
}
static void datacpy_sint8_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint8_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_sint16(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 2 * n);
}
static void datacpy_sint16_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint16_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_sint32(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 4 * n);
}
static void datacpy_sint32_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint32_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_sint64(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 8 * n);
}
static void datacpy_sint64_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_sint64_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float8_t*)dst)[i] = float8_t(((uint8_t*)src)[i]) * 0.00392156862745098f;
}
}
static void datacpy_float8_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float8_t*)dst)[i] = float8_t(((uint16_t*)src)[i]) * 1.5259021896696422e-05f;
}
}
static void datacpy_float8_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float8_t*)dst)[i] = float8_t(((uint32_t*)src)[i]) * 2.3283064370807974e-10f;
}
}
static void datacpy_float8_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float8_t*)dst)[i] = float8_t(((uint64_t*)src)[i]) * 5.421010862427522e-20f;
}
}
static void datacpy_float8_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float8_float8(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 1 * n);
}
static void datacpy_float8_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float8_t*)dst)[i] = float8_t(((float16_t*)src)[i]);
}
}
static void datacpy_float8_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float8_t*)dst)[i] = float8_t(((float32_t*)src)[i]);
}
}
static void datacpy_float8_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float8_t*)dst)[i] = float8_t(((float64_t*)src)[i]);
}
}
static void datacpy_float16_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float16_t*)dst)[i] = float16_t(((uint8_t*)src)[i]) * 0.00392156862745098f;
}
}
static void datacpy_float16_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float16_t*)dst)[i] = float16_t(((uint16_t*)src)[i]) * 1.5259021896696422e-05f;
}
}
static void datacpy_float16_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float16_t*)dst)[i] = float16_t(((uint32_t*)src)[i]) * 2.3283064370807974e-10f;
}
}
static void datacpy_float16_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float16_t*)dst)[i] = float16_t(((uint64_t*)src)[i]) * 5.421010862427522e-20f;
}
}
static void datacpy_float16_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float16_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float16_t*)dst)[i] = float16_t(((float8_t*)src)[i]);
}
}
static void datacpy_float16_float16(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 2 * n);
}
static void datacpy_float16_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float16_t*)dst)[i] = float16_t(((float32_t*)src)[i]);
}
}
static void datacpy_float16_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float16_t*)dst)[i] = float16_t(((float64_t*)src)[i]);
}
}
static void datacpy_float32_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float32_t*)dst)[i] = float32_t(((uint8_t*)src)[i]) * 0.00392156862745098f;
}
}
static void datacpy_float32_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float32_t*)dst)[i] = float32_t(((uint16_t*)src)[i]) * 1.5259021896696422e-05f;
}
}
static void datacpy_float32_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float32_t*)dst)[i] = float32_t(((uint32_t*)src)[i]) * 2.3283064370807974e-10f;
}
}
static void datacpy_float32_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float32_t*)dst)[i] = float32_t(((uint64_t*)src)[i]) * 5.421010862427522e-20f;
}
}
static void datacpy_float32_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float32_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float32_t*)dst)[i] = float32_t(((float8_t*)src)[i]);
}
}
static void datacpy_float32_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float32_t*)dst)[i] = float32_t(((float16_t*)src)[i]);
}
}
static void datacpy_float32_float32(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 4 * n);
}
static void datacpy_float32_float64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float32_t*)dst)[i] = float32_t(((float64_t*)src)[i]);
}
}
static void datacpy_float64_unorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float64_t*)dst)[i] = float64_t(((uint8_t*)src)[i]) * 0.00392156862745098;
}
}
static void datacpy_float64_unorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float64_t*)dst)[i] = float64_t(((uint16_t*)src)[i]) * 1.5259021896696422e-05;
}
}
static void datacpy_float64_unorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float64_t*)dst)[i] = float64_t(((uint32_t*)src)[i]) * 2.3283064370807974e-10;
}
}
static void datacpy_float64_unorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float64_t*)dst)[i] = float64_t(((uint64_t*)src)[i]) * 5.421010862427522e-20;
}
}
static void datacpy_float64_snorm8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_snorm16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_snorm32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_snorm64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_uint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_uint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_uint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_uint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_sint8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_sint16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_sint32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_sint64(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
}
}
static void datacpy_float64_float8(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float64_t*)dst)[i] = float64_t(((float8_t*)src)[i]);
}
}
static void datacpy_float64_float16(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float64_t*)dst)[i] = float64_t(((float16_t*)src)[i]);
}
}
static void datacpy_float64_float32(void* dst, const void* src, size_t n) {
for (size_t i = 0; i < n; ++i) {
((float64_t*)dst)[i] = float64_t(((float32_t*)src)[i]);
}
}
static void datacpy_float64_float64(void* dst, const void* src, size_t n) {
::memcpy(dst, src, 8 * n);
}
static datacpy_t datacpy_table[] = {
datacpy_unorm8_unorm8,
datacpy_unorm8_unorm16,
datacpy_unorm8_unorm32,
datacpy_unorm8_unorm64,
datacpy_unorm8_snorm8,
datacpy_unorm8_snorm16,
datacpy_unorm8_snorm32,
datacpy_unorm8_snorm64,
datacpy_unorm8_uint8,
datacpy_unorm8_uint16,
datacpy_unorm8_uint32,
datacpy_unorm8_uint64,
datacpy_unorm8_sint8,
datacpy_unorm8_sint16,
datacpy_unorm8_sint32,
datacpy_unorm8_sint64,
datacpy_unorm8_float8,
datacpy_unorm8_float16,
datacpy_unorm8_float32,
datacpy_unorm8_float64,
datacpy_unorm16_unorm8,
datacpy_unorm16_unorm16,
datacpy_unorm16_unorm32,
datacpy_unorm16_unorm64,
datacpy_unorm16_snorm8,
datacpy_unorm16_snorm16,
datacpy_unorm16_snorm32,
datacpy_unorm16_snorm64,
datacpy_unorm16_uint8,
datacpy_unorm16_uint16,
datacpy_unorm16_uint32,
datacpy_unorm16_uint64,
datacpy_unorm16_sint8,
datacpy_unorm16_sint16,
datacpy_unorm16_sint32,
datacpy_unorm16_sint64,
datacpy_unorm16_float8,
datacpy_unorm16_float16,
datacpy_unorm16_float32,
datacpy_unorm16_float64,
datacpy_unorm32_unorm8,
datacpy_unorm32_unorm16,
datacpy_unorm32_unorm32,
datacpy_unorm32_unorm64,
datacpy_unorm32_snorm8,
datacpy_unorm32_snorm16,
datacpy_unorm32_snorm32,
datacpy_unorm32_snorm64,
datacpy_unorm32_uint8,
datacpy_unorm32_uint16,
datacpy_unorm32_uint32,
datacpy_unorm32_uint64,
datacpy_unorm32_sint8,
datacpy_unorm32_sint16,
datacpy_unorm32_sint32,
datacpy_unorm32_sint64,
datacpy_unorm32_float8,
datacpy_unorm32_float16,
datacpy_unorm32_float32,
datacpy_unorm32_float64,
datacpy_unorm64_unorm8,
datacpy_unorm64_unorm16,
datacpy_unorm64_unorm32,
datacpy_unorm64_unorm64,
datacpy_unorm64_snorm8,
datacpy_unorm64_snorm16,
datacpy_unorm64_snorm32,
datacpy_unorm64_snorm64,
datacpy_unorm64_uint8,
datacpy_unorm64_uint16,
datacpy_unorm64_uint32,
datacpy_unorm64_uint64,
datacpy_unorm64_sint8,
datacpy_unorm64_sint16,
datacpy_unorm64_sint32,
datacpy_unorm64_sint64,
datacpy_unorm64_float8,
datacpy_unorm64_float16,
datacpy_unorm64_float32,
datacpy_unorm64_float64,
datacpy_snorm8_unorm8,
datacpy_snorm8_unorm16,
datacpy_snorm8_unorm32,
datacpy_snorm8_unorm64,
datacpy_snorm8_snorm8,
datacpy_snorm8_snorm16,
datacpy_snorm8_snorm32,
datacpy_snorm8_snorm64,
datacpy_snorm8_uint8,
datacpy_snorm8_uint16,
datacpy_snorm8_uint32,
datacpy_snorm8_uint64,
datacpy_snorm8_sint8,
datacpy_snorm8_sint16,
datacpy_snorm8_sint32,
datacpy_snorm8_sint64,
datacpy_snorm8_float8,
datacpy_snorm8_float16,
datacpy_snorm8_float32,
datacpy_snorm8_float64,
datacpy_snorm16_unorm8,
datacpy_snorm16_unorm16,
datacpy_snorm16_unorm32,
datacpy_snorm16_unorm64,
datacpy_snorm16_snorm8,
datacpy_snorm16_snorm16,
datacpy_snorm16_snorm32,
datacpy_snorm16_snorm64,
datacpy_snorm16_uint8,
datacpy_snorm16_uint16,
datacpy_snorm16_uint32,
datacpy_snorm16_uint64,
datacpy_snorm16_sint8,
datacpy_snorm16_sint16,
datacpy_snorm16_sint32,
datacpy_snorm16_sint64,
datacpy_snorm16_float8,
datacpy_snorm16_float16,
datacpy_snorm16_float32,
datacpy_snorm16_float64,
datacpy_snorm32_unorm8,
datacpy_snorm32_unorm16,
datacpy_snorm32_unorm32,
datacpy_snorm32_unorm64,
datacpy_snorm32_snorm8,
datacpy_snorm32_snorm16,
datacpy_snorm32_snorm32,
datacpy_snorm32_snorm64,
datacpy_snorm32_uint8,
datacpy_snorm32_uint16,
datacpy_snorm32_uint32,
datacpy_snorm32_uint64,
datacpy_snorm32_sint8,
datacpy_snorm32_sint16,
datacpy_snorm32_sint32,
datacpy_snorm32_sint64,
datacpy_snorm32_float8,
datacpy_snorm32_float16,
datacpy_snorm32_float32,
datacpy_snorm32_float64,
datacpy_snorm64_unorm8,
datacpy_snorm64_unorm16,
datacpy_snorm64_unorm32,
datacpy_snorm64_unorm64,
datacpy_snorm64_snorm8,
datacpy_snorm64_snorm16,
datacpy_snorm64_snorm32,
datacpy_snorm64_snorm64,
datacpy_snorm64_uint8,
datacpy_snorm64_uint16,
datacpy_snorm64_uint32,
datacpy_snorm64_uint64,
datacpy_snorm64_sint8,
datacpy_snorm64_sint16,
datacpy_snorm64_sint32,
datacpy_snorm64_sint64,
datacpy_snorm64_float8,
datacpy_snorm64_float16,
datacpy_snorm64_float32,
datacpy_snorm64_float64,
datacpy_uint8_unorm8,
datacpy_uint8_unorm16,
datacpy_uint8_unorm32,
datacpy_uint8_unorm64,
datacpy_uint8_snorm8,
datacpy_uint8_snorm16,
datacpy_uint8_snorm32,
datacpy_uint8_snorm64,
datacpy_uint8_uint8,
datacpy_uint8_uint16,
datacpy_uint8_uint32,
datacpy_uint8_uint64,
datacpy_uint8_sint8,
datacpy_uint8_sint16,
datacpy_uint8_sint32,
datacpy_uint8_sint64,
datacpy_uint8_float8,
datacpy_uint8_float16,
datacpy_uint8_float32,
datacpy_uint8_float64,
datacpy_uint16_unorm8,
datacpy_uint16_unorm16,
datacpy_uint16_unorm32,
datacpy_uint16_unorm64,
datacpy_uint16_snorm8,
datacpy_uint16_snorm16,
datacpy_uint16_snorm32,
datacpy_uint16_snorm64,
datacpy_uint16_uint8,
datacpy_uint16_uint16,
datacpy_uint16_uint32,
datacpy_uint16_uint64,
datacpy_uint16_sint8,
datacpy_uint16_sint16,
datacpy_uint16_sint32,
datacpy_uint16_sint64,
datacpy_uint16_float8,
datacpy_uint16_float16,
datacpy_uint16_float32,
datacpy_uint16_float64,
datacpy_uint32_unorm8,
datacpy_uint32_unorm16,
datacpy_uint32_unorm32,
datacpy_uint32_unorm64,
datacpy_uint32_snorm8,
datacpy_uint32_snorm16,
datacpy_uint32_snorm32,
datacpy_uint32_snorm64,
datacpy_uint32_uint8,
datacpy_uint32_uint16,
datacpy_uint32_uint32,
datacpy_uint32_uint64,
datacpy_uint32_sint8,
datacpy_uint32_sint16,
datacpy_uint32_sint32,
datacpy_uint32_sint64,
datacpy_uint32_float8,
datacpy_uint32_float16,
datacpy_uint32_float32,
datacpy_uint32_float64,
datacpy_uint64_unorm8,
datacpy_uint64_unorm16,
datacpy_uint64_unorm32,
datacpy_uint64_unorm64,
datacpy_uint64_snorm8,
datacpy_uint64_snorm16,
datacpy_uint64_snorm32,
datacpy_uint64_snorm64,
datacpy_uint64_uint8,
datacpy_uint64_uint16,
datacpy_uint64_uint32,
datacpy_uint64_uint64,
datacpy_uint64_sint8,
datacpy_uint64_sint16,
datacpy_uint64_sint32,
datacpy_uint64_sint64,
datacpy_uint64_float8,
datacpy_uint64_float16,
datacpy_uint64_float32,
datacpy_uint64_float64,
datacpy_sint8_unorm8,
datacpy_sint8_unorm16,
datacpy_sint8_unorm32,
datacpy_sint8_unorm64,
datacpy_sint8_snorm8,
datacpy_sint8_snorm16,
datacpy_sint8_snorm32,
datacpy_sint8_snorm64,
datacpy_sint8_uint8,
datacpy_sint8_uint16,
datacpy_sint8_uint32,
datacpy_sint8_uint64,
datacpy_sint8_sint8,
datacpy_sint8_sint16,
datacpy_sint8_sint32,
datacpy_sint8_sint64,
datacpy_sint8_float8,
datacpy_sint8_float16,
datacpy_sint8_float32,
datacpy_sint8_float64,
datacpy_sint16_unorm8,
datacpy_sint16_unorm16,
datacpy_sint16_unorm32,
datacpy_sint16_unorm64,
datacpy_sint16_snorm8,
datacpy_sint16_snorm16,
datacpy_sint16_snorm32,
datacpy_sint16_snorm64,
datacpy_sint16_uint8,
datacpy_sint16_uint16,
datacpy_sint16_uint32,
datacpy_sint16_uint64,
datacpy_sint16_sint8,
datacpy_sint16_sint16,
datacpy_sint16_sint32,
datacpy_sint16_sint64,
datacpy_sint16_float8,
datacpy_sint16_float16,
datacpy_sint16_float32,
datacpy_sint16_float64,
datacpy_sint32_unorm8,
datacpy_sint32_unorm16,
datacpy_sint32_unorm32,
datacpy_sint32_unorm64,
datacpy_sint32_snorm8,
datacpy_sint32_snorm16,
datacpy_sint32_snorm32,
datacpy_sint32_snorm64,
datacpy_sint32_uint8,
datacpy_sint32_uint16,
datacpy_sint32_uint32,
datacpy_sint32_uint64,
datacpy_sint32_sint8,
datacpy_sint32_sint16,
datacpy_sint32_sint32,
datacpy_sint32_sint64,
datacpy_sint32_float8,
datacpy_sint32_float16,
datacpy_sint32_float32,
datacpy_sint32_float64,
datacpy_sint64_unorm8,
datacpy_sint64_unorm16,
datacpy_sint64_unorm32,
datacpy_sint64_unorm64,
datacpy_sint64_snorm8,
datacpy_sint64_snorm16,
datacpy_sint64_snorm32,
datacpy_sint64_snorm64,
datacpy_sint64_uint8,
datacpy_sint64_uint16,
datacpy_sint64_uint32,
datacpy_sint64_uint64,
datacpy_sint64_sint8,
datacpy_sint64_sint16,
datacpy_sint64_sint32,
datacpy_sint64_sint64,
datacpy_sint64_float8,
datacpy_sint64_float16,
datacpy_sint64_float32,
datacpy_sint64_float64,
datacpy_float8_unorm8,
datacpy_float8_unorm16,
datacpy_float8_unorm32,
datacpy_float8_unorm64,
datacpy_float8_snorm8,
datacpy_float8_snorm16,
datacpy_float8_snorm32,
datacpy_float8_snorm64,
datacpy_float8_uint8,
datacpy_float8_uint16,
datacpy_float8_uint32,
datacpy_float8_uint64,
datacpy_float8_sint8,
datacpy_float8_sint16,
datacpy_float8_sint32,
datacpy_float8_sint64,
datacpy_float8_float8,
datacpy_float8_float16,
datacpy_float8_float32,
datacpy_float8_float64,
datacpy_float16_unorm8,
datacpy_float16_unorm16,
datacpy_float16_unorm32,
datacpy_float16_unorm64,
datacpy_float16_snorm8,
datacpy_float16_snorm16,
datacpy_float16_snorm32,
datacpy_float16_snorm64,
datacpy_float16_uint8,
datacpy_float16_uint16,
datacpy_float16_uint32,
datacpy_float16_uint64,
datacpy_float16_sint8,
datacpy_float16_sint16,
datacpy_float16_sint32,
datacpy_float16_sint64,
datacpy_float16_float8,
datacpy_float16_float16,
datacpy_float16_float32,
datacpy_float16_float64,
datacpy_float32_unorm8,
datacpy_float32_unorm16,
datacpy_float32_unorm32,
datacpy_float32_unorm64,
datacpy_float32_snorm8,
datacpy_float32_snorm16,
datacpy_float32_snorm32,
datacpy_float32_snorm64,
datacpy_float32_uint8,
datacpy_float32_uint16,
datacpy_float32_uint32,
datacpy_float32_uint64,
datacpy_float32_sint8,
datacpy_float32_sint16,
datacpy_float32_sint32,
datacpy_float32_sint64,
datacpy_float32_float8,
datacpy_float32_float16,
datacpy_float32_float32,
datacpy_float32_float64,
datacpy_float64_unorm8,
datacpy_float64_unorm16,
datacpy_float64_unorm32,
datacpy_float64_unorm64,
datacpy_float64_snorm8,
datacpy_float64_snorm16,
datacpy_float64_snorm32,
datacpy_float64_snorm64,
datacpy_float64_uint8,
datacpy_float64_uint16,
datacpy_float64_uint32,
datacpy_float64_uint64,
datacpy_float64_sint8,
datacpy_float64_sint16,
datacpy_float64_sint32,
datacpy_float64_sint64,
datacpy_float64_float8,
datacpy_float64_float16,
datacpy_float64_float32,
datacpy_float64_float64,
};
void datacpy(void* dst, const void* src, data_t dtype, data_t stype) {
datacpy_table[index(dtype) * 20 + index(stype)](dst, src, min(ndim(dtype), ndim(stype)));
}
data_t unorm8(size_t components) {
switch(components) {
case 1: return data_t::unorm8x1;
case 2: return data_t::unorm8x2;
case 3: return data_t::unorm8x3;
case 4: return data_t::unorm8x4;
default: return data_t::unorm8x4;
}
}
}
| true |
a2195dfcc27bcd2be61841ba517972d5b97a00c6 | C++ | getov/TopCoder | /TopCoder SRM solutions/SRM 424 DIV 2 Level One (250)/MagicSpell.cpp | UTF-8 | 803 | 3.53125 | 4 | [] | no_license | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class MagicSpell
{
public:
string fixTheSpell(string spell);
};
string MagicSpell::fixTheSpell(string spell)
{
vector<char> coll;
for (int i = 0; i < spell.size(); ++i)
{
if (spell[i] == 'A' || spell[i] == 'Z')
{
coll.push_back(spell[i]);
}
}
reverse(coll.begin(), coll.end());
vector<char>::iterator iter = coll.begin();
for (int i = 0; i < spell.size(); ++i)
{
if (spell[i] == 'A' || spell[i] == 'Z')
{
if (iter != coll.end())
{
spell[i] = *iter;
++iter;
}
}
}
return spell;
}
int main()
{
MagicSpell test;
cout << test.fixTheSpell("AZBASGHNAZAHBNVZZGGGAGGZAZ") << endl;
return EXIT_SUCCESS;
} | true |