blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 2
247
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
57
| license_type
stringclasses 2
values | repo_name
stringlengths 4
111
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringlengths 4
58
| visit_date
timestamp[ns]date 2015-07-25 18:16:41
2023-09-06 10:45:08
| revision_date
timestamp[ns]date 1970-01-14 14:03:36
2023-09-06 06:22:19
| committer_date
timestamp[ns]date 1970-01-14 14:03:36
2023-09-06 06:22:19
| github_id
int64 3.89k
689M
⌀ | star_events_count
int64 0
209k
| fork_events_count
int64 0
110k
| gha_license_id
stringclasses 25
values | gha_event_created_at
timestamp[ns]date 2012-06-07 00:51:45
2023-09-14 21:58:52
⌀ | gha_created_at
timestamp[ns]date 2008-03-27 23:40:48
2023-08-24 19:49:39
⌀ | gha_language
stringclasses 159
values | src_encoding
stringclasses 34
values | language
stringclasses 1
value | is_vendor
bool 1
class | is_generated
bool 2
classes | length_bytes
int64 7
10.5M
| extension
stringclasses 111
values | filename
stringlengths 1
195
| text
stringlengths 7
10.5M
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
749127d1feaf24ebd5aeba401383553cb3687f28
|
9b9c176687cfa74feb338efc00bc16f13bec28da
|
/src/castiglione.h
|
133090d1abc455410187d6966a168efdfc55e0f2
|
[] |
no_license
|
jcrangel/periodic_fix_points
|
1b2d0afec0c3c5b2ec55f4aca2743a013534f3e7
|
c0804485913cff945ec0c4f0a858a33fbde8d7d8
|
refs/heads/master
| 2020-05-09T04:15:19.092002
| 2019-07-09T02:15:05
| 2019-07-09T02:15:05
| 180,983,794
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,616
|
h
|
castiglione.h
|
/**********************************************************************************************/ /**
* Copyright 2018 Julio C. Rangel
* @file castiglione.h
*
* @brief From paper. Optimal Control in a Model of Dendritic Cell Transfection Cancer Immunotherapy
**************************************************************************************************/
#ifndef MURINEMODEL_H
#define MURINEMODEL_H
#include "util.h"
#include <cmath>
class Castiglione
{
private:
std::vector<Doub> parameters;
const int systemSize = 5; // number of states
int controlIndex = 3; // The index of the state where the control happens
int tumorIndex = 2; // The index were the tumor is located M var in this case
const int numParameters = 17;
Doub a0, b0, c0, d0, f0;
Doub a1, b1, c1, d1, f1;
Doub d2, f2, e2;
Doub e3;
Doub a4, c4, e4;
void loadParameters()
{
a0 = parameters[0];
b0 = parameters[1];
c0 = parameters[2];
d0 = parameters[3];
f0 = parameters[4];
a1 = parameters[5];
b1 = parameters[6];
c1 = parameters[7];
d1 = parameters[8];
f1 = parameters[9];
d2 = parameters[10];
f2 = parameters[11];
e2 = parameters[12];
e3 = parameters[13];
a4 = parameters[14];
c4 = parameters[15];
e4 = parameters[16];
}
void changeParameters(std::vector<Doub> newParameters)
{
parameters = newParameters;
loadParameters();
}
public:
Castiglione(std::vector<Doub> parameters) : parameters(parameters)
{
loadParameters();
}
template <class T>
void operator()(const T &x, T &dxdt, Doub /*t*/)
{
Doub H = x[0];
Doub C = x[1];
Doub M = x[2];
Doub D = x[3];
Doub I = x[4];
dxdt[0] = a0 - b0 * H + c0 * D*(d0 * H*(1 - H / f0));
dxdt[1] = a1 - b1 * C + c1 * I*(M + D)*(d1 * C*(1 - C / f1));
dxdt[2] = (d2 * M*(1 - M / f2)) - e2 * M*C;
dxdt[3] = -e3 * D*C;
dxdt[4] = a4 * H*D - c4 * C*I - e4 * I;
//Doub H = x[2];
//Doub C = x[3];
//Doub M = x[0];
//Doub D = x[1];
//Doub I = x[4];
//dxdt[2] = a0 - b0 * H + c0 * D*(d0 * H*(1 - H / f0));
//dxdt[3] = a1 - b1 * C + c1 * I*(M + D)*(d1 * C*(1 - C / f1));
//dxdt[0] = (d2 * M*(1 - M / f2)) - e2 * M*C;
//dxdt[1] = -e3 * D*C;
//dxdt[4] = a4 * H*D - c4 * C*I - e4 * I;
}
/**
* This is needed for the Stiff integrator
*
*/
//void operator()(const VectorBoost &x, VectorBoost &dxdt, Doub /*t*/)
//{
//}
/**
* The jacobian of the system
*/
void operator()(const VectorBoost &x, MatrixBoost &M, Doub /*t*/, VectorBoost &dfdt) {
}
int getSystemSize() {
return systemSize;
}
int getControlIndex()
{
return controlIndex;
}
int getTumorIndex()
{
return tumorIndex;
}
};
#endif
|
d8d9850168e60019f9bc9d559afdc0720db11133
|
7d49da1e15460064a87e8393361952dfa7586896
|
/Homework2_Two-way_Min-cut_Partitioning/src/Structure/Data.hpp
|
5fc90bc4925765f129f0b632905694b69b53c3fc
|
[] |
no_license
|
zihaokuo/Physical_Design_Automation
|
a4f9307d2fc4f100e5d7a4a076c153715bb1bbf2
|
00efdd761018efb0a70e7ea2fadf8f1930ac99a6
|
refs/heads/main
| 2023-03-14T11:41:26.949943
| 2021-03-03T03:17:52
| 2021-03-03T03:17:52
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,296
|
hpp
|
Data.hpp
|
#pragma once
#include <string>
#include <unordered_map>
#include <vector>
struct Cell;
struct Node
{
Cell *cell;
Node *next, *before;
Node(Cell *cell) : cell(cell), next(nullptr), before(nullptr) {}
};
struct Net;
struct Cell
{
std::string name;
int size, set, gain;
bool lock;
std::vector<Net *> nets;
Node *node;
Cell(std::string name, int size)
: name(name), size(size), set(2), gain(0), lock(false), node(new Node(this)) {}
};
struct Net
{
std::string name;
std::vector<int> groupCnt;
std::vector<Cell *> cells;
Net(std::string name) : name(name)
{
groupCnt.resize(2, 0);
}
};
struct FMInput
{
double balanceFactor;
std::vector<Cell *> cells;
std::vector<Net *> nets;
FMInput(double balanceFactor, std::vector<Cell *> cells, std::vector<Net *> nets)
: balanceFactor(balanceFactor), cells(cells), nets(nets) {}
};
struct Group
{
int size, Pmax, bucketListCnt;
std::unordered_map<int, Node *> bucketList;
Group() : size(0), Pmax(0), bucketListCnt(0) {}
void insertCell(Cell *cell);
void removeCell(Cell *cell);
void bulidBucketList();
void insertNode(Cell *cell);
void removeNode(Cell *cell);
void moveNode(Cell *cell);
Cell *getBaseCell();
};
|
ff92cc8c2168ae2b8053f2396cea88beff7784e2
|
e6652252222ce9e4ff0664e539bf450bc9799c50
|
/d0710/attachments/source/郑州外国语-Fancy/thefall3.cpp
|
750b77f592cf2ccd085c51af35f610c672e9c01c
|
[] |
no_license
|
cjsoft/inasdfz
|
db0cea1cf19cf6b753353eda38d62f1b783b8f76
|
3690e76404b9189e4dd52de3770d59716c81a4df
|
refs/heads/master
| 2021-01-17T23:13:51.000569
| 2016-07-12T07:21:19
| 2016-07-12T07:21:19
| 62,596,117
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 922
|
cpp
|
thefall3.cpp
|
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
typedef int LL;
const int N=10001;
int m,fr,to;
int tot,prime[N],not_p[N],mu[N];
inline void Pre()
{
not_p[1]=1;mu[1]=1;
for(int i=2;i<N;i++)
{
if(!not_p[i])
prime[++tot]=i,mu[i]=-1;
for(int j=1,p=2,k;j<=tot&&p*i<N;p=prime[++j])
{
k=p*i;
not_p[k]=1;
if(i%p) mu[k]=-mu[i];
else
{
mu[k]=0;break;
}
}
}
}
LL rzz(LL n,LL s)
{
LL t=0;
for(LL i=1;i<=n;i++)
if(mu[i]==s)t++;
return t;
}
int main()
{
freopen("thefall3.in","r",stdin);
Pre();
int T;
for(cin>>T;T--;)
{
cin>>m;
fr=to=0;
for(LL i=1;i<=m;i++)
fr=min(fr,mu[i]),to=max(to,mu[i]);
for(LL s=fr,k;s<=to;s++)
{
for(k=1;rzz(k,s)<=m;k++)
if(rzz(k,s)==m)break;
cout<<k;
if(s==to)cout<<endl;
else cout<<' ';
}
}
return 0;
}
|
bcd9974933739559d9ffe2d0103f5bf40db10954
|
0a7c429c78853d865ff19f2a75f26690b8e61b9c
|
/Experimental/AppFrameWork/Predicates/ConditionWrapper.cpp
|
2cdba8fb3f9475deb21d2715e795d426f8f7944d
|
[] |
no_license
|
perryiv/cadkit
|
2a896c569b1b66ea995000773f3e392c0936c5c0
|
723db8ac4802dd8d83ca23f058b3e8ba9e603f1a
|
refs/heads/master
| 2020-04-06T07:43:30.169164
| 2018-11-13T03:58:57
| 2018-11-13T03:58:57
| 157,283,008
| 2
| 2
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,701
|
cpp
|
ConditionWrapper.cpp
|
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002, Perry L Miller IV
// All rights reserved.
// BSD License: http://www.opensource.org/licenses/bsd-license.html
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// Predicate class that wraps a condition.
//
///////////////////////////////////////////////////////////////////////////////
#include "AppFrameWork/Predicates/ConditionWrapper.h"
#include "AppFrameWork/Conditions/Condition.h"
#include "Usul/Errors/Assert.h"
#include "Usul/Pointers/Intrusive.h"
#include <stdexcept>
using namespace AFW::Predicates;
///////////////////////////////////////////////////////////////////////////////
//
// Constructor.
//
///////////////////////////////////////////////////////////////////////////////
ConditionWrapper::ConditionWrapper ( AFW::Conditions::Condition *c ) : BaseClass(),
_c ( 0x0 )
{
this->_set ( c );
}
///////////////////////////////////////////////////////////////////////////////
//
// Copy constructor.
//
///////////////////////////////////////////////////////////////////////////////
ConditionWrapper::ConditionWrapper ( const ConditionWrapper &c ) : BaseClass ( c ),
_c ( 0x0 )
{
this->_set ( c._c );
}
///////////////////////////////////////////////////////////////////////////////
//
// Destructor.
//
///////////////////////////////////////////////////////////////////////////////
ConditionWrapper::~ConditionWrapper()
{
Usul::Pointers::unreference ( _c );
}
///////////////////////////////////////////////////////////////////////////////
//
// Assignment operator.
//
///////////////////////////////////////////////////////////////////////////////
ConditionWrapper &ConditionWrapper::operator () ( const ConditionWrapper &c )
{
this->_set ( c._c );
return *this;
}
///////////////////////////////////////////////////////////////////////////////
//
// Set condition.
//
///////////////////////////////////////////////////////////////////////////////
void ConditionWrapper::_set ( AFW::Conditions::Condition *c )
{
if ( 0x0 == c )
throw std::runtime_error ( "Error 2279915253: Null condition given" );
Usul::Pointers::unreference ( _c );
_c = c;
Usul::Pointers::reference ( _c );
}
///////////////////////////////////////////////////////////////////////////////
//
// Overloaded operator.
//
///////////////////////////////////////////////////////////////////////////////
bool ConditionWrapper::operator () ( AFW::Core::Object *obj ) const
{
USUL_ASSERT ( 0x0 != _c );
return _c->evaluate ( obj );
}
|
fd24de65c4540d126bd47042cf71cf2af7642918
|
b107483b1c9834cc7b1df560d645cd3008364ed1
|
/Sources/GXEngine/GXAnimSolverPlayer.cpp
|
a6766da0ad7a1a67ba9de71f1d026b6fc7a95c67
|
[] |
no_license
|
Goshido/GXEngine-Windows-OS
|
1a420b109c047778c3eff1f97eb284254806df5e
|
6745e3e86a94f90124300821d920073d54069644
|
refs/heads/master
| 2016-08-12T22:14:41.976336
| 2016-03-05T17:37:06
| 2016-03-05T17:37:06
| 47,348,608
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,477
|
cpp
|
GXAnimSolverPlayer.cpp
|
//version 1.3
#include <GXEngine/GXAnimSolverPlayer.h>
#include <GXCommon/GXAVLTree.h>
#include <new>
class GXBoneFinderNode : public GXAVLTreeNode
{
public:
const GXUTF8* boneName;
GXUShort boneIndex;
public:
GXBoneFinderNode ( const GXUTF8* boneName, GXUShort boneIndex );
virtual const GXVoid* GetKey ();
static GXInt GXCALL Compare ( const GXVoid* a, const GXVoid* b );
};
GXBoneFinderNode::GXBoneFinderNode ( const GXUTF8* boneName, GXUShort boneIndex )
{
this->boneName = boneName;
this->boneIndex = boneIndex;
}
const GXVoid* GXBoneFinderNode::GetKey ()
{
return boneName;
}
GXInt GXCALL GXBoneFinderNode::Compare ( const GXVoid* a, const GXVoid* b )
{
return strcmp ( (const GXUTF8*)a, (const GXUTF8*)b );
}
//--------------------------------------------------------------------------------------------------
class GXBoneFinder : public GXAVLTree
{
private:
GXBoneFinderNode* cacheFriendlyNodes;
public:
GXBoneFinder ( const GXSkeletalMeshAnimationInfo &animInfo );
virtual ~GXBoneFinder ();
GXUShort FindBoneIndex ( const GXUTF8* boneName );
};
GXBoneFinder::GXBoneFinder ( const GXSkeletalMeshAnimationInfo &animInfo ) :
GXAVLTree ( &GXBoneFinderNode::Compare, GX_FALSE )
{
cacheFriendlyNodes = (GXBoneFinderNode*)malloc ( sizeof ( GXBoneFinderNode ) * animInfo.totalbones );
for ( GXUShort i = 0; i < animInfo.totalbones; i++ )
{
new ( cacheFriendlyNodes + i ) GXBoneFinderNode ( animInfo.Bones[ i ].Name, i );
Add ( cacheFriendlyNodes + i );
}
}
GXBoneFinder::~GXBoneFinder ()
{
free ( cacheFriendlyNodes );
}
GXUShort GXBoneFinder::FindBoneIndex ( const GXUTF8* boneName )
{
const GXBoneFinderNode* node = (const GXBoneFinderNode*)FindByKey ( boneName );
if ( !node )
return 0xFFFF;
return node->boneIndex;
}
//--------------------------------------------------------------------------------------------------
GXAnimSolverPlayer::GXAnimSolverPlayer ( GXUShort solverID ):
GXAnimSolver ( solverID )
{
animPos = 0.0f;
finder = 0;
}
GXAnimSolverPlayer::~GXAnimSolverPlayer ()
{
GXSafeDelete ( finder );
}
GXVoid GXAnimSolverPlayer::GetBone ( const GXUTF8* boneName, const GXQuat** rot, const GXVec3** loc )
{
if ( !finder )
{
*rot = 0;
*loc = 0;
return;
}
#define GET_RAW_FRAME(anim,frame) \
( ( animData->Animations[ anim ].FirstRawFrame + frame ) * animData->totalbones )
GXUShort i = finder->FindBoneIndex ( boneName );
GXInt frame = (GXInt)( animPos * animData->Animations[ 0 ].NumRawFrames );
if ( frame == animData->Animations[ 0 ].NumRawFrames ) frame--;
*rot = i >= animData->totalbones ? 0 : &animData->RawKeys[ GET_RAW_FRAME ( 0, frame ) + i ].Orientation;
*loc = i >= animData->totalbones ? 0 : &animData->RawKeys[ GET_RAW_FRAME ( 0, frame ) + i ].Position;
#undef GET_RAW_FRAME
}
GXVoid GXAnimSolverPlayer::Update ( GXFloat delta )
{
animPos += delta * multiplier * delta2PartFartor;
if ( animPos > 1.0f )
{
while ( animPos > 1.0f )
animPos -= 1.0f;
}
else if ( animPos < 0.0f )
{
while ( animPos < 0.0f )
animPos += 1.0f;
}
}
GXVoid GXAnimSolverPlayer::SetAnimationSequence ( const GXSkeletalMeshAnimationInfo* animData )
{
GXSafeDelete ( finder );
finder = new GXBoneFinder ( *animData );
this->animData = animData;
delta2PartFartor = (GXFloat)animData->Animations[ 0 ].FPS / (GXFloat)animData->Animations[ 0 ].NumRawFrames;
}
GXVoid GXAnimSolverPlayer::SetAnimationMultiplier ( GXFloat multiplier )
{
this->multiplier = multiplier;
}
|
3dc185722591d558b90b8a2f8810ea90bf914def
|
ee8e175ea4fc19a3f050cc8c8c7ab239491c173b
|
/CellularBlockWorld/Game/Genome.hpp
|
e9bcfd8420ec85d04e4e5c9a8216a908c5be246d
|
[] |
no_license
|
BrianRust/Smooth-Life
|
76635fcc3be79045b89ee4d335d78c0494dc57f2
|
c8a5200522202ef1acc8aa924a41c1006b682e28
|
refs/heads/master
| 2016-09-01T05:03:58.903009
| 2015-10-07T01:59:00
| 2015-10-07T01:59:00
| 43,098,092
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,623
|
hpp
|
Genome.hpp
|
#ifndef included_Genome
#define included_Genome
#pragma once
//-------------------------------------------------------------
//-------------------------------------------------------------
class Genome
{
public:
Genome()
{
m_maxStarveLossPerStep = 0.f;
m_maxCrowdLossPerStep = 0.f;
m_maxBirthsPerStep = 0.f;
m_starveThreshold = 0.f;
m_crowdThreshold = 0.f;
m_stableThreshold = 0.f;
m_initialLifePercentageInWorld = 0;
m_fitnessScore = 0.f;
};
Genome(float starveLoss, float crowdLoss, float birthGain, float starveThreshold, float crowdThreshold, float stableThreshold, int lifeRatio)
{
m_maxStarveLossPerStep = starveLoss;
m_maxCrowdLossPerStep = crowdLoss;
m_maxBirthsPerStep = birthGain;
m_starveThreshold = starveThreshold;
m_crowdThreshold = crowdThreshold;
m_stableThreshold = stableThreshold;
m_initialLifePercentageInWorld = lifeRatio;
m_fitnessScore = 0.f;
};
float GetMaxBirthThreshold() const
{
return (m_stableThreshold + m_starveThreshold) * 0.5f;
}
float m_maxStarveLossPerStep;
float m_maxCrowdLossPerStep;
float m_maxBirthsPerStep;
float m_starveThreshold;
float m_crowdThreshold;
float m_stableThreshold;
int m_initialLifePercentageInWorld;
float m_fitnessScore;
/*
Max starve loss per step
Max crowding loss per step
Max births life per step
Starve threshold
Crowd threshold
Stable threshold
Initial ratio of living cells
*/
};
inline bool operator < (const Genome& first, const Genome& second)
{
if (first.m_fitnessScore < second.m_fitnessScore) {
return true;
}
else {
return false;
}
};
#endif //included_Genome
|
a1b8cb91f9186b41944eb8598e9b314f0291a154
|
5cbcc8d5822a6e15418c5edb33b95eaf195ec4f2
|
/w02/wk02_hwD_chesj445/src/Ball.hpp
|
a911675e8ff788284b7941bec874365fdd82c4da
|
[] |
no_license
|
jeanachesnik/chesj445_AlgoSims2016
|
aa34f48acdff5373c43c8dafb72d93e2cf711e23
|
1c9abc44db4343d6721fa2826f6f5715c5c7b3fe
|
refs/heads/master
| 2021-01-11T18:21:03.691214
| 2016-12-16T02:07:58
| 2016-12-16T02:07:58
| 67,174,521
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 631
|
hpp
|
Ball.hpp
|
//
// Ball.hpp
// wk02_hwD_chesj445
//
// Created by Jeana Chesnik on 9/18/16.
//
//
#ifndef _BALL // if this class hasn't been defined, the program can define it
#define _BALL // by using this if statement you prevent the class to be called more than once which would confuse the compiler
#include "ofMain.h"
class Ball {
public: // place public functions or variables declarations here
void setup();
void update();
void draw();
// variables
float x;
float y;
float speedY;
float speedX;
int dim;
ofColor color;
Ball();
private:
};
#endif /* Ball_hpp */
|
c595125052d5b3fa7557a3a8e884fea67c8bcbfb
|
9cb68d0570a8203e1e7b8c5dfe03db3d142a8f53
|
/src/Resources/Modelling/ModelBase.cpp
|
4a54ea0efc8de5d9761acedce63d60f2bf71055a
|
[] |
no_license
|
Serflous/ICT397-Modern
|
a97fa2898f229f88d53fbc1caec40bc26f8b5c14
|
cab4aba962d87eddb8bff8aebcda6a19440ef124
|
refs/heads/master
| 2020-03-10T03:33:32.271533
| 2018-06-01T00:39:23
| 2018-06-01T00:39:23
| 129,168,162
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,251
|
cpp
|
ModelBase.cpp
|
#include "ModelBase.h"
ModelBase::ModelBase()
{
m_vaoId = 0;
m_vertexCount = 0;
m_texture = nullptr;
}
void ModelBase::SetVAOID(int vaoId)
{
m_vaoId = vaoId;
}
void ModelBase::SetVertexCount(int vertexCount)
{
m_vertexCount = vertexCount;
}
void ModelBase::SetTexture(Texture2D * texture)
{
m_texture = texture;
}
void ModelBase::SetVertexes(std::vector<glm::vec3> verts)
{
m_verts = verts;
}
void ModelBase::SetUVS(std::vector<glm::vec2> uvs)
{
m_uvs = uvs;
}
void ModelBase::SetNorms(std::vector<glm::vec3> norms)
{
m_norms = norms;
}
int ModelBase::GetVAOID()
{
return m_vaoId;
}
int ModelBase::GetVertexCount()
{
return m_vertexCount;
}
Texture2D * ModelBase::GetTexture()
{
return m_texture;
}
std::vector<glm::vec3> ModelBase::GetVertexes()
{
return m_verts;
}
std::vector<glm::vec2> ModelBase::GetUVS()
{
return m_uvs;
}
std::vector<glm::vec3> ModelBase::GetNorms()
{
return m_norms;
}
float ModelBase::GetModelHeight()
{
int maxY = INT_MIN;
int minY = INT_MAX;
std::vector<glm::vec3>::iterator vertIter;
for (vertIter = m_verts.begin(); vertIter != m_verts.end(); vertIter++)
{
if ((*vertIter).y > maxY)
maxY = (*vertIter).y;
if ((*vertIter).y < minY)
minY = (*vertIter).y;
}
return maxY - minY;
}
|
6b30df98435712b1eb64c29da33cc41daaff53fa
|
c831d5b1de47a062e1e25f3eb3087404b7680588
|
/webkit/Source/WebKit/win/DOMEventsClasses.cpp
|
ad8766b31b5683a69ce5475bf7704bca3dc836d4
|
[
"BSD-2-Clause"
] |
permissive
|
naver/sling
|
705b09c6bba6a5322e6478c8dc58bfdb0bfb560e
|
5671cd445a2caae0b4dd0332299e4cfede05062c
|
refs/heads/master
| 2023-08-24T15:50:41.690027
| 2016-12-20T17:19:13
| 2016-12-20T17:27:47
| 75,152,972
| 126
| 6
| null | 2022-10-31T00:25:34
| 2016-11-30T04:59:07
|
C++
|
UTF-8
|
C++
| false
| false
| 20,278
|
cpp
|
DOMEventsClasses.cpp
|
/*
* Copyright (C) 2006-2007, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "WebKitDLL.h"
#include <initguid.h>
#include "DOMEventsClasses.h"
#include <WebCore/COMPtr.h>
#include <WebCore/DOMWindow.h>
#include <WebCore/Event.h>
#include <WebCore/EventNames.h>
#include <WebCore/KeyboardEvent.h>
#include <WebCore/MouseEvent.h>
#include <WebCore/ScriptExecutionContext.h>
// DOMEventListener -----------------------------------------------------------
HRESULT DOMEventListener::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IDOMEventListener))
*ppvObject = static_cast<IDOMEventListener*>(this);
else
return DOMObject::QueryInterface(riid, ppvObject);
AddRef();
return S_OK;
}
HRESULT DOMEventListener::handleEvent(_In_opt_ IDOMEvent* /*evt*/)
{
return E_NOTIMPL;
}
WebEventListener::WebEventListener(IDOMEventListener* i)
: EventListener(CPPEventListenerType)
, m_iDOMEventListener(i)
{
m_iDOMEventListener->AddRef();
}
WebEventListener::~WebEventListener()
{
m_iDOMEventListener->Release();
}
bool WebEventListener::operator==(const WebCore::EventListener& other) const
{
return (other.type() == CPPEventListenerType
&& reinterpret_cast<const WebEventListener*>(&other)->m_iDOMEventListener == m_iDOMEventListener);
}
void WebEventListener::handleEvent(WebCore::ScriptExecutionContext* s, WebCore::Event* e)
{
RefPtr<WebCore::Event> ePtr(e);
COMPtr<IDOMEvent> domEvent = DOMEvent::createInstance(ePtr);
m_iDOMEventListener->handleEvent(domEvent.get());
}
Ref<WebEventListener> WebEventListener::create(IDOMEventListener* d)
{
return adoptRef(*new WebEventListener(d));
}
// DOMEvent -------------------------------------------------------------------
DOMEvent::DOMEvent(PassRefPtr<WebCore::Event> e)
{
m_event = e;
}
DOMEvent::~DOMEvent()
{
}
IDOMEvent* DOMEvent::createInstance(PassRefPtr<WebCore::Event> e)
{
if (!e)
return nullptr;
HRESULT hr;
IDOMEvent* domEvent = nullptr;
switch (e->eventInterface()) {
case WebCore::KeyboardEventInterfaceType: {
DOMKeyboardEvent* newEvent = new DOMKeyboardEvent(e);
hr = newEvent->QueryInterface(IID_IDOMKeyboardEvent, (void**)&domEvent);
break;
}
case WebCore::MouseEventInterfaceType: {
DOMMouseEvent* newEvent = new DOMMouseEvent(e);
hr = newEvent->QueryInterface(IID_IDOMMouseEvent, (void**)&domEvent);
break;
}
case WebCore::MutationEventInterfaceType: {
DOMMutationEvent* newEvent = new DOMMutationEvent(e);
hr = newEvent->QueryInterface(IID_IDOMMutationEvent, (void**)&domEvent);
break;
}
case WebCore::OverflowEventInterfaceType: {
DOMOverflowEvent* newEvent = new DOMOverflowEvent(e);
hr = newEvent->QueryInterface(IID_IDOMOverflowEvent, (void**)&domEvent);
break;
}
case WebCore::WheelEventInterfaceType: {
DOMWheelEvent* newEvent = new DOMWheelEvent(e);
hr = newEvent->QueryInterface(IID_IDOMWheelEvent, (void**)&domEvent);
break;
}
default:
if (e->isUIEvent()) {
DOMUIEvent* newEvent = new DOMUIEvent(e);
hr = newEvent->QueryInterface(IID_IDOMUIEvent, (void**)&domEvent);
} else {
DOMEvent* newEvent = new DOMEvent(e);
hr = newEvent->QueryInterface(IID_IDOMEvent, (void**)&domEvent);
}
}
if (FAILED(hr))
return nullptr;
return domEvent;
}
HRESULT DOMEvent::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_DOMEvent))
*ppvObject = this;
else if (IsEqualGUID(riid, IID_IDOMEvent))
*ppvObject = static_cast<IDOMEvent*>(this);
else
return DOMObject::QueryInterface(riid, ppvObject);
AddRef();
return S_OK;
}
HRESULT DOMEvent::type(__deref_opt_out BSTR* result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMEvent::target(_COM_Outptr_opt_ IDOMEventTarget** result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMEvent::currentTarget(_COM_Outptr_opt_ IDOMEventTarget** result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMEvent::eventPhase(_Out_ unsigned short* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMEvent::bubbles(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMEvent::cancelable(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMEvent::timeStamp(_Out_ DOMTimeStamp* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMEvent::stopPropagation()
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMEvent::preventDefault()
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMEvent::initEvent(_In_ BSTR /*eventTypeArg*/, BOOL /*canBubbleArg*/, BOOL /*cancelableArg*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
// DOMUIEvent -----------------------------------------------------------------
HRESULT DOMUIEvent::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IDOMUIEvent))
*ppvObject = static_cast<IDOMUIEvent*>(this);
else
return DOMEvent::QueryInterface(riid, ppvObject);
AddRef();
return S_OK;
}
HRESULT DOMUIEvent::view(_COM_Outptr_opt_ IDOMWindow** result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMUIEvent::detail(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMUIEvent::initUIEvent(_In_ BSTR /*type*/, BOOL /*canBubble*/, BOOL /*cancelable*/, _In_opt_ IDOMWindow* /*view*/, long /*detail*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMUIEvent::keyCode(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMUIEvent::charCode(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMUIEvent::unused1(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMUIEvent::unused2(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMUIEvent::pageX(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMUIEvent::pageY(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMUIEvent::which(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
// DOMKeyboardEvent -----------------------------------------------------------
HRESULT DOMKeyboardEvent::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IDOMKeyboardEvent))
*ppvObject = static_cast<IDOMKeyboardEvent*>(this);
else
return DOMUIEvent::QueryInterface(riid, ppvObject);
AddRef();
return S_OK;
}
HRESULT DOMKeyboardEvent::keyIdentifier(__deref_opt_out BSTR* result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMKeyboardEvent::location(_Out_ unsigned long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMKeyboardEvent::keyLocation(_Out_ unsigned long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMKeyboardEvent::ctrlKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isKeyboardEvent())
return E_FAIL;
WebCore::KeyboardEvent* keyEvent = static_cast<WebCore::KeyboardEvent*>(m_event.get());
*result = keyEvent->ctrlKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMKeyboardEvent::shiftKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isKeyboardEvent())
return E_FAIL;
WebCore::KeyboardEvent* keyEvent = static_cast<WebCore::KeyboardEvent*>(m_event.get());
*result = keyEvent->shiftKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMKeyboardEvent::altKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isKeyboardEvent())
return E_FAIL;
WebCore::KeyboardEvent* keyEvent = static_cast<WebCore::KeyboardEvent*>(m_event.get());
*result = keyEvent->altKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMKeyboardEvent::metaKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isKeyboardEvent())
return E_FAIL;
WebCore::KeyboardEvent* keyEvent = static_cast<WebCore::KeyboardEvent*>(m_event.get());
*result = keyEvent->metaKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMKeyboardEvent::altGraphKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isKeyboardEvent())
return E_FAIL;
WebCore::KeyboardEvent* keyEvent = static_cast<WebCore::KeyboardEvent*>(m_event.get());
*result = keyEvent->altGraphKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMKeyboardEvent::getModifierState(_In_ BSTR /*keyIdentifierArg*/, _Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMKeyboardEvent::initKeyboardEvent(_In_ BSTR /*type*/, BOOL /*canBubble*/, BOOL /*cancelable*/,
_In_opt_ IDOMWindow* /*view*/, _In_ BSTR /*keyIdentifier*/, unsigned long /*keyLocation*/,
BOOL /*ctrlKey*/, BOOL /*altKey*/, BOOL /*shiftKey*/, BOOL /*metaKey*/, BOOL /*graphKey*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
// DOMMouseEvent --------------------------------------------------------------
HRESULT DOMMouseEvent::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IDOMMouseEvent))
*ppvObject = static_cast<IDOMMouseEvent*>(this);
else
return DOMUIEvent::QueryInterface(riid, ppvObject);
AddRef();
return S_OK;
}
HRESULT DOMMouseEvent::screenX(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::screenY(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::clientX(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::clientY(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::ctrlKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isMouseEvent())
return E_FAIL;
WebCore::MouseEvent* mouseEvent = static_cast<WebCore::MouseEvent*>(m_event.get());
*result = mouseEvent->ctrlKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMMouseEvent::shiftKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isMouseEvent())
return E_FAIL;
WebCore::MouseEvent* mouseEvent = static_cast<WebCore::MouseEvent*>(m_event.get());
*result = mouseEvent->shiftKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMMouseEvent::altKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isMouseEvent())
return E_FAIL;
WebCore::MouseEvent* mouseEvent = static_cast<WebCore::MouseEvent*>(m_event.get());
*result = mouseEvent->altKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMMouseEvent::metaKey(_Out_ BOOL* result)
{
if (!result)
return E_POINTER;
*result = FALSE;
if (!m_event || !m_event->isMouseEvent())
return E_FAIL;
WebCore::MouseEvent* mouseEvent = static_cast<WebCore::MouseEvent*>(m_event.get());
*result = mouseEvent->metaKey() ? TRUE : FALSE;
return S_OK;
}
HRESULT DOMMouseEvent::button(_Out_ unsigned short* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::relatedTarget(_COM_Outptr_opt_ IDOMEventTarget** result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::initMouseEvent(_In_ BSTR /*type*/, BOOL /*canBubble*/, BOOL /*cancelable*/,
_In_opt_ IDOMWindow* /*view*/, long /*detail*/, long /*screenX*/, long /*screenY*/, long /*clientX*/, long /*clientY*/,
BOOL /*ctrlKey*/, BOOL /*altKey*/, BOOL /*shiftKey*/, BOOL /*metaKey*/, unsigned short /*button*/,
_In_opt_ IDOMEventTarget* /*relatedTarget*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::offsetX(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::offsetY(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::x(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::y(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::fromElement(_COM_Outptr_opt_ IDOMNode** result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMMouseEvent::toElement(_COM_Outptr_opt_ IDOMNode** result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
// DOMMutationEvent -----------------------------------------------------------
HRESULT DOMMutationEvent::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IDOMMutationEvent))
*ppvObject = static_cast<IDOMMutationEvent*>(this);
else
return DOMEvent::QueryInterface(riid, ppvObject);
AddRef();
return S_OK;
}
HRESULT DOMMutationEvent::relatedNode(_COM_Outptr_opt_ IDOMNode** result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMMutationEvent::prevValue(__deref_opt_out BSTR* result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMMutationEvent::newValue(__deref_opt_out BSTR* result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMMutationEvent::attrName(__deref_opt_out BSTR* result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = nullptr;
return E_NOTIMPL;
}
HRESULT DOMMutationEvent::attrChange(_Out_ unsigned short* result)
{
ASSERT_NOT_REACHED();
if (!result)
return E_POINTER;
*result = 0;
return E_NOTIMPL;
}
HRESULT DOMMutationEvent::initMutationEvent(_In_ BSTR /*type*/, BOOL /*canBubble*/, BOOL /*cancelable*/,
_In_opt_ IDOMNode* /*relatedNode*/, _In_ BSTR /*prevValue*/, _In_ BSTR /*newValue*/, _In_ BSTR /*attrName*/,
unsigned short /*attrChange*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
// DOMOverflowEvent -----------------------------------------------------------
HRESULT DOMOverflowEvent::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IDOMOverflowEvent))
*ppvObject = static_cast<IDOMOverflowEvent*>(this);
else
return DOMEvent::QueryInterface(riid, ppvObject);
AddRef();
return S_OK;
}
HRESULT DOMOverflowEvent::orient(_Out_ unsigned short* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMOverflowEvent::horizontalOverflow(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMOverflowEvent::verticalOverflow(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
// DOMWheelEvent --------------------------------------------------------------
HRESULT DOMWheelEvent::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IDOMWheelEvent))
*ppvObject = static_cast<IDOMWheelEvent*>(this);
else
return DOMUIEvent::QueryInterface(riid, ppvObject);
AddRef();
return S_OK;
}
HRESULT DOMWheelEvent::screenX(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::screenY(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::clientX(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::clientY(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::ctrlKey(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::shiftKey(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::altKey(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::metaKey(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::wheelDelta(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::wheelDeltaX(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::wheelDeltaY(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::offsetX(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::offsetY(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::x(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::y(_Out_ long* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::isHorizontal(_Out_ BOOL* /*result*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
HRESULT DOMWheelEvent::initWheelEvent(long /*wheelDeltaX*/, long /*wheelDeltaY*/,
_In_opt_ IDOMWindow* /*view*/, long /*screenX*/, long /*screenY*/, long /*clientX*/, long /*clientY*/,
BOOL /*ctrlKey*/, BOOL /*altKey*/, BOOL /*shiftKey*/, BOOL /*metaKey*/)
{
ASSERT_NOT_REACHED();
return E_NOTIMPL;
}
|
7f653b35f560b98283630f4507c72ac16b0f044a
|
6dacb8f59751c9647685d4b931b2cbef00fcd302
|
/PepLectures/Lec02_28-Jan/reverseNumber.cpp
|
b7902b0ff6794cd7648339eaeb24753856a0eadf
|
[] |
no_license
|
sudhanshu-t/DSA
|
88662429514509c3a063d7610db3d32a6854c5c0
|
042fad26085405f77f159eb08c53555de9fb7732
|
refs/heads/master
| 2021-07-19T15:26:34.310444
| 2020-07-09T11:59:41
| 2020-07-09T11:59:41
| 278,350,018
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 196
|
cpp
|
reverseNumber.cpp
|
#include<iostream>
using namespace std;
int main(int argc, char** argv){
int n, d;
cin>>n;
while(n != 0){
d = n%10;
n = n/10;
cout<<d;
}
return 0;
}
|
3479c535b322b69f419a99e4e6911711815a432b
|
fcf64d18154ed142371db8cb058a82049c23f78f
|
/WorkZix/LinuxBackUp/VelodyneSlamTest/Param.h
|
384def8c8035504ca90011f5390387dda230e90e
|
[] |
no_license
|
peterdu88/WorkZix
|
fc1408b59dc21a1aa16ce3a8f5eb0ff0b1b72827
|
9223999b95a24fc1134f808853a97fce7f27812a
|
refs/heads/master
| 2022-03-13T04:32:11.654753
| 2018-09-24T16:42:54
| 2018-09-24T16:42:54
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 442
|
h
|
Param.h
|
#include "OpenCVInc.h"
class VelodyneParam
{
public:
VelodyneParam();
double dTreadSlope; //road edge slope threashold (degree)
cv::Point3d CalibT; //calibrate translation
cv::Point3d CalibR; //calibrate rotation
double dVehicleWidthHalf; //mm
double dVehicleLen; //mm
double dPathChangeToleratePer; //percent[0-1]
double dPathChangeDist; //m
int nStableCont;
int nStableValid;
};
|
4e5619d72d59473d53ab98561a8442de294a5451
|
a27e8fbaf88288f161615345a6398852dac46efd
|
/src/read_mapper/mapper/read_query_file.cpp
|
2863399e62285dc26483c3415f0dcc11e2c18349
|
[
"CC-BY-4.0",
"MIT",
"CC0-1.0",
"LicenseRef-scancode-public-domain"
] |
permissive
|
seqan/learning-resources
|
e33a32c36ec88acb30581e51afa614f6654bbc2f
|
e6447edca3a349cb350b73b31dbed9e3215447fc
|
refs/heads/gh-pages
| 2021-12-24T15:02:58.551100
| 2021-09-14T12:16:45
| 2021-09-14T12:16:45
| 203,571,340
| 7
| 5
|
NOASSERTION
| 2021-09-14T09:14:01
| 2019-08-21T11:36:26
|
C++
|
UTF-8
|
C++
| false
| false
| 184
|
cpp
|
read_query_file.cpp
|
#include "read_query_file.hpp"
namespace read_mapper::mapper
{
void read_query_file(cli_arguments const & arguments, read_query_file_callback callback)
{
}
} // read_mapper::mapper
|
a2b1e6abfe3080a0f2454faf9c1c71b16c43b595
|
fca68c5fec6df6f999408571315c2b8e7c4b8ce9
|
/service/navtrack_home/src/Navigation/Navigation/NavMuonId.h
|
d83911035bb0200e54a6e2a59af3367918fad55c
|
[] |
no_license
|
jpivarski-talks/1999-2006_gradschool-3
|
8b2ea0b6babef104b0281c069994fc9894a05b14
|
57e80d601c0519f9e01a07ecb53d367846e8306e
|
refs/heads/master
| 2022-11-19T12:01:42.959599
| 2020-07-25T01:19:59
| 2020-07-25T01:19:59
| 282,235,559
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 5,463
|
h
|
NavMuonId.h
|
#if !defined(NAVIGATION_NAVMUONID_H)
#define NAVIGATION_NAVMUONID_H
// -*- C++ -*-
//
// Package: Navigation
// Module: NavMuonId
//
/**\class NavMuonId NavMuonId.h Navigation/NavMuonId.h
Description: Muon id info
Usage: through member functions
Note that there are two pre-packaged muon id criteria, 1 and 2.
simpleMuonId1() is better for analyses that are extremely
sensitive to fakes in the momentum range
1.5-2 GeV/c.
The efficiency in this momentum range
is slightly smaller (~20%) than
the other simple cut (below), but has
8-10 times lower fake rates in that region.
simpleMuonId2() is better for analyses that are extremely
sensitive to having high eff in the momentum
range 1.5-2 GeV/c.
The efficiency in this momentum range
is slightly larger (~20%) than
the other simple cut (above), but has
8-10 times higher fake rates in that region.
Both "simple" criteria require track momentum (pion hypothesis)
exceeding 1 GeV/c, matched calorimeter energy between
0.1 and 0.6 GeV, muon quality word muqual=0, and
the depth of penetration into the muon system of
3 interaction lengths at "low" momentum and 5 at "high"
momentum. They differ only in the borderline between
"low" and "high" momentum, which is 1.5 GeV/c for
the first criterion and 2.0 GeV/c for the second.
The user is referred to CBX 95-35, 96-41(Appendix A), 97-59.
Of course, the user is free to bypass these prepackaged
criteria but using the depth(), matchedEnergy(), and/or
member functions of the associated MuTrack object.
Please note that the depth() function returns 0
in two cases: there was no muon system response for
this track, or there was a matching muon response
but it had non-zero muqual. Experience shows muon
id is only reliable if muqual=0 is required.
*/
//
// Author: Brian K. Heltsley
// Created: Thu Jun 1 08:59:07 EDT 2000
// $Id: NavMuonId.h,v 1.4 2002/08/06 17:09:20 cleo3 Exp $
//
// Revision history
//
// $Log: NavMuonId.h,v $
// Revision 1.4 2002/08/06 17:09:20 cleo3
// removed use of FAItem to decrease dependencies
//
// Revision 1.3 2001/09/07 18:04:02 cleo3
// removed forward declaration of ostream
//
// Revision 1.2 2000/08/11 00:21:09 bkh
// Add operator<< functionality to these classes
//
// Revision 1.1 2000/06/06 18:38:59 bkh
// Install dedx, electron id, and muon id interfaces
//
// system include files
// user include files
#include "FrameAccess/FAItem.h"
#include "C3cc/CcTypes.h"
// forward declarations
#include "C++Std/fwd_ostream.h"
class MuTrack ;
class NavTrack ;
class NavMuonId ;
ostream& operator<<( ostream& os, const NavMuonId& aMu ) ;
class NavMuonId
{
// ---------- friend classes and functions ---------------
public:
// ---------- constants, enums and typedefs --------------
// ---------- Constructors and destructor ----------------
NavMuonId( const NavTrack& aNavTrack ,
const MuTrack* aMuTrack ) ;
virtual ~NavMuonId() {}
// ---------- member functions ---------------------------
// ---------- const member functions ---------------------
DABoolean simpleMuonId1() const ; // simple, reliable muon id
// "one-stop shopping"
// 0.1 < Ematched < 0.6 GeV &&
// p>1.0 && muqual==0 &&
// dpthmu>3(5) for p<1.5(>1.5)
DABoolean simpleMuonId2() const ; // simple, reliable muon id
// "one-stop shopping"
// 0.1 < Ematched < 0.6 GeV &&
// p>1.0 && muqual==0 &&
// dpthmu>3(5) for p<2(>2)
Real depth() const ; // dpthmu if muqual==0; else 0
CcGeV matchedEnergy() const ; // 0 if no match (from tk-shw match)
FAItem< MuTrack > muTrack() const ; // access for the expert
// ---------- static member functions --------------------
protected:
// ---------- protected member functions -----------------
// ---------- protected const member functions -----------
private:
// ---------- Constructors and destructor ----------------
NavMuonId( const NavMuonId& ); // stop default
// ---------- assignment operator(s) ---------------------
const NavMuonId& operator=( const NavMuonId& ); // stop default
// ---------- private member functions -------------------
// ---------- private const member functions -------------
// ---------- data members -------------------------------
DABoolean m_simple1 ;
DABoolean m_simple2 ;
Real m_depth ;
CcGeV m_energy ;
const MuTrack* m_muTrack ;
// ---------- static data members ------------------------
};
// inline function definitions
#endif /* NAVIGATION_NAVMUONID_H */
|
51d9ed9395dae33cf17232c165fc5d1fd7bc7848
|
120fbb2b537fd6db34eadc07336192abc0f980ba
|
/src/TestDataCreation.h
|
7090575a3946285c0a917ebf8aa31b94d0c63ae6
|
[] |
no_license
|
soonraah/dstclst
|
639679d5c93e6ede5777be73c764dc72b8ad98e2
|
8507507245ac1561e28526436097e94c4d801f70
|
refs/heads/master
| 2020-04-22T03:42:24.868886
| 2012-08-24T00:53:29
| 2012-08-24T00:53:29
| 5,278,144
| 2
| 0
| null | null | null | null |
SHIFT_JIS
|
C++
| false
| false
| 35,427
|
h
|
TestDataCreation.h
|
/**************************************************************************//**
* @file TestDataCreation.h
*****************************************************************************/
#include <vector>
#include <cmath>
//! 1000個のデータ間の距離テーブルを作る(doc/TestDataMaking.xls の Data_Large, Graph_Large)
void setDataDistance1( std::vector< std::vector< float > >& distTbl )
{
int numData = 1000;
// 領域の確保
distTbl.clear();
distTbl.reserve( numData );
distTbl.resize( numData );
for( int i = 0; i < numData; ++i )
{
distTbl[ i ].reserve( i );
distTbl[ i ].resize( i );
}
// 元のxy座標情報
// 距離で情報を持つとこのソースが大きくなりすぎるので。。。
float coordinate[ 1000 ][ 2 ] = {
{5.414618645f, 5.142687625f},
{6.346431411f, 5.395244593f},
{3.552669138f, 9.247060959f},
{2.439113868f, 6.896929731f},
{6.050667005f, 0.950500822f},
{6.469817946f, 1.67622054f},
{1.633904433f, 4.730010406f},
{5.878940417f, 8.32391405f},
{1.378369966f, 4.782340337f},
{5.69689017f, 3.213838927f},
{2.927922004f, 7.414707489f},
{5.236064981f, 2.115628991f},
{1.920803531f, 6.407842209f},
{2.068545314f, 4.869467732f},
{8.485964538f, 3.14083428f},
{6.499254817f, 2.944219273f},
{5.470029382f, 4.998400343f},
{1.619190951f, 6.03211684f},
{7.165521483f, 5.755645701f},
{5.121484797f, 8.406719533f},
{3.982175122f, 6.521830556f},
{8.582533974f, 3.797164711f},
{7.694563776f, 4.98096195f},
{8.715683559f, 4.7814113f},
{7.935538814f, 2.380993791f},
{5.708026593f, 3.292473535f},
{2.7046615f, 3.95470668f},
{6.025869572f, 3.037538325f},
{0.768256836f, 6.118741792f},
{2.565836165f, 8.308501721f},
{1.027204987f, 7.086478339f},
{6.788265073f, 3.052362653f},
{1.127037772f, 3.986805789f},
{0.808357498f, 4.99568639f},
{8.204504172f, 2.642958348f},
{5.909986383f, 6.441758455f},
{5.000960797f, 6.275251106f},
{7.323025285f, 7.175689945f},
{3.982412377f, 4.483158924f},
{1.560119717f, 6.349776628f},
{1.82622288f, 4.354568711f},
{3.343159748f, 3.647909306f},
{6.199456264f, 1.969631002f},
{5.400022336f, 6.956313744f},
{5.361088981f, 3.176886989f},
{2.423359068f, 4.100657902f},
{6.087781005f, 7.533433818f},
{3.448058864f, 1.558659548f},
{8.901597138f, 5.17421497f},
{8.888270078f, 3.514470397f},
{7.127230876f, 5.655667003f},
{4.025494772f, 3.52272888f},
{4.715089277f, 2.134614379f},
{8.140189479f, 3.348815619f},
{1.644173522f, 6.941726879f},
{3.22302792f, 3.883323379f},
{6.91138684f, 5.184744769f},
{8.106094236f, 7.334679179f},
{5.30189658f, 6.507996019f},
{1.686243986f, 6.050032122f},
{5.825746284f, 6.236242067f},
{3.520115641f, 2.619510629f},
{0.924949332f, 4.737289655f},
{0.926359977f, 5.01357665f},
{6.614344917f, 1.7265032f},
{5.379033494f, 4.318975319f},
{4.001054817f, 6.695067295f},
{6.620822775f, 2.405083236f},
{4.346561494f, 2.450597085f},
{4.851044249f, 4.763035134f},
{3.002157006f, 6.025959678f},
{4.283592447f, 5.267187911f},
{3.263249898f, 6.467244155f},
{7.010240889f, 8.665566786f},
{1.931199912f, 7.95549336f},
{7.383915298f, 7.123109356f},
{1.803234385f, 2.559087664f},
{1.771283574f, 2.668963424f},
{7.74226595f, 4.899569602f},
{7.890080386f, 2.184069245f},
{3.513901613f, 1.52697315f},
{7.484689721f, 4.283915501f},
{5.269166255f, 6.748276586f},
{2.43561895f, 2.726453737f},
{5.376149845f, 7.416032968f},
{5.588260075f, 1.894974414f},
{7.342123756f, 1.451387287f},
{3.084629698f, 0.965497956f},
{7.339026503f, 8.449733089f},
{7.490123224f, 3.681785977f},
{7.095046676f, 3.921364016f},
{6.890913326f, 8.173446035f},
{4.260568689f, 2.593682538f},
{8.972315634f, 4.099036561f},
{5.106765606f, 5.60027438f},
{3.141822909f, 6.492907504f},
{5.613042923f, 5.521386319f},
{3.211582867f, 0.933645606f},
{7.599239748f, 4.924088467f},
{4.873492045f, 6.746731992f},
{1.683998708f, 5.198912752f},
{9.294669864f, 5.954531743f},
{2.930217827f, 8.576530692f},
{4.05435659f, 3.832568962f},
{2.659881497f, 8.811230213f},
{6.14010447f, 3.74607076f},
{2.750058238f, 7.332252514f},
{6.533011088f, 5.372990733f},
{2.999129124f, 1.367010171f},
{4.244468355f, 9.182306204f},
{4.623916328f, 3.150468379f},
{5.759098298f, 3.552413612f},
{5.415145937f, 6.028839966f},
{7.420734915f, 8.747029312f},
{5.590285205f, 1.909575323f},
{6.987153186f, 2.569102585f},
{2.222003281f, 5.875228944f},
{2.127795348f, 7.647564716f},
{1.252435694f, 4.36691292f},
{3.300910809f, 8.280028823f},
{2.91768974f, 2.790784071f},
{3.381711693f, 7.136610097f},
{8.701731399f, 5.607148846f},
{4.41026669f, 8.503468813f},
{4.276565013f, 4.48495833f},
{7.442808978f, 1.736551654f},
{5.979797203f, 3.652645013f},
{4.970193372f, 7.825241671f},
{5.968431003f, 8.518415207f},
{6.103858534f, 8.99816452f},
{6.558206603f, 5.80683805f},
{1.212327294f, 4.856437623f},
{8.327305017f, 5.043840325f},
{5.967249022f, 3.369761228f},
{6.925527519f, 1.172858359f},
{4.466809017f, 2.894022138f},
{9.368151917f, 5.530415215f},
{5.255420524f, 6.121084224f},
{8.860413347f, 5.346831487f},
{8.905140585f, 6.186295088f},
{2.96420808f, 4.424580104f},
{8.871502623f, 6.896643134f},
{1.844654931f, 6.941420546f},
{4.398933528f, 4.315958689f},
{4.802863498f, 3.545562418f},
{8.235468244f, 2.042814544f},
{7.798682868f, 5.152508099f},
{4.22456778f, 4.121874479f},
{7.487587276f, 2.653303768f},
{8.335831751f, 6.54863632f},
{3.496385566f, 2.95029684f},
{2.554042726f, 6.241781432f},
{7.420695872f, 5.606775333f},
{7.94220927f, 2.040076358f},
{8.279280913f, 5.867988808f},
{7.886363535f, 2.553999558f},
{3.213064936f, 1.30138287f},
{6.812759718f, 8.683239424f},
{4.868727605f, 1.765239485f},
{2.382540599f, 1.939357117f},
{2.423316873f, 7.604828706f},
{7.826418774f, 3.443388985f},
{2.322327389f, 6.857081089f},
{7.202896211f, 5.950440446f},
{1.769987098f, 4.14113046f},
{7.247153467f, 6.216484476f},
{5.702212343f, 7.666603973f},
{4.251321453f, 7.32225999f},
{5.705872539f, 7.018345084f},
{0.64530139f, 4.152158712f},
{6.345763185f, 1.04114397f},
{4.953079487f, 3.065693845f},
{4.268038951f, 8.609834852f},
{8.421900717f, 4.430176174f},
{5.666000589f, 5.89242594f},
{9.35661033f, 3.990621044f},
{1.422478968f, 6.057478961f},
{6.393599821f, 2.317188394f},
{2.117439405f, 3.804276142f},
{2.960467752f, 8.084062134f},
{4.042304252f, 9.068330903f},
{7.494510471f, 8.670238093f},
{6.606389107f, 2.382587956f},
{2.390666159f, 6.093321548f},
{7.937531216f, 3.501636073f},
{3.132027973f, 8.835405811f},
{3.453481557f, 5.856498281f},
{2.941537958f, 6.551393708f},
{6.551996095f, 7.957246859f},
{3.647754961f, 5.517937942f},
{2.209520612f, 6.991059919f},
{6.190246599f, 2.639381159f},
{1.456559694f, 4.43769381f},
{3.681536339f, 1.370260865f},
{0.92031107f, 4.649541074f},
{6.732414399f, 2.874246842f},
{5.673334328f, 9.032280627f},
{6.581148281f, 7.877060741f},
{5.755547449f, 5.942121399f},
{5.865292262f, 7.188479733f},
{6.857701535f, 2.254655895f},
{6.56858827f, 1.146322798f},
{8.692066905f, 4.327363968f},
{2.548769273f, 3.525640441f},
{5.385764395f, 5.696647399f},
{4.613758179f, 4.672557935f},
{0.834314792f, 5.598336177f},
{8.603932288f, 5.577223289f},
{7.819165642f, 2.603211928f},
{2.722664678f, 7.873692721f},
{6.145585192f, 0.737438096f},
{6.306188071f, 6.080227252f},
{6.292672449f, 6.171250394f},
{3.655395727f, 6.757357074f},
{5.489220769f, 2.898855738f},
{7.982771996f, 5.742351808f},
{6.110711894f, 0.968734627f},
{1.242084285f, 3.260857937f},
{1.375535137f, 7.05852425f},
{6.963634558f, 4.280951881f},
{8.218691919f, 8.079312397f},
{3.578262678f, 7.354755836f},
{3.390029189f, 2.625094306f},
{8.584370122f, 3.499357514f},
{7.445166655f, 3.139733973f},
{1.033375968f, 4.032212605f},
{5.244519806f, 7.266207488f},
{6.178356647f, 7.590201138f},
{2.383137837f, 6.899274731f},
{8.047037849f, 7.697213971f},
{8.405212548f, 3.053892488f},
{5.346053807f, 2.042919385f},
{3.14090023f, 4.263312925f},
{6.533403914f, 6.465374042f},
{6.657175528f, 5.131872242f},
{2.238705691f, 6.483486551f},
{6.19984604f, 6.368531409f},
{7.922556275f, 8.23065935f},
{4.47602344f, 5.407274975f},
{4.807326551f, 7.311220017f},
{5.679593843f, 5.038464071f},
{2.991718228f, 5.475666351f},
{9.174046752f, 4.613304918f},
{4.448823754f, 9.291153915f},
{2.941974213f, 3.75190327f},
{4.665339192f, 9.368759085f},
{8.731815675f, 4.560013569f},
{2.987069989f, 2.331079649f},
{1.454408879f, 6.539059202f},
{3.4027064f, 1.109651208f},
{4.998924313f, -6.389226303f},
{3.625832134f, -6.352655487f},
{4.630008771f, -5.790292392f},
{3.606044096f, -4.9558245f},
{2.486850702f, -2.46056303f},
{4.99827211f, -5.285266028f},
{5.460512312f, -8.028821339f},
{1.550388125f, -3.681475871f},
{8.803486477f, -4.595619124f},
{3.06112134f, -2.268068628f},
{1.097999027f, -3.844128254f},
{4.650595924f, -1.237576245f},
{3.526748921f, -7.790831794f},
{9.383366042f, -4.309190102f},
{4.378518837f, -4.709408866f},
{7.651012129f, -8.622568723f},
{3.61325015f, -7.527373368f},
{4.446875207f, -1.758765196f},
{2.12548186f, -6.579165264f},
{7.717455834f, -7.294270436f},
{5.624763257f, -7.182213531f},
{5.819818567f, -1.51787901f},
{4.454156165f, -8.328517149f},
{3.537955056f, -7.002830013f},
{6.635132571f, -3.467134143f},
{2.641048009f, -4.388146534f},
{5.799287876f, -2.537818044f},
{5.507912988f, -5.05178034f},
{4.032757684f, -1.87327043f},
{5.864227599f, -6.322334096f},
{5.886638681f, -1.43546789f},
{8.515019189f, -6.909758176f},
{7.758336804f, -5.111337855f},
{6.107524148f, -2.37149703f},
{6.475585974f, -7.54784684f},
{4.171732402f, -4.206716904f},
{2.433063891f, -8.274882796f},
{4.509635071f, -2.995979599f},
{7.420944461f, -6.539440326f},
{4.288627635f, -9.305970112f},
{5.462537419f, -6.04728583f},
{3.288799408f, -3.512180115f},
{7.948992276f, -5.573202417f},
{1.978743168f, -2.369887348f},
{7.395203351f, -7.057040253f},
{1.687296682f, -2.078966769f},
{5.637157907f, -9.433433665f},
{3.626054819f, -4.41992063f},
{7.32408726f, -1.824178167f},
{4.075670319f, -2.688046733f},
{3.763982942f, -2.626582362f},
{4.868832525f, -1.846071516f},
{2.196917125f, -6.300113614f},
{3.809960903f, -6.197936491f},
{2.890113431f, -6.072756149f},
{3.720415716f, -6.442106943f},
{0.980918983f, -3.863780201f},
{6.928714771f, -5.438805701f},
{6.339015917f, -8.137899509f},
{8.627539864f, -3.686923486f},
{0.562568459f, -5.048918203f},
{4.916267856f, -1.566105382f},
{4.608659118f, -6.061762938f},
{0.806816463f, -4.529657632f},
{6.093371754f, -4.650529733f},
{0.871151199f, -4.455498615f},
{3.133548606f, -5.030991257f},
{3.711217511f, -7.324164048f},
{3.200599144f, -2.150651665f},
{5.108568651f, -4.844625965f},
{2.363715469f, -3.957029582f},
{2.055493224f, -7.478809764f},
{6.841282502f, -2.547793604f},
{3.716940721f, -8.158456415f},
{7.013093699f, -5.805083371f},
{4.429260816f, -3.063346268f},
{2.796778117f, -3.672958344f},
{2.760685284f, -8.380110599f},
{2.936823168f, -5.656620338f},
{2.342429816f, -7.888926617f},
{1.144365886f, -2.779670079f},
{0.876204348f, -6.155633489f},
{2.198738523f, -1.722064013f},
{4.766479219f, -4.881346242f},
{2.984004539f, -8.446815174f},
{6.12283028f, -2.07134022f},
{1.36669976f, -2.74735862f},
{5.792298988f, -8.214197351f},
{6.520756982f, -7.516191952f},
{4.547750036f, -8.596253474f},
{6.83143273f, -8.4452365f},
{4.979871015f, -3.149542488f},
{2.863011778f, -2.369845024f},
{5.029148363f, -7.579974892f},
{6.538629282f, -1.807316272f},
{4.92466137f, -5.704089881f},
{4.732258713f, -7.040618737f},
{3.67342796f, -6.271924846f},
{2.210322195f, -5.482111957f},
{3.157188307f, -6.87906192f},
{4.288035674f, -5.983753086f},
{1.354602261f, -7.551258885f},
{6.75953563f, -6.53054739f},
{8.564456307f, -5.118432984f},
{4.625364779f, -1.406514069f},
{4.89390116f, -5.18149347f},
{8.609706455f, -3.484693062f},
{6.368287091f, -2.818141603f},
{0.78094514f, -4.881649742f},
{5.862420667f, -7.535585846f},
{3.633168317f, -4.534370833f},
{8.592245929f, -2.514942025f},
{3.092616832f, -2.067373624f},
{7.175818058f, -7.409459318f},
{1.635304675f, -3.937959915f},
{6.474575894f, -6.237354326f},
{6.333020984f, -1.985831892f},
{2.994392574f, -6.834947901f},
{5.001365765f, -1.180941666f},
{4.667987508f, -4.46977209f},
{8.331616513f, -2.730875687f},
{5.742482005f, -7.322344712f},
{4.887585852f, -9.221202227f},
{3.276538715f, -1.026360249f},
{4.276848673f, -4.487348133f},
{3.36307419f, -4.244781614f},
{8.836414368f, -2.750574978f},
{7.921232349f, -8.023847412f},
{3.046881352f, -5.431689553f},
{1.559867591f, -2.540011469f},
{7.294366603f, -3.607460017f},
{1.842071432f, -5.312779241f},
{8.649592166f, -6.810995343f},
{8.058798178f, -8.16466473f},
{4.41749615f, -8.779703955f},
{2.091772904f, -2.282251113f},
{9.033994338f, -3.411557521f},
{1.512863741f, -7.620734631f},
{5.545652511f, -7.840396743f},
{0.831219498f, -5.358783879f},
{0.933378691f, -5.432437784f},
{4.521397429f, -6.117649771f},
{8.143616105f, -3.781956962f},
{5.566306873f, -3.981056214f},
{1.911311431f, -4.68071155f},
{4.775106027f, -6.687747315f},
{7.107638619f, -3.964340761f},
{2.859754103f, -2.552649948f},
{6.410215993f, -1.919934681f},
{3.085367686f, -9.008621098f},
{5.484595019f, -6.168205012f},
{1.980968374f, -5.626725352f},
{8.282505462f, -7.514682244f},
{7.083357643f, -6.602310674f},
{7.178777723f, -2.979507338f},
{4.36028641f, -4.388296464f},
{3.094207421f, -5.639872758f},
{3.351642749f, -7.956395003f},
{6.098074696f, -0.953570823f},
{1.529632978f, -4.671743887f},
{1.60329308f, -4.504876955f},
{2.74355629f, -5.306565187f},
{8.18551179f, -2.558545942f},
{5.566164019f, -0.703466239f},
{7.304072972f, -2.18851291f},
{3.93376007f, -2.301889837f},
{9.182385973f, -3.504244413f},
{4.903271448f, -4.873035481f},
{3.942805674f, -3.445109282f},
{1.503060477f, -6.577625909f},
{1.961051243f, -6.401651045f},
{7.480450005f, -5.582807405f},
{5.023501908f, -7.685876246f},
{5.133119969f, -9.257787636f},
{8.306652484f, -4.351600277f},
{5.877575724f, -2.286593225f},
{6.569492307f, -8.866778466f},
{1.996526314f, -5.622452456f},
{3.416061564f, -8.392162171f},
{5.713778974f, -2.162754753f},
{2.882500982f, -4.255551234f},
{2.622611839f, -3.093859f},
{3.487867253f, -4.687468463f},
{6.721068553f, -3.299797474f},
{4.929394102f, -3.849976017f},
{1.712210562f, -6.242793746f},
{5.327270276f, -4.253584889f},
{8.488599275f, -5.464190548f},
{4.035890833f, -3.101169243f},
{5.977708714f, -2.251804501f},
{9.018988953f, -4.415187632f},
{2.998308723f, -6.825689876f},
{4.007790052f, -6.781310257f},
{5.315789395f, -2.923025598f},
{1.981107187f, -7.668058977f},
{8.395248198f, -3.871620222f},
{2.520262049f, -3.804401819f},
{4.960441404f, -6.256437777f},
{5.960532581f, -7.642260127f},
{8.780036631f, -3.847699499f},
{0.824342803f, -4.935303852f},
{2.956179059f, -2.726959515f},
{3.658231994f, -6.993662181f},
{3.301981414f, -8.995904436f},
{7.862688637f, -5.009324415f},
{4.173034687f, -6.757067862f},
{5.109804609f, -4.578951351f},
{0.708576926f, -5.16931128f},
{1.028815755f, -5.023993717f},
{3.724342091f, -3.193918539f},
{6.626892388f, -1.162869861f},
{4.660614692f, -6.932587233f},
{4.66334266f, -2.370601175f},
{6.974291627f, -5.11613008f},
{6.175638814f, -6.784857209f},
{8.860117982f, -2.707578121f},
{3.406792402f, -5.399326873f},
{9.344497112f, -5.912390735f},
{7.446676465f, -6.14506827f},
{6.525201113f, -6.786963105f},
{4.465800963f, -1.368600399f},
{7.974248884f, -4.47793132f},
{1.915825688f, -3.593487642f},
{3.180296577f, -8.690762482f},
{6.877142921f, -3.290226997f},
{4.747192188f, -1.842669092f},
{1.665038609f, -7.869782353f},
{4.86452949f, -2.618815955f},
{1.847707093f, -2.697145522f},
{3.199223279f, -5.084061147f},
{9.405181245f, -5.870268781f},
{2.706769515f, -6.747519074f},
{2.5891877f, -5.502653308f},
{5.246707673f, -6.933730576f},
{5.551477019f, -6.684031003f},
{4.800936743f, -0.597930217f},
{1.247036406f, -5.362627917f},
{2.497038935f, -7.228690905f},
{2.253703887f, -4.960337409f},
{0.847609909f, -4.115250354f},
{2.915772966f, -1.195481925f},
{2.450573774f, -1.335716956f},
{6.519226878f, -8.410975044f},
{1.904140432f, -6.70174182f},
{3.030263509f, -8.062047782f},
{1.977434575f, -4.756124519f},
{8.84011199f, -6.637068981f},
{4.197741515f, -4.480631554f},
{6.834013355f, -1.082138052f},
{4.320108355f, -5.283461618f},
{-1.524162152f, -3.949022375f},
{-6.957962186f, -2.029404408f},
{-1.559740297f, -4.754511902f},
{-5.80656279f, -9.334302679f},
{-7.48000563f, -5.483178752f},
{-7.706947409f, -6.394009871f},
{-7.052858622f, -3.908162427f},
{-7.178022496f, -8.904886603f},
{-0.543335537f, -4.450639833f},
{-2.966828579f, -6.991275371f},
{-3.807876834f, -3.811424183f},
{-6.066595912f, -3.050750067f},
{-3.374766007f, -8.130064683f},
{-2.137780211f, -7.026551733f},
{-6.650878678f, -5.890994968f},
{-2.431422617f, -7.02608443f},
{-6.054972986f, -3.022618015f},
{-1.922968579f, -3.1465237f},
{-6.068319653f, -0.638765437f},
{-6.993829347f, -0.997298723f},
{-8.492912827f, -7.047867095f},
{-7.606213009f, -5.14864668f},
{-8.937811803f, -5.847937572f},
{-8.897445508f, -3.52678577f},
{-2.653353248f, -7.512092132f},
{-4.072152102f, -3.864034416f},
{-3.127851259f, -4.901540368f},
{-7.677423381f, -4.936787526f},
{-8.353454993f, -4.859887494f},
{-6.476760379f, -5.053706406f},
{-5.897436866f, -6.764346278f},
{-5.602158946f, -1.688970954f},
{-2.593872924f, -2.089224296f},
{-8.190185045f, -3.987197967f},
{-5.753901374f, -4.042613503f},
{-3.990791856f, -4.974964313f},
{-8.600022342f, -7.004448229f},
{-7.688110666f, -7.689772713f},
{-4.149522952f, -0.949715229f},
{-8.447653129f, -4.665292497f},
{-5.641636465f, -2.405160537f},
{-7.667639887f, -6.803370113f},
{-4.493175326f, -5.382234863f},
{-2.607854252f, -2.201257615f},
{-5.776220476f, -6.488321078f},
{-7.145097166f, -1.27276146f},
{-8.170637422f, -5.769608409f},
{-0.967510389f, -6.035899417f},
{-4.337526275f, -2.574256212f},
{-3.415725095f, -8.415142616f},
{-5.326507689f, -5.312531939f},
{-1.159961361f, -3.74291361f},
{-5.579287632f, -6.318834925f},
{-2.844254363f, -1.990787795f},
{-8.486495409f, -4.234833272f},
{-2.037104309f, -6.331654381f},
{-7.572196458f, -7.051959224f},
{-4.510041142f, -2.380837528f},
{-0.916509851f, -6.873452103f},
{-5.523179088f, -0.85788763f},
{-4.318029236f, -6.37871278f},
{-5.852963267f, -6.468390317f},
{-7.346961661f, -3.345427989f},
{-5.043860503f, -6.804773269f},
{-4.283591258f, -2.751968821f},
{-4.695655321f, -6.884659787f},
{-8.720872752f, -5.172976128f},
{-5.792185814f, -6.580342507f},
{-3.546798772f, -7.759648367f},
{-7.900959193f, -4.56886037f},
{-4.175964487f, -1.259150304f},
{-6.588942265f, -1.218240647f},
{-7.943637186f, -2.463559682f},
{-2.229095631f, -6.283070069f},
{-2.116743885f, -2.004937488f},
{-3.016472182f, -8.397884451f},
{-4.356835711f, -9.013595021f},
{-2.624576388f, -4.819244867f},
{-7.807393579f, -5.671418108f},
{-2.837762018f, -5.952496409f},
{-2.308081907f, -7.424893307f},
{-5.712680975f, -5.938273207f},
{-7.941329984f, -4.440260146f},
{-0.771933047f, -3.71482243f},
{-8.671629383f, -5.995032859f},
{-5.374930635f, -3.535985191f},
{-4.503579527f, -3.396615882f},
{-3.033940249f, -7.033727753f},
{-4.771944049f, -1.825286103f},
{-6.625980278f, -8.761875048f},
{-9.078655483f, -4.218143678f},
{-1.88398213f, -5.870470686f},
{-4.952390432f, -7.733934578f},
{-8.268299581f, -3.415980625f},
{-6.686193238f, -3.909388407f},
{-7.901327895f, -4.258192365f},
{-6.201856236f, -9.145824386f},
{-4.868768966f, -2.159475516f},
{-4.520852544f, -5.990173432f},
{-4.447015372f, -7.845675947f},
{-7.944746679f, -7.822301526f},
{-9.305610772f, -5.55616018f},
{-5.899753657f, -5.648327068f},
{-5.422334809f, -1.452935565f},
{-3.691799087f, -7.608318759f},
{-3.155470125f, -4.434970671f},
{-2.157015448f, -7.38437901f},
{-2.911121857f, -4.744246172f},
{-7.372072539f, -6.7529231f},
{-6.064062924f, -4.233002224f},
{-5.929986098f, -8.035077683f},
{-7.528096053f, -4.675317481f},
{-3.390715799f, -4.008894046f},
{-1.252011906f, -3.026972522f},
{-2.752830181f, -5.393509127f},
{-5.259667135f, -3.493988738f},
{-2.312523752f, -7.106347976f},
{-7.598420014f, -7.361857589f},
{-4.388321703f, -9.006777744f},
{-1.619848399f, -5.922195192f},
{-4.670799976f, -5.949880265f},
{-7.178224999f, -1.720773055f},
{-7.92616133f, -7.726638503f},
{-7.285061042f, -5.372986179f},
{-2.682448407f, -8.603190415f},
{-6.925329988f, -4.096390632f},
{-3.518750907f, -9.076218647f},
{-4.845897674f, -3.461206236f},
{-6.100010815f, -8.112258884f},
{-5.333764354f, -5.304250446f},
{-9.283126253f, -5.705337714f},
{-3.284883648f, -7.918697838f},
{-3.345021169f, -3.963591737f},
{-2.749723135f, -1.900866542f},
{-7.238194932f, -3.009917155f},
{-6.956092202f, -5.922913065f},
{-6.143249416f, -2.835409885f},
{-2.656186661f, -1.499261816f},
{-1.754776572f, -8.103325562f},
{-8.544162355f, -3.982472856f},
{-1.859309448f, -3.980749834f},
{-3.613437792f, -6.558945498f},
{-2.558383913f, -5.960964064f},
{-5.129675278f, -4.645395429f},
{-7.802896106f, -5.171971338f},
{-2.834151355f, -2.769872949f},
{-1.303745702f, -2.632296551f},
{-7.413420323f, -4.89790308f},
{-2.06969219f, -3.135646055f},
{-2.799224308f, -2.462278662f},
{-7.657803378f, -7.389725183f},
{-5.857287301f, -2.540905165f},
{-5.405425917f, -5.341954494f},
{-6.237661078f, -2.669946931f},
{-7.008156895f, -6.081679732f},
{-5.876772968f, -3.005711712f},
{-5.574151465f, -4.821917564f},
{-6.852426918f, -4.534221054f},
{-3.670745204f, -8.97305769f},
{-5.121638785f, -9.45902374f},
{-3.226727594f, -3.723313903f},
{-4.628136694f, -3.073725509f},
{-4.600124249f, -7.533233284f},
{-3.676328244f, -6.840192036f},
{-4.202182063f, -5.010315119f},
{-4.093607433f, -0.950475158f},
{-2.712135761f, -5.465127473f},
{-8.060446228f, -2.312883073f},
{-2.901127121f, -4.641048227f},
{-4.36012372f, -6.919376197f},
{-5.963479213f, -8.578285549f},
{-5.367141919f, -7.68767237f},
{-6.977668704f, -1.947076628f},
{-4.321787507f, -3.504418004f},
{-5.343817058f, -1.613009978f},
{-0.755093763f, -5.840423593f},
{-5.004400502f, -8.566934757f},
{-3.130873528f, -5.104327793f},
{-6.612560117f, -2.80699202f},
{-2.289026703f, -1.866270122f},
{-4.073475821f, -3.52760002f},
{-2.848576376f, -7.160014086f},
{-3.855575745f, -1.714895139f},
{-3.972431332f, -5.484376249f},
{-6.127586035f, -2.61035716f},
{-5.806517126f, -2.218186315f},
{-7.629110396f, -8.409229964f},
{-1.421951731f, -7.136565801f},
{-7.033022636f, -3.020319179f},
{-8.735938369f, -7.216408097f},
{-4.887738045f, -9.105189002f},
{-2.496368582f, -3.85018973f},
{-6.892999005f, -8.933721378f},
{-2.190188867f, -8.028255155f},
{-6.887767264f, -5.411317825f},
{-1.938610122f, -2.985234136f},
{-5.494089095f, -9.061604741f},
{-2.16546398f, -8.461228717f},
{-1.722259367f, -4.489309221f},
{-5.288192427f, -8.812665069f},
{-5.857042215f, -3.204607394f},
{-5.795838999f, -3.963652424f},
{-3.622674132f, -4.297544871f},
{-3.679341887f, -8.249400503f},
{-4.463852363f, -7.778252597f},
{-8.517378222f, -6.609979004f},
{-1.33128594f, -3.554037767f},
{-6.471811027f, -3.853482201f},
{-2.56552579f, -2.77059207f},
{-6.406614166f, -5.199068253f},
{-8.595308074f, -5.919560849f},
{-4.606661672f, -5.642576313f},
{-5.62807664f, -8.691207788f},
{-1.949644293f, -7.756461083f},
{-1.866907114f, -2.021507091f},
{-2.07823145f, -2.770885231f},
{-1.207779249f, -3.95977275f},
{-5.633245965f, -4.313785406f},
{-4.035394096f, -3.525880219f},
{-1.587936644f, -4.561922646f},
{-5.797015515f, -7.752908337f},
{-6.944878057f, -5.522060587f},
{-3.261188772f, -3.185177768f},
{-4.026076577f, -4.740553817f},
{-4.411330358f, -5.496922253f},
{-4.806202812f, -6.125040384f},
{-5.239434044f, -6.158369472f},
{-0.756692394f, -5.640656667f},
{-2.43371255f, -4.993821684f},
{-8.011760553f, -6.771101043f},
{-0.9316725f, -4.609447745f},
{-3.368799314f, -5.520392415f},
{-8.125874377f, -3.927808301f},
{-5.028037988f, -6.495042833f},
{-4.16598828f, -3.952958539f},
{-4.621616106f, -5.428241041f},
{-4.477157535f, -3.625485859f},
{-3.257274141f, -7.473347967f},
{-0.953064797f, -6.933080019f},
{-3.505205482f, -8.79915421f},
{-3.580509084f, -2.421310243f},
{-7.148629639f, -7.745105322f},
{-1.473510826f, -5.189266824f},
{-2.927580353f, -6.882350923f},
{-6.406367213f, -4.124511548f},
{-5.703369953f, -4.963962787f},
{-8.299585737f, -5.272559158f},
{-6.612098651f, -9.069781387f},
{-6.34542984f, -3.753518383f},
{-8.733624474f, -7.388559685f},
{-8.565870866f, 7.600999681f},
{-4.257305413f, 5.062600442f},
{-5.309623005f, 6.339994282f},
{-9.075857893f, 6.065952944f},
{-4.080511006f, 8.140547587f},
{-4.516922903f, 4.523068143f},
{-2.748871421f, 4.284351437f},
{-1.417257254f, 4.654859784f},
{-7.958832209f, 2.63104786f},
{-5.710311026f, 3.417084048f},
{-6.529105777f, 8.62197934f},
{-3.413662582f, 1.009625569f},
{-8.061662598f, 8.271096669f},
{-7.128622812f, 6.346294749f},
{-1.711512916f, 5.926098059f},
{-5.867307712f, 8.343142852f},
{-3.633750182f, 0.917052333f},
{-8.351981352f, 3.02473349f},
{-3.898914389f, 5.816900183f},
{-4.203693615f, 8.969617938f},
{-2.487295314f, 7.259887837f},
{-1.520743715f, 4.333054939f},
{-7.020667001f, 4.366284071f},
{-7.68438285f, 3.06105698f},
{-2.475190508f, 2.799581509f},
{-3.726841019f, 9.118374456f},
{-0.988907997f, 6.915821132f},
{-2.349170281f, 3.036191623f},
{-6.024291343f, 2.610578046f},
{-3.985430317f, 8.790603306f},
{-3.847427817f, 3.763115552f},
{-2.528904436f, 4.347018023f},
{-1.502786582f, 5.741781215f},
{-7.129537927f, 4.945363434f},
{-3.083879567f, 4.519163401f},
{-3.607172282f, 4.962202363f},
{-1.082514764f, 4.834913806f},
{-8.21764215f, 6.938112678f},
{-5.72525575f, 2.094423356f},
{-7.089346551f, 3.948568614f},
{-3.583662335f, 8.348017592f},
{-6.42936536f, 6.997441804f},
{-8.228406302f, 5.150086326f},
{-9.276330157f, 3.856927795f},
{-6.307105454f, 1.377814847f},
{-7.118875811f, 2.790359694f},
{-3.33647626f, 7.215284693f},
{-0.621846163f, 5.161957493f},
{-3.385676369f, 3.653605979f},
{-5.278970412f, 8.180430069f},
{-6.978710354f, 8.366659674f},
{-2.031819679f, 5.830324221f},
{-5.992177784f, 4.977791789f},
{-1.580353743f, 3.993555655f},
{-5.453350686f, 3.061957346f},
{-5.127001279f, 7.943622918f},
{-8.771454035f, 3.482853243f},
{-6.100464811f, 4.862115435f},
{-4.769568387f, 3.331478876f},
{-4.546445389f, 1.947661431f},
{-1.48815181f, 4.441335241f},
{-7.104291423f, 4.530929416f},
{-2.069925503f, 3.156970697f},
{-7.464613779f, 2.509852496f},
{-7.59039352f, 8.671570967f},
{-4.207474676f, 8.898514435f},
{-8.494849532f, 3.318355911f},
{-7.795021523f, 3.547783117f},
{-4.804289236f, 7.628015977f},
{-5.295124524f, 7.205287258f},
{-5.187043728f, 6.011958861f},
{-2.949228905f, 2.300408925f},
{-5.696780563f, 8.245225588f},
{-3.044266424f, 2.21048708f},
{-2.722787706f, 7.18979792f},
{-7.0531407f, 2.114173162f},
{-4.401106087f, 1.049267576f},
{-6.097713471f, 1.187257917f},
{-3.208864177f, 2.81728033f},
{-3.945015334f, 6.425827547f},
{-3.154794017f, 3.31033572f},
{-5.780196632f, 7.588969217f},
{-5.199152823f, 9.399581477f},
{-3.648302576f, 9.073755886f},
{-2.754451015f, 5.786988069f},
{-4.234423179f, 8.964155449f},
{-4.203568584f, 8.76475274f},
{-4.241446272f, 5.688606522f},
{-8.510989242f, 3.367203268f},
{-0.808400269f, 4.032043025f},
{-4.341816268f, 2.414593369f},
{-5.091403519f, 2.256184835f},
{-2.233143695f, 2.151641216f},
{-3.488510036f, 8.14635617f},
{-5.879252245f, 7.597213017f},
{-8.029065405f, 6.532149193f},
{-1.641072438f, 5.498741042f},
{-7.269058386f, 5.530185108f},
{-2.467723252f, 8.648673591f},
{-2.405289984f, 2.825151592f},
{-7.262007783f, 5.682237022f},
{-4.443659191f, 9.267808082f},
{-6.491998882f, 4.716026269f},
{-3.818794603f, 2.017311417f},
{-4.596518995f, 8.699420812f},
{-7.84129316f, 5.695484929f},
{-3.725802416f, 2.303473628f},
{-2.689636939f, 3.129414732f},
{-6.730932794f, 7.716333673f},
{-5.942139069f, 8.906731426f},
{-3.958910564f, 4.151877981f},
{-1.877387028f, 5.612611711f},
{-9.05478393f, 6.516026431f},
{-8.466665129f, 6.034639902f},
{-2.815924485f, 6.135766607f},
{-2.37012807f, 6.732819435f},
{-2.951588565f, 4.939839037f},
{-8.096240504f, 7.153281235f},
{-3.494455395f, 6.406146772f},
{-1.925218288f, 8.0738515f},
{-5.568350168f, 0.87833777f},
{-4.147442368f, 3.555646813f},
{-3.554380163f, 7.80457854f},
{-1.401352685f, 3.854356262f},
{-7.503620095f, 3.677271481f},
{-7.722866019f, 2.996417926f},
{-4.545411331f, 8.600396521f},
{-8.378993738f, 4.162945839f},
{-7.255227805f, 2.073719035f},
{-4.268551973f, 1.989085052f},
{-6.219838111f, 0.915120875f},
{-3.545700654f, 3.957291226f},
{-5.469176934f, 8.586488982f},
{-4.490861021f, 2.79972917f},
{-4.555588268f, 1.137426104f},
{-1.042340342f, 7.041160791f},
{-8.853851298f, 4.880540857f},
{-2.365053567f, 6.298751489f},
{-5.021065859f, 4.666988391f},
{-2.768683782f, 4.929611241f},
{-5.680948014f, 8.749705019f},
{-3.58584104f, 6.864068721f},
{-5.472945347f, 3.704223765f},
{-6.261179753f, 5.4172039f},
{-8.911716357f, 3.230596217f},
{-9.062893979f, 6.725602619f},
{-3.775507882f, 0.771224069f},
{-2.457980045f, 2.590919955f},
{-2.029984572f, 8.236276276f},
{-1.598859125f, 3.205520246f},
{-4.441712745f, 8.279502804f},
{-4.826154891f, 0.976799466f},
{-2.547984676f, 8.521162507f},
{-4.651153551f, 0.845783474f},
{-5.695090208f, 1.501537995f},
{-7.062970019f, 6.745558144f},
{-2.198574634f, 3.181157177f},
{-6.165064592f, 4.407131845f},
{-5.516621946f, 2.762268379f},
{-3.028368082f, 5.01562744f},
{-1.014054601f, 6.909270922f},
{-2.207290349f, 7.248515078f},
{-4.64748563f, 8.87923914f},
{-4.483032929f, 6.096954533f},
{-3.364451219f, 7.525586191f},
{-7.872688927f, 4.399434927f},
{-2.064272593f, 5.481845924f},
{-5.761115786f, 3.604977262f},
{-2.361380744f, 2.005608376f},
{-4.746312848f, 5.021575194f},
{-1.790154362f, 5.898244198f},
{-7.031117607f, 1.326779605f},
{-7.446207653f, 3.593653625f},
{-7.067365214f, 2.308385629f},
{-2.480025478f, 2.745838038f},
{-6.393838888f, 6.243795941f},
{-7.168231297f, 1.909696684f},
{-5.051215751f, 3.868751242f},
{-0.595118193f, 5.41436455f},
{-6.981432145f, 5.892958363f},
{-6.239043017f, 7.548283281f},
{-7.966423419f, 2.810528974f},
{-2.561786534f, 8.089249368f},
{-5.055978133f, 3.441692041f},
{-6.934524745f, 8.039714725f},
{-3.252478686f, 4.779094179f},
{-3.402876123f, 0.892005348f},
{-2.435186092f, 2.268577553f},
{-4.204852747f, 6.662637204f},
{-3.135767044f, 7.358212247f},
{-4.832211786f, 2.010656371f},
{-5.376860891f, 9.379270639f},
{-4.706612288f, 7.737197308f},
{-6.876254297f, 2.496196391f},
{-4.418698173f, 1.240070258f},
{-7.729667956f, 6.726129203f},
{-5.768291748f, 8.579621865f},
{-6.751753351f, 6.916217532f},
{-6.281397325f, 2.688050491f},
{-7.736422375f, 4.655937961f},
{-4.884006861f, 2.824139709f},
{-6.63356665f, 8.787525735f},
{-2.59140202f, 3.247816884f},
{-7.638542674f, 8.086707195f},
{-6.397968836f, 4.035223225f},
{-3.482773591f, 8.838380573f},
{-8.025159484f, 3.640677636f},
{-9.230738094f, 6.314570094f},
{-7.614119384f, 5.002386368f},
{-8.19610068f, 6.479042611f},
{-7.396662138f, 7.393487565f},
{-6.47479208f, 5.978135111f},
{-8.743251247f, 6.966149759f},
{-6.795112715f, 6.336316749f},
{-1.105905694f, 7.233130423f},
{-7.74999654f, 4.318262474f},
{-5.927234505f, 4.02357259f},
{-1.885763916f, 5.949642029f},
{-7.268201083f, 3.024838965f},
{-7.012486994f, 8.559448446f},
{-5.060688916f, 3.952778082f},
{-8.952754965f, 3.026344486f},
{-7.796971139f, 1.610134399f},
{-6.601188424f, 6.69628123f},
{-7.330157696f, 6.612357448f},
{-8.996524122f, 6.614173574f},
{-7.867242959f, 3.910635219f},
{-2.59566045f, 2.457956277f},
{-0.582805223f, 5.857627387f},
{-4.17956456f, 6.450757863f},
{-6.686293676f, 6.604556808f},
{-5.518482799f, 8.981042558f},
{-4.801798189f, 3.07720098f},
{-0.502656438f, 4.937830125f},
{-6.785163226f, 1.353271231f},
{-7.49016797f, 6.201933558f},
{-4.66045185f, 2.827653707f},
{-1.37352814f, 4.430212226f},
{-6.178675416f, 9.292319542f},
{-4.030888494f, 1.403671718f},
{-5.321340643f, 1.261092688f},
{-5.617755762f, 1.968227403f},
{-8.061104042f, 4.424363241f},
{-8.801353253f, 3.850898023f},
{-8.432063025f, 2.282307015f},
{-4.811110566f, 1.787067473f},
{-7.858931277f, 2.03203383f},
{-3.105540942f, 6.94628694f},
{-4.669957208f, 9.037719086f},
{-2.793461929f, 7.010099952f}
};
for( int i = 0; i < numData; ++i )
{
for( int j = 0; j < i; ++j )
{
// 2点間距離を計算してテーブルに格納
distTbl[ i ][ j ] = sqrt( pow( coordinate[ i ][ 0 ] - coordinate[ j ][ 0 ], 2 ) + pow( coordinate[ i ][ 1 ] - coordinate[ j ][ 1 ], 2 ) );
}
}
return;
}
//! 距離が0の関係を含む距離テーブルを作る
void setDataDistance2( std::vector< std::vector< float > >& distTbl )
{
int numData = 10;
// 領域の確保
distTbl.clear();
distTbl.reserve( numData );
distTbl.resize( numData );
for( int i = 0; i < numData; ++i )
{
distTbl[ i ].reserve( i );
distTbl[ i ].resize( i );
}
// 距離格納
for( int i = 0; i < numData; ++i )
{
for( int j = 0; j < i; ++j )
{
// (5, 4)のみ距離1.0で他は0にする。
distTbl[ i ][ j ] = ( i == 5 && j == 4 ) ? 1.0f : 0.0f;
}
}
}
|
70c779274347357e414112516faa4c2d1dca67be
|
7f676c9764673d8b446deb07b3f5823c113016c6
|
/components/utilities/i2cw.cpp
|
94477c7d5b20397aa48584fb70a4dc7d1bf9a020
|
[
"MIT"
] |
permissive
|
richardgedwards/guava
|
435bc96302cc459784ae4e54327918b15914ed02
|
82817e940174838cf2aa9ee5f8940f8588c9dc72
|
refs/heads/main
| 2023-02-07T12:21:54.741084
| 2020-12-24T00:18:39
| 2020-12-24T00:18:39
| 322,672,550
| 1
| 1
|
MIT
| 2020-12-24T00:22:51
| 2020-12-18T18:19:06
|
C++
|
UTF-8
|
C++
| false
| false
| 3,331
|
cpp
|
i2cw.cpp
|
#include "i2cw.h"
#include "esp_exception.h" // define THROW macro
#include "esp_log.h"
// I2CMaster
I2CMaster::I2CMaster(i2c_port_t port, int sda_io_num, int scl_io_num, uint32_t clk_speed)
: I2CBase(port, sda_io_num, scl_io_num)
{
_config.sda_pullup_en = GPIO_PULLUP_ENABLE;
_config.scl_pullup_en = GPIO_PULLUP_ENABLE;
_config.mode = I2C_MODE_MASTER;
_config.master.clk_speed = clk_speed;
i2c_param_config(_port, &_config);
i2c_driver_install(_port, _config.mode, 0, 0, 0);
}
void I2CDevice::readRegister(uint8_t register_address, uint8_t *data) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (_device_address << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write_byte(cmd, register_address, ACK_CHECK_EN);
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (_device_address << 1) | I2C_MASTER_READ, ACK_CHECK_EN);
i2c_master_read_byte(cmd, data, I2C_MASTER_NACK);
i2c_master_stop(cmd);
THROW(i2c_master_cmd_begin(_i2c.getPort(), cmd, 1000 / portTICK_RATE_MS));
i2c_cmd_link_delete(cmd);
}
void I2CDevice::writeRegister(uint8_t register_address, uint8_t data) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (_device_address << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write_byte(cmd, register_address, ACK_CHECK_EN);
i2c_master_write_byte(cmd, data, I2C_MASTER_ACK);
i2c_master_stop(cmd);
THROW(i2c_master_cmd_begin(_i2c.getPort(), cmd, 1000 / portTICK_RATE_MS));
i2c_cmd_link_delete(cmd);
}
void I2CDevice::read(uint8_t register_address, uint8_t *data, size_t data_len) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (_device_address << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write_byte(cmd, register_address, ACK_CHECK_EN);
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (_device_address << 1) | I2C_MASTER_READ, ACK_CHECK_EN);
i2c_master_read(cmd, data, data_len, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd);
THROW(i2c_master_cmd_begin(_i2c.getPort(), cmd, 1000 / portTICK_RATE_MS));
i2c_cmd_link_delete(cmd);
}
void I2CDevice::write(uint8_t register_address, uint8_t *data, size_t data_len) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (_device_address << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write_byte(cmd, register_address, ACK_CHECK_EN);
i2c_master_write(cmd, data, data_len, true);
i2c_master_stop(cmd);
THROW(i2c_master_cmd_begin(_i2c.getPort(), cmd, 1000 / portTICK_RATE_MS));
i2c_cmd_link_delete(cmd);
}
// I2CSlave
I2CSlave::I2CSlave(
i2c_port_t port,
int sda_io_num,
int scl_io_num,
uint16_t i2c_addr,
size_t rx_buf_length,
size_t tx_buf_length,
bool addr_10bit_en
) : I2CBase(port, sda_io_num, scl_io_num)
{
_config.sda_pullup_en = GPIO_PULLUP_DISABLE;
_config.scl_pullup_en = GPIO_PULLUP_DISABLE;
_config.mode = I2C_MODE_SLAVE;
_config.slave.slave_addr = i2c_addr;
_config.slave.addr_10bit_en = addr_10bit_en;
i2c_param_config(_port, &_config);
i2c_driver_install(_port, _config.mode, rx_buf_length, tx_buf_length, 0);
}
|
c2ea18a38abf5a8912621e1ca119072d1bf3b0a9
|
6737c2c4e8a45b11fa1a6284af4f17b120305343
|
/MyCDR/FixedRecordIteraor.cpp
|
9ecf6ed3abd9a8f1db96619e2b3eccb25e1404ed
|
[] |
no_license
|
anandrathi/MyCDR
|
6f072e47a2bb07eeffaa5ac0694bfcf686eb7fde
|
574e9bd81628819796b0b70372a3467fa5e27337
|
refs/heads/master
| 2021-01-13T01:37:07.879020
| 2012-03-13T01:52:16
| 2012-03-13T01:52:16
| 3,233,831
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,824
|
cpp
|
FixedRecordIteraor.cpp
|
#include "FixedRecordIteraor.h"
#include "ace/Log_Msg.h"
#include "cpptcl.h"
#include "FixedLocationRecord.h"
#include <sqrat.h>
FixedRecordIteraor::FixedRecordIteraor(RecordDetails* pRecordDetails):Recorditerator(pRecordDetails)
{
ACE_TRACE("FixedRecordIteraor::FixedRecordIteraor");
_data=0;
_RecordNumber=0;
_TotalRecords=0;
_currentRowData=_data;
_currentColData=_currentRowData;
_reclen=0;
RecordDetails::FIELDDETAILS::iterator it = _RecordDetails->GetFieldDetails()->begin();
RecordDetails::FIELDDETAILS::iterator eit = _RecordDetails->GetFieldDetails()->end();
for(;it !=eit ; it++ )
{
int len = (it->END - it->START) + 1;
_reclen+=len;
}
}
FixedRecordIteraor::~FixedRecordIteraor(void)
{
}
AR_INT64 FixedRecordIteraor::Prev(void)
{
return 0;
}
void FixedRecordIteraor::begin(void)
{
_currentRowData=_data;
_currentColData=_currentRowData;
_pos = Recorditerator::RECORDPOSITION_BEGIN;
_error = Recorditerator::RECORDERROR_BEGIN;
}
AR_INT64 FixedRecordIteraor::Next(void)
{
ACE_TRACE("FixedRecordIteraor::Next");
PARSESTATE s;
char * ps=_currentRowData;
char * psCol=_currentRowData;
char * pe=_currentRowData;
char * end = _data + this->_filesize;
RecordDetails::FIELDDETAILS::iterator it = _RecordDetails->GetFieldDetails()->begin();
RecordDetails::FIELDDETAILS::iterator eit = _RecordDetails->GetFieldDetails()->end();
int LINE_SEPERATOR=_RecordDetails->LINE_SEPERATOR;
psCol=ps;
if ( _currentRowData >= end )
{
_pos = Recorditerator::RECORDPOSITION_END;
return Recorditerator::RECORDPOSITION_END;
}
int i =0;
while(1)
{
if(*pe==LINE_SEPERATOR)
{
break;
}
if(pe>=end)
{
break;
}
pe++;
i++;
}
if(pe<=end)
{
if(pe<end)
{
_currentRowData=pe+1;
}
if(pe==end)
{
_currentRowData=pe;
}
}
_pos = Recorditerator::RECORDPOSITION_OK;
if( (pe-ps) != this->_reclen)
{
//bad record
ACE_ERROR((LM_ERROR, "(%t) FixedRecordIteraor::Next Length=%d dosent Match Data Len=%d\n", this->_reclen , (pe-ps) ));
_error=Recorditerator::RECORDERROR_BADLENGTH;
}
else
{
_error=RECORDERROR::RECORDERROR_GOOD;
for(;it!= eit ;it++)
{
it->END-it->START;
if(it->_RecordData.cell.capacity() < it->_RecordData.len)
{
it->_RecordData.cell.resize(it->_RecordData.len+1+1, 0);
}
memcpy(&it->_RecordData.cell[0], psCol, it->_RecordData.len);
psCol+=it->_RecordData.len;
}
}
//if ( _currentRowData >= end )
//{
// _pos = Recorditerator::RECORDPOSITION_END;
//}
_RecordNumber++;
return _RecordNumber;
}
AR_INT64 FixedRecordIteraor::getPos(void)
{
return 0;
}
bool FixedRecordIteraor::isEnd(void )
{
return true;
}
void FixedRecordIteraor::goBegin(void )
{
return ;
}
void FixedRecordIteraor::goEnd(void )
{
return ;
}
AR_INT64 FixedRecordIteraor::goTo(AR_INT64 index)
{
return 0;
}
void FixedRecordIteraor::dump(void)
{
ACE_DEBUG ((LM_DEBUG, "(%D)(%t) FixedRecordIteraor \n"));
}
void FixedRecordIteraor::setSTRVar(std::map<std::string, std::string> &s)
{
ACE_TRACE("(%D)(%t) FixedRecordIteraor::setSTRVar");
RecordDetails::FIELDDETAILS::iterator it = _RecordDetails->GetFieldDetails()->begin();
for(;it!=_RecordDetails->GetFieldDetails()->end();it++)
{
char *addr = const_cast<char*>(it->_RecordData.cell.data());
s[it->NAME]=addr ;
}
}
void FixedRecordIteraor::InitScriptVar(void *p, void * s)
{
ACE_TRACE("(%D)(%t) FixedRecordIteraor::InitScriptVar");
//Record::RECORDDATANAME::iterator it = _FixedLocationRecord->_recordDataName.begin();
//for(;it!=_FixedLocationRecord->_recordDataName.end();it++)
//{
// unsigned long i=0;
// SQChar *varName = (SQChar *)it->field.c_str();
// SQChar *addr = const_cast<SQChar*>( "" );
// Sqrat::Table* pRecordTable = reinterpret_cast<Sqrat::Table *>(p);
// pRecordTable->SetValue( varName, addr );
//}
//Sqrat::Script* pScript = reinterpret_cast<Sqrat::Script *>(s);
// pScript->Compile
}
void FixedRecordIteraor::setScriptVar(void *p)
{
ACE_TRACE("(%D)(%t) FixedRecordIteraor::setScriptVar");
RecordDetails::FIELDDETAILS::iterator it = _RecordDetails->GetFieldDetails()->begin();
//Record::RECORDDATANAME::iterator it = _FixedLocationRecord->_recordDataName.begin();
for(;it!=_RecordDetails->GetFieldDetails()->end();it++)
{
unsigned long i=0;
//const char *varName = it->field.c_str();
//char *addr = const_cast<char*>(it->cell.data());
SQChar *varName = (SQChar *) it->NAME.c_str();
SQChar *addr = const_cast<SQChar*>( it->_RecordData.cell.data() );
Sqrat::Table* pRecordTable = reinterpret_cast<Sqrat::Table *>(p);
//pConstTable->Const( varName, addr );
pRecordTable->SetValue( varName, addr );
//int type =TCL_LINK_STRING | TCL_LINK_READ_ONLY;
//Tcl_Interp * _ti = (Tcl_Interp *)ptcl;
//char current_title_space[60];
//Tcl_LinkVar(_ti, varName, (char*)&addr, type);
}
}
|
dfecb17cd806ff7b203c4d38f014f6a408592f59
|
79864cee4de758c833447763947cc7dbb3aa1b40
|
/Source/WTF/wtf/unicode/wchar/UnicodeCaseTable.cpp
|
141b88acbd8c73a64af753f11b664989e6b9b435
|
[] |
no_license
|
masali-hp/webkit
|
1a7722d5463e47e5750ba974c14f0099164c7066
|
e49996e0fa12de5ee666e58a968c6447b8c2dcf0
|
refs/heads/master
| 2023-03-02T00:23:00.643613
| 2014-11-17T23:12:07
| 2014-11-17T23:27:18
| 7,653,236
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,820
|
cpp
|
UnicodeCaseTable.cpp
|
/* Table for lcase value of unicode chars
* Incoming vlaues are offset by 0x100
* (so char 0 is actually 0x100). Ends at 0x17F
*/
const wchar_t lcase_tableA[] = {
0x101, 0x101, 0x103, 0x103,
0x105, 0x105, 0x107, 0x107,
0x109, 0x109, 0x10B, 0x10B,
0x10D, 0x10D, 0x10F, 0x10F,
0x111, 0x111, 0x113, 0x113,
0x115, 0x115, 0x117, 0x117,
0x119, 0x119, 0x11B, 0x11B,
0x11D, 0x11D, 0x11F, 0x11F,
0x121, 0x121, 0x123, 0x123,
0x125, 0x125, 0x127, 0x127,
0x129, 0x129, 0x12B, 0x12B,
0x12D, 0x12D, 0x12F, 0x12F,
0x069, 0x131, 0x133, 0x133,
0x135, 0x135, 0x137, 0x137,
0x138, 0x13A, 0x13A, 0x13C,
0x13C, 0x13E, 0x13E, 0x140,
0x140, 0x142, 0x142, 0x144,
0x144, 0x146, 0x146, 0x148,
0x148, 0x149, 0x14B, 0x14B,
0x14D, 0x14D, 0x14F, 0x14F,
0x151, 0x151, 0x153, 0x153,
0x155, 0x155, 0x157, 0x157,
0x159, 0x159, 0x15B, 0x15B,
0x15D, 0x15D, 0x15F, 0x15F,
0x161, 0x161, 0x163, 0x163,
0x165, 0x165, 0x167, 0x167,
0x169, 0x169, 0x16B, 0x16B,
0x16D, 0x16D, 0x16F, 0x16F,
0x171, 0x171, 0x173, 0x173,
0x175, 0x175, 0x177, 0x177,
0x0FF, 0x17A, 0x17A, 0x17C,
0x17C, 0x17E, 0x17E, 0x17F,
};
/* Table for ucase value of unicdoe chars
* Incoming vlaues are offset by 0x100
* (so char 0 is actually 0x100). Ends at 0x17F
*/
const wchar_t ucase_tableA[] = {
0x100, 0x100, 0x102, 0x102,
0x104, 0x104, 0x106, 0x106,
0x108, 0x108, 0x10A, 0x10A,
0x10C, 0x10C, 0x10E, 0x10E,
0x110, 0x110, 0x112, 0x112,
0x114, 0x114, 0x116, 0x116,
0x118, 0x118, 0x11A, 0x11A,
0x11C, 0x11C, 0x11E, 0x11E,
0x120, 0x120, 0x122, 0x122,
0x124, 0x124, 0x126, 0x126,
0x128, 0x128, 0x12A, 0x12A,
0x12C, 0x12C, 0x12E, 0x12E,
0x130, 0x049, 0x132, 0x132,
0x134, 0x134, 0x136, 0x136,
0x138, 0x139, 0x139, 0x13B,
0x13B, 0x13D, 0x13D, 0x13F,
0x13F, 0x141, 0x141, 0x143,
0x143, 0x145, 0x145, 0x147,
0x147, 0x2BC, 0x14A, 0x14A,
0x14C, 0x14C, 0x14E, 0x14E,
0x150, 0x150, 0x152, 0x152,
0x154, 0x154, 0x156, 0x156,
0x158, 0x158, 0x15A, 0x15A,
0x15C, 0x15C, 0x15E, 0x15E,
0x160, 0x160, 0x162, 0x162,
0x164, 0x164, 0x166, 0x166,
0x168, 0x168, 0x16A, 0x16A,
0x16C, 0x16C, 0x16E, 0x16E,
0x170, 0x170, 0x172, 0x172,
0x174, 0x174, 0x176, 0x176,
0x178, 0x179, 0x179, 0x17B,
0x17B, 0x17D, 0x17D, 0x053,
};
/* Table for lcase value of unicode chars
* Incoming vlaues are offset by 0x400
* (so char 0 is actually 0x400). Ends at 0x45f
*/
const wchar_t lcase_tableB[] = {
0x450, 0x451, 0x452, 0x453,
0x454, 0x455, 0x456, 0x457,
0x458, 0x459, 0x45A, 0x45B,
0x45C, 0x45D, 0x45E, 0x45F,
0x430, 0x431, 0x432, 0x433,
0x434, 0x435, 0x436, 0x437,
0x438, 0x439, 0x43A, 0x43B,
0x43C, 0x43D, 0x43E, 0x43F,
0x440, 0x441, 0x442, 0x443,
0x444, 0x445, 0x446, 0x447,
0x448, 0x449, 0x44A, 0x44B,
0x44C, 0x44D, 0x44E, 0x44F,
0x430, 0x431, 0x432, 0x433,
0x434, 0x435, 0x436, 0x437,
0x438, 0x439, 0x43A, 0x43B,
0x43C, 0x43D, 0x43E, 0x43F,
0x440, 0x441, 0x442, 0x443,
0x444, 0x445, 0x446, 0x447,
0x448, 0x449, 0x44A, 0x44B,
0x44C, 0x44D, 0x44E, 0x44F,
0x450, 0x451, 0x452, 0x453,
0x454, 0x455, 0x456, 0x457,
0x458, 0x459, 0x45A, 0x45B,
0x45C, 0x45D, 0x45E, 0x45F,
0x461, 0x461, 0x463, 0x463,
0x465, 0x465, 0x467, 0x467,
0x469, 0x469, 0x46B, 0x46B,
0x46D, 0x46D, 0x46F, 0x46F,
0x471, 0x471, 0x473, 0x473,
0x475, 0x475, 0x477, 0x477,
0x479, 0x479, 0x47B, 0x47B,
0x47D, 0x47D, 0x47F, 0x47F,
0x481, 0x481,
};
/* Table for ucase value of unicode chars
* Incoming vlaues are offset by 0x400
* (so char 0 is actually 0x400). Ends at 0x45f
*/
const wchar_t ucase_tableB[] = {
0x400, 0x401, 0x402, 0x403,
0x404, 0x405, 0x406, 0x407,
0x408, 0x409, 0x40A, 0x40B,
0x40C, 0x40D, 0x40E, 0x40F,
0x410, 0x411, 0x412, 0x413,
0x414, 0x415, 0x416, 0x417,
0x418, 0x419, 0x41A, 0x41B,
0x41C, 0x41D, 0x41E, 0x41F,
0x420, 0x421, 0x422, 0x423,
0x424, 0x425, 0x426, 0x427,
0x428, 0x429, 0x42A, 0x42B,
0x42C, 0x42D, 0x42E, 0x42F,
0x410, 0x411, 0x412, 0x413,
0x414, 0x415, 0x416, 0x417,
0x418, 0x419, 0x41A, 0x41B,
0x41C, 0x41D, 0x41E, 0x41F,
0x420, 0x421, 0x422, 0x423,
0x424, 0x425, 0x426, 0x427,
0x428, 0x429, 0x42A, 0x42B,
0x42C, 0x42D, 0x42E, 0x42F,
0x400, 0x401, 0x402, 0x403,
0x404, 0x405, 0x406, 0x407,
0x408, 0x409, 0x40A, 0x40B,
0x40C, 0x40D, 0x40E, 0x40F,
0x460, 0x460, 0x462, 0x462,
0x464, 0x464, 0x466, 0x466,
0x468, 0x468, 0x46A, 0x46A,
0x46C, 0x46C, 0x46E, 0x46E,
0x470, 0x470, 0x472, 0x472,
0x474, 0x474, 0x476, 0x476,
0x478, 0x478, 0x47A, 0x47A,
0x47C, 0x47C, 0x47E, 0x47E,
0x480, 0x480,
};
|
5b3dc40d564e4affde639f597792f59bdbaa3410
|
fd3788a0b9c64bd4dbb325c414d3cb9eaa13e00c
|
/fit_histo.cc
|
51c88df4699764c1c5bb0f7015cc3a49b63abcfa
|
[] |
no_license
|
project8/mindworm
|
615c6ecd46dbcbb5599a6e438c5b4b37555aab10
|
51bf6aba0d8fac38b0406a03ebb8f4b26d0bee4b
|
refs/heads/master
| 2016-09-11T00:59:49.296826
| 2013-06-10T01:59:59
| 2013-06-10T01:59:59
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,625
|
cc
|
fit_histo.cc
|
#include "Histogram.hh"
#include "Minimization1d.hh"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
class ExpLogLike : public SingleParameterFunction
{
public:
double evaluate(const double ¶m);
double getA(const double ¶m);
int hstart;
Histogram thehisto;
};
int main(int argc,char *argv[])
{
ExpLogLike myfunc;
myfunc.thehisto.loadFromFile(string(argv[1]));
double thecut=atof(argv[2]);
// cout << "size " << myfunc.thehisto.size << endl;
// cout << "min " << myfunc.thehisto.min << endl;
// cout << "max " << myfunc.thehisto.max << endl;
// cout << "the cut is " << thecut << endl;
myfunc.hstart=myfunc.thehisto.getbin(thecut);
// cout << "hstart is " << myfunc.hstart << endl;
// cout << "ll is " << myfunc.evaluate(-1) << endl;
Golden_Mean_Minimizer minimizer(&myfunc);
minimizer.accuracy=0.001;
minimizer.epsilon=0.00001;
minimizer.minimize_between(0,10);
printf("%g %g\n",minimizer.minimum_param,myfunc.getA(minimizer.minimum_param));
}
double ExpLogLike::getA(const double ¶m)
{
double sum=0;
double sumn=0;
for(int i=hstart;i<thehisto.size;i++) {
double x=thehisto.getx(i);
sum+=thehisto.data[i];
sumn+=exp(-param*x);
}
return sum/sumn;
}
double ExpLogLike::evaluate(const double ¶m)
{
double A=getA(param);
double k=param;
double ll=0;
for(int i=hstart;i<thehisto.size;i++) {
double x=thehisto.getx(i);
double lambda=A*exp(-x*k);
double lla=thehisto.data[i]*log(lambda)-lambda-lgamma(thehisto.data[i]+1);
// cout << x << " " << lambda << " " << lla << endl;
ll+=lla;
}
// cout << param << " " << -ll << endl;
return -ll;
}
|
289614f772d7f09bac2058d3551190fb303bb394
|
26bb69977888fdc5f701f32027a0a6ae33c769f2
|
/qt/kitchen_leakage.h
|
b773421e700696beccbde3886295969c34396926
|
[] |
no_license
|
AM20302030/fastfd
|
a7ab37e3abdd9728f58fdcc76679fb9b1d1d22bf
|
4b23ee7e736afac6603588dcf8079fae889134f5
|
refs/heads/master
| 2023-03-15T23:21:51.398989
| 2017-07-17T02:19:45
| 2017-07-17T02:19:45
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 960
|
h
|
kitchen_leakage.h
|
#ifndef KITCHEN_LEAKAGE_H
#define KITCHEN_LEAKAGE_H
#include <QDialog>
#include <QStandardItemModel>
#include <QSqlDatabase>
#include <QTimer>
namespace Ui {
class kitchen_leakage;
}
class kitchen_leakage : public QDialog
{
Q_OBJECT
public:
explicit kitchen_leakage(QWidget *parent = 0);
~kitchen_leakage();
void init_control();
void re_model();
private slots:
void on_pushButton_7_clicked();
void on_radioButton_clicked();
void on_radioButton_2_clicked();
void on_pushButton_8_clicked();
void on_pushButton_9_clicked();
void on_pushButton_10_clicked();
void update_refresh(bool flag);
void update_refresh_time(const QString &time);
void torefresh();
void to_auto_print(bool flag);
void on_pushButton_11_clicked();
private:
Ui::kitchen_leakage *ui;
QStandardItemModel *tab_model;
QSqlDatabase lostform_db;
QTimer refresh_timer;
};
#endif // KITCHEN_LEAKAGE_H
|
0b80c66609541e55ed5269c2cfcb50a2f2ec706c
|
9fec729f365812836ca0b6a68031b9e0d6561766
|
/codeforce/global_round_4/B.cpp
|
41888730452ec430e2921f622dae871f9817a396
|
[] |
no_license
|
lee-jeong-geun/ps
|
d681b47c9c3a7f8f0aa29fae961df5c109f55926
|
8306c546820be5e089ab52abdc1cb03722adbecb
|
refs/heads/master
| 2023-04-23T23:38:48.291444
| 2021-05-05T16:29:47
| 2021-05-05T16:29:47
| 106,931,221
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,315
|
cpp
|
B.cpp
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> vec;
char str[1000005];
int length;
long long result, Sum[1000005];
/*
연속된 v와 o를 카운트 하는데 v는 2개이상이 연속된 경우에만 해준다.
o에 대해서 왼쪽 v의 개수와 오른쪽 v의 개수를 곱해서 결과값에 더해주면 된다.
*/
int main()
{
scanf("%s", str);
length = strlen(str);
int count = 0;
vec.push_back({0, 0});
for(int i = 0; i < length; i++)
{
count = 0;
//연속된 문자 카운트
for(int j = i; j < length; j++)
{
//다르면 종료
if(str[i] != str[j])
break;
count++;
i = j;
}
if(str[i] == 'v')
vec.push_back({1, count});
else
vec.push_back({0, count});
}
//v에 대해서 누적합
for(int i = 1; i < vec.size(); i++)
{
Sum[i] = Sum[i - 1];
//2개이상 연속인 v에 대해서만 합 구함
if(vec[i].first == 1 && vec[i].second > 1)
Sum[i] += (vec[i].second - 1);
}
for(int i = 1; i < vec.size(); i++)
{
if(vec[i].first == 0)
result += Sum[i] * vec[i].second * (Sum[vec.size() - 1] - Sum[i]);
}
printf("%lld", result);
}
|
1ce68b32107d1e975e208e1a218a5fde31e81cb0
|
2f4cd5d7594e34c4f0f71d6f19a7c76418e4b943
|
/6/1056.cpp
|
0770ab3a38954117b6ab41cffdc58c8ab25fe2e2
|
[] |
no_license
|
Gurrium/programming_challenge
|
dbde476c42ef6a198af3149e783c945b4aa0193c
|
e1b5b781bdaa8d885ef2b3fc4ca8b171d6e1667b
|
refs/heads/master
| 2022-01-13T10:39:37.564009
| 2019-06-20T06:28:40
| 2019-06-20T06:28:40
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,969
|
cpp
|
1056.cpp
|
#include <iostream>
#include <vector>
#include <map>
#define INF 10000
using namespace std;
map<string, int> dictionary;
int dic_counter = 0;
vector<bool> visited;
int id(string name) {
if(dictionary.find(name) == dictionary.end()) {
return dictionary[name] = dic_counter++;
} else {
return dictionary[name];
}
}
void dfs(int node, vector<vector<int> > graph) {
if(visited[node]) {
return;
}
visited[node] = true;
int size = graph[node].size();
for(int i = 0;i < size;i++) {
dfs(graph[node][i], graph);
}
}
int main() {
int p, r;
int counter = 1;
cin >> p >> r;
while(p + r != 0) {
dic_counter = 0;
dictionary.clear();
visited.assign(p, false);
int weight[p][p];
for(int i = 0;i < p;i++) {
for(int j = 0;j < p;j++) {
weight[i][j] = INF;
}
}
vector<vector<int> > graph(p);
for(int i = 0;i < r;i++) {
string from, to;
int from_id, to_id;
cin >> from >> to;
from_id = id(from);
to_id = id(to);
graph[from_id].push_back(to_id);
graph[to_id].push_back(from_id);
weight[from_id][to_id] = weight[to_id][from_id] = 1;
}
bool flag = false;
int size = graph.size();
dfs(0, graph);
for(int i = 0;i < p;i++) {
if(!visited[i]) {
printf("Network %d: DISCONNECTED\n\n", counter++);
flag = true;
break;
}
}
if(flag){
cin >> p >> r;
continue;
}
for(int i = 0;i < p;i++) {
weight[i][i] = 0;
}
for(int i = 0;i < p;i++) {
for(int j = 0;j < p;j++) {
for(int k = 0;k < p;k++) {
weight[j][k] = min(weight[j][k], weight[j][i] + weight[i][k]);
}
}
}
int max_weight = 0;
for(int i = 0;i < p;i++) {
for(int j = 0;j < p;j++) {
max_weight = max(weight[i][j], max_weight);
}
}
printf("Network %d: %d\n\n", counter++, max_weight);
cin >> p >> r;
}
return 0;
}
|
ffc3c0f9a438af58180e525e3c87e13e59ac7b50
|
1497386b0fe450e6c3881c8c6d52d9e6ad9117ab
|
/trunk/libcvact/include/actKey.h
|
8a1fd3c5930f5665c3d3970c4dc5f69f91a4269d
|
[
"Apache-2.0"
] |
permissive
|
flomar/CrypTool-VS2015
|
403f538d6cad9b2f16fbf8846d94456c0944569b
|
6468257af2e1002418882f22a9ed9fabddde096d
|
refs/heads/master
| 2021-01-21T14:39:58.113648
| 2017-02-22T14:10:19
| 2017-02-22T14:10:19
| 57,972,666
| 0
| 5
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,276
|
h
|
actKey.h
|
//////////////////////////////////////////////////////////////////////////////////
// Name: actKey.h
// Product: cv act library
// Purpose: The class Key manages information relevant to keys (e.g.
// domain parameters or the key itself). In the case of symmetric
// encryption only a (the) secret key is generated. In the case of
// of asymetric encryption a private and a public key are generated.
// This handle allows a universal approach for different families of
// algorithms.
//
//
// Copyright: (c) 2000 cv cryptovision GmbH
// all rights reserved
// Licence: The conditions for the use of this software are regulated
// in the cv act library licence agreement.
//////////////////////////////////////////////////////////////////////////////////
#ifndef ACT_Key_h
#define ACT_Key_h
#include "actBasics.h"
#include "actBlob.h"
namespace act
{
class IRNGAlg;
class IAlgorithm;
class IKey;
class ICertificate;
class Key
{
public:
Key();
Key(const Key& key);
Key(IKey* keyptr);
Key(const Blob& keyblob);
Key(const ICertificate* cert);
Key(const char* keytype);
void Import(const Blob& keyblob);
void Export(Blob& keyblob, export_t type = DEFAULT) const;
void SetParam(paramid_t id, const Blob& blob);
void SetParam(paramid_t id, int val);
void SetParam(paramid_t id, const char* cstr);
int GetParam(paramid_t id) const;
void GetParam(paramid_t id, Blob& blob) const;
void Generate(IAlgorithm* prng = 0);
void Derive(const Blob& data, const Blob& salt = Blob());
IAlgorithm* CreateAlgorithm(mode_t Mode) const;
IAlgorithm* CreateAlgorithm(mode_t Mode, const Blob& data) const;
IKey* GetPointer();
const IKey* GetPointer() const;
operator IKey*();
operator const IKey*() const;
IKey* ReleasePointer();
template<typename KeyTypeT>
inline KeyTypeT* As() { return static_cast<KeyTypeT*>(GetPointer()); }
template<typename KeyTypeT>
inline const KeyTypeT* As() const { return static_cast<const KeyTypeT*>(GetPointer()); }
Key& operator=(const Key& key);
Key& Reset(IKey* key);
Key& Required(const char* where = 0);
~Key();
private:
IKey *mKey;
};
} // namespace act
#endif // ACT_Key_h
|
64c97455529b083491c11b1b06de1f54f247b37e
|
29e0ff76571947ed785ef4cb73899d572ff2caa1
|
/src/editor/win_scro.cpp
|
942085f81a5c7606f6296c349199b521fc5483db
|
[] |
no_license
|
SimonN/Lix
|
b0ad837f208fe03cc7821a71145be2a10f2bfe16
|
845ace4cb360f832e58c8f417039a67b5d926474
|
refs/heads/master
| 2021-01-19T00:57:27.103756
| 2017-08-22T01:16:36
| 2017-08-22T01:17:18
| 1,491,253
| 28
| 12
| null | 2016-07-17T10:49:39
| 2011-03-17T11:39:36
|
C++
|
UTF-8
|
C++
| false
| false
| 4,451
|
cpp
|
win_scro.cpp
|
/*
* editor/win_scro.cpp
*
*/
#include "win_scro.h"
#include "../other/help.h"
#include "../other/language.h"
#include "../other/user.h"
namespace Api {
const unsigned WindowScroll::this_xl(420);
const unsigned WindowScroll::this_yl(300);
const unsigned WindowScroll::nrxl(180); // Number X-Length
const unsigned WindowScroll::rgxl(180); // Regular X-Length
const unsigned WindowScroll::step_small(10); // Fuer Rasterbestimmung
WindowScroll::WindowScroll(Level& l, Map& m)
:
Window(LEMSCR_X/2 - this_xl/2,
LEMSCR_Y/2 - this_yl/2 - 30,
this_xl, this_yl, Language::win_scroll_title),
level(l),
map (m),
manual (20, 40),
desc_manual(60, 40, Language::win_scroll_manual),
x(this_xl-20-nrxl, 80, nrxl, 4, 0, level.size_x, level.start_x, true),
y(this_xl-20-nrxl, 100, nrxl, 4, 0, level.size_y, level.start_y, true),
jump (20, 140, rgxl),
current(this_xl-20-nrxl, 140, nrxl),
bg_r(this_xl-20-nrxl, 180, nrxl),
bg_g(this_xl-20-nrxl, 200, nrxl),
bg_b(this_xl-20-nrxl, 220, nrxl),
desc_win_scroll_x(20, 80, Language::win_scroll_x),
desc_win_scroll_y(20, 100, Language::win_scroll_y),
desc_win_scroll_r(20, 180, Language::win_scroll_r),
desc_win_scroll_g(20, 200, Language::win_scroll_g),
desc_win_scroll_b(20, 220, Language::win_scroll_b),
ok (20, 260, rgxl),
cancel (this_xl-20-nrxl, 260, nrxl)
{
add_child(manual);
add_child(desc_manual);
add_child(x);
add_child(y);
add_child(bg_r);
add_child(bg_g);
add_child(bg_b);
add_child(jump);
add_child(current);
add_child(ok);
add_child(cancel);
add_child(desc_win_scroll_x);
add_child(desc_win_scroll_y);
add_child(desc_win_scroll_r);
add_child(desc_win_scroll_g);
add_child(desc_win_scroll_b);
manual.set_checked(l.start_manual);
x .set_hidden(! manual.get_checked());
y .set_hidden(! manual.get_checked());
desc_win_scroll_x.set_hidden(! manual.get_checked());
desc_win_scroll_y.set_hidden(! manual.get_checked());
jump .set_hidden(! manual.get_checked());
current .set_hidden(! manual.get_checked());
x.set_step_sml ( 2);
y.set_step_sml ( 2);
x.set_step_med (16);
y.set_step_med (16);
x.set_step_big (80);
y.set_step_big (80);
x.set_white_zero();
y.set_white_zero();
x .set_undraw_color(color[COL_API_M]);
y .set_undraw_color(color[COL_API_M]);
jump .set_undraw_color(color[COL_API_M]);
current.set_undraw_color(color[COL_API_M]);
bg_r.set_macro_color(level.bg_red);
bg_g.set_macro_color(level.bg_green);
bg_b.set_macro_color(level.bg_blue);
jump .set_text(Language::win_scroll_jump );
current.set_text(Language::win_scroll_current);
ok .set_text(Language::common_ok );
cancel .set_text(Language::common_cancel );
ok .set_hotkey(useR->key_me_okay);
cancel .set_hotkey(useR->key_me_exit);
}
WindowScroll::~WindowScroll()
{
}
void WindowScroll::calc_self()
{
if (manual.get_clicked()) {
x .set_hidden(! manual.get_checked());
y .set_hidden(! manual.get_checked());
desc_win_scroll_x.set_hidden(! manual.get_checked());
desc_win_scroll_y.set_hidden(! manual.get_checked());
jump .set_hidden(! manual.get_checked());
current .set_hidden(! manual.get_checked());
}
if (jump.get_clicked()) {
map.set_screen_x(x.get_number());
map.set_screen_y(y.get_number());
}
if (current.get_clicked()) {
int ax = (map.get_screen_x()+step_small/2) / step_small * step_small;
int ay = (map.get_screen_y()+step_small/2) / step_small * step_small;
x.set_number(Help::mod(ax, level.size_x));
y.set_number(Help::mod(ay, level.size_y));
map.set_screen_x(x.get_number());
map.set_screen_y(y.get_number());
}
if (ok.get_clicked() || hardware.get_mr()) {
level.start_manual = manual.get_checked();
level.start_x = x.get_number();
level.start_y = y.get_number();
level.bg_red = bg_r.get_number();
level.bg_green = bg_g.get_number();
level.bg_blue = bg_b.get_number();
set_exit();
}
else if (cancel.get_clicked()) set_exit();
}
} // Ende Namensraum Api
|
3428d3803226457cb33def4e3c4c18245eb5e501
|
914e9e0df3a19bb355982a4db48af864070a7033
|
/src/cmessage.cpp
|
49b2476095bf7fa228543a291e94f701e453a1e1
|
[
"MIT"
] |
permissive
|
hreintke/Seeed_Arduino_ooFreeRTOS
|
ce7bdf6d973b6e300781f870489d4cdc3e98b839
|
d0695a89c28c467532eed25c2b39102cd062ed28
|
refs/heads/master
| 2022-12-11T07:45:24.532415
| 2020-08-25T09:12:14
| 2020-08-25T09:12:14
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,478
|
cpp
|
cmessage.cpp
|
/****************************************************************************
*
* Copyright (c) 2017, Michael Becker (michael.f.becker@gmail.com)
*
* This file is part of the FreeRTOS Add-ons project.
*
* Source Code:
* https://github.com/michaelbecker/freertos-addons
*
* Project Page:
* http://michaelbecker.github.io/freertos-addons/
*
* On-line Documentation:
* http://michaelbecker.github.io/freertos-addons/docs/html/index.html
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so,subject to the
* following conditions:
*
* + The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* + Credit is appreciated, but not required, if you find this project
* useful enough to include in your application, product, device, etc.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
***************************************************************************/
#include "message.hpp"
using namespace cpp_freertos;
Message::Message(UBaseType_t bufferSize)
{
handle = xMessageBufferCreate(bufferSize);
if (handle == NULL)
{
#ifndef CPP_FREERTOS_NO_EXCEPTIONS
throw MessageCreateException();
#else
configASSERT(!"Queue Constructor Failed");
#endif
}
}
Message::~Message()
{
vMessageBufferDelete(handle);
}
size_t Message::Send(void *buff, size_t length, TickType_t Timeout)
{
size_t xBytesSent;
xBytesSent = xMessageBufferSend(handle, (void *)buff, length, Timeout);
return xBytesSent;
}
size_t Message::Receive(void *buff, size_t length, TickType_t Timeout)
{
size_t xReceivedBytes;
xReceivedBytes = xMessageBufferReceive(handle, (void *)buff, length, Timeout);
return xReceivedBytes;
}
size_t Message::SendFromISR(void *buff, size_t length, BaseType_t *pxHigherPriorityTaskWoken)
{
size_t xBytesSent;
xBytesSent = xMessageBufferSendFromISR(handle, (void *)buff, length, pxHigherPriorityTaskWoken);
return xBytesSent;
}
size_t Message::ReceiveFromISR(void *buff, size_t length, BaseType_t *pxHigherPriorityTaskWoken)
{
size_t xReceivedBytes;
xReceivedBytes = xMessageBufferReceiveFromISR(handle, (void *)buff, length, pxHigherPriorityTaskWoken);
return xReceivedBytes;
}
bool Message::IsEmpty()
{
UBaseType_t cnt = xMessageBufferIsEmpty(handle);
return cnt == pdTRUE ? true : false;
}
bool Message::IsFull()
{
UBaseType_t cnt = xMessageBufferIsFull(handle);
return cnt == pdTRUE ? true : false;
}
void Message::Flush()
{
xMessageBufferReset(handle);
}
UBaseType_t Message::NumSpacesLeft()
{
return xMessageBufferSpacesAvailable(handle);
}
|
6096d2e616fad57fc8ddfe8a67760fffa13e7500
|
2d42a50f7f3b4a864ee19a42ea88a79be4320069
|
/source/tests/punk_math_test/polygon3d_test.h
|
6fc20ac8348179520419da3cab442d26d4a141cd
|
[] |
no_license
|
Mikalai/punk_project_a
|
8a4f55e49e2ad478fdeefa68293012af4b64f5d4
|
8829eb077f84d4fd7b476fd951c93377a3073e48
|
refs/heads/master
| 2016-09-06T05:58:53.039941
| 2015-01-24T11:56:49
| 2015-01-24T11:56:49
| 14,536,431
| 1
| 0
| null | 2014-06-26T06:40:50
| 2013-11-19T20:03:46
|
C
|
UTF-8
|
C++
| false
| false
| 133
|
h
|
polygon3d_test.h
|
#ifndef POLYGON3D_TEST_H
#define POLYGON3D_TEST_H
class Polygon3dTest
{
public:
Polygon3dTest();
};
#endif // POLYGON3D_TEST_H
|
42a6ea35b18612432956728574b2939d91a1b797
|
c418d1cf53a1be843a86a77c30c2f3a312959cfb
|
/int_fast8_t.hxx
|
b46332aa4527b5d3edfd346f3dc9dde3b32ddfaa
|
[
"MIT"
] |
permissive
|
mojo-runtime/lib-std
|
f12e2dba26c3d6f2eb7c66fa72e506eb6e43501b
|
35178964db5b51184f35447f33c379de9768b534
|
refs/heads/master
| 2016-09-06T18:39:42.577507
| 2015-06-10T20:20:18
| 2015-06-10T20:20:18
| 37,212,466
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 128
|
hxx
|
int_fast8_t.hxx
|
#pragma once
namespace std {
#if defined(__INT_FAST8_TYPE__)
typedef __INT_FAST8_TYPE__ int_fast8_t;
#else
# error
#endif
}
|
236aaae8b9134c07d2e25a7c4ffc08593f820fd4
|
bcae7c39974b62dfbaccc4cb4ec12282ea2d7807
|
/Game/Game/MainScene.cpp
|
2fc09078a1d6b8a99830b5c634a53eb387063ca4
|
[] |
no_license
|
jenspetter/JEngine
|
dd3f503f22fe5d6d95777c237be9e16d647d06fd
|
fe7d400cdffa6b8301a7475d598126c79fd667e4
|
refs/heads/master
| 2021-07-21T15:52:51.187739
| 2017-10-30T21:05:13
| 2017-10-30T21:05:13
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 477
|
cpp
|
MainScene.cpp
|
#include "MainScene.h"
MainScene::MainScene()
{
}
MainScene::~MainScene() {
}
void MainScene::Start()
{
Scene::Start();
//sprite2.SetPosition(400, 0);
}
void MainScene::Update(float deltaTime)
{
Scene::Update(deltaTime);
/*
if (Input->KeyDown(sf::Keyboard::A)) {
sprite2.Move(-2, 0);
}
else if (Input->KeyDown(sf::Keyboard::D)) {
sprite2.Move(2, 0);
}
GameObject* box = boxCollider2.Collide();
if (box) {
std::cout << box->Name << std::endl;
}
*/
}
|
526f3aabd751653c70e34a6d6e75f8cd52de5d72
|
f7d8a9c80ddace22825e986bdbcb4b099cea2b4f
|
/Laboratorio_No_6.cpp
|
369bf52854eb4dfb68b6fefc1fc528c3897a66dd
|
[] |
no_license
|
Mcoconan/laboratorio6--
|
574dfb268fc8fcfb293c7eba9808c7678f65d34d
|
aaccc0fdce12200592b0e11bf6b6b6eb8d94d526
|
refs/heads/master
| 2022-02-23T02:11:02.151300
| 2019-09-22T05:13:10
| 2019-09-22T05:13:10
| null | 0
| 0
| null | null | null | null |
MacCentralEurope
|
C++
| false
| false
| 580
|
cpp
|
Laboratorio_No_6.cpp
|
/*
*Universidad del Valle de Guatemala
*Josť Ovando 18071
*Mario Sarmientos 17055
*Laboratorio No. 6
*/
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<fstream>
using namespace std;
void lectura();
int main()
{
lectura();
system("pause");
return 0;
}
void lectura(){
ifstream archivo;
string texto;
archivo.open("FUENTE.txt",ios::in);
if(archivo.fail()){
cout<<"No se encuentra el archivo";
exit(1);
}
while(!archivo.eof()){
getline(archivo,texto);
cout<<texto<<endl;
}
archivo.close();
}
|
d75bf7c97705057ef4d4c058db8a108cee6a34db
|
5f975169aeb67c7cd0a08683e6b9eee253f84183
|
/algorithms/medium/0318. Maximum Product of Word Lengths.h
|
cdcb9aed154fb7dead5076d4bb5b338ffb777c85
|
[
"MIT"
] |
permissive
|
MultivacX/leetcode2020
|
6b743ffb0d731eea436d203ccb221be14f2346d3
|
83bfd675052de169ae9612d88378a704c80a50f1
|
refs/heads/master
| 2023-03-17T23:19:45.996836
| 2023-03-16T07:54:45
| 2023-03-16T07:54:45
| 231,091,990
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 919
|
h
|
0318. Maximum Product of Word Lengths.h
|
// 318. Maximum Product of Word Lengths
// Runtime: 40 ms, faster than 98.17% of C++ online submissions for Maximum Product of Word Lengths.
// Memory Usage: 12.2 MB, less than 100.00% of C++ online submissions for Maximum Product of Word Lengths.
class Solution {
public:
int maxProduct(vector<string>& words) {
const int n = words.size();
if (n <= 1) return 0;
vector<int> nums(n, 0);
for (int i = 0; i < n; ++i)
for (const char& c : words[i])
nums[i] |= 1 << (c - 'a');
// for (int i = 0; i < n; ++i)
// cout << bitset<32>(nums[i]) << endl;
int ans = 0;
for (int i = 0; i < n - 1; ++i)
for (int j = i + 1; j < n; ++j)
if ((nums[i] & nums[j]) == 0)
ans = max(ans, (int)(words[i].length() * words[j].length()));
return ans;
}
};
|
6ee3d88f4729343e5c3f0066ea748bd2324d33d6
|
1de7bc93ba6d2e2000683eaf97277b35679ab873
|
/SecureIM/svcs_rsa.cpp
|
73fbb385d8c1d809acf431d30c6536c560e419ab
|
[] |
no_license
|
mohamadpk/secureimplugin
|
b184642095e24b623b618d02cc7c946fc9bed6bf
|
6ebfa5477b1aa8baaccea3f86f402f6d7f808de1
|
refs/heads/master
| 2021-03-12T23:50:12.141449
| 2010-04-28T06:54:37
| 2010-04-28T06:54:37
| 37,033,105
| 0
| 0
| null | null | null | null |
WINDOWS-1251
|
C++
| false
| false
| 6,694
|
cpp
|
svcs_rsa.cpp
|
#include "commonheaders.h"
pRSA_EXPORT exp = NULL;
RSA_IMPORT imp = {
rsa_inject,
rsa_check_pub,
rsa_notify
};
BOOL rsa_4096=0;
int __cdecl rsa_inject(HANDLE context, LPCSTR msg) {
pUinKey ptr = getUinCtx(context); if(!ptr) return 0;
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("rsa_inject: '%s'", msg);
#endif
int len = strlen(msg)+1;
LPSTR buf = (LPSTR) mir_alloc(LEN_SECU+len);
memcpy(buf,SIG_SECU,LEN_SECU);
memcpy(buf+LEN_SECU,msg,len);
// отправляем сообщение
splitMessageSend(ptr,buf);
mir_free(buf);
return 1;
}
#define MSGSIZE 1024
int __cdecl rsa_check_pub(HANDLE context, PBYTE pub, int pubLen, PBYTE sig, int sigLen) {
int v=0, k=0;
pUinKey ptr = getUinCtx(context); if(!ptr) return 0;
LPSTR cnm = (LPSTR) mir_alloc(NAMSIZE); getContactNameA(ptr->hContact,cnm);
LPSTR uin = (LPSTR) mir_alloc(KEYSIZE); getContactUinA(ptr->hContact,uin);
LPSTR msg = (LPSTR) mir_alloc(MSGSIZE);
LPSTR sha = mir_strdup(to_hex(sig,sigLen));
LPSTR sha_old = NULL;
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("rsa_check_pub: %s %s %s", cnm, uin, sha);
#endif
DBVARIANT dbv;
dbv.type = DBVT_BLOB;
if( DBGetContactSetting(ptr->hContact,szModuleName,"rsa_pub",&dbv) == 0 ) {
k = 1;
PBYTE buf = (PBYTE) alloca(sigLen); int len;
exp->rsa_get_hash((PBYTE)dbv.pbVal,dbv.cpbVal,(PBYTE)buf,&len);
sha_old = mir_strdup(to_hex(buf,len));
DBFreeVariant(&dbv);
}
if( bAAK ) {
if( k ) mir_snprintf(msg,MSGSIZE,Translate(sim523),cnm,uin,sha,sha_old);
else mir_snprintf(msg,MSGSIZE,Translate(sim521),cnm,uin,sha);
showPopUpKRmsg(ptr->hContact,msg);
HistoryLog(ptr->hContact,msg);
v = 1;
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("rsa_check_pub: auto accepted");
#endif
}
else {
if( k ) mir_snprintf(msg,MSGSIZE,Translate(sim522),cnm,sha,sha_old);
else mir_snprintf(msg,MSGSIZE,Translate(sim520),cnm,sha);
v = (msgbox(0,msg,szModuleName,MB_YESNO|MB_ICONQUESTION)==IDYES);
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("rsa_check_pub: manual accepted %d",v);
#endif
}
if(v) {
DBCONTACTWRITESETTING cws;
cws.szModule = szModuleName;
cws.szSetting = "rsa_pub";
cws.value.type = DBVT_BLOB;
cws.value.pbVal = pub;
cws.value.cpbVal = pubLen;
CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)ptr->hContact, (LPARAM)&cws);
ptr->keyLoaded = true;
}
mir_free(cnm);
mir_free(uin);
mir_free(msg);
mir_free(sha);
SAFE_FREE(sha_old);
return v;
}
void __cdecl rsa_notify(HANDLE context, int state) {
pUinKey ptr = getUinCtx(context); if(!ptr) return;
LPCSTR msg=NULL;
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("rsa_notify: 0x%x", state);
#endif
switch( state ) {
case 1: {
showPopUpEC(ptr->hContact);
ShowStatusIconNotify(ptr->hContact);
waitForExchange(ptr,2); // досылаем сообщения из очереди
return;
}
case -1: // сессия разорвана по ошибке, неверный тип сообщения
msg=sim501; break;
case -2: // сессия разорвана по ошибке другой стороной
msg=sim502; break;
case -5: // ошибка декодирования AES сообщения
msg=sim505; break;
case -6: // ошибка декодирования RSA сообщения
msg=sim506; break;
case -7: // таймаут установки соединения (10 секунд)
msg=sim507; break;
case -8: { // сессия разорвана по причине "disabled"
msg=sim508;
// ptr->status=ptr->tstatus=STATUS_DISABLED;
// DBWriteContactSettingByte(ptr->hContact, szModuleName, "StatusID", ptr->status);
} break;
case -0x10: // сессия разорвана по ошибке
case -0x21:
case -0x22:
case -0x23:
case -0x24:
case -0x32:
case -0x33:
case -0x34:
case -0x40:
case -0x50:
case -0x60: {
char buf[1024];
sprintf(buf,sim510,-state);
showPopUpDCmsg(ptr->hContact,buf);
ShowStatusIconNotify(ptr->hContact);
if(ptr->cntx) deleteRSAcntx(ptr);
waitForExchange(ptr,3); // досылаем нешифровано
return;
}
case -3: // соединение разорвано вручную
case -4: { // соединение разорвано вручную другой стороной
showPopUpDC(ptr->hContact);
ShowStatusIconNotify(ptr->hContact);
if(ptr->cntx) deleteRSAcntx(ptr);
waitForExchange(ptr,3); // досылаем нешифровано
return;
}
default:
return;
}
showPopUpDCmsg(ptr->hContact,msg);
ShowStatusIconNotify(ptr->hContact);
if(ptr->cntx) deleteRSAcntx(ptr);
waitForExchange(ptr,3); // досылаем нешифровано
}
unsigned __stdcall sttGenerateRSA( LPVOID param ) {
char priv_key[4096]; int priv_len;
char pub_key[4096]; int pub_len;
exp->rsa_gen_keypair(CPP_MODE_RSA_4096);
DBCONTACTWRITESETTING cws;
cws.szModule = szModuleName;
cws.value.type = DBVT_BLOB;
exp->rsa_get_keypair(CPP_MODE_RSA_4096,(PBYTE)&priv_key,&priv_len,(PBYTE)&pub_key,&pub_len);
cws.szSetting = "rsa_priv";
cws.value.pbVal = (PBYTE)&priv_key;
cws.value.cpbVal = priv_len;
CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)0, (LPARAM)&cws);
cws.szSetting = "rsa_pub";
cws.value.pbVal = (PBYTE)&pub_key;
cws.value.cpbVal = pub_len;
CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)0, (LPARAM)&cws);
rsa_4096=1;
return 0;
}
// загружает паблик-ключ в RSA контекст
BYTE loadRSAkey(pUinKey ptr) {
if( !ptr->keyLoaded ) {
DBVARIANT dbv;
dbv.type = DBVT_BLOB;
if( DBGetContactSetting(ptr->hContact,szModuleName,"rsa_pub",&dbv) == 0 ) {
ptr->keyLoaded = exp->rsa_set_pubkey(ptr->cntx,dbv.pbVal,dbv.cpbVal);
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("loadRSAkey %d", ptr->keyLoaded);
#endif
DBFreeVariant(&dbv);
}
}
return ptr->keyLoaded;
}
// создает RSA контекст
void createRSAcntx(pUinKey ptr) {
if( !ptr->cntx ) {
ptr->cntx = cpp_create_context(CPP_MODE_RSA);
ptr->keyLoaded = 0;
}
}
// пересоздает RSA контекст
void resetRSAcntx(pUinKey ptr) {
if( ptr->cntx ) {
cpp_delete_context(ptr->cntx);
ptr->cntx = cpp_create_context(CPP_MODE_RSA);
ptr->keyLoaded = 0;
}
}
// удаляет RSA контекст
void deleteRSAcntx(pUinKey ptr) {
cpp_delete_context(ptr->cntx);
ptr->cntx = 0;
ptr->keyLoaded = 0;
}
// EOF
|
84d4b1e3244f9198bdedcdcb29f4474fdfd9e8c0
|
5d180787540ba25634df8de7b9879f91f4866844
|
/rza1lu_soundbar_v1/src/tes/Guiliani/Include/Core/GUIObserver.h
|
c8712833abccaac5d6561f7119e58f2df8a4d1cd
|
[] |
no_license
|
mkosinski05/rza1_Soundbar
|
ecddaaf56aedeaba91f11079179a74419b3ea21b
|
63bd806c224e38b760c4a95d4245546e4d0a8746
|
refs/heads/master
| 2023-01-12T01:49:20.904465
| 2020-11-16T15:14:36
| 2020-11-16T15:14:36
| 304,695,885
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,143
|
h
|
GUIObserver.h
|
/*
* Copyright (C) TES Electronic Solutions GmbH,
* All Rights Reserved.
* Contact: info@guiliani.de
*
* This file is part of the Guiliani HMI framework
* for the development of graphical user interfaces on embedded systems.
*/
#ifndef GUIOBSERVER__H_
#define GUIOBSERVER__H_
#include "eC_TList_doubleLinked.h"
#include "GUIValue.h"
class CGUISubject;
class CGUIObject;
/// Observer Base class for Observer-Design-Pattern within Guiliani.
/**
Use this base class if you wish to follow the observer-design-pattern within your application.
Simply derive the class that you want to act as an observer from CGUIObserver, and implement
the desired functionality within OnNotification(). This method will be called whenever an
observed subject changes.
*/
class CGUIObserver
{
friend class CGUISubject;
public:
/// Default constructor.
CGUIObserver() : m_bAutoDelete(false) {}
/// Default destructor. Notifies all subjects of destruction.
virtual ~CGUIObserver();
/// Called by CGUISubject whenever an observed object triggers an update.
virtual void OnNotification() {}
/** Called by CGUISubject whenever an observed object triggers an update.
@param kMessage The updated string value.
*/
virtual void OnNotification (const eC_String& kMessage) {}
/**
Called by a subject whenever the observed object triggers update.
@param pkUpdatedObject The observed object (can be NULL)
*/
virtual void OnNotification(const CGUIObject* const pkUpdatedObject) {}
/**
Called by a subject whenever the observed value changes.
@param kObservedValue The updated observed value.
@param pkUpdatedObject The observed object (can be NULL)
@param uiX X-Index Additional X-Index in case the updated value is part of a multidimensional array
@param uiY Y-Index Additional Y-Index in case the updated value is part of a multidimensional array
*/
virtual void OnNotification(const CGUIValue& kObservedValue, const CGUIObject* const pkUpdatedObject, const eC_UInt uiX=0, const eC_UInt uiY=0) {}
/** @return The list of all subjects to which this observer is registered
*/
const eC_TListDoubleLinked<CGUISubject*>& GetSubjectList() const
{
return m_kSubjectList;
}
/** Specifies if this observer will automatically delete itself when the number of observed subjects reaches zero.
@param bAutoDelete If True, this observer will delete itself when RemoveSubject() is called for the last observed subject.
*/
void SetAutoDelete(const eC_Bool bAutoDelete)
{
m_bAutoDelete = bAutoDelete;
}
protected:
/** Called on destruction of the subject to reset the internal Subject
pointer.
ATTENTION: Call base implementation when deriving from this method.
@param pSubjectToRemove The Subject that shall be removed from the
internal list.
*/
virtual void RemoveSubject(CGUISubject* pSubjectToRemove);
/** Called by the subject when the Observer is added.
ATTENTION: Call base implementation when deriving from this method.
@param pSubjectToAdd The Subject that shall be added to the internal
list.
*/
virtual void AddSubject(CGUISubject* pSubjectToAdd);
private:
/** Copy-constructor. Should not be used.
* Dummy declaration with no implementation, just to hide the function.
@param kSource Source object to be copied.
*/
CGUIObserver(const CGUIObserver& kSource);
/** Operator= method. Should not be used.
* Dummy declaration with no implementation, just to hide the function.
@param kSource Source object to be copied.
@return This object.
*/
CGUIObserver& operator=(const CGUIObserver& kSource);
/** Holds the pointers to the Subjects subscribed to,
to unsubscribe the Observer on destruction.
*/
eC_TListDoubleLinked<CGUISubject*> m_kSubjectList;
/** Indicates if this observer will automatically delete itself when the number of observed subjects reaches zero */
eC_Bool m_bAutoDelete;
};
#endif
|
dd991bb836ad7cb24471b0ec0777848057586f14
|
09c57873d0aec96baab343e45de1dbdd493ef6ab
|
/test/idea.cpp
|
d956b4758fc7ee8a934dd4439142cefb1045ac5c
|
[] |
no_license
|
pass0a/cactus
|
58153dd067aed85dda022a0b60740f9c64bb4a0b
|
9ffa5c323e1d833b2409c71f12e61fe5d86ac64a
|
refs/heads/master
| 2020-03-27T21:55:50.976935
| 2019-08-12T07:12:37
| 2019-08-12T07:12:37
| 147,187,930
| 0
| 1
| null | 2019-08-12T07:28:54
| 2018-09-03T10:17:21
|
C++
|
UTF-8
|
C++
| false
| false
| 153
|
cpp
|
idea.cpp
|
#include "cactus.hpp"
#include "core/kernels/eigenwrapper.h"
#include <algorithm>
using namespace cactus;
int main()
{
return 0;
}
|
edc5e80b83ea72fd4a9ec524a6965e7d76a92175
|
cdf8258aa3a44fbac1e3d735b4490b840be3d6b4
|
/P2-Obl1PiasSegovia/boolean.cpp
|
b0e9b2a757c1e96c1162a796bb3e18853dea828c
|
[
"MIT"
] |
permissive
|
joasegovia9427/P2Obl1-2017-Segovia-Pias
|
91654b335a8c4a39f8fde4f85a9321d23eae21bd
|
051df96ebc1cc604669ff0db27697c71c4a45b92
|
refs/heads/master
| 2021-04-12T12:27:10.704278
| 2018-03-22T17:50:40
| 2018-03-22T17:50:40
| 126,373,843
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 950
|
cpp
|
boolean.cpp
|
#include <stdio.h>
#include "boolean.h"
void booleanPROC_carga(boolean &booleanoAcargar){
char opcion;
do{
fflush(stdin);
printf("\nIngrese una opci%sn(S o N): ", LETRA_o);
scanf("%c",&opcion);
switch (opcion){
case 's': booleanoAcargar=TRUE;
break;
case 'S': booleanoAcargar=TRUE;
break;
case 'n': booleanoAcargar=FALSE;
break;
case 'N': booleanoAcargar=FALSE;
break;
default:
printf("\nError al leer dato, reintente...");
break;
}
} while (opcion != 'S' && opcion != 's' && opcion != 'N' && opcion != 'n');
}
void booleanPROC_mostrar(boolean booleanoAdesplegar){
switch (booleanoAdesplegar){
case FALSE: printf(" Falso");
break;
case TRUE: printf(" Verdadero");
break;
}
}
|
25f365413d00bb78214d55ef0293183a85977de1
|
d1bae97cbf46068cc1e91a23aaac7340d4483265
|
/SpaceGolfGame/SpaceGolfGame/Gui/GuiBgfxRenderTarget.h
|
6f1aee642e6347c9c7cd5164ef37ae4bb07e3712
|
[] |
no_license
|
jinsuoliu/SpaceGolfGame
|
20cf02cc00f5f1cb6be442f95e0a2e1ab9927484
|
7cba5262c6495167aaccff9f198ec7f64f56d00d
|
refs/heads/master
| 2020-08-06T21:51:53.985391
| 2018-06-09T12:23:51
| 2018-06-09T12:23:51
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 893
|
h
|
GuiBgfxRenderTarget.h
|
#pragma once
#include <CEGUI/CEGUI.h>
using namespace CEGUI;
#include "GuiBgfxRenderer.h"
class GuiBgfxRenderTarget : public RenderTarget
{
protected:
GuiBgfxRenderer& owner;
uint8_t passId;
Rectf area;
public:
GuiBgfxRenderTarget(GuiBgfxRenderer& owner);
~GuiBgfxRenderTarget();
virtual void destroy() {}
// Inherited via RenderTarget
virtual void draw(const GeometryBuffer & buffer) override;
virtual void draw(const RenderQueue & queue) override;
virtual void setArea(const Rectf & area) override;
virtual const Rectf & getArea() const override;
virtual bool isImageryCache() const override;
virtual void activate() override;
virtual void deactivate() override;
virtual void unprojectPoint(const GeometryBuffer & buff, const Vector2f & p_in, Vector2f & p_out) const override;
void setPassId(uint8_t value) { passId = value; }
uint8_t getPassId() { return passId; }
};
|
c487de488edcad7588153766c9699a5b0eded721
|
66caf343d6a7e8ddc96743774dd19e7317a6ba5b
|
/shaderforth/pref_file.cpp
|
5a03558132550e7905d88f7d6ccf15ec7b80a466
|
[
"MIT"
] |
permissive
|
janm31415/vectorforth
|
906aa95736b30d2b9b444b210e4e9ec6d678a275
|
75a6dd7477f3b77238c54e3bde4de129099365d8
|
refs/heads/master
| 2023-02-17T11:09:15.414398
| 2023-02-13T16:47:54
| 2023-02-13T16:47:54
| 262,822,526
| 10
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 5,368
|
cpp
|
pref_file.cpp
|
#include "pref_file.h"
#include <sstream>
#include <iostream>
#include <fstream>
#include <json.hpp>
struct node_type
{
node_type() : j(nullptr) {}
node_type(nlohmann::json& i_j) : j(&i_j) {}
nlohmann::json* j;
};
pref_file_element::pref_file_element(const char* _parent_label, const std::shared_ptr<node_type>& _node) : node(_node), parent_label(_parent_label)
{}
pref_file_element::~pref_file_element()
{
}
namespace
{
std::string _to_string(const nlohmann::json& j)
{
std::stringstream str;
switch (j.type())
{
case nlohmann::detail::value_t::string:
{
const std::string& s = j.get<std::string>();
return s;
break;
}
case nlohmann::detail::value_t::number_integer:
{
str << j.get<nlohmann::json::number_integer_t>();
return str.str();
break;
}
case nlohmann::detail::value_t::number_unsigned:
{
str << j.get<nlohmann::json::number_unsigned_t>();
return str.str();
break;
}
case nlohmann::detail::value_t::number_float:
{
str << j.get<nlohmann::json::number_float_t>();
return str.str();
break;
}
case nlohmann::detail::value_t::boolean:
{
str << j.get<nlohmann::json::boolean_t>();
return str.str();
break;
}
}
return std::string();
}
}
std::string pref_file_element::to_string() const
{
if (node)
{
return _to_string(*(node->j));
}
return std::string();
}
std::vector<std::string> pref_file_element::get_text() const
{
std::vector<std::string> out;
if (node)
{
switch (node->j->type())
{
case nlohmann::detail::value_t::array:
{
for (nlohmann::json::const_iterator it = node->j->begin(); it != node->j->end(); ++it)
out.push_back(_to_string(it.value()));
}
}
}
std::string s = _to_string(*(node->j));
if (!s.empty())
out.push_back(s);
return out;
}
bool pref_file_element::valid() const
{
return node != nullptr;
}
pref_file_element pref_file_element::operator[](const char* label) const
{
if (node)
{
switch (node->j->type())
{
case nlohmann::detail::value_t::object:
{
for (nlohmann::json::iterator it = node->j->begin(); it != node->j->end(); ++it)
{
if (it.key() == std::string(label))
{
return pref_file_element(label, std::make_shared<node_type>(it.value()));
}
}
break;
}
}
}
return pref_file_element(label, nullptr);
}
pref_file_element pref_file_element::AddChild(const char* label)
{
(*node->j)[label] = nullptr;
for (nlohmann::json::iterator it = node->j->begin(); it != node->j->end(); ++it)
{
if (it.key() == std::string(label))
{
return pref_file_element(label, std::make_shared<node_type>(it.value()));
}
}
return pref_file_element(label, nullptr);
}
pref_file_element pref_file_element::AddValue(const std::string& value)
{
(*node->j) = value;
return *this;
}
pref_file_element pref_file_element::AddValue(const char* value)
{
(*node->j) = value;
return *this;
}
pref_file_element pref_file_element::AddValue(double value)
{
(*node->j) = value;
return *this;
}
pref_file_element pref_file_element::AddValue(int value)
{
(*node->j) = value;
return *this;
}
pref_file_element pref_file_element::AddValue(int64_t value)
{
(*node->j) = value;
return *this;
}
pref_file_element pref_file_element::AddValue(uint64_t value)
{
(*node->j) = value;
return *this;
}
pref_file_element pref_file_element::AddValue(bool value)
{
(*node->j) = value;
return *this;
}
pref_file_element pref_file_element::PushValue(const std::string& value)
{
(*node->j).push_back(value);
return *this;
}
pref_file_element pref_file_element::PushValue(const char* value)
{
(*node->j).push_back(value);
return *this;
}
pref_file_element pref_file_element::PushValue(double value)
{
(*node->j).push_back(value);
return *this;
}
pref_file_element pref_file_element::PushValue(int value)
{
(*node->j).push_back(value);
return *this;
}
pref_file_element pref_file_element::PushValue(int64_t value)
{
(*node->j).push_back(value);
return *this;
}
pref_file_element pref_file_element::PushValue(uint64_t value)
{
(*node->j).push_back(value);
return *this;
}
pref_file_element pref_file_element::PushValue(bool value)
{
(*node->j).push_back(value);
return *this;
}
///////////////////////////////////////////////////////////////////////////////
pref_file::pref_file(const char* _filename, EFileMode _mode) : filename(_filename), mode(_mode),
pref_file_element("root", std::make_shared<node_type>())
{
node->j = new nlohmann::json();
if (mode == READ)
{
std::ifstream i(_filename);
if (i.is_open())
{
try
{
i >> *(node->j);
}
catch (nlohmann::detail::exception e)
{
printf("Error: %s\n", e.what());
}
i.close();
}
}
}
pref_file::~pref_file()
{
delete node->j;
}
void pref_file::release()
{
if (mode == WRITE)
{
std::ofstream o(filename);
if (o.is_open())
{
o << *(node->j);
o.close();
}
}
}
|
2ad926a19b1fb111dc1f57e253624a0b9e18979d
|
4573f01e53932292ea6a9525c489e00520e00338
|
/docs/sphinx/examples/metadata-formatwriter2.cpp
|
ce3a5822df5aaa2230862dfd544d0304e3ea512e
|
[
"BSD-2-Clause"
] |
permissive
|
moalsad/ome-files-cpp
|
2090ea74a6f4986dbae2e7e460d75bc79a4bfaeb
|
e8e3c03cab4d00edb96f40aa2b86bc7c99d6588c
|
refs/heads/master
| 2022-01-25T08:14:17.801554
| 2019-06-26T10:01:42
| 2019-06-26T10:01:42
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 14,929
|
cpp
|
metadata-formatwriter2.cpp
|
/*
* #%L
* OME-FILES C++ library for image IO.
* Copyright © 2015–2017 Open Microscopy Environment:
* - Massachusetts Institute of Technology
* - National Institutes of Health
* - University of Dundee
* - Board of Regents of the University of Wisconsin-Madison
* - Glencoe Software, Inc.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of any organization.
* #L%
*/
#include <iostream>
#include <memory>
#include <boost/filesystem/path.hpp>
#include <ome/files/CoreMetadata.h>
#include <ome/files/MetadataTools.h>
#include <ome/files/VariantPixelBuffer.h>
#include <ome/files/out/OMETIFFWriter.h>
#include <ome/xml/meta/OMEXMLMetadata.h>
#include <ome/xml/model/AnnotationRef.h>
#include <ome/xml/model/Channel.h>
#include <ome/xml/model/Detector.h>
#include <ome/xml/model/DetectorSettings.h>
#include <ome/xml/model/Image.h>
#include <ome/xml/model/Instrument.h>
#include <ome/xml/model/LongAnnotation.h>
#include <ome/xml/model/MapAnnotation.h>
#include <ome/xml/model/OME.h>
#include <ome/xml/model/Objective.h>
using boost::filesystem::path;
using std::make_shared;
using std::shared_ptr;
using std::static_pointer_cast;
using ome::files::createID;
using ome::files::dimension_size_type;
using ome::files::fillMetadata;
using ome::files::CoreMetadata;
using ome::files::DIM_SPATIAL_X;
using ome::files::DIM_SPATIAL_Y;
using ome::files::DIM_CHANNEL;
using ome::files::FormatWriter;
using ome::files::MetadataMap;
using ome::files::out::OMETIFFWriter;
using ome::files::PixelBuffer;
using ome::files::PixelBufferBase;
using ome::files::PixelProperties;
using ome::files::VariantPixelBuffer;
using ome::xml::model::enums::Binning;
using ome::xml::model::enums::Immersion;
using ome::xml::model::enums::PixelType;
using ome::xml::model::enums::DetectorType;
using ome::xml::model::enums::DimensionOrder;
using ome::xml::model::enums::UnitsLength;
using ome::xml::model::primitives::Quantity;
using ome::xml::meta::MetadataRetrieve;
using ome::xml::meta::MetadataStore;
using ome::xml::meta::Metadata;
using ome::xml::meta::OMEXMLMetadata;
namespace
{
shared_ptr<OMEXMLMetadata>
createMetadata()
{
/* create-metadata-start */
// OME-XML metadata store.
auto meta = make_shared<OMEXMLMetadata>();
// Create simple CoreMetadata and use this to set up the OME-XML
// metadata. This is purely for convenience in this example; a
// real writer would typically set up the OME-XML metadata from an
// existing MetadataRetrieve instance or by hand.
std::vector<shared_ptr<CoreMetadata>> seriesList;
shared_ptr<CoreMetadata> core(make_shared<CoreMetadata>());
core->sizeX = 512U;
core->sizeY = 512U;
core->sizeC.clear(); // defaults to 1 channel with 1 subchannel; clear this
core->sizeC.push_back(1);
core->sizeC.push_back(1);
core->sizeC.push_back(1);
core->pixelType = PixelType::UINT16;
core->interleaved = false;
core->bitsPerPixel = 12U;
core->dimensionOrder = DimensionOrder::XYZTC;
seriesList.push_back(core);
seriesList.push_back(core); // add two identical series
fillMetadata(*meta, seriesList);
/* create-metadata-end */
return meta;
}
void
addExtendedMetadata(shared_ptr<OMEXMLMetadata> store)
{
/* extended-metadata-start */
// Get root OME object
std::shared_ptr<ome::xml::meta::OMEXMLMetadataRoot>
root(std::dynamic_pointer_cast<ome::xml::meta::OMEXMLMetadataRoot>
(store->getRoot()));
if (!root)
return;
MetadataStore::index_type annotation_idx = 0;
// Create an Instrument.
auto instrument = make_shared<ome::xml::model::Instrument>();
instrument->setID(createID("Instrument", 0));
root->addInstrument(instrument);
// Create an Objective for this Instrument.
auto objective = make_shared<ome::xml::model::Objective>();
objective->setID(createID("Objective", 0));
auto objective_manufacturer = std::make_shared<std::string>("InterFocal");
objective->setManufacturer(objective_manufacturer);
auto objective_nominal_mag = std::make_shared<double>(40.0);
objective->setNominalMagnification(objective_nominal_mag);
auto objective_na = std::make_shared<double>(0.4);
objective->setLensNA(objective_na);
auto objective_immersion = std::make_shared<Immersion>(Immersion::OIL);
objective->setImmersion(objective_immersion);
auto objective_wd = std::make_shared<Quantity<UnitsLength>>
(0.34, UnitsLength::MILLIMETER);
objective->setWorkingDistance(objective_wd);
instrument->addObjective(objective);
// Create a Detector for this Instrument.
auto detector = make_shared<ome::xml::model::Detector>();
std::string detector_id = createID("Detector", 0);
detector->setID(detector_id);
auto detector_manufacturer = std::make_shared<std::string>("MegaCapture");
detector->setManufacturer(detector_manufacturer);
auto detector_type = std::make_shared<DetectorType>(DetectorType::CCD);
detector->setType(detector_type);
instrument->addDetector(detector);
// Get Image and Channel for future use. Note for your own code,
// you should check that the elements exist before accessing them;
// here we know they are valid because we created them above.
auto image = root->getImage(0);
auto pixels = image->getPixels();
auto channel0 = pixels->getChannel(0);
auto channel1 = pixels->getChannel(1);
auto channel2 = pixels->getChannel(2);
// Create Settings for this Detector for each Channel on the Image.
auto detector_settings0 = make_shared<ome::xml::model::DetectorSettings>();
{
detector_settings0->setID(detector_id);
auto detector_binning = std::make_shared<Binning>(Binning::TWOBYTWO);
detector_settings0->setBinning(detector_binning);
auto detector_gain = std::make_shared<double>(83.81);
detector_settings0->setGain(detector_gain);
channel0->setDetectorSettings(detector_settings0);
}
auto detector_settings1 = make_shared<ome::xml::model::DetectorSettings>();
{
detector_settings1->setID(detector_id);
auto detector_binning = std::make_shared<Binning>(Binning::TWOBYTWO);
detector_settings1->setBinning(detector_binning);
auto detector_gain = std::make_shared<double>(56.89);
detector_settings1->setGain(detector_gain);
channel1->setDetectorSettings(detector_settings1);
}
auto detector_settings2 = make_shared<ome::xml::model::DetectorSettings>();
{
detector_settings2->setID(detector_id);
auto detector_binning = std::make_shared<Binning>(Binning::FOURBYFOUR);
detector_settings2->setBinning(detector_binning);
auto detector_gain = std::make_shared<double>(12.93);
detector_settings2->setGain(detector_gain);
channel2->setDetectorSettings(detector_settings2);
}
/* extended-metadata-end */
/* annotations-start */
// Add Structured Annotations.
auto sa = std::make_shared<ome::xml::model::StructuredAnnotations>();
root->setStructuredAnnotations(sa);
// Create a MapAnnotation.
auto map_ann0 = std::make_shared<ome::xml::model::MapAnnotation>();
std::string annotation_id = createID("Annotation", annotation_idx);
map_ann0->setID(annotation_id);
auto map_ann0_ns = std::make_shared<std::string>
("https://microscopy.example.com/colour-balance");
map_ann0->setNamespace(map_ann0_ns);
ome::xml::model::primitives::OrderedMultimap map;
map.push_back({"white-balance", "5,15,8"});
map.push_back({"black-balance", "112,140,126"});
map_ann0->setValue(map);
sa->addMapAnnotation(map_ann0);
// Link MapAnnotation to Detector.
detector->linkAnnotation(map_ann0);
// Create a LongAnnotation.
auto long_ann0 = std::make_shared<ome::xml::model::LongAnnotation>();
++annotation_idx;
annotation_id = createID("Annotation", annotation_idx);
long_ann0->setID(annotation_id);
auto long_ann0_ns = std::make_shared<std::string>
("https://microscopy.example.com/trigger-delay");
long_ann0->setNamespace(long_ann0_ns);
long_ann0->setValue(239423);
sa->addLongAnnotation(long_ann0);
// Link LongAnnotation to Image.
image->linkAnnotation(long_ann0);
// Create a second LongAnnotation.
auto long_ann1 = std::make_shared<ome::xml::model::LongAnnotation>();
++annotation_idx;
annotation_id = createID("Annotation", annotation_idx);
long_ann1->setID(annotation_id);
auto long_ann1_ns = std::make_shared<std::string>
("https://microscopy.example.com/sample-number");
long_ann1->setNamespace(long_ann1_ns);
long_ann1->setValue(934223);
sa->addLongAnnotation(long_ann1);
// Link second LongAnnotation to Image.
image->linkAnnotation(long_ann1);
/* annotations-end */
}
void
writePixelData(FormatWriter& writer,
std::ostream& stream)
{
/* pixel-example-start */
// Total number of images (series)
dimension_size_type ic = writer.getMetadataRetrieve()->getImageCount();
stream << "Image count: " << ic << '\n';
// Loop over images
for (dimension_size_type i = 0 ; i < ic; ++i)
{
// Change the current series to this index
writer.setSeries(i);
// Total number of planes.
dimension_size_type pc = 1U;
pc *= writer.getMetadataRetrieve()->getPixelsSizeZ(i);
pc *= writer.getMetadataRetrieve()->getPixelsSizeT(i);
pc *= writer.getMetadataRetrieve()->getChannelCount(i);
stream << "\tPlane count: " << pc << '\n';
// Loop over planes (for this image index)
for (dimension_size_type p = 0 ; p < pc; ++p)
{
// Change the current plane to this index.
writer.setPlane(p);
// Pixel buffer; size 512 × 512 with 3 channels of type
// uint16_t. It uses the native endianness and has a
// storage order of XYZTC without interleaving
// (subchannels are planar).
shared_ptr<PixelBuffer<PixelProperties<PixelType::UINT16>::std_type>>
buffer(make_shared<PixelBuffer<PixelProperties<PixelType::UINT16>::std_type>>
(boost::extents[512][512][1][1][1][1][1][1][1],
PixelType::UINT16, ome::files::ENDIAN_NATIVE,
PixelBufferBase::make_storage_order(DimensionOrder::XYZTC, false)));
// Fill each subchannel with a different intensity ramp in
// the 12-bit range. In a real program, the pixel data
// would typically be obtained from data acquisition or
// another image.
for (dimension_size_type x = 0; x < 512; ++x)
for (dimension_size_type y = 0; y < 512; ++y)
{
PixelBufferBase::indices_type idx;
std::fill(idx.begin(), idx.end(), 0);
idx[DIM_SPATIAL_X] = x;
idx[DIM_SPATIAL_Y] = y;
idx[DIM_CHANNEL] = 0;
switch(p)
{
case 0:
buffer->at(idx) = (static_cast<float>(x) / 512.0f) * 4096.0f;
break;
case 1:
buffer->at(idx) = (static_cast<float>(y) / 512.0f) * 4096.0f;
break;
case 2:
buffer->at(idx) = (static_cast<float>(x+y) / 1024.0f) * 4096.0f;
break;
default:
break;
}
}
VariantPixelBuffer vbuffer(buffer);
stream << "PixelBuffer PixelType is " << buffer->pixelType() << '\n';
stream << "VariantPixelBuffer PixelType is " << vbuffer.pixelType() << '\n';
stream << std::flush;
// Write the the entire pixel buffer to the plane.
writer.saveBytes(p, vbuffer);
stream << "Wrote " << buffer->num_elements() << ' ' << buffer->pixelType() << " pixels\n";
}
}
/* pixel-example-end */
}
}
int
main(int argc, char *argv[])
{
// This is the default, but needs setting manually on Windows.
ome::common::setLogLevel(ome::logging::trivial::warning);
try
{
if (argc > 1)
{
// Portable path
path filename(argv[1]);
/* writer-example-start */
// Create metadata for the file to be written.
auto meta = createMetadata();
// Add extended metadata.
addExtendedMetadata(meta);
// Create TIFF writer
auto writer = make_shared<OMETIFFWriter>();
// Set writer options before opening a file
auto retrieve = static_pointer_cast<MetadataRetrieve>(meta);
writer->setMetadataRetrieve(retrieve);
writer->setInterleaved(false);
// Open the file
writer->setId(filename);
// Write pixel data
writePixelData(*writer, std::cout);
// Explicitly close writer
writer->close();
/* writer-example-end */
}
else
{
std::cerr << "Usage: " << argv[0] << " ome-xml.ome.tiff\n";
std::exit(1);
}
}
catch (const std::exception& e)
{
std::cerr << "Caught exception: " << e.what() << '\n';
std::exit(1);
}
catch (...)
{
std::cerr << "Caught unknown exception\n";
std::exit(1);
}
}
|
4a6fab8fc32e7299c7a903bb1d5712c41822b72c
|
1bc03dc0faba85119c44c2e0d90dbcbba72d56e5
|
/1.cpp
|
edba31908ea83b57771c726376d4349880d5f93d
|
[] |
no_license
|
SHOAIBAHMED12842/INTENSIVE-C-PROGRAMMING-UNIT
|
3ad936727a9d98a25c2f1d344344fe328ea63e0f
|
d69902e2579badc8030377cebeee1cf8ba463444
|
refs/heads/master
| 2021-10-11T13:17:29.417031
| 2019-01-26T10:59:34
| 2019-01-26T10:59:34
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 185
|
cpp
|
1.cpp
|
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10,c=15,sum;
printf("input three numbers=%d,%d,%d",a,b,c);
sum=a+b+c;
printf("\nsum of three numbers=%d",sum);
}
|
0223249ba5e3cb4220b8bf12e43bf837896accc1
|
ac682ebfe420577fdbd033f5839d2a934072debc
|
/jobdu/1135.cpp
|
0f0868e74502123f54eb26901cefabc989556747
|
[] |
no_license
|
ButteredCat/Online_Judge
|
de70ef477a80e54db382df2e8ddb00d2a1772e60
|
da2ad04352e32e5334b89b59969ec704faa23446
|
refs/heads/master
| 2021-01-22T23:49:09.926787
| 2014-12-28T06:07:47
| 2014-12-28T06:07:47
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 422
|
cpp
|
1135.cpp
|
#include<iostream>
#include<string>
#include<map>
using namespace std;
int
main ()
{
int n;
while (cin >> n)
{
string s;
multimap < string::size_type, string > m;
cin.ignore ();
while (n-- && getline (cin, s) && s != "stop")
m.insert (make_pair (s.size (), s));
for (multimap < string::size_type, string >::iterator i =
m.begin (); i != m.end (); ++i)
cout << i->second << endl;
}
return 0;
}
|
6154dd12707999a049bc10bf6ced450d4b20a62e
|
d525a38d6e99862dbb1186058dc7e77fcb7f1488
|
/Source/A/MyPlayerState.cpp
|
b6380b770f9365d8913e34e001ffe1092f745e90
|
[] |
no_license
|
Yuandiaodiaodiao/UE4-startup
|
0f9f3d2ea24e07e97ece5a2dda005763c76fd426
|
d2ddbbe22e173bac4bb15305f62ffa5dfd174f95
|
refs/heads/master
| 2023-09-03T22:13:31.683579
| 2021-09-12T16:49:07
| 2021-09-12T16:49:07
| 306,943,082
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 206
|
cpp
|
MyPlayerState.cpp
|
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyPlayerState.h"
void AMyPlayerState::BeginPlay()
{
UE_LOG(LogTemp, Warning, TEXT("MyPlayerState begin"));
}
|
62098350e5abfff5076dab35c4e5aca07dc7aed5
|
42db2e546425ee98a43419a4231447e87cbef14b
|
/ProyectoFinal/ProyectoFinal/Personaje.h
|
12e419966bc8c1fd7631b80de343128631549bed
|
[] |
no_license
|
JoanRufo/ProyectoProgramacion
|
2ded521a2d37d6b2228b67e43e5f0949b5ac16b8
|
cbf5e32c9e9d991433f6daeff6befc3a9207fd88
|
refs/heads/main
| 2023-05-08T13:11:50.279607
| 2021-06-03T21:30:28
| 2021-06-03T21:30:28
| 340,086,678
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 889
|
h
|
Personaje.h
|
#pragma once
#include "SDL.h"
#include <iostream>
#include <stdio.h>
#include "Controles.h"
#include "ResourceManager.h"
#include "Video.h"
#include "Balas.h"
#include "Habitacion2.h"
#include <vector>
class Personaje
{
int velPersonaje;
int bala;
bool a;
bool b;
public:
float Posx;
float Posy;
float width;
float height;
float vel = 0.35;
int idDelPersonaje;
int idDelPersonaje2;
int idDelPersonaje3;
int idDelPersonaje4;
int PersonajeDerecha;
int PersonajeIzquierda;
int PersonajeAbajo;
int PersonajeArriba;
int idPersonaje;
int idDireccion;
void init();
void update();
void render();
void MovimientoPersonaje();
ResourceManager* mResourceManager = ResourceManager::getInstance();
Video* mVideo = Video::getInstance();
std::vector<Balas>* pVectorBalas;
void setpVectorBalas(std::vector<Balas> *a) {
pVectorBalas = a;
}
};
|
0e9ea83c7185871e18a5b8dd25dfad85055886b0
|
5bb332b9a97ffa7089b0b3a055bca1e90ea728e9
|
/components/path_follower/src/specificworker.cpp
|
c3da8d56726b9942537aad09a1d889be3c029383
|
[] |
no_license
|
robocomp/dsr-graph
|
c47f8e51b0745489b7a576e3fd2506a5c2a23e3e
|
04c3f18f5bcb51edf15f2ad6a6f06a65c94bd293
|
refs/heads/development
| 2022-07-28T14:59:20.071299
| 2022-06-29T20:00:24
| 2022-06-29T20:00:24
| 161,624,159
| 6
| 35
| null | 2021-10-07T10:07:17
| 2018-12-13T10:42:09
|
C++
|
UTF-8
|
C++
| false
| false
| 26,434
|
cpp
|
specificworker.cpp
|
/*
* Copyright (C) 2020 by YOUR NAME HERE
*
* This file is part of RoboComp
*
* RoboComp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RoboComp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RoboComp. If not, see <http://www.gnu.org/licenses/>.
*/
#include "specificworker.h"
#include <cppitertools/zip.hpp>
#include <cppitertools/sliding_window.hpp>
#include <cppitertools/enumerate.hpp>
#include <cppitertools/range.hpp>
#include <algorithm>
#include <QPointF>
#include <ranges>
/**
* \brief Default constructor
*/
SpecificWorker::SpecificWorker(TuplePrx tprx, bool startup_check) : GenericWorker(tprx)
{
qRegisterMetaType<std::uint64_t>("std::uint64_t");
this->startup_check_flag = startup_check;
QLoggingCategory::setFilterRules("*.debug=false\n");
}
/**
* \brief Default destructor
*/
SpecificWorker::~SpecificWorker()
{
std::cout << "Destroying SpecificWorker" << std::endl;
G.reset();
}
bool SpecificWorker::setParams(RoboCompCommonBehavior::ParameterList params)
{
conf_params = std::make_shared<RoboCompCommonBehavior::ParameterList>(params);
try
{
std::setlocale(LC_NUMERIC, "C");
agent_name = params["agent_name"].value;
agent_id = stoi(params["agent_id"].value);
tree_view = params["tree_view"].value == "true";
graph_view = params["graph_view"].value == "true";
qscene_2d_view = params["2d_view"].value == "true";
osg_3d_view = params["3d_view"].value == "true";
consts.max_adv_speed = stof(params.at("max_advance_speed").value);
consts.max_rot_speed = stof(params.at("max_rotation_speed").value);
consts.max_side_speed = stof(params.at("max_side_speed").value);
consts.robot_length = stof(params.at("robot_length").value);
consts.robot_width = stof(params.at("robot_width").value);
consts.robot_radius = stof(params.at("robot_radius").value);
consts.lateral_correction_gain = stof(params.at("lateral_correction_gain").value);
consts.lateral_correction_for_side_velocity = stof(params.at("lateral_correction_for_side_velocity").value);
consts.rotation_gain = std::stof(params.at("rotation_gain").value);
consts.times_final_distance_to_target_before_zero_rotation = stof(params.at("times_final_distance_to_target_before_zero_rotation").value);
consts.advance_gaussian_cut_x = stof(params.at("advance_gaussian_out_x").value);
consts.advance_gaussian_cut_y = stof(params.at("advance_gaussian_out_y").value);
consts.final_distance_to_target = stof(params.at("final_distance_to_target").value); // mm
}
catch (const std::exception &e)
{
std::cout << __FUNCTION__ << " Problem reading params" << std::endl;
std::terminate();
};
return true;
}
void SpecificWorker::initialize(int period)
{
std::cout << __FUNCTION__ << std::endl;
this->Period = period;
if(this->startup_check_flag)
this->startup_check();
else
{
// create graph
G = std::make_shared<DSR::DSRGraph>(0, agent_name, agent_id); // Init nodes
std::cout<< __FUNCTION__ << "Graph loaded" << std::endl;
// Graph viewer
using opts = DSR::DSRViewer::view;
int current_opts = 0;
opts main = opts::none;
if(tree_view)
current_opts = current_opts | opts::tree;
if(graph_view)
current_opts = current_opts | opts::graph;
if(qscene_2d_view)
current_opts = current_opts | opts::scene;
if(osg_3d_view)
current_opts = current_opts | opts::osg;
dsr_viewer = std::make_unique<DSR::DSRViewer>(this, G, current_opts, main);
setWindowTitle(QString::fromStdString(agent_name + "-" + std::to_string(agent_id)));
//dsr update signals
connect(G.get(), &DSR::DSRGraph::update_node_signal, this, &SpecificWorker::add_or_assign_node_slot, Qt::QueuedConnection);
//connect(G.get(), &DSR::DSRGraph::update_edge_signal, this, &SpecificWorker::add_or_assign_edge_slot);
//connect(G.get(), &DSR::DSRGraph::update_attrs_signal, this, &SpecificWorker::add_or_assign_attrs_slot);
//connect(G.get(), &DSR::DSRGraph::del_edge_signal, this, &SpecificWorker::del_edge_slot);
connect(G.get(), &DSR::DSRGraph::del_node_signal, this, &SpecificWorker::del_node_slot, Qt::QueuedConnection);
//Inner Api
inner_eigen = G->get_inner_eigen_api();
// self agent api
agent_info_api = std::make_unique<DSR::AgentInfoAPI>(G.get());
// Ignore attributes from G
G->set_ignored_attributes<cam_rgb_att, cam_depth_att >();
// Custom widget
dsr_viewer->add_custom_widget_to_dock("Path follower", &custom_widget);
connect(custom_widget.startButton, &QPushButton::clicked, [this]()
{
if(robot_is_active)
{
robot_is_active = false;
send_command_to_robot((std::make_tuple(0, 0, 0)));
custom_widget.startButton->setText("Start");
}
else
{
robot_is_active = true;
custom_widget.startButton->setText("Stop");
}
});
widget_2d = qobject_cast<DSR::QScene2dViewer *>(dsr_viewer->get_widget(opts::scene));
if (widget_2d != nullptr)
widget_2d->set_draw_laser(false);
// path planner
path_follower_initialize();
// check for existing path node
if(auto paths = G->get_nodes_by_type(path_to_target_type_name); not paths.empty())
{
std::cout << paths.front().name() << paths.front().id() << std::endl;
this->add_or_assign_node_slot(paths.front().id(), path_to_target_type_name);
}
std::cout<< __FUNCTION__ << "Initialization finished" << std::endl;
timer.start(Period);
}
}
void SpecificWorker::compute()
{
static std::vector<Eigen::Vector2f> path, saved_path;
// Check for existing path_to_target_nodes
if (auto path_o = path_buffer.try_get(); path_o.has_value()) // NEW PATH!
{
qInfo() << __FUNCTION__ << "New path";
path.clear();
path = path_o.value();
if(is_cyclic.load())
saved_path = path;
current_target = path.back();
robot_is_active = true;
if(widget_2d != nullptr)
draw_path(path, &widget_2d->scene);
}
// if there is a path in G
if(auto node_path = G->get_node(current_path_name); node_path.has_value())
{
//if (const auto laser_data = laser_buffer.try_get(); laser_data.has_value())
{
//const auto &[angles, dists, laser_poly, laser_cart] = laser_data.value();
auto nose_3d = inner_eigen->transform(world_name, Mat::Vector3d(0, 500, 0), robot_name).value();
auto robot_pose_3d = inner_eigen->transform(world_name, robot_name).value();
auto robot_nose = Eigen::Vector2f(nose_3d.x(), nose_3d.y());
auto robot_pose = Eigen::Vector2f(robot_pose_3d.x(), robot_pose_3d.y());
auto speeds = update(path, QPolygonF(), robot_pose, robot_nose, current_target);
auto[adv, side, rot] = send_command_to_robot(speeds);
if(not is_cyclic.load())
remove_trailing_path(path, robot_pose);
if(not robot_is_active) // robot reached the target
{
if(not is_cyclic.load())
if(auto path_d = G->get_node(current_path_name); path_d.has_value())
G->delete_node(path_d.value().id());
else
{
path = saved_path;
robot_is_active = true;
}
}
print_current_state(path, robot_pose, adv, side, rot);
}
//else
//{} // check elapsed time since last reading. Stop the robot if too long
}
else // stop controlling
{
qDebug() << __FUNCTION__ << "No path_node found in G. Stopping the robot";
}
fps.print("FPS: ", [this](auto x){ dsr_viewer->set_external_hz(x);});
}
void SpecificWorker::path_follower_initialize()
{
qDebug() << __FUNCTION__ << "Controller - ";
robotBottomLeft = Mat::Vector3d(-consts.robot_width / 2, -consts.robot_length / 2, 0);
robotBottomRight = Mat::Vector3d(consts.robot_width / 2, -consts.robot_length / 2, 0);
robotTopRight = Mat::Vector3d(consts.robot_width / 2, consts.robot_length / 2, 0);
robotTopLeft = Mat::Vector3d(-consts.robot_width / 2, consts.robot_length / 2, 0);
qInfo() << __FUNCTION__ << "CONTROLLER: Params from config:" << consts.max_adv_speed << consts.max_rot_speed << consts.max_side_speed << consts.max_lag
<< consts.robot_radius;
}
void SpecificWorker::remove_trailing_path(const std::vector<Eigen::Vector2f> &path, const Eigen::Vector2f &robot_pose)
{
// closest point to robot nose in path
if(path.size() == 1) return;
auto closest_point_to_robot = std::ranges::min_element(path, [robot_pose](auto &a, auto &b){ return (robot_pose - a).norm() < (robot_pose - b).norm();});
std::vector<float> x_values; x_values.reserve(path.size());
std::transform(closest_point_to_robot, path.cend(), std::back_inserter(x_values),
[](const auto &value) { return value.x(); });
std::vector<float> y_values; y_values.reserve(path.size());
std::transform(closest_point_to_robot, path.cend(), std::back_inserter(y_values),
[](const auto &value) { return value.y(); });
qInfo() << __FUNCTION__ << " new paths " << x_values.size() << y_values.size();
if (auto node_path = G->get_node(current_path_name); node_path.has_value())
//if (auto node_paths = G->get_nodes_by_type(path_to_target_type_name); not node_paths.empty())
{
//auto path_to_target_node = node_paths.front();
G->add_or_modify_attrib_local<path_x_values_att>(node_path.value(), x_values);
G->add_or_modify_attrib_local<path_y_values_att>(node_path.value(), y_values);
G->update_node(node_path.value());
}
else
std::cout << __FUNCTION__ << "No path target " << std::endl;
}
float SpecificWorker::dist_along_path(const std::vector<Eigen::Vector2f> &path)
{
float len = 0.0;
for(auto &&p : iter::sliding_window(path, 2))
len += (p[1]-p[0]).norm();
return len;
};
std::tuple<float, float, float> SpecificWorker::update(const std::vector<Eigen::Vector2f> &path, const QPolygonF &laser_poly, const Eigen::Vector2f &robot_pose,
const Eigen::Vector2f &robot_nose, const Eigen::Vector2f &target)
{
static float adv_vel_ant = 0;
qDebug() << " Controller - "<< __FUNCTION__;
if(path.size() < 2)
{
qWarning() << __FUNCTION__ << " Path with less than 2 elements. Returning";
robot_is_active = false;
return std::make_tuple(0, 0, 0);
}
// now y is forward direction and x is pointing rightwards
float advVel = 0.f, sideVel = 0.f, rotVel = 0.f;
// Compute euclidean distance to target
float euc_dist_to_target = (robot_pose - target).norm();
auto is_increasing = [](float new_val)
{ static float ant_value = 0.f;
bool res = false;
if( new_val - ant_value > 0 ) res = true;
ant_value = new_val;
return res;
};
//if( (path.size() < 2) or (euc_dist_to_target < consts.final_distance_to_target))
if( (path.size() < 2) or (dist_along_path(path) < consts.final_distance_to_target))
{
qInfo() << __FUNCTION__ << " -------------- Target achieved -----------------";
advVel = 0; sideVel= 0; rotVel = 0;
robot_is_active = false;
custom_widget.startButton->setText("Start");
return std::make_tuple(0,0,0); //adv, side, rot
}
// lambda to convert from Eigen to QPointF
auto to_QPointF = [](const Eigen::Vector2f &a){ return QPointF(a.x(), a.y());};
/// Compute rotational speed with the Stanley algorithm
// closest point to robot nose in path
auto closest_point_to_nose = std::ranges::min_element(path, [robot_nose](auto &a, auto &b){ return (robot_nose - a).norm() < (robot_nose - b).norm();});
// compute angle between robot-to-nose line and tangent to closest point in path
QLineF tangent;
if(std::distance(path.cbegin(), closest_point_to_nose) == 0)
tangent = QLineF(to_QPointF(*closest_point_to_nose), to_QPointF(*std::next(path.cbegin(),1)));
else if(std::distance(closest_point_to_nose, path.cend()) == 0)
tangent = QLineF(to_QPointF(*closest_point_to_nose), to_QPointF(*path.cend()));
else tangent = QLineF(to_QPointF(*(closest_point_to_nose - 1)), to_QPointF(*(closest_point_to_nose + 1)));
QLineF robot_to_nose(to_QPointF(robot_pose), to_QPointF(robot_nose));
float angle = rewrapAngleRestricted(qDegreesToRadians(robot_to_nose.angleTo(tangent)));
// compute distance to path to cancel stationary error
auto e_tangent = Eigen::Hyperplane<float, 2>::Through(Eigen::Vector2f(tangent.p1().x(), tangent.p1().y()),
Eigen::Vector2f(tangent.p2().x(), tangent.p2().y()));
float signed_distance = e_tangent.signedDistance(robot_nose);
//float correction = consts.lateral_correction_gain * tanh(signed_distance);
adv_vel_ant = std::clamp(adv_vel_ant, 10.f, 1000.f);
float correction = atan2( consts.lateral_correction_gain * signed_distance, adv_vel_ant);
angle += correction;
//
sideVel = consts.lateral_correction_for_side_velocity * correction;
// rot speed gain
rotVel = consts.rotation_gain * angle;
qInfo() << __FUNCTION__ << " angle error: " << angle << " correction: " << correction << " rorVel" << rotVel << " gain" << consts.rotation_gain << " max_rot_speed" << consts.max_rot_speed;
// limit angular values to physical limits
rotVel = std::clamp(rotVel, -consts.max_rot_speed, consts.max_rot_speed);
// cancel final rotation
if(euc_dist_to_target < consts.times_final_distance_to_target_before_zero_rotation * consts.final_distance_to_target)
rotVel = 0.f;
/// Compute advance speed
advVel = std::min(consts.max_adv_speed * exponentialFunction(rotVel, consts.advance_gaussian_cut_x, consts.advance_gaussian_cut_y, 0),
euc_dist_to_target);
adv_vel_ant = advVel;
return std::make_tuple(advVel, sideVel, rotVel);
}
//
//void SpecificWorker::pure_pursuit_control()
//{
//
//}
std::vector<QPointF> SpecificWorker::get_points_along_extended_robot_polygon(int offset, int chunck)
{
static QGraphicsRectItem *poly_draw = nullptr;
std::vector<QPointF> poly;
QRectF rp(QPointF(robotTopLeft.x(),robotTopLeft.y()), QPointF(robotBottomRight.x(), robotBottomRight.y()));
rp.adjust(-offset, offset, offset, -offset);
QLineF bottom(rp.bottomLeft(), rp.bottomRight());
QLineF left(rp.topLeft(), rp.bottomLeft());
QLineF top(rp.topLeft(), rp.topRight());
QLineF right(rp.topRight(), rp.bottomRight());
for(auto i : iter::range(0.f, 1.f, (float)(1.f/(top.length()/chunck))))
{
poly.push_back(top.pointAt(i));
poly.push_back(bottom.pointAt(i));
//auto aux = inner_eigen->transform(world_name, Eigen::Vector3d{point.x(), point.y(), 0.f}, robot_name);
//poly << QPointF(aux.value().x(), aux.value().y());
//point = bottom.pointAt(i);
//aux = inner_eigen->transform(world_name, Eigen::Vector3d{point.x(), point.y(), 0.f}, robot_name);
//poly << QPointF(aux.value().x(), aux.value().y());
}
for(auto i : iter::range(0.f, 1.f, (float)(1.f/(left.length()/chunck))))
{
poly.push_back(left.pointAt(i));
poly.push_back(right.pointAt(i));
// auto point = left.pointAt(i);
// auto aux = inner_eigen->transform(world_name, Eigen::Vector3d{point.x(), point.y(), 0.f}, robot_name);
// poly << QPointF(aux.value().x(), aux.value().y());
// point = right.pointAt(i);
// aux = inner_eigen->transform(world_name, Eigen::Vector3d{point.x(), point.y(), 0.f}, robot_name);
// poly << QPointF(aux.value().x(), aux.value().y());
}
if(poly_draw != nullptr)
{
widget_2d->scene.removeItem(poly_draw);
delete poly_draw;
}
poly_draw = widget_2d->scene.addRect(rp, QPen(QColor("blue"), 10));
auto robot_pos = inner_eigen->transform_axis(world_name, robot_name).value();
poly_draw->setRotation(qRadiansToDegrees(robot_pos[5]));
poly_draw->setPos(QPointF(robot_pos[0], robot_pos[1]));
return poly;
}
std::tuple<float, float, float> SpecificWorker::send_command_to_robot(const std::tuple<float, float, float> &speeds) //adv, side, rot
{
auto &[adv_, side_, rot_] = speeds;
if(auto robot_node = G->get_node(robot_name); robot_node.has_value())
{
G->add_or_modify_attrib_local<robot_ref_adv_speed_att>(robot_node.value(), (float) adv_);
G->add_or_modify_attrib_local<robot_ref_rot_speed_att>(robot_node.value(), (float) rot_);
G->add_or_modify_attrib_local<robot_ref_side_speed_att>(robot_node.value(), (float) side_);
G->update_node(robot_node.value());
}
else qWarning() << __FUNCTION__ << "No robot node found";
return std::make_tuple(adv_, side_, rot_);
}
// compute max de gauss(value) where gauss(x)=y y min
float SpecificWorker::exponentialFunction(float value, float xValue, float yValue, float min)
{
if (yValue <= 0)
return 1.f;
float landa = -fabs(xValue) / log(yValue);
float res = exp(-fabs(value) / landa);
return std::max(res, min);
}
float SpecificWorker::rewrapAngleRestricted(const float angle)
{
if (angle > M_PI)
return angle - M_PI * 2;
else if (angle < -M_PI)
return angle + M_PI * 2;
else
return angle;
}
void SpecificWorker::print_current_state(const std::vector<Eigen::Vector2f> &path, Eigen::Matrix<float, 2, 1> robot_pose, float adv, float side, float rot)
{
std::cout << "---------------------------" << std::endl;
std::cout << "Robot position: " << std::endl;
std::cout << "\t " << robot_pose.x() << ", " << robot_pose.y() << std::endl;
std::cout << "Target position: " << std::endl;
std::cout << "\t " << path.back().x() << ", " << path.back().y() << std::endl;
std::cout << "Dist to target: " << std::endl;
std::cout << "\t " << dist_along_path(path) << std::endl;
std::cout << "Ref speeds: " << std::endl;
std::cout << "\t Advance-> " << adv << std::endl;
std::cout << "\t Side -> " << side << std::endl;
std::cout << "\t Rotate -> " << rot << std::endl;
std::cout << "\tRobot_is_active -> " << std::boolalpha << robot_is_active << std::endl;
}
///////////////////////////////////////////////////////
//// Check new target from mouse
///////////////////////////////////////////////////////
void SpecificWorker::new_target_from_mouse(int pos_x, int pos_y, int id)
{
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
/// Asynchronous changes on G nodes from G signals
/////////////////////////////////////////////////////////////////////////////////////////////////////
void SpecificWorker::add_or_assign_node_slot(const std::uint64_t id, const std::string &type)
{
//check node type
if (type == path_to_target_type_name)
{
if( auto node = G->get_node(id); node.has_value())
{
auto x_values = G->get_attrib_by_name<path_x_values_att>(node.value());
auto y_values = G->get_attrib_by_name<path_y_values_att>(node.value());
auto is_cyclic_o = G->get_attrib_by_name<path_is_cyclic_att>(node.value());
if(is_cyclic_o.has_value())
is_cyclic.store(is_cyclic_o.value());
else is_cyclic.store(false);
if(x_values.has_value() and y_values.has_value())
{
auto x = x_values.value().get();
auto y = y_values.value().get();
std::vector<Eigen::Vector2f> path; path.reserve(x.size());
for (auto &&[x, y] : iter::zip(x, y))
path.push_back(Eigen::Vector2f(x, y));
path_buffer.put(std::move(path));
auto t_x = G->get_attrib_by_name<path_target_x_att>(node.value()); //
auto t_y = G->get_attrib_by_name<path_target_y_att>(node.value());
if(t_x.has_value() and t_y.has_value())
current_target = Eigen::Vector2f(t_x.value(), t_y.value());
auto cyclic = G->get_attrib_by_name<path_is_cyclic_att>(node.value()); //
}
}
}
// else if (type == laser_type_name) // Laser node updated
// {
// //qInfo() << __FUNCTION__ << " laser node change";
// if( auto node = G->get_node(id); node.has_value())
// {
// auto angles = G->get_attrib_by_name<laser_angles_att>(node.value());
// auto dists = G->get_attrib_by_name<laser_dists_att>(node.value());
// if(dists.has_value() and angles.has_value())
// {
// //if(dists.value().get().empty() or angles.value().get().empty()) return;
// //qInfo() << __FUNCTION__ << dists->get().size();
//
// std::tuple<std::vector<float>, std::vector<float>> && tuple = std::make_tuple(angles.value().get(), dists.value().get());
// laser_buffer.put(std::move(tuple),
// [this](LaserData &&in, std::tuple<std::vector<float>, std::vector<float>, QPolygonF, std::vector<QPointF>> &out)
// {
// QPolygonF laser_poly;
// std::vector<QPointF> laser_cart;
// auto &&[angles, dists] = in;
// for (auto &&[angle, dist] : iter::zip(std::move(angles), std::move(dists)))
// {
// //convert laser polar coordinates to cartesian
// float x = dist * sin(angle);
// float y = dist * cos(angle);
// Mat::Vector3d laserWorld = inner_eigen->transform(world_name,Mat::Vector3d(x, y, 0), laser_name).value();
// laser_poly << QPointF(x, y);
// laser_cart.emplace_back(QPointF(laserWorld.x(), laserWorld.y()));
// }
// out = std::make_tuple(angles, dists, laser_poly, laser_cart);
// });
// }
// }
// }
}
void SpecificWorker::del_node_slot(std::uint64_t from)
{
if( auto node = G->get_node(current_path_name); not node.has_value())
{
qInfo() << __FUNCTION__ << "Path node deleter. Aborting control";
send_command_to_robot(std::make_tuple(0.0,0.0,0.0));
}
}
///////////////////////////////////////////////////
/// GUI
//////////////////////////////////////////////////
int SpecificWorker::startup_check()
{
std::cout << "Startup check" << std::endl;
QTimer::singleShot(200, qApp, SLOT(quit()));
return 0;
}
/**************************************/
void SpecificWorker::draw_path(std::vector<Eigen::Vector2f> &path, QGraphicsScene* viewer_2d)
{
static std::vector<QGraphicsLineItem *> scene_road_points;
//clear previous points
for (QGraphicsLineItem* item : scene_road_points)
{
viewer_2d->removeItem(item);
delete item;
}
scene_road_points.clear();
/// Draw all points
QGraphicsLineItem *line1, *line2;
std::string color;
for(auto &&p_pair : iter::sliding_window(path, 2))
{
Mat::Vector2d a_point(p_pair[0].x(), p_pair[0].y());
Mat::Vector2d b_point(p_pair[1].x(), p_pair[1].y());
Mat::Vector2d dir = a_point - b_point;
Mat::Vector2d dir_perp = dir.unitOrthogonal();
Eigen::ParametrizedLine segment = Eigen::ParametrizedLine<double, 2>::Through(a_point, b_point);
Eigen::ParametrizedLine<double, 2> segment_perp((a_point+b_point)/2, dir_perp);
auto left = segment_perp.pointAt(50);
auto right = segment_perp.pointAt(-50);
QLineF qsegment(QPointF(a_point.x(), a_point.y()), QPointF(b_point.x(), b_point.y()));
QLineF qsegment_perp(QPointF(left.x(), left.y()), QPointF(right.x(), right.y()));
line1 = viewer_2d->addLine(qsegment, QPen(QBrush(QColor(QString::fromStdString(color))), 20));
line2 = viewer_2d->addLine(qsegment_perp, QPen(QBrush(QColor(QString::fromStdString("#F0FF00"))), 20));
scene_road_points.push_back(line1);
scene_road_points.push_back(line2);
}
}
/// Compute bumper-away speed
//QVector2D total{0, 0};
// const auto &[angles, dists] = laser_data;
// for (const auto &[angle, dist] : iter::zip(angles, dists))
// {
// float limit = (fabs(ROBOT_LENGTH / 2.f * sin(angle)) + fabs(ROBOT_LENGTH / 2.f * cos(angle))) + 200;
// float diff = limit - dist;
// if (diff >= 0)
// total = total + QVector2D(-diff * cos(angle), -diff * sin(angle));
// }
/// Compute bumper away speed for rectangular shape
// get extendedrobot polygon in worlds's coordinate frame
// std::vector<QPointF> rp = get_points_along_extended_robot_polygon(200, 40);
// for (const auto &p : rp)
// if(not laser_poly.containsPoint(p, Qt::OddEvenFill))
// total = total + QVector2D(p);
// qInfo() << __FUNCTION__ << total;
// sideVel = std::clamp(total.y(), -MAX_SIDE_SPEED, MAX_SIDE_SPEED);
|
5dceb71dd2cc942b30e3004d0543390bbc1e67ab
|
e48a848ccf26fa9131fa674af31d0bdbb1409cb6
|
/winner.h
|
4182153dac6af556243445206e499f75bbf4d5ab
|
[] |
no_license
|
ThomasWitte/policypf
|
3f0d9f7d0793a68f31264896c619b612f0539ddc
|
d29790956ad78962e0bbe86cd20c22a67a67ca81
|
refs/heads/master
| 2021-01-02T09:27:46.087090
| 2013-08-06T12:14:40
| 2013-08-06T12:14:40
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,178
|
h
|
winner.h
|
#ifndef _POLPF_WINNER_H_
#define _POLPF_WINNER_H_
#include <vector>
#include <deque>
#include <type_traits>
namespace policy_pf {
namespace winner_policies {
template<typename State, typename Weight, typename Enable = void>
class WeightedArithmeticMean_ {
protected:
State winner(const std::vector<State>& state_v, const std::vector<Weight>& weight_v) {
State win = {0};
for(size_t i = 0; i < state_v.size(); ++i)
win = win + (state_v[i]*weight_v[i]);
return win;
}
};
// Specialization for array type States. As c++ methods cannot return arrays
// winner returns a pointer to a State array.
template<typename State, typename Weight>
class WeightedArithmeticMean_<State, Weight, typename std::enable_if<std::is_array<State>::value >::type> {
protected:
State* winner(const std::vector<State>& state_v, const std::vector<Weight>& weight_v) {
State* win = (State*) new State;
for(size_t j = 0; j < std::extent<State>::value; ++j) {
(*win)[j] = 0;
for(size_t i = 0; i < state_v.size(); ++i)
(*win)[j] = (*win)[j] + (state_v[i][j] * weight_v[i]);
}
return win;
}
};
template <typename T> struct isContainer {static const bool value = false;};
template <typename T> struct isContainer<std::vector<T> > {static const bool value = true;};
template <typename T> struct isContainer<std::deque<T> > {static const bool value = true;};
template<typename State, typename Weight>
class WeightedArithmeticMean_<State, Weight, typename std::enable_if<isContainer<State>::value >::type> {
protected:
State winner(const std::vector<State>& state_v, const std::vector<Weight>& weight_v) {
size_t sz = (state_v.size() > 0 ? state_v[0].size() : 0);
State win(sz, 0);
for(size_t i = 0; i < sz; ++i)
for(size_t j = 0; j < state_v.size(); ++j)
win[i] = win[i] + (state_v[j][i]*weight_v[j]);
return win;
}
};
#if GCC_VERSION >= 40700
// Workaround for g++ 4.7
template<typename State, typename Weight>
using WeightedArithmeticMean = WeightedArithmeticMean_<State, Weight>;
#else
// Workaround for g++ 4.6
template<typename State, typename Weight>
class WeightedArithmeticMean : public WeightedArithmeticMean_<State, Weight> {};
#endif
}}
#endif
|
c7226f9d5598f29737f3ca2acd2573d3a3ffaabc
|
de44e9777ee18b920adbe7f4477ef9c7959f53f9
|
/src/nimcsgo/renderer/font.cpp
|
3028bad87aa26d356a4dec322b30a5a5a7e39a00
|
[] |
no_license
|
balenamiaa/nimcsgo
|
d981a7d2994a3b027206889fc2dda87352b681bd
|
ab1958190022341435ef2903127351bc009419ea
|
refs/heads/master
| 2023-02-21T02:54:26.685641
| 2021-01-25T05:42:57
| 2021-01-25T05:42:57
| 325,797,532
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 18,209
|
cpp
|
font.cpp
|
#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <d3dx9.h>
#include "font.h"
#define SAFE_RELEASE(p) \
{ \
if (p) \
{ \
(p)->Release(); \
(p) = NULL; \
} \
}
//-----------------------------------------------------------------------------
// Custom vertex types for rendering text
//-----------------------------------------------------------------------------
#define MAX_NUM_VERTICES 50 * 6
struct FONT2DVERTEX
{
D3DXVECTOR4 p;
DWORD color;
FLOAT tu, tv;
};
struct FONT3DVERTEX
{
D3DXVECTOR3 p;
D3DXVECTOR3 n;
FLOAT tu, tv;
};
#define D3DFVF_FONT2DVERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)
#define D3DFVF_FONT3DVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)
inline FONT2DVERTEX InitFont2DVertex(const D3DXVECTOR4 &p, D3DCOLOR color,
FLOAT tu, FLOAT tv)
{
FONT2DVERTEX v;
v.p = p;
v.color = color;
v.tu = tu;
v.tv = tv;
return v;
}
inline FONT3DVERTEX InitFont3DVertex(const D3DXVECTOR3 &p, const D3DXVECTOR3 &n,
FLOAT tu, FLOAT tv)
{
FONT3DVERTEX v;
v.p = p;
v.n = n;
v.tu = tu;
v.tv = tv;
return v;
}
//-----------------------------------------------------------------------------
// Name: CD3DFont()
// Desc: Font class constructor
//-----------------------------------------------------------------------------
CD3DFont::CD3DFont(const char *strFontName, DWORD dwHeight, DWORD dwFlags)
{
_tcsncpy(m_strFontName, strFontName, sizeof(m_strFontName) / sizeof(char));
m_strFontName[sizeof(m_strFontName) / sizeof(char) - 1] = '\0';
m_dwFontHeight = dwHeight;
m_dwFontFlags = dwFlags;
m_dwSpacing = 0;
m_pd3dDevice = NULL;
m_pTexture = NULL;
m_pVB = NULL;
m_pStateBlockSaved = NULL;
m_pStateBlockDrawText = NULL;
}
//-----------------------------------------------------------------------------
// Name: ~CD3DFont()
// Desc: Font class destructor
//-----------------------------------------------------------------------------
CD3DFont::~CD3DFont()
{
InvalidateDeviceObjects();
DeleteDeviceObjects();
}
//-----------------------------------------------------------------------------
// Name: CreateGDIFont
// Desc: Create a font based on the current state of related member variables
// and return the handle (or null on error)
//-----------------------------------------------------------------------------
HRESULT CD3DFont::CreateGDIFont(HDC hDC, HFONT *pFont)
{
// Create a font. By specifying ANTIALIASED_QUALITY, we might get an
// antialiased font, but this is not guaranteed.
INT nHeight = -MulDiv(m_dwFontHeight,
(INT)(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale),
72);
DWORD dwBold = (m_dwFontFlags & D3DFONT_BOLD) ? FW_BOLD : FW_NORMAL;
DWORD dwItalic = (m_dwFontFlags & D3DFONT_ITALIC) ? TRUE : FALSE;
*pFont = CreateFont(nHeight, 0, 0, 0, dwBold, dwItalic,
FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
VARIABLE_PITCH, m_strFontName);
if (*pFont == NULL)
return E_FAIL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: PaintAlphabet
// Desc: Paint the printable characters for the given GDI font onto the
// provided device context. If the bMeasureOnly flag is set, no drawing
// will occur.
//-----------------------------------------------------------------------------
HRESULT CD3DFont::PaintAlphabet(HDC hDC, BOOL bMeasureOnly)
{
SIZE size;
char str[2] = "x"; // One-character, null-terminated string
// Calculate the spacing between characters based on line height
if (0 == GetTextExtentPoint32(hDC, str, 1, &size))
return E_FAIL;
m_dwSpacing = (DWORD)ceil(size.cy * 0.3f);
// Set the starting point for the drawing
DWORD x = m_dwSpacing;
DWORD y = 0;
// For each character, draw text on the DC and advance the current position
for (char c = 32; c < 127; c++)
{
str[0] = c;
if (0 == GetTextExtentPoint32(hDC, str, 1, &size))
return E_FAIL;
if ((DWORD)(x + size.cx + m_dwSpacing) > m_dwTexWidth)
{
x = m_dwSpacing;
y += size.cy + 1;
}
// Check to see if there's room to write the character here
if (y + size.cy > m_dwTexHeight)
return D3DERR_MOREDATA;
if (!bMeasureOnly)
{
// Perform the actual drawing
if (0 == ExtTextOut(hDC, x + 0, y + 0, ETO_OPAQUE, NULL, str, 1, NULL))
return E_FAIL;
m_fTexCoords[c - 32][0] = ((FLOAT)(x + 0 - m_dwSpacing)) / m_dwTexWidth;
m_fTexCoords[c - 32][1] = ((FLOAT)(y + 0 + 0)) / m_dwTexHeight;
m_fTexCoords[c - 32][2] = ((FLOAT)(x + size.cx + m_dwSpacing)) / m_dwTexWidth;
m_fTexCoords[c - 32][3] = ((FLOAT)(y + size.cy + 0)) / m_dwTexHeight;
}
x += size.cx + (2 * m_dwSpacing);
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initializes device-dependent objects, including the vertex buffer used
// for rendering text and the texture map which stores the font image.
//-----------------------------------------------------------------------------
HRESULT CD3DFont::InitDeviceObjects(LPDIRECT3DDEVICE9 pd3dDevice)
{
HRESULT hr = S_OK;
HFONT hFont = NULL;
HFONT hFontOld = NULL;
HDC hDC = NULL;
HBITMAP hbmBitmap = NULL;
HGDIOBJ hbmOld = NULL;
// Keep a local copy of the device
m_pd3dDevice = pd3dDevice;
// Assume we will draw fonts into texture without scaling unless the
// required texture size is found to be larger than the device max
m_fTextScale = 1.0f;
hDC = CreateCompatibleDC(NULL);
SetMapMode(hDC, MM_TEXT);
hr = CreateGDIFont(hDC, &hFont);
if (FAILED(hr))
goto LCleanReturn;
hFontOld = (HFONT)SelectObject(hDC, hFont);
// Calculate the dimensions for the smallest power-of-two texture which
// can hold all the printable characters
m_dwTexWidth = m_dwTexHeight = 128;
while (D3DERR_MOREDATA == (hr = PaintAlphabet(hDC, true)))
{
m_dwTexWidth *= 2;
m_dwTexHeight *= 2;
}
if (FAILED(hr))
goto LCleanReturn;
// If requested texture is too big, use a smaller texture and smaller font,
// and scale up when rendering.
D3DCAPS9 d3dCaps;
m_pd3dDevice->GetDeviceCaps(&d3dCaps);
if (m_dwTexWidth > d3dCaps.MaxTextureWidth)
{
m_fTextScale = (FLOAT)d3dCaps.MaxTextureWidth / (FLOAT)m_dwTexWidth;
m_dwTexWidth = m_dwTexHeight = d3dCaps.MaxTextureWidth;
bool bFirstRun = true; // Flag clear after first run
do
{
// If we've already tried fitting the new text, the scale is still
// too large. Reduce and try again.
if (!bFirstRun)
m_fTextScale *= 0.9f;
// The font has to be scaled to fit on the maximum texture size; our
// current font is too big and needs to be recreated to scale.
DeleteObject(SelectObject(hDC, hFontOld));
hr = CreateGDIFont(hDC, &hFont);
if (FAILED(hr))
goto LCleanReturn;
hFontOld = (HFONT)SelectObject(hDC, hFont);
bFirstRun = false;
} while (D3DERR_MOREDATA == (hr = PaintAlphabet(hDC, true)));
}
// Create a new texture for the font
hr = m_pd3dDevice->CreateTexture(m_dwTexWidth, m_dwTexHeight, 1,
0, D3DFMT_A4R4G4B4,
D3DPOOL_MANAGED, &m_pTexture, NULL);
if (FAILED(hr))
goto LCleanReturn;
// Prepare to create a bitmap
DWORD *pBitmapBits;
BITMAPINFO bmi;
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = (int)m_dwTexWidth;
bmi.bmiHeader.biHeight = -(int)m_dwTexHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biBitCount = 32;
// Create a bitmap for the font
hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS,
(void **)&pBitmapBits, NULL, 0);
hbmOld = SelectObject(hDC, hbmBitmap);
// Set text properties
SetTextColor(hDC, RGB(255, 255, 255));
SetBkColor(hDC, 0x00000000);
SetTextAlign(hDC, TA_TOP);
// Paint the alphabet onto the selected bitmap
hr = PaintAlphabet(hDC, false);
if (FAILED(hr))
goto LCleanReturn;
// Lock the surface and write the alpha values for the set pixels
D3DLOCKED_RECT d3dlr;
m_pTexture->LockRect(0, &d3dlr, 0, 0);
BYTE *pDstRow;
pDstRow = (BYTE *)d3dlr.pBits;
WORD *pDst16;
BYTE bAlpha; // 4-bit measure of pixel intensity
DWORD x, y;
for (y = 0; y < m_dwTexHeight; y++)
{
pDst16 = (WORD *)pDstRow;
for (x = 0; x < m_dwTexWidth; x++)
{
bAlpha = (BYTE)((pBitmapBits[m_dwTexWidth * y + x] & 0xff) >> 4);
if (bAlpha > 0)
{
*pDst16++ = (WORD)((bAlpha << 12) | 0x0fff);
}
else
{
*pDst16++ = 0x0000;
}
}
pDstRow += d3dlr.Pitch;
}
hr = S_OK;
// Done updating texture, so clean up used objects
LCleanReturn:
if (m_pTexture)
m_pTexture->UnlockRect(0);
SelectObject(hDC, hbmOld);
SelectObject(hDC, hFontOld);
DeleteObject(hbmBitmap);
DeleteObject(hFont);
DeleteDC(hDC);
return hr;
}
//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CD3DFont::RestoreDeviceObjects()
{
HRESULT hr;
// Create vertex buffer for the letters
int vertexSize = std::max(sizeof(FONT2DVERTEX), sizeof(FONT3DVERTEX));
if (FAILED(hr = m_pd3dDevice->CreateVertexBuffer(MAX_NUM_VERTICES * vertexSize,
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
D3DPOOL_DEFAULT, &m_pVB, NULL)))
{
return hr;
}
bool bSupportsAlphaBlend = true;
LPDIRECT3D9 pd3d9 = NULL;
if (SUCCEEDED(m_pd3dDevice->GetDirect3D(&pd3d9)))
{
D3DCAPS9 Caps;
D3DDISPLAYMODE Mode;
LPDIRECT3DSURFACE9 pSurf = NULL;
D3DSURFACE_DESC Desc;
m_pd3dDevice->GetDeviceCaps(&Caps);
m_pd3dDevice->GetDisplayMode(0, &Mode);
if (SUCCEEDED(m_pd3dDevice->GetRenderTarget(0, &pSurf)))
{
pSurf->GetDesc(&Desc);
if (FAILED(pd3d9->CheckDeviceFormat(Caps.AdapterOrdinal, Caps.DeviceType, Mode.Format,
D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3DRTYPE_SURFACE,
Desc.Format)))
{
bSupportsAlphaBlend = false;
}
SAFE_RELEASE(pSurf);
}
SAFE_RELEASE(pd3d9);
}
// Create the state blocks for rendering text
for (UINT which = 0; which < 2; which++)
{
m_pd3dDevice->BeginStateBlock();
m_pd3dDevice->SetTexture(0, m_pTexture);
if (D3DFONT_ZENABLE & m_dwFontFlags)
m_pd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
else
m_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
if (bSupportsAlphaBlend)
{
m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
}
else
{
m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
m_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, 0x08);
m_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
m_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
m_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
m_pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
m_pd3dDevice->SetRenderState(D3DRS_CLIPPING, TRUE);
m_pd3dDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, FALSE);
m_pd3dDevice->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE);
m_pd3dDevice->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
m_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
m_pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE,
D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN |
D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
m_pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
m_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
m_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
m_pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
if (which == 0)
m_pd3dDevice->EndStateBlock(&m_pStateBlockSaved);
else
m_pd3dDevice->EndStateBlock(&m_pStateBlockDrawText);
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InvalidateDeviceObjects()
// Desc: Destroys all device-dependent objects
//-----------------------------------------------------------------------------
HRESULT CD3DFont::InvalidateDeviceObjects()
{
SAFE_RELEASE(m_pVB);
SAFE_RELEASE(m_pStateBlockSaved);
SAFE_RELEASE(m_pStateBlockDrawText);
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DeleteDeviceObjects()
// Desc: Destroys all device-dependent objects
//-----------------------------------------------------------------------------
HRESULT CD3DFont::DeleteDeviceObjects()
{
SAFE_RELEASE(m_pTexture);
m_pd3dDevice = NULL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: GetTextExtent()
// Desc: Get the dimensions of a text string
//-----------------------------------------------------------------------------
HRESULT CD3DFont::GetTextExtent(const char *strText, SIZE *pSize)
{
if (NULL == strText || NULL == pSize)
return E_FAIL;
FLOAT fRowWidth = 0.0f;
FLOAT fRowHeight = (m_fTexCoords[0][3] - m_fTexCoords[0][1]) * m_dwTexHeight;
FLOAT fWidth = 0.0f;
FLOAT fHeight = fRowHeight;
while (*strText)
{
char c = *strText++;
if (c == '\n')
{
fRowWidth = 0.0f;
fHeight += fRowHeight;
}
if ((c - 32) < 0 || (c - 32) >= 128 - 32)
continue;
FLOAT tx1 = m_fTexCoords[c - 32][0];
FLOAT tx2 = m_fTexCoords[c - 32][2];
fRowWidth += (tx2 - tx1) * m_dwTexWidth - 2 * m_dwSpacing;
if (fRowWidth > fWidth)
fWidth = fRowWidth;
}
pSize->cx = (int)fWidth;
pSize->cy = (int)fHeight;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DrawText()
// Desc: Draws 2D text. Note that sx and sy are in pixels
//-----------------------------------------------------------------------------
HRESULT CD3DFont::DrawText(FLOAT sx, FLOAT sy, DWORD dwColor,
const char *strText, DWORD dwFlags)
{
if (m_pd3dDevice == NULL)
return E_FAIL;
m_pStateBlockSaved->Capture();
m_pStateBlockDrawText->Apply();
m_pd3dDevice->SetFVF(D3DFVF_FONT2DVERTEX);
m_pd3dDevice->SetPixelShader(NULL);
m_pd3dDevice->SetStreamSource(0, m_pVB, 0, sizeof(FONT2DVERTEX));
if (dwFlags & D3DFONT_FILTERED)
{
m_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
m_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}
sx -= m_dwSpacing;
FLOAT fStartX = sx;
FONT2DVERTEX *pVertices = NULL;
DWORD dwNumTriangles = 0;
m_pVB->Lock(0, 0, (void **)&pVertices, D3DLOCK_DISCARD);
while (*strText)
{
char c = *strText++;
if (c == '\n')
{
sx = fStartX;
sy += (m_fTexCoords[0][3] - m_fTexCoords[0][1]) * m_dwTexHeight;
}
if ((c - 32) < 0 || (c - 32) >= 128 - 32)
continue;
FLOAT tx1 = m_fTexCoords[c - 32][0];
FLOAT ty1 = m_fTexCoords[c - 32][1];
FLOAT tx2 = m_fTexCoords[c - 32][2];
FLOAT ty2 = m_fTexCoords[c - 32][3];
FLOAT w = (tx2 - tx1) * m_dwTexWidth / m_fTextScale;
FLOAT h = (ty2 - ty1) * m_dwTexHeight / m_fTextScale;
if (c != ' ')
{
*pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), dwColor, tx1, ty2);
*pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), dwColor, tx1, ty1);
*pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), dwColor, tx2, ty2);
*pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), dwColor, tx2, ty1);
*pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + w - 0.5f, sy + h - 0.5f, 0.9f, 1.0f), dwColor, tx2, ty2);
*pVertices++ = InitFont2DVertex(D3DXVECTOR4(sx + 0 - 0.5f, sy + 0 - 0.5f, 0.9f, 1.0f), dwColor, tx1, ty1);
dwNumTriangles += 2;
if (dwNumTriangles * 3 > (MAX_NUM_VERTICES - 6))
{
// Unlock, render, and relock the vertex buffer
m_pVB->Unlock();
m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
pVertices = NULL;
m_pVB->Lock(0, 0, (void **)&pVertices, D3DLOCK_DISCARD);
dwNumTriangles = 0L;
}
}
sx += w - (2 * m_dwSpacing);
}
// Unlock and render the vertex buffer
m_pVB->Unlock();
if (dwNumTriangles > 0)
m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
// Restore the modified renderstates
m_pStateBlockSaved->Apply();
return S_OK;
}
|
85bd9aa64a75c16b4b94f8c8cda1d89b5bf66353
|
e81a82daa6542cd7c9e339f5bed5a3b17533d2ca
|
/StateObject/BodyState/bodystate.cc
|
97dab30495803a9ff32df3828327e74c1df18c7b
|
[
"Apache-2.0"
] |
permissive
|
drewnoakes/bold-humanoid
|
56ea9c06d673eff73bd07865bb0bea8d91371a04
|
6025fcc92cdf3ce9486d4fe5af4f30ee7a7a3335
|
refs/heads/master
| 2023-07-16T13:30:17.976858
| 2021-08-24T12:05:48
| 2021-08-24T12:05:48
| 398,125,395
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,753
|
cc
|
bodystate.cc
|
#include "bodystate.hh"
#include "../HardwareState/hardwarestate.hh"
#include "../../BodyControl/bodycontrol.hh"
#include "../../BodyModel/bodymodel.hh"
#include "../../Config/config.hh"
#include "../../MX28/mx28.hh"
using namespace bold;
using namespace std;
using namespace Eigen;
LimbPosition::LimbPosition(shared_ptr<Limb const> limb, Affine3d const& transform)
: BodyPartPosition(transform),
d_limb(limb)
{
ASSERT(limb);
}
Vector3d LimbPosition::getCentreOfMassPosition() const
{
return getTransform() * getLimb()->com;
}
////////////////////////////////////////////////////////////////////////////////
JointPosition::JointPosition(shared_ptr<Joint const> joint, Affine3d const& transform, double angleRads)
: BodyPartPosition(transform),
d_joint(joint),
d_angleRads(angleRads)
{
ASSERT(joint);
}
////////////////////////////////////////////////////////////////////////////////
BodyState::BodyState(shared_ptr<BodyModel const> const& bodyModel, array<double,23> const& angles, array<short,21> const& positionValueDiffs, ulong cycleNumber)
: d_positionValueDiffById(positionValueDiffs),
d_torso(),
d_jointById(),
d_limbByName(),
d_isCentreOfMassComputed(false),
d_motionCycleNumber(cycleNumber)
{
initialise(bodyModel, angles);
}
BodyState::BodyState(shared_ptr<BodyModel const> const& bodyModel, shared_ptr<HardwareState const> const& hardwareState, shared_ptr<BodyControl> const& bodyControl, ulong cycleNumber)
: d_torso(),
d_jointById(),
d_limbByName(),
d_isCentreOfMassComputed(false),
d_motionCycleNumber(cycleNumber)
{
// Add three extra as:
// - we don't use index 0
// - we add two extra joints for the camera's calibration pan & tilt within the head
array<double,23> angles;
angles[0] = 0;
for (uchar jointId = (uchar)JointId::MIN; jointId <= (uchar)JointId::MAX; jointId++)
{
auto const& joint = hardwareState->getMX28State(jointId);
JointControl* jointControl = bodyControl->getJoint((JointId)jointId);
angles[jointId] = joint.presentPosition;
d_positionValueDiffById[jointId] = (short)jointControl->getValue() + jointControl->getModulationOffset() - joint.presentPositionValue;
}
static auto tiltSetting = Config::getSetting<double>("camera.calibration.tilt-angle-degrees");
static auto panSetting = Config::getSetting<double>("camera.calibration.pan-angle-degrees");
// Set the camera head tilt according to the configured angle
angles[(uchar)JointId::CAMERA_CALIB_TILT] = Math::degToRad(tiltSetting->getValue());
angles[(uchar)JointId::CAMERA_CALIB_PAN ] = Math::degToRad(panSetting->getValue());
initialise(bodyModel, angles);
}
Vector3d const& BodyState::getCentreOfMass() const
{
if (!d_isCentreOfMassComputed)
{
double totalMass = 0.0;
Vector3d weightedSum(0,0,0);
visitLimbs([&](shared_ptr<LimbPosition const> limbPosition)
{
double mass = limbPosition->getLimb()->mass;
totalMass += mass;
weightedSum += mass * limbPosition->getCentreOfMassPosition();
});
d_centreOfMass = weightedSum / totalMass;
d_isCentreOfMassComputed = true;
}
return d_centreOfMass;
}
shared_ptr<LimbPosition const> BodyState::getLimb(string const& name) const
{
// NOTE cannot use '[]' on a const map
auto const& i = d_limbByName.find(name);
if (i == d_limbByName.end())
{
log::error("BodyState::getJoint") << "Invalid limb name: " << name;
throw runtime_error("Invalid limb name: " + name);
}
return i->second;
}
shared_ptr<JointPosition const> BodyState::getJoint(JointId jointId) const
{
ASSERT(jointId >= JointId::MIN && jointId <= JointId::MAX);
return d_jointById[(uchar)jointId];
}
void BodyState::visitJoints(function<void(shared_ptr<JointPosition const> const&)> visitor) const
{
for (uchar jointId = (uchar)JointId::MIN; jointId <= (uchar)JointId::MAX; jointId++)
visitor(d_jointById[(uchar)jointId]);
}
void BodyState::visitLimbs(function<void(shared_ptr<LimbPosition const> const&)> visitor) const
{
for (auto const& pair : d_limbByName)
visitor(pair.second);
}
Affine3d BodyState::determineFootAgentTr(bool leftFoot) const
{
auto footTorsoTr = getLimb(leftFoot ? "left-foot" : "right-foot")->getTransform().inverse();
return Math::alignUp(footTorsoTr);
}
shared_ptr<BodyState const> BodyState::zero(shared_ptr<BodyModel const> const& bodyModel, ulong thinkCycleNumber)
{
array<double,23> angles;
angles.fill(0);
// Tilt the head up slightly, so that we can see the horizon in the image (better for testing)
angles[(int)JointId::HEAD_TILT] = MX28::degs2Value(20.0);
array<short,21> positionValueDiffs;
positionValueDiffs.fill(0);
return make_shared<BodyState>(bodyModel, angles, positionValueDiffs, thinkCycleNumber);
}
|
b07788f39476a6fff8a45da8d4bde25373e3697b
|
f0144e164f25fd6b78f31ad654ec9788680ea91e
|
/libdev/devices/CameraViewer/src/gui/widgetserialport.cpp
|
86ff7d78625b29e977b12460376c51caa6bd0f86
|
[] |
no_license
|
pospiech/code
|
6378c089b46b05891cb4dd4696a322178db65d3b
|
676ff299d4c7b8d7205393190e275ca310b39945
|
refs/heads/master
| 2021-01-10T04:40:03.434313
| 2019-01-16T07:42:43
| 2019-01-16T07:42:43
| 43,712,092
| 1
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 705
|
cpp
|
widgetserialport.cpp
|
#include "widgetserialport.h"
#include <QSerialPort>
WidgetSerialPort::WidgetSerialPort(QWidget *parent)
: QWidget(parent)
, m_serial(new QSerialPort(this))
{
}
void WidgetSerialPort::writeData(const QByteArray &data)
{
m_serial->write(data);
}
void WidgetSerialPort::closeSerialPort()
{
if (m_serial->isOpen())
m_serial->close();
// m_console->setEnabled(false);
// m_ui->actionConnect->setEnabled(true);
// m_ui->actionDisconnect->setEnabled(false);
// m_ui->actionConfigure->setEnabled(true);
// showStatusMessage(tr("Disconnected"));
}
void WidgetSerialPort::readData()
{
const QByteArray data = m_serial->readAll();
// m_console->putData(data);
}
|
97f18564e64efd18250b1919708ac92abc74796e
|
663e6946a2091178cd5ffd6a9f92e748dcabb1b0
|
/mini/constexpr.cpp
|
5115bc3e068a06ff9970f8953b6964cfedae093f
|
[] |
no_license
|
wssbygone/mydepot
|
b9425b4df259457d82ce54e5227771e0daa2406d
|
e4106958a80ae16d2410bb29c6131a243b4221ca
|
refs/heads/master
| 2023-08-24T18:12:18.286550
| 2023-08-09T02:42:13
| 2023-08-09T02:42:13
| 132,110,129
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 108
|
cpp
|
constexpr.cpp
|
#include<iostream>
static constexpr int N = 3;
int main()
{
constexpr const int * NP = &N;
return 0;
}
|
68084d762e0e64fe6bcc11deab9870c811a7298e
|
e2cc6f14535540a556cfa4327212d0082bb62521
|
/SortCharactersByFrequency.cpp
|
ac29051acb5073794c78a432c9ad363a7c321797
|
[] |
no_license
|
web3Payne/LeetCode
|
267105b51329e3d500136e6879fee31e3943c648
|
8609bc4e3ecf0c75e997a810183589dd869a20d7
|
refs/heads/master
| 2021-09-29T04:41:30.650155
| 2017-02-09T09:39:13
| 2017-02-09T09:39:13
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 674
|
cpp
|
SortCharactersByFrequency.cpp
|
class Solution {
public:
string frequencySort(string s) {
unordered_map<char, int> mymap;
for (char c : s) ++mymap[c];
auto cmp = [](pair<char, int>& a, pair<char, int>& b) -> bool {return a.second < b.second;};
priority_queue<pair<char, int>, vector<pair<char, int>>, decltype(cmp)> maxHeap(cmp);
for (auto it = mymap.begin(); it != mymap.end(); ++it) {
maxHeap.emplace(it->first, it->second);
}
string res;
while (!maxHeap.empty()) {
auto p = maxHeap.top();
res += string(p.second, p.first);
maxHeap.pop();
}
return res;
}
};
bucket sort is better
|
5433e1d9ed5f401996004d61fd0422334e982180
|
d3746bedda6f72e8107ca823057c21047b13854f
|
/kinematics.cpp
|
8419f9f4a62e5dd6ddc720a51c114f71fec545bd
|
[
"LicenseRef-scancode-public-domain",
"MIT"
] |
permissive
|
bburrough/Descartes
|
88dbc62ba2cb1d9c94b2487c683a1c0e545ca4d3
|
3341d6907b5b99b604debe065bb1972b352e5200
|
refs/heads/master
| 2021-12-07T19:54:19.350453
| 2021-10-14T21:52:34
| 2021-10-14T21:52:34
| 212,020,171
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 9,582
|
cpp
|
kinematics.cpp
|
#include "kinematics.h"
/*
Kinematic Equations
distance = initial_velocity * time + 1/2 * acceleration * time^2
time = sqrt(2 * distance / acceleration)
final_velocity^2 = initial_velocity^2 + 2 * acceleration * distance
final_velocity = initial_velocity + acceleration * time
distance = (initial_velocity + final_velocity) / 2 * time
*/
// time to max velocity from a dead stop
seconds TimeToVelocity(const mmM& final_velocity, const mmS2& acceleration_arg)
{
return mmS(final_velocity) / acceleration_arg;
}
// time to max velocity starting from a pre-existing velocity
seconds TimeToVelocity(const mmM& initial_velocity, const mmM& final_velocity, const mmS2& acceleration_arg)
{
return mmS((final_velocity - initial_velocity)) / acceleration_arg;
}
mm DistanceToVelocity(const mmM& final_velocity, const mmS2& acceleration_arg)
{
//x = 1 / 2 * acceleration * tmax ^ 2
seconds tmax = TimeToVelocity(final_velocity, acceleration_arg);
return 0.5f * acceleration_arg * (tmax * tmax);
}
// 1 / 2 * a * b^2
//
// 1 / 2 * 6 * 2 * 2 = 12
// 6 / 2 * 2 * 2 = 12
// acceleration_arg / 2 * (tmax * tmax)
// .5 * mm/S2 * S2
mm DistanceToVelocity(const mmM& initial_velocity, const mmM& final_velocity, const mmS2& acceleration_arg)
{
if (initial_velocity == final_velocity) return mm(0.0f);
if (acceleration_arg == 0.0f) throw(exception("impossible to decelerate from initial_velocity to final velocity because acceleration is zero"));
if (acceleration_arg <= 0.0f && final_velocity >= initial_velocity) throw(exception("impossible to decelerate from initial_velocity to final velocity because final_velocity >= initial_velocity"));
if (initial_velocity < 0.0f || final_velocity < 0.0f) throw(exception("velocity can't be negative"));
//x = 1 / 2 * acceleration * tmax ^ 2
seconds tmax = TimeToVelocity(initial_velocity, final_velocity, acceleration_arg);
//return initial_velocity * tmax + 0.5f * acceleration_arg * (tmax * tmax);
return mmS(initial_velocity) * tmax + 0.5f * acceleration_arg * (tmax * tmax);
}
seconds TimeToAccelerateOverDistance(const mm& distance, const mmS2& acceleration_arg)
{
return sqrt(2.0f * distance / acceleration_arg);
}
/*
seconds TimeToAccelerateOverDistance2(const mmM& initial_velocity, const mm& distance, const mmS2& acceleration_arg)
{
return mmS(initial_velocity) / distance + sqrt(2.0f * distance / acceleration_arg);
}
*/
// mm/S / mm
// mm/S * 1/mm
// 1/S
// time to max velocity starting from a pre-existing velocity
seconds TimeToAccelerateOverDistance(const mmM& initial_velocity, const mm& distance, const mmS2& acceleration_arg)
{
if (distance == 0.0f)
return seconds(0.0f);
if (acceleration_arg <= 0.0f && initial_velocity <= 0.0f)
return seconds(NAN); // you can't decelerate from zero
mmS velocity_S(initial_velocity);
/*
bool test = false;
float up = (-velocity_S + sqrt(velocity_S*velocity_S + 2.0f * acceleration_arg * distance)) / acceleration_arg;
float down = (-velocity_S - sqrt(velocity_S*velocity_S + 2.0f * acceleration_arg * distance)) / acceleration_arg;
if (isnan(up))
test = true;
*/
// standard quadratic solver
return (sqrt(velocity_S*velocity_S + 2.0f * acceleration_arg * distance) - velocity_S) / acceleration_arg;
// Citardauq quadratic solver
//return (2.0f * -distance) / (-velocity_S - sqrt(velocity_S*velocity_S + 2.0f * acceleration_arg * distance));
}
// from dead stop
mm DistanceGivenAccelerationOverTime(const seconds& time, const mmS2& acceleration_arg)
{
if (time == 0.0f) return mm(0.0f);
if (acceleration_arg <= 0.0f) return mm(0.0f);
if (time < 0.0f) throw(exception("can't decelerate over negative time"));
return 0.5f * acceleration_arg * (time * time);
}
// from initial_velocity
mm DistanceGivenAccelerationOverTime(const mmM& initial_velocity, const seconds& time, const mmS2& acceleration_arg)
{
if (time == 0.0f) return mm(0.0f);
if (acceleration_arg < 0.0f && initial_velocity == 0.0f) return mm(0.0f);
if (initial_velocity < 0.0f) throw(exception("velocity can't be negative"));
if (time < 0.0f) throw(exception("can't decelerate over negative time"));
return mmS(initial_velocity) * time + 0.5f * acceleration_arg * (time * time);
}
// Vf^2 = Vi^2 + 2a * (Xf - Xi)
// Xf - Xi = Vi^2 / Vf^2 + 2a / Vf^2
mm DistanceGivenVelocitiesOverTime(const mmM& initial_velocity, const mmM& final_velocity, const seconds& time)
{
return 0.5f * mmS(initial_velocity + final_velocity) * time;
}
/*
seconds TimeToAccelerateOverDistance(mm distance)
{
return TimeToAccelerateOverDistance(distance, acceleration);
}
*/
// from a dead stop
/*
mmM VelocityGivenAccelerationOverDistance(const mm& distance, const mmS2& acceleration_arg)
{
return 0.5f * acceleration_arg * (distance * distance);
// mm/S^2 * mm^2 = mm^3/S^2
}
*/
mmM VelocityGivenAccelerationOverDistance(const mmM& initial_velocity, const mm& distance, const mmS2& acceleration_arg)
{
mmS initial_velocity_S(initial_velocity);
return mmM(sqrt(initial_velocity_S*initial_velocity_S + 2 * acceleration_arg * distance));
}
seconds AxisMoveDuration(const mm& distance_arg, const mmM& max_feed_rate, const mmS2& acceleration_arg)
{
/*
we know that we have to both accelerate and decelerate. So the motion
is basically the same as two acceleration events (at least WRT duration anyway).
So just divide the distance by two, calculate the duration given the acceleration
factor, then multiply that by two.
*/
if (distance_arg == 0.0f)
return seconds(0.0f);
mm distance = distance_arg / 2.0f;
// calculate the distance achieved at max_velocity
// if the distance at max velocity is greater than the distance argument
// then we can use the dumb accel calculation.
// However, if the distance at max velocity is less than the distance argument
// then we need to use the dum accel up to the distance at max velocity,
// then add in the simple velocity * distance for the remaining distance
mm max_velocity_achieved_at_distance = DistanceToVelocity(max_feed_rate, acceleration_arg);
seconds max_velocity_component(0.0f);
if (max_velocity_achieved_at_distance < distance)
{
// mm / mm / S = mm * S / mm
max_velocity_component = (distance - max_velocity_achieved_at_distance) / mmS(max_feed_rate);
distance = max_velocity_achieved_at_distance;
}
return (TimeToAccelerateOverDistance(distance, acceleration_arg) + max_velocity_component) * 2.0f;
}
/*
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2003-2019 Bobby G. Burrough
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/
|
2c24808abcf4b5e65749a5d8326abb9dbc67dd0f
|
d352cb980107b8665e63c8b8b21e2921af53b8d3
|
/Codeforces/4C.cpp
|
ef38410aaf5f6ba66c6ba1d48b5acc9236777c54
|
[] |
no_license
|
sir-rasel/Online_Judge_Problem_Solve
|
490949f0fc639956b20f6dec32676c7d8dc66a81
|
9fb93ff4d143d56228443e55e8d8dac530ce728b
|
refs/heads/master
| 2021-06-03T19:48:04.700992
| 2021-03-30T16:41:03
| 2021-03-30T16:41:03
| 133,169,776
| 3
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 373
|
cpp
|
4C.cpp
|
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int main(){
map<string,int>m;
int test;
scanf("%d",&test);
string a;
while(test--){
cin>>a;
if(m[a]==0){
printf("OK\n");
m[a]++;
}
else{
cout<<a<<m[a]<<endl;
m[a]++;
}
}
return 0;
}
|
5e237481643c789c550282f8926ca9e5dffe470a
|
dc135861f62e1b835b27206ad9c3af69742b04de
|
/PAT-A/PAT_A1010.cpp
|
12114b5ae71962c76d1e068e8aac87af85e3a840
|
[] |
no_license
|
Philo-Li/PAT-Solutions
|
b025cc7671c71f4a1107140748d47b73b1d0ccc9
|
a7d00677a969c57e8fe77fd9e1193e9cf3f25ba3
|
refs/heads/master
| 2023-04-11T12:18:25.991971
| 2021-04-26T05:53:59
| 2021-04-26T05:53:59
| 93,131,936
| 4
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,683
|
cpp
|
PAT_A1010.cpp
|
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
#include <iostream>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;
//A1010 Radix
long long n1, n2, tag, d, low, high, mid, ans = -1;
int maxe = 2;
string str1, str2;
int getnum(char a){ return isdigit(a) ? a - '0' : a - 'a' + 10; }
long long change(string a, int d){
long long temp = 0;
for(int i = 0; i < a.length(); i++){
temp = temp * d + getnum(a[i]);
}
return temp;
}
int main() {
cin >> str1 >> str2 >> tag >> d;
if(tag == 2) swap(str1, str2);
n1 = change(str1, d);
low = getnum(*max_element(str2.begin(), str2.end())) + 1;//下界是最小数字+1
high = max(low, n1);
while(low <= high){
mid = (low + high) / 2;
n2 = change(str2, mid);
// printf("n1:%lld n2:%lld left:%lld mid:%lld right:%lld\n", n1, n2, low, mid, high);
if(n1 < n2 || n2 < 0) high = mid - 1;
else if(n1 == n2){
ans = mid; break;
}
else low = mid + 1;
}
if(ans != -1) printf("%lld\n", ans);
else printf("Impossible\n");
return 0;
}
// #define _CRT_SECURE_NO_WARNINGS
// #include <cstring>
// #include <cstdio>
// #include <iostream>
// #include <string>
// #include <cctype>
// #include <cmath>
// #include <algorithm>
// using namespace std;
// //A1010 Radix
// long long convert(string n, long long radix) {
// long long sum = 0;
// int index = 0, temp = 0;
// for (auto it = n.rbegin(); it != n.rend(); it++) {
// temp = isdigit(*it) ? *it - '0' : *it - 'a' + 10;
// sum += temp * pow(radix, index++);
// }
// return sum;
// }
// long long find_radix(string n, long long num) {
// char it = *max_element(n.begin(), n.end());
// long long low = (isdigit(it) ? it - '0': it - 'a' + 10) + 1;//+1
// long long high = max(num, low);
// while (low <= high) {//等号
// long long mid = (low + high) / 2;
// long long t = convert(n, mid);//如果n是mid进制,转为十进制
// if (t < 0 || t > num) high = mid - 1;//十进制的n比num大
// //说明进制太大,上界变小
// else if (t == num) return mid;
// //如果十进制的n比num小,则说明进制太小,下界变大
// else low = mid + 1;
// }
// return -1;
// }
// int main() {
// string n1, n2;
// long long tag = 0, radix = 0, result_radix;
// cin >> n1 >> n2 >> tag >> radix;
// result_radix = tag == 1 ? find_radix(n2, convert(n1, radix)) : find_radix(n1, convert(n2, radix));
// if (result_radix != -1) {
// printf("%lld", result_radix);
// } else {
// printf("Impossible");
// }
// return 0;
// }
//
//
|
1d7e2228de2e0dfb94a5a0cb588bfaccd68c5a3b
|
cdf7718cb0f3730682b42cedba79b96d690284b2
|
/1136 - Division by 3.cpp
|
cd884dd4ce9247055d41358e79101ba6ea027fac
|
[] |
no_license
|
raihan02/Light-OJ-
|
327fb270557ecfff375af483a588ee12061188e5
|
5bf501e00ecf7de5f1f8114a6585b7e6880da0c0
|
refs/heads/master
| 2022-11-24T05:44:12.966009
| 2022-11-08T16:30:39
| 2022-11-08T16:30:39
| 53,657,945
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 368
|
cpp
|
1136 - Division by 3.cpp
|
#include <bits/stdc++.h>
using namespace std;
typedef long l;
bool ck (l n)
{
if(n % 3 == 2)
return 1;
else
return 0;
}
long fun (l n)
{
return (n / 3) * 2 + ck(n);
}
int main()
{
l a, b, tes,o=0;
cin >> tes;
while(tes--)
{
o++;
cin >>a >> b;
printf("Case %d: %ld\n",o, fun(b) - fun(a -1));
}
}
|
62dfdf4fbcb2d7b14a0c262c09c3b356cc260adb
|
31f5cddb9885fc03b5c05fba5f9727b2f775cf47
|
/engine/modules/pcg/data/pcg_data.cpp
|
ec0dec76241b3a638a9d850d445e543c7aedf240
|
[
"MIT"
] |
permissive
|
timi-liuliang/echo
|
2935a34b80b598eeb2c2039d686a15d42907d6f7
|
d6e40d83c86431a819c6ef4ebb0f930c1b4d0f24
|
refs/heads/master
| 2023-08-17T05:35:08.104918
| 2023-08-11T18:10:35
| 2023-08-11T18:10:35
| 124,620,874
| 822
| 102
|
MIT
| 2021-06-11T14:29:03
| 2018-03-10T04:07:35
|
C++
|
UTF-8
|
C++
| false
| false
| 112
|
cpp
|
pcg_data.cpp
|
#include "pcg_data.h"
namespace Echo
{
PCGData::PCGData()
{
}
PCGData::~PCGData()
{
}
}
|
128f52135605b4be814bb7a0c6944cb0a29f7938
|
3d0423b17b6fb3f146293514dc7e147333260c5a
|
/Server-Client/MyPacket.h
|
31ab4ddb780ae9cd0cf560f455b762b3f6b46b01
|
[
"MIT"
] |
permissive
|
matzar/SFML-Networking
|
02941c2420152da7601340e4e066e3d60afaeb0d
|
2623ae7c38ada2dfcbbdf725345222e58a86336b
|
refs/heads/master
| 2021-09-08T08:34:14.125242
| 2018-03-08T18:46:49
| 2018-03-08T18:46:49
| 110,551,568
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 570
|
h
|
MyPacket.h
|
#pragma once
#include <SFML/Network.hpp>
//#include "Messages.h"
/** A position update message. */
struct PlayerMessage {
/** The object number of this Player within the game world. */
int id;
/** The coordinates of this Player within the game world. */
float x, y;
/** The time at which this message was sent.
(Not the time at which it was received!) */
float time;
};
class MyPacket : public sf::Packet
{
public:
MyPacket();
~MyPacket();
void addMessage(const PlayerMessage& player_message);
//sf::Packet& operator>>(PlayerMessage& player_message);
};
|
474298b856413532c260e5ee4c126fd1a97a0385
|
68393cc174986df5ce765f971bb46a764184990f
|
/codeforces/contest_1027/B.cpp
|
9d1cbc4a0f435d7774eff409d0981f72f314f43a
|
[] |
no_license
|
zhangji0629/algorithm
|
151e9a0bc8978863da4d6de5aa282c3593c02386
|
530026b4329adbab8eb2002ee547951f5d6b8418
|
refs/heads/master
| 2021-05-10T16:38:30.036308
| 2020-05-24T11:41:50
| 2020-05-24T11:41:50
| 118,584,175
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 578
|
cpp
|
B.cpp
|
#include<bits/stdc++.h>
using LL = long long;
int main()
{
LL n, q;
while(std::cin >> n >> q) {
while(q--) {
int x, y;
std::cin >> x >> y;
LL ans = 0;
if((x+y)%2 == 0) {
ans = (x-1)/2 * n/2 + (x-1 - (x-1)/2) * (n-n/2);
if(x%2) {
ans += y-y/2;
} else {
ans += y/2;
}
} else {
if(n%2) {
ans += n*n/2+1;
} else {
ans += n*n/2;
}
ans += (x-1)/2 * (n-n/2) + (x-1 - (x-1)/2) * n/2;
if(x%2) {
ans += y/2;
} else {
ans += y-y/2;
}
}
std::cout << ans << std::endl;
}
}
return 0;
}
|
efc1da2cce0eea7dc12043aae55601564b12dc85
|
c1466e0815558818829d51326d445df6ffad9c17
|
/cpp_xcode/FIrst_Project/FIrst_Project/Game21/House.hpp
|
c46955de8c56ea229917454f0f5ac6d992be8469
|
[] |
no_license
|
ojaster/first_project
|
2177bc78d6a6000862a306ebce71d2cdeee8d475
|
0a09308acd6270085959251ca8892dc22d272cfb
|
refs/heads/master
| 2021-07-07T13:04:51.200496
| 2020-06-25T10:52:08
| 2020-06-25T10:52:08
| 129,524,939
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 497
|
hpp
|
House.hpp
|
//
// House.hpp
// FIrst_Project
//
// Created by Данил on 19/04/2019.
// Copyright © 2019 Daniil. All rights reserved.
//
#ifndef House_hpp
#define House_hpp
#include <stdio.h>
#include "House.hpp"
#include <iostream>
#include "GenericPLayer.h"
#include "Card.h"
using namespace std;
class House:public GenericPlayer{
public:
virtual bool isHitting() const;
void flipFirstCard();
House(const string & HouseName = "House");
virtual ~House();
};
#endif /* House_hpp */
|
bbfc17c5377f0c2a3cb9d7359001d73b75d196a7
|
f4892c12c0e2ffdfbd678176dc8fa03f051314c4
|
/experimental/tiledb/common/dag/data_block/test/unit_data_block.cc
|
5ddda52147298aefde3bbfbb1c8e00510a62d68d
|
[
"MIT"
] |
permissive
|
TileDB-Inc/TileDB
|
06c15bcf6e3c62b191a6daa40fb33b41af2bdcdc
|
fddbe978d50ea7c9706fb0b7ca403c47986a4909
|
refs/heads/dev
| 2023-09-04T01:18:20.642838
| 2023-08-31T19:23:04
| 2023-09-02T14:36:02
| 86,868,560
| 1,779
| 204
|
MIT
| 2023-09-14T14:40:20
| 2017-03-31T23:44:23
|
C++
|
UTF-8
|
C++
| false
| false
| 26,549
|
cc
|
unit_data_block.cc
|
/**
* @file unit_data_block.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2022 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* Unit tests for the data_block class. We test with 3 sizes: size equal to a
* complete chunk, a size equal to half a chunk - 1, and a size equal to half a
* chunk + 1. The latter two are to check for some corner cases. We implement
* tests as templated functions to accommodate the differently sized
* `DataBlocks`.
*
* In addition to tests of `DataBlock`s, we also include tests of `DataBlock`s
* that have been joined into a virtual contiguous range. The implementation of
* `join` is in dag/utils/range_join.h.
*/
#include "unit_data_block.h"
#include <algorithm>
/**
* @todo Use proper checks for preprocessor directives to selectively include
* test with `std::execution` policy.
*/
#if 0
#include <execution>
#endif
#include <list>
#include <memory>
#include <vector>
#include "experimental/tiledb/common/dag/data_block/data_block.h"
#include "experimental/tiledb/common/dag/utility/range_join.h"
using namespace tiledb::common;
/**
* Test constructor
*/
TEST_CASE("DataBlock: Test create DataBlock", "[data_block]") {
SECTION("Constructor compilation tests") {
DataBlock da;
CHECK(da.size() == 0);
CHECK(da.capacity() == DataBlock::max_size());
DataBlock db{};
CHECK(db.size() == 0);
CHECK(db.capacity() == DataBlock::max_size());
DataBlock dc{0};
CHECK(dc.size() == 0);
CHECK(dc.capacity() == DataBlock::max_size());
DataBlock dd{DataBlock::max_size()};
CHECK(dd.size() == DataBlock::max_size());
CHECK(dd.capacity() == DataBlock::max_size());
auto de = DataBlock();
CHECK(de.size() == 0);
CHECK(de.capacity() == DataBlock::max_size());
auto df = DataBlock{};
CHECK(df.size() == 0);
CHECK(df.capacity() == DataBlock::max_size());
auto dg = DataBlock(0);
CHECK(dg.size() == 0);
CHECK(dg.capacity() == DataBlock::max_size());
auto dh = DataBlock{0};
CHECK(dh.size() == 0);
CHECK(dh.capacity() == DataBlock::max_size());
auto di = DataBlock(DataBlock::max_size());
CHECK(di.size() == DataBlock::max_size());
CHECK(di.capacity() == DataBlock::max_size());
auto dj = DataBlock{DataBlock::max_size()};
CHECK(dj.size() == DataBlock::max_size());
CHECK(dj.capacity() == DataBlock::max_size());
}
}
/**
* Some simple tests of the DataBlock interface.
*
* @tparam The `DataBlock` type
*/
template <class DB>
void db_test_0(DB& db) {
auto a = db.begin();
auto b = db.cbegin();
auto c = db.end();
auto d = db.cend();
CHECK(db.size() != 0);
CHECK(a == b);
CHECK(++a == ++b);
CHECK(a++ == b++);
CHECK(a == b);
CHECK(++a != b);
CHECK(a == ++b);
CHECK(c == d);
auto e = c + 5;
auto f = d + 5;
CHECK(c == e - 5);
CHECK(d == f - 5);
CHECK(e == f);
CHECK(e - 5 == f - 5);
auto g = a + 1;
CHECK(g > a);
CHECK(g >= a);
CHECK(a < g);
CHECK(a <= g);
}
template <class DB>
void db_test_1(const DB& db) {
auto a = db.begin();
auto b = db.cbegin();
auto c = db.end();
auto d = db.cend();
CHECK(db.size() != 0);
CHECK(a == b);
CHECK(++a == ++b);
CHECK(a++ == b++);
CHECK(a == b);
CHECK(++a != b);
CHECK(a == ++b);
CHECK(c == d);
auto e = c + 5;
auto f = d + 5;
CHECK(c == e - 5);
CHECK(d == f - 5);
CHECK(e == f);
CHECK(e - 5 == f - 5);
auto g = a + 1;
CHECK(g > a);
CHECK(g >= a);
CHECK(a < g);
CHECK(a <= g);
}
/**
* Invoke simple API tests with a basic `DataBlock`
*/
TEST_CASE("DataBlock: Test API of variously sized DataBlock", "[data_block]") {
SECTION("Specific size constructed") {
auto db = DataBlock{1};
db_test_0(db);
db_test_1(db);
}
SECTION("Specific size constructed") {
auto db = DataBlock{chunk_size_};
db_test_0(db);
db_test_1(db);
}
SECTION("Specific size constructed") {
auto db = DataBlock{chunk_size_ - 1};
db_test_0(db);
db_test_1(db);
}
SECTION("Specific size constructed") {
auto db = DataBlock{chunk_size_ / 2};
db_test_0(db);
db_test_1(db);
}
SECTION("Specific size constructed") {
auto db = DataBlock{chunk_size_ / 2 - 1};
db_test_0(db);
db_test_1(db);
}
SECTION("Specific size constructed") {
auto db = DataBlock{chunk_size_ / 2 + 1};
db_test_0(db);
db_test_1(db);
}
SECTION("Max size constructed") {
auto db = DataBlock{DataBlock::max_size()};
db_test_0(db);
db_test_1(db);
}
}
/**
* Invoke the simple tests with a `DataBlock` created with an `std::allocator`.
*/
TEST_CASE(
"DataBlock: Test create DataBlock with std::allocator<std::byte>",
"[data_block]") {
auto db = DataBlockImpl<std::allocator<std::byte>>{chunk_size_};
CHECK(db.size() == chunk_size_);
CHECK(db.capacity() == DataBlock::max_size());
db_test_0(db);
db_test_1(db);
auto dc = DataBlock{chunk_size_};
CHECK(dc.size() == chunk_size_);
CHECK(dc.capacity() == DataBlock::max_size());
db_test_0(dc);
db_test_1(dc);
}
/**
* Test iterating through a `DataBlock`
*/
template <class DB>
void db_test_2(DB& db) {
for (auto& j : db) {
j = std::byte{255};
}
auto e = std::find_if_not(
db.begin(), db.end(), [](auto a) { return std::byte{255} == a; });
CHECK(e == db.end());
for (auto& j : db) {
j = std::byte{13};
}
auto f = std::find_if_not(
db.begin(), db.end(), [](auto a) { return std::byte{13} == a; });
CHECK(f == db.end());
}
/**
* Run iteration test on DataBlock allocated with `std::allocator` and with our
* `PoolAllocator`.
*/
TEST_CASE("DataBlock: Iterate through data_block", "[data_block]") {
auto db = DataBlockImpl<std::allocator<std::byte>>{};
db_test_2(db);
auto dc = DataBlock{chunk_size_};
db_test_2(dc);
}
/**
* Run iteration test on multiple DataBlocks, again allocated with
* `std::allocator` and with our `PoolAllocator`.
*/
TEST_CASE("DataBlock: Iterate through 8 data_blocks", "[data_block]") {
for (size_t i = 0; i < 8; ++i) {
auto db = DataBlockImpl<std::allocator<std::byte>>{};
db_test_2(db);
}
for (size_t i = 0; i < 8; ++i) {
auto db = DataBlock{chunk_size_};
db_test_2(db);
}
}
/**
* Verify some properties of `DataBlock`s
*/
TEST_CASE("DataBlock: Get span", "[data_block]") {
auto a = DataBlock{};
auto b = DataBlock{};
auto c = DataBlock{};
CHECK(a.size() == 0);
CHECK(b.size() == 0);
CHECK(c.size() == 0);
CHECK(a.data() != b.data());
CHECK(a.data() != c.data());
CHECK(b.data() != c.data());
CHECK(a.capacity() == 4'194'304);
CHECK(b.capacity() == 4'194'304);
CHECK(c.capacity() == 4'194'304);
SECTION("entire_span") {
auto span_a = a.entire_span();
auto span_b = b.entire_span();
auto span_c = c.entire_span();
CHECK(span_a.data() == a.data());
CHECK(span_b.data() == b.data());
CHECK(span_c.data() == c.data());
CHECK(span_a.size() == 4'194'304);
CHECK(span_b.size() == 4'194'304);
CHECK(span_c.size() == 4'194'304);
}
SECTION("span") {
auto span_a = a.span();
auto span_b = b.span();
auto span_c = c.span();
CHECK(span_a.data() == a.data());
CHECK(span_b.data() == b.data());
CHECK(span_c.data() == c.data());
CHECK(span_a.size() == 0);
CHECK(span_b.size() == 0);
CHECK(span_c.size() == 0);
}
}
/**
* Test resizing.
*/
TEST_CASE("DataBlock: Test resize", "[data_block]") {
auto a = DataBlock{chunk_size_};
auto b = DataBlock{chunk_size_};
auto c = DataBlock{chunk_size_};
a.resize(1'000'000);
b.resize(2'000'000);
c.resize(3'000'000);
CHECK(a.size() == 1'000'000);
CHECK(b.size() == 2'000'000);
CHECK(c.size() == 3'000'000);
auto span_a = a.span();
auto span_b = b.span();
auto span_c = c.span();
CHECK(span_a.size() == 1'000'000);
CHECK(span_b.size() == 2'000'000);
CHECK(span_c.size() == 3'000'000);
}
TEST_CASE("DataBlock: Test (shallow) copying", "[data_block]") {
auto a = DataBlock{DataBlock::max_size()};
auto b = DataBlock{DataBlock::max_size()};
auto c = DataBlock{DataBlock::max_size()};
[[maybe_unused]] auto da = a.data();
[[maybe_unused]] auto db = b.data();
[[maybe_unused]] auto dc = c.data();
CHECK(a.size() == DataBlock::max_size());
CHECK(b.size() == DataBlock::max_size());
CHECK(c.size() == DataBlock::max_size());
CHECK(a.capacity() == DataBlock::max_size());
CHECK(b.capacity() == DataBlock::max_size());
CHECK(c.capacity() == DataBlock::max_size());
/* Hmm... Can't do arithmetic on std::byte */
std::iota(
reinterpret_cast<uint8_t*>(a.begin()),
reinterpret_cast<uint8_t*>(a.end()),
uint8_t{0});
std::iota(
reinterpret_cast<uint8_t*>(b.begin()),
reinterpret_cast<uint8_t*>(b.end()),
uint8_t{0});
std::iota(
reinterpret_cast<uint8_t*>(c.begin()),
reinterpret_cast<uint8_t*>(c.end()),
uint8_t{0});
auto check_iota = [](const DataBlock& y) {
uint8_t b{0};
for (auto&& j : y) {
if (static_cast<uint8_t>(j) != b) {
return false;
}
++b;
}
return true;
};
auto check_zero = [](const DataBlock& y) {
uint8_t b{0};
for (auto&& j : y) {
if (static_cast<uint8_t>(j) != b) {
return false;
}
}
return true;
};
CHECK(check_iota(a));
CHECK(check_iota(b));
CHECK(check_iota(c));
CHECK(!check_zero(a));
CHECK(!check_zero(b));
CHECK(!check_zero(c));
auto verify_da = [&check_iota, &check_zero](DataBlock& d, DataBlock& a) {
CHECK(a.data() == d.data());
CHECK(d.size() == a.size());
a.resize(1);
CHECK(a.size() == 1);
CHECK(d.size() == DataBlock::max_size());
a.resize(DataBlock::max_size());
CHECK(a.size() == DataBlock::max_size());
CHECK(d.size() == DataBlock::max_size());
/**
* Test changes to a reflecting in d
*/
CHECK(check_iota(a));
CHECK(check_iota(d));
std::fill(a.begin(), a.end(), std::byte{0});
CHECK(check_zero(a));
CHECK(check_zero(d));
/**
* Test changes to d reflecting in a
*/
std::iota(
reinterpret_cast<uint8_t*>(a.begin()),
reinterpret_cast<uint8_t*>(a.end()),
uint8_t{0});
CHECK(check_iota(a));
CHECK(check_iota(d));
std::fill(d.begin(), d.end(), std::byte{0});
CHECK(check_zero(a));
CHECK(check_zero(d));
};
SECTION("Test copy constructor") {
auto d = a;
verify_da(d, a);
}
SECTION("Test copy constructor, ii") {
DataBlock d(a);
verify_da(d, a);
}
SECTION("Test assignment") {
DataBlock d;
d = a;
verify_da(d, a);
}
/**
* Test move constructors. This is dangerous because in general, pointers may
* not be valid.
*/
SECTION("Test move constructor, ii") {
DataBlock tmp = b;
CHECK(tmp.use_count() == 2);
CHECK(b.use_count() == 2);
DataBlock d(std::move(b));
CHECK(d.use_count() == 2);
CHECK(b.use_count() == 0);
CHECK(tmp.use_count() == 2);
// Don't verify against something that has been moved from
// verify_da(d, b);
CHECK(db == tmp.data());
CHECK(db == d.data());
verify_da(d, tmp);
}
SECTION("Test move assignment") {
DataBlock tmp = c;
DataBlock d;
CHECK(c.use_count() == 2);
d = std::move(c);
CHECK(dc == d.data());
CHECK(c.use_count() == 0); // Can't use c any longer
// Don't verify against something that has been moved from
// verify_da(d, c);
verify_da(d, tmp);
}
}
#if 0
/**
* Attempt to test destructor by invoking it explicitly. Unfortunately, the destructor will be invoked again when the variable goes out of scope. Which is bad.
*/
TEST_CASE(
"DataBlock: Test allocation and deallocation of DataBlock", "[data_block") {
auto a = DataBlock{chunk_size_};
auto ptr_a = a.data();
// Don't do this! It will call destructor again when `a` goes out of scope
// (which would be bad)
a.~DataBlock();
auto b = DataBlock{chunk_size_};
auto ptr_b = b.data();
CHECK(ptr_a == ptr_b);
}
#endif
/**
* Verify that blocks are deallocated properly when the destructor is called. We
* leverage the fact (and also check) that the `PoolAllocator` is a FIFO buffer
* and check that when we deallocate a block, that will be the block that is
* returned on next call to allocate.
*/
TEST_CASE(
"DataBlock: Test deallocation of DataBlock on destruction",
"[data_block]") {
std::byte* x;
std::byte* y;
{
auto a = DataBlock{chunk_size_};
auto b = DataBlock{chunk_size_};
x = a.data();
y = b.data();
CHECK(x != y);
}
// b is deallocated first, then a is deallocated (LIFO)
// allocate a first, then b
auto a = DataBlock{chunk_size_};
auto b = DataBlock{chunk_size_};
auto ptr_a = a.data();
auto ptr_b = b.data();
CHECK(ptr_a != ptr_b);
CHECK(x == ptr_a);
CHECK(y == ptr_b);
}
TEST_CASE(
"DataBlock: Test DataBlock allocation/deallocation from pool, etc",
"[data_block]") {
auto a = DataBlock{chunk_size_};
auto b = DataBlock{chunk_size_};
auto c = DataBlock{chunk_size_};
auto da = a.data();
auto db = b.data();
auto dc = c.data();
CHECK(da != db);
CHECK(da != dc);
CHECK(db != dc);
decltype(da) dd = nullptr;
{
auto d = DataBlock{chunk_size_};
dd = d.data();
CHECK(da != dd);
CHECK(db != dd);
CHECK(dc != dd);
auto e = DataBlock{chunk_size_};
auto de = e.data();
CHECK(da != de);
CHECK(db != de);
CHECK(dc != de);
CHECK(dd != de);
}
{
auto d = DataBlock{chunk_size_};
auto de = d.data();
CHECK(dd == de);
CHECK(da != de);
CHECK(db != de);
CHECK(dc != de);
}
}
TEST_CASE(
"DataBlock: Test DataBlock allocation/deallocation on copying, etc",
"[data_block]") {
auto a = DataBlock{chunk_size_};
auto b = DataBlock{chunk_size_};
auto c = DataBlock{chunk_size_};
auto da = a.data();
auto db = b.data();
auto dc = c.data();
CHECK(da != db);
CHECK(da != dc);
CHECK(db != dc);
auto test_use_counts = [](DataBlock& d, DataBlock& a) {
auto dd = d.data();
auto da = a.data();
CHECK(da == dd);
CHECK(d.use_count() == 2);
CHECK(a.use_count() == 2);
{
auto e = a;
auto de = e.data();
CHECK(da == de);
CHECK(e.use_count() == 3);
CHECK(d.use_count() == 3);
CHECK(a.use_count() == 3);
}
CHECK(d.use_count() == 2);
CHECK(a.use_count() == 2);
};
auto test_use_counts_move = [](DataBlock& d, DataBlock& a) {
auto dd = d.data();
auto da = a.data();
CHECK(da == dd);
CHECK(d.use_count() == 1);
CHECK(a.use_count() == 0);
{
auto e = d;
auto de = e.data();
CHECK(dd == de);
CHECK(e.use_count() == 2);
CHECK(d.use_count() == 2);
CHECK(a.use_count() == 0);
}
CHECK(d.use_count() == 1);
CHECK(a.use_count() == 0);
};
SECTION("Test uses with copy constructor") {
{
auto d = a;
test_use_counts(d, a);
}
CHECK(a.use_count() == 1);
}
SECTION("Test copy constructor, ii") {
{
DataBlock d(a);
test_use_counts(d, a);
}
CHECK(a.use_count() == 1);
}
SECTION("Test assignment") {
{
DataBlock d;
d = a;
test_use_counts(d, a);
}
CHECK(a.use_count() == 1);
}
SECTION("Test move constructor, ii") {
{
DataBlock d(std::move(b));
test_use_counts_move(d, b);
}
CHECK(b.use_count() == 0);
}
SECTION("Test move assignment") {
{
DataBlock d;
d = std::move(c);
test_use_counts_move(d, c);
}
CHECK(c.use_count() == 0);
}
}
/**
* Verify the random-access range interface of a `DataBlock` by using
* `std::fill` algorithm.
*/
void test_std_fill(size_t test_size) {
auto a = DataBlock{test_size};
auto b = DataBlock{test_size};
auto c = DataBlock{test_size};
CHECK(a.begin() + test_size == a.end());
CHECK(b.begin() + test_size == b.end());
CHECK(c.begin() + test_size == c.end());
CHECK(a.size() == test_size);
CHECK(b.size() == test_size);
CHECK(c.size() == test_size);
std::fill(a.begin(), a.end(), std::byte{0});
std::fill(b.begin(), b.end(), std::byte{0});
std::fill(c.begin(), c.end(), std::byte{0});
a[33] = std::byte{19};
CHECK(a[32] == std::byte{0});
CHECK(a[33] == std::byte{19});
CHECK(a[34] == std::byte{0});
b[127] = std::byte{23};
CHECK(b[126] == std::byte{0});
CHECK(b[127] == std::byte{23});
CHECK(b[128] == std::byte{0});
c[432] = std::byte{29};
CHECK(c[431] == std::byte{0});
CHECK(c[432] == std::byte{29});
CHECK(c[433] == std::byte{0});
for (auto& j : a) {
j = std::byte{23};
}
for (auto& j : b) {
j = std::byte{23};
}
for (auto& j : c) {
j = std::byte{29};
}
std::fill(a.begin(), a.end(), std::byte{0});
std::fill(b.begin(), b.end(), std::byte{0});
std::fill(c.begin(), c.end(), std::byte{0});
CHECK(a.end() == std::find_if_not(a.begin(), a.end(), [](auto e) {
return (std::byte{0} == e);
}));
CHECK(b.end() == std::find_if_not(b.begin(), b.end(), [](auto e) {
return (std::byte{0} == e);
}));
CHECK(c.end() == std::find_if_not(c.begin(), c.end(), [](auto e) {
return (std::byte{0} == e);
}));
std::fill(a.begin(), a.end(), std::byte{19});
std::fill(b.begin(), b.end(), std::byte{23});
std::fill(c.begin(), c.end(), std::byte{29});
CHECK(a.end() == std::find_if_not(a.begin(), a.end(), [](auto e) {
return (std::byte{19} == e);
}));
CHECK(b.end() == std::find_if_not(b.begin(), b.end(), [](auto e) {
return (std::byte{23} == e);
}));
CHECK(c.end() == std::find_if_not(c.begin(), c.end(), [](auto e) {
return (std::byte{29} == e);
}));
}
/**
* Verify the random-access range interface of a `DataBlock` by using
* `std::fill` algorithm.
*/
TEST_CASE("DataBlock: Fill with std::fill", "[data_block]") {
SECTION("chunk_size") {
test_std_fill(chunk_size_);
}
SECTION("chunk_size / 2 + 1") {
test_std_fill(chunk_size_ / 2 + 1);
}
SECTION("chunk_size / 2 -1") {
test_std_fill(chunk_size_ / 2 - 1);
}
}
/**
* Verify some properties of joined `DataBlock`s.
*/
void test_join(size_t test_size) {
auto a = DataBlock{test_size};
auto b = DataBlock{test_size};
auto c = DataBlock{test_size};
std::list<DataBlock> x{a, b, c};
auto y = join(x);
CHECK(a.begin() + test_size == a.end());
CHECK(b.begin() + test_size == b.end());
CHECK(c.begin() + test_size == c.end());
CHECK(a.size() == test_size);
CHECK(b.size() == test_size);
CHECK(c.size() == test_size);
CHECK(y.size() == (a.size() + b.size() + c.size()));
for (auto& j : a) {
j = std::byte{19};
}
for (auto& j : b) {
j = std::byte{23};
}
for (auto& j : c) {
j = std::byte{29};
}
auto e = std::find_if_not(y.begin(), y.end(), [](auto a) {
return (std::byte{19} == a) || (std::byte{23} == a) || (std::byte{29} == a);
});
CHECK(e == y.end());
size_t k = 0;
for ([[maybe_unused]] auto& j : y) {
++k;
}
CHECK(k == y.size());
for (auto& j : y) {
j = std::byte{89};
}
auto f = std::find_if_not(
a.begin(), a.end(), [](auto a) { return (std::byte{89} == a); });
CHECK(f == a.end());
for (auto& j : y) {
j = std::byte{91};
}
auto g = std::find_if_not(
b.begin(), b.end(), [](auto a) { return (std::byte{91} == a); });
CHECK(g == b.end());
for (auto& j : y) {
j = std::byte{103};
}
auto h = std::find_if_not(
c.begin(), c.end(), [](auto a) { return (std::byte{103} == a); });
CHECK(h == c.end());
}
TEST_CASE("DataBlock: Join data_blocks (join view)", "[data_block]") {
SECTION("chunk_size") {
test_join(chunk_size_);
}
SECTION("chunk_size / 2") {
test_join(chunk_size_ / 2 + 1);
}
SECTION("chunk_size / 2") {
test_join(chunk_size_ / 2 - 1);
}
}
/**
* Verify that joined `DataBlock`s operate as a forward range by using standard
* library algorithms.
*/
void test_join_std_fill(size_t test_size) {
auto a = DataBlock{test_size};
auto b = DataBlock{test_size};
auto c = DataBlock{test_size};
CHECK(a.begin() + test_size == a.end());
CHECK(b.begin() + test_size == b.end());
CHECK(c.begin() + test_size == c.end());
std::fill(a.begin(), a.end(), std::byte{0});
std::fill(b.begin(), b.end(), std::byte{0});
std::fill(c.begin(), c.end(), std::byte{0});
std::list<DataBlock> x{a, b, c};
auto y = join(x);
CHECK(y.size() == (a.size() + b.size() + c.size()));
auto e = std::find_if_not(
y.begin(), y.end(), [](auto e) { return (std::byte{0} == e); });
CHECK(e == y.end());
std::fill(y.begin(), y.end(), std::byte{77});
auto f = std::find_if_not(
y.begin(), y.end(), [](auto e) { return (std::byte{77} == e); });
CHECK(f == y.end());
auto g = std::find_if_not(
a.begin(), a.end(), [](auto e) { return (std::byte{77} == e); });
CHECK(g == a.end());
auto h = std::find_if_not(
b.begin(), b.end(), [](auto e) { return (std::byte{77} == e); });
CHECK(h == b.end());
auto i = std::find_if_not(
c.begin(), c.end(), [](auto e) { return (std::byte{77} == e); });
CHECK(i == c.end());
}
TEST_CASE("DataBlock: Join data_blocks std::fill", "[data_block]") {
SECTION("chunk_size") {
test_join_std_fill(chunk_size_);
}
SECTION("chunk_size / 2") {
test_join_std_fill(chunk_size_ / 2 + 1);
}
SECTION("chunk_size / 2") {
test_join_std_fill(chunk_size_ / 2 - 1);
}
}
/**
* Test `operator[]` of joined `DataBlock`s.
*/
void test_join_operator_bracket(size_t test_size) {
auto a = DataBlock{test_size};
auto b = DataBlock{test_size};
auto c = DataBlock{test_size};
CHECK(a.begin() + test_size == a.end());
CHECK(b.begin() + test_size == b.end());
CHECK(c.begin() + test_size == c.end());
std::fill(a.begin(), a.end(), std::byte{33});
std::fill(b.begin(), b.end(), std::byte{66});
std::fill(c.begin(), c.end(), std::byte{99});
std::vector<DataBlock> x{a, b, c};
auto y = join(x);
a[33] = std::byte{19};
CHECK(a[32] == std::byte{33});
CHECK(a[33] == std::byte{19});
CHECK(a[34] == std::byte{33});
b[127] = std::byte{23};
CHECK(b[126] == std::byte{66});
CHECK(b[127] == std::byte{23});
CHECK(b[128] == std::byte{66});
c[432] = std::byte{29};
CHECK(c[431] == std::byte{99});
CHECK(c[432] == std::byte{29});
CHECK(c[433] == std::byte{99});
CHECK(y[0] == std::byte{33});
CHECK(y[32] == std::byte{33});
CHECK(y[33] == std::byte{19});
CHECK(y[34] == std::byte{33});
CHECK(y[test_size + 126] == std::byte{66});
CHECK(y[test_size + 127] == std::byte{23});
CHECK(y[test_size + 128] == std::byte{66});
CHECK(y[2 * test_size + 431] == std::byte{99});
CHECK(y[2 * test_size + 432] == std::byte{29});
CHECK(y[2 * test_size + 433] == std::byte{99});
}
TEST_CASE("DataBlock: Join data_blocks operator[]", "[data_block]") {
SECTION("chunk_size") {
test_join_operator_bracket(chunk_size_);
}
SECTION("chunk_size / 2") {
test_join_operator_bracket(chunk_size_ / 2 + 1);
}
SECTION("chunk_size / 2") {
test_join_operator_bracket(chunk_size_ / 2 - 1);
}
}
/**
* Additional standard library uses of joined `DataBlock`s.
*/
void test_operator_bracket_loops(size_t test_size) {
auto a = DataBlock{test_size};
auto b = DataBlock{test_size};
auto c = DataBlock{test_size};
CHECK(a.size() == test_size);
CHECK(b.size() == test_size);
CHECK(c.size() == test_size);
std::vector<DataBlock> x{a, b, c};
CHECK(x.size() == 3);
auto y = join(x);
CHECK(y.size() == a.size() + b.size() + c.size());
CHECK(y.size() == 3 * test_size);
/* Hmm... Can't do arithmetic on std::byte */
std::iota(
reinterpret_cast<uint8_t*>(a.begin()),
reinterpret_cast<uint8_t*>(a.end()),
uint8_t{0});
std::iota(
reinterpret_cast<uint8_t*>(b.begin()),
reinterpret_cast<uint8_t*>(b.end()),
static_cast<uint8_t>(a.back()) + 1);
std::iota(
reinterpret_cast<uint8_t*>(c.begin()),
reinterpret_cast<uint8_t*>(c.end()),
static_cast<uint8_t>(b.back()) + 1);
CHECK([&]() {
uint8_t b{0};
for (size_t i = 0; i < y.size(); ++i) {
if (static_cast<uint8_t>(y[i]) != b) {
std::cout << i << " " << static_cast<uint8_t>(y[i]) << " " << b
<< std::endl;
return false;
}
++b;
}
return true;
}());
CHECK([&]() {
uint8_t b{0};
for (auto&& j : y) {
if (static_cast<uint8_t>(j) != b) {
std::cout << static_cast<uint8_t>(j) << " " << b << std::endl;
return false;
}
++b;
}
return true;
}());
uint8_t d{0};
auto z = std::find_if_not(y.begin(), y.end(), [&d](auto e) {
return static_cast<uint8_t>(e) == d++;
});
CHECK(z == y.end());
/**
* @todo Use proper checks for preprocessor directives to selectively include
* test with `std::execution` policy.
*/
#if 0
d = 0;
auto u = std::find_if_not(
std::execution::par_unseq, y.begin(), y.end(), [&d](auto e) {
return static_cast<uint8_t>(e) == d++;
});
CHECK(u == y.end());
#endif
}
TEST_CASE("DataBlock: Join data_blocks loops operator[]", "[data_block]") {
SECTION("chunk_size") {
test_operator_bracket_loops(chunk_size_);
}
SECTION("chunk_size / 2") {
test_operator_bracket_loops(chunk_size_ / 2 + 1);
}
SECTION("chunk_size / 2") {
test_operator_bracket_loops(chunk_size_ / 2 - 1);
}
}
|
9704caeffb934f87a55530676ad33fa9db5f39fd
|
353701a914f9d3bd4bd5b6cc61e47ba969b8682d
|
/topic/rtm_standard/rtm.cpp
|
6d196f6782e93a6675ff492f34f4f837c79d2638
|
[] |
no_license
|
yuanwujun/mllib
|
88025f6be08d52102fae35b0884ba8d3f08628bd
|
4a43c80a9e660b160c58cdafaad0984e645c57d3
|
refs/heads/master
| 2021-01-10T20:30:11.879844
| 2015-01-29T07:04:23
| 2015-01-29T07:04:23
| 24,022,914
| 0
| 2
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 401
|
cpp
|
rtm.cpp
|
// Copyright 2014 lijiankou. All Rights Reserved.
// Author: lijk_start@163.com (Jiankou Li)
#include "rtm.h"
void ml::RTMSuffStats::SetZero(int k, int v) {
topic.resize(k, v);
topic.setZero();
topic_sum.resize(k);
topic_sum.setZero();
}
void ml::RTMSuffStats::InitSS(int k, int v) {
topic.resize(k, v);
topic.setConstant(1.0 / v);
topic_sum.resize(k);
topic_sum.setConstant(1);
}
|
66b26ad85dbc0ec880a74cf4617920c1573641bc
|
1a973acc4d44988f036431300477d8656dd7a60a
|
/Algorithm/Greedy Algorithm/0435 Non-overlapping Intervals.cpp
|
cc549d148e3d38814131cf9fa2f6c6db947adbd4
|
[] |
no_license
|
kerry918/Leetcode
|
9a7291e726b3fef8b6d187ee0132b79bacc209cd
|
cecc65b040eeb5b54eb28d17559a888c8b0d36c5
|
refs/heads/master
| 2023-05-05T23:10:13.167770
| 2021-05-27T13:42:24
| 2021-05-27T13:42:24
| 267,178,510
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 993
|
cpp
|
0435 Non-overlapping Intervals.cpp
|
class Solution {
public:
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
int size = intervals.size(), remove = 0;
// if 0 or 1 interval, then no interval should be removed
if (size <= 1) return 0;
// sort by endpoint
sort(intervals.begin(), intervals.end(), [](const vector<int>& a, const vector<int>& b){
// put a infront of b when the endpoint of a is less than endpoint of b
return a[1] < b[1];
});
int prevEnd = intervals[0][1]; // initialize the endpoint to the first interval
// loop the rest of the interval in a for loop
for (int i = 1; i < size; i++){
// if the current interval start is less than the previous interval end, then overlap
if (intervals[i][0] < prevEnd){
remove ++;
}
// if there is not overlap, update the prevEnd to the current one
else prevEnd = intervals[i][1];
}
return remove;
}
};
// https://www.youtube.com/watch?v=hyQZCTfQDxo
|
70df7925a5a8d98c938c0b5756b6ea3473befd72
|
6d088ec295b33db11e378212d42d40d5a190c54c
|
/contrib/conversions/math/vnl_vector_to_vbl_array.h
|
b63e0e7e85c8005abf8b52017fc87bd5455d105d
|
[] |
no_license
|
vxl/vxl
|
29dffd5011f21a67e14c1bcbd5388fdbbc101b29
|
594ebed3d5fb6d0930d5758630113e044fee00bc
|
refs/heads/master
| 2023-08-31T03:56:24.286486
| 2023-08-29T17:53:12
| 2023-08-29T17:53:12
| 9,819,799
| 224
| 126
| null | 2023-09-14T15:52:32
| 2013-05-02T18:32:27
|
C++
|
UTF-8
|
C++
| false
| false
| 301
|
h
|
vnl_vector_to_vbl_array.h
|
#ifndef vnl_vector_to_vbl_array_h_
#define vnl_vector_to_vbl_array_h_
#include <vnl/vnl_vector.h>
#include <vbl/vbl_array_1d.h>
template <class T>
inline vbl_array_1d<T> vnl_vector_to_vbl_array(vnl_vector<T> v)
{
return vbl_array_1d<T>(v.begin(), v.end());
}
#endif // vnl_vector_to_vbl_array_h_
|
20aabbbbca57564bc25476bcb3dc30df0f1cdc45
|
e675779071e22d3224de816fa1e5da02921cc10b
|
/Algorithm/Utilities/Utilities.h
|
50186a6ec5a4a1c25836a1f7f1f4e76da2c4a494
|
[
"Apache-2.0"
] |
permissive
|
xiaoyaolanyun/QPanda-2
|
c7743a8fe1a3e0d4fec5800210677cb350b38f98
|
04dc1114ee46bcfa2f69417f71507c6c050c006f
|
refs/heads/master
| 2020-04-23T20:07:03.133965
| 2019-02-19T03:37:07
| 2019-02-19T03:37:07
| 171,428,729
| 1
| 0
| null | 2019-02-19T07:43:30
| 2019-02-19T07:43:29
| null |
UTF-8
|
C++
| false
| false
| 1,078
|
h
|
Utilities.h
|
/*
Copyright (c) 2017-2018 Origin Quantum Computing. All Right Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef UTILITIES_H
#define UTILITIES_H
#include "../QAlgorithm.h"
namespace QPanda
{
void Reset_Qubit(Qubit*, bool setVal);
QProg Reset_Qubit_Circuit(Qubit *q, CBit* cbit, bool setVal);
void Reset_All(vector<Qubit*> qubit_vector, bool setVal);
/*
CNOT all qubits (except last) with the last qubit
param:
qubit_vec: qubit vecotr
return:
QCircuit
*/
QCircuit parity_check_circuit(std::vector<Qubit*> qubit_vec);
}
#endif
|
9317f51cf4faf4d0dcdab80e4e4e78dce73af78a
|
aa9887968b39c45f0cda27cf22152fc5e5b7d46d
|
/src/vendor/Karabiner-VirtualHIDDevice/tests/src/hid_report/test.cpp
|
380a74405a0c780e7ab4ae1bd0fa133a91513256
|
[
"Unlicense"
] |
permissive
|
paganholiday/key-remap
|
9edef7910dc8a791090d559997d42e94fca8b904
|
a9154a6b073a3396631f43ed11f6dc603c28ea7b
|
refs/heads/master
| 2021-07-06T05:11:50.653378
| 2020-01-11T14:21:58
| 2020-01-11T14:21:58
| 233,709,937
| 0
| 1
|
Unlicense
| 2021-04-13T18:21:39
| 2020-01-13T22:50:13
|
C++
|
UTF-8
|
C++
| false
| false
| 8,959
|
cpp
|
test.cpp
|
#define CATCH_CONFIG_MAIN
#include "../../vendor/catch/catch.hpp"
#include "karabiner_virtual_hid_device.hpp"
TEST_CASE("modifiers") {
{
pqrs::karabiner_virtual_hid_device::hid_report::modifiers modifiers;
REQUIRE(modifiers.get_raw_value() == 0x0);
REQUIRE(modifiers.empty());
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_command));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_command));
modifiers.insert(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_control);
REQUIRE(modifiers.get_raw_value() == 0x1);
REQUIRE(!modifiers.empty());
REQUIRE(modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_command));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_command));
modifiers.insert(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_control);
REQUIRE(modifiers.get_raw_value() == 0x11);
REQUIRE(!modifiers.empty());
REQUIRE(modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_command));
REQUIRE(modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_command));
modifiers.erase(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_shift);
REQUIRE(modifiers.get_raw_value() == 0x11);
REQUIRE(!modifiers.empty());
REQUIRE(modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_command));
REQUIRE(modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_command));
modifiers.erase(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_control);
REQUIRE(modifiers.get_raw_value() == 0x10);
REQUIRE(!modifiers.empty());
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_command));
REQUIRE(modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_command));
modifiers.clear();
REQUIRE(modifiers.get_raw_value() == 0x0);
REQUIRE(modifiers.empty());
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::left_command));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_control));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_shift));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_option));
REQUIRE(!modifiers.exists(pqrs::karabiner_virtual_hid_device::hid_report::modifier::right_command));
}
}
TEST_CASE("keys") {
{
pqrs::karabiner_virtual_hid_device::hid_report::keys keys;
uint8_t expected[32];
REQUIRE(keys.count() == 0);
REQUIRE(keys.empty());
memset(expected, 0, sizeof(expected));
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
keys.insert(10);
REQUIRE(keys.count() == 1);
REQUIRE(!keys.empty());
REQUIRE(keys.exists(10));
REQUIRE(!keys.exists(20));
expected[0] = 10;
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
keys.insert(10);
REQUIRE(keys.count() == 1);
REQUIRE(!keys.empty());
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
keys.erase(20);
REQUIRE(keys.count() == 1);
REQUIRE(!keys.empty());
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
keys.erase(10);
REQUIRE(keys.count() == 0);
REQUIRE(keys.empty());
expected[0] = 0;
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
keys.erase(10);
REQUIRE(keys.count() == 0);
REQUIRE(keys.empty());
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
keys.insert(10);
REQUIRE(keys.count() == 1);
REQUIRE(!keys.empty());
expected[0] = 10;
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
keys.insert(20);
REQUIRE(keys.count() == 2);
REQUIRE(!keys.empty());
expected[1] = 20;
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
keys.clear();
REQUIRE(keys.count() == 0);
REQUIRE(keys.empty());
expected[0] = 0;
expected[1] = 0;
REQUIRE(memcmp(keys.get_raw_value(), expected, sizeof(expected)) == 0);
}
{
// Overflow
pqrs::karabiner_virtual_hid_device::hid_report::keys keys;
REQUIRE(keys.count() == 0);
for (int i = 0; i < 32; ++i) {
keys.insert(i + 1);
REQUIRE(keys.count() == (i + 1));
}
keys.insert(10);
REQUIRE(keys.count() == 32);
keys.insert(20);
REQUIRE(keys.count() == 32);
}
}
TEST_CASE("buttons") {
{
pqrs::karabiner_virtual_hid_device::hid_report::buttons buttons;
REQUIRE(buttons.get_raw_value() == 0);
REQUIRE(buttons.empty());
buttons.insert(1);
REQUIRE(buttons.get_raw_value() == 0x1);
REQUIRE(!buttons.empty());
buttons.insert(32);
REQUIRE(buttons.get_raw_value() == 0x80000001);
REQUIRE(!buttons.empty());
buttons.insert(0);
REQUIRE(buttons.get_raw_value() == 0x80000001);
REQUIRE(!buttons.empty());
buttons.insert(33);
REQUIRE(buttons.get_raw_value() == 0x80000001);
REQUIRE(!buttons.empty());
buttons.erase(1);
REQUIRE(buttons.get_raw_value() == 0x80000000);
REQUIRE(!buttons.empty());
buttons.clear();
REQUIRE(buttons.get_raw_value() == 0);
REQUIRE(buttons.empty());
}
}
|
a49a328b250616ac36ebdc3a19b2cf6620351e25
|
8559edef3b57407ac5d11cb23df68b50b07b7911
|
/Bestt_algorithm Based problems code/C++ .STL Container/Stack example/stack.cpp
|
786a9eb1e522fd2c1eba6dda7fed6f34e0d83415
|
[] |
no_license
|
mijanur-rahman-40/C-C-plus-plus-Online-Judge-Algorithms-Practise-Programming
|
2a031b0743356ba4c8670623aaa87b57f0b43f27
|
254924e4bd890e2f6d434abcc9ef52ef3e209211
|
refs/heads/master
| 2023-02-13T06:26:20.422678
| 2021-01-13T14:20:21
| 2021-01-13T14:20:21
| 329,330,528
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 333
|
cpp
|
stack.cpp
|
#include <bits/stdc++.h>
using namespace std;
int main(){
stack<int>st;
for(int i = 0 ;i < 5 ;i++){
if(st.size() > 2){
cout<<"overflow"<<endl;
}
else st.push(i);
}
while( !st.empty() ){
int x = st.top();
st.pop();
cout<<x<<endl;
}
return 0;
}
|
8453617bfc21f956339cc4e98511af5e0da550dd
|
150b7df40c5d97fc7ab403dc60edc57aa5cb1130
|
/DSA/tranposematrix.cpp
|
990ec2c8a87f316fa840c22db7eaec3238cde5e6
|
[] |
no_license
|
anshusinha872/HacktoberFest-2021
|
ba530fcac67a8339db1437d561443488d675a825
|
f03278bf213b96ce5829807ea81aa194d18742df
|
refs/heads/main
| 2023-08-20T06:41:41.102952
| 2021-10-15T17:01:33
| 2021-10-15T17:01:33
| 411,524,395
| 0
| 13
| null | 2021-10-03T08:35:07
| 2021-09-29T04:02:51
|
C++
|
UTF-8
|
C++
| false
| false
| 749
|
cpp
|
tranposematrix.cpp
|
#include<iostream>
using namespace std;
int main(){
int n,m;
cout<<"Enter the number of Rows :";
cin>>n;
cout<<"Enter the number of Columns :";
cin>>m;
int arr[n][m];
cout<<"Enter the Elements of array :";
for (int i = 0; i < n; i++)
{
for(int j=0; j<m; j++)
{
cin>>arr[i][j];
}
}
for (int i = 0; i < n; i++)
{
for(int j=i; j<m; j++)
{
int temp= arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i]= temp;
}
}
cout<<"Array after tranpose :";
for (int i = 0; i < n; i++)
{
for(int j=0; j<m; j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
}
|
d3d1ed6dc3b0c4e41790c83f99e545728218bc8e
|
3db233d14bc4f9f350db3b69a7b18ee287381813
|
/StampPress/stampstream.h
|
c1b95b9711465ca53926f953325abfb1fc7605a9
|
[] |
no_license
|
pinakdas163/CPP-Projects
|
e6f5d2d7403f220860d399c0c75213ecbad12553
|
08981f3894225d7f591d051ce9b749191f343aa1
|
refs/heads/master
| 2020-04-10T05:10:29.176672
| 2017-02-02T08:26:23
| 2017-02-02T08:26:23
| 68,132,474
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 364
|
h
|
stampstream.h
|
#ifndef STAMPSTREAM_H
#define STAMPSTREAM_H
#include <iostream>
#include "stampbuf.h"
#include "row.h"
class stampstream: public std::ostream
{
public:
stampstream(int r, int c);
~stampstream();
private:
int cur_column;
int cur_row;
};
std::ostream& endrow(std::ostream& os);
std::ostream& operator<<(std::ostream& os, const row& r);
#endif
|
8b0cb217d1bc1d0037a85530fafde2a1596bc15b
|
efc4b3be9fd74865352809d36e00fbe72eba9b48
|
/BDK/Include/BreadSSEVector4.h
|
a3adf450c7303433ae9fe92a54ee98433e995b1c
|
[] |
no_license
|
prodongi/Bread
|
3d2cc9b272b71345f777f5dc6e314b657032c530
|
07916d523f6730b4a3c9a8e2babf2f1929c3f6c6
|
refs/heads/master
| 2020-05-30T16:08:31.844074
| 2013-09-09T13:53:39
| 2013-09-09T13:53:39
| 12,702,338
| 0
| 1
| null | null | null | null |
UHC
|
C++
| false
| false
| 270
|
h
|
BreadSSEVector4.h
|
#ifndef _BreadSSEVector4_h_
#define _BreadSSEVector4_h_
#include <xmmintrin.h>
namespace Bread
{
/*
@date 2011.08.16
@auth prodongi
@desc SSE를 이용한 sVector4, Game Engine Architecture 참조
@todo
*/
struct sSSEVector4
{
__m128 m;
};
}
#endif
|
64291faa5e325084ae598947731c2d07b60aec73
|
c600acf91635b765165826e3048a9ea6fd55d5e7
|
/src/TrackMeas.hpp
|
edc87facf69e4c3d9dd1a680cf30374b0ae60c56
|
[] |
no_license
|
JAGF009/TrackComp
|
e20bf5a305a59ab72a411e084dad9f9814dd48fc
|
b47b9eb851241fc24bf2ee65c58cf8b4dc019a6e
|
refs/heads/master
| 2020-03-15T11:12:43.825088
| 2018-05-28T15:56:31
| 2018-05-28T15:56:31
| 132,115,948
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,213
|
hpp
|
TrackMeas.hpp
|
#ifndef TRACKMEAS_H
#define TRACKMEAS_H
#include <vector>
#include <memory>
#include <unordered_set>
#include <opencv2/opencv.hpp>
#include <fstream>
#include "Rect.hpp"
#include "Factory.hpp"
#include "Trajectory.hpp"
namespace pix{
struct Comp
{
Comp(double athres): thresh(athres) {}
bool operator()(const double& lhs) { return lhs >= thresh;}
double thresh;
};
class TrackMeas
{
private:
m_int n_frames {0};
m_int n_track {0};
m_int n_gts {0};
m_int n_false_positives {0};
m_int n_false_negatives {0};
m_int m_frameSkip{0};
m_int m_width{0};
m_int m_height{0};
m_int frame_number{0};
bool m_stop{false};
bool store{false};
std::ofstream storage;
std::string m_id;
std::unique_ptr<DBReader> db;
std::unique_ptr<pix::TrackerInterface> tracker;
cv::Mat image;
std::vector<double> m_fScore {};
std::vector<double> m_f1Score {};
std::vector<double> m_distances {};
pix::Trajectory real_traj;
pix::Trajectory detectec_traj;
public:
TrackMeas() = default;
TrackMeas(const std::string& path, const std::string& id, pix::DBType dt_type, pix::TrackerType track_type);
~TrackMeas();
m_int frameSkip() const noexcept { return m_frameSkip; }
void setFrameSkip(m_int fs) noexcept { m_frameSkip = fs; }
void stop() noexcept { m_stop = true; }
bool stopped() const noexcept { return m_stop; }
bool idInFrame(m_int, const std::string&, std::unordered_set<std::string>&) const;
void init_track(const cv::Mat&, const pix::Rect&);
void go();
void goStoreResults(const std::string& path);
double fScore(double) const noexcept;
double f1Score() const noexcept;
double OTA(double) const noexcept;
double OTP(double) const noexcept;
double ATA() const noexcept;
double Deviation() const noexcept;
private:
void show(const pix::Rect&, const pix::Rect&, int time = 1);
void newFrame(const pix::Rect& = pix::Rect(), const pix::Rect& = pix::Rect());
};
}
#endif // TRACKMEAS_H
|
1073a5799aa93979bcfafd64baeac2fe3db9d26e
|
4f2dd8732d674a80208b37b04730785a3dd093a5
|
/ds.cc
|
7599460a835ffc0df8b124100953af21cdf00ae0
|
[] |
no_license
|
grasingerm/PL
|
5fa05b1147e8a51cc1144ec392adf3b260fbb9fd
|
c271d3d4135f3b1dec28cdabbb4298c77a981c5f
|
refs/heads/master
| 2022-11-10T23:05:48.931924
| 2022-09-26T03:58:43
| 2022-09-26T03:58:43
| 21,368,370
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 656
|
cc
|
ds.cc
|
#include <stack>
#include <queue>
#include <iostream>
#include <string>
using namespace std;
int main() {
stack<string> s;
s.push(string("this is a stack"));
s.push(string("one"));
s.push(string("two"));
cout << "Popping off stack...\n";
while (!s.empty()) {
cout << s.top() << "\n";
s.pop();
}
queue<int> q;
for (int i = -1; i < 10; ++i) q.push(i);
cout << "Queue front, first value entered in queue = " << q.front() << '\n';
cout << "Queue back, last value entered in queue = " << q.back() << '\n';
cout << "Popping off queue...\n";
while (!q.empty()) {
cout << q.front() << "\n";
q.pop();
}
return 0;
}
|
e871b30127790c20320558d06688364ba845e5c6
|
9071731d1cf5d6d509adb8f5d1e4027075127a2c
|
/handler.cpp
|
ba5e60f6b0dc1cfb050646487969b3a6dad59b09
|
[] |
no_license
|
haowenCS/daataabaase
|
f2b9e2d377f77af5a306a8a524d483b428a5f4fc
|
d16c0252f9f2c6d8c35598971cc3600afa30450c
|
refs/heads/master
| 2023-03-15T13:56:05.481118
| 2019-11-10T05:20:38
| 2019-11-10T05:20:38
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 56,575
|
cpp
|
handler.cpp
|
//
// handler.cpp
//
//
// Created by 赖金霖 on 2018/12/27.
//
#include "handler.h"
#include "bufmanager/BufPageManager.h"
#include "fileio/FileManager.h"
#include "utils/pagedef.h"
#include "RecordManager.h"
#include "BPlusTree.h"
std::string database;
RecordManager* rm;
FileManager* fileManager;
BufPageManager* bufPageManager;
std::string getdatabase(){
return database;
}
struct table{
int place,fileid;
std::string name;
};
std::vector<table> globaltables;
bool doOperation(Value v1,int op,Value v2){
if(v1.type==Value::_NULL||v2.type==Value::_NULL)return true;
if(v1.type==Value::_STRING){
if(op==WhereItem::_EQUAL)return v1.stringValue==v2.stringValue;
if(op==WhereItem::_NOT_EQUAL)return v1.stringValue!=v2.stringValue;
if(op==WhereItem::_LESS_OR_EQUAL)return v1.stringValue<=v2.stringValue;
if(op==WhereItem::_MORE_OR_EQUAL)return v1.stringValue>=v2.stringValue;
if(op==WhereItem::_LESS)return v1.stringValue<v2.stringValue;
if(op==WhereItem::_MORE)return v1.stringValue>v2.stringValue;
return false;
}
if(v1.type==Value::_DATE){
if(op==WhereItem::_EQUAL)return v1.dateValue==v2.dateValue;
if(op==WhereItem::_NOT_EQUAL)return v1.dateValue!=v2.dateValue;
if(op==WhereItem::_LESS_OR_EQUAL)return v1.dateValue<=v2.dateValue;
if(op==WhereItem::_MORE_OR_EQUAL)return v1.dateValue>=v2.dateValue;
if(op==WhereItem::_LESS)return v1.dateValue<v2.dateValue;
if(op==WhereItem::_MORE)return v1.dateValue>v2.dateValue;
return false;
}
if(v1.type==Value::_INT&&v2.type==Value::_INT){
//printf("recognized!\n");
if(op==WhereItem::_EQUAL)return v1.intValue==v2.intValue;
if(op==WhereItem::_NOT_EQUAL)return v1.intValue!=v2.intValue;
if(op==WhereItem::_LESS_OR_EQUAL)return v1.intValue<=v2.intValue;
if(op==WhereItem::_MORE_OR_EQUAL)return v1.intValue>=v2.intValue;
if(op==WhereItem::_LESS)return v1.intValue<v2.intValue;
if(op==WhereItem::_MORE)return v1.intValue>v2.intValue;
return false;
}
if(v1.type==Value::_INT&&v2.type==Value::_FLOAT){
if(op==WhereItem::_EQUAL)return v1.intValue==v2.floatValue;
if(op==WhereItem::_NOT_EQUAL)return v1.intValue!=v2.floatValue;
if(op==WhereItem::_LESS_OR_EQUAL)return v1.intValue<=v2.floatValue;
if(op==WhereItem::_MORE_OR_EQUAL)return v1.intValue>=v2.floatValue;
if(op==WhereItem::_LESS)return v1.intValue<v2.floatValue;
if(op==WhereItem::_MORE)return v1.intValue>v2.floatValue;
return false;
}
if(v1.type==Value::_FLOAT&&v2.type==Value::_INT){
if(op==WhereItem::_EQUAL)return v1.floatValue==v2.intValue;
if(op==WhereItem::_NOT_EQUAL)return v1.floatValue!=v2.intValue;
if(op==WhereItem::_LESS_OR_EQUAL)return v1.floatValue<=v2.intValue;
if(op==WhereItem::_MORE_OR_EQUAL)return v1.floatValue>=v2.intValue;
if(op==WhereItem::_LESS)return v1.floatValue<v2.intValue;
if(op==WhereItem::_MORE)return v1.floatValue>v2.intValue;
return false;
}
if(v1.type==Value::_FLOAT&&v2.type==Value::_FLOAT){
if(op==WhereItem::_EQUAL)return v1.floatValue==v2.floatValue;
if(op==WhereItem::_NOT_EQUAL)return v1.floatValue!=v2.floatValue;
if(op==WhereItem::_LESS_OR_EQUAL)return v1.floatValue<=v2.floatValue;
if(op==WhereItem::_MORE_OR_EQUAL)return v1.floatValue>=v2.floatValue;
if(op==WhereItem::_LESS)return v1.floatValue<v2.floatValue;
if(op==WhereItem::_MORE)return v1.floatValue>v2.floatValue;
return false;
}
return false;
}
int getSizeLength(Type type){
if(type.typeId==Type::_FLOAT)return 4;
if(type.typeId==Type::_DATE)return 4;
if(type.typeId==Type::_INT)return 4;
if(type.typeId==Type::_CHAR)return 4+(type.len+2)/4*4;
return 0;
}
void printValue(Value value){
std::string toprint;
std::ostringstream oss;
if(value.type==Value::_INT){
oss<<value.intValue;
}
if(value.type==Value::_STRING){
oss<<value.stringValue;
}
if(value.type==Value::_NULL){
oss<<"NULL";
}
if(value.type==Value::_FLOAT){
oss<<value.floatValue;
}
if(value.type==Value::_DATE){
oss<<value.dateValue/10000<<"-"<<value.dateValue%10000/100<<"-"<<value.dateValue%100;
}
toprint=oss.str();
if(toprint.length()>20){
toprint.erase(0,toprint.length()-17);
toprint="..."+toprint;
}
while(toprint.length()<20)
toprint=toprint+" ";
printf("%s",toprint.c_str());
}
union val{
unsigned int i;
float f;
};
Value extractValue(const char* record,int left,int right,Type type){
Value ret;
bool isnull=true;
for(int i=left;i<right;i++)
if(record[i]!=-1){
isnull=false;
break;
}
if(isnull){
ret.type=Value::_NULL;
return ret;
}
val unionvalue;
unionvalue.i=0;
for(int i=left+3;i>=left;i--)
unionvalue.i=unionvalue.i*256+(unsigned char)record[i];
if(type.typeId==Type::_FLOAT){
//printf("Getting float %d\n",unionvalue.i);
ret.type=Value::_FLOAT;
ret.floatValue=unionvalue.f;
}
if(type.typeId==Type::_INT){
//printf("Getting int %d\n",unionvalue.i);
ret.type=Value::_INT;
ret.intValue=unionvalue.i;
}
if(type.typeId==Type::_CHAR){
ret.type=Value::_STRING;
char* ch=new char[record[left]+1];
//printf("charlen:%d\n",record[left]);
memcpy(ch,record+left+1,record[left]);
ch[record[left]]='\0';
ret.stringValue=ch;
}
if(type.typeId==Type::_DATE){
ret.type=Value::_DATE;
ret.dateValue=unionvalue.i;
}
return ret;
}
std::string getTypeName(int typeId,int len){
if(typeId==Type::_FLOAT)return "FLOAT";
if(typeId==Type::_DATE)return "DATE";
char s[20];
if(typeId==Type::_INT){
sprintf(s,"INT(%d)",len);
return s;
}
if(typeId==Type::_CHAR){
sprintf(s,"CHAR(%d)",len);
return s;
}
return "UNKNOWN";
}
void init(){
rm=new RecordManager();
fileManager=rm->getFileManager();
bufPageManager=rm->getBufPageManager();
srand(time(0));
std::string rd;
database.erase();
}
std::vector<Field> getColumns(std::string table){
std::string configfile=database+"/.config";
std::vector<Field> ret;
ret.clear();
for(int i=0;i<globaltables.size();i++){
if(globaltables[i].name==table){
int theIndex;
fileManager->openFile(configfile.c_str(),theIndex);
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,globaltables[i].place,pageIndex);
for(int j=0;j<page0[0];j++){
Field field;
field.colName.erase();
field.reftable.erase();
field.refcolumn.erase();
bool finish=false;
for(int k=4;k<16;k++){
int theInt=page0[1024+64*j+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
field.colName.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
if(page0[1024+64*j+16]){
field.type=Field::foreignkey;
finish=false;
for(int k=20;k<32;k++){
int theInt=page0[1024+64*j+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
field.reftable.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
finish=false;
for(int k=32;k<48;k++){
int theInt=page0[1024+64*j+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
field.refcolumn.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
}else field.type=Field::column;
field.left=page0[1024+64*j+17];
field.right=page0[1024+64*j+18];
field.isprimarykey=(page0[1024+64*j+3]==1);
field.Nullable=(page0[1024+64*j+2]==1);
field.thetype.typeId=page0[1024+64*j];
field.thetype.len=page0[1024+64*j+1];
ret.push_back(field);
}
bufPageManager->release(pageIndex);
fileManager->closeFile(theIndex);
}
}
return ret;
}
bool getColumn(std::string table,std::string column,Field& field){
std::string configfile=database+"/.config";
bool found=false;
for(int i=0;i<globaltables.size();i++){
if(globaltables[i].name==table){
int theIndex;
fileManager->openFile(configfile.c_str(),theIndex);
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,globaltables[i].place,pageIndex);
for(int j=0;j<page0[0];j++){
field.colName.erase();
field.reftable.erase();
field.refcolumn.erase();
bool finish=false;
for(int k=4;k<16;k++){
int theInt=page0[1024+64*j+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
field.colName.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
if(field.colName!=column)continue;
found=true;
if(page0[1024+64*j+16]){
field.type=Field::foreignkey;
finish=false;
for(int k=20;k<32;k++){
int theInt=page0[1024+64*j+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
field.reftable.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
finish=false;
for(int k=32;k<48;k++){
int theInt=page0[1024+64*j+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
field.refcolumn.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
}else field.type=Field::column;
field.left=page0[1024+64*j+17];
field.right=page0[1024+64*j+18];
field.isprimarykey=(page0[1024+64*j+3]==1);
field.Nullable=(page0[1024+64*j+2]==1);
field.thetype.typeId=page0[1024+64*j];
field.thetype.len=page0[1024+64*j+1];
}
bufPageManager->release(pageIndex);
fileManager->closeFile(theIndex);
}
}
if(found==false){
printf("No such table or column!\n");
}
return found;
}
void Handler::accept(){
}
void checkglobalconfig(){
FILE* file;
if((file=fopen(".config","rb"))==NULL){
fileManager->createFile(".config");
int theIndex;
fileManager->openFile(".config",theIndex);
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,0,pageIndex);
bufPageManager->markDirty(pageIndex);
page0[0]=0;
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
}else fclose(file);
}
void ShowDatabases::accept(){
checkglobalconfig();
int theIndex;
fileManager->openFile(".config",theIndex);
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,0,pageIndex);
bufPageManager->markDirty(pageIndex);
printf("%d\n",page0[0]);
for(int i=0;i<page0[0];i++){
std::string name;
name.erase();
bool finish=false;
for(int k=0;k<8;k++){
int theInt=page0[256+16*i+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
name.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
printf("%s\n",name.c_str());
}
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
}
void CreateDatabase::accept(){
checkglobalconfig();
if(dbname.length()>32){
printf("Too long database name\n");
return;
}
int theIndex;
fileManager->openFile(".config",theIndex);
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,0,pageIndex);
bufPageManager->markDirty(pageIndex);
page0[0]++;
for(int j=0;j<dbname.length()+4;j++){
if(j%4==3){
int toins=0;
for(int k=0;k<4;k++)
toins=toins*256+(j-k<dbname.length()?dbname[j-k]:0);
page0[(page0[0]-1)*16+256+j/4]=toins;
}
}
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
std::string command = "mkdir -p " + dbname;
system(command.c_str());
std::string configfile=dbname + "/.config";
fileManager->createFile(configfile.c_str());
fileManager->openFile(configfile.c_str(),theIndex);
page0=bufPageManager->getPage(theIndex,0,pageIndex);
bufPageManager->markDirty(pageIndex);
page0[0]=0;
page0[1]=1;
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
}
void DropDatabase::accept(){
checkglobalconfig();
int theIndex;
fileManager->openFile(".config",theIndex);
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,0,pageIndex);
bufPageManager->markDirty(pageIndex);
bool found=false;
for(int i=0;i<page0[0];i++){
std::string name;
name.erase();
bool finish=false;
for(int k=0;k<8;k++){
int theInt=page0[256+16*i+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
name.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
if(name==dbname){
found=true;
memcpy(page0+256+i*16,page0+256+(page0[0]-1)*16,16);
break;
}
}
if(dbname==database){
printf("Cannot delete the database in use!\n");
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
return;
}
if(found==false){
printf("No such database!\n");
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
return;
}
page0[0]--;
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
std::string command = "rm -r " + dbname;
system(command.c_str());
}
void UseDatabase::accept(){
checkglobalconfig();
std::string configfile=dbname + "/.config";
int theIndex;
if(!fileManager->openFile(configfile.c_str(),theIndex)){
printf("No such database!\n");
return;
}
//printf("%d\n",theIndex);
if(database.length()){
for(int i=0;i<globaltables.size();i++){
rm->closeFile(globaltables[i].fileid);
}
}
globaltables.clear();
database=dbname;
printf("Switched to database %s\n",database.c_str());
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,0,pageIndex);
// printf("%d\n",page0[0]);
for(int i=0;i<page0[0];i++){
table tb;
tb.place=page0[i*64+64];
bool finish=false;
tb.name.erase();
for(int j=1;j<64;j++){
int theInt=page0[i*64+64+j];
for(int k=0;k<4;k++){
if(theInt%256==0){
finish=true;
break;
}
tb.name.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
std::string thename=database+"/"+tb.name;
//printf("%s\n",thename.c_str());
tb.fileid=rm->openFile(thename.c_str());
//printf("%d\n",tb.fileid);
globaltables.push_back(tb);
}
bufPageManager->release(pageIndex);
fileManager->closeFile(theIndex);
}
void ShowTables::accept(){
for(int i=0;i<globaltables.size();i++)
printf("%s\n",globaltables[i].name.c_str());
}
bool sametype(Type t1,Type t2){
if(t1.typeId!=t2.typeId)return false;
if(t1.typeId==Type::_DATE||t1.typeId==Type::_FLOAT)return true;
return t1.len==t2.len;
}
void CreateTable::accept(){
for(int i=0;i<globaltables.size();i++)
if(tbname==globaltables[i].name){
printf("Repeated table name!\n");
return;
}
std::string configfile=database + "/.config";
int theIndex;
fileManager->openFile(configfile.c_str(),theIndex);
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,0,pageIndex);
bufPageManager->markDirty(pageIndex);
for(int j=0;j<fields.size();j++){
fields[j].isprimarykey=false;
if(fields[j].type!=Field::primarykey&&fields[j].colName.length()>32){
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
printf("Column name too long!\n");
return;
}
for(int i=j+1;i<fields.size();i++)
if(fields[j].type==Field::column&&fields[i].type==Field::column&&fields[j].colName==fields[i].colName){
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
printf("Repeated column name!\n");
return;
}
}
int columncnt=fields.size();
for(int i=0;i<fields.size();i++){
if(fields[i].type==Field::primarykey){
columncnt--;
for(int j=0;j<fields[i].columns.size();j++)
for(int k=j+1;k<fields[i].columns.size();k++)
if(fields[i].columns[j]==fields[i].columns[k]){
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
printf("Repeated primary keys!\n");
return;
}
for(int j=0;j<fields[i].columns.size();j++){
bool found=false;
for(int k=0;k<fields.size();k++)
if(fields[k].type==Field::column&&fields[k].colName==fields[i].columns[j]){
found=true;
fields[k].isprimarykey=true;
break;
}
if(!found){
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
printf("Invalid primary key!\n");
return;
}
}
fields[i].type=Field::skip;
}else if(fields[i].type==Field::foreignkey){
columncnt--;
bool found=false;
int j;
for(j=0;j<i;j++)
if(fields[j].type==Field::column&&fields[i].colName==fields[j].colName){
found=true;
break;
}
if(!found){
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
printf("Invalid foreign key!\n");
return;
}
Field foreigncolumn;
if(getColumn(fields[i].reftable,fields[i].refcolumn,foreigncolumn)){
if(!foreigncolumn.isprimarykey){
printf("Foreign key is not primary key!\n");
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
return;
}
if(!sametype(foreigncolumn.thetype,fields[j].thetype)){
printf("Incompatible foreign key type!\n");
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
return;
}
fields[j].type=fields[i].type;
fields[j].reftable=fields[i].reftable;
fields[j].refcolumn=fields[i].refcolumn;
fields[i].type=Field::skip;
}else{
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
printf("Invalid foreign key!\n");
return;
}
}
}
if(page0[0]==16){
printf("Too many tables!\n");
}else{
table tb;
tb.name=tbname;
tb.place=page0[0]+1;
std::string sqlfile=database+"/"+tbname;
//printf("%d\n",recordLength);
page0[64*(globaltables.size()+1)]=tb.place;
for(int i=0;i<tbname.length()+4;i++){
if(i%4==3){
int toins=0;
for(int k=0;k<4;k++)
toins=toins*256+(i-k<tbname.length()?tbname[i-k]:0);
page0[(1+globaltables.size())*64+1+i/4]=toins;
}
}
int pageIndex;
if(page0[0]+1>=page0[1]){
BufType page1=bufPageManager->allocPage(theIndex,page0[1],pageIndex);
page0[1]++;
bufPageManager->markDirty(pageIndex);
bufPageManager->writeBack(pageIndex);
}
BufType page1=bufPageManager->getPage(theIndex,page0[0]+1,pageIndex);
bufPageManager->markDirty(pageIndex);
page0[0]++;
page1[0]=columncnt;
int recordLength=0;
for(int i=0;i<fields.size();i++)
if(fields[i].type!=Field::skip){
int columnLength=getSizeLength(fields[i].thetype);
page1[i*64+1024+17]=recordLength;
recordLength+=getSizeLength(fields[i].thetype);
page1[i*64+1024+18]=recordLength;
//printf("%d\n",i);
page1[i*64+1024]=fields[i].thetype.typeId;
page1[i*64+1024+1]=fields[i].thetype.len;
page1[i*64+1024+2]=int(fields[i].Nullable);
page1[i*64+1024+3]=int(fields[i].isprimarykey);
for(int j=0;j<fields[i].colName.length()+4;j++){
//printf("%d\n",j);
if(j%4==3){
int toins=0;
for(int k=0;k<4;k++)
toins=toins*256+(j-k<fields[i].colName.length()?fields[i].colName[j-k]:0);
page1[i*64+1024+4+j/4]=toins;
}
}
page1[i*64+1024+16]=int(fields[i].type==Field::foreignkey);
if(fields[i].type==Field::foreignkey){
for(int j=0;j<fields[i].reftable.length()+4;j++){
if(j%4==3){
int toins=0;
for(int k=0;k<4;k++)
toins=toins*256+(j-k<fields[i].reftable.length()?fields[i].reftable[j-k]:0);
page1[i*64+1024+20+j/4]=toins;
}
}
for(int j=0;j<fields[i].refcolumn.length()+4;j++){
if(j%4==3){
int toins=0;
for(int k=0;k<4;k++)
toins=toins*256+(j-k<fields[i].refcolumn.length()?fields[i].refcolumn[j-k]:0);
page1[i*64+1024+32+j/4]=toins;
}
}
}
}
bufPageManager->writeBack(pageIndex);
rm->createFile(sqlfile.c_str(),recordLength);
tb.fileid=rm->openFile(sqlfile.c_str());
globaltables.push_back(tb);
}
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
}
void DropTable::accept(){
bool found=false;
for(int i=0;i<globaltables.size();i++){
if(globaltables[i].name==tbname){
found=true;
std::string configfile=database + "/.config";
int theIndex;
fileManager->openFile(configfile.c_str(),theIndex);
//printf("%s %d\n",configfile.c_str(),theIndex);
int pageIndex,pageIndex1,pageIndex2;
BufType page00=bufPageManager->getPage(theIndex,0,pageIndex);
//printf("%d %d\n",page00[0],page00[1]);
bufPageManager->markDirty(pageIndex);
BufType page0=bufPageManager->getPage(theIndex,globaltables[i].place,pageIndex1);
//printf("%d %d\n",page0[0],page0[1]);
bufPageManager->markDirty(pageIndex1);
BufType page1=bufPageManager->getPage(theIndex,globaltables[globaltables.size()-1].place,pageIndex2);
//printf("%d %d\n",page1[0],page1[1]);
bufPageManager->markDirty(pageIndex2);
page00[64*globaltables.size()]=page00[64*(i+1)];
//printf("%d %d\n",64*globaltables.size(),64*(i+1));
memcpy(page0,page1,PAGE_SIZE);
memcpy(page00+64+i*64,page00+64+(globaltables.size()-1)*64,64);
//printf("%d\n",globaltables[i].fileid);
page00[0]--;
//printf("%d %d\n",page00[0],page00[1]);
bufPageManager->writeBack(pageIndex1);
bufPageManager->writeBack(pageIndex);
bufPageManager->release(pageIndex2);
fileManager->closeFile(theIndex);
globaltables[globaltables.size()-1].place=globaltables[i].place;
rm->closeFile(globaltables[i].fileid);
globaltables[i]=globaltables[globaltables.size()-1];
globaltables.pop_back();
break;
}
}
if(found==false){
printf("No such table!\n");
}
}
void DescTable::accept(){
std::string configfile=database + "/.config";
std::vector<Field> columns=getColumns(tbname);
for(int i=0;i<columns.size();i++){
printf("%s %s %s %s %s %s %s\n",columns[i].colName.c_str(),getTypeName(columns[i].thetype.typeId,columns[i].thetype.len).c_str(),
columns[i].Nullable?"NULLABLE":"",columns[i].isprimarykey?"PRIMARY_KEY":"",columns[i].type==Field::foreignkey?"FOREIGN_KEY":"",columns[i].type==Field::foreignkey?columns[i].reftable.c_str():"",columns[i].type==Field::foreignkey?columns[i].refcolumn.c_str():"");
}
}
bool canassign(int type,int valuetype){
if(valuetype==Value::_NULL)return true;
if(type==Type::_FLOAT&&valuetype==Value::_FLOAT)return true;
if(type==Type::_FLOAT&&valuetype==Value::_INT)return true;
if(type==Type::_INT&&valuetype==Value::_INT)return true;
if(type==Type::_CHAR&&valuetype==Value::_STRING)return true;
if(type==Type::_DATE&&valuetype==Value::_DATE)return true;
if(type==Type::_DATE&&valuetype==Value::_STRING)return true;
return false;
}
bool cancompare(int type,int type2){
if(type==Type::_FLOAT&&type2==Type::_FLOAT)return true;
if(type==Type::_FLOAT&&type2==Type::_INT)return true;
if(type==Type::_INT&&type2==Type::_FLOAT)return true;
if(type==Type::_INT&&type2==Type::_INT)return true;
if(type==Type::_CHAR&&type2==Type::_CHAR)return true;
if(type==Type::_DATE&&type2==Type::_DATE)return true;
return false;
}
bool dateerror;
const int datemonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool validdate(int date){
int y=date/10000,m=date/100%100,d=date%100;
if(y<0)return false;
if(m<1||m>12)return false;
if(y%4==0&&y%100!=0||y%400==0){
if(m==2&&d==29)return true;
}
return d>0&&d<=datemonth[m];
}
int parseDate(std::string st){
dateerror=false;
int ret=0;
if(st.length()<12){
dateerror=true;
return -1;
}
for(int i=1;i<11;i++){
if(i==5||i==8)continue;
ret=ret*10;
ret+=st[i]-'0';
}
if(!validdate(ret))dateerror=true;
//printf("%d\n",dateerror);
return ret;
}
char* Value::toString(Type type){
//printf("type:%d %d\n",this->type,type.typeId);
int len=getSizeLength(type);
char* ret=new char[len];
if(this->type==_NULL){
memset(ret,255,len);
return ret;
}
if(type.typeId==Type::_FLOAT){
float fl=(this->type==_FLOAT)?floatValue:intValue;
//printf("%d %f\n",len,fl);
memcpy(ret,&fl,len);
}
if(type.typeId==Type::_DATE){
if(this->type==_STRING){
//printf("parsing date\n");
dateValue=parseDate(stringValue);
}
memcpy(ret,&dateValue,len);
}
if(type.typeId==Type::_INT){
memcpy(ret,&intValue,len);
}
if(type.typeId==Type::_CHAR){
ret[0]=stringValue.length();
memcpy(ret+1,stringValue.c_str(),ret[0]);
}
return ret;
}
int Value::toInt(Type type){
int ret=0;
if(this->type==_NULL)return -1;
if(type.typeId==Type::_FLOAT){
float fl=(this->type==_FLOAT)?floatValue:intValue;
//printf("%d %f\n",len,fl);
memcpy(&ret,&fl,4);
}
if(type.typeId==Type::_DATE){
if(this->type==_STRING){
dateValue=parseDate(stringValue);
}
return dateValue;
}
if(type.typeId==Type::_INT){
return intValue;
}
return ret;
}
void InsertValue::accept(){
printf("Begin insert\n");
bool found=false;
for(int i=0;i<globaltables.size();i++){
if(globaltables[i].name==tbname){
found=true;
std::string configfile=database + "/.config";
int theIndex;
fileManager->openFile(configfile.c_str(),theIndex);
int pageIndex;
BufType page0=bufPageManager->getPage(theIndex,globaltables[i].place,pageIndex);
for(int j=0;j<values.size();j++)
if(values[j].size()!=page0[0]){
printf("Incompatible value list!\n");
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
return;
}
for(int j=0;j<page0[0];j++){
printf("Checking column %d\n",j);
for(int k=0;k<values.size();k++){
if((page0[j*64+1024+2]==0&&values[k][j].type==Value::_NULL)||!canassign(page0[j*64+1024],values[k][j].type)){
printf("Incompatible value list!\n");
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
return;
}
}
if(page0[64*j+1024+16]!=0){
std::string reftable;
std::string refcolumn;
reftable.erase();
refcolumn.erase();
bool finish=false;
for(int k=20;k<32;k++){
int theInt=page0[1024+64*j+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
reftable.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
finish=false;
for(int k=32;k<48;k++){
int theInt=page0[1024+64*j+k];
for(int l=0;l<4;l++){
if(theInt%256==0){
finish=true;
break;
}
refcolumn.append(1,char(theInt%256));
theInt/=256;
}
if(finish)break;
}
// printf("%s %s\n",reftable.c_str(),refcolumn.c_str());
//INSERT INTO `orders` VALUES (100001,301743,260874,'2017-09-14',5);
Field foreigncolumn;
if(!getColumn(reftable,refcolumn,foreigncolumn)){
bufPageManager->writeBack(pageIndex);
fileManager->closeFile(theIndex);
printf("Invalid foreign key! case 1\n");
return;
}
std::string foreignfile=database+"/"+tbname;
int ref=-1;
for(int k=0;k<globaltables.size();k++)
if(globaltables[k].name==reftable){
ref=globaltables[k].fileid;
//printf("%d %d\n",k,ref);
break;
}
if(ref==-1){
printf("Unfound foreign key(maybe an internal error)!\n");
bufPageManager->release(pageIndex);
fileManager->closeFile(theIndex);
return;
}
for(int k=0;k<values.size();k++){
Type type;
type.typeId=page0[j*64+1024];
type.len=page0[j*64+1024+1];
std::vector<char*> ret;
int toint=values[k][j].toInt(type);
if(foreigncolumn.right-foreigncolumn.left==4&&rm->hasIndex(ref,foreigncolumn.left/4+1))
ret=rm->findbyIndex(ref,foreigncolumn.left/4+1,toint,toint+1);
else ret=rm->filterRecord(ref,foreigncolumn.left,foreigncolumn.right,values[k][j].toString(type),new EqualFilter());
if(ret.size()==0){
printf("Invalid foreign key!\n");
bufPageManager->release(pageIndex);
fileManager->closeFile(theIndex);
return;
}
}
}
if(page0[64*j+1024+3]!=0){
int ref=globaltables[i].fileid;
for(int k=0;k<values.size();k++){
Type type;
type.typeId=page0[j*64+1024];
type.len=page0[j*64+1024+1];
std::vector<char*> ret;
int toint=values[k][j].toInt(type);
if(page0[64*j+1024+18]-page0[64*j+1024+17]==4&&rm->hasIndex(ref,page0[64*j+1024+17]/4+1))
ret=rm->findbyIndex(ref,page0[64*j+1024+17]/4+1,toint,toint+1);
else ret=rm->filterRecord(ref,page0[64*j+1024+17],page0[64*j+1024+18],values[k][j].toString(type),new EqualFilter());
if(ret.size()!=0){
printf("Repeated primary key!\n");
bufPageManager->release(pageIndex);
fileManager->closeFile(theIndex);
return;
}
}
}
}
printf("Checked up\n");
std::string thisfile=database+"/"+tbname;
int ref=globaltables[i].fileid;
int len=rm->getRecordLength(ref);
for(int j=0;j<values.size();j++){
char* rc=new char[len];
//rc[len]='\0';
for(int k=0;k<page0[0];k++){
Type type;
type.typeId=page0[k*64+1024];
type.len=page0[k*64+1024+1];
char* tos=values[j][k].toString(type);
//printf("%d %d\n",j,k);
if(dateerror){
printf("INVALID DATE\n");
dateerror=false;
bufPageManager->release(pageIndex);
fileManager->closeFile(theIndex);
rm->saveFile(globaltables[i].fileid);
return;
}
memcpy(rc+page0[k*64+1024+17],values[j][k].toString(type),page0[k*64+1024+18]-page0[k*64+1024+17]);
}
//for(int k=0;k<len;k++)
//printf("value %d : %d\n",k,rc[k]);
rm->insertRecord(ref,rc);
}
bufPageManager->release(pageIndex);
fileManager->closeFile(theIndex);
rm->saveFile(globaltables[i].fileid);
}
}
if(found==false){
printf("No such table!\n");
}else {
printf("Inserted!\n");
}
}
void DeleteValues::accept(){
uint lower=0,upper=-1,index=-1;
for(int i=0;i<wheres.size();i++){
if((wheres[i].left.hastable&&wheres[i].left.table!=tbname)||(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::COL&&wheres[i].expr.column.hastable&&wheres[i].expr.column.table!=tbname)){
printf("Invalid column!\n");
return;
}
Field field;
if(!getColumn(tbname,wheres[i].left.column,field)){
printf("Unfound column!\n");
return;
}
wheres[i].left.left=field.left;
wheres[i].left.right=field.right;
wheres[i].left.type=field.thetype;
if(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::COL){
if(!getColumn(tbname,wheres[i].expr.column.column,field)){
printf("Unfound column!\n");
return;
}
wheres[i].expr.column.left=field.left;
wheres[i].expr.column.right=field.right;
wheres[i].expr.column.type=field.thetype;
if(!cancompare(wheres[i].left.type.typeId,field.thetype.typeId)){
printf("Invalid operation!\n");
return;
}
}else if(wheres[i].type==WhereItem::OPERATION&&!canassign(field.thetype.typeId,wheres[i].expr.value.type)){
printf("Invalid operation!\n");
return;
}
if(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::VALUE&&wheres[i].Operator!=WhereItem::_NOT_EQUAL){
int val=wheres[i].expr.value.toInt(wheres[i].left.type);
index=wheres[i].left.left/4+1;
if(wheres[i].Operator==WhereItem::_EQUAL){
lower=val;
upper=val+1;
}
if(wheres[i].Operator==WhereItem::_LESS_OR_EQUAL){
lower=0;
upper=val+1;
}
if(wheres[i].Operator==WhereItem::_MORE_OR_EQUAL){
lower=val;
upper=-1;
}
if(wheres[i].Operator==WhereItem::_LESS){
lower=0;
upper=val;
}
if(wheres[i].Operator==WhereItem::_MORE){
lower=val+1;
upper=-1;
}
}
}
int ref=-1;
for(int j=0;j<globaltables.size();j++){
if(tbname==globaltables[j].name)ref=globaltables[j].fileid;
}
if(ref==-1){
printf("Unknown table!\n");
return;
}
printf("Deleted:\n");
int len=rm->getRecordLength(ref);
std::vector<int> todelete;
todelete.clear();
//printf("%d\n",len);
std::vector<char*> gt;
if((int)index!=-1&&rm->hasIndex(ref,index))gt=rm->findbyIndex(ref,index,lower,upper);
else gt=rm->filterRecord(ref,0,0,NULL,new TransparentFilter());
for(int i=0;i<gt.size();i++){
bool valid=true;
for(int j=0;j<wheres.size();j++){
//printf("%d\n",wheres[i].type);
if(wheres[j].type==WhereItem::OPERATION){
//printf("Checking operation\n");
int place=wheres[j].left.place;
Value left=extractValue(gt[i],wheres[j].left.left+4,wheres[j].left.right+4,wheres[j].left.type);
Value right=wheres[j].expr.value;
if(wheres[j].expr.type==Expr::COL){
right=extractValue(gt[i],wheres[j].expr.column.left+4,wheres[j].expr.column.right+4,wheres[j].expr.column.type);
}
if(!doOperation(left,wheres[j].Operator,right)){
valid=false;
break;
}
}
if(wheres[j].type==WhereItem::ISNULL){
int place=wheres[j].left.place;
Value left=extractValue(gt[i],wheres[j].left.left+4,wheres[j].left.right+4,wheres[j].left.type);
if(left.type!=Value::_NULL){
valid=false;
break;
}
}
if(wheres[j].type==WhereItem::ISNOTNULL){
int place=wheres[j].left.place;
Value left=extractValue(gt[i],wheres[j].left.left+4,wheres[j].left.right+4,wheres[j].left.type);
if(left.type==Value::_NULL){
valid=false;
break;
}
}
}
if(valid){
printf("%d\n",rm->parseIndex(gt[i]));
todelete.push_back(rm->parseIndex(gt[i]));
}
}
for(int i=0;i<todelete.size();i++)
rm->deleteRecord(ref,todelete[i]);
rm->saveFile(ref);
}
void UpdateValues::accept(){
uint lower=0,upper=-1,index=-1;
int ref=-1;
for(int j=0;j<globaltables.size();j++){
if(tbname==globaltables[j].name)ref=globaltables[j].fileid;
}
if(ref==-1){
printf("Unknown table!\n");
return;
}
for(int i=0;i<wheres.size();i++){
if((wheres[i].left.hastable&&wheres[i].left.table!=tbname)||(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::COL&&wheres[i].expr.column.hastable&&wheres[i].expr.column.table!=tbname)){
printf("Invalid column!\n");
return;
}
Field field;
if(!getColumn(tbname,wheres[i].left.column,field)){
printf("Unfound column!\n");
return;
}
wheres[i].left.left=field.left;
wheres[i].left.right=field.right;
wheres[i].left.type=field.thetype;
if(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::COL){
if(!getColumn(tbname,wheres[i].expr.column.column,field)){
printf("Unfound column!\n");
return;
}
wheres[i].expr.column.left=field.left;
wheres[i].expr.column.right=field.right;
wheres[i].expr.column.type=field.thetype;
if(!cancompare(wheres[i].left.type.typeId,field.thetype.typeId)){
printf("Invalid operation!\n");
return;
}
}else if(wheres[i].type==WhereItem::OPERATION&&!canassign(field.thetype.typeId,wheres[i].expr.value.type)){
printf("Invalid operation!\n");
return;
}
if(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::VALUE&&wheres[i].Operator!=WhereItem::_NOT_EQUAL){
int val=wheres[i].expr.value.toInt(wheres[i].left.type);
index=wheres[i].left.left/4+1;
if(wheres[i].Operator==WhereItem::_EQUAL){
lower=val;
upper=val+1;
}
if(wheres[i].Operator==WhereItem::_LESS_OR_EQUAL){
lower=0;
upper=val+1;
}
if(wheres[i].Operator==WhereItem::_MORE_OR_EQUAL){
lower=val;
upper=-1;
}
if(wheres[i].Operator==WhereItem::_LESS){
lower=0;
upper=val;
}
if(wheres[i].Operator==WhereItem::_MORE){
lower=val+1;
upper=-1;
}
}
}
bool affectprimarykey=false;
for(int i=0;i<sets.size();i++){
Field field;
if(!getColumn(tbname,sets[i].column,field)){
printf("Unfound column in setclause!\n");
return;
}
sets[i].left=field.left;
sets[i].right=field.right;
sets[i].type=field.thetype;
if(!canassign(field.thetype.typeId,sets[i].value.type)){
printf("Invalid operation!\n");
return;
}
if(field.type==Field::foreignkey){
int foundref=-1;
for(int j=0;j<globaltables.size();j++){
if(globaltables[j].name==field.reftable){
foundref=globaltables[j].fileid;
break;
}
}
if(foundref==-1){
printf("Internal error!\n");
return;
}
Field f2;
if(!getColumn(field.reftable,field.refcolumn,f2)){
printf("Internal error!\n");
return;
}
std::vector<char*> ret;
int toint=sets[i].value.toInt(sets[i].type);
if(f2.right-f2.left==4&&rm->hasIndex(foundref,f2.left/4+1))
ret=rm->findbyIndex(ref,f2.left/4+1,toint,toint+1);
else ret=rm->filterRecord(foundref,f2.left,f2.right,sets[i].value.toString(sets[i].type),new EqualFilter());
if(ret.size()==0){
printf("Unfound primary key!\n");
return;
}
}
if(field.isprimarykey){
affectprimarykey=true;
std::vector<char*> ret;
int toint=sets[i].value.toInt(sets[i].type);
if(field.right-field.left==4&&rm->hasIndex(ref,field.left/4+1))
ret=rm->findbyIndex(ref,field.left/4+1,toint,toint+1);
else ret=rm->filterRecord(ref,field.left,field.right,sets[i].value.toString(sets[i].type),new EqualFilter());
if(ret.size()>0){
printf("Repeated primary key!\n");
return;
}
}
}
int len=rm->getRecordLength(ref);
std::vector<int> toupdate;
toupdate.clear();
std::vector<char*> torenew;
torenew.clear();
//printf("%d\n",len);
std::vector<char*> gt;
if((int)index!=-1&&rm->hasIndex(ref,index))gt=rm->findbyIndex(ref,index,lower,upper);
else gt=rm->filterRecord(ref,0,0,NULL,new TransparentFilter());
for(int i=0;i<gt.size();i++){
bool valid=true;
for(int j=0;j<wheres.size();j++){
//printf("%d\n",wheres[i].type);
if(wheres[j].type==WhereItem::OPERATION){
//printf("Checking operation\n");
int place=wheres[j].left.place;
Value left=extractValue(gt[i],wheres[j].left.left+4,wheres[j].left.right+4,wheres[j].left.type);
Value right=wheres[j].expr.value;
if(wheres[j].expr.type==Expr::COL){
right=extractValue(gt[i],wheres[j].expr.column.left+4,wheres[j].expr.column.right+4,wheres[j].expr.column.type);
}
if(!doOperation(left,wheres[j].Operator,right)){
valid=false;
break;
}
}
if(wheres[j].type==WhereItem::ISNULL){
int place=wheres[j].left.place;
Value left=extractValue(gt[i],wheres[j].left.left+4,wheres[j].left.right+4,wheres[j].left.type);
if(left.type!=Value::_NULL){
valid=false;
break;
}
}
if(wheres[j].type==WhereItem::ISNOTNULL){
int place=wheres[j].left.place;
Value left=extractValue(gt[i],wheres[j].left.left+4,wheres[j].left.right+4,wheres[j].left.type);
if(left.type==Value::_NULL){
valid=false;
break;
}
}
}
if(valid){
toupdate.push_back(rm->parseIndex(gt[i]));
torenew.push_back(gt[i]);
}
}
if(affectprimarykey&&toupdate.size()>1){
printf("Error: May result in multiple primary key!\n");
return;
}
printf("Renewed:\n");
for(int i=0;i<toupdate.size();i++){
printf("%d\n",toupdate[i]);
for(int j=0;j<sets.size();j++){
char* dt=sets[j].value.toString(sets[j].type);
if(dateerror){
printf("INVALID DATE\n");
dateerror=false;
rm->saveFile(ref);
return;
}
memcpy(torenew[i]+4+sets[j].left,dt,sets[j].right-sets[j].left);
}
rm->renewRecord(ref,toupdate[i],torenew[i]+4);
}
rm->saveFile(ref);
}
void SelectValues::accept(){
printf("selecting..\n");
if(selector.type==Selector::cols){
for(int i=0;i<selector.columns.size();i++){
if(tables.size()==1&&selector.columns[i].hastable==false){
selector.columns[i].hastable=true;
selector.columns[i].table=tables[0];
}
if(selector.columns[i].hastable==false){
printf("Undetermined selector!\n");
return;
}
bool found=false;
for(int j=0;j<tables.size();j++){
if(selector.columns[i].table==tables[j]){
selector.columns[i].place=j;
found=true;
}
}
if(found==false){
printf("Unfound selector column!\n");
return;
}
Field field;
if(!getColumn(selector.columns[i].table,selector.columns[i].column,field)){
printf("Unfound selector column!\n");
return;
}
selector.columns[i].left=field.left;
selector.columns[i].right=field.right;
selector.columns[i].type=field.thetype;
}
}else{
selector.columns.clear();
for(int i=0;i<tables.size();i++){
//printf("%d\n",i);//use dlfjadf;select * from tb1 where a is null;
std::vector<Field> columns=getColumns(tables[i]);
for(int j=0;j<columns.size();j++){
//printf(" %d\n",j);
Column col;
col.hastable=true;
col.table=tables[i];
col.column=columns[j].colName;
col.place=i;
col.left=columns[j].left;
col.right=columns[j].right;
col.type=columns[j].thetype;
selector.columns.push_back(col);
}
}
}
std::vector<uint> lower;
std::vector<uint> upper;
std::vector<uint> index;
lower.clear();
upper.clear();
index.clear();
for(int i=0;i<tables.size();i++){
lower.push_back(0);
upper.push_back(-1);
index.push_back(-1);
}
for(int i=0;i<wheres.size();i++){
if(tables.size()==1){
if(wheres[i].left.hastable==false){
wheres[i].left.hastable=true;
wheres[i].left.table=tables[0];
}
if(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::COL&&wheres[i].expr.column.hastable==false){
wheres[i].expr.column.hastable=true;
wheres[i].expr.column.table=tables[0];
}
}
if(wheres[i].left.hastable==false||(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::COL&&wheres[i].expr.column.hastable==false)){
printf("Undetermined column!\n");
return;
}
Field field;
if(!getColumn(wheres[i].left.table,wheres[i].left.column,field)){
printf("Unfound column!\n");
return;
}
wheres[i].left.left=field.left;
wheres[i].left.right=field.right;
wheres[i].left.type=field.thetype;
if(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::COL){
if(!getColumn(wheres[i].expr.column.table,wheres[i].expr.column.column,field)){
printf("Unfound column!\n");
return;
}
wheres[i].expr.column.left=field.left;
wheres[i].expr.column.right=field.right;
wheres[i].expr.column.type=field.thetype;
if(!cancompare(wheres[i].left.type.typeId,field.thetype.typeId)){
printf("Invalid operation!\n");
return;
}
}else if(wheres[i].type==WhereItem::OPERATION&&!canassign(field.thetype.typeId,wheres[i].expr.value.type)){
printf("Invalid operation!\n");
return;
}
bool found=false,found2=wheres[i].type!=WhereItem::OPERATION||wheres[i].expr.type!=Expr::COL;
for(int j=0;j<tables.size();j++){
if(wheres[i].left.table==tables[j]){
wheres[i].left.place=j;
if(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::VALUE&&wheres[i].Operator!=WhereItem::_NOT_EQUAL){
int val=wheres[i].expr.value.toInt(wheres[i].left.type);
index[j]=wheres[i].left.left/4+1;
if(wheres[i].Operator==WhereItem::_EQUAL){
lower[j]=val;
upper[j]=val+1;
}
if(wheres[i].Operator==WhereItem::_LESS_OR_EQUAL){
lower[j]=0;
upper[j]=val+1;
}
if(wheres[i].Operator==WhereItem::_MORE_OR_EQUAL){
lower[j]=val;
upper[j]=-1;
}
if(wheres[i].Operator==WhereItem::_LESS){
lower[j]=0;
upper[j]=val;
}
if(wheres[i].Operator==WhereItem::_MORE){
lower[j]=val+1;
upper[j]=-1;
}
}
found=true;
}
if(wheres[i].type==WhereItem::OPERATION&&wheres[i].expr.type==Expr::COL&&wheres[i].expr.column.table==tables[j]){
wheres[i].expr.column.place=j;
found2=true;
}
}
if(found==false||found2==false){
printf("Unfound column!\n");
return;
}
}
// printf("finish where pre\n");
unsigned int cnt=0;
std::vector<std::vector<char*> > cols;
std::vector<int> rfs;
rfs.clear();
cols.clear();
std::vector<int> ns;
ns.clear();
std::vector<int> is;
is.clear();
for(int i=0;i<tables.size();i++){
std::string thisfile=database+"/"+tables[i];
//printf("%s\n",thisfile.c_str());
int ref=-1;
for(int j=0;j<globaltables.size();j++){
if(tables[i]==globaltables[j].name)ref=globaltables[j].fileid;
//printf("%s %d\n",globaltables[j].name.c_str(),globaltables[j].fileid);
}
if(ref==-1){
printf("Unknown table!\n");
return;
}
rfs.push_back(ref);
//printf("%s\n",tables[i].c_str());
int len=rm->getRecordLength(ref);
//printf("%d\n",len);
std::vector<char*> gt;
if((int)index[i]!=-1&&rm->hasIndex(ref,index[i]))gt=rm->findbyIndex(ref,index[i],lower[i],upper[i]);
else gt=rm->filterRecord(ref,0,0,NULL,new TransparentFilter());
printf("%u\n",gt.size());
/*for(int j=0;j<gt.size();j++){
for(int k=0;k<len+4;k++)
printf("value %d : %u\n",k,(unsigned char)gt[j][k]);
}*/
//printf("%u\n",gt.size());
cols.push_back(gt);
ns.push_back(gt.size());
is.push_back(0);
//printf("%d\n",gt.size());
}
for(int i=0;i<selector.columns.size();i++){
std::string toprint=selector.columns[i].table+"."+selector.columns[i].column;
if(toprint.length()>20){
toprint.erase(0,toprint.length()-17);
toprint="..."+toprint;
}
while(toprint.length()<20)
toprint=toprint+" ";
printf("%s ",toprint.c_str());
}
printf("\n");
//after adjust
for(int i=0;i<wheres.size();i++){
if(wheres[i].type==WhereItem::OPERATION){
//printf("Checking operation\n");
if(wheres[i].expr.type==Expr::COL){
int place=wheres[i].expr.column.place;
int leftref=rfs[wheres[i].left.place];
//printf("%d %d\n",place,wheres[i].left.place);
if(place==0&&wheres[i].left.place>0){
Value right=extractValue(cols[place][is[place]],wheres[i].expr.column.left+4,wheres[i].expr.column.right+4,wheres[i].expr.column.type);
if(rm->hasIndex(leftref,wheres[i].left.left/4+1)){
// printf("rfd\n");
unsigned int lower,upper;
int val=right.toInt(wheres[i].left.type);
if(wheres[i].Operator==WhereItem::_EQUAL){
lower=val;
upper=val+1;
}
if(wheres[i].Operator==WhereItem::_LESS_OR_EQUAL){
lower=0;
upper=val+1;
}
if(wheres[i].Operator==WhereItem::_MORE_OR_EQUAL){
lower=val;
upper=-1;
}
if(wheres[i].Operator==WhereItem::_LESS){
lower=0;
upper=val;
}
if(wheres[i].Operator==WhereItem::_MORE){
lower=val+1;
upper=-1;
}
// printf("%d %d\n",lower,upper);
cols[wheres[i].left.place]=rm->findbyIndex(leftref,wheres[i].left.left/4+1,lower,upper);
ns[wheres[i].left.place]=cols[wheres[i].left.place].size();
//printf("%u\n",ns[wheres[i].left.place]);
}
}
}
}
}
//printf("%d\n",tables.size());
while(true){
bool tf=false;
for(int i=0;i<tables.size();i++)
if(is[i]>=ns[i]){
tf=true;
break;
}
if(tf)break;
/*for(int i=0;i<tables.size();i++)
printf("%d ",is[i]);
printf("\n");*/
//SELECT customer.name,food.name,orders.quantity FROM orders,customer,food WHERE customer.id=orders.customer_id AND food.id=orders.food_id AND orders.date='2017/11/11';
//INSERT INTO orders VALUES(1,315000,201015,'2018/02/28',8);
bool valid=true;
//printf("%u\n",wheres.size());
for(int i=0;i<wheres.size();i++){
//printf("%d\n",wheres[i].type);
if(wheres[i].type==WhereItem::OPERATION){
//printf("Checking operation\n");
int place=wheres[i].left.place;
Value left=extractValue(cols[place][is[place]],wheres[i].left.left+4,wheres[i].left.right+4,wheres[i].left.type);
Value right=wheres[i].expr.value;
if(wheres[i].expr.type==Expr::COL){
place=wheres[i].expr.column.place;
right=extractValue(cols[place][is[place]],wheres[i].expr.column.left+4,wheres[i].expr.column.right+4,wheres[i].expr.column.type);
}
if(!doOperation(left,wheres[i].Operator,right)){
valid=false;
break;
}
}
if(wheres[i].type==WhereItem::ISNULL){
int place=wheres[i].left.place;
Value left=extractValue(cols[place][is[place]],wheres[i].left.left+4,wheres[i].left.right+4,wheres[i].left.type);
if(left.type!=Value::_NULL){
valid=false;
break;
}
}
if(wheres[i].type==WhereItem::ISNOTNULL){
int place=wheres[i].left.place;
Value left=extractValue(cols[place][is[place]],wheres[i].left.left+4,wheres[i].left.right+4,wheres[i].left.type);
if(left.type==Value::_NULL){
valid=false;
break;
}
}
}
if(valid){
cnt++;
for(int i=0;i<selector.columns.size();i++){
int place=selector.columns[i].place;
Value value=extractValue(cols[place][is[place]],selector.columns[i].left+4,selector.columns[i].right+4,selector.columns[i].type);
printValue(value);printf(" ");
}
printf("\n");
}
is[tables.size()-1]++;
int n=tables.size()-1;
while(n>0&&is[n]>=ns[n]){
is[n]=0;
is[--n]++;
if(is[n]<ns[n]){
for(int i=0;i<wheres.size();i++){
if(wheres[i].type==WhereItem::OPERATION){
//printf("Checking operation\n");
if(wheres[i].expr.type==Expr::COL){
int place=wheres[i].expr.column.place;
int leftref=rfs[wheres[i].left.place];
if(place==n&&wheres[i].left.place>n){
Value right=extractValue(cols[place][is[place]],wheres[i].expr.column.left+4,wheres[i].expr.column.right+4,wheres[i].expr.column.type);
if(rm->hasIndex(leftref,wheres[i].left.left/4+1)){
unsigned int lower,upper;
int val=right.toInt(wheres[i].left.type);
if(wheres[i].Operator==WhereItem::_EQUAL){
lower=val;
upper=val+1;
}
if(wheres[i].Operator==WhereItem::_LESS_OR_EQUAL){
lower=0;
upper=val+1;
}
if(wheres[i].Operator==WhereItem::_MORE_OR_EQUAL){
lower=val;
upper=-1;
}
if(wheres[i].Operator==WhereItem::_LESS){
lower=0;
upper=val;
}
if(wheres[i].Operator==WhereItem::_MORE){
lower=val+1;
upper=-1;
}
cols[wheres[i].left.place]=rm->findbyIndex(leftref,wheres[i].left.left/4+1,lower,upper);
ns[wheres[i].left.place]=cols[wheres[i].left.place].size();
}
}
}
}
}
}
}
}
printf("%u\n",cnt);
}
void CreateIndex::accept(){
int ref=-1;
for(int j=0;j<globaltables.size();j++){
if(tbname==globaltables[j].name)ref=globaltables[j].fileid;
}
if(ref==-1){
printf("Unknown table!\n");
return;
}
Field field;
if(!getColumn(tbname,colname,field)){
printf("Unfound column!\n");
return;
}
rm->createIndex(ref,field.left+4,field.right+4);
}
void DropIndex::accept(){
int ref=-1;
for(int j=0;j<globaltables.size();j++){
if(tbname==globaltables[j].name)ref=globaltables[j].fileid;
}
if(ref==-1){
printf("Unknown table!\n");
return;
}
Field field;
if(!getColumn(tbname,colname,field)){
printf("Unfound column!\n");
return;
}
rm->deleteIndex(ref,field.left/4+1);
}
void Exiter::accept(){
rm->closeAll();
exit(0);
}
CreateDatabase::CreateDatabase(std::string dbname){
this->dbname=dbname;
}
DropDatabase::DropDatabase(std::string dbname){
this->dbname=dbname;
}
UseDatabase::UseDatabase(std::string dbname){
this->dbname=dbname;
}
CreateTable::CreateTable(std::string tbname, std::vector<Field> fields){
this->tbname=tbname;
this->fields=fields;
}
DropTable::DropTable(std::string tbname){
this->tbname=tbname;
}
DescTable::DescTable(std::string tbname){
this->tbname=tbname;
}
InsertValue::InsertValue(std::string tbname, std::vector<std::vector<Value> > values){
this->tbname=tbname;
this->values=values;
}
DeleteValues::DeleteValues(std::string tbname, std::vector<WhereItem> wheres){
this->tbname=tbname;
this->wheres=wheres;
}
UpdateValues::UpdateValues(std::string tbname, std::vector<Set> sets, std::vector<WhereItem> wheres){
this->tbname=tbname;
this->sets=sets;
this->wheres=wheres;
}
SelectValues::SelectValues(Selector selector, std::vector<std::string> tables, std::vector<WhereItem> wheres){
this->selector=selector;
this->tables=tables;
this->wheres=wheres;
}
CreateIndex::CreateIndex(std::string tbname, std::string colname){
this->tbname=tbname;
this->colname=colname;
}
DropIndex::DropIndex(std::string tbname, std::string colname){
this->tbname=tbname;
this->colname=colname;
}
Exiter::Exiter(){
}
|
131f715014ff5d22e431337c4713e0e2960688b0
|
20c583020ceb6f823a83e277c31a9ce9a8903ef0
|
/ClusterSys/base/messages/ClusterPkt_m.cc
|
5068fbe2797f9fae9b0881e29be3cb258ff5c3cb
|
[] |
no_license
|
fams/ClusterBase
|
a6ba2709d983ef580af072709d03c69779de13cd
|
af0f87ecc7062094c25430b780240c8cbba08d39
|
refs/heads/master
| 2016-09-06T15:08:18.465435
| 2012-09-25T19:08:45
| 2012-09-25T19:08:45
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 9,818
|
cc
|
ClusterPkt_m.cc
|
//
// Generated file, do not edit! Created by opp_msgc 4.2 from base/messages/ClusterPkt.msg.
//
// Disable warnings about unused variables, empty switch stmts, etc:
#ifdef _MSC_VER
# pragma warning(disable:4101)
# pragma warning(disable:4065)
#endif
#include <iostream>
#include <sstream>
#include "ClusterPkt_m.h"
// Template rule which fires if a struct or class doesn't have operator<<
template<typename T>
std::ostream& operator<<(std::ostream& out,const T&) {return out;}
// Another default rule (prevents compiler from choosing base class' doPacking())
template<typename T>
void doPacking(cCommBuffer *, T& t) {
throw cRuntimeError("Parsim error: no doPacking() function for type %s or its base class (check .msg and _m.cc/h files!)",opp_typename(typeid(t)));
}
template<typename T>
void doUnpacking(cCommBuffer *, T& t) {
throw cRuntimeError("Parsim error: no doUnpacking() function for type %s or its base class (check .msg and _m.cc/h files!)",opp_typename(typeid(t)));
}
EXECUTE_ON_STARTUP(
cEnum *e = cEnum::find("ClusterMessageTypes");
if (!e) enums.getInstance()->add(e = new cEnum("ClusterMessageTypes"));
e->insert(CLUSTER_DATA, "CLUSTER_DATA");
e->insert(CLUSTER_CONTROL, "CLUSTER_CONTROL");
e->insert(LAST_CLUSTER_MESSAGE_KIND, "LAST_CLUSTER_MESSAGE_KIND");
);
Register_Class(ClusterPkt);
ClusterPkt::ClusterPkt(const char *name, int kind) : ApplPkt(name,kind)
{
this->msgtype_var = 0;
this->headId_var = 0;
this->originId_var = 0;
}
ClusterPkt::ClusterPkt(const ClusterPkt& other) : ApplPkt(other)
{
copy(other);
}
ClusterPkt::~ClusterPkt()
{
}
ClusterPkt& ClusterPkt::operator=(const ClusterPkt& other)
{
if (this==&other) return *this;
ApplPkt::operator=(other);
copy(other);
return *this;
}
void ClusterPkt::copy(const ClusterPkt& other)
{
this->msgtype_var = other.msgtype_var;
this->headId_var = other.headId_var;
this->originId_var = other.originId_var;
}
void ClusterPkt::parsimPack(cCommBuffer *b)
{
ApplPkt::parsimPack(b);
doPacking(b,this->msgtype_var);
doPacking(b,this->headId_var);
doPacking(b,this->originId_var);
}
void ClusterPkt::parsimUnpack(cCommBuffer *b)
{
ApplPkt::parsimUnpack(b);
doUnpacking(b,this->msgtype_var);
doUnpacking(b,this->headId_var);
doUnpacking(b,this->originId_var);
}
int ClusterPkt::getMsgtype() const
{
return msgtype_var;
}
void ClusterPkt::setMsgtype(int msgtype)
{
this->msgtype_var = msgtype;
}
int ClusterPkt::getHeadId() const
{
return headId_var;
}
void ClusterPkt::setHeadId(int headId)
{
this->headId_var = headId;
}
int ClusterPkt::getOriginId() const
{
return originId_var;
}
void ClusterPkt::setOriginId(int originId)
{
this->originId_var = originId;
}
class ClusterPktDescriptor : public cClassDescriptor
{
public:
ClusterPktDescriptor();
virtual ~ClusterPktDescriptor();
virtual bool doesSupport(cObject *obj) const;
virtual const char *getProperty(const char *propertyname) const;
virtual int getFieldCount(void *object) const;
virtual const char *getFieldName(void *object, int field) const;
virtual int findField(void *object, const char *fieldName) const;
virtual unsigned int getFieldTypeFlags(void *object, int field) const;
virtual const char *getFieldTypeString(void *object, int field) const;
virtual const char *getFieldProperty(void *object, int field, const char *propertyname) const;
virtual int getArraySize(void *object, int field) const;
virtual std::string getFieldAsString(void *object, int field, int i) const;
virtual bool setFieldAsString(void *object, int field, int i, const char *value) const;
virtual const char *getFieldStructName(void *object, int field) const;
virtual void *getFieldStructPointer(void *object, int field, int i) const;
};
Register_ClassDescriptor(ClusterPktDescriptor);
ClusterPktDescriptor::ClusterPktDescriptor() : cClassDescriptor("ClusterPkt", "ApplPkt")
{
}
ClusterPktDescriptor::~ClusterPktDescriptor()
{
}
bool ClusterPktDescriptor::doesSupport(cObject *obj) const
{
return dynamic_cast<ClusterPkt *>(obj)!=NULL;
}
const char *ClusterPktDescriptor::getProperty(const char *propertyname) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
return basedesc ? basedesc->getProperty(propertyname) : NULL;
}
int ClusterPktDescriptor::getFieldCount(void *object) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
return basedesc ? 3+basedesc->getFieldCount(object) : 3;
}
unsigned int ClusterPktDescriptor::getFieldTypeFlags(void *object, int field) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->getFieldTypeFlags(object, field);
field -= basedesc->getFieldCount(object);
}
static unsigned int fieldTypeFlags[] = {
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
};
return (field>=0 && field<3) ? fieldTypeFlags[field] : 0;
}
const char *ClusterPktDescriptor::getFieldName(void *object, int field) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->getFieldName(object, field);
field -= basedesc->getFieldCount(object);
}
static const char *fieldNames[] = {
"msgtype",
"headId",
"originId",
};
return (field>=0 && field<3) ? fieldNames[field] : NULL;
}
int ClusterPktDescriptor::findField(void *object, const char *fieldName) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
int base = basedesc ? basedesc->getFieldCount(object) : 0;
if (fieldName[0]=='m' && strcmp(fieldName, "msgtype")==0) return base+0;
if (fieldName[0]=='h' && strcmp(fieldName, "headId")==0) return base+1;
if (fieldName[0]=='o' && strcmp(fieldName, "originId")==0) return base+2;
return basedesc ? basedesc->findField(object, fieldName) : -1;
}
const char *ClusterPktDescriptor::getFieldTypeString(void *object, int field) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->getFieldTypeString(object, field);
field -= basedesc->getFieldCount(object);
}
static const char *fieldTypeStrings[] = {
"int",
"int",
"int",
};
return (field>=0 && field<3) ? fieldTypeStrings[field] : NULL;
}
const char *ClusterPktDescriptor::getFieldProperty(void *object, int field, const char *propertyname) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->getFieldProperty(object, field, propertyname);
field -= basedesc->getFieldCount(object);
}
switch (field) {
case 0:
if (!strcmp(propertyname,"enum")) return "ClusterMessageTypes";
return NULL;
default: return NULL;
}
}
int ClusterPktDescriptor::getArraySize(void *object, int field) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->getArraySize(object, field);
field -= basedesc->getFieldCount(object);
}
ClusterPkt *pp = (ClusterPkt *)object; (void)pp;
switch (field) {
default: return 0;
}
}
std::string ClusterPktDescriptor::getFieldAsString(void *object, int field, int i) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->getFieldAsString(object,field,i);
field -= basedesc->getFieldCount(object);
}
ClusterPkt *pp = (ClusterPkt *)object; (void)pp;
switch (field) {
case 0: return long2string(pp->getMsgtype());
case 1: return long2string(pp->getHeadId());
case 2: return long2string(pp->getOriginId());
default: return "";
}
}
bool ClusterPktDescriptor::setFieldAsString(void *object, int field, int i, const char *value) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->setFieldAsString(object,field,i,value);
field -= basedesc->getFieldCount(object);
}
ClusterPkt *pp = (ClusterPkt *)object; (void)pp;
switch (field) {
case 0: pp->setMsgtype(string2long(value)); return true;
case 1: pp->setHeadId(string2long(value)); return true;
case 2: pp->setOriginId(string2long(value)); return true;
default: return false;
}
}
const char *ClusterPktDescriptor::getFieldStructName(void *object, int field) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->getFieldStructName(object, field);
field -= basedesc->getFieldCount(object);
}
static const char *fieldStructNames[] = {
NULL,
NULL,
NULL,
};
return (field>=0 && field<3) ? fieldStructNames[field] : NULL;
}
void *ClusterPktDescriptor::getFieldStructPointer(void *object, int field, int i) const
{
cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount(object))
return basedesc->getFieldStructPointer(object, field, i);
field -= basedesc->getFieldCount(object);
}
ClusterPkt *pp = (ClusterPkt *)object; (void)pp;
switch (field) {
default: return NULL;
}
}
|
a43c94f34ae5bb496cef29d059116cd50187fb5d
|
0ccae222bb5d73b3ad9f9c465709685f7586fdb8
|
/src/dev/UniqueCreator.Graphics.Gpu.ComputeShaderByteCode.h
|
8ead79a20c5992785e7aea5a09ab3363e00e7b38
|
[] |
no_license
|
UniqueCreator/uc-graphics-winrt
|
c790048e8bfc768acc30d40f378a516e8214f1cc
|
c36e6436c9aca4ababc3ba6fa7d82b070f293656
|
refs/heads/master
| 2020-04-27T18:17:23.047144
| 2019-06-15T09:34:31
| 2019-06-15T09:34:31
| 174,563,143
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 820
|
h
|
UniqueCreator.Graphics.Gpu.ComputeShaderByteCode.h
|
#pragma once
#include "UniqueCreator.Graphics.Gpu.ComputeShaderByteCode.g.h"
#include "IShaderByteCodeNative.h"
namespace winrt::UniqueCreator::Graphics::Gpu::implementation
{
using namespace Windows::Foundation::Collections;
struct ComputeShaderByteCode : ComputeShaderByteCodeT<ComputeShaderByteCode, IShaderByteCodeNative>
{
ComputeShaderByteCode();
IVector<uint8_t> Code();
void Code(IVector<uint8_t> const& value);
Blob GetShaderByteCode();
using vector = impl::input_vector<uint8_t, std::vector<uint8_t, std::allocator<uint8_t> > >;
vector m_code;
};
}
namespace winrt::UniqueCreator::Graphics::Gpu::factory_implementation
{
struct ComputeShaderByteCode : ComputeShaderByteCodeT<ComputeShaderByteCode, implementation::ComputeShaderByteCode>
{
};
}
|
9141eb756bf5455b1e177bda02d30e224659eeeb
|
4141c107a783133d44c16f5ef4c910056866dec9
|
/perm_and_comb.cpp
|
8628450aa07371d6d53aea52ee1d058bedfe8ee9
|
[] |
no_license
|
DDUC-CS-Sanjeet/p-and-c-using-recursion-kdhyani502
|
84ed4e7892eaa88284984d4fed3ded4edf5fcfdc
|
831cebf19b51ddf0256bbca2318da78cefa264bb
|
refs/heads/master
| 2020-12-20T04:53:34.161438
| 2020-01-24T16:08:20
| 2020-01-24T16:08:20
| 235,968,042
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 162
|
cpp
|
perm_and_comb.cpp
|
#include<iostream>
using namespace std;
int permutation(int n, int r)
{
return 0;
}
int combination(int n, int r)
{
return 0;
}
int main()
{
return 0;
}
|
c51e25d6860d9104b326d6084d836aabdfc7fdff
|
45045d64033b9e9b9a1340278fa539290543d6aa
|
/render/gpu_resource.h
|
d6a6327dc497400ab2d812c5f2e6c927ae6dd85f
|
[] |
no_license
|
lenxyang/azer2
|
829c366350307c890dabd02ca61a48fae94a500f
|
e12d47e1f7a268a17a80f5637453c47cdeba5779
|
refs/heads/master
| 2021-01-13T09:48:30.723491
| 2016-11-20T15:11:30
| 2016-11-20T15:11:30
| 26,254,526
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,075
|
h
|
gpu_resource.h
|
#pragma once
#include <memory>
#include "base/memory/ref_counted.h"
#include "base/callback.h"
#include "azer/base/export.h"
#include "azer/render/common.h"
namespace azer {
class Renderer;
class GpuResLockData;
class GpuResource;
typedef scoped_refptr<GpuResLockData> GpuResLockDataPtr;
typedef scoped_refptr<GpuResource> GpuResourcePtr;
class AZER_EXPORT GpuResLockData: public ::base::RefCounted<GpuResLockData> {
public:
GpuResLockData(uint8_t* data, int row_size, int column,
::base::Callback<void()> release);
~GpuResLockData();
uint8_t* data_ptr() const { return data_;}
int row_size() const { return row_size_;}
int column_num() const { return column_num_;}
int size() const { return row_size_ * column_num_;}
private:
uint8_t* data_;
int row_size_;
int column_num_;
int size_;
::base::Callback<void(void)> release_callback_;
DISALLOW_COPY_AND_ASSIGN(GpuResLockData);
};
enum class GpuResType {
kUnknown = 0x0000,
kCommonBuffer = 0x0001,
kVertexBuffer = 0x0010,
kIndicesBuffer = 0x0020,
kStructuredBuffer = 0x0040,
kConstantTable = 0x0080,
kTexture = 0x0100,
};
struct AZER_EXPORT GpuResOptions {
BufferUsage usage;
CPUAccess cpu_access; // defined render_system
uint32_t target;
GpuResType type;
GpuResOptions();
};
AZER_EXPORT std::ostream& operator << (std::ostream& os, const GpuResType& res);
class AZER_EXPORT GpuResource : public ::base::RefCounted<GpuResource> {
public:
GpuResource(const GpuResOptions& opt);
virtual ~GpuResource();
virtual void SetName(const std::string& name) = 0;
virtual GpuResLockDataPtr map(MapType flags) = 0;
virtual void unmap() = 0;
virtual bool CopyTo(GpuResource* res) = 0;
virtual NativeGpuResourceHandle native_handle() = 0;
GpuResType resource_type() const { return resource_options_.type;}
const GpuResOptions& resource_options() const { return resource_options_;}
private:
const GpuResOptions resource_options_;
DISALLOW_COPY_AND_ASSIGN(GpuResource);
};
} // namespace azer
|
062e1587a3f51e1e086f2be0f40d4627765f3ee1
|
5cc698e6bba5e1b659467836f9e7155bd7807c2f
|
/NTupleMaker/bin/CreateCards_emu.cpp
|
5ba94073c58d142e05042f1a3d2e972b4fdf8a7b
|
[] |
no_license
|
neogyk/DesyTauAnalysesRun2_25ns
|
2e44f766184381cec0083a16295fade5e95b0526
|
bfad836fb7c79649295a896529489bfc679e7cac
|
refs/heads/master
| 2023-06-27T06:03:41.146619
| 2021-07-13T10:48:36
| 2021-07-13T10:48:36
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,656
|
cpp
|
CreateCards_emu.cpp
|
//#include "DesyTauAnalyses/NTupleMaker/interface/settings.h"
#include "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "TH1.h"
#include "TH2.h"
#include <iostream>
#include "DesyTauAnalyses/NTupleMaker/interface/Config.h"
#include "DesyTauAnalyses/NTupleMaker/interface/CardsEMu.h"
using namespace std;
int main(int argc, char * argv[]) {
// argument - config file
if (argc!=5) {
std::cout << "usage of the script : CreateCards_emu [era=2016,2017,2018] [Sample=Data,EWK,DYJets,EMB,TTbar,SMggH,SMothers,bbH,ggH_{t,b,i}] [category] [Systematics=0,1]" << std::endl;
exit(-1);
}
int nBinsNoBTag = 27;
double binsNoBTag[28] =
{40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,
225,250,275,300,325,350,400,500,700,900,5000};
int nBinsBTag = 15;
double binsBTag[16] =
{40,60,80,100,120,140,160,180,200,250,300,350,400,500,700,5000};
int nBinsBTag2 = 7;
double binsBTag2[8] =
{40,80,120,160,200,300,500,5000};
int nBinsTTbar = 12;
double binsTTbar[13] = {40, 60, 80, 100,
120, 150, 200, 250,
300, 400, 500, 1000,5000};
// std::vector<double> binsVector = {0, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 525, 550, 575, 600, 625, 650, 675, 700, 725, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, 1550, 1600, 1650, 1700, 1750, 1800, 1850, 1900, 1950, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900, 5000};
std::vector<double> binsNoBTagVector = {0,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,225,250,275,300,325,350,400,450,500,600,700,800,900,1100,1300,1500,1700,1900,2100,2300,2500,2700,2900,3100,3300,3500,3700,3900,4100,4300,4500,4700,5000};
std::vector<double> binsBTagVector = {0,60,80,100,120,140,160,180,200,250,300,350,400,500,600,700,800,900,1100,1300,1500,1700,1900,2100,2300,2500,2700,2900,3100,3300,3500,3700,3900,4100,4300,4500,4700,5000};
// int nBinsFine = binsVector.size()-1;
nBinsBTag = binsBTagVector.size()-1;
nBinsNoBTag = binsNoBTagVector.size()-1;
TString era(argv[1]);
TString sample(argv[2]);
TString category(argv[3]);
int systematics = atoi(argv[4]);
int triggerOption = 0;
TString inputDir("/nfs/dust/cms/user/rasp/Run/emu_MSSM/Feb10/");
TString outputDir("/nfs/dust/cms/user/rasp/Run/emu_MSSM/Feb10/datacards/");
TString variable("mt_tot");
int nbins = 20;
double xmin = 0;
double xmax = 1000;
bool runWithSystematics = true;
if (systematics==0) runWithSystematics = false;
bool runOnEmbedded = true;
CardsEMu * cardsEMu = new CardsEMu(sample,
era,
category,
inputDir,
outputDir,
variable,
nbins,
xmin,
xmax,
triggerOption,
runWithSystematics,
runOnEmbedded
);
cardsEMu->PrintSamples();
cardsEMu->PrintShapeSystematics();
cardsEMu->PrintWeightSystematics();
if (category.Contains("_DZetaLtm35"))
cardsEMu->SetVariableToPlot(variable,nBinsNoBTag,binsNoBTagVector);
else {
if (category.Contains("_NbtagGt1")||
category.Contains("_Nbtag1"))
cardsEMu->SetVariableToPlot(variable,nBinsBTag,binsBTagVector);
else
cardsEMu->SetVariableToPlot(variable,nBinsNoBTag,binsNoBTagVector);
}
cardsEMu->Run();
cardsEMu->CloseFile();
delete cardsEMu;
}
|
4e1f151547ff248e2e2745a01a8c88ba2023b0e4
|
b14d5833a79518a40d302e5eb40ed5da193cf1b2
|
/cpp/extern/xercesc++/2.6.0/src/xercesc/framework/XMLContentModel.cpp
|
31f6c2e29b6271cb15041ff890a1d2ef20fc5f97
|
[
"Apache-2.0"
] |
permissive
|
andyburke/bitflood
|
dcb3fb62dad7fa5e20cf9f1d58aaa94be30e82bf
|
fca6c0b635d07da4e6c7fbfa032921c827a981d6
|
refs/heads/master
| 2016-09-10T02:14:35.564530
| 2011-11-17T09:51:49
| 2011-11-17T09:51:49
| 2,794,411
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,023
|
cpp
|
XMLContentModel.cpp
|
/*
* Copyright 1999-2000,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* $Log: XMLContentModel.cpp,v $
* Revision 1.3 2004/09/08 13:55:58 peiyongz
* Apache License Version 2.0
*
* Revision 1.2 2002/11/04 15:00:21 tng
* C++ Namespace Support.
*
* Revision 1.1.1.1 2002/02/01 22:21:51 peiyongz
* sane_include
*
* Revision 1.3 2001/05/28 20:53:35 tng
* Schema: move static data gInvalidTrans, gEOCFakeId, gEpsilonFakeId to XMLContentModel for others to access
*
* Revision 1.2 2000/02/06 07:47:47 rahulj
* Year 2K copyright swat.
*
* Revision 1.1.1.1 1999/11/09 01:08:30 twl
* Initial checkin
*
* Revision 1.2 1999/11/08 20:44:37 rahul
* Swat for adding in Product name and CVS comment log variable.
*
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/framework/XMLContentModel.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// public static data
// ---------------------------------------------------------------------------
const unsigned int XMLContentModel::gInvalidTrans = 0xFFFFFFFF;
const unsigned int XMLContentModel::gEOCFakeId = 0xFFFFFFF1;
const unsigned int XMLContentModel::gEpsilonFakeId = 0xFFFFFFF2;
XERCES_CPP_NAMESPACE_END
|
47b2d77e9353f2ca1c7210470d09655a872f3828
|
bb8d76ce8e285a500d0ba44b22389553e7d6db87
|
/Repetitions.cpp
|
14a48e90c99a8a9d6535eb48903a2266011d7a89
|
[] |
no_license
|
viiku/cses
|
38261166f38b18b86a3224ab51f751a5d8c50ac4
|
a7d0bff553d0ee42fa54ec6a74429fe104edfb1e
|
refs/heads/main
| 2023-05-20T04:55:21.252111
| 2021-06-08T06:13:04
| 2021-06-08T06:13:04
| 346,925,636
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 552
|
cpp
|
Repetitions.cpp
|
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main(){
string str;cin>>str;
int cnt=0,mx=0;
if(str.size()==1){
cout<<1<<"\n";
}else{
int n=str.size()-1;
for(int i=0;i<n;i++){
if(str[i]==str[i+1]){
cnt+=2;
mx=max(mx,cnt);
cnt-=1;
}else if(str[i]!=str[i+1]){
cnt+=1;
mx=max(mx,cnt);
cnt=0;
}
}
cout<<mx<<"\n";
}
}
|
9a489e7bc89c6c54492586e9f71b44c5dd1eea0c
|
d541df6887615aa0a072a1852135e67e884929fe
|
/include/snaze.h
|
b4ea90f659f9b6eed25048f5b0b835d8b60a3967
|
[
"MIT"
] |
permissive
|
Carvs10/Snaze
|
4d4f5a988e088842d2f6d08f882bc2ea1d7ea1d3
|
87bdc2df2caf2357639601f438cc5ff46a398a8a
|
refs/heads/master
| 2020-06-01T01:27:57.544321
| 2019-06-20T17:35:17
| 2019-06-20T17:35:17
| 190,576,612
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 897
|
h
|
snaze.h
|
#ifndef SNAZE_H
#define SNAZE_H
#include <iostream>
#include "snapshot.h"
#include <list>
namespace Snaze{
class Snake{
private:
std::pair<int,int> spawn;
int life //!< store the ammount of life
int head_x;
int head_y;
Directions direct;
public:
std::list< std::pair<int,int> > body;
//=== Consturctors
Snake( int x = 0, int y = 0, Directions d=UP )
: life(5)
{
spawn.first = head_x = x;
spawn.second = head_y = y;
direct = d;
}
void set_pos( int x, int y)
{
}
//=== Desturctor
~Snake()
//=== Growing the snake
void evolve();
};
}
#endif
|
b63ba8f56798b6cfc6a7b430aa95c797af5499eb
|
2450434635e1df43a79f01566e11f09e55a0f3b7
|
/Documents/c++/Notes/swapnum.cpp
|
a4b0df1dd1cd3fdc0b17f0554ba9436b4c486cc6
|
[] |
no_license
|
l-jovanni-l/finalProject
|
eb6d3b9cff622efe88a3a53fa23feb3ed3ae0b88
|
59a5cdab633922c807400fc71a949f700ad6a069
|
refs/heads/master
| 2020-06-26T10:23:23.822967
| 2020-05-22T07:18:40
| 2020-05-22T07:18:40
| 199,607,128
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 578
|
cpp
|
swapnum.cpp
|
#include <iostream>
using namespace std;
void swap(int*, int*); //protoypes says youre gonna accept two pointers
/* Everything on top is a directive and just include one header file */
void swap(int *n1, int *n2){ //going to accept two pointers
int temp = *n1;
*n1 = *n2; //These are no longer values they are pointer referance
*n2 = temp;
}
int main () {
int a = 3, b = 5;
int temp;
cout << a << " " << b << endl;
swap(&a, &b);
/* temp = a;
a = b;
b = temp; */
cout << a << " " << b << endl;
return 0;
}
|
2cd22550e120567dfb4ad69c6e22d2fe1e0da2aa
|
117da1e307f00037b66a061c1744d1e5a37d06d3
|
/ColorRecognitionTCS230.cpp
|
f63af8dbed8cd86248d3531d272e48dc94ca7722
|
[
"MIT"
] |
permissive
|
patriciohc/tcs230
|
30175d6108b747832a3160d308171e1f83efc337
|
f2c7df92a4688d3177599e06523f6b59d5587077
|
refs/heads/master
| 2021-01-10T05:24:18.164765
| 2016-01-07T02:33:06
| 2016-01-07T02:33:06
| 46,098,796
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,202
|
cpp
|
ColorRecognitionTCS230.cpp
|
/**
* Arduino - Color Recognition Sensor
*
* ColorRecognitionTCS230.h
*
* The abstract class for the Color Recognition TCS230 sensor.
*
* @author Dalmir da Silva <dalmirdasilva@gmail.com>
*/
#ifndef __ARDUINO_DRIVER_COLOR_RECOGNITION_TCS230_CPP__
#define __ARDUINO_DRIVER_COLOR_RECOGNITION_TCS230_CPP__ 1
#include "ColorRecognitionTCS230.h"
#include <Arduino.h>
#include <TimerOne.h>
ColorRecognitionTCS230 ColorRecognitionTCS230::instance;
void ColorRecognitionTCS230::initialize(unsigned char outPin, unsigned char s2Pin, unsigned char s3Pin) {
this->s2Pin = s2Pin;
this->s3Pin = s3Pin;
this->outPin = outPin;
this->currentFilter = CLEAR_FILTER;
pinMode(s2Pin, OUTPUT);
pinMode(s3Pin, OUTPUT);
pinMode(outPin, INPUT);
Timer1.initialize();
Timer1.attachInterrupt(ColorRecognitionTCS230::timerInterruptHandler);
attachInterrupt((outPin - 2), ColorRecognitionTCS230::externalInterruptHandler, RISING);
}
void ColorRecognitionTCS230::adjustWhiteBalance() {
delay(4000);
instance.whiteBalanceFrequencies[0] = instance.lastFrequencies[0];
instance.whiteBalanceFrequencies[1] = instance.lastFrequencies[1];
instance.whiteBalanceFrequencies[2] = instance.lastFrequencies[2];
}
void ColorRecognitionTCS230::externalInterruptHandler() {
instance.count++;
}
void ColorRecognitionTCS230::timerInterruptHandler() {
switch (instance.currentFilter) {
case CLEAR_FILTER:
setFilter(RED_FILTER);
break;
case RED_FILTER:
instance.lastFrequencies[0] = instance.count;
setFilter(GREEN_FILTER);
break;
case GREEN_FILTER:
instance.lastFrequencies[1] = instance.count;
setFilter(BLUE_FILTER);
break;
case BLUE_FILTER:
instance.lastFrequencies[2] = instance.count;
setFilter(RED_FILTER);
break;
}
instance.count = 0;
Timer1.setPeriod(1000000);
}
unsigned char ColorRecognitionTCS230::getRed() {
if (lastFrequencies[0] > whiteBalanceFrequencies[0]) {
return 255;
}
return (unsigned char) map(lastFrequencies[0], 0, whiteBalanceFrequencies[0], 0, 255);
}
unsigned char ColorRecognitionTCS230::getGreen() {
if (lastFrequencies[1] > whiteBalanceFrequencies[1]) {
return 255;
}
return (unsigned char) map(lastFrequencies[1], 0, whiteBalanceFrequencies[1], 0, 255);
}
unsigned char ColorRecognitionTCS230::getBlue() {
if (lastFrequencies[2] > whiteBalanceFrequencies[2]) {
return 255;
}
return (unsigned char) map(lastFrequencies[2], 0, whiteBalanceFrequencies[2], 0, 255);
}
bool ColorRecognitionTCS230::fillRGB(unsigned char buf[3]) {
buf[0] = getRed();
buf[1] = getGreen();
buf[2] = getBlue();
return true;
}
void ColorRecognitionTCS230::setFilter(Filter filter) {
unsigned char s2 = LOW, s3 = LOW;
instance.currentFilter = filter;
if (filter == CLEAR_FILTER || filter == GREEN_FILTER) {
s2 = HIGH;
}
if (filter == BLUE_FILTER || filter == GREEN_FILTER) {
s3 = HIGH;
}
digitalWrite(instance.s2Pin, s2);
digitalWrite(instance.s3Pin, s3);
}
#endif /* __ARDUINO_DRIVER_COLOR_RECOGNITION_TCS230_CPP__ */
|
8dff32c977dc425ecc7dc0c101a396ee1b5b84a3
|
12faf41c596568f32785d5e841d930c67a7e0649
|
/include/lsst/meas/algorithms/shapelet/BVec.h
|
294d37046b6d5bb498cb1c01d1e251c8ce2cdc13
|
[
"NCSA"
] |
permissive
|
DarkEnergySurvey/LSSTmeasalgorithms
|
086dad3e1ccf595eebb089346842558b0ef12f21
|
1d91d52849eff71238f90c4ae3f374458ed4e12d
|
refs/heads/master
| 2023-03-12T04:26:49.887471
| 2021-03-03T21:19:27
| 2021-03-03T21:19:27
| 339,210,664
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,682
|
h
|
BVec.h
|
#ifndef MeasAlgoShapeletBVec_H
#define MeasAlgoShapeletBVec_H
#include "lsst/meas/algorithms/shapelet/MyMatrix.h"
#include <complex>
#include <vector>
#include "lsst/meas/algorithms/shapelet/dbg.h"
namespace lsst {
namespace meas {
namespace algorithms {
namespace shapelet {
class BVec;
class AssignableToBVec
{
public:
virtual void assignTo(BVec& bvec) const = 0;
virtual int getOrder() const = 0;
virtual double getSigma() const = 0;
virtual ~AssignableToBVec() {}
};
class BVec : public AssignableToBVec
{
public :
BVec(int order, double sigma) :
_order(order), _sigma(sigma),
_b((_order+1)*(_order+2)/2)
{ _b.setZero(); }
BVec(int order, double sigma, double* bvec) :
_order(order), _sigma(sigma),
#ifdef USE_TMV
_b((_order+1)*(_order+2)/2,bvec)
#else
_b(DVector::Map(bvec,(_order+1)*(_order+1)/2))
#endif
{}
BVec(int order, double sigma, const DVector& bvec) :
_order(order), _sigma(sigma), _b(bvec)
{}
BVec(const BVec& rhs) :
_order(rhs._order), _sigma(rhs._sigma), _b(rhs._b)
{}
~BVec() {}
BVec& operator=(const AssignableToBVec& rhs);
BVec& operator=(const BVec& rhs);
void assignTo(BVec& bvec) const;
DVector& vec() { return _b; }
const DVector& vec() const { return _b; }
double& operator()(int i) { return _b(i); }
double operator()(int i) const { return _b(i); }
int getOrder() const { return _order; }
double getSigma() const { return _sigma; }
const DVector& getValues() const { return _b; }
size_t size() const { return _b.size(); }
void setSigma(double sigma) { _sigma = sigma; }
// For this one v is allowed to be smaller than size,
// and the rest of the values are filled in as 0's.
void setValues(const DVector& v);
// For this one, the sizes must match.
// b.setValues(v) is equivalent to b.vec() = v.
template <typename V>
void setValues(const V& v)
{
Assert(v.size() == size());
_b = v;
}
void normalize() { _b /= _b(0); }
void conjugateSelf();
private :
int _order;
double _sigma;
DVector _b;
};
inline std::ostream& operator<<(std::ostream& os, const BVec& b)
{ os << b.getOrder()<<" "<<b.getSigma()<<" "<<b.vec(); return os; }
// NB: All of the following calculate and augment functions assume that
// the input matrix has already been zeroed before calling the function.
// This is because the sparsity of the matrices maintains its structure
// for different values of mu, g, theta, and z. So it is faster to
// just overwrite the locations that need to be written and skip the zeroes
// each time you call these functions.
void calculateZTransform(
std::complex<double> z, int order1, int order2, DMatrix& T);
inline void calculateZTransform(std::complex<double> z, int order, DMatrix& T)
{ calculateZTransform(z,order,order,T); }
void augmentZTransformCols(std::complex<double> z, int order, DMatrix& T);
void applyZ(std::complex<double> z, BVec& b);
void calculateMuTransform(double mu, int order1, int order2, DMatrix& D);
inline void calculateMuTransform(double mu, int order, DMatrix& D)
{ calculateMuTransform(mu,order,order,D); }
void augmentMuTransformRows(double mu, int order, DMatrix& D);
void augmentMuTransformCols(double mu, int order, DMatrix& D);
void applyMu(double mu, BVec& b);
void calculateThetaTransform(
double theta, int order1, int order2, DBandMatrix& R);
inline void calculateThetaTransform(double theta, int order, DBandMatrix& R)
{ calculateThetaTransform(theta,order,order,R); }
void applyTheta(double theta, BVec& b);
void calculateGTransform(
std::complex<double> g, int order1, int order2, DMatrix& S);
inline void calculateGTransform(std::complex<double> g, int order, DMatrix& S)
{ calculateGTransform(g,order,order,S); }
void augmentGTransformCols(std::complex<double> g, int order, DMatrix& S);
void applyG(std::complex<double> g, BVec& b);
void calculatePsfConvolve(
const BVec& bpsf, int order1, int order2, double sigma, DMatrix& C);
inline void calculatePsfConvolve(
const BVec& bpsf, int order, double sigma, DMatrix& C)
{ calculatePsfConvolve(bpsf,order,order,sigma,C); }
void applyPsf(const BVec& bpsf, BVec& b);
}}}}
#endif
|
a1bd9ebf6c30b866891aa985f0e89f2568909704
|
cb8da384669141a74a55e58f3899abf168f24d6c
|
/sprite.cpp
|
273502d7f082676bc2b3bdd02c6c91afb5f60af7
|
[] |
no_license
|
sisyamo2236/kuma
|
e8d861ec22c675fa14c32769dbbb87f1adc8b7a3
|
ac37fc9b980381e293c3ea42f69e4f93a641bcfd
|
refs/heads/master
| 2022-12-29T06:29:48.412202
| 2020-10-22T08:08:22
| 2020-10-22T08:08:22
| 306,259,899
| 0
| 0
| null | null | null | null |
SHIFT_JIS
|
C++
| false
| false
| 12,803
|
cpp
|
sprite.cpp
|
#include "mydirect3d.h"
#include "game.h"
#include "texture.h"
#include <d3dx9.h>
#include <d3d9.h>
//グローバル変数
static LPDIRECT3DTEXTURE9 g_pTexture3[6] = { NULL,NULL,NULL,NULL,NULL,NULL };//テクスチャインターフェース テクスチャ1つにつき1つ必要
static float f = 0.0f;
static float move_x = 0.0f;
bool turn = false;
// FVF ... フレキシブルバーテックスフォーマット
// 座標変換済み頂点 RHW = 1
static LPDIRECT3DVERTEXBUFFER9 g_pVertexBuffer = NULL;//頂点バッファインターフェース
static LPDIRECT3DINDEXBUFFER9 g_pIndexBuffer = NULL;//インデックスバッファインターフェース
static D3DCOLOR g_Color = 0xffffffff;
texture Texture(true);
void sprite:: Sprite_Initialize(void) {
LPDIRECT3DDEVICE9 pDevice = MYDirect3D_GetDevice();
if (!pDevice) {
return;
}
//頂点バッファバイト数,使い方,FVF,メモリの管理方法,取得したインターフェースのアドレスを記録するポインタ,謎
pDevice->CreateVertexBuffer(sizeof(Vertex2D)*4,D3DUSAGE_WRITEONLY,FVF_VERTEX2D,D3DPOOL_MANAGED,&g_pVertexBuffer,NULL);
pDevice->CreateIndexBuffer(sizeof(WORD)*6,D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &g_pIndexBuffer, NULL);
}
void sprite::Sprite_Finalize(void) {
if (g_pVertexBuffer) {
g_pVertexBuffer->Release();
g_pVertexBuffer = NULL;
}
if (g_pIndexBuffer) {
g_pIndexBuffer->Release();
g_pIndexBuffer = NULL;
}
}
//スプライトポリゴンカラー設定
void sprite::Sprite_SetColor(D3DCOLOR color) {
g_Color = color;
}
void sprite::Sprite_SetColor(int r, int g, int b, int a) {
g_Color = (a << 24) + (r << 16) + (g << 8) + (b);
}
//カラー初期化
void sprite::Sprite_SetColorDefault() {
g_Color = 0xffffffff;
}
void sprite::Sprite_Draw_test3(int textureId, float dx, float dy, float dw, float dh, int tcx, int tcy, int tcw, int tch) {
LPDIRECT3DDEVICE9 g_pDevice = MYDirect3D_GetDevice();
g_pDevice->SetFVF(FVF_VERTEX2D);
g_pDevice->SetTexture(0, Texture.Texture_GetTexture(textureId));
//テクスチャのサイズ取得
int w = Texture.Texture_GetTextureWidth(textureId);
int h = Texture.Texture_GetTextureHeight(textureId);
//テクスチャ切り取りUV座標
float u0 = (float)tcx / w;
float v0 = (float)tcy / h;
float u1 = (float)(tcx + tcw) / w;
float v1 = (float)(tcy + tch) / h;
Vertex2D v[] = {
{D3DXVECTOR4(dx - 0.5f ,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v0)},
{D3DXVECTOR4(dx - 0.5f + dw ,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v0)},
{D3DXVECTOR4(dx - 0.5f ,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v1)},
{D3DXVECTOR4(dx - 0.5f + dw ,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v1)},
};
//頂点バッファのロックとデータの書き込み
Vertex2D* pV;
g_pVertexBuffer->Lock(0, 0, (void**)&pV, 0);//書き込みの確保
memcpy(pV, v, sizeof(v));
g_pVertexBuffer->Unlock();//書き込みの終了
//インデックスバッファのロックと書き込み
WORD* pI;
g_pIndexBuffer->Lock(0,0,(void**)&pI,0);
pI[0] = 0;
pI[1] = 1;
pI[2] = 3;
pI[3] = 0;
pI[4] = 3;
pI[5] = 2;
g_pIndexBuffer->Unlock();
//デバイスの頂点バッファを設定
g_pDevice->SetStreamSource(0, g_pVertexBuffer, 0, sizeof(Vertex2D));
//デバイスにインデックスバッファを設定
g_pDevice->SetIndices(g_pIndexBuffer);
////頂点バッファとインデックスバッファを利用したプリミティブ描画
//描き方、最初インデックス,最小インデックス,頂点の数,最初のやつ、図形の数
g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,4,0,2);
}
//dx ・・・描画座標
//dy ・・・描画座標
//dw ・・・ポリゴンサイズ幅
//dh ・・・ポリゴンサイズ高さ
//tcx ・・・描画座標
//tcy ・・・描画座標
//tcw ・・・
//tch ・・・
void sprite::Sprite_Draw_test2(int textureId, float dx, float dy, float dw, float dh, int tcx, int tcy, int tcw, int tch) {
LPDIRECT3DDEVICE9 g_pDevice = MYDirect3D_GetDevice();
g_pDevice->SetFVF(FVF_VERTEX2D);
g_pDevice->SetTexture(0, Texture.Texture_GetTexture(textureId));
//テクスチャのサイズ取得
int w = Texture.Texture_GetTextureWidth(textureId);
int h = Texture.Texture_GetTextureHeight(textureId);
//テクスチャ切り取りUV座標
float u0 = (float)tcx / w;
float v0 = (float)tcy / h;
float u1 = (float)(tcx + tcw) / w;
float v1 = (float)(tcy + tch) / h;
Vertex2D v[] = {
{D3DXVECTOR4(dx - 0.5f ,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v0)},
{D3DXVECTOR4(dx - 0.5f + dw ,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v0)},
{D3DXVECTOR4(dx - 0.5f ,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v1)},
{D3DXVECTOR4(dx - 0.5f + dw ,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v1)},
};
//頂点バッファのロックとデータの書き込み
Vertex2D* pV;
////これが大切
//引数 ロックする先頭 0は先頭、ロックする長さ 0は全部
g_pVertexBuffer->Lock(0,0,(void**)&pV,0);//書き込みの確保
memcpy(pV,v,sizeof(v));
g_pVertexBuffer->Unlock();//書き込みの終了
//頂点バッファの指定
g_pDevice->SetStreamSource(0,g_pVertexBuffer,0,sizeof(Vertex2D));
//プリミティブ描画
//引数 描き方 スタート地点 いくつ描くか
g_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0, 2);
}
void sprite::Sprite_Draw_test(int textureId, float dx, float dy, float dw, float dh, int tcx, int tcy, int tcw, int tch) {
LPDIRECT3DDEVICE9 g_pDevice = MYDirect3D_GetDevice();
g_pDevice->SetFVF(FVF_VERTEX2D);
g_pDevice->SetTexture(0, Texture.Texture_GetTexture(textureId));
//テクスチャのサイズ取得
int w = Texture.Texture_GetTextureWidth(textureId);
int h = Texture.Texture_GetTextureHeight(textureId);
//テクスチャ切り取りUV座標
float u0 = (float)tcx / w;
float v0 = (float)tcy / h;
float u1 = (float)(tcx + tcw) / w;
float v1 = (float)(tcy + tch) / h;
Vertex2D v[] = {
{D3DXVECTOR4(dx - 0.5f ,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v0)},
{D3DXVECTOR4(dx - 0.5f + dw ,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v0)},
{D3DXVECTOR4(dx - 0.5f ,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v1)},
{D3DXVECTOR4(dx - 0.5f + dw ,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v1)},
};
//インデックスデータ
unsigned short index[] = { 0,1,3,0,3,2 };
// 最小のインデックス値,使う頂点、図形の数,インデックスデータの先頭アドレス,フォーマット,頂点データ,隣の頂点までのバイト数
g_pDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, index, D3DFMT_INDEX16, v, sizeof(Vertex2D));
//ポリゴンを書く(簡易版)
//引数 描画タイプ、数、先頭アドレス,隣の頂点まで何バイト
//g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, v, sizeof(Vertex2D));
}
void sprite::Sprite_Draw(int textureId, float dx, float dy, float dw, float dh) {
LPDIRECT3DDEVICE9 g_pDevice = MYDirect3D_GetDevice();
g_pDevice->SetFVF(FVF_VERTEX2D);
g_pDevice->SetTexture(0, Texture.Texture_GetTexture(textureId));
//テクスチャのサイズ取得
int w = Texture.Texture_GetTextureWidth(textureId);
int h = Texture.Texture_GetTextureHeight(textureId);
Vertex2D v[] = {
{D3DXVECTOR4(dx - 0.5f,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(0,0)},
{D3DXVECTOR4(dx - 0.5f + dw,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(1,0)},
{D3DXVECTOR4(dx - 0.5f,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(0,1)},
{D3DXVECTOR4(dx - 0.5f + dw,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(1,1)},
};
//ポリゴンを書く(簡易版)
//引数 描画タイプ、数、先頭アドレス,隣の頂点まで何バイト
g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(Vertex2D));
}
void sprite::Sprite_Draw(int textureId, float dx, float dy,float dw,float dh,int tcx,int tcy,int tcw, int tch) {
LPDIRECT3DDEVICE9 g_pDevice = MYDirect3D_GetDevice();
g_pDevice->SetFVF(FVF_VERTEX2D);
g_pDevice->SetTexture(0, Texture.Texture_GetTexture(textureId));
//テクスチャのサイズ取得
int w = Texture.Texture_GetTextureWidth(textureId);
int h = Texture.Texture_GetTextureHeight(textureId);
//テクスチャ切り取りUV座標
float u0 = (float)tcx / w;
float v0 = (float)tcy / h;
float u1 = (float)(tcx + tcw) / w;
float v1 = (float)(tcy + tch) / h;
Vertex2D v[] = {
{D3DXVECTOR4(dx - 0.5f,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v0)},
{D3DXVECTOR4(dx - 0.5f + dw,dy - 0.5f,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v0)},
{D3DXVECTOR4(dx - 0.5f,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v1)},
{D3DXVECTOR4(dx - 0.5f + dw,dy - 0.5f + dh,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v1)},
};
//ポリゴンを書く(簡易版)
//引数 描画タイプ、数、先頭アドレス,隣の頂点まで何バイト
g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(Vertex2D));
}
//cx.cy 回転拡大の中心座標
//angle ポリゴンの回転角度
void sprite::Sprite_Draw(int textureId, float dx, float dy, float dw, float dh, int tcx, int tcy, int tcw, int tch, float cx, float cy, float angle) {
LPDIRECT3DDEVICE9 g_pDevice = MYDirect3D_GetDevice();
g_pDevice->SetFVF(FVF_VERTEX2D);
g_pDevice->SetTexture(0, Texture.Texture_GetTexture(textureId));
//テクスチャのサイズ取得
int w = Texture.Texture_GetTextureWidth(textureId);
int h = Texture.Texture_GetTextureHeight(textureId);
//テクスチャ切り取りUV座標
float u0 = (float)tcx / w;
float v0 = (float)tcy / h;
float u1 = (float)(tcx + tcw) / w;
float v1 = (float)(tcy + tch) / h;
Vertex2D v[] = {
{D3DXVECTOR4( - 0.5f, - 0.5f ,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v0)},
{D3DXVECTOR4( - 0.5f + dw, - 0.5f ,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v0)},
{D3DXVECTOR4( - 0.5f, - 0.5f + dh ,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u0,v1)},
{D3DXVECTOR4( - 0.5f + dw, - 0.5f + dh ,1.0f,1.0f) ,g_Color,D3DXVECTOR2(u1,v1)},
};
//平行移動行列
D3DXMATRIX mtxTranslationC;//元に戻す
D3DXMatrixTranslation(&mtxTranslationC,-cx,-cy,0.0f);
D3DXMATRIX mtxTranslationI;//移動させる
D3DXMatrixTranslation(&mtxTranslationI, cx + dx, cy + dx, 0.0f);
//回転行列
D3DXMATRIX mtxRotation;
D3DXMatrixRotationZ(&mtxRotation,angle);
//拡大行列
D3DXMATRIX mtxScale;
D3DXMatrixScaling(&mtxScale,1.0f,1.0f,1.0f);
////拡大して回転して平行移動
//行列の合成
D3DXMATRIX mtxWorld;
mtxWorld = mtxTranslationC * mtxRotation * mtxTranslationI;
//座標変換
for (int i = 0; i < 4; i++) {
D3DXVec4Transform(&v[i].Position,&v[i].Position,&mtxWorld);
}
//ポリゴンを書く(簡易版)
//引数 描画タイプ、数、先頭アドレス,隣の頂点まで何バイト
g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(Vertex2D));
}
void sprite::Sprite_Draw_Turn(int textureId, float dx, float dy, float dw, float dh, int tcx, int tcy, int tcw, int tch, float cx, float cy, float angle) {
LPDIRECT3DDEVICE9 g_pDevice = MYDirect3D_GetDevice();
g_pDevice->SetFVF(FVF_VERTEX2D);
g_pDevice->SetTexture(0, Texture.Texture_GetTexture(textureId));
//テクスチャのサイズ取得
int w = Texture.Texture_GetTextureWidth(textureId);
int h = Texture.Texture_GetTextureHeight(textureId);
//テクスチャ切り取りUV座標
float u0 = (float)tcx / w;
float v0 = (float)tcy / h;
float u1 = (float)(tcx + tcw) / w;
float v1 = (float)(tcy + tch) / h;
Vertex2D v[] = {
{D3DXVECTOR4(-0.5f, -0.5f ,1.0f,1.0f),D3DCOLOR_RGBA(255,255,255,255),D3DXVECTOR2(u1,v0)},
{D3DXVECTOR4(-0.5f + dw, -0.5f ,1.0f,1.0f),D3DCOLOR_RGBA(255,255,255,255),D3DXVECTOR2(u0,v0)},
{D3DXVECTOR4(-0.5f, -0.5f + dh ,1.0f,1.0f),D3DCOLOR_RGBA(255,255,255,255),D3DXVECTOR2(u1,v1)},
{D3DXVECTOR4(-0.5f + dw, -0.5f + dh ,1.0f,1.0f),D3DCOLOR_RGBA(255,255,255,255),D3DXVECTOR2(u0,v1)},
};
//平行移動行列
D3DXMATRIX mtxTranslationC;//元に戻す
D3DXMatrixTranslation(&mtxTranslationC, -cx, -cy, 0.0f);
D3DXMATRIX mtxTranslationI;//移動させる
D3DXMatrixTranslation(&mtxTranslationI, cx + dx, cy + dy, 0.0f);
//回転行列
D3DXMATRIX mtxRotation;
D3DXMatrixRotationZ(&mtxRotation, angle);
//拡大行列
D3DXMATRIX mtxScale;
D3DXMatrixScaling(&mtxScale, 1.0f, 1.0f, 1.0f);
////拡大して回転して平行移動
//行列の合成
D3DXMATRIX mtxWorld;
mtxWorld = mtxTranslationC * mtxRotation * mtxTranslationI;
//座標変換
for (int i = 0; i < 4; i++) {
D3DXVec4Transform(&v[i].Position, &v[i].Position, &mtxWorld);
}
//ポリゴンを書く(簡易版)
//引数 描画タイプ、数、先頭アドレス,隣の頂点まで何バイト
g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(Vertex2D));
}
|
cf6348f00288b53b6ccc3aa732fd202085252527
|
1d1555e1ebb20b546dd451e378fbf6d1e1e9db69
|
/light/light.ino
|
7bf7153edab177fc760c43426219136e14ef4a59
|
[] |
no_license
|
jjbohn/arduino-basics
|
3191ef484824be5141833179d801551c9070817d
|
cfc332761682f72ca8680e217692701eac91dc97
|
refs/heads/master
| 2020-04-06T03:33:30.766165
| 2012-06-11T20:42:53
| 2012-06-11T20:42:53
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 688
|
ino
|
light.ino
|
#define LED 9
#define BUTTON 7
int val = 0;
int oldVal = 0;
int state = 0;
int brightness = 128;
unsigned long startTime = 0;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop()
{
val = digitalRead(BUTTON);
if (val == HIGH && oldVal != val) {
state = 1 - state;
startTime = millis();
delay(30);
}
if (val == HIGH && oldVal == val) {
unsigned long duration = millis() - startTime;
if (state == 1 && duration > 250) {
brightness++;
delay(5);
if (brightness >= 255) {
brightness = 0;
}
} else {
brightness = 255;
}
}
oldVal = val;
if (state == 1) {
analogWrite(LED, brightness);
} else {
analogWrite(LED, 0);
}
}
|
31eeb5e8bc103cf34fc90b90b9e3a9f65ced13ee
|
0eff74b05b60098333ad66cf801bdd93becc9ea4
|
/second/download/CMake/CMake-gumtree/Kitware_CMake_repos_basic_block_block_661.cpp
|
47f138f8f6e35ab42c02d94ed6394c08699cec79
|
[] |
no_license
|
niuxu18/logTracker-old
|
97543445ea7e414ed40bdc681239365d33418975
|
f2b060f13a0295387fe02187543db124916eb446
|
refs/heads/master
| 2021-09-13T21:39:37.686481
| 2017-12-11T03:36:34
| 2017-12-11T03:36:34
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 285
|
cpp
|
Kitware_CMake_repos_basic_block_block_661.cpp
|
{
fpos_t p;
fgetpos(f, &p);
if (fread(b, 1, 2, f) == 2 && b[0] == 0 && b[1] == 0) {
return cmListFileLexer_BOM_UTF32LE;
}
if (fsetpos(f, &p) != 0) {
return cmListFileLexer_BOM_Broken;
}
return cmListFileLexer_BOM_UTF16LE;
}
|
53eb98033451ddacfc33174785159f99a4d45060
|
f9798f58a53495ebb3ffe541debae69a31c6cfc9
|
/grafDFSrecur.cpp
|
108c180561645663e6ec19d2316e889c94c32c49
|
[] |
no_license
|
danziss/Algorytmy-zadania
|
99ee45157a613581ca2798039cf54b59c4972d6c
|
0f9a4524bf15838cc74ae93213d86e2685536551
|
refs/heads/master
| 2022-09-30T04:59:00.096344
| 2020-05-31T00:08:46
| 2020-05-31T00:08:46
| 268,178,046
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,631
|
cpp
|
grafDFSrecur.cpp
|
#include <cstdio>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
//wersja nieskierowany
//wierzchołki to inty od 0 do N
class Graf{
private:
int N;
std::vector<std::vector<int>> adjList;
public:
Graf(int maxSize){
N = maxSize;
adjList.resize(N);
}
void addEdge(int v1, int v2){
adjList[v1].push_back(v2);
}
void print();
void DFSRecursion(int s);
void dfsUtil(int s, bool visited[]);
};
void Graf::print(){
std::cout << "Lista sąsiadów grafu: \n";
for (int i = 0; i < adjList.size(); i++){
std::cout << "Wierzchołek " << i << ":\n";
for (int j = 0; j < adjList[i].size(); j++){
std::cout << " -> " << adjList[i][j];
}
std::cout << "\n";
}
}
void Graf::dfsUtil(int s, bool visited[]){
visited[s] = true;
int check = 0;
std::cout << s << "->";
for (int i = 0; i < adjList[s].size(); i++){
check = adjList[s][i];
if (!visited[check])
dfsUtil(check, visited);
}
}
void Graf::DFSRecursion(int s){
std::cout<<"DFS Rekurencja od wierzcholka " << s <<":\n";
bool *visited = new bool[N];
for (int i = 0; i < N; i++){
visited[i] = false;
}
dfsUtil(s, visited);
std::cout << "\n";
}
int main (){
Graf g(6);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 3);
g.addEdge(1, 4);
g.addEdge(2, 3);
g.addEdge(2, 5);
g.addEdge(3, 0);
g.addEdge(4, 3);
g.print();
g.DFSRecursion(0);
return 0;
}
|
7ff22bee20579d31998735c0f1b30e2fe01b3ccd
|
a1865c0aa83e961430b39bebbb3c28d947606dee
|
/DungeonCrawler/Bitmap.h
|
2bb27384e579ebf9ce7110eab5949648e495ade3
|
[] |
no_license
|
Istinra/dungeon-crawler
|
371a0fccab425750d943acbe82782c8dbb64a755
|
bcf9afb3286d0b42fbad05260378197e999ed934
|
refs/heads/master
| 2021-01-18T14:03:08.415865
| 2014-03-15T07:10:17
| 2014-03-15T07:10:17
| 16,509,051
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 696
|
h
|
Bitmap.h
|
//
// Graphics.h
// DungeonCrawler
//
// Created by Samuel Hands on 14/12/2013.
// Copyright (c) 2013 Sam. All rights reserved.
//
#ifndef DungeonCrawler_Bitmap_h
#define DungeonCrawler_Bitmap_h
class Bitmap
{
public:
Bitmap(unsigned int height, unsigned int width);
Bitmap(unsigned int height, unsigned int width, unsigned int *data, bool cleanUp);
virtual ~Bitmap();
inline unsigned int const *Pixels() const
{
return pixels;
};
inline int Height() const
{
return height;
};
inline int Width() const
{
return width;
};
protected:
const bool cleanUp;
int height, width;
unsigned int *pixels;
};
#endif
|
fb51faf9ca8eb919f1bfc123ddfc750a84ff4c02
|
2a5b3545d937445ea28f43848762148e7d46f295
|
/tachecomposite.h
|
9e3c6fa47b56ca856c440f606dba69069f328215
|
[] |
no_license
|
TheFump/ProjetQT
|
7f76c4ebf6f995585683ece60d3f924a5f5ac208
|
ac638acec63922f8da1db74c9f4b89fd076326ac
|
refs/heads/master
| 2016-09-05T13:58:40.617722
| 2015-06-14T15:01:41
| 2015-06-14T15:01:41
| 37,214,170
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 785
|
h
|
tachecomposite.h
|
#ifndef TACHECOMPOSITE_H
#define TACHECOMPOSITE_H
#include <QString>
#include <QStringList>
#include "taches.h"
class TacheComposite: public Tache
{
friend class TacheManager;
private:
Tache** tabSousTache;
unsigned int nb;
unsigned int nbMax;
void addTache(Tache& t);
public:
TacheComposite(const QString& id,const QString& t, const QDate& dispo, const QDate& deadline):Tache(id,t,dispo,deadline),tabSousTache(0),nb(0),nbMax(0) {}
~TacheComposite() { Tache::~Tache(); delete[] tabSousTache; }
void ajouterContraintePrecedance(Tache& t);
Tache& trouverSousTache (const QString& t);
void ajouterSousTache(QStringList& chemin, Tache& t);
Iterator getIteratorComposite() { return Iterator(tabSousTache,nb); }
};
#endif // TACHECOMPOSITE_H
|
dbc25f1492a56ebb401dedf80e80faf7edb0ce9c
|
6c6f58124fe1a7e43775e4a95c358f7959f25c04
|
/Hashing/UncommonCharacters.cpp
|
20f53927760d56a4c531a263f589e241ada755d8
|
[] |
no_license
|
gargdev/GFG-Must-Do-Coding-Questions
|
09174d01a00baeb9dd21f25f7cbc1d6f39ff4f6e
|
1cbad0ef29343fe24cc6fc7ece7c936c262ad3e4
|
refs/heads/master
| 2023-08-02T15:04:09.838415
| 2021-09-29T11:46:36
| 2021-09-29T11:46:36
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 992
|
cpp
|
UncommonCharacters.cpp
|
// { Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
string UncommonChars(string A, string B)
{
// code here
int map1[26] = {0};
int map2[26] = {0};
for(char c : A)
map1[c - 'a']++;
for(char c : B)
map2[c - 'a']++;
string res = "";
for(int i = 0 ; i < 26 ; i++)
{
if(map1[i] != 0 && map2[i] == 0)
res += (i + 'a');
else if(map1[i] == 0 && map2[i] != 0)
res += (i + 'a');
}
return res.length() ? res : "-1";
}
};
// { Driver Code Starts.
int main()
{
int t;
cin>>t;
while(t--)
{
string A,B;
cin>>A;
cin>>B;
Solution ob;
cout<<ob.UncommonChars(A, B);
cout<<endl;
}
return 0;
} // } Driver Code Ends
|
f639ba9b31a031f3e3ba6f67bff5e8ec28276a6b
|
18aa2fc900f95084c5e256f9c1b97adecc0beb2d
|
/lib/Node.h
|
3fbf8e27dd03d48d069b84433887885eb7cc9170
|
[] |
no_license
|
sushuiyuzhou/mai
|
8aace03b5468a7aecabb1e0367687887fe8be6c4
|
9bc69324769dc5ed40768779dee0b5cc72b127c2
|
refs/heads/master
| 2023-01-01T10:22:40.816807
| 2020-06-02T20:55:18
| 2020-06-02T20:55:18
| 258,140,127
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,957
|
h
|
Node.h
|
//
// Created by suhuiyuzhou on 26/05/2020.
//
#ifndef MAI_NODE_H
#define MAI_NODE_H
#include "Context.h"
#include "Index.h"
#include "utils.h"
#include <typeinfo>
#include <filesystem>
#include <fstream>
namespace mai {
class Context;
class Graph;
template<typename T>
struct IsSerializable {
static constexpr bool value = true;
};
class ResouceBase {
public:
virtual void Serialize(Index const&) { };
virtual void Deserialize(Index const&) { };
virtual ~ResouceBase() = default;
virtual void print(std::ostream& os) const = 0;
};
template<typename T,
typename = std::enable_if_t<IsSerializable<T>::value, void>>
class Resource : public ResouceBase {
public:
explicit Resource(T&& r)
:_r(std::forward<T>(r))
{
getLogger(log_level::DEBUG).log("constructing resource with: ", r);
}
void print(std::ostream& os) const override
{
os << _r << std::endl;
}
void Serialize(Index const& ind) override
{
auto p = std::filesystem::path(mai::g_root_dir)/ind.to_string();
std::ofstream os{p};
if (!os.is_open()) {
throw std::runtime_error(std::string("file not opened: ")+p.string());
}
os << _r;
}
void Deserialize(Index const& ind) override
{
auto p = std::filesystem::path(mai::g_root_dir)/ind.to_string();
std::ifstream is{p};
if (!is.is_open()) {
throw std::runtime_error(std::string("file not opened: ")+p.string());
}
is >> _r;
}
// ~Resource() override = default;
~Resource() override
{
getLogger(log_level::DEBUG).log("remove resource: ", _r);
}
private:
T _r;
};
using ResourcePtr = std::shared_ptr<ResouceBase>;
class Node;
using NodePtr = std::shared_ptr<Node>;
class Node {
public:
using Children = std::vector<NodePtr>;
explicit Node(Index sym, Index prefix = Index{});
~Node();
Index path() const
{
return std::move(_prefix+_sym); // + returns a new Index object
}
// setter and getter for content
template<typename T>
void set(T&& t)
{
auto ctn = std::make_shared<Resource<T>>(std::forward<T>(t));
registerResource(ctn);
}
ResourcePtr get() const;
template<typename T>
void operator=(T&& t)
{
set(std::forward<T>(t));
}
Node& attach(Index sym);
template<typename... Args>
Node& attach(Args... args)
{
return attach(Index(std::forward<Args>(args)...));
}
friend std::ostream& operator<<(std::ostream& os, Node const& node);
private:
void registerResource(ResourcePtr ptr) const;
private:
Index _prefix, _sym;
Context& _cxt;
Graph& _graph;
};
}
#endif //MAI_NODE_H
|
54c85c71abb6e06f10effc0dc1248efa2867aabe
|
7f56794370174fc8f5275593a6302e6db692bc60
|
/include/VolatilitySort.h
|
44133f70c734f7da4f41b813661244bf66ef1425
|
[
"BSD-3-Clause"
] |
permissive
|
bloomtime/streamgraph_generator
|
5a1584055bc4704ac7c98c7f66badda0a8c643e3
|
ad19f8ec32a16bff33d0c3691f927e0d02086a29
|
refs/heads/master
| 2021-01-18T08:47:57.685368
| 2012-05-08T19:10:16
| 2012-05-08T19:10:16
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 972
|
h
|
VolatilitySort.h
|
#pragma once
#include "LayerSort.h"
#include "VolatilityComparator.h"
/**
* VolatilitySort
* Sorts an array of layers by their volatility, placing the most volatile
* layers along the outsides of the graph, thus minimizing unneccessary
* distortion.
*
* First sort by volatility, then creates a 'top' and 'bottom' collection.
* Iterating through the sorted list of layers, place each layer in whichever
* collection has less total mass, arriving at an evenly weighted graph.
*
* @author Lee Byron
* @author Martin Wattenberg
*/
class VolatilitySort : public LayerSort {
public:
static LayerSortRef create() {
return LayerSortRef(new VolatilitySort());
}
std::string getName() {
return "Volatility Sorting, Evenly Weighted";
}
void sort(LayerRefVec& layers) {
// first sort by volatility
std::sort(layers.begin(), layers.end(), VolatilityComparator(true));
orderToOutside(layers);
}
private:
VolatilitySort() {}
};
|
dd2e3e5962806d0a1e513987b22848b9c974160d
|
012712451c82f5e2e8d5ce1fd93247713760884c
|
/ConverterFactoryPlugin/int/signed/IntToDoubleConverter.cpp
|
7573ab6f127d54219204aa33efa195ef0999603f
|
[] |
no_license
|
gbumgard/QObjectGraphEditor
|
735b29178d7928ef8a14f13c42e42aa1d737c506
|
2fde592a20830362504d4c1662dccab352e62885
|
refs/heads/master
| 2023-05-01T00:11:40.635181
| 2023-04-18T04:02:35
| 2023-04-18T04:02:35
| 265,347,674
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 194
|
cpp
|
IntToDoubleConverter.cpp
|
#include "IntToDoubleConverter.h"
#include "ConverterFactoryPlugin.h"
REGISTER_CLASS(IntToDoubleConverter)
IntToDoubleConverter::IntToDoubleConverter(QObject *parent)
: QObject(parent)
{
}
|
018083fe183538034cf999db9e7548bcaf9c9424
|
4ce229882610ebf1371b962e4e9655a0a89167a2
|
/XMLDocument.hpp
|
f95580dec5be240134ecac40ff32647b24942a67
|
[] |
no_license
|
JordiFSM/PP2-DATAESTRUCT
|
d0fb50c70c6e8862822cadd3b3cef53161ab8d75
|
11028cfb063b78e6500132051bd33a518b837161
|
refs/heads/main
| 2023-01-08T14:44:52.998232
| 2020-11-13T23:35:38
| 2020-11-13T23:35:38
| 308,115,060
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,390
|
hpp
|
XMLDocument.hpp
|
#include "tree.hpp"
#include "utilitarios.hpp"
class XMLDocument {
private:// Function operating modes, use the constant names and not the values in the code
const int ADD = 100; // Mode addition, adds the value to the beginning of the set
// as allowed by the specific function (with or without repetition)
const int OVR = 200; // Mode overwrite, if it already exists, replaces the value, if not, just add it.
const int APD = 300; // Mode append, appends the value to the end of the set as
// allowed by the specific function (with or without repetition)
const int DEL = 400; // Mode delete, if the value exists, it is deleted instead
// Node content location type
const int BEG = 10; // Content is displayed before children of node, just after the opening tag.
const int END = 20; // Content is displayed after children of node, just before the closing tag.
tree *ptree;
// Public functions
public:
XMLDocument();
int Root (char *name);
bool Select (int id);
int Child (char *name);
int Child (char *name, char *content);
bool EditAttribute (char *key, char *value, int mode);
bool EditContent (char *content, int mode);
bool SwitchContentPosition ();
bool SetBalanced ();
bool Delete ();
char* ViewTree ();
char* ViewNode ();
char* ViewXML ();
bool Save (char *filename);
};
|
b8c5fb71249fe620328ae7a68b75aaa25ed5fd33
|
e30131d9939b3eaacc79e6b41c9e1b172da4a8a4
|
/proxy/include/udt/NatSocket.h
|
7e45e69cb57c33ad16511679229f8e8b072003e1
|
[] |
no_license
|
ashevchuk/proxy
|
5cf2772407a8284bd1c8d28e83baece4f8ce0ddc
|
200f55c45c3aa8a95d15d70cb1d2ddcb725100b5
|
refs/heads/master
| 2021-04-22T00:01:21.144935
| 2014-10-09T09:52:11
| 2014-10-09T09:52:11
| null | 0
| 0
| null | null | null | null |
GB18030
|
C++
| false
| false
| 2,732
|
h
|
NatSocket.h
|
// NatSocket.h: interface for the NatSocket type.
//
//////////////////////////////////////////////////////////////////////
#ifndef _NAT_SOCKET_H_
#define _NAT_SOCKET_H_
#include "NatUserDefine.h"
#include <set>
typedef void* NatSocket;
#define NAT_SOCKET_INVALID NULL
typedef std::set<NatSocket> NatSocketSet;
/**
* NAT客户端错误
*/
enum NAT_CLIENT_ERROR
{
NAT_CLI_OK = 0, // 成功
NAT_CLI_ERR_UNKNOWN, // 未知错误
NAT_CLI_ERR_TIMEOUT, // 客户端超时
NAT_CLI_ERR_DEVICE_OFFLINE, // 设备不在线
NAT_CLI_ERR_SERVER_OVERLOAD, // 服务器负载过重,无法再提供服务
NAT_CLI_ERR_DEVICE_NO_RELAY, // 设备不支持中继通信功能
NAT_CLI_ERR_SYS, // 系统错误
NAT_CLI_ERR_NETWORK // 网络错误
};
/**
* NAT客户端状态
*/
enum NAT_CLIENT_STATE
{
NAT_CLI_STATE_INIT = 0, // 本地系统出错
NAT_CLI_STATE_P2P_SERVER, // P2P穿透模式下,与服务器通信的过程
NAT_CLI_STATE_P2P_DEVICE, // P2P穿透模式下,与设备通信的过程
NAT_CLI_STATE_RELAY_SERVER, // RELAY模式下,与服务器通信的过程
NAT_CLI_STATE_RELAY_DEVICE, // RELAY模式下,与设备通信的过程
};
const char* NAT_GetClientErrorText(NAT_CLIENT_ERROR error);
typedef struct _nat_socket_info_
{
unsigned long remoteIp;
unsigned short remotePort;
}NAT_SOCKET_INFO;
/**
* NAT模块的初始化,需要在程序开始运行时调用
* 非线程安全
*/
int NAT_Init();
/**
* NAT模块的终止化,释放NAT模块所占用的全局资源,需要在程序结束运行时调用
* 非线程安全
*/
int NAT_Quit();
int NAT_CloseSocket(NatSocket sock);
int NAT_GetSocketInfo(NatSocket sock, NAT_SOCKET_INFO &info);
int NAT_Select(NatSocketSet *readSet, NatSocketSet *writeSet, int iTimeout);
int NAT_Send(NatSocket sock, const void *pBuf, int iLen);
int NAT_Recv(NatSocket sock, void *pBuf, int iLen);
/**
* 获取当前可以发送数据的字节大小
* @return 如果没有错误,则返回当前可以发送数据的字节大小,0表示发送缓冲区满了;否则,出错返回-1
*/
int NAT_GetSendAvailable(NatSocket sock);
/**
* 获取可以接收数据的字节大小,主要用于主动接收数据
* @return 如果没有错误,则返回当前可以接收数据的字节大小,0表示无数据;否则,出错返回-1
*/
int NAT_GetRecvAvailable(NatSocket sock);
bool NAT_IsSocketInSet(NatSocket sock, NatSocketSet *socketSet);
void NAT_EraseSocketFromSet(NatSocket sock, NatSocketSet *socketSet);
void NAT_InsertSocketToSet(NatSocket sock, NatSocketSet *socketSet);
#endif//_NAT_SOCKET_H_
|
269889dc28ec85e8c2c73b444ad17ed937489bff
|
9c2ed0c83f234e64dc3a70078b6682d82954dc93
|
/Biquadris/level0.cc
|
cdc6ff6a7a75d7639818a91402bd418fdfd8f63b
|
[] |
no_license
|
XinhaoGeUW/MyProjects
|
2a0e29a544b2cc166b6558d3dac03d317664020d
|
146779bc5a792d4b891b965f2ac063b92ff27253
|
refs/heads/master
| 2022-12-17T16:15:34.412295
| 2020-09-20T20:29:54
| 2020-09-20T20:29:54
| 297,136,899
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 358
|
cc
|
level0.cc
|
#include "level0.h"
#include "Command.h"
#include "lowerlevel.h"
using namespace std;
Level0::Level0(string file): blocks {ifstream (file)} {}
char Level0::createnext(int ID) {
char c;
blocks >> c;
return c;
}
Command *Level0::createCommand() {
Command *a = new lowerlevel();
return a;
}
void Level0::num_move(Board *) {}
Level0::~Level0() {}
|
853f5fb974dc1c5c970457c36d9a5be4dd0638d6
|
71157bf5a13bd285400cc32c6e551adfcc53ea7d
|
/Server.tproj/XServer.cpp
|
7050134986b4b017cce038d5bf2d3327359d22cf
|
[] |
no_license
|
stoaven/XServer
|
16c130acdc078810484ff0a2f2eccdf67173a25d
|
937b9f863923c03c317059489f96ee48957685c4
|
refs/heads/master
| 2021-05-28T20:40:18.582076
| 2015-04-23T14:08:50
| 2015-04-23T14:08:50
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 6,579
|
cpp
|
XServer.cpp
|
#include <stdarg.h>
#include <sys/mman.h>
#include "OS.h"
#include "Queue.h"
#include "Packet.h"
#include "XServer.h"
#include "SocketUtils.h"
#include "EventContext.h"
#include "NetStream.h"
XServer* XServer::sServer = NULL;
XServer::XServer()
: fServerState(kStartingUpState),
fDefaultIPAddr(0),
fSigInt(false),
fSigTerm(false),
fDebugLevel(0),
fMaxObserver(0),
fNumThreads(0),
fNumListeners(0),
fNumShortThreads(0),
fNumBlockingThreads(0),
fMaxConnections(0),
fMessagePort(0),
fAudioPort(0),
fVideoPort(0),
fMessagePacketSize(128),
fMaxMessagePackets(10),
fAudioPacketSize(1024),
fMaxAudioPackets(10),
fVideoPacketSize(40960),
fMaxVideoPackets(5),
fKeepAliveInMilSec(0),
fSynTimeIntervalMilSec(0),
fNumMessageSession(0),
fNumAudioSession(0),
fNumVideoSession(0),
fProcessNum(0),
fWebPort(0),
fStartupTime_UnixMilli(0),
fGMTOffset(0),
fErrorLog(NULL),
fMessageListener(NULL)
{
memset(fWebIP, 0 , kIPSize);
memset(fServerID, 0, kServerIDSize);
memset(fLogPath, 0, kFilePathSize);
sServer = this;
};
XServer::~XServer()
{
if (fMessageListener)
{
fMessageListener->Cleanup();
delete fMessageListener;
fMessageListener = NULL;
}
};
bool XServer::Initialize(ConfigPrefsParser *inConfigPrefsParser, UInt16 inPort, bool createListeners)
{
fServerState = kFatalErrorState;
fNumShortThreads = inConfigPrefsParser->GetShortTaskThreadsNum();
fNumBlockingThreads = inConfigPrefsParser->GetBlockingThreadsNum();
fMaxConnections = inConfigPrefsParser->GetMaxConnections();
fMessagePort = inConfigPrefsParser->GetMessagePort();
fAudioPort = inConfigPrefsParser->GetAudioPort();
fVideoPort = inConfigPrefsParser->GetVideoPort();
fMessagePacketSize = inConfigPrefsParser->GetMessagePacketSize();
fMaxMessagePackets = inConfigPrefsParser->GetMaxMessagePackets();
fAudioPacketSize = inConfigPrefsParser->GetAudioPacketSize();
fMaxAudioPackets = inConfigPrefsParser->GetMaxAudioPackets();
fVideoPacketSize = inConfigPrefsParser->GetVideoPacketSize();
fMaxVideoPackets = inConfigPrefsParser->GetMaxVideoPackets();
fKeepAliveInMilSec = inConfigPrefsParser->GetKeepAlive() * 1000;
fSynTimeIntervalMilSec = inConfigPrefsParser->GetSynchronizeTime() * 1000;
fProcessNum = inConfigPrefsParser->GetProcessNum();
fWebPort = inConfigPrefsParser->GetWebPort();
fMaxObserver = inConfigPrefsParser->GetMaxObserver();
strncpy(fWebIP, inConfigPrefsParser->GetWebIP(), kIPSize);
strncpy(fServerID, inConfigPrefsParser->GetServerID(), kServerIDSize);
strncpy(fLogPath, inConfigPrefsParser->GetLogPath(), kFilePathSize);
printf("fNumShortThreads = %u\n", fNumShortThreads);
printf("fNumBlockingThreads = %u\n", fNumBlockingThreads);
printf("fMaxConnections = %u\n", fMaxConnections);
printf("fMessagePort = %hu\n", fMessagePort);
printf("fAudioPort = %hu\n", fAudioPort);
printf("fVideoPort = %hu\n", fVideoPort );
printf("fMessagePacketSize = %u\n", fMessagePacketSize);
printf("fMaxMessagePackets = %u\n", fMaxMessagePackets);
printf("fAudioPacketSize = %u\n", fAudioPacketSize);
printf("fMaxAudioPackets = %u\n", fMaxAudioPackets);
printf("fVideoPacketSize = %u\n", fVideoPacketSize);
printf("fMaxVideoPackets = %u\n", fMaxVideoPackets);
printf("fKeepAliveInMilSec = %u\n", fKeepAliveInMilSec);
printf("fSynTimeIntervalMilSec = %u\n", fSynTimeIntervalMilSec);
printf("fProcessNum = %u\n", fProcessNum);
printf("fWebPort = %hu\n", fWebPort);
printf("fMaxObserver = %u\n", fMaxObserver);
printf("fWebIP = %s\n", fWebIP);
printf("fServerID = %s\n", fServerID);
printf("fLogPath = %s\n", fLogPath);
//
// SETUP ASSERT BEHAVIOR
//
// Depending on the server preference, we will either break when we hit an
// assert, or log the assert to the error log
// DEFAULT IP ADDRESS & DNS NAME
if (!this->SetDefaultIPAddr())
return false;
fStartupTime_UnixMilli = OS::Milliseconds();
fGMTOffset = OS::GetGMTOffset();
//
// BEGIN LISTENING
if (createListeners)
{
this->CreateListeners(true, inPort);
}
if (fNumListeners < 1)
return false;
fServerState = kStartingUpState;
return true;
}
bool XServer::SetDefaultIPAddr()
{
//check to make sure there is an available ip interface
if (SocketUtils::GetNumIPAddrs() == 0)
return false;
//find out what our default IP addr is & dns name
fDefaultIPAddr = SocketUtils::GetIPAddr(0);
return true;
}
bool XServer::CreateListeners(bool startListeningNow, UInt16 inPort)
{
if (fMessageListener == NULL)
{
fMessageListener = new MessageListenerSocket;
int err = fMessageListener->Initialize(INADDR_ANY, fMessagePort);
//
// If there was an error creating this listener, destroy it and log an error
if ((startListeningNow) && (err != 0))
delete fMessageListener;
if (err == EADDRINUSE)
printf("EADDRINUSE\n");
else if (err == EACCES)
printf("EACCES\n");
else if (err != 0)
printf("ERROR\n");
else
{
//
// This listener was successfully created.
if (startListeningNow)
fMessageListener->RequestEvent(EV_RE, 0);
fNumListeners++;
}
}
return (fNumListeners >= 1);
}
void XServer::StartTasks()
{
if (fMessageListener) fMessageListener->RequestEvent(EV_RE, 0);
fServerState = kStartingUpState;
}
bool XServer::SwitchPersonality()
{
return true;
}
int XServer::WriteLog(const char* fmt, ...)
{
MutexLocker theLocker(&fMutex);
Log *theLog = XServer::GetServer()->GetLog();
char theLogData[kLogDataSize];
va_list args;
::va_start(args, fmt);
int result = ::vsprintf(theLogData, fmt, args);
::va_end(args);
theLog->LogInfo(theLogData);
#if XSERVER_DEBUG
printf("%s\n", theLogData);
#endif
return result;
}
|
2da929f929fc6edaa618061b99322e4feeeb752d
|
e18f2a5d34a0a1d27afb20e743827f39f62edb6c
|
/src/chipKITMax32_ArduinoDue.cpp
|
a54ba51ea82d3e2fc141ee24dab414d6229b24a0
|
[] |
no_license
|
kyab/mruby-arduino
|
caebc5e8783d35a24327af47669318dd09e6d510
|
70db8f383e902c853cb83a6801f7530ae09bd41a
|
refs/heads/master
| 2021-01-19T06:37:01.568955
| 2014-09-02T14:29:54
| 2014-09-02T14:29:54
| 8,029,465
| 41
| 6
| null | 2013-11-26T13:02:53
| 2013-02-05T13:23:49
|
C++
|
UTF-8
|
C++
| false
| false
| 10,250
|
cpp
|
chipKITMax32_ArduinoDue.cpp
|
#include "mruby-arduino.h"
#ifdef MRUBY_ARDUINO_BOARD_CHIPKIT_OR_DUE
#include <new>
#include "mruby.h"
#include "mruby/class.h"
#include "mruby/string.h"
#include "mruby/data.h"
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#if defined(__SAM3X8E__) //Arduino IDE
#include <Servo.h>
#else
#include <Servo/Servo.h>
#endif
mrb_value mrb_serial_available(mrb_state *mrb, mrb_value self){
return mrb_fixnum_value(Serial.available());
}
mrb_value mrb_serial_begin(mrb_state *mrb, mrb_value self){
mrb_int speed = 0;
mrb_get_args(mrb,"i",&speed);
Serial.begin(speed);
return mrb_nil_value();
}
mrb_value mrb_serial_println(mrb_state *mrb, mrb_value self){
mrb_value s;
mrb_get_args(mrb,"S", &s);
for (int i = 0; i < RSTRING_LEN(s); i++){
Serial.print( RSTRING_PTR(s)[i] );
}
Serial.println("");
return mrb_nil_value();
}
void mrb_servo_free(mrb_state *mrb, void *ptr){
Servo *servo = (Servo *)ptr;
servo->~Servo();
mrb_free(mrb, servo);
}
struct mrb_data_type mrb_servo_type = {"Servo", mrb_servo_free};
mrb_value mrb_servo_initialize(mrb_state *mrb, mrb_value self){
void *p = mrb_malloc(mrb, sizeof(Servo));
Servo *newServo = new(p) Servo();
DATA_PTR(self) = newServo;
DATA_TYPE(self) = &mrb_servo_type;
return self;
}
mrb_value mrb_servo_attach(mrb_state *mrb, mrb_value self){
Servo *servo = (Servo *)mrb_get_datatype(mrb, self, &mrb_servo_type);
mrb_int pin = 0;
mrb_get_args(mrb, "i", &pin);
servo->attach(pin);
return mrb_nil_value();
}
mrb_value mrb_servo_write(mrb_state *mrb, mrb_value self){
Servo *servo = (Servo *)mrb_get_datatype(mrb, self, &mrb_servo_type);
mrb_int angle = 0;
mrb_get_args(mrb, "i", &angle);
servo->write(angle);
return mrb_nil_value();
}
mrb_value mrb_servo_detach(mrb_state *mrb, mrb_value self){
Servo *servo = (Servo *)mrb_get_datatype(mrb, self, &mrb_servo_type);
servo->detach();
return mrb_nil_value();
}
mrb_value mrb_arduino_pinMode(mrb_state *mrb, mrb_value self){
mrb_int pin, mode;
mrb_get_args(mrb, "ii", &pin, &mode);
pinMode(pin, mode);
return mrb_nil_value();
}
mrb_value mrb_arduino_digitalWrite(mrb_state *mrb, mrb_value self){
mrb_int pin, value;
mrb_get_args(mrb, "ii", &pin, &value);
digitalWrite(pin, value);
return mrb_nil_value();
}
mrb_value mrb_arduino_digitalRead(mrb_state *mrb, mrb_value self){
mrb_int pin;
mrb_get_args(mrb, "i", &pin);
int val = digitalRead(pin);
return mrb_fixnum_value(val);
}
mrb_value mrb_arduino_analogReference(mrb_state *mrb, mrb_value self){
mrb_int type;
mrb_get_args(mrb, "i", &type);
#if defined(MPIDE)
analogReference(type);
#else
analogReference((eAnalogReference)type);
#endif
return mrb_nil_value();
}
mrb_value mrb_arduino_analogWrite(mrb_state *mrb, mrb_value self){
mrb_int pin, value;
mrb_get_args(mrb, "ii", &pin, &value);
analogWrite(pin, value);
return mrb_nil_value();
}
mrb_value mrb_arduino_analogRead(mrb_state *mrb, mrb_value self){
mrb_int pin;
mrb_get_args(mrb, "i", &pin);
int val = analogRead(pin);
return mrb_fixnum_value(val);
}
#if defined(MPIDE)
mrb_value mrb_arduino_tone(mrb_state *mrb, mrb_value self){
mrb_int pin, frequency, duration;
mrb_int n = mrb_get_args(mrb, "ii|i", &pin, &frequency, &duration);
if (n == 2){
tone(pin, frequency);
}else if(n == 3){
tone(pin, frequency, duration);
}
return mrb_nil_value();
}
mrb_value mrb_arduino_noTone(mrb_state *mrb, mrb_value self){
mrb_int pin;
mrb_get_args(mrb, "i", &pin);
noTone(pin);
return mrb_nil_value();
}
#endif
mrb_value mrb_arduino_shiftOut(mrb_state *mrb, mrb_value self){
mrb_int dataPin, clockPin, bitOrder, value;
mrb_get_args(mrb, "iiii", &dataPin, &clockPin, &bitOrder, &value);
shiftOut(dataPin, clockPin, bitOrder, (byte)value);
return mrb_nil_value();
}
#if defined(MPIDE) && MPIDE <= 23
//seems like MPIDE does not define shiftIn.
extern uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
#endif
mrb_value mrb_arduino_shiftIn(mrb_state *mrb, mrb_value self){
mrb_int dataPin, clockPin, bitOrder;
mrb_get_args(mrb, "iii", &dataPin, &clockPin, &bitOrder);
return mrb_fixnum_value(shiftIn(dataPin, clockPin, bitOrder));
}
mrb_value mrb_arduino_pulseIn(mrb_state *mrb, mrb_value self){
mrb_int pin, value, timeout;
mrb_int n = mrb_get_args(mrb, "ii|i", &pin, &value, &timeout);
unsigned long ret = 0;
if (n == 2){
ret = pulseIn(pin, value);
}else if (n == 3){
ret = pulseIn(pin, value, timeout);
}
return mrb_fixnum_value(ret);
}
mrb_value mrb_arduino_millis(mrb_state *mrb, mrb_value self){
return mrb_fixnum_value(millis());
}
mrb_value mrb_arduino_micros(mrb_state *mrb, mrb_value self){
return mrb_fixnum_value(micros());
}
mrb_value mrb_arduino_delay(mrb_state *mrb, mrb_value self){
mrb_int ms;
mrb_get_args(mrb, "i", &ms);
delay(ms);
return mrb_nil_value();
}
mrb_value mrb_arduino_delayMicroseconds(mrb_state *mrb, mrb_value self){
mrb_int us;
mrb_get_args(mrb, "i", &us);
delayMicroseconds(us);
return mrb_nil_value();
}
mrb_value mrb_arduino_map(mrb_state *mrb, mrb_value self){
mrb_int value, fromLow, fromHigh, toLow, toHigh;
mrb_get_args(mrb, "iiiii", &value, &fromLow, &fromHigh, &toLow, &toHigh);
mrb_int ret = map(value, fromLow, fromHigh, toLow, toHigh);
return mrb_fixnum_value(ret);
}
mrb_value mrb_arduino_randomSeed(mrb_state *mrb, mrb_value self){
mrb_int seed;
mrb_get_args(mrb, "i", &seed);
randomSeed(seed);
return mrb_nil_value();
}
mrb_value mrb_arduino_random(mrb_state *mrb, mrb_value self){
mrb_int arg1, arg2;
mrb_int n = mrb_get_args(mrb, "i|i", &arg1, &arg2 );
if (n == 1){
return mrb_fixnum_value(random(arg1));
}else{
return mrb_fixnum_value(random(arg1, arg2));
}
}
mrb_value mrb_arduino_interrupts(mrb_state *mrb, mrb_value self){
interrupts();
return mrb_nil_value();
}
mrb_value mrb_arduino_noInterrupts(mrb_state *mrb, mrb_value self){
noInterrupts();
return mrb_nil_value();
}
extern "C"
void
mruby_arduino_init_chipKIT_or_Due(mrb_state* mrb) {
RClass *serialClass = mrb_define_class(mrb, "Serial", mrb->object_class);
mrb_define_class_method(mrb, serialClass, "available", mrb_serial_available, ARGS_NONE());
mrb_define_class_method(mrb, serialClass, "begin",mrb_serial_begin, ARGS_REQ(1));
mrb_define_class_method(mrb, serialClass, "println", mrb_serial_println, ARGS_REQ(1));
RClass *servoClass = mrb_define_class(mrb, "Servo", mrb->object_class);
MRB_SET_INSTANCE_TT(servoClass, MRB_TT_DATA);
mrb_define_method(mrb, servoClass, "initialize", mrb_servo_initialize, ARGS_NONE());
mrb_define_method(mrb, servoClass, "attach", mrb_servo_attach, ARGS_REQ(1));
mrb_define_method(mrb, servoClass, "write", mrb_servo_write, ARGS_REQ(1));
mrb_define_method(mrb, servoClass, "detach", mrb_servo_detach, ARGS_NONE());
RClass *arduinoModule = mrb_define_module(mrb, "Arduino");
mrb_define_module_function(mrb, arduinoModule, "pinMode", mrb_arduino_pinMode, ARGS_REQ(2));
mrb_define_module_function(mrb, arduinoModule, "digitalWrite", mrb_arduino_digitalWrite, ARGS_REQ(2));
mrb_define_module_function(mrb, arduinoModule, "digitalRead", mrb_arduino_digitalRead, ARGS_REQ(1));
mrb_define_module_function(mrb, arduinoModule, "analogReference", mrb_arduino_analogReference, ARGS_REQ(1));
mrb_define_module_function(mrb, arduinoModule, "analogWrite", mrb_arduino_analogWrite, ARGS_REQ(2));
mrb_define_module_function(mrb, arduinoModule, "analogRead", mrb_arduino_analogRead, ARGS_REQ(1));
#if defined(MPIDE)
mrb_define_module_function(mrb, arduinoModule, "tone", mrb_arduino_tone, ARGS_REQ(2) | ARGS_OPT(1));
mrb_define_module_function(mrb, arduinoModule, "noTone", mrb_arduino_noTone, ARGS_REQ(1));
#endif
mrb_define_module_function(mrb, arduinoModule, "shiftOut", mrb_arduino_shiftOut, ARGS_REQ(4));
mrb_define_module_function(mrb, arduinoModule, "shiftIn", mrb_arduino_shiftOut, ARGS_REQ(3));
mrb_define_module_function(mrb, arduinoModule, "pulseIn", mrb_arduino_pulseIn, ARGS_REQ(2) | ARGS_OPT(1));
mrb_define_module_function(mrb, arduinoModule, "millis", mrb_arduino_millis, ARGS_NONE());
mrb_define_module_function(mrb, arduinoModule, "micros", mrb_arduino_micros, ARGS_NONE());
mrb_define_module_function(mrb, arduinoModule, "delay", mrb_arduino_delay, ARGS_REQ(1));
mrb_define_module_function(mrb, arduinoModule, "delayMicroseconds", mrb_arduino_delayMicroseconds, ARGS_REQ(1));
mrb_define_module_function(mrb, arduinoModule, "map", mrb_arduino_map, ARGS_REQ(5));
mrb_define_module_function(mrb, arduinoModule, "randomSeed", mrb_arduino_randomSeed, ARGS_REQ(1));
mrb_define_module_function(mrb, arduinoModule, "random", mrb_arduino_random, ARGS_REQ(1) | ARGS_OPT(1));
mrb_define_module_function(mrb, arduinoModule, "interrupts", mrb_arduino_interrupts, ARGS_NONE());
mrb_define_module_function(mrb, arduinoModule, "noInterrupts", mrb_arduino_noInterrupts, ARGS_NONE());
mrb_define_const(mrb, arduinoModule, "HIGH", mrb_fixnum_value(HIGH));
mrb_define_const(mrb, arduinoModule, "LOW", mrb_fixnum_value(LOW));
mrb_define_const(mrb, arduinoModule, "INPUT", mrb_fixnum_value(INPUT));
mrb_define_const(mrb, arduinoModule, "OUTPUT", mrb_fixnum_value(OUTPUT));
#ifdef INPUT_PULLUP
mrb_define_const(mrb, arduinoModule, "INPUT_PULLUP", mrb_fixnum_value(INPUT_PULLUP));
#endif
#ifdef DEFAULT
mrb_define_const(mrb, arduinoModule, "DEFAULT", mrb_fixnum_value(DEFAULT));
#endif
#ifdef INTERNAL
mrb_define_const(mrb, arduinoModule, "INTERNAL", mrb_fixnum_value(INTERNAL));
#endif
#ifdef EXTERNAL
mrb_define_const(mrb, arduinoModule, "EXTERNAL", mrb_fixnum_value(EXTERNAL));
#endif
//for chipKit, below are not defined.
#ifdef INTERNAL1V1
mrb_define_const(mrb, arduinoModule, "INTERNAL1V1", mrb_fixnum_value(INTERNAL1V1));
#endif
#ifdef INTERNAL2V56
mrb_define_const(mrb, arduinoModule, "INTERNAL2V56", mrb_fixnum_value(INTERNAL2V56));
#endif
#ifdef MSBFIRST
mrb_define_const(mrb, arduinoModule, "MSBFIRST", mrb_fixnum_value(MSBFIRST));
#endif
#ifdef LSBFIRST
mrb_define_const(mrb, arduinoModule, "LSBFIRST", mrb_fixnum_value(LSBFIRST));
#endif
}
#endif /*MRUBY_ARDUINO_CHIPKIT_OR_DUE*/
|
bbbfcf6d36f9df0e51f9ec0a9aa15bf78a504de8
|
dd2da6fb22df2ee2ea57a0e2981c66d20ca8f040
|
/src/main/events/SceneManager.cpp
|
f29bbeb39355b8b28c70e345c4ff58f010bda4a7
|
[] |
no_license
|
annarose2255/Genesis
|
186abdfb9ca958c037af6d78d74798ff53aeb202
|
cf8162d1ed0b2c675f78374cfb5da4344c2d5fb4
|
refs/heads/master
| 2021-01-03T00:33:25.733702
| 2020-04-24T05:06:39
| 2020-04-24T05:06:39
| 239,835,448
| 0
| 0
| null | 2020-04-03T03:33:42
| 2020-02-11T18:33:40
|
C++
|
UTF-8
|
C++
| false
| false
| 15,773
|
cpp
|
SceneManager.cpp
|
#include "SceneManager.h"
#include "Layer.h"
#include "Game.h"
#include "MyGame.h"
#include "SelectionMenu.h"
#include "MenuItem.h"
#include <iostream>
#include <string>
SceneManager::SceneManager(Player* chara, Scene* s)
{
currentS = s;
player = chara;
}
SceneManager::~SceneManager()
{
delete door;
}
void SceneManager::handleEvent(Event* e)
{
if (e->getType() == CHANGE)
{
// Event* event = dynamic_cast<Event*>(event);
MyGame::collisionSystem->clearAllData();
Scene* nextScene = new Scene();
nextScene->loadTileMap(e->getScenePath());
int fromRm = currentS->getSceneNum();
int toRm = nextScene->getSceneNum(); //room numbers of current level and next level
string otherFilepath = "./resources/scenes/Room"+ to_string(toRm) + ".json"; //get filepath for enemies in scene
nextScene->loadScene(otherFilepath);
//load enemies + objects
player = e->getPlayer();
Layer* layer = new Layer();
layer->scrollSpeed = 1;
layer->addChild(player);
nextScene->addChild(layer);
SDL_Point pos;
//determine where to spawn character
if (fromRm > toRm) {
pos = nextScene->charEnd[fromRm];
Game::camera->position.x = nextScene->right;
Game::camera->position.y = nextScene->bottom;
}
else if (fromRm < toRm) {
pos = nextScene->charStart[fromRm];
Game::camera->position.x = nextScene->left;
Game::camera->position.y = nextScene->bottom;
}
player->position.x = pos.x;
player->position.y = pos.y;
nextScene->setPlayer(player);
//set other enemies
//Save prev position & prev scene
prevPos = pos;
prevS = currentS;
// EventDispatcher* ed = e->getSource();
// ed->removeEventListener(this, CHANGE);
currentS = nextScene;
//remove previous scene & re-add new scene
Game::camera->removeImmediateChild(MyGame::currentScene);
MyGame::currentScene = currentS;
Game::camera->addChild(MyGame::currentScene);
MyGame::collisionSystem->watchForCollisions("player", "platform");
MyGame::collisionSystem->watchForCollisions("player", "enemy");
//Tween scene in
Tween* newFade = new Tween(currentS);
TweenableParams alpha;
alpha.name = "alpha";
newFade->animate(alpha, 0, 255, 3);
MyGame::tj->add(newFade);
// ed->addEventListener(this, CHANGE);
}
else if (e->getType() == FIGHT)
{
//add player and enemy turn listeners
//when player finishes a move, move on to enemy turn
Scene* nextScene = new Scene();
nextScene->inBattle = true;
//don't load in character, save it from the previous scene
//set it back in revert
//get Player instead of character??
player = e->getPlayer();
e->getEnemy()->position.x = 400;
e->getEnemy()->position.y = 400;
Layer* layer = new Layer();
layer->scrollSpeed = 1;
layer->addChild(e->getEnemy());
//set action menu
MyGame::actionMenu->getItem(0)->setAction(new Event(ATTACK, MyGame::eDispatcher, player, e->getEnemy()));
MyGame::actionMenu->getItem(3)->setAction(new Event(REVERTBATTLE, MyGame::eDispatcher, player, e->getEnemy()));
MyGame::actionMenu->visible = true;
enemyHP->visible = true;
nextScene->addChild(layer);
nextScene->setPlayer(player);
nextScene->setEnemy(e->getEnemy());
// turnCount++;
SDL_Point pos = {player->position.x, player->position.y};
prevPos = pos;
EventDispatcher* ed = e->getSource();
// ed->removeEventListener(this, CHANGE);
prevS = currentS;
currentS = nextScene;
Game::camera->removeImmediateChild(MyGame::currentScene);
//Transition to scene
MyGame::currentScene = currentS;
Game::camera->addChild(MyGame::currentScene);
prevCam.x = Game::camera->position.x;
prevCam.y = Game::camera->position.y;
Game::camera->position.x = 0; //reset camera position
Game::camera->position.y = 0;
Tween* menuMove = new Tween(MyGame::actionMenu);
Tween* enemyMove = new Tween(MyGame::currentScene->getEnemy());
TweenableParams mfade, emove, egrowX, egrowY;
mfade.name = "alpha";
emove.name = "position.x";
egrowX.name = "scaleX";
egrowY.name = "scaleY";
menuMove->animate(mfade, 0, 255, 5);
enemyMove->animate(emove, 800, MyGame::currentScene->getEnemy()->position.x, 5);
enemyMove->animate(egrowX, MyGame::currentScene->getEnemy()->scaleX, 2.5, 5);
enemyMove->animate(egrowY, MyGame::currentScene->getEnemy()->scaleY, 2.5, 5);
MyGame::tj->add(menuMove);
MyGame::tj->add(enemyMove);
cout << "in fight" << endl;
}
else if (e->getType() == ATTACK){
TextBox* playerturn = new TextBox();
turnCount++;
if (enemyHP->curVal < 10) {
cout << "ENEMY HEALTH DEPLETED"<<endl;
enemyHP->curVal = 0;
MyGame::actionMenu->selectedaitem = false;
MyGame::eDispatcher->dispatchEvent(new Event(DEFEATEDENEMY, MyGame::eDispatcher, player, e->getEnemy()));
cout<<"defeat enemy"<<endl;
enemyDefeated = true;
// break;
//cout<<"selected: "<<MyGame::actionMenu->selectedaitem<<endl;
}
else { //damage
if (jumpAbility == false && (block != true || blockUse == 2) && turnCount >= turnAbilityStop){ //|| abilityUse == 4) && && (lasting == 0 || lasting == 3)){ //check for not block, not jump, and make sure
//actions havent been used in a row too much, and make sure ghost isnt still happening
abilityUse = 0;
blockUse =0;
enemyHP->curVal -= 10;
turnAbilityStop = 0;
playerturn->setText("You attacked! Press SPACE to continue.");
}
else if( turnCount < turnAbilityStop){ //lasting == 1 || lasting == 2 ){
playerturn->setText("You attack goes right through the enemy! Press SPACE to continue.");
}
else if (block == true){
enemyHP->curVal -= 5;
playerturn->setText("You attacked but it isnt very effective. Press SPACE to continue.");
}
else{ //do no damage
playerturn->setText("You attack seems to cause no harm! Press SPACE to continue.");
}
// if (lasting == 2){ //reset lasting
// lasting = 0;
// }
jumpAbility = false;
block = false;
MyGame::actionMenu->enemyTurn = true;
MyGame::actionMenu->selectedaitem = false;
//cout<<"selected: "<<MyGame::actionMenu->selectedaitem<<endl;
}
if (enemyHP->curVal <= 0 && enemyDefeated == false){
enemyHP->curVal = 0;
cout << "ENEMY DEFEATED"<<endl;
enemyHP->curVal = 0;
MyGame::actionMenu->selectedaitem = false;
MyGame::eDispatcher->dispatchEvent(new Event(DEFEATEDENEMY, MyGame::eDispatcher, player, e->getEnemy()));
cout<<"defeat enemy"<<endl;
}
else {
MyGame::actionMenu->visible = false;
if (enemyDefeated == false){
TextBox* playerturn = new TextBox();
playerturn->setText("You attacked! Press SPACE to continue.");
MyGame::currentScene->addChild(playerturn);
}
//MyGame::eDispatcher->dispatchEvent(new Event(ENEMYTURN, MyGame::eDispatcher, e->getPlayer(), e->getEnemy()));
cout<<"player turn over"<<endl;
}
//player turn over
}
else if (e->getType() == ENEMYTURN) {
//if (lasting )
TextBox* enemyattack = new TextBox();
// cout<<"cooldown: "<<cooldown<<endl;
// if (cooldown == 0){ //rest cooldown
// cooldown = 4;
// }
// if (cooldown <= 3){ //decrease cooldown
// cooldown--;
// }
int choose = rand() % 100;
if ( turnAbilityUse > turnCount){// } <= 3 && (choose > 33 && choose <= 66)){ //choose another ability b/c ability is on cooldown
choose = rand() % 100;
if (choose >= 64){
choose = 88;
cout<<"choose block"<<endl;
}
else{
choose = 23;
cout<<"choose attack"<<endl;
}
}
//if (turnAbilityUse )
cout<<choose<<endl;
if (choose <= 33){
//attack
cout<<"use attack"<<endl;
playerHP->curVal-=5;
// if(lasting > 0){ //if the old ability is still lasting,
// lasting++;
// if (lasting == 2){ //if the end of the ability lasting decrease cooldown
// cooldown--;
// }
// }
enemyattack->setText("The enemy attacked back! Press C to continue.");
MyGame::currentScene->addChild(enemyattack);
lastAction = "attack";
}
else if (choose > 33 && choose <= 66){
//use ability
cout<<"use ability"<<endl;
if (lastAction == "ability"){//check for same action in a row
abilityUse ++;
}
else{
abilityUse--;
}
string id = MyGame::currentScene->getEnemy()->id;
id.pop_back();
if (id == "frog"){ //if its a frog use jump
jumpAbility = true;
turnAbilityUse = turnCount + 4;
turnAbilityStop = turnCount+2;
enemyattack->setText("The enemy jumped up high! Press C to continue.");
// if (cooldown <= 4){ //start cooldown
// cooldown--;
// }
}
else if (id == "ghost"){ //if its a ghost
ghostAbility = true;
turnAbilityUse = turnCount+8;
turnAbilityStop = turnCount+4;
// lasting++; //add to duration
// if (lasting == 2){ //if its the end of the duration, start cooldown
// cooldown--;
// }
enemyattack->setText("The enemy is transparent! Press C to continue.");
}
//cout<<id<<endl;
if (abilityUse == 4){ //if abilities has been used 4 times in a row
enemyattack->setText("The enemy tried and failed to use an ability! Press C to continue.");
}
//enemyattack->setText("The enemy used an ability! Press C to continue.");
MyGame::currentScene->addChild(enemyattack);
lastAction = "ability";
}
else{
cout<<"block"<<endl;
block = true;
// if(lasting > 0){ //if we are still seeing how long abilities last, increase lasting
// lasting++;
// }
// if (lasting == 2){ //if its the end of the ability lasting, start cooldown
// cooldown--;
// }
if(lastAction == "block"){ //check for same action in a row
blockUse++;
}
else if (blockUse == 0){
}
else{
blockUse--;
}
cout<<"block use: "<<blockUse<<endl;
if (blockUse >= 2){ //if the enemy has tried to use block 3 times in a row
if (blockUse >= 3){ //rest block if over 3 attempts
blockUse = 0;
}
enemyattack->setText("The enemy tried and failed to use block! Press C to continue.");
//blockUse
//blockUse = 0;
}
else{
enemyattack->setText("The enemy blocked! Press C to continue.");
}
MyGame::currentScene->addChild(enemyattack);
lastAction = "block";
}
MyGame::actionMenu->enemyTurn = false;
cout<<"END OF ENEMY TURN"<<endl;
//enemy turn over
//how to remove/change actionMenu??? use the same menu but change the options??
// Game::camera->removeImmediateChild(MyGame::currentScene);
// MyGame::currentScene->removeImmediateChild(enemyattack);
// Game::camera->addChild(MyGame::currentScene);
// MyGame::actionMenu->visible = true;
// MyGame::actionMenu->visible = true;
}
else if (e->getType() == DEFEATEDENEMY) {
cout << "u defeated the enemy!"<< endl;
MyGame::actionMenu->visible = false;
MyGame::actionMenu->decideFate = true;
TextBox* victoryMSG = new TextBox();
victoryMSG->setText("Congrats, you won! Press TAb to decide the enemy's fate.");
victoryMSG->visible = true;
MyGame::currentScene->addChild(victoryMSG);
}
else if (e->getType() == DECIDEFATE) {
cout << "inside decide fate event"<<endl;
MyGame::actionMenu->visible = false;
MyGame::enemyFate->visible = true;
MyGame::enemyFate->getItem(0)->setAction(new Event(SPARE, MyGame::eDispatcher, player, e->getEnemy()));
MyGame::enemyFate->getItem(1)->setAction(new Event(KILL, MyGame::eDispatcher, player, e->getEnemy()));
MyGame::enemyFate->getItem(2)->setAction(new Event(CONSUME, MyGame::eDispatcher, player, e->getEnemy()));
}
else if (e->getType() == SPARE) {
//Same as Revert battle basically
//character stuff
e->setType(REVERTBATTLE);
}
else if (e->getType() == KILL) {
e->setType(REVERTBATTLE);
}
else if (e->getType() == CONSUME) {
e->setType(REVERTBATTLE);
}
else if (e->getType() == REVERT)
{
currentS = prevS;
//if e->getEnemy()->state = "killed" or e->getEnemy()->state = "captured"
//delete currentS->enemy.at(e->getEnemy()->id)
currentS->isBattle = false;
player->position = prevPos;
}
if (e->getType() == REVERTBATTLE)
{
currentS = prevS;
//if e->getEnemy()->state = "killed" or e->getEnemy()->state = "captured"
//delete currentS->enemy.at(e->getEnemy()->id)
currentS->isBattle = false;
player->position = prevPos;
MyGame::actionMenu->visible = false;
MyGame::enemyFate->visible = false;
MyGame::actionMenu->selectInd = 0;
e->getEnemy()->visible = false;
enemyHP->visible = false;
enemyHP->curVal = enemyHP->maxVal;
e->getEnemy()->gameType = "defeated"; //so player doesn't collide with it again
Game::camera->removeImmediateChild(MyGame::currentScene);
MyGame::currentScene = currentS;
Game::camera->addChild(MyGame::currentScene);
Game::camera->position.x = prevCam.x;
Game::camera->position.y = prevCam.y;
jumpAbility = false;
block = false;
abilityUse = 0;
enemyDefeated = false;
blockUse = 0;
ghostAbility = false;
turnCount = 0; //the current turn #
turnAbilityUse = 0; // turn where ability can be used again
turnAbilityStop = 0; //turn where ability stops being used;
lastAction = "";
}
}
Scene* SceneManager::getCurrentScene(){
return this->currentS;
}
|
e1ad31341e285f057c41bed6446b9c6a42317ed9
|
8a9e8ae39f501e06223e48cd3fc963ff675fb820
|
/src/materials/materialAsset.h
|
1ca8eb14acf6b3ed0a00a2e78a22ed756f055b8e
|
[
"MIT"
] |
permissive
|
seuzht/Torque6
|
0f093f918f247288c6b0c93237fa409e6c0205de
|
db6cd08f18f4917e0c6557b2766fb40d8e2bee39
|
refs/heads/master
| 2023-03-27T02:36:30.374795
| 2016-06-20T15:24:13
| 2016-06-20T15:24:13
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,846
|
h
|
materialAsset.h
|
//-----------------------------------------------------------------------------
// Copyright (c) 2015 Andrew Mac
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _MATERIAL_ASSET_H_
#define _MATERIAL_ASSET_H_
#ifndef _ASSET_PTR_H_
#include "assets/assetPtr.h"
#endif
#ifndef _VERTEXLAYOUTS_H_
#include "graphics/core.h"
#endif
#ifndef _TEXTURE_MANAGER_H_
#include "graphics/TextureManager.h"
#endif
#ifndef _SHADERS_H_
#include "graphics/shaders.h"
#endif
#ifndef _TEXTURE_MANAGER_H_
#include "graphics/TextureManager.h"
#endif
#ifndef _BASE_COMPONENT_H_
#include "scene/components/baseComponent.h"
#endif
#ifndef _RENDERING_H_
#include "rendering/rendering.h"
#endif
#ifndef _MATERIAL_TEMPLATE_H_
#include "materialTemplate.h"
#endif
//-----------------------------------------------------------------------------
DefineConsoleType( TypeMaterialAssetPtr )
//-----------------------------------------------------------------------------
class DLL_PUBLIC MaterialAsset : public AssetBase
{
private:
typedef AssetBase Parent;
protected:
Materials::MaterialTemplate* mTemplate;
StringTableEntry mTemplateFile;
S32 mTextureCount;
Vector<bgfx::TextureHandle> mTextureHandles;
Vector<Graphics::Shader*> mShaders;
Vector<Graphics::Shader*> mSkinnedShaders;
public:
MaterialAsset();
virtual ~MaterialAsset();
static void initPersistFields();
virtual bool onAdd();
virtual void onRemove();
virtual void copyTo(SimObject* object);
// Asset validation.
virtual bool isAssetValid( void ) const;
Materials::MaterialTemplate* getTemplate() { return mTemplate; }
StringTableEntry getTemplateFile() { return mTemplateFile; }
void setTemplateFile(const char* templateFile);
S32 getTextureCount() { return mTextureCount; }
void destroyShaders();
void applyMaterial(Rendering::RenderData* renderData);
void submit(U8 viewID, bool skinned = false, S32 variantIndex = -1);
void saveMaterial();
void compileMaterial(bool recompile = false);
void compileMaterialVariant(const char* variant, bool recompile = false);
void reloadMaterial();
void loadTextures();
Vector<bgfx::TextureHandle>* getTextureHandles() { return &mTextureHandles; }
/// Declare Console Object.
DECLARE_CONOBJECT(MaterialAsset);
protected:
virtual void initializeAsset(void);
virtual void onAssetRefresh(void);
static bool setTemplateFile(void* obj, const char* data) { static_cast<MaterialAsset*>(obj)->setTemplateFile(data); return false; }
};
#endif // _Base_MATERIAL_ASSET_H_
|
2e97e29bddcb7f95c8e7a0ac25a3dd905d4fa2c0
|
891ff124e61679a01362caae30ead0c1e3f562e3
|
/src/ros2mav/src/ros2att.cpp
|
78018f46669e73c67a71e6e7fd61543b0f4b6623
|
[] |
no_license
|
makquel/drone_ros
|
1352774804637d81c27b4507810f0b6ee15e9fe8
|
901aacb90b4205500f3e6eb82a6dbb696482de0a
|
refs/heads/master
| 2023-03-23T01:48:02.671894
| 2018-01-26T12:36:22
| 2018-01-26T12:36:22
| 346,856,039
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,426
|
cpp
|
ros2att.cpp
|
#include "Ros2Att.h"
Ros2Att::Ros2Att(){
ROS_INFO("ATT_CONSTRUCTOR");
std::string rpy_topic, imu_topic;
ros::NodeHandle nh;
nh.getParam("imu_topic", imu_topic);
nh.getParam("rpy_topic", rpy_topic);
nh.param("att_mav_freq", freq, 0.0);
sync = (freq>0.0);
rpy_sub = nh.subscribe<geometry_msgs::Vector3Stamped>(rpy_topic, 10, &Ros2Att::rpyCallback, this);
imu_sub = nh.subscribe<sensor_msgs::Imu>(imu_topic, 10, &Ros2Att::imuCallback, this);
}
void Ros2Att::send(){
mavlink_message_t mmsg;
ros::Time now=ros::Time::now();
att.time_boot_ms=(uint64_t)now.sec*1000+(uint64_t)now.nsec/1.0e6;
mavlink_msg_attitude_encode( (uint8_t) 1, (uint8_t) 240, &mmsg, &att);
MavMessenger::send(mmsg);
}
void Ros2Att::imuCallback(const sensor_msgs::Imu::ConstPtr& imu){
att.rollspeed=imu->angular_velocity.x;
att.pitchspeed=imu->angular_velocity.y;
att.yawspeed=imu->angular_velocity.z;
if(!sync) send();
}
void Ros2Att::rpyCallback(const geometry_msgs::Vector3Stamped::ConstPtr& rpy){
//
att.roll = (rpy->vector.x)/RAD_TO_DEG; // 1/RAD_TO_DEG = DEG_TO_RAD
att.pitch = -rpy->vector.y/RAD_TO_DEG;
att.yaw = (270.0-rpy->vector.z)/RAD_TO_DEG; //Heading adjustment from XSENS
if(!sync) send();
}
int main(int argc, char** argv) {
ros::init(argc, argv, "ros2att");
Ros2Att Ros2Att;
ROS_DEBUG("ENTERING LOOP");
ros::spin();
ROS_INFO("OUT OF THE LOOP");
}
|
f4aa524ff33e752794ca7ced1349c4323e32e8ef
|
1f4c4146d26c856dcb2a9086877fb1797a80cc91
|
/messages/ccn_data_m.h
|
511aa25b0a5fb27c5b2b42b94f7ca37f60f74395
|
[] |
no_license
|
itZhy/CCNSimForPowerPlanning
|
2e515a3b6d9538e14ae9baec4e8a6ad5f22c8640
|
7dbc7683a6760808b86d41adef9349c878c31905
|
refs/heads/master
| 2016-09-01T21:38:47.626670
| 2013-03-27T07:39:55
| 2013-03-27T07:39:55
| 7,438,543
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,814
|
h
|
ccn_data_m.h
|
//
// Generated file, do not edit! Created by opp_msgc 4.2 from messages/ccn_data.msg.
//
#ifndef _CCN_DATA_M_H_
#define _CCN_DATA_M_H_
#include <omnetpp.h>
// opp_msgc version check
#define MSGC_VERSION 0x0402
#if (MSGC_VERSION!=OMNETPP_VERSION)
# error Version mismatch! Probably this file was generated by an earlier version of opp_msgc: 'make clean' should help.
#endif
/**
* Class generated from <tt>messages/ccn_data.msg</tt> by opp_msgc.
* <pre>
* message ccn_data{
* unsigned long chunk;
* double d = 0;
* double hops = 0;
* unsigned long repository;
* }
* </pre>
*/
class ccn_data : public ::cMessage
{
protected:
unsigned long chunk_var;
double d_var;
double hops_var;
unsigned long repository_var;
private:
void copy(const ccn_data& other);
protected:
// protected and unimplemented operator==(), to prevent accidental usage
bool operator==(const ccn_data&);
public:
ccn_data(const char *name=NULL, int kind=0);
ccn_data(const ccn_data& other);
virtual ~ccn_data();
ccn_data& operator=(const ccn_data& other);
virtual ccn_data *dup() const {return new ccn_data(*this);}
virtual void parsimPack(cCommBuffer *b);
virtual void parsimUnpack(cCommBuffer *b);
// field getter/setter methods
virtual unsigned long getChunk() const;
virtual void setChunk(unsigned long chunk);
virtual double getD() const;
virtual void setD(double d);
virtual double getHops() const;
virtual void setHops(double hops);
virtual unsigned long getRepository() const;
virtual void setRepository(unsigned long repository);
};
inline void doPacking(cCommBuffer *b, ccn_data& obj) {obj.parsimPack(b);}
inline void doUnpacking(cCommBuffer *b, ccn_data& obj) {obj.parsimUnpack(b);}
#endif // _CCN_DATA_M_H_
|
320a2c9e8f578b8f9c16bb31d3c70cadf0bd0a24
|
a9c52b680b03508db0b73779d2bfc5808f709441
|
/SLIDE/Layer.h
|
5f501f9946ce0839cd4db118a87963ab830fb8fc
|
[] |
no_license
|
pombredanne/HashingDeepLearning
|
22ff453cbd4c4516ac538f3712e3a8be2647a1c7
|
e430d6934f23c3a117dcbd27f202d1c61ce0f2b2
|
refs/heads/master
| 2020-05-01T12:11:45.600592
| 2019-03-18T06:03:53
| 2019-03-18T06:03:53
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,424
|
h
|
Layer.h
|
#pragma once
#include "Node.h"
#include "WtaHash.h"
#include "DensifiedMinhash.h"
#include "srp.h"
#include "LSH.h"
#include "DensifiedWtaHash.h"
#include "cnpy.h"
using namespace std;
class Layer
{
private:
NodeType _type;
Node** _Nodes;
int * _randNode;
float* _normalizationConstants;
int*_inputIDs; //needed for SOFTMAX
int _K, _L, _RangeRow, _previousLayerNumOfNodes, _batchsize;
public:
int _layerID, _noOfActive;
int _noOfNodes;
float* _weights;
float* _adamAvgMom;
float* _adamAvgVel;
float* _bias;
LSH *_hashTables;
WtaHash *_wtaHasher;
DensifiedMinhash *_MinHasher;
SparseRandomProjection *_srp;
DensifiedWtaHash *_dwtaHasher;
int * _binids;
Layer(int _numNodex, int previousLayerNumOfNodes, int layerID, NodeType type, int batchsize, int K, int L, int RangePow, float Sparsity, float* weights=NULL, float* bias=NULL, float *adamAvgMom=NULL, float *adamAvgVel=NULL);
Node* getNodebyID(int nodeID);
Node** getAllNodes();
void addtoHashTable(float* weights, int length, float bias, int id);
float getNomalizationConstant(int inputID);
int queryActiveNodeandComputeActivations(int** activenodesperlayer, float** activeValuesperlayer, int* inlenght, int layerID, int inputID, int* label, int labelsize, float Sparsity, int iter);
void saveWeights(string file);
void updateTable();
void updateRandomNodes();
~Layer();
};
|
de37f7b0915cb3b555bedfd4a66eb9ca87bf6854
|
09fa7f46d0ab78c7cf56c39535030476471ca051
|
/03_프로그래머스/모두 0으로 만들기.cpp
|
e0431fd36acdf1d5251c64a505c55a9694f35ae1
|
[] |
no_license
|
ChoiHeon/algorithm
|
4089259685550fb658524d2f3a1160ee1fa6e105
|
cb174711afa6a7ac14cb830861dc54a53abf5329
|
refs/heads/master
| 2021-11-23T13:23:50.945628
| 2021-11-08T15:46:54
| 2021-11-08T15:46:54
| 230,856,736
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 905
|
cpp
|
모두 0으로 만들기.cpp
|
// https://programmers.co.kr/learn/courses/30/lessons/77885
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <cstdlib>
using namespace std;
long long dfs(vector<long long>& b, vector<vector<int>>& graph, int crnt, int prev) {
long long ret = 0LL;
for (auto next : graph[crnt]) {
if (next == prev)
continue;
ret += dfs(b, graph, next, crnt);
}
b[prev] += b[crnt];
ret += abs(b[crnt]);
return ret;
}
long long solution(vector<int> a, vector<vector<int>> edges) {
long long answer;
vector<vector<int>> graph(a.size());
vector<long long> b(a.size());
for (int i = 0; i < a.size(); i++)
b[i] = a[i];
for (auto edge : edges) {
graph[edge[0]].push_back(edge[1]);
graph[edge[1]].push_back(edge[0]);
}
answer = dfs(b, graph, 0, 0);
return b[0] == 0 ? answer : -1;
}
int main() {
long long a = 0LL;
a += 1000000000000000;
cout << a;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.