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
08305327b2a3b7d6da4becf7c9d09287981ceb38
53733f73b922407a958bebde5e674ec7f045d1ba
/OtherSites/TopCoder/SRM/797/Three/main1.cpp
3c5d4283b5b824a430b5f8507f4f172fcad596f3
[]
no_license
makio93/atcoder
040c3982e5e867b00a0d0c34b2a918dd15e95796
694a3fd87b065049f01f7a3beb856f8260645d94
refs/heads/master
2021-07-23T06:22:59.674242
2021-03-31T02:25:55
2021-03-31T02:25:55
245,409,583
0
0
null
null
null
null
UTF-8
C++
false
false
1,693
cpp
main1.cpp
#include <bits/stdc++.h> using namespace std; class FlightPlan { public: long long fly(int R, int C, vector<int> H, int cup, int cdn, int clr) { vector<vector<vector<int>>> dist(R*C, vector<vector<int>>(R, vector<int>(C, (int)(1e9)))); for (int i1=0; i1<R*C; ++i1) { if (H[0] > H[i1]) continue; queue<pair<int,int>> que; que.emplace(0, 0); dist[i1][0][0] = 0; while (!que.empty()) { auto p = que.front(); que.pop(); int r = p.first, c = p.second, d = dist[i1][r][c], nd = d + 1; const vector<int> dr = { -1, 0, 1, 0 }, dc = { 0, 1, 0, -1 }; for (int i=0; i<4; ++i) { int nr = r + dr[i], nc = c + dc[i]; if (nr<0 || nr>=R || nc<0 || nc>=C) continue; if (H[nr*C+nc] > H[i1]) continue; if (dist[i1][nr][nc] <= nd) continue; que.emplace(nr, nc); dist[i1][nr][nc] = nd; } } } long long ans = (long long)(1e18); for (int i=0; i<R*C; ++i) { if (dist[i][R-1][C-1] == (int)(1e9)) continue; ans = min(ans, dist[i][R-1][C-1]*(long long)(clr)+(H[i]-H[0])*(long long)(cup)+(H[i]-H[R*C-1])*(long long)(cdn)); } return ans; } }; int main(){ FlightPlan cl; int r, c, cup, cdn, clr; cin >> r >> c; vector<int> h(r*c); for (int i=0; i<r*c; ++i) cin >> h[i]; cin >> cup >> cdn >> clr; cout << cl.fly(r, c, h, cup, cdn, clr) << endl; return 0; }
5373cbceca68433823ed799570fde41d01a33761
69edc451cdb4bf23de322c9d8335af39d583cc82
/UVa/011753.cpp
fa83c3cf44b3b37b9a3efc5847e1d167ee8c9b11
[]
no_license
jesusmoraleda/competitive-programming
cbd90384641565b651ac2694f98f5d10870b83a9
97511d4fd00e90fe6676bfd134c0eb56be3c7580
refs/heads/master
2020-09-04T17:09:37.607768
2017-08-13T10:06:04
2017-08-13T10:06:04
null
0
0
null
null
null
null
UTF-8
C++
false
false
665
cpp
011753.cpp
#include <iostream> using namespace std; int c, K, a[10000]; int f(int i, int j) { if (c > K) return c; if (i >= j) return 0; if (a[i] == a[j]) return f(i+1, j-1); c++; int D = 1 + min(f(i+1, j), f(i, j-1)); c--; return D; } int main() { int T; cin >> T; for (int t = 1; t <= T; t++) { int N; cin >> N >> K; for (int i = 0; i < N; i++) cin >> a[i]; c = 0; int D = f(0, N-1); printf("Case %d: ", t); if (D == 0) cout << "Too easy" << endl; else if (D > K) cout << "Too difficult" << endl; else cout << D << endl; } return 0; }
0b60c6299b18f21580245e439978aa34711fd382
4ad8a2fe729d10bdbb4f8fbdf9ef81612ba891d6
/模板/分治/树分治/树链剖分.cpp
fb910f74276b0986bbce822cd757e547f3ce97f9
[]
no_license
zh-dou/Source-File
3b54df7ab321e5355bea821aa82b77ae958965d3
a2f9198803d1bf23a5d1f364f0bff11072a9a578
refs/heads/master
2020-09-21T03:10:24.689192
2020-06-17T07:09:41
2020-06-17T07:09:41
224,661,593
0
0
null
null
null
null
UTF-8
C++
false
false
4,070
cpp
树链剖分.cpp
#include<queue> #include<cmath> #include<cstdio> #include<string> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; #define N 100010 inline int read(){ int x=0,y=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')y=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x*y; } struct Edge{ int nxt,to; }edge[N<<1]; int n,m,root,rt,mod,val[N],head[N],cnt,tot,fa[N],dep[N],son[N],size[N],top[N],dfn[N],id[N]; inline void add(int x,int y){ edge[++cnt].nxt=head[x];edge[cnt].to=y;head[x]=cnt; swap(x,y); edge[++cnt].nxt=head[x];edge[cnt].to=y;head[x]=cnt; } void dfs1(int x){ size[x]=1,dep[x]=dep[fa[x]]+1; for(int v,i=head[x];i;i=edge[i].nxt) if((v=edge[i].to)!=fa[x]){ fa[v]=x,dfs1(v),size[x]+=size[v]; if(size[son[x]]<size[v]) son[x]=v; } } void dfs2(int x,int tp){ top[x]=tp,dfn[x]=++cnt,id[cnt]=x; if(son[x]) dfs2(son[x],tp); for(int v,i=head[x];i;i=edge[i].nxt){ if((v=edge[i].to)!=fa[x]&&v!=son[x]) dfs2(v,v); } } struct Segment_Tree{ struct Node{ int l,r,ls,rs,sum,lazy; }tree[N<<1]; inline void pushup(int x){ tree[x].sum=(tree[tree[x].ls].sum+tree[tree[x].rs].sum)%mod; } void build(int l,int r,int x){ if(l==r){ tree[x].sum=val[id[l]],tree[x].l=tree[x].r=l; return; } int mid=(l+r)>>1; tree[x].ls=tot++;tree[x].rs=tot++; build(l,mid,tree[x].ls);build(mid+1,r,tree[x].rs); tree[x].l=l;tree[x].r=r; pushup(x); } inline int len(int x){ return tree[x].r-tree[x].l+1; } inline void pushdown(int x){ if(tree[x].lazy){ int lz=tree[x].lazy; (tree[tree[x].ls].lazy+=lz)%=mod;(tree[tree[x].rs].lazy+=lz)%=mod; (tree[tree[x].ls].sum+=lz*len(tree[x].ls))%=mod;(tree[tree[x].rs].sum+=lz*len(tree[x].rs))%=mod; tree[x].lazy=0; } } void update(int l,int r,int c,int x){ if(tree[x].l>=l&&tree[x].r<=r){ (tree[x].lazy+=c)%=mod;(tree[x].sum+=len(x)*c)%=mod; return; } pushdown(x); int mid=(tree[x].l+tree[x].r)>>1; if(mid>=l) update(l,r,c,tree[x].ls); if(mid<r) update(l,r,c,tree[x].rs); pushup(x); } int query(int l,int r,int x){ if(tree[x].l>=l&&tree[x].r<=r) return tree[x].sum; pushdown(x); int mid=(tree[x].l+tree[x].r)>>1,tot=0; if(mid>=l) tot+=query(l,r,tree[x].ls); if(mid<r) tot+=query(l,r,tree[x].rs); return tot%mod; } inline int sum(int x,int y){ int ret=0; while(top[x]!=top[y]){ if(dep[top[x]]<dep[top[y]]) swap(x,y); (ret+=query(dfn[top[x]],dfn[x],rt))%=mod; x=fa[top[x]]; } if(dfn[x]>dfn[y]) swap(x,y); return (ret+query(dfn[x],dfn[y],rt))%mod; } inline void updates(int x,int y,int c){ while(top[x]!=top[y]){ if(dep[top[x]]<dep[top[y]]) swap(x,y); update(dfn[top[x]],dfn[x],c,rt); x=fa[top[x]]; } if(dfn[x]>dfn[y]) swap(x,y); update(dfn[x],dfn[y],c,rt); } }Tree; signed main(){ n=read();m=read();root=read();mod=read(); for(int i=1;i<=n;i++) val[i]=read(); for(int x,y,i=1;i<n;i++){ x=read();y=read(); add(x,y); } cnt=0; dfs1(root);dfs2(root,root); Tree.build(1,n,rt=tot++); for(int op,x,y,k,i=1;i<=m;i++){ op=read(); if(op==1){ x=read();y=read();k=read(); Tree.updates(x,y,k); } if(op==2){ x=read();y=read(); cout<<Tree.sum(x,y)<<"\n"; } if(op==3){ x=read();y=read(); Tree.update(dfn[x],dfn[x]+size[x]-1,y,rt); } if(op==4){ x=read(); cout<<Tree.query(dfn[x],dfn[x]+size[x]-1,rt)<<"\n"; } } return 0; }
cdc82093e82a6725a9ec89f989172c058d2ee879
aec5cf4d630d0b7de9a5599091f3c13962380c47
/code01.ino
7c1159180987e37820ecf469dee71a28cbdafaf3
[]
no_license
PhantomHT/Arduino_digital_voltmeter
8fa1322ebb55ab3d6368ca4a5e99ea13251b71ff
91426acac37a7abcf21bb58325cc2ab83e50fafa
refs/heads/master
2021-01-20T00:22:22.142714
2017-11-24T22:01:42
2017-11-24T22:01:42
89,123,258
0
0
null
null
null
null
UTF-8
C++
false
false
348
ino
code01.ino
# 1 channel digital voltmeter # using analog inputs and basic conversion formula int input_pin= A0; float serial_voltage=0.00; void setup() { Serial.begin(9600); pinMode(input_pin, INPUT); } void loop() { serial_voltage=analogRead(input_pin*5.0)/1024.0; Serial.print("Voltage: "); Serial.println(serial_voltage); delay(100); }
f6f0f245bc785ecaab0800f8eb5f3341260eaba2
0aedbcfb57f277669084a1a905eb873a2ac60fe6
/Heaps_FindTheRunningMedian.cpp
d49c0301e7b9150557045665ba9ec39bdcf6afa5
[]
no_license
gunanksood/Cracking-the-Coding-Interview-Solutions
7e841da2a616a0a35d2e1c0e3a06aa70362301cf
a58a5f8d3a512d32de69254b416f8a2b35b63f87
refs/heads/master
2021-01-25T09:43:35.597619
2017-06-11T17:17:59
2017-06-11T17:17:59
93,873,171
0
0
null
null
null
null
UTF-8
C++
false
false
2,005
cpp
Heaps_FindTheRunningMedian.cpp
/* https://www.hackerrank.com/challenges/ctci-find-the-running-median */ #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <string> #include <bitset> #include <cstdio> #include <limits> #include <vector> #include <climits> #include <cstring> #include <cstdlib> #include <fstream> #include <numeric> #include <sstream> #include <iostream> #include <algorithm> #include <unordered_map> #include<iomanip> using namespace std; int main(){ long long int n; cin >> n; priority_queue<double > max ; priority_queue<double,vector<double>, greater<double> > min ; double top_max = 0.0, top_min = 0.0; for(long long int i = 0 ; i < n ; i++) { double num; cin >> num; if(num < top_max) { if(max.size() <= min.size()) { max.push(num); top_max = max.top(); } else { top_min = max.top(); max.pop(); min.push(top_min); max.push(num); top_max = max.top(); } } else { if(max.size() >= min.size()) { min.push(num); top_max = min.top(); } else { top_min = min.top(); min.pop(); max.push(top_min); min.push(num); top_max = min.top(); } } if(max.size() - min.size() == 1) { cout<< setprecision(1)<<fixed<<max.top()<<endl; } else if(min.size() - max.size() == 1) { cout<<setprecision(1)<<fixed<<min.top()<<endl; } else { cout<<setprecision(1)<<fixed<<(min.top() + max.top()) / 2<<endl; } } return 0; }
5072bf5c7ef5b06ae732d9b465c185c34e60f30a
c34f46ea941aa42a3c7c976d70cc987684d988b5
/HW7/DenialOfServiceAnalyzer.h
eff933c83270d3389cab42e6e29f5adbc6227a27
[]
no_license
emperorbyl/PeerReview
c613dda92b5c8beb5c4412068adc7b1200f823d4
78d182aaa586af30b731534dd9abb1d6896cd909
refs/heads/master
2021-01-20T03:29:14.129404
2017-04-27T02:26:37
2017-04-27T02:26:37
89,545,239
0
0
null
null
null
null
UTF-8
C++
false
false
579
h
DenialOfServiceAnalyzer.h
// // Created by Justin Fairbourn on 4/23/2017. // #ifndef HW7_DENIALOFSERVICEANALYZER_H #define HW7_DENIALOFSERVICEANALYZER_H #include "Analyzer.h" class DenialOfServiceAnalyzer : public Analyzer { public: DenialOfServiceAnalyzer(Configuration config); ResultSet run(std::istream &in); private: int timeframe; int likelyThreshold; int possibleThreshold; int checkTimeBlock(int startingIndex, Dictionary<int, int> *timeRecord); Dictionary<std::string, Dictionary<int, int>*> data; ResultSet results; }; #endif //HW7_DENIALOFSERVICEANALYZER_H
e3ae5d2cabb62d70eee05b638dfbc5455a22e67b
228b25458e74199b18bfcdd0d1dc400e39e4a651
/old/2178/bfs.cpp
9bd4f9b9a4df7ce2a5d73e78d2beff0515291fc1
[]
no_license
luxroot/baekjoon
9146f18ea345d6998e471439117516f2ea26f22c
ed40287fd53ae1f41d2958c68e6e04d498d528b9
refs/heads/master
2023-06-27T05:50:41.303356
2021-08-06T04:18:33
2021-08-06T04:18:33
111,078,357
1
0
null
null
null
null
UTF-8
C++
false
false
1,132
cpp
bfs.cpp
#include <bits/stdc++.h> using namespace std; int v[105][105]; int main() { int n,m,i,j,cnt=1; cin >> n >> m; for(i=0;i<n;i++){ string temp; cin >> temp; for(j=0;j<m;j++){ v[i][j]=temp[j]-'0'; } } queue< pair<int,int> > q; pair<int,int> c; q.push(make_pair(0,0)); v[0][0]=1; while(!q.empty()){ c=q.front(); q.pop(); if(v[c.first+1][c.second] == 1){ q.push(make_pair(c.first+1,c.second)); v[c.first+1][c.second]=v[c.first][c.second]+1; } if(v[c.first][c.second+1] == 1){ q.push(make_pair(c.first,c.second+1)); v[c.first][c.second+1]=v[c.first][c.second]+1; } if(c.first>0 && v[c.first-1][c.second] == 1){ q.push(make_pair(c.first-1,c.second)); v[c.first-1][c.second]=v[c.first][c.second]+1; } if(c.second >0 && v[c.first][c.second-1] == 1){ q.push(make_pair(c.first,c.second-1)); v[c.first][c.second-1]=v[c.first][c.second]+1; } } cout<<v[n-1][m-1]; return 0; }
ff8405bfd4d491a419b84cf1b56a4b449577fdc8
5cd30c7bc36af0d37e4c4c0ecd6bf3d84d1e710a
/src/d2d/SpriteAnimationSystem.cpp
3509727e05faf3c7654f60f3548ccbd194988f19
[]
no_license
Dwergi/prototype-engine
89cb8a4c90344ab046d176beff7b19468abd6d4e
0d792ded0141b2a913200f6f1c27084d65f42627
refs/heads/master
2023-04-27T21:08:31.482645
2023-04-21T09:17:36
2023-04-21T09:17:36
31,064,734
1
0
null
null
null
null
UTF-8
C++
false
false
1,083
cpp
SpriteAnimationSystem.cpp
#include "PCH.h" #include "d2d/SpriteAnimationSystem.h" #include "d2d/SpriteAnimationComponent.h" #include "d2d/SpriteComponent.h" namespace d2d { SpriteAnimationSystem::SpriteAnimationSystem() : ddc::System("Sprite Animation") { RequireTag(ddc::Tag::Visible); RequireWrite<d2d::SpriteAnimationComponent>(); RequireWrite<d2d::SpriteComponent>(); } void SpriteAnimationSystem::Update(ddc::UpdateData& update_data) { auto anims = update_data.Data().Write<d2d::SpriteAnimationComponent>(); auto sprites = update_data.Data().Write<d2d::SpriteComponent>(); float delta_t = update_data.Delta(); for (int i = 0; i < anims.Size(); ++i) { d2d::SpriteAnimationComponent& anim = anims[i]; if (!anim.IsPlaying) { continue; } anim.Time += delta_t; const float frametime = 1.0f / anim.Framerate; if (anim.Time > frametime) { anim.Time -= frametime; ++anim.CurrentFrame; if (anim.CurrentFrame == anim.Frames.Size()) { anim.CurrentFrame = 0; } sprites[i].Sprite = anim.Frames[anim.CurrentFrame]; } } } }
dc0e9db355664efa984ff467249f37c36e4aa8ce
9870e11c26c15aec3cc13bc910e711367749a7ff
/SPOJ/sp_8317.cpp
0dfbddc08e045ead088ff2339c77a32e97395202
[]
no_license
liuq901/code
56eddb81972d00f2b733121505555b7c7cbc2544
fcbfba70338d3d10bad2a4c08f59d501761c205a
refs/heads/master
2021-01-15T23:50:10.570996
2016-01-16T16:14:18
2016-01-16T16:14:18
12,918,517
1
1
null
null
null
null
UTF-8
C++
false
false
2,597
cpp
sp_8317.cpp
#include <cstdio> #include <algorithm> using namespace std; struct tree { int l,r,maxl,maxr,maxs,minl,minr,mins,sum; bool change; }; tree a[270000]; int b[100010]; void updata(int x) { if (!a[x].change) return; if (a[x].l!=a[x].r) { int ls=x<<1,rs=ls+1; a[ls].change=!a[ls].change; a[rs].change=!a[rs].change; } a[x].change=false; swap(a[x].maxl,a[x].minl); a[x].maxl*=-1,a[x].minl*=-1; swap(a[x].maxr,a[x].minr); a[x].maxr*=-1,a[x].minr*=-1; swap(a[x].maxs,a[x].mins); a[x].maxs*=-1,a[x].mins*=-1; a[x].sum*=-1; } tree merge(tree ls,tree rs) { tree ret; ret.sum=ls.sum+rs.sum; ret.maxl=max(ls.maxl,ls.sum+rs.maxl); ret.minl=min(ls.minl,ls.sum+rs.minl); ret.maxr=max(rs.maxr,rs.sum+ls.maxr); ret.minr=min(rs.minr,rs.sum+ls.minr); ret.maxs=max(max(ls.maxs,rs.maxs),ls.maxr+rs.maxl); ret.mins=min(min(ls.mins,rs.mins),ls.minr+rs.minl); return(ret); } void update(int x) { int ls=x<<1,rs=ls+1,l=a[x].l,r=a[x].r; updata(ls),updata(rs); a[x]=merge(a[ls],a[rs]); a[x].l=l,a[x].r=r,a[x].change=false; } void build(int x,int l,int r) { a[x].l=l,a[x].r=r; a[x].change=false; if (l==r) { a[x].maxl=a[x].maxr=a[x].maxs=a[x].minl=a[x].minr=a[x].mins=a[x].sum=b[l]; return; } int ls=x<<1,rs=ls+1,mid=l+r>>1; build(ls,l,mid); build(rs,mid+1,r); update(x); } void modify(int x,int l,int r) { if (l==a[x].l && r==a[x].r) { a[x].change=!a[x].change; return; } updata(x); int ls=x<<1,rs=ls+1,mid=a[x].l+a[x].r>>1; if (r<=mid) modify(ls,l,r); else if (l>mid) modify(rs,l,r); else { modify(ls,l,mid); modify(rs,mid+1,r); } update(x); } tree get(int x,int l,int r) { updata(x); if (a[x].l==l && a[x].r==r) return(a[x]); int ls=x<<1,rs=ls+1,mid=a[x].l+a[x].r>>1; if (r<=mid) return(get(ls,l,r)); else if (l>mid) return(get(rs,l,r)); else return(merge(get(ls,l,mid),get(rs,mid+1,r))); } int main() { int T; scanf("%d",&T); while (T--) { int n; scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&b[i]); build(1,1,n); int Q; scanf("%d",&Q); while (Q--) { int op,x,y; scanf("%d%d%d",&op,&x,&y); x++,y++; if (!op) modify(1,x,y); else printf("%d\n",get(1,x,y).maxs); } } return(0); }
0051c63961724a1bf59f2b2ce417c75e9bbf59b1
93a3c16d413b193c2f870862dd784c1ac6b842dd
/Orryx/Input.cpp
fff5dc3858708c412cc9ab01b3cf5619e15a2126
[]
no_license
tedajax/orryx
d6f7b19703a8a0c755938f5f82b669651bbe089f
232bb0c57607d8dfa8d5d6101ac801304cd724cc
refs/heads/master
2016-09-06T01:42:42.590729
2014-11-11T08:54:56
2014-11-11T08:54:56
null
0
0
null
null
null
null
UTF-8
C++
false
false
951
cpp
Input.cpp
#include "Input.h" namespace orx { Input::Input() { for (int i = 0; i < SDL_NUM_SCANCODES; ++i) { m_previousState[i] = false; m_currentState[i] = false; } } Input::~Input() { } bool Input::getKey(SDL_Scancode key) { return m_currentState[key]; } bool Input::getKeyDown(SDL_Scancode key) { return m_currentState[key] && !m_previousState[key]; } bool Input::getKeyUp(SDL_Scancode key) { return !m_currentState[key] && m_previousState[key]; } void Input::update() { for (int i = 0; i < SDL_NUM_SCANCODES; ++i) { m_previousState[i] = m_currentState[i]; } } void Input::onKeyEvent(const SDL_KeyboardEvent& event) { SDL_Scancode code = event.keysym.scancode; bool down = (event.state == SDL_PRESSED); m_currentState[code] = down; } }
2a90a81b5a451f994e21992f65bbb6ed3e1743ad
a43dd6906848d560a0adf8b8bfffe2458d028996
/chain_of_respon.cpp
a7bbd7777fb1d2384cbd855ee7528bbf13425384
[]
no_license
wzpchris/design_pattern
50b85270e28e7a986da3230200eea7efe6bb0239
cbe50ecf50019038ab349a735e44f9396404d8cb
refs/heads/master
2020-03-23T00:11:57.476696
2018-07-13T13:29:57
2018-07-13T13:29:57
140,849,922
0
0
null
null
null
null
UTF-8
C++
false
false
2,252
cpp
chain_of_respon.cpp
/************************************************************************* > File Name: chain_of_respon.cpp > Author: > Mail: > Created Time: 2018年07月13日 星期五 19时49分40秒 ************************************************************************/ //职责连模式 #include<iostream> using namespace std; class Manager { protected: Manager *m_manager; string m_name; public: Manager(Manager *manager, string name):m_manager(manager), m_name(name) {} virtual void dealWithRequest(string name, int num) {} }; //经理 class CommonManager:public Manager { public: CommonManager(Manager *manager, string name):Manager(manager,name){} void dealWithRequest(string name, int num) { if(num < 500) //经理职权之内 { cout << "经理"<<m_name<<"批准"<<name<<"加薪"<<num<<"元"<< endl << endl;; }else { cout << "经理"<<m_name<<"无法处理,交由总监处理"<<endl; m_manager->dealWithRequest(name,num); } } }; //总监 class Majordomo:public Manager { public: Majordomo(Manager *manager,string name):Manager(manager,name) {} void dealWithRequest(string name, int num) { if(num < 1000) //总监职权之内 { cout<<"总监"<<m_name<<"批准"<<name<<"加薪"<<num<<"元"<<endl << endl; }else { cout<<"总监"<<m_name<<"无法处理,交由经理处理"<<endl; m_manager->dealWithRequest(name,num); } } }; //总经理 class GeneralManager:public Manager { public: GeneralManager(Manager *manager,string name):Manager(manager,name){} void dealWithRequest(string name, int num) { cout<<"总经理"<<m_name<<"批准"<<name<<"加薪"<<num<<"元"<<endl << endl; } }; int main(int argc, char **argv) { Manager *general = new GeneralManager(NULL, "A"); //设置上级,总经理没有上级 Manager *majordomo = new Majordomo(general, "B"); //设置上级 Manager *common = new CommonManager(majordomo, "C"); //设置上级 common->dealWithRequest("D", 300); common->dealWithRequest("E", 600); common->dealWithRequest("F", 1000); delete common; delete majordomo; delete general; return 0; }
46a79a4467a17e925c26a58427f7c0353ad202b1
cd5771b452cc78c6a71d697b9d7d4d3209d51485
/WaterSurface/Matrix4f.h
4697df73eef59581b3094b87e1ebab7fdbafce1b
[ "BSD-3-Clause" ]
permissive
Gekoncze/ExamplesOpenglWaterSurface
d0f7a0a65612434dcd67ad0c3a6eaf6cc0505666
76bec224365c25eca9df757181157fb3faf1ee2f
refs/heads/master
2020-05-27T03:52:27.180964
2019-05-24T20:19:45
2019-05-24T20:19:45
188,473,657
0
0
null
null
null
null
UTF-8
C++
false
false
1,212
h
Matrix4f.h
#pragma once class Matrix4f { private: float data[16]; public: Matrix4f( float f0, float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15 ); Matrix4f(); ~Matrix4f(); float* getData(); static Matrix4f identity(); static Matrix4f translation(float x, float y, float z); static Matrix4f scale(float x, float y, float z); static Matrix4f rotation(float angle, float x, float y, float z); static Matrix4f rotationX(float angle); static Matrix4f rotationY(float angle); static Matrix4f rotationZ(float angle); static Matrix4f ortho(float left, float right, float bottom, float top, float near, float far); static Matrix4f frustum(float left, float right, float bottom, float top, float near, float far); static Matrix4f perspective(float angle, float aspect, float near, float far); static Matrix4f yawPitchRoll(float yaw, float pitch, float roll); static Matrix4f multiply(Matrix4f left, Matrix4f right); static Matrix4f multiply(Matrix4f left, Matrix4f middle, Matrix4f right); }; inline Matrix4f operator*(Matrix4f left, Matrix4f right) { return Matrix4f::multiply(left, right); }
ac38037e3d144d3e196c2814c8297a8cf3b9530c
07e23ccae6c7a19bb556ad04a157346c8c9026d5
/src/memhookcore/leveldb_storage.cpp
a5bc684ad649f333b7213b91720fc44b078c5f29
[ "BSD-3-Clause" ]
permissive
sergzub/memhook
4a60a1aa0e5ac165d29e853920c593def42d7536
51206e1bb54b08a658a3524d169e81c5abd4b61c
refs/heads/master
2020-04-24T11:08:38.231435
2019-02-21T17:43:53
2019-02-21T18:05:21
171,916,212
0
0
BSD-3-Clause
2019-02-21T17:36:19
2019-02-21T17:36:18
null
UTF-8
C++
false
false
2,999
cpp
leveldb_storage.cpp
#include "leveldb_storage.h" #include <boost/chrono/system_clocks.hpp> #include <boost/filesystem/operations.hpp> #include <boost/throw_exception.hpp> #include <leveldb/comparator.h> namespace memhook { namespace { class SystemClockComparator : public leveldb::Comparator { public: int Compare(const leveldb::Slice &lhs, const leveldb::Slice &rhs) const { const chrono::system_clock::rep lhs_rep = *reinterpret_cast<const chrono::system_clock::rep *>(lhs.data()); const chrono::system_clock::rep rhs_rep = *reinterpret_cast<const chrono::system_clock::rep *>(rhs.data()); if (lhs_rep < rhs_rep) return -1; if (lhs_rep > rhs_rep) return 1; return 0; } const char *Name() const { return "SystemClockComparator"; } void FindShortestSeparator(std::string *, const leveldb::Slice &) const {} void FindShortSuccessor(std::string *) const {} }; SystemClockComparator SYSTEM_CLOCK_COMPARATOR; } // namespace LevelDBStorage::LevelDBStorage(const char *path, std::size_t cache_size_mb) : m_path(path) , m_cache_size_mb(cache_size_mb) { if (!boost::filesystem::is_directory(m_path)) { if (boost::filesystem::exists(m_path)) boost::filesystem::remove(m_path); boost::filesystem::create_directory(m_path); } leveldb::Options options; options.create_if_missing = true; options.compression = leveldb::kNoCompression; m_symtab = OpenDB(options, m_path / "symtab"); m_shltab = OpenDB(options, m_path / "shltab"); options.comparator = &SYSTEM_CLOCK_COMPARATOR; if (m_cache_size_mb) { options.block_cache = leveldb::NewLRUCache(m_cache_size_mb * 1024 * 1024); m_dcache = unique_ptr<leveldb::Cache>(options.block_cache); } m_dattab = OpenDB(options, m_path / "dattab"); } unique_ptr<leveldb::DB> LevelDBStorage::OpenDB(const leveldb::Options &options, const boost::filesystem::path &path) const { leveldb::DB *db = NULL; leveldb::Status status = leveldb::DB::Open(options, path.string(), &db); if (!status.ok()) { BOOST_THROW_EXCEPTION(std::runtime_error(status.ToString())); } return unique_ptr<leveldb::DB>(db); } void LevelDBStorage::Add(uintptr_t address, std::size_t memsize, const CallStackInfo &callstack, const chrono::system_clock::time_point &timestamp) {} bool LevelDBStorage::Remove(uintptr_t address) { return false; } bool LevelDBStorage::UpdateSize(uintptr_t address, std::size_t memsize) { return false; } void LevelDBStorage::Clear() {} void LevelDBStorage::Flush() {} std::string LevelDBStorage::GetName() const { return m_path.string(); } unique_ptr<MappedStorage> NewLevelDBStorage(const char *path, std::size_t cache_size_mb) { return unique_ptr<MappedStorage>(new LevelDBStorage(path, cache_size_mb)); } } // memhook
2f4b872ec08aae2567176ea5bd2ea95250047da3
f12474fd5330114bebf9982a366d8629dcf40c2a
/hello world/三个数的max.cpp
ac4c486fbf9f5fd403684d693fc0854a9a5f4be0
[]
no_license
yaolaotou/C-s-Class
b7d2d50832cc7bef8ce54bed3a70eb7cc44ba36b
abe52a4071c6e0c79d1496e069e3b758bb8d9a32
refs/heads/master
2021-04-03T04:33:07.618445
2018-03-09T16:31:06
2018-03-09T16:31:06
124,563,757
0
0
null
null
null
null
ISO-8859-7
C++
false
false
229
cpp
三个数的max.cpp
#include<stdio.h> main() { int a,b,c; int max; printf("ΗλΚδΘλΘύΈφΚύ£Ί"); scanf("%d %d %d",&a,&b,&c); if(a>b&&a>c) { max = a; } else if(b>a&&b>c) { max = b; } else { max=c; } printf("%d\n",max); }
1d6f858f5f3b0d1062399f4d288b637e5dd9b5de
7e52c0da52a2569be2caaeffa7aa74b4ee1b5bc3
/model/PlayfieldState.h
4053e36951463411a95aa71781f374cad7721dea
[]
no_license
furkoch/tic_tac_toe
1766c6dd38ad95469fc33223c2f519e43826e001
8e5e0d729c350be462ef365637d0ac5b30ad35cd
refs/heads/master
2020-04-03T15:35:49.496069
2018-10-30T10:48:33
2018-10-30T10:48:33
155,368,096
0
0
null
null
null
null
UTF-8
C++
false
false
544
h
PlayfieldState.h
#ifndef PLAYFIELD_STATE #define PLAYFIELD_STATE #include <vector> enum GameState {PLAYING, PLAYER_ONE_WON, PLAYER_TWO_WON, PLAYER_AI_WON, DRAW}; class PlayfieldState { public: PlayfieldState(int boardSize); ~PlayfieldState(); inline const std::vector<std::vector<char>>& getStateMatrix() { return stateMatrix; } inline GameState getGameState() & { return gameState; } void setGameState(GameState gs); void update(int row, int col, char val); private: GameState gameState; std::vector<std::vector<char>> stateMatrix; }; #endif
857a0360307df409eceda948b019916f94a149e3
2c430e743e4cb78cfab6688043b4d98fff00f255
/examples/todomvc - ssr/src/server/app.cpp
68411477ce7c443e9861c2eda2a4a12e25a29b6a
[ "MIT" ]
permissive
mbasso/asm-dom
8c346960ed2403f0822b2ea5a6d0357b58682665
795529cacd3d41154c701e52bd9da0f483e8f916
refs/heads/master
2023-08-28T21:35:35.559219
2022-08-28T09:11:42
2022-08-28T09:11:42
83,154,886
2,921
128
NOASSERTION
2023-03-03T18:16:02
2017-02-25T18:59:11
C++
UTF-8
C++
false
false
1,520
cpp
app.cpp
#include "../../../../src/cpp/asm-dom.hpp" #include "../../../../src/cpp/asm-dom-server.hpp" #include "../shared/todos.hpp" #include "../shared/helpers.hpp" #include <emscripten.h> #include <emscripten/bind.h> using namespace asmdom; using namespace todomvc::todos; std::function<void(todomvc::todos::action)> handler; void onRequest(emscripten::val req, emscripten::val res, emscripten::val next) { std::string appString = toHTML( view(todomvc::todos::init(), handler) ); res.call<void>("send", utf8_to_wstring( "<!doctype html>" "<html lang=\"en\">" "<head>" "<meta charset=\"utf-8\">" "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" "<title>asm-dom • TodoMVC</title>" "</head>" "<body>" + appString + "<footer class=\"info\">" "<p>Double-click to edit a todo</p>" "<p>Created by <a href=\"https://github.com/mbasso\">Matteo Basso</a></p>" "<p>Part of <a href=\"http://todomvc.com\">TodoMVC</a></p>" "</footer>" "<script src=\"bundle.js\"></script>" "</body>" "</html>" ) ); }; int main() { Config config; init(config); EM_ASM( var path = require('path'); var express = require('express'); var app = express(); var port = 9000; app.use(express['static']('./dist/client')); app.get('/', Module['onRequest']); app.listen(port); console.log('Listening on port ' + port + '...'); ); return 0; }; EMSCRIPTEN_BINDINGS(app) { emscripten::function("onRequest", &onRequest); };
551ca6447f3543bb3c248d6b731ae267f32c10fd
dd7f966edda4df817612c53a3eeb1e46af668e35
/Arduino/HS1/sgtl5000_LHI.ino
a3026dbf8f938d0468e6d0579b20835c755994e7
[]
no_license
loggerhead-instruments/HS1
a1863f8b1cb1178d2b90677494651d8534cc7536
28fa92ae6ccf6cc0c686fc438f40dded219581b6
refs/heads/master
2020-06-16T01:46:41.430397
2019-12-16T20:52:45
2019-12-16T20:52:45
195,446,861
0
0
null
null
null
null
UTF-8
C++
false
false
26,777
ino
sgtl5000_LHI.ino
#include "control_sgtl5000.h" //#include "Wire.h" #define SGTL5000_I2C_ADDR 0x0A // CTRL_ADR0_CS pin low (normal configuration) #define CHIP_ID 0x0000 // 15:8 PARTID 0xA0 - 8 bit identifier for SGTL5000 // 7:0 REVID 0x00 - revision number for SGTL5000. #define CHIP_DIG_POWER 0x0002 // 6 ADC_POWERUP 1=Enable, 0=disable the ADC block, both digital & analog, // 5 DAC_POWERUP 1=Enable, 0=disable the DAC block, both analog and digital // 4 DAP_POWERUP 1=Enable, 0=disable the DAP block // 1 I2S_OUT_POWERUP 1=Enable, 0=disable the I2S data output // 0 I2S_IN_POWERUP 1=Enable, 0=disable the I2S data input #define CHIP_CLK_CTRL 0x0004 // 5:4 RATE_MODE Sets the sample rate mode. MCLK_FREQ is still specified // relative to the rate in SYS_FS // 0x0 = SYS_FS specifies the rate // 0x1 = Rate is 1/2 of the SYS_FS rate // 0x2 = Rate is 1/4 of the SYS_FS rate // 0x3 = Rate is 1/6 of the SYS_FS rate // 3:2 SYS_FS Sets the internal system sample rate (default=2) // 0x0 = 32 kHz // 0x1 = 44.1 kHz // 0x2 = 48 kHz // 0x3 = 96 kHz // 1:0 MCLK_FREQ Identifies incoming SYS_MCLK frequency and if the PLL should be used // 0x0 = 256*Fs // 0x1 = 384*Fs // 0x2 = 512*Fs // 0x3 = Use PLL // The 0x3 (Use PLL) setting must be used if the SYS_MCLK is not // a standard multiple of Fs (256, 384, or 512). This setting can // also be used if SYS_MCLK is a standard multiple of Fs. // Before this field is set to 0x3 (Use PLL), the PLL must be // powered up by setting CHIP_ANA_POWER->PLL_POWERUP and // CHIP_ANA_POWER->VCOAMP_POWERUP. Also, the PLL dividers must // be calculated based on the external MCLK rate and // CHIP_PLL_CTRL register must be set (see CHIP_PLL_CTRL register // description details on how to calculate the divisors). #define CHIP_I2S_CTRL 0x0006 // 8 SCLKFREQ Sets frequency of I2S_SCLK when in master mode (MS=1). When in slave // mode (MS=0), this field must be set appropriately to match SCLK input // rate. // 0x0 = 64Fs // 0x1 = 32Fs - Not supported for RJ mode (I2S_MODE = 1) // 7 MS Configures master or slave of I2S_LRCLK and I2S_SCLK. // 0x0 = Slave: I2S_LRCLK an I2S_SCLK are inputs // 0x1 = Master: I2S_LRCLK and I2S_SCLK are outputs // NOTE: If the PLL is used (CHIP_CLK_CTRL->MCLK_FREQ==0x3), // the SGTL5000 must be a master of the I2S port (MS==1) // 6 SCLK_INV Sets the edge that data (input and output) is clocked in on for I2S_SCLK // 0x0 = data is valid on rising edge of I2S_SCLK // 0x1 = data is valid on falling edge of I2S_SCLK // 5:4 DLEN I2S data length (default=1) // 0x0 = 32 bits (only valid when SCLKFREQ=0), // not valid for Right Justified Mode // 0x1 = 24 bits (only valid when SCLKFREQ=0) // 0x2 = 20 bits // 0x3 = 16 bits // 3:2 I2S_MODE Sets the mode for the I2S port // 0x0 = I2S mode or Left Justified (Use LRALIGN to select) // 0x1 = Right Justified Mode // 0x2 = PCM Format A/B // 0x3 = RESERVED // 1 LRALIGN I2S_LRCLK Alignment to data word. Not used for Right Justified mode // 0x0 = Data word starts 1 I2S_SCLK delay after I2S_LRCLK // transition (I2S format, PCM format A) // 0x1 = Data word starts after I2S_LRCLK transition (left // justified format, PCM format B) // 0 LRPOL I2S_LRCLK Polarity when data is presented. // 0x0 = I2S_LRCLK = 0 - Left, 1 - Right // 1x0 = I2S_LRCLK = 0 - Right, 1 - Left // The left subframe should be presented first regardless of // the setting of LRPOL. #define CHIP_SSS_CTRL 0x000A // 14 DAP_MIX_LRSWAP DAP Mixer Input Swap // 0x0 = Normal Operation // 0x1 = Left and Right channels for the DAP MIXER Input are swapped. // 13 DAP_LRSWAP DAP Mixer Input Swap // 0x0 = Normal Operation // 0x1 = Left and Right channels for the DAP Input are swapped // 12 DAC_LRSWAP DAC Input Swap // 0x0 = Normal Operation // 0x1 = Left and Right channels for the DAC are swapped // 10 I2S_LRSWAP I2S_DOUT Swap // 0x0 = Normal Operation // 0x1 = Left and Right channels for the I2S_DOUT are swapped // 9:8 DAP_MIX_SELECT Select data source for DAP mixer // 0x0 = ADC // 0x1 = I2S_IN // 0x2 = Reserved // 0x3 = Reserved // 7:6 DAP_SELECT Select data source for DAP // 0x0 = ADC // 0x1 = I2S_IN // 0x2 = Reserved // 0x3 = Reserved // 5:4 DAC_SELECT Select data source for DAC (default=1) // 0x0 = ADC // 0x1 = I2S_IN // 0x2 = Reserved // 0x3 = DAP // 1:0 I2S_SELECT Select data source for I2S_DOUT // 0x0 = ADC // 0x1 = I2S_IN // 0x2 = Reserved // 0x3 = DAP #define CHIP_ADCDAC_CTRL 0x000E // 13 VOL_BUSY_DAC_RIGHT Volume Busy DAC Right // 0x0 = Ready // 0x1 = Busy - This indicates the channel has not reached its // programmed volume/mute level // 12 VOL_BUSY_DAC_LEFT Volume Busy DAC Left // 0x0 = Ready // 0x1 = Busy - This indicates the channel has not reached its // programmed volume/mute level // 9 VOL_RAMP_EN Volume Ramp Enable (default=1) // 0x0 = Disables volume ramp. New volume settings take immediate // effect without a ramp // 0x1 = Enables volume ramp // This field affects DAC_VOL. The volume ramp effects both // volume settings and mute When set to 1 a soft mute is enabled. // 8 VOL_EXPO_RAMP Exponential Volume Ramp Enable // 0x0 = Linear ramp over top 4 volume octaves // 0x1 = Exponential ramp over full volume range // This bit onlay takes effect if VOL_RAMP_EN is 1. // 3 DAC_MUTE_RIGHT DAC Right Mute (default=1) // 0x0 = Unmute // 0x1 = Muted // If VOL_RAMP_EN = 1, this is a soft mute. // 2 DAC_MUTE_LEFT DAC Left Mute (default=1) // 0x0 = Unmute // 0x1 = Muted // If VOL_RAMP_EN = 1, this is a soft mute. // 1 ADC_HPF_FREEZE ADC High Pass Filter Freeze // 0x0 = Normal operation // 0x1 = Freeze the ADC high-pass filter offset register. The // offset continues to be subtracted from the ADC data stream. // 0 ADC_HPF_BYPASS ADC High Pass Filter Bypass // 0x0 = Normal operation // 0x1 = Bypassed and offset not updated #define CHIP_DAC_VOL 0x0010 // 15:8 DAC_VOL_RIGHT DAC Right Channel Volume. Set the Right channel DAC volume // with 0.5017 dB steps from 0 to -90 dB // 0x3B and less = Reserved // 0x3C = 0 dB // 0x3D = -0.5 dB // 0xF0 = -90 dB // 0xFC and greater = Muted // If VOL_RAMP_EN = 1, there is an automatic ramp to the // new volume setting. // 7:0 DAC_VOL_LEFT DAC Left Channel Volume. Set the Left channel DAC volume // with 0.5017 dB steps from 0 to -90 dB // 0x3B and less = Reserved // 0x3C = 0 dB // 0x3D = -0.5 dB // 0xF0 = -90 dB // 0xFC and greater = Muted // If VOL_RAMP_EN = 1, there is an automatic ramp to the // new volume setting. #define CHIP_PAD_STRENGTH 0x0014 // 9:8 I2S_LRCLK I2S LRCLK Pad Drive Strength (default=1) // Sets drive strength for output pads per the table below. // VDDIO 1.8 V 2.5 V 3.3 V // 0x0 = Disable // 0x1 = 1.66 mA 2.87 mA 4.02 mA // 0x2 = 3.33 mA 5.74 mA 8.03 mA // 0x3 = 4.99 mA 8.61 mA 12.05 mA // 7:6 I2S_SCLK I2S SCLK Pad Drive Strength (default=1) // 5:4 I2S_DOUT I2S DOUT Pad Drive Strength (default=1) // 3:2 CTRL_DATA I2C DATA Pad Drive Strength (default=3) // 1:0 CTRL_CLK I2C CLK Pad Drive Strength (default=3) // (all use same table as I2S_LRCLK) #define CHIP_ANA_ADC_CTRL 0x0020 // 8 ADC_VOL_M6DB ADC Volume Range Reduction // This bit shifts both right and left analog ADC volume // range down by 6.0 dB. // 0x0 = No change in ADC range // 0x1 = ADC range reduced by 6.0 dB // 7:4 ADC_VOL_RIGHT ADC Right Channel Volume // Right channel analog ADC volume control in 1.5 dB steps. // 0x0 = 0 dB // 0x1 = +1.5 dB // ... // 0xF = +22.5 dB // This range is -6.0 dB to +16.5 dB if ADC_VOL_M6DB is set to 1. // 3:0 ADC_VOL_LEFT ADC Left Channel Volume // (same scale as ADC_VOL_RIGHT) #define CHIP_ANA_HP_CTRL 0x0022 // 14:8 HP_VOL_RIGHT Headphone Right Channel Volume (default 0x18) // Right channel headphone volume control with 0.5 dB steps. // 0x00 = +12 dB // 0x01 = +11.5 dB // 0x18 = 0 dB // ... // 0x7F = -51.5 dB // 6:0 HP_VOL_LEFT Headphone Left Channel Volume (default 0x18) // (same scale as HP_VOL_RIGHT) #define CHIP_ANA_CTRL 0x0024 // 15:9 Reserved // 8 MUTE_LO LINEOUT Mute, 0 = Unmute, 1 = Mute (default 1) // 7 Reserved // 6 SELECT_HP Select the headphone input, 0 = DAC, 1 = LINEIN // 5 EN_ZCD_HP Enable the headphone zero cross detector (ZCD) // 0x0 = HP ZCD disabled // 0x1 = HP ZCD enabled // 4 MUTE_HP Mute the headphone outputs, 0 = Unmute, 1 = Mute (default) // 3 Reserved // 2 SELECT_ADC Select the ADC input, 0 = Microphone, 1 = LINEIN // 1 EN_ZCD_ADC Enable the ADC analog zero cross detector (ZCD) // 0x0 = ADC ZCD disabled // 0x1 = ADC ZCD enabled // 0 MUTE_ADC Mute the ADC analog volume, 0 = Unmute, 1 = Mute (default) #define CHIP_LINREG_CTRL 0x0026 // 6 VDDC_MAN_ASSN Determines chargepump source when VDDC_ASSN_OVRD is set. // 0x0 = VDDA // 0x1 = VDDIO // 5 VDDC_ASSN_OVRD Charge pump Source Assignment Override // 0x0 = Charge pump source is automatically assigned based // on higher of VDDA and VDDIO // 0x1 = the source of charge pump is manually assigned by // VDDC_MAN_ASSN If VDDIO and VDDA are both the same // and greater than 3.1 V, VDDC_ASSN_OVRD and // VDDC_MAN_ASSN should be used to manually assign // VDDIO as the source for charge pump. // 3:0 D_PROGRAMMING Sets the VDDD linear regulator output voltage in 50 mV steps. // Must clear the LINREG_SIMPLE_POWERUP and STARTUP_POWERUP bits // in the 0x0030 (CHIP_ANA_POWER) register after power-up, for // this setting to produce the proper VDDD voltage. // 0x0 = 1.60 // 0xF = 0.85 #define CHIP_REF_CTRL 0x0028 // bandgap reference bias voltage and currents // 8:4 VAG_VAL Analog Ground Voltage Control // These bits control the analog ground voltage in 25 mV steps. // This should usually be set to VDDA/2 or lower for best // performance (maximum output swing at minimum THD). This VAG // reference is also used for the DAC and ADC voltage reference. // So changing this voltage scales the output swing of the DAC // and the output signal of the ADC. // 0x00 = 0.800 V // 0x1F = 1.575 V // 3:1 BIAS_CTRL Bias control // These bits adjust the bias currents for all of the analog // blocks. By lowering the bias current a lower quiescent power // is achieved. It should be noted that this mode can affect // performance by 3-4 dB. // 0x0 = Nominal // 0x1-0x3=+12.5% // 0x4=-12.5% // 0x5=-25% // 0x6=-37.5% // 0x7=-50% // 0 SMALL_POP VAG Ramp Control // Setting this bit slows down the VAG ramp from ~200 to ~400 ms // to reduce the startup pop, but increases the turn on/off time. // 0x0 = Normal VAG ramp // 0x1 = Slow down VAG ramp #define CHIP_MIC_CTRL 0x002A // microphone gain & internal microphone bias // 9:8 BIAS_RESISTOR MIC Bias Output Impedance Adjustment // Controls an adjustable output impedance for the microphone bias. // If this is set to zero the micbias block is powered off and // the output is highZ. // 0x0 = Powered off // 0x1 = 2.0 kohm // 0x2 = 4.0 kohm // 0x3 = 8.0 kohm // 6:4 BIAS_VOLT MIC Bias Voltage Adjustment // Controls an adjustable bias voltage for the microphone bias // amp in 250 mV steps. This bias voltage setting should be no // more than VDDA-200 mV for adequate power supply rejection. // 0x0 = 1.25 V // ... // 0x7 = 3.00 V // 1:0 GAIN MIC Amplifier Gain // Sets the microphone amplifier gain. At 0 dB setting the THD // can be slightly higher than other paths- typically around // ~65 dB. At other gain settings the THD are better. // 0x0 = 0 dB // 0x1 = +20 dB // 0x2 = +30 dB // 0x3 = +40 dB #define CHIP_LINE_OUT_CTRL 0x002C // 11:8 OUT_CURRENT Controls the output bias current for the LINEOUT amplifiers. The // nominal recommended setting for a 10 kohm load with 1.0 nF load cap // is 0x3. There are only 5 valid settings. // 0x0=0.18 mA // 0x1=0.27 mA // 0x3=0.36 mA // 0x7=0.45 mA // 0xF=0.54 mA // 5:0 LO_VAGCNTRL LINEOUT Amplifier Analog Ground Voltage // Controls the analog ground voltage for the LINEOUT amplifiers // in 25 mV steps. This should usually be set to VDDIO/2. // 0x00 = 0.800 V // ... // 0x1F = 1.575 V // ... // 0x23 = 1.675 V // 0x24-0x3F are invalid #define CHIP_LINE_OUT_VOL 0x002E // 12:8 LO_VOL_RIGHT LINEOUT Right Channel Volume (default=4) // Controls the right channel LINEOUT volume in 0.5 dB steps. // Higher codes have more attenuation. // 4:0 LO_VOL_LEFT LINEOUT Left Channel Output Level (default=4) // Used to normalize the output level of the left line output // to full scale based on the values used to set // LINE_OUT_CTRL->LO_VAGCNTRL and CHIP_REF_CTRL->VAG_VAL. // In general this field should be set to: // 40*log((VAG_VAL)/(LO_VAGCNTRL)) + 15 // Suggested values based on typical VDDIO and VDDA voltages. // VDDA VAG_VAL VDDIO LO_VAGCNTRL LO_VOL_* // 1.8 V 0.9 3.3 V 1.55 0x06 // 1.8 V 0.9 1.8 V 0.9 0x0F // 3.3 V 1.55 1.8 V 0.9 0x19 // 3.3 V 1.55 3.3 V 1.55 0x0F // After setting to the nominal voltage, this field can be used // to adjust the output level in +/-0.5 dB increments by using // values higher or lower than the nominal setting. #define CHIP_ANA_POWER 0x0030 // power down controls for the analog blocks. // The only other power-down controls are BIAS_RESISTOR in the MIC_CTRL register // and the EN_ZCD control bits in ANA_CTRL. // 14 DAC_MONO While DAC_POWERUP is set, this allows the DAC to be put into left only // mono operation for power savings. 0=mono, 1=stereo (default) // 13 LINREG_SIMPLE_POWERUP Power up the simple (low power) digital supply regulator. // After reset, this bit can be cleared IF VDDD is driven // externally OR the primary digital linreg is enabled with // LINREG_D_POWERUP // 12 STARTUP_POWERUP Power up the circuitry needed during the power up ramp and reset. // After reset this bit can be cleared if VDDD is coming from // an external source. // 11 VDDC_CHRGPMP_POWERUP Power up the VDDC charge pump block. If neither VDDA or VDDIO // is 3.0 V or larger this bit should be cleared before analog // blocks are powered up. // 10 PLL_POWERUP PLL Power Up, 0 = Power down, 1 = Power up // When cleared, the PLL is turned off. This must be set before // CHIP_CLK_CTRL->MCLK_FREQ is programmed to 0x3. The // CHIP_PLL_CTRL register must be configured correctly before // setting this bit. // 9 LINREG_D_POWERUP Power up the primary VDDD linear regulator, 0 = Power down, 1 = Power up // 8 VCOAMP_POWERUP Power up the PLL VCO amplifier, 0 = Power down, 1 = Power up // 7 VAG_POWERUP Power up the VAG reference buffer. // Setting this bit starts the power up ramp for the headphone // and LINEOUT. The headphone (and/or LINEOUT) powerup should // be set BEFORE clearing this bit. When this bit is cleared // the power-down ramp is started. The headphone (and/or LINEOUT) // powerup should stay set until the VAG is fully ramped down // (200 to 400 ms after clearing this bit). // 0x0 = Power down, 0x1 = Power up // 6 ADC_MONO While ADC_POWERUP is set, this allows the ADC to be put into left only // mono operation for power savings. This mode is useful when // only using the microphone input. // 0x0 = Mono (left only), 0x1 = Stereo // 5 REFTOP_POWERUP Power up the reference bias currents // 0x0 = Power down, 0x1 = Power up // This bit can be cleared when the part is a sleep state // to minimize analog power. // 4 HEADPHONE_POWERUP Power up the headphone amplifiers // 0x0 = Power down, 0x1 = Power up // 3 DAC_POWERUP Power up the DACs // 0x0 = Power down, 0x1 = Power up // 2 CAPLESS_HEADPHONE_POWERUP Power up the capless headphone mode // 0x0 = Power down, 0x1 = Power up // 1 ADC_POWERUP Power up the ADCs // 0x0 = Power down, 0x1 = Power up // 0 LINEOUT_POWERUP Power up the LINEOUT amplifiers // 0x0 = Power down, 0x1 = Power up #define CHIP_PLL_CTRL 0x0032 // 15:11 INT_DIVISOR // 10:0 FRAC_DIVISOR #define CHIP_CLK_TOP_CTRL 0x0034 // 11 ENABLE_INT_OSC Setting this bit enables an internal oscillator to be used for the // zero cross detectors, the short detect recovery, and the // charge pump. This allows the I2S clock to be shut off while // still operating an analog signal path. This bit can be kept // on when the I2S clock is enabled, but the I2S clock is more // accurate so it is preferred to clear this bit when I2S is present. // 3 INPUT_FREQ_DIV2 SYS_MCLK divider before PLL input // 0x0 = pass through // 0x1 = SYS_MCLK is divided by 2 before entering PLL // This must be set when the input clock is above 17 Mhz. This // has no effect when the PLL is powered down. #define CHIP_ANA_STATUS 0x0036 // 9 LRSHORT_STS This bit is high whenever a short is detected on the left or right // channel headphone drivers. // 8 CSHORT_STS This bit is high whenever a short is detected on the capless headphone // common/center channel driver. // 4 PLL_IS_LOCKED This bit goes high after the PLL is locked. #define CHIP_ANA_TEST1 0x0038 // intended only for debug. #define CHIP_ANA_TEST2 0x003A // intended only for debug. #define CHIP_SHORT_CTRL 0x003C #define DAP_AVC_CTRL 0x0124 //audio volume control // 0 Disable bool audio_enable(int fs_mode) { int sgtl_mode=fs_mode-2; if(sgtl_mode>3) sgtl_mode=3; if(sgtl_mode<0) sgtl_mode=0; // muted = true; // Serial.print("audio ID = "); // delay(5); // unsigned int n = read(CHIP_ID); // Serial.println(n, HEX); chipWrite(CHIP_ANA_POWER, 0x4060); // VDDD is externally driven with 1.8V chipWrite(CHIP_LINREG_CTRL, 0x006C); // VDDA & VDDIO both over 3.1V chipWrite(CHIP_REF_CTRL, 0x01F0); // VAG=1.575, normal ramp, no bias current; //chipWrite(CHIP_REF_CTRL, 0x01F2); // VAG=1.575, normal ramp, +12.5% bias current chipWrite(CHIP_MIC_CTRL, 0x00); // Mic bias off; Mic Amplifier gain 0 dB chipWrite(CHIP_LINE_OUT_CTRL, 0x0F22); // LO_VAGCNTRL=1.65V, OUT_CURRENT=0.54mA chipWrite(CHIP_SHORT_CTRL, 0x4446); // allow up to 125mA chipWrite(CHIP_ANA_CTRL, 0x0137); // enable zero cross detectors audio_power_up(); delay(400); //chipWrite(CHIP_LINE_OUT_VOL, 0x1D1D); // default approx 1.3 volts peak-to-peak chipWrite(CHIP_LINE_OUT_VOL, 0x1919); // default approx 1.3 volts peak-to-peak // chipWrite(CHIP_CLK_CTRL, (sgtl_mode<<2)); // 256*Fs| sgtl_mode = 0:32 kHz; 1:44.1 kHz; 2:48 kHz; 3:96 kHz chipWrite(CHIP_I2S_CTRL, 0x0130); // SCLK=32*Fs, 16bit, I2S format // default signal routing is ok? //chipWrite(CHIP_SSS_CTRL, 0x0010); // ADC->I2S, I2S->DAC chipWrite(CHIP_SSS_CTRL, 0x0000); // ADC->I2S, ADC->DAC chipWrite(CHIP_ADCDAC_CTRL, 0x0008); // DAC mute right; DAC left unmute; ADC HPF normal operation chipWrite(CHIP_DAC_VOL, 0xFF3C); // dac mute right; left 0 dB chipWrite(CHIP_ANA_HP_CTRL, 0x7F7F); // set headphone volume (lowest level) //chipWrite(CHIP_ANA_CTRL, 0x0036); // enable zero cross detectors; line input chipWrite(DAP_AVC_CTRL, 0x0000); //no automatic volume control //chipWrite(CHIP_ANA_CTRL, 0x0114); // lineout mute, headphone mute, no zero cross detectors, line input selected chipWrite(CHIP_ANA_CTRL, 0x0014); // lineout unmute, headphone mute, no zero cross detectors, line input selected chipWrite(CHIP_MIC_CTRL, 0x0000); //microphone off //chipWrite(CHIP_ANA_ADC_CTRL, 0x0000); // 0 dB gain //chipWrite(CHIP_ANA_ADC_CTRL, 0x0100); // -6 dB gain //Serial.print("Set gain:"); //Serial.println(gainSetting); chipWrite(CHIP_ANA_ADC_CTRL, gainSetting); // set left gain return true; } /* bool audio_enable(int fs_mode) { int sgtl_mode=fs_mode-2; if(sgtl_mode>3) sgtl_mode=3; if(sgtl_mode<0) sgtl_mode=0; // muted = true; // Serial.print("audio ID = "); // delay(5); // unsigned int n = read(CHIP_ID); // Serial.println(n, HEX); chipWrite(CHIP_ANA_POWER, 0x4060); // VDDD is externally driven with 1.8V chipWrite(CHIP_LINREG_CTRL, 0x006C); // VDDA & VDDIO both over 3.1V chipWrite(CHIP_REF_CTRL, 0x01F0); // VAG=1.575, normal ramp, normal bias current; less pronounced noise in quiet // chipWrite(CHIP_REF_CTRL, 0x01F2); // VAG=1.575, normal ramp, +12.5% bias current; more pronounced noise in quiet //chipWrite(CHIP_REF_CTRL, 0x01F4); // VAG=1.575, normal ramp, -12.5% bias current chipWrite(CHIP_LINE_OUT_CTRL, 0x0F22); // LO_VAGCNTRL=1.65V, OUT_CURRENT=0.54mA chipWrite(CHIP_SHORT_CTRL, 0x0000); // disable headphone short control //chipWrite(CHIP_SHORT_CTRL, 0x4446); // allow up to 125mA // chipWrite(CHIP_ANA_CTRL, 0x0137); // enable zero cross detectors audio_power_up(); //chipWrite(CHIP_LINE_OUT_VOL, 0x1D1D); // default approx 1.3 volts peak-to-peak //chipWrite(CHIP_LINE_OUT_VOL, 0x1919); // default approx 1.3 volts peak-to-peak chipWrite(CHIP_CLK_CTRL, (sgtl_mode<<2)); // 256*Fs| sgtl_mode = 0:32 kHz; 1:44.1 kHz; 2:48 kHz; 3:96 kHz chipWrite(CHIP_I2S_CTRL, 0x0130); // SCLK=32*Fs, 16bit, I2S format // default signal routing is ok? //chipWrite(CHIP_SSS_CTRL, 0x0010); // ADC->I2S, I2S->DAC chipWrite(CHIP_SSS_CTRL, 0x0000); // ADC->I2S, ADC->DAC chipWrite(CHIP_ADCDAC_CTRL, 0x0008); // DAC mute right; DAC left unmute; ADC HPF normal operation chipWrite(CHIP_DAC_VOL, 0xFFFF); // dac mute right; DAC mute left chipWrite(CHIP_ANA_HP_CTRL, 0x7F7F); // set headphone volume (lowest level) //chipWrite(CHIP_ANA_CTRL, 0x0036); // enable zero cross detectors; line input chipWrite(DAP_AVC_CTRL, 0x0000); //no automatic volume control chipWrite(CHIP_ANA_CTRL, 0x0114); // lineout mute, headphone mute, no zero cross detectors, line input selected //chipWrite(CHIP_ANA_CTRL, 0x0014); // lineout unmute, headphone mute, no zero cross detectors, line input selected chipWrite(CHIP_MIC_CTRL, 0x0000); //microphone off //chipWrite(CHIP_ANA_ADC_CTRL, 0x0000); // 0 dB gain //chipWrite(CHIP_ANA_ADC_CTRL, 0x0100); // -6 dB gain Serial.print("Set gain:"); Serial.println(gainSetting); Serial.println(chipWrite(CHIP_ANA_ADC_CTRL, gainSetting<<4 | gainSetting)); // set left and right gain return true; } */ void audio_freeze_adc_hp(){ chipWrite(CHIP_ADCDAC_CTRL, 0x000A); // DAC mute right; DAC left unmute; ADC high pass filter frozen; ADC HPF normal operation } void audio_bypass_adc_hp(){ chipWrite(CHIP_ADCDAC_CTRL, 0x000B); // DAC mute right; DAC left unmute; ADC high pass filter frozen; ADC HPF bypassed (so does not matter it is frozen); get offset of about 370 units } void audio_power_down(void){ chipWrite(CHIP_ANA_POWER, 0x0000); // analog power down: everything chipWrite(CHIP_DIG_POWER, 0x0000); // digital power down: everything } void audio_power_up(void){ if(NCHAN==2) chipWrite(CHIP_ANA_POWER, 0x00E2); // power up: adc Stereo = E2; Mono (Left): A2 else chipWrite(CHIP_ANA_POWER, 0x00A2); // power up: adc Stereo = E2; Mono (Left): A2 chipWrite(CHIP_DIG_POWER, 0x0043); // power up only analag ADC and I2S; disable DAC and DAP } bool chipWrite(unsigned int reg, unsigned int val) { // if (reg == CHIP_ANA_CTRL) ana_ctrl = val; Wire.beginTransmission(SGTL5000_I2C_ADDR); Wire.write(reg >> 8); Wire.write(reg); Wire.write(val >> 8); Wire.write(val); if (Wire.endTransmission() == 0) return true; return false; } //------------------------------modify I2S------------------------------------------- // attempt to generate dividers programmatically // always better to check void I2S_dividers(uint32_t *iscl, uint32_t fsamp, uint32_t nbits) { int64_t i1 = 1; int64_t i2 = 1; int64_t i3 = iscl[2]+1; int fcpu=F_CPU; if((F_CPU==96000000) || (F_CPU==48000000) || (F_CPU==24000000)) fcpu=96000000; float A=fcpu/2.0f/i3/(2.0f*nbits*fsamp); float mn=1.0; for(int ii=1;ii<64;ii++) { float xx; xx=A*ii-(int32_t)(A*ii); if(xx<mn && A*ii<256.0) { mn=xx; i1=ii; i2=A*ii;} //select first candidate } iscl[0] = (int) (i1-1); iscl[1] = (int) (i2-1); iscl[2] = (int) (i3-1); } void I2S_modification(uint32_t fsamp, uint16_t nbits) { uint32_t iscl[3]; if(nbits==16) iscl[2]=3; // 16 bit I2S (256/2*(2*16)-1) else if(nbits==32) iscl[2]=1; // 32 bit modified I2S (256/(2*(2*32)-1) I2S_dividers(iscl, fsamp ,nbits); int fcpu=F_CPU; if((F_CPU==96000000) || (F_CPU==48000000) || (F_CPU==24000000)) fcpu=96000000; float fs = (fcpu * (iscl[0]+1.0f)) / (iscl[1]+1l) / 2 / (iscl[2]+1l) / (2l*nbits); if(printDiags) Serial.printf("%d %d: %d %d %d %d %d %d\n\r", F_CPU, fcpu, fsamp, (int)fs, nbits,iscl[0]+1,iscl[1]+1,iscl[2]+1); // stop I2S I2S0_RCSR &= ~(I2S_RCSR_RE | I2S_RCSR_BCE); // modify sampling frequency I2S0_MDR = I2S_MDR_FRACT(iscl[0]) | I2S_MDR_DIVIDE(iscl[1]); // configure transmitter I2S0_TCR2 = I2S_TCR2_SYNC(0) | I2S_TCR2_BCP | I2S_TCR2_MSEL(1) | I2S_TCR2_BCD | I2S_TCR2_DIV(iscl[2]); // configure receiver (sync'd to transmitter clocks) I2S0_RCR2 = I2S_RCR2_SYNC(1) | I2S_TCR2_BCP | I2S_RCR2_MSEL(1) | I2S_RCR2_BCD | I2S_RCR2_DIV(iscl[2]); //restart I2S I2S0_RCSR |= I2S_RCSR_RE | I2S_RCSR_BCE; }
d091bc6bcc6451360e0d2aefb19a2d00f8a9419e
39ed472003b20d0844bd7fdd3b1db366ff1394d1
/Pirates Hide and Seek/Source.cpp
6068f6e7d06add2bbbfdfb1ae7db3cc914b4bcd9
[ "MIT" ]
permissive
AdrianCert/Pirates-Hide-and-Seek
785d27bde1f8a652dbaddf84e36686e970d3e1fb
ec430e8fe9e20820d663c25d78732f7b805dbe05
refs/heads/master
2020-11-26T10:21:08.080820
2020-01-19T08:16:50
2020-01-19T08:16:50
229,040,432
0
2
MIT
2020-01-16T09:52:24
2019-12-19T11:27:59
C++
UTF-8
C++
false
false
2,381
cpp
Source.cpp
#include "Source.h" #include "Level.h" using namespace sf; int main() { int gameWidth, gameHeight, gameSSyle; std::string gameName; cfg::dictionaty* configuration = new cfg::dictionaty(); if (!ReadConfiguration(configuration, "Resource/ConfigureFile.txt")) return EXIT_FAILURE; if (!GetParm(configuration, "gameWidth", gameWidth) || !GetParm(configuration, "gameHeight", gameHeight) || !GetParm(configuration, "gameName", gameName) || !GetParm(configuration, "gameSSyle", gameSSyle) ) return EXIT_FAILURE; sf::ContextSettings settings; settings.antialiasingLevel = 8; sf::Music music1, music2, music3, music4; if (!music1.openFromFile("Resource/song1.ogg") || !music2.openFromFile("Resource/song2.ogg") || !music3.openFromFile("Resource/song3.ogg") || !music4.openFromFile("Resource/song4.ogg") ) return EXIT_FAILURE; // error sf::Music* music[4] = {&music1, &music2, &music3, &music4 }; int* user_settings = new int[GameEnum::OptionField::OptionFieldCount]; GetParm(configuration, "music", user_settings[GameEnum::OptionField::Music]); GetParm(configuration, "sfx", user_settings[GameEnum::OptionField::SFX]); RenderWindow window(VideoMode(gameWidth, gameHeight), gameName, gameSSyle, settings); window.setFramerateLimit(140); SceneManager* sceneManager = new SceneManager(); sceneManager->RenderWindow = &window; sceneManager->CurentFrame = GameEnum::GameFrame::Intro; sceneManager->Configurator = configuration; sceneManager->LevelState = 0; sceneManager->djValy = music; sceneManager->Settings = user_settings; while (window.isOpen()) { bool gameContinue = false; switch (sceneManager->CurentFrame) { case GameEnum::GameFrame::Intro: gameContinue = Intro(sceneManager); break; case GameEnum::GameFrame::GameSelection: gameContinue = GameSelect(sceneManager); break; case GameEnum::GameFrame::Menu: gameContinue = Menu(sceneManager); break; case GameEnum::GameFrame::Game: gameContinue = Game(sceneManager); break; case GameEnum::GameFrame::Option: gameContinue = Option(sceneManager); break; case GameEnum::GameFrame::Exit: window.close(); break; case GameEnum::GameFrame::HowToPlay: gameContinue = howto(sceneManager); break; default: break; } if(!gameContinue) sceneManager->CurentFrame = GameEnum::GameFrame::Exit; } return EXIT_SUCCESS; }
7f81635b5b2864a2e31edd38f5f16daedcd84f7c
898c761766be7b0db4ea51e50f11953a04da0f50
/2021-3-14/ARC114/C.cpp
f2d3fc216234cf19dc1648461f709a461bb29ba8
[]
no_license
zhoufangyuanTV/zzzz
342f87de6fdbdc7f8c6dce12649fe96c2c1bcf9c
1d686ff1bc6adb883fa18d0e110df7f82ebe568d
refs/heads/master
2023-08-25T03:22:41.184640
2021-09-30T12:42:01
2021-09-30T12:42:01
286,425,935
0
0
null
null
null
null
UTF-8
C++
false
false
580
cpp
C.cpp
#include<cstdio> #include<cstring> using namespace std; long long ksm(long long x,long long k) { long long s=1; while(k>0) { if(k&1)s=s*x%998244353; x=x*x%998244353; k>>=1; } return s; } long long a[5100]; int main() { int n,m;scanf("%d%d",&n,&m); long long p=n,s=0,np=ksm(m,998244351); for(int i=0;i<=m;i++)a[i]=1; long long N=np*np%998244353; for(int i=2;i<=n;i++,N=N*np%998244353) { for(int j=0;j<m;j++)s=(s+a[j]*N)%998244353; p=(p-s+998244353)%998244353; for(int j=0;j<m;j++)a[j]=a[j]*j%998244353; } printf("%lld\n",p*ksm(m,n)%998244353); return 0; }
7faa37869f7d04ce2217cf4c936a384b0a65114c
05e08bccc745c4c2e368c0b8dbcb2574ee610cb2
/spoj/beehive.cpp
089c493c52599e54db2f9d92c4d382be5fd0e4d1
[]
no_license
anurag95/MyCodes
76dce681edd3fa8824dbe94d169d6e8ba4571175
9bd890306f6b10b60ca60a02c9f7e5765b5ac538
refs/heads/master
2021-01-10T13:52:30.866762
2015-11-18T12:41:37
2015-11-18T12:41:37
46,417,942
0
0
null
null
null
null
UTF-8
C++
false
false
468
cpp
beehive.cpp
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define pb push_back #define si(x) scanf("%d", &x); #define sii(x,y) scanf("%d%d", &x, &y); #define sll(x) scanf("%lld", &x); #define pi(x) printf("%d\n", x); #define pll(x) printf("%lld\n", x); int main() { int n; si(n) while(n!=-1) { n--; int i=1; while(n>0) { n-=(6*i); i++; } if(!n) printf("Y\n"); else printf("N\n"); si(n) } return 0; }
6a33ef877f2b565cf703e9155d9f80a87892cb87
fdfbebcc3a5e635b8273d1b39492e797932d547f
/wxRaytracer/raytracer/Textures/TInstance.cpp
02a2fb0ee047593d6034d24139ab7175869cce8b
[]
no_license
WindyPaper/raytracing
eca738ff67ce420be8e151d5c6a4ce62ac749ae4
2e38260e33fd87c1ff07f6212bc394470d89dbbc
refs/heads/master
2021-01-23T06:45:15.360491
2017-09-07T15:29:26
2017-09-07T15:29:26
86,397,382
0
1
null
null
null
null
UTF-8
C++
false
false
5,825
cpp
TInstance.cpp
// Copyright (C) Mp77 2012 // Original from Kevin Suffern 2000-2007 // This C++ code is for non-commercial purposes only. // This C++ code is licensed under the GNU General Public License Version 2. // See the file COPYING.txt for the full license. #include "TInstance.h" #include "Maths.h" TInstance::TInstance(void): texture_ptr(0) { }; TInstance::TInstance(const TInstance& sc): texture_ptr(sc.texture_ptr), inv_matrix(sc.inv_matrix) { }; TInstance::TInstance(Texture *t) : texture_ptr(t) { }; TInstance& TInstance::operator= (const TInstance& rhs) { if (this == &rhs) return (*this); Texture::operator=(rhs); texture_ptr = rhs.texture_ptr; inv_matrix = rhs.inv_matrix; return (*this); }; TInstance* TInstance::clone(void) const { return (new TInstance(*this)); }; TInstance::~TInstance(void) { }; void TInstance::scale(const double sx, const double sy, const double sz) { Matrix inv_scaling_matrix; // temporary inverse scaling matrix inv_scaling_matrix.m[0][0] = 1.0 / sx; inv_scaling_matrix.m[1][1] = 1.0 / sy; inv_scaling_matrix.m[2][2] = 1.0 / sz; inv_matrix = inv_matrix * inv_scaling_matrix; } // Second form of scale function used in 30.01a void TInstance::scale(const double x) { Matrix inv_scaling_matrix; // temporary inverse scaling matrix inv_scaling_matrix.m[0][0] = 1.0 / x; inv_scaling_matrix.m[1][1] = 1.0 / x; inv_scaling_matrix.m[2][2] = 1.0 / x; inv_matrix = inv_matrix * inv_scaling_matrix; } // Note: One line is different here from Listing 30.7. // There is no *= operator implemented for multiplying a Point3D by a // Matrix on the left. // The notation below is consistent with Instance.cpp which uses, for example, // inv_ray.d = inv_matrix * inv_ray.d; RGBColor TInstance::get_color(const ShadeRec& sr) const { ShadeRec local_sr(sr); local_sr.local_hit_point = inv_matrix * local_sr.local_hit_point; return (texture_ptr->get_color(local_sr)); } //-------------------------------------------------------------------------------- translate void TInstance::translate(const Vector3D& trans) { Matrix inv_translation_matrix; // temporary inverse translation matrix inv_translation_matrix.m[0][3] = -trans.x; inv_translation_matrix.m[1][3] = -trans.y; inv_translation_matrix.m[2][3] = -trans.z; inv_matrix = inv_matrix * inv_translation_matrix; } //-------------------------------------------------------------------------------- translate void TInstance::translate(const double dx, const double dy, const double dz) { Matrix inv_translation_matrix; // temporary inverse translation matrix inv_translation_matrix.m[0][3] = -dx; inv_translation_matrix.m[1][3] = -dy; inv_translation_matrix.m[2][3] = -dz; inv_matrix = inv_matrix * inv_translation_matrix; } //-------------------------------------------------------------------------------- rotate_x void TInstance::rotate_x(const double theta) { double sin_theta = sin(theta * PI_ON_180); double cos_theta = cos(theta * PI_ON_180); Matrix inv_x_rotation_matrix; // temporary inverse rotation matrix about x axis inv_x_rotation_matrix.m[1][1] = cos_theta; inv_x_rotation_matrix.m[1][2] = sin_theta; inv_x_rotation_matrix.m[2][1] = -sin_theta; inv_x_rotation_matrix.m[2][2] = cos_theta; inv_matrix = inv_matrix * inv_x_rotation_matrix; } //-------------------------------------------------------------------------------- rotate_y void TInstance::rotate_y(const double theta) { double sin_theta = sin(theta * PI / 180.0); double cos_theta = cos(theta * PI / 180.0); Matrix inv_y_rotation_matrix; // temporary inverse rotation matrix about y axis inv_y_rotation_matrix.m[0][0] = cos_theta; inv_y_rotation_matrix.m[0][2] = -sin_theta; inv_y_rotation_matrix.m[2][0] = sin_theta; inv_y_rotation_matrix.m[2][2] = cos_theta; inv_matrix = inv_matrix * inv_y_rotation_matrix; } //-------------------------------------------------------------------------------- rotate_z void TInstance::rotate_z(const double theta) { double sin_theta = sin(theta * PI / 180.0); double cos_theta = cos(theta * PI / 180.0); Matrix inv_z_rotation_matrix; // temporary inverse rotation matrix about y axis inv_z_rotation_matrix.m[0][0] = cos_theta; inv_z_rotation_matrix.m[0][1] = sin_theta; inv_z_rotation_matrix.m[1][0] = -sin_theta; inv_z_rotation_matrix.m[1][1] = cos_theta; inv_matrix = inv_matrix * inv_z_rotation_matrix; } //-------------------------------------------------------------------------------- shear void TInstance::shear(const Matrix& s) { Matrix inverse_shearing_matrix; // inverse shear matrix // discriminant double d = 1.0 - s.m[1][0] * s.m[0][1] - s.m[2][0] * s.m[0][2] - s.m[2][1] * s.m[1][2] + s.m[1][0] * s.m[2][1] * s.m[0][2] + s.m[2][0] * s.m[0][1] * s.m[2][1]; // diagonals inverse_shearing_matrix.m[0][0] = 1.0 - s.m[2][1] * s.m[1][2]; inverse_shearing_matrix.m[1][1] = 1.0 - s.m[2][0] * s.m[0][2]; inverse_shearing_matrix.m[2][2] = 1.0 - s.m[1][0] * s.m[0][1]; inverse_shearing_matrix.m[3][3] = d; // first row inverse_shearing_matrix.m[0][1] = -s.m[1][0] + s.m[2][0] * s.m[1][2]; inverse_shearing_matrix.m[0][2] = -s.m[2][0] + s.m[1][0] * s.m[2][1]; // second row inverse_shearing_matrix.m[1][0] = -s.m[0][1] + s.m[2][1] * s.m[0][2]; inverse_shearing_matrix.m[1][2] = -s.m[2][1] + s.m[2][0] * s.m[0][1]; // third row inverse_shearing_matrix.m[2][0] = -s.m[0][2] + s.m[0][1] * s.m[1][2]; inverse_shearing_matrix.m[2][1] = -s.m[1][2] + s.m[1][0] * s.m[0][2] ; // divide by discriminant inverse_shearing_matrix = inverse_shearing_matrix / d; inv_matrix = inv_matrix * inverse_shearing_matrix; }
2524b5c4712d8627765432974c0eb5c004a78368
91a882547e393d4c4946a6c2c99186b5f72122dd
/Source/XPSP1/NT/printscan/faxsrv/src/test/src/xxxunusedxxx/deviceioctls/socketserverioctl.cpp
b0ed7d8c8279dfa82ec49c9870c68176eba2563f
[]
no_license
IAmAnubhavSaini/cryptoAlgorithm-nt5src
94f9b46f101b983954ac6e453d0cf8d02aa76fc7
d9e1cdeec650b9d6d3ce63f9f0abe50dabfaf9e2
refs/heads/master
2023-09-02T10:14:14.795579
2021-11-20T13:47:06
2021-11-20T13:47:06
null
0
0
null
null
null
null
UTF-8
C++
false
false
4,438
cpp
socketserverioctl.cpp
#include "DeviceIOCTLS.pch" #pragma hdrstop /* */ #define MAX_PORT_NUM (0xFFFF) // // must be defined 1st to override winsock1 // //#include <winsock2.h> // // defines for WSASocet() params // #define PROTO_TYPE_UNICAST 0 #define PROTO_TYPE_MCAST 1 #define PROTOCOL_ID(Type, VendorMajor, VendorMinor, Id) (((Type)<<28)|((VendorMajor)<<24)|((VendorMinor)<<16)|(Id)) /* #include <windows.h> #include <tchar.h> #include <stdio.h> #include <crtdbg.h> */ #include "SocketServerIOCTL.h" static bool s_fVerbose = false; // // LPWSAOVERLAPPED_COMPLETION_ROUTINE // we do not use it, but we need it defined for the overlapped UDP ::WSARecvFrom() // static void __stdcall fn( DWORD dwError, DWORD cbTransferred, LPWSAOVERLAPPED lpOverlapped, DWORD dwFlags ) { UNREFERENCED_PARAMETER(dwError); UNREFERENCED_PARAMETER(cbTransferred); UNREFERENCED_PARAMETER(lpOverlapped); UNREFERENCED_PARAMETER(dwFlags); return; } CIoctlSocketServer::CIoctlSocketServer(CDevice *pDevice): CIoctlSocket(pDevice) { ; } CIoctlSocketServer::~CIoctlSocketServer() { ; } HANDLE CIoctlSocketServer::CreateDevice(CDevice *pDevice) { m_sListeningSocket = CreateSocket(pDevice); if (INVALID_SOCKET == m_sListeningSocket) { return INVALID_HANDLE_VALUE; } if (!Bind(pDevice, SERVER_SIDE)) { // // so i did not bind, let's IOCTL (m_sListeningSocket) anyway! // return (HANDLE)m_sListeningSocket; //goto error_exit; } // // listen (on TCP) or WSARecvFrom (on UDP). // do not care if I fail. // // // BUGBUG: should i insist on lintening because of fault-injections? // if (true)//m_fTCP { if (SOCKET_ERROR == ::listen(m_sListeningSocket, SOMAXCONN)) { DPF((TEXT("listen() failed with %d.\n"), ::WSAGetLastError())); } else { DPF((TEXT("listen() SUCCEEDED\n"))); } } else//UDP BUGBUG: NIY { // // these must be static, because when we close the socket, the overlapped is aborted // static char buff[1024]; static WSABUF wsabuff; wsabuff.buf = buff; wsabuff.len = sizeof(buff); static DWORD dwNumberOfBytesRecvd; static WSAOVERLAPPED wsaOverlapped; DWORD dwFlags = MSG_PEEK; if (SOCKET_ERROR == ::WSARecvFrom ( m_sListeningSocket, &wsabuff, 1, &dwNumberOfBytesRecvd, &dwFlags, NULL,//struct sockaddr FAR * lpFrom, NULL,//LPINT lpFromlen, &wsaOverlapped, fn ) ) { if (::WSAGetLastError() != ERROR_IO_PENDING) { //HOGGERDPF(("CWSASocketHog::CreatePseudoHandle(%d): WSARecvFrom(%d) failed with %d, m_dwOccupiedAddresses=%d.\n", index, wAddress, ::WSAGetLastError(), m_dwOccupiedAddresses)); } } else { //HOGGERDPF(("CWSASocketHog::CreatePseudoHandle(%d): listen(%d) SUCCEEDED instead failing with ERROR_IO_PENDING, m_dwOccupiedAddresses=%d.\n", index, wAddress, ::WSAGetLastError(), m_dwOccupiedAddresses)); } } // // we may have failed to listen, but since i don't mind failing, i try to accept anyways // it is actually an interesting testcase to accept if listen faile // /* SOCKET sAccept = ::accept( m_sListeningSocket, NULL, //struct sockaddr FAR *addr, NULL //int FAR *addrlen ); */ // // TODO: the m_asAcceptingSocket can accept several connections. // the code does not support it yet, so only 1 accept is performed // m_asAcceptingSocket[0] = ::WSAAccept( m_sListeningSocket, NULL, //struct sockaddr FAR *addr, NULL, //int FAR *addrlen NULL, NULL ); if (INVALID_SOCKET == m_asAcceptingSocket[0]) { // // return the WSASocket() and not the accept() // it may may be interesting to IOCTL this and not that // return (HANDLE)m_sListeningSocket; } else { _ASSERTE(INVALID_HANDLE_VALUE != (HANDLE)m_asAcceptingSocket[0]); return (HANDLE)m_asAcceptingSocket[0]; } return (HANDLE)m_asAcceptingSocket[0]; } BOOL CIoctlSocketServer::CloseDevice(CDevice *pDevice) { ::closesocket(m_asAcceptingSocket[0]); m_asAcceptingSocket[0] = INVALID_SOCKET; return (CloseSocket(pDevice)); }
00d47e6bf048c05583f694b1dda0c3f5fcd7d5a7
39c662ae86764ed201d7f303eb6c109b647b89e5
/FillUpY_Case1.cpp
30e265b5a64c01bf0ccd8dc850202464686e1af7
[]
no_license
yujiadeng/ITRSimulation
d94189652ea521319cba5ecbce09663641f0c406
45e3662bb2a3f5a0d921717f8ebd9852221f89c9
refs/heads/master
2020-04-02T12:24:00.204828
2018-12-15T03:31:38
2018-12-15T03:31:38
154,431,838
1
0
null
2018-12-15T03:18:31
2018-10-24T03:15:47
Python
UTF-8
C++
false
false
510
cpp
FillUpY_Case1.cpp
// // Created by Haoda Fu on 8/5/18. // #include "FillUpY_Case1.h" std::vector<double> FillUpY_Case1::valueY(size_t row, DataTable & dataM, int trt) { std::vector<double> Yi(dataM.getVarY().size(),0); size_t yDim=dataM.getVarY().size(); for(size_t item=0;item < yDim; ++item){ Yi.at(item) = (double)trt+(double(trt)-1.5)*(double)(dataM.getVarX_Cont().at(1).at(row)>0.7 && dataM.getVarX_Nom().at(0).at(row)==0)+2*dataM.getVarX_Cont().at(0).at(row)+rnorm(generator); } return Yi; }
dcd5bcd0c3a7349fb12a27e6cd808b433d566aca
1a98cb54d824e477774337223872792f50be0ef7
/C++/DataStructures/0_Stack/client1.cpp
9c13388d4cb04a80cdef59b2c8bda16580b3e2c7
[]
no_license
jacobgamez/portfolio
2d06be9c107f47d05f25de2f56d0d838bf40e437
9cb2980e60df75363f9afcab666e41e2f383146d
refs/heads/master
2020-04-22T22:59:22.010811
2015-03-05T00:33:34
2015-03-05T00:33:34
30,324,060
0
0
null
null
null
null
UTF-8
C++
false
false
2,699
cpp
client1.cpp
// ========================================================= //Stack Client //Your name: Jacob Gamez //Complier: g++ //File type: cpp client file //================================================================ #ifndef CLIENT_C #define CLIENT_C #include <iostream> #include <string> #include <cctype> //Including to use isdigit #include "stack.h" using namespace std; int main() { stack postfixstack; // integer stack string expression; cout << "type a postfix expression: " ; cin >> expression; int i = 0; // character position within expression char item; int box1; // receive things from pop int box2; // receive things from pop int result; //missing variable from popped boxes & will use for final solution while (expression[i] != '\0') { try { item = expression[i]; //1. read an item. i++; //increment i for the while loop if (isdigit(item)) //Check if is operand (isdigit is function of cctype) { int number=item-'0'; //convert item to integer postfixstack.push(number); //push it (you might get Overflow exception) } //3. else if it is an operator, // pop the two operands (you might get Underflow exception), and // apply the operator to the two operands, and // push the result. else if ( (item == '+') || (item == '-') || (item == '*')) { postfixstack.pop(box1); postfixstack.pop(box2); // a whole bunch of cases if (item == '-') result = box2-box1; // also do the + and * cases else if (item=='+') result=box2+box1; else if (item=='*') result=box2*box1; // push the result postfixstack.push(result); } else throw "invalid item"; } // this closes try // Catch exceptions and report problems and quit the program now. catch (stack::Overflow) { cout << "STACK OVERFLOW: Too many operands" << endl; return 1; } catch (stack::Underflow) { cout << "STACK UNDERFLOW: Not enough operands for operators" << endl; return 1; } catch (char const* errorcode) // for invalid item { cout << "You entered an unsupported symbol" << endl; return 1; } // go back to the loop //End of exception handling }// end of while // After the loop successfully completes: // The result will be at the top of the stack. Pop it and show it. // If anything is left on the stack, an incomplete expression was found // inform the user. postfixstack.pop(result); if(!postfixstack.isEmpty()) { cout << "Incomplete Expression" << endl; return 1; } cout << "Solution: " << result<< endl; return 0; } #endif //CLIENT_C
f0245c30d59b249b10c6a5ad95a0587cf6d94d19
fc30e371a9aef058478fe9e9cb90495f15b1de82
/Spoj_CANTON.cpp
c8a3437aa2801d3a80229da7200e9ac7b17f8b42
[]
no_license
abhi-upadhyay28/Spoj-Solutions
017325457ba9c84a0177ac2c12dfc7919f29f392
30e907c20794ddef426fa4f4805763d9ad644f9f
refs/heads/master
2021-01-21T10:26:04.789744
2017-02-28T17:32:31
2017-02-28T17:32:31
83,429,278
0
0
null
null
null
null
UTF-8
C++
false
false
367
cpp
Spoj_CANTON.cpp
#include<iostream> using namespace std; int main(){ int t; cin>>t; while(t--){ int num,sum=0; cin>>num; int i; for(i=1; ;i++) { sum+=i; if(sum>=num) break; } int total=i+1; int temp=num-(sum-i); if(i%2==0) cout<<"TERM "<<num<<" IS "<<temp<<"/"<<total-temp<<"\n"; else cout<<"TERM "<<num<<" IS "<<total-temp<<"/"<<temp<<"\n"; } return 0; }
35079675faf3280110ec0c28371f7222fd1746a9
3051050dc3dee97dc60ef78d31ff500b6e93d0fb
/ash/capture_mode/capture_mode_behavior.cc
ea72605f5a1ae85654a4f0d7fbac010aebe239a3
[ "BSD-3-Clause" ]
permissive
weblifeio/chromium
cd249e1c9418dcf0792bd68bbdcd2a6e56af0e2e
74ac962b3a95c88614f734066ab2cc48b572359c
refs/heads/main
2023-06-09T19:45:03.535378
2023-05-26T19:16:31
2023-05-26T19:16:31
177,631,387
0
0
null
2019-03-25T17:15:48
2019-03-25T17:15:47
null
UTF-8
C++
false
false
3,880
cc
capture_mode_behavior.cc
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ash/capture_mode/capture_mode_behavior.h" #include <memory> #include "ash/capture_mode/capture_mode_metrics.h" #include "ash/capture_mode/capture_mode_types.h" namespace ash { namespace { // ----------------------------------------------------------------------------- // DefaultBehavior: // Implements the `CaptureModeBehavior` interface with behavior defined for the // default capture mode. class DefaultBehavior : public CaptureModeBehavior { public: DefaultBehavior() : CaptureModeBehavior({CaptureModeType::kImage, CaptureModeSource::kRegion, RecordingType::kWebM, /*audio_on=*/false, /*demo_tools_enabled=*/false}) {} DefaultBehavior(const DefaultBehavior&) = delete; DefaultBehavior& operator=(const DefaultBehavior&) = delete; ~DefaultBehavior() override = default; }; // ----------------------------------------------------------------------------- // ProjectorBehavior: // Implements the `CaptureModeBehavior` interface with behavior defined for the // projector-initiated capture mode. class ProjectorBehavior : public CaptureModeBehavior { public: ProjectorBehavior() : CaptureModeBehavior({CaptureModeType::kVideo, CaptureModeSource::kRegion, RecordingType::kWebM, /*audio_on=*/true, /*demo_tools_enabled=*/true}) {} ProjectorBehavior(const ProjectorBehavior&) = delete; ProjectorBehavior& operator=(const ProjectorBehavior&) = delete; ~ProjectorBehavior() override = default; // CaptureModeBehavior: bool ShouldImageCaptureTypeBeAllowed() const override { return false; } bool ShouldSaveToSettingsBeIncluded() const override { return false; } bool ShouldGifBeSupported() const override { return false; } bool ShouldShowPreviewNotification() const override { return false; } bool ShouldCreateRecordingOverlayController() const override { return true; } }; } // namespace // ----------------------------------------------------------------------------- // CaptureModeBehavior: CaptureModeBehavior::CaptureModeBehavior( const CaptureModeSessionConfigs& configs) : capture_mode_configs_(configs) {} // static std::unique_ptr<CaptureModeBehavior> CaptureModeBehavior::Create( BehaviorType behavior_type) { switch (behavior_type) { case BehaviorType::kProjector: return std::make_unique<ProjectorBehavior>(); case BehaviorType::kDefault: return std::make_unique<DefaultBehavior>(); } } bool CaptureModeBehavior::ShouldImageCaptureTypeBeAllowed() const { return true; } bool CaptureModeBehavior::ShouldVideoCaptureTypeBeAllowed() const { return true; } bool CaptureModeBehavior::ShouldFulscreenCaptureSourceBeAllowed() const { return true; } bool CaptureModeBehavior::ShouldRegionCaptureSourceBeAllowed() const { return true; } bool CaptureModeBehavior::ShouldWindowCaptureSourceBeAllowed() const { return true; } bool CaptureModeBehavior::ShouldAudioInputSettingsBeIncluded() const { return true; } bool CaptureModeBehavior::ShouldCameraSelectionSettingsBeIncluded() const { return true; } bool CaptureModeBehavior::ShouldDemoToolsSettingsBeIncluded() const { return true; } bool CaptureModeBehavior::ShouldSaveToSettingsBeIncluded() const { return true; } bool CaptureModeBehavior::ShouldGifBeSupported() const { return true; } bool CaptureModeBehavior::ShouldShowPreviewNotification() const { return true; } bool CaptureModeBehavior::ShouldSkipVideoRecordingCountDown() const { return false; } bool CaptureModeBehavior::ShouldCreateRecordingOverlayController() const { return false; } } // namespace ash
515f1c5e242fd0730bd1519d4b08e65ece9baf6a
e7164d44058a06331c034cc17eefe1521d6c95a2
/include/feature/FeatureNormalizer.h
5d865327e42ef8d6ae9bfb9534a6138f09fbf8ab
[]
no_license
chenghuige/gezi
fbc1e655396fbc365fffacc10409d35d20e3952c
4fc8f9a3c5837e8add720bf6954a4f52abfff8b5
refs/heads/master
2021-01-20T01:57:18.362413
2016-11-08T15:34:07
2016-11-08T15:34:07
101,304,774
0
3
null
null
null
null
GB18030
C++
false
false
4,121
h
FeatureNormalizer.h
#ifndef _NORMALIZE_FILTER_H_ #define _NORMALIZE_FILTER_H_ #include "Feature.h" #include "common_util.h" #include "stdio.h" #include "stdlib.h" #include <math.h> #include <string.h> namespace gezi { //@TODO 目前Feature已经改成按照TLC标准 0 开始 这个也不再对应 //将会改成完全按照TLC标准 对应增加 linear svm,svm, logistic regression 等等 class FeatureNormalizer { public: //libsvm use 1 as the first index, while tlc or others use 0 FeatureNormalizer(int startIndex = 1, bool useTruncate = false, int maxFeatureNum = 102400) : _startIndex(startIndex), _useTruncate(useTruncate) { _pairs.resize(maxFeatureNum + 1); } FeatureNormalizer& startIndex(int startIndex_) { _startIndex = startIndex_; return *this; } FeatureNormalizer& useTruncate(bool useTruncate_) { _useTruncate = useTruncate_; return *this; } FeatureNormalizer& maxFeatureNum(int maxFeatureNum_) { _pairs.resize(maxFeatureNum_ + 1); return *this; } struct Pair { Pair() : lower(0), upper(0) { } Pair(double lower_, double upper_) : lower(lower_), upper(upper_) { } double lower; double upper; }; //当前是完全参照libsvm 3.17的输出文件格式 bool open(const char* file) { vector<string> lines = read_lines(file); if (lines.empty()) { LOG(WARNING) << "Could not open the file " << file; return false; } vector<string> parts; boost::split(parts, lines[1], is_any_of("\t ")); _lower = DOUBLE(parts[0]); _upper = DOUBLE(parts[1]); size_t i = 2; for (; i < lines.size(); i++) { vector<string> parts; boost::split(parts, lines[i], is_any_of("\t ")); int index = INT(parts[0]); _pairs[index] = Pair(DOUBLE(parts[1]), DOUBLE(parts[2])); if (i == (lines.size() - 1)) { _featureNum = index; } } Pval(_featureNum); return true; } int featureNum() { return _featureNum; } //TODO 专门提出MinMax Guass Bining Normalizer 同时支持 incl 和 excl //可以考虑在添加特征的时候 就做normalize 接近0的不 add <=> Normalize(value) 或者这里整体norm 之后再去掉0的 //TODO 注意当前的设计都是Feature保留有sparse 和 dense 双重value void norm(int index, double value, vector<Feature::Node>& result) { if (_pairs[index].upper == _pairs[index].lower) { //如果相同 该特征在训练数据中未出现 或者所有训练数据中这个特征值都一样 scale文件中没有它的范围 这种特征在线忽略掉 return; } if (_useTruncate) { //注意下面的处理是截断处理不是完全线性scale 和libsvm以及tlc里面处理不同 可能测试集合结果略有不同 if (value <= _pairs[index].lower) { value = _pairs[index].lower; } else if (value >= _pairs[index].upper) { value = _pairs[index].upper; } else { value = _lower + (_upper - _lower) * (value - _pairs[index].lower) / (_pairs[index].upper - _pairs[index].lower); } } else { //当前采用不截断处理 保持和libsvm,tlc一致 TODO 实验下单个特征过大值对结果影响 value = _lower + (_upper - _lower) * (value - _pairs[index].lower) / (_pairs[index].upper - _pairs[index].lower); } if (value != 0) { result.push_back(Feature::Node(index, value)); } } int normalize(Feature* feature) { vector<Feature::Node>& nodes = feature->nodes(); vector<Feature::Node> temp; int idx = _startIndex; foreach(Feature::Node& node, nodes) { for (int i = idx; i < node.index; i++) { norm(i, 0, temp); } norm(node.index, node.value, temp); idx = node.index + 1; } nodes.swap(temp); return 0; } private: int _featureNum; vector<Pair> _pairs; //每个特征的上下界 double _lower; //要归一化到的 下界 double _upper; int _startIndex; bool _useTruncate; }; } #endif
e073ca681194c86387ef471396aa16ed9e85a04d
e064df5d2c9a958d4b226323b1e355a56799b344
/cpp/dataStructures/searchTrees/Ssets_sat.cpp
d028d5f5474f802620df08f86e0c5b9e9b46437d
[]
no_license
jonturner53/grafalgo
68605d12d1258ea70a4eb50e370afa56fb07747b
5063c695a66e9d17e4f70bc50452c88908e34dbe
refs/heads/master
2023-08-07T07:25:57.261886
2023-07-30T14:05:48
2023-07-30T14:05:48
32,212,221
4
3
null
null
null
null
UTF-8
C++
false
false
4,395
cpp
Ssets_sat.cpp
/** @file Ssets_sat.cpp * * @author Jon Turner * @date 2011 * This is open source software licensed under the Apache 2.0 license. * See http://www.apache.org/licenses/LICENSE-2.0 for details. */ #include "Ssets_sat.h" #define left(x) node[x].left #define right(x) node[x].right #define p(x) node[x].p #define kee(x) node[x].kee namespace grafalgo { /** Constructor for Ssets_sat class. * @param n defines the index range for the constructed object. */ Ssets_sat::Ssets_sat(int n) : Ssets(n) {} /** Destructor for Ssets_sat class. */ Ssets_sat::~Ssets_sat() {} /** Splay a search tree. * @param x is an item in a bst (equivalently, node in a search tree); * the operation restructures the tree, moving x to the root * @return the root of the bst following the restructuring */ index Ssets_sat::splay(index x) { while (p(x) != 0) splaystep(x); return x; } /** Perform a single splay step. * @param x is a node in a search tree */ void Ssets_sat::splaystep(index x) { index y = p(x); if (y == 0) return; index z = p(y); if (z != 0) { if (x == left(left(z)) || x == right(right(z))) rotate(y); else // x is "inner grandchild" rotate(x); } rotate(x); } /** Get the root of the bst containing an item. * @param i is an item in some bst * @return the canonical element of the bst containing i; note that * the operation restructures the tree possibly changing the root */ bst Ssets_sat::find(index i) { assert(valid(i)); return splay(i); } /** Get the root of the bst containing an item. * @param i is an item in some bst * @return the canonical element of the bst containing i; note that * this operation does not restructure the tree */ bst Ssets_sat::findroot(index i) { assert(valid(i)); while (p(i) != 0) i = p(i); return i; } /** Get the item with a specified key value. * @param k is a key value * @param t is a reference to the root of some bst; * if the operation changes the root, then t will change * @return the item in the tree with the specified key, or 0 if * no item has that key */ index Ssets_sat::access(keytyp k, bst& t) { assert (t == 0 || valid(t)); index x = t; while (true) { if (k < kee(x) && left(x) != 0) x = left(x); else if (k > kee(x) && right(x) != 0) x = right(x); else break; } splay(x); t = x; return key(x) == k ? x : 0; } /** Insert item into a bst. * @param i is a singleton item * @param t is the root of the bst that i is to be inserted into; * if the operation changes the root, t is changed * @return true on success, false on failure */ bool Ssets_sat::insert(index i, bst& t) { if (t == 0) { t = i; return true; } assert(valid(t) && p(t) == 0); index x = t; while (true) { if (kee(i) < kee(x) && left(x) != 0) x = left(x); else if (kee(i) > kee(x) && right(x) != 0) x = right(x); else break; } if (kee(i) < kee(x)) left(x) = i; else if (kee(i) > kee(x)) right(x) = i; else { splay(x); return false; } p(i) = x; splay(i); t = i; return true; } /** Remove an item from a bst. * @param i is an item in some bst * @param t is a reference to the root of the bst containing i; * if the operation changes the root of the tree, then the variable * in the calling program is updated to reflect this */ void Ssets_sat::remove(index i, bst& t) { assert(valid(i) && valid(t) && p(t) == 0); index j; if (left(i) != 0 && right(i) != 0) { for (j = left(i); right(j) != 0; j = right(j)) {} swap(i,j); } // now, i has at most one child j = (left(i) != 0 ? left(i) : right(i)); // j is now the index of the only child that could be non-null if (j != 0) p(j) = p(i); if (p(i) != 0) { if (i == left(p(i))) left(p(i)) = j; else if (i == right(p(i))) right(p(i)) = j; t = splay(p(i)); } else t = j; p(i) = left(i) = right(i) = 0; return; } /** Divide a bst at an item * @param i is the index of a node in some bst * @param t is the root of the bst containing i * @return the pair of bst [t1,t2] that results from splitting t into three * parts; t1 (containing ityems with keys smaller than that of i), i itself, * and t2 (contining items with keys larger than that of i) */ Ssets::BstPair Ssets_sat::split(index i, bst t) { assert(valid(i) && valid(t)); splay(i); Ssets::BstPair pair(left(i),right(i)); left(i) = right(i) = p(i) = 0; p(pair.t1) = p(pair.t2) = 0; return pair; } } // ends namespace
b1423084ce98300018d7a25c52c94b5284b02c58
97afeb94887caf226ff36f90961fbfc96040f9c1
/src/PathPlanner.cpp
e06cbb19dd9eaf86b3479c75c1c2a4b12bd1cc03
[ "MIT" ]
permissive
JiaweiHan88/PathPlanning
89bf9b0da6b75f3eaf43e9bc17e0d747315bb9df
c38852b3d294eb5c9baf13be2332ebd23b93e298
refs/heads/main
2023-06-08T01:38:16.345202
2021-06-27T14:24:52
2021-06-27T14:24:52
380,759,222
0
0
null
null
null
null
UTF-8
C++
false
false
5,463
cpp
PathPlanner.cpp
#include "PathPlanner.h" #include "helpers.h" #include "spline.h" #include <algorithm> #include <iostream> using std::vector; PathPlanner::PathPlanner(VEMPtr env) : m_env(env) { m_pred = std::make_shared<Predictor>(env); m_ref_vel = 0; } void PathPlanner::updatePreviousPath(json &j) { // Previous path data given to the Planner m_previous_path_x = j["previous_path_x"]; m_previous_path_y = j["previous_path_y"]; // Previous path's end s and d values m_end_path_s = j["end_path_s"]; m_end_path_d = j["end_path_d"]; } void PathPlanner::updatePath() { m_next_x_vals.clear(); m_next_y_vals.clear(); auto &egoCar = m_env->m_EgoVeh; //check whether we want to change lane and whether its possible to change lane bool change_lane = egoCar.m_laneChangeWish && m_pred->checkTargetLaneSafety(); // && (m_time_since_lastLC > 250); double target_d = egoCar.m_laneID * 4 + 2; if (change_lane) { target_d = egoCar.m_targetLaneID * 4 + 2; } //regardless whether we want to change lane or not, we have to adapt our velocity base on preceeding vehicle if (egoCar.m_preVeh) { double dist = 100; //safety distance = distance in m travelled in 2 seconds with the current velocity double safedist = std::max(egoCar.m_speed_abs * 2.0, 6.0); dist = fabs(egoCar.m_s - egoCar.m_preVeh->m_s); //if we are more then 2 times safety dist away, we can drive with max velocity; if (dist > 2 * safedist) { egoCar.m_targetSpeed = egoCar.m_desiredSpeed; } //else if we are between 2xsafety distance and 1x safety distance else if (dist > safedist) { tk::spline sp; sp.set_points(std::vector<double>{5, safedist, safedist * 2}, std::vector<double>{0, egoCar.m_preVeh->m_speed_abs, egoCar.m_desiredSpeed}); egoCar.m_targetSpeed = std::min(sp(dist), egoCar.m_desiredSpeed); } else { egoCar.m_targetSpeed = egoCar.m_targetSpeed - 0.2; } } else { egoCar.m_targetSpeed = egoCar.m_desiredSpeed; } //adapt our reference velocity in small steps to keep acceleration under threshhold if (m_ref_vel < egoCar.m_targetSpeed) { m_ref_vel += 0.1; } else { m_ref_vel -= 0.1; } //define some anchor points for our spline trajectory vector<double> anchor_x; vector<double> anchor_y; //if we have some left over previous path points, we use them as starting anchor point to smooth our trajectory //else we use the current ego Car position and a calculated previous position as starting anchor points int previous_path_size = m_previous_path_x.size(); double ref_x = egoCar.m_x; double ref_y = egoCar.m_y; double ref_yaw = egoCar.m_yaw_rad; double prev_car_x = egoCar.m_x - cos(egoCar.m_yaw_rad); double prev_car_y = egoCar.m_y - sin(egoCar.m_yaw_rad); if (previous_path_size >= 2) { ref_x = m_previous_path_x[previous_path_size - 1]; ref_y = m_previous_path_y[previous_path_size - 1]; prev_car_x = m_previous_path_x[previous_path_size - 2]; prev_car_y = m_previous_path_y[previous_path_size - 2]; ref_yaw = atan2(ref_y - prev_car_y, ref_x - prev_car_x); } anchor_x.push_back(prev_car_x); anchor_x.push_back(ref_x); anchor_y.push_back(prev_car_y); anchor_y.push_back(ref_y); //define 3 additional anchor points based on the target lane; double anchor1_s_offset = std::max(egoCar.m_speed_abs * 2 + 5, 25.0); auto anchor1 = Helpers::getInstance().getXY(egoCar.m_s + anchor1_s_offset, target_d); auto anchor2 = Helpers::getInstance().getXY(egoCar.m_s + anchor1_s_offset + 30, target_d); auto anchor3 = Helpers::getInstance().getXY(egoCar.m_s + anchor1_s_offset + 60, target_d); anchor_x.push_back(anchor1[0]); anchor_x.push_back(anchor2[0]); anchor_x.push_back(anchor3[0]); anchor_y.push_back(anchor1[1]); anchor_y.push_back(anchor2[1]); anchor_y.push_back(anchor3[1]); //shift to car reference for (int i = 0; i < anchor_x.size(); i++) { double shift_x = anchor_x[i] - ref_x; double shift_y = anchor_y[i] - ref_y; anchor_x[i] = shift_x * cos(-ref_yaw) - shift_y * sin(-ref_yaw); anchor_y[i] = shift_x * sin(-ref_yaw) + shift_y * cos(-ref_yaw); } tk::spline sp; sp.set_points(anchor_x, anchor_y); //fill trajectory with left over previous path points for (int i = 0; i < previous_path_size; i++) { m_next_x_vals.push_back(m_previous_path_x[i]); m_next_y_vals.push_back(m_previous_path_y[i]); } //split spline in appropriate x distance to get y values double target_x = anchor1_s_offset; double target_y = sp(target_x); double target_dist = sqrt(target_x * target_x + target_y * target_y); double N = target_dist / (0.02 * m_ref_vel); double x, y, x_temp, y_temp; for (int i = 1; i <= 50 - previous_path_size; i++) { //shift back to global coordinates and push to next path points x = i * (target_x / N); y = sp(x); x_temp = x; y_temp = y; x = x_temp * cos(ref_yaw) - y_temp * sin(ref_yaw) + ref_x; y = x_temp * sin(ref_yaw) + y_temp * cos(ref_yaw) + ref_y; m_next_x_vals.push_back(x); m_next_y_vals.push_back(y); } }
48e39f69a130098e2f4c63f8cc76f4af295ceef0
df689da61dc21d79fca81254d2e8878278cc5443
/AxWinLib/CWinVersion.cpp
a57e33c146490ceaae6149559521b37a7c678ef2
[]
no_license
mirsys/xecrets-file
f01fc60eda4c55cc3b1eabc319aeb47f94abdb13
f0496fd2b490ae2817c1e3089f6e5f7036f2a87e
refs/heads/master
2022-11-11T11:10:42.571622
2020-07-08T18:54:38
2020-07-08T18:54:38
null
0
0
null
null
null
null
ISO-8859-1
C++
false
false
3,119
cpp
CWinVersion.cpp
/*! \file \brief Determine Windows Version @(#) $Id$ AxLib - Collection of useful code. All code here is generally intended to be simply included in the projects, the intention is not to províde a stand-alone linkable library, since so many variants are possible (single/multithread release/debug etc) and also because it is frequently used in open source programs, and then the distributed source must be complete and there is no real reason to make the distributions so large etc. It's of course also possible to build a partial or full library in the respective solution. Copyright (C) 2009 Svante Seleborg/Axantum Software AB, All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA The author may be reached at mailto:software@axantum.com and http://www.axantum.com ---- AxAssert.cpp */ #include "StdAfx.h" #define WIN32_LEAN_AND_MEAN ///< Exclude rarely-used stuff from Windows headers #include <windows.h> #include <VersionHelpers.h> #include "IWinVersion.h" // This should be done for every source file to ensure correct reference in the assert #include "AxAssert.h" #define AXLIB_ASSERT_FILE "CWinVersion.cpp" namespace AxLib { class CWinVersion : public IWinVersion { int GetVersion(); }; IWinVersion::~IWinVersion() { } IWinVersion *IWinVersion::New() { return new CWinVersion(); } int CWinVersion::GetVersion() { // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn424972(v=vs.85).aspx int version; if (IsWindows8OrGreater()) { version = WINXX; } else if (IsWindows7OrGreater()) { version = IsWindowsServer() ? WIN2008 : WIN7; } else if (IsWindowsVistaOrGreater()) { version = IsWindowsServer() ? WIN2008 : WINVISTA; } else { version = WINXX; } typedef void (WINAPI *PFGETNATIVESYSTEMINFO)(LPSYSTEM_INFO lpSystemInfo); HMODULE hKernel32; PFGETNATIVESYSTEMINFO pfGetNativeSystemInfo; if (hKernel32 = GetModuleHandle(_T("kernel32.dll"))) { pfGetNativeSystemInfo = (PFGETNATIVESYSTEMINFO)GetProcAddress(hKernel32, "GetNativeSystemInfo"); } SYSTEM_INFO si; ZeroMemory(&si, sizeof si); if (pfGetNativeSystemInfo != NULL) { (*pfGetNativeSystemInfo)(&si); } else { GetSystemInfo(&si); } if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { version |= X64; } return version; } }
e36b458eaf3f0c88ea5a2ff22a287227d81584dd
7da24497832d8afafefa36db391d644e7fceef40
/others/CODE_FESTIVAL_2014_Final_F_Gojoho.cpp
98930f4b9a194a841a734e010661ec57a3b8a1eb
[]
no_license
shugo256/AtCoder
864e70a54cb5cb8a3dddd038cb425a96aacb54bf
57c81746c83b11bd1373cfff8a0358af3ba67f65
refs/heads/master
2021-06-12T14:46:54.073135
2021-04-25T08:09:15
2021-04-25T08:09:15
180,904,626
0
0
null
null
null
null
UTF-8
C++
false
false
1,102
cpp
CODE_FESTIVAL_2014_Final_F_Gojoho.cpp
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <string> using ll = long long; using namespace std; template <typename T> T gcd(T a, T b) { if (a > b) { T buf = a; a = b; b = buf; } return a == 0 ? b : gcd(a, b%a); } int check(vector<int> &invalid) { int cur = 0, ans = 0; for (auto &i:invalid) { if (i < cur) continue; cur = i + 3; ans++; } return ans; } int main() { int n; cin >> n; int b[n]; for (auto &bi:b) cin >> bi; vector<int> invalid; for (int i=0; i<n; i++) { int i1 = (i + 1) % n, i2 = (i + 2) % n; if (b[i1] % gcd(b[i], b[i2]) != 0) invalid.push_back(i); } int res1 = check(invalid); if (invalid[0] == 0 || invalid[0] == 1) { invalid.push_back(invalid[0] + n); invalid[0] = -1; } int res2 = check(invalid); if (invalid[1] == 1) { invalid.push_back(invalid[1] + n); invalid[1] = -1; } int res3 = check(invalid); cout << min({res1, res2, res3}) << '\n'; return 0; }
1ff970fcc90514d57582066d417a2885ab781c00
0954c102d25ae4e26fdc3453d3cf4d405aedd35b
/Noah-doho-6-and-6---master (Animation) 2/Classes/StoryBook/Scene3/NoahAndDove.h
54bb40aceb10e9807080f242721fbc810148e72e
[]
no_license
73153/Cocos2dx-animation-cocosbuuilder
c987c34c3e24cf1b44c9560bf10f1ac3af05b433
1f423549b7da96da86cdc5eb92afea8011ecbf66
refs/heads/master
2020-04-06T04:41:50.056706
2017-02-22T11:21:02
2017-02-22T11:21:02
82,796,159
0
0
null
null
null
null
UTF-8
C++
false
false
2,570
h
NoahAndDove.h
// // NoahAndDove.h // Noah360 // // Created by Neil D on 03/10/13. // // #ifndef __Noah360__NoahAndDove__ #define __Noah360__NoahAndDove__ #include <iostream> #include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; class NoahAndDove: public cocos2d::CCNode,public CCTargetedTouchDelegate { public: CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(NoahAndDove, create); NoahAndDove(); virtual ~NoahAndDove(); virtual void onEnter(); virtual void onExit(); virtual bool init(); //CCB methods... virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(cocos2d::CCObject * pTarget, const char * pSelectorName); virtual cocos2d::extension::SEL_CCControlHandler onResolveCCBCCControlSelector(cocos2d::CCObject * pTarget, const char * pSelectorName); virtual bool onAssignCCBMemberVariable(cocos2d::CCObject * pTarget, const char * pMemberVariableName, cocos2d::CCNode * pNode); virtual bool onAssignCCBCustomProperty(CCObject* pTarget, const char* pMemberVariableName, cocos2d::extension::CCBValue* pCCBValue); virtual void onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader); virtual cocos2d::SEL_CallFuncN onResolveCCBCCCallFuncSelector(CCObject * pTarget, const char* pSelectorName); CCSize screenSize; CCSprite * head; CCSprite * body; CCSprite * leftHandStaff; CCSprite * leftForeHarm; CCSprite * leftLowerSleeve; CCSprite * leftUpperSleeve; CCSprite * rightSleeve; CCSprite * rightHand; CCSprite * dove; CCAnimation *doveShakeHead; CCAnimation *doveFlapWings; CCArray *doveShakeHeadFrames; CCArray *doveFlapWingsFrames; bool runningAnimation; bool firstAnimation; CCPoint upperToLowerSleeve; CCPoint sleeveToForearm; CCPoint forearmToHand; CCPoint handToDove; int lastSentence; unsigned int noahSpeech; CC_SYNTHESIZE(bool,interactionsEnabled,interactionsEnabled); CC_SYNTHESIZE(bool,isPlaying,isPlaying); public: virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); virtual void ccTouchEnded(CCTouch* touch, CCEvent* event); void tick(float dt); void EnableInteractions(); void stopSwallingTouchs(); void ChangeBackNoahFace(); void MakeFeathersAppear(float dt); void RunRandomNoahAnimation(); void WaitForSpeechToEnd(float dt); private: cocos2d::extension::CCBAnimationManager *mAnimationManager; }; #endif /* defined(__Noah360__NoahAndDove__) */
5ba58dbce6047d832013cfdece958c567af606e4
318b737f3fe69171f706d2d990c818090ee6afce
/hybridse/examples/toydb/src/cmd/toydb.cc
57658da86f455a3509a5b9be427fbf50409bc9e4
[ "Apache-2.0" ]
permissive
4paradigm/OpenMLDB
e884c33f62177a70749749bd3b67e401c135f645
a013ba33e4ce131353edc71e27053b1801ffb8f7
refs/heads/main
2023-09-01T02:15:28.821235
2023-08-31T11:42:02
2023-08-31T11:42:02
346,976,717
3,323
699
Apache-2.0
2023-09-14T09:55:44
2021-03-12T07:18:31
C++
UTF-8
C++
false
false
16,456
cc
toydb.cc
/* * Copyright 2021 4Paradigm * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <fcntl.h> #include <sched.h> #include <signal.h> #include <unistd.h> #include <fstream> #include <iostream> #include <string> #include "absl/strings/str_cat.h" #include "base/fe_linenoise.h" #include "base/fe_strings.h" #include "base/texttable.h" #include "brpc/server.h" #include "dbms/dbms_server_impl.h" #include "glog/logging.h" #include "hybridse_version.h" //NOLINT #include "llvm/Support/InitLLVM.h" #include "llvm/Support/TargetSelect.h" #include "plan/plan_api.h" #include "sdk/dbms_sdk.h" #include "sdk/tablet_sdk.h" #include "tablet/tablet_server_impl.h" DECLARE_string(toydb_endpoint); DECLARE_string(tablet_endpoint); DECLARE_int32(toydb_port); DECLARE_int32(toydb_thread_pool_size); DEFINE_string(role, "tablet | dbms | client ", "Set the hybridse role"); namespace hybridse { namespace cmd { static std::shared_ptr<::hybridse::sdk::DBMSSdk> dbms_sdk; static std::shared_ptr<::hybridse::sdk::TabletSdk> table_sdk; struct DBContxt { std::string name; }; static DBContxt cmd_client_db; void HandleSqlScript(const std::string &script, hybridse::sdk::Status &status); // NOLINT (runtime/references) void HandleEnterDatabase(const std::string &db_name); void HandleCmd(const hybridse::node::CmdPlanNode *cmd_node, hybridse::sdk::Status &status); // NOLINT (runtime/references) void SetupLogging(char *argv[]) { google::InitGoogleLogging(argv[0]); } void StartTablet(int argc, char *argv[]) { ::llvm::InitLLVM X(argc, argv); ::llvm::InitializeNativeTarget(); ::llvm::InitializeNativeTargetAsmPrinter(); ::hybridse::tablet::TabletServerImpl *tablet = new ::hybridse::tablet::TabletServerImpl(); bool ok = tablet->Init(); if (!ok) { LOG(WARNING) << "Fail to init tablet service"; exit(1); } brpc::ServerOptions options; options.num_threads = FLAGS_toydb_thread_pool_size; brpc::Server server; if (server.AddService(tablet, brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { LOG(WARNING) << "Fail to add tablet service"; exit(1); } if (server.Start(FLAGS_toydb_port, &options) != 0) { LOG(WARNING) << "Fail to start tablet server"; exit(1); } std::ostringstream oss; oss << HYBRIDSE_VERSION_MAJOR << "." << HYBRIDSE_VERSION_MINOR << "." << HYBRIDSE_VERSION_BUG; DLOG(INFO) << "start tablet on port " << FLAGS_toydb_port << " with version " << oss.str(); server.set_version(oss.str()); server.RunUntilAskedToQuit(); } void StartDBMS(char *argv[]) { SetupLogging(argv); ::hybridse::dbms::DBMSServerImpl *dbms = new ::hybridse::dbms::DBMSServerImpl(); brpc::ServerOptions options; options.num_threads = FLAGS_toydb_thread_pool_size; brpc::Server server; if (server.AddService(dbms, brpc::SERVER_DOESNT_OWN_SERVICE) != 0) { LOG(WARNING) << "Fail to add dbms service"; exit(1); } if (server.Start(FLAGS_toydb_port, &options) != 0) { LOG(WARNING) << "Fail to start dbms server"; exit(1); } std::ostringstream oss; oss << HYBRIDSE_VERSION_MAJOR << "." << HYBRIDSE_VERSION_MINOR << "." << HYBRIDSE_VERSION_BUG; DLOG(INFO) << "start dbms on port " << FLAGS_toydb_port << " with version " << oss.str(); server.set_version(oss.str()); server.RunUntilAskedToQuit(); } void StartClient(char *argv[]) { SetupLogging(argv); std::cout << "Welcome to TOYDB " << HYBRIDSE_VERSION_MAJOR << "." << HYBRIDSE_VERSION_MINOR << "." << HYBRIDSE_VERSION_BUG << std::endl; cmd_client_db.name = ""; std::string log = "hybridse"; std::string display_prefix = ">"; std::string continue_prefix = "..."; std::string cmd_str; bool cmd_mode = true; while (true) { std::string buf; std::string prefix = ""; if (cmd_client_db.name.empty()) { prefix = log + display_prefix; } else { prefix = log + "/" + cmd_client_db.name + display_prefix; } char *line = ::hybridse::base::linenoise(cmd_mode ? prefix.c_str() : continue_prefix.c_str()); if (line == NULL) { return; } if (line[0] != '\0' && line[0] != '/') { buf.assign(line); if (!buf.empty()) { ::hybridse::base::linenoiseHistoryAdd(line); } } ::hybridse::base::linenoiseFree(line); if (buf.empty()) { continue; } cmd_str.append(buf); // TODO(CHENJING) remove if (cmd_str.back() == ';') { ::hybridse::sdk::Status status; HandleSqlScript(cmd_str, status); if (0 != status.code) { std::cout << "ERROR[" << status.code << "]: " << status.msg << std::endl; } cmd_str.clear(); cmd_mode = true; } else { cmd_str.append("\n"); cmd_mode = false; } } } void PrintResultSet(std::ostream &stream, ::hybridse::sdk::ResultSet *result_set) { if (!result_set || result_set->Size() == 0) { stream << "Empty set" << std::endl; return; } ::hybridse::base::TextTable t('-', '|', '+'); const ::hybridse::sdk::Schema *schema = result_set->GetSchema(); // Add Header for (int32_t i = 0; i < schema->GetColumnCnt(); i++) { t.add(schema->GetColumnName(i)); } t.end_of_row(); while (result_set->Next()) { for (int32_t i = 0; i < schema->GetColumnCnt(); i++) { sdk::DataType data_type = schema->GetColumnType(i); switch (data_type) { case hybridse::sdk::kTypeInt16: { int16_t value = 0; result_set->GetInt16(i, &value); t.add(std::to_string(value)); break; } case hybridse::sdk::kTypeInt32: { int32_t value = 0; result_set->GetInt32(i, &value); t.add(std::to_string(value)); break; } case hybridse::sdk::kTypeInt64: { int64_t value = 0; result_set->GetInt64(i, &value); t.add(std::to_string(value)); break; } case hybridse::sdk::kTypeFloat: { float value = 0; result_set->GetFloat(i, &value); t.add(std::to_string(value)); break; } case hybridse::sdk::kTypeDouble: { double value = 0; result_set->GetDouble(i, &value); t.add(std::to_string(value)); break; } case hybridse::sdk::kTypeString: { std::string val; result_set->GetString(i, &val); t.add(val); break; } default: { t.add("NA"); } } } t.end_of_row(); } stream << t << std::endl; stream << result_set->Size() << " rows in set" << std::endl; } void PrintTableSchema(std::ostream &stream, const std::shared_ptr<hybridse::sdk::Schema> &schema) { if (nullptr == schema || schema->GetColumnCnt() == 0) { stream << "Empty set" << std::endl; return; } uint32_t items_size = schema->GetColumnCnt(); ::hybridse::base::TextTable t('-', '|', '+'); t.add("Field"); t.add("Type"); t.add("Null"); t.end_of_row(); for (uint32_t i = 0; i < items_size; i++) { t.add(schema->GetColumnName(i)); t.add(hybridse::sdk::DataTypeName(schema->GetColumnType(i))); t.add(schema->IsColumnNotNull(i) ? "YES" : "NO"); t.end_of_row(); } stream << t; if (items_size > 1) { stream << items_size << " rows in set" << std::endl; } else { stream << items_size << " row in set" << std::endl; } } void PrintItems(std::ostream &stream, const std::string &head, const std::vector<std::string> &items) { if (items.empty()) { stream << "Empty set" << std::endl; return; } ::hybridse::base::TextTable t('-', '|', '+'); t.add(head); t.end_of_row(); for (auto item : items) { t.add(item); t.end_of_row(); } stream << t; auto items_size = items.size(); if (items_size > 1) { stream << items_size << " rows in set" << std::endl; } else { stream << items_size << " row in set" << std::endl; } } void HandleSqlScript(const std::string &script, hybridse::sdk::Status &status) { // NOLINT (runtime/references) if (!dbms_sdk) { dbms_sdk = ::hybridse::sdk::CreateDBMSSdk(FLAGS_toydb_endpoint); if (!dbms_sdk) { status.code = hybridse::common::kRpcError; status.msg = "Fail to connect to dbms"; return; } } { hybridse::node::NodeManager node_manager; hybridse::base::Status sql_status; hybridse::node::PlanNodeList plan_trees; hybridse::plan::PlanAPI::CreatePlanTreeFromScript(script, plan_trees, &node_manager, sql_status); if (0 != sql_status.code) { status.code = sql_status.code; status.msg = sql_status.str(); LOG(WARNING) << status.msg; return; } hybridse::node::PlanNode *node = plan_trees[0]; if (nullptr == node) { status.msg = "fail to execute cmd: parser tree is null"; status.code = hybridse::common::kPlanError; LOG(WARNING) << status.msg; return; } switch (node->GetType()) { case hybridse::node::kPlanTypeCmd: { hybridse::node::CmdPlanNode *cmd = dynamic_cast<hybridse::node::CmdPlanNode *>(node); HandleCmd(cmd, status); return; } case hybridse::node::kPlanTypeCreate: { dbms_sdk->ExecuteQuery(cmd_client_db.name, script, &status); return; } case hybridse::node::kPlanTypeInsert: { if (!table_sdk) { table_sdk = ::hybridse::sdk::CreateTabletSdk(FLAGS_tablet_endpoint); } if (!table_sdk) { status.code = hybridse::common::kConnError; status.msg = " Fail to create tablet sdk"; return; } table_sdk->Insert(cmd_client_db.name, script, &status); if (0 != status.code) { return; } std::cout << "Insert success" << std::endl; return; } case hybridse::node::kPlanTypeFuncDef: case hybridse::node::kPlanTypeExplain: { std::string empty; std::string mu_script = script; mu_script.replace(0u, 7u, empty); std::shared_ptr<::hybridse::sdk::ExplainInfo> info = dbms_sdk->Explain(cmd_client_db.name, mu_script, &status); if (0 != status.code) { return; } std::cout << info->GetPhysicalPlan() << std::endl; return; } case hybridse::node::kPlanTypeQuery: { if (!table_sdk) { table_sdk = ::hybridse::sdk::CreateTabletSdk(FLAGS_tablet_endpoint); } if (!table_sdk) { status.code = hybridse::common::kConnError; status.msg = " Fail to create tablet sdk"; return; } std::shared_ptr<::hybridse::sdk::ResultSet> rs = table_sdk->Query(cmd_client_db.name, script, &status); if (rs) { PrintResultSet(std::cout, rs.get()); } return; } default: { status.msg = "Fail to execute script with un-support type" + hybridse::node::NameOfPlanNodeType(node->GetType()); status.code = hybridse::common::kUnSupport; return; } } } } void HandleCmd(const hybridse::node::CmdPlanNode *cmd_node, hybridse::sdk::Status &status) { // NOLINT (runtime/references) if (dbms_sdk == NULL) { dbms_sdk = ::hybridse::sdk::CreateDBMSSdk(FLAGS_toydb_endpoint); if (dbms_sdk == NULL) { std::cout << "Fail to connect to dbms" << std::endl; return; } } std::string db = cmd_client_db.name; switch (cmd_node->GetCmdType()) { case hybridse::node::kCmdShowDatabases: { std::vector<std::string> names = dbms_sdk->GetDatabases(&status); if (status.code == 0) { PrintItems(std::cout, "Databases", names); } return; } case hybridse::node::kCmdShowTables: { std::shared_ptr<hybridse::sdk::TableSet> rs = dbms_sdk->GetTables(db, &status); if (status.code == 0) { std::ostringstream oss; std::vector<std::string> names; while (rs->Next()) { names.push_back(rs->GetTable()->GetName()); } PrintItems(std::cout, "Tables_In_" + cmd_client_db.name, names); } return; } case hybridse::node::kCmdDescTable: { std::shared_ptr<hybridse::sdk::TableSet> rs = dbms_sdk->GetTables(db, &status); if (rs) { while (rs->Next()) { if (rs->GetTable()->GetName() == cmd_node->GetArgs()[0]) { PrintTableSchema(std::cout, rs->GetTable()->GetSchema()); } } } break; } case hybridse::node::kCmdCreateDatabase: { std::string name = cmd_node->GetArgs()[0]; dbms_sdk->CreateDatabase(name, &status); if (0 == status.code) { std::cout << "Create database success" << std::endl; } break; } case hybridse::node::kCmdUseDatabase: { std::string name = cmd_node->GetArgs()[0]; std::vector<std::string> names = dbms_sdk->GetDatabases(&status); if (status.code == 0) { for (uint32_t i = 0; i < names.size(); i++) { if (names[i] == name) { cmd_client_db.name = name; std::cout << "Database changed" << std::endl; return; } } } std::cout << "Database '" << name << "' not exists" << std::endl; break; } case hybridse::node::kCmdExit: { exit(0); } default: { status.code = hybridse::common::kUnSupport; status.msg = absl::StrCat("UnSupport Cmd ", hybridse::node::CmdTypeName(cmd_node->GetCmdType())); } } } } // namespace cmd } // namespace hybridse int main(int argc, char *argv[]) { ::google::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_role == "dbms") { ::hybridse::cmd::StartDBMS(argv); } else if (FLAGS_role == "tablet") { ::hybridse::cmd::StartTablet(argc, argv); } else if (FLAGS_role == "client") { ::hybridse::cmd::StartClient(argv); } else if (FLAGS_role == "csv") { } else { std::cout << "Start failed! FLAGS_role must be tablet, client, dbms" << std::endl; return 1; } return 0; }
93ab4226d5af896ed2ed4e3f5196625002486068
885595ecb8a07d54ebb2386dbc390358ff592d52
/src/sakura/c.cpp
3a7248a40e92ba3f4546260902e4bdccd4876dac
[]
no_license
PyYoshi/libsakura
74001e5291faf0d264e63b3312004b963c7b4abb
7f145fa007e12a6b08d5ff2cf2a893949986c100
refs/heads/master
2023-06-12T06:09:00.910700
2015-05-30T15:22:53
2015-05-30T15:22:53
34,127,787
1
0
null
null
null
null
UTF-8
C++
false
false
5,225
cpp
c.cpp
#include "c.h" #include "Sakura.h" extern "C" { struct sakura_picture_t {Sakura::Picture* rep;}; void sakura_free_picture(sakura_picture_t* pic) { delete pic->rep; delete pic; } sakura_picture_t* sakura_scale(sakura_picture_t* in_pic, int out_width, int out_height, int scale_filter, char** errptr) { try { sakura_picture_t* result = new sakura_picture_t; Sakura::Picture * out_pic = Sakura::Scale(in_pic->rep, out_width, out_height, static_cast<Sakura::ScaleFilter>(scale_filter)); result->rep = out_pic; return result; } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); return NULL; } } void sakura_to_rgb_from_rgba_bg_white(sakura_picture_t* in_pic, char** errptr) { try { Sakura::ToRGBFromRGBA(in_pic->rep); } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); } } void sakura_to_rgb_from_rgba(sakura_picture_t* in_pic, unsigned char bg_red, unsigned char bg_green, unsigned char bg_blue, char** errptr) { try { Sakura::ToRGBFromRGBA(in_pic->rep, bg_red, bg_green, bg_blue); } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); } } sakura_picture_t* sakura_load_png(unsigned char* input_buffer, unsigned long* buf_size, char** errptr) { try { sakura_picture_t* result = new sakura_picture_t; Sakura::Picture * pic = Sakura::LoadPng(input_buffer, buf_size); result->rep = pic; return result; } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); return NULL; } } sakura_picture_t* sakura_load_png_file(const char* file_path, char** errptr) { try { sakura_picture_t* result = new sakura_picture_t; Sakura::Picture * pic = Sakura::LoadPng(file_path); result->rep = pic; return result; } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); return NULL; } } sakura_picture_t* sakura_load_jpeg(unsigned char* input_buffer, unsigned long* buf_size, char** errptr) { try { sakura_picture_t* result = new sakura_picture_t; Sakura::Picture * pic = Sakura::LoadJpeg(input_buffer, buf_size); result->rep = pic; return result; } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); return NULL; } } sakura_picture_t* sakura_load_jpeg_file(const char* file_path, char** errptr) { try { sakura_picture_t* result = new sakura_picture_t; Sakura::Picture * pic = Sakura::LoadJpeg(file_path); result->rep = pic; return result; } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); return NULL; } } sakura_picture_t* sakura_load_webp(unsigned char* input_buffer, unsigned long* buf_size, char** errptr) { try { sakura_picture_t* result = new sakura_picture_t; Sakura::Picture * pic = Sakura::LoadWebp(input_buffer, buf_size); result->rep = pic; return result; } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); return NULL; } } sakura_picture_t* sakura_load_webp_file(const char* file_path, char** errptr) { try { sakura_picture_t* result = new sakura_picture_t; Sakura::Picture * pic = Sakura::LoadWebp(file_path); result->rep = pic; return result; } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); return NULL; } } void sakura_output_png(unsigned char** out_buffer, sakura_picture_t* in_pic, unsigned int comp_level, char** errptr) { try { Sakura::OutputPng(out_buffer, in_pic->rep, comp_level); } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); } } void sakura_output_png_file(const char* file_path, sakura_picture_t* in_pic, unsigned int comp_level, char** errptr) { try { Sakura::OutputPng(file_path, in_pic->rep, comp_level); } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); } } void sakura_output_jpeg(unsigned char** out_buffer, sakura_picture_t* in_pic, unsigned int quality, char** errptr) { try { Sakura::OutputJpeg(out_buffer, in_pic->rep, quality); } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); } } void sakura_output_jpeg_file(const char* file_path, sakura_picture_t* in_pic, unsigned int quality, char** errptr) { try { Sakura::OutputJpeg(file_path, in_pic->rep, quality); } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); } } void sakura_output_webp(unsigned char** out_buffer, sakura_picture_t* in_pic, unsigned int quality, char** errptr) { try { Sakura::OutputWebp(out_buffer, in_pic->rep, quality); } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); } } void sakura_output_webp_file(const char* file_path, sakura_picture_t* in_pic, unsigned int quality, char** errptr) { try { Sakura::OutputWebp(file_path, in_pic->rep, quality); } catch (const Sakura::Exception * e) { *errptr = strdup(e->what()); } } }
4350dd7f157c77c5566ec66dccb1367ba4faca05
17870e158e43f474897f013fdf8fb51e2b2e48e7
/expressions/aggregation/AggregateFunctionFactory.hpp
0553542846149bd3380ca14d7e8d54542ed27988
[ "Apache-2.0" ]
permissive
cramja/quickstep
cf3a3862a99174774f1565c8d4b536b84f3d3671
02364b2f43bf87849c0c5a6c12107d22840402af
refs/heads/master
2020-04-05T22:59:46.825680
2016-11-09T23:23:14
2016-11-09T23:23:14
60,444,794
0
0
null
2016-06-05T05:30:15
2016-06-05T05:30:15
null
UTF-8
C++
false
false
3,421
hpp
AggregateFunctionFactory.hpp
/** * Copyright 2015 Pivotal Software, Inc. * * 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 QUICKSTEP_EXPRESSIONS_AGGREGATION_AGGREGATE_FUNCTION_FACTORY_HPP_ #define QUICKSTEP_EXPRESSIONS_AGGREGATION_AGGREGATE_FUNCTION_FACTORY_HPP_ #include <string> #include "expressions/aggregation/AggregationID.hpp" #include "utility/Macros.hpp" namespace quickstep { class AggregateFunction; namespace serialization { class AggregateFunction; } /** \addtogroup Expressions * @{ */ /** * @brief All-static factory class that provides access to the various concrete * implementations of AggregateFunction. * * AggregateFunctionFactory allows client code to use any AggregateFunction in * Quickstep in a generic way without having to know about all the specific * subclasses of AggregateFunction. In particular, it is used to deserialize * AggregateFunctions used in AggregationOperationState from their protobuf * representations (originally created by the optimizer) when deserializing a * QueryContext. **/ class AggregateFunctionFactory { public: /** * @brief Get a particular AggregateFunction by its ID. * * @param agg_id The ID of the desired AggregateFunction. * @return A reference to the singleton instance of the AggregateFunction * specified by agg_id. **/ static const AggregateFunction& Get(const AggregationID agg_id); /** * @brief Get a particular AggregateFunction by its name in SQL syntax. * * @param name The name of the desired AggregateFunction in lower case. * @return A pointer to the AggregateFunction specified by name, or NULL if * name does not match any known AggregateFunction. **/ static const AggregateFunction* GetByName(const std::string &name); /** * @brief Determine if a serialized protobuf representation of an * AggregateFunction is fully-formed and valid. * * @param proto A serialized protobuf representation of an AggregateFunction * to check for validity. * @return Whether proto is fully-formed and valid. **/ static bool ProtoIsValid(const serialization::AggregateFunction &proto); /** * @brief Get the AggregateFunction represented by a proto. * * @warning It is an error to call this method with an invalid proto. * ProtoIsValid() should be called first to check. * * @param proto A serialized protobuf representation of an AggregateFunction. * @return The AggregateFunction represented by proto. **/ static const AggregateFunction& ReconstructFromProto( const serialization::AggregateFunction &proto); private: // Class is all-static and can not be instantiated. AggregateFunctionFactory(); DISALLOW_COPY_AND_ASSIGN(AggregateFunctionFactory); }; /** @} */ } // namespace quickstep #endif // QUICKSTEP_EXPRESSIONS_AGGREGATION_AGGREGATE_FUNCTION_FACTORY_HPP_
e325a6c4a3d75a99021883e4d99effce2bb1cb7b
9d963319678fcd4930c8a0b2f29e2dd7575ca5c3
/ArcGISRuntimeSDKQt_CppSamples/Routing/FindRoute/FindRoute.cpp
3326dc6b783347f6883c551fff30b396f1d6e12c
[ "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
Gela/arcgis-runtime-samples-qt
a9ed563fe1b483c3fdb593e423955f45194b1304
1fe287ebd2ee887e708c22d620b3f28107d62e85
refs/heads/main
2023-08-03T06:20:11.722313
2021-08-25T21:35:42
2021-08-25T21:35:42
402,888,991
2
0
Apache-2.0
2021-09-03T20:21:22
2021-09-03T20:21:22
null
UTF-8
C++
false
false
6,518
cpp
FindRoute.cpp
// [WriteFile Name=FindRoute, Category=Routing] // [Legal] // Copyright 2016 Esri. // 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. // [Legal] #ifdef PCH_BUILD #include "pch.hpp" #endif // PCH_BUILD #include "FindRoute.h" #include "Map.h" #include "MapQuickView.h" #include "Basemap.h" #include "ArcGISVectorTiledLayer.h" #include "GraphicsOverlay.h" #include "Viewpoint.h" #include "Point.h" #include "SpatialReference.h" #include "SimpleRenderer.h" #include "SimpleLineSymbol.h" #include "PictureMarkerSymbol.h" #include "RouteTask.h" #include "RouteParameters.h" #include "Stop.h" using namespace Esri::ArcGISRuntime; FindRoute::FindRoute(QQuickItem* parent) : QQuickItem(parent) { } FindRoute::~FindRoute() = default; void FindRoute::init() { qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView"); qmlRegisterUncreatableType<QAbstractListModel>("Esri.Samples", 1, 0, "AbstractListModel", "AbstractListModel is uncreateable"); qmlRegisterType<FindRoute>("Esri.Samples", 1, 0, "FindRouteSample"); } void FindRoute::componentComplete() { QQuickItem::componentComplete(); // find QML MapView component m_mapView = findChild<MapQuickView*>("mapView"); // create a new basemap instance Basemap* basemap = new Basemap(BasemapStyle::ArcGISNavigation, this); // create a new map instance m_map = new Map(basemap, this); m_map->setInitialViewpoint(Viewpoint(Point(-13041154, 3858170, SpatialReference(3857)), 1e5)); // set map on the map view m_mapView->setMap(m_map); // create initial graphics overlays m_routeGraphicsOverlay = new GraphicsOverlay(this); SimpleLineSymbol* simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("cyan"), 4, this); SimpleRenderer* simpleRenderer = new SimpleRenderer(simpleLineSymbol, this); m_routeGraphicsOverlay->setRenderer(simpleRenderer); m_stopsGraphicsOverlay = new GraphicsOverlay(this); m_mapView->graphicsOverlays()->append(m_routeGraphicsOverlay); m_mapView->graphicsOverlays()->append(m_stopsGraphicsOverlay); // connect to loadStatusChanged signal connect(m_map, &Map::loadStatusChanged, this, [this](LoadStatus loadStatus) { if (loadStatus == LoadStatus::Loaded) { addStopGraphics(); setupRouteTask(); } }); } void FindRoute::addStopGraphics() { //! [FindRoute cpp addStopGraphics] // create the stop graphics' geometry Point stop1Geometry(-13041171, 3860988, SpatialReference(3857)); Point stop2Geometry(-13041693, 3856006, SpatialReference(3857)); // create the stop graphics' symbols PictureMarkerSymbol* stop1Symbol = getPictureMarkerSymbol(QUrl("qrc:/Samples/Routing/FindRoute/pinA.png")); PictureMarkerSymbol* stop2Symbol = getPictureMarkerSymbol(QUrl("qrc:/Samples/Routing/FindRoute/pinB.png")); // create the stop graphics Graphic* stop1Graphic = new Graphic(stop1Geometry, stop1Symbol, this); Graphic* stop2Graphic = new Graphic(stop2Geometry, stop2Symbol, this); // add to the overlay m_stopsGraphicsOverlay->graphics()->append(stop1Graphic); m_stopsGraphicsOverlay->graphics()->append(stop2Graphic); //! [FindRoute cpp addStopGraphics] } // Helper function for creating picture marker symbols PictureMarkerSymbol* FindRoute::getPictureMarkerSymbol(QUrl imageUrl) { PictureMarkerSymbol* pictureMarkerSymbol = new PictureMarkerSymbol(imageUrl, this); pictureMarkerSymbol->setWidth(32); pictureMarkerSymbol->setHeight(32); pictureMarkerSymbol->setOffsetY(16); return pictureMarkerSymbol; } void FindRoute::setupRouteTask() { //! [FindRoute new RouteTask] // create the route task pointing to an online service m_routeTask = new RouteTask(QUrl("https://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/Route"), this); // connect to loadStatusChanged signal connect(m_routeTask, &RouteTask::loadStatusChanged, this, [this](LoadStatus loadStatus) { if (loadStatus == LoadStatus::Loaded) { // Request default parameters once the task is loaded m_routeTask->createDefaultParameters(); } }); //! [FindRoute new RouteTask] //! [FindRoute connect RouteTask signals] // connect to createDefaultParametersCompleted signal connect(m_routeTask, &RouteTask::createDefaultParametersCompleted, this, [this](QUuid, RouteParameters routeParameters) { // Store the resulting route parameters m_routeParameters = routeParameters; }); // connect to solveRouteCompleted signal connect(m_routeTask, &RouteTask::solveRouteCompleted, this, [this](QUuid, RouteResult routeResult) { // Add the route graphic once the solve completes Route generatedRoute = routeResult.routes().at(0); Graphic* routeGraphic = new Graphic(generatedRoute.routeGeometry(), this); m_routeGraphicsOverlay->graphics()->append(routeGraphic); // set the direction maneuver list model m_directions = generatedRoute.directionManeuvers(this); emit directionsChanged(); // emit that the route has solved successfully emit solveRouteComplete(); }); //! [FindRoute connect RouteTask signals] // load the route task m_routeTask->load(); } QAbstractListModel* FindRoute::directions() { return m_directions; } //! [FindRoute solveRoute] void FindRoute::solveRoute() { if (m_routeTask->loadStatus() == LoadStatus::Loaded) { if (!m_routeParameters.isEmpty()) { // set parameters to return directions m_routeParameters.setReturnDirections(true); // clear previous stops from the parameters m_routeParameters.clearStops(); // set the stops to the parameters Stop stop1(m_stopsGraphicsOverlay->graphics()->at(0)->geometry()); stop1.setName("Origin"); Stop stop2(m_stopsGraphicsOverlay->graphics()->at(1)->geometry()); stop2.setName("Destination"); m_routeParameters.setStops(QList<Stop> { stop1, stop2 }); // solve the route with the parameters m_routeTask->solveRoute(m_routeParameters); } } } //! [FindRoute solveRoute]
2ad2cbba720995f7d0ea087d795a8fb048278d25
e79abd8b490c5cc302cbe51603b5757288ae8ab6
/src/PerlCommandLine.h
78497342d380e823b4ac27d5c62d376a64f0b19e
[ "MIT" ]
permissive
BenBanerjeeRichards/perl-ide-server
316ee1b918fce71520cba9b9071d76fa3cef1c0b
9a4a2d6342219241ef56da8b968688626d3102f3
refs/heads/master
2022-04-12T21:41:19.895439
2020-02-19T13:06:26
2020-02-19T13:06:26
203,227,113
1
0
null
null
null
null
UTF-8
C++
false
false
929
h
PerlCommandLine.h
// // Created by Ben Banerjee-Richards on 2019-10-18. // #ifndef PERLPARSER_PERLCOMMANDLINE_H #define PERLPARSER_PERLCOMMANDLINE_H #include "PerlProject.h" #include "../lib/pstreams.h" #include "Util.h" #include <iostream> #include <vector> #include <fstream> #include <optional> struct RunResult { // Each element represents a new line std::vector<std::string> output; std::vector<std::string> error; std::string toStr(); }; RunResult runCommand(std::string command); RunResult runCommand(const std::string &perlPath, const std::string &arguments); std::vector<std::string> getIncludePaths(const std::string &contextDir); std::optional<std::string> resolveModulePath(const std::vector<std::string> &includePaths, const std::vector<std::string> &module); std::optional<std::string> resolvePath(const std::vector<std::string> &includePaths, const std::string &path); #endif //PERLPARSER_PERLCOMMANDLINE_H
9863aa34fda2c48d6c8424ebff9795ca51eabcd7
27817c37b7e8e9e2a0831edb1d2a7f56a91e3f94
/src/config/reader.cpp
04c183a833dec8ba50f806c84f0e083c7a981e5d
[ "MIT" ]
permissive
weiwei2285762217/EDCC-Palmprint-Recognition
a00d089c9c4852ad1d0fa3ccb4473e648fcba8e3
c90875837c8bbd9be889dbd42ee51f78c9354683
refs/heads/master
2023-03-19T17:20:19.501232
2021-02-08T07:34:36
2021-02-08T07:34:36
null
0
0
null
null
null
null
UTF-8
C++
false
false
2,448
cpp
reader.cpp
// Copyright (c) 2019 leosocy. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. #include "config/reader.h" namespace edcc { #define INVOKE_SETTER_WITH_STATUS_CHECKING(setter) \ do { \ auto status = setter; \ if (!status.IsOk()) { \ return status; \ } \ } while (0) Status ConfigReader::SetImageSize(uint8_t size) { if (size < limit::kMinImageSize) { return Status::InvalidArgument("Image size less than minimum limit."); } encoder_cfg_.image_size = size; return Status::Ok(); } Status ConfigReader::SetGaborKernelSize(uint8_t size) { if (size > encoder_cfg_.image_size) { return Status::InvalidArgument("Gabor kernel size larger than image size."); } if ((size & 0x01) == 0) { return Status::InvalidArgument("Gabor kernel size not odd."); } encoder_cfg_.gabor_kernel_size = size; return Status::Ok(); } Status ConfigReader::SetLaplaceKernelSize(uint8_t size) { if (size > encoder_cfg_.image_size || size > limit::kMaxLaplaceKernelSize) { return Status::InvalidArgument("Laplace kernel size larger than image size or %d.", limit::kMaxLaplaceKernelSize); } if ((size & 0x01) == 0) { return Status::InvalidArgument("Laplace kernel size not odd."); } encoder_cfg_.laplace_kernel_size = size; return Status::Ok(); } Status ConfigReader::SetGaborDirections(uint8_t num) { if (num > limit::kMaxGaborDirections || num < limit::kMinGaborDirections) { return Status::InvalidArgument("Gabor directions not in range [%d, %d].", limit::kMinGaborDirections, limit::kMaxGaborDirections); } encoder_cfg_.gabor_directions = num; return Status::Ok(); } SimpleConfigReader::SimpleConfigReader(const EncoderConfig& config) { encoder_cfg_ = config; } Status SimpleConfigReader::LoadAndValidate() { INVOKE_SETTER_WITH_STATUS_CHECKING(SetImageSize(encoder_cfg_.image_size)); INVOKE_SETTER_WITH_STATUS_CHECKING(SetGaborKernelSize(encoder_cfg_.gabor_kernel_size)); INVOKE_SETTER_WITH_STATUS_CHECKING(SetLaplaceKernelSize(encoder_cfg_.laplace_kernel_size)); INVOKE_SETTER_WITH_STATUS_CHECKING(SetGaborDirections(encoder_cfg_.gabor_directions)); return Status::Ok(); } } // namespace edcc
c0f65beaf6b0f4d8df947913b325eeefb44234c1
792d53ec1b8fe7afb46450312fca4ef1edf056da
/MultiThread/MultiThread/main.cpp
7688186a68aa75bc7a8f2085c46fd380e437803a
[]
no_license
kuroki-ty/what-is-programming
a8ace08866063bc8eadcb641965a2f701e38cb62
efa87cf20a8e192148324a043e9a547fffd22c4b
refs/heads/master
2021-01-01T18:05:44.716889
2018-03-29T07:35:21
2018-03-29T07:35:21
98,247,579
0
0
null
2018-03-29T07:35:22
2017-07-25T00:47:14
C
UTF-8
C++
false
false
2,946
cpp
main.cpp
#include <iostream> #include <vector> #include <numeric> #include <pthread.h> #include <condition_variable> #include <errno.h> namespace { const uint32_t N = 256; // リングバッファ限界値 } // namespace template <typename T> class MultiThreadQueue { public: void enqueue(const T &data) { std::unique_lock<std::mutex> lock(_mutex); int next = (_tail + 1) % N; // リングバッファがいっぱいの時はブロックして待つ _notFull.wait(lock, [this, next] { return next != _head; }); // キューに入れる _data[_tail] = data; _tail = next; _notEmpty.notify_all(); // dequeue OK } T dequeue() { std::unique_lock<std::mutex> lock(_mutex); T ret = T(); // リングバッファが空の時はブロックして待つ _notEmpty.wait(lock, [this] { return _head != _tail; }); // キューから取り出す ret = _data[_head]; _head = (_head + 1) % N; _notFull.notify_all(); // enqueue OK return ret; } private: T _data[N]; // バッファ int _head = 0; // 読み出しポインタ int _tail = 0; // 書き出しポインタ std::mutex _mutex; std::condition_variable _notFull; // enqueue用状態変数 std::condition_variable _notEmpty; // dequeue用状態変数 }; struct WorkData { enum { MESSAGE_TERMINATE, MESSAGE_CALCSUM, } message; std::vector<int> vec; }; MultiThreadQueue<WorkData> queue; void* worker(void *) { /* 渡されたWorkDataに基づいて処理する */ for (;;) { WorkData data = queue.dequeue(); if (data.message == WorkData::MESSAGE_TERMINATE) { /* スレッドを終了する */ pthread_exit(NULL); // スレッドを終了 break; } if (data.message == WorkData::MESSAGE_CALCSUM) { int sum = std::accumulate(data.vec.begin(), data.vec.end(), 0); printf("sum of vector is %d\n", sum); } } return nullptr; } int main() { /* スレッドを起動する */ pthread_t th1; pthread_create(&th1, NULL, worker, NULL); WorkData work1 = { WorkData::MESSAGE_CALCSUM, { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } }; // 55 queue.enqueue(work1); WorkData work2 = { WorkData::MESSAGE_CALCSUM, { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 } }; // 100 queue.enqueue(work2); WorkData work3 = { WorkData::MESSAGE_CALCSUM, { 1, -1, 3, -3, 5, -5, 7, -7, 9, -9 } }; // 0 queue.enqueue(work3); WorkData work4 = { WorkData::MESSAGE_CALCSUM, { 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 } }; // 385 queue.enqueue(work4); WorkData work5 = { WorkData::MESSAGE_TERMINATE, { } }; queue.enqueue(work5); /* スレッドの終了を待つ */ pthread_join(th1, NULL); return 0; }
9704d41759481f6e1d1e57b6ed8df6948aba3fec
c224d77a3c2b4e8683edaaacc8b225ca4196d232
/FINAL.CPP
a697e96c5d36343652c40df971e74d43fea78928
[]
no_license
smitavaidya/Event-management-System-using-Hashing
6fb769cfd3fdaddb3213b523f46ea524ad8aa597
20cb2e791ea6d3379e75623d1eb659074e330155
refs/heads/master
2020-03-26T22:11:38.646432
2018-08-20T15:57:37
2018-08-20T15:57:37
145,439,266
17
10
null
null
null
null
UTF-8
C++
false
false
10,436
cpp
FINAL.CPP
// 1RN15IS083 && 1RN15IS091 #include<fstream.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<iostream.h> #include<iomanip.h> #define studentfile"event.txt" #define datafile"dat.txt" #define recsize 80 #define max 100 #include<dir.h> #include<dos.h> #include<bios.h> #include<graphics.h> fstream file,ifile; char buffer[85]; class student { public: char eid[15],ename[20],rfee[5],pamt[5],toc[10]; void initial(); void read(); void retrieve(int addr,char k[]); void display(); void ddisp(); void edelete(int addr,char k[]); void modify(int addr,char k[]); }; void student::initial() { int i,j; ifile.open(datafile,ios::app); if(!ifile) { cout<<"Unable to open a file"<<endl; getch(); exit(1); } file.open(studentfile,ios::in); if(!file) { file.open(studentfile,ios::out); if(!file) { cout<<"unable to open the file"; exit(1); } for(i=0;i<max;i++) { file.seekp(i*recsize,ios::beg); for(j=0;j<recsize-2;j++) file<<"#"; file<<endl; } cout<<"empty file created"; } file.close(); ifile.close(); return; } void student::read() { clrscr(); int i; gotoxy(20,2); for(i=0;i<50;i++) cout<<"*"; gotoxy(35,4); cout<<"ADD AN EVENT"; gotoxy(20,6); for(i=0;i<50;i++) cout<<"*"; gotoxy(20,8); cout<<"ENTER EVENT DETAILS:"<<endl; cout<<"\tEnter the event id:(ev__)";gets(eid); cout<<"\tEnter the event name:"; gets(ename); cout<<"\tEnter the time of conduct:";gets(toc); cout<<"\tEnter the registeration fee:";gets(rfee); cout<<"\tEnter the prize money:"; gets(pamt); strcpy(buffer,eid); strcat(buffer,"|"); strcat(buffer,ename); strcat(buffer,"|"); strcat(buffer,toc); strcat(buffer,"|"); strcat(buffer,rfee); strcat(buffer,"|"); strcat(buffer,pamt); strcat(buffer,"|"); return; } int hash(char key[]) { int i=0,sum=0; while(key[i]!='\0') { sum=sum+(key[i]); i++; } return sum % max; } void store(int addr) { char dummy[10]; int flag=0,i; ifile.open(datafile,ios::app); ifile.fill('*'); ifile<<setiosflags(ios::left)<<setw(sizeof(student))<<buffer<<endl; file.open(studentfile,ios::in|ios::out); file.seekp(addr*recsize,ios::beg); file.getline(dummy,5,'\n'); if(strcmp(dummy,"####")==0) { file.seekp(addr*recsize,ios::beg); file<<buffer; flag=1; } else { for(i=addr+1;i!=addr;i++) { if(i%max==0) i=0; file.seekg(i*recsize,ios::beg); file.getline(dummy,5,'\n'); if(strcmp(dummy,"####")==0) { // cout<<"\n collision has occured\n"; // cout<<"home address is:"<<addr<<"actual address is:"<<i<<"\n"; file.seekp(i*recsize,ios::beg); file<<buffer; flag=1; break; } } } if(i==addr && (!flag)) cout<<"hash file is full,record cannot be inserted\n"; file.close(); ifile.close(); return; } void student::retrieve(int addr,char k[]) { int found=0,i; char dummy[10]; i=addr; file.open(studentfile,ios::in|ios::out); do { file.seekg(i*recsize,ios::beg); file.getline(dummy,5,'\n'); if(strcmp(dummy,"####")==0) break; file.seekg(i*recsize,ios::beg); file.getline(eid,15,'|'); if(strcmp(eid,k)==0) { found=1; textcolor(RED); cout<<"\n"; gotoxy(20,12); cout<<"RECORD FOUND!!\n"; cout<<endl; file.getline(ename,20,'|'); file.getline(toc,10,'|'); file.getline(rfee,5,'|'); file.getline(pamt,5,'|'); gotoxy(20,14); cout<<"ID:"<<eid<<endl; gotoxy(20,15); cout<<"NAME:"<<ename; gotoxy(20,16); cout<<"Time Of Conduct:"<<toc; gotoxy(20,17); cout<<"Registeration Fee:"<<rfee; gotoxy(20,18); cout<<"Prize Amount:"<<pamt; break; } else { i++; if(i%max==0) i=0; } } while(i!=addr); if(found==0) cout<<"\n\t\t\trecord does not exist in hash file\n"; getch(); return; } void student::display() { clrscr(); char dummy[85]; file.open(studentfile,ios::in|ios::out); cout<<setiosflags(ios::left); cout<<"\t\t\t\tEVENT DETAILS"<<endl; cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl; cout<<"\t"<<setw(10)<<"ID"<<setw(20)<<"NAME"<<setw(15)<<"CONDUCT TIME"<<setw(10)<<"FEE"<<setw(10)<<"PRIZE"<<endl; cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl; while(1) { file.getline(eid,15,'|'); file.getline(ename,20,'|'); file.getline(toc,10,'|'); file.getline(rfee,5,'|'); file.getline(pamt,5,'|'); file.getline(dummy,85,'\n'); if(file.eof()) break; if(eid[0]!='#') { cout<<"\t"<<setw(10)<<eid<<setw(20)<<ename<<setw(15)<<toc<<setw(10)<<rfee<<setw(10)<<pamt<<"\n"; } } file.close(); getch(); } void student::edelete(int addr,char k[]) { int found=0,i,j,fn; char dummy[10],temp[80]; i=addr; ifile.open(datafile,ios::in|ios::out); while(!(ifile.eof())) { fn = ifile.tellg(); ifile.getline(eid,15,'|'); ifile.getline(temp,80,'\n'); if(strcmp(eid,k)==0) { ifile.seekg(fn,ios::beg); ifile.put('$'); } } ifile.close(); file.open(studentfile,ios::in|ios::out); do { file.seekg(i*recsize,ios::beg); file.getline(dummy,5,'\n'); if(strcmp(dummy,"####")==0) break; file.seekg(i*recsize,ios::beg); file.getline(eid,15,'|'); if(strcmp(eid,k)==0) { found=1; cout<<"\n\t\t\t\tRECORD FOUND!!\n"; cout<<endl; file.getline(ename,20,'|'); cout<<"\t\t\t\tkey="<<eid<<endl<<"\n\t\t\t\tname="<<ename<<"\n"; file.seekg(i*recsize,ios::beg); for(j=0;j<recsize-2;j++) file<<"#"; file<<endl; break; } else { i++; if(i%max==0) i=0; } } while(i!=addr); if(found==0) cout<<"\n\t\t\trecord does not exist in hash file\n"; getch(); return; } void student::ddisp() { clrscr(); char dummy[80]; ifile.open(datafile,ios::in); cout<<setiosflags(ios::left); cout<<"\t\t\t\tEVENT DETAILS"<<endl; cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl; cout<<"\t"<<setw(10)<<"ID"<<setw(20)<<"NAME"<<setw(15)<<"CONDUCT TIME"<<setw(10)<<"FEE"<<setw(10)<<"PRIZE"<<endl; cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl; while(1) { ifile.getline(eid,15,'|'); ifile.getline(ename,20,'|'); ifile.getline(toc,10,'|'); ifile.getline(rfee,5,'|'); ifile.getline(pamt,5,'|'); ifile.getline(dummy,80,'\n'); if(ifile.eof()) break; if(eid[0]!='$') { cout<<"\t"<<setw(10)<<eid<<setw(20)<<ename<<setw(15)<<toc<<setw(10)<<rfee<<setw(10)<<pamt<<"\n"; } } ifile.close(); getch(); } void student::modify(int addr,char k[]) { int found=0,i,count,fn; char dummy[10],temp[80]; i=addr; ifile.open(datafile,ios::in|ios::out); while(!(ifile.eof())) { fn = ifile.tellg(); ifile.getline(eid,15,'|'); ifile.getline(temp,80,'\n'); if(strcmp(eid,k)==0) { ifile.seekg(fn,ios::beg); ifile.put('$'); } } ifile.close(); file.open(studentfile,ios::in|ios::out); do { file.seekg(i*recsize,ios::beg); file.getline(dummy,5,'\n'); if(strcmp(dummy,"####")==0) break; file.seekg(i*recsize,ios::beg); file.getline(eid,15,'|'); if(strcmp(eid,k)==0) { found=1; textcolor(RED); cout<<"\n"; gotoxy(20,12); cout<<"RECORD FOUND!!\n"; cout<<endl; file.getline(ename,20,'|'); gotoxy(20,13); cout<<"ID:"<<eid<<endl; gotoxy(20,14); cout<<"NAME:"<<ename<<"\n"; file.getline(ename,20,'|'); gotoxy(20,16); cout<<"Enter the event name:"; gets(ename); gotoxy(20,17); cout<<"Enter the time of conduct:"; gets(toc); gotoxy(20,18); cout<<"Enter the registration fee:"; gets(rfee); gotoxy(20,19); cout<<"Enter the prize amount:"; gets(pamt); strcpy(buffer,eid); strcat(buffer,"|"); strcat(buffer,ename); strcat(buffer,"|"); strcat(buffer,toc); strcat(buffer,"|"); strcat(buffer,rfee); strcat(buffer,"|"); strcat(buffer,pamt); strcat(buffer,"|"); file.seekp(addr*recsize,ios::beg); file<<buffer; break; } else { i++; if(i%max==0) i=0; } } while(i!=addr); if(found==0) cout<<"\n\t\t\trecord does not exist in hash file\n"; getch(); ifile.open(datafile,ios::app); ifile.fill('*'); ifile<<setiosflags(ios::left)<<setw(sizeof(student))<<buffer<<endl; ifile.close(); return; } void screen() { int i; textcolor(YELLOW); clrscr(); gotoxy(20,2); for(i=0;i<50;i++) cout<<"*"; gotoxy(20,4); cout<<"*"; gotoxy(36,4); cout<<"MAIN MENU"; gotoxy(70,4); cout<<"*"; gotoxy(20,6); for(i=0;i<50;i++) cout<<"*"; gotoxy(30,8); cout<<"* "<<"1. Add an event"<<endl; gotoxy(30,10); cout<<"* "<<"2. Display events in Datafile"<<endl; gotoxy(30,12); cout<<"* "<<"3. Search event details"<<endl; gotoxy(30,14); cout<<"* "<<"4. Display all event"<<endl; gotoxy(30,16); cout<<"* "<<"5. Delete an event "<<endl; gotoxy(30,18); cout<<"* "<<"6. Modify an event"<<endl; gotoxy(30,20); cout<<"* "<<"7. Quit Program\n"; gotoxy(20,22); for(i=0;i<50;i++) cout<<"*"; } void main() { int ch,addr,i,j; char skey[15],dkey[15],mkey[15]; student s; clrscr(); s.initial(); for(;;) { screen(); gotoxy(20,24); cout<<"ENTER YOUR CHOICE:"; cin>>ch; switch(ch) { case 1: s.read(); addr=hash(s.eid); store(addr); break; case 2:s.ddisp(); break; case 3: clrscr(); gotoxy(20,2); for(i=0;i<50;i++) cout<<"*"; gotoxy(30,4); cout<<"SEARCH FOR EVENT DETAILS"; gotoxy(20,6); for(i=0;i<50;i++) cout<<"*"; gotoxy(20,8); cout<<"ENTER EVENT ID:"; cin>>skey; gotoxy(20,10); cout<<"++++++++++++++++++++++++++++++++"<<endl; addr=hash(skey); s.retrieve(addr,skey); break; case 4: s.display(); break; case 5: clrscr(); gotoxy(20,2); for(i=0;i<50;i++) cout<<"*"; gotoxy(30,4); cout<<"DELETE AN EVENT"; gotoxy(20,6); for(i=0;i<50;i++) cout<<"*"; gotoxy(20,8); cout<<"Enter the ID to delete:"; cin>>dkey; gotoxy(20,10); cout<<"+++++++++++++++++++++++++++++++++++++++++++"<<endl; addr=hash(dkey); s.edelete(addr,dkey); break; case 6:clrscr(); gotoxy(20,2); for(i=0;i<50;i++) cout<<"*"; gotoxy(30,4); cout<<"MODIFY AN EVENT"; gotoxy(20,6); for(i=0;i<50;i++) cout<<"*"; gotoxy(20,8); cout<<"ENTER EVENT ID:"; cin>>mkey; gotoxy(20,10); cout<<"++++++++++++++++++++++++++++++++"<<endl; addr=hash(mkey); s.modify(addr,mkey); break; default:exit(0); break; } file.close(); } }
6126f11e7eb0645c26929cb921f8a011df3033e0
44f3ce9f51f04c550d89bc6ea6723caf8ffa66b4
/include/PokemonUtils.hh
ec0ee07d29495d5b49a94b48a8e4eb7bed86894e
[ "MIT" ]
permissive
ZackDibe/pokebot
f9b519581b83e5d3098d76d99dfc9cbdad13cb83
0d649dc7bccaccc52097898dcf0dc093e3d7c427
refs/heads/master
2021-05-28T01:14:24.635515
2014-06-29T11:47:35
2014-06-29T11:47:35
null
0
0
null
null
null
null
UTF-8
C++
false
false
423
hh
PokemonUtils.hh
#ifndef __POKEMONUTILS_HH__ #define __POKEMONUTILS_HH__ #include <stdint.h> #define WRAM_OFFSET 0x2000000 #define IRAM_OFFSET 0x3000000 #define ROM_OFFSET 0x8000000 #define BANK_PTR 0x3526A8 #define NAMES_PTR 0x245EE0 #define PTEAM_PTR 0x024284 #define ETEAM_PTR 0x02402C #define CURR_BANK_PTR 0x031DBC #define CURR_MAP_PTR 0x031DBD #define POW(x) ((x) * (x)) char pokeCharsetToAscii(uint8_t c); #endif
a7c406d00f1546aaa7d8e9a375c3240020f8d16e
5d83739af703fb400857cecc69aadaf02e07f8d1
/Archive2/b5/a6693500e3acc4/main.cpp
cf7d9e0c8f9ab334d21b186f76ff655d33c520da
[]
no_license
WhiZTiM/coliru
3a6c4c0bdac566d1aa1c21818118ba70479b0f40
2c72c048846c082f943e6c7f9fa8d94aee76979f
refs/heads/master
2021-01-01T05:10:33.812560
2015-08-24T19:09:22
2015-08-24T19:09:22
56,789,706
3
0
null
null
null
null
UTF-8
C++
false
false
191
cpp
main.cpp
#include <stdio.h> enum blah { A = (1 << 16), B = (1 << 17), C = (1 << 18), G = (1 << 20), TEST = (A | B | C , G) } ; int main() { printf( "%d\n", TEST ) ; }
81358032c095465bef8ea40d2275718142da2750
eb63872abbac7b41cf0b5441abc7e2462f66a885
/media/devices/devicemanager_unittest.cc
0789c412103959e06f3b79df6eecc86dee8c2a7c
[]
no_license
mehome/droid.external.libjingle.talk
e84a25bfbfbe52e99bf482fc9836f12ad801f2cf
8e9ecc3aeff6be3f121e732963191826f17f4fdd
refs/heads/master
2021-08-30T00:33:21.175036
2017-12-15T08:03:46
2017-12-15T08:03:46
null
0
0
null
null
null
null
UTF-8
C++
false
false
17,436
cc
devicemanager_unittest.cc
/* * libjingle * Copyright 2004 Google 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 "talk/media/devices/devicemanager.h" #ifdef WIN32 #include "talk/base/win32.h" #include <objbase.h> #endif #include <string> #include "talk/base/fileutils.h" #include "talk/base/gunit.h" #include "talk/base/logging.h" #include "talk/base/pathutils.h" #include "talk/base/scoped_ptr.h" #include "talk/base/stream.h" #include "talk/base/windowpickerfactory.h" #include "talk/media/base/fakevideocapturer.h" #include "talk/media/base/testutils.h" #include "talk/media/devices/filevideocapturer.h" #include "talk/media/devices/v4llookup.h" #ifdef LINUX // TODO(juberti): Figure out why this doesn't compile on Windows. #include "talk/base/fileutils_mock.h" #endif // LINUX using talk_base::Pathname; using talk_base::FileTimeType; using talk_base::scoped_ptr; using cricket::Device; using cricket::DeviceManager; using cricket::DeviceManagerFactory; using cricket::DeviceManagerInterface; const cricket::VideoFormat kVgaFormat(640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); const cricket::VideoFormat kHdFormat(1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); class FakeVideoCapturerFactory : public cricket::VideoCapturerFactory { public: FakeVideoCapturerFactory() {} virtual ~FakeVideoCapturerFactory() {} virtual cricket::VideoCapturer* Create(const cricket::Device& device) { return new cricket::FakeVideoCapturer; } }; class DeviceManagerTestFake : public testing::Test { public: virtual void SetUp() { dm_.reset(DeviceManagerFactory::Create()); EXPECT_TRUE(dm_->Init()); DeviceManager* device_manager = static_cast<DeviceManager*>(dm_.get()); device_manager->set_device_video_capturer_factory( new FakeVideoCapturerFactory()); } virtual void TearDown() { dm_->Terminate(); } protected: scoped_ptr<DeviceManagerInterface> dm_; }; // Test that we startup/shutdown properly. TEST(DeviceManagerTest, StartupShutdown) { scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); EXPECT_TRUE(dm->Init()); dm->Terminate(); } // Test CoInitEx behavior #ifdef WIN32 TEST(DeviceManagerTest, CoInitialize) { scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); std::vector<Device> devices; // Ensure that calls to video device work if COM is not yet initialized. EXPECT_TRUE(dm->Init()); EXPECT_TRUE(dm->GetVideoCaptureDevices(&devices)); dm->Terminate(); // Ensure that the ref count is correct. EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); CoUninitialize(); // Ensure that Init works in COINIT_APARTMENTTHREADED setting. EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); EXPECT_TRUE(dm->Init()); dm->Terminate(); CoUninitialize(); // Ensure that the ref count is correct. EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); CoUninitialize(); // Ensure that Init works in COINIT_MULTITHREADED setting. EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); EXPECT_TRUE(dm->Init()); dm->Terminate(); CoUninitialize(); // Ensure that the ref count is correct. EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); CoUninitialize(); } #endif // Test enumerating devices (although we may not find any). TEST(DeviceManagerTest, GetDevices) { scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); std::vector<Device> audio_ins, audio_outs, video_ins; std::vector<cricket::Device> video_in_devs; cricket::Device def_video; EXPECT_TRUE(dm->Init()); EXPECT_TRUE(dm->GetAudioInputDevices(&audio_ins)); EXPECT_TRUE(dm->GetAudioOutputDevices(&audio_outs)); EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_in_devs)); EXPECT_EQ(video_ins.size(), video_in_devs.size()); // If we have any video devices, we should be able to pick a default. EXPECT_TRUE(dm->GetVideoCaptureDevice( cricket::DeviceManagerInterface::kDefaultDeviceName, &def_video) != video_ins.empty()); } // Test that we return correct ids for default and bogus devices. TEST(DeviceManagerTest, GetAudioDeviceIds) { scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); Device device; EXPECT_TRUE(dm->Init()); EXPECT_TRUE(dm->GetAudioInputDevice( cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); EXPECT_EQ("-1", device.id); EXPECT_TRUE(dm->GetAudioOutputDevice( cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); EXPECT_EQ("-1", device.id); EXPECT_FALSE(dm->GetAudioInputDevice("_NOT A REAL DEVICE_", &device)); EXPECT_FALSE(dm->GetAudioOutputDevice("_NOT A REAL DEVICE_", &device)); } // Test that we get the video capture device by name properly. TEST(DeviceManagerTest, GetVideoDeviceIds) { scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); Device device; EXPECT_TRUE(dm->Init()); EXPECT_FALSE(dm->GetVideoCaptureDevice("_NOT A REAL DEVICE_", &device)); std::vector<Device> video_ins; EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); if (!video_ins.empty()) { // Get the default device with the parameter kDefaultDeviceName. EXPECT_TRUE(dm->GetVideoCaptureDevice( cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); // Get the first device with the parameter video_ins[0].name. EXPECT_TRUE(dm->GetVideoCaptureDevice(video_ins[0].name, &device)); EXPECT_EQ(device.name, video_ins[0].name); EXPECT_EQ(device.id, video_ins[0].id); } } TEST(DeviceManagerTest, GetVideoDeviceIds_File) { scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); EXPECT_TRUE(dm->Init()); Device device; const std::string test_file = cricket::GetTestFilePath("captured-320x240-2s-48.frames"); EXPECT_TRUE(dm->GetVideoCaptureDevice(test_file, &device)); EXPECT_TRUE(cricket::FileVideoCapturer::IsFileVideoCapturerDevice(device)); } TEST(DeviceManagerTest, VerifyDevicesListsAreCleared) { const std::string imaginary("_NOT A REAL DEVICE_"); scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); std::vector<Device> audio_ins, audio_outs, video_ins; audio_ins.push_back(Device(imaginary, imaginary)); audio_outs.push_back(Device(imaginary, imaginary)); video_ins.push_back(Device(imaginary, imaginary)); EXPECT_TRUE(dm->Init()); EXPECT_TRUE(dm->GetAudioInputDevices(&audio_ins)); EXPECT_TRUE(dm->GetAudioOutputDevices(&audio_outs)); EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); for (size_t i = 0; i < audio_ins.size(); ++i) { EXPECT_NE(imaginary, audio_ins[i].name); } for (size_t i = 0; i < audio_outs.size(); ++i) { EXPECT_NE(imaginary, audio_outs[i].name); } for (size_t i = 0; i < video_ins.size(); ++i) { EXPECT_NE(imaginary, video_ins[i].name); } } static bool CompareDeviceList(std::vector<Device>& devices, const char* const device_list[], int list_size) { if (list_size != static_cast<int>(devices.size())) { return false; } for (int i = 0; i < list_size; ++i) { if (devices[i].name.compare(device_list[i]) != 0) { return false; } } return true; } TEST(DeviceManagerTest, VerifyFilterDevices) { static const char* const kTotalDevicesName[] = { "Google Camera Adapters are tons of fun.", "device1", "device2", "device3", "device4", "device5", "Google Camera Adapter 0", "Google Camera Adapter 1", }; static const char* const kFilteredDevicesName[] = { "device2", "device4", "Google Camera Adapter", NULL, }; static const char* const kDevicesName[] = { "device1", "device3", "device5", }; std::vector<Device> devices; for (int i = 0; i < ARRAY_SIZE(kTotalDevicesName); ++i) { devices.push_back(Device(kTotalDevicesName[i], i)); } EXPECT_TRUE(CompareDeviceList(devices, kTotalDevicesName, ARRAY_SIZE(kTotalDevicesName))); // Return false if given NULL as the exclusion list. EXPECT_TRUE(DeviceManager::FilterDevices(&devices, NULL)); // The devices should not change. EXPECT_TRUE(CompareDeviceList(devices, kTotalDevicesName, ARRAY_SIZE(kTotalDevicesName))); EXPECT_TRUE(DeviceManager::FilterDevices(&devices, kFilteredDevicesName)); EXPECT_TRUE(CompareDeviceList(devices, kDevicesName, ARRAY_SIZE(kDevicesName))); } #ifdef LINUX class FakeV4LLookup : public cricket::V4LLookup { public: explicit FakeV4LLookup(std::vector<std::string> device_paths) : device_paths_(device_paths) {} protected: bool CheckIsV4L2Device(const std::string& device) { return std::find(device_paths_.begin(), device_paths_.end(), device) != device_paths_.end(); } private: std::vector<std::string> device_paths_; }; TEST(DeviceManagerTest, GetVideoCaptureDevices_K2_6) { std::vector<std::string> devices; devices.push_back("/dev/video0"); devices.push_back("/dev/video5"); cricket::V4LLookup::SetV4LLookup(new FakeV4LLookup(devices)); std::vector<talk_base::FakeFileSystem::File> files; files.push_back(talk_base::FakeFileSystem::File("/dev/video0", "")); files.push_back(talk_base::FakeFileSystem::File("/dev/video5", "")); files.push_back(talk_base::FakeFileSystem::File( "/sys/class/video4linux/video0/name", "Video Device 1")); files.push_back(talk_base::FakeFileSystem::File( "/sys/class/video4linux/video1/model", "Bad Device")); files.push_back( talk_base::FakeFileSystem::File("/sys/class/video4linux/video5/model", "Video Device 2")); talk_base::FilesystemScope fs(new talk_base::FakeFileSystem(files)); scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); std::vector<Device> video_ins; EXPECT_TRUE(dm->Init()); EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); EXPECT_EQ(2u, video_ins.size()); EXPECT_EQ("Video Device 1", video_ins.at(0).name); EXPECT_EQ("Video Device 2", video_ins.at(1).name); } TEST(DeviceManagerTest, GetVideoCaptureDevices_K2_4) { std::vector<std::string> devices; devices.push_back("/dev/video0"); devices.push_back("/dev/video5"); cricket::V4LLookup::SetV4LLookup(new FakeV4LLookup(devices)); std::vector<talk_base::FakeFileSystem::File> files; files.push_back(talk_base::FakeFileSystem::File("/dev/video0", "")); files.push_back(talk_base::FakeFileSystem::File("/dev/video5", "")); files.push_back(talk_base::FakeFileSystem::File( "/proc/video/dev/video0", "param1: value1\nname: Video Device 1\n param2: value2\n")); files.push_back(talk_base::FakeFileSystem::File( "/proc/video/dev/video1", "param1: value1\nname: Bad Device\n param2: value2\n")); files.push_back(talk_base::FakeFileSystem::File( "/proc/video/dev/video5", "param1: value1\nname: Video Device 2\n param2: value2\n")); talk_base::FilesystemScope fs(new talk_base::FakeFileSystem(files)); scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); std::vector<Device> video_ins; EXPECT_TRUE(dm->Init()); EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); EXPECT_EQ(2u, video_ins.size()); EXPECT_EQ("Video Device 1", video_ins.at(0).name); EXPECT_EQ("Video Device 2", video_ins.at(1).name); } TEST(DeviceManagerTest, GetVideoCaptureDevices_KUnknown) { std::vector<std::string> devices; devices.push_back("/dev/video0"); devices.push_back("/dev/video5"); cricket::V4LLookup::SetV4LLookup(new FakeV4LLookup(devices)); std::vector<talk_base::FakeFileSystem::File> files; files.push_back(talk_base::FakeFileSystem::File("/dev/video0", "")); files.push_back(talk_base::FakeFileSystem::File("/dev/video1", "")); files.push_back(talk_base::FakeFileSystem::File("/dev/video5", "")); talk_base::FilesystemScope fs(new talk_base::FakeFileSystem(files)); scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); std::vector<Device> video_ins; EXPECT_TRUE(dm->Init()); EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); EXPECT_EQ(2u, video_ins.size()); EXPECT_EQ("/dev/video0", video_ins.at(0).name); EXPECT_EQ("/dev/video5", video_ins.at(1).name); } #endif // LINUX TEST(DeviceManagerTest, GetWindows) { if (!talk_base::WindowPickerFactory::IsSupported()) { BLOG(LS_INFO) << "skipping test: window capturing is not supported with " << "current configuration."; return; } scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); std::vector<talk_base::WindowDescription> descriptions; EXPECT_TRUE(dm->Init()); if (!dm->GetWindows(&descriptions) || descriptions.empty()) { BLOG(LS_INFO) << "skipping test: window capturing. Does not have any " << "windows to capture."; return; } scoped_ptr<cricket::VideoCapturer> capturer(dm->CreateWindowCapturer( descriptions.front().id())); EXPECT_FALSE(capturer.get() == NULL); // TODO(hellner): creating a window capturer and immediately deleting it // results in "Continuous Build and Test Mainline - Mac opt" failure (crash). // Remove the following line as soon as this has been resolved. talk_base::Thread::Current()->ProcessMessages(1); } TEST(DeviceManagerTest, GetDesktops) { if (!talk_base::WindowPickerFactory::IsSupported()) { BLOG(LS_INFO) << "skipping test: desktop capturing is not supported with " << "current configuration."; return; } scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); std::vector<talk_base::DesktopDescription> descriptions; EXPECT_TRUE(dm->Init()); if (!dm->GetDesktops(&descriptions) || descriptions.empty()) { BLOG(LS_INFO) << "skipping test: desktop capturing. Does not have any " << "desktops to capture."; return; } scoped_ptr<cricket::VideoCapturer> capturer(dm->CreateDesktopCapturer( descriptions.front().id())); EXPECT_FALSE(capturer.get() == NULL); } TEST_F(DeviceManagerTestFake, CaptureConstraintsWhitelisted) { const Device device("white", "white_id"); dm_->SetVideoCaptureDeviceMaxFormat(device.name, kHdFormat); scoped_ptr<cricket::VideoCapturer> capturer( dm_->CreateVideoCapturer(device)); cricket::VideoFormat best_format; capturer->set_enable_camera_list(true); EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); EXPECT_EQ(kHdFormat, best_format); } TEST_F(DeviceManagerTestFake, CaptureConstraintsNotWhitelisted) { const Device device("regular", "regular_id"); scoped_ptr<cricket::VideoCapturer> capturer( dm_->CreateVideoCapturer(device)); cricket::VideoFormat best_format; capturer->set_enable_camera_list(true); EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); EXPECT_EQ(kVgaFormat, best_format); } TEST_F(DeviceManagerTestFake, CaptureConstraintsUnWhitelisted) { const Device device("un_white", "un_white_id"); dm_->SetVideoCaptureDeviceMaxFormat(device.name, kHdFormat); dm_->ClearVideoCaptureDeviceMaxFormat(device.name); scoped_ptr<cricket::VideoCapturer> capturer( dm_->CreateVideoCapturer(device)); cricket::VideoFormat best_format; capturer->set_enable_camera_list(true); EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); EXPECT_EQ(kVgaFormat, best_format); } TEST_F(DeviceManagerTestFake, CaptureConstraintsWildcard) { const Device device("any_device", "any_device"); dm_->SetVideoCaptureDeviceMaxFormat("*", kHdFormat); scoped_ptr<cricket::VideoCapturer> capturer( dm_->CreateVideoCapturer(device)); cricket::VideoFormat best_format; capturer->set_enable_camera_list(true); EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); EXPECT_EQ(kHdFormat, best_format); }
9a604f8182afd9de2b7e9be700765bac63483767
3fdd206959153e15412be20d440e7544c0407e3a
/include/MyImage.h
d7dc140643009ce528cb469cacc24d621fae7059
[]
no_license
minilagrotte/ProjetTraitement
3f2c9768b3c6c44751c0fa577e93d7099a114ffd
1322538123d9d0b9c8cc37add134c3b0e1720bff
refs/heads/master
2021-04-09T16:54:58.757877
2018-04-17T19:55:35
2018-04-17T19:55:35
125,872,908
0
0
null
null
null
null
UTF-8
C++
false
false
953
h
MyImage.h
#ifndef MYIMAGE_H #define MYIMAGE_H #include <wx/wxprec.h> #ifndef WX_PRECOMP #include <wx/wx.h> #include <stdlib.h> #endif class MyImage : public wxImage { public: MyImage(const wxString& fileName); MyImage(wxImage image); MyImage(int largeur, int hauteur); MyImage(); void negative(); void Desaturate(); void Threshold(int seuil); void Mirroir(bool horiz = true); MyImage* Rotation90(); void posterize(); int histogramme(); void Trame(); int recupSeuil(int xCase,int yCase); virtual ~MyImage(); inline void GetPixel(unsigned char* data, int width, int height, int x,int y, unsigned char& r,unsigned char& g,unsigned char& b); inline void SetPixel(unsigned char* data, int width, int height, int x, int y, unsigned char& r,unsigned char& g,unsigned char& b); protected: private: }; #endif // MYIMAGE_H
de5c148227898f02719294cf6525ccb2b17c66f8
2098d9206e87d3e00da9368e9db4e1643600c198
/util/time.h
50a3c59e2e83413f37db73ea061ca070594032ac
[ "MIT" ]
permissive
wtliu/motor_sim
791670ac4c64738aea3bab051036966ce0c2fee2
62e3d5555e06b84bbc638b348595150e47fe751b
refs/heads/master
2022-12-16T21:39:31.770143
2020-09-23T16:43:46
2020-09-23T16:43:46
null
0
0
null
null
null
null
UTF-8
C++
false
false
374
h
time.h
#pragma once // increment the timer by dt // if the timer is greater than period, reset the timer and return true template <typename TScalar> inline bool periodic_timer(const TScalar period, const TScalar dt, TScalar* timer) { *timer += dt; if (*timer >= period) { *timer -= period; return true; } return false; }
1cea4d0bd2bcd0c01998108af496160d5ee48963
29e67a7175da3c0f558dfc8697ef21c2a98879e5
/CSS343Project4/customer.cpp
2283067fb5889fa3a6e83cd87d1486d3af4d6866
[]
no_license
stephen1994/UW-CSS-Projects
a859f68a1613a69515db6ebab7db72cfddd04e02
e27084eee38db724f59f6f7dd2e0520f6810934e
refs/heads/master
2022-08-03T09:50:04.724903
2020-05-21T06:25:52
2020-05-21T06:25:52
264,371,581
1
0
null
null
null
null
UTF-8
C++
false
false
5,880
cpp
customer.cpp
// ---------------------------customer.cpp------------------------------------- // Can Tosun and Stephen Choi CSS 343 C // 03/03/2020 // 03/14/2020 - Date of Last Modification // ---------------------------------------------------------------------------- // Purpose - This project initialize the contents of the inventory from a // file(data4movies.txt), the customer list from another file(data4customers.txt), // and then process an arbitrary sequence of commands from a third file(data4commands.txt). // ---------------------------------------------------------------------------- #include "customer.h" //========================Customer()=============================== // Description: Default contructor. // Preconditions: none // Postconditions: reserving set size of vector and assigning the variables //==================================================================== Customer::Customer() : id(-1), firstName(""), lastName("") { tranHistory.reserve(5); } //end constructor //========================Customer() constructor ========================== // Description: Istream setting data constructor. // Preconditions: file is not empty and valid // Postconditions: setting the data //==================================================================== Customer::Customer(istream& readFile) { setData(readFile); } //end constructor //========================Customer() copy constructor ========================== // Description: copy right side to into this one(new customer) // Preconditions: file is not empty and valid // Postconditions: copying the data //==================================================================== Customer::Customer(const Customer& rightSide) { id = rightSide.id; firstName = rightSide.firstName; lastName = rightSide.lastName; } //end copy Constructor //========================Customer() destructor ========================== // Description: Destructor for the customer // Preconditions: No precondition // Postconditions: destruct the customer object //==================================================================== Customer::~Customer() { } //end destructor //========================setData========================== // Description: setting the data to customer from reading the file // Preconditions: file must be valid // Postconditions: getting the data from file and set it to variables //==================================================================== void Customer::setData(istream& readFile) { //get the id readFile >> id; if (readFile.eof()) { return; } //get the lastname readFile.get(); readFile >> lastName; //get the firstname readFile.get(); readFile >> firstName; } //end setData //========================display Customer History======================= // Description: displaying customer history // Preconditions: none // Postconditions: outputs the history vector for specified customer //==================================================================== void Customer::displayCustomerHistory() const { //customer id name lastname cout << " **** Customer: " << id << " " << lastName << ", " << firstName << endl; int size = tranHistory.size(); if (size > 0) { //display the transaction history for (int i = 0; i < size; i++) { tranHistory[i].display(); tranHistory[i].getTitle()->display(); } cout << endl; } else { //otherwise print out error message cout << "No Transactions for Customer" << endl; } cout << endl; } //end displayCustomerHistory //========================add transaction ======================= // Description: adding a transaction to the customer's history // Preconditions: none // Postconditions: adding a transaction to the customer's history //==================================================================== void Customer::addTransaction(Transaction trans) { tranHistory.push_back(trans); } //end addTransaction //========================display================================ // Description // display: Function to call displayCustomerHistory // predonditions: No preconditions // postconditions: Display the customer history // ==================================================================== void Customer::display() const { displayCustomerHistory(); } //end display //all getters in one description //========================getters implementation ========================== // Description: accesing the private data under control // Preconditions: none // Postconditions: return the value of customerid, firstname and lastname //==================================================================== int Customer::getCustomerID() const { return id; } string Customer::getFirstName() const { return firstName; } string Customer::getLastName() const { return lastName; } //end getters //========================Comparison operator == ========================== // Description: testing left side and right side is equal or not // Preconditions: none // Postconditions: return true if equal, false otherwise //==================================================================== bool Customer::operator==(const Customer& rightSide) const { return (id == rightSide.id); } //end operator== //========================Comparison operator != ========================== // Description: testing left side and right side is equal or not // Preconditions: none // Postconditions: return true if not equal, false otherwise //==================================================================== bool Customer::operator!=(const Customer& rightSide) const { return (id != rightSide.id); } //end operator!=
8b9d308230506cc28733adea4d3476ca51a39454
ed9d434b634bbc7ba9d96ae0d017fedafcbdeafb
/src/L0/SU3/Vector.h
6120da1ba698a732aa0a590afb1f57e85e0ab50a
[]
no_license
duuucccan23/ahmidas
138f63a6c16ee049e2e7f9f246d5528213a43714
bc0ba6c5420fbc886170945ce100264f0ecc6f80
refs/heads/master
2021-01-10T12:23:15.700484
2012-02-16T13:01:11
2012-02-16T13:01:11
48,803,724
0
0
null
null
null
null
UTF-8
C++
false
false
1,432
h
Vector.h
#pragma once #include <L0/SU3/Tensor.h> namespace SU3 { template <> class Tensor< 1 > { std::complex< double > d_data[3]; // Some useful constant matrices static const Tensor< 1 > s_zero; public: Tensor(); Tensor(double const *data); Tensor(std::complex< double > const *data); Tensor(Tensor< 1 > const &other); Tensor &operator=(Tensor< 1 > const &other); void setToRandom(); void setToZero(); static Tensor< 1 > random(); static Tensor< 1 > const &zero(); ~Tensor(); friend std::ostream &operator<<(std::ostream &out, Tensor< 1 > const &vec); template< typename T > Tensor< 1 > &operator+=(T const &rhand); template< typename T > Tensor< 1 > &operator-=(T const &rhand); template< typename T > Tensor< 1 > &operator*=(T const &rhand); template< typename T > Tensor< 1 > &operator/=(T const &rhand); void leftMultiply(Matrix const &mat); void leftMultiply(hcMatrix const &mat); std::complex< double > &operator[](short component); std::complex< double > const &operator[](short component) const; size_t size() const; }; typedef class Tensor< 1 > Vector; std::ostream &operator<<(std::ostream &out, Vector const &vec); std::complex< double > innerProduct(Vector const &left, Vector const &right); } #include "Vector/Vector.inlines"
82742db9f587ae2a7e217611f89d890fc06108e1
26868da0803802edef8bf88747261dd768091b8a
/ACM/BOJ1039.cpp
c44ea21dc283a37165a180ea9b195288657ea3e1
[]
no_license
zhming0/Mingorithm
4f10ad1b33e474f6461e47949ed930363e838a6d
f0e6bf190a9a5f0701eefbcbf9ec5aeac492e355
refs/heads/master
2020-05-27T19:16:53.260899
2012-03-13T06:48:04
2012-03-13T06:48:04
null
0
0
null
null
null
null
UTF-8
C++
false
false
992
cpp
BOJ1039.cpp
#include<cstring> #include<cstdio> #include <iostream> using namespace std; char grid[110][110]; bool vst[110][110]; int main (int argc, const char * argv[]) { int n,m; while (~scanf("%d %d",&n, &m)) { int ret=0; for (int i=0; i<n; i++) for (int j=0; j<m; j++) scanf("%c", &grid[i][j]); memset(vst, false, sizeof(vst)); for (int i=0; i<n; i++) { for (int j=0; j<m; j++) { if (grid[i][j]=='#'&&!vst[i][j]) { ret++; vst[i][j]=true; if(j<m-1&&grid[i][j+1]=='#'){ vst[i][j+1]=true; //continue; } if (i<n-1&&grid[i+1][j]=='#') { vst[i+1][j]=true; //continue; } } } } printf("%d", ret); } return 0; }
8aaa7090b2c1597c27234f53234e2ae1066ac078
0eff74b05b60098333ad66cf801bdd93becc9ea4
/second/download/httpd/gumtree/httpd_new_log_7732.cpp
40fdd9e432aed78f5d887e99e295b3df730c3f60
[]
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
237
cpp
httpd_new_log_7732.cpp
ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02577) "Init: SSLPassPhraseDialog builtin is not " "supported on Win32 (key file " "%s)", ppcb_arg.pkey_file);
06eb1245d57cee139a7b495e09ac4f7ebff872da
4bea57e631734f8cb1c230f521fd523a63c1ff23
/projects/openfoam/rarefied-flows/impingment/sims/test/nozzle1/0.02/grad(T)
33b1d893c1a5ecf1bfdf47ac7e7bfeb19615a154
[]
no_license
andytorrestb/cfal
76217f77dd43474f6b0a7eb430887e8775b78d7f
730fb66a3070ccb3e0c52c03417e3b09140f3605
refs/heads/master
2023-07-04T01:22:01.990628
2021-08-01T15:36:17
2021-08-01T15:36:17
294,183,829
1
0
null
null
null
null
UTF-8
C++
false
false
41,132
grad(T)
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: v1912 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volVectorField; location "0.02"; object grad(T); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 -1 0 1 0 0 0]; internalField nonuniform List<vector> 1900 ( (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -2.1684e-15 0) (0 0 0) (0 -2.1684e-15 0) (0 0 0) (0 0 0) (0 -2.1684e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (2.1684e-15 0 0) (0 2.1684e-15 0) (-2.1684e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (2.1684e-15 0 0) (0 0 0) (-2.1684e-15 0 0) (2.1684e-15 0 0) (-2.1684e-15 0 0) (0 0 0) (0 0 0) (0 2.1684e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 -2.1684e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (2.1684e-15 0 0) (-2.1684e-15 0 0) (2.1684e-15 0 0) (-2.1684e-15 2.1684e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (2.9462e-15 0 9.82067e-16) (-3.56645e-15 0 -1.18882e-15) (1.50584e-15 -3.01167e-15 -1.50584e-15) (0 0 0) (-1.06161e-12 -6.45358e-15 -6.45358e-15) (-2.45517e-16 0 9.82067e-16) (-2.97205e-16 0 1.18882e-15) (3.76459e-16 3.01167e-15 1.50584e-15) (-2.56677e-15 0 0) (-9.3577e-14 -6.45358e-15 0) (2.45517e-16 0 0) (2.97205e-16 0 0) (-1.8823e-15 0 0) (5.13353e-16 0 0) (-1.6134e-14 0 0) (-2.45517e-15 0 9.82067e-16) (2.37764e-15 0 1.18882e-15) (2.25875e-15 0 1.50584e-15) (-3.08012e-15 0 0) (-8.71234e-14 1.29072e-14 0) (0 0 -2.9462e-15) (-1.18882e-15 0 -1.18882e-15) (0 0 -1.50584e-15) (4.10683e-15 0 -4.10683e-15) (-1.04225e-12 1.93608e-14 6.45358e-15) (-6.49057e-11 4.48465e-12 2.73788e-15) (2.08757e-09 1.91519e-10 -2.31667e-15) (2.2429e-05 -1.67832e-09 0) (0.000799784 -5.06028e-05 1.77158e-15) (0.00019337 -0.00172582 -7.92656e-16) (-6.22663e-12 4.84058e-12 -1.36894e-15) (1.49321e-09 2.0788e-10 1.15834e-15) (2.46499e-06 -3.76495e-09 0) (4.39482e-05 -5.66829e-05 -1.10723e-15) (-9.34551e-05 -0.00182994 1.98137e-16) (-1.50943e-12 1.09515e-14 0) (7.4915e-10 -4.63334e-15 0) (6.63545e-08 2.81089e-14 0) (1.6845e-06 -1.77157e-14 4.42893e-16) (-4.25554e-06 -6.34036e-14 -3.96274e-16) (-6.22834e-12 -4.8132e-12 -1.36894e-15) (1.49322e-09 -2.07847e-10 1.15834e-15) (2.46499e-06 3.76498e-09 0) (4.39482e-05 5.66829e-05 -1.10723e-15) (-9.34551e-05 0.00182994 1.98137e-16) (-6.49022e-11 -4.45728e-12 1.36894e-15) (2.08756e-09 -1.91487e-10 -5.76699e-27) (2.2429e-05 1.6783e-09 0) (0.000799784 5.06028e-05 -1.52399e-21) (0.00019337 0.00172582 7.92656e-16) (-0.00120798 0.00646316 0) (-0.000192547 0.00810033 0) (0.000628824 0.000207583 0) (1.78442e-05 1.5638e-07 0) (1.46759e-08 2.23149e-12 0) (2.2374e-13 0 0) (0 3.94255e-15 0) (0 -3.94255e-15 0) (0 0 0) (0 -3.94255e-15 0) (0 0 0) (0 3.94255e-15 0) (0 -3.94255e-15 0) (0 0 0) (1.97128e-15 -3.94255e-15 0) (-1.97128e-15 0 0) (0 0 0) (1.97128e-15 0 0) (9.85638e-16 -1.18277e-14 0) (-2.95692e-15 7.88511e-15 0) (0 -3.94255e-15 0) (0 3.94255e-15 0) (1.97128e-15 0 0) (9.85638e-16 -1.18277e-14 0) (-2.95692e-15 7.88511e-15 0) (0 -3.94255e-15 0) (0 0 0) (0 0 0) (0 -3.94255e-15 0) (0 -3.94255e-15 0) (0 -3.94255e-15 0) (0 0 0) (0 0 0) (0 0 0) (-1.21726e-12 0 0) (-8.61456e-08 -2.75979e-14 0) (-0.000115842 4.33681e-14 0) (-0.00458343 3.5483e-14 0) (-0.00445008 -3.94255e-15 0) (1.75912e-05 -1.97128e-14 0) (-5.15172e-05 -0.000600085 0) (-1.6268e-05 0.00216034 0) (1.83914e-05 6.13279e-05 0) (5.98195e-07 5.03788e-08 0) (5.40308e-10 7.64855e-13 0) (8.87075e-15 0 0) (0 0 0) (-1.97128e-15 0 0) (0 0 0) (0 3.94255e-15 0) (1.97128e-15 0 0) (0 0 0) (-1.97128e-15 0 0) (0 0 0) (0 3.94255e-15 0) (0 0 0) (0 0 0) (0 0 0) (1.97128e-15 -3.94255e-15 0) (0 -7.88511e-15 0) (0 0 0) (0 0 0) (-1.97128e-15 0 0) (1.97128e-15 -3.94255e-15 0) (0 -7.88511e-15 0) (-1.97128e-15 3.94255e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.22219e-12 0 0) (-8.61456e-08 -1.97128e-14 0) (-0.000115842 5.12532e-14 0) (-0.00458343 2.36553e-14 0) (-0.00445008 -1.97128e-14 0) (1.75912e-05 -3.94255e-15 0) (-1.8496e-06 1.97128e-14 0) (-1.36364e-07 -3.94255e-15 0) (3.75375e-07 -7.88511e-15 0) (3.34345e-09 1.97128e-14 0) (2.02194e-11 -3.94255e-15 0) (1.97128e-15 0 0) (0 -3.94255e-15 0) (0 0 0) (0 0 0) (1.97128e-15 0 0) (-1.97128e-15 0 0) (0 -3.94255e-15 0) (0 0 0) (0 0 0) (1.97128e-15 0 0) (-1.97128e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -3.94255e-15 0) (0 0 0) (0 -3.94255e-15 0) (0 -3.94255e-15 0) (0 0 0) (1.97128e-15 -3.94255e-15 0) (0 0 0) (-1.97128e-15 0 0) (0 -3.94255e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -3.94255e-15 0) (0 0 0) (-1.22219e-12 0 0) (-8.61456e-08 0 0) (-0.000115842 -5.51957e-14 0) (-0.00458343 3.15404e-14 0) (-0.00445008 3.94255e-15 0) (1.75912e-05 7.88511e-15 0) (-5.15172e-05 0.000600085 0) (-1.6268e-05 -0.00216034 0) (1.83914e-05 -6.13279e-05 0) (5.98195e-07 -5.03787e-08 0) (5.40302e-10 -7.7274e-13 0) (6.89947e-15 0 0) (1.97128e-15 0 0) (-1.97128e-15 3.94255e-15 0) (0 0 0) (0 -3.94255e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -3.94255e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.97128e-15 0 0) (0 -3.94255e-15 0) (1.97128e-15 0 0) (0 0 0) (0 -3.94255e-15 0) (-1.97128e-15 0 0) (0 -3.94255e-15 0) (1.97128e-15 0 0) (0 0 0) (0 0 0) (-1.97128e-15 0 0) (0 -3.94255e-15 0) (1.97128e-15 0 0) (-1.22219e-12 0 0) (-8.61456e-08 1.97128e-14 0) (-0.000115842 -7.88511e-14 0) (-0.00458343 -7.88511e-15 0) (-0.00445008 1.97128e-14 0) (1.75912e-05 -1.18277e-14 0) (-0.00120798 -0.00646316 0) (-0.000192547 -0.00810033 0) (0.000628824 -0.000207583 0) (1.78442e-05 -1.5638e-07 0) (1.46759e-08 -2.24726e-12 0) (2.26697e-13 0 0) (0 0 0) (0 0 0) (0 0 0) (0 3.94255e-15 0) (0 0 0) (0 0 0) (0 3.94255e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (1.97128e-15 3.94255e-15 0) (-1.97128e-15 0 0) (0 0 0) (0 7.88511e-15 0) (0 0 0) (1.97128e-15 3.94255e-15 0) (-1.97128e-15 0 0) (0 0 0) (0 7.88511e-15 0) (0 0 0) (0 3.94255e-15 0) (0 0 0) (0 0 0) (0 7.88511e-15 0) (0 0 0) (-1.21726e-12 0 0) (-8.61456e-08 2.36553e-14 0) (-0.000115842 -3.94255e-15 0) (-0.00458343 -5.51957e-14 0) (-0.00445008 -3.94255e-15 0) (1.75912e-05 0 0) (-0.000171302 -0.00736606 0) (0.00411151 -0.00619873 0) (0.00439359 -0.000153456 0) (0.000110869 -1.11788e-07 0) (8.22889e-08 -1.54251e-12 0) (1.16283e-12 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (-1.21401e-12 0 0) (-8.61456e-08 0 0) (-0.000115842 -2.38041e-15 0) (-0.00458343 -3.57061e-15 0) (-0.00445008 -1.1902e-15 0) (1.75912e-05 1.42825e-14 0) (-1.76908e-05 -0.000356512 0) (0.0044498 -0.000197001 0) (0.00458325 -5.16084e-06 0) (0.000115837 -4.0022e-09 0) (8.61421e-08 -5.35592e-14 0) (1.21163e-12 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (-1.21877e-12 0 0) (-8.61456e-08 -8.33143e-15 0) (-0.000115842 7.14123e-15 0) (-0.00458343 1.07118e-14 0) (-0.00445008 4.76082e-15 0) (1.75912e-05 -2.38041e-15 0) (-1.75911e-05 -2.91505e-07 0) (0.00445008 -1.88044e-07 0) (0.00458343 -4.59335e-09 0) (0.000115842 -3.64798e-12 0) (8.61456e-08 -3.57061e-15 0) (1.21282e-12 0 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (1.1902e-15 1.1902e-15 0) (0 -1.1902e-15 0) (0 1.1902e-15 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (1.1902e-15 1.1902e-15 0) (0 0 0) (-1.1902e-15 1.1902e-15 0) (-1.22115e-12 0 0) (-8.61456e-08 -1.07118e-14 0) (-0.000115842 1.07118e-14 0) (-0.00458343 -2.38041e-15 0) (-0.00445008 1.1902e-15 0) (1.75912e-05 -4.76082e-15 0) (-1.75912e-05 -2.74818e-12 0) (0.00445008 -3.55276e-12 0) (0.00458343 -1.05928e-13 0) (0.000115842 2.38041e-15 0) (8.61456e-08 -1.07118e-14 0) (1.21401e-12 0 0) (0 1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (-1.22948e-12 -1.1902e-15 0) (-8.61456e-08 8.33143e-15 0) (-0.000115842 1.66629e-14 0) (-0.00458343 -8.33143e-15 0) (-0.00445008 -7.14123e-15 0) (1.75912e-05 -1.1902e-15 0) (-1.75912e-05 -1.1902e-15 0) (0.00445008 1.78531e-14 0) (0.00458343 4.76082e-15 0) (0.000115842 -8.33143e-15 0) (8.61456e-08 -2.38041e-15 0) (1.22591e-12 0 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (1.1902e-15 1.1902e-15 0) (-1.1902e-15 0 0) (1.1902e-15 -1.1902e-15 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.1902e-15 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (0 0 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.1902e-15 0 0) (-1.21282e-12 0 0) (-8.61456e-08 9.52164e-15 0) (-0.000115842 -5.95102e-15 0) (-0.00458343 0 0) (-0.00445008 0 0) (1.75912e-05 -8.33143e-15 0) (-1.75912e-05 2.38041e-15 0) (0.00445008 4.76082e-15 0) (0.00458343 1.78531e-14 0) (0.000115842 0 0) (8.61456e-08 -1.1902e-15 0) (1.21639e-12 0 0) (0 0 0) (0 1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (-1.21996e-12 1.1902e-15 0) (-8.61456e-08 1.1902e-15 0) (-0.000115842 -3.57061e-15 0) (-0.00458343 9.52164e-15 0) (-0.00445008 9.52164e-15 0) (1.75912e-05 2.38041e-15 0) (-1.75912e-05 -1.1902e-15 0) (0.00445008 -9.52164e-15 0) (0.00458343 -4.76082e-15 0) (0.000115842 0 0) (8.61456e-08 4.76082e-15 0) (1.2271e-12 0 0) (0 1.1902e-15 0) (0 0 0) (0 1.1902e-15 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 -1.1902e-15 0) (-1.21163e-12 0 0) (-8.61456e-08 8.33143e-15 0) (-0.000115842 4.76082e-15 0) (-0.00458343 0 0) (-0.00445008 0 0) (1.75912e-05 8.33143e-15 0) (-1.75912e-05 -1.1902e-15 0) (0.00445008 5.95102e-15 0) (0.00458343 -2.38041e-15 0) (0.000115842 -1.07118e-14 0) (8.61456e-08 1.66629e-14 0) (1.21163e-12 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (1.1902e-15 -1.1902e-15 0) (-1.1902e-15 0 0) (1.1902e-15 1.1902e-15 0) (0 0 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21163e-12 0 0) (-8.61456e-08 -8.33143e-15 0) (-0.000115842 -1.30923e-14 0) (-0.00458343 -1.42825e-14 0) (-0.00445008 -1.07118e-14 0) (1.75912e-05 -2.38041e-15 0) (-1.75912e-05 9.52164e-15 0) (0.00445008 1.1902e-15 0) (0.00458343 0 0) (0.000115842 1.1902e-14 0) (8.61456e-08 -1.66629e-14 0) (1.21163e-12 0 0) (0 -1.1902e-15 0) (0 0 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (0 0 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21877e-12 0 0) (-8.61456e-08 -5.95102e-15 0) (-0.000115842 2.38041e-15 0) (-0.00458343 -3.57061e-15 0) (-0.00445008 1.1902e-15 0) (1.75912e-05 1.1902e-15 0) (-1.75912e-05 -5.95102e-15 0) (0.00445008 -5.95102e-15 0) (0.00458343 -1.1902e-15 0) (0.000115842 1.07118e-14 0) (8.61456e-08 0 0) (1.2271e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.1902e-15 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (0 -1.1902e-15 0) (-1.1902e-15 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (-1.21639e-12 0 0) (-8.61456e-08 5.95102e-15 0) (-0.000115842 -8.33143e-15 0) (-0.00458343 0 0) (-0.00445008 8.33143e-15 0) (1.75912e-05 3.57061e-15 0) (-1.75912e-05 2.38041e-15 0) (0.00445008 1.1902e-15 0) (0.00458343 1.1902e-15 0) (0.000115842 2.38041e-15 0) (8.61456e-08 1.66629e-14 0) (1.21163e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21401e-12 0 0) (-8.61456e-08 5.95102e-15 0) (-0.000115842 -2.38041e-15 0) (-0.00458343 1.1902e-15 0) (-0.00445008 4.76082e-15 0) (1.75912e-05 -2.38041e-15 0) (-1.75912e-05 1.42825e-14 0) (0.00445008 -7.14123e-15 0) (0.00458343 -1.1902e-15 0) (0.000115842 -3.57061e-15 0) (8.61456e-08 4.76082e-15 0) (1.21163e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.1902e-15 -1.1902e-15 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21163e-12 0 0) (-8.61456e-08 -3.57061e-15 0) (-0.000115842 1.42825e-14 0) (-0.00458343 7.14123e-15 0) (-0.00445008 0 0) (1.75912e-05 -8.33143e-15 0) (-1.75912e-05 -1.1902e-15 0) (0.00445008 -1.07118e-14 0) (0.00458343 4.76082e-15 0) (0.000115842 3.57061e-15 0) (8.61456e-08 -1.1902e-15 0) (1.20687e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21877e-12 0 0) (-8.61456e-08 -3.57061e-15 0) (-0.000115842 -1.07118e-14 0) (-0.00458343 -8.33143e-15 0) (-0.00445008 -5.95102e-15 0) (1.75912e-05 3.57061e-15 0) (-1.75912e-05 0 0) (0.00445008 1.54727e-14 0) (0.00458343 -5.95102e-15 0) (0.000115842 -1.1902e-14 0) (8.61456e-08 -1.07118e-14 0) (1.21163e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (-1.21401e-12 0 0) (-8.61456e-08 0 0) (-0.000115842 -2.38041e-15 0) (-0.00458343 -1.07118e-14 0) (-0.00445008 -1.07118e-14 0) (1.75912e-05 3.57061e-15 0) (-1.75912e-05 -1.67819e-12 0) (0.00445008 -1.65796e-12 0) (0.00458343 -1.68295e-12 0) (0.000115842 -1.67343e-12 0) (8.61456e-08 -1.67462e-12 0) (1.21877e-12 -1.677e-12 0) (0 -1.66986e-12 0) (0 -1.67581e-12 0) (0 -1.677e-12 0) (-1.1902e-15 -1.68295e-12 0) (0 -1.67581e-12 0) (1.1902e-15 -1.67462e-12 0) (0 -1.67581e-12 0) (-1.1902e-15 -1.67462e-12 0) (0 -1.68176e-12 0) (1.1902e-15 -1.67462e-12 0) (0 -1.67343e-12 0) (0 -1.67938e-12 0) (-2.38041e-15 -1.66986e-12 0) (0 -1.68295e-12 0) (0 -1.677e-12 0) (1.1902e-15 -1.68176e-12 0) (1.1902e-15 -1.66986e-12 0) (-1.1902e-15 -1.66986e-12 0) (-1.1902e-15 -1.68295e-12 0) (0 -1.677e-12 0) (1.1902e-15 -1.68295e-12 0) (0 -1.677e-12 0) (0 -1.67581e-12 0) (0 -1.68295e-12 0) (-1.1902e-15 -1.67581e-12 0) (1.1902e-15 -1.67938e-12 0) (0 -1.677e-12 0) (0 -1.68295e-12 0) (-1.21758e-12 -1.68057e-12 0) (-8.61456e-08 -1.68295e-12 0) (-0.000115842 -1.66034e-12 0) (-0.00458343 -1.65796e-12 0) (-0.00445008 -1.66986e-12 0) (1.75912e-05 -1.67224e-12 0) (-1.75912e-05 -1.07644e-07 0) (0.00445008 -1.07711e-07 0) (0.00458343 -1.07883e-07 0) (0.000115842 -1.07888e-07 0) (8.61456e-08 -1.07888e-07 0) (1.2152e-12 -1.07888e-07 0) (1.1902e-15 -1.07888e-07 0) (-8.33143e-15 -1.07888e-07 0) (-4.76082e-15 -1.07888e-07 0) (0 -1.07888e-07 0) (7.14123e-15 -1.07888e-07 0) (1.1902e-15 -1.07888e-07 0) (-1.1902e-15 -1.07888e-07 0) (-4.76082e-15 -1.07888e-07 0) (0 -1.07888e-07 0) (9.52164e-15 -1.07888e-07 0) (-5.95102e-15 -1.07888e-07 0) (3.57061e-15 -1.07888e-07 0) (-2.38041e-15 -1.07888e-07 0) (-7.14123e-15 -1.07888e-07 0) (1.1902e-15 -1.07888e-07 0) (5.95102e-15 -1.07888e-07 0) (1.1902e-14 -1.07888e-07 0) (-1.1902e-14 -1.07888e-07 0) (-7.14123e-15 -1.07888e-07 0) (0 -1.07888e-07 0) (0 -1.07888e-07 0) (4.76082e-15 -1.07888e-07 0) (-3.57061e-15 -1.07888e-07 0) (0 -1.07888e-07 0) (3.57061e-15 -1.07888e-07 0) (-1.1902e-15 -1.07888e-07 0) (-3.57061e-15 -1.07888e-07 0) (-4.76082e-15 -1.07888e-07 0) (-1.21401e-12 -1.07888e-07 0) (-8.61456e-08 -1.07888e-07 0) (-0.000115842 -1.07888e-07 0) (-0.00458343 -1.07883e-07 0) (-0.00445008 -1.07711e-07 0) (1.75912e-05 -1.07644e-07 0) (-1.75912e-05 -0.000134121 0) (0.00445008 -0.000134106 0) (0.00458343 -0.000134268 0) (0.000115842 -0.000134274 0) (8.61456e-08 -0.000134274 0) (1.22353e-12 -0.000134274 0) (-4.76082e-15 -0.000134274 0) (-1.1902e-15 -0.000134274 0) (4.76082e-15 -0.000134274 0) (-2.38041e-15 -0.000134274 0) (3.57061e-15 -0.000134274 0) (-5.95102e-15 -0.000134274 0) (-7.14123e-15 -0.000134274 0) (4.76082e-15 -0.000134274 0) (0 -0.000134274 0) (-4.76082e-15 -0.000134274 0) (-2.38041e-15 -0.000134274 0) (1.1902e-15 -0.000134274 0) (1.1902e-15 -0.000134274 0) (0 -0.000134274 0) (0 -0.000134274 0) (5.95102e-15 -0.000134274 0) (9.52164e-15 -0.000134274 0) (3.57061e-15 -0.000134274 0) (-2.38041e-15 -0.000134274 0) (-5.95102e-15 -0.000134274 0) (2.38041e-15 -0.000134274 0) (0 -0.000134274 0) (-7.14123e-15 -0.000134274 0) (-3.57061e-15 -0.000134274 0) (-2.38041e-15 -0.000134274 0) (4.76082e-15 -0.000134274 0) (-2.38041e-15 -0.000134274 0) (1.1902e-15 -0.000134274 0) (-1.21639e-12 -0.000134274 0) (-8.61456e-08 -0.000134274 0) (-0.000115842 -0.000134274 0) (-0.00458343 -0.000134268 0) (-0.00445008 -0.000134106 0) (1.75912e-05 -0.000134121 0) (-1.75765e-05 -0.00510001 0) (0.00444994 -0.0050998 0) (0.00458327 -0.00510882 0) (0.000115837 -0.00510898 0) (8.61409e-08 -0.00510898 0) (1.21758e-12 -0.00510898 0) (1.1902e-15 -0.00510898 0) (0 -0.00510898 0) (-5.95102e-15 -0.00510898 0) (-8.33143e-15 -0.00510898 0) (-2.38041e-15 -0.00510898 0) (2.38041e-15 -0.00510898 0) (1.42825e-14 -0.00510898 0) (1.07118e-14 -0.00510898 0) (-1.54727e-14 -0.00510898 0) (-1.42825e-14 -0.00510898 0) (-3.57061e-15 -0.00510898 0) (7.14123e-15 -0.00510898 0) (4.76082e-15 -0.00510898 0) (0 -0.00510898 0) (0 -0.00510898 0) (1.1902e-14 -0.00510898 0) (2.38041e-15 -0.00510898 0) (-1.07118e-14 -0.00510898 0) (0 -0.00510898 0) (-4.76082e-15 -0.00510898 0) (1.07118e-14 -0.00510898 0) (4.76082e-15 -0.00510898 0) (-5.95102e-15 -0.00510898 0) (-3.57061e-15 -0.00510898 0) (-5.95102e-15 -0.00510898 0) (1.1902e-14 -0.00510898 0) (-2.38041e-15 -0.00510898 0) (0 -0.00510898 0) (-1.20687e-12 -0.00510898 0) (-8.6141e-08 -0.00510898 0) (-0.000115837 -0.00510898 0) (-0.00458327 -0.00510882 0) (-0.00444994 -0.0050998 0) (1.75765e-05 -0.00510001 0) (-1.73825e-05 -0.00494399 0) (0.00444159 -0.00494349 0) (0.00457458 -0.00495213 0) (0.000115686 -0.00495227 0) (8.59935e-08 -0.00495227 0) (1.20806e-12 -0.00495227 0) (0 -0.00495227 0) (7.14123e-15 -0.00495227 0) (-5.95102e-15 -0.00495227 0) (-8.33143e-15 -0.00495227 0) (1.1902e-15 -0.00495227 0) (5.95102e-15 -0.00495227 0) (2.38041e-15 -0.00495227 0) (2.38041e-15 -0.00495227 0) (0 -0.00495227 0) (-1.07118e-14 -0.00495227 0) (5.95102e-15 -0.00495227 0) (8.33143e-15 -0.00495227 0) (1.1902e-15 -0.00495227 0) (-4.76082e-15 -0.00495227 0) (-2.38041e-15 -0.00495227 0) (-8.33143e-15 -0.00495227 0) (2.38041e-15 -0.00495227 0) (1.54727e-14 -0.00495227 0) (-5.95102e-15 -0.00495227 0) (-4.76082e-15 -0.00495227 0) (3.57061e-15 -0.00495227 0) (-2.38041e-15 -0.00495227 0) (2.38041e-15 -0.00495227 0) (0 -0.00495227 0) (0 -0.00495227 0) (-2.38041e-15 -0.00495227 0) (-4.76082e-15 -0.00495227 0) (7.14123e-15 -0.00495227 0) (-1.20568e-12 -0.00495227 0) (-8.59935e-08 -0.00495227 0) (-0.000115686 -0.00495227 0) (-0.00457458 -0.00495213 0) (-0.00444159 -0.00494349 0) (1.73825e-05 -0.00494399 0) (-1.70951e-05 2.20128e-05 0) (0.00444209 2.2311e-05 0) (0.0045748 2.25268e-05 0) (0.0001157 2.25411e-05 0) (8.59365e-08 2.25411e-05 0) (1.21163e-12 2.25411e-05 0) (8.33143e-15 2.25411e-05 0) (-2.38041e-15 2.25411e-05 0) (-1.30923e-14 2.25411e-05 0) (1.1902e-15 2.25411e-05 0) (1.1902e-15 2.25411e-05 0) (3.57061e-15 2.25411e-05 0) (2.38041e-15 2.25411e-05 0) (-1.1902e-15 2.25411e-05 0) (4.76082e-15 2.25411e-05 0) (-3.57061e-15 2.25411e-05 0) (-2.38041e-15 2.25411e-05 0) (-4.76082e-15 2.25411e-05 0) (-3.57061e-15 2.25411e-05 0) (0 2.25411e-05 0) (0 2.25411e-05 0) (1.1902e-15 2.25411e-05 0) (3.57061e-15 2.25411e-05 0) (2.38041e-15 2.25411e-05 0) (-4.76082e-15 2.25411e-05 0) (-4.76082e-15 2.25411e-05 0) (2.38041e-15 2.25411e-05 0) (0 2.25411e-05 0) (0 2.25411e-05 0) (1.1902e-15 2.25411e-05 0) (-1.1902e-15 2.25411e-05 0) (7.14123e-15 2.25411e-05 0) (2.38041e-15 2.25411e-05 0) (-4.76082e-15 2.25411e-05 0) (-1.21996e-12 2.25411e-05 0) (-8.59364e-08 2.25411e-05 0) (-0.0001157 2.25411e-05 0) (-0.0045748 2.25268e-05 0) (-0.00444209 2.2311e-05 0) (1.70951e-05 2.20128e-05 0) (-1.70951e-05 -2.20128e-05 0) (0.00444209 -2.2311e-05 0) (0.0045748 -2.25268e-05 0) (0.0001157 -2.25411e-05 0) (8.59365e-08 -2.25411e-05 0) (1.20687e-12 -2.25411e-05 0) (-2.38041e-15 -2.25411e-05 0) (0 -2.25411e-05 0) (-1.1902e-15 -2.25411e-05 0) (5.95102e-15 -2.25411e-05 0) (-3.57061e-15 -2.25411e-05 0) (-5.95102e-15 -2.25411e-05 0) (7.14123e-15 -2.25411e-05 0) (7.14123e-15 -2.25411e-05 0) (-1.1902e-15 -2.25411e-05 0) (-4.76082e-15 -2.25411e-05 0) (1.1902e-15 -2.25411e-05 0) (-1.1902e-15 -2.25411e-05 0) (3.57061e-15 -2.25411e-05 0) (1.1902e-15 -2.25411e-05 0) (-1.1902e-15 -2.25411e-05 0) (-1.1902e-15 -2.25411e-05 0) (-4.76082e-15 -2.25411e-05 0) (5.95102e-15 -2.25411e-05 0) (1.1902e-15 -2.25411e-05 0) (-3.57061e-15 -2.25411e-05 0) (2.38041e-15 -2.25411e-05 0) (0 -2.25411e-05 0) (-4.76082e-15 -2.25411e-05 0) (0 -2.25411e-05 0) (2.38041e-15 -2.25411e-05 0) (-2.38041e-15 -2.25411e-05 0) (0 -2.25411e-05 0) (2.38041e-15 -2.25411e-05 0) (-1.21044e-12 -2.25411e-05 0) (-8.59365e-08 -2.25411e-05 0) (-0.0001157 -2.25411e-05 0) (-0.0045748 -2.25268e-05 0) (-0.00444209 -2.2311e-05 0) (1.70951e-05 -2.20128e-05 0) (-1.73825e-05 0.00494399 0) (0.00444159 0.00494349 0) (0.00457458 0.00495213 0) (0.000115686 0.00495227 0) (8.59935e-08 0.00495227 0) (1.19616e-12 0.00495227 0) (1.1902e-15 0.00495227 0) (1.30923e-14 0.00495227 0) (-2.38041e-15 0.00495227 0) (-5.95102e-15 0.00495227 0) (-1.1902e-15 0.00495227 0) (4.76082e-15 0.00495227 0) (5.95102e-15 0.00495227 0) (1.1902e-15 0.00495227 0) (-7.14123e-15 0.00495227 0) (-1.42825e-14 0.00495227 0) (8.33143e-15 0.00495227 0) (1.30923e-14 0.00495227 0) (2.38041e-15 0.00495227 0) (-1.30923e-14 0.00495227 0) (-2.38041e-15 0.00495227 0) (-2.38041e-15 0.00495227 0) (1.1902e-15 0.00495227 0) (1.54727e-14 0.00495227 0) (-8.33143e-15 0.00495227 0) (0 0.00495227 0) (1.1902e-14 0.00495227 0) (-1.1902e-14 0.00495227 0) (-5.95102e-15 0.00495227 0) (4.76082e-15 0.00495227 0) (3.57061e-15 0.00495227 0) (2.38041e-15 0.00495227 0) (0 0.00495227 0) (2.38041e-15 0.00495227 0) (-1.21758e-12 0.00495227 0) (-8.59935e-08 0.00495227 0) (-0.000115686 0.00495227 0) (-0.00457458 0.00495213 0) (-0.00444159 0.00494349 0) (1.73825e-05 0.00494399 0) (-1.75765e-05 0.00510001 0) (0.00444994 0.0050998 0) (0.00458327 0.00510882 0) (0.000115837 0.00510898 0) (8.61409e-08 0.00510898 0) (1.21639e-12 0.00510898 0) (-4.76082e-15 0.00510898 0) (-7.14123e-15 0.00510898 0) (-1.1902e-15 0.00510898 0) (5.95102e-15 0.00510898 0) (0 0.00510898 0) (-7.14123e-15 0.00510898 0) (3.57061e-15 0.00510898 0) (1.1902e-15 0.00510898 0) (-7.14123e-15 0.00510898 0) (0 0.00510898 0) (7.14123e-15 0.00510898 0) (0 0.00510898 0) (-2.38041e-15 0.00510898 0) (-1.1902e-15 0.00510898 0) (5.95102e-15 0.00510898 0) (1.07118e-14 0.00510898 0) (-7.14123e-15 0.00510898 0) (-3.57061e-15 0.00510898 0) (-3.57061e-15 0.00510898 0) (-5.95102e-15 0.00510898 0) (9.52164e-15 0.00510898 0) (2.38041e-15 0.00510898 0) (-1.1902e-15 0.00510898 0) (-4.76082e-15 0.00510898 0) (-5.95102e-15 0.00510898 0) (1.54727e-14 0.00510898 0) (0 0.00510898 0) (-1.1902e-14 0.00510898 0) (-1.20687e-12 0.00510898 0) (-8.61409e-08 0.00510898 0) (-0.000115837 0.00510898 0) (-0.00458327 0.00510882 0) (-0.00444994 0.0050998 0) (1.75765e-05 0.00510001 0) (-1.75912e-05 0.000134121 0) (0.00445008 0.000134106 0) (0.00458343 0.000134268 0) (0.000115842 0.000134274 0) (8.61456e-08 0.000134274 0) (1.21401e-12 0.000134274 0) (-4.76082e-15 0.000134274 0) (-7.14123e-15 0.000134274 0) (1.1902e-14 0.000134274 0) (4.76082e-15 0.000134274 0) (-1.1902e-15 0.000134274 0) (-1.07118e-14 0.000134274 0) (-7.14123e-15 0.000134274 0) (1.1902e-14 0.000134274 0) (1.54727e-14 0.000134274 0) (-7.14123e-15 0.000134274 0) (-1.54727e-14 0.000134274 0) (1.1902e-14 0.000134274 0) (8.33143e-15 0.000134274 0) (-8.33143e-15 0.000134274 0) (0 0.000134274 0) (5.95102e-15 0.000134274 0) (4.76082e-15 0.000134274 0) (-4.76082e-15 0.000134274 0) (-8.33143e-15 0.000134274 0) (-4.76082e-15 0.000134274 0) (3.57061e-15 0.000134274 0) (4.76082e-15 0.000134274 0) (-1.1902e-14 0.000134274 0) (-3.57061e-15 0.000134274 0) (8.33143e-15 0.000134274 0) (-3.57061e-15 0.000134274 0) (-1.1902e-15 0.000134274 0) (-3.57061e-15 0.000134274 0) (-1.2152e-12 0.000134274 0) (-8.61456e-08 0.000134274 0) (-0.000115842 0.000134274 0) (-0.00458343 0.000134268 0) (-0.00445008 0.000134106 0) (1.75912e-05 0.000134121 0) (-1.75912e-05 1.07644e-07 0) (0.00445008 1.07711e-07 0) (0.00458343 1.07883e-07 0) (0.000115842 1.07888e-07 0) (8.61456e-08 1.07888e-07 0) (1.2152e-12 1.07888e-07 0) (1.1902e-15 1.07888e-07 0) (-8.33143e-15 1.07888e-07 0) (-4.76082e-15 1.07888e-07 0) (0 1.07888e-07 0) (7.14123e-15 1.07888e-07 0) (1.1902e-15 1.07888e-07 0) (0 1.07888e-07 0) (-5.95102e-15 1.07888e-07 0) (0 1.07888e-07 0) (8.33143e-15 1.07888e-07 0) (4.76082e-15 1.07888e-07 0) (3.57061e-15 1.07888e-07 0) (-1.1902e-14 1.07888e-07 0) (-5.95102e-15 1.07888e-07 0) (5.95102e-15 1.07888e-07 0) (-1.1902e-15 1.07888e-07 0) (3.57061e-15 1.07888e-07 0) (8.33143e-15 1.07888e-07 0) (-4.76082e-15 1.07888e-07 0) (3.57061e-15 1.07888e-07 0) (1.1902e-15 1.07888e-07 0) (-8.33143e-15 1.07888e-07 0) (-8.33143e-15 1.07888e-07 0) (-1.1902e-15 1.07888e-07 0) (1.1902e-14 1.07888e-07 0) (0 1.07888e-07 0) (3.57061e-15 1.07888e-07 0) (1.1902e-15 1.07888e-07 0) (-1.22948e-12 1.07888e-07 0) (-8.61456e-08 1.07888e-07 0) (-0.000115842 1.07888e-07 0) (-0.00458343 1.07883e-07 0) (-0.00445008 1.07711e-07 0) (1.75912e-05 1.07644e-07 0) (-1.75912e-05 1.67343e-12 0) (0.00445008 1.6651e-12 0) (0.00458343 1.66986e-12 0) (0.000115842 1.66748e-12 0) (8.61456e-08 1.66629e-12 0) (1.21877e-12 1.677e-12 0) (-1.1902e-15 1.66986e-12 0) (0 1.67581e-12 0) (1.1902e-15 1.677e-12 0) (0 1.68295e-12 0) (0 1.677e-12 0) (0 1.67462e-12 0) (0 1.67581e-12 0) (0 1.67462e-12 0) (-1.1902e-15 1.68295e-12 0) (0 1.67462e-12 0) (1.1902e-15 1.67462e-12 0) (0 1.66986e-12 0) (-1.1902e-15 1.66986e-12 0) (0 1.68295e-12 0) (1.1902e-15 1.67581e-12 0) (0 1.67581e-12 0) (0 1.677e-12 0) (0 1.67224e-12 0) (0 1.66986e-12 0) (0 1.67581e-12 0) (0 1.66629e-12 0) (0 1.67462e-12 0) (0 1.67581e-12 0) (0 1.68295e-12 0) (0 1.677e-12 0) (0 1.67105e-12 0) (0 1.677e-12 0) (0 1.66629e-12 0) (-1.21282e-12 1.67581e-12 0) (-8.61456e-08 1.68295e-12 0) (-0.000115842 1.66748e-12 0) (-0.00458343 1.66391e-12 0) (-0.00445008 1.67581e-12 0) (1.75912e-05 1.67105e-12 0) (-1.75912e-05 1.07118e-14 0) (0.00445008 -2.02335e-14 0) (0.00458343 4.76082e-15 0) (0.000115842 8.33143e-15 0) (8.61456e-08 -2.38041e-15 0) (1.21996e-12 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (0 1.1902e-15 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21401e-12 0 0) (-8.61456e-08 3.57061e-15 0) (-0.000115842 3.57061e-15 0) (-0.00458343 -1.07118e-14 0) (-0.00445008 1.07118e-14 0) (1.75912e-05 2.38041e-15 0) (-1.75912e-05 -9.52164e-15 0) (0.00445008 4.76082e-15 0) (0.00458343 8.33143e-15 0) (0.000115842 4.76082e-15 0) (8.61456e-08 9.52164e-15 0) (1.22115e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (0 1.1902e-15 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.20925e-12 0 0) (-8.61456e-08 -7.14123e-15 0) (-0.000115842 -7.14123e-15 0) (-0.00458343 2.38041e-15 0) (-0.00445008 1.1902e-15 0) (1.75912e-05 -3.57061e-15 0) (-1.75912e-05 -5.95102e-15 0) (0.00445008 -3.57061e-15 0) (0.00458343 -3.57061e-15 0) (0.000115842 -1.07118e-14 0) (8.61456e-08 2.38041e-15 0) (1.21163e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.1902e-15 1.1902e-15 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.22115e-12 0 0) (-8.61456e-08 -4.76082e-15 0) (-0.000115842 4.76082e-15 0) (-0.00458343 -2.38041e-15 0) (-0.00445008 8.33143e-15 0) (1.75912e-05 1.1902e-14 0) (-1.75912e-05 1.42825e-14 0) (0.00445008 4.76082e-15 0) (0.00458343 2.38041e-15 0) (0.000115842 -8.33143e-15 0) (8.61456e-08 -1.30923e-14 0) (1.21877e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21401e-12 0 0) (-8.61456e-08 3.57061e-15 0) (-0.000115842 0 0) (-0.00458343 -3.57061e-15 0) (-0.00445008 -1.07118e-14 0) (1.75912e-05 -2.38041e-15 0) (-1.75912e-05 -2.38041e-15 0) (0.00445008 1.30923e-14 0) (0.00458343 4.76082e-15 0) (0.000115842 4.76082e-15 0) (8.61456e-08 -9.52164e-15 0) (1.22353e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.1902e-15 0 0) (0 -1.1902e-15 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (-1.1902e-15 -1.1902e-15 0) (1.1902e-15 -1.1902e-15 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (0 1.1902e-15 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 1.1902e-15 0) (-1.21639e-12 0 0) (-8.61456e-08 -3.57061e-15 0) (-0.000115842 -8.33143e-15 0) (-0.00458343 9.52164e-15 0) (-0.00445008 -3.57061e-15 0) (1.75912e-05 -3.57061e-15 0) (-1.75912e-05 -1.07118e-14 0) (0.00445008 0 0) (0.00458343 -2.38041e-15 0) (0.000115842 -3.57061e-15 0) (8.61456e-08 1.30923e-14 0) (1.2271e-12 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.1902e-15 1.1902e-15 0) (0 1.1902e-15 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (-1.1902e-15 1.1902e-15 0) (1.1902e-15 1.1902e-15 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (-1.21758e-12 0 0) (-8.61456e-08 5.95102e-15 0) (-0.000115842 0 0) (-0.00458343 0 0) (-0.00445008 8.33143e-15 0) (1.75912e-05 3.57061e-15 0) (-1.75912e-05 -7.14123e-15 0) (0.00445008 -9.52164e-15 0) (0.00458343 0 0) (0.000115842 4.76082e-15 0) (8.61456e-08 0 0) (1.21163e-12 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (1.1902e-15 1.1902e-15 0) (-1.1902e-15 0 0) (1.1902e-15 0 0) (0 0 0) (-1.1902e-15 1.1902e-15 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 1.1902e-15 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (-1.21163e-12 0 0) (-8.61456e-08 1.1902e-15 0) (-0.000115842 1.1902e-15 0) (-0.00458343 3.57061e-15 0) (-0.00445008 -1.07118e-14 0) (1.75912e-05 -3.57061e-15 0) (-1.75912e-05 -7.14123e-15 0) (0.00445008 -3.57061e-15 0) (0.00458343 -8.33143e-15 0) (0.000115842 2.38041e-15 0) (8.61456e-08 -1.30923e-14 0) (1.2271e-12 0 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21639e-12 0 0) (-8.61456e-08 -7.14123e-15 0) (-0.000115842 1.1902e-15 0) (-0.00458343 2.38041e-15 0) (-0.00445008 -1.1902e-15 0) (1.75912e-05 -5.95102e-15 0) (-1.75912e-05 1.1902e-14 0) (0.00445008 5.95102e-15 0) (0.00458343 -1.1902e-15 0) (0.000115842 -3.57061e-15 0) (8.61456e-08 1.07118e-14 0) (1.22353e-12 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (-1.1902e-15 0 0) (0 1.1902e-15 0) (1.1902e-15 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.21639e-12 -1.1902e-15 0) (-8.61456e-08 5.95102e-15 0) (-0.000115842 9.52164e-15 0) (-0.00458343 5.95102e-15 0) (-0.00445008 4.76082e-15 0) (1.75912e-05 0 0) (-1.75912e-05 4.76082e-15 0) (0.00445008 -3.57061e-15 0) (0.00458343 1.30923e-14 0) (0.000115842 -8.33143e-15 0) (8.61456e-08 -5.95102e-15 0) (1.21758e-12 0 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (0 1.1902e-15 0) (0 0 0) (-1.1902e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (0 0 0) (-1.1902e-15 0 0) (0 0 0) (1.1902e-15 0 0) (0 0 0) (-1.1902e-15 0 0) (0 0 0) (1.1902e-15 0 0) (0 0 0) (0 0 0) (-1.1902e-15 0 0) (-1.21282e-12 0 0) (-8.61456e-08 2.38041e-15 0) (-0.000115842 -1.30923e-14 0) (-0.00458343 8.33143e-15 0) (-0.00445008 -1.1902e-15 0) (1.75912e-05 5.95102e-15 0) (-1.75912e-05 2.7458e-12 0) (0.00445008 3.54443e-12 0) (0.00458343 9.04556e-14 0) (0.000115842 -4.76082e-15 0) (8.61456e-08 4.76082e-15 0) (1.22829e-12 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (-1.1902e-15 0 0) (1.1902e-15 -1.1902e-15 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (1.1902e-15 1.1902e-15 0) (0 0 0) (-1.1902e-15 0 0) (0 1.1902e-15 0) (0 0 0) (1.1902e-15 0 0) (0 0 0) (-1.1902e-15 1.1902e-15 0) (-1.21401e-12 1.1902e-15 0) (-8.61456e-08 -9.52164e-15 0) (-0.000115842 -1.42825e-14 0) (-0.00458343 -1.90433e-14 0) (-0.00445008 1.1902e-15 0) (1.75912e-05 3.57061e-15 0) (-1.75911e-05 2.91505e-07 0) (0.00445008 1.88044e-07 0) (0.00458343 4.59334e-09 0) (0.000115842 3.66226e-12 0) (8.61456e-08 1.78531e-14 0) (1.21401e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 -1.1902e-15 0) (-1.22115e-12 0 0) (-8.61456e-08 -7.14123e-15 0) (-0.000115842 1.1902e-15 0) (-0.00458343 -7.14123e-15 0) (-0.00445008 5.95102e-15 0) (1.75912e-05 8.33143e-15 0) (-1.76908e-05 0.000356512 0) (0.0044498 0.000197001 0) (0.00458325 5.16084e-06 0) (0.000115837 4.0022e-09 0) (8.61421e-08 6.07004e-14 0) (1.21163e-12 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (-1.22115e-12 0 0) (-8.61456e-08 8.33143e-15 0) (-0.000115842 -7.14123e-15 0) (-0.00458343 -1.1902e-15 0) (-0.00445008 -2.38041e-15 0) (1.75912e-05 2.38041e-15 0) (-0.000171302 0.00736606 0) (0.00411151 0.00619873 0) (0.00439359 0.000153456 0) (0.000110869 1.11788e-07 0) (8.22889e-08 1.54251e-12 0) (1.1545e-12 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (0 4.76082e-15 0) (1.1902e-15 1.1902e-15 0) (-1.1902e-15 1.1902e-15 0) (0 0 0) (0 0 0) (0 4.76082e-15 0) (0 1.1902e-15 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 1.1902e-15 0) (0 1.1902e-15 0) (0 1.1902e-15 0) (0 0 0) (0 0 0) (0 0 0) (-1.21401e-12 0 0) (-8.61456e-08 4.76082e-15 0) (-0.000115842 1.54727e-14 0) (-0.00458343 -1.1902e-15 0) (-0.00445008 -1.1902e-15 0) (1.75912e-05 -9.52164e-15 0) ) ; boundaryField { inlet { type extrapolatedCalculated; value uniform (0 0 0); } outlet { type extrapolatedCalculated; value nonuniform List<vector> 165 ( (0 -0.00736606 0) (0 -0.000356512 0) (0 -2.91505e-07 0) (0 -2.74818e-12 0) (0 -1.1902e-15 0) (0 2.38041e-15 0) (0 -1.1902e-15 0) (0 -1.1902e-15 0) (0 9.52164e-15 0) (0 -5.95102e-15 0) (0 2.38041e-15 0) (0 1.42825e-14 0) (0 -1.1902e-15 0) (0 0 0) (0 -1.67819e-12 0) (0 -1.07644e-07 0) (0 -0.000134121 0) (0 -0.00510001 0) (0 -0.00494399 0) (0 2.20128e-05 0) (-1.70951e-05 0 0) (0.00444209 0 0) (0.0045748 0 0) (0.0001157 0 0) (8.59365e-08 0 0) (1.21163e-12 0 0) (8.33143e-15 0 0) (-2.38041e-15 0 0) (-1.30923e-14 0 0) (1.1902e-15 0 0) (1.1902e-15 0 0) (3.57061e-15 0 0) (2.38041e-15 0 0) (-1.1902e-15 0 0) (4.76082e-15 0 0) (-3.57061e-15 0 0) (-2.38041e-15 0 0) (-4.76082e-15 0 0) (-3.57061e-15 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (3.57061e-15 0 0) (2.38041e-15 0 0) (-4.76082e-15 0 0) (-4.76082e-15 0 0) (2.38041e-15 0 0) (0 0 0) (0 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (7.14123e-15 0 0) (2.38041e-15 0 0) (-4.76082e-15 0 0) (-1.21996e-12 0 0) (-8.59364e-08 0 0) (-0.0001157 0 0) (-0.0045748 0 0) (-0.00444209 0 0) (1.70951e-05 0 0) (0 1.42825e-14 0) (0 -2.38041e-15 0) (0 -4.76082e-15 0) (0 -1.1902e-15 0) (0 -8.33143e-15 0) (0 2.38041e-15 0) (0 8.33143e-15 0) (0 -2.38041e-15 0) (0 1.1902e-15 0) (0 3.57061e-15 0) (0 -2.38041e-15 0) (0 -8.33143e-15 0) (0 3.57061e-15 0) (0 3.57061e-15 0) (0 -1.67224e-12 0) (0 -1.07644e-07 0) (0 -0.000134121 0) (0 -0.00510001 0) (0 -0.00494399 0) (0 2.20128e-05 0) (0 -1.97128e-14 0) (0 -3.94255e-15 0) (0 7.88511e-15 0) (0 -1.18277e-14 0) (0 0 0) (0 -2.20128e-05 0) (0 0.00494399 0) (0 0.00510001 0) (0 0.000134121 0) (0 1.07644e-07 0) (0 1.67105e-12 0) (0 2.38041e-15 0) (0 -3.57061e-15 0) (0 1.1902e-14 0) (0 -2.38041e-15 0) (0 -3.57061e-15 0) (0 3.57061e-15 0) (0 -3.57061e-15 0) (0 -5.95102e-15 0) (0 0 0) (0 5.95102e-15 0) (0 3.57061e-15 0) (0 8.33143e-15 0) (0 2.38041e-15 0) (0 -9.52164e-15 0) (-1.70951e-05 0 0) (0.00444209 0 0) (0.0045748 0 0) (0.0001157 0 0) (8.59365e-08 0 0) (1.20687e-12 0 0) (-2.38041e-15 0 0) (0 0 0) (-1.1902e-15 0 0) (5.95102e-15 0 0) (-3.57061e-15 0 0) (-5.95102e-15 0 0) (7.14123e-15 0 0) (7.14123e-15 0 0) (-1.1902e-15 0 0) (-4.76082e-15 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (3.57061e-15 0 0) (1.1902e-15 0 0) (-1.1902e-15 0 0) (-1.1902e-15 0 0) (-4.76082e-15 0 0) (5.95102e-15 0 0) (1.1902e-15 0 0) (-3.57061e-15 0 0) (2.38041e-15 0 0) (0 0 0) (-4.76082e-15 0 0) (0 0 0) (2.38041e-15 0 0) (-2.38041e-15 0 0) (0 0 0) (2.38041e-15 0 0) (-1.21044e-12 0 0) (-8.59365e-08 0 0) (-0.0001157 0 0) (-0.0045748 0 0) (-0.00444209 0 0) (1.70951e-05 0 0) (0 -2.20128e-05 0) (0 0.00494399 0) (0 0.00510001 0) (0 0.000134121 0) (0 1.07644e-07 0) (0 1.67343e-12 0) (0 1.07118e-14 0) (0 -9.52164e-15 0) (0 -5.95102e-15 0) (0 1.42825e-14 0) (0 -2.38041e-15 0) (0 -1.07118e-14 0) (0 -7.14123e-15 0) (0 -7.14123e-15 0) (0 1.1902e-14 0) (0 4.76082e-15 0) (0 2.7458e-12 0) (0 2.91505e-07 0) (0 0.000356512 0) (0 0.00736606 0) ) ; } obstacle { type extrapolatedCalculated; value nonuniform List<vector> 40 ( (0 0 0) (2.1684e-15 0 0) (-2.1684e-15 0 0) (2.1684e-15 0 0) (-2.1684e-15 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (0 0 0) (2.03968e-15 1.35979e-15 9.82067e-16) (-2.46908e-15 -1.64606e-15 -1.18882e-15) (-3.47501e-16 -2.31667e-16 -1.50584e-15) (0 0 0) (-7.37943e-13 -4.91962e-13 -6.45358e-15) (-2.45714e-31 -3.68571e-31 -2.9462e-15) (-8.23028e-16 5.48685e-16 -1.18882e-15) (0 0 -1.50584e-15) (2.84319e-15 -1.89546e-15 -4.10683e-15) (-7.30496e-13 4.86997e-13 6.45358e-15) (-6.46e-11 -7.17777e-12 1.36894e-15) (2.04109e-09 2.26788e-10 6.83007e-27) (2.21557e-05 2.46174e-06 0) (0.000795584 8.83983e-05 -2.66227e-21) (0.000380431 4.22701e-05 7.92605e-16) (-6.46063e-11 7.17848e-12 2.73788e-15) (2.04109e-09 -2.26788e-10 -2.31667e-15) (2.21557e-05 -2.46174e-06 0) (0.000795584 -8.83983e-05 1.77158e-15) (0.000380431 -4.22701e-05 -7.92605e-16) ) ; } empty { type empty; } } // ************************************************************************* //
b51d1b7f2cd03a8f4ed97b6bce340806bf79ab62
e0024dd3cceebdf1e58da21b684d00d7d8c713bd
/模板/组合数+快速幂.cpp
4bca1b5d246c5d12c2cbe59f9007df6cc4443039
[]
no_license
wind641727121/ACM-cpp-code
84554f242fc296593310bc4052e78901fafe659e
793da708de46b85bb4ae6e0ec5c761c1f19751fb
refs/heads/master
2020-03-27T05:53:38.463779
2018-10-28T14:22:29
2018-10-28T14:22:29
146,060,497
0
0
null
null
null
null
UTF-8
C++
false
false
1,036
cpp
组合数+快速幂.cpp
#include<cstdio> #include<cstring> #include<cmath> #include<string> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<algorithm> using namespace std; const int mod=998244353; typedef long long ll; ll poww(ll a,ll b) { ll ans=1,base=a; while(b!=0) { if(b&1!=0) ans=(ans*base)%mod; base =(base*base)%mod; b>>=1; } return ans; } ll extend_gcd(ll a,ll b,ll &x,ll &y) { if(a==0&&b==0) return -1;//无最大公约数 if(b==0) { x=1; y=0; return a; } ll d=extend_gcd(b,a%b,y,x); y-=a/b*x; return d; } ll mod_reverse(ll a,ll n) { ll x,y; ll d=extend_gcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1; } ll c(ll m,ll n) { if(m>n) return 0; ll i,j,t1,t2,ans; t1=t2=1; for(i=n; i>=n-m+1; i--) t1=t1*i%mod; for(i=1; i<=m; i++) t2=t2*i%mod; return t1*mod_reverse(t2,mod)%mod; } int t,n,q; ll a,b,cc,d,ans;
b8ead209e6f2c55f13a0bbb24bf9624ee1430d7a
288e945732ace900035694661b076ecc1d5d29e8
/tmp.cpp
3bc64197df525afcd8fec7364b741c2db77701d0
[]
no_license
AtomicOrbital/CppSource
bf440704386cbd200f90b333a7c3c63dfee45abf
29e312fb1f9b3f1be1c4aee86db8c1942b17bcbd
refs/heads/main
2023-06-20T00:42:21.656879
2021-07-16T08:27:35
2021-07-16T08:27:35
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,512
cpp
tmp.cpp
#include<bits/stdc++.h> #define mp make_pair #define F first #define S second using namespace std; typedef long long ll; struct dat { string conf; int a; }; vector<dat> way; vector<int> a; int sum = 0; dat tinh(string s) { dat x = {s, 0}; for(char c: x.conf) if (c == '1') x.a++; return x; } void sinh(int spt,string s, int n) { if (spt>n) { way.push_back(tinh(s)); return; } for(char i = '0'; i <= '1'; i++) { sinh(spt+1, s+i, n); } } int BS(int l, int r, dat x) { if (l > r) return -1; int mid = (l+r) / 2; if (way[mid].a + x.a == sum*2 - (way[mid].a + x.a)) return mid; if (way[mid].a + x.a > sum*2 - (way[mid].a + x.a)) return BS(l, mid -1, x); return BS(mid + 1, r, x); } bool cmp(dat a, dat b) { return a.a < b.a; } void solve() { int n; cin >> n; // n chan a.resize(n); for(int i = 0; i <n; i++) { cin >> a[i]; sum += a[i]; } sinh(1, "", n/2); sort(way.begin(), way.end(), cmp); for(int i =0; i < n; i++) { cout << way[i].conf <<"--" << way[i].a << endl; } for(int i = 0; i < n; i++) if (BS(0, i-1, way[i]) != -1) { cout << "YES\n"; return; } else if (BS(i+1, n-1, way[i]) != -1) { cout << "YES\n"; return; } cout << "NO\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }
1db41af586391a0cce5e262c03932fe283941a6a
26f1bcb7031611ad636c65ceaacc43251f7f4d09
/Include/MessageLogHandlerRegex.hpp
7d4c063f830c3b808c2c29ef63f085ed5887689d
[]
no_license
ice10513/devCC
2b554a0eeb8e10c92b0b01f5bd5c64bada39d539
c5a4ea253da7e32270096563b43cc6c25906ae12
refs/heads/master
2020-03-24T03:24:25.416267
2018-07-29T15:50:39
2018-07-29T15:54:13
142,418,326
0
0
null
null
null
null
UTF-8
C++
false
false
843
hpp
MessageLogHandlerRegex.hpp
#pragma once #include <string> namespace Shb { const std::string g_respMsgNameRegex = R"(message recv (\w+_\w+Resp)\(0x[\dA-F]{1,4}\))"; const std::string g_resultStatusRegex = R"(\tmessageResult.status = (\d+))"; const std::string g_resultCauseRegex = R"(\tmessageResult.cause = (\d+))"; const std::string g_resultSpecificCauseRegex = R"(\tmessageResult.specificCause = (\d+))"; const std::string g_ueContextIdRegex = R"(\tuecContextId = (\d+))"; const std::string g_crntiRegex = R"(\tcrnti = (\d+))"; const std::string g_asnMsgIdRegex = R"(\tasnMsgId = (\w+))"; const std::string g_unorderedCommonRegex = R"(\t[\w\.]+ = (\w+))"; const std::string g_msgSentRegex = R"(message sent (\w+_\w+)\(0x[\dA-F]{1,4}\))"; const std::string g_msgRecvRegex = R"(message recv (\w+_\w+)\(0x[\dA-F]{1,4}\))"; // C++ not support (?<!Resp) } // namespace Shb
96e305c51cf2299e8c42093ace0aea150449a772
235f4eaa89b561c4b4d18f6907eb70ba10303b1c
/DequeArrays.cpp
21b12031dd1f0543283b668158b406c6c5965c29
[]
no_license
ankan-das-2001/Basic-Datastructure-For-Competitive-Programming
39c509495c3493084f17b662cedc51df3761ca8b
2902f396a01d21dd32b8fb41101e27360f69aeaf
refs/heads/master
2023-03-02T04:43:28.201127
2021-02-07T08:22:07
2021-02-07T08:22:07
336,737,375
0
0
null
null
null
null
UTF-8
C++
false
false
931
cpp
DequeArrays.cpp
#include<bits/stdc++.h> using namespace std; int main(){ //Unlike normal dynamic arrays we can insert an element to its begining and its end //Lets see this in an example below deque<int> d; d.push_back(5); //Present Array: [5] d.push_back(12); //Present Array: [5,12] d.push_front(3); //Present Array: [3,5,12] //Printing our array for(auto x:d){ cout<<x<<" "; } cout<<"\n"; //Popping our array contains from backside and front-side cout<<"Beginning element array popped out and so the array is: "; d.pop_front(); //taking out the front element //Printing our array for(auto x:d){ cout<<x<<" "; } cout<<"\n"; cout<<"Last element array popped out and so the array is: "; d.pop_back(); //taking out the last element out of the array //Printing our array for(auto x:d){ cout<<x<<" "; } }
117bdc613ee8396730c5195fb3d8ba23a9498370
bc997f47b4cffef395f0ce85d72f113ceb1466e6
/JOI/camp17_sparklers.cpp
f72445b7779989173149668a8ed243abf3eaee71
[ "LicenseRef-scancode-public-domain" ]
permissive
koosaga/olympiad
1f069dd480004c9df033b73d87004b765d77d622
fcb87b58dc8b5715b3ae2fac788bd1b7cac9bffe
refs/heads/master
2023-09-01T07:37:45.168803
2023-08-31T14:18:03
2023-08-31T14:18:03
45,691,895
246
49
null
2020-10-20T16:52:45
2015-11-06T16:01:57
C++
UTF-8
C++
false
false
1,821
cpp
camp17_sparklers.cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; using lint = long long; using pi = pair<int, int>; int n, k, a[MAXN]; int t; bool solve(vector<lint> x, vector<lint> y){ if(x[0] < y[0]) return 0; vector<int> sx = {0}, sy = {0}; for(int i=1; i<x.size(); i++){ if(x[sx.back()] <= x[i]) sx.push_back(i); } for(int i=1; i<y.size(); i++){ if(y[sy.back()] >= y[i]) sy.push_back(i); } vector<lint> prec; for(int i=0; i+1<sy.size(); i++){ prec.push_back(*max_element(y.begin() + sy[i] + 1, y.begin() + sy[i + 1] + 1)); } int cs = 0, ce = 0; for(int i=0; i<sx.size(); i++){ while(ce + 1 < sy.size()){ lint nxtmax = prec[ce]; if(nxtmax <= x[sx[i]]) ce++; else break; } if(i + 1 < sx.size()){ lint nxtmin = *min_element(x.begin() + sx[i] + 1, x.begin() + sx[i + 1] + 1); while(cs <= ce && y[sy[cs]] > nxtmin) cs++; if(cs > ce) return 0; } } return ce + 1 == sy.size(); } bool trial(int s){ lint L = min(2ll * t * s, 2ll * a[n]); vector<lint> vu, vd; for(int i=1; i<=n; i++){ if(i <= k) vu.push_back(a[i] - L * i); if(i >= k) vd.push_back(a[i] - L * i); } reverse(vu.begin(), vu.end()); int mx1 = max_element(vu.begin(), vu.end()) - vu.begin(); int mx2 = min_element(vd.begin(), vd.end()) - vd.begin(); vector<lint> u1, u2, d1, d2; for(int i=0; i<=mx1; i++) u1.push_back(vu[i]); for(int i=0; i<=mx2; i++) d1.push_back(vd[i]); for(int i=mx1; i<vu.size(); i++) u2.push_back(vu[i]); for(int i=mx2; i<vd.size(); i++) d2.push_back(vd[i]); reverse(u2.begin(), u2.end()); reverse(d2.begin(), d2.end()); return solve(u1, d1) && solve(u2, d2); } int main(){ scanf("%d %d %d",&n,&k,&t); for(int i=1; i<=n; i++) scanf("%d",&a[i]); int s = 0, e = 1e9; while(s != e){ int m = (s+e)/2; if(trial(m)) e = m; else s = m + 1; } cout << s << endl; }
c9d967677fc080f2e73e2456314c2cfd1e38631b
b206a0421b2805492cfe2c354c4ff2fb35dbb905
/实验7/EXP7.1/EXP7.1/StuScore.h
b43cb92ed76603cd4c34eb4c4e68342c14655192
[]
no_license
AhuntSun/C-CLI
48cf819ce63b2d1a07421ece860ed6d8a9252d28
d4b4105faf26cab3fcd9a7215e860e974cb2e05a
refs/heads/master
2020-11-28T16:28:46.792097
2019-12-24T04:44:33
2019-12-24T04:44:33
229,865,007
0
0
null
null
null
null
UTF-8
C++
false
false
145
h
StuScore.h
#pragma once using namespace System; ref class StuScore { public: StuScore(void); String ^strName; String ^strID; array<float>^fScore; };
52fa053b405958eb4b9528c2d21e0ef90a886b12
b6ccf9976e1a8f0cb18e76ea8280d6fe07cdd88b
/xtd.forms.native.wxwidgets/src/xtd/forms/native/wxwidgets/control.cpp
2739a7a9d82bb157c828e09447b8b7498e8ef55a
[ "MIT" ]
permissive
lineCode/xtd.forms
ec9bc039203bd8f7f4ab99b66b56a0c150340cb4
53b126a41513b4009870498b9f8e522dfc94c8de
refs/heads/master
2020-07-26T03:52:17.779555
2019-09-14T19:27:12
2019-09-14T19:27:12
208,525,716
1
0
MIT
2019-09-15T01:26:53
2019-09-15T01:26:53
null
UTF-8
C++
false
false
12,053
cpp
control.cpp
#include <map> #include <stdexcept> #include <xtd/drawing/system_colors.hpp> #include <xtd/drawing/system_fonts.hpp> #include <xtd/forms/native/application.hpp> #include <xtd/forms/native/control.hpp> #include "hdc_wrapper.hpp" #include "wx_button.hpp" #include "wx_check_box.hpp" #include "wx_control.hpp" #include "wx_form.hpp" #include "wx_group_box.hpp" #include "wx_label.hpp" #include "wx_list_box.hpp" #include "wx_panel.hpp" #include "wx_progress_bar.hpp" #include "wx_radio_button.hpp" #include "wx_text_box.hpp" #include "wx_track_bar.hpp" #include <wx/dcmemory.h> #include <wx/dcclient.h> #include <wx/dcscreen.h> #include <wx/font.h> using namespace std; using namespace xtd; using namespace xtd::drawing; using namespace xtd::forms::native; extern int32_t __mainloop_runnning__; color control::back_color(intptr_t control) { if (control == 0) return color::empty; wxColour colour = reinterpret_cast<control_handler*>(control)->control()->GetBackgroundColour(); #if defined (__WXOSX__) return color::from_handle(reinterpret_cast<intptr_t>(colour.OSXGetNSColor())); #endif return color::from_argb(colour.Alpha(), colour.Red(), colour.Green(), colour.Blue()); } void control::back_color(intptr_t control, const color& color) { if (control == 0) return; #if defined (__WXOSX__) if (color.handle()) reinterpret_cast<control_handler*>(control)->control()->SetBackgroundColour(wxColour(reinterpret_cast<WX_NSColor>(color.handle()))); else reinterpret_cast<control_handler*>(control)->control()->SetBackgroundColour(wxColour(color.r(), color.g(), color.b(), color.a())); #else reinterpret_cast<control_handler*>(control)->control()->SetBackgroundColour(wxColour(color.r(), color.g(), color.b(), color.a())); #endif } intptr_t control::create(const forms::create_params& create_params) { application::start_application(); // Must be first if (create_params.class_name() == "button") return reinterpret_cast<intptr_t>(new wx_button(create_params)); if (create_params.class_name() == "checkbox") return reinterpret_cast<intptr_t>(new wx_check_box(create_params)); if (create_params.class_name() == "form") return reinterpret_cast<intptr_t>(new wx_form(create_params)); if (create_params.class_name() == "groupbox") return reinterpret_cast<intptr_t>(new wx_group_box(create_params)); if (create_params.class_name() == "label") return reinterpret_cast<intptr_t>(new wx_label(create_params)); if (create_params.class_name() == "listbox") return reinterpret_cast<intptr_t>(new wx_list_box(create_params)); if (create_params.class_name() == "panel") return reinterpret_cast<intptr_t>(new wx_panel(create_params)); if (create_params.class_name() == "progressbar") return reinterpret_cast<intptr_t>(new wx_progress_bar(create_params)); if (create_params.class_name() == "radiobutton") return reinterpret_cast<intptr_t>(new wx_radio_button(create_params)); if (create_params.class_name() == "textbox") return reinterpret_cast<intptr_t>(new wx_text_box(create_params)); if (create_params.class_name() == "trackbar") return reinterpret_cast<intptr_t>(new wx_track_bar(create_params)); return reinterpret_cast<intptr_t>(new wx_control(create_params)); } intptr_t control::create_paint_graphics(intptr_t control) { xtd::drawing::native::hdc_wrapper* hdc_wrapper = new xtd::drawing::native::hdc_wrapper(); if (control == 0) hdc_wrapper->create<wxScreenDC>(); else hdc_wrapper->create<wxPaintDC>(reinterpret_cast<control_handler*>(control)->control()); return reinterpret_cast<intptr_t>(hdc_wrapper); } intptr_t control::create_graphics(intptr_t control) { xtd::drawing::native::hdc_wrapper* hdc_wrapper = new xtd::drawing::native::hdc_wrapper(); if (control == 0) hdc_wrapper->create<wxScreenDC>(); else hdc_wrapper->create<wxClientDC>(reinterpret_cast<control_handler*>(control)->control()); return reinterpret_cast<intptr_t>(hdc_wrapper); } intptr_t control::def_wnd_proc(intptr_t control, intptr_t hwnd, int32_t msg, intptr_t wparam, intptr_t lparam, intptr_t presult, intptr_t handle) { if (!control) return 0; switch (msg) { case WM_GETTEXTLENGTH: return (reinterpret_cast<control_handler*>(hwnd))->control()->GetLabel().ToStdString().size(); break; case WM_GETTEXT: return strlen(strncpy(reinterpret_cast<char*>(lparam), reinterpret_cast<control_handler*>(hwnd)->control()->GetLabel().ToStdString().c_str(), wparam)); break; } if (handle != 0) return reinterpret_cast<control_handler*>(control)->call_def_wnd_proc(hwnd, msg, wparam, lparam, presult, handle); return 0; } color control::default_back_color() { #if wxMAJOR_VERSION >= 3 && wxMINOR_VERSION >= 1 return system_colors::control(); #else static color default_color; if (default_color == color::empty) { native::application::start_application(); wxFrame* frame = new wxFrame(nullptr, wxID_ANY, ""); wxButton* button = new wxButton(frame, wxID_ANY, ""); wxColour colour = button->GetBackgroundColour(); #if defined (__WXOSX__) default_color = color::from_handle(reinterpret_cast<intptr_t>(colour.OSXGetNSColor())); #else default_color = color::from_argb(colour.Alpha(), colour.Red(), colour.Green(), colour.Blue()); #endif delete button; delete frame; } return default_color; #endif } color control::default_fore_color() { #if wxMAJOR_VERSION >= 3 && wxMINOR_VERSION >= 1 return system_colors::control_text(); #else static color default_color; if (default_color == color::empty) { native::application::start_application(); wxFrame* frame = new wxFrame(nullptr, wxID_ANY, ""); wxButton* button = new wxButton(frame, wxID_ANY, ""); wxColour colour = button->GetForegroundColour(); #if defined (__WXOSX__) default_color = color::from_handle(reinterpret_cast<intptr_t>(colour.OSXGetNSColor())); #else default_color = color::from_argb(colour.Alpha(), colour.Red(), colour.Green(), colour.Blue()); #endif delete button; delete frame; } return default_color; #endif } font control::default_font() { return system_fonts::default_font(); } void control::destroy(intptr_t control) { if (control == 0) return; if (reinterpret_cast<control_handler*>(control)->control() == 0) return; if (wxTheApp) { reinterpret_cast<control_handler*>(control)->destroy(); #if !defined (__WXOSX__) wxTheApp->wxEvtHandler::ProcessPendingEvents(); //if (!wxTheApp->IsMainLoopRunning()) { //application::end_application(); //application::start_application(); //} #endif } delete reinterpret_cast<class control_handler*>(control); } void control::init() { application::start_application(); // Must be first } drawing::rectangle control::client_rectangle(intptr_t control) { if (control == 0) return {}; wxRect rect = reinterpret_cast<control_handler*>(control)->control()->GetClientRect(); return {rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight()}; } drawing::size control::client_size(intptr_t control) { if (control == 0) return {}; wxSize size = reinterpret_cast<control_handler*>(control)->control()->GetClientSize(); return {size.GetWidth(), size.GetHeight()}; } void control::client_size(intptr_t control, const drawing::size& size) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->control()->SetClientSize(size.width(), size.height()); } bool control::enabled(intptr_t control) { if (control == 0) return false; return reinterpret_cast<control_handler*>(control)->control()->IsEnabled(); } void control::enabled(intptr_t control, bool enabled) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->control()->Enable(enabled); } color control::fore_color(intptr_t control) { if (control == 0) return color::empty; wxColour colour = reinterpret_cast<control_handler*>(control)->control()->GetForegroundColour(); #if defined (__WXOSX__) return color::from_handle(reinterpret_cast<intptr_t>(colour.OSXGetNSColor())); #endif return color::from_argb(colour.Alpha(), colour.Red(), colour.Green(), colour.Blue()); } void control::fore_color(intptr_t control, const color& color) { if (control == 0) return; #if defined (__WXOSX__) if (color.handle()) reinterpret_cast<control_handler*>(control)->control()->SetForegroundColour(wxColour(reinterpret_cast<WX_NSColor>(color.handle()))); else reinterpret_cast<control_handler*>(control)->control()->SetForegroundColour(wxColour(color.r(), color.g(), color.b(), color.a())); #else reinterpret_cast<control_handler*>(control)->control()->SetForegroundColour(wxColour(color.r(), color.g(), color.b(), color.a())); #endif } drawing::font control::font(intptr_t control) { return drawing::font::from_hfont(reinterpret_cast<intptr_t>(new wxFont(reinterpret_cast<control_handler*>(control)->control()->GetFont()))); } void control::font(intptr_t control, const drawing::font& font) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->control()->SetFont(*reinterpret_cast<wxFont*>(font.handle())); } point control::location(intptr_t control) { if (control == 0) return {}; wxPoint location = reinterpret_cast<control_handler*>(control)->control()->GetPosition(); return {location.x, location.y}; } void control::location(intptr_t control, const point& location) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->control()->SetPosition({location.x(), location.y()}); } intptr_t control::parent(intptr_t control) { return reinterpret_cast<intptr_t>(reinterpret_cast<control_handler*>(control)->control()->GetParent()); } void control::parent(intptr_t control, intptr_t parent) { reinterpret_cast<control_handler*>(control)->control()->Reparent(reinterpret_cast<control_handler*>(parent)->control()); } drawing::size control::size(intptr_t control) { if (control == 0) return {}; wxSize size = reinterpret_cast<control_handler*>(control)->control()->GetSize(); return {size.GetWidth(), size.GetHeight()}; } void control::size(intptr_t control, const drawing::size& size) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->SetSize(size.width(), size.height()); } string control::text(intptr_t control) { if (control == 0) return {}; //return reinterpret_cast<control_handler*>(control)->control()->GetLabel().ToStdString(); intptr_t result = send_message(control, control, WM_GETTEXTLENGTH, 0, 0); string text(result, 0); result = send_message(control, control, WM_GETTEXT, result + 1, reinterpret_cast<intptr_t>(text.data())); return text; } void control::text(intptr_t control, const string& text) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->control()->SetLabel(text); send_message(control, control, WM_SETTEXT, 0, reinterpret_cast<intptr_t>(reinterpret_cast<control_handler*>(control)->control()->GetLabel().ToStdString().c_str())); } bool control::visible(intptr_t control) { if (control == 0) return false; return reinterpret_cast<control_handler*>(control)->control()->IsShown(); } void control::visible(intptr_t control, bool visible) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->control()->Show(visible); } void control::refresh(intptr_t control) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->control()->Refresh(); } void control::register_wnd_proc(intptr_t control, const delegate<intptr_t(intptr_t, int32_t, intptr_t, intptr_t, intptr_t)>& wnd_proc) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->wnd_proc += wnd_proc; } void control::unregister_wnd_proc(intptr_t control, const delegate<intptr_t(intptr_t, int32_t, intptr_t, intptr_t, intptr_t)>& wnd_proc) { if (control == 0) return; reinterpret_cast<control_handler*>(control)->wnd_proc -= wnd_proc; } intptr_t control::send_message(intptr_t control, intptr_t hwnd, int32_t msg, intptr_t wparam, intptr_t lparam) { if (hwnd == 0) return -1; return reinterpret_cast<control_handler*>(control)->send_message(hwnd, msg, wparam, lparam, 0); }
6d72d2132939403f8bf9bbdd4d72442ce221792b
da3c59e9e54b5974648828ec76f0333728fa4f0c
/messagingappbase/ncnlist/src/CVoiceMailManager.cpp
22d9c3f171aa45861c823dda83a8b6461c911352
[]
no_license
finding-out/oss.FCL.sf.app.messaging
552a95b08cbff735d7f347a1e6af69fc427f91e8
7ecf4269c53f5b2c6a47f3596e77e2bb75c1700c
refs/heads/master
2022-01-29T12:14:56.118254
2010-11-03T20:32:03
2010-11-03T20:32:03
null
0
0
null
null
null
null
UTF-8
C++
false
false
13,993
cpp
CVoiceMailManager.cpp
/* * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: Handles the notifications for voice mail messages * : Keeps track about the number of voice mail messages * : Has support for alternative line (ALS) * */ // INCLUDE FILES #include <centralrepository.h> #include <messagingvariant.hrh> // For CR key handling local variation flags #include <centralrepository.h> // For CR key handling #include <NcnListInternalCRKeys.h> // For CR key handling #include <RSSSettings.h> // For ALS detection #include <startupdomainpskeys.h> #include <MessagingDomainCRKeys.h> #include "NcnDebug.h" #include "NcnCRHandler.h" #include "CVoiceMailManager.h" #include "CNcnNotifier.h" #include "NcnModelBase.h" #include "MNcnMsgWaitingManager.h" // ----------------------------------------------------------------- // CVoiceMailManager::NewL // ----------------------------------------------------------------- CVoiceMailManager* CVoiceMailManager::NewL( CNcnModelBase& aModel ) { CVoiceMailManager* self = new (ELeave) CVoiceMailManager( aModel ); CleanupStack::PushL( self ); self->ConstructL(); CleanupStack::Pop( self ); return self; } // ----------------------------------------------------------------- // CVoiceMailManager::~CVoiceMailManager // ----------------------------------------------------------------- CVoiceMailManager::~CVoiceMailManager() { } // ----------------------------------------------------------------- // CVoiceMailManager::CVoiceMailManager // ----------------------------------------------------------------- CVoiceMailManager::CVoiceMailManager( CNcnModelBase& aModel ) : iIsALSSupported(EFalse), iModel( aModel ) { // EMPTY } // ----------------------------------------------------------------- // CVoiceMailManager::ConstructL // ----------------------------------------------------------------- void CVoiceMailManager::ConstructL( ) { NCN_RDEBUG( _L("CVoiceMailManager : Constructing") ); //Clear soft notifications that might be drawn automatically by avkon //TSW Error TWOK-6PNT26 ClearVoiceMailSoftNotes(); //clear Voicemail indicators only when KMuiuSupressAllNotificationConfiguration(VVM) is enabled. if(CheckSupressNotificationSettingL()) { iModel.MsgWaitingManager().SetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine1, EFalse ); iModel.MsgWaitingManager().SetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine2, EFalse ); } //Get SIM change status at the startup. If the SIM will change after //boot-up we get notifed by the Model so no need to subscribe for this key //TSW ID EHCN-6NRAZE TInt simValue = 0; TInt status = RProperty::Get( KPSUidStartup, KPSSimChanged, simValue ); NCN_RDEBUG_INT2(_L("CVoiceMailManager : Requested SIM change! status: %d value: %d"), status, simValue ); //Handle SIM change in a separate method //no need to continue in constructor after this if( status == KErrNone && simValue == ESimChanged ) { NotifyAboutSIMChange(); return; } //Get the ALS status iIsALSSupported = UpdateALSStatus(); /////////////////////////////////////////////////////////////////////////////////////// // Soft notification must be drawn and the right icon triggered at the boot // if there are active voice mail messages waiting /////////////////////////////////////////////////////////////////////////////////////// } // --------------------------------------------------------- // CVoiceMailManager::VMReceived // Received a voice mail message to line 1 or 2 // --------------------------------------------------------- // void CVoiceMailManager::VMMessageReceived( MNcnMsgWaitingManager::TNcnMessageType aLineType, TUint aAmount ) { //Check the value. It must be between 0 - 254 (0xfe) or fuzzy note will be used if( aAmount > EVMMaximumNumber ) { aAmount = EVMExistsButCountNotKnown; } //The amount might be an exact value 0-254 or a special value EVMExistsButCountNotKnown iModel.MsgWaitingManager().SetMessageCount( aLineType, aAmount, EFalse ); //Update notifications UpdateVMNotifications(); } // --------------------------------------------------------- // CVoiceMailManager::NotifyAboutSIMChange() // SIM has changed so we will need to erase old notes. // Model uses this method to notify voice mail manager // We also use this in the ConstructL if we notice that // the SIM has changed in boot-up // --------------------------------------------------------- // void CVoiceMailManager::NotifyAboutSIMChange() { NCN_RDEBUG(_L("CVoiceMailManager::NotifyAboutSIMChange - SIM has changed!")); //Get the ALS status. ALS status can change if SIM changes iIsALSSupported = UpdateALSStatus(); //Update notifications UpdateVMNotifications(); } // --------------------------------------------------------- // CVoiceMailManager::HandlePropertyChangedL() // Handles the subscribed PS property changes. // --------------------------------------------------------- // void CVoiceMailManager::HandlePropertyChangedL( const TUid& /*aCategory*/, TInt /*aKey*/ ) { // Empty } // --------------------------------------------------------- // CVoiceMailManager::ClearVoiceMailSoftNotes // In boot-up Avkon automatically draws the soft notes that // were present at the time of the shut down. This is not // wanted for the voice mails so we manually null them during // the boot. // --------------------------------------------------------- // void CVoiceMailManager::ClearVoiceMailSoftNotes() { NCN_RDEBUG(_L("CVoiceMailManager::ClearVoiceMailSoftNotes") ); iModel.NcnNotifier().SetNotification( MNcnNotifier::ENcnVoiceMailNotification, 0 ); iModel.NcnNotifier().SetNotification( MNcnNotifier::ENcnVoiceMailOnLine1Notification, 0 ); iModel.NcnNotifier().SetNotification( MNcnNotifier::ENcnVoiceMailOnLine2Notification, 0 ); } // --------------------------------------------------------- // Indication message updates status only for one line at a time. // Both lines need to be updated. // --------------------------------------------------------- // void CVoiceMailManager::UpdateNoteAndIndicationWithALS( TInt aVoiceMailsInLine1, TInt aVoiceMailsInLine2 ) { //Soft notifications NCN_RDEBUG_INT(_L("CVoiceMailManager : %d voice mails in line 1 (ALS supported)"), aVoiceMailsInLine1 ); NCN_RDEBUG_INT(_L("CVoiceMailManager : %d voice mails in line 2 (ALS supported)"), aVoiceMailsInLine2 ); if(!CheckSupressNotificationSettingL()) { iModel.NcnNotifier().SetNotification( MNcnNotifier::ENcnVoiceMailOnLine1Notification, aVoiceMailsInLine1 ); iModel.NcnNotifier().SetNotification( MNcnNotifier::ENcnVoiceMailOnLine2Notification, aVoiceMailsInLine2 ); NCN_RDEBUG( _L("CVoiceMailManager: UpdateNoteAndIndicationWithALS With VVM off") ); // Indications // SysApp checks ALS support and decides whether to use o_o or O_o (left O full), if ALS supported iModel.MsgWaitingManager().SetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine1, aVoiceMailsInLine1 ? ETrue : EFalse ); iModel.MsgWaitingManager().SetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine2, aVoiceMailsInLine2 ? ETrue : EFalse ); } } // --------------------------------------------------------- // Update soft notification and trigger icon drawing to // reflect the current state of the lines // --------------------------------------------------------- // void CVoiceMailManager::UpdateVMNotifications() { //We now need a conversion from our internally held voice mail count number //to a format that is used in soft notifications. // if ( !iModel.MsgWaitingManager().ConstructionReady() ) { return; } TUint voiceMailsInLine1 = 0; TUint voiceMailsInLine2 = 0; //Internally we use value EVMExistsButCountNotKnown to specify a case where the //exact count of the voice mails is not know. However, the soft notes are designed //so that voice mail strings are either exact or "fuzzy", meaning that the expression //used in the string does not imply the exact number. //The "fuzzy" string is the singular string in the voice mail's soft note. To //use the singular form of the string we need to give voice mail count 1 in case the //internal value is EVMExistsButCountNotKnown. TBool line1(EFalse); TBool line2(EFalse); iModel.MsgWaitingManager().GetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine1, line1 ); iModel.MsgWaitingManager().GetMessageCount( MNcnMsgWaitingManager::ENcnMessageTypeVMLine1, voiceMailsInLine1 ); NCN_RDEBUG_INT2(_L("CVoiceMailManager : line 1 indicator %d, count %d"), line1, voiceMailsInLine1 ); if ( line1 && voiceMailsInLine1 == 0) { voiceMailsInLine1 = EVMExistsButCountNotKnown; } iModel.MsgWaitingManager().GetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine2, line2 ); iModel.MsgWaitingManager().GetMessageCount( MNcnMsgWaitingManager::ENcnMessageTypeVMLine2, voiceMailsInLine2 ); NCN_RDEBUG_INT2(_L("CVoiceMailManager : line 2 indicator %d, count %d"), line2, voiceMailsInLine2 ); if ( line2 && voiceMailsInLine2 == 0) { voiceMailsInLine2 = EVMExistsButCountNotKnown; } //The most common case. ALS is not supported in the terminal //Notifications show no line information. Only the information in //iVoiceMailCountInLine1 matters if( iIsALSSupported == EFalse && voiceMailsInLine1 > 0) { NCN_RDEBUG_INT(_L("CVoiceMailManager : %d voice mails in line 1 (ALS not supported)"), voiceMailsInLine1 ); if(!CheckSupressNotificationSettingL()) { NCN_RDEBUG( _L("CVoiceMailManager:SetIndicator and Notification ALS not supported With VVM off") ); //Soft notification. The SN must not contain any reference to line numbers iModel.NcnNotifier().SetNotification( MNcnNotifier::ENcnVoiceMailNotification, voiceMailsInLine1 ); // SysApp checks ALS support and decides whether to use o_o or O_o (left O full), if ALS supported // ENcnIndicatorVMLine1 is mapped to KDisplayVoicemailActive in CNcnMsgWaitingManager iModel.MsgWaitingManager().SetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine1, ETrue ); } } else if( iIsALSSupported == TRUE ) { UpdateNoteAndIndicationWithALS( voiceMailsInLine1, voiceMailsInLine2 ); } //No voice mails waiting. Clear the messages else { NCN_RDEBUG( _L("CVoiceMailManager : No voice mails in line 1 nor in line 2") ); //Clear soft notifications ClearVoiceMailSoftNotes(); iModel.MsgWaitingManager().SetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine1, EFalse ); iModel.MsgWaitingManager().SetIndicator( MNcnMsgWaitingManager::ENcnIndicatorVMLine2, EFalse ); } } // ------------------------------------------------------------------- // Find out if alternative line subscription is active in the terminal // ------------------------------------------------------------------- // TBool CVoiceMailManager::UpdateALSStatus() { //Open the information settings RSSSettings settings; TInt status = settings.Open(); NCN_RDEBUG_INT( _L("CVoiceMailManager.UpdateALSStatus() : Opened RSSSettings! status %d"), status ); //Get the ALS information, // ALS is supported, if: // 1. supported by the device (ALS PP enabled) // 2. CSP enabled and SIM supports alternative service line (line2) TInt alsValue = KErrUnknown; status = settings.Get( ESSSettingsAls, alsValue ); NCN_RDEBUG_INT2( _L("CVoiceMailManager.UpdateALSStatus() : Got ALS info Status: %d Value: %d"), status, alsValue); //Close the settings, they are no longer needed settings.Close(); //Meaning of the ALS values // ESSSettingsAlsNotSupported - ALS not supported, always primary line. // ESSSettingsAlsPrimary - ALS supported, primary line selected. // ESSSettingsAlsAlternate - ALS supported, alternate line selected. //Value read OK and ALS not supported if( status == KErrNone && alsValue == ESSSettingsAlsNotSupported ) { NCN_RDEBUG( _L("ALS value read properly! ALS not supported!") ); return EFalse; } //Value read OK and ALS is supported else if( status == KErrNone && ( alsValue == ESSSettingsAlsPrimary || alsValue == ESSSettingsAlsAlternate ) ) { NCN_RDEBUG( _L("ALS value read properly! ALS is supported!") ); return ETrue; } //Default value. ALS not supported. Returned if ALS status can't be read properly! else { NCN_RDEBUG_INT2( _L("ALS value NOT read properly! Status: %d Value: %d"), status, alsValue ); return EFalse; } } // ------------------------------------------------------------------- // Check the KMuiuSupressAllNotificationConfiguration value // ------------------------------------------------------------------- // TBool CVoiceMailManager::CheckSupressNotificationSettingL() { TBool result = EFalse; TInt value = 0; CRepository* repository = NULL; TRAPD( err, repository = CRepository::NewL( KCRUidMuiuMessagingConfiguration ) ); if( err == KErrNone && repository != NULL ) { CleanupStack::PushL( repository ); err = repository->Get( KMuiuSupressAllNotificationConfiguration, value ); if(err == KErrNone && (value & KMuiuNotificationSupressedForVoiceMail )) { result = ETrue; } } NCN_RDEBUG_INT( _L("CNcnNotifier::CheckSupressNotificationSetting() - result: %d"), result ); CleanupStack::PopAndDestroy( repository ); return result; } // End of File
c4b5a9fadce3aa0f9367b91cbce6b6d7341f26d6
c43039d34f392903f4c9215b56b30ad0e1e92340
/include/svgplotlib/plotlib_core.h
a9d7f91d41f1998e3cd4c9677785d20a4ac990cf
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
suluke/svgutils
690638ba536785d2a308a8a9ac6f04c397b5ed3d
1cbea7eb71e69aa271bb6aae7ab664bec8e4dad3
refs/heads/master
2020-04-01T10:34:07.543931
2018-11-25T18:30:39
2018-11-25T18:30:39
153,122,562
0
0
null
null
null
null
UTF-8
C++
false
false
9,021
h
plotlib_core.h
#ifndef SVGPLOTLIB_PLOTLIB_CORE_H #define SVGPLOTLIB_PLOTLIB_CORE_H #include "svgutils/css_utils.h" #include "svgutils/svg_writer.h" #include <functional> #include <optional> #include <string_view> namespace plots { template <typename WriterTy> struct PlotWriter : public svg::ExtendableWriter<PlotWriter<WriterTy>> { using base_t = svg::ExtendableWriter<PlotWriter<WriterTy>>; using RetTy = svg::SVGWriterErrorOr<PlotWriter *>; template <typename... args_t> PlotWriter(args_t &&... args) : base_t(std::make_unique<svg::WriterModel<WriterTy>>( std::forward<args_t>(args)...)) {} template <typename... attrs_t> RetTy grid(double top, double left, double width, double height, double distx, double disty, attrs_t... attrs) { std::vector<svg::SVGAttribute> attrVec({std::forward<attrs_t>(attrs)...}); return grid(top, left, width, height, distx, disty, attrVec); } template <typename container_t> RetTy grid(double top, double left, double width, double height, double distx, double disty, const container_t &attrs) { using namespace svg; std::vector<svg::SVGAttribute> attrsExt(attrs.begin(), attrs.end()); auto &self = static_cast<base_t &>(*this); for (double i = top; i <= top + height; i += disty) { attrsExt.erase(attrsExt.begin() + attrs.size(), attrsExt.end()); attrsExt.insert(attrsExt.end(), {x1(left), y1(i), x2(left + width), y2(i)}); self.line(attrsExt); } for (double i = left; i < left + width; i += distx) { attrsExt.erase(attrsExt.begin() + attrs.size(), attrsExt.end()); attrsExt.insert(attrsExt.end(), {x1(i), y1(top), x2(i), y2(top + height)}); self.line(attrsExt); } return this; } }; struct PlotWriterConcept : public virtual svg::WriterConcept { using RetTy = svg::SVGWriterErrorOr<PlotWriterConcept *>; virtual RetTy grid(double top, double left, double width, double height, double distx, double disty, const std::vector<svg::SVGAttribute> &attrs) = 0; template <typename... attrs_t> RetTy grid(double top, double left, double width, double height, double distx, double disty, attrs_t... attrs) { std::vector<svg::SVGAttribute> attrVec({std::forward<attrs_t>(attrs)...}); return grid(top, left, width, height, distx, disty, attrVec); } }; template <typename WriterTy> struct PlotWriterModel : public PlotWriterConcept, public svg::WriterModel<WriterTy> { using ModelBase_t = svg::WriterModel<WriterTy>; using RetTy = PlotWriterConcept::RetTy; template <typename... args_t> PlotWriterModel(args_t &&... args) : ModelBase_t(std::forward<args_t>(args)...) {} RetTy grid(double top, double left, double width, double height, double distx, double disty, const std::vector<svg::SVGAttribute> &attrs) override { return this->ModelBase_t::Writer.grid(top, left, width, height, distx, disty, attrs).with_value(static_cast<PlotWriterConcept *>(this)); } }; struct Axis; struct Plot { Plot(std::string name) : name(std::move(name)) {} virtual ~Plot() = default; virtual double getMinX() const = 0; virtual double getMaxX() const = 0; virtual double getMinY() const = 0; virtual double getMaxY() const = 0; virtual void renderPreview(PlotWriterConcept &writer) const = 0; virtual void compile(PlotWriterConcept &writer, const Axis &axis) const = 0; const std::string &getName() const { return name; } private: std::string name; }; struct Legend { virtual ~Legend() = default; virtual double getWidth() const = 0; virtual double getHeight() const = 0; virtual void addPlot(Plot *plot) = 0; virtual void compile(PlotWriterConcept &writer) const = 0; }; template <unsigned dim, typename data_t = double> struct Point { std::array<data_t, dim> dimensions; constexpr Point() = default; template <typename... args_t> constexpr Point(args_t &&... args) : dimensions({{std::forward<args_t>(args)...}}){}; constexpr data_t x() const { static_assert(dim > 0, "Cannot get first dimension of vector with zero dimensions"); return dimensions[0]; } constexpr data_t y() const { static_assert( dim > 1, "Cannot get second dimension of vector with less than two dimensions"); return dimensions[1]; } constexpr void x(data_t val) { static_assert(dim > 0, "Cannot set first dimension of vector with zero dimensions"); dimensions[0] = val; } constexpr void y(data_t val) { static_assert( dim > 1, "Cannot set second dimension of vector with less than two dimensions"); dimensions[1] = val; } constexpr auto begin() { return dimensions.begin(); } constexpr auto end() { return dimensions.end(); } constexpr auto begin() const { return dimensions.begin(); } constexpr auto end() const { return dimensions.end(); } constexpr unsigned size() const { return dim; } template <unsigned odim> constexpr auto operator+(const Point<odim, data_t> &o) const { constexpr unsigned maxDim = dim > odim ? dim : odim; Point<maxDim, data_t> p; auto outIt = p.begin(); for (auto D : dimensions) *(outIt++) = D; outIt = p.begin(); for (auto D : o.dimensions) *(outIt++) = D; return p; } template <unsigned odim> constexpr auto operator-(const Point<odim, data_t> &o) const { return *this + (o * -1.); } constexpr Point<dim, data_t> operator+(data_t o) const { auto p = *this; for (data_t &d : p) d += o; return p; } constexpr Point<dim, data_t> operator-(data_t o) const { return *this + (-o); } constexpr Point<dim, data_t> operator*(data_t o) const { auto p = *this; for (data_t &d : p) d *= o; return p; } }; /// Simple base implementation of an interface to query font styles and /// text dimensions struct FontInfo { FontInfo() = default; FontInfo(std::string font, double fontSize) : font(std::move(font)), fontSize(fontSize) {} FontInfo(const FontInfo &) = default; FontInfo(FontInfo &&) = default; FontInfo &operator=(const FontInfo &) = default; FontInfo &operator=(FontInfo &&) = default; virtual ~FontInfo() = default; void setFont(std::string font) { font = std::move(font); } void setSize(double s) { fontSize = s; } double getSize() const { return fontSize; } virtual std::string getFontStyle() const; virtual double getWidth(std::string_view text, bool multiLine = false) const; virtual double getHeight(std::string_view text, bool multiLine = false) const; virtual void placeText(const char *text, PlotWriterConcept &writer, Point<2> position, Point<2> anchor = {0., 0.}, bool multiLine = false) const; private: std::string font = "Times, serif"; double fontSize = 12; }; struct AxisStyle { using TickGen = std::function<std::string(double coord)>; enum Type { OUTER, INNER } type = OUTER; bool grid = true; double minX = 0; double maxX; double minY = 0; double maxY; double xStep = 1.; double yStep = 1.; std::string xLabel = "x"; std::string yLabel = "y"; TickGen xTickGen = [](double x) { return std::to_string(x); }; TickGen yTickGen = [](double y) { return std::to_string(y); }; }; struct Graph; struct Axis { virtual ~Axis() = default; template <typename PlotTy> PlotTy *addPlot(std::unique_ptr<PlotTy> plot) { plots.emplace_back(std::move(plot)); return static_cast<PlotTy *>(plots.back().get()); } void setLegend(std::unique_ptr<Legend> legend) { this->legend = std::move(legend); } virtual void compile(PlotWriterConcept &writer, const Graph &graph, double width, double height); virtual Point<2> project(Point<2> p) const; AxisStyle &prepareStyle(); AxisStyle &getStyle(); const AxisStyle &getStyle() const { assert(style); return *style; } private: double width; double height; Point<2> translation; std::unique_ptr<Legend> legend; std::vector<std::unique_ptr<Plot>> plots; std::optional<AxisStyle> style; }; struct Graph { Graph(double width, double height, std::unique_ptr<FontInfo> font = nullptr) : width(width), height(height), font(font ? std::move(font) : std::make_unique<FontInfo>()) {} template <typename AxisTy> AxisTy *addAxis(std::unique_ptr<AxisTy> axis) { Axes.emplace_back(std::move(axis)); return static_cast<AxisTy *>(Axes.back().get()); } void addCSSRule(svg::CSSRule rule) { CssRules.emplace_back(std::move(rule)); } FontInfo &getFontInfo() const { return *font; } void compile(PlotWriterConcept &writer) const; private: double width; double height; std::vector<std::unique_ptr<Axis>> Axes; std::vector<svg::CSSRule> CssRules; std::unique_ptr<FontInfo> font; }; } // namespace plots #endif // SVGPLOTLIB_PLOTLIB_CORE_H
068f79615e1ac79fd5914fad1f743bb85c39d714
f0dbabac157fc79094062513cfcc28be253d9b70
/modules/trustchain/test/test_actions_usergroupaddition.cpp
fcbee48209f72f5c35365edfbbed8b64673e252f
[ "Apache-2.0" ]
permissive
TankerHQ/sdk-native
4c3a81d83a9e144c432ca74c3e327225e6814e91
c062edc4b6ad26ce90e0aebcc2359adde4ca65db
refs/heads/master
2023-08-19T02:59:40.445973
2023-08-09T12:04:46
2023-08-09T12:04:46
160,206,027
20
4
null
null
null
null
UTF-8
C++
false
false
25,835
cpp
test_actions_usergroupaddition.cpp
#include <Tanker/Trustchain/Actions/UserGroupAddition.hpp> #include <Tanker/Crypto/Crypto.hpp> #include <Tanker/Serialization/Serialization.hpp> #include <Tanker/Trustchain/UserId.hpp> #include <Helpers/Buffers.hpp> #include <catch2/catch_test_macros.hpp> using namespace Tanker; using namespace Tanker::Trustchain; using namespace Tanker::Trustchain::Actions; TEST_CASE("UserGroupAddition serialization test vectors") { SECTION("it should serialize/deserialize a UserGroupAddition1") { // clang-format off std::vector<std::uint8_t> const serializedUserGroupAddition = { // varint version 0x01, // varint index 0x00, // trustchain id 0x74, 0x72, 0x75, 0x73, 0x74, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // varint nature 0x0c, // varint payload size 0xe1, 0x02, // group id 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // previous group block hash 0x70, 0x72, 0x65, 0x76, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // varint 0x02, // public user encryption key 1 0x70, 0x75, 0x62, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // encrypted group private encryption key 1 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public user encryption key 2 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x70, 0x75, 0x62, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // encrypted group private encryption key 2 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // self signature 0x73, 0x65, 0x6c, 0x66, 0x20, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // author 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // signature 0x73, 0x69, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; // clang-format on auto const groupId = make<GroupId>("group id"); auto const previousGroupBlockHash = make<Crypto::Hash>("prev group block"); UserGroupAddition::v1::SealedPrivateEncryptionKeysForUsers const sealedPrivateEncryptionKeysForUsers{ {make<Crypto::PublicEncryptionKey>("pub user key"), make<Crypto::SealedPrivateEncryptionKey>( "encrypted group priv key")}, {make<Crypto::PublicEncryptionKey>("second pub user key"), make<Crypto::SealedPrivateEncryptionKey>( "second encrypted group priv key")}}; auto const selfSignature = make<Crypto::Signature>("self signature"); auto const trustchainId = make<TrustchainId>("trustchain id"); auto const author = make<Crypto::Hash>("author"); auto const signature = make<Crypto::Signature>("sig"); auto const hash = mgs::base64::decode<Crypto::Hash>( "+J1iz8DZz+W+QUwyfjXCd/zEa0KQQkTqz1Ougnq3xFg="); UserGroupAddition::v1 const uga{trustchainId, groupId, previousGroupBlockHash, sealedPrivateEncryptionKeysForUsers, selfSignature, author, hash, signature}; CHECK(Serialization::serialize(uga) == serializedUserGroupAddition); CHECK(Serialization::deserialize<UserGroupAddition::v1>( serializedUserGroupAddition) == uga); } SECTION("it should serialize/deserialize a UserGroupAddition2") { // clang-format off std::vector<std::uint8_t> const serializedUserGroupAddition = { // varint version 0x01, // varint index 0x00, // trustchain id 0x74, 0x72, 0x75, 0x73, 0x74, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // varint nature 0x10, // varint payload size 0xa2, 0x06, // group id 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // previous group block hash 0x70, 0x72, 0x65, 0x76, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // varint 0x02, // User ID 1 0x75, 0x73, 0x65, 0x72, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public user encryption key 1 0x70, 0x75, 0x62, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // encrypted group private encryption key 1 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // User ID 2 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public user encryption key 2 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x70, 0x75, 0x62, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // encrypted group private encryption key 2 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Varint 0x02, // public app signature key 1 0x61, 0x70, 0x70, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public tanker signature key 1 0x74, 0x61, 0x6e, 0x6b, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // encrypted group private encryption key 1 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // provisional user app signature key 2 0x32, 0x6e, 0x64, 0x20, 0x61, 0x70, 0x70, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, // provisional user tanker signature key 2 0x32, 0x6e, 0x64, 0x20, 0x74, 0x61, 0x6e, 0x6b, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, // encrypted group private encryption key 2 0x32, 0x6e, 0x64, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // self signature 0x73, 0x65, 0x6c, 0x66, 0x20, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // author 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // signature 0x73, 0x69, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; // clang-format on auto const trustchainId = make<TrustchainId>("trustchain id"); auto const author = make<Crypto::Hash>("author"); auto const signature = make<Crypto::Signature>("sig"); auto const groupId = make<GroupId>("group id"); auto const previousGroupBlockHash = make<Crypto::Hash>("prev group block"); std::vector<UserGroupAddition::v2::Member> const members{ {make<UserId>("user id"), make<Crypto::PublicEncryptionKey>("pub user key"), make<Crypto::SealedPrivateEncryptionKey>("encrypted group priv key")}, {make<UserId>("second user id"), make<Crypto::PublicEncryptionKey>("second pub user key"), make<Crypto::SealedPrivateEncryptionKey>( "second encrypted group priv key")}}; std::vector<UserGroupAddition::v2::ProvisionalMember> const provisionalMembers{ {make<Crypto::PublicSignatureKey>("app provisional sig key"), make<Crypto::PublicSignatureKey>("tanker provisional sig key"), make<Crypto::TwoTimesSealedPrivateEncryptionKey>( "provisional encrypted group priv key")}, {make<Crypto::PublicSignatureKey>("2nd app provisional sig key"), make<Crypto::PublicSignatureKey>("2nd tanker provisional sig key"), make<Crypto::TwoTimesSealedPrivateEncryptionKey>( "2nd provisional encrypted group priv key")}}; auto const selfSignature = make<Crypto::Signature>("self signature"); auto const hash = mgs::base64::decode<Crypto::Hash>( "KrjiPbdL/Eekt+vTD03gMiAjafG3wod2DI03wsggiOo="); UserGroupAddition::v2 const uga{trustchainId, groupId, previousGroupBlockHash, members, provisionalMembers, selfSignature, author, hash, signature}; CHECK(Serialization::serialize(uga) == serializedUserGroupAddition); CHECK(Serialization::deserialize<UserGroupAddition::v2>( serializedUserGroupAddition) == uga); } SECTION("it should serialize/deserialize a UserGroupAddition3") { // clang-format off std::vector<std::uint8_t> const serializedUserGroupAddition = { // varint version 0x01, // varint index 0x00, // trustchain id 0x74, 0x72, 0x75, 0x73, 0x74, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // varint nature 0x12, // varint payload size 0xa2, 0x07, // group id 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // previous group block hash 0x70, 0x72, 0x65, 0x76, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // varint 0x02, // User ID 1 0x75, 0x73, 0x65, 0x72, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public user encryption key 1 0x70, 0x75, 0x62, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // encrypted group private encryption key 1 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // User ID 2 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public user encryption key 2 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x70, 0x75, 0x62, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // encrypted group private encryption key 2 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Varint 0x02, // public app signature key 1 0x61, 0x70, 0x70, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public tanker signature key 1 0x74, 0x61, 0x6e, 0x6b, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public app encryption key 1 0x61, 0x70, 0x70, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x63, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // public tanker encryption key 1 0x74, 0x61, 0x6e, 0x6b, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x63, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // encrypted group private encryption key 1 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // provisional user app signature key 2 0x32, 0x6e, 0x64, 0x20, 0x61, 0x70, 0x70, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, // provisional user tanker signature key 2 0x32, 0x6e, 0x64, 0x20, 0x74, 0x61, 0x6e, 0x6b, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, // provisional user app encryption key 2 0x32, 0x6e, 0x64, 0x20, 0x61, 0x70, 0x70, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x63, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, // provisional user tanker encryption key 2 0x32, 0x6e, 0x64, 0x20, 0x74, 0x61, 0x6e, 0x6b, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x63, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, // encrypted group private encryption key 2 0x32, 0x6e, 0x64, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x20, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x70, 0x72, 0x69, 0x76, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // self signature 0x73, 0x65, 0x6c, 0x66, 0x20, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // author 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // signature 0x73, 0x69, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; // clang-format on auto const trustchainId = make<TrustchainId>("trustchain id"); auto const author = make<Crypto::Hash>("author"); auto const signature = make<Crypto::Signature>("sig"); auto const groupId = make<GroupId>("group id"); auto const previousGroupBlockHash = make<Crypto::Hash>("prev group block"); std::vector<UserGroupAddition::v2::Member> const members{ {make<UserId>("user id"), make<Crypto::PublicEncryptionKey>("pub user key"), make<Crypto::SealedPrivateEncryptionKey>("encrypted group priv key")}, {make<UserId>("second user id"), make<Crypto::PublicEncryptionKey>("second pub user key"), make<Crypto::SealedPrivateEncryptionKey>( "second encrypted group priv key")}}; std::vector<UserGroupAddition::v3::ProvisionalMember> const provisionalMembers{ {make<Crypto::PublicSignatureKey>("app provisional sig key"), make<Crypto::PublicSignatureKey>("tanker provisional sig key"), make<Crypto::PublicEncryptionKey>("app provisional enc key"), make<Crypto::PublicEncryptionKey>("tanker provisional enc key"), make<Crypto::TwoTimesSealedPrivateEncryptionKey>( "provisional encrypted group priv key")}, {make<Crypto::PublicSignatureKey>("2nd app provisional sig key"), make<Crypto::PublicSignatureKey>("2nd tanker provisional sig key"), make<Crypto::PublicEncryptionKey>("2nd app provisional enc key"), make<Crypto::PublicEncryptionKey>( "2nd tanker provisional enc key"), make<Crypto::TwoTimesSealedPrivateEncryptionKey>( "2nd provisional encrypted group priv key")}}; auto const selfSignature = make<Crypto::Signature>("self signature"); auto const hash = mgs::base64::decode<Crypto::Hash>( "j6fNrHULMUAhPAIEXQAkeHscTh+wDuRmVQEMP/hKlhI="); UserGroupAddition::v3 const uga{trustchainId, groupId, previousGroupBlockHash, members, provisionalMembers, selfSignature, author, hash, signature}; CHECK(Serialization::serialize(uga) == serializedUserGroupAddition); CHECK(Serialization::deserialize<UserGroupAddition::v3>( serializedUserGroupAddition) == uga); } }
190af12493f8e50f52af9188bb193025584e8957
8f7c8beaa2fca1907fb4796538ea77b4ecddc300
/ozone/wayland/seat.cc
d6e79560c192ef01354a9c2af519fb76aba0872e
[ "BSD-3-Clause" ]
permissive
lgsvl/chromium-src
8f88f6ae2066d5f81fa363f1d80433ec826e3474
5a6b4051e48b069d3eacbfad56eda3ea55526aee
refs/heads/ozone-wayland-62.0.3202.94
2023-03-14T10:58:30.213573
2017-10-26T19:27:03
2017-11-17T09:42:56
108,161,483
8
4
null
2017-12-19T22:53:32
2017-10-24T17:34:08
null
UTF-8
C++
false
false
4,199
cc
seat.cc
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2013 Intel Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ozone/wayland/seat.h" #include "base/logging.h" #if defined(USE_DATA_DEVICE_MANAGER) #include "ozone/wayland/data_device.h" #endif #include "ozone/wayland/display.h" #include "ozone/wayland/input/cursor.h" #include "ozone/wayland/input/keyboard.h" #include "ozone/wayland/input/pointer.h" #include "ozone/wayland/input/text_input.h" #include "ozone/wayland/input/touchscreen.h" namespace ozonewayland { WaylandSeat::WaylandSeat(WaylandDisplay* display, uint32_t id) : focused_window_handle_(0), grab_window_handle_(0), grab_button_(0), seat_(NULL), input_keyboard_(NULL), input_pointer_(NULL), input_touch_(NULL), text_input_(NULL) { static const struct wl_seat_listener kInputSeatListener = { WaylandSeat::OnSeatCapabilities, }; seat_ = static_cast<wl_seat*>( wl_registry_bind(display->registry(), id, &wl_seat_interface, 1)); DCHECK(seat_); wl_seat_add_listener(seat_, &kInputSeatListener, this); wl_seat_set_user_data(seat_, this); #if defined(USE_DATA_DEVICE_MANAGER) data_device_ = new WaylandDataDevice(display, seat_); #endif text_input_ = new WaylandTextInput(this); } WaylandSeat::~WaylandSeat() { #if defined(USE_DATA_DEVICE_MANAGER) delete data_device_; #endif delete input_keyboard_; delete input_pointer_; delete text_input_; if (input_touch_ != NULL) { delete input_touch_; } wl_seat_destroy(seat_); } void WaylandSeat::OnSeatCapabilities(void *data, wl_seat *seat, uint32_t caps) { WaylandSeat* device = static_cast<WaylandSeat*>(data); if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !device->input_keyboard_) { device->input_keyboard_ = new WaylandKeyboard(); device->input_keyboard_->OnSeatCapabilities(seat, caps); } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && device->input_keyboard_) { delete device->input_keyboard_; device->input_keyboard_ = NULL; } if ((caps & WL_SEAT_CAPABILITY_POINTER) && !device->input_pointer_) { device->input_pointer_ = new WaylandPointer(); device->input_pointer_->OnSeatCapabilities(seat, caps); } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && device->input_pointer_) { delete device->input_pointer_; device->input_pointer_ = NULL; } if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !device->input_touch_) { device->input_touch_ = new WaylandTouchscreen(); device->input_touch_->OnSeatCapabilities(seat, caps); } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && device->input_touch_) { delete device->input_touch_; device->input_touch_ = NULL; } } void WaylandSeat::SetFocusWindowHandle(unsigned windowhandle) { focused_window_handle_ = windowhandle; WaylandWindow* window = NULL; if (windowhandle) window = WaylandDisplay::GetInstance()->GetWindow(windowhandle); text_input_->SetActiveWindow(window); } void WaylandSeat::SetGrabWindowHandle(unsigned windowhandle, uint32_t button) { grab_window_handle_ = windowhandle; grab_button_ = button; } void WaylandSeat::SetCursorBitmap(const std::vector<SkBitmap>& bitmaps, const gfx::Point& location) { if (!input_pointer_) { LOG(WARNING) << "Tried to change cursor without input configured"; return; } input_pointer_->Cursor()->UpdateBitmap( bitmaps, location, WaylandDisplay::GetInstance()->GetSerial()); } void WaylandSeat::MoveCursor(const gfx::Point& location) { if (!input_pointer_) { LOG(WARNING) << "Tried to move cursor without input configured"; return; } input_pointer_->Cursor()->MoveCursor( location, WaylandDisplay::GetInstance()->GetSerial()); } void WaylandSeat::ResetIme() { text_input_->ResetIme(); } void WaylandSeat::ImeCaretBoundsChanged(gfx::Rect rect) { NOTIMPLEMENTED(); } void WaylandSeat::ShowInputPanel() { text_input_->ShowInputPanel(seat_); } void WaylandSeat::HideInputPanel() { text_input_->HideInputPanel(seat_); } } // namespace ozonewayland
76d8b7eadceec70eeaf20651919b7d7344a579ee
087feb02b7c78067524a68b593c012f6725b88c1
/Relocation/ASTRelocation.cpp
9d1bbd0999d34b135825de7568cf10557160288c
[]
no_license
ginusxiao/AutoStorageTiering
70b0e6b3e6d8bf430ce54523181b43e2e63a6e8a
8b112d40836eb373fbc4f84eb385deb181e56ed2
refs/heads/master
2023-01-19T03:09:32.322569
2020-11-14T04:40:25
2020-11-14T04:40:25
312,745,412
0
0
null
null
null
null
UTF-8
C++
false
false
28,595
cpp
ASTRelocation.cpp
#include "OSSCommon/Logger.hpp" #include "AST/ASTLogicalConfig.hpp" #include "AST/ASTIO.hpp" #include "AST/ASTSwapOut.hpp" #include "AST/ASTHeatDistribution.hpp" #include "AST/ASTAdvice.hpp" #include "AST/ASTPerformance.hpp" #include "AST/ASTPlan.hpp" #include "AST/ASTArb.hpp" #include "AST/ASTMigration.hpp" #include "AST/AST.hpp" #include "AST/MessageImpl.hpp" #include "AST/ASTSwapOut.hpp" #include "AST/ASTRelocation.hpp" RelocationTask::RelocationTask(AST* ast) { YWB_ASSERT(ast != NULL); mAst = ast; } RelocationTask::~RelocationTask() { mAst = NULL; } ywb_status_t RelocationTask::Prepare() { return YWB_SUCCESS; } //ywb_status_t //RelocationTask::DoCycleWork(ywb_uint32_t phase) //{ // return YWB_SUCCESS; //} ywb_status_t RelocationTask::DoCycleWork() { return YWB_SUCCESS; } RelocationLearning::RelocationLearning(AST* ast) : RelocationTask(ast), mAdviceAfterLearning(false) { GetAST(&ast); ast->GetLogicalConfig(&mConfigManager); ast->GetIOManager(&mIOManager); #ifdef WITH_INITIAL_PLACEMENT ast->GetSwapOutManager(&mSwapOutManager); YWB_ASSERT(mSwapOutManager != NULL); #endif YWB_ASSERT(mConfigManager != NULL); YWB_ASSERT(mIOManager != NULL); mLearningEvent = NULL; } RelocationLearning::~RelocationLearning() { mConfigManager = NULL; mIOManager = NULL; mLearningEvent = NULL; #ifdef WITH_INITIAL_PLACEMENT mSwapOutManager = NULL; #endif } ywb_status_t RelocationLearning::Reset() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("Learning task reset"); mConfigManager->Reset(); mIOManager->Reset(); #ifdef WITH_INITIAL_PLACEMENT mSwapOutManager->Reset(); #endif return ret; } ywb_status_t RelocationLearning::MarkLogicalConfigAsSuspicious() { ywb_status_t ret = YWB_SUCCESS; SubPool* subpool = NULL; Tier* tier = NULL; Disk* disk = NULL; OBJ* obj = NULL; SubPoolKey subpoolkey; ywb_uint32_t tiertype = Tier::TIER_cnt; /*mark all subpools/disks/OBJs as suspicious*/ ret = mConfigManager->GetFirstSubPool(&subpool, &subpoolkey); while((YWB_SUCCESS == ret) && (subpool != NULL)) { subpool->SetFlagComb(SubPool::SPF_suspicious); tiertype = Tier::TIER_0; for(; tiertype < Tier::TIER_cnt; tiertype++) { ret = subpool->GetTier(tiertype, &tier); if((YWB_SUCCESS == ret) && (tier != NULL)) { ret = tier->GetFirstDisk(&disk); while((YWB_SUCCESS == ret) && (disk != NULL)) { disk->SetFlagComb(Disk::DF_suspicious); ret = disk->GetFirstOBJ(&obj); while((YWB_SUCCESS == ret) && (obj != NULL)) { obj->SetFlagComb(OBJ::OF_suspicious); mConfigManager->PutOBJ(obj); ret = disk->GetNextOBJ(&obj); } tier->PutDisk(disk); ret = tier->GetNextDisk(&disk); } subpool->PutTier(tier); } } mConfigManager->PutSubPool(subpool); ret = mConfigManager->GetNextSubPool(&subpool, &subpoolkey); } return ret; } #if 0 ywb_status_t RelocationLearning::RemoveUnConfirmedSuspect() { ywb_status_t ret = YWB_SUCCESS; SubPool* subpool = NULL; Tier* tier = NULL; Disk* disk = NULL; OBJVal* obj = NULL; SubPoolKey subpoolkey; DiskKey diskkey; OBJKey objkey; ywb_uint32_t tiertype = Tier::TIER_cnt; /*remove those subpools/disks/OBJs have not been confirmed*/ ret = mConfigManager->GetFirstSubPool(&subpool, &subpoolkey); while((YWB_SUCCESS == ret) && (subpool != NULL)) { if(subpool->TestFlag(SubPool::SPF_suspicious)) { mConfigManager->RemoveSubPool(subpoolkey); } else { tiertype = Tier::TIER_0; for(; tiertype < Tier::TIER_cnt; tiertype++) { ret = subpool->GetTier(tiertype, &tier); if(!((YWB_SUCCESS == ret) && (tier != NULL))) { continue; } ret = tier->GetFirstDisk(&disk, &diskkey); while((YWB_SUCCESS == ret) && (disk != NULL)) { if(disk->TestFlag(Disk::DF_suspicous)) { subpool->RemoveDisk(diskkey); } else { ret = disk->GetFirstOBJ(&obj, &objkey); while((YWB_SUCCESS == ret) && (obj != NULL)) { if(obj->TestFlag(OBJ::OF_suspicious)) { disk->RemoveOBJ(objkey); } mConfigManager->PutOBJ(obj); ret = disk->GetNextOBJ(&obj, &objkey); } } mConfigManager->PutDisk(disk); ret = tier->GetNextDisk(&disk, &diskkey); } subpool->PutTier(tier); } } mConfigManager->PutSubPool(subpool); ret = mConfigManager->GetNextSubPool(&subpool, &subpoolkey); } return ret; } #endif ywb_status_t RelocationLearning::RemoveUnConfirmedSuspect() { ywb_status_t ret = YWB_SUCCESS; SubPool* subpool = NULL; Tier* tier = NULL; Disk* disk = NULL; OBJVal* obj = NULL; SubPoolKey subpoolkey; DiskKey diskkey; OBJKey objkey; ywb_uint32_t tiertype = Tier::TIER_cnt; /*remove those subpools/disks/OBJs have not been confirmed*/ ret = mConfigManager->GetFirstSubPool(&subpool, &subpoolkey); while((YWB_SUCCESS == ret) && (subpool != NULL)) { if(subpool->TestFlag(SubPool::SPF_suspicious)) { mConfigManager->AddDeletedSubPool(subpoolkey); } else { tiertype = Tier::TIER_0; for(; tiertype < Tier::TIER_cnt; tiertype++) { ret = subpool->GetTier(tiertype, &tier); if(!((YWB_SUCCESS == ret) && (tier != NULL))) { continue; } ret = tier->GetFirstDisk(&disk, &diskkey); while((YWB_SUCCESS == ret) && (disk != NULL)) { if(disk->TestFlag(Disk::DF_suspicious)) { mConfigManager->AddDeletedDisk(diskkey); } else { ret = disk->GetFirstOBJ(&obj, &objkey); while((YWB_SUCCESS == ret) && (obj != NULL)) { if(obj->TestFlag(OBJ::OF_suspicious)) { mConfigManager->AddDeletedOBJ(objkey); } mConfigManager->PutOBJ(obj); ret = disk->GetNextOBJ(&obj, &objkey); } } mConfigManager->PutDisk(disk); ret = tier->GetNextDisk(&disk, &diskkey); } subpool->PutTier(tier); } } mConfigManager->PutSubPool(subpool); ret = mConfigManager->GetNextSubPool(&subpool, &subpoolkey); } return ret; } ywb_status_t RelocationLearning::Consolidate() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("Learning task consolidate"); mConfigManager->Consolidate(); mIOManager->Consolidate(); #ifdef WITH_INITIAL_PLACEMENT mSwapOutManager->Consolidate(); #endif return ret; } ywb_status_t RelocationLearning::Prepare() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("Learning task preparation"); MarkLogicalConfigAsSuspicious(); return ret; } ywb_status_t RelocationLearning::DoCycleWork() { ywb_status_t ret = YWB_SUCCESS; AST* ast = NULL; Generator* gen = NULL; Executor* exe = NULL; GeneratorEventSet::LearningEvent* learningevent = NULL; void* resp = NULL; CollectOBJResponse* collectobjresponse = NULL; ywb_uint32_t flag = 0; learningevent = mLearningEvent; YWB_ASSERT(learningevent != NULL); GetAST(&ast); ast->GetGenerator(&gen); ast->GetExecutor(&exe); ast_log_debug("Learning task cyclic work, phase: " << learningevent->GetPhase() << "[P_collect_logical_config: 0, P_resolve_logical_config: 1," << " P_collect_OBJ_io: 2, P_resolve_OBJ_io : 3," << " P_resolve_deleted_OBJs: 4, P_resolve_deleted_disks : 5," << " P_resolve_deleted_subpools: 6]"); switch(learningevent->GetPhase()) { case Generator::P_collect_logical_config: /*prepare for collecting logical config and OBJ IO in new cycle*/ Prepare(); gen->SetStatus(Generator::S_learning); mAdviceAfterLearning = learningevent->GetAdviceAfterLearning(); ret = mConfigManager->CollectLogicalConfig(Constant::OSS_ID); break; case Generator::P_resolve_logical_config: YWB_ASSERT(Generator::S_learning == gen->GetStatus()); learningevent->GetResp(&resp); ret = mConfigManager->ResolveLogicalConfig( (CollectLogicalConfigResponse*)resp); if(YWB_SUCCESS == ret) { mIOManager->CollectOBJIOPrep(Constant::OSS_ID); /*directly call CollectOBJIO() instead of launch an event*/ ret = mIOManager->CollectOBJIO(Constant::OSS_ID); } else { /* * FIXME: here will not call RemoveUnConfirmedSuspect, NOOP * is enough for both Generator and Executor * */ gen->SetStatus(Generator::S_noop); exe->SetStatus(Executor::S_noop); gen->HandlePendingEvent(); } break; case Generator::P_resolve_OBJ_io: YWB_ASSERT(Generator::S_learning == gen->GetStatus()); learningevent->GetResp(&resp); collectobjresponse = (CollectOBJResponse*)resp; YWB_ASSERT(collectobjresponse != NULL); if((YWB_SUCCESS == collectobjresponse->GetStatus()) && (Generator::S_noop != gen->GetStatus())) { flag = collectobjresponse->GetFlag(); if(CollectOBJResponse::F_next_batch == flag) { mIOManager->CollectOBJIO(Constant::OSS_ID); } ret = mIOManager->ResolveOBJIO(collectobjresponse); if((YWB_SUCCESS == ret) && (CollectOBJResponse::F_end == flag)) { mIOManager->CollectOBJIOPost(Constant::OSS_ID); RemoveUnConfirmedSuspect(); if(true == mAdviceAfterLearning) { gen->SetStatus(Generator::S_advising); /*issue stall event*/ exe->LaunchStallEvent(); } else { gen->SetStatus(Generator::S_learning_done); gen->HandlePendingEvent(); } } else if(YWB_SUCCESS != ret) { mIOManager->CollectOBJIOPost(Constant::OSS_ID); /* * FIXME: here will not call RemoveUnConfirmedSuspect, NOOP * is enough for both Generator and Executor * */ gen->SetStatus(Generator::S_noop); exe->SetStatus(Executor::S_noop); gen->HandlePendingEvent(); } } else { collectobjresponse->DecRef(); if(Generator::S_noop != gen->GetStatus()) { mIOManager->CollectOBJIOPost(Constant::OSS_ID); } } break; case Generator::P_resolve_deleted_OBJs: learningevent->GetResp(&resp); ret = mConfigManager->ResolveDeletedOBJs( (ReportDeleteOBJsMessage*)resp); break; case Generator::P_resolve_deleted_disks: learningevent->GetResp(&resp); ret = mConfigManager->ResolveDeletedDisks( (ReportDeleteDisksMessage*)resp); break; case Generator::P_resolve_deleted_subpools: learningevent->GetResp(&resp); ret = mConfigManager->ResolveDeletedSubPools( (ReportDeleteSubPoolsMessage*)resp); break; case Generator::P_resolve_deleted_OBJ: learningevent->GetResp(&resp); ret = mConfigManager->ResolveDeletedOBJ( (ReportDeleteOBJMessage*)resp); break; case Generator::P_resolve_deleted_disk: learningevent->GetResp(&resp); ret = mConfigManager->ResolveDeletedDisk( (ReportDeleteDiskMessage*)resp); break; case Generator::P_resolve_deleted_subpool: learningevent->GetResp(&resp); ret = mConfigManager->ResolveDeletedSubPool( (ReportDeleteSubPoolMessage*)resp); break; #ifdef WITH_INITIAL_PLACEMENT case Generator::P_resolve_relocation_type: learningevent->GetResp(&resp); /*swap out manager resolves its own part only*/ ret = mSwapOutManager->ResolveRelocationType( (NotifyRelocationType*)resp); /*logical config resolves its own part*/ ret = mConfigManager->ResolveRelocationType( (NotifyRelocationType*)resp); break; case Generator::P_resolve_swap_requirement: learningevent->GetResp(&resp); ret = mSwapOutManager->ResolveSwapRequirement( (NotifySwapRequirement*)resp); break; case Generator::P_resolve_swap_cancellation: learningevent->GetResp(&resp); ret = mSwapOutManager->ResolveSwapCancellation( (NotifySwapCancellation*)resp); break; #endif default: YWB_ASSERT(0); break; } return ret; } RelocationCTR::RelocationCTR(AST* ast) : RelocationTask(ast) { GetAST(&ast); ast->GetAdviseManager(&mAdviceManager); ast->GetHeatDistributionManager(&mHeatDistributionManager); YWB_ASSERT(mAdviceManager != NULL); YWB_ASSERT(mHeatDistributionManager != NULL); } RelocationCTR::~RelocationCTR() { mAdviceManager = NULL; mHeatDistributionManager = NULL; } ywb_status_t RelocationCTR::Reset() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("CTR task reset"); mAdviceManager->Reset(); mHeatDistributionManager->Reset(); return ret; } ywb_status_t RelocationCTR::Init() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("CTR task init"); mAdviceManager->Init(); mHeatDistributionManager->Init(); return ret; } ywb_status_t RelocationCTR::Prepare() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("CTR task prepare"); Reset(); Init(); return ret; } ywb_status_t RelocationCTR::DoCycleWork() { ywb_status_t ret = YWB_SUCCESS; AST* ast = NULL; LogicalConfig* config = NULL; SwapOutManager* swapoutmgr = NULL; SubPool* subpool = NULL; SubPoolKey subpoolkey; AdviceRule* hotadvicerule = NULL; AdviceRule* coldadvicerule = NULL; AdviceRule* hotfilterrule = NULL; AdviceRule* coldfilterrule = NULL; #ifdef WITH_INITIAL_PLACEMENT AdviceRule* swapuprule = NULL; AdviceRule* swapdownrule = NULL; AdviceRule* swapupfilterrule = NULL; AdviceRule* swapdownfilterrule = NULL; #endif GetAST(&ast); ast->GetLogicalConfig(&config); #ifdef WITH_INITIAL_PLACEMENT ast->GetSwapOutManager(&swapoutmgr); #endif ast_log_debug("CTR task cyclic work"); /*rule for CTR hot advice*/ hotadvicerule = new AdviceRule(AdviceType::AT_ctr_hot, PartitionScope::PS_tier_wise, PartitionBase::PB_long_term | PartitionBase::PB_ema | PartitionBase::PB_random | PartitionBase::PB_rt, SortBase::SB_short_term | SortBase::SB_ema | SortBase::SB_rnd_seq | SortBase::SB_iops, Selector::SEL_from_larger); /*rule for CTR cold advice*/ coldadvicerule = new AdviceRule(AdviceType::AT_ctr_cold, PartitionScope::PS_tier_wise, PartitionBase::PB_long_term | PartitionBase::PB_ema | PartitionBase::PB_sequential | PartitionBase::PB_rt, SortBase::SB_short_term | SortBase::SB_ema | SortBase::SB_rnd_seq | SortBase::SB_iops, Selector::SEL_from_larger); #if 0 /*filter rule for CTR cold advice*/ coldfilterrule = new AdviceRule(AdviceType::AT_ctr_cold, PartitionScope::PS_tier_wise, PartitionBase::PB_long_term | PartitionBase::PB_ema | PartitionBase::PB_random | PartitionBase::PB_rt, SortBase::SB_short_term | SortBase::SB_ema | SortBase::SB_rnd_seq | SortBase::SB_iops, Selector::SEL_from_smaller); #endif /*rule for swap up advice*/ swapuprule = new AdviceRule(AdviceType::AT_swap_up, PartitionScope::PS_tier_internal_disk_wise, PartitionBase::PB_long_term | PartitionBase::PB_ema | PartitionBase::PB_random | PartitionBase::PB_rt, SortBase::SB_short_term | SortBase::SB_ema | SortBase::SB_rnd_seq | SortBase::SB_iops, Selector::SEL_from_larger); swapdownrule = new AdviceRule(AdviceType::AT_swap_down, PartitionScope::PS_tier_internal_disk_wise, PartitionBase::PB_long_term | PartitionBase::PB_ema | PartitionBase::PB_sequential | PartitionBase::PB_rt, SortBase::SB_short_term | SortBase::SB_ema | SortBase::SB_rnd_seq | SortBase::SB_iops, Selector::SEL_from_smaller); YWB_ASSERT(hotadvicerule); YWB_ASSERT(coldadvicerule); /*YWB_ASSERT(coldfilterrule);*/ YWB_ASSERT(swapuprule); YWB_ASSERT(swapdownrule); ret = config->GetFirstSubPool(&subpool, &subpoolkey); while((YWB_SUCCESS == ret) && (subpool != NULL)) { ret = mAdviceManager->PreGenerateCheck(subpool); if(YWB_SUCCESS == ret) { #ifdef WITH_INITIAL_PLACEMENT if(ywb_true == swapoutmgr->GetSwapRequired(subpoolkey)) { ast_log_debug("CTR generate SWAPUP advice for subpool: [" << subpoolkey.GetOss() << ", " << subpoolkey.GetPoolId() << ", " << subpoolkey.GetSubPoolId() << "]"); mAdviceManager->GenerateAdvice( subpoolkey, *swapuprule, swapupfilterrule, 0); ast_log_debug("CTR generate SWAPDOWN advice for subpool: [" << subpoolkey.GetOss() << ", " << subpoolkey.GetPoolId() << ", " << subpoolkey.GetSubPoolId() << "]"); mAdviceManager->GenerateAdvice( subpoolkey, *swapdownrule, swapdownfilterrule, 0); } else #endif { ast_log_debug("CTR generate HOT advice for subpool: [" << subpoolkey.GetOss() << ", " << subpoolkey.GetPoolId() << ", " << subpoolkey.GetSubPoolId() << "]"); mAdviceManager->GenerateAdvice( subpoolkey, *hotadvicerule, hotfilterrule, 0); ast_log_debug("CTR generate COLD advice for subpool: [" << subpoolkey.GetOss() << ", " << subpoolkey.GetPoolId() << ", " << subpoolkey.GetSubPoolId() << "]"); // mAdviceManager->GenerateAdvice( // subpoolkey, *coldadvicerule, coldfilterrule, 1); mAdviceManager->GenerateAdvice( subpoolkey, *coldadvicerule, coldfilterrule, 0); } } config->PutSubPool(subpool); ret = config->GetNextSubPool(&subpool, &subpoolkey); } if(hotadvicerule) { delete hotadvicerule; hotadvicerule = NULL; } if(coldadvicerule) { delete coldadvicerule; coldadvicerule = NULL; } if(hotfilterrule) { delete hotfilterrule; hotfilterrule = NULL; } if(coldfilterrule) { delete coldfilterrule; coldfilterrule = NULL; } if(swapuprule) { delete swapuprule; swapuprule = NULL; } if(swapupfilterrule) { delete swapupfilterrule; swapupfilterrule = NULL; } if(swapdownrule) { delete swapdownrule; swapdownrule = NULL; } if(swapdownfilterrule) { delete swapdownfilterrule; swapdownfilterrule = NULL; } return ret; } RelocationITR::RelocationITR(AST* ast) : RelocationTask(ast) { GetAST(&ast); ast->GetAdviseManager(&mAdviceManager); ast->GetHeatDistributionManager(&mHeatDistributionManager); YWB_ASSERT(mAdviceManager != NULL); YWB_ASSERT(mHeatDistributionManager != NULL); } RelocationITR::~RelocationITR() { mAdviceManager = NULL; mHeatDistributionManager = NULL; } /*currently ITR is not supported*/ ywb_status_t RelocationITR::Reset() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("ITR task reset"); return ret; } ywb_status_t RelocationITR::Init() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("ITR task init"); return ret; } ywb_status_t RelocationITR::Prepare() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("ITR task prepare"); Reset(); Init(); return ret; } /*currently ITR is not supported*/ ywb_status_t RelocationITR::DoCycleWork() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("ITR task cyclic work"); return ret; } RelocationPlan::RelocationPlan(AST* ast) : RelocationTask(ast) { GetAST(&ast); ast->GetPerfManager(&mDiskPerfManager); ast->GetPlanManager(&mPlanManager); YWB_ASSERT(mDiskPerfManager != NULL); YWB_ASSERT(mPlanManager != NULL); } RelocationPlan::~RelocationPlan() { mDiskPerfManager = NULL; mPlanManager = NULL; } ywb_status_t RelocationPlan::Reset() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("Plan task reset"); mPlanManager->Reset(ywb_false); mDiskPerfManager->Reset(); return ret; } ywb_status_t RelocationPlan::Init() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("Plan task init"); mDiskPerfManager->Init(); mPlanManager->Init(); return ret; } ywb_status_t RelocationPlan::HandleCompleted(SubPoolKey& subpoolkey, DiskKey& sourcekey, DiskKey& targetkey, ywb_bool_t triggermore, ywb_status_t migstatus) { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("Plan task handle completion notification"); ret = mPlanManager->Complete(subpoolkey, sourcekey, targetkey, triggermore, migstatus); return ret; } ywb_status_t RelocationPlan::HandleExpired(SubPoolKey& subpoolkey, DiskKey& sourcekey, DiskKey& targetkey, ywb_bool_t triggermore) { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("Plan task handle expiration notification"); ret = mPlanManager->Expire(subpoolkey, sourcekey, targetkey, triggermore); return ret; } ywb_status_t RelocationPlan::Prepare() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("Plan task prepare"); Reset(); Init(); return ret; } ywb_status_t RelocationPlan::DoCycleWork() { ywb_status_t ret = YWB_SUCCESS; AST* ast = NULL; LogicalConfig* config = NULL; PlanManager* planmgr = NULL; Error* err = NULL; SubPoolPlans* subpoolplans = NULL; SubPoolKey subpoolkey; ywb_uint32_t numplans = 0; ywb_uint32_t scheduledsubpools = 0; GetAST(&ast); ast->GetLogicalConfig(&config); ast->GetPlanManager(&planmgr); ast->GetError(&err); ast_log_debug("Plan task cyclic work"); ret = planmgr->GetFirstSubPoolPlans(&subpoolplans, &subpoolkey); while((YWB_SUCCESS == ret) && (subpoolplans != NULL)) { numplans = 0; /*generate plan*/ ret = mPlanManager->ScheduleFirstBatch(subpoolkey, &numplans); if((YWB_SUCCESS == ret)) { mPlanManager->SubmitFirstBatch(subpoolkey); } else if(Error::PLNE_subpool_schedule_timed_delay == err->GetPLNErr()) { ast_log_debug("Timed-delay schedule first batch"); mPlanManager->ScheduleFirstBatchTimedDelay(subpoolkey, ((Constant::CYCLE_PERIOD) * YWB_USEC_PER_SEC)); } else if(Error::PLNE_subpool_no_more_plan != err->GetPLNErr()) { ast_log_debug("Timed-delay schedule first batch"); mPlanManager->ScheduleFirstBatchDelay(subpoolkey); } scheduledsubpools++; ret = planmgr->GetNextSubPoolPlans(&subpoolplans, &subpoolkey); } if((scheduledsubpools > 0) && (YFS_ENOENT == ret)) { ret = YWB_SUCCESS; } return ret; } RelocationARB::RelocationARB(AST* ast) : RelocationTask(ast) { GetAST(&ast); ast->GetArb(&mArb); YWB_ASSERT(mArb != NULL); } RelocationARB::~RelocationARB() { mArb = NULL; } ywb_status_t RelocationARB::Reset() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("ARB task reset"); ret = mArb->Reset(ywb_false); return ret; } ywb_status_t RelocationARB::HandleCompleted(SubPoolKey& subpoolkey, ArbitrateeKey& arbitrateekey, ywb_bool_t curwindow, ywb_status_t migstatus) { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("ARB task handle completion notification"); ret = mArb->Complete(subpoolkey, arbitrateekey, curwindow, migstatus); return ret; } ywb_status_t RelocationARB::HandleExpired(SubPoolKey& subpoolkey, ArbitrateeKey& arbitrateekey, ywb_bool_t curwindow) { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("ARB task handle expiration notification"); ret = mArb->Expire(subpoolkey, arbitrateekey, curwindow); return ret; } ywb_status_t RelocationARB::Prepare() { ast_log_debug("ARB task prepare"); return Reset(); } ywb_status_t RelocationARB::DoCycleWork() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("ARB task cyclic work"); /*nothing to do at current*/ return ret; } RelocationMIG::RelocationMIG(AST* ast) : RelocationTask(ast) { GetAST(&ast); ast->GetMigration(&mMigrationManager); YWB_ASSERT(mMigrationManager != NULL); } RelocationMIG::~RelocationMIG() { mMigrationManager = NULL; } ywb_status_t RelocationMIG::Reset() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("MIG task reset"); mMigrationManager->Reset(ywb_false); return ret; } ywb_status_t RelocationMIG::Init() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("MIG task init"); mMigrationManager->Init(); return ret; } ywb_status_t RelocationMIG::HandleCompleted(DiskKey& diskkey, ArbitrateeKey& arbitrateekey, ywb_status_t migerr, ywb_bool_t triggermore) { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("MIG task handle completion notification"); ret = mMigrationManager->Complete(diskkey, arbitrateekey, migerr, triggermore); return ret; } ywb_status_t RelocationMIG::HandleExpired(DiskKey& diskkey, ArbitrateeKey& arbitrateekey, ywb_bool_t triggermore) { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("MIG task handle expiration notification"); ret = mMigrationManager->Expire(diskkey, arbitrateekey, triggermore); return ret; } ywb_status_t RelocationMIG::RemoveInflight(ArbitrateeKey& arbitrateekey) { return mMigrationManager->RemoveInflight(arbitrateekey); } ywb_uint32_t RelocationMIG::GetInflightEmpty() { return mMigrationManager->GetInflightEmpty(); } ywb_status_t RelocationMIG::Prepare() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("MIG task prepare"); Reset(); Init(); return ret; } ywb_status_t RelocationMIG::DoCycleWork() { ywb_status_t ret = YWB_SUCCESS; ast_log_debug("MIG task cyclic work"); /*nothing to do at current*/ return ret; } /* vim:set ts=4 sw=4 expandtab */
270203a7d2d677994dd37cff2890f6ce3c03e0d9
aa4733448f2768f936ae98379fa6555025e37dff
/Source/MobileTV/CMCC/Utility.cpp
a12eb43ca0921cb1a8ba2adf7efe43d40e052e80
[]
no_license
schreibikus/nmPlayer
0048599d6e5fc60cc44f480fed85f9cf6446cfb4
1e6f3fb265ab8ec091177c8cd8f3c6e384df7edc
refs/heads/master
2020-04-01T20:34:56.120981
2017-05-06T08:33:55
2017-05-06T08:33:55
null
0
0
null
null
null
null
UTF-8
C++
false
false
4,246
cpp
Utility.cpp
/************************************************************************ * * * VisualOn, Inc. Confidential and Proprietary, 2003 - 2009 * * * ************************************************************************/ /******************************************************************************* File: Utility.cpp Contains: Utility header file Written by: Thomas Liang Change History (most recent first): 2011-03-09 Thomas Liang Create file *******************************************************************************/ #include "Utility.h" #ifdef WIN32 #include "Windows.h" #elif defined LINUX #include <sys/time.h> #endif //WIN32 #include "voLog.h" #define LOG_TAG "Utility" DWORD voTimeGetTime(){ #ifdef WIN32 return timeGetTime(); #else struct timeval tval; gettimeofday(&tval, NULL); return tval.tv_sec*1000 + tval.tv_usec/1000; #endif } void list_init(NODE *head) { head->prev = head; head->next = head; } NODE *list_next(NODE *head) { if(head->next == head) return NULL; NODE *tmp = head->next; tmp->next->prev = head; head->next=tmp->next; return tmp; } int list_add(NODE *head, NODE *node) { if(!node) return -1; node->next = head; node->prev = head->prev; head->prev->next = node; head->prev = node; return 0; } int list_num(NODE *head) { NODE * node=head; int num=0; if(!head) return 0; while(node->next!=head) { node=node->next; num++; } return num; } CCMCCRTPSink::CCMCCRTPSink(int num) { MEM_NODE *node = NULL; list_init(&m_freeList); list_init(&m_dataList); list_init(&m_missList); for(int i=0;i<num;i++) { node = AllocFreeNode(); list_add(&m_freeList,(NODE *)node); } } CCMCCRTPSink::~CCMCCRTPSink() { NODE *tmp = NULL; MEM_NODE *mem = NULL; MISS_NODE *miss = NULL; VOLOGI("%s: free remain %d\n", __FUNCTION__,list_num(&m_freeList)); VOLOGI("%s: data remain %d\n", __FUNCTION__,list_num(&m_dataList)); VOLOGI("%s: miss remain %d\n", __FUNCTION__,list_num(&m_missList)); do { tmp = list_next(&m_missList); if(!tmp) break; miss = (MISS_NODE *)tmp; delete miss; }while(1); do { tmp = list_next(&m_dataList); if(!tmp) break; mem = (MEM_NODE *)tmp; delete mem; }while(1); do { tmp = list_next(&m_freeList); if(!tmp) break; mem = (MEM_NODE *)tmp; delete mem; }while(1); } MEM_NODE * CCMCCRTPSink::AllocFreeNode() { MEM_NODE *node = new MEM_NODE; node->node.next = NULL; node->node.prev = NULL; node->size = RTP_PAYLOAD_SIZE; node->readSize = 0; memset(node->buf, 0, RTP_PAYLOAD_SIZE); return node; } int CCMCCRTPSink::InsertFreeNode(MEM_NODE *node) { voCAutoLock lock(&m_freeListLock); VOLOGI("%s: remain %d", __FUNCTION__,list_num(&m_freeList)); memset(node, 0, sizeof(MEM_NODE)); node->size = RTP_PAYLOAD_SIZE; list_add(&m_freeList, (NODE *)node); return 0; } MEM_NODE * CCMCCRTPSink::GetFreeNode() { voCAutoLock lock(&m_freeListLock); MEM_NODE *node = NULL; node = (MEM_NODE *)list_next(&m_freeList); if(!node) { VOLOGW("%s: free list is empty", __FUNCTION__); node = AllocFreeNode(); } return node; } int CCMCCRTPSink::InsertDataNode(MEM_NODE *node) { voCAutoLock lock(&m_dataListLock); return list_add(&m_dataList, (NODE *)node); } MEM_NODE * CCMCCRTPSink::GetDataNode() { voCAutoLock lock(&m_dataListLock); return (MEM_NODE *)list_next(&m_dataList); } int CCMCCRTPSink::InsertMissNode(MISS_NODE *node) { voCAutoLock lock(&m_missListLock); return list_add(&m_missList, (NODE *)node); } MISS_NODE * CCMCCRTPSink::GetMissNode() { voCAutoLock lock(&m_missListLock); return (MISS_NODE *)list_next(&m_missList); } MISS_NODE * CCMCCRTPSink::FindAndGetMissNode(unsigned short index) { voCAutoLock lock(&m_missListLock); NODE *tmp = m_missList.next; /*while(tmp != &m_missList) { if(tmp->index == index) { tmp->prev->next = tmp->next; tmp->next->prev = tmp->prev; return tmp; } tmp = tmp->next; }*/ return NULL; }
cac5f2722b8386466480214097e7003f72d6a62e
fd09451d2f030609f4a9fc44c2a2bf8f41c17317
/src/external/murmur3.cpp
5047a39f1a3f767044bbc2d562a6c275aa5febbf
[]
no_license
mghosh4/CompactionSimulator
c870e126e43c251f3d73df6dc54bb779ab35a9e0
3390b27c9a92565fdc37f81206063d1118e85247
refs/heads/master
2021-01-23T16:40:02.007653
2014-12-31T04:45:55
2014-12-31T04:45:55
null
0
0
null
null
null
null
UTF-8
C++
false
false
165
cpp
murmur3.cpp
#include <stdio.h> #include "murmur3.h" void MurmurHash3Wrpr( const void * key, int len, uint32_t seed, void * out ) { MurmurHash3_x86_32(key, len, seed, out); }
2a9f18ac3b06ae3ee660d6cd227ae2f915fbe3ea
48021421682126f38de1ae3af13c64bc83f6d250
/onion-path-finder/src/utils/oracle-network.h
8a69fda68207990f9483c3107ab784ead351d640
[ "Apache-2.0" ]
permissive
AdrianAntunez/DTN-Onion-Routing-NS-3
c6346972a8347ad60b8e5900b3cc6927d170937e
91e16826c0fe55dbdcd81473ab3c4ca0b3ede244
refs/heads/master
2021-05-01T19:43:20.021542
2016-01-19T14:07:39
2016-01-19T14:07:39
32,728,017
0
0
null
null
null
null
UTF-8
C++
false
false
1,975
h
oracle-network.h
/** * @copyright * Copyright (C) 2016 Universitat Autònoma de Barcelona * Department of Information and Communications Engineering * @file oracle-network.h * @author Adrian Antunez * @date Created on: 26 May 2015 */ #ifndef ORACLENETWORK_H_ #define ORACLENETWORK_H_ #include "graph-util.h" /** * @brief The OracleNetwork class Implements the exploration methods used by a communication source to find multiple possible paths to destination according * to characteristics given as parameters. */ class OracleNetwork : public GraphUtil { public: /** * @brief Default Constructor. */ OracleNetwork(); /** * @brief Parametized Constructor. * @param nodes: Graph representation. */ OracleNetwork(Nodes nodes, nodeid source, nodeid destination, uint32_t startTime, uint32_t numPaths, uint32_t numNodes, uint32_t transmissionTime, bool noCycles); /** * @brief Destructor */ virtual ~OracleNetwork(); /** * @brief getPaths: iteraritve search of multiple paths meeting specified conditions given by parameters. * * @param source: source node. * @param destination: destination node. * @param time: starting time. * @param numPaths: number of paths to return. * @param numNodes: number of nodes per path (path length). * @param transmissionTime: time spent * @return PathVector */ virtual PathVector getPaths(); private: /** * @brief getPathsRecursive: Recursively explore paths increasing time at each hop * @param currentPath: explored nodes up to this point. * @param time: time left for path exploration. * @return array with explored paths meeting conditions. */ virtual PathVector getPathsRecursive(Path currentPath, uint32_t time); /** * @brief m_targetNode */ nodeid m_targetNode; /** * @brief m_startingTime */ uint32_t m_startingTime; }; #endif /* ORACLENETWORK_H_ */
ea7316f6a9afaf30fa0d407dfe1e3421e78423a7
60265a3101d48d796ee9755a4c025ed3f4f3b839
/algorithms/merge_sort.cpp
8b4678f12386252e70f08c22095619d0cb87ec1f
[]
no_license
khasanovaa/algorithms_and_data_structures
4243bcc247b5e6a2e0a55e81d712d1939461f83a
da4d8b3789028dc625d2d75c4fec3bc83a609217
refs/heads/master
2021-07-01T19:29:54.511304
2020-02-12T08:23:06
2020-02-12T08:23:06
151,773,853
3
1
null
2020-10-01T06:26:29
2018-10-05T20:21:35
C++
UTF-8
C++
false
false
1,128
cpp
merge_sort.cpp
#include <iostream> #include <vector> using namespace std; template<typename It, typename d> d merge(It begin1, It end1, It begin2, It end2, d first) { while (begin1 != end1 && begin2 != end2) { if (*begin1 < *begin2) { *first = *begin1; begin1++; } else { *first = *begin2; begin2++; } first++; } while (begin2 != end2) { *first = *begin2; first++; begin2++; } while (begin1 != end1) { *first = *begin1; first++; begin1++; } return first; } template<typename it> void msort(it first, it last) { if (last - first == 1) return; int m = (last - first) / 2; msort(first, first + m); msort(first + m, last); int *dm = new int[last - first]; merge(first, first + m, first + m, last, dm); int i = 0; for (first; first != last; first++) { *first = dm[i]; i++; } delete[] dm; return; } int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int n = 0; cin >> n; if (n == 0) return 0; vector <int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } msort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { cout << v[i] << ' '; } }
f51b60297c31e42321405056d1e8318ebfd15aaa
8ec968525f3551ce5550c22edc013d62a2dc44cf
/leetcode submissions/algorithms/Continuous Subarray Sum.cpp
076236de93ca7de7ceb7f4386dd22bb21b90277d
[]
no_license
manishankarbalu/CampusPlacement
5f0abec05ee78462b34d20c3c6456320dadade16
905fb2ece09b2314b58b5d5eae4920bcf2c07a62
refs/heads/master
2023-05-30T20:57:59.140557
2020-03-19T10:05:04
2020-03-19T10:05:04
115,243,914
4
1
null
2020-03-19T10:05:07
2017-12-24T06:11:36
C++
UTF-8
C++
false
false
935
cpp
Continuous Subarray Sum.cpp
class Solution { public: bool func1(vector<int>& nums, int k,int l,int r) { if(r-l<2) return false; int sum=0; for(int i=l;i<r;i++) sum+=nums[i]; if(sum==0 && k==0) return true; else if(sum!=0 && k==0) return false; else if(sum%k==0 ) return true; else return func1(nums,k,l+1,r) || func1(nums,k,l,r-1); } bool checkSubarraySum(vector<int>& nums, int k) { //return func1(nums,k,0,nums.size()); set<int> s; int sum=0;int pre=0; for(int i=0;i<nums.size();i++) { sum+=nums[i]; int mod= (k==0)? sum: sum%k; if(s.count(mod)) return true; s.insert(pre); pre=mod; } return false; } };
985a2613ae607e233a4bb2cf4de909f8df982ad2
fadf7624a65da71173b3d5dea510fc50ecbe7321
/Dialog/Dialog_ModelInformation.h
149d4b613866bc14c4bf66e958ec6ec3389f7c23
[ "MIT" ]
permissive
aCrazyCoder/Finite_Element
a329fd8c5874606d050925a8db07ae434e5a0c08
42d296a88ab23df62955569261c4948dbd93d79b
refs/heads/master
2020-03-29T18:40:50.041793
2018-09-25T07:47:33
2018-09-25T07:47:33
150,226,224
3
0
null
null
null
null
UTF-8
C++
false
false
1,023
h
Dialog_ModelInformation.h
#ifndef DIALOG_MODELINFORMATION_H #define DIALOG_MODELINFORMATION_H /* * brief: 模型信息对话框 * auther: Shao Xingchen * version: v1.0 * date: 2018年1月4日 * note: */ #include <QWidget> #include <QPushButton> #include <QLabel> #include <QLayout> #include <QString> #include <QIcon> #include "Global/Global_Variable.h" class Dialog_ModelInformation : public QWidget { Q_OBJECT public: explicit Dialog_ModelInformation(QWidget *parent = nullptr); ~Dialog_ModelInformation(); signals: public slots: private: QLabel *classification; QLabel *SegmentationUnit; QLabel *ModelInfo; QLabel *MaxStrain; QLabel *MaxStrainInfo; QLabel *MinStrain; QLabel *MinStrainInfo; QLabel *MaxStress; QLabel *MaxStressInfo; QLabel *MinStress; QLabel *MinStressInfo; QLabel *MaxShift; QLabel *MaxShiftInfo; QLabel *MinShift; QLabel *MinShiftInfo; QPushButton *sureBtn; QGridLayout *mainLayout; }; #endif // DIALOG_MODELINFORMATION_H
c29fe90695d17003c603892fab79bf4e87c04e26
48c3101da2a27e0d46086b51f67f9a96a17ced68
/cpp/flags.h
e895cfa455858e9b3211d57f920b5c5180684a62
[ "ISC" ]
permissive
jlguenego/node-expose-sspi
5e5aead713ab5fc342cbd9b9e342eda7ce996ff6
ebbe3046e6b346ee7cf9cfd6c6d0dc3b72fb115e
refs/heads/master
2023-01-24T02:51:22.270949
2023-01-18T11:39:59
2023-01-18T11:39:59
234,580,010
114
22
ISC
2023-01-18T11:40:00
2020-01-17T15:44:04
C++
UTF-8
C++
false
false
1,144
h
flags.h
#include <string> #include "napi.h" // context flag #define GETFLAG_EXTENDED_NAME_FORMAT 0 #define ACCESS_TOKEN_FLAGS 1 #define ASC_REQ_FLAGS 2 #define ISC_REQ_FLAGS 3 #define ASC_RET_FLAGS 4 #define ISC_RET_FLAGS 5 #define SECURITY_DREP_FLAGS 6 #define CREDENTIAL_USE_FLAG 7 #define ADS_AUTHENTICATION_FLAGS 8 #define COINIT_FLAGS 9 #define COMPUTER_NAME_FORMAT_FLAGS 10 #define USER_INFO_1_FLAGS 11 #define USER_PRIVILEGE_FLAGS 12 #define EWX_FLAGS 13 #define SHTDN_FLAGS 14 namespace myAddon { void initFlags(); int64_t getFlagValue(Napi::Env env, int context, std::string str); int64_t getFlags(Napi::Env env, int context, Napi::Array flagArray, int64_t defaultFlags = 0); int64_t getFlags(Napi::Env env, int context, Napi::Object input, std::string value, int64_t defaultFlags = 0); int64_t getFlag(Napi::Env env, int context, Napi::String flagStr, int64_t defaultFlags); int64_t getFlag(Napi::Env env, int context, Napi::Object input, std::string value, int64_t defaultFlags); Napi::Array setFlags(Napi::Env env, int context, int64_t flags); } // namespace myAddon
e408702245f249f29de59240e7e493f20051e24e
3a8408aefe35580e4c1f6a4ac3d22c8bf41827af
/kuka/other/robot_interface_definition/include/robot_interface_definition/robot_interface.h
e9b68b34b855942f5032a4e732a918ade158ae70
[]
no_license
Hankfirst/neurobots_demonstrator
df9cc2b44785da6866fb8161bd9ac4811f886009
b77fadce8054163899ff7ca65d2d4417441649f0
refs/heads/master
2021-09-24T22:04:15.493990
2018-10-15T13:27:20
2018-10-15T13:27:20
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,186
h
robot_interface.h
/* * Copyright (c) 2016 Daniel Kuhner <kuhnerd@informatik.uni-freiburg.de>. * All rights reserved. * * Created on: Jun 9, 2016 * Author: Daniel Kuhner <kuhnerd@informatik.uni-freiburg.de> * Filename: robot_interface.h */ #ifndef ROBOT_INTERFACE_H_ #define ROBOT_INTERFACE_H_ #include <Eigen/Geometry> #include <vector> namespace robot_interface_definition { class RobotInterface { public: RobotInterface() { } virtual ~RobotInterface() { } /** * Implement this method in your planner. * The frame of 'goal' is 'world' */ virtual bool plan(const Eigen::Affine3d& goal) { return true; } /** * Can be used for, e.g., pouring */ virtual bool plan(const std::vector<std::string>& params) { return true; } virtual bool execute() { return true; } virtual bool grasp(const std::string& object) { return true; } virtual bool drop(const std::string& object, const Eigen::Affine3d& pose) { return true; } //Only used to activate/deactivate the prm planners virtual bool activate() { return true; } virtual bool deactivate() { return true; } }; } /* namespace robot_interface */ #endif /* ROBOT_INTERFACE_H_ */
81848de696552e6737ab6fdfaa380155de43e498
b7b8083156d2bd7502a1d38d709c408cf0c917ef
/semester1/hw2/2.2/main.cpp
d7ed427f5a4da9799d5a8a4064163ec37be6b275
[]
no_license
rprtr258/spbsu-programming
7e74f24ffbda4952409ddcef2f94b6430641a592
43123373a11c91a4fe79eadde17b6ff6677ebcce
refs/heads/master
2022-01-11T21:37:45.034246
2019-06-10T23:58:54
2019-06-10T23:58:54
105,365,570
0
0
null
2019-06-10T08:14:37
2017-09-30T11:31:55
Java
UTF-8
C++
false
false
569
cpp
main.cpp
#include <stdio.h> int pow(const int &base, const int &degree) { if (degree == 0) return 1; if (degree == 1) return base; if (degree == 2) return base * base; if (degree % 2 == 1) return base * pow(pow(base, degree / 2), 2); // degree % 2 == 0 return pow(pow(base, degree / 2), 2); } int main() { printf("Write base and degree:\n"); int base = 0; int degree = 0; scanf("%d %d", &base, &degree); int result = pow(base, degree); printf("%d**%d = %d", base, degree, result); return 0; }
71ae6ea25e66ca440895871b5307830f7df0b335
afd455d3a5a2b8a0f3d57f80aec1861846e9b958
/draft/comunication_client_serveur/client/co_client/co_client/debug.h
16e320c97a1e20a975322d8bddcfba66767caeaa
[]
no_license
martiall99/Pro3600-RPG-
d28dd9da62445108c7d45eb196889baad991159a
0b344f407acc9216766c89eb0ff4fdcb774c4952
refs/heads/master
2021-01-17T17:00:32.702724
2016-05-14T13:20:50
2016-05-14T13:20:50
null
0
0
null
null
null
null
UTF-8
C++
false
false
171
h
debug.h
#ifndef debug #include <iostream> #include <string> void debug(std::string mess, bool stop = false); std::string coupeChaine(std::string &ch, char a); #endif // !debug
3eb5a90292be5d3be5127248b5f0f0007fc298d9
6886fbbee272b224ef929e96200d516e43c07fc1
/libraries/arduino_NFC/examples/read_mifare/read_mifare.ino
011ec8c229f112fbdfe8eb58045f8a28f36577d1
[]
no_license
manorius/Arduino
db91b67e6e8ec5f39ce3ed2e6785e57cef469a8f
ca971a49d27089405200819f85ff5d9b77dd0f7e
refs/heads/master
2021-01-24T03:43:54.646095
2017-03-04T17:40:10
2017-03-04T17:40:10
44,327,197
0
0
null
null
null
null
UTF-8
C++
false
false
2,747
ino
read_mifare.ino
/**************************************************************************/ /*! @file read_mifare.pde @author odopod thisispete @license This file shows how to initialize either the SPI or I2C versions of the pn532 development sheilds and read a mifare tag. */ /**************************************************************************/ //compiler complains if you don't include this even if you turn off the I2C.h //@TODO: look into how to disable completely //#include <Wire.h> //I2C: //#include <PN532_I2C.h> #define IRQ 2 #define RESET 3 PN532 * board = new PN532_I2C(IRQ, RESET); //end I2C --> //SPI: //#include <PN532_SPI.h> // //#define SCK 13 //#define MOSI 11 //#define SS 10 //#define MISO 12 // //PN532 * board = new PN532_SPI(SCK, MISO, MOSI, SS); //end SPI --> //#include <Mifare.h> Mifare mifare; //init keys for reading classic uint8_t Mifare::useKey = KEY_A; uint8_t Mifare::keyA[6] = {0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 }; uint8_t Mifare::keyB[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; uint32_t Mifare::cardType = 0; //will get overwritten if it finds a different card //#include <NDEF.h> #define PAYLOAD_SIZE 224 uint8_t payload[PAYLOAD_SIZE] = {}; void setup(void) { Serial.begin(115200); board->begin(); uint32_t versiondata = board->getFirmwareVersion(); if (! versiondata) { Serial.println("err"); while (1); // halt } // Got ok data, print it out! Serial.print("5");Serial.println((versiondata>>24) & 0xFF, HEX); // Serial.print("v: "); Serial.println((versiondata>>16) & 0xFF, DEC); // Serial.println((versiondata>>8) & 0xFF, DEC); // Serial.print("Supports "); Serial.println(versiondata & 0xFF, HEX); if(mifare.SAMConfig()){ Serial.println("ok"); }else{ Serial.println("er"); } } void loop(void) { uint8_t * uid = mifare.readTarget(); if(uid){ Serial.println(Mifare::cardType == MIFARE_CLASSIC ?"Classic" : "Ultralight"); memset(payload, 0, PAYLOAD_SIZE); //read mifare.readPayload(payload, PAYLOAD_SIZE); FOUND_MESSAGE m = NDEF().decode_message(payload); switch(m.type){ case NDEF_TYPE_URI: Serial.print("URI: "); Serial.println((int)m.format); Serial.println((char*) m.payload); break; case NDEF_TYPE_TEXT: Serial.print("TEXT: "); Serial.println(m.format); Serial.println((char*)m.payload); break; case NDEF_TYPE_MIME: Serial.print("MIME: "); Serial.println(m.format); Serial.println((char*)m.payload); break; default: Serial.println("unsupported"); break; } } delay(5000); }
bbbfa1287760f5e2ccb199a5ffce11f42919e6fd
102beccb4a386876dfeaea493209537c9a0db742
/RexLogicModule/Environment/PrimMesher.cpp
8a7d170b7ee19958ec2d7efbd25a2efecfb10677
[ "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
Chiru/naali
cc4150241d37849dde1b9a1df983e41a53bfdab1
b0fb756f6802ac09a7cd9733e24e4db37d5c1b7e
refs/heads/master
2020-12-25T05:03:47.606650
2010-09-16T14:08:42
2010-09-17T08:34:19
1,290,932
1
1
null
null
null
null
UTF-8
C++
false
false
63,534
cpp
PrimMesher.cpp
// For conditions of distribution and use, see copyright notice in license.txt // Based on PrimMesher project, converted from C# to C++ /* * Copyright (c) Contributors * See CONTRIBUTORS.TXT for a full list of copyright holders. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 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. * * Neither the name of the OpenSim Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 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. */ /* CONTRIBUTORS.TXT The primary developer of PrimMesher is Dahlia Trimble. Some portions of PrimMesher are from the following projects: * OpenSimulator (original extrusion concept) * LibOpenMetaverse (quaternion multiplication routine) */ #include "StableHeaders.h" #include "Environment/PrimMesher.h" #include "CoreMath.h" #include "CoreException.h" namespace PrimMesher { Angle angles3[] = { Angle(0.0f, 1.0f, 0.0f), Angle(0.33333333333333333f, -0.5f, 0.86602540378443871f), Angle(0.66666666666666667f, -0.5f, -0.86602540378443837f), Angle(1.0f, 1.0f, 0.0f) }; Coord normals3[] = { Coord(0.25f, 0.4330127019f, 0.0f).Normalize(), Coord(-0.5f, 0.0f, 0.0f).Normalize(), Coord(0.25f, -0.4330127019f, 0.0f).Normalize(), Coord(0.25f, 0.4330127019f, 0.0f).Normalize() }; Angle angles4[] = { Angle(0.0f, 1.0f, 0.0f), Angle(0.25f, 0.0f, 1.0f), Angle(0.5f, -1.0f, 0.0f), Angle(0.75f, 0.0f, -1.0f), Angle(1.0f, 1.0f, 0.0f) }; Coord normals4[] = { Coord(0.5f, 0.5f, 0.0f).Normalize(), Coord(-0.5f, 0.5f, 0.0f).Normalize(), Coord(-0.5f, -0.5f, 0.0f).Normalize(), Coord(0.5f, -0.5f, 0.0f).Normalize(), Coord(0.5f, 0.5f, 0.0f).Normalize() }; Angle angles24[] = { Angle(0.0f, 1.0f, 0.0f), Angle(0.041666666666666664f, 0.96592582628906831f, 0.25881904510252074f), Angle(0.083333333333333329f, 0.86602540378443871f, 0.5f), Angle(0.125f, 0.70710678118654757f, 0.70710678118654746f), Angle(0.16666666666666667f, 0.5f, 0.8660254037844386f), Angle(0.20833333333333331f, 0.25881904510252096f, 0.9659258262890682f), Angle(0.25f, 0.0f, 1.0f), Angle(0.29166666666666663f, -0.25881904510252063f, 0.96592582628906831f), Angle(0.33333333333333333f, -0.5f, 0.86602540378443871f), Angle(0.375f, -0.70710678118654746f, 0.70710678118654757f), Angle(0.41666666666666663f, -0.86602540378443849f, 0.5f), Angle(0.45833333333333331f, -0.9659258262890682f, 0.25881904510252102f), Angle(0.5f, -1.0f, 0.0f), Angle(0.54166666666666663f, -0.96592582628906842f, -0.25881904510252035f), Angle(0.58333333333333326f, -0.86602540378443882f, -0.5f), Angle(0.62499999999999989f, -0.70710678118654791f, -0.70710678118654713f), Angle(0.66666666666666667f, -0.5f, -0.86602540378443837f), Angle(0.70833333333333326f, -0.25881904510252152f, -0.96592582628906809f), Angle(0.75f, 0.0f, -1.0f), Angle(0.79166666666666663f, 0.2588190451025203f, -0.96592582628906842f), Angle(0.83333333333333326f, 0.5f, -0.86602540378443904f), Angle(0.875f, 0.70710678118654735f, -0.70710678118654768f), Angle(0.91666666666666663f, 0.86602540378443837f, -0.5f), Angle(0.95833333333333326f, 0.96592582628906809f, -0.25881904510252157f), Angle(1.0f, 1.0f, 0.0f) }; static const float twoPi = 2.0f * (float)PI; Quat::Quat() { X = 0.0f; Y = 0.0f; Z = 0.0f; W = 1.0f; } Quat::Quat(float x, float y, float z, float w) { X = x; Y = y; Z = z; W = w; } Quat::Quat(const Coord& axis, float angle) { Coord axisNorm = axis; axisNorm.Normalize(); angle *= 0.5f; float c = (float)cos(angle); float s = (float)sin(angle); X = axisNorm.X * s; Y = axisNorm.Y * s; Z = axisNorm.Z * s; W = c; Normalize(); } float Quat::Length() { return (float)sqrt(X * X + Y * Y + Z * Z + W * W); } Quat& Quat::Normalize() { const float MAG_THRESHOLD = 0.0000001f; float mag = Length(); // Catch very small rounding errors when normalizing if (mag > MAG_THRESHOLD) { float oomag = 1.0f / mag; X *= oomag; Y *= oomag; Z *= oomag; W *= oomag; } else { X = 0.0f; Y = 0.0f; Z = 0.0f; W = 1.0f; } return *this; } Coord::Coord() { X = 0.0f; Y = 0.0f; Z = 0.0f; } Coord::Coord(float x, float y, float z) { X = x; Y = y; Z = z; } float Coord::Length() { return (float)sqrt(X * X + Y * Y + Z * Z); } Coord& Coord::Invert() { X = -X; Y = -Y; Z = -Z; return *this; } Coord& Coord::Normalize() { const float MAG_THRESHOLD = 0.0000001f; float mag = Length(); // Catch very small rounding errors when normalizing if (mag > MAG_THRESHOLD) { float oomag = 1.0f / mag; X *= oomag; Y *= oomag; Z *= oomag; } else { X = 0.0f; Y = 0.0f; Z = 0.0f; } return *this; } Coord Coord::Cross(const Coord& c1, const Coord& c2) { return Coord( c1.Y * c2.Z - c2.Y * c1.Z, c1.Z * c2.X - c2.Z * c1.X, c1.X * c2.Y - c2.X * c1.Y ); } UVCoord::UVCoord() { U = 0.0f; V = 0.0f; } UVCoord::UVCoord(float u, float v) { U = u; V = v; } UVCoord UVCoord::Flip() { return UVCoord(1.0f - U, 1.0f - V); } Face::Face() { primFace = 0; v1 = 0; v2 = 0; v3 = 0; n1 = 0; n2 = 0; n3 = 0; uv1 = 0; uv2 = 0; uv3 = 0; } Face::Face(int pv1, int pv2, int pv3) { primFace = 0; v1 = pv1; v2 = pv2; v3 = pv3; n1 = 0; n2 = 0; n3 = 0; uv1 = 0; uv2 = 0; uv3 = 0; } Face::Face(int pv1, int pv2, int pv3, int pn1, int pn2, int pn3) { primFace = 0; v1 = pv1; v2 = pv2; v3 = pv3; n1 = pn1; n2 = pn2; n3 = pn3; uv1 = 0; uv2 = 0; uv3 = 0; } Coord Face::SurfaceNormal(const std::vector<Coord>& coordList) { const Coord& c1 = coordList[v1]; const Coord& c2 = coordList[v2]; const Coord& c3 = coordList[v3]; Coord edge1 = Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z); Coord edge2 = Coord(c3.X - c1.X, c3.Y - c1.Y, c3.Z - c1.Z); return Coord::Cross(edge1, edge2).Normalize(); } ViewerFace::ViewerFace() { primFaceNumber = 0; } ViewerFace::ViewerFace(int pprimFaceNumber) { primFaceNumber = pprimFaceNumber; } void ViewerFace::Scale(float x, float y, float z) { v1.X *= x; v1.Y *= y; v1.Z *= z; v2.X *= x; v2.Y *= y; v2.Z *= z; v3.X *= x; v3.Y *= y; v3.Z *= z; } void ViewerFace::AddRot(const Quat& q) { v1 *= q; v2 *= q; v3 *= q; n1 *= q; n2 *= q; n3 *= q; } void ViewerFace::CalcSurfaceNormal() { Coord edge1(v2.X - v1.X, v2.Y - v1.Y, v2.Z - v1.Z); Coord edge2(v3.X - v1.X, v3.Y - v1.Y, v3.Z - v1.Z); n1 = n2 = n3 = Coord::Cross(edge1, edge2).Normalize(); } Angle::Angle() { angle = 0; X = 0; Y = 0; } Angle::Angle(float pangle, float px, float py) { angle = pangle; X = px; Y = py; } Angle AngleList::interpolatePoints(float newPoint, const Angle& p1, const Angle& p2) { float m = (newPoint - p1.angle) / (p2.angle - p1.angle); return Angle(newPoint, p1.X + m * (p2.X - p1.X), p1.Y + m * (p2.Y - p1.Y)); } void AngleList::intersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { // ref: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ double denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1); double uaNumerator = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3); if (denom != 0.0) { double ua = uaNumerator / denom; iX = (float)(x1 + ua * (x2 - x1)); iY = (float)(y1 + ua * (y2 - y1)); } } void AngleList::makeAngles(int sides, float startAngle, float stopAngle) { angles.clear(); normals.clear(); double twoPi = PI * 2.0; float twoPiInv = 1.0f / (float)twoPi; if (sides < 1) throw Exception("number of sides not greater than zero"); if (stopAngle <= startAngle) throw Exception("stopAngle not greater than startAngle"); if ((sides == 3 || sides == 4 || sides == 24)) { startAngle *= twoPiInv; stopAngle *= twoPiInv; Angle* sourceAngles; int endAngleIndex; if (sides == 3) { sourceAngles = angles3; endAngleIndex = 3; } else if (sides == 4) { sourceAngles = angles4; endAngleIndex = 4; } else { sourceAngles = angles24; endAngleIndex = 24; } int startAngleIndex = (int)(startAngle * sides); if (stopAngle < 1.0f) endAngleIndex = (int)(stopAngle * sides) + 1; if (endAngleIndex == startAngleIndex) endAngleIndex++; for (int angleIndex = startAngleIndex; angleIndex < endAngleIndex + 1; angleIndex++) { angles.push_back(sourceAngles[angleIndex]); if (sides == 3) normals.push_back(normals3[angleIndex]); else if (sides == 4) normals.push_back(normals4[angleIndex]); } if (startAngle > 0.0f) angles[0] = interpolatePoints(startAngle, angles[0], angles[1]); if (stopAngle < 1.0f) { int lastAngleIndex = angles.size() - 1; angles[lastAngleIndex] = interpolatePoints(stopAngle, angles[lastAngleIndex - 1], angles[lastAngleIndex]); } } else { double stepSize = twoPi / sides; int startStep = (int)(startAngle / stepSize); double angle = stepSize * startStep; int step = startStep; double stopAngleTest = stopAngle; if (stopAngle < twoPi) { stopAngleTest = stepSize * ((int)(stopAngle / stepSize) + 1); if (stopAngleTest < stopAngle) stopAngleTest += stepSize; if (stopAngleTest > twoPi) stopAngleTest = twoPi; } while (angle <= stopAngleTest) { Angle newAngle; newAngle.angle = (float)angle; newAngle.X = (float)cos(angle); newAngle.Y = (float)sin(angle); angles.push_back(newAngle); step += 1; angle = stepSize * step; } if (startAngle > angles[0].angle) { Angle newAngle; intersection(angles[0].X, angles[0].Y, angles[1].X, angles[1].Y, 0.0f, 0.0f, (float)cos(startAngle), (float)sin(startAngle)); newAngle.angle = startAngle; newAngle.X = iX; newAngle.Y = iY; angles[0] = newAngle; } int index = angles.size() - 1; if (stopAngle < angles[index].angle) { Angle newAngle; intersection(angles[index - 1].X, angles[index - 1].Y, angles[index].X, angles[index].Y, 0.0f, 0.0f, (float)cos(stopAngle), (float)sin(stopAngle)); newAngle.angle = stopAngle; newAngle.X = iX; newAngle.Y = iY; angles[index] = newAngle; } } } Profile::Profile() { faceNormal = Coord(0.0f, 0.0f, 1.0f); numOuterVerts = 0; numHollowVerts = 0; bottomFaceNumber = 0; numPrimFaces = 0; } Profile::Profile(int psides, float pprofileStart, float pprofileEnd, float phollow, int phollowSides, bool pcreateFaces) { faceNormal = Coord(0.0f, 0.0f, 1.0f); numOuterVerts = 0; numHollowVerts = 0; bottomFaceNumber = 0; numPrimFaces = 0; Coord center(0.0f, 0.0f, 0.0f); std::vector<Coord>hollowCoords; std::vector<Coord>hollowNormals; std::vector<float>hollowUs; bool hasHollow = (phollow > 0.0f); bool hasProfileCut = (pprofileStart > 0.0f || pprofileEnd < 1.0f); AngleList angles; AngleList hollowAngles; float xScale = 0.5f; float yScale = 0.5f; if (psides == 4) // corners of a square are sqrt(2) from center { xScale = 0.707f; yScale = 0.707f; } float startAngle = pprofileStart * twoPi; float stopAngle = pprofileEnd * twoPi; angles.makeAngles(psides, startAngle, stopAngle); numOuterVerts = angles.angles.size(); // flag to create as few triangles as possible for 3 or 4 side profile //bool simpleFace = (psides < 5 && !(hasHollow || hasProfileCut)); bool simpleFace = (psides < 5 && !hasHollow && !hasProfileCut); if (hasHollow) { if (psides == phollowSides) hollowAngles = angles; else { hollowAngles.makeAngles(phollowSides, startAngle, stopAngle); } numHollowVerts = hollowAngles.angles.size(); } else if (!simpleFace) { coords.push_back(center); vertexNormals.push_back(Coord(0.0f, 0.0f, 1.0f)); us.push_back(0.0f); } float z = 0.0f; Angle angle; Coord newVert; if (hasHollow && phollowSides != psides) { int numHollowAngles = hollowAngles.angles.size(); for (int i = 0; i < numHollowAngles; i++) { angle = hollowAngles.angles[i]; newVert.X = phollow * xScale * angle.X; newVert.Y = phollow * yScale * angle.Y; newVert.Z = z; hollowCoords.push_back(newVert); if (phollowSides < 5) hollowNormals.push_back(hollowAngles.normals[i].Invert()); else hollowNormals.push_back(Coord(-angle.X, -angle.Y, 0.0f)); hollowUs.push_back(angle.angle * phollow); } } int index = 0; int numAngles = angles.angles.size(); for (int i = 0; i < numAngles; i++) { //int iNext = i == numAngles ? i + 1 : 0; angle = angles.angles[i]; newVert.X = angle.X * xScale; newVert.Y = angle.Y * yScale; newVert.Z = z; coords.push_back(newVert); if (psides < 5) { vertexNormals.push_back(angles.normals[i]); float u = angle.angle; us.push_back(u); } else { vertexNormals.push_back(Coord(angle.X, angle.Y, 0.0f)); us.push_back(angle.angle); } if (hasHollow) { if (phollowSides == psides) { newVert.X *= phollow; newVert.Y *= phollow; newVert.Z = z; hollowCoords.push_back(newVert); if (psides < 5) { hollowNormals.push_back(angles.normals[i].Invert()); } else hollowNormals.push_back(Coord(-angle.X, -angle.Y, 0.0f)); hollowUs.push_back(angle.angle * phollow); } } else if (!simpleFace && pcreateFaces && angle.angle > 0.0001f) { Face newFace; newFace.v1 = 0; newFace.v2 = index; newFace.v3 = index + 1; faces.push_back(newFace); } index += 1; } if (hasHollow) { std::reverse(hollowCoords.begin(), hollowCoords.end()); std::reverse(hollowNormals.begin(), hollowNormals.end()); std::reverse(hollowUs.begin(), hollowUs.end()); if (pcreateFaces) { int numOuterVerts = coords.size(); int numHollowVerts = hollowCoords.size(); int numTotalVerts = numOuterVerts + numHollowVerts; if (numOuterVerts == numHollowVerts) { Face newFace; for (int coordIndex = 0; coordIndex < numOuterVerts - 1; coordIndex++) { newFace.v1 = coordIndex; newFace.v2 = coordIndex + 1; newFace.v3 = numTotalVerts - coordIndex - 1; faces.push_back(newFace); newFace.v1 = coordIndex + 1; newFace.v2 = numTotalVerts - coordIndex - 2; newFace.v3 = numTotalVerts - coordIndex - 1; faces.push_back(newFace); } } else { if (numOuterVerts < numHollowVerts) { Face newFace; int j = 0; // j is the index for outer vertices int maxJ = numOuterVerts - 1; for (int i = 0; i < numHollowVerts; i++) // i is the index for inner vertices { if (j < maxJ) if (angles.angles[j + 1].angle - hollowAngles.angles[i].angle < hollowAngles.angles[i].angle - angles.angles[j].angle + 0.000001f) { newFace.v1 = numTotalVerts - i - 1; newFace.v2 = j; newFace.v3 = j + 1; faces.push_back(newFace); j += 1; } newFace.v1 = j; newFace.v2 = numTotalVerts - i - 2; newFace.v3 = numTotalVerts - i - 1; faces.push_back(newFace); } } else // numHollowVerts < numOuterVerts { Face newFace; int j = 0; // j is the index for inner vertices int maxJ = numHollowVerts - 1; for (int i = 0; i < numOuterVerts; i++) { if (j < maxJ) if (hollowAngles.angles[j + 1].angle - angles.angles[i].angle < angles.angles[i].angle - hollowAngles.angles[j].angle + 0.000001f) { newFace.v1 = i; newFace.v2 = numTotalVerts - j - 2; newFace.v3 = numTotalVerts - j - 1; faces.push_back(newFace); j += 1; } newFace.v1 = numTotalVerts - j - 1; newFace.v2 = i; newFace.v3 = i + 1; faces.push_back(newFace); } } } } coords.insert(coords.end(), hollowCoords.begin(), hollowCoords.end()); vertexNormals.insert(vertexNormals.end(), hollowNormals.begin(), hollowNormals.end()); us.insert(us.end(), hollowUs.begin(), hollowUs.end()); } if (simpleFace && pcreateFaces) { if (psides == 3) faces.push_back(Face(0, 1, 2)); else if (psides == 4) { faces.push_back(Face(0, 1, 2)); faces.push_back(Face(0, 2, 3)); } } if (hasProfileCut) { if (hasHollow) { int lastOuterVertIndex = numOuterVerts - 1; cutNormal1.X = coords[0].Y - coords[coords.size() - 1].Y; cutNormal1.Y = -(coords[0].X - coords[coords.size() - 1].X); cutNormal2.X = coords[lastOuterVertIndex + 1].Y - coords[lastOuterVertIndex].Y; cutNormal2.Y = -(coords[lastOuterVertIndex + 1].X - coords[lastOuterVertIndex].X); } else { cutNormal1.X = vertexNormals[1].Y; cutNormal1.Y = -vertexNormals[1].X; cutNormal2.X = -vertexNormals[vertexNormals.size() - 2].Y; cutNormal2.Y = vertexNormals[vertexNormals.size() - 2].X; } cutNormal1.Normalize(); cutNormal2.Normalize(); } MakeFaceUVs(); hollowCoords.clear(); hollowNormals.clear(); hollowUs.clear(); // calculate prim face numbers // I know it's ugly but so is the whole concept of prim face numbers int faceNum = 1; int startVert = hasProfileCut && !hasHollow ? 1 : 0; if (startVert > 0) faceNumbers.push_back(0); for (int i = 0; i < numOuterVerts; i++) faceNumbers.push_back(psides < 5 ? faceNum++ : faceNum); if (psides > 4) faceNum++; if (hasProfileCut) faceNumbers.push_back(0); for (int i = 0; i < numHollowVerts; i++) //faceNumbers.push_back(faceNum++); faceNumbers.push_back(phollowSides < 5 ? faceNum++ : faceNum); bottomFaceNumber = faceNum++; if (hasHollow && hasProfileCut) faceNumbers.push_back(faceNum++); for (int i = 0; i < faceNumbers.size(); i++) if (faceNumbers[i] == 0) faceNumbers[i] = faceNum++; numPrimFaces = faceNum; } void Profile::MakeFaceUVs() { faceUVs.clear(); for (unsigned i = 0; i < coords.size(); ++i) { const Coord& c = coords[i]; faceUVs.push_back(UVCoord(1.0f - (0.5f + c.X), 1.0f - (0.5f - c.Y))); } } void Profile::AddPos(Coord v) { AddPos(v.X, v.Y, v.Z); } void Profile::AddPos(float x, float y, float z) { int i; int numVerts = coords.size(); Coord vert; for (i = 0; i < numVerts; i++) { vert = coords[i]; vert.X += x; vert.Y += y; vert.Z += z; coords[i] = vert; } } void Profile::AddRot(Quat q) { int i; int numVerts = coords.size(); for (i = 0; i < numVerts; i++) coords[i] *= q; int numNormals = vertexNormals.size(); for (i = 0; i < numNormals; i++) vertexNormals[i] *= q; faceNormal *= q; cutNormal1 *= q; cutNormal2 *= q; } void Profile::Scale(float x, float y) { int i; int numVerts = coords.size(); Coord vert; for (i = 0; i < numVerts; i++) { vert = coords[i]; vert.X *= x; vert.Y *= y; coords[i] = vert; } } /// <summary> /// Changes order of the vertex indices and negates the center vertex normal. Does not alter vertex normals of radial vertices /// </summary> void Profile::FlipNormals() { int i; int numFaces = faces.size(); Face tmpFace; int tmp; for (i = 0; i < numFaces; i++) { tmpFace = faces[i]; tmp = tmpFace.v3; tmpFace.v3 = tmpFace.v1; tmpFace.v1 = tmp; faces[i] = tmpFace; } int normalCount = vertexNormals.size(); if (normalCount > 0) { Coord n = vertexNormals[normalCount - 1]; n.Z = -n.Z; vertexNormals[normalCount - 1] = n; } faceNormal.X = -faceNormal.X; faceNormal.Y = -faceNormal.Y; faceNormal.Z = -faceNormal.Z; int numfaceUVs = faceUVs.size(); for (i = 0; i < numfaceUVs; i++) { UVCoord uv = faceUVs[i]; uv.V = 1.0f - uv.V; faceUVs[i] = uv; } } void Profile::AddValue2FaceVertexIndices(int num) { int numFaces = faces.size(); Face tmpFace; for (int i = 0; i < numFaces; i++) { tmpFace = faces[i]; tmpFace.v1 += num; tmpFace.v2 += num; tmpFace.v3 += num; faces[i] = tmpFace; } } void Profile::AddValue2FaceNormalIndices(int num) { int numFaces = faces.size(); Face tmpFace; for (int i = 0; i < numFaces; i++) { tmpFace = faces[i]; tmpFace.n1 += num; tmpFace.n2 += num; tmpFace.n3 += num; faces[i] = tmpFace; } } PrimMesh::PrimMesh() { sides = 4; hollowSides = 4; profileStart = 0.0f; profileEnd = 1.0f; hollow = 0.0f; twistBegin = 0; twistEnd = 0; topShearX = 0.0f; topShearY = 0.0f; pathCutBegin = 0.0f; pathCutEnd = 1.0f; dimpleBegin = 0.0f; dimpleEnd = 1.0f; skew = 0.0f; holeSizeX = 1.0f; // called pathScaleX in pbs holeSizeY = 0.25f; taperX = 0.0f; taperY = 0.0f; radius = 0.0f; revolutions = 1.0f; // Reduced prim lod stepsPerRevolution = 12; //stepsPerRevolution = 24; hasProfileCut = false; hasHollow = false; normalsProcessed = false; viewerMode = true; numPrimFaces = 0; } /// <summary> /// Constructs a PrimMesh object and creates the profile for extrusion. /// </summary> /// <param name="psides"></param> /// <param name="pprofileStart"></param> /// <param name="pprofileEnd"></param> /// <param name="phollow"></param> /// <param name="phollowSides"></param> PrimMesh::PrimMesh(int psides, float pprofileStart, float pprofileEnd, float phollow, int phollowSides) { sides = psides; hollowSides = phollowSides; profileStart = pprofileStart; profileEnd = pprofileEnd; hollow = phollow; twistBegin = 0; twistEnd = 0; topShearX = 0.0f; topShearY = 0.0f; pathCutBegin = 0.0f; pathCutEnd = 1.0f; dimpleBegin = 0.0f; dimpleEnd = 1.0f; skew = 0.0f; holeSizeX = 1.0f; // called pathScaleX in pbs holeSizeY = 0.25f; taperX = 0.0f; taperY = 0.0f; radius = 0.0f; revolutions = 1.0f; // Reduced prim lod stepsPerRevolution = 12; //stepsPerRevolution = 24; hasProfileCut = false; hasHollow = false; normalsProcessed = false; viewerMode = true; numPrimFaces = 0; if (sides < 3) sides = 3; if (hollowSides < 3) hollowSides = 3; if (profileStart < 0.0f) profileStart = 0.0f; if (profileEnd > 1.0f) profileEnd = 1.0f; if (profileEnd < 0.02f) profileEnd = 0.02f; if (profileStart >= profileEnd) profileStart = profileEnd - 0.02f; if (hollow > 0.99f) hollow = 0.99f; if (hollow < 0.0f) hollow = 0.0f; hasProfileCut = (profileStart > 0.0f || profileEnd < 1.0f); hasHollow = (hollow > 0.001f); } /// <summary> /// Extrudes a profile along a straight line path. Used for prim types box, cylinder, and prism. /// </summary> void PrimMesh::ExtrudeLinear() { coords.clear(); faces.clear(); normals.clear(); viewerFaces.clear(); int step = 0; int steps = 1; float length = pathCutEnd - pathCutBegin; normalsProcessed = false; if (viewerMode && sides == 3) { // prisms don't taper well so add some vertical resolution // other prims may benefit from this but just do prisms for now if (abs(taperX) > 0.01 || abs(taperY) > 0.01) steps = (int)(steps * 4.5 * length); } float twistBegin = this->twistBegin / 360.0f * twoPi; float twistEnd = this->twistEnd / 360.0f * twoPi; float twistTotal = twistEnd - twistBegin; float twistTotalAbs = abs(twistTotal); if (twistTotalAbs > 0.01f) steps += (int)(twistTotalAbs * 3.66); // dahlia's magic number // Reduced prim lod: cap maximum steps if (steps > 24) steps = 24; float start = -0.5f; float stepSize = length / (float)steps; float percentOfPathMultiplier = stepSize; float xProfileScale = 1.0f; float yProfileScale = 1.0f; float xOffset = 0.0f; float yOffset = 0.0f; float zOffset = start; float xOffsetStepIncrement = topShearX / steps; float yOffsetStepIncrement = topShearY / steps; float percentOfPath = pathCutBegin; zOffset += percentOfPath; float hollow = this->hollow; // sanity checks float initialProfileRot = 0.0f; if (sides == 3) { if (hollowSides == 4) { if (hollow > 0.7f) hollow = 0.7f; hollow *= 0.707f; } else hollow *= 0.5f; } else if (sides == 4) { initialProfileRot = 1.25f * (float)PI; if (hollowSides != 4) hollow *= 0.707f; } // Support also 12 side reduced lod else if ((sides == 24 && hollowSides == 4) || (sides == 12 && hollowSides == 4)) hollow *= 1.414f; Profile profile(sides, profileStart, profileEnd, hollow, hollowSides, true); numPrimFaces = profile.numPrimFaces; int cut1Vert = -1; int cut2Vert = -1; if (hasProfileCut) { cut1Vert = hasHollow ? profile.coords.size() - 1 : 0; cut2Vert = hasHollow ? profile.numOuterVerts - 1 : profile.numOuterVerts; } if (initialProfileRot != 0.0f) { profile.AddRot(Quat(Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); if (viewerMode) profile.MakeFaceUVs(); } Coord lastCutNormal1; Coord lastCutNormal2; float lastV = 1.0f; bool done = false; while (!done) { Profile newLayer = profile; if (taperX == 0.0f) xProfileScale = 1.0f; else if (taperX > 0.0f) xProfileScale = 1.0f - percentOfPath * taperX; else xProfileScale = 1.0f + (1.0f - percentOfPath) * taperX; if (taperY == 0.0f) yProfileScale = 1.0f; else if (taperY > 0.0f) yProfileScale = 1.0f - percentOfPath * taperY; else yProfileScale = 1.0f + (1.0f - percentOfPath) * taperY; if (xProfileScale != 1.0f || yProfileScale != 1.0f) newLayer.Scale(xProfileScale, yProfileScale); float twist = twistBegin + twistTotal * percentOfPath; if (twist != 0.0f) newLayer.AddRot(Quat(Coord(0.0f, 0.0f, 1.0f), twist)); newLayer.AddPos(xOffset, yOffset, zOffset); if (step == 0) { newLayer.FlipNormals(); // add the top faces to the viewerFaces list here if (viewerMode) { Coord faceNormal = newLayer.faceNormal; int numFaces = newLayer.faces.size(); for (int i = 0; i < numFaces; i++) { ViewerFace newViewerFace(newLayer.bottomFaceNumber); const Face& face = newLayer.faces[i]; newViewerFace.v1 = newLayer.coords[face.v1]; newViewerFace.v2 = newLayer.coords[face.v2]; newViewerFace.v3 = newLayer.coords[face.v3]; newViewerFace.n1 = faceNormal; newViewerFace.n2 = faceNormal; newViewerFace.n3 = faceNormal; newViewerFace.uv1 = newLayer.faceUVs[face.v1].Flip(); newViewerFace.uv2 = newLayer.faceUVs[face.v2].Flip(); newViewerFace.uv3 = newLayer.faceUVs[face.v3].Flip(); viewerFaces.push_back(newViewerFace); } } } // append this layer int coordsLen = coords.size(); newLayer.AddValue2FaceVertexIndices(coordsLen); coords.insert(coords.end(), newLayer.coords.begin(), newLayer.coords.end()); newLayer.AddValue2FaceNormalIndices(normals.size()); normals.insert(normals.end(), newLayer.vertexNormals.begin(), newLayer.vertexNormals.end()); if (percentOfPath < pathCutBegin + 0.01f || percentOfPath > pathCutEnd - 0.01f) faces.insert(faces.end(), newLayer.faces.begin(), newLayer.faces.end()); // fill faces between layers int numVerts = newLayer.coords.size(); Face newFace; if (step > 0) { int startVert = coordsLen + 1; int endVert = coords.size(); if (sides < 5 || hasProfileCut || hollow > 0.0f) startVert--; for (int i = startVert; i < endVert; i++) { int iNext = i + 1; if (i == endVert - 1) iNext = startVert; int whichVert = i - startVert; newFace.v1 = i; newFace.v2 = i - numVerts; newFace.v3 = iNext - numVerts; faces.push_back(newFace); newFace.v2 = iNext - numVerts; newFace.v3 = iNext; faces.push_back(newFace); if (viewerMode) { // add the side faces to the list of viewerFaces here int primFaceNum = 1; if (whichVert >= sides) primFaceNum = 2; ViewerFace newViewerFace1(primFaceNum); ViewerFace newViewerFace2(primFaceNum); float u1 = newLayer.us[whichVert]; float u2 = 1.0f; if (whichVert < newLayer.us.size() - 1) u2 = newLayer.us[whichVert + 1]; if (whichVert == cut1Vert || whichVert == cut2Vert) { u1 = 0.0f; u2 = 1.0f; } else if (sides < 5) { // boxes and prisms have one texture face per side of the prim, so the U values have to be scaled // to reflect the entire texture width u1 *= sides; u2 *= sides; u2 -= (int)u1; u1 -= (int)u1; if (u2 < 0.1f) u2 = 1.0f; //newViewerFace2.primFaceNumber = newViewerFace1.primFaceNumber = whichVert + 1; } newViewerFace1.uv1.U = u1; newViewerFace1.uv2.U = u1; newViewerFace1.uv3.U = u2; newViewerFace1.uv1.V = 1.0f - percentOfPath; newViewerFace1.uv2.V = lastV; newViewerFace1.uv3.V = lastV; newViewerFace2.uv1.U = u1; newViewerFace2.uv2.U = u2; newViewerFace2.uv3.U = u2; newViewerFace2.uv1.V = 1.0f - percentOfPath; newViewerFace2.uv2.V = lastV; newViewerFace2.uv3.V = 1.0f - percentOfPath; newViewerFace1.v1 = coords[i]; newViewerFace1.v2 = coords[i - numVerts]; newViewerFace1.v3 = coords[iNext - numVerts]; newViewerFace2.v1 = coords[i]; newViewerFace2.v2 = coords[iNext - numVerts]; newViewerFace2.v3 = coords[iNext]; // profile cut faces if (whichVert == cut1Vert) { newViewerFace1.n1 = newLayer.cutNormal1; newViewerFace1.n2 = newViewerFace1.n3 = lastCutNormal1; newViewerFace2.n1 = newViewerFace2.n3 = newLayer.cutNormal1; newViewerFace2.n2 = lastCutNormal1; } else if (whichVert == cut2Vert) { newViewerFace1.n1 = newLayer.cutNormal2; newViewerFace1.n2 = newViewerFace1.n3 = lastCutNormal2; newViewerFace2.n1 = newViewerFace2.n3 = newLayer.cutNormal2; newViewerFace2.n2 = lastCutNormal2; } else // outer and hollow faces { if ((sides < 5 && whichVert < newLayer.numOuterVerts) || (hollowSides < 5 && whichVert >= newLayer.numOuterVerts)) { newViewerFace1.CalcSurfaceNormal(); newViewerFace2.CalcSurfaceNormal(); } else { newViewerFace1.n1 = normals[i]; newViewerFace1.n2 = normals[i - numVerts]; newViewerFace1.n3 = normals[iNext - numVerts]; newViewerFace2.n1 = normals[i]; newViewerFace2.n2 = normals[iNext - numVerts]; newViewerFace2.n3 = normals[iNext]; } } newViewerFace2.primFaceNumber = newViewerFace1.primFaceNumber = newLayer.faceNumbers[whichVert]; viewerFaces.push_back(newViewerFace1); viewerFaces.push_back(newViewerFace2); } } } lastCutNormal1 = newLayer.cutNormal1; lastCutNormal2 = newLayer.cutNormal2; lastV = 1.0f - percentOfPath; // calc the step for the next iteration of the loop if (step < steps) { step += 1; percentOfPath += percentOfPathMultiplier; xOffset += xOffsetStepIncrement; yOffset += yOffsetStepIncrement; zOffset += stepSize; if (percentOfPath > pathCutEnd) done = true; } else done = true; if (done && viewerMode) { // add the top faces to the viewerFaces list here ViewerFace newViewerFace; Coord faceNormal = newLayer.faceNormal; newViewerFace.primFaceNumber = 0; int numFaces = newLayer.faces.size(); const std::vector<Face>& faces = newLayer.faces; for (int i = 0; i < numFaces; i++) { const Face& face = faces[i]; newViewerFace.v1 = newLayer.coords[face.v1 - coordsLen]; newViewerFace.v2 = newLayer.coords[face.v2 - coordsLen]; newViewerFace.v3 = newLayer.coords[face.v3 - coordsLen]; newViewerFace.n1 = faceNormal; newViewerFace.n2 = faceNormal; newViewerFace.n3 = faceNormal; newViewerFace.uv1 = newLayer.faceUVs[face.v1 - coordsLen].Flip();; newViewerFace.uv2 = newLayer.faceUVs[face.v2 - coordsLen].Flip();; newViewerFace.uv3 = newLayer.faceUVs[face.v3 - coordsLen].Flip();; viewerFaces.push_back(newViewerFace); } } } } /// <summary> /// Extrude a profile into a circular path prim mesh. Used for prim types torus, tube, and ring. /// </summary> void PrimMesh::ExtrudeCircular() { coords.clear(); faces.clear(); viewerFaces.clear(); normals.clear(); int step = 0; // Reduced prim lod int steps = 12; //int steps = 24; normalsProcessed = false; float twistBegin = this->twistBegin / 360.0f * twoPi; float twistEnd = this->twistEnd / 360.0f * twoPi; float twistTotal = twistEnd - twistBegin; // if the profile has a lot of twist, add more layers otherwise the layers may overlap // and the resulting mesh may be quite inaccurate. This method is arbitrary and doesn't // accurately match the viewer float twistTotalAbs = abs(twistTotal); if (twistTotalAbs > 0.01f) { if (twistTotalAbs > PI * 1.5f) steps *= 2; if (twistTotalAbs > PI * 3.0f) steps *= 2; } float yPathScale = holeSizeY * 0.5f; float pathLength = pathCutEnd - pathCutBegin; float totalSkew = skew * 2.0f * pathLength; float skewStart = pathCutBegin * 2.0f * skew - skew; float xOffsetTopShearXFactor = topShearX * (0.25f + 0.5f * (0.5f - holeSizeY)); float yShearCompensation = 1.0f + abs(topShearY) * 0.25f; // It's not quite clear what pushY (Y top shear) does, but subtracting it from the start and end // angles appears to approximate it's effects on path cut. Likewise, adding it to the angle used // to calculate the sine for generating the path radius appears to approximate it's effects there // too, but there are some subtle differences in the radius which are noticeable as the prim size // increases and it may affect megaprims quite a bit. The effect of the Y top shear parameter on // the meshes generated with this technique appear nearly identical in shape to the same prims when // displayed by the viewer. float startAngle = (twoPi * pathCutBegin * revolutions) - topShearY * 0.9f; float endAngle = (twoPi * pathCutEnd * revolutions) - topShearY * 0.9f; float stepSize = twoPi / stepsPerRevolution; step = (int)(startAngle / stepSize); int firstStep = step; float angle = startAngle; float hollow = this->hollow; // sanity checks float initialProfileRot = 0.0f; if (sides == 3) { initialProfileRot = (float)PI; if (hollowSides == 4) { if (hollow > 0.7f) hollow = 0.7f; hollow *= 0.707f; } else hollow *= 0.5f; } else if (sides == 4) { initialProfileRot = 0.25f * (float)PI; if (hollowSides != 4) hollow *= 0.707f; } else if (sides > 4) { initialProfileRot = (float)PI; if (hollowSides == 4) { if (hollow > 0.7f) hollow = 0.7f; hollow /= 0.7f; } } bool needEndFaces = false; if (pathCutBegin != 0.0f || pathCutEnd != 1.0f) needEndFaces = true; else if (taperX != 0.0f || taperY != 0.0f) needEndFaces = true; else if (skew != 0.0f) needEndFaces = true; else if (twistTotal != 0.0f) needEndFaces = true; else if (radius != 0.0f) needEndFaces = true; Profile profile(sides, profileStart, profileEnd, hollow, hollowSides, needEndFaces); numPrimFaces = profile.numPrimFaces; int cut1Vert = -1; int cut2Vert = -1; if (hasProfileCut) { cut1Vert = hasHollow ? profile.coords.size() - 1 : 0; cut2Vert = hasHollow ? profile.numOuterVerts - 1 : profile.numOuterVerts; } if (initialProfileRot != 0.0f) { profile.AddRot(Quat(Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); if (viewerMode) profile.MakeFaceUVs(); } Coord lastCutNormal1; Coord lastCutNormal2; float lastV = 1.0f; bool done = false; while (!done) // loop through the length of the path and add the layers { bool isEndLayer = false; if (angle <= startAngle + .01f || angle >= endAngle - .01f) isEndLayer = true; //Profile newLayer = profile.Copy(isEndLayer && needEndFaces); Profile newLayer = profile; float xProfileScale = (1.0f - abs(skew)) * holeSizeX; float yProfileScale = holeSizeY; float percentOfPath = angle / (twoPi * revolutions); float percentOfAngles = (angle - startAngle) / (endAngle - startAngle); if (taperX > 0.01f) xProfileScale *= 1.0f - percentOfPath * taperX; else if (taperX < -0.01f) xProfileScale *= 1.0f + (1.0f - percentOfPath) * taperX; if (taperY > 0.01f) yProfileScale *= 1.0f - percentOfPath * taperY; else if (taperY < -0.01f) yProfileScale *= 1.0f + (1.0f - percentOfPath) * taperY; if (xProfileScale != 1.0f || yProfileScale != 1.0f) newLayer.Scale(xProfileScale, yProfileScale); float radiusScale = 1.0f; if (radius > 0.001f) radiusScale = 1.0f - radius * percentOfPath; else if (radius < 0.001f) radiusScale = 1.0f + radius * (1.0f - percentOfPath); float twist = twistBegin + twistTotal * percentOfPath; float xOffset = 0.5f * (skewStart + totalSkew * percentOfAngles); xOffset += (float)sin(angle) * xOffsetTopShearXFactor; float yOffset = yShearCompensation * (float)cos(angle) * (0.5f - yPathScale) * radiusScale; float zOffset = (float)sin(angle + topShearY) * (0.5f - yPathScale) * radiusScale; // next apply twist rotation to the profile layer if (twistTotal != 0.0f || twistBegin != 0.0f) newLayer.AddRot(Quat(Coord(0.0f, 0.0f, 1.0f), twist)); // now orient the rotation of the profile layer relative to it's position on the path // adding taperY to the angle used to generate the quat appears to approximate the viewer newLayer.AddRot(Quat(Coord(1.0f, 0.0f, 0.0f), angle + topShearY)); newLayer.AddPos(xOffset, yOffset, zOffset); if (isEndLayer && angle <= startAngle + .01f) { newLayer.FlipNormals(); // add the top faces to the viewerFaces list here if (viewerMode && needEndFaces) { Coord faceNormal = newLayer.faceNormal; for (unsigned i = 0; i < newLayer.faces.size(); ++i) { const Face& face = newLayer.faces[i]; ViewerFace newViewerFace; newViewerFace.primFaceNumber = 0; newViewerFace.v1 = newLayer.coords[face.v1]; newViewerFace.v2 = newLayer.coords[face.v2]; newViewerFace.v3 = newLayer.coords[face.v3]; newViewerFace.n1 = faceNormal; newViewerFace.n2 = faceNormal; newViewerFace.n3 = faceNormal; newViewerFace.uv1 = newLayer.faceUVs[face.v1]; newViewerFace.uv2 = newLayer.faceUVs[face.v2]; newViewerFace.uv3 = newLayer.faceUVs[face.v3]; viewerFaces.push_back(newViewerFace); } } } // append the layer and fill in the sides int coordsLen = coords.size(); newLayer.AddValue2FaceVertexIndices(coordsLen); coords.insert(coords.end(), newLayer.coords.begin(), newLayer.coords.end()); newLayer.AddValue2FaceNormalIndices(normals.size()); normals.insert(normals.end(), newLayer.vertexNormals.begin(), newLayer.vertexNormals.end()); if (isEndLayer) faces.insert(faces.end(), newLayer.faces.begin(), newLayer.faces.end()); // fill faces between layers int numVerts = newLayer.coords.size(); Face newFace; if (step > firstStep) { int startVert = coordsLen + 1; int endVert = coords.size(); if (sides < 5 || hasProfileCut || hollow > 0.0f) startVert--; for (int i = startVert; i < endVert; i++) { int iNext = i + 1; if (i == endVert - 1) iNext = startVert; int whichVert = i - startVert; newFace.v1 = i; newFace.v2 = i - numVerts; newFace.v3 = iNext - numVerts; faces.push_back(newFace); newFace.v2 = iNext - numVerts; newFace.v3 = iNext; faces.push_back(newFace); if (viewerMode) { // add the side faces to the list of viewerFaces here ViewerFace newViewerFace1; ViewerFace newViewerFace2; float u1 = newLayer.us[whichVert]; float u2 = 1.0f; if (whichVert < newLayer.us.size() - 1) u2 = newLayer.us[whichVert + 1]; if (whichVert == cut1Vert || whichVert == cut2Vert) { u1 = 0.0f; u2 = 1.0f; } else if (sides < 5) { // boxes and prisms have one texture face per side of the prim, so the U values have to be scaled // to reflect the entire texture width u1 *= sides; u2 *= sides; u2 -= (int)u1; u1 -= (int)u1; if (u2 < 0.1f) u2 = 1.0f; //newViewerFace2.primFaceNumber = newViewerFace1.primFaceNumber = whichVert + 1; } newViewerFace1.uv1.U = u1; newViewerFace1.uv2.U = u1; newViewerFace1.uv3.U = u2; newViewerFace1.uv1.V = 1.0f - percentOfPath; newViewerFace1.uv2.V = lastV; newViewerFace1.uv3.V = lastV; newViewerFace2.uv1.U = u1; newViewerFace2.uv2.U = u2; newViewerFace2.uv3.U = u2; newViewerFace2.uv1.V = 1.0f - percentOfPath; newViewerFace2.uv2.V = lastV; newViewerFace2.uv3.V = 1.0f - percentOfPath; newViewerFace1.v1 = coords[i]; newViewerFace1.v2 = coords[i - numVerts]; newViewerFace1.v3 = coords[iNext - numVerts]; newViewerFace2.v1 = coords[i]; newViewerFace2.v2 = coords[iNext - numVerts]; newViewerFace2.v3 = coords[iNext]; // profile cut faces if (whichVert == cut1Vert) { newViewerFace1.n1 = newLayer.cutNormal1; newViewerFace1.n2 = newViewerFace1.n3 = lastCutNormal1; newViewerFace2.n1 = newViewerFace2.n3 = newLayer.cutNormal1; newViewerFace2.n2 = lastCutNormal1; } else if (whichVert == cut2Vert) { newViewerFace1.n1 = newLayer.cutNormal2; newViewerFace1.n2 = newViewerFace1.n3 = lastCutNormal2; newViewerFace2.n1 = newViewerFace2.n3 = newLayer.cutNormal2; newViewerFace2.n2 = lastCutNormal2; } else // periphery faces { if (sides < 5 && whichVert < newLayer.numOuterVerts) { newViewerFace1.n1 = normals[i]; newViewerFace1.n2 = normals[i - numVerts]; newViewerFace1.n3 = normals[i - numVerts]; newViewerFace2.n1 = normals[i]; newViewerFace2.n2 = normals[i - numVerts]; newViewerFace2.n3 = normals[i]; } else if (hollowSides < 5 && whichVert >= newLayer.numOuterVerts) { newViewerFace1.n1 = normals[iNext]; newViewerFace1.n2 = normals[iNext - numVerts]; newViewerFace1.n3 = normals[iNext - numVerts]; newViewerFace2.n1 = normals[iNext]; newViewerFace2.n2 = normals[iNext - numVerts]; newViewerFace2.n3 = normals[iNext]; } else { newViewerFace1.n1 = normals[i]; newViewerFace1.n2 = normals[i - numVerts]; newViewerFace1.n3 = normals[iNext - numVerts]; newViewerFace2.n1 = normals[i]; newViewerFace2.n2 = normals[iNext - numVerts]; newViewerFace2.n3 = normals[iNext]; } } newViewerFace1.primFaceNumber = newViewerFace2.primFaceNumber = newLayer.faceNumbers[whichVert]; viewerFaces.push_back(newViewerFace1); viewerFaces.push_back(newViewerFace2); } } } lastCutNormal1 = newLayer.cutNormal1; lastCutNormal2 = newLayer.cutNormal2; lastV = 1.0f - percentOfPath; // calculate terms for next iteration // calculate the angle for the next iteration of the loop if (angle >= endAngle) { done = true; } else { step += 1; angle = stepSize * step; if (angle > endAngle) angle = endAngle; } if (done && viewerMode && needEndFaces) { // add the bottom faces to the viewerFaces list here Coord faceNormal = newLayer.faceNormal; ViewerFace newViewerFace; newViewerFace.primFaceNumber = newLayer.bottomFaceNumber; for (unsigned i = 0; i < newLayer.faces.size(); ++i) { const Face& face = newLayer.faces[i]; newViewerFace.v1 = newLayer.coords[face.v1 - coordsLen]; newViewerFace.v2 = newLayer.coords[face.v2 - coordsLen]; newViewerFace.v3 = newLayer.coords[face.v3 - coordsLen]; newViewerFace.n1 = faceNormal; newViewerFace.n2 = faceNormal; newViewerFace.n3 = faceNormal; newViewerFace.uv1 = newLayer.faceUVs[face.v1 - coordsLen]; newViewerFace.uv2 = newLayer.faceUVs[face.v2 - coordsLen]; newViewerFace.uv3 = newLayer.faceUVs[face.v3 - coordsLen]; viewerFaces.push_back(newViewerFace); } } } } Coord PrimMesh::SurfaceNormal(const Coord& c1, const Coord& c2, const Coord& c3) { Coord edge1(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z); Coord edge2(c3.X - c1.X, c3.Y - c1.Y, c3.Z - c1.Z); Coord normal = Coord::Cross(edge1, edge2); normal.Normalize(); return normal; } Coord PrimMesh::SurfaceNormal(const Face& face) { return SurfaceNormal(coords[face.v1], coords[face.v2], coords[face.v3]); } /// <summary> /// Calculate the surface normal for a face in the list of faces /// </summary> /// <param name="faceIndex"></param> /// <returns></returns> Coord PrimMesh::SurfaceNormal(int faceIndex) { int numFaces = faces.size(); if (faceIndex < 0 || faceIndex >= numFaces) throw Exception("faceIndex out of range"); return SurfaceNormal(faces[faceIndex]); } /// <summary> /// Calculate surface normals for all of the faces in the list of faces in this mesh /// </summary> void PrimMesh::CalcNormals() { if (normalsProcessed) return; normalsProcessed = true; int numFaces = faces.size(); normals.clear(); for (int i = 0; i < numFaces; i++) { Face face = faces[i]; normals.push_back(SurfaceNormal(i).Normalize()); int normIndex = normals.size() - 1; face.n1 = normIndex; face.n2 = normIndex; face.n3 = normIndex; faces[i] = face; } } /// <summary> /// Adds a value to each XYZ vertex coordinate in the mesh /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> void PrimMesh::AddPos(float x, float y, float z) { int i; int numVerts = coords.size(); Coord vert; for (i = 0; i < numVerts; i++) { vert = coords[i]; vert.X += x; vert.Y += y; vert.Z += z; coords[i] = vert; } } /// <summary> /// Rotates the mesh /// </summary> /// <param name="q"></param> void PrimMesh::AddRot(Quat q) { int i; int numVerts = coords.size(); for (i = 0; i < numVerts; i++) coords[i] *= q; int numNormals = normals.size(); for (i = 0; i < numNormals; i++) normals[i] *= q; int numViewerFaces = viewerFaces.size(); for (i = 0; i < numViewerFaces; i++) { ViewerFace v = viewerFaces[i]; v.v1 *= q; v.v2 *= q; v.v3 *= q; v.n1 *= q; v.n2 *= q; v.n3 *= q; viewerFaces[i] = v; } } /// <summary> /// Scales the mesh /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> void PrimMesh::Scale(float x, float y, float z) { int i; int numVerts = coords.size(); //Coord vert; Coord m(x, y, z); for (i = 0; i < numVerts; i++) coords[i] *= m; int numViewerFaces = viewerFaces.size(); for (i = 0; i < numViewerFaces; i++) { ViewerFace v = viewerFaces[i]; v.v1 *= m; v.v2 *= m; v.v3 *= m; viewerFaces[i] = v; } } }
c0f476b7b080033e5ce3bf25eaa5aadbfb852b35
b179ee1c603139301b86fa44ccbbd315a148c47b
/engine/effects/source/TeleportEffect.cpp
28e27e53f951120746dc4a304486282fe371e230
[ "MIT", "Zlib" ]
permissive
prolog/shadow-of-the-wyrm
06de691e94c2cb979756cee13d424a994257b544
cd419efe4394803ff3d0553acf890f33ae1e4278
refs/heads/master
2023-08-31T06:08:23.046409
2023-07-08T14:45:27
2023-07-08T14:45:27
203,472,742
71
9
MIT
2023-07-08T14:45:29
2019-08-21T00:01:37
C++
UTF-8
C++
false
false
5,700
cpp
TeleportEffect.cpp
#include <boost/range/adaptors.hpp> #include <boost/range/algorithm.hpp> #include "Conversion.hpp" #include "Creature.hpp" #include "CreatureProperties.hpp" #include "EffectProperties.hpp" #include "EffectTextKeys.hpp" #include "Game.hpp" #include "Log.hpp" #include "MapProperties.hpp" #include "MapUtils.hpp" #include "MessageManagerFactory.hpp" #include "RNG.hpp" #include "TeleportEffect.hpp" using namespace std; const string TeleportEffect::TELEPORT_BLINK = "TELEPORT_BLINK"; TeleportEffect::TeleportEffect() : blink_effect(false), teleport_location({false, {-1,-1}}) { } string TeleportEffect::get_effect_identification_message(CreaturePtr creature) const { string effect_msg; if (creature) { effect_msg = EffectTextKeys::get_teleport_effect_message(creature->get_description_sid(), creature->get_is_player()); } return effect_msg; } bool TeleportEffect::is_negative_effect() const { return true; } Effect* TeleportEffect::clone() { return new TeleportEffect(*this); } bool TeleportEffect::effect_blessed(CreaturePtr creature, ActionManager * const am, const Coordinate& affected_coordinate, TilePtr affected_tile) { return teleport(creature); } bool TeleportEffect::effect_uncursed(CreaturePtr creature, ActionManager * const am, const Coordinate& affected_coordinate, TilePtr affected_tile) { return teleport(creature); } bool TeleportEffect::effect_cursed(CreaturePtr creature, ActionManager * am, const Coordinate& affected_coordinate, TilePtr affected_tile) { return teleport(creature); } bool TeleportEffect::teleport(CreaturePtr creature) { bool teleported = false; if (creature != nullptr) { Game& game = Game::instance(); MapPtr map = game.get_current_map(); // The creature's original tile. TilePtr old_tile = map->at(map->get_location(creature->get_id())); string map_cannot_teleport = map->get_property(MapProperties::MAP_PROPERTIES_CANNOT_TELEPORT); if (map_cannot_teleport.empty() || (String::to_bool(map_cannot_teleport) == false)) { if (blink_effect) { // Blink just teleports in the field of view. teleported = blink(creature, map, old_tile); } else { // Proper teleporting can go anywhere on the map. teleported = teleport(creature, map, old_tile); } } else { if (creature->get_is_player()) { IMessageManager& manager = MM::instance(); manager.add_new_message(StringTable::get(EffectTextKeys::EFFECT_TELEPORT_CANNOT_TELEPORT)); manager.send(); } } } if (teleported && creature != nullptr) { creature->get_automatic_movement_ref().reset(); creature->set_additional_property(CreatureProperties::CREATURE_PROPERTIES_TELEPORTED, std::to_string(true)); } return teleported; } void TeleportEffect::read_properties(const map<string, string>& properties) { auto p_it = properties.find(TELEPORT_BLINK); if (p_it != properties.end()) { try { blink_effect = String::to_bool(p_it->second); } catch (...) { Log::instance().error("Could not convert blink effect value!"); } } p_it = properties.find(EffectProperties::EFFECT_PROPERTIES_TELEPORT_LOCATION); if (p_it != properties.end()) { vector<string> coords = String::create_string_vector_from_csv_string(p_it->second); if (coords.size() == 2) { teleport_location.first = true; teleport_location.second = {String::to_int(coords.at(0)), String::to_int(coords.at(1))}; } } } bool TeleportEffect::blink(CreaturePtr creature, MapPtr current_map, TilePtr old_tile) { bool teleported = false; if (creature && current_map && old_tile) { MapPtr fov_map = creature->get_decision_strategy()->get_fov_map(); vector<string> keys = get_appropriate_keys(fov_map, teleport_location); TilesContainer tiles; if (fov_map != nullptr) { tiles = current_map->get_tiles_ref(); } while (!keys.empty() && !teleported) { string k = keys.back(); Coordinate c = MapUtils::convert_map_key_to_coordinate(k); TilePtr tile = tiles.find(k)->second; if (tile && MapUtils::is_tile_available_for_creature(creature, tile)) { MapUtils::add_or_update_location(current_map, creature, c, old_tile); teleported = true; } keys.pop_back(); } } return teleported; } bool TeleportEffect::teleport(CreaturePtr creature, MapPtr map, TilePtr old_tile) { bool teleported = false; if (creature && map && old_tile) { Dimensions dim = map->size(); int rows = dim.get_y(); int cols = dim.get_x(); // Make a number of attempts to teleport. for (int i = 0; i < 100; i++) { int row = RNG::range(0, rows); int col = RNG::range(0, cols); Coordinate c(row, col); if (teleport_location.first == true) { c = teleport_location.second; } TilePtr tile = map->at(c); if (tile && !tile->get_creature() && !tile->get_is_blocking(creature)) { MapUtils::add_or_update_location(map, creature, c, old_tile); teleported = true; break; } } } return teleported; } vector<string> TeleportEffect::get_appropriate_keys(MapPtr map, const pair<bool, Coordinate>& teleport_loc) { vector<string> keys; if (teleport_loc.first == true) { keys.push_back(MapUtils::convert_coordinate_to_map_key(teleport_loc.second)); } else { TilesContainer& tiles = map->get_tiles_ref(); for (const auto& pair : tiles) { keys.push_back(pair.first); } shuffle(keys.begin(), keys.end(), RNG::get_engine()); } return keys; }
38366320a35d16f0d132d2fae9dc796f75446017
6325cd777d23a7b6c94918bc17d927e91c65ecfe
/stl/algorithm/test_algorithm.cpp
9a0db159c4c171eab9c14de4fd134e881e900f64
[]
no_license
ShodanHo/code-and-tools
c3448e3cd20d38c3c95ac3c981cc5de17dcbf8ce
771ffd0800dce89221eebaea76638efc0118b715
refs/heads/master
2021-01-21T00:35:52.691015
2016-04-27T15:44:46
2016-04-27T15:44:46
23,016,213
0
0
null
null
null
null
UTF-8
C++
false
false
1,089
cpp
test_algorithm.cpp
/*************************************************************************/ /* */ /* Project: Standard Template Library. */ /* */ /* Description: Playing with the algorithms in the STL. */ /* */ /* Date: September 10, 2011. */ /* */ /*************************************************************************/ /* * $Id: test_algorithm.cpp,v 1.1 2013/09/21 18:01:48 knoppix Exp $ * * $Log: test_algorithm.cpp,v $ * Revision 1.1 2013/09/21 18:01:48 knoppix * Original * */ #include <iostream> #include <stdlib.h> using namespace std; #define STR(x) #x << '=' << x << ' ' int main(int argc, char **argv) { cout << __FILE__ << " start\n"; cout << __FILE__ << " end\n"; return 0; } // End of file
48110abf3ce93e1a17c22323deca27a73fb9932a
8775fa748f40950d10122016ff4fe44c03f4e0c5
/polygonRSA/NeighbourGrid.h
ae1f666c84df2c209e13fa8275233af412767230
[]
no_license
misiekc/polygonRSA
2f7561a524d08ab384ea8da8b784761085bafc95
f286d80b9a0aec672085a6e4c7adb16d2abc0a4e
refs/heads/master
2021-06-24T06:20:33.419569
2021-01-06T15:12:05
2021-01-06T15:12:05
186,135,672
5
1
null
null
null
null
UTF-8
C++
false
false
3,391
h
NeighbourGrid.h
/* * NeighbourGrid.h * * Created on: 07.03.2017 * Author: Michal Ciesla */ #ifndef NEIGHBOURGRID_H_ #define NEIGHBOURGRID_H_ #include <vector> #include <cmath> #include <algorithm> #include "BoundaryConditions.h" #include "Utils.h" template <typename E> class NeighbourGrid{ private: double linearSize; int n; double dx; // contains vectors of cells (vectors with Positioned* inside) std::vector<std::vector<E * > * > lists; std::vector<std::vector<int> * > neighbouringCells; void init(double size, size_t n){ this->linearSize = size; this->n = n; this->dx = size/this->n; int length = (int) round(pow(this->n, 2)); this->lists.reserve(length); this->neighbouringCells.reserve(length); int in[2]; double da[2]; int coords[2]; for(int i=0; i<length; i++){ this->lists.push_back(new std::vector<E *>); this->neighbouringCells.push_back(new std::vector<int>); this->neighbouringCells[i]->reserve((4)); i2position(da, 2, i, this->dx, this->n); in[0] = 0; in[1] = 0; coordinates(coords, da, 2, this->linearSize, this->dx); do{ int iCell = neighbour2i(coords, in, 2, 1, this->n); this->neighbouringCells[i]->push_back(iCell); }while(increment(in, 2, 2)); // sort and erase to avoid duplicates - important for small packings std::sort( neighbouringCells[i]->begin(), neighbouringCells[i]->end() ); neighbouringCells[i]->erase( std::unique( neighbouringCells[i]->begin(), neighbouringCells[i]->end() ), neighbouringCells[i]->end() ); } } public: NeighbourGrid(double size, double dx){ // @suppress("Class members should be properly initialized") Expects(size > 0); Expects(dx > 0); size_t n = (size_t)(size/dx); if (n == 0) throw std::runtime_error("neighbour grid cell too big"); this->init(size, n); } NeighbourGrid(double size, size_t n){ // @suppress("Class members should be properly initialized") Expects(size > 0); Expects(n > 0); this->init(size, n); } virtual ~NeighbourGrid(){ for(unsigned int i=0; i<this->lists.size(); i++){ delete this->lists[i]; delete this->neighbouringCells[i]; } } void add(E* s, const RSAVector &da){ double array[2]; da.copyToArray(array); int i = position2i(array, 2, this->linearSize, this->dx, this->n); this->lists[i]->push_back(s); } void remove(E* s, const RSAVector &da){ double array[2]; da.copyToArray(array); int i = position2i(array, 2, this->linearSize, this->dx, this->n); typename std::vector<E *>::iterator it; if ( (it = std::find(this->lists[i]->begin(), this->lists[i]->end(), s)) != this->lists[i]->end()) this->lists[i]->erase(it); } void clear(){ for(unsigned int i=0; i<this->lists.size(); i++){ this->lists[i]->clear(); } } std::vector<E*> * getCell(const RSAVector &da){ double array[2]; da.copyToArray(array); int i = position2i(array, 2, this->linearSize, this->dx, this->n); return this->lists[i]; } void getNeighbours(std::vector<E *> *result, const RSAVector &da) const{ result->clear(); std::vector<E *> *vTmp; double array[2]; da.copyToArray(array); int i = position2i(array, 2, this->linearSize, this->dx, this->n); for(int iCell : *(this->neighbouringCells[i])){ vTmp = (this->lists[iCell]); result->insert(result->end(), vTmp->begin(), vTmp->end()); } } }; #endif /* NEIGHBOURGRID_H_ */
8651457be00c5b2a172646580c0f661ebadad693
0fa1152e1e434ce9fe9e2db95f43f25675bf7d27
/src/modules/mavlink/streams/ODOMETRY.hpp
60b8564bc2adc6e0e33794635a3f35b83399d559
[ "BSD-3-Clause" ]
permissive
PX4/PX4-Autopilot
4cc90dccc9285ca4db7f595ac5a7547df02ca92e
3d61ab84c42ff8623bd48ff0ba74f9cf26bb402b
refs/heads/main
2023-08-30T23:58:35.398450
2022-03-26T01:29:03
2023-08-30T15:40:01
5,298,790
3,146
3,798
BSD-3-Clause
2023-09-14T17:22:04
2012-08-04T21:19:36
C++
UTF-8
C++
false
false
5,470
hpp
ODOMETRY.hpp
/**************************************************************************** * * Copyright (c) 2021-2022 PX4 Development Team. 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. * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * * 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 OWNER 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. * ****************************************************************************/ #ifndef ODOMETRY_HPP #define ODOMETRY_HPP #include <uORB/topics/vehicle_odometry.h> class MavlinkStreamOdometry : public MavlinkStream { public: static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamOdometry(mavlink); } static constexpr const char *get_name_static() { return "ODOMETRY"; } static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_ODOMETRY; } const char *get_name() const override { return get_name_static(); } uint16_t get_id() override { return get_id_static(); } unsigned get_size() override { return _vehicle_odometry_sub.advertised() ? MAVLINK_MSG_ID_ODOMETRY_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: explicit MavlinkStreamOdometry(Mavlink *mavlink) : MavlinkStream(mavlink) {} uORB::Subscription _vehicle_odometry_sub{ORB_ID(vehicle_odometry)}; bool send() override { vehicle_odometry_s odom; if (_vehicle_odometry_sub.update(&odom)) { mavlink_odometry_t msg{}; msg.time_usec = odom.timestamp_sample; // set the frame_id according to the local frame of the data switch (odom.pose_frame) { case vehicle_odometry_s::POSE_FRAME_NED: msg.frame_id = MAV_FRAME_LOCAL_NED; break; case vehicle_odometry_s::POSE_FRAME_FRD: msg.frame_id = MAV_FRAME_LOCAL_FRD; break; } switch (odom.velocity_frame) { case vehicle_odometry_s::VELOCITY_FRAME_NED: msg.child_frame_id = MAV_FRAME_LOCAL_NED; break; case vehicle_odometry_s::VELOCITY_FRAME_FRD: msg.child_frame_id = MAV_FRAME_LOCAL_FRD; break; case vehicle_odometry_s::VELOCITY_FRAME_BODY_FRD: msg.child_frame_id = MAV_FRAME_BODY_FRD; break; } msg.x = odom.position[0]; msg.y = odom.position[1]; msg.z = odom.position[2]; msg.q[0] = odom.q[0]; msg.q[1] = odom.q[1]; msg.q[2] = odom.q[2]; msg.q[3] = odom.q[3]; msg.vx = odom.velocity[0]; msg.vy = odom.velocity[1]; msg.vz = odom.velocity[2]; // Current body rates msg.rollspeed = odom.angular_velocity[0]; msg.pitchspeed = odom.angular_velocity[1]; msg.yawspeed = odom.angular_velocity[2]; // pose_covariance // Row-major representation of a 6x6 pose cross-covariance matrix upper right triangle // (states: x, y, z, roll, pitch, yaw; first six entries are the first ROW, next five entries are the second ROW, etc.) for (auto &pc : msg.pose_covariance) { pc = NAN; } msg.pose_covariance[0] = odom.position_variance[0]; // X row 0, col 0 msg.pose_covariance[6] = odom.position_variance[1]; // Y row 1, col 1 msg.pose_covariance[11] = odom.position_variance[2]; // Z row 2, col 2 msg.pose_covariance[15] = odom.orientation_variance[0]; // R row 3, col 3 msg.pose_covariance[18] = odom.orientation_variance[1]; // P row 4, col 4 msg.pose_covariance[20] = odom.orientation_variance[2]; // Y row 5, col 5 // velocity_covariance // Row-major representation of a 6x6 velocity cross-covariance matrix upper right triangle // (states: vx, vy, vz, rollspeed, pitchspeed, yawspeed; first six entries are the first ROW, next five entries are the second ROW, etc.) for (auto &vc : msg.velocity_covariance) { vc = NAN; } msg.velocity_covariance[0] = odom.velocity_variance[0]; // X row 0, col 0 msg.velocity_covariance[6] = odom.velocity_variance[1]; // Y row 1, col 1 msg.velocity_covariance[11] = odom.velocity_variance[2]; // Z row 2, col 2 msg.reset_counter = odom.reset_counter; // source: PX4 estimator msg.estimator_type = MAV_ESTIMATOR_TYPE_AUTOPILOT; msg.quality = odom.quality; mavlink_msg_odometry_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; #endif // ODOMETRY_HPP
a342c689855b9a705df685c7642dc8690ac6c954
3ee0a38604348183ece0fd53a9d0b809db92d838
/Screen.cpp
bca1274072c485cffb0e5d4b8a861b47f9d61d95
[]
no_license
f4z3r/particle_explosion
2b8ea48b6f65bf4d2ec14937c2d94b47fc1bc19a
37a6ab37ab0e680ad58b68fec7f822e7a9b23f3b
refs/heads/master
2021-07-04T15:11:04.300409
2017-09-28T18:39:07
2017-09-28T18:39:07
null
0
0
null
null
null
null
UTF-8
C++
false
false
3,879
cpp
Screen.cpp
// Name Screen.cpp #include "Screen.hpp" namespace jhb { Screen::Screen(): m_window(NULL), m_renderer(NULL), m_texture(NULL), m_buffer1(NULL), m_buffer2(NULL){ } bool Screen::init(const char* title) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { return false; } // Initialise window m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if(m_window == NULL) { SDL_Quit(); return false; } // Initialise renderer m_renderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_PRESENTVSYNC); if(m_renderer == NULL) { SDL_DestroyWindow(m_window); SDL_Quit(); return false; } // Initialise texture m_texture = SDL_CreateTexture(m_renderer,SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, SCREEN_WIDTH, SCREEN_HEIGHT); if(m_texture == NULL) { SDL_DestroyRenderer(m_renderer); SDL_DestroyWindow(m_window); SDL_Quit(); return false; } // Initialise buffer and fill with black m_buffer1 = new Uint32[SCREEN_WIDTH * SCREEN_HEIGHT]; memset(m_buffer1, 0, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(Uint32)); m_buffer2 = new Uint32[SCREEN_WIDTH * SCREEN_HEIGHT]; memset(m_buffer2, 0, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(Uint32)); return true; } bool Screen::process_events() { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) { return false; } } return true; } void Screen::set_pixel(int x, int y, Uint8 red, Uint8 green, Uint8 blue) { if(x < 0 || x >= SCREEN_WIDTH || y < 0 || y >= SCREEN_HEIGHT) { return; } Uint32 color = 0; color += red; color <<= 8; color += green; color <<= 8; color += blue; color <<= 8; color += 0xff; m_buffer1[(y * SCREEN_WIDTH) + x] = color; } void Screen::update() { SDL_UpdateTexture(m_texture, NULL, m_buffer1, SCREEN_WIDTH * sizeof(Uint32)); SDL_RenderClear(m_renderer); SDL_RenderCopy(m_renderer, m_texture, NULL, NULL); SDL_RenderPresent(m_renderer); } void Screen::close() { delete[] m_buffer1; delete[] m_buffer2; SDL_DestroyTexture(m_texture); SDL_DestroyRenderer(m_renderer); SDL_DestroyWindow(m_window); SDL_Quit(); } void Screen::gaussian_blur() { Uint32* tmp = m_buffer1; m_buffer1 = m_buffer2; m_buffer2 = tmp; for(int y=0; y<SCREEN_HEIGHT; y++) { for(int x=0; x<SCREEN_WIDTH; x++) { double red_tot = 0; double green_tot = 0; double blue_tot = 0; for(int row=0; row<=2; row++) { for(int col=0; col<=2; col++) { int current_x = x + col - 1; int current_y = y + row - 1; if(current_x >= 0 && current_x < SCREEN_WIDTH && current_y >= 0 && current_y < SCREEN_HEIGHT) { Uint32 color = m_buffer2[current_y*SCREEN_WIDTH + current_x]; Uint8 red = color >> 24; Uint8 green = color >> 16; Uint8 blue = color >> 8; red_tot += red * m_blur[row][col]; green_tot += green * m_blur[row][col]; blue_tot += blue * m_blur[row][col]; } } } Uint8 red = red_tot; Uint8 green = green_tot; Uint8 blue = blue_tot; set_pixel(x, y, red, green, blue); } } } } // namespace jhb
5ebd585413d493b11b320ebfac976864cc10ce1d
23d54380b1652c5f464fa656d1e70b72968956c1
/SFML_HungryHoney2/SFML_HungryHoney2/PlayerCharacter.h
6f97d71138a9641a15803a89142dbdb6f42ed3ca
[]
no_license
wakcs/HungryHoney
6559516b7b93bfebc0e902922ea9c5bb97403c84
2f802012d7f2cdb02b1ebff0a7332df233781f93
refs/heads/master
2021-05-03T08:52:43.251008
2016-05-09T15:51:02
2016-05-09T15:51:02
54,651,368
0
0
null
null
null
null
UTF-8
C++
false
false
1,254
h
PlayerCharacter.h
#pragma once #include "Character.h" class PlayerCharacter : public Character { public: bool blockTop, blockBottom, blockLeft, blockRight; PlayerCharacter(); PlayerCharacter(Texture*charachterTexture, Vector2f position, SoundBuffer* bufHit, Texture* suitTexture, Texture*weaponTexture, float maxSpeed, float healthPoints, float defencePoints, float damagePoints, float attackRange); ~PlayerCharacter(); //called in the update void Update(vector<Character*> enemys); void Draw(RenderWindow&window); //getters float GetDefencePoints(); float GetScore(); Keyboard::Key GetInteractKey(); //setters void SetDefencePoints(float defencePoints); void SetSuit(Sprite suit); void SetWeapon(Sprite weapon); void SetScore(float score); void AddScore(float points); void SubtractScore(float points); private: float fDefencePoints, fScore; Sprite sprtSuit, sprtWeapon; Vector2f suitOffset, weaponOffset; //inputs Keyboard::Key kbUp = Keyboard::Key::Up; Keyboard::Key kbDown = Keyboard::Key::Down; Keyboard::Key kbLeft = Keyboard::Key::Left; Keyboard::Key kbRight = Keyboard::Key::Right; Keyboard::Key kbInteract = Keyboard::Key::E; Keyboard::Key kbShoot = Keyboard::Key::Space; void Move(); void GetHit(float damagePoints); };
c3fc43e8dd0a0d4c9dbf6221f1e47ba34e87bd04
bcd32907dc7b292350371ac5cc9b67bd3b7a99c2
/development/C++/samples/server/BisDemo/DeviceElement.h
cd0f15719511b17abed76e2d7f3ce7b08ce00e6f
[ "MIT" ]
permissive
SoftingIndustrial/OPC-Classic-SDK
c6d3777e2121d6ca34da571930a424717740171e
08f4b3e968acfce4b775299741cef1819e24fda1
refs/heads/main
2022-07-28T14:53:00.481800
2022-01-17T13:58:46
2022-01-17T13:58:46
335,269,862
41
16
MIT
2022-01-17T15:11:39
2021-02-02T11:43:04
C++
UTF-8
C++
false
false
4,252
h
DeviceElement.h
#ifndef _DEVICEELEMENT_H_ #define _DEVICEELEMENT_H_ #include "BaseDaElement.h" using namespace SoftingOPCToolboxServer; //----------------------------------------------------------------------------- // DeviceElement //----------------------------------------------------------------------------- class DeviceElement : public BaseDaElement { public: DeviceElement( tstring& aName, int aDataTypeId, tstring& aDescription) : BaseDaElement() { setAccessRights(EnumAccessRights_READABLE); setDatatype(VT_UI4); setIoMode(EnumIoMode_REPORT); setName(aName); setHasChildren(false); setIoMode(EnumIoMode_POLL); DateTime time; time.now(); ValueQT value(Variant(aDescription.c_str()), EnumQuality_GOOD, time); addProperty(new DaConstantProperty(101, tstring(_T("Description")), tstring(_T("Description")), value)); addProperty(new DataPointTypeProperty(aDataTypeId)); } // end ctr virtual ~DeviceElement( void) { } // end dtor bool getConnected( void) { ValueQT cacheValue; getCacheValue(cacheValue); if (cacheValue.getQuality() == EnumQuality_GOOD) { return (cacheValue.getData().intVal >= 1); } else { return false; } // end if } // end getConnected void setConnected( bool value) { ValueQT cacheValue; getCacheValue(cacheValue); Variant cacheValueVariant = cacheValue.getData(); if (cacheValueVariant.intVal > 1) { cacheValueVariant.intVal = 1; } // end if if ((cacheValue.getQuality() == EnumQuality_GOOD) && (cacheValueVariant.intVal >= 1) == value) { return; } // end if DateTime time; time.now(); Variant aVariant; if (value == true) { aVariant.setINT(1); } else { aVariant.setINT(0); } // end if .. else cacheValue = ValueQT(aVariant, EnumQuality_GOOD, time); // Notify value changed to the DA Element valueChanged(cacheValueVariant.intVal, 0, tstring(_T("simulation Address")), tstring(_T("simulation Text Description"))); // Create a State change event and fire it DeviceEvent deviceState(getItemId(), cacheValueVariant); deviceState.setActorId(tstring(_T("OPC User"))); if (value == true) { deviceState.setMessage(tstring(_T("Connected"))); deviceState.setSeverity(1); } else { deviceState.setMessage(tstring(_T("Disconnected"))); deviceState.setSeverity(1000); } // end if .. else deviceState.fire(); } // end setConnected virtual void simulate( void) { if (m_simulationOn == true) { ValueQT cacheValue; getCacheValue(cacheValue); bool simulationCV = (cacheValue.getData().intVal > 0); simulationCV = simulationCV ? false : true; setConnected(simulationCV); } // end if BaseDaElement::simulate(); } // end simulate virtual long valueChanged( int aDataCv, int anInternalData, const tstring& anAddress, const tstring& aTextDescription) { ValueQT cacheValue; getCacheValue(cacheValue); Variant cacheValueVariant = cacheValue.getData(); if (cacheValueVariant.intVal > 1) { cacheValueVariant.intVal = 1; } // end if if (aDataCv > 1) { aDataCv = 1; } // end if if (cacheValue.getQuality() == EnumQuality_GOOD && cacheValueVariant.intVal == aDataCv) { return (long)EnumResultCode_S_OK; } // end if DateTime time; time.now(); Variant aVariant; aVariant.setINT(aDataCv); cacheValue = ValueQT(aVariant, EnumQuality_GOOD, time); // Notify value changed to the DA Element BaseDaElement::valueChanged(cacheValue); // Create a Data change event and fire it cacheValueVariant = cacheValue.getData(); DeviceEvent* deviceEvent = new DeviceEvent(getItemId(), cacheValueVariant); deviceEvent->setActorId(tstring(_T("OPC User"))); if (aDataCv > 0) { deviceEvent->setMessage(tstring(_T("Connected"))); deviceEvent->setSeverity(1); } else { deviceEvent->setMessage(tstring(_T("Disconnected"))); deviceEvent->setSeverity(1000); } // end if .. else return deviceEvent->fire(); } // end valueChanged virtual unsigned int executeCommand( const tstring& anAddress, const tstring& aCommand, const tstring& aDescription) { return valueChanged(_tstoi(aCommand.c_str()), 0, anAddress, aDescription); } // end executeCommand }; // end DeviceElement #endif
7eac3992078b1d483a91574051ec2ef41a913603
dcf14554414c5f053bfa1b4a4e3c5084bf89ef7f
/modules/core/src/MetaObject/thread/Mutex.hpp
3ef179787aa77f6a71948a71f76e24d0f8a4eb8b
[ "MIT" ]
permissive
dtmoodie/MetaObject
2eab87e97423a49a6910586e1cf828da4a80ec32
8238d143d578ff9c0c6506e7e627eca15e42369e
refs/heads/master
2023-03-09T09:03:25.555934
2020-04-26T02:27:05
2020-04-26T02:27:05
63,189,210
2
3
MIT
2019-12-05T04:41:19
2016-07-12T20:10:17
C++
UTF-8
C++
false
false
2,354
hpp
Mutex.hpp
#ifndef MO_CORE_MUTEX_HPP #define MO_CORE_MUTEX_HPP #include <MetaObject/core.hpp> #include <chrono> #include <memory> #include <mutex> namespace boost { namespace fibers { class recursive_timed_mutex; class recursive_mutex; class mutex; } // namespace fibers } // namespace boost namespace mo { struct MO_EXPORTS Mutex { using Lock_t = std::unique_lock<Mutex>; Mutex(); ~Mutex(); void lock(); bool try_lock(); void unlock(); private: std::unique_ptr<boost::fibers::mutex> m_mtx; }; struct MO_EXPORTS RecursiveMutex { using Lock_t = std::unique_lock<RecursiveMutex>; RecursiveMutex(); ~RecursiveMutex(); void lock(); bool try_lock() noexcept; void unlock(); operator boost::fibers::recursive_mutex&(); private: std::unique_ptr<boost::fibers::recursive_mutex> m_mtx; }; struct MO_EXPORTS TimedMutex { using Lock_t = std::unique_lock<TimedMutex>; TimedMutex(); ~TimedMutex(); void lock(); bool try_lock() noexcept; template <typename Clock, typename Duration> bool try_lock_until(std::chrono::time_point<Clock, Duration> const& timeout_time_); template <typename Rep, typename Period> bool try_lock_for(std::chrono::duration<Rep, Period> const& timeout_duration); void unlock(); operator boost::fibers::recursive_timed_mutex&(); private: bool try_lock_until_(std::chrono::steady_clock::time_point const& timeout_time) noexcept; std::unique_ptr<boost::fibers::recursive_timed_mutex> m_mtx; }; template <typename Clock, typename Duration> bool TimedMutex::try_lock_until(std::chrono::time_point<Clock, Duration> const& timeout_time_) { std::chrono::steady_clock::time_point timeout_time = std::chrono::steady_clock::now() + (timeout_time_ - Clock::now()); return try_lock_until_(timeout_time); } template <typename Rep, typename Period> bool TimedMutex::try_lock_for(std::chrono::duration<Rep, Period> const& timeout_duration) { return try_lock_until_(std::chrono::steady_clock::now() + timeout_duration); } } // namespace mo #endif // MO_CORE_MUTEX_HPP
64bf57b9e462d6231cee406149f9ac05052b7b18
ab9147e5209b5b5b3be74eaa50a615ec341e4aa5
/Uebung6/uebung06/point.cc
6f07c8b89d82d3b6b409fd912bd74e46341a16c1
[]
no_license
M0M097/ipk-Uebungen
075583cc1a251235cbd3c35ee69fd850d9b3884d
5a21480005731db5d64c257491a5ffd9fead39af
refs/heads/main
2023-02-22T00:24:14.742065
2021-01-23T10:54:21
2021-01-23T10:54:21
315,058,445
0
0
null
null
null
null
UTF-8
C++
false
false
189
cc
point.cc
#include "point.hh" Point::Point() : _x(0), _y(0){} Point::Point(double a, double b) : _x(a), _y(b){} double Point::x() const { return _x; } double Point::y() const { return _y; }
ad8cf9f875a0f4491f93e1843f604fbdc0a1479b
64178ab5958c36c4582e69b6689359f169dc6f0d
/vscode/wg/sdk/FCameraFocusSettings.hpp
bc8436042cbfd3d6cd293b7d11f9344524168ed2
[]
no_license
c-ber/cber
47bc1362f180c9e8f0638e40bf716d8ec582e074
3cb5c85abd8a6be09e0283d136c87761925072de
refs/heads/master
2023-06-07T20:07:44.813723
2023-02-28T07:43:29
2023-02-28T07:43:29
40,457,301
5
5
null
2023-05-30T19:14:51
2015-08-10T01:37:22
C++
UTF-8
C++
false
false
3,282
hpp
FCameraFocusSettings.hpp
#pragma once #include "ECameraFocusMethod.hpp" #include "FCameraTrackingFocusSettings.hpp" #include "FColor.hpp" #ifdef _MSC_VER #pragma pack(push, 1) #endif namespace PUBGSDK { struct alignas(1) FCameraFocusSettings // Size: 0x38 { public: TEnumAsByte<enum ECameraFocusMethod> FocusMethod; /* Ofs: 0x0 Size: 0x1 EnumProperty CinematicCamera.CameraFocusSettings.FocusMethod */ uint8_t UnknownData1[0x3]; float ManualFocusDistance; /* Ofs: 0x4 Size: 0x4 FloatProperty CinematicCamera.CameraFocusSettings.ManualFocusDistance */ FCameraTrackingFocusSettings TrackingFocusSettings; /* Ofs: 0x8 Size: 0x18 StructProperty CinematicCamera.CameraFocusSettings.TrackingFocusSettings */ bool bDrawDebugFocusPlane; /* Ofs: 0x20 Size: 0x1 BitMask: 01 BoolProperty CinematicCamera.CameraFocusSettings.bDrawDebugFocusPlane */ uint8_t UnknownData21[0x3]; FColor DebugFocusPlaneColor; /* Ofs: 0x24 Size: 0x4 StructProperty CinematicCamera.CameraFocusSettings.DebugFocusPlaneColor */ bool bSmoothFocusChanges; /* Ofs: 0x28 Size: 0x1 BitMask: 01 BoolProperty CinematicCamera.CameraFocusSettings.bSmoothFocusChanges */ uint8_t UnknownData29[0x3]; float FocusSmoothingInterpSpeed; /* Ofs: 0x2C Size: 0x4 FloatProperty CinematicCamera.CameraFocusSettings.FocusSmoothingInterpSpeed */ float FocusOffset; /* Ofs: 0x30 Size: 0x4 FloatProperty CinematicCamera.CameraFocusSettings.FocusOffset */ uint8_t UnknownData34[0x4]; }; #ifdef VALIDATE_SDK namespace Validation{ auto constexpr sizeofFCameraFocusSettings = sizeof(FCameraFocusSettings); // 56 static_assert(sizeof(FCameraFocusSettings) == 0x38, "Size of FCameraFocusSettings is not correct."); auto constexpr FCameraFocusSettings_FocusMethod_Offset = offsetof(FCameraFocusSettings, FocusMethod); static_assert(FCameraFocusSettings_FocusMethod_Offset == 0x0, "FCameraFocusSettings::FocusMethod offset is not 0"); auto constexpr FCameraFocusSettings_ManualFocusDistance_Offset = offsetof(FCameraFocusSettings, ManualFocusDistance); static_assert(FCameraFocusSettings_ManualFocusDistance_Offset == 0x4, "FCameraFocusSettings::ManualFocusDistance offset is not 4"); auto constexpr FCameraFocusSettings_TrackingFocusSettings_Offset = offsetof(FCameraFocusSettings, TrackingFocusSettings); static_assert(FCameraFocusSettings_TrackingFocusSettings_Offset == 0x8, "FCameraFocusSettings::TrackingFocusSettings offset is not 8"); auto constexpr FCameraFocusSettings_DebugFocusPlaneColor_Offset = offsetof(FCameraFocusSettings, DebugFocusPlaneColor); static_assert(FCameraFocusSettings_DebugFocusPlaneColor_Offset == 0x24, "FCameraFocusSettings::DebugFocusPlaneColor offset is not 24"); auto constexpr FCameraFocusSettings_FocusSmoothingInterpSpeed_Offset = offsetof(FCameraFocusSettings, FocusSmoothingInterpSpeed); static_assert(FCameraFocusSettings_FocusSmoothingInterpSpeed_Offset == 0x2c, "FCameraFocusSettings::FocusSmoothingInterpSpeed offset is not 2c"); auto constexpr FCameraFocusSettings_FocusOffset_Offset = offsetof(FCameraFocusSettings, FocusOffset); static_assert(FCameraFocusSettings_FocusOffset_Offset == 0x30, "FCameraFocusSettings::FocusOffset offset is not 30"); } #endif } #ifdef _MSC_VER #pragma pack(pop) #endif
5b33423391ac50745727c0b5b4f14d7564c17ded
5f552344baa57f868f167b0c0a94e7657cdc78f4
/lab11/lab11.cpp
550ccaca489b0eeec42b5e5825f6a8f09b40e910
[]
no_license
rslater003/RileySlater-CSCI20-SPR2017
dd93b2c09c3e9900595b209e407c7b923637b6dd
85199e6ef98a663104a53d69ad1f0d00cfa6fdd2
refs/heads/master
2021-01-11T14:34:24.146913
2017-05-09T21:56:35
2017-05-09T21:56:35
80,164,092
0
0
null
null
null
null
UTF-8
C++
false
false
1,057
cpp
lab11.cpp
/* 1. Computer picks a random number between 1 and 10. Set an integer to points equal to 10. 2. User makes a random guess and based on that guess the computer either A. Tells the user the number is higher B. Tells the user the number is lower C. Tells the user the number is correct 3. If the computer has chosen option A, then the computer will deduct 1 point from int points and output: "The number picked is higher." Check if int points has hit 0, if it has, then reset program after showing output: "You lost." If int points is above 0 then repeat step 2. If the computer has chosen option B, then the computer will deduct 1 point from int points and output: "The number picked is lower." Check if int points has hit 0, if it has, then reset program after showing output: "You lost." If int points is above 0 then repeat step 2. If the computer has chosen option C, then the computer will output: "You have guessed my number!" Show congratulations pop-up. */
59fd9ab650344759ecdbff23e3fc870717bf28ce
8c76b2293240579b00661448032b530cec2e8ab8
/03.06.2015/03.06.2015/03.06.2015View.h
f3db527921bff5083460640a429b339c13e3f7d4
[]
no_license
Marezen/GDI
ba29552bf9c60d661ac6b6e057c960930d152866
8332ea2d558219bc06de800e9c833355d4448a18
refs/heads/master
2021-06-27T17:11:00.274313
2021-03-17T01:07:36
2021-03-17T01:07:36
221,233,950
0
0
null
null
null
null
UTF-8
C++
false
false
1,488
h
03.06.2015View.h
#pragma once #include "DImage.h" class CMy03062015View : public CView { protected: // create from serialization only CMy03062015View() noexcept; DECLARE_DYNCREATE(CMy03062015View) // Attributes public: CMy03062015Doc* GetDocument() const; DImage *background; // pozadina novcica // Operations public: // Overrides public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //funkcije zadatka: void DrawBackground(CDC* pDC,CPoint ptCenter,int radius,CString strPicture); void DrawCoin(CDC* pDC,CPoint ptCenter,int radius,CString strText,int fsizeText,CString strCoin,int fsizeCoin,COLORREF clrTExt); void SaveBMP(CString name,CDC* pDC,CPoint ptCEnter,int radius); //Transformacije void Rotate(CDC* pDC,float angle,bool right); void TranslateRotate(CDC* pDC,float x,float y,float angle,float distance); protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); // Implementation public: virtual ~CMy03062015View(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in 03.06.2015View.cpp inline CMy03062015Doc* CMy03062015View::GetDocument() const { return reinterpret_cast<CMy03062015Doc*>(m_pDocument); } #endif
3421392676652e71704b1bb50c570304ba8d6497
da66e463a924d8412c343033dbcd143e197c5c5c
/src/mtf.cc
5e1d905ea39d0531f534595e266390922af8a2d5
[]
no_license
xdlaba02/MUL
c7ca944eb2b0272c57aeb83cfa82edbe3b57a4c0
a988d04977b43093919159ac89f76713d89d00cc
refs/heads/master
2023-02-13T16:24:47.953789
2021-01-08T13:33:39
2021-01-08T13:33:39
327,911,963
0
0
null
null
null
null
UTF-8
C++
false
false
1,972
cc
mtf.cc
/** * @file mtf.cc * @author Drahomír Dlabaja (xdlaba02) * @date 23. 4. 2020 * @brief Funkce pro mtf transformaci. */ #include <vector> #include <string> #include <algorithm> #include <cmath> #include "mtf.h" void update_base(std::vector<uint8_t> &dictionary, uint8_t i) { auto it = std::begin(dictionary) + i; std::rotate(std::begin(dictionary), it, std::next(it)); } void update_m1ff(std::vector<uint8_t> &dictionary, uint8_t i) { auto it = std::begin(dictionary) + i; if (it <= std::next(std::begin(dictionary))) { std::rotate(std::begin(dictionary), it, std::next(it)); } else { std::rotate(std::next(std::begin(dictionary)), it, std::next(it)); } } void update_m1ff2(std::vector<uint8_t> &dictionary, uint8_t i, int16_t prev[2]) { auto it = std::begin(dictionary) + i; uint8_t c = *it; if (it <= std::next(std::begin(dictionary))) { std::rotate(std::begin(dictionary), it, std::next(it)); } else if (prev[0] == *std::begin(dictionary) || prev[1] == *std::begin(dictionary)) { std::rotate(std::next(std::begin(dictionary)), it, std::next(it)); } else { std::rotate(std::begin(dictionary), it, std::next(it)); } prev[1] = prev[0]; prev[0] = c; } void update_sticky(std::vector<uint8_t> &dictionary, uint8_t i, double v) { auto it = std::begin(dictionary) + i; size_t new_pos = std::round(i * v); std::rotate(std::begin(dictionary) + new_pos, it, std::next(it)); } void update_k(std::vector<uint8_t> &dictionary, uint8_t i, size_t k) { auto it = std::begin(dictionary) + i; size_t new_pos = std::max<int64_t>(0, static_cast<int64_t>(i) - static_cast<int64_t>(k)); std::rotate(std::begin(dictionary) + new_pos, it, std::next(it)); } void update_c(std::vector<uint8_t> &dictionary, uint8_t i, size_t c, std::map<uint8_t, size_t> &counts) { auto it = std::begin(dictionary) + i; if (counts[*it] >= c) { std::rotate(std::begin(dictionary), it, std::next(it)); } counts[*it]++; }
c237906793d4531b3a51c1e178c4f6ce41d203b5
29ca69170c7133d506e3f519a9c358ec949ed3ca
/project4/Schedule.h
fed7424c18111806c4377801ba858c6263d71bc4
[]
no_license
mwleeds/cs360
be057692decea33091bacd46f83e656336f1bfb4
7292121747c8871d6f7fc94781ae7a6ed253cc1f
refs/heads/master
2021-01-17T07:39:57.423305
2015-04-10T13:59:33
2015-04-10T13:59:33
null
0
0
null
null
null
null
UTF-8
C++
false
false
845
h
Schedule.h
// File: Schedule.h // Author: Matthew Leeds // Last Edit: 2015-03-11 #pragma once #include "Activity.h" typedef unsigned int uint; using namespace std; class Schedule { public: Schedule(); // reads in _endTime and _numActivities ~Schedule(); void recordActivities(); // reads all activities from stdin void sortByFinishTime(); void findOptimalSchedule(); // uses an optimal greedy algorithm void printOptimalSchedule(); private: uint _endTime; // >= latest finish time uint _numActivities; // total number of activities uint _numUsedActivities; // nmuber used in optimal schedule Activity** _Activities; // all activities Activity** _optimalSchedule; // schedule with maximum resource usage void _countingSort(short digit); };
7000712ed512bbc18ed466e03585264d6ef66da3
98f92b1375d23823a4f36136b7762ac79d33e5a4
/src/string_cache.hpp
256b96f11a2b9b2c7dd4a15e2cf14a63bcae926f
[ "MIT" ]
permissive
cooky451/pingstats
d60f5e311c30e35da65a18b6df121d081430133f
ed908ff6ed8fed40623c9eb8d4ae255c3c188061
refs/heads/master
2021-01-15T15:25:51.179585
2017-09-22T04:56:58
2017-09-22T04:56:58
50,164,393
19
5
null
2017-09-23T22:19:13
2016-01-22T07:08:20
C++
UTF-8
C++
false
false
4,683
hpp
string_cache.hpp
/* * Copyright (c) 2016 - 2017 cooky451 * * 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. * */ #pragma once #include "utility/utility.hpp" #include "winapi/utility.hpp" #include "canvas_drawing.hpp" #include <algorithm> #include <vector> namespace pingstats // export { using namespace utility::literals; namespace ut = utility; namespace wa = winapi; class FontSpacing { public: LONG fontWidth{ 8 }; LONG fontHeight{ 16 }; LONG fontLineSpacing{ 16 }; }; class StringCache { static constexpr std::size_t CACHE_MAX_SIZE{ 512 }; static constexpr std::size_t CACHE_CLEAR_SIZE{ 256 }; class ColoredString { public: wa::MemoryCanvas canvas; std::string str; Color clearColor{ 0, 0, 0 }; Color stringColor{ 0, 0, 0 }; mutable uint32_t usageCounter = {}; ColoredString() = default; ColoredString(std::string str, Color clearColor, Color stringColor) : str{ std::move(str) } , clearColor{ clearColor } , stringColor{ stringColor } {} bool operator == (const ColoredString& rhs) const { return str == rhs.str && clearColor.value == rhs.clearColor.value && stringColor.value == rhs.stringColor.value; } }; std::vector<ColoredString> _cache; wa::DeviceContext _deviceContext; wa::FontPtr _font; LOGFONT _logFont; FontSpacing _spacing{}; public: StringCache(const LOGFONT& logFont) : _deviceContext{ CreateCompatibleDC(nullptr) } , _font{ CreateFontIndirectW(&logFont) } , _logFont{ logFont } { _deviceContext.select(_font.get()); TEXTMETRIC metric; if (GetTextMetricsW(_deviceContext.get(), &metric)) { _spacing.fontWidth = metric.tmAveCharWidth; _spacing.fontHeight = metric.tmHeight; _spacing.fontLineSpacing = metric.tmHeight + metric.tmExternalLeading; } } auto& getLogicalFont() const { return _logFont; } auto& getFontSpacing() const { return _spacing; } void draw( wa::MemoryCanvas& canvas, Color clearColor, Color stringColor, int32_t x, int32_t y, std::string s) { if (s.size() == 0) { return; } shrink(); ColoredString cs{ std::move(s), clearColor, stringColor }; auto it = std::find(_cache.begin(), _cache.end(), cs); if (it == _cache.end()) { const auto strSize = static_cast<int>(cs.str.size()); cs.canvas = wa::MemoryCanvas{ strSize * _spacing.fontWidth, _spacing.fontHeight }; _deviceContext.select(cs.canvas.get()); clearCanvas(cs.canvas, clearColor); SetBkMode(_deviceContext.get(), TRANSPARENT); SetTextColor(_deviceContext.get(), stringColor.toColorRef()); TextOutA(_deviceContext.get(), 0, 0, cs.str.data(), strSize); _cache.push_back(std::move(cs)); it = _cache.begin() + (_cache.size() - 1); } it->usageCounter += 1; const Rect rect{ x, y, x + static_cast<pxindex>(it->canvas.width()), y + static_cast<pxindex>(it->canvas.height()) }; copyCanvasRect(canvas, it->canvas, rect, 0, 0); } void shrink() { if (_cache.size() >= CACHE_MAX_SIZE) { std::sort(_cache.begin(), _cache.end(), [](const ColoredString& lhs, const ColoredString& rhs) { return lhs.usageCounter > rhs.usageCounter; } ); _cache.resize(CACHE_CLEAR_SIZE); } } }; StringCache& getStaticStringCache(const LOGFONT& logFont) { thread_local std::vector<StringCache> cache; for (size_t i = 0; i < cache.size(); ++i) { if (std::memcmp( &cache[i].getLogicalFont(), &logFont, sizeof logFont) == 0) { return cache[i]; } } cache.emplace_back(logFont); return cache.back(); } }
b71f563082c89756b8c47dca2276ff1222c9a613
addf488ba98b8d09b0c430779ebd2649d29a3fea
/kdepim/kresources/blogging/xmlrpcjob.cpp
76bee44f804b6d96b58f98c797a442cb994edc42
[]
no_license
iegor/kdesktop
3d014d51a1fafaec18be2826ca3aa17597af9c07
d5dccbe01eeb7c0e82ac5647cf2bc2d4c7beda0b
refs/heads/master
2020-05-16T08:17:14.972852
2013-02-19T21:47:05
2013-02-19T21:47:05
9,459,573
1
0
null
null
null
null
UTF-8
C++
false
false
13,692
cpp
xmlrpcjob.cpp
/* This file is part of the KDE libraries Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com> Based on the davjob: Copyright (C) 2002 Jan-Pascal van Best <janpascal@vanbest.org> XML-RPC specific parts taken from the xmlrpciface: Copyright (C) 2003 - 2004 by Frerich Raabe <raabe@kde.org> Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "xmlrpcjob.h" #include <qvariant.h> #include <qregexp.h> #include <kdebug.h> #include <klocale.h> #include <kio/http.h> #include <kmdcodec.h> #include <kio/davjob.h> #define KIO_ARGS QByteArray packedArgs; \ QDataStream stream( packedArgs, IO_WriteOnly ); stream using namespace KIO; namespace KIO { class XMLRPCResult { friend class XmlrpcJob; public: XMLRPCResult() {} bool success() const { return m_success; } int errorCode() const { return m_errorCode; } QString errorString() const { return m_errorString; } QValueList<QVariant> data() const { return m_data; } private: bool m_success; int m_errorCode; QString m_errorString; QValueList<QVariant> m_data; }; } class XmlrpcJob::XmlrpcJobPrivate { public: // QByteArray savedStaticData; }; XmlrpcJob::XmlrpcJob( const KURL& url, const QString& method, const QValueList<QVariant> &params, bool showProgressInfo) : TransferJob( url, KIO::CMD_SPECIAL, QByteArray(), QByteArray(), showProgressInfo ) { d = new XmlrpcJobPrivate; // We couldn't set the args when calling the parent constructor, // so do it now. QDataStream stream( m_packedArgs, IO_WriteOnly ); stream << (int)1 << url; kdDebug()<<"XMLrpcJob::url="<<url.url()<<endl; kdDebug()<<"XmlrpcJob::XmlrpcJob, method="<<method<<endl; // Same for static data if ( ! method.isEmpty() ) { kdDebug()<<"XmlrpcJob::XmlrpcJob, method not empty."<<endl; QString call = markupCall( method, params ); staticData = call.utf8(); staticData.truncate( staticData.size() - 1 ); kdDebug() << "Message: " << call << endl; // d->savedStaticData = staticData.copy(); } addMetaData( "UserAgent", "KDE XML-RPC TransferJob" ); addMetaData( "content-type", "Content-Type: text/xml; charset=utf-8" ); addMetaData( "ConnectTimeout", "50" ); } XmlrpcJob::~XmlrpcJob() { delete d; d = 0; } QString XmlrpcJob::markupCall( const QString &cmd, const QValueList<QVariant> &args ) { kdDebug()<<"XmlrpcJob::markupCall, cmd="<<cmd<<endl; QString markup = "<?xml version=\"1.0\" ?>\r\n<methodCall>\r\n"; markup += "<methodName>" + cmd + "</methodName>\r\n"; if ( !args.isEmpty() ) { markup += "<params>\r\n"; QValueList<QVariant>::ConstIterator it = args.begin(); QValueList<QVariant>::ConstIterator end = args.end(); for ( ; it != end; ++it ) markup += "<param>\r\n" + marshal( *it ) + "</param>\r\n"; markup += "</params>\r\n"; } markup += "</methodCall>\r\n"; return markup; } void XmlrpcJob::slotData( const QByteArray& data ) { kdDebug()<<"XmlrpcJob::slotData()"<<endl; if ( m_redirectionURL.isEmpty() || !m_redirectionURL.isValid() || m_error ) m_str_response.append( QString( data ) ); } void XmlrpcJob::slotFinished() { kdDebug() << "XmlrpcJob::slotFinished()" << endl; kdDebug() << m_str_response << endl; // TODO: Redirection with XML-RPC?? /* if (! m_redirectionURL.isEmpty() && m_redirectionURL.isValid() ) { QDataStream istream( m_packedArgs, IO_ReadOnly ); int s_cmd, s_method; KURL s_url; istream >> s_cmd; istream >> s_url; istream >> s_method; // PROPFIND if ( (s_cmd == 7) && (s_method == (int)KIO::HTTP_POST) ) { m_packedArgs.truncate(0); QDataStream stream( m_packedArgs, IO_WriteOnly ); stream << (int)7 << m_redirectionURL << (int)KIO::HTTP_POST; } } else */ kdDebug() << "\033[35;40mResult: " << m_str_response << "\033[0;0m" << endl; QDomDocument doc; QString errMsg; int errLine, errCol; if ( doc.setContent( m_str_response, false, &errMsg, &errLine, &errCol ) ) { if ( isMessageResponse( doc ) ) { m_response = parseMessageResponse( doc ).data(); m_responseType = XMLRPCMessageResponse; } else if ( isFaultResponse( doc ) ) { // TODO: Set the error of the job m_response.clear(); m_response << QVariant( parseFaultResponse( doc ).errorString() ); m_responseType = XMLRPCFaultResponse; } else { // TODO: Set the error of the job m_response.clear(); m_response << QVariant( i18n( "Unknown type of XML markup received. " "Markup: \n %1" ).arg( m_str_response ) ); m_responseType = XMLRPCUnknownResponse; } } else { // TODO: if we can't parse the XML response, set the correct error message! // emit fault( -1, i18n( "Received invalid XML markup: %1 at %2:%3" ) // .arg( errMsg ).arg( errLine ).arg( errCol ), m_id ); } TransferJob::slotFinished(); // TODO: Redirect: if( d ) staticData = d->savedStaticData.copy(); // Need to send XMLRPC request to this host too } bool XmlrpcJob::isMessageResponse( const QDomDocument &doc ) { return doc.documentElement().firstChild().toElement() .tagName().lower() == "params"; } XMLRPCResult XmlrpcJob::parseMessageResponse( const QDomDocument &doc ) { XMLRPCResult response; response.m_success = true; QDomNode paramNode = doc.documentElement().firstChild().firstChild(); while ( !paramNode.isNull() ) { response.m_data << demarshal( paramNode.firstChild().toElement() ); paramNode = paramNode.nextSibling(); } return response; } bool XmlrpcJob::isFaultResponse( const QDomDocument &doc ) { return doc.documentElement().firstChild().toElement() .tagName().lower() == "fault"; } XMLRPCResult XmlrpcJob::parseFaultResponse( const QDomDocument &doc ) { XMLRPCResult response; response.m_success = false; QDomNode errorNode = doc.documentElement().firstChild().firstChild(); const QVariant errorVariant = demarshal( errorNode.toElement() ); response.m_errorCode = errorVariant.toMap() [ "faultCode" ].toInt(); response.m_errorString = errorVariant.toMap() [ "faultString" ].toString(); return response; } QString XmlrpcJob::marshal( const QVariant &arg ) { switch ( arg.type() ) { case QVariant::String: case QVariant::CString: return "<value><string>" + arg.toString() + "</string></value>\r\n"; case QVariant::Int: return "<value><int>" + QString::number( arg.toInt() ) + "</int></value>\r\n"; case QVariant::Double: return "<value><double>" + QString::number( arg.toDouble() ) + "</double></value>\r\n"; case QVariant::Bool: { QString markup = "<value><boolean>"; markup += arg.toBool() ? "1" : "0"; markup += "</boolean></value>\r\n"; return markup; } case QVariant::ByteArray: return "<value><base64>" + KCodecs::base64Encode( arg.toByteArray() ) + "</base64></value>\r\n"; case QVariant::DateTime: return "<value><datetime.iso8601>" + arg.toDateTime().toString( Qt::ISODate ) + "</datetime.iso8601></value>\r\n"; case QVariant::List: { QString markup = "<value><array><data>\r\n"; const QValueList<QVariant> args = arg.toList(); QValueList<QVariant>::ConstIterator it = args.begin(); QValueList<QVariant>::ConstIterator end = args.end(); for ( ; it != end; ++it ) markup += marshal( *it ); markup += "</data></array></value>\r\n"; return markup; } case QVariant::Map: { QString markup = "<value><struct>\r\n"; QMap<QString, QVariant> map = arg.toMap(); QMap<QString, QVariant>::ConstIterator it = map.begin(); QMap<QString, QVariant>::ConstIterator end = map.end(); for ( ; it != end; ++it ) { markup += "<member>\r\n"; markup += "<name>" + it.key() + "</name>\r\n"; markup += marshal( it.data() ); markup += "</member>\r\n"; } markup += "</struct></value>\r\n"; return markup; } default: kdWarning() << "Failed to marshal unknown variant type: " << arg.type() << endl; }; return QString::null; } QVariant XmlrpcJob::demarshal( const QDomElement &elem ) { Q_ASSERT( elem.tagName().lower() == "value" ); if ( !elem.hasChildNodes() ) { // it doesn't have child nodes, so no explicit type name was given, // i.e. <value>here comes the value</value> instead of // <value><string>here comes the value</string></value> // Assume <string> in that case: // Actually, the element will still have a child node, so this will not help here. // The dirty hack is at the end of this method. kdDebug()<<"XmlrpcJob::demarshal: No child nodes, assume type=string. Text: "<<elem.text()<<endl; return QVariant( elem.text() ); } kdDebug()<<"Demarshalling element \"" << elem.text() <<"\"" << endl; const QDomElement typeElement = elem.firstChild().toElement(); const QString typeName = typeElement.tagName().lower(); if ( typeName == "string" ) return QVariant( typeElement.text() ); else if ( typeName == "i4" || typeName == "int" ) return QVariant( typeElement.text().toInt() ); else if ( typeName == "double" ) return QVariant( typeElement.text().toDouble() ); else if ( typeName == "boolean" ) { if ( typeElement.text().lower() == "true" || typeElement.text() == "1" ) return QVariant( true ); else return QVariant( false ); } else if ( typeName == "base64" ) return QVariant( KCodecs::base64Decode( typeElement.text().latin1() ) ); else if ( typeName == "datetime" || typeName == "datetime.iso8601" ) { QString text( typeElement.text() ); if ( text.find( QRegExp("^[0-9]{8,8}T") ) >= 0 ) { // It's in the format 20041120T...., so adjust it to correct // ISO 8601 Format 2004-11-20T..., else QDateTime::fromString won't work: text = text.insert( 6, '-' ); text = text.insert( 4, '-' ); } return QVariant( QDateTime::fromString( text, Qt::ISODate ) ); } else if ( typeName == "array" ) { QValueList<QVariant> values; QDomNode valueNode = typeElement.firstChild().firstChild(); while ( !valueNode.isNull() ) { values << demarshal( valueNode.toElement() ); valueNode = valueNode.nextSibling(); } return QVariant( values ); } else if ( typeName == "struct" ) { QMap<QString, QVariant> map; QDomNode memberNode = typeElement.firstChild(); while ( !memberNode.isNull() ) { const QString key = memberNode.toElement().elementsByTagName( "name" ).item( 0 ).toElement().text(); const QVariant data = demarshal( memberNode.toElement().elementsByTagName( "value" ).item( 0 ).toElement() ); map[ key ] = data; memberNode = memberNode.nextSibling(); } return QVariant( map ); } else { kdWarning() << "Cannot demarshal unknown type " << typeName << ", text= " << typeElement.text() << endl; // FIXME: This is just a workaround, for the issue mentioned at the beginning of this method. return QVariant( elem.text() ); } return QVariant(); } /* Convenience methods */ XmlrpcJob* KIO::xmlrpcCall( const KURL& url, const QString &method, const QValueList<QVariant> &params, bool showProgressInfo ) { if ( url.isEmpty() ) { kdWarning() << "Cannot execute call to " << method << ": empty server URL" << endl; return 0; } XmlrpcJob *job = new XmlrpcJob( url, method, params, showProgressInfo ); // job->addMetaData( "xmlrpcDepth", depth ); return job; } XmlrpcJob* KIO::xmlrpcCall( const KURL& url, const QString &method, const QVariant &arg, bool showProgressInfo ) { QValueList<QVariant> args; args << arg; return KIO::xmlrpcCall( url, method, args, showProgressInfo ); } XmlrpcJob* KIO::xmlrpcCall( const KURL& url, const QString &method, const QStringList &arg, bool showProgressInfo ) { QValueList<QVariant> args; QStringList::ConstIterator it = arg.begin(); QStringList::ConstIterator end = arg.end(); for ( ; it != end; ++it ) args << QVariant( *it ); return KIO::xmlrpcCall( url, method, args, showProgressInfo ); } template <typename T> XmlrpcJob* KIO::xmlrpcCall( const KURL& url, const QString &method, const QValueList<T>&arg, bool showProgressInfo ) { QValueList<QVariant> args; typename QValueList<T>::ConstIterator it = arg.begin(); typename QValueList<T>::ConstIterator end = arg.end(); for ( ; it != end; ++it ) args << QVariant( *it ); return KIO::xmlrpcCall( url, method, args, showProgressInfo ); } #include "xmlrpcjob.moc"
528dfed076a85b4989f2ac4f3b37a9297d3413c6
a362e94fa7babfe78650c81f2fc09fad64f66503
/src/wrappers/wmutex.h
8ccd8d6ae476dd5220268cc436117d524922c470
[]
no_license
Nopik/nrf_radio_crash
7c283d7b0848cc8234248f2a8eb83454d7ea9c29
c15fa621f1324d9472968e54f3f5b54d54d8af29
refs/heads/master
2020-04-01T02:18:34.281222
2018-10-15T09:28:47
2018-10-15T09:28:47
152,773,763
0
0
null
null
null
null
UTF-8
C++
false
false
1,497
h
wmutex.h
#ifndef NODE_THREAD_CMUTEX_H #define NODE_THREAD_CMUTEX_H #include "FreeRTOS.h" #include "semphr.h" namespace Wrappers { class MutexBase { public: bool Take(TickType_t aTimeout = portMAX_DELAY); bool TakeFromISR(BaseType_t *xHigherPriorityTaskWoken = nullptr); bool Give(); bool GiveFromISR(BaseType_t *xHigherPriorityTaskWoken = nullptr); protected: SemaphoreHandle_t mMutexHandle = nullptr; }; class Mutex : public MutexBase { public: Mutex(); }; class RecursiveMutex { public: RecursiveMutex(); bool Take(TickType_t aTimeout = portMAX_DELAY); bool Give(); protected: SemaphoreHandle_t mMutexHandle = nullptr; }; class Semaphore : public MutexBase { public: Semaphore(); }; class LockGuard { public: explicit LockGuard(Mutex& aMutex); ~LockGuard(); private: /** * Remove copy constructor. */ LockGuard(const LockGuard&); Mutex& mMutex; }; class LockGuardRecursive { public: explicit LockGuardRecursive(RecursiveMutex& aMutex); ~LockGuardRecursive(); private: /** * Remove copy constructor. */ LockGuardRecursive(const LockGuardRecursive&); RecursiveMutex& mMutex; }; class LockGuardFromISR { public: explicit LockGuardFromISR(Mutex& aMutex); ~LockGuardFromISR(); private: /** * Remove copy constructor. */ LockGuardFromISR(const LockGuardFromISR&); Mutex& mMutex; }; } // namespace Wrappers #endif //NODE_THREAD_CMUTEX_H
5960cafe7f89fe26a502e6215ac63dd1adca3dd0
7c2b0060356c4d310f5cca7c8b29ee22f4fca506
/myexamples/imProcessingBench/bench_matching.cpp
8818c53d810786563b16b64599f89c20c298e0fd
[]
no_license
contaconta/grpc_test
eeda6c4837f9bcc98529c5e1643083199ace492a
8f47a1f4e8cdc1f8bc3a2002ab7d557ac28f4bc7
refs/heads/master
2021-01-11T05:50:12.535505
2016-10-01T04:01:44
2016-10-01T04:01:44
69,648,575
0
0
null
null
null
null
UTF-8
C++
false
false
1,113
cpp
bench_matching.cpp
//Template Matching #include <iostream> #include <vector> #include <chrono> #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #define NTIMES 1000 using namespace std; using namespace cv; int main(int argc, char* argv[]){ Mat img,tmp,result; Point top_left; double proccessingTime=0; if(argc!=3){ cerr<<"usage imgfilename tmpfilename"<<endl; exit(1); } img=imread(argv[1]); tmp=imread(argv[2]); int width=tmp.cols; int height=tmp.rows; for(int i=0;i<NTIMES;i++){ auto start=std::chrono::system_clock::now(); matchTemplate( img, tmp, result, TM_CCOEFF_NORMED); auto end=std::chrono::system_clock::now(); proccessingTime+=std::chrono::duration_cast<std::chrono::milliseconds> /// Localizing the best match with minMaxLoc double minVal, maxVal; Point minLoc, maxLoc; minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() ); top_left= maxLoc; } cerr<<"matched at ( "<<top_left.x<<", "<<top_left.y<<" ) to ( "<<(top_left.x+width)<<" , "<<(top_left.y+height)<<" )."<<endl; cout<<"Time "<<proccessingTime<<"ms"<<std::endl; return 0; }
dcfe722524fc63bc3d0bc80540c01b028697cf75
a4f955e84880c1a110e65484187d221c54b7c799
/ch15_oop/class.cpp
c25b55057ec1521eb38c8163185ea7aa88d06f52
[]
no_license
kk4728/CppPrimer5th
5fe6a1997002ed8e8ef3c0c0a508666b403956af
7fa2d6d7957fe0a8b53a2cbfe71e63babb16cdee
refs/heads/master
2020-04-24T18:12:12.155711
2019-04-23T08:25:04
2019-04-23T08:25:04
172,173,131
0
0
null
null
null
null
UTF-8
C++
false
false
1,393
cpp
class.cpp
#include <iostream> using namespace std; class A { public: A() = default; //A& operator=(const A& ) = default; virtual ~A() =default; virtual void net_work() { cout << "A: net_work() " << endl; }; void print() { cout << "m:addr: " << &m << endl; cout << "A::a:addr: " << &a << endl; } public: int m; protected: int a; }; class B : public A { public: void net_work() { cout << "B: net_work() " <<endl; } void print() { cout << "m:addr: " << &m << endl; cout << "a:addr: " << &a << endl; } //B& operator=(const B&) = default; //int m; }; class D : public A {}; //OK class D1 : private A {}; //OK //class D2 : public A; // 声明中不能包含派生列表 //class D3 : public D3 {}; //不能以自己为基类(自身还未定义) int main() { A a1 ; B b1 ; A *p1 = new A(); A* p2 = new B(); p1->net_work(); p2->net_work(); a1.net_work(); b1.net_work(); //a1.a; a1.m = 100; //b1.A::a; a1.print(); b1.print(); //////////////////// //A 为基类;B为派生类 A a11; //B b11 = a11; // 派生类对象无法赋值给基类 //B b12(a11); // 没有找到匹配的构造函数 //b11 = a11; // B b13; A a12(b13); // b13被截断,实际上B中只有基类部分初始化 a11 = b13; // b13被截断,实际上B中只有基类部分被赋值 return 0; }
50b5e31938e6cf01e298867efaece3268affe7e5
366d1b9a999aaa856a325ae80268af20b995babe
/src/shogun/preprocessor/SortWordString.cpp
45a0b62f75b8651baa7e5034ffdb1b947a5979b3
[ "BSD-3-Clause", "DOC", "GPL-3.0-only" ]
permissive
karlnapf/shogun
bc3fcbeef377b8157bd8a9639211c2667b535846
eebce07a4309bb7e1d3a4f0981efd49e687533b6
refs/heads/develop
2020-04-05T22:46:38.369312
2019-07-09T08:59:14
2019-07-09T08:59:14
4,420,161
1
1
BSD-3-Clause
2018-09-04T10:50:41
2012-05-23T13:12:40
C++
UTF-8
C++
false
false
1,323
cpp
SortWordString.cpp
/* * This software is distributed under BSD 3-clause license (see LICENSE file). * * Authors: Soeren Sonnenburg, Evan Shelhamer */ #include <shogun/preprocessor/SortWordString.h> #include <shogun/features/Features.h> #include <shogun/features/StringFeatures.h> #include <shogun/mathematics/Math.h> using namespace shogun; CSortWordString::CSortWordString() : CStringPreprocessor<uint16_t>() { } CSortWordString::~CSortWordString() { } /// clean up allocated memory void CSortWordString::cleanup() { } /// initialize preprocessor from file bool CSortWordString::load(FILE* f) { SG_SET_LOCALE_C; SG_RESET_LOCALE; return false; } /// save preprocessor init-data to file bool CSortWordString::save(FILE* f) { SG_SET_LOCALE_C; SG_RESET_LOCALE; return false; } void CSortWordString::apply_to_string_list(SGStringList<uint16_t> string_list) { for (auto i : range(string_list.num_strings)) { int32_t len = 0 ; auto& vec = string_list.strings[i]; //CMath::qsort(vec, len); CMath::radix_sort(vec.string, vec.slen); } } /// apply preproc on single feature vector uint16_t* CSortWordString::apply_to_string(uint16_t* f, int32_t& len) { uint16_t* vec=SG_MALLOC(uint16_t, len); int32_t i=0; for (i=0; i<len; i++) vec[i]=f[i]; //CMath::qsort(vec, len); CMath::radix_sort(vec, len); return vec; }
020bbac24f35f2bf97705d258c965c0252389625
6923f79f1eaaba0ab28b25337ba6cb56be97d32d
/rcrandall-segment/ReadWritePBM.h
dca5d8c1f34fbd162218b2541a136009103c3d06
[]
no_license
burakbayramli/books
9fe7ba0cabf06e113eb125d62fe16d4946f4a4f0
5e9a0e03aa7ddf5e5ddf89943ccc68d94b539e95
refs/heads/master
2023-08-17T05:31:08.885134
2023-08-14T10:05:37
2023-08-14T10:05:37
72,460,321
223
174
null
2022-10-24T12:15:06
2016-10-31T17:24:00
Jupyter Notebook
UTF-8
C++
false
false
419
h
ReadWritePBM.h
// R. Crandall // // Functions to read/write NetPBM image files #ifndef READ_WRITE_PBM_H #define READ_WRITE_PBM_H #include "Image.h" #include <fstream> #include <string> #include <iostream> #include <cstdlib> using namespace std; // Read/write a P5 image (binary PGM data) Image<unsigned char>* ReadP5image(string filename); void WriteP5image(Image<unsigned char>* image, string filename, int grayLevel); #endif
1aca91844f81b7356ad55d88ec2d43c13677d4c2
8f1d29f843158f191fa28a6987aefdaeb0c5159e
/asteroids/src/asteroids.cpp
13b881df35d144acd2a9ff4f172c3ceeb0d4601e
[]
no_license
Small-Embedded-Systems/assignment-2-asteroids-jackmullins06
b58be1f39e86f191631e494db5e8d5c10703d4b8
abdebec78b1b473678767c8eec97f601ac6a8115
refs/heads/master
2021-01-24T18:27:24.527209
2017-05-14T22:05:03
2017-05-14T22:05:03
84,449,220
0
0
null
null
null
null
UTF-8
C++
false
false
1,423
cpp
asteroids.cpp
/* Asteroids Sample solution for assignment Semester 2 -- Small Embedded Systems Dr Alun Moon */ /* C libraries */ #include <stdlib.h> #include <stdint.h> #include <stdbool.h> #include <math.h> #include <string.h> /* hardware platform libraries */ #include <display.h> #include <mbed.h> /* Main game elements */ #include "model.h" #include "view.h" #include "controller.h" /* Game state */ float elapsed_time; int score; int lives; struct ship player; float Dt = 0.01f; bool gameStart = false; bool inPlay = false; Ticker model, view, controller, rocks; void timerHandler(); bool paused = true; /* The single user button needs to have the PullUp resistor enabled */ DigitalIn userbutton(P2_10,PullUp); /* Set game variables back to default */ void resetGame(void) { lives = 5; player.shield = 3; score = 0; player.x = 230; player.y = 120; } int main() { init_DBuffer(); intialiseAsteroidHeap(); intialiseMissileHeap(); view.attach(draw, 0.025); model.attach(physics, Dt); controller.attach(controls, 0.1); rocks.attach(spawnAsteroid, 0.1); lives = 5; while(userbutton.read()){ /* remember 1 is not pressed */ paused=true; wait_ms(100); } paused = false; while(true) { if(gameStart == true && lives == 0) { view.detach(); model.detach(); controller.detach(); rocks.detach(); drawEndScreen(); wait_ms(300); } } }
0df11b79db36b818c3ee5a1f05b5d4d48544f8af
1b4ff18ee477ea9e07a9032c6d5712f5f44a7b6e
/Cpf/Plugins/Platform/Concurrency/UnitTest/Test_Scheduler_Opcode_SharedAddressRegister.cpp
adee2201f7cb579110c26655bb478d69104bc549
[ "MIT" ]
permissive
All8Up/cpf
df05f5425d68a1b910e22f9b982edf037fce8809
81c68fbb69619261a5aa058cda73e35812ed3543
refs/heads/master
2021-09-23T12:18:24.989618
2017-10-31T03:19:15
2017-10-31T03:19:15
81,844,814
6
3
null
null
null
null
UTF-8
C++
false
false
996
cpp
Test_Scheduler_Opcode_SharedAddressRegister.cpp
////////////////////////////////////////////////////////////////////////// #include "Configuration.hpp" #include "gmock/gmock.h" #include "Concurrency/Scheduler.hpp" #if 0 TEST(Concurrency, Set_SharedAddressRegister) { using namespace CPF; using namespace Concurrency; ScopedInitializer<Platform::TimeInitializer> timeInit; Threading::Thread::Group threads(Threading::Thread::GetHardwareThreadCount()); Scheduler* scheduler = new Scheduler; Scheduler::Semaphore sync; scheduler->Initialize(std::move(threads)); { Scheduler::Queue queue = scheduler->CreateQueue(); for (intptr_t i = 0; i < Scheduler::kRegisterCount; ++i) queue.SA(int(i), (void*)i); for (intptr_t i = 0; i < Scheduler::kRegisterCount; ++i) queue.FirstOne([](Scheduler::ThreadContext& threadContext, void* context) { int ival(int((intptr_t)context)); EXPECT_EQ(ival, (intptr_t)threadContext.SA(ival)); }, (void*)intptr_t(i)); queue.Submit(sync); queue.Execute(); sync.Acquire(); } } #endif
d9a7c0e724568880b9c1e841e0a53c5077b38bfa
2a34b0c2779c8220272cd3781a39c5867146b615
/src/libc/float10/f10enc_get_float.cc
51613fba1a4b84867b95e294d78e63413a63cced
[ "LicenseRef-scancode-unknown-license-reference", "BSD-2-Clause" ]
permissive
yurydelendik/cloudlibc
f824043879ee7147049eb2bf5b243e7b0b5ac530
b25d9232b3e5b3757231afdc888d2b9072673917
refs/heads/master
2020-04-10T02:42:27.618187
2018-12-15T00:53:03
2018-12-15T00:53:03
160,750,519
0
0
NOASSERTION
2018-12-07T00:43:43
2018-12-07T00:43:43
null
UTF-8
C++
false
false
332
cc
f10enc_get_float.cc
// Copyright (c) 2015 Nuxi, https://nuxi.nl/ // // SPDX-License-Identifier: BSD-2-Clause #include <common/float10.h> #include <double-conversion/strtod.h> float __f10enc_get_float(const char *str, size_t len, int exponent) { return double_conversion::Strtof( double_conversion::Vector<const char>(str, len), exponent); }
87461ee11148b57313f6bcbf9dfd198cd10dd859
7d5119d123d65ccf3a2ead8bbb85fc9263acbb7a
/ssl/connector.h
a045df1e5fe7996030b1cc64a9219582f08a5c44
[]
no_license
LeTobi/tobilib
ce5fd1e86acbbab31f469c3f0fd698209c034077
cca1f359dac60055f319efa232353ffd9c9f83b3
refs/heads/stage
2022-05-09T18:35:06.247528
2022-04-03T17:14:30
2022-04-03T17:14:30
145,462,833
0
0
null
2021-05-24T09:21:58
2018-08-20T19:41:27
C++
UTF-8
C++
false
false
1,283
h
connector.h
#ifndef TC_NETWORK_SSL_CONNECTOR_H #define TC_NETWORK_SSL_CONNECTOR_H #include <boost/asio.hpp> #include <memory> #include <string> #include "alias.h" #include "../network/tcp-connector.h" #include "../network/acceptor.h" namespace tobilib { namespace network { namespace detail { class SSL_ClientConnector: public Connector<SSL_Socket> { public: SSL_ClientConnector(const std::string&, unsigned int, SSL_Socket*, boost::asio::io_context&, ConnectorOptions&); void tick(); void connect(); void cancel(); void reset(SSL_Socket*); private: bool asio_handshaking = false; Timer hs_timer; TCP_ClientConnector lowerlevel; SSL_Socket* socket; std::string target_address; void on_handshake(const boost::system::error_code&); }; class SSL_ServerConnector: public Connector<SSL_Socket> { public: SSL_ServerConnector(Acceptor&, SSL_Socket*, boost::asio::io_context&, ConnectorOptions&); void tick(); void connect(); void cancel(); void reset(SSL_Socket*); private: bool asio_handshaking = false; Timer hs_timer; TCP_ServerConnector lowerlevel; SSL_Socket* socket; void on_handshake(const boost::system::error_code&); }; } // namespace detail } // namespace network } // namespace tobilib #endif
1bb7909e5cd8f03a1ff8a2d51b84dcef5125c0c5
e398e01aa3de2a8da61adcfd3833689ea080f231
/test/TestClientRepository.cpp
c8beb919a611cfe0492afc6e72ae9e28468304a2
[]
no_license
agnieszka2018/vehiclesRent
0391ca88ab4216724f1ff8cfbf5e87fc24a42cf3
9ff446ab3763f26e2507963f522748174555ac7c
refs/heads/master
2020-04-21T07:14:14.884605
2019-01-11T00:26:35
2019-01-11T00:26:35
169,387,671
0
0
null
null
null
null
UTF-8
C++
false
false
5,426
cpp
TestClientRepository.cpp
// // Created by pobi on 09.01.19. // #include <boost/test/unit_test.hpp> #include <iostream> #include <string> #include "list" #include <memory> #include "model/client/Client.h" #include "model/repositories/ClientRepository.h" #include "model/client/Address.h" #include "model/client/RegularType.h" #include "model/client/VipType.h" typedef std::shared_ptr<ClientRepository> ClientRepoPtr; typedef std::shared_ptr<Address> AddressPtr; typedef std::shared_ptr<RegularType> RegularTypePtr; typedef std::shared_ptr<VipType> VipTypePtr; BOOST_AUTO_TEST_SUITE(RentSuiteCorrect) BOOST_AUTO_TEST_CASE(ClientRepositoryAddClientCase) { //data RegularTypePtr regulartype = std::make_shared<RegularType>(); AddressPtr actuallAddress = std::make_shared<Address>("Mickiewicza", "7"); AddressPtr actuallRegAddress = std::make_shared<Address>("Redutowa", "744"); ClientPtr klientStefan = std::make_shared<Client>("Stefan", "Stonoga", "1029384756", regulartype, actuallAddress, actuallRegAddress); ClientRepository RepozytoriumKlientow; RepozytoriumKlientow.addClient(klientStefan); VipTypePtr viptype = std::make_shared<VipType>(); AddressPtr actuallAddressOther = std::make_shared<Address>("Rudnickiego", "89"); AddressPtr actuallRegAddressOther = std::make_shared<Address>("Kasprowicza", "14"); ClientPtr klientZofia = std::make_shared<Client>("Zofia", "Kowalska", "9000084758", viptype, actuallAddressOther, actuallRegAddressOther); RepozytoriumKlientow.addClient(klientZofia); std::list<ClientPtr> klienci = RepozytoriumKlientow.getClients(); int liczbaKlientow = klienci.size(); BOOST_REQUIRE_EQUAL(2, liczbaKlientow); } BOOST_AUTO_TEST_CASE(ClientRepositoryRemoveClientCase) { //data RegularTypePtr regulartype = std::make_shared<RegularType>(); AddressPtr actuallAddress = std::make_shared<Address>("Mickiewicza", "7"); AddressPtr actuallRegAddress = std::make_shared<Address>("Redutowa", "744"); ClientPtr klientStefan = std::make_shared<Client>("Stefan", "Stonoga", "1029384756", regulartype, actuallAddress, actuallRegAddress); VipTypePtr viptype = std::make_shared<VipType>(); AddressPtr actuallAddressOther = std::make_shared<Address>("Rudnickiego", "89"); AddressPtr actuallRegAddressOther = std::make_shared<Address>("Kasprowicza", "14"); ClientPtr klientZofia = std::make_shared<Client>("Zofia", "Kowalska", "9000084758", viptype, actuallAddressOther, actuallRegAddressOther); ClientRepository RepozytoriumKlientow; RepozytoriumKlientow.addClient(klientStefan); RepozytoriumKlientow.addClient(klientZofia); RepozytoriumKlientow.removeClient(klientStefan); //została tylko klientka Zofia std::list<ClientPtr> listaKlientow = RepozytoriumKlientow.getClients(); ClientPtr klientNowy = listaKlientow.back(); BOOST_REQUIRE_EQUAL(klientNowy, klientZofia); RepozytoriumKlientow.removeClient(klientZofia); //od teraz lista jest pusta listaKlientow = RepozytoriumKlientow.getClients(); BOOST_REQUIRE_EQUAL(true, listaKlientow.empty()); } BOOST_AUTO_TEST_CASE(ClientRepositoryModifyTypeCase) { //data RegularTypePtr regulartype = std::make_shared<RegularType>(); AddressPtr actuallAddress = std::make_shared<Address>("Mickiewicza", "7"); AddressPtr actuallRegAddress = std::make_shared<Address>("Redutowa", "744"); ClientPtr klientStefan = std::make_shared<Client>("Stefan", "Stonoga", "1029384756", regulartype, actuallAddress, actuallRegAddress); VipTypePtr viptype = std::make_shared<VipType>(); AddressPtr actuallAddressOther = std::make_shared<Address>("Rudnickiego", "89"); AddressPtr actuallRegAddressOther = std::make_shared<Address>("Kasprowicza", "14"); ClientPtr klientZofia = std::make_shared<Client>("Zofia", "Kowalska", "9000084758", viptype, actuallAddressOther, actuallRegAddressOther); ClientRepository RepozytoriumKlientow; RepozytoriumKlientow.addClient(klientStefan); RepozytoriumKlientow.addClient(klientZofia); RepozytoriumKlientow.modifyClientType(klientStefan, viptype); std::list<ClientPtr> listaKlientow = RepozytoriumKlientow.getClients(); std::list<ClientPtr>::iterator iter; ClientTypePtr typ; for (iter = listaKlientow.begin(); iter != listaKlientow.end(); iter++) { if (*iter == klientStefan) typ = (*iter)->getClientType(); } BOOST_REQUIRE_EQUAL(viptype, typ); } BOOST_AUTO_TEST_SUITE_END()