hexsha
stringlengths
40
40
size
int64
7
1.05M
ext
stringclasses
13 values
lang
stringclasses
1 value
max_stars_repo_path
stringlengths
4
269
max_stars_repo_name
stringlengths
5
109
max_stars_repo_head_hexsha
stringlengths
40
40
max_stars_repo_licenses
listlengths
1
9
max_stars_count
int64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
4
269
max_issues_repo_name
stringlengths
5
116
max_issues_repo_head_hexsha
stringlengths
40
40
max_issues_repo_licenses
listlengths
1
9
max_issues_count
int64
1
48.5k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
4
269
max_forks_repo_name
stringlengths
5
116
max_forks_repo_head_hexsha
stringlengths
40
40
max_forks_repo_licenses
listlengths
1
9
max_forks_count
int64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
7
1.05M
avg_line_length
float64
1.21
330k
max_line_length
int64
6
990k
alphanum_fraction
float64
0.01
0.99
author_id
stringlengths
2
40
e9195c62e6f80681cacee7d40079aa49e1f7115a
1,441
cpp
C++
test/proto_test.cpp
irl-game/irl
ba507a93371ab172b705c1ede8cd062123fc96f5
[ "MIT" ]
null
null
null
test/proto_test.cpp
irl-game/irl
ba507a93371ab172b705c1ede8cd062123fc96f5
[ "MIT" ]
null
null
null
test/proto_test.cpp
irl-game/irl
ba507a93371ab172b705c1ede8cd062123fc96f5
[ "MIT" ]
null
null
null
#include <catch2/catch.hpp> #include <ser/macro.hpp> #include <ser/overloaded.hpp> #include <ser/proto.hpp> #include <ser/ser.hpp> #include <sstream> class A { public: int a = 0; #define SER_PROPERTY_LIST SER_PROPERTY(a); SER_DEFINE_PROPERTIES() #undef SER_PROPERTY_LIST }; class B { public: int a = 0; #define SER_PROPERTY_LIST SER_PROPERTY(a); SER_DEFINE_PROPERTIES(); #undef SER_PROPERTY_LIST }; TEST_CASE("Simple A", "[proto]") { A a; Proto<A, B> p; std::vector<char> buff; OStrm ost(buff); p.ser(ost, a); IStrm ist{buff.data(), buff.data() + buff.size()}; auto isRecvdA{false}; auto isRecvdB{false}; p.deser(ist, overloaded{[&isRecvdA](const A &) { isRecvdA = true; }, [&isRecvdB](const B &) { isRecvdB = true; }}); REQUIRE(isRecvdA); REQUIRE(!isRecvdB); } TEST_CASE("Simple B", "[proto]") { B a; Proto<A, B> p; std::vector<char> buff; OStrm ost(buff); p.ser(ost, a); IStrm ist{buff.data(), buff.data() + buff.size()}; auto isRecvdA{false}; auto isRecvdB{false}; p.deser(ist, overloaded{[&isRecvdA](const A &) { isRecvdA = true; }, [&isRecvdB](const B &) { isRecvdB = true; }}); REQUIRE(!isRecvdA); REQUIRE(isRecvdB); } TEST_CASE("Version", "[proto]") { Proto<A> p1; Proto<B> p2; REQUIRE(p1.version() == p2.version()); // A and B have same structure Proto<A, B> p3; REQUIRE(p1.version() != p3.version()); }
21.191176
71
0.617627
irl-game
e9196783db929d2a6360702c0d7083201818f5a4
442
hpp
C++
include/util.hpp
adi-g15/saras
a9d5f8c4b2d4da4b14e025329dd5654b0044aef6
[ "Unlicense" ]
5
2021-11-26T09:43:45.000Z
2021-12-01T19:52:21.000Z
include/util.hpp
adi-g15/saras
a9d5f8c4b2d4da4b14e025329dd5654b0044aef6
[ "Unlicense" ]
null
null
null
include/util.hpp
adi-g15/saras
a9d5f8c4b2d4da4b14e025329dd5654b0044aef6
[ "Unlicense" ]
2
2021-11-26T11:16:06.000Z
2021-12-01T19:52:09.000Z
#pragma once #include <functional> #include <memory> // https://arne-mertz.de/2018/05/overload-build-a-variant-visitor-on-the-fly/ // Common pattern to allow overloading lambdas for use in std::visit // https://devdocs.io/cpp/utility/variant/visit template <class... Ts> struct overload : Ts... { using Ts::operator()...; }; template <class... Ts> overload(Ts...) -> overload<Ts...>; template <typename T> using Ptr = std::unique_ptr<T>;
31.571429
77
0.696833
adi-g15
e91e1ac4050bbd8b2c576a48cb2fda8ea9f074c8
167,305
cpp
C++
srcmglplot/src/exec.cpp
jerrykrinock/IupCocoaTouch
861248b0814a5ec75cf948ed9518ac812435dd31
[ "MIT" ]
1
2016-01-13T03:42:23.000Z
2016-01-13T03:42:23.000Z
srcmglplot/src/exec.cpp
jerrykrinock/IupCocoaTouch
861248b0814a5ec75cf948ed9518ac812435dd31
[ "MIT" ]
null
null
null
srcmglplot/src/exec.cpp
jerrykrinock/IupCocoaTouch
861248b0814a5ec75cf948ed9518ac812435dd31
[ "MIT" ]
null
null
null
/*************************************************************************** * exec.cpp is part of Math Graphic Library * Copyright (C) 2007-2014 Alexey Balakin <mathgl.abalakin@gmail.ru> * * * * This program 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 3 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library 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. * ***************************************************************************/ #ifdef WIN32 #include <io.h> #include <direct.h> #else #include <unistd.h> #endif #include "mgl2/base.h" #include "mgl2/parser.h" inline long iint(mreal x) {return long(x+0.5);} wchar_t *mgl_str_copy(const char *s); //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_addlegend(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"ss")) gr->AddLegend(a[0].w.c_str(),a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_addto(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dd")) *d += *(a[1].d); else if(!strcmp(k,"dn"))*d += a[1].v; else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_sort(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dn")) d->Sort(a[1].v, -1); else if(!strcmp(k,"dnn")) d->Sort(a[1].v, a[2].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_alpha(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->Alpha(true); else if(!strcmp(k,"n")) gr->Alpha(a[0].v!=0); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_plotid(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"s")) gr->SetPlotId(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_mask(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"sn")) gr->SetMask(a[0].s[0],a[1].v); else if(!strcmp(k,"ss")) gr->SetMask(a[0].s[0],a[1].s.c_str()); else if(!strcmp(k,"n")) gr->SetMaskAngle(iint(a[0].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_alphadef(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetAlphaDef(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ambient(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetAmbient(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_diffuse(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetDiffuse(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_area(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Area(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Area(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Area(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Area(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Area(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Area(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_aspect(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nn")) gr->Aspect(a[0].v, a[1].v, 1); else if(!strcmp(k,"nnn")) gr->Aspect(a[0].v, a[1].v, a[2].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_axial(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Axial(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Axial(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Axial(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Axial(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_axis(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"")) gr->Axis("xyz","",opt); else if(!strcmp(k,"s")) gr->Axis(a[0].s.c_str(), "",opt); else if(!strcmp(k,"ss")) gr->Axis(a[0].s.c_str(), a[1].s.c_str(),opt); else if(!strcmp(k,"sss")) gr->SetFunc(a[0].s.c_str(),a[1].s.c_str(),a[2].s.c_str(),""); else if(!strcmp(k,"ssss")) gr->SetFunc(a[0].s.c_str(),a[1].s.c_str(),a[2].s.c_str(),a[3].s.c_str()); else if(!strcmp(k,"n")) gr->SetCoor(iint(a[0].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ball(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nn")) gr->Mark(mglPoint(a[0].v,a[1].v,NAN),"r."); else if(!strcmp(k,"nns")) gr->Mark(mglPoint(a[0].v,a[1].v,NAN),a[2].s.c_str()); else if(!strcmp(k,"nnn")) gr->Mark(mglPoint(a[0].v,a[1].v,a[2].v),"r."); else if(!strcmp(k,"nnns")) gr->Mark(mglPoint(a[0].v,a[1].v,a[2].v),a[3].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_box(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"")) gr->Box(); else if(!strcmp(k,"s")) gr->Box(a[0].s.c_str()); else if(!strcmp(k,"sn")) gr->Box(a[0].s.c_str(), a[1].v); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ohlc(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dddd")) gr->OHLC(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->OHLC(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), a[4].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->OHLC(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d), "",opt); else if(!strcmp(k,"ddddds")) gr->OHLC(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d), a[5].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_bars(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Bars(*(a[0].d), "",opt); else if(!strcmp(k,"ds")) gr->Bars(*(a[0].d), a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Bars(*(a[0].d), *(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->Bars(*(a[0].d), *(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Bars(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Bars(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_barh(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Barh(*(a[0].d), "",opt); else if(!strcmp(k,"ds")) gr->Barh(*(a[0].d), a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Barh(*(a[0].d), *(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->Barh(*(a[0].d), *(a[1].d), a[2].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_cones(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Cones(*(a[0].d), "",opt); else if(!strcmp(k,"ds")) gr->Cones(*(a[0].d), a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Cones(*(a[0].d), *(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->Cones(*(a[0].d), *(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Cones(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Cones(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_belt(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Belt(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Belt(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Belt(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Belt(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_boxs(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Boxs(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Boxs(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Boxs(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Boxs(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_beam(mglGraph *gr, long , mglArg *a, const char *k, const char *) // NOTE beam can be made obsolete ??? { int res=0; if(!strcmp(k,"ddddn")) gr->Beam(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].v,"",0, 3); else if(!strcmp(k,"ddddns")) gr->Beam(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].v,a[5].s.c_str(),0, 3); else if(!strcmp(k,"ddddnsn")) gr->Beam(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].v,a[5].s.c_str(),iint(a[6].v), 3); else if(!strcmp(k,"ddddnsnn")) gr->Beam(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].v,a[5].s.c_str(),iint(a[6].v), iint(a[7].v)); else if(!strcmp(k,"nddddn")) gr->Beam(a[0].v,*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].v,"",0); else if(!strcmp(k,"nddddns")) gr->Beam(a[0].v,*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].v,a[6].s.c_str(),0); else if(!strcmp(k,"nddddnsn")) gr->Beam(a[0].v,*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].v,a[6].s.c_str(),iint(a[7].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_clearlegend(mglGraph *gr, long , mglArg *, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->ClearLegend(); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_rasterize(mglGraph *gr, long , mglArg *, const char *, const char *) { gr->Rasterize(); return 0; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_background(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"s")) gr->LoadBackground(a[0].s.c_str()); else if(!strcmp(k,"sn")) gr->LoadBackground(a[0].s.c_str(),a[1].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_clf(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->Clf(); else if(!strcmp(k,"s")) gr->Clf(a[0].s.c_str()); else if(!strcmp(k,"nnn")) gr->Clf(a[0].v,a[1].v,a[2].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_reset(mglGraph *gr, long , mglArg *, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->DefaultPlotParam(); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_chart(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Chart(*(a[0].d), "",opt); else if(!strcmp(k,"ds")) gr->Chart(*(a[0].d), a[1].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_cloud(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Cloud(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Cloud(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Cloud(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Cloud(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_crange(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"d")) gr->SetRange('c',*(a[0].d)); else if(!strcmp(k,"dn")) gr->SetRange('c',*(a[0].d),a[1].v); else if(!strcmp(k,"nn")) gr->SetRange('c', a[0].v, a[1].v); else if(!strcmp(k,"nnn")) { if(a[2].v) gr->AddRange('c', a[0].v, a[1].v); else gr->SetRange('c', a[0].v, a[1].v); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_crop(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dnns")) d->Crop(iint(a[1].v),iint(a[2].v),a[3].s.c_str()[0]); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_clean(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dn")) d->Clean(iint(a[1].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_cumsum(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) d->CumSum(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_curve(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nnnnnnnn")) gr->Curve(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v), mglPoint(a[4].v,a[5].v,NAN), mglPoint(a[6].v,a[7].v)); else if(!strcmp(k,"nnnnnnnns")) gr->Curve(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v), mglPoint(a[4].v,a[5].v,NAN), mglPoint(a[6].v,a[7].v), a[8].s.c_str()); else if(!strcmp(k,"nnnnnnnnnnnn")) gr->Curve(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), mglPoint(a[6].v,a[7].v,a[8].v), mglPoint(a[9].v,a[10].v,a[11].v)); else if(!strcmp(k,"nnnnnnnnnnnns")) gr->Curve(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), mglPoint(a[6].v,a[7].v,a[8].v), mglPoint(a[9].v,a[10].v,a[11].v), a[12].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_cut(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetCut(a[0].v != 0); else if(!strcmp(k,"nnnnnn")) gr->SetCutBox(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v)); else if(!strcmp(k,"s")) gr->CutOff(a[0].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_crust(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"ddd")) gr->Crust(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Crust(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_colorbar(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"")) gr->Colorbar(); else if(!strcmp(k,"s")) gr->Colorbar(a[0].s.c_str()); else if(!strcmp(k,"d")) gr->Colorbar(*(a[0].d)); else if(!strcmp(k,"ds")) gr->Colorbar(*(a[0].d), a[1].s.c_str()); else if(!strcmp(k,"snn")) gr->Colorbar(a[0].s.c_str(), a[1].v, a[2].v); else if(!strcmp(k,"snnn")) gr->Colorbar(a[0].s.c_str(), a[1].v, a[2].v, a[3].v,1); else if(!strcmp(k,"snnnn")) gr->Colorbar(a[0].s.c_str(), a[1].v, a[2].v, a[3].v,a[4].v); else if(!strcmp(k,"dsnn")) gr->Colorbar(*(a[0].d), a[1].s.c_str(), a[2].v, a[3].v); else if(!strcmp(k,"dsnnn")) gr->Colorbar(*(a[0].d), a[1].s.c_str(), a[2].v, a[3].v, a[4].v,1); else if(!strcmp(k,"dsnnnn")) gr->Colorbar(*(a[0].d), a[1].s.c_str(), a[2].v, a[3].v, a[4].v,a[5].v); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_copy(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dd")) d->Set(*(a[1].d)); else if(!strcmp(k,"dds")) { d->Set(*(a[1].d)); gr->Fill(*d, a[2].s.c_str()); } else if(!strcmp(k,"dn")) *d = a[1].v; else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_cont(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Cont(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Cont(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Cont(*(a[0].d), *(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->Cont(*(a[0].d), *(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Cont(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Cont(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Cont(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->Cont(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contv(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContV(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->ContV(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->ContV(*(a[0].d), *(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->ContV(*(a[0].d), *(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->ContV(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->ContV(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->ContV(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->ContV(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contf(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContF(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->ContF(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->ContF(*(a[0].d), *(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->ContF(*(a[0].d), *(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->ContF(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->ContF(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->ContF(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->ContF(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contd(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContD(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->ContD(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->ContD(*(a[0].d), *(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->ContD(*(a[0].d), *(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->ContD(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->ContD(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->ContD(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->ContD(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_cont3(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Cont3(*(a[0].d), "", -1,opt); else if(!strcmp(k,"ds")) gr->Cont3(*(a[0].d), a[1].s.c_str(), -1,opt); else if(!strcmp(k,"dsn")) gr->Cont3(*(a[0].d), a[1].s.c_str(), iint(a[2].v),opt); else if(!strcmp(k,"dd")) gr->Cont3(*(a[0].d), *(a[1].d), "", -1,opt); else if(!strcmp(k,"dds")) gr->Cont3(*(a[0].d), *(a[1].d), a[2].s.c_str(),-1,opt); else if(!strcmp(k,"ddsn")) gr->Cont3(*(a[0].d), *(a[1].d), a[2].s.c_str(),iint(a[3].v),opt); else if(!strcmp(k,"dddd")) gr->Cont3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), "", -1,opt); else if(!strcmp(k,"dddds")) gr->Cont3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(),-1,opt); else if(!strcmp(k,"ddddsn")) gr->Cont3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(),iint(a[5].v),opt); else if(!strcmp(k,"ddddd")) gr->Cont3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), "", -1,opt); else if(!strcmp(k,"ddddds")) gr->Cont3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), a[5].s.c_str(),-1,opt); else if(!strcmp(k,"dddddsn"))gr->Cont3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), a[5].s.c_str(),iint(a[6].v),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contf3(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContF3(*(a[0].d), "", -1,opt); else if(!strcmp(k,"ds")) gr->ContF3(*(a[0].d), a[1].s.c_str(), -1,opt); else if(!strcmp(k,"dsn")) gr->ContF3(*(a[0].d), a[1].s.c_str(), iint(a[2].v),opt); else if(!strcmp(k,"dd")) gr->ContF3(*(a[0].d), *(a[1].d), "", -1,opt); else if(!strcmp(k,"dds")) gr->ContF3(*(a[0].d), *(a[1].d), a[2].s.c_str(),-1,opt); else if(!strcmp(k,"ddsn")) gr->ContF3(*(a[0].d), *(a[1].d), a[2].s.c_str(),iint(a[3].v),opt); else if(!strcmp(k,"dddd")) gr->ContF3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), "", -1,opt); else if(!strcmp(k,"dddds")) gr->ContF3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(),-1,opt); else if(!strcmp(k,"ddddsn")) gr->ContF3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(),iint(a[5].v),opt); else if(!strcmp(k,"ddddd")) gr->ContF3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), "", -1,opt); else if(!strcmp(k,"ddddds")) gr->ContF3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), a[5].s.c_str(),-1,opt); else if(!strcmp(k,"dddddsn"))gr->ContF3(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), a[5].s.c_str(),iint(a[6].v),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contx(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContX(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->ContX(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->ContX(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contfx(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContFX(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->ContFX(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->ContFX(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_conty(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContY(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->ContY(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->ContY(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contfy(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContFY(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->ContFY(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->ContFY(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contz(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContZ(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->ContZ(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->ContZ(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_contfz(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->ContFZ(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->ContFZ(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->ContFZ(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_cone(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnnnn")) gr->Cone(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v); else if(!strcmp(k,"nnnnnnns")) gr->Cone(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v,-1, a[7].s.c_str()); else if(!strcmp(k,"nnnnnnnn")) gr->Cone(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v, a[7].v); else if(!strcmp(k,"nnnnnnnns")) gr->Cone(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v, a[7].v, a[8].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ellipse(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnn")) gr->Ellipse(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), a[4].v); else if(!strcmp(k,"nnnnns")) gr->Ellipse(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), a[4].v, a[5].s.c_str()); else if(!strcmp(k,"nnnnnnn")) gr->Ellipse(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v); else if(!strcmp(k,"nnnnnnns")) gr->Ellipse(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v, a[7].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_circle(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnn")) gr->Circle(mglPoint(a[0].v,a[1].v, NAN), a[2].v); else if(!strcmp(k,"nnns")) gr->Circle(mglPoint(a[0].v,a[1].v, NAN), a[2].v, a[3].s.c_str()); else if(!strcmp(k,"nnnn")) gr->Circle(mglPoint(a[0].v,a[1].v,a[2].v), a[3].v); else if(!strcmp(k,"nnnns")) gr->Circle(mglPoint(a[0].v,a[1].v,a[2].v), a[3].v, a[4].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_rhomb(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnn")) gr->Rhomb(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), a[4].v); else if(!strcmp(k,"nnnnns")) gr->Rhomb(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), a[4].v, a[5].s.c_str()); else if(!strcmp(k,"nnnnnnn")) gr->Rhomb(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v); else if(!strcmp(k,"nnnnnnns")) gr->Rhomb(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v, a[7].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_polygon(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnn")) gr->Polygon(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), iint(a[4].v)); else if(!strcmp(k,"nnnnns")) gr->Polygon(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), iint(a[4].v), a[5].s.c_str()); else if(!strcmp(k,"nnnnnnn")) gr->Polygon(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), iint(a[6].v)); else if(!strcmp(k,"nnnnnnns")) gr->Polygon(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), iint(a[6].v), a[7].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_arc(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnn")) gr->Arc(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), a[4].v); else if(!strcmp(k,"nnnnns")) gr->Arc(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), a[4].v, a[5].s.c_str()); else if(!strcmp(k,"nnnnnn")) gr->Arc(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v), a[5].v); else if(!strcmp(k,"nnnnnns")) gr->Arc(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v), a[5].v, a[6].s.c_str()); else if(!strcmp(k,"nnnnnnnnnn")) gr->Arc(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v, a[5].v), mglPoint(a[6].v,a[7].v, a[8].v), a[9].v); else if(!strcmp(k,"nnnnnnnnnns")) gr->Arc(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v, a[5].v), mglPoint(a[6].v,a[7].v, a[8].v), a[9].v, a[10].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_dens(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Dens(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Dens(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Dens(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Dens(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_dens3(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Dens3(*(a[0].d),"",-1,opt); else if(!strcmp(k,"ds")) gr->Dens3(*(a[0].d),a[1].s.c_str(),-1,opt); else if(!strcmp(k,"dsn")) gr->Dens3(*(a[0].d),a[1].s.c_str(),iint(a[2].v),opt); else if(!strcmp(k,"dddd")) gr->Dens3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"", -1,opt); else if(!strcmp(k,"dddds")) gr->Dens3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),-1,opt); else if(!strcmp(k,"ddddsn")) gr->Dens3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),iint(a[5].v),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_densx(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->DensX(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->DensX(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->DensX(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_densy(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->DensY(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->DensY(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->DensY(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_densz(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->DensZ(*(a[0].d),"",NAN,opt); else if(!strcmp(k,"ds")) gr->DensZ(*(a[0].d),a[1].s.c_str(),NAN,opt); else if(!strcmp(k,"dsn")) gr->DensZ(*(a[0].d),a[1].s.c_str(),a[2].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_divto(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dd")) *d /= *(a[1].d); else if(!strcmp(k,"dn")) *d /= a[1].v; else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_multo(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dd")) *d *= *(a[1].d); else if(!strcmp(k,"dn")) *d *= a[1].v; else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_subto(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dd")) *d -= *(a[1].d); else if(!strcmp(k,"dn")) *d -= a[1].v; else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_dots(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"ddd")) gr->Dots(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Dots(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Dots(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Dots(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->Dots(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),"",opt); else if(!strcmp(k,"ddddds"))gr->Dots(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_diff(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) d->Diff(a[1].s.c_str()); else if(!strcmp(k,"ddd")) d->Diff(*(a[1].d), *(a[2].d)); else if(!strcmp(k,"dddd")) d->Diff(*(a[1].d), *(a[2].d), *(a[3].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_diff2(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) d->Diff2(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_drop(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnn")) gr->Drop(mglPoint(a[0].v,a[1].v), mglPoint(a[2].v,a[3].v), a[4].v); else if(!strcmp(k,"nnnnns")) gr->Drop(mglPoint(a[0].v,a[1].v), mglPoint(a[2].v,a[3].v), a[4].v, a[5].s.c_str()); else if(!strcmp(k,"nnnnnsn")) gr->Drop(mglPoint(a[0].v,a[1].v), mglPoint(a[2].v,a[3].v), a[4].v, a[5].s.c_str(), a[6].v); else if(!strcmp(k,"nnnnnsnn")) gr->Drop(mglPoint(a[0].v,a[1].v), mglPoint(a[2].v,a[3].v), a[4].v, a[5].s.c_str(), a[6].v, a[7].v); else if(!strcmp(k,"nnnnnnn")) gr->Drop(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v); else if(!strcmp(k,"nnnnnnns")) gr->Drop(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v, a[7].s.c_str()); else if(!strcmp(k,"nnnnnnnsn")) gr->Drop(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v, a[7].s.c_str(), a[8].v); else if(!strcmp(k,"nnnnnnnsnn")) gr->Drop(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].v, a[7].s.c_str(), a[8].v, a[9].v); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_dew(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Dew(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Dew(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Dew(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Dew(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fall(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Fall(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Fall(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Fall(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Fall(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_mesh(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Mesh(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Mesh(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Mesh(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Mesh(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_surf(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Surf(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Surf(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Surf(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Surf(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_surfc(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->SurfC(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->SurfC(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->SurfC(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->SurfC(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_surfa(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->SurfA(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->SurfA(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->SurfA(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->SurfA(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_flow(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Flow(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Flow(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Flow(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Flow(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Flow(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Flow(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"dddddd")) gr->Flow(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",opt); else if(!strcmp(k,"dddddds")) gr->Flow(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),opt); else if(!strcmp(k,"nndd")) gr->FlowP(mglPoint(a[0].v,a[1].v,NAN), *(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"nndds")) gr->FlowP(mglPoint(a[0].v,a[1].v,NAN), *(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"nndddd")) gr->FlowP(mglPoint(a[0].v,a[1].v,NAN), *(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",opt); else if(!strcmp(k,"nndddds")) gr->FlowP(mglPoint(a[0].v,a[1].v,NAN), *(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),opt); else if(!strcmp(k,"nnnddd")) gr->FlowP(mglPoint(a[0].v,a[1].v,a[2].v), *(a[3].d),*(a[4].d),*(a[5].d),"",opt); else if(!strcmp(k,"nnnddds")) gr->FlowP(mglPoint(a[0].v,a[1].v,a[2].v), *(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),opt); else if(!strcmp(k,"nnndddddd")) gr->FlowP(mglPoint(a[0].v,a[1].v,a[2].v), *(a[3].d),*(a[4].d),*(a[5].d),*(a[6].d),*(a[7].d),*(a[8].d),"",opt); else if(!strcmp(k,"nnndddddds")) gr->FlowP(mglPoint(a[0].v,a[1].v,a[2].v), *(a[3].d),*(a[4].d),*(a[5].d),*(a[6].d),*(a[7].d),*(a[8].d),a[9].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_grad(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Grad(*(a[0].d), "",opt); else if(!strcmp(k,"ds")) gr->Grad(*(a[0].d), a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Grad(*(a[0].d),*(a[1].d),*(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Grad(*(a[0].d),*(a[1].d),*(a[2].d), a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Grad(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->Grad(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fill(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dnn")) d->Fill(a[1].v,a[2].v); else if(!strcmp(k,"dnns")) d->Fill(a[1].v,a[2].v,a[3].s.c_str()[0]); else if(!strcmp(k,"ds")) gr->Fill(*d,a[1].s.c_str(),opt); else if(!strcmp(k,"dsd")) gr->Fill(*d,a[1].s.c_str(), *(a[2].d),opt); else if(!strcmp(k,"dsdd")) gr->Fill(*d,a[1].s.c_str(), *(a[2].d), *(a[3].d),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_refill(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddd")) gr->Refill(*d,*(a[1].d),*(a[2].d),-1,opt); else if(!strcmp(k,"dddn")) gr->Refill(*d,*(a[1].d),*(a[2].d),iint(a[3].v),opt); else if(!strcmp(k,"dddd")) gr->Refill(*d,*(a[1].d),*(a[2].d),*(a[3].d),-1,opt); else if(!strcmp(k,"ddddn")) gr->Refill(*d,*(a[1].d),*(a[2].d),*(a[3].d),iint(a[4].v),opt); else if(!strcmp(k,"ddddd")) gr->Refill(*d,*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_gspline(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddd")) d->RefillGS(*(a[1].d),*(a[2].d),gr->Self()->Min.x,gr->Self()->Max.x,-1); else if(!strcmp(k,"dddn")) d->RefillGS(*(a[1].d),*(a[2].d),gr->Self()->Min.x,gr->Self()->Max.x,iint(a[3].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fillsample(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) d->FillSample(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fog(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->Fog(a[0].v); else if(!strcmp(k,"nn")) gr->Fog(a[0].v,a[1].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_font(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"s")) gr->SetFontDef(a[0].s.c_str()); else if(!strcmp(k,"sn")) { gr->SetFontDef(a[0].s.c_str()); gr->SetFontSize(a[1].v); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_loadfont(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"") || (!strcmp(k,"s") && a[0].s[0]==0)) gr->RestoreFont(); else if(!strcmp(k,"s")) gr->LoadFont(a[0].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_grid(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"")) gr->Grid("xyzt", "B",opt); else if(!strcmp(k,"s")) gr->Grid(a[0].s.c_str(), "B",opt); else if(!strcmp(k,"ss"))gr->Grid(a[0].s.c_str(), a[1].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_grid2(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Grid(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Grid(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Grid(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Grid(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_grid3(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Grid3(*(a[0].d),"",-1,opt); else if(!strcmp(k,"ds")) gr->Grid3(*(a[0].d),a[1].s.c_str(),-1,opt); else if(!strcmp(k,"dsn")) gr->Grid3(*(a[0].d),a[1].s.c_str(),iint(a[2].v),opt); else if(!strcmp(k,"dddd")) gr->Grid3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",-1,opt); else if(!strcmp(k,"dddds")) gr->Grid3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),-1,opt); else if(!strcmp(k,"ddddsn"))gr->Grid3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),iint(a[5].v),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_light(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->Light(true); else if(!strcmp(k,"n")) gr->Light(a[0].v!=0); else if(!strcmp(k,"nn")) gr->Light(iint(a[0].v),a[1].v!=0); else if(!strcmp(k,"nnnn")) gr->AddLight(iint(a[0].v),mglPoint(a[1].v,a[2].v,a[3].v)); else if(!strcmp(k,"nnnns")) gr->AddLight(iint(a[0].v),mglPoint(a[1].v,a[2].v,a[3].v), a[4].s.c_str()[0]); else if(!strcmp(k,"nnnnsn"))gr->AddLight(iint(a[0].v),mglPoint(a[1].v,a[2].v,a[3].v), a[4].s.c_str()[0],a[5].v); else if(!strcmp(k,"nnnnsnn")) gr->AddLight(iint(a[0].v),mglPoint(a[1].v,a[2].v,a[3].v), a[4].s.c_str()[0],a[5].v,a[6].v); else if(!strcmp(k,"nnnnnnn")) gr->AddLight(iint(a[0].v),mglPoint(a[1].v,a[2].v,a[3].v),mglPoint(a[4].v,a[5].v,a[6].v)); else if(!strcmp(k,"nnnnnnns")) gr->AddLight(iint(a[0].v),mglPoint(a[1].v,a[2].v,a[3].v),mglPoint(a[4].v,a[5].v,a[6].v), a[7].s.c_str()[0]); else if(!strcmp(k,"nnnnnnnsn")) gr->AddLight(iint(a[0].v),mglPoint(a[1].v,a[2].v,a[3].v),mglPoint(a[4].v,a[5].v,a[6].v), a[7].s.c_str()[0],a[8].v); else if(!strcmp(k,"nnnnnnnsnn")) gr->AddLight(iint(a[0].v),mglPoint(a[1].v,a[2].v,a[3].v),mglPoint(a[4].v,a[5].v,a[6].v), a[7].s.c_str()[0],a[8].v,a[9].v); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_line(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnn")) gr->Line(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN)); else if(!strcmp(k,"nnnns")) gr->Line(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), a[4].s.c_str()); else if(!strcmp(k,"nnnnnn")) gr->Line(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v)); else if(!strcmp(k,"nnnnnns")) gr->Line(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_errbox(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnn")) gr->Error(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN)); else if(!strcmp(k,"nnnns")) gr->Error(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), a[4].s.c_str()); else if(!strcmp(k,"nnnnnn")) gr->Error(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v)); else if(!strcmp(k,"nnnnnns")) gr->Error(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_legend(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"")) gr->Legend(3, "#", opt); else if(!strcmp(k,"n")) gr->Legend(iint(a[0].v), "#", opt); else if(!strcmp(k,"ns")) gr->Legend(iint(a[0].v), a[1].s.c_str(), opt); else if(!strcmp(k,"nn")) gr->Legend(a[0].v, a[1].v, "#", opt); else if(!strcmp(k,"nns")) gr->Legend(a[0].v, a[1].v, a[2].s.c_str(), opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_barwidth(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetBarWidth(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_legendmarks(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetLegendMarks(iint(a[0].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_modify(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) d->Modify(a[1].s.c_str()); else if(!strcmp(k,"dsn")) d->Modify(a[1].s.c_str(), iint(a[2].v)); else if(!strcmp(k,"dsd")) d->Modify(a[1].s.c_str(),*(a[2].d)); else if(!strcmp(k,"dsdd")) d->Modify(a[1].s.c_str(),*(a[2].d),*(a[3].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_max(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dds")) *d = mglData(true,mgl_data_max_dir(a[1].d,a[2].s.c_str())); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_min(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dds")) *d = mglData(true,mgl_data_min_dir(a[1].d,a[2].s.c_str())); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_sum(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dds")) *d = mglData(true,mgl_data_sum(a[1].d,a[2].s.c_str())); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_meshnum(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetMeshNum(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_facenum(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetFaceNum(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_quality(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->SetQuality(); else if(!strcmp(k,"n")) gr->SetQuality(iint(a[0].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_marksize(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetMarkSize(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_mark(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Mark(*(a[0].d), *(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->Mark(*(a[0].d), *(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Mark(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Mark(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Mark(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->Mark(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_map(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Map(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Map(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Map(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Map(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_read(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; bool rr=true; mglData *d = dynamic_cast<mglData *>(a[0].d); mglData *f = dynamic_cast<mglData *>(a[1].d); if(!d) return 1; mglDataC c; if(!strcmp(k,"ds")) { rr=c.Read(a[1].s.c_str()); *d = c.Real(); } else if(!strcmp(k,"dsn")) { rr=c.Read(a[1].s.c_str(), iint(a[2].v)); *d = c.Real(); } else if(!strcmp(k,"dsnn")) { rr=c.Read(a[1].s.c_str(), iint(a[2].v),iint(a[3].v)); *d = c.Real(); } else if(!strcmp(k,"dsnnn")) { rr=c.Read(a[1].s.c_str(), iint(a[2].v),iint(a[3].v),iint(a[4].v)); *d = c.Real(); } if(!strcmp(k,"dds") && f) { rr=c.Read(a[2].s.c_str()); *d = c.Real(); *f = c.Imag(); } if(!strcmp(k,"ddsn") && f) { rr=c.Read(a[2].s.c_str(), iint(a[3].v)); *d = c.Real(); *f = c.Imag(); } if(!strcmp(k,"ddsnn") && f) { rr=c.Read(a[2].s.c_str(), iint(a[3].v),iint(a[4].v)); *d = c.Real(); *f = c.Imag(); } if(!strcmp(k,"ddsnnn") && f) { rr=c.Read(a[2].s.c_str(), iint(a[3].v),iint(a[4].v),iint(a[5].v)); *d = c.Real(); *f = c.Imag(); } if(!rr) gr->SetWarn(mglWarnFile,"Read"); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_readmat(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; bool rr=true; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) rr=d->ReadMat(a[1].s.c_str()); else if(!strcmp(k,"dsn")) rr=d->ReadMat(a[1].s.c_str(), iint(a[2].v)); else res = 1; if(!rr) gr->SetWarn(mglWarnFile,"ReadMat"); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_readall(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; bool rr=true; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) rr=d->ReadAll(a[1].s.c_str()); else if(!strcmp(k,"dsn")) rr=d->ReadAll(a[1].s.c_str(), a[2].v); else if(!strcmp(k,"dsnn")) rr=d->ReadRange(a[1].s.c_str(), a[2].v, a[3].v); else if(!strcmp(k,"dsnnn")) rr=d->ReadRange(a[1].s.c_str(), a[2].v, a[3].v, a[4].v); else if(!strcmp(k,"dsnnnn"))rr=d->ReadRange(a[1].s.c_str(), a[2].v, a[3].v, a[4].v, a[5].v); else res = 1; if(!rr) gr->SetWarn(mglWarnFile,"ReadMat"); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_readhdf(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dss")) d->ReadHDF(a[1].s.c_str(), a[2].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_savehdf(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"dss")) a[0].d->SaveHDF(a[1].s.c_str(), a[2].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_rect(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnn")) gr->Face(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[0].v,a[3].v,NAN), mglPoint(a[2].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN)); else if(!strcmp(k,"nnnns")) gr->Face(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[0].v,a[3].v,NAN), mglPoint(a[2].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN),a[4].s.c_str()); else if(!strncmp(k,"nnnnnn",6)) { if(a[0].v==a[3].v) gr->Face(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[0].v,a[4].v,a[2].v), mglPoint(a[3].v,a[1].v,a[5].v), mglPoint(a[3].v,a[4].v,a[5].v), k[6]=='s' ? a[6].s.c_str() : 0); else gr->Face(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[0].v,a[4].v,a[5].v), mglPoint(a[3].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), k[6]=='s' ? a[6].s.c_str() : 0); } else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_face(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnnnnn")) gr->Face(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), mglPoint(a[4].v,a[5].v,NAN), mglPoint(a[6].v,a[7].v,NAN)); else if(!strcmp(k,"nnnnnnnns")) gr->Face(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v,NAN), mglPoint(a[4].v,a[5].v,NAN), mglPoint(a[6].v,a[7].v,NAN), a[8].s.c_str()); else if(!strcmp(k,"nnnnnnnnnnnn")) gr->Face(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), mglPoint(a[6].v,a[7].v,a[8].v), mglPoint(a[9].v,a[10].v,a[11].v)); else if(!strcmp(k,"nnnnnnnnnnnns")) gr->Face(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), mglPoint(a[6].v,a[7].v,a[8].v), mglPoint(a[9].v,a[10].v,a[11].v), a[12].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_logo(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"s")) gr->Logo(a[0].s.c_str(),false,opt); else if(!strcmp(k,"sn")) gr->Logo(a[0].s.c_str(),iint(a[1].v),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_resize(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddn")) *d = mglData(true,mgl_data_resize_box(a[1].d, iint(a[2].v),0,0, 0,1, 0,1, 0,1)); else if(!strcmp(k,"ddnn")) *d = mglData(true,mgl_data_resize_box(a[1].d, iint(a[2].v),iint(a[3].v),0, 0,1, 0,1, 0,1)); else if(!strcmp(k,"ddnnn")) *d = mglData(true,mgl_data_resize_box(a[1].d, iint(a[2].v),iint(a[3].v),iint(a[4].v), 0,1, 0,1, 0,1)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_rotate(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nn")) gr->Rotate(a[0].v, a[1].v, 0); else if(!strcmp(k,"nnn")) gr->Rotate(a[0].v, a[1].v, a[2].v); else if(!strcmp(k,"nnnn")) gr->RotateN(a[0].v, a[1].v, a[2].v, a[3].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_rotatetext(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetRotatedText(a[0].v!=0); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tuneticks(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetTuneTicks(iint(a[0].v)); else if(!strcmp(k,"nn")) gr->SetTuneTicks(iint(a[0].v),a[1].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ticktime(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"s")) gr->SetTicksTime(a[0].s[0]); else if(!strcmp(k,"sn")) gr->SetTicksTime(a[0].s[0],a[1].v); else if(!strcmp(k,"sns")) gr->SetTicksTime(a[0].s[0],a[1].v,a[2].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_save(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"ds")) a[0].d->Save(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_smooth(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"d")) d->Smooth(); else if(!strcmp(k,"ds")) d->Smooth(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_swap(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) d->Swap(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_idset(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); mglDataC *c = dynamic_cast<mglDataC *>(a[0].d); if(!strcmp(k,"ds") && d) d->SetColumnId(a[1].s.c_str()); else if(!strcmp(k,"ds") && c) c->SetColumnId(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_stem(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Stem(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Stem(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Stem(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Stem(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Stem(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Stem(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_step(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Step(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Step(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Step(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Step(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Step(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Step(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_plot(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Plot(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Plot(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Plot(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Plot(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Plot(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Plot(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tape(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Tape(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Tape(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Tape(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Tape(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Tape(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Tape(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_boxplot(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->BoxPlot(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->BoxPlot(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->BoxPlot(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->BoxPlot(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_candle(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Candle(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Candle(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Candle(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Candle(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Candle(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Candle(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Candle(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Candle(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->Candle(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),"",opt); else if(!strcmp(k,"ddddds"))gr->Candle(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_radar(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Radar(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Radar(*(a[0].d),a[1].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_squeeze(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dn")) d->Squeeze(iint(a[1].v)); else if(!strcmp(k,"dnn")) d->Squeeze(iint(a[1].v), iint(a[2].v)); else if(!strcmp(k,"dnnn")) d->Squeeze(iint(a[1].v), iint(a[2].v),iint(a[3].v)); else if(!strcmp(k,"dnnnn")) d->Squeeze(iint(a[1].v), iint(a[2].v),iint(a[3].v), a[4].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_stfad(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dddn")) *d = mglSTFA(*(a[1].d),*(a[2].d), iint(a[3].v)); else if(!strcmp(k,"dddns")) *d = mglSTFA(*(a[1].d),*(a[2].d), iint(a[3].v), a[4].s.c_str()[0]); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_setsize(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nn") && a[1].v>1 && a[0].v>1) gr->SetSize(iint(a[0].v), iint(a[1].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_sphere(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnn")) gr->Sphere(mglPoint(a[0].v,a[1].v), a[2].v); else if(!strcmp(k,"nnns")) gr->Sphere(mglPoint(a[0].v,a[1].v), a[2].v, a[3].s.c_str()); else if(!strcmp(k,"nnnn")) gr->Sphere(mglPoint(a[0].v,a[1].v,a[2].v), a[3].v); else if(!strcmp(k,"nnnns")) gr->Sphere(mglPoint(a[0].v,a[1].v,a[2].v), a[3].v, a[4].s.c_str()); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_stfa(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"ddn")) gr->STFA(*(a[0].d),*(a[1].d), iint(a[2].v), "",opt); else if(!strcmp(k,"ddns")) gr->STFA(*(a[0].d),*(a[1].d), iint(a[2].v), a[3].s.c_str(),opt); else if(!strcmp(k,"ddddn")) gr->STFA(*(a[0].d),*(a[1].d), *(a[2].d),*(a[3].d), iint(a[4].v), "",opt); else if(!strcmp(k,"ddddns")) gr->STFA(*(a[0].d),*(a[1].d), *(a[2].d),*(a[3].d), iint(a[4].v), a[5].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_surf3(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Surf3(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Surf3(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"dn")) gr->Surf3(a[1].v,*(a[0].d),"",opt); else if(!strcmp(k,"dns")) gr->Surf3(a[1].v,*(a[0].d),a[2].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Surf3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->Surf3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), a[4].s.c_str(),opt); else if(!strcmp(k,"ddddn")) gr->Surf3(a[4].v,*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"ddddns"))gr->Surf3(a[4].v,*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[5].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_surf3c(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Surf3C(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Surf3C(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddn")) gr->Surf3C(a[2].v,*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"ddns")) gr->Surf3C(a[2].v,*(a[0].d),*(a[1].d),a[3].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->Surf3C(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d), "",opt); else if(!strcmp(k,"ddddds")) gr->Surf3C(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d), a[5].s.c_str(),opt); else if(!strcmp(k,"dddddn")) gr->Surf3C(a[5].v,*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),"",opt); else if(!strcmp(k,"dddddns")) gr->Surf3C(a[5].v,*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[6].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_surf3a(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Surf3A(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Surf3A(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddn")) gr->Surf3A(a[2].v,*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"ddns")) gr->Surf3A(a[2].v,*(a[0].d),*(a[1].d),a[3].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->Surf3A(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d), "",opt); else if(!strcmp(k,"ddddds")) gr->Surf3A(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d), a[5].s.c_str(),opt); else if(!strcmp(k,"dddddn")) gr->Surf3A(a[5].v,*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),"",opt); else if(!strcmp(k,"dddddns")) gr->Surf3A(a[5].v,*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[6].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_subplot(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nnn")) gr->SubPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v)); else if(!strcmp(k,"nnns")) gr->SubPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v), a[3].s.c_str()); else if(!strcmp(k,"nnnsnn")) gr->SubPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v), a[3].s.c_str(), a[4].v,a[5].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_multiplot(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nnnnn")) gr->MultiPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v), iint(a[3].v), iint(a[4].v)); else if(!strcmp(k,"nnnnns")) gr->MultiPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v), iint(a[3].v), iint(a[4].v), a[5].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_title(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"s")) gr->Title(a[0].w.c_str()); else if(!strcmp(k,"ss")) gr->Title(a[0].w.c_str(), a[1].s.c_str()); else if(!strcmp(k,"ssn")) gr->Title(a[0].w.c_str(), a[1].s.c_str(),a[2].v); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_column(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dds")) *d = mglData(true,mgl_data_column(a[1].d,a[2].s.c_str())); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_subdata(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddn")) *d = mglData(true,mgl_data_subdata(a[1].d, iint(a[2].v), -1, -1)); else if(!strcmp(k,"ddnn")) *d = mglData(true,mgl_data_subdata(a[1].d, iint(a[2].v), iint(a[3].v), -1)); else if(!strcmp(k,"ddnnn")) *d = mglData(true,mgl_data_subdata(a[1].d, iint(a[2].v), iint(a[3].v), iint(a[4].v))); else if(!strcmp(k,"ddd")) *d = mglSubData(*(a[1].d), *(a[2].d)); else if(!strcmp(k,"dddd")) *d = mglSubData(*(a[1].d), *(a[2].d), *(a[3].d)); else if(!strcmp(k,"ddddd")) *d = mglSubData(*(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_trace(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dd")) *d = mglData(true,mgl_data_trace(a[1].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tile(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Tile(*(a[0].d),"",opt); else if(!strcmp(k,"ds")) gr->Tile(*(a[0].d),a[1].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Tile(*(a[0].d), *(a[1].d), *(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Tile(*(a[0].d), *(a[1].d), *(a[2].d), a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tiles(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->TileS(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->TileS(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->TileS(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->TileS(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_text(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) // NOTE don't use options -- Puts can be part of group { int res=0; if(k[0]=='n') { gr->Self()->SaveState(opt); if(!strcmp(k,"nns")) gr->Putsw(mglPoint(a[0].v,a[1].v,NAN),a[2].w.c_str()); else if(!strcmp(k,"nnss")) gr->Putsw(mglPoint(a[0].v,a[1].v,NAN),a[2].w.c_str(), a[3].s.c_str()); else if(!strcmp(k,"nnssn")) gr->Putsw(mglPoint(a[0].v,a[1].v,NAN),a[2].w.c_str(), a[3].s.c_str(),a[4].v); else if(!strcmp(k,"nnns")) gr->Putsw(mglPoint(a[0].v,a[1].v,a[2].v),a[3].w.c_str()); else if(!strcmp(k,"nnnss")) gr->Putsw(mglPoint(a[0].v,a[1].v,a[2].v),a[3].w.c_str(), a[4].s.c_str()); else if(!strcmp(k,"nnnssn")) gr->Putsw(mglPoint(a[0].v,a[1].v,a[2].v),a[3].w.c_str(), a[4].s.c_str(),a[5].v); else if(!strcmp(k,"nnnns")) gr->Putsw(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v), a[4].w.c_str()); else if(!strcmp(k,"nnnnss")) gr->Putsw(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v), a[4].w.c_str(), a[5].s.c_str()); else if(!strcmp(k,"nnnnssn")) gr->Putsw(mglPoint(a[0].v,a[1].v,NAN), mglPoint(a[2].v,a[3].v), a[4].w.c_str(), a[5].s.c_str(),a[6].v); else if(!strcmp(k,"nnnnnns")) gr->Putsw(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].w.c_str()); else if(!strcmp(k,"nnnnnnss")) gr->Putsw(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].w.c_str(), a[7].s.c_str()); else if(!strcmp(k,"nnnnnnssn")) gr->Putsw(mglPoint(a[0].v,a[1].v,a[2].v), mglPoint(a[3].v,a[4].v,a[5].v), a[6].w.c_str(), a[7].s.c_str(),a[8].v); else res=1; gr->Self()->LoadState(); } else if(!strcmp(k,"ds")) gr->Text(*(a[0].d),a[1].w.c_str(),"",opt); else if(!strcmp(k,"dss")) gr->Text(*(a[0].d),a[1].w.c_str(),a[2].s.c_str(),opt); else if(!strcmp(k,"dds")) gr->Text(*(a[0].d),*(a[1].d),a[2].w.c_str(),"",opt); else if(!strcmp(k,"ddss")) gr->Text(*(a[0].d),*(a[1].d),a[2].w.c_str(),a[3].s.c_str(),opt); else if(!strcmp(k,"ddds")) gr->Text(*(a[0].d),*(a[1].d),*(a[2].d),a[3].w.c_str(),"",opt); else if(!strcmp(k,"dddss")) gr->Text(*(a[0].d),*(a[1].d),*(a[2].d),a[3].w.c_str(),a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_torus(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Torus(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Torus(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_transptype(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetTranspType(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fourier(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *re = dynamic_cast<mglData *>(a[0].d), *im = dynamic_cast<mglData *>(a[1].d); if(!strcmp(k,"dds") && re && im) mglFourier(*re,*im,a[2].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_transform(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"dsdd") && d) *d = mglTransform(*(a[2].d),*(a[3].d),a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_transforma(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"dsdd") && d) *d = mglTransformA(*(a[2].d),*(a[3].d),a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tube(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dn")) gr->Tube(*(a[0].d),a[1].v,"",opt); else if(!strcmp(k,"dns")) gr->Tube(*(a[0].d),a[1].v,a[2].s.c_str(),opt); else if(!strcmp(k,"dd")) gr->Tube(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Tube(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddn")) gr->Tube(*(a[0].d),*(a[1].d),a[2].v,"",opt); else if(!strcmp(k,"ddns")) gr->Tube(*(a[0].d),*(a[1].d),a[2].v,a[3].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Tube(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Tube(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else if(!strcmp(k,"dddn")) gr->Tube(*(a[0].d),*(a[1].d),*(a[2].d),a[3].v,"",opt); else if(!strcmp(k,"dddns")) gr->Tube(*(a[0].d),*(a[1].d),*(a[2].d),a[3].v,a[4].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Tube(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Tube(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_textmark(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"ds")) gr->TextMark(*(a[0].d),a[1].w.c_str(),"",opt); else if(!strcmp(k,"dss")) gr->TextMark(*(a[0].d),a[1].w.c_str(),a[2].s.c_str(),opt); else if(!strcmp(k,"dds")) gr->TextMark(*(a[0].d),*(a[1].d),a[2].w.c_str(),"",opt); else if(!strcmp(k,"ddss")) gr->TextMark(*(a[0].d),*(a[1].d),a[2].w.c_str(),a[3].s.c_str(),opt); else if(!strcmp(k,"ddds")) gr->TextMark(*(a[0].d),*(a[1].d),*(a[2].d),a[3].w.c_str(),"",opt); else if(!strcmp(k,"dddss")) gr->TextMark(*(a[0].d),*(a[1].d),*(a[2].d),a[3].w.c_str(),a[4].s.c_str(),opt); else if(!strcmp(k,"dddds")) gr->TextMark(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].w.c_str(),"",opt); else if(!strcmp(k,"ddddss"))gr->TextMark(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].w.c_str(),a[5].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_triplot(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"ddd")) gr->TriPlot(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->TriPlot(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->TriPlot(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->TriPlot(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->TriPlot(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),"",opt); else if(!strcmp(k,"ddddds"))gr->TriPlot(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_quadplot(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"ddd")) gr->QuadPlot(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->QuadPlot(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->QuadPlot(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->QuadPlot(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->QuadPlot(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),"",opt); else if(!strcmp(k,"ddddds"))gr->QuadPlot(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tricont(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dddd")) gr->TriCont(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->TriCont(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->TriContV(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),"",opt); else if(!strcmp(k,"ddddds")) gr->TriContV(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].s.c_str(),opt); else if(!strcmp(k,"dddddd")) gr->TriCont(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",opt); else if(!strcmp(k,"dddddds")) gr->TriCont(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tricontv(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dddd")) gr->TriContVt(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->TriContVt(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"ddddd")) gr->TriContVt(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),"",opt); else if(!strcmp(k,"ddddds")) gr->TriContVt(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].s.c_str(),opt); else if(!strcmp(k,"dddddd")) gr->TriContVt(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",opt); else if(!strcmp(k,"dddddds")) gr->TriContVt(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ternary(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->Ternary(int(a[0].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_transpose(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"d")) d->Transpose(); else if(!strcmp(k,"ds")) d->Transpose(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_vect(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Vect(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Vect(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Vect(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Vect(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Vect(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Vect(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"dddddd")) gr->Vect(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",opt); else if(!strcmp(k,"dddddds")) gr->Vect(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_vect3(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"ddd")) gr->Vect3(*(a[0].d),*(a[1].d),*(a[2].d),"",-1,opt); else if(!strcmp(k,"ddds")) gr->Vect3(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),-1,opt); else if(!strcmp(k,"dddsn")) gr->Vect3(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),a[4].v,opt); else if(!strcmp(k,"dddddd")) gr->Vect3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",-1,opt); else if(!strcmp(k,"dddddds")) gr->Vect3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),-1,opt); else if(!strcmp(k,"ddddddsn")) gr->Vect3(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),a[7].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_traj(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dddd")) gr->Traj(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Traj(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"dddddd")) gr->Traj(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",opt); else if(!strcmp(k,"dddddds")) gr->Traj(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_xlabel(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"s")) gr->Label('x', a[0].w.c_str(), 1, opt); else if(!strcmp(k,"sn")) gr->Label('x', a[0].w.c_str(), a[1].v, opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ylabel(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"s")) gr->Label('y', a[0].w.c_str(), 1, opt); else if(!strcmp(k,"sn")) gr->Label('y', a[0].w.c_str(), a[1].v, opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_zlabel(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"s")) gr->Label('z', a[0].w.c_str(), 1, opt); else if(!strcmp(k,"sn")) gr->Label('z', a[0].w.c_str(), a[1].v, opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tlabel(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"s")) gr->Label('t', a[0].w.c_str(), 1, opt); else if(!strcmp(k,"sn")) gr->Label('t', a[0].w.c_str(), a[1].v, opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_label(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"ds")) gr->Label(*(a[0].d), a[1].w.c_str(), "",opt); else if(!strcmp(k,"dss")) gr->Label(*(a[0].d), a[1].w.c_str(), a[2].s.c_str(),opt); else if(!strcmp(k,"dds")) gr->Label(*(a[0].d), *(a[1].d), a[2].w.c_str(), "",opt); else if(!strcmp(k,"ddss")) gr->Label(*(a[0].d), *(a[1].d), a[2].w.c_str(), a[3].s.c_str(),opt); else if(!strcmp(k,"ddds")) gr->Label(*(a[0].d), *(a[1].d), *(a[2].d), a[3].w.c_str(), "",opt); else if(!strcmp(k,"dddss")) gr->Label(*(a[0].d), *(a[1].d), *(a[2].d), a[3].w.c_str(), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_table(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"d")) gr->Table(*(a[0].d), L"", "#|",opt); else if(!strcmp(k,"ds")) gr->Table(*(a[0].d), a[1].w.c_str(), "#|",opt); else if(!strcmp(k,"dss")) gr->Table(*(a[0].d), a[1].w.c_str(), a[2].s.c_str(),opt); else if(!strcmp(k,"nnd")) gr->Table(a[0].v, a[1].v, *(a[2].d), L"", "#|",opt); else if(!strcmp(k,"nnds")) gr->Table(a[0].v, a[1].v, *(a[2].d), a[3].w.c_str(), "#|",opt); else if(!strcmp(k,"nndss")) gr->Table(a[0].v, a[1].v, *(a[2].d), a[3].w.c_str(), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_xrange(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"d")) gr->SetRange('x',*(a[0].d)); else if(!strcmp(k,"dn")) gr->SetRange('x',*(a[0].d),a[1].v); else if(!strcmp(k,"nn")) gr->SetRange('x', a[0].v, a[1].v); else if(!strcmp(k,"nnn")) { if(a[2].v) gr->AddRange('x', a[0].v, a[1].v); else gr->SetRange('x', a[0].v, a[1].v); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_yrange(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"d")) gr->SetRange('y',*(a[0].d)); else if(!strcmp(k,"dn")) gr->SetRange('y',*(a[0].d),a[1].v); else if(!strcmp(k,"nn")) gr->SetRange('y', a[0].v, a[1].v); else if(!strcmp(k,"nnn")) { if(a[2].v) gr->AddRange('y', a[0].v, a[1].v); else gr->SetRange('y', a[0].v, a[1].v); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_zrange(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"d")) gr->SetRange('z',*(a[0].d)); else if(!strcmp(k,"dn")) gr->SetRange('z',*(a[0].d),a[1].v); else if(!strcmp(k,"nn")) gr->SetRange('z', a[0].v, a[1].v); else if(!strcmp(k,"nnn")) { if(a[2].v) gr->AddRange('z', a[0].v, a[1].v); else gr->SetRange('z', a[0].v, a[1].v); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ctick(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"s")) gr->SetTickTempl('c',a[0].w.c_str()); else if(!strcmp(k,"n")) gr->SetTicks('c',a[0].v,0,0); else if(!strcmp(k,"ns")) gr->SetTicks('c',a[0].v,0,0,a[1].w.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_xtick(mglGraph *gr, long n, mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetTicks('x', a[0].v); else if(!strcmp(k,"ns")) gr->SetTicks('x', a[0].v, 0, NAN, a[1].w.c_str()); else if(!strcmp(k,"nn")) gr->SetTicks('x', a[0].v, iint(a[1].v)); else if(!strcmp(k,"nns")) gr->SetTicks('x', a[0].v, iint(a[1].v), NAN, a[2].w.c_str()); else if(!strcmp(k,"nnn")) gr->SetTicks('x', a[0].v, iint(a[1].v), a[2].v); else if(!strcmp(k,"nnns")) gr->SetTicks('x', a[0].v, iint(a[1].v), a[2].v, a[3].w.c_str()); else if(!strcmp(k,"s")) gr->SetTickTempl('x',a[0].w.c_str()); else if(!strcmp(k,"ds")) gr->SetTicksVal('x', *(a[0].d), a[1].w.c_str()); else if(!strcmp(k,"dsn")) gr->SetTicksVal('x', *(a[0].d), a[1].w.c_str(), a[2].v); else if(!strncmp(k,"ns",2)) { mreal v[50]; std::wstring s; int i; for(i=0;i<50 && i<n/2;i++) { if(a[2*i].type==2 && a[2*i+1].type==1) { v[i] = a[2*i].v; s += a[2*i+1].w+L"\n"; } else break; } gr->SetTicksVal('x',mglData(i,v),s.c_str(),a[2*i].type==2?a[2*i].v:0); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ytick(mglGraph *gr, long n, mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetTicks('y', a[0].v); else if(!strcmp(k,"ns")) gr->SetTicks('y', a[0].v, 0, NAN, a[1].w.c_str()); else if(!strcmp(k,"nn")) gr->SetTicks('y', a[0].v, iint(a[1].v)); else if(!strcmp(k,"nns")) gr->SetTicks('y', a[0].v, iint(a[1].v), NAN, a[2].w.c_str()); else if(!strcmp(k,"nnn")) gr->SetTicks('y', a[0].v, iint(a[1].v), a[2].v); else if(!strcmp(k,"nnns")) gr->SetTicks('y', a[0].v, iint(a[1].v), a[2].v, a[3].w.c_str()); else if(!strcmp(k,"s")) gr->SetTickTempl('y',a[0].w.c_str()); else if(!strcmp(k,"ds")) gr->SetTicksVal('y', *(a[0].d), a[1].w.c_str()); else if(!strcmp(k,"dsn")) gr->SetTicksVal('y', *(a[0].d), a[1].w.c_str(), a[2].v); else if(!strncmp(k,"ns",2)) { mreal v[50]; std::wstring s; int i; for(i=0;i<50 && i<n/2;i++) { if(a[2*i].type==2 && a[2*i+1].type==1) { v[i] = a[2*i].v; s += a[2*i+1].w+L"\n"; } else break; } gr->SetTicksVal('y',mglData(i,v),s.c_str()); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ztick(mglGraph *gr, long n, mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetTicks('z', a[0].v); else if(!strcmp(k,"ns")) gr->SetTicks('z', a[0].v, 0, NAN, a[1].w.c_str()); else if(!strcmp(k,"nn")) gr->SetTicks('z', a[0].v, iint(a[1].v)); else if(!strcmp(k,"nns")) gr->SetTicks('z', a[0].v, iint(a[1].v), NAN, a[2].w.c_str()); else if(!strcmp(k,"nnn")) gr->SetTicks('z', a[0].v, iint(a[1].v), a[2].v); else if(!strcmp(k,"nnns")) gr->SetTicks('z', a[0].v, iint(a[1].v), a[2].v, a[3].w.c_str()); else if(!strcmp(k,"s")) gr->SetTickTempl('z',a[0].w.c_str()); else if(!strcmp(k,"ds")) gr->SetTicksVal('z', *(a[0].d), a[1].w.c_str()); else if(!strcmp(k,"dsn")) gr->SetTicksVal('z', *(a[0].d), a[1].w.c_str(), a[2].v); else if(!strncmp(k,"ns",2)) { mreal v[50]; std::wstring s; int i; for(i=0;i<50 && i<n/2;i++) { if(a[2*i].type==2 && a[2*i+1].type==1) { v[i] = a[2*i].v; s += a[2*i+1].w+L"\n"; } else break; } gr->SetTicksVal('z',mglData(i,v),s.c_str()); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_error(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Error(*(a[0].d),*(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->Error(*(a[0].d),*(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Error(*(a[0].d),*(a[1].d),*(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Error(*(a[0].d),*(a[1].d),*(a[2].d), a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Error(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->Error(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_extend(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dn")) d->Extend(iint(a[1].v)); else if(!strcmp(k,"dnn")) d->Extend(iint(a[1].v),iint(a[2].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_join(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"dd") && d) d->Join(*(a[1].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_datas(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"s")) { char *buf=new char[1024]; mgl_datas_hdf(a[0].s.c_str(),buf,1024); gr->SetWarn(-1,buf); delete []buf; } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_info(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"d")) gr->SetWarn(-1,a[0].d->PrintInfo()); else if(!strcmp(k,"s")) gr->SetWarn(-1,a[0].s.c_str()); else if(!strcmp(k,"n")) { char buf[128]; snprintf(buf,128,"value = %g",a[0].v); buf[127]=0; gr->SetWarn(-1,buf); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_integrate(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"ds") && d) d->Integral(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_inplot(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nnnn")) gr->InPlot(a[0].v, a[1].v, a[2].v, a[3].v); else if(!strcmp(k,"nnnnn")) gr->InPlot(a[0].v, a[1].v, a[2].v, a[3].v, a[4].v!=0); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_columnplot(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nn")) gr->ColumnPlot(iint(a[0].v), iint(a[1].v)); else if(!strcmp(k,"nnn")) gr->ColumnPlot(iint(a[0].v), iint(a[1].v), a[2].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_gridplot(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nnn")) gr->GridPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v)); else if(!strcmp(k,"nnnn")) gr->GridPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v), a[3].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_stickplot(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nnnn")) gr->StickPlot(iint(a[0].v), iint(a[1].v), a[2].v, a[3].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_pipe(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Pipe(*(a[0].d),*(a[1].d),"",0.05,opt); else if(!strcmp(k,"dds")) gr->Pipe(*(a[0].d),*(a[1].d),a[2].s.c_str(),0.05,opt); else if(!strcmp(k,"ddsn")) gr->Pipe(*(a[0].d),*(a[1].d),a[2].s.c_str(),a[3].v,opt); else if(!strcmp(k,"dddd")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",0.05,opt); else if(!strcmp(k,"dddds")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),0.05,opt); else if(!strcmp(k,"ddddsn")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),a[5].v,opt); else if(!strcmp(k,"ddd")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),"",0.05,opt); else if(!strcmp(k,"ddds")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),0.05,opt); else if(!strcmp(k,"dddsn")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),a[4].v,opt); else if(!strcmp(k,"dddddd")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",0.05,opt); else if(!strcmp(k,"dddddds")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),0.05,opt); else if(!strcmp(k,"ddddddsn")) gr->Pipe(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),a[7].v,opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_origin(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nn")) gr->SetOrigin(a[0].v,a[1].v,NAN); else if(!strcmp(k,"nnn")) gr->SetOrigin(a[0].v,a[1].v,a[2].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_norm(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dnn")) d->Norm(a[1].v,a[2].v); else if(!strcmp(k,"dnnn")) d->Norm(a[1].v,a[2].v,a[3].v!=0); else if(!strcmp(k,"dnnnn")) d->Norm(a[1].v,a[2].v,a[3].v!=0,iint(a[4].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_hist(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddd")) *d = gr->Hist(*(a[1].d), *(a[2].d),opt); else if(!strcmp(k,"dddd")) *d = gr->Hist(*(a[1].d), *(a[2].d), *(a[3].d),opt); else if(!strcmp(k,"ddddd")) *d = gr->Hist(*(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d),opt); else if(!strcmp(k,"ddnnn")) *d = mglData(true,mgl_data_hist(a[1].d,int(a[2].v+0.5), a[3].v, a[4].v, 0)); else if(!strcmp(k,"ddnnnn")) *d = mglData(true,mgl_data_hist(a[1].d,int(a[2].v+0.5), a[3].v, a[4].v, int(a[5].v+0.5))); else if(!strcmp(k,"dddnnn")) *d = mglData(true,mgl_data_hist_w(a[1].d,a[2].d, int(a[3].v+0.5), a[4].v, a[5].v, 0)); else if(!strcmp(k,"dddnnnn")) *d = mglData(true,mgl_data_hist_w(a[1].d,a[2].d, int(a[3].v+0.5), a[4].v, a[5].v, int(a[6].v+0.5))); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_mirror(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"ds") && d) d->Mirror(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_hankel(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"ds") && d) d->Hankel(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_sinfft(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"ds") && d) d->SinFFT(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_cosfft(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"ds") && d) d->CosFFT(a[1].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_new(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dn")) d->Create(iint(a[1].v)); else if(!strcmp(k,"dns")) { d->Create(iint(a[1].v)); d->Fill(gr->Self(),a[2].s.c_str(),opt); } else if(!strcmp(k,"dnn")) d->Create(iint(a[1].v),iint(a[2].v)); else if(!strcmp(k,"dnns")) { d->Create(iint(a[1].v),iint(a[2].v)); d->Fill(gr->Self(),a[3].s.c_str(),opt); } else if(!strcmp(k,"dnnn")) d->Create(iint(a[1].v),iint(a[2].v),iint(a[3].v)); else if(!strcmp(k,"dnnns")) { d->Create(iint(a[1].v),iint(a[2].v),iint(a[3].v)); d->Fill(gr->Self(),a[4].s.c_str(),opt); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_var(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); // TODO use mglDataV here?! if(!d) return 1; if(!strcmp(k,"dnn")) { d->Create(iint(a[1].v)); d->Fill(a[2].v, NAN); } else if(!strcmp(k,"dnnn")) { d->Create(iint(a[1].v)); d->Fill(a[2].v, a[3].v); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_chdir(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"s")) { if(chdir(a[0].s.c_str())) gr->SetWarn(mglWarnFile,"chdir"); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_perspective(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->Perspective(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_facex(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnn")) gr->FaceX(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v); else if(!strcmp(k,"nnnnns")) gr->FaceX(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v, a[5].s.c_str()); else if(!strcmp(k,"nnnnnsnn")) gr->FaceX(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v, a[5].s.c_str(),a[6].v,a[7].v); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_facey(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnn")) gr->FaceY(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v); else if(!strcmp(k,"nnnnns")) gr->FaceY(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v, a[5].s.c_str()); else if(!strcmp(k,"nnnnnsnn")) gr->FaceY(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v, a[5].s.c_str(),a[6].v,a[7].v); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_facez(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nnnnn")) gr->FaceZ(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v); else if(!strcmp(k,"nnnnns")) gr->FaceZ(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v, a[5].s.c_str()); else if(!strcmp(k,"nnnnnsnn")) gr->FaceZ(mglPoint(a[0].v, a[1].v, a[2].v), a[3].v, a[4].v, a[5].s.c_str(),a[6].v,a[7].v); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_normsl(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dnn")) d->NormSl(a[1].v, a[2].v); else if(!strcmp(k,"dnns")) d->NormSl(a[1].v, a[2].v, a[3].s.c_str()[0]); else if(!strcmp(k,"dnnsn")) d->NormSl(a[1].v, a[2].v, a[3].s.c_str()[0],a[4].v); else if(!strcmp(k,"dnnsnn"))d->NormSl(a[1].v, a[2].v, a[3].s.c_str()[0],a[4].v,a[5].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_momentum(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dds")) *d = mglData(true,mgl_data_momentum(a[1].d,'z', a[2].s.c_str())); else if(!strcmp(k,"ddss")) *d = mglData(true,mgl_data_momentum(a[1].d,a[3].s.c_str()[0], a[2].s.c_str())); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fit(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dddddssd")) { mglData *i = dynamic_cast<mglData *>(a[7].d); if(i) *d = gr->Fit(*(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), a[5].s.c_str(), a[6].s.c_str(), *i,opt); else res = 1; } else if(!strcmp(k,"dddddss")) *d = gr->Fit(*(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), a[5].s.c_str(), a[6].s.c_str(),opt); else if(!strcmp(k,"ddddssd")) { mglData *i = dynamic_cast<mglData *>(a[6].d); if(i) *d = gr->Fit(*(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(), a[5].s.c_str(), *i,opt); else res = 1; } else if(!strcmp(k,"ddddss")) *d = gr->Fit(*(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(), a[5].s.c_str(),opt); else if(!strcmp(k,"dddssd")) { mglData *i = dynamic_cast<mglData *>(a[5].d); if(i) *d = gr->Fit(*(a[1].d), *(a[2].d), a[3].s.c_str(), a[4].s.c_str(), *i,opt); else res = 1; } else if(!strcmp(k,"dddss")) *d = gr->Fit(*(a[1].d), *(a[2].d), a[3].s.c_str(), a[4].s.c_str(),opt); else if(!strcmp(k,"ddssd")) { mglData *i = dynamic_cast<mglData *>(a[4].d); if(i) *d = gr->Fit(*(a[1].d), a[2].s.c_str(), a[3].s.c_str(), *i,opt); else res = 1; } else if(!strcmp(k,"ddss")) *d = gr->Fit(*(a[1].d), a[2].s.c_str(), a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fits(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddddddssd")) { mglData *i = dynamic_cast<mglData *>(a[8].d); if(i) *d = gr->FitS(*(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), *(a[5].d), a[6].s.c_str(), a[7].s.c_str(), *i,opt); else res = 1; } else if(!strcmp(k,"ddddddss")) *d = gr->FitS(*(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), *(a[5].d), a[6].s.c_str(), a[7].s.c_str(),opt); else if(!strcmp(k,"dddddssd")) { mglData *i = dynamic_cast<mglData *>(a[7].d); if(i) *d = gr->FitS(*(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), a[5].s.c_str(), a[6].s.c_str(), *i,opt); else res = 1; } else if(!strcmp(k,"dddddss")) *d = gr->FitS(*(a[1].d), *(a[2].d), *(a[3].d), *(a[4].d), a[5].s.c_str(), a[6].s.c_str(),opt); else if(!strcmp(k,"ddddssd")) { mglData *i = dynamic_cast<mglData *>(a[6].d); if(i) *d = gr->FitS(*(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(), a[5].s.c_str(), *i,opt); else res = 1; } else if(!strcmp(k,"ddddss")) *d = gr->FitS(*(a[1].d), *(a[2].d), *(a[3].d), a[4].s.c_str(), a[5].s.c_str(),opt); else if(!strcmp(k,"dddssd")) { mglData *i = dynamic_cast<mglData *>(a[5].d); if(i) *d = gr->FitS(*(a[1].d), *(a[2].d), a[3].s.c_str(), a[4].s.c_str(), *i,opt); else res = 1; } else if(!strcmp(k,"dddss")) *d = gr->FitS(*(a[1].d), *(a[2].d), a[3].s.c_str(), a[4].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_putsfit(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; gr->Self()->SaveState(opt); if(!strcmp(k,"nn")) gr->PutsFit(mglPoint(a[0].v,a[1].v)); else if(!strcmp(k,"nns")) gr->PutsFit(mglPoint(a[0].v,a[1].v), a[2].s.c_str()); else if(!strcmp(k,"nnss")) gr->PutsFit(mglPoint(a[0].v,a[1].v), a[2].s.c_str(),a[3].s.c_str()); else if(!strcmp(k,"nnssn")) gr->PutsFit(mglPoint(a[0].v,a[1].v), a[2].s.c_str(),a[3].s.c_str(),a[4].v); else if(!strcmp(k,"nnn")) gr->PutsFit(mglPoint(a[0].v,a[1].v,a[2].v)); else if(!strcmp(k,"nnns")) gr->PutsFit(mglPoint(a[0].v,a[1].v,a[2].v), a[3].s.c_str()); else if(!strcmp(k,"nnnss")) gr->PutsFit(mglPoint(a[0].v,a[1].v,a[2].v), a[3].s.c_str(),a[4].s.c_str()); else if(!strcmp(k,"nnnssn"))gr->PutsFit(mglPoint(a[0].v,a[1].v,a[2].v), a[3].s.c_str(),a[4].s.c_str(),a[5].v); else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_arrowsize(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetArrowSize(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_rearrange(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dn")) d->Rearrange(iint(a[1].v)); else if(!strcmp(k,"dnn")) d->Rearrange(iint(a[1].v), iint(a[2].v)); else if(!strcmp(k,"dnnn")) d->Rearrange(iint(a[1].v), iint(a[2].v), iint(a[3].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fplot(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"s")) gr->FPlot(a[0].s.c_str(), "",opt); else if(!strcmp(k,"ss")) gr->FPlot(a[0].s.c_str(), a[1].s.c_str(),opt); else if(!strcmp(k,"sss")) gr->FPlot(a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str(), "",opt); else if(!strcmp(k,"ssss")) gr->FPlot(a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str(), a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fsurf(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"s")) gr->FSurf(a[0].s.c_str(), "",opt); else if(!strcmp(k,"ss")) gr->FSurf(a[0].s.c_str(), a[1].s.c_str(),opt); else if(!strcmp(k,"sss")) gr->FSurf(a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str(), "",opt); else if(!strcmp(k,"ssss")) gr->FSurf(a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str(), a[3].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_fgets(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) // NOTE don't use options -- Puts can be part of group { int res=0; gr->Self()->SaveState(opt); char buf[1024]; FILE *fp; if(!strncmp(k,"nns",3)) { int i, n = (k[3]=='n'?iint(a[3].v):0); fp = fopen(a[2].s.c_str(),"rt"); if(!fp) { gr->SetWarn(mglWarnOpen,a[2].s.c_str()); return res; } for(i=0;i<n;i++) if(!fgets(buf,1024,fp)) continue; memset(buf,0,1024); if(!fgets(buf,1024,fp)) { char b[32]; snprintf(b,32,"%d",n); b[31]=0; gr->SetWarn(mglWarnOpen,(a[2].s+" - line "+b).c_str()); fclose(fp); return res; } fclose(fp); gr->Puts(mglPoint(a[0].v,a[1].v,NAN),buf, (k[4]=='s')?a[4].s.c_str():"", k[5]=='n'?a[5].v:-1); } else if(!strncmp(k,"nnns",4)) { int i, n = (k[4]=='n'?iint(a[4].v):0); fp = fopen(a[3].s.c_str(),"rt"); if(!fp) { gr->SetWarn(mglWarnOpen,a[3].s.c_str()); return res; } for(i=0;i<n;i++) if(!fgets(buf,1024,fp)) continue; memset(buf,0,1024); if(!fgets(buf,1024,fp)) { char b[32]; snprintf(b,32,"%d",n); b[31]=0; gr->SetWarn(mglWarnOpen,(a[3].s+" - line "+b).c_str()); fclose(fp); return res; } fclose(fp); gr->Puts(mglPoint(a[0].v,a[1].v,a[2].v),buf, (k[5]=='s')?a[5].s.c_str():"", k[6]=='n'?a[6].v:-1); } else res = 1; gr->Self()->LoadState(); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_import(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dss")) d->Import(a[1].s.c_str(), a[2].s.c_str()); else if(!strcmp(k,"dssnn")) d->Import(a[1].s.c_str(), a[2].s.c_str(), a[3].v,a[4].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_export(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"dss")) a[0].d->Export(a[1].s.c_str(), a[2].s.c_str()); else if(!strcmp(k,"dssnn")) a[0].d->Export(a[1].s.c_str(), a[2].s.c_str(), a[3].v,a[4].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_write(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->WriteFrame("", "MathGL"); else if(!strcmp(k,"s")) gr->WriteFrame(a[0].s.c_str(), "MathGL"); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_region(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Region(*(a[0].d),*(a[1].d),"",opt); else if(!strcmp(k,"dds")) gr->Region(*(a[0].d),*(a[1].d),a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Region(*(a[0].d),*(a[1].d),*(a[2].d),"",opt); else if(!strcmp(k,"ddds")) gr->Region(*(a[0].d),*(a[1].d),*(a[2].d),a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Region(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),"",opt); else if(!strcmp(k,"dddds")) gr->Region(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].s.c_str(),opt); else if(!strcmp(k,"dddddd")) gr->Region(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),"",opt); else if(!strcmp(k,"dddddds")) gr->Region(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),*(a[5].d),a[6].s.c_str(),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_envelop(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"d")) d->Envelop(); else if(!strcmp(k,"ds")) d->Envelop(a[1].s.c_str()[0]); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_sew(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"d")) d->Sew(); else if(!strcmp(k,"ds")) d->Sew(a[1].s.c_str()); else if(!strcmp(k,"dsn")) d->Sew(a[1].s.c_str(), a[2].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_evaluate(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddd")) *d = mglData(true,mgl_data_evaluate(a[1].d,a[2].d,0,0,true)); else if(!strcmp(k,"dddn")) *d = mglData(true,mgl_data_evaluate(a[1].d,a[2].d,0,0, a[3].v!=0)); else if(!strcmp(k,"dddd")) *d = mglData(true,mgl_data_evaluate(a[1].d,a[2].d,a[3].d,0,true)); else if(!strcmp(k,"ddddn")) *d = mglData(true,mgl_data_evaluate(a[1].d,a[2].d,a[3].d,0, a[4].v!=0)); else if(!strcmp(k,"ddddd")) *d = mglData(true,mgl_data_evaluate(a[1].d,a[2].d,a[3].d,a[4].d,true)); else if(!strcmp(k,"dddddn"))*d = mglData(true,mgl_data_evaluate(a[1].d,a[2].d,a[3].d,a[4].d, a[5].v!=0)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_solve(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddns")) *d = mglData(true,mgl_data_solve(a[1].d, a[2].v, a[3].s[0], 0, true)); else if(!strcmp(k,"ddnsn")) *d = mglData(true,mgl_data_solve(a[1].d, a[2].v, a[3].s[0], 0, a[4].v!=0)); else if(!strcmp(k,"ddnsd")) *d = mglData(true,mgl_data_solve(a[1].d, a[2].v, a[3].s[0], a[4].d, true)); else if(!strcmp(k,"ddnsdn"))*d = mglData(true,mgl_data_solve(a[1].d, a[2].v, a[3].s[0], a[4].d, a[5].v!=0)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_put(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dn")) d->Put(a[1].v); else if(!strcmp(k,"dnn")) d->Put(a[1].v, iint(a[2].v)); else if(!strcmp(k,"dnnn")) d->Put(a[1].v, iint(a[2].v),iint(a[3].v)); else if(!strcmp(k,"dnnnn")) d->Put(a[1].v, iint(a[2].v),iint(a[3].v),iint(a[4].v)); else if(!strcmp(k,"dd")) d->Put(*(a[1].d)); else if(!strcmp(k,"ddn")) d->Put(*(a[1].d), iint(a[2].v)); else if(!strcmp(k,"ddnn")) d->Put(*(a[1].d), iint(a[2].v),iint(a[3].v)); else if(!strcmp(k,"ddnnn")) d->Put(*(a[1].d), iint(a[2].v),iint(a[3].v),iint(a[4].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_palette(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"s")) gr->SetPalette(a[0].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_combine(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"ddd") && d) *d = mglData(true,mgl_data_combine(a[1].d, a[2].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_correl(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"ddds") && d) *d = mglData(true,mgl_data_correl(a[1].d, a[2].d, a[3].s.c_str())); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_roots(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dsds")) *d = mglData(true,mgl_data_roots(a[1].s.c_str(), a[2].d, a[3].s[0])); else if(!strcmp(k,"dsns")) d->a[0] = mgl_find_root_txt(a[1].s.c_str(), a[2].v, a[3].s[0]); else if(!strcmp(k,"dsd")) *d = mglData(true,mgl_data_roots(a[1].s.c_str(), a[2].d, 'x')); else if(!strcmp(k,"dsn")) d->a[0] = mgl_find_root_txt(a[1].s.c_str(), a[2].v, 'x'); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ode(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dssd")) *d = mglODE(a[1].s.c_str(), a[2].s.c_str(), *(a[3].d)); else if(!strcmp(k,"dssdnn")) *d = mglODE(a[1].s.c_str(), a[2].s.c_str(), *(a[3].d), a[4].v, a[5].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_pde(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d), *c = dynamic_cast<mglData *>(a[1].d); if(!d) return 1; if(!strcmp(k,"dsdd")) // TODO mglDataC can be used here *d = gr->PDE(a[1].s.c_str(), *(a[2].d), *(a[3].d), 0.1,100,opt); else if(!strcmp(k,"dsddn")) *d = gr->PDE(a[1].s.c_str(), *(a[2].d), *(a[3].d), a[4].v,100,opt); else if(!strcmp(k,"dsddnn")) *d = gr->PDE(a[1].s.c_str(), *(a[2].d), *(a[3].d), a[4].v,a[5].v,opt); else if(!strcmp(k,"ddsdd") && c) { mglDataC res = mglDataC(true, mgl_pde_solve_c(gr->Self(),a[2].s.c_str(), a[3].d, a[4].d, 0.1,100,opt)); *d = res.Abs(); *c = res.Arg(); } else if(!strcmp(k,"ddsddn") && c) { mglDataC res = mglDataC(true, mgl_pde_solve_c(gr->Self(),a[2].s.c_str(), a[3].d, a[4].d, a[5].v,100,opt)); *d = res.Abs(); *c = res.Arg(); } else if(!strcmp(k,"ddsddnn") && c) { mglDataC res = mglDataC(true, mgl_pde_solve_c(gr->Self(),a[2].s.c_str(), a[3].d, a[4].d, a[5].v,a[6].v,opt)); *d = res.Abs(); *c = res.Arg(); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_qo2d(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d), *c = dynamic_cast<mglData *>(a[1].d); if(!d) return 1; if(!strcmp(k,"dsddd")) *d = mglData(true, mgl_qo2d_solve(a[1].s.c_str(), a[2].d, a[3].d, a[4].d, 1,100, 0,0)); else if(!strcmp(k,"dsdddn")) *d = mglData(true, mgl_qo2d_solve(a[1].s.c_str(), a[2].d, a[3].d, a[4].d, a[5].v,100, 0,0)); else if(!strcmp(k,"dsdddnn")) *d = mglData(true, mgl_qo2d_solve(a[1].s.c_str(), a[2].d, a[3].d, a[4].d, a[5].v,a[6].v, 0,0)); else if(!strcmp(k,"dsdddnndd")) *d = mglData(true, mgl_qo2d_solve(a[1].s.c_str(), a[2].d, a[3].d, a[4].d, a[5].v,a[6].v, dynamic_cast<mglData *>(a[7].d),dynamic_cast<mglData *>(a[8].d))); else if(!strcmp(k,"ddsddd") && c) { mglDataC res = mglDataC(true, mgl_qo2d_solve_c(a[2].s.c_str(), a[3].d, a[4].d, a[5].d, 1,100, 0,0)); *d = res.Abs(); *c = res.Arg(); } else if(!strcmp(k,"ddsdddn") && c) { mglDataC res = mglDataC(true, mgl_qo2d_solve_c(a[2].s.c_str(), a[3].d, a[4].d, a[5].d, a[6].v,100, 0,0)); *d = res.Abs(); *c = res.Arg(); } else if(!strcmp(k,"ddsdddnn") && c) { mglDataC res = mglDataC(true, mgl_qo2d_solve_c(a[2].s.c_str(), a[3].d, a[4].d, a[5].d, a[6].v,a[7].v, 0,0)); *d = res.Abs(); *c = res.Arg(); } else if(!strcmp(k,"ddsdddnndd") && c) { mglDataC res = mglDataC(true, mgl_qo2d_solve_c(a[2].s.c_str(), a[3].d, a[4].d, a[5].d, a[6].v,a[7].v, dynamic_cast<mglData *>(a[8].d),dynamic_cast<mglData *>(a[9].d))); *d = res.Abs(); *c = res.Arg(); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_qo3d(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d), *c = dynamic_cast<mglData *>(a[1].d); if(!d) return 1; if(!strcmp(k,"dsddd")) *d = mglData(true, mgl_qo3d_solve(a[1].s.c_str(), a[2].d, a[3].d, a[4].d, 1,100, 0,0,0)); else if(!strcmp(k,"dsdddn")) *d = mglData(true, mgl_qo3d_solve(a[1].s.c_str(), a[2].d, a[3].d, a[4].d, a[5].v,100, 0,0,0)); else if(!strcmp(k,"dsdddnn")) *d = mglData(true, mgl_qo3d_solve(a[1].s.c_str(), a[2].d, a[3].d, a[4].d, a[5].v,a[6].v, 0,0,0)); else if(!strcmp(k,"dsdddnnddd")) *d = mglData(true, mgl_qo3d_solve(a[1].s.c_str(), a[2].d, a[3].d, a[4].d, a[5].v,a[6].v, dynamic_cast<mglData *>(a[7].d),dynamic_cast<mglData *>(a[8].d),dynamic_cast<mglData *>(a[9].d))); else if(!strcmp(k,"ddsddd") && c) { mglDataC res = mglDataC(true, mgl_qo3d_solve_c(a[2].s.c_str(), a[3].d, a[4].d, a[5].d, 1,100, 0,0,0)); *d = res.Abs(); *c = res.Arg(); } else if(!strcmp(k,"ddsdddn") && c) { mglDataC res = mglDataC(true, mgl_qo3d_solve_c(a[2].s.c_str(), a[3].d, a[4].d, a[5].d, a[6].v,100, 0,0,0)); *d = res.Abs(); *c = res.Arg(); } else if(!strcmp(k,"ddsdddnn") && c) { mglDataC res = mglDataC(true, mgl_qo3d_solve_c(a[2].s.c_str(), a[3].d, a[4].d, a[5].d, a[6].v,a[7].v, 0,0,0)); *d = res.Abs(); *c = res.Arg(); } else if(!strcmp(k,"ddsdddnnddd") && c) { mglDataC res = mglDataC(true, mgl_qo3d_solve_c(a[2].s.c_str(), a[3].d, a[4].d, a[5].d, a[6].v,a[7].v, dynamic_cast<mglData *>(a[8].d),dynamic_cast<mglData *>(a[9].d),dynamic_cast<mglData *>(a[10].d))); *d = res.Abs(); *c = res.Arg(); } else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ray(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"dsnnnn")) *d = mglRay(a[1].s.c_str(), mglPoint(a[2].v, a[3].v), mglPoint(a[4].v, a[5].v)); else if(!strcmp(k,"dsnnnnnn")) *d = mglRay(a[1].s.c_str(), mglPoint(a[2].v, a[3].v, a[4].v), mglPoint(a[5].v, a[6].v, a[7].v)); else if(!strcmp(k,"dsnnnnnnn")) *d = mglRay(a[1].s.c_str(), mglPoint(a[2].v, a[3].v, a[4].v), mglPoint(a[5].v, a[6].v, a[7].v), a[8].v); else if(!strcmp(k,"dsnnnnnnnn")) *d = mglRay(a[1].s.c_str(), mglPoint(a[2].v, a[3].v, a[4].v), mglPoint(a[5].v, a[6].v, a[7].v), a[8].v,a[9].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_jacobian(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddd")) *d = mglJacobian(*(a[1].d), *(a[2].d)); else if(!strcmp(k,"dddd")) *d = mglJacobian(*(a[1].d), *(a[2].d), *(a[3].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tens(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; if(!strcmp(k,"dd")) gr->Tens(*(a[0].d),*(a[1].d), "",opt); else if(!strcmp(k,"dds")) gr->Tens(*(a[0].d),*(a[1].d), a[2].s.c_str(),opt); else if(!strcmp(k,"ddd")) gr->Tens(*(a[0].d),*(a[1].d),*(a[2].d), "",opt); else if(!strcmp(k,"ddds")) gr->Tens(*(a[0].d),*(a[1].d),*(a[2].d), a[3].s.c_str(),opt); else if(!strcmp(k,"dddd")) gr->Tens(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), "",opt); else if(!strcmp(k,"dddds")) gr->Tens(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d), a[4].s.c_str(),opt); return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ticklen(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetTickLen(a[0].v); else if(!strcmp(k,"nn")) gr->SetTickLen(a[0].v, a[1].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_tickshift(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetTickShift(mglPoint(a[0].v)); else if(!strcmp(k,"nn")) gr->SetTickShift(mglPoint(a[0].v, a[1].v)); else if(!strcmp(k,"nnn")) gr->SetTickShift(mglPoint(a[0].v, a[1].v, a[2].v)); else if(!strcmp(k,"nnnn")) gr->SetTickShift(mglPoint(a[0].v, a[1].v, a[2].v, a[3].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_origintick(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"n")) gr->SetOriginTick(a[0].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_axisstl(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->SetAxisStl(); else if(!strcmp(k,"s")) gr->SetAxisStl(a[0].s.c_str()); else if(!strcmp(k,"ss")) gr->SetAxisStl(a[0].s.c_str(), a[1].s.c_str()); else if(!strcmp(k,"sss")) gr->SetAxisStl(a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_ranges(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nnnn")) gr->SetRanges(a[0].v,a[1].v, a[2].v,a[3].v); else if(!strcmp(k,"nnnnnn"))gr->SetRanges(a[0].v,a[1].v,a[2].v, a[3].v,a[4].v,a[5].v); else if(!strcmp(k,"dd")) gr->SetRanges(*(a[0].d),*(a[1].d)); else if(!strcmp(k,"ddd")) gr->SetRanges(*(a[0].d),*(a[1].d), *(a[2].d)); else if(!strcmp(k,"dddd")) gr->SetRanges(*(a[0].d),*(a[1].d), *(a[2].d),*(a[3].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_adjust(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->Adjust(); else if(!strcmp(k,"s")) gr->Adjust(a[0].s.c_str()); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_insert(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) d->Insert(a[1].s.c_str()[0]); else if(!strcmp(k,"dsn")) d->Insert(a[1].s.c_str()[0], iint(a[2].v)); else if(!strcmp(k,"dsnn")) d->Insert(a[1].s.c_str()[0], iint(a[2].v), iint(a[3].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_delete(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ds")) d->Delete(a[1].s.c_str()[0]); else if(!strcmp(k,"dsn")) d->Delete(a[1].s.c_str()[0], iint(a[2].v)); else if(!strcmp(k,"dsnn")) d->Delete(a[1].s.c_str()[0], iint(a[2].v), iint(a[3].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_roll(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"dsn") && d) d->Roll(a[1].s.c_str()[0], iint(a[2].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_datagrid(mglGraph *gr, long , mglArg *a, const char *k, const char *opt) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!strcmp(k,"dddd") && d) gr->DataGrid(*d, *(a[1].d), *(a[2].d), *(a[3].d),opt); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_triangulate(mglGraph *, long , mglArg *a, const char *k, const char *) { int res=0; mglData *d = dynamic_cast<mglData *>(a[0].d); if(!d) return 1; if(!strcmp(k,"ddd")) *d = mglTriangulation(*(a[1].d), *(a[2].d)); else if(!strcmp(k,"dddd")) *d = mglTriangulation(*(a[1].d), *(a[2].d), *(a[3].d)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_view(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nn")) gr->View(a[0].v, a[1].v); else if(!strcmp(k,"nnn")) gr->View(a[0].v, a[1].v, a[2].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_zoom(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nnnn")) gr->Zoom(a[0].v, a[1].v, a[2].v, a[3].v); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_zoomaxis(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"nn")) gr->ZoomAxis(mglPoint(a[0].v), mglPoint(a[1].v)); else if(!strcmp(k,"nnnn")) gr->ZoomAxis(mglPoint(a[0].v, a[1].v), mglPoint(a[2].v, a[3].v)); else if(!strcmp(k,"nnnnnn")) gr->ZoomAxis(mglPoint(a[0].v, a[1].v, a[2].v), mglPoint(a[3].v, a[4].v, a[5].v)); else if(!strcmp(k,"nnnnnnnn")) gr->ZoomAxis(mglPoint(a[0].v, a[1].v, a[2].v, a[3].v), mglPoint(a[4].v, a[5].v, a[6].v, a[7].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_drawreg(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) gr->SetDrawReg(); else if(!strcmp(k,"nnn")) gr->SetDrawReg(iint(a[0].v), iint(a[1].v), iint(a[2].v)); else res = 1; return res; } //----------------------------------------------------------------------------- int MGL_NO_EXPORT mgls_version(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; char buf[32]; sprintf(buf,"MathGL version is 2.%g",MGL_VER2); if(!strcmp(k,"")) gr->SetWarn(-1,buf); else if(!strcmp(k,"s")) res = mgl_check_version(a[0].s.c_str())?1:0; else res = 1; return res; } //----------------------------------------------------------------------------- mglCommand mgls_base_cmd[] = { {"addlegend","Add legend entry","addlegend 'txt' 'fmt'", mgls_addlegend,15}, {"addto","Add data or number","addto Var Dat|Var num", mgls_addto ,3}, {"adjust","Adjust ticks for best view","adjust ['dir']", mgls_adjust ,14}, {"alpha","Switch on/off transparency","alpha [val]", mgls_alpha ,2}, {"alphadef","Set default transparency","alphadef val", mgls_alphadef ,2}, {"ambient","Set ambient light brightness","ambient val", mgls_ambient ,2}, {"arc","Draw angle arc","arc x0 y0 x1 y1 a ['fmt']|x0 y0 z0 x1 y1 a ['fmt']|x0 y0 z0 xr yr zr x1 y1 z1 a ['fmt']", mgls_arc ,13}, {"area","Draw area plot for 1D data","area Ydat ['fmt']|Xdat Ydat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_area ,7}, {"arrowsize","Set size of arrows","arrowsize val", mgls_arrowsize ,2}, {"ask","Define parameter from user input","ask $N 'question'", 0, 6}, {"aspect","Set aspect ration","aspect valx valy [valz]", mgls_aspect ,5}, {"axial","Draw surfaces of contour lines rotation","axial Zdat ['fmt' num]|Xdat Ydat Zdat ['fmt' num]", mgls_axial ,8}, {"axis","Setup or draw axis","axis ['dir' 'fmt']|'fx' 'fy' 'fz' ['fc']|how", mgls_axis ,12}, {"axisstl","Set axis and tick style","axisstl 'stl' ['sub']", mgls_axisstl ,14}, {"background","Load image for background","background 'fname'", mgls_background ,12}, {"ball","Draw point (ball)","ball posx posy ['fmt']|posx posy posz ['fmt']", mgls_ball ,13}, {"barh","Draw horizontal bars for 1D data", "barh Ydat ['fmt' above]|Xdat Ydat ['fmt' above]", mgls_barh ,7}, {"bars","Draw bars for 1D data","bars Ydat ['fmt' above]|Xdat Ydat ['fmt' above]|Xdat Ydat Zdat ['fmt' above]", mgls_bars ,7}, {"barwidth","Set default bars width","barwidth val", mgls_barwidth ,2}, {"beam","Draw quasioptical beam","beam Tr G1 G2 Adat r ['sch' flag num] ", mgls_beam ,9}, {"belt","Draw belts","belt Zdat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_belt ,8}, {"box","Draw bounding box","box ['fmt' ticks]", mgls_box ,12}, {"boxplot","Draw boxplot for 2D data","boxplot Ydat ['fmt']|Xdat Ydat ['fmt']", mgls_boxplot ,7}, {"boxs","Draw boxes","boxs Zdat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_boxs ,8}, {"break","Break for-cycle","break", 0, 6}, {"call","Execute script in external file","call 'name' [args]", 0, 6}, {"candle","Draw candlestick chart","candle candle Vdat1 ['fmt']|Vdat1 Vdat2 ['fmt']|Vdat1 Ydat1 Ydat2 ['fmt']||Vdat1 Vdat2 Ydat1 Ydat2 ['fmt']|Xdat Vdat1 Vdat2 Ydat1 Ydat2 ['fmt']", mgls_candle ,7}, {"chart","Draw chart","chart Dat ['fmt']", mgls_chart ,7}, {"chdir","Change current directory","chdir 'path'", mgls_chdir ,2}, {"circle","Draw circle","circle x y r ['fmt']|x y z r ['fmt']", mgls_circle ,13}, {"clean","Remove duplicate rows","clean Dat id", mgls_clean ,3}, {"clearlegend","Clear legend antries","clearlegend", mgls_clearlegend ,15}, {"clf","Clear picture","clf|'col'|r g b", mgls_clf ,12}, {"cloud","Draw cloud","cloud Adat ['fmt']|Xdat Ydat Zdat Adat ['fmt']", mgls_cloud ,9}, {"colorbar","Draw colorbar","colorbar ['fmt' pos]|Vdat ['fmt' pos]|'sch' pos x y [w h]|Vdat 'sch' pos x y [w h]", mgls_colorbar ,12}, {"column","Get data column filled by formula on column ids","column Res Dat 'eq'", mgls_column ,4}, {"columnplot","Set position of plot inside cell of column", "columnplot num ind [d]", mgls_columnplot ,5}, {"combine", "Direct multiplication of arrays", "combine Res Adat Bdat", mgls_combine ,4}, {"cone","Draw cone","cone x1 y1 z1 x2 y2 z2 r1 [r2 'fmt' edge]", mgls_cone ,13}, {"cones","Draw cones for 1D data","cones Ydat ['fmt' above]|Xdat Ydat ['fmt' above]|Xdat Ydat Zdat ['fmt' above]", mgls_cones ,7}, {"cont","Draw contour lines","cont Zdat ['fmt' num zpos]|Vdat Zdat ['fmt' zpos]|Xdat Ydat Zdat ['fmt' num zpos]|Vdat Xdat Ydat Zdat ['fmt' zpos]", mgls_cont ,8}, {"cont3","Draw contour lines for 3D data","cont3 Adat 'dir' [val 'fmt' num]|Vdat Adat 'dir' [val 'fmt']|Xdat Ydat Zdat Adat 'dir' [val 'fmt' num]|Vdat Xdat Ydat Zdar Adat 'dir' [val 'fmt']", mgls_cont3 ,9}, {"contd","Draw solid contours with manual colors","contd Zdat ['fmt' num zpos]|Vdat Zdat ['fmt' zpos]|Xdat Ydat Zdat ['fmt' num zpos]|Vdat Xdat Ydat Zdat ['fmt' zpos]", mgls_contd ,8}, {"contf","Draw solid contours","contf Zdat ['fmt' num zpos]|Vdat Zdat ['fmt' zpos]|Xdat Ydat Zdat ['fmt' num zpos]|Vdat Xdat Ydat Zdat ['fmt' zpos]", mgls_contf ,8}, {"contf3","Draw solid contour lines for 3D data","contf3 Adat 'dir' [val 'fmt' num]|Vdat Adat 'dir' [val 'fmt']|Xdat Ydat Zdat Adat 'dir' [val 'fmt' num]|Vdat Xdat Ydat Zdar Adat 'dir' [val 'fmt']", mgls_contf3 ,9}, {"contfx","Draw solid contour lines at x-slice (or x-plane)","contfx Dat ['fmt' pos num]", mgls_contfx ,0}, {"contfy","Draw solid contour lines at y-slice (or y-plane)","contfy Dat ['fmt' pos num]", mgls_contfy ,0}, {"contfz","Draw solid contour lines at z-slice (or z-plane)","contfz Dat ['fmt' pos num]", mgls_contfz ,0}, {"continue","Skip commands and iterate for-cycle again","continue", 0, 6}, {"contv","Draw contour tubes","contv Zdat ['fmt' num zpos]|Vdat Zdat ['fmt' zpos]|Xdat Ydat Zdat ['fmt' num zpos]|Vdat Xdat Ydat Zdat ['fmt' zpos]", mgls_contv ,0}, {"contx","Draw contour lines at x-slice (or x-plane)","contx Dat ['fmt' pos num]", mgls_contx ,0}, {"conty","Draw contour lines at y-slice (or y-plane)","conty Dat ['fmt' pos num]", mgls_conty ,0}, {"contz","Draw contour lines at z-slice (or z-plane)","contz Dat ['fmt' pos num]", mgls_contz ,0}, {"copy","Copy data from another variable","copy Dat1 Dat2 ['eq' onaxis]", mgls_copy ,4}, {"correl", "Find correlation between data arrays", "correl Res Adat Bdat 'dir'", mgls_correl ,4}, {"cosfft","Cos-Fourier transform at some direction","cosfft Dat 'dir'", mgls_cosfft ,16}, {"crange","Set color range","crange Dat [add] | c1 c2 [add]", mgls_crange ,14}, {"crop","Crop edge of data","crop Dat n1 n2 'dir'", mgls_crop ,16}, {"crust","Draw reconstructed surface for arbitrary data points","crust Xdat Ydat Zdat ['fmt']", mgls_crust ,0}, {"ctick","Set ticks for colorbar","ctick 'tmpl' | dc ['factor']", mgls_ctick ,14}, {"cumsum","Cumulative summation","cumsum Dat 'dir'", mgls_cumsum ,16}, {"curve","Draw curve","curve x1 y1 dx1 dy1 x2 y2 dx2 dy2 ['fmt']|x1 y1 z1 dx1 dy1 dz1 x2 y2 z2 dx2 dy2 dz2 ['fmt']", mgls_curve ,13}, {"cut","Setup plot points cutting","cut val|x1 y1 z1 x2 y2 z2|'cond'", mgls_cut ,2}, {"datagrid","Fill data by triangulated values","datagrid Var Xdat Ydat Zdat", mgls_datagrid ,3}, {"datas","Print list of data names in HDF file","datas 'fname'", mgls_datas ,3}, {"defchr","Define parameter as character","defchr $N val", 0, 6}, {"define","Define constant or parameter","define $N sth | Var val", 0, 6}, {"defnum","Define parameter as numerical value","defnum $N val", 0, 6}, {"defpal","Define parameter as palette color","defpal $N val", 0, 6}, {"delete","Delete slice of data","delete Dat 'dir' [pos=0 num=1]", mgls_delete ,3}, {"dens","Draw density plot","dens Zdat ['fmt' zpos]|Xdat Ydat Zdat ['fmt' zpos]", mgls_dens ,8}, {"dens3","Draw density plot at slices of 3D data","dens3 Adat 'dir' [pos 'fmt']|Xdat Ydat Zdat Adat 'dir' [pos 'fmt']", mgls_dens3 ,9}, {"densx","Draw density plot at x-slice (or x-plane)","densx Dat ['fmt' pos]", mgls_densx ,0}, {"densy","Draw density plot at y-slice (or y-plane)","densy Dat ['fmt' pos]", mgls_densy ,0}, {"densz","Draw density plot at z-slice (or z-plane)","densz Dat ['fmt' pos]", mgls_densz ,0}, {"dew","Draw dew plot","dew Udat Vdat ['fmt']|Xdat Ydat Udat Vdat ['fmt']", mgls_dew ,11}, {"diff","Numerically differentiate data","diff Var 'dir'", mgls_diff ,16}, {"diff2","Numerically double differentiate data","diff2 Var 'dir'", mgls_diff2 ,16}, {"diffuse","Set diffusive light brightness","diffuse val", mgls_diffuse ,2}, {"divto","Divide by data or number","divto Var Dat|Var num", mgls_divto ,3}, {"dots","Draw dots for arbitrary data points","dots Xdat Ydat Zdat ['fmt']|Xdat Ydat Zdat Adat ['fmt']|Xdat Ydat Zdat Cdat Adat ['fmt']", mgls_dots ,9}, {"drawreg","Set draw region for quality&4","drawreg|nx ny m", mgls_drawreg ,2}, {"drop","Draw drop","drop x0 y0 dx dy r ['col' sh asp]|x0 y0 z0 dx dy dz r ['col' sh asp]", mgls_drop ,13}, {"ellipse","Draw ellipse","ellipse x1 y1 x2 y2 r ['fmt']|x1 y1 z1 x2 y2 z2 r ['fmt']", mgls_ellipse ,13}, {"else","Execute if condition is false","else", 0, 6}, {"elseif","Conditional operator","elseif val|Dat ['cond']", 0, 6}, {"endif","Finish if/else block","endif", 0, 6}, {"envelop","Find envelop for the data","envelop Dat ['dir']", mgls_envelop ,16}, {"errbox","Draw error box","errbox x y ex ey ['fmt']|x y z ex ey ez ['fmt']", mgls_errbox ,13}, {"error","Draw error boxes","error Ydat Yerr ['fmt']|Xdat Ydat Yerr ['fmt']|Xdat Ydat Xerr Yerr ['fmt']", mgls_error ,7}, {"evaluate","Evaluate (interpolate) values of array Dat at points i=idat,j=jdat,k=kdat","evaluate Res Dat Idat [norm]|Res Dat Idat Jdat [norm]|Res Dat Idat Jdat Kdat [norm]", mgls_evaluate ,4}, {"export","Export data to PNG picture","export Dat 'fname' 'sch' [v1 v2]", mgls_export ,3}, {"extend","Extend data array","extend Dat dim1 [dim2]", mgls_extend ,3}, {"face","Draw face (quadrangle)","face x1 y1 x2 y2 x3 y3 x4 y4 ['fmt']|x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 ['fmt']", mgls_face ,13}, {"facenum","Set number of visible faces","facenum val", mgls_facenum ,2}, {"facex","Draw face perpendicular to x-axis","facex x0 y0 z0 wy wz ['fmt' d1 d2]", mgls_facex ,13}, {"facey","Draw face perpendicular to y-axis","facex x0 y0 z0 wx wz ['fmt' d1 d2]", mgls_facey ,13}, {"facez","Draw face perpendicular to z-axis","facex x0 y0 z0 wy wz ['fmt' d1 d2]", mgls_facez ,13}, {"fall","Draw waterfalls","fall Zdat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_fall ,8}, {"fgets","Print string from file","fgets x y z 'fname' [pos=0 'fmt' size]|x y z 'fname' [pos=0 'fmt' size]", mgls_fgets ,15}, {"fill","Fill data linearly in range [v1, v2]","fill Var v1 v2 ['dir'] | Var 'eq' [Vdat Wdat]", mgls_fill ,3}, {"fillsample","Fill x-,k-samples for transforms","fillsample Var 'how'", mgls_fillsample ,3}, {"fit","Fit data to formula","fit Res A 'eq' 'var' [Ini]|Res X A 'eq' 'var' [Ini]|Res X Y A 'eq' 'var' [Ini]|Res X Y Z A 'eq' 'var' [Ini]", mgls_fit ,4}, {"fits","Fit data to formula","fits Res A S 'eq' 'var' [Ini]|Res X A S 'eq' 'var' [Ini]|Res X Y A S 'eq' 'var' [Ini]|Res X Y Z A S 'eq' 'var' [Ini]", mgls_fits ,4}, {"flow","Draw flow threads for vector field","flow Udat Vdat ['fmt' num]|Xdat Ydat Udat Vdat ['fmt' num]|Udat Vdat Wdat ['fmt' num]|Xdat Ydat Zdat Udat Vdat ['fmt' num]|\ x0 y0 Udat Vdat ['fmt']|x0 y0 Xdat Ydat Udat Vdat ['fmt']|x0 y0 z0 Udat Vdat Wdat ['fmt']|x0 y0 z0 Xdat Ydat Zdat Udat Vdat Wdat ['fmt']", mgls_flow ,11}, {"fog","Switch on/off fog","fog val [pos]", mgls_fog ,2}, {"font","Setup font","font 'fmt' [size]", mgls_font ,15}, {"for","For cycle","for $N v1 v2 [dv] | $N Dat", 0, 6}, {"fourier","In-place Fourier transform","fourier ReDat ImDat 'dir'", mgls_fourier , 16}, {"fplot","Plot curve by formula","fplot 'y_x' ['fmt']|'x_t' 'y_t' 'z_t' ['fmt']", mgls_fplot ,1}, {"fsurf","Plot surface by formula","fsurf 'z_xy' ['fmt']|'x_uv' 'y_uv' 'z_uv' ['fmt']", mgls_fsurf ,1}, {"func","Start function definition and stop execution of main script","func 'name' [narg]", 0, 6}, {"grad","Draw gradient lines for scalar field","grad Phi ['fmt' num]|Xdat Ydat Phi ['fmt' num]|Xdat Ydat Zdat Phi ['fmt' num]", mgls_grad ,8}, {"grid","Draw grid","grid ['dir' 'fmt']", mgls_grid ,12}, {"grid2","Draw grid for data array(s)","grid Zdat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_grid2 ,8}, {"grid3","Draw grid at slices of 3D data","grid3 Adat 'dir' [pos 'fmt']|Xdat Ydat Zdat Adat 'dir' [pos 'fmt']", mgls_grid3 ,9}, {"gridplot","Set position of plot inside cell of matrix", "gridplot nx ny ind [d]", mgls_gridplot ,5}, {"gspline","Fill data by global spline of Vdat","gspline Dat Xdat Vdat [sl]", mgls_gspline ,3}, {"hankel","Hankel transform at some direction","hankel Dat 'dir'", mgls_hankel ,16}, {"hist","Create histogram (distribution) of data values","hist Res Dat num v1 v2 [nsub]|Res Dat Wdat num v1 v2 [nsub]", mgls_hist ,4}, {"idset","Set column id for data","idset Dat 'ids'", mgls_idset ,3}, {"if","Conditional operator","if val|Dat ['cond']", 0, 6}, {"import","Import data from PNG picture","import Dat 'fname' 'scheme' [v1 v2]", mgls_import ,4}, {"info","Print information about data","info Dat [detail]|'message'", mgls_info ,3}, {"inplot","Set position of plot in picture","x1 x2 y1 y2 [rel]", mgls_inplot ,5}, {"insert","Insert slice of data","insert Dat 'dir' [pos=0 num=1]", mgls_insert ,3}, {"integrate","Integrate data","integrate Dat 'dir'", mgls_integrate ,16}, {"jacobian","Get Jacobian","jacobian Res Xdat Ydat [Zdat]", mgls_jacobian ,4}, {"join","Join data arrays","join Dat Add", mgls_join ,3}, {"label","Draw label at arbitrary position","label Ydat 'txt' ['fmt'='']|Xdat Ydat 'txt' ['fmt'='']|Xdat Ydat Zdat 'txt' ['fmt'='']", mgls_label ,7}, {"legend","Draw legend","legend [pos 'fmt']|x y ['fmt']", mgls_legend ,15}, {"legendmarks","Set number of marks in the legend","legendmarks val", mgls_legendmarks ,15}, {"light","Setup light","light [val] | val num | num xpos ypos zpos ['fmt' br]", mgls_light ,2}, {"line","Draw line","line x1 y1 x2 y2 ['fmt']|x1 y1 z1 x2 y2 z2 ['fmt']", mgls_line ,13}, {"list","Creates new variable from list of numbers or data","list Var v1 ...|Var D1 ...", 0, 4}, {"load","Load commands from external DLL","load 'fname'", 0, 6}, {"loadfont","Load fontfaces","loadfont ['face']", mgls_loadfont ,15}, {"logo","Draw bitmap (logo) along axis range","logo 'fname' [smooth]", mgls_logo ,13}, {"map","Draw mapping plot","map Udat Vdat ['fmt']|Xdat Ydat Udat Vdat ['fmt']", mgls_map ,10}, {"mark","Draw mark plot for 1D data","mark Ydat Rdat ['fmt']|Xdat Ydat Rdat ['fmt']|Xdat Ydat Zdat Rdat ['fmt']", mgls_mark ,7}, {"marksize","Set size of markers","marksize val", mgls_marksize ,2}, {"mask","Set brush for given mask","mask 'id' 'val'|'id' val|angle", mgls_mask ,2}, {"max","Find maximal value over direction","max Res Dat 'dir'", mgls_max ,4}, {"mesh","Draw mesh surface","mesh Zdat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_mesh ,8}, {"meshnum","Set number of lines in mesh/fall/vect and so on","meshnum val", mgls_meshnum ,2}, {"min","Find minimal value over direction","min Res Dat 'dir'", mgls_min ,4}, {"mirror","Mirror data at some direction","mirror Dat 'dir'", mgls_mirror ,16}, {"modify","Modify data values by formula","modify Dat 'eq' [num] | Dat 'eq' Vdat [Wdat]", mgls_modify ,3}, {"momentum","Get momentum along direction","momentum Res Dat 'how' ['dir']", mgls_momentum ,4}, {"multiplot","Set position of plot","multiplot m n pos dx dy 'style'", mgls_multiplot ,5}, {"multo","Multiply by data or number","multo Var Dat|Var num", mgls_multo ,3}, {"new","Create new data","new Dat nx ny nz ['eq']|new Dat nx ny ['eq']|new Dat nx ['eq']", mgls_new ,4}, {"next","Start next for-cycle iteration","next", 0, 6}, {"norm","Normalize data","norm Dat v1 v2 [sym dim]", mgls_norm ,16}, {"normsl","Normalize data slice by slice","normsl Dat v1 v2 ['dir' keep sym] ", mgls_normsl ,16}, {"ode","Solve ODE","ode Res 'df' 'var' Ini [dt tmax]", mgls_ode ,4}, {"ohlc","Draw Open-High-Low-Close (OHLC) diagram","ohlc Odat Hdat Ldat Cdat ['fmt']|Xdat Odat Hdat Ldat Cdat ['fmt']", mgls_ohlc ,7}, {"once","Start/close commands which should executed only once","once val", 0, 6}, {"origin","Set axis origin","origin x0 y0 [z0]", mgls_origin ,14}, {"origintick","Set tick labels drawing at origin","origintick val", mgls_origintick ,14}, {"palette","Set palette for 1D plots","palette 'colors'", mgls_palette ,2}, {"pde","Solve PDE","pde Res 'ham' IniRe IniIm [dz k0]", mgls_pde ,4}, {"perspective","Set perspective","perspective val", mgls_perspective ,2}, {"pipe","Draw flow pipes for vector field","pipe Udat Vdat ['fmt' rad num]|Xdat Ydat Udat Vdat ['fmt' rad num]|Udat Vdat Wdat ['fmt' rad num]|Xdat Ydat Zdat Udat Vdat Wdat ['fmt' rad num]", mgls_pipe ,11}, {"plot","Draw usual plot for 1D data","plot Ydat ['fmt']|Xdat Ydat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_plot ,7}, {"plotid","Set default filename","plotid 'name'", mgls_plotid ,2}, {"polygon","Draw polygon","polygon x1 y1 x2 y2 num ['fmt']|x1 y1 z1 x2 y2 z2 num ['fmt']", mgls_polygon ,13}, {"put","Put value (numeric or array) to given data element","put Dat val [i j k] | Dat Val [i j k]", mgls_put ,3}, {"putsfit","Print fitted formula","putsfit x y ['pre' 'font' size]|x y z ['pre' 'font' size]", mgls_putsfit ,15}, {"qo2d","Solve PDE in accompanied coordinates for 2d case","qo2d Res 'ham' IniRe IniIm Ray [r k0 Xout Yout]", mgls_qo2d ,4}, {"qo3d","Solve PDE in accompanied coordinates for 3d case","qo3d Res 'ham' IniRe IniIm Ray [r k0 Xout Yout Zout]", mgls_qo3d ,4}, {"quadplot","Draw surface of quadrangles","quadplot Idat Xdat Ydat ['fmt']|Idat Xdat Ydat Zdat ['fmt']|Idat Xdat Ydat Zdat Cdat ['fmt'] ", mgls_quadplot ,0}, {"quality","Set plot quality","quality [val]", mgls_quality ,2}, {"radar","Draw radar chart","radar Rdat ['fmt']", mgls_radar ,7}, {"ranges","Set axis ranges","ranges x1 x2 y1 y2 [z1 z2]", mgls_ranges ,14}, {"rasterize","Rasterize and save to background","rasterize", mgls_rasterize ,12}, {"ray","Solve Hamiltonian ODE (find GO ray or trajectory)","ray Res 'ham' x0 y0 z0 px0 py0 pz0 [dz=0.1 tmax=10]", mgls_ray ,4}, {"read","Read data from file","read Dat 'file' [nx ny nz] | ReDat ImDat 'file' [nx ny nz]", mgls_read ,4}, {"readall","Read and join data from several files","readall Dat 'templ' [slice]", mgls_readall ,4}, {"readhdf","Read data from HDF5 file","readhdf Dat 'file' 'id'", mgls_readhdf ,4}, {"readmat","Read data from file with sizes specified in first row","readmat Dat 'file' [dim]", mgls_readmat ,4}, {"rearrange","Rearrange data dimensions","rearrange Dat mx [my mz]", mgls_rearrange ,3}, {"rect","Draw rectangle","rect x1 y1 x2 y2 ['fmt']|x1 y1 z1 x2 y2 z2 ['fmt']", mgls_rect ,13}, {"refill","Fill data by interpolation of Vdat","refill Dat Xdat Vdat [sl] | Dat Xdat Ydat Vdat [sl] | Dat Xdat Ydat Zdat Vdat", mgls_refill ,3}, {"region","Draw filled region (ribbon) between 2 curves","region Ydat1 Ydat2 ['fmt']|Xdat Ydat1 Ydat2 ['fmt']||Xdat1 Ydat1 Xdat2 Ydat2 ['fmt']|Xdat1 Ydat1 Zdat1 Xdat2 Ydat2 Zdat2 ['fmt']", mgls_region ,7}, {"reset","Reset settings and clear picture","reset", mgls_reset ,12}, {"resize","Resize data","resize Res Dat mx [my mz]", mgls_resize ,4}, {"return","Return from function","return", 0, 6}, {"rhomb","Draw rhombus","rhomb x1 y1 x2 y2 r ['fmt']|x1 y1 z1 x2 y2 z2 r ['fmt']", mgls_rhomb ,13}, {"roll","Roll data along direction","roll Dat 'dir' num", mgls_roll ,16}, {"roots", "Find roots using data as initial values", "roots Res 'func' Ini ['var']|Res 'func' ini ['var']", mgls_roots ,4}, {"rotate","Rotate plot","rotate tetz tetx [tety] | tet x y z", mgls_rotate ,5}, {"rotatetext","Set to auto rotate text or not","rotatetext val", mgls_rotatetext ,15}, {"save","Save data to file","save Dat 'file'", mgls_save ,3}, {"savehdf","Save data to HDF5 file","savehdf Dat 'file' 'id'", mgls_savehdf ,3}, {"setsize","Set picture size","setsize width height", mgls_setsize ,2}, {"sew","Remove jump into the data, like phase jumps","sew Dat ['dir' da]", mgls_sew ,16}, {"sinfft","Sin-Fourier transform at some direction","sinfft Dat 'dir'", mgls_sinfft ,16}, {"smooth","Smooth data","smooth Dat [kind 'dir']", mgls_smooth ,16}, {"solve","Find root Dat_{i,j,k}=val (inverse evaluate)","solve Res Dat val 'dir' [Idat norm]", mgls_solve ,4}, {"sort","Sort data by values in column","sort Dat idx [idy]", mgls_sort ,3}, {"sphere","Draw sphere","sphere x0 y0 r ['fmt']|x0 y0 z0 r ['fmt']", mgls_sphere ,13}, {"squeeze","Squeeze data","squeeze Dat kx [ky kz]", mgls_squeeze ,3}, {"stem","Draw stem plot for 1D data","stem Ydat ['fmt']|Xdat Ydat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_stem ,7}, {"step","Draw step plot for 1D data","step Ydat ['fmt']|Xdat Ydat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_step ,7}, {"stfa","Draw STFA diagram","stfa Udat Vdat dn ['fmt']|Xdat Ydat Udat Vdat dn ['fmt']", mgls_stfa ,10}, {"stfad","Do STFA transform","stfad Res Real Imag dn ['dir']", mgls_stfad ,4}, {"stickplot","Set position of plot inside cell of stick", "stickplot num ind tet phi", mgls_stickplot ,5}, {"stop","Stop execution","stop", 0, 6}, {"subdata","Extract sub-array","subdata Res Dat nx [ny nz]", mgls_subdata ,4}, {"subplot","Set position of plot","subplot m n pos ['style' dx dy]", mgls_subplot ,5}, {"subto","Subtract data or number","subto Var Dat|Var num", mgls_subto ,3}, {"sum","Find summation over direction","sum Res Dat 'dir'", mgls_sum ,4}, {"surf","Draw solid surface","surf Zdat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_surf ,8}, {"surf3","Draw isosurface for 3D data","surf3 Adat ['fmt' num]|Xdat Ydat Zdat Adat ['fmt' num]|Adat val ['fmt']|Xdat Ydat Zdat Adat val ['fmt']", mgls_surf3 ,9}, {"surf3a","Draw isosurface for 3D data transpared by other data","surf3a Adat Cdat ['fmt' num]|Xdat Ydat Zdat Adat Cdat ['fmt' num]|Adat Cdat val ['fmt']|Xdat Ydat Zdat Adat Cdat val ['fmt']", mgls_surf3a ,10}, {"surf3c","Draw isosurface for 3D data colored by other data","surf3c Adat Cdat ['fmt' num]|Xdat Ydat Zdat Adat Cdat ['fmt' num]|Adat Cdat val ['fmt']|Xdat Ydat Zdat Adat Cdat val ['fmt']", mgls_surf3c ,10}, {"surfa","Draw solid surface transpared by other data","surfa Zdat Cdat ['fmt']|Xdat Ydat Zdat Cdat ['fmt']", mgls_surfa ,10}, {"surfc","Draw solid surface colored by other data","surfc Zdat Cdat ['fmt']|Xdat Ydat Zdat Cdat ['fmt']", mgls_surfc ,10}, {"swap","Swap data (usefull after Fourier transform)","swap Dat 'dir'", mgls_swap ,16}, {"table","Draw table with data values","table Dat ['txt' 'fmt']|x y Dat ['txt' 'fmt']", mgls_table ,7}, {"tape","Draw binormales for 1D data","tape Ydat ['fmt']|Xdat Ydat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_tape ,7}, {"tens","Draw tension plot for 1D data","tens Ydat Cdat ['fmt']|Xdat Ydat Cdat ['fmt']|Xdat Ydat Zdat Cdat ['fmt']", mgls_tens ,7}, {"ternary","Switch on/off to use ternary axis","ternary val", mgls_ternary ,14}, {"text","Draw text at some position or along curve","text x y 'txt' ['fmt' size]|x y z 'txt' ['fmt' size]|x y dx dy 'txt' ['fmt' size]|x y z dx dy dz 'txt' ['fmt' size]|Ydat 'txt' ['font' sise]|Xdat Ydat 'txt' ['font' sise]", mgls_text ,15}, {"textmark","Draw TeX mark at point position","textmark Ydat Rdat 'text' ['fmt']|Xdat Ydat Rdat 'text' ['fmt']|Xdat Ydat Zdat Rdat 'text' ['fmt']", mgls_textmark ,7}, {"ticklen","Set tick length","ticklen val [stt]", mgls_ticklen ,14}, {"tickshift","Set additional tick and axis labels shift","tickshift dx [dy dz dc]", mgls_tickshift ,14}, {"ticktime","Set ticks in time format","ticktime 'dir' [dv 'tmpl']", mgls_ticktime ,14}, {"tile","Draw horizontal tiles","tile Zdat ['fmt']|Xdat Ydat Zdat ['fmt']", mgls_tile ,8}, {"tiles","Draw horizontal tiles with variable size","tiles Zdat Rdat ['fmt']|Xdat Ydat Zdat Rdat ['fmt']", mgls_tiles ,10}, {"title","Add title for current subplot/inplot","title 'txt' ['fmt' size]", mgls_title ,5}, {"tlabel","Draw label for t-axis","tlabel 'txt' [pos]", mgls_tlabel ,12}, {"torus","Draw surface of curve rotation","torus Rdat ['fmt']|Zdat Rdat ['fmt']", mgls_torus ,7}, {"trace","Get trace of array","trace Res Dat", mgls_trace ,4}, {"traj","Draw vectors along a curve","traj Xdat Ydat Udat Vdat ['fmt' len]|Xdat Ydat Zdat Udat Vdat Wdat ['fmt' len]", mgls_traj ,11}, {"transform","Do integral transform of data","transform Res 'how' Rdat Idat", mgls_transform ,4}, {"transforma","Do integral transform of data","transforma Res 'how' Adat Pdat", mgls_transforma ,4}, {"transpose","Transpose data array","transpose Dat ['dir']", mgls_transpose ,16}, {"transptype","Set type transparency","transptype val", mgls_transptype ,2}, {"triangulate","Find triangles of randomly placed points","triangulate Res Xdat Ydat [er]|Res Xdat Ydat Zdat [er]", mgls_triangulate ,4}, {"tricont","Draw contour lines for surface of triangles","tricont Idat Xdat Ydat Cdat ['fmt']|Idat Xdat Ydat Zdat Cdat ['fmt']|Vdat Idat Xdat Ydat Cdat ['fmt']|Vdat Idat Xdat Ydat Zdat Cdat ['fmt']", mgls_tricont ,0}, {"tricontv","Draw contour tubes for surface of triangles","tricontv Idat Xdat Ydat Cdat ['fmt']|Idat Xdat Ydat Zdat Cdat ['fmt']|Vdat Idat Xdat Ydat Cdat ['fmt']|Vdat Idat Xdat Ydat Zdat Cdat ['fmt']", mgls_tricontv ,0}, {"triplot","Draw surface of triangles","triplot Idat Xdat Ydat ['fmt']|Idat Xdat Ydat Zdat ['fmt']|Idat Xdat Ydat Zdat Cdat ['fmt'] ", mgls_triplot ,0}, {"tube","Draw curve by tube","tube Ydat Rdat ['fmt']|Ydat rval ['fmt']|Xdat Ydat Rdat ['fmt']|Xdat Ydat rval ['fmt']|Xdat Ydat Zdat Rdat ['fmt']|Xdat Ydat Zdat rval ['fmt']", mgls_tube ,7}, {"tuneticks","Set ticks tuning","tuneticks val [fctr]", mgls_tuneticks ,14}, {"var","Create new 1D data and fill it in range","var Dat nx x1 [x2]", mgls_var ,4}, {"vect","Draw vector field","vect Udat Vdat ['fmt']|Xdat Ydat Udat Vdat ['fmt']|Udat Vdat Wdat ['fmt']|Xdat Ydat Zdat Udat Vdat Wdat ['fmt']", mgls_vect ,11}, {"vect3","Draw vector field at slices of 3D data","vect Udat Vdat Wdat ['fmt' sval]|Xdat Ydat Zdat Udat Vdat Wdat ['fmt' sval]", mgls_vect3 ,11}, {"version","Print MathGL version or check if it is valid","version |'ver'", mgls_version, 2}, {"view","Change view angles - use 'rotate' for plot rotation","view tetz tetx [tety]", mgls_view ,5}, {"write","Write current image to graphical file","write ['fname']", mgls_write ,2}, {"xlabel","Draw label for x-axis","xlabel 'txt' [pos]", mgls_xlabel ,12}, {"xrange","Set range for x-axis","xrange Dat [add] | x1 x2 [add]", mgls_xrange ,14}, {"xtick","Set ticks for x-axis","xtick dx ['factor'] | dx sx ['factor'] | dx sx tx ['factor'] | 'tmpl' | Xdat 'lbl' [add] | v1 'lbl1' ...", mgls_xtick,14}, {"ylabel","Draw label for y-axis","ylabel 'txt' [pos]", mgls_ylabel,12}, {"yrange","Set range for y-axis","yrange Dat [add] | y1 y2 [add]", mgls_yrange,14}, {"ytick","Set ticks for y-axis","ytick dy ['factor'] | dy sy ['factor'] | dy sy ty ['factor'] | 'tmpl' | Ydat 'lbl' [add] | v1 'lbl1' ...", mgls_ytick,14}, {"zlabel","Draw label for z-axis","zlabel 'txt' [pos]", mgls_zlabel,12}, {"zoom","Zoom plot region","zoom x1 x2 y1 y2", mgls_zoom,5}, {"zoomaxis","Zoom axis range","zoomaxis x1 x2|x1 x2 y1 y2|x1 x2 y1 y2 z1 z2|x1 x2 y1 y2 z1 z2 c1 c2", mgls_zoomaxis,14}, {"zrange","Set range for z-axis","yrange Dat [add] | z1 z2 [add]", mgls_zrange ,14}, {"ztick","Set ticks for z-axis","ztick dz ['factor'] | dz sz ['factor'] | dz sz tz ['factor'] | 'tmpl' | Zdat 'lbl' [add] | v1 'lbl1' ...", mgls_ztick,14}, {"","","",NULL,0}}; //-----------------------------------------------------------------------------
52.611635
242
0.512627
jerrykrinock
e91fbc48d2a68920ebd83b559ee67b3851383bb9
8,486
cc
C++
gui/components/gui_scrollpane.cc
128na/simutrans
2518159a78100024e61b95b28510b2748e3f63d5
[ "Artistic-1.0" ]
null
null
null
gui/components/gui_scrollpane.cc
128na/simutrans
2518159a78100024e61b95b28510b2748e3f63d5
[ "Artistic-1.0" ]
null
null
null
gui/components/gui_scrollpane.cc
128na/simutrans
2518159a78100024e61b95b28510b2748e3f63d5
[ "Artistic-1.0" ]
null
null
null
/* * This file is part of the Simutrans project under the Artistic License. * (see LICENSE.txt) */ #include "../../simdebug.h" #include "../gui_frame.h" #include "gui_scrollpane.h" #include "gui_scrollbar.h" #include "gui_button.h" #include "../../dataobj/loadsave.h" #include "../../display/simgraph.h" #include "../../simcolor.h" /** * @param comp the scrolling component */ gui_scrollpane_t::gui_scrollpane_t(gui_component_t *comp, bool b_scroll_x, bool b_scroll_y) : scroll_x(scrollbar_t::horizontal), scroll_y(scrollbar_t::vertical) { this->comp = comp; max_width = D_DEFAULT_WIDTH-D_MARGIN_LEFT-D_MARGIN_RIGHT; b_show_scroll_x = b_scroll_x; b_show_scroll_y = b_scroll_y; b_has_size_corner = true; old_comp_size = scr_size::invalid; take_cached_size = false; maximize = false; } scr_size gui_scrollpane_t::get_min_size() const { // request width of largest element, but leave enough space for scrollbars scr_size csize = take_cached_size ? cached_min_size : comp->get_min_size(); csize.w = max( csize.w, scroll_x.get_min_size().w ); csize.w = min( csize.w, max_width ); csize.h = min( csize.h, scroll_y.get_min_size().h ); return csize; } scr_size gui_scrollpane_t::get_max_size() const { scr_size csize = take_cached_size ? cached_max_size : comp->get_max_size(); return csize; } /** * recalc the scroll bar sizes */ void gui_scrollpane_t::recalc_sliders(scr_size size) { scroll_x.set_pos( scr_coord(0, size.h-D_SCROLLBAR_HEIGHT) ); scroll_y.set_pos( scr_coord(size.w-D_SCROLLBAR_WIDTH, 0) ); if( b_show_scroll_y && scroll_y.is_visible() ) { scroll_x.set_size( size-D_SCROLLBAR_SIZE ); scroll_x.set_knob( size.w-D_SCROLLBAR_WIDTH, comp->get_size().w + comp->get_pos().x ); } else if( b_has_size_corner ) { scroll_x.set_size( size-D_SCROLLBAR_SIZE ); scroll_x.set_knob( size.w, comp->get_size().w + comp->get_pos().x ); } else { scroll_x.set_size( size-D_SCROLLBAR_SIZE ); scroll_x.set_knob( size.w, comp->get_size().w + comp->get_pos().x ); } if( b_show_scroll_x && scroll_x.is_visible() ) { scroll_y.set_size( size-D_SCROLLBAR_SIZE ); scroll_y.set_knob( size.h-D_SCROLLBAR_HEIGHT, comp->get_size().h + comp->get_pos().y ); } else if( b_has_size_corner ) { scroll_y.set_size( size-D_SCROLLBAR_SIZE ); scroll_y.set_knob( size.h, comp->get_size().h + comp->get_pos().y ); } else { scroll_y.set_size( size-scr_coord(D_SCROLLBAR_WIDTH,0) ); scroll_y.set_knob( size.h, comp->get_size().h + comp->get_pos().y ); } old_comp_size = comp->get_size(); } /** * Scrollpanes _must_ be used in this method to set the size */ void gui_scrollpane_t::set_size(scr_size size) { gui_component_t::set_size(size); // automatically increase/decrease slider area scr_coord k = comp->get_size()+comp->get_pos(); scroll_x.set_visible( (k.x > size.w) && b_show_scroll_x ); scroll_y.set_visible( (k.y > size.h) && b_show_scroll_y ); scr_size c_size = size - comp->get_pos(); // resize scrolled component if (scroll_x.is_visible()) { c_size.h -= scroll_x.get_size().h; } if (scroll_y.is_visible()) { c_size.w -= scroll_y.get_size().w; } cached_min_size = comp->get_min_size(); cached_max_size = comp->get_max_size(); take_cached_size = false; // disabled, there is no proper way to check whether cache is still valid c_size.clip_lefttop( cached_min_size ); c_size.clip_rightbottom( cached_max_size ); comp->set_size(c_size); recalc_sliders(size); show_focused(); } scr_size gui_scrollpane_t::request_size(scr_size request) { // do not enlarge past max size of comp scr_size cmax = take_cached_size ? cached_max_size : comp->get_max_size(); if (cmax.w < request.w - comp->get_pos().x && cmax.h < request.h - comp->get_pos().y) { request = cmax; } set_size(request); return get_size(); } /** * Events werden hiermit an die GUI-components gemeldet */ bool gui_scrollpane_t::infowin_event(const event_t *ev) { bool swallow = false; if( (b_show_scroll_y && scroll_y.is_visible()) && ev->ev_class!=EVENT_KEYBOARD && (scroll_y.getroffen(ev->mx, ev->my) || scroll_y.getroffen(ev->cx, ev->cy)) ) { event_t ev2 = *ev; ev2.move_origin(scroll_y.get_pos()); return scroll_y.infowin_event(&ev2); } else if( (b_show_scroll_x && scroll_x.is_visible()) && ev->ev_class!=EVENT_KEYBOARD && (scroll_x.getroffen(ev->mx, ev->my) || scroll_x.getroffen(ev->cx, ev->cy))) { event_t ev2 = *ev; ev2.move_origin(scroll_x.get_pos()); return scroll_x.infowin_event(&ev2); } else if( ev->ev_class<EVENT_CLICK || (ev->mx>=0 && ev->my>=0 && ev->mx<=size.w && ev->my<=size.h) ) { // since we get can grab the focus to get keyboard events, we must make sure to handle mouse events only if we are hit // translate according to scrolled position event_t ev2 = *ev; const scr_coord offset(scroll_x.get_knob_offset(), scroll_y.get_knob_offset()); ev2.move_origin(comp->get_pos() - offset); gui_component_t *focused = get_focus(); // hand event to component swallow = comp->infowin_event(&ev2); // check if we need to scroll to the focused component if( get_focus() && focused != get_focus() ) { show_focused(); } // hack: component could have changed size // this recalculates the scrollbars if( old_comp_size!=comp->get_size() ) { recalc_sliders(get_size()); } } // now process wheel-events that are not swallowed by component, scroll the pane if (!swallow) { if((IS_WHEELUP(ev) || IS_WHEELDOWN(ev)) && (((b_show_scroll_y && scroll_y.is_visible()) && !IS_SHIFT_PRESSED(ev)) || ((b_show_scroll_x && scroll_x.is_visible()) && IS_SHIFT_PRESSED(ev)))) { // otherwise these events are only registered where directly over the scroll region // (and sometime even not then ... ) return IS_SHIFT_PRESSED(ev) ? scroll_x.infowin_event(ev) : scroll_y.infowin_event(ev); } } return swallow; } void gui_scrollpane_t::show_focused() { const gui_component_t *const focused_comp = comp->get_focus(); if( focused_comp ) { const scr_size comp_size = focused_comp->get_size(); const scr_coord relative_pos = comp->get_focus_pos(); if( b_show_scroll_x ) { const sint32 knob_offset_x = scroll_x.get_knob_offset(); const sint32 view_width = size.w-D_SCROLLBAR_WIDTH; if( relative_pos.x+comp_size.w<knob_offset_x ) { scroll_x.set_knob_offset(relative_pos.x); } if( relative_pos.x>knob_offset_x+view_width ) { scroll_x.set_knob_offset(relative_pos.x+comp_size.w-view_width); } } if( b_show_scroll_y ) { const sint32 knob_offset_y = scroll_y.get_knob_offset(); const sint32 view_height = (b_has_size_corner || b_show_scroll_x) ? size.h-D_SCROLLBAR_HEIGHT : size.h; if( relative_pos.y+comp_size.h<knob_offset_y ) { scroll_y.set_knob_offset(relative_pos.y); } if( relative_pos.y>knob_offset_y+view_height ) { scroll_y.set_knob_offset(relative_pos.y+comp_size.h-view_height); } } } } /** * Set the position of the Scrollbars */ void gui_scrollpane_t::set_scroll_position(int x, int y) { scroll_x.set_knob_offset(x); scroll_y.set_knob_offset(y); } int gui_scrollpane_t::get_scroll_x() const { return scroll_x.get_knob_offset(); } int gui_scrollpane_t::get_scroll_y() const { return scroll_y.get_knob_offset(); } scr_rect gui_scrollpane_t::get_client( void ) { scr_rect client( pos, pos+size ); if( b_show_scroll_x && scroll_x.is_visible() ) { client.h -= D_SCROLLBAR_HEIGHT; } if( b_show_scroll_y && scroll_y.is_visible() ) { client.w -= D_SCROLLBAR_WIDTH; } return client; } /** * Draw the component */ void gui_scrollpane_t::draw(scr_coord pos) { // check, if we need to recalc slider size if( old_comp_size != comp->get_size() ) { recalc_sliders( size ); } // get client area (scroll panel - scrollbars) scr_rect client = get_client() + pos; PUSH_CLIP_FIT( client.x, client.y, client.w, client.h ) comp->draw( client.get_pos()-scr_coord(scroll_x.get_knob_offset(), scroll_y.get_knob_offset()) ); POP_CLIP() // sliding bar background color is now handled by the scrollbar! if( b_show_scroll_x && scroll_x.is_visible() ) { scroll_x.draw( pos+get_pos() ); } if( b_show_scroll_y && scroll_y.is_visible() ) { scroll_y.draw( pos+get_pos() ); } } void gui_scrollpane_t::rdwr( loadsave_t *file ) { sint32 x = get_scroll_x(); sint32 y = get_scroll_y(); file->rdwr_long(x); file->rdwr_long(y); if (file->is_loading()) { set_scroll_position(x, y); } }
29.061644
172
0.702922
128na
11e6601169612607f67a029459f086e4cb0d56df
2,657
cpp
C++
plugins/blockvault_client_plugin/blockvault_client_plugin.cpp
forfreeday/eos
11d35f0f934402321853119d36caeb7022813743
[ "Apache-2.0", "MIT" ]
13,162
2017-05-29T22:08:27.000Z
2022-03-29T19:25:05.000Z
plugins/blockvault_client_plugin/blockvault_client_plugin.cpp
forfreeday/eos
11d35f0f934402321853119d36caeb7022813743
[ "Apache-2.0", "MIT" ]
6,450
2017-05-30T14:41:50.000Z
2022-03-30T11:30:04.000Z
plugins/blockvault_client_plugin/blockvault_client_plugin.cpp
forfreeday/eos
11d35f0f934402321853119d36caeb7022813743
[ "Apache-2.0", "MIT" ]
4,491
2017-05-29T22:08:32.000Z
2022-03-29T07:09:52.000Z
#include "block_vault_impl.hpp" #include "zlib_compressor.hpp" #include <boost/algorithm/string/predicate.hpp> #include <eosio/blockvault_client_plugin/blockvault_client_plugin.hpp> // eosio::blockvault_client_plugin #include <fc/log/log_message.hpp> // FC_LOG_MESSAGE #include <vector> // std::vector #if HAS_PQXX #include "postgres_backend.hpp" #endif namespace eosio { static appbase::abstract_plugin& _blockvault_client_plugin = app().register_plugin<blockvault_client_plugin>(); using vault_impl = eosio::blockvault::block_vault_impl<eosio::blockvault::zlib_compressor>; class blockvault_client_plugin_impl : public vault_impl { public: blockvault_client_plugin_impl(std::unique_ptr<blockvault::backend>&& be) : vault_impl(std::move(be)) {} }; blockvault_client_plugin::blockvault_client_plugin() {} blockvault_client_plugin::~blockvault_client_plugin() {} void blockvault_client_plugin::set_program_options(options_description&, options_description& cfg) { #ifdef HAS_PQXX cfg.add_options()("block-vault-backend", bpo::value<std::string>(), "the uri for block vault backend. Currently, only PostgreSQL is supported, the format is " "'postgresql://username:password@localhost/company'"); #endif } void blockvault_client_plugin::plugin_initialize(const variables_map& options) { ilog("initializing blockvault_client plugin"); #ifdef HAS_PQXX try { if (options.count("block-vault-backend")) { std::string uri = options["block-vault-backend"].as<std::string>(); if (boost::starts_with(uri, "postgresql://") || boost::starts_with(uri, "postgres://")) { my.reset(new blockvault_client_plugin_impl(std::make_unique<blockvault::postgres_backend>(uri))); ilog("blockvault_client plugin started"); } else if (uri.size()) { elog("unknown block-vault-backend option, skipping it"); } } } FC_RETHROW_EXCEPTIONS ( error, "blockvault_client plugin initialization error, please double check if the specified `--block-vault-backend` value is correct") #endif } void blockvault_client_plugin::plugin_startup() { handle_sighup(); // setup logging if (my.get()) my->start(); } void blockvault_client_plugin::plugin_shutdown() { if (my.get()) my->stop(); } eosio::blockvault::block_vault_interface* blockvault_client_plugin::get() { return my.get(); } void blockvault_client_plugin::handle_sighup() { if (my.get()) my->set_logger_name("blockvault_client_plugin"); } } // namespace eosio
37.422535
161
0.697027
forfreeday
11e7002077089b9cba4b2df7e80595ad0642cb5c
560
cpp
C++
renderer/core/src/core/ogl/uniforms/OpenGLDoubleUniformVariable.cpp
wookie41/blitz
7f587bee9b6189c32f0f60c69316bc8deca23c16
[ "MIT" ]
1
2020-01-04T21:04:52.000Z
2020-01-04T21:04:52.000Z
renderer/core/src/core/ogl/uniforms/OpenGLDoubleUniformVariable.cpp
wookie41/blitz
7f587bee9b6189c32f0f60c69316bc8deca23c16
[ "MIT" ]
15
2019-08-26T20:54:31.000Z
2020-03-15T14:11:44.000Z
renderer/core/src/core/ogl/uniforms/OpenGLDoubleUniformVariable.cpp
wookie41/blitz
7f587bee9b6189c32f0f60c69316bc8deca23c16
[ "MIT" ]
null
null
null
#include <core/ogl/uniforms/OpenGLDoubleUniformVariable.h> namespace blitz::ogl { void OpenGLDoubleUniformVariable::bind() { glUniform1d(variableLocation, value); dirty = false; } DataType OpenGLDoubleUniformVariable::getType() const { return DataType::INT; } OpenGLDoubleUniformVariable::OpenGLDoubleUniformVariable(const GLint& variableLocation, const GLdouble& value, const blitz::string& name) : UniformVariable<GLdouble>(value, name), OpenGLUniformVariable(variableLocation) { } } // namespace blitz::ogl
32.941176
141
0.735714
wookie41
11e913ba2260647c8c982a20f90ca796da76069c
632
cpp
C++
C_C++_Projects/1_C++_Codes/parkpaths/parkpaths.cpp
sunjerry019/RandomCodes
4402604aaeee63bb1ce6fa962c496b438bb17e50
[ "MIT" ]
null
null
null
C_C++_Projects/1_C++_Codes/parkpaths/parkpaths.cpp
sunjerry019/RandomCodes
4402604aaeee63bb1ce6fa962c496b438bb17e50
[ "MIT" ]
null
null
null
C_C++_Projects/1_C++_Codes/parkpaths/parkpaths.cpp
sunjerry019/RandomCodes
4402604aaeee63bb1ce6fa962c496b438bb17e50
[ "MIT" ]
null
null
null
#include "parkpaths.h" #include <bits/stdc++.h> using namespace std; int cost = 0; map<char, int> letters; int pairs = 0; int pairarr[26][26] = {0}; int parkpaths(string s) { int length = s.length(); for(int i=0; i<length; i++) { if(letters[s[i]]) letters[s[i]] += 1; else letters[s[i]] = 1; if(i) { int a = min(s[i],s[i-1]) - 'A'; int b = max(s[i],s[i-1]) - 'A'; if(!pairarr[a][b]) { pairs++; pairarr[a][b] = 1; } } } cost += pairs; cost += letters.size()*2; return cost; }
19.151515
45
0.435127
sunjerry019
11ec85cee486384f4f9923177c9cfb5e3b403249
9,979
cpp
C++
src/Compact10Filter.cpp
emathew1/MPI_3DCompact
1945eabdc240e8754c9ea356ba954683dee0149f
[ "MIT" ]
2
2021-01-14T21:13:53.000Z
2022-01-16T23:03:43.000Z
src/Compact10Filter.cpp
emathew1/MPI_3DCompact
1945eabdc240e8754c9ea356ba954683dee0149f
[ "MIT" ]
null
null
null
src/Compact10Filter.cpp
emathew1/MPI_3DCompact
1945eabdc240e8754c9ea356ba954683dee0149f
[ "MIT" ]
3
2018-11-17T21:24:57.000Z
2020-08-02T03:19:42.000Z
#include "Compact10Filter.hpp" using namespace std; void Compact10Filter::multRHSPeriodicFilter(double *phi, double *RHSvec){ double cc0 = a0_10; double cc1 = a1_10/2.0; double cc2 = a2_10/2.0; double cc3 = a3_10/2.0; double cc4 = a4_10/2.0; double cc5 = a5_10/2.0; for(int ip = 0; ip < N; ip++){ if(ip == 0){ RHSvec[ip] = cc5*phi[N-5] + cc4*phi[N-4] + cc3*phi[N-3] + cc2*phi[N-2] + cc1*phi[N-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[ip+4] + cc5*phi[ip+5]; }else if(ip == 1){ RHSvec[ip] = cc5*phi[N-4] + cc4*phi[N-3] + cc3*phi[N-2] + cc2*phi[N-1] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[ip+4] + cc5*phi[ip+5]; }else if(ip == 2){ RHSvec[ip] = cc5*phi[N-3] + cc4*phi[N-2] + cc3*phi[N-1] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[ip+4] + cc5*phi[ip+5]; }else if(ip == 3){ RHSvec[ip] = cc5*phi[N-2] + cc4*phi[N-1] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[ip+4] + cc5*phi[ip+5]; }else if(ip == 4){ RHSvec[ip] = cc5*phi[N-1] + cc4*phi[ip-4] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[ip+4] + cc5*phi[ip+5]; }else if(ip == N-5){ RHSvec[ip] = cc5*phi[ip-5] + cc4*phi[ip-4] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[ip+4] + cc5*phi[0]; }else if(ip == N-4){ RHSvec[ip] = cc5*phi[ip-5] + cc4*phi[ip-4] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[0] + cc5*phi[1]; }else if(ip == N-3){ RHSvec[ip] = cc5*phi[ip-5] + cc4*phi[ip-4] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[0] + cc4*phi[1] + cc5*phi[2]; }else if(ip == N-2){ RHSvec[ip] = cc5*phi[ip-5] + cc4*phi[ip-4] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[0] + cc3*phi[1] + cc4*phi[2] + cc5*phi[3]; }else if(ip == N-1){ RHSvec[ip] = cc5*phi[ip-5] + cc4*phi[ip-4] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[0] + cc2*phi[1] + cc3*phi[2] + cc4*phi[3] + cc5*phi[4]; }else{ RHSvec[ip] = cc5*phi[ip-5] + cc4*phi[ip-4] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[ip+4] + cc5*phi[ip+5]; } } } void Compact10Filter::multRHSDirichletFilter(double *phi, double *RHSvec){ double cc0 = a0_10; double cc1 = a1_10/2.0; double cc2 = a2_10/2.0; double cc3 = a3_10/2.0; double cc4 = a4_10/2.0; double cc5 = a5_10/2.0; // RHSvec[0] = a00*phi[0] + a01*phi[1] + a02*phi[2] + a03*phi[3] + a04*phi[4]; // RHSvec[1] = b00*phi[0] + b01*phi[1] + b02*phi[2] + b03*phi[3] + b04*phi[4]; // RHSvec[2] = c00*phi[0] + c01*phi[1] + c02*phi[2] + c03*phi[3] + c04*phi[4]; RHSvec[0] = phi[0]; // RHSvec[0] = FB1_a*phi[0] + FB1_b*phi[1] + FB1_c*phi[2] + FB1_d*phi[3] + FB1_e*phi[4] + // FB1_f*phi[5] + FB1_g*phi[6] + FB1_h*phi[7] + FB1_i*phi[8] + FB1_j*phi[9] + // FB1_k*phi[10]; RHSvec[1] = FB2_a*phi[0] + FB2_b*phi[1] + FB2_c*phi[2] + FB2_d*phi[3] + FB2_e*phi[4] + FB2_f*phi[5] + FB2_g*phi[6] + FB2_h*phi[7] + FB2_i*phi[8] + FB2_j*phi[9] + FB2_k*phi[10]; RHSvec[2] = FB3_a*phi[0] + FB3_b*phi[1] + FB3_c*phi[2] + FB3_d*phi[3] + FB3_e*phi[4] + FB3_f*phi[5] + FB3_g*phi[6] + FB3_h*phi[7] + FB3_i*phi[8] + FB3_j*phi[9] + FB3_k*phi[10]; RHSvec[3] = FB4_a*phi[0] + FB4_b*phi[1] + FB4_c*phi[2] + FB4_d*phi[3] + FB4_e*phi[4] + FB4_f*phi[5] + FB4_g*phi[6] + FB4_h*phi[7] + FB4_i*phi[8] + FB4_j*phi[9] + FB4_k*phi[10]; RHSvec[4] = FB5_a*phi[0] + FB5_b*phi[1] + FB5_c*phi[2] + FB5_d*phi[3] + FB5_e*phi[4] + FB5_f*phi[5] + FB5_g*phi[6] + FB5_h*phi[7] + FB5_i*phi[8] + FB5_j*phi[9] + FB5_k*phi[10]; RHSvec[N-1] = phi[N-1]; // RHSvec[N-1] = a00*phi[N-1] + a01*phi[N-2] + a02*phi[N-3] + a03*phi[N-4] + a04*phi[N-5]; // RHSvec[N-2] = b00*phi[N-1] + b01*phi[N-2] + b02*phi[N-3] + b03*phi[N-4] + b04*phi[N-5]; // RHSvec[N-3] = c00*phi[N-1] + c01*phi[N-2] + c02*phi[N-3] + c03*phi[N-4] + c04*phi[N-5]; // RHSvec[N-1] = FB1_a*phi[N-1] + FB1_b*phi[N-2] + FB1_c*phi[N-3] + FB1_d*phi[N-4] + FB1_e*phi[N-5] + // FB1_f*phi[N-6] + FB1_g*phi[N-7] + FB1_h*phi[N-8] + FB1_i*phi[N-9] + FB1_j*phi[N-10]+ // FB1_k*phi[N-11]; RHSvec[N-2] = FB2_a*phi[N-1] + FB2_b*phi[N-2] + FB2_c*phi[N-3] + FB2_d*phi[N-4] + FB2_e*phi[N-5] + FB2_f*phi[N-6] + FB2_g*phi[N-7] + FB2_h*phi[N-8] + FB2_i*phi[N-9] + FB2_j*phi[N-10]+ FB2_k*phi[N-11]; RHSvec[N-3] = FB3_a*phi[N-1] + FB3_b*phi[N-2] + FB3_c*phi[N-3] + FB3_d*phi[N-4] + FB3_e*phi[N-5] + FB3_f*phi[N-6] + FB3_g*phi[N-7] + FB3_h*phi[N-8] + FB3_i*phi[N-9] + FB3_j*phi[N-10]+ FB3_k*phi[N-11]; RHSvec[N-4] = FB4_a*phi[N-1] + FB4_b*phi[N-2] + FB4_c*phi[N-3] + FB4_d*phi[N-4] + FB4_e*phi[N-5] + FB4_f*phi[N-6] + FB4_g*phi[N-7] + FB4_h*phi[N-8] + FB4_i*phi[N-9] + FB4_j*phi[N-10]+ FB4_k*phi[N-11]; RHSvec[N-5] = FB5_a*phi[N-1] + FB5_b*phi[N-2] + FB5_c*phi[N-3] + FB5_d*phi[N-4] + FB5_e*phi[N-5] + FB5_f*phi[N-6] + FB5_g*phi[N-7] + FB5_h*phi[N-8] + FB5_i*phi[N-9] + FB5_j*phi[N-10]+ FB5_k*phi[N-11]; for(int ip = 5; ip < N-5; ip++){ RHSvec[ip] = cc5*phi[ip-5] + cc4*phi[ip-4] + cc3*phi[ip-3] + cc2*phi[ip-2] + cc1*phi[ip-1] + cc0*phi[ip] + cc1*phi[ip+1] + cc2*phi[ip+2] + cc3*phi[ip+3] + cc4*phi[ip+4] + cc5*phi[ip+5]; } } void Compact10Filter::FilterPeriodic(double *phi, double *phiF){ double RHSvec[N]; multRHSPeriodicFilter(phi, RHSvec); cyclic(offlowerF, diagF, offupperF, alphaF, alphaF, RHSvec, N, phiF); } void Compact10Filter::FilterDirichlet(double *phi, double *phiF){ double RHSvec[N]; double *work = new double[N]; multRHSDirichletFilter(phi, RHSvec); solveTri(offlowerF, diagF, offupperF, RHSvec, phiF, work, N); delete[] work; } void Compact10Filter::compactFilter(double *phi, double *phiF){ if(bcType == Options::PERIODIC_SOLVE){ FilterPeriodic(phi, phiF); }else if(bcType == Options::DIRICHLET_SOLVE){ FilterDirichlet(phi, phiF); } } void Compact10Filter::filterField(double *dataIn, double *dataOut){ if(currentDir == AbstractDerivatives::DIRX){ FOR_Z_XPEN{ FOR_Y_XPEN{ double kGlob = GETGLOBALZIND_XPEN; double jGlob = GETGLOBALYIND_XPEN; bool passFlag = false; if(bc->bcZType == Options::DIRICHLET_SOLVE && (kGlob == 0 || kGlob == Nz-1)){ passFlag =true; } if(bc->bcYType == Options::DIRICHLET_SOLVE && (jGlob == 0 || jGlob == Ny-1)){ passFlag = true; } double *dataInLocal, *dataOutLocal; int ii = k*pxSize[0]*pxSize[1] + j*pxSize[0]; dataInLocal = &dataIn[ii]; dataOutLocal = &dataOut[ii]; if(passFlag){ memcpy(dataOutLocal, dataInLocal, sizeof(double)*pxSize[0]); }else{ compactFilter(dataInLocal, dataOutLocal); } } } }else if(currentDir == AbstractDerivatives::DIRY){ FOR_X_YPEN{ FOR_Z_YPEN{ double iGlob = GETGLOBALXIND_YPEN; double kGlob = GETGLOBALZIND_YPEN; bool passFlag = false; if(bc->bcXType == Options::DIRICHLET_SOLVE && (iGlob == 0 || iGlob == Nx-1)) passFlag = true; if(bc->bcZType == Options::DIRICHLET_SOLVE && (kGlob == 0 || kGlob == Nz-1)) passFlag = true; double *dataInLocal, *dataOutLocal; int ii = i*pySize[2]*pySize[1] + k*pySize[1]; dataInLocal = &dataIn[ii]; dataOutLocal = &dataOut[ii]; if(passFlag){ memcpy(dataOutLocal, dataInLocal, sizeof(double)*pySize[1]); }else{ compactFilter(dataInLocal, dataOutLocal); } } } }else if(currentDir == AbstractDerivatives::DIRZ){ FOR_Y_ZPEN{ FOR_X_ZPEN{ double jGlob = GETGLOBALYIND_ZPEN; double iGlob = GETGLOBALXIND_ZPEN; bool passFlag = false; if(bc->bcYType == Options::DIRICHLET_SOLVE && (jGlob == 0 || jGlob == Ny-1)) passFlag = true; if(bc->bcXType == Options::DIRICHLET_SOLVE && (iGlob == 0 || iGlob == Nx-1)) passFlag = true; double *dataInLocal, *dataOutLocal; int ii = j*pzSize[2]*pzSize[0] + i*pzSize[2]; dataInLocal = &dataIn[ii]; dataOutLocal = &dataOut[ii]; if(passFlag){ memcpy(dataOutLocal, dataInLocal, sizeof(double)*pzSize[2]); }else{ compactFilter(dataInLocal, dataOutLocal); } } } } }
39.442688
104
0.501253
emathew1
11ed411b284c4344029f1d28b2b9acd8141e15f5
568
cpp
C++
main/dad/Link.cpp
irumsey/ijrumsey.com
3dcf909eada5a09d39e6bf89a1f0bf1fa7328789
[ "MIT" ]
null
null
null
main/dad/Link.cpp
irumsey/ijrumsey.com
3dcf909eada5a09d39e6bf89a1f0bf1fa7328789
[ "MIT" ]
null
null
null
main/dad/Link.cpp
irumsey/ijrumsey.com
3dcf909eada5a09d39e6bf89a1f0bf1fa7328789
[ "MIT" ]
null
null
null
/// /// lucid libraries /// #if defined(CONFIG) # undef CONFIG #endif #if defined(_DEBUG) # define CONFIG "d" #else # define CONFIG "r" #endif #if defined(PLATFORM) # undef PLATFORM #endif #if defined(_WIN64) # define PLATFORM "64" #else # define PLATFORM "32" #endif #pragma comment (lib, "core." PLATFORM CONFIG ".lib") #pragma comment (lib, "core.win." PLATFORM CONFIG ".lib") #pragma comment (lib, "gal.d3d11." PLATFORM CONFIG ".lib") #pragma comment (lib, "gigl." PLATFORM CONFIG ".lib") #pragma comment (lib, "orbit." PLATFORM CONFIG ".lib")
18.933333
58
0.667254
irumsey
11efd9e14dc7f0c4b32001c4d822d8ab2d1e06ba
18,775
cpp
C++
src/plugins/azoth/plugins/murm/vkaccount.cpp
MellonQ/leechcraft
71cbb238d2dade56b3865278a6a8e6a58c217fc5
[ "BSL-1.0" ]
null
null
null
src/plugins/azoth/plugins/murm/vkaccount.cpp
MellonQ/leechcraft
71cbb238d2dade56b3865278a6a8e6a58c217fc5
[ "BSL-1.0" ]
null
null
null
src/plugins/azoth/plugins/murm/vkaccount.cpp
MellonQ/leechcraft
71cbb238d2dade56b3865278a6a8e6a58c217fc5
[ "BSL-1.0" ]
null
null
null
/********************************************************************** * LeechCraft - modular cross-platform feature rich internet client. * Copyright (C) 2006-2014 Georg Rudoy * * Boost Software License - Version 1.0 - August 17th, 2003 * * Permission is hereby granted, free of charge, to any person or organization * obtaining a copy of the software and accompanying documentation covered by * this license (the "Software") to use, reproduce, display, distribute, * execute, and transmit the Software, and to prepare derivative works of the * Software, and to permit third-parties to whom the Software is furnished to * do so, all subject to the following: * * The copyright notices in the Software and this entire statement, including * the above license grant, this restriction and the following disclaimer, * must be included in all copies of the Software, in whole or in part, and * all derivative works of the Software, unless such copies or derivative * works are solely in the form of machine-executable object code generated by * a source language processor. * * 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, TITLE AND NON-INFRINGEMENT. IN NO EVENT * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. **********************************************************************/ #include "vkaccount.h" #include <stdexcept> #include <QUuid> #include <QIcon> #include <QtDebug> #include <util/svcauth/vkcaptchadialog.h> #include "vkprotocol.h" #include "vkconnection.h" #include "vkentry.h" #include "vkmessage.h" #include "photostorage.h" #include "georesolver.h" #include "groupsmanager.h" #include "xmlsettingsmanager.h" #include "vkchatentry.h" #include "logger.h" #include "accountconfigdialog.h" #include "serverhistorymanager.h" #include "vkconnectiontunesetter.h" #include "transfermanager.h" namespace LeechCraft { namespace Azoth { namespace Murm { VkAccount::VkAccount (const QString& name, VkProtocol *proto, ICoreProxy_ptr proxy, const QByteArray& id, const QByteArray& cookies) : QObject (proto) , CoreProxy_ (proxy) , Proto_ (proto) , ID_ (id.isEmpty () ? QUuid::createUuid ().toByteArray () : id) , PhotoStorage_ (new PhotoStorage (proxy->GetNetworkAccessManager (), ID_)) , Name_ (name) , Logger_ (new Logger (ID_, this)) , Conn_ (new VkConnection (name, cookies, proxy, *Logger_)) , ConnTuneSetter_ (new VkConnectionTuneSetter (Conn_, proxy)) , GroupsMgr_ (new GroupsManager (Conn_)) , GeoResolver_ (new GeoResolver (Conn_, this)) , ServHistMgr_ (new ServerHistoryManager (this)) , XFerMgr_ (new TransferManager (this)) { connect (Conn_, SIGNAL (cookiesChanged ()), this, SLOT (emitUpdateAcc ())); connect (Conn_, SIGNAL (stoppedPolling ()), this, SLOT (finishOffline ())); connect (Conn_, SIGNAL (gotSelfInfo (UserInfo)), this, SLOT (handleSelfInfo (UserInfo))); connect (Conn_, SIGNAL (gotUsers (QList<UserInfo>)), this, SLOT (handleUsers (QList<UserInfo>))); connect (Conn_, SIGNAL (gotNRIList (QList<qulonglong>)), this, SLOT (handleNRIList (QList<qulonglong>))); connect (Conn_, SIGNAL (userStateChanged (qulonglong, bool)), this, SLOT (handleUserState (qulonglong, bool))); connect (Conn_, SIGNAL (gotMessage (MessageInfo)), this, SLOT (handleMessage (MessageInfo))); connect (Conn_, SIGNAL (gotMessage (FullMessageInfo, MessageInfo)), this, SLOT (handleMessage (FullMessageInfo, MessageInfo))); connect (Conn_, SIGNAL (gotTypingNotification (qulonglong)), this, SLOT (handleTypingNotification (qulonglong))); connect (Conn_, SIGNAL (statusChanged (EntryStatus)), this, SIGNAL (statusChanged (EntryStatus))); connect (Conn_, SIGNAL (mucChanged (qulonglong)), this, SLOT (handleMucChanged (qulonglong))); connect (Conn_, SIGNAL (gotChatInfo (ChatInfo)), this, SLOT (handleGotChatInfo (ChatInfo))); connect (Conn_, SIGNAL (chatUserRemoved (qulonglong, qulonglong)), this, SLOT (handleChatUserRemoved (qulonglong, qulonglong))); connect (Conn_, SIGNAL (captchaNeeded (QString, QUrl)), this, SLOT (handleCaptcha (QString, QUrl))); connect (Logger_, SIGNAL (gotConsolePacket (QByteArray, IHaveConsole::PacketDirection, QString)), this, SIGNAL (gotConsolePacket (QByteArray, IHaveConsole::PacketDirection, QString))); connect (ServHistMgr_, SIGNAL (serverHistoryFetched (QModelIndex, QByteArray, SrvHistMessages_t)), this, SIGNAL (serverHistoryFetched (QModelIndex, QByteArray, SrvHistMessages_t))); } QByteArray VkAccount::Serialize () const { QByteArray result; QDataStream out (&result, QIODevice::WriteOnly); out << static_cast<quint8> (4) << ID_ << Name_ << Conn_->GetCookies () << EnableFileLog_ << PublishTune_ << MarkAsOnline_ << UpdateStatus_; return result; } VkAccount* VkAccount::Deserialize (const QByteArray& data, VkProtocol *proto, ICoreProxy_ptr proxy) { QDataStream in (data); quint8 version = 0; in >> version; if (version < 1 || version > 4) { qWarning () << Q_FUNC_INFO << "unknown version" << version; return nullptr; } QByteArray id; QString name; QByteArray cookies; in >> id >> name >> cookies; auto acc = new VkAccount (name, proto, proxy, id, cookies); if (version >= 2) in >> acc->EnableFileLog_ >> acc->PublishTune_; if (version >= 3) in >> acc->MarkAsOnline_; if (version >= 4) in >> acc->UpdateStatus_; acc->Init (); return acc; } void VkAccount::Init () { Logger_->SetFileEnabled (EnableFileLog_); handleMarkOnline (); } void VkAccount::Send (qulonglong to, VkConnection::Type type, VkMessage *msg, const QStringList& attachments) { QPointer<VkMessage> safeMsg { msg }; Conn_->SendMessage (to, msg->GetRawBody (), [safeMsg] (qulonglong id) { if (safeMsg) safeMsg->SetID (id); }, type, attachments); } void VkAccount::CreateChat (const QString& name, const QList<VkEntry*>& entries) { QList<qulonglong> ids; for (auto entry : entries) ids << entry->GetInfo ().ID_; Conn_->CreateChat (name, ids); } VkEntry* VkAccount::GetEntry (qulonglong id) const { return Entries_.value (id); } VkEntry* VkAccount::FindEntryById (const QString& entryId) const { const auto pos = std::find_if (Entries_.begin (), Entries_.end (), [&entryId] (VkEntry *entry) { return entry->GetEntryID () == entryId; }); return pos != Entries_.end () ? *pos : nullptr; } VkEntry* VkAccount::GetSelf () const { return SelfEntry_; } VkEntry* VkAccount::GetEntryOrCreate (const UserInfo& info) { if (!Entries_.contains (info.ID_)) CreateUsers ({ info }); return Entries_.value (info.ID_); } ICoreProxy_ptr VkAccount::GetCoreProxy () const { return CoreProxy_; } VkConnection* VkAccount::GetConnection () const { return Conn_; } PhotoStorage* VkAccount::GetPhotoStorage () const { return PhotoStorage_; } GeoResolver* VkAccount::GetGeoResolver () const { return GeoResolver_; } GroupsManager* VkAccount::GetGroupsManager () const { return GroupsMgr_; } Logger& VkAccount::GetLogger () const { return *Logger_; } QObject* VkAccount::GetQObject () { return this; } VkProtocol* VkAccount::GetParentProtocol () const { return Proto_; } IAccount::AccountFeatures VkAccount::GetAccountFeatures () const { return AccountFeature::FRenamable; } QList<QObject*> VkAccount::GetCLEntries () { QList<QObject*> result; result.reserve (Entries_.size () + ChatEntries_.size ()); std::copy (Entries_.begin (), Entries_.end (), std::back_inserter (result)); std::copy (ChatEntries_.begin (), ChatEntries_.end (), std::back_inserter (result)); return result; } QString VkAccount::GetAccountName () const { return Name_; } QString VkAccount::GetOurNick () const { return tr ("me"); } void VkAccount::RenameAccount (const QString& name) { Name_ = name; emit accountRenamed (name); emit accountChanged (this); } QByteArray VkAccount::GetAccountID () const { return ID_; } QList<QAction*> VkAccount::GetActions () const { return {}; } void VkAccount::OpenConfigurationDialog () { auto dia = new AccountConfigDialog; AccConfigDia_ = dia; dia->SetFileLogEnabled (EnableFileLog_); dia->SetPublishTuneEnabled (PublishTune_); dia->SetMarkAsOnline (MarkAsOnline_); dia->SetUpdateStatusEnabled (UpdateStatus_); connect (dia, SIGNAL (reauthRequested ()), Conn_, SLOT (reauth ())); connect (dia, SIGNAL (rejected ()), dia, SLOT (deleteLater ())); connect (dia, SIGNAL (accepted ()), this, SLOT (handleConfigDialogAccepted ())); dia->show (); } EntryStatus VkAccount::GetState () const { return Conn_->GetStatus (); } void VkAccount::ChangeState (const EntryStatus& status) { Conn_->SetStatus (status, UpdateStatus_); } void VkAccount::Authorize (QObject*) { } void VkAccount::DenyAuth (QObject*) { } void VkAccount::RequestAuth (const QString&, const QString&, const QString&, const QStringList&) { } void VkAccount::RemoveEntry (QObject *entryObj) { auto entry = qobject_cast<VkEntry*> (entryObj); if (!entry) { qWarning () << Q_FUNC_INFO << entry << "is not a VkEntry"; return; } if (entry->IsNonRoster ()) { emit removedCLItems ({ entry }); const auto id = entry->GetInfo ().ID_; Entries_.remove (id); entry->deleteLater (); NonRosterItems_.removeOne (id); Conn_->SetNRIList (NonRosterItems_); return; } } QObject* VkAccount::GetTransferManager () const { return XFerMgr_; } void VkAccount::PublishTune (const QMap<QString, QVariant>& tuneData) { if (!PublishTune_) return; ConnTuneSetter_->SetTune (tuneData); } QObject* VkAccount::GetSelfContact () const { return SelfEntry_; } QImage VkAccount::GetSelfAvatar () const { return SelfEntry_ ? SelfEntry_->GetAvatar () : QImage (); } QIcon VkAccount::GetAccountIcon () const { return {}; } IHaveConsole::PacketFormat VkAccount::GetPacketFormat () const { return PacketFormat::PlainText; } void VkAccount::SetConsoleEnabled (bool) { } QObject* VkAccount::CreateNonRosterItem (const QString& idStr) { auto realId = idStr; if (realId.startsWith ("id")) realId = realId.remove (0, 2); bool ok = false; const auto id = realId.toULongLong (&ok); if (!ok) throw std::runtime_error (tr ("%1 is invalid VKontake ID") .arg (idStr) .toUtf8 ().constData ()); if (Entries_.contains (id)) return Entries_ [id]; const auto entry = CreateNonRosterItem (id); emit gotCLItems ({ entry }); NonRosterItems_ << id; Conn_->SetNRIList (NonRosterItems_); Conn_->GetUserInfo ({ id }); return entry; } bool VkAccount::HasFeature (ServerHistoryFeature feature) const { switch (feature) { case ServerHistoryFeature::AccountSupportsHistory: return true; case ServerHistoryFeature::Configurable: return false; } qWarning () << Q_FUNC_INFO << "unknown feature" << static_cast<int> (feature); return false; } void VkAccount::OpenServerHistoryConfiguration () { } QAbstractItemModel* VkAccount::GetServerContactsModel () const { return ServHistMgr_->GetModel (); } void VkAccount::FetchServerHistory (const QModelIndex& contact, const QByteArray& startId, int count) { ServHistMgr_->RequestHistory (contact, startId.toInt (), count); } DefaultSortParams VkAccount::GetSortParams () const { return { 0, ServerHistoryRole::LastMessageDate, Qt::DescendingOrder }; } void VkAccount::TryPendingMessages () { decltype (PendingMessages_) pending; std::swap (pending, PendingMessages_); for (const auto& pair : pending) handleMessage (pair.second, pair.first); } VkEntry* VkAccount::CreateNonRosterItem (qulonglong id) { UserInfo info; info.ID_ = id; auto entry = new VkEntry (info, this); entry->SetNonRoster (); Entries_ [id] = entry; return entry; } bool VkAccount::CreateUsers (const QList<UserInfo>& infos) { QList<QObject*> newEntries; QHash<int, QString> newCountries; QHash<int, QString> newCities; bool hadNew = false; for (const auto& info : infos) { if (Entries_.contains (info.ID_)) { Entries_ [info.ID_]->UpdateInfo (info); continue; } auto entry = new VkEntry (info, this); Entries_ [info.ID_] = entry; newEntries << entry; newCountries [info.Country_] = info.CountryName_; newCities [info.City_] = info.CityName_; hadNew = true; } GeoResolver_->AddCountriesToCache (newCountries); GeoResolver_->AddCitiesToCache (newCities); if (!newEntries.isEmpty ()) emit gotCLItems (newEntries); return hadNew; } void VkAccount::handleSelfInfo (const UserInfo& info) { CreateUsers ({ info }); SelfEntry_ = Entries_ [info.ID_]; SelfEntry_->SetSelf (); } void VkAccount::handleUsers (const QList<UserInfo>& infos) { if (CreateUsers (infos)) { TryPendingMessages (); ServHistMgr_->refresh (); } } void VkAccount::handleNRIList (const QList<qulonglong>& ids) { QList<qulonglong> toRequest; QList<QObject*> objs; for (auto id : ids) { if (Entries_.contains (id)) continue; toRequest << id; objs << CreateNonRosterItem (id); } emit gotCLItems (objs); Conn_->GetUserInfo (toRequest); NonRosterItems_ = toRequest; } void VkAccount::handleUserState (qulonglong id, bool isOnline) { if (!Entries_.contains (id)) { qWarning () << Q_FUNC_INFO << "unknown user" << id; Conn_->RerequestFriends (); return; } auto entry = Entries_.value (id); auto info = entry->GetInfo (); info.IsOnline_ = isOnline; entry->UpdateInfo (info); } void VkAccount::handleMessage (const MessageInfo& info) { handleMessage ({}, info); } void VkAccount::handleMessage (const FullMessageInfo& fullInfo, const MessageInfo& info) { if (info.Params_.value ("source_act") == "chat_kick_user" && info.Params_.value ("source_mid").toULongLong () == SelfEntry_->GetInfo ().ID_) return; const auto from = info.From_; if (info.Flags_ & MessageFlag::Chat) { if (!ChatEntries_.contains (from)) { qDebug () << Q_FUNC_INFO << "unknown chat entry" << from; if (!std::any_of (PendingMessages_.begin (), PendingMessages_.end (), [from] (const QPair<MessageInfo, FullMessageInfo>& info) { return from == info.first.From_; })) { qDebug () << Q_FUNC_INFO << "requesting info for" << from; Conn_->RequestChatInfo (from); } PendingMessages_.append ({ info, fullInfo }); return; } switch (ChatEntries_.value (from)->HandleMessage (info, fullInfo)) { case VkChatEntry::HandleMessageResult::Accepted: case VkChatEntry::HandleMessageResult::Rejected: return; case VkChatEntry::HandleMessageResult::UserInfoRequested: PendingMessages_.append ({ info, fullInfo }); return; } } else { if (!Entries_.contains (from)) { qWarning () << Q_FUNC_INFO << "message from unknown user" << from; PendingMessages_.append ({ info, fullInfo }); Conn_->GetUserInfo ({ from }); return; } Entries_.value (from)->HandleMessage (info, fullInfo); } } void VkAccount::handleTypingNotification (qulonglong uid) { if (!Entries_.contains (uid)) { qWarning () << Q_FUNC_INFO << "message from unknown user" << uid; Conn_->RerequestFriends (); return; } const auto entry = Entries_.value (uid); entry->HandleTypingNotification (); } void VkAccount::handleMarkOnline () { Conn_->SetMarkingOnlineEnabled (MarkAsOnline_); } void VkAccount::finishOffline () { if (!ChatEntries_.isEmpty ()) { QList<QObject*> toRemove; for (auto item : ChatEntries_) toRemove << item; emit removedCLItems (toRemove); qDeleteAll (ChatEntries_); ChatEntries_.clear (); } for (auto entry : Entries_) { auto info = entry->GetInfo (); info.IsOnline_ = false; entry->UpdateInfo (info, false); } } void VkAccount::handleCaptcha (const QString& cid, const QUrl& url) { if (IsRequestingCaptcha_) { Conn_->HandleCaptcha (cid, {}); return; } auto dia = new Util::SvcAuth::VkCaptchaDialog (url, cid, CoreProxy_->GetNetworkAccessManager ()); dia->SetContextName ("Azoth Murm"); connect (dia, SIGNAL (gotCaptcha (QString, QString)), this, SLOT (handleCaptchaEntered (QString, QString))); dia->show (); IsRequestingCaptcha_ = true; } void VkAccount::handleCaptchaEntered (const QString& cid, const QString& value) { Conn_->HandleCaptcha (cid, value); IsRequestingCaptcha_ = false; } void VkAccount::handleConfigDialogAccepted() { if (!AccConfigDia_) return; EnableFileLog_ = AccConfigDia_->GetFileLogEnabled (); Logger_->SetFileEnabled (EnableFileLog_); MarkAsOnline_ = AccConfigDia_->GetMarkAsOnline (); handleMarkOnline (); PublishTune_ = AccConfigDia_->GetPublishTuneEnabled (); UpdateStatus_ = AccConfigDia_->GetUpdateStatusEnabled (); emit accountChanged (this); AccConfigDia_->deleteLater (); } void VkAccount::handleMucChanged (qulonglong chat) { if (!ChatEntries_.contains (chat)) { qDebug () << Q_FUNC_INFO << "ignoring chat change for non-present chat" << chat; return; } Conn_->RequestChatInfo (chat); } void VkAccount::handleGotChatInfo (const ChatInfo& info) { if (!ChatEntries_.contains (info.ChatID_)) { auto entry = new VkChatEntry (info, this); connect (entry, SIGNAL (removeEntry (VkChatEntry*)), this, SLOT (handleRemoveEntry (VkChatEntry*))); ChatEntries_ [info.ChatID_] = entry; emit gotCLItems ({ entry }); TryPendingMessages (); } else ChatEntries_ [info.ChatID_]->UpdateInfo (info); } void VkAccount::handleRemoveEntry (VkChatEntry *entry) { ChatEntries_.remove (ChatEntries_.key (entry)); emit removedCLItems ({ entry }); entry->deleteLater (); } void VkAccount::handleChatUserRemoved (qulonglong chat, qulonglong id) { if (!ChatEntries_.contains (chat)) { qWarning () << Q_FUNC_INFO << "unknown chat" << chat; return; } ChatEntries_ [chat]->HandleRemoved (id); } void VkAccount::emitUpdateAcc () { emit accountChanged (this); } } } }
22.81288
102
0.675899
MellonQ
11f84e571df01facf0640e97db6bfd91b9aafa66
4,757
hpp
C++
include/async_web_server_cpp/http_reply.hpp
rohbotics/async_web_server_cpp
fac1c096a820f8d6b88ba9cfe1afa08c4307a63f
[ "BSD-3-Clause" ]
24
2016-04-24T12:19:43.000Z
2021-06-01T18:48:11.000Z
include/async_web_server_cpp/http_reply.hpp
rohbotics/async_web_server_cpp
fac1c096a820f8d6b88ba9cfe1afa08c4307a63f
[ "BSD-3-Clause" ]
13
2016-08-09T22:03:36.000Z
2021-03-04T12:17:57.000Z
include/async_web_server_cpp/http_reply.hpp
rohbotics/async_web_server_cpp
fac1c096a820f8d6b88ba9cfe1afa08c4307a63f
[ "BSD-3-Clause" ]
37
2017-04-27T06:49:17.000Z
2022-03-06T00:26:55.000Z
#ifndef CPP_WEB_SERVER_HTTP_REPLY_HPP #define CPP_WEB_SERVER_HTTP_REPLY_HPP #include <vector> #include <string> #include <boost/asio.hpp> #include "async_web_server_cpp/http_header.hpp" #include "async_web_server_cpp/http_connection.hpp" #include "async_web_server_cpp/http_request_handler.hpp" #include <boost/filesystem.hpp> namespace async_web_server_cpp { class ReplyBuilder; /** * Utility methods for constructing replys */ struct HttpReply { enum status_type { switching_protocols = 101, ok = 200, created = 201, accepted = 202, no_content = 204, multiple_choices = 300, moved_permanently = 301, moved_temporarily = 302, not_modified = 304, bad_request = 400, unauthorized = 401, forbidden = 403, not_found = 404, internal_server_error = 500, not_implemented = 501, bad_gateway = 502, service_unavailable = 503 } status; static std::vector<boost::asio::const_buffer> to_buffers(const std::vector<HttpHeader> &headers); /** * Create a request handler that sends a stock reply based on the stats code */ static HttpServerRequestHandler stock_reply(status_type status); /** * Create a request handler that sends the contents of a file */ static HttpServerRequestHandler from_file(HttpReply::status_type status, const std::string& content_type, const std::string& filename, const std::vector<HttpHeader>& additional_headers = std::vector<HttpHeader>()); /** * Create a request handler that reads files from the filesystem * No content type is served and it is left to the browser to determine the content type * @param path_root the prefix in the request path that should be ignored * @param filesystem_root the path to search for the requested file */ static HttpServerRequestHandler from_filesystem(HttpReply::status_type status, const std::string& path_root, const std::string& filesystem_root, bool list_directories, const std::vector<HttpHeader>& additional_headers = std::vector<HttpHeader>()); /** * Create a request handler that sends a static response */ static HttpServerRequestHandler static_reply(status_type status, const std::string& content_type, const std::string& content, const std::vector<HttpHeader>& additional_headers = std::vector<HttpHeader>()); /** * Create a builder to create and send reply headers */ static ReplyBuilder builder(status_type status); }; /** * Object to build and send reply headers */ class ReplyBuilder { public: ReplyBuilder(HttpReply::status_type status); /** * Add a header to the reply */ ReplyBuilder &header(const std::string &name, const std::string &value); /** * Add a header to the reply */ ReplyBuilder &header(const HttpHeader &header); /** * Add a group of headers to the reply */ ReplyBuilder &headers(const std::vector<HttpHeader> &headers); /** * Send the headers over the connection */ void write(HttpConnectionPtr connection); private: HttpReply::status_type status_; boost::shared_ptr<std::vector<HttpHeader> > headers_; }; /** * Request Handler that serves a predefined response */ class StaticHttpRequestHandler { public: StaticHttpRequestHandler(HttpReply::status_type status, const std::vector<HttpHeader> &headers, const std::string &content); bool operator()(const HttpRequest &, boost::shared_ptr<HttpConnection>, const char* begin, const char* end); private: ReplyBuilder reply_builder_; const std::string content_string_; }; /** * Request Handler that serves a response from a file */ class FileHttpRequestHandler { public: FileHttpRequestHandler(HttpReply::status_type status, const std::string& filename, const std::vector<HttpHeader>& headers); bool operator()(const HttpRequest &, boost::shared_ptr<HttpConnection>, const char* begin, const char* end); private: HttpReply::status_type status_; std::vector<HttpHeader> headers_; std::string filename_; }; /** * Request Handler that serves a responses from the filesystem from a base path */ class FilesystemHttpRequestHandler { public: FilesystemHttpRequestHandler(HttpReply::status_type status, const std::string& path_root, const std::string& filesystem_root, bool list_directories, const std::vector<HttpHeader>& headers); bool operator()(const HttpRequest &, boost::shared_ptr<HttpConnection>, const char* begin, const char* end); private: HttpReply::status_type status_; std::vector<HttpHeader> headers_; std::string path_root_; boost::filesystem::path filesystem_root_; bool list_directories_; }; } #endif
26.724719
110
0.715367
rohbotics
f50104e1fe831589674c7f5a34bc5cb53bd158d6
22,245
hpp
C++
core/src/Kokkos_ROCmSpace.hpp
MalachiTimothyPhillips/kokkos
d3a941925cbfb71785d8ea68259123ed52d3f9da
[ "BSD-3-Clause" ]
2
2019-12-18T20:37:06.000Z
2020-04-07T00:44:39.000Z
core/src/Kokkos_ROCmSpace.hpp
MalachiTimothyPhillips/kokkos
d3a941925cbfb71785d8ea68259123ed52d3f9da
[ "BSD-3-Clause" ]
2
2020-01-15T21:08:09.000Z
2020-12-05T06:07:35.000Z
core/src/Kokkos_ROCmSpace.hpp
MalachiTimothyPhillips/kokkos
d3a941925cbfb71785d8ea68259123ed52d3f9da
[ "BSD-3-Clause" ]
2
2020-04-01T19:16:16.000Z
2022-02-09T21:45:19.000Z
/* //@HEADER // ************************************************************************ // // Kokkos v. 2.0 // Copyright (2014) Sandia Corporation // // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // the U.S. Government retains certain rights in this software. // // 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 of the Corporation nor the names of the // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "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 SANDIA CORPORATION OR 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. // // Questions? Contact Christian R. Trott (crtrott@sandia.gov) // // ************************************************************************ //@HEADER */ #ifndef KOKKOS_ROCMSPACE_HPP #define KOKKOS_ROCMSPACE_HPP #include <Kokkos_Core_fwd.hpp> #if defined( KOKKOS_ENABLE_ROCM ) #include <iosfwd> #include <typeinfo> #include <string> #include <Kokkos_HostSpace.hpp> /*--------------------------------------------------------------------------*/ namespace Kokkos { namespace Experimental { /** \brief ROCm on-device memory management */ class ROCmSpace { public: //! Tag this class as a kokkos memory space typedef ROCmSpace memory_space ; typedef Kokkos::Experimental::ROCm execution_space ; typedef Kokkos::Device<execution_space,memory_space> device_type; typedef unsigned int size_type ; /*--------------------------------*/ ROCmSpace(); ROCmSpace( ROCmSpace && rhs ) = default ; ROCmSpace( const ROCmSpace & rhs ) = default ; ROCmSpace & operator = ( ROCmSpace && rhs ) = default ; ROCmSpace & operator = ( const ROCmSpace & rhs ) = default ; ~ROCmSpace() = default ; /**\brief Allocate untracked memory in the rocm space */ void * allocate( const size_t arg_alloc_size ) const ; /**\brief Deallocate untracked memory in the rocm space */ void deallocate( void * const arg_alloc_ptr , const size_t arg_alloc_size ) const ; /**\brief Return Name of the MemorySpace */ static constexpr const char* name() { return m_name; }; /*--------------------------------*/ /** \brief Error reporting for HostSpace attempt to access ROCmSpace */ static void access_error(); static void access_error( const void * const ); private: int m_device ; ///< Which ROCm device static constexpr const char* m_name = "ROCm"; friend class Kokkos::Impl::SharedAllocationRecord< Kokkos::Experimental::ROCmSpace , void > ; }; } // namespace Experimental namespace Impl { void * rocm_device_allocate(int); void * rocm_hostpinned_allocate(int); void rocm_device_free(void * ); /// \brief Initialize lock array for arbitrary size atomics. /// /// Arbitrary atomics are implemented using a hash table of locks /// where the hash value is derived from the address of the /// object for which an atomic operation is performed. /// This function initializes the locks to zero (unset). void init_lock_arrays_rocm_space(); /// \brief Retrieve the pointer to the lock array for arbitrary size atomics. /// /// Arbitrary atomics are implemented using a hash table of locks /// where the hash value is derived from the address of the /// object for which an atomic operation is performed. /// This function retrieves the lock array pointer. /// If the array is not yet allocated it will do so. int* atomic_lock_array_rocm_space_ptr(bool deallocate = false); /// \brief Retrieve the pointer to the scratch array for team and thread private global memory. /// /// Team and Thread private scratch allocations in /// global memory are aquired via locks. /// This function retrieves the lock array pointer. /// If the array is not yet allocated it will do so. int* scratch_lock_array_rocm_space_ptr(bool deallocate = false); /// \brief Retrieve the pointer to the scratch array for unique identifiers. /// /// Unique identifiers in the range 0-ROCm::concurrency /// are provided via locks. /// This function retrieves the lock array pointer. /// If the array is not yet allocated it will do so. int* threadid_lock_array_rocm_space_ptr(bool deallocate = false); } } // namespace Kokkos /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ namespace Kokkos { namespace Experimental { /** \brief Host memory that is accessible to ROCm execution space * through ROCm's host-pinned memory allocation. */ class ROCmHostPinnedSpace { public: //! Tag this class as a kokkos memory space /** \brief Memory is in HostSpace so use the HostSpace::execution_space */ typedef HostSpace::execution_space execution_space ; typedef ROCmHostPinnedSpace memory_space ; typedef Kokkos::Device<execution_space,memory_space> device_type; typedef unsigned int size_type ; /*--------------------------------*/ ROCmHostPinnedSpace(); ROCmHostPinnedSpace( ROCmHostPinnedSpace && rhs ) = default ; ROCmHostPinnedSpace( const ROCmHostPinnedSpace & rhs ) = default ; ROCmHostPinnedSpace & operator = ( ROCmHostPinnedSpace && rhs ) = default ; ROCmHostPinnedSpace & operator = ( const ROCmHostPinnedSpace & rhs ) = default ; ~ROCmHostPinnedSpace() = default ; /**\brief Allocate untracked memory in the space */ void * allocate( const size_t arg_alloc_size ) const ; /**\brief Deallocate untracked memory in the space */ void deallocate( void * const arg_alloc_ptr , const size_t arg_alloc_size ) const ; /**\brief Return Name of the MemorySpace */ static constexpr const char* name() { return m_name; }; private: static constexpr const char* m_name = "ROCmHostPinned"; /*--------------------------------*/ }; } // namespace Experimental } // namespace Kokkos /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ namespace Kokkos { namespace Impl { static_assert( Kokkos::Impl::MemorySpaceAccess< Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCmSpace >::assignable , "" ); //---------------------------------------- template<> struct MemorySpaceAccess< Kokkos::HostSpace , Kokkos::Experimental::ROCmSpace > { enum { assignable = false }; enum { accessible = false }; enum { deepcopy = true }; }; template<> struct MemorySpaceAccess< Kokkos::HostSpace , Kokkos::Experimental::ROCmHostPinnedSpace > { // HostSpace::execution_space == ROCmHostPinnedSpace::execution_space enum { assignable = true }; enum { accessible = true }; enum { deepcopy = true }; }; //---------------------------------------- template<> struct MemorySpaceAccess< Kokkos::Experimental::ROCmSpace , Kokkos::HostSpace > { enum { assignable = false }; enum { accessible = false }; enum { deepcopy = true }; }; template<> struct MemorySpaceAccess< Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCmHostPinnedSpace > { // ROCmSpace::execution_space != ROCmHostPinnedSpace::execution_space enum { assignable = false }; enum { accessible = true }; // ROCmSpace::execution_space enum { deepcopy = true }; }; //---------------------------------------- // ROCmHostPinnedSpace::execution_space == HostSpace::execution_space // ROCmHostPinnedSpace accessible to both ROCm and Host template<> struct MemorySpaceAccess< Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::HostSpace > { enum { assignable = false }; // Cannot access from ROCm enum { accessible = true }; // ROCmHostPinnedSpace::execution_space enum { deepcopy = true }; }; template<> struct MemorySpaceAccess< Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCmSpace > { enum { assignable = false }; // Cannot access from Host enum { accessible = false }; enum { deepcopy = true }; }; }; //---------------------------------------- } // namespace Kokkos::Impl /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ namespace Kokkos { namespace Impl { hc::completion_future DeepCopyAsyncROCm( void * dst , const void * src , size_t n); template<> struct DeepCopy< Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCm> { DeepCopy( void * dst , const void * src , size_t ); DeepCopy( const Kokkos::Experimental::ROCm & , void * dst , const void * src , size_t ); }; template<> struct DeepCopy< Kokkos::Experimental::ROCmSpace , HostSpace , Kokkos::Experimental::ROCm > { DeepCopy( void * dst , const void * src , size_t ); DeepCopy( const Kokkos::Experimental::ROCm & , void * dst , const void * src , size_t ); }; template<> struct DeepCopy< HostSpace , Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCm > { DeepCopy( void * dst , const void * src , size_t ); DeepCopy( const Kokkos::Experimental::ROCm & , void * dst , const void * src , size_t ); }; template<class ExecutionSpace> struct DeepCopy< Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCmSpace , ExecutionSpace > { inline DeepCopy( void * dst , const void * src , size_t n ) { (void) DeepCopy< Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCm >( dst , src , n ); } inline DeepCopy( const ExecutionSpace& exec, void * dst , const void * src , size_t n ) { exec.fence(); hc::completion_future fut = DeepCopyAsyncROCm (dst,src,n); fut.wait(); // DeepCopy (dst,src,n); } }; template<class ExecutionSpace> struct DeepCopy< Kokkos::Experimental::ROCmSpace , HostSpace , ExecutionSpace > { inline DeepCopy( void * dst , const void * src , size_t n ) { (void) DeepCopy< Kokkos::Experimental::ROCmSpace , HostSpace , Kokkos::Experimental::ROCm>( dst , src , n ); } inline DeepCopy( const ExecutionSpace& exec, void * dst , const void * src , size_t n ) { exec.fence(); DeepCopy (dst,src,n); } }; template<class ExecutionSpace> struct DeepCopy< HostSpace , Kokkos::Experimental::ROCmSpace , ExecutionSpace > { inline DeepCopy( void * dst , const void * src , size_t n ) { (void) DeepCopy< HostSpace , Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCm >( dst , src , n ); } inline DeepCopy( const ExecutionSpace& exec, void * dst , const void * src , size_t n ) { exec.fence(); DeepCopy (dst,src,n); } }; template<> struct DeepCopy< Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCm> { DeepCopy( void * dst , const void * src , size_t ); DeepCopy( const Kokkos::Experimental::ROCm & , void * dst , const void * src , size_t ); }; template<> struct DeepCopy< Kokkos::Experimental::ROCmHostPinnedSpace , HostSpace , Kokkos::Experimental::ROCm > { DeepCopy( void * dst , const void * src , size_t ); DeepCopy( const Kokkos::Experimental::ROCm & , void * dst , const void * src , size_t ); }; template<> struct DeepCopy< HostSpace , Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCm > { DeepCopy( void * dst , const void * src , size_t ); DeepCopy( const Kokkos::Experimental::ROCm & , void * dst , const void * src , size_t ); }; template<class ExecutionSpace> struct DeepCopy< Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCmHostPinnedSpace , ExecutionSpace> { inline DeepCopy( void * dst , const void * src , size_t n ) { (void) DeepCopy< Kokkos::Experimental::ROCmSpace , HostSpace , Kokkos::Experimental::ROCm >( dst , src , n ); } inline DeepCopy( const ExecutionSpace& exec, void * dst , const void * src , size_t n ) { exec.fence(); hc::completion_future fut = DeepCopyAsyncROCm (dst,src,n); fut.wait(); // DeepCopyROCm (dst,src,n); } }; template<class ExecutionSpace> struct DeepCopy< Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCmSpace , ExecutionSpace > { inline DeepCopy( void * dst , const void * src , size_t n ) { (void) DeepCopy< HostSpace , Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCm >( dst , src , n ); } inline DeepCopy( const ExecutionSpace& exec, void * dst , const void * src , size_t n ) { exec.fence(); hc::completion_future fut = DeepCopyAsyncROCm (dst,src,n); fut.wait(); // DeepCopyROCm (dst,src,n); } }; template<class ExecutionSpace> struct DeepCopy< Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCmHostPinnedSpace , ExecutionSpace > { inline DeepCopy( void * dst , const void * src , size_t n ) { (void) DeepCopy< Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCm >( dst , src , n ); } inline DeepCopy( const ExecutionSpace& exec, void * dst , const void * src , size_t n ) { exec.fence(); // hc::completion_future fut = DeepCopyAsyncROCm (dst,src,n); // fut.wait(); // DeepCopyAsyncROCm (dst,src,n); DeepCopy (dst,src,n); } }; template<class ExecutionSpace> struct DeepCopy< Kokkos::Experimental::ROCmHostPinnedSpace , HostSpace , ExecutionSpace > { inline DeepCopy( void * dst , const void * src , size_t n ) { (void) DeepCopy< Kokkos::Experimental::ROCmHostPinnedSpace , HostSpace , Kokkos::Experimental::ROCm>( dst , src , n ); } inline DeepCopy( const ExecutionSpace& exec, void * dst , const void * src , size_t n ) { exec.fence(); DeepCopy (dst,src,n); } }; template<class ExecutionSpace> struct DeepCopy< HostSpace , Kokkos::Experimental::ROCmHostPinnedSpace , ExecutionSpace > { inline DeepCopy( void * dst , const void * src , size_t n ) { (void) DeepCopy< HostSpace , Kokkos::Experimental::ROCmHostPinnedSpace , Kokkos::Experimental::ROCm >( dst , src , n ); } inline DeepCopy( const ExecutionSpace& exec, void * dst , const void * src , size_t n ) { exec.fence(); DeepCopy (dst,src,n); } }; } // namespace Impl } // namespace Kokkos //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- namespace Kokkos { namespace Impl { /** Running in ROCmSpace attempting to access HostSpace: error */ template<> struct VerifyExecutionCanAccessMemorySpace< Kokkos::Experimental::ROCmSpace , Kokkos::HostSpace > { enum { value = false }; KOKKOS_INLINE_FUNCTION static void verify( void ) { Kokkos::abort("ROCm code attempted to access HostSpace memory"); } KOKKOS_INLINE_FUNCTION static void verify( const void * ) { Kokkos::abort("ROCm code attempted to access HostSpace memory"); } }; /** Running in ROCmSpace accessing ROCmHostPinnedSpace: ok */ template<> struct VerifyExecutionCanAccessMemorySpace< Kokkos::Experimental::ROCmSpace , Kokkos::Experimental::ROCmHostPinnedSpace > { enum { value = true }; KOKKOS_INLINE_FUNCTION static void verify( void ) { } KOKKOS_INLINE_FUNCTION static void verify( const void * ) { } }; /** Running in ROCmSpace attempting to access an unknown space: error */ template< class OtherSpace > struct VerifyExecutionCanAccessMemorySpace< typename enable_if< ! is_same<Kokkos::Experimental::ROCmSpace,OtherSpace>::value , Kokkos::Experimental::ROCmSpace >::type , OtherSpace > { enum { value = false }; KOKKOS_INLINE_FUNCTION static void verify( void ) { Kokkos::abort("ROCm code attempted to access unknown Space memory"); } KOKKOS_INLINE_FUNCTION static void verify( const void * ) { Kokkos::abort("ROCm code attempted to access unknown Space memory"); } }; //---------------------------------------------------------------------------- /** Running in HostSpace attempting to access ROCmSpace */ template<> struct VerifyExecutionCanAccessMemorySpace< Kokkos::HostSpace , Kokkos::Experimental::ROCmSpace > { enum { value = false }; inline static void verify( void ) { Kokkos::Experimental::ROCmSpace::access_error(); } inline static void verify( const void * p ) { Kokkos::Experimental::ROCmSpace::access_error(p); } }; /** Running in HostSpace accessing ROCmHostPinnedSpace is OK */ template<> struct VerifyExecutionCanAccessMemorySpace< Kokkos::HostSpace , Kokkos::Experimental::ROCmHostPinnedSpace > { enum { value = true }; KOKKOS_INLINE_FUNCTION static void verify( void ) {} KOKKOS_INLINE_FUNCTION static void verify( const void * ) {} }; } // namespace Impl } // namespace Kokkos //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- namespace Kokkos { namespace Impl { template<> class SharedAllocationRecord< Kokkos::Experimental::ROCmSpace , void > : public SharedAllocationRecord< void , void > { private: typedef SharedAllocationRecord< void , void > RecordBase ; SharedAllocationRecord( const SharedAllocationRecord & ) = delete ; SharedAllocationRecord & operator = ( const SharedAllocationRecord & ) = delete ; static void deallocate( RecordBase * ); #ifdef KOKKOS_DEBUG static RecordBase s_root_record ; #endif const Kokkos::Experimental::ROCmSpace m_space ; protected: ~SharedAllocationRecord(); SharedAllocationRecord( const Kokkos::Experimental::ROCmSpace & arg_space , const std::string & arg_label , const size_t arg_alloc_size , const RecordBase::function_type arg_dealloc = & deallocate ); public: std::string get_label() const ; static SharedAllocationRecord * allocate( const Kokkos::Experimental::ROCmSpace & arg_space , const std::string & arg_label , const size_t arg_alloc_size ); /**\brief Allocate tracked memory in the space */ static void * allocate_tracked( const Kokkos::Experimental::ROCmSpace & arg_space , const std::string & arg_label , const size_t arg_alloc_size ); /**\brief Reallocate tracked memory in the space */ static void * reallocate_tracked( void * const arg_alloc_ptr , const size_t arg_alloc_size ); /**\brief Deallocate tracked memory in the space */ static void deallocate_tracked( void * const arg_alloc_ptr ); static SharedAllocationRecord * get_record( void * arg_alloc_ptr ); static void print_records( std::ostream & , const Kokkos::Experimental::ROCmSpace & , bool detail = false ); }; template<> class SharedAllocationRecord< Kokkos::Experimental::ROCmHostPinnedSpace , void > : public SharedAllocationRecord< void , void > { private: typedef SharedAllocationRecord< void , void > RecordBase ; SharedAllocationRecord( const SharedAllocationRecord & ) = delete ; SharedAllocationRecord & operator = ( const SharedAllocationRecord & ) = delete ; static void deallocate( RecordBase * ); #ifdef KOKKOS_DEBUG static RecordBase s_root_record ; #endif const Kokkos::Experimental::ROCmHostPinnedSpace m_space ; protected: ~SharedAllocationRecord(); SharedAllocationRecord() : RecordBase(), m_space() {} SharedAllocationRecord( const Kokkos::Experimental::ROCmHostPinnedSpace & arg_space , const std::string & arg_label , const size_t arg_alloc_size , const RecordBase::function_type arg_dealloc = & deallocate ); public: std::string get_label() const ; static SharedAllocationRecord * allocate( const Kokkos::Experimental::ROCmHostPinnedSpace & arg_space , const std::string & arg_label , const size_t arg_alloc_size ); /**\brief Allocate tracked memory in the space */ static void * allocate_tracked( const Kokkos::Experimental::ROCmHostPinnedSpace & arg_space , const std::string & arg_label , const size_t arg_alloc_size ); /**\brief Reallocate tracked memory in the space */ static void * reallocate_tracked( void * const arg_alloc_ptr , const size_t arg_alloc_size ); /**\brief Deallocate tracked memory in the space */ static void deallocate_tracked( void * const arg_alloc_ptr ); static SharedAllocationRecord * get_record( void * arg_alloc_ptr ); static void print_records( std::ostream & , const Kokkos::Experimental::ROCmHostPinnedSpace & , bool detail = false ); }; } // namespace Impl } // namespace Kokkos //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- #endif /* #if defined( KOKKOS_ENABLE_ROCM ) */ #endif /* #define KOKKOS_ROCMSPACE_HPP */
35.478469
157
0.647516
MalachiTimothyPhillips
f50491534326c1d9715943a471868c7e6209fc08
3,810
cpp
C++
3rdparty/aws-sdk-cpp-master/aws-cpp-sdk-ecs/source/ECSErrors.cpp
prateek-s/mesos
4b81147797e4d9a45e0b2f5e5634d4a214dbc4e8
[ "Apache-2.0" ]
2
2019-02-08T21:29:57.000Z
2021-07-27T06:59:19.000Z
3rdparty/aws-sdk-cpp-master/aws-cpp-sdk-ecs/source/ECSErrors.cpp
prateek-s/mesos
4b81147797e4d9a45e0b2f5e5634d4a214dbc4e8
[ "Apache-2.0" ]
null
null
null
3rdparty/aws-sdk-cpp-master/aws-cpp-sdk-ecs/source/ECSErrors.cpp
prateek-s/mesos
4b81147797e4d9a45e0b2f5e5634d4a214dbc4e8
[ "Apache-2.0" ]
null
null
null
/* * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file 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 <aws/core/client/AWSError.h> #include <aws/core/utils/HashingUtils.h> #include <aws/ecs/ECSErrors.h> using namespace Aws::Client; using namespace Aws::ECS; using namespace Aws::Utils; namespace Aws { namespace ECS { namespace ECSErrorMapper { static const int UPDATE_IN_PROGRESS_HASH = HashingUtils::HashString("UpdateInProgressException"); static const int CLIENT_HASH = HashingUtils::HashString("ClientException"); static const int CLUSTER_CONTAINS_CONTAINER_INSTANCES_HASH = HashingUtils::HashString("ClusterContainsContainerInstancesException"); static const int NO_UPDATE_AVAILABLE_HASH = HashingUtils::HashString("NoUpdateAvailableException"); static const int CLUSTER_CONTAINS_SERVICES_HASH = HashingUtils::HashString("ClusterContainsServicesException"); static const int SERVER_HASH = HashingUtils::HashString("ServerException"); static const int CLUSTER_NOT_FOUND_HASH = HashingUtils::HashString("ClusterNotFoundException"); static const int SERVICE_NOT_ACTIVE_HASH = HashingUtils::HashString("ServiceNotActiveException"); static const int INVALID_PARAMETER_HASH = HashingUtils::HashString("InvalidParameterException"); static const int SERVICE_NOT_FOUND_HASH = HashingUtils::HashString("ServiceNotFoundException"); static const int MISSING_VERSION_HASH = HashingUtils::HashString("MissingVersionException"); AWSError<CoreErrors> GetErrorForName(const char* errorName) { int hashCode = HashingUtils::HashString(errorName); if (hashCode == UPDATE_IN_PROGRESS_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::UPDATE_IN_PROGRESS), false); } else if (hashCode == CLIENT_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::CLIENT), false); } else if (hashCode == CLUSTER_CONTAINS_CONTAINER_INSTANCES_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::CLUSTER_CONTAINS_CONTAINER_INSTANCES), false); } else if (hashCode == NO_UPDATE_AVAILABLE_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::NO_UPDATE_AVAILABLE), false); } else if (hashCode == CLUSTER_CONTAINS_SERVICES_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::CLUSTER_CONTAINS_SERVICES), false); } else if (hashCode == SERVER_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::SERVER), false); } else if (hashCode == CLUSTER_NOT_FOUND_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::CLUSTER_NOT_FOUND), false); } else if (hashCode == SERVICE_NOT_ACTIVE_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::SERVICE_NOT_ACTIVE), false); } else if (hashCode == INVALID_PARAMETER_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::INVALID_PARAMETER), false); } else if (hashCode == SERVICE_NOT_FOUND_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::SERVICE_NOT_FOUND), false); } else if (hashCode == MISSING_VERSION_HASH) { return AWSError<CoreErrors>(static_cast<CoreErrors>(ECSErrors::MISSING_VERSION), false); } return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false); } } // namespace ECSErrorMapper } // namespace ECS } // namespace Aws
39.278351
132
0.780577
prateek-s
f507306575457b08568e9284854ba429b23e8293
4,038
cpp
C++
pass/lec/pass_lec.cpp
arikyueh/livehd
cbbf13e77359cf135638b3710fd3ea4a6c895b68
[ "BSD-3-Clause" ]
1
2021-01-07T00:15:00.000Z
2021-01-07T00:15:00.000Z
pass/lec/pass_lec.cpp
arikyueh/livehd
cbbf13e77359cf135638b3710fd3ea4a6c895b68
[ "BSD-3-Clause" ]
null
null
null
pass/lec/pass_lec.cpp
arikyueh/livehd
cbbf13e77359cf135638b3710fd3ea4a6c895b68
[ "BSD-3-Clause" ]
null
null
null
// This file is distributed under the BSD 3-Clause License. See LICENSE for details. #include "pass_lec.hpp" #include <stdio.h> #include <stdlib.h> #include <cassert> #include <fstream> #include <iostream> #include <map> #include <string> #include "annotate.hpp" #include "boolector.h" #include "cell.hpp" #include "lbench.hpp" #include "lezminisat.hpp" #include "lezsat.hpp" #include "lgedgeiter.hpp" #include "lgraph.hpp" #include "node.hpp" #include "node_pin.hpp" static Pass_plugin sample("pass_lec", Pass_lec::setup); void Pass_lec::setup() { Eprp_method m1("pass.lec", "Checks if all the LGraph outputs are satisfiable", &Pass_lec::work); register_pass(m1); } Pass_lec::Pass_lec(const Eprp_var &var) : Pass("pass.lec", var) {} void Pass_lec::do_work(LGraph *g) { fmt::print("before check lec\n"); check_lec(g); fmt::print("inside do work\n"); } // do work: call function to get lgraph1, call function to get lgraph2, or get all lgraphs // call function to check equivalence void Pass_lec::work(Eprp_var &var) { Pass_lec p(var); for (const auto &g : var.lgs) { p.do_work(g); fmt::print("Lgraph Size: {}\n", var.lgs.size()); fmt::print("name: {}\n", g->get_name()); } } void Pass_lec::check_lec(LGraph *g) { fmt::print("**********BEGIN check LEC\n"); std::multimap<std::string, std::string> nodeMap; // fmt::print("TODO: implement LEC\n"); //------------------------------------------------- fmt::print("LGraph name: {}\n", g->get_name()); /* Btor *btor; BoolectorNode *input1, *input2, *formula1; BoolectorSort s; int result; btor = boolector_new(); s = boolector_bitvec_sort( btor, 8); input1 = boolector_var( btor, s, NULL); input2 = boolector_var( btor, s, NULL); */ // determine no of inputs int i_num = 0; int i_bits = 0; g->each_graph_input([&i_num, &i_bits](const Node_pin &pin) { i_num++; i_bits += pin.get_bits(); }); fmt::print("num of inputs: {}, no of Bits: {}\n", i_num, i_bits); // determine no of outputs int o_num = 0; int o_bits = 0; g->each_graph_output([&o_num, &o_bits](const Node_pin &pin) { o_num++; o_bits += pin.get_bits(); }); fmt::print("num of outputs: {}, no of Bits: {}\n", o_num, o_bits); for (const auto &node : g->forward()) { fmt::print("Node type: {}\n", node.get_type_name()); nodeMap.insert(std::make_pair(node.get_type_name(), g->get_name())); // fmt::print("No of edges: {}, input edges: {}, output edges: {}\n", node.get_num_edges(), node.get_num_inp_edges(), // node.get_num_out_edges() ); /* for (const auto &edge : node.inp_edges()){ auto indpin = edge.driver; auto indpin_pid = indpin.get_pid(); //auto inspin_pid = edge.sink.get_pid(); fmt::print("input edge driver pin id: {}\n", indpin_pid); //fmt::print("input edge sink pin id: {}\n", inspin_pid); }; for (const auto &edge : node.out_edges()){ //auto outdpin = edge.driver; //auto outdpin_pid = outdpin.get_pid(); auto outspin = edge.sink; auto outspin_pid = outspin.get_pid(); //fmt::print("output edge driver pid: {}\n", outdpin_pid); fmt::print("output edge sink pid: {}\n", outspin_pid); }; fmt::print("\n");*/ }; for (auto &p : nodeMap) { fmt::print("{}->{}\n", p.first, p.second); } fmt::print("No of Graphs for XOR: {}\n", nodeMap.count("XOR")); fmt::print("*************END check LEC\n"); /* //c = a ^ b formula1 = boolector_assert(btor, formula1); result = boolector_sat(btor); fmt::print("Expect: unsat\n"); fmt::print("Boolector: {}\n",result == BOOLECTOR_SAT ? "sat" : (result == BOOLECTOR_UNSAT ? "unsat":"unknown")); if(result != BOOLECTOR_UNSAT) { abort(); }; //clean up boolector_release( btor, input1); boolector_release( btor, input2); boolector_release( btor, formula1); boolector_release_sort( btor, s); assert (boolector_get_refs (btor) == 0); boolector_delete(btor);*/ }
26.220779
121
0.613175
arikyueh
f5077be0f98fc0eb8493d37079e3a16a8a72fd32
4,598
cpp
C++
sysid-application/src/test/native/cpp/analysis/FilterTest.cpp
Ocean-Moist/sysid
a7aa964fcfcc78cabcb7bfc02c8389d791acece5
[ "BSD-3-Clause" ]
null
null
null
sysid-application/src/test/native/cpp/analysis/FilterTest.cpp
Ocean-Moist/sysid
a7aa964fcfcc78cabcb7bfc02c8389d791acece5
[ "BSD-3-Clause" ]
null
null
null
sysid-application/src/test/native/cpp/analysis/FilterTest.cpp
Ocean-Moist/sysid
a7aa964fcfcc78cabcb7bfc02c8389d791acece5
[ "BSD-3-Clause" ]
null
null
null
// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. #include <array> #include <cmath> #include <vector> #include "gtest/gtest.h" #include "sysid/analysis/AnalysisManager.h" #include "sysid/analysis/FeedforwardAnalysis.h" #include "sysid/analysis/FilteringUtils.h" #include "sysid/analysis/Storage.h" TEST(FilterTest, MedianFilter) { std::vector<sysid::PreparedData> testData{ sysid::PreparedData{0_s, 0, 0, 0}, sysid::PreparedData{0_s, 0, 0, 1}, sysid::PreparedData{0_s, 0, 0, 10}, sysid::PreparedData{0_s, 0, 0, 5}, sysid::PreparedData{0_s, 0, 0, 3}, sysid::PreparedData{0_s, 0, 0, 0}, sysid::PreparedData{0_s, 0, 0, 1000}, sysid::PreparedData{0_s, 0, 0, 7}, sysid::PreparedData{0_s, 0, 0, 6}, sysid::PreparedData{0_s, 0, 0, 5}}; std::vector<sysid::PreparedData> expectedData{ sysid::PreparedData{0_s, 0, 0, 0}, sysid::PreparedData{0_s, 0, 0, 1}, sysid::PreparedData{0_s, 0, 0, 5}, sysid::PreparedData{0_s, 0, 0, 5}, sysid::PreparedData{0_s, 0, 0, 3}, sysid::PreparedData{0_s, 0, 0, 3}, sysid::PreparedData{0_s, 0, 0, 7}, sysid::PreparedData{0_s, 0, 0, 7}, sysid::PreparedData{0_s, 0, 0, 6}, sysid::PreparedData{0_s, 0, 0, 5}}; sysid::ApplyMedianFilter(&testData, 3); EXPECT_EQ(expectedData, testData); } TEST(FilterTest, AccelNoiseFloor) { std::vector<sysid::PreparedData> testData = { {0_s, 1, 2, 3, 5_ms, 0, 0}, {1_s, 1, 2, 3, 5_ms, 1, 0}, {2_s, 1, 2, 3, 5_ms, 2, 0}, {3_s, 1, 2, 3, 5_ms, 5, 0}, {4_s, 1, 2, 3, 5_ms, 0.35, 0}, {5_s, 1, 2, 3, 5_ms, 0.15, 0}, {6_s, 1, 2, 3, 5_ms, 0, 0}, {7_s, 1, 2, 3, 5_ms, 0.02, 0}, {8_s, 1, 2, 3, 5_ms, 0.01, 0}, {9_s, 1, 2, 3, 5_ms, 0, 0}}; double noiseFloor = GetAccelNoiseFloor(testData, 2); EXPECT_NEAR(0.953, noiseFloor, 0.001); } TEST(FilterTest, StepTrim) { std::vector<sysid::PreparedData> testData = { {0_s, 1, 2, 3, 5_ms, 0, 0}, {1_s, 1, 2, 3, 5_ms, 0.25, 0}, {2_s, 1, 2, 3, 5_ms, 0.5, 0}, {3_s, 1, 2, 3, 5_ms, 0.45, 0}, {4_s, 1, 2, 3, 5_ms, 0.35, 0}, {5_s, 1, 2, 3, 5_ms, 0.15, 0}, {6_s, 1, 2, 3, 5_ms, 0, 0}, {7_s, 1, 2, 3, 5_ms, 0.02, 0}, {8_s, 1, 2, 3, 5_ms, 0.01, 0}, {9_s, 1, 2, 3, 5_ms, 0, 0}, }; std::vector<sysid::PreparedData> expectedData = { {2_s, 1, 2, 3, 5_ms, 0.5, 0}, {3_s, 1, 2, 3, 5_ms, 0.45, 0}, {4_s, 1, 2, 3, 5_ms, 0.35, 0}, {5_s, 1, 2, 3, 5_ms, 0.15, 0}}; auto maxTime = 9_s; auto minTime = maxTime; sysid::AnalysisManager::Settings settings; minTime = sysid::TrimStepVoltageData(&testData, &settings, minTime, maxTime); EXPECT_EQ(expectedData[0].acceleration, testData[0].acceleration); EXPECT_EQ(expectedData.back().acceleration, testData.back().acceleration); EXPECT_EQ(5, settings.stepTestDuration.value()); EXPECT_EQ(2, minTime.value()); } TEST(FilterTest, CentralFiniteDifference) { constexpr double h = 0.05; auto CheckResults = [](auto&& f, auto&& dfdx, double h, double min, double max) { for (int i = min / h; i < max / h; ++i) { // The order of accuracy is O(h^(N - d)) where N is number of stencil // points and d is order of derivative EXPECT_NEAR(sysid::CentralFiniteDifference<2>(f, i, h), dfdx(i), std::max(std::pow(h, 3 - 1), 1e-7)); EXPECT_NEAR(sysid::CentralFiniteDifference<4>(f, i, h), dfdx(i), std::max(std::pow(h, 5 - 1), 1e-7)); EXPECT_NEAR(sysid::CentralFiniteDifference<6>(f, i, h), dfdx(i), std::max(std::pow(h, 7 - 1), 1e-7)); EXPECT_NEAR(sysid::CentralFiniteDifference<8>(f, i, h), dfdx(i), std::max(std::pow(h, 9 - 1), 1e-7)); } }; CheckResults( [=](int i) { // f(x) = x^2 double x = i * h; return x * x; }, [=](int i) { // df/dx = 2x double x = i * h; return 2.0 * x; }, h, -20.0, 20.0); CheckResults( [=](int i) { // f(x) = std::sin(x) double x = i * h; return std::sin(x); }, [=](int i) { // df/dx = std::cos(x) double x = i * h; return std::cos(x); }, h, -20.0, 20.0); CheckResults( [=](int i) { // f(x) = ln(x) double x = i * h; return std::log(x); }, [=](int i) { // df/dx = 1 / x double x = i * h; return 1.0 / x; }, h, 1.0, 20.0); }
35.643411
79
0.549369
Ocean-Moist
f5079addce6582eddf1063438ca371980684b40b
763
hpp
C++
Http/HttpHeader.hpp
westcoastcode-se/JsonSlave
60f12b39ed78644811b2c14fb877a14b9432b8f0
[ "MIT" ]
null
null
null
Http/HttpHeader.hpp
westcoastcode-se/JsonSlave
60f12b39ed78644811b2c14fb877a14b9432b8f0
[ "MIT" ]
null
null
null
Http/HttpHeader.hpp
westcoastcode-se/JsonSlave
60f12b39ed78644811b2c14fb877a14b9432b8f0
[ "MIT" ]
null
null
null
// // Created by Per Andersson on 2018-02-23. // Copyright (c) 2018 West Coast Code AB. All rights reserved. // #ifndef JSONSLAVE_HTTPHEADER_HPP #define JSONSLAVE_HTTPHEADER_HPP #include "../Config.hpp" /** * Object representing an Http Header */ struct HttpHeader { HttpHeader(const string& name, const string& value) : mName(name), mValue(value) {} explicit HttpHeader(const HttpHeader& rhs) : mName(rhs.mName), mValue(rhs.mValue) {} /** * @return The name of the header */ inline const string& GetName() const { return mName; } /** * @return The headers value */ inline const string& GetValue() const { return mValue; } int GetIntValue() const; private: string mName; string mValue; }; #endif //JSONSLAVE_HTTPHEADER_HPP
17.340909
62
0.693316
westcoastcode-se
f50c769f22f56795c196d396428ededb50524474
4,681
hpp
C++
src/sn_Meta/constexpr_container.hpp
Airtnp/SuperNaiveCppLib
0745aa79dc5060cd0f7025658164374b991c698e
[ "MIT" ]
4
2017-04-01T08:09:09.000Z
2017-05-20T11:35:58.000Z
src/sn_Meta/constexpr_container.hpp
Airtnp/ACppLib
0745aa79dc5060cd0f7025658164374b991c698e
[ "MIT" ]
null
null
null
src/sn_Meta/constexpr_container.hpp
Airtnp/ACppLib
0745aa79dc5060cd0f7025658164374b991c698e
[ "MIT" ]
null
null
null
#include "../sn_CommonHeader.h" namespace sn_Meta { namespace constexpr_container { // ref: https://github.com/ZaMaZaN4iK/constexpr_allocator/blob/master/test.cpp template <class T, unsigned N = 100> struct constexpr_allocator { T data[N] = {}; unsigned used = 0; using value_type = T; using pointer = T*; constexpr pointer allocate(unsigned s) { pointer ret = data + used; used += s; return ret; } template< class U, class... Args > constexpr void construct( U* p, Args&&... args ) { *p = T(std::forward<Args>(args)...); } template< class U > constexpr void destroy( U* ) {} constexpr void deallocate(T* p, unsigned n ) { if (data + used - n == p) used -= n; } static constexpr bool allocator_auto_cleanup = true; }; template <typename T, std::size_t N> class static_vector { private: std::size_t m_size = 0; // T m_data[N] {}; std::aligned_storage_t<sizeof(T), alignof(T)> m_data[N]; public: using iterator = T*; static_vector() {} constexpr std::size_t size() const { return m_size; } constexpr T& operator[](std::size_t n) { return *reinterpret_cast<T*>(m_data + n); } constexpr const T& operator[](std::size_t n) const { return *reinterpret_cast<const T*>(m_data + n); } constexpr iterator begin() { return m_data; } constexpr iterator end() { return (m_data + N); } template <typename ...Args> void emplace_back(Args&&... args) { if (m_size >= N) throw std::bad_alloc{}; new (m_data + m_size) T{std::forward<Args>(args)...}; ++m_size; } ~static_vector() { for (std::size_t pos = 0; pos < m_size; ++pos) { reinterpret_cast<T*>(m_data + pos)->~T(); } } }; template <typename T, typename ...Names> struct static_map { private: template <typename Name> struct element { using name = Name; explicit element(T v) : value(v) {} T value; }; public: template <typename ...Args> static_map(Args&&... args) : m_elements(std::make_tuple(elements<Args>(std::forward<Args>(args)...)) { static_assert(sizeof...(Names) == sizeof...(Args), "Not match."); } template <typename Name> decltype(auto) get() const { return std::get<element<Name>>(m_elements).value; } template <typename Name> void set(const T& v) { std::get<element<Name>>(m_elements).value = v; } template <typename Name> void set(T&& v) { std::get<element<Name>>(m_elements).value = std::move_if_noexcept(v); } private: std::tuple<element<Names>...> m_elements; }; template <typename T, std::size_t ...Dimensions> struct static_multi_array { constexpr const T& M_access() const { return M_data; } T M_data; }; template <typename T, std::size_t first, std::size_t ...rest> struct static_multi_array<T, first, rest...> { template <typename ...Args> constexpr const T& M_access(std::size_t first_idx, Args&&... rest_idxs) const { return M_arr[first_idx].M_access(rest_idxs...); } static_multi_array<T, rest...> M_arr[first]; }; template <typename T, std::size_t ...Dimensions> struct static_multi_access_array; template <typename T, std::size_t first, std::size_t ...rest> struct static_multi_access_array<T, first, rest...> { constexpr const T& operator[](std::size_t idx) const { return M_arr[idx]; } static_multi_access_array<T, rest...> M_arr[first]; }; template <typename T, std::size_t first> struct static_multi_access_array<T, first> { constexpr const T& operator[](std::size_t idx) const { return M_arr[idx]; } T M_arr[first]; }; } }
33.92029
91
0.493271
Airtnp
f50d4d8abb1d2ee2a788e59ad48c3d8aeba87dbd
23,483
cc
C++
chrome/browser/notifications/extension_welcome_notification_unittest.cc
lauer3912/chromium.src
969c559f5e43b329295b68c49ae9bf46a833395c
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
2
2019-01-16T03:57:28.000Z
2021-01-23T15:29:45.000Z
chrome/browser/notifications/extension_welcome_notification_unittest.cc
davgit/chromium.src
29b19806a790a12fb0a64ee148d019e27db350db
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
null
null
null
chrome/browser/notifications/extension_welcome_notification_unittest.cc
davgit/chromium.src
29b19806a790a12fb0a64ee148d019e27db350db
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
1
2017-03-15T13:21:38.000Z
2017-03-15T13:21:38.000Z
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/notifications/extension_welcome_notification.h" #include <string> #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/prefs/pref_service.h" #include "base/strings/utf_string_conversions.h" #include "base/test/test_simple_task_runner.h" #include "base/thread_task_runner_handle.h" #include "chrome/browser/notifications/notification.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_pref_service_syncable.h" #include "chrome/test/base/testing_profile.h" #include "components/user_prefs/pref_registry_syncable.h" #include "sync/api/fake_sync_change_processor.h" #include "sync/api/sync_error_factory_mock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/message_center/fake_message_center.h" #include "ui/message_center/notification.h" const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; class MockMessageCenter : public message_center::FakeMessageCenter { public: MockMessageCenter() : add_notification_calls_(0), remove_notification_calls_(0), notifications_with_shown_as_popup_(0) { } int add_notification_calls() { return add_notification_calls_; } int remove_notification_calls() { return remove_notification_calls_; } int notifications_with_shown_as_popup() { return notifications_with_shown_as_popup_; } // message_center::FakeMessageCenter Overrides virtual bool HasNotification(const std::string& id) OVERRIDE { return last_notification.get() && (last_notification->id() == id); } virtual void AddNotification( scoped_ptr<message_center::Notification> notification) OVERRIDE { EXPECT_FALSE(last_notification.get()); last_notification.swap(notification); add_notification_calls_++; if (last_notification->shown_as_popup()) notifications_with_shown_as_popup_++; } virtual void RemoveNotification(const std::string& id, bool by_user) OVERRIDE { EXPECT_TRUE(last_notification.get()); last_notification.reset(); remove_notification_calls_++; } void CloseCurrentNotification() { EXPECT_TRUE(last_notification.get()); last_notification->delegate()->Close(true); RemoveNotification(last_notification->id(), true); } private: scoped_ptr<message_center::Notification> last_notification; int add_notification_calls_; int remove_notification_calls_; int notifications_with_shown_as_popup_; DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); }; class WelcomeNotificationDelegate : public ExtensionWelcomeNotification::Delegate { public: WelcomeNotificationDelegate() : start_time_(base::Time::Now()), message_center_(new MockMessageCenter()) { } // ExtensionWelcomeNotification::Delegate virtual message_center::MessageCenter* GetMessageCenter() OVERRIDE { return message_center_.get(); } virtual base::Time GetCurrentTime() OVERRIDE { return start_time_ + elapsed_time_; } virtual void PostTask( const tracked_objects::Location& from_here, const base::Closure& task) OVERRIDE { EXPECT_TRUE(pending_task_.is_null()); pending_task_ = task; } // WelcomeNotificationDelegate MockMessageCenter* message_center() const { return message_center_.get(); } base::Time GetStartTime() const { return start_time_; } void SetElapsedTime(base::TimeDelta elapsed_time) { elapsed_time_ = elapsed_time; } void RunPendingTask() { base::Closure task_to_run = pending_task_; pending_task_.Reset(); task_to_run.Run(); } private: const base::Time start_time_; base::TimeDelta elapsed_time_; scoped_ptr<MockMessageCenter> message_center_; base::Closure pending_task_; DISALLOW_COPY_AND_ASSIGN(WelcomeNotificationDelegate); }; class ExtensionWelcomeNotificationTest : public testing::Test { protected: ExtensionWelcomeNotificationTest() { scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry( new user_prefs::PrefRegistrySyncable()); ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get()); } virtual void SetUp() { task_runner_ = new base::TestSimpleTaskRunner(); thread_task_runner_handle_.reset( new base::ThreadTaskRunnerHandle(task_runner_)); profile_.reset(new TestingProfile()); delegate_ = new WelcomeNotificationDelegate(); welcome_notification_ = ExtensionWelcomeNotification::Create( kChromeNowExtensionID, profile_.get(), delegate_); } virtual void TearDown() { delegate_ = NULL; welcome_notification_.reset(); profile_.reset(); thread_task_runner_handle_.reset(); task_runner_ = NULL; } void StartPreferenceSyncing() const { PrefServiceSyncable::FromProfile(profile_.get()) ->GetSyncableService(syncer::PREFERENCES) ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), scoped_ptr<syncer::SyncChangeProcessor>( new syncer::FakeSyncChangeProcessor), scoped_ptr<syncer::SyncErrorFactory>( new syncer::SyncErrorFactoryMock())); } void ShowChromeNowNotification() const { ShowNotification( "ChromeNowNotification", message_center::NotifierId(message_center::NotifierId::APPLICATION, kChromeNowExtensionID)); } void ShowRegularNotification() const { ShowNotification( "RegularNotification", message_center::NotifierId(message_center::NotifierId::APPLICATION, "aaaabbbbccccddddeeeeffffggghhhhi")); } void FlushMessageLoop() { delegate_->RunPendingTask(); } MockMessageCenter* message_center() const { return delegate_->message_center(); } base::TestSimpleTaskRunner* task_runner() const { return task_runner_.get(); } base::Time GetStartTime() const { return delegate_->GetStartTime(); } void SetElapsedTime(base::TimeDelta elapsed_time) const { delegate_->SetElapsedTime(elapsed_time); } bool GetBooleanPref(const char* path) const { return profile_->GetPrefs()->GetBoolean(path); } void SetBooleanPref(const char* path, bool value) const { profile_->GetPrefs()->SetBoolean(path, value); } int64 GetInt64Pref(const char* path) const { return profile_->GetPrefs()->GetInt64(path); } void SetInt64Pref(const char* path, int64 value) const { profile_->GetPrefs()->SetInt64(path, value); } private: class TestNotificationDelegate : public NotificationDelegate { public: explicit TestNotificationDelegate(const std::string& id) : id_(id) {} // Overridden from NotificationDelegate: virtual void Display() OVERRIDE {} virtual void Error() OVERRIDE {} virtual void Close(bool by_user) OVERRIDE {} virtual void Click() OVERRIDE {} virtual void ButtonClick(int index) OVERRIDE {} virtual std::string id() const OVERRIDE { return id_; } virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { return NULL; } private: virtual ~TestNotificationDelegate() {} const std::string id_; DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate); }; void ShowNotification(std::string notification_id, const message_center::NotifierId& notifier_id) const { message_center::RichNotificationData rich_notification_data; rich_notification_data.priority = 0; Notification notification(message_center::NOTIFICATION_TYPE_BASE_FORMAT, GURL("http://tests.url"), base::UTF8ToUTF16("Title"), base::UTF8ToUTF16("Body"), gfx::Image(), blink::WebTextDirectionDefault, notifier_id, base::UTF8ToUTF16("Source"), base::UTF8ToUTF16(notification_id), rich_notification_data, new TestNotificationDelegate("TestNotification")); welcome_notification_->ShowWelcomeNotificationIfNecessary(notification); } scoped_refptr<base::TestSimpleTaskRunner> task_runner_; scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; scoped_ptr<TestingProfile> profile_; // Weak Ref owned by welcome_notification_ WelcomeNotificationDelegate* delegate_; scoped_ptr<ExtensionWelcomeNotification> welcome_notification_; DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest); }; // Show a regular notification. Expect that WelcomeNotification will // not show a welcome notification. TEST_F(ExtensionWelcomeNotificationTest, FirstRunShowRegularNotification) { StartPreferenceSyncing(); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowRegularNotification(); EXPECT_EQ(message_center()->add_notification_calls(), 0); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Show a Chrome Now notification. Expect that WelcomeNotification will // show a welcome notification. TEST_F(ExtensionWelcomeNotificationTest, FirstRunChromeNowNotification) { StartPreferenceSyncing(); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); EXPECT_EQ(message_center()->add_notification_calls(), 1); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Show a Chrome Now notification that was already shown before. TEST_F(ExtensionWelcomeNotificationTest, ShowWelcomeNotificationAgain) { StartPreferenceSyncing(); SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); EXPECT_EQ(message_center()->add_notification_calls(), 1); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 1); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Don't show a welcome notification if it was previously dismissed on another // machine that wrote the synced flag. TEST_F(ExtensionWelcomeNotificationTest, WelcomeNotificationPreviouslyDismissed) { StartPreferenceSyncing(); SetBooleanPref(prefs::kWelcomeNotificationDismissed, true); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); EXPECT_EQ(message_center()->add_notification_calls(), 0); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Don't show a welcome notification if it was previously dismissed on this // machine. TEST_F(ExtensionWelcomeNotificationTest, WelcomeNotificationPreviouslyDismissedLocal) { StartPreferenceSyncing(); SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); EXPECT_EQ(message_center()->add_notification_calls(), 0); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Don't show a welcome notification if it was previously dismissed with the // local flag and synced flag. This case is possible but rare. TEST_F(ExtensionWelcomeNotificationTest, WelcomeNotificationPreviouslyDismissedSyncedAndLocal) { StartPreferenceSyncing(); SetBooleanPref(prefs::kWelcomeNotificationDismissed, true); SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); EXPECT_EQ(message_center()->add_notification_calls(), 0); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Show a Chrome Now notification and dismiss it. // Expect welcome toast dismissed to be true. TEST_F(ExtensionWelcomeNotificationTest, DismissWelcomeNotification) { StartPreferenceSyncing(); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); message_center()->CloseCurrentNotification(); FlushMessageLoop(); EXPECT_EQ(message_center()->add_notification_calls(), 1); EXPECT_EQ(message_center()->remove_notification_calls(), 1); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Show a Chrome Now notification and dismiss it via a synced preference change. // Expect welcome toast dismissed to be true. TEST_F(ExtensionWelcomeNotificationTest, SyncedDismissalWelcomeNotification) { StartPreferenceSyncing(); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); SetBooleanPref(prefs::kWelcomeNotificationDismissed, true); EXPECT_EQ(message_center()->add_notification_calls(), 1); EXPECT_EQ(message_center()->remove_notification_calls(), 1); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Simulate a delayed preference sync when the welcome notification was // previously dismissed. TEST_F(ExtensionWelcomeNotificationTest, DelayedPreferenceSyncPreviouslyDismissed) { // Show a notification while the preference system is not syncing. EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); EXPECT_EQ(message_center()->add_notification_calls(), 0); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); // Now start the preference syncing with a previously dismissed welcome. SetBooleanPref(prefs::kWelcomeNotificationDismissed, true); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); StartPreferenceSyncing(); EXPECT_EQ(message_center()->add_notification_calls(), 0); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Simulate a delayed preference sync when the welcome notification was // never shown. TEST_F(ExtensionWelcomeNotificationTest, DelayedPreferenceSyncNeverShown) { // Show a notification while the preference system is not syncing. EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); ShowChromeNowNotification(); EXPECT_EQ(message_center()->add_notification_calls(), 0); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); // Now start the preference syncing with the default preference values. EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); StartPreferenceSyncing(); EXPECT_EQ(message_center()->add_notification_calls(), 1); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); } // Simulate the passage of time when the welcome notification // automatically dismisses. TEST_F(ExtensionWelcomeNotificationTest, TimeExpiredNotification) { StartPreferenceSyncing(); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 0); EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); ShowChromeNowNotification(); base::TimeDelta requested_show_time = base::TimeDelta::FromDays( ExtensionWelcomeNotification::kRequestedShowTimeDays); EXPECT_EQ(task_runner()->GetPendingTasks().size(), 1U); EXPECT_EQ(task_runner()->NextPendingTaskDelay(), requested_show_time); EXPECT_EQ(message_center()->add_notification_calls(), 1); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); EXPECT_EQ( GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), (GetStartTime() + requested_show_time).ToInternalValue()); SetElapsedTime(requested_show_time); task_runner()->RunPendingTasks(); EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); EXPECT_EQ(message_center()->add_notification_calls(), 1); EXPECT_EQ(message_center()->remove_notification_calls(), 1); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); EXPECT_EQ( GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), (GetStartTime() + requested_show_time).ToInternalValue()); } // Simulate the passage of time after Chrome is closed and the welcome // notification expiration elapses. TEST_F(ExtensionWelcomeNotificationTest, NotificationPreviouslyExpired) { StartPreferenceSyncing(); SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true); SetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp, 1); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1); EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); const base::TimeDelta requested_show_time = base::TimeDelta::FromDays( ExtensionWelcomeNotification::kRequestedShowTimeDays); SetElapsedTime(requested_show_time); ShowChromeNowNotification(); EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); EXPECT_EQ(message_center()->add_notification_calls(), 0); EXPECT_EQ(message_center()->remove_notification_calls(), 0); EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1); } // C++ Readability Review Change Trigger
42.618875
80
0.780139
lauer3912
f5149fc85697799341bd95957e366a8f970a9d35
6,025
cc
C++
source/exe/main_common.cc
jaricftw/envoy
766f3fb8dbdafce402631c43c16fda46ed003462
[ "Apache-2.0" ]
1
2019-11-19T22:27:58.000Z
2019-11-19T22:27:58.000Z
source/exe/main_common.cc
jaricftw/envoy
766f3fb8dbdafce402631c43c16fda46ed003462
[ "Apache-2.0" ]
null
null
null
source/exe/main_common.cc
jaricftw/envoy
766f3fb8dbdafce402631c43c16fda46ed003462
[ "Apache-2.0" ]
null
null
null
#include "exe/main_common.h" #include <iostream> #include <memory> #include <new> #include "common/common/compiler_requirements.h" #include "common/common/perf_annotation.h" #include "common/network/utility.h" #include "common/stats/symbol_table_creator.h" #include "common/stats/thread_local_store.h" #include "server/config_validation/server.h" #include "server/drain_manager_impl.h" #include "server/hot_restart_nop_impl.h" #include "server/listener_hooks.h" #include "server/options_impl.h" #include "server/server.h" #include "absl/strings/str_split.h" #ifdef ENVOY_HOT_RESTART #include "server/hot_restart_impl.h" #endif namespace Envoy { Server::DrainManagerPtr ProdComponentFactory::createDrainManager(Server::Instance& server) { // The global drain manager only triggers on listener modification, which effectively is // hot restart at the global level. The per-listener drain managers decide whether to // to include /healthcheck/fail status. return std::make_unique<Server::DrainManagerImpl>(server, envoy::api::v2::Listener_DrainType_MODIFY_ONLY); } Runtime::LoaderPtr ProdComponentFactory::createRuntime(Server::Instance& server, Server::Configuration::Initial& config) { return Server::InstanceUtil::createRuntime(server, config); } MainCommonBase::MainCommonBase(const OptionsImpl& options, Event::TimeSystem& time_system, ListenerHooks& listener_hooks, Server::ComponentFactory& component_factory, std::unique_ptr<Runtime::RandomGenerator>&& random_generator, Thread::ThreadFactory& thread_factory, Filesystem::Instance& file_system, std::unique_ptr<ProcessContext> process_context) : options_(options), component_factory_(component_factory), thread_factory_(thread_factory), file_system_(file_system), symbol_table_(Stats::SymbolTableCreator::initAndMakeSymbolTable( options_.fakeSymbolTableEnabled())), stats_allocator_(*symbol_table_) { switch (options_.mode()) { case Server::Mode::InitOnly: case Server::Mode::Serve: { #ifdef ENVOY_HOT_RESTART if (!options.hotRestartDisabled()) { restarter_ = std::make_unique<Server::HotRestartImpl>(options_); } #endif if (restarter_ == nullptr) { restarter_ = std::make_unique<Server::HotRestartNopImpl>(); } tls_ = std::make_unique<ThreadLocal::InstanceImpl>(); Thread::BasicLockable& log_lock = restarter_->logLock(); Thread::BasicLockable& access_log_lock = restarter_->accessLogLock(); auto local_address = Network::Utility::getLocalAddress(options_.localAddressIpVersion()); logging_context_ = std::make_unique<Logger::Context>(options_.logLevel(), options_.logFormat(), log_lock, options_.logFormatEscaped()); configureComponentLogLevels(); // Provide consistent behavior for out-of-memory, regardless of whether it occurs in a try/catch // block or not. std::set_new_handler([]() { PANIC("out of memory"); }); stats_store_ = std::make_unique<Stats::ThreadLocalStoreImpl>(stats_allocator_); server_ = std::make_unique<Server::InstanceImpl>( *init_manager_, options_, time_system, local_address, listener_hooks, *restarter_, *stats_store_, access_log_lock, component_factory, std::move(random_generator), *tls_, thread_factory_, file_system_, std::move(process_context)); break; } case Server::Mode::Validate: restarter_ = std::make_unique<Server::HotRestartNopImpl>(); logging_context_ = std::make_unique<Logger::Context>(options_.logLevel(), options_.logFormat(), restarter_->logLock(), options_.logFormatEscaped()); break; } } void MainCommonBase::configureComponentLogLevels() { for (auto& component_log_level : options_.componentLogLevels()) { Logger::Logger* logger_to_change = Logger::Registry::logger(component_log_level.first); ASSERT(logger_to_change); logger_to_change->setLevel(component_log_level.second); } } bool MainCommonBase::run() { switch (options_.mode()) { case Server::Mode::Serve: server_->run(); return true; case Server::Mode::Validate: { auto local_address = Network::Utility::getLocalAddress(options_.localAddressIpVersion()); return Server::validateConfig(options_, local_address, component_factory_, thread_factory_, file_system_); } case Server::Mode::InitOnly: PERF_DUMP(); return true; } NOT_REACHED_GCOVR_EXCL_LINE; } void MainCommonBase::adminRequest(absl::string_view path_and_query, absl::string_view method, const AdminRequestFn& handler) { std::string path_and_query_buf = std::string(path_and_query); std::string method_buf = std::string(method); server_->dispatcher().post([this, path_and_query_buf, method_buf, handler]() { Http::HeaderMapImpl response_headers; std::string body; server_->admin().request(path_and_query_buf, method_buf, response_headers, body); handler(response_headers, body); }); } MainCommon::MainCommon(int argc, const char* const* argv) : options_(argc, argv, &MainCommon::hotRestartVersion, spdlog::level::info), base_(options_, real_time_system_, default_listener_hooks_, prod_component_factory_, std::make_unique<Runtime::RandomGeneratorImpl>(), platform_impl_.threadFactory(), platform_impl_.fileSystem(), nullptr) {} std::string MainCommon::hotRestartVersion(bool hot_restart_enabled) { #ifdef ENVOY_HOT_RESTART if (hot_restart_enabled) { return Server::HotRestartImpl::hotRestartVersion(); } #else UNREFERENCED_PARAMETER(hot_restart_enabled); #endif return "disabled"; } } // namespace Envoy
40.166667
100
0.693942
jaricftw
f514cd1557537062b2cd1c09206d7872e05c2932
1,401
hpp
C++
red-microdnf/microdnf/utils.hpp
redpesk-labs/red-pak
bd11881f50ae627a0641448ae0b307a9a9e2877e
[ "Apache-2.0" ]
5
2021-02-24T09:00:36.000Z
2022-02-10T16:37:10.000Z
red-microdnf/microdnf/utils.hpp
redpesk-labs/red-pak
bd11881f50ae627a0641448ae0b307a9a9e2877e
[ "Apache-2.0" ]
null
null
null
red-microdnf/microdnf/utils.hpp
redpesk-labs/red-pak
bd11881f50ae627a0641448ae0b307a9a9e2877e
[ "Apache-2.0" ]
null
null
null
/* Copyright (C) 2020 Red Hat, Inc. This file is part of microdnf: https://github.com/rpm-software-management/libdnf/ Microdnf 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. Microdnf 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 microdnf. If not, see <https://www.gnu.org/licenses/>. */ #ifndef MICRODNF_UTILS_HPP #define MICRODNF_UTILS_HPP #include <libdnf/base/goal.hpp> #include <sys/types.h> #include <string> namespace microdnf { /// Returns "true" if program runs with effective user ID = 0 bool am_i_root() noexcept; /// Gets the login uid, if available. /// The getuid() is returned instead if there was a problem. /// The value is cached. uid_t get_login_uid() noexcept; /// find the base architecture const char * get_base_arch(const char * arch); /// detect hardware architecture std::string detect_arch(); /// detect operation system release std::string detect_release(const std::string & install_root_path); } // namespace microdnf #endif
28.02
81
0.763026
redpesk-labs
f5187d31fc1fbf92b7f30daeeb15c9943d766215
6,011
cpp
C++
async_simple/coro/test/ConditionVariableTest.cpp
ChuanqiXu9/async_simple
5b93ea57e8b96a366909a657049140c8a54f6873
[ "Apache-2.0" ]
169
2022-02-17T02:59:37.000Z
2022-03-31T12:40:58.000Z
async_simple/coro/test/ConditionVariableTest.cpp
ChuanqiXu9/async_simple
5b93ea57e8b96a366909a657049140c8a54f6873
[ "Apache-2.0" ]
49
2022-02-21T04:49:36.000Z
2022-03-31T04:22:04.000Z
async_simple/coro/test/ConditionVariableTest.cpp
ChuanqiXu9/async_simple
5b93ea57e8b96a366909a657049140c8a54f6873
[ "Apache-2.0" ]
35
2022-02-21T03:29:28.000Z
2022-03-31T09:36:54.000Z
/* * Copyright (c) 2022, Alibaba Group Holding Limited; * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <async_simple/coro/ConditionVariable.h> #include <async_simple/coro/Lazy.h> #include <async_simple/coro/SpinLock.h> #include <async_simple/executors/SimpleExecutor.h> #include <async_simple/test/unittest.h> #include <chrono> using namespace std::chrono_literals; namespace async_simple { namespace coro { #define CHECK_EXECUTOR(ex) \ do { \ EXPECT_TRUE((ex)->currentThreadInExecutor()) << (ex)->name(); \ auto current = co_await CurrentExecutor(); \ EXPECT_EQ((ex), current) << (ex)->name(); \ } while (0) class ConditionVariableTest : public FUTURE_TESTBASE { public: ConditionVariableTest() : _executor(2) {} void caseSetUp() override {} void caseTearDown() override {} executors::SimpleExecutor _executor; }; TEST_F(ConditionVariableTest, testSingleWait) { auto data = 0; Notifier notifier; std::atomic<size_t> latch(2); executors::SimpleExecutor e1(1); executors::SimpleExecutor e2(1); auto producer = [&]() -> Lazy<void> { data = 1; CHECK_EXECUTOR(&e2); notifier.notify(); CHECK_EXECUTOR(&e2); latch.fetch_sub(1u, std::memory_order_relaxed); co_return; }; auto awaiter = [&]() -> Lazy<void> { CHECK_EXECUTOR(&e1); co_await notifier.wait(); CHECK_EXECUTOR(&e1); EXPECT_EQ(1, data); data = 2; latch.fetch_sub(1u, std::memory_order_relaxed); co_return; }; awaiter().via(&e1).start([](Try<void> var) {}); producer().via(&e2).start([](Try<void> var) {}); while (latch.load(std::memory_order_relaxed)) ; EXPECT_EQ(2, data); } TEST_F(ConditionVariableTest, testMultiWait) { auto data = 0; Notifier notifier; std::atomic<int> barrier(0); auto producer = [&]() -> Lazy<void> { std::this_thread::sleep_for(100us); data = 1; notifier.notify(); co_return; }; auto awaiter1 = [&]() -> Lazy<void> { co_await notifier.wait(); EXPECT_EQ(1, data); barrier.fetch_add(1, std::memory_order_relaxed); co_return; }; auto awaiter2 = [&]() -> Lazy<void> { co_await notifier.wait(); EXPECT_EQ(1, data); barrier.fetch_add(1, std::memory_order_relaxed); co_return; }; awaiter2().via(&_executor).start([](Try<void> var) {}); awaiter1().via(&_executor).start([](Try<void> var) {}); producer().via(&_executor).start([](Try<void> var) {}); // spin wait while (barrier.load(std::memory_order_relaxed) < 2) ; notifier.reset(); std::atomic<size_t> latch(2); auto producer2 = [&]() -> Lazy<void> { data = 0; notifier.notify(); latch.fetch_sub(1u, std::memory_order_relaxed); co_return; }; auto awaiter3 = [&]() -> Lazy<void> { co_await notifier.wait(); EXPECT_EQ(0, data); latch.fetch_sub(1u, std::memory_order_relaxed); co_return; }; producer2().via(&_executor).start([](Try<void> var) {}); awaiter3().via(&_executor).start([](Try<void> var) {}); while (latch.load(std::memory_order_relaxed)) ; EXPECT_EQ(0, data); } TEST_F(ConditionVariableTest, testSingleWaitPredicate) { SpinLock mutex; ConditionVariable<SpinLock> cv; auto var = 0; executors::SimpleExecutor e1(1); executors::SimpleExecutor e2(1); std::atomic<size_t> latch(2); auto producer = [&]() -> Lazy<void> { CHECK_EXECUTOR(&e2); co_await mutex.coLock(); CHECK_EXECUTOR(&e2); var = 1; cv.notify(); CHECK_EXECUTOR(&e2); std::this_thread::sleep_for(500us); mutex.unlock(); CHECK_EXECUTOR(&e2); latch.fetch_sub(1u, std::memory_order_relaxed); co_return; }; auto awaiter = [&]() -> Lazy<void> { CHECK_EXECUTOR(&e1); co_await mutex.coLock(); CHECK_EXECUTOR(&e1); co_await cv.wait(mutex, [&] { return var > 0; }); CHECK_EXECUTOR(&e1); mutex.unlock(); CHECK_EXECUTOR(&e1); EXPECT_EQ(1, var); latch.fetch_sub(1u, std::memory_order_relaxed); co_return; }; awaiter().via(&e1).start([](Try<void> var) {}); producer().via(&e2).start([](Try<void> var) {}); while (latch.load(std::memory_order_relaxed)) ; } TEST_F(ConditionVariableTest, testSingleWaitPredicateWithScopeLock) { SpinLock mutex; ConditionVariable<SpinLock> cv; auto var = 0; std::atomic<size_t> latch(2); auto producer = [&]() -> Lazy<void> { auto scoper = co_await mutex.coScopedLock(); var = 1; cv.notify(); latch.fetch_sub(1u, std::memory_order_relaxed); co_return; }; auto awaiter = [&]() -> Lazy<void> { auto scoper = co_await mutex.coScopedLock(); co_await cv.wait(mutex, [&] { return var > 0; }); EXPECT_EQ(1, var); latch.fetch_sub(1u, std::memory_order_relaxed); co_return; }; awaiter().via(&_executor).start([](Try<void> var) {}); producer().via(&_executor).start([](Try<void> var) {}); while (latch.load(std::memory_order_relaxed)) ; } } // namespace coro } // namespace async_simple
30.825641
75
0.593745
ChuanqiXu9
f5192f27d84eb1105012a99e9f3b294bbd955f7c
11,164
hpp
C++
src/data_structures/APR/ExtraParticleData.hpp
BioDataAnalysis/LibAPR
16cce980061d9210ed82258d6893e4c7b07782ec
[ "Apache-2.0" ]
null
null
null
src/data_structures/APR/ExtraParticleData.hpp
BioDataAnalysis/LibAPR
16cce980061d9210ed82258d6893e4c7b07782ec
[ "Apache-2.0" ]
null
null
null
src/data_structures/APR/ExtraParticleData.hpp
BioDataAnalysis/LibAPR
16cce980061d9210ed82258d6893e4c7b07782ec
[ "Apache-2.0" ]
null
null
null
// // Created by cheesema on 16.01.18. // #ifndef PARTPLAY_EXTRAPARTICLEDATA_HPP #define PARTPLAY_EXTRAPARTICLEDATA_HPP #include <algorithm> template<typename V> class APR; template<typename V> class APRIterator; template<typename V> class APRTree; template<typename DataType> class ExtraParticleData { private: static const uint64_t parallel_particle_number_threshold = 5000000l; public: std::vector<DataType> data; ExtraParticleData() {}; template<typename S> ExtraParticleData(const APR<S> &apr) { init(apr); } template<typename S> ExtraParticleData(const APRTree<S> &apr_tree) { init_tree(apr_tree); } template<typename S> void init(const APR<S> &apr){ data.resize(apr.total_number_particles()); } template<typename S> void init_tree(const APRTree<S> &apr_tree){ //initialization when using with APRTree class data.resize(apr_tree.total_number_parent_cells()); } uint64_t total_number_particles() const { return data.size(); } /** * Access particle via iterator * @param apr_iterator * @return reference to stored particle */ template<typename S> DataType& operator[](const APRIterator<S>& apr_iterator) { return data[apr_iterator.global_index()]; } template<typename S> DataType get_particle(const APRIterator<S>& apr_iterator) const { return data[apr_iterator.global_index()]; } template<typename S> void set_particle(const APRIterator<S>& apr_iterator, DataType set_val) { data[apr_iterator.global_index()] = set_val; } /** * Copy's the data from one particle dataset to another */ template<typename S,typename T> void copy_parts(APR<T> &apr, const ExtraParticleData<S> &particlesToCopy, uint64_t level = 0, unsigned int aNumberOfBlocks = 10) { const uint64_t total_number_of_particles = particlesToCopy.data.size(); //checking if its the right size, if it is, this should do nothing. data.resize(total_number_of_particles); APRIterator<T> apr_iterator(apr); size_t particle_number_start; size_t particle_number_stop; if (level==0){ particle_number_start = 0; particle_number_stop = total_number_of_particles; } else { particle_number_start = apr_iterator.particles_level_begin(level); particle_number_stop = apr_iterator.particles_level_end(level); } //determine if openMP should be used. size_t total_particles_to_iterate = particle_number_stop - particle_number_start; if (total_particles_to_iterate < parallel_particle_number_threshold) { aNumberOfBlocks = 1; } const size_t numOfElementsPerBlock = total_particles_to_iterate/aNumberOfBlocks; #ifdef HAVE_OPENMP #pragma omp parallel for schedule(static) #endif for (unsigned int blockNum = 0; blockNum < aNumberOfBlocks; ++blockNum) { size_t offsetBegin = particle_number_start + blockNum * numOfElementsPerBlock; size_t offsetEnd = offsetBegin + numOfElementsPerBlock; if (blockNum == aNumberOfBlocks - 1) { // Handle tailing elements if number of blocks does not divide. offsetEnd = particle_number_stop; } //Operation to be performed on the chunk std::copy(particlesToCopy.data.begin() + offsetBegin, particlesToCopy.data.begin() + offsetEnd, data.begin() + offsetBegin); } } /** * Takes two particle data sets and adds them, and puts it in the first one * Bevan Cheeseman 2017 * TODO: zip and zip_inplace are doing technicaly same thing - merge them */ template<typename V,class BinaryOperation,typename T> void zip_inplace(APR<T> &apr, const ExtraParticleData<V> &parts2, BinaryOperation op, uint64_t level = 0, unsigned int aNumberOfBlocks = 10) { APRIterator<T> apr_iterator(apr); size_t particle_number_start; size_t particle_number_stop; if (level==0) { particle_number_start = 0; particle_number_stop = total_number_particles(); } else { particle_number_start = apr_iterator.particles_level_begin(level); particle_number_stop = apr_iterator.particles_level_end(level); } //determine if openMP should be used. size_t total_particles_to_iterate = particle_number_stop - particle_number_start; if (total_particles_to_iterate < parallel_particle_number_threshold) { aNumberOfBlocks = 1; } const size_t numOfElementsPerBlock = total_particles_to_iterate/aNumberOfBlocks; #ifdef HAVE_OPENMP #pragma omp parallel for schedule(static) #endif for (unsigned int blockNum = 0; blockNum < aNumberOfBlocks; ++blockNum) { size_t offsetBegin = particle_number_start + blockNum * numOfElementsPerBlock; size_t offsetEnd = offsetBegin + numOfElementsPerBlock; if (blockNum == aNumberOfBlocks - 1) { // Handle tailing elements if number of blocks does not divide. offsetEnd = particle_number_stop; } //Operation to be performed on the chunk std::transform(data.begin() + offsetBegin, data.begin() + offsetEnd, parts2.data.begin() + offsetBegin, data.begin() + offsetBegin, op); } } /** * Takes two particle data sets and adds them, and puts it in the output * Bevan Cheeseman 2017 */ template<typename V,class BinaryOperation,typename T> void zip(APR<T>& apr, const ExtraParticleData<V> &parts2, ExtraParticleData<V>& output, BinaryOperation op, uint64_t level = 0, unsigned int aNumberOfBlocks = 10) { output.data.resize(data.size()); APRIterator<T> apr_iterator(apr); size_t particle_number_start; size_t particle_number_stop; if (level==0) { particle_number_start = 0; particle_number_stop = total_number_particles(); } else { particle_number_start = apr_iterator.particles_level_begin(level); particle_number_stop = apr_iterator.particles_level_end(level); } //determine if openMP should be used. size_t total_particles_to_iterate = particle_number_stop - particle_number_start; if (total_particles_to_iterate < parallel_particle_number_threshold) { aNumberOfBlocks = 1; } const size_t numOfElementsPerBlock = total_particles_to_iterate/aNumberOfBlocks; #ifdef HAVE_OPENMP #pragma omp parallel for schedule(static) #endif for (unsigned int blockNum = 0; blockNum < aNumberOfBlocks; ++blockNum) { size_t offsetBegin = particle_number_start + blockNum * numOfElementsPerBlock; size_t offsetEnd = offsetBegin + numOfElementsPerBlock; if (blockNum == aNumberOfBlocks - 1) { // Handle tailing elements if number of blocks does not divide. offsetEnd = particle_number_stop; } //Operation to be performed on the chunk std::transform(data.begin() + offsetBegin, data.begin() + offsetEnd, parts2.data.begin() + offsetBegin, output.data.begin() + offsetBegin, op); } } /** * Performs a unary operator on a particle dataset in parrallel and returns it in output * Bevan Cheeseman 2018 * TODO: map and map_inplace are doing technicaly same thing - merge them */ template<typename T,typename U,class UnaryOperator> void map(APR<T>& apr,ExtraParticleData<U>& output,UnaryOperator op,const uint64_t level = 0,unsigned int aNumberOfBlocks = 10){ output.data.resize(data.size()); APRIterator<T> apr_iterator(apr); size_t particle_number_start; size_t particle_number_stop; if (level==0) { particle_number_start=0; particle_number_stop = total_number_particles(); } else { particle_number_start = apr_iterator.particles_level_begin(level); particle_number_stop = apr_iterator.particles_level_end(level); } //determine if openMP should be used. size_t total_particles_to_iterate = particle_number_stop - particle_number_start; if (total_particles_to_iterate < parallel_particle_number_threshold) { aNumberOfBlocks = 1; } const size_t numOfElementsPerBlock = total_particles_to_iterate/aNumberOfBlocks; #ifdef HAVE_OPENMP #pragma omp parallel for schedule(static) #endif for (unsigned int blockNum = 0; blockNum < aNumberOfBlocks; ++blockNum) { size_t offsetBegin = particle_number_start + blockNum * numOfElementsPerBlock; size_t offsetEnd = offsetBegin + numOfElementsPerBlock; if (blockNum == aNumberOfBlocks - 1) { // Handle tailing elements if number of blocks does not divide. offsetEnd = particle_number_stop; } //Operation to be performed on the chunk std::transform(data.begin() + offsetBegin,data.begin() + offsetEnd, output.data.begin() + offsetBegin, op); } } /** * Performs a unary operator on a particle dataset inplace in parrallel * Bevan Cheeseman 2018 */ template<class UnaryOperator,typename T> void map_inplace(APR<T>& apr,UnaryOperator op,const uint64_t level = 0,unsigned int aNumberOfBlocks = 10){ APRIterator<T> apr_iterator(apr); size_t particle_number_start; size_t particle_number_stop; if (level==0) { particle_number_start=0; particle_number_stop = total_number_particles(); } else { particle_number_start = apr_iterator.particles_level_begin(level); particle_number_stop = apr_iterator.particles_level_end(level); } //determine if openMP should be used. size_t total_particles_to_iterate = particle_number_stop - particle_number_start; if (total_particles_to_iterate < parallel_particle_number_threshold){ aNumberOfBlocks = 1; } const size_t numOfElementsPerBlock = total_particles_to_iterate/aNumberOfBlocks; #ifdef HAVE_OPENMP #pragma omp parallel for schedule(static) #endif for (unsigned int blockNum = 0; blockNum < aNumberOfBlocks; ++blockNum) { size_t offsetBegin = particle_number_start + blockNum * numOfElementsPerBlock; size_t offsetEnd = offsetBegin + numOfElementsPerBlock; if (blockNum == aNumberOfBlocks - 1) { // Handle tailing elements if number of blocks does not divide. offsetEnd = particle_number_stop; } //Operation to be performed on the chunk std::transform(data.begin() + offsetBegin, data.begin() + offsetEnd, data.begin() + offsetBegin, op); } } }; #endif //PARTPLAY_EXTRAPARTICLEDATA_HPP
38.102389
168
0.663741
BioDataAnalysis
f51967f231166ec2057a9af46d81aae6798d908f
4,238
cpp
C++
tests/performance/local/swarm_homogeneous_timed_task_spawn.cpp
kempj/hpx
ffdbfed5dfa029a0f2e97e7367cb66d12103df67
[ "BSL-1.0" ]
null
null
null
tests/performance/local/swarm_homogeneous_timed_task_spawn.cpp
kempj/hpx
ffdbfed5dfa029a0f2e97e7367cb66d12103df67
[ "BSL-1.0" ]
null
null
null
tests/performance/local/swarm_homogeneous_timed_task_spawn.cpp
kempj/hpx
ffdbfed5dfa029a0f2e97e7367cb66d12103df67
[ "BSL-1.0" ]
null
null
null
// Copyright (c) 2011-2012 Bryce Adelstein-Lelbach // Copyright (c) 2007-2012 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include "worker_timed.hpp" #include <hpx/util/assert.hpp> #include <hpx/util/high_resolution_timer.hpp> #include <swarm/Runtime.h> #include <swarm/Scheduler.h> #include <stdexcept> #include <iostream> #include <boost/format.hpp> #include <boost/program_options.hpp> using boost::program_options::variables_map; using boost::program_options::options_description; using boost::program_options::value; using boost::program_options::store; using boost::program_options::command_line_parser; using boost::program_options::notify; using hpx::util::high_resolution_timer; /////////////////////////////////////////////////////////////////////////////// // Applications globals. swarm_dependency_t flag; swarm_Runtime_params params = swarm_Runtime_params_INITIALIZER; // Command-line variables. boost::uint64_t tasks = 500000; boost::uint64_t delay = 0; bool header = true; /////////////////////////////////////////////////////////////////////////////// void print_results( boost::uint64_t cores , double walltime ) { if (header) std::cout << "OS-threads,Tasks,Delay (iterations)," "Total Walltime (seconds),Walltime per Task (seconds)\n"; std::string const cores_str = boost::str(boost::format("%lu,") % cores); std::string const tasks_str = boost::str(boost::format("%lu,") % tasks); std::string const delay_str = boost::str(boost::format("%lu,") % delay); std::cout << ( boost::format("%-21s %-21s %-21s %10.12s, %10.12s\n") % cores_str % tasks_str % delay_str % walltime % (walltime / tasks)); } /////////////////////////////////////////////////////////////////////////////// extern "C" void worker_func( void* ) { worker_timed(delay * 1000); swarm_satisfy(&flag, 1); } /////////////////////////////////////////////////////////////////////////////// extern "C" void finish( void* p ) { HPX_ASSERT(p); high_resolution_timer* t = static_cast<high_resolution_timer*>(p); print_results(params.maxThreadCount, t->elapsed()); delete t; swarm_shutdownRuntime(0); } /////////////////////////////////////////////////////////////////////////////// extern "C" void spawner( void* p ) { HPX_ASSERT(p); swarm_dependency_init(&flag, tasks, finish, p); for (boost::uint64_t i = 0; i < tasks; ++i) swarm_scheduleGeneral(worker_func, 0); } /////////////////////////////////////////////////////////////////////////////// int swarm_main( variables_map& vm ) { // Validate command line. if (0 == tasks) throw std::invalid_argument("count of 0 tasks specified\n"); // Start the clock. high_resolution_timer* t = new high_resolution_timer; return !swarm_enterRuntime(&params, spawner, t); } /////////////////////////////////////////////////////////////////////////////// int main( int argc , char** argv ) { // Parse command line. variables_map vm; options_description cmdline("Usage: " HPX_APPLICATION_STRING " [options]"); cmdline.add_options() ( "help,h" , "print out program usage (this message)") ( "threads,t" , value<boost::uint32_t>()->default_value(1), "number of OS-threads to use") ( "tasks" , value<boost::uint64_t>(&tasks)->default_value(500000) , "number of tasks to invoke") ( "delay" , value<boost::uint64_t>(&delay)->default_value(0) , "number of iterations in the delay loop") ( "no-header" , "do not print out the csv header row") ; ; store(command_line_parser(argc, argv).options(cmdline).run(), vm); notify(vm); // Print help screen. if (vm.count("help")) { std::cout << cmdline; return 0; } if (vm.count("no-header")) header = false; // Setup the SWARM environment. params.maxThreadCount = vm["threads"].as<boost::uint32_t>(); return swarm_main(vm); }
25.684848
80
0.559226
kempj
f51bc0d5934d51d75165a550ecf30e8a5cf2a7ed
460
hxx
C++
Core/GameKit/IEngine.hxx
broken-bytes/Cyanite-Engine
5733e1fc010b375bbafc9ebfa41e248845f945b3
[ "MIT" ]
null
null
null
Core/GameKit/IEngine.hxx
broken-bytes/Cyanite-Engine
5733e1fc010b375bbafc9ebfa41e248845f945b3
[ "MIT" ]
null
null
null
Core/GameKit/IEngine.hxx
broken-bytes/Cyanite-Engine
5733e1fc010b375bbafc9ebfa41e248845f945b3
[ "MIT" ]
1
2020-12-20T07:35:05.000Z
2020-12-20T07:35:05.000Z
#pragma once namespace Cyanite::GameKit { class IEngine { public: virtual ~IEngine() = default; virtual auto StartUp() -> void = 0; virtual auto CleanUp() -> void = 0; virtual auto Shutdown() -> void = 0; virtual auto OnInit() -> void = 0; virtual auto OnUpdate() -> void = 0; virtual auto OnRender() -> void = 0; virtual auto OnDestroy() -> void = 0; virtual auto OnResize(uint32_t width, uint32_t height) -> void = 0; }; }
24.210526
70
0.626087
broken-bytes
f51cd323bb6bc16100ba8d8db3682257c1bff148
20,174
cpp
C++
src/allegro_flare/path2d.cpp
MarkOates/allegro_flare
b454cb85eb5e43d19c23c0c6fd2dc11b96666ce7
[ "MIT" ]
25
2015-03-30T02:02:43.000Z
2019-03-04T22:29:12.000Z
src/allegro_flare/path2d.cpp
MarkOates/allegro_flare
b454cb85eb5e43d19c23c0c6fd2dc11b96666ce7
[ "MIT" ]
122
2015-04-01T08:15:26.000Z
2019-10-16T20:31:22.000Z
src/allegro_flare/path2d.cpp
allegroflare/allegro_flare
21d6fe2a5a5323102285598c8a8c75b393ce0322
[ "MIT" ]
4
2020-02-25T18:17:31.000Z
2021-04-17T05:06:52.000Z
#include <allegro_flare/path2d.h> #include <iostream> //#include <allegro_flare/text_object.h> #include <AllegroFlare/Useful.hpp> #include <AllegroFlare/UsefulPHP.hpp> namespace allegro_flare { SegmentInfo::SegmentInfo(AllegroFlare::vec2d &start, AllegroFlare::vec2d &end) { this->start = start; this->end = end; from_start = end - start; middle = from_start/2 + start; length = distance(start, end); radius = length/2; perpendicular = AllegroFlare::vec2d(-from_start.y, from_start.x); normal = ~-perpendicular; } path2d::path2d() : _length(0.0f) { } path2d::path2d(std::string filename) : _length(0.0f) { load(filename); } path2d::~path2d() { clear(); } path2d &path2d::add_point(float x, float y, bool refresh) { point.push_back(AllegroFlare::vec2d(x, y)); if (point.size() == 1) _length = 0.0f; else { segment.push_back(new SegmentInfo(point[point.size()-2], point[point.size()-1])); _length += segment.back()->length; } if (refresh) refresh_segment_info(); return *this; } path2d &path2d::add_arc(float center_x, float center_y, float radius_x, float radius_y, float start_theta, float delta_theta, int num_segments, bool refresh) // this is a little dirty, might be able to speed it up somehow { if (num_segments >= 256) { std::cout << "[path2d::add_arc] you can't have more than 256 segments." << std::endl; return *this; } float points[256]; al_calculate_arc(&(points[0]), sizeof(float)*2, center_x, center_y, radius_x, radius_y, start_theta, delta_theta, 0, num_segments); for (int i=0; i<num_segments*2; i+=2) add_point(points[i], points[i+1], false); if (refresh) refresh_segment_info(); return *this; } path2d &path2d::make_arc(int first_index, float arc_strength, int num_segments, bool refresh) { float points[256]; num_segments++; AllegroFlare::vec2d arc_center = (point[first_index+1] + point[first_index]) / 2; float radius = distance(point[first_index+1], point[first_index]) / 2; float start_theta = (point[first_index+1] - arc_center).get_angle(); float end_theta = (point[first_index] - arc_center).get_angle(); al_calculate_arc(&(points[0]), sizeof(float)*2, arc_center.x, arc_center.y, radius, radius, start_theta, start_theta-end_theta, 0, num_segments); for (int i=2; i<(num_segments-1)*2; i+=2) insert_point(first_index+1, points[i], points[i+1], true); //add_point(points[i], points[i+1], false); if (refresh) refresh_segment_info(); return *this; } path2d &path2d::clear() { //for (int i=0; i<(int)point.size(); i++) delete point[i]; for (unsigned i=0; i<segment.size(); i++) delete segment[i]; point.clear(); segment.clear(); _length = 0; return *this; } path2d &path2d::concat(path2d &path) { if (this == &path) { std::cout << "[path2d::concat] cannot concat to self (line " + AllegroFlare::tostring(__LINE__) + ")"; return *this; } // prevent self-appending AllegroFlare::vec2d displacement = point.back() - path.point.front(); for (int i=0; i<(int)path.point.size(); i++) point.push_back(path.point[i] + displacement); _length += path._length; refresh_segment_info(); return *this; } AllegroFlare::vec2d path2d::top_left() { return _top_left; } AllegroFlare::vec2d path2d::bottom_right() { return _bottom_right; } float path2d::width() { return _bottom_right.x - _top_left.x; } float path2d::height() { return _bottom_right.y - _top_left.y; } path2d &path2d::top_left(float x, float y) { AllegroFlare::vec2d disp = AllegroFlare::vec2d(x, y) - _top_left; return move(disp.x, disp.y); } // math might be wrong path2d &path2d::bottom_right(float x, float y) { AllegroFlare::vec2d disp = _bottom_right - AllegroFlare::vec2d(x, y); return move(disp.x, disp.y); } // this has not been tested path2d &path2d::insert_point(unsigned at, float x, float y, bool refresh) { if (point.size() <= at) { std::cout << "[path2d::insert] could not insert point at index " << at << " - point.size() is " << point.size(); return *this; } point.insert(point.begin()+at, AllegroFlare::vec2d(x, y)); if (refresh) refresh_segment_info(); return *this; } void path2d::set_shape_color(ALLEGRO_COLOR col) { for (int i=0; i<(int)vertex.size(); i++) { vertex[i].color = col; } } path2d &path2d::append(path2d &path) { if (this == &path) { std::cout << "[path2d::append] cannot append to self (line " + AllegroFlare::tostring(__LINE__) + ")"; return *this; } // prevent self-appending for (int i=0; i<(int)path.point.size(); i++) point.push_back(path.point[i]); _length += path._length; refresh_segment_info(); return *this; } AllegroFlare::vec2d path2d::coordinate_at(float dist) { // this can be optimized float len = 0.0f; if (point.empty()) return AllegroFlare::vec2d(0, 0); if (dist < 0) return point.front(); if (dist >= _length) return point.back(); for (int i=1; i<(int)point.size(); i++) { len += segment[i-1]->length; if (dist < len) { float percentage = (segment[i-1]->length - (len - dist)) / segment[i-1]->length; return segment[i-1]->from_start * percentage + point[i-1]; } } return AllegroFlare::vec2d(0, 0); } path2d &path2d::rotate(float angle, float anchor_x, float anchor_y) { ALLEGRO_TRANSFORM t; al_build_transform(&t, anchor_x, anchor_y, 1.0, 1.0, angle); for (int i=0; i<(int)point.size(); i++) al_transform_coordinates(&t, &point[i].x, &point[i].y); refresh_segment_info(); return *this; } path2d &path2d::rotate(float angle, AllegroFlare::vec2d pivot) { return rotate(angle, pivot.x, pivot.y); } path2d &path2d::rotate(float angle) { return rotate(angle, 0, 0); } path2d &path2d::flip_v() { // this can be optimized // one possibility is to add an "off switch" for update_segment_info, so it can be done at the end, instead of at each step AllegroFlare::vec2d pos = this->_top_left; this->to_origin(); for (unsigned i=0; i<point.size(); i++) this->point[i].y *= -1; refresh_segment_info(); // <-- needed to recalc the bounding box this->top_left(pos.x, pos.y); return *this; } path2d &path2d::flip_h() { // this can be optimized // one possibility is to add an "off switch" for update_segment_info, so it can be done at the end, instead of at each step AllegroFlare::vec2d pos = this->_top_left; this->to_origin(); for (unsigned i=0; i<point.size(); i++) this->point[i].x *= -1; refresh_segment_info(); // <-- needed to recalc the bounding box this->top_left(pos.x, pos.y); return *this; } path2d &path2d::reverse() { if (point.size() <= 1) return *this; std::vector<AllegroFlare::vec2d> *newpoints = new std::vector<AllegroFlare::vec2d>; for (int i=point.size()-1; i>=0; i--) { newpoints->push_back(point[i]); } clear(); point = *newpoints; refresh_segment_info(); return *this; } void path2d::refresh_segment_info() { //if (_length<=1) return; // <-- I'm not sure why this was here if (point.size() <= 1) return; // <-- replaced it with this _length = 0; for (int i=0; i<(int)segment.size(); i++) delete segment[i]; segment.clear(); _top_left = point.front(); _bottom_right = point.front(); for (int i=1; i<(int)point.size(); i++) { segment.push_back(new SegmentInfo(point[i-1], point[i])); _length += segment.back()->length; if (point[i].x < _top_left.x) _top_left.x = point[i].x; if (point[i].x > _bottom_right.x) _bottom_right.x = point[i].x; if (point[i].y < _top_left.y) _top_left.y = point[i].y; if (point[i].y > _bottom_right.y) _bottom_right.y = point[i].y; } } float path2d::length() { return _length; } path2d &path2d::soften() { if (point.size() <= 1) return *this; std::vector<AllegroFlare::vec2d> *newpoints = new std::vector<AllegroFlare::vec2d>; // break each segment into 4 seperate segments for (int i=1; i<(int)point.size(); i++) { newpoints->push_back(AllegroFlare::vec2d((point[i]-point[i-1])*0.0 + point[i-1])); newpoints->push_back(AllegroFlare::vec2d((point[i]-point[i-1])*0.25 + point[i-1])); newpoints->push_back(AllegroFlare::vec2d((point[i]-point[i-1])*0.5 + point[i-1])); newpoints->push_back(AllegroFlare::vec2d((point[i]-point[i-1])*0.75 + point[i-1])); } newpoints->push_back(point[point.size()-1]); // skip the first 2 // erase every other point bool keep = true; for (int i=1; i<(int)newpoints->size(); i++) { if (!keep) { //delete newpoints->at(i); newpoints->erase(newpoints->begin()+i); i--; } keep = !keep; } newpoints->push_back(AllegroFlare::vec2d(point[point.size()-1])); //delete newpoints->at(1); newpoints->erase(newpoints->begin()+1); //delete newpoints->at((int)newpoints->size()-2); newpoints->erase(newpoints->end()-2); // clear the current points // and fill with the new points clear(); point = *newpoints; refresh_segment_info(); return *this; } path2d &path2d::move(float x, float y) { for (int i=0; i<(int)point.size(); i++) { point[i].x += x; point[i].y += y; } for (int i=0; i<(int)segment.size(); i++) { segment[i]->start.x += x; segment[i]->start.y += y; segment[i]->end.x += x; segment[i]->end.y += y; segment[i]->middle.x += x; segment[i]->middle.y += y; } refresh_segment_info(); return *this; } path2d &path2d::to_origin() { return this->move_start_to(0,0); } path2d &path2d::move_start_to(float x, float y) { if (point.empty()) return *this; move(-point[0].x + x, -point[0].y + y); return *this; } path2d &path2d::move_end_to(float x, float y) { if (point.empty()) return *this; move(-point.back().x + x, -point.back().y + y); return *this; } path2d &path2d::scale(float s) { return this->scale(s, s); } path2d &path2d::scale_to(float w, float h) { return scale(w/width(), h/height()); } path2d &path2d::scale(float x, float y) { for (int i=0; i<(int)point.size(); i++) { point[i].x *= x; point[i].y *= y; } refresh_segment_info(); return *this; } // this function will take the whole path and split it into // num_segments of equal length, traveling along the path. path2d &path2d::resegment(int num_segments, bool refresh) { if (num_segments <= 1) return *this; std::vector<AllegroFlare::vec2d> *newpoints = new std::vector<AllegroFlare::vec2d>; //vec2d p; for (int seg = 0; seg <= num_segments; seg++) { //std::cout << std::endl << _length * ((float)seg / num_segments); newpoints->push_back(AllegroFlare::vec2d( coordinate_at(_length * ((float)seg / num_segments)) )); } //std::cout << std::endl << point.size(); clear(); //std::cout << std::endl << this->length(); point = *newpoints; if (refresh) refresh_segment_info(); //std::cout << std::endl << this->length(); return *this; } float path2d::length_along(int first_index, int last_index) { float len = 0; if (first_index<0) return 0; if (first_index>=(int)point.size()) return 0; if (last_index<0) return 0; if ((first_index+last_index)>=(int)point.size()) return 0; if (last_index <= (first_index+1)) return 0; for (int i=first_index+1; i<=last_index; i++) { len += distance(point[i-1], point[i]); } return len; } float path2d::length_to(int index) { if (index <= 0) return 0; if ((int)point.size() <= index) return 0; float len = 0; for (int i=1; i<=index; i++) { len += distance(point[i-1], point[i]); } return len; } void path2d::draw(bool show_points, bool show_normals, bool show_bounding_box, bool show_normal_angles, ALLEGRO_COLOR col, float thickness) { if (point.size() <= 1) return; if (show_bounding_box) al_draw_rectangle(_top_left.x, _top_left.y, _bottom_right.x, _bottom_right.y, al_color_name("yellow"), 1.0); for (int i=1; i<(int)point.size(); i++) { al_draw_line(point[i-1].x, point[i-1].y, point[i].x, point[i].y, col, thickness); if (show_points) al_draw_filled_circle(point[i-1].x, point[i-1].y, 2, al_color_name("dodgerblue")); } if (show_points) al_draw_filled_circle(point.front().x, point.front().y, 2, al_color_name("forestgreen")); if (show_points) al_draw_circle(point.back().x, point.back().y, 3, al_color_name("brown"), 1.0f); //float normal_length = 5; /* Text t; t.font(get_font("04B_03B_.TTF", -8)).align(0.5, 1.0); for (int i=0; i<(int)segment.size(); i++) { if (show_normals) al_draw_line(segment[i]->middle.x, segment[i]->middle.y, segment[i]->middle.x + segment[i]->normal.x * normal_length, segment[i]->middle.y + segment[i]->normal.y * normal_length, al_map_rgba_f(0.5, 0.5, 0, 1), 1.0); if (show_normal_angles) t.text(tostring((segment[i]->normal.GetAngle()))).position(segment[i]->middle.x, segment[i]->middle.y).print(); } */ } AllegroFlare::vec2d path2d::at(int index) { if (index < 0 || index >= (int)point.size()) return AllegroFlare::vec2d(0,0); return point.at(index); } const path2d &path2d::copy_to(path2d *dest) const { if (!dest) return *this; if (dest==this) return *this; dest->clear(); for (int i=0; i<(int)point.size(); i++) dest->point.push_back(point[i]); dest->refresh_segment_info(); dest->_length = _length; return *this; } path2d *path2d::create_copy() { path2d *dest = new path2d; dest->clear(); for (int i=0; i<(int)point.size(); i++) dest->point.push_back(point[i]); dest->refresh_segment_info(); dest->_length = _length; return dest; } bool path2d::load(std::string filename) { clear(); if (!AllegroFlare::php::file_exists(filename)) { std::cout << "[path2d::load] file not found."; return false; } std::vector<std::string> parts = AllegroFlare::php::explode("\n", AllegroFlare::php::file_get_contents(filename)); for (int i=0; i<(int)parts.size(); i++) { //std::cout << parts[i] << std::endl; std::vector<std::string> coord_string = AllegroFlare::php::explode(" ", parts[i]); add_point(atof(coord_string[0].c_str()), atof(coord_string[1].c_str()), false); } refresh_segment_info(); return true; } bool path2d::save(std::string filename) { std::string output = ""; for (int i=0; i<(int)point.size(); i++) { output += AllegroFlare::tostring(point[i].x) + " " + AllegroFlare::tostring(point[i].y); if (i!=((int)point.size()-1)) output += "\n"; } AllegroFlare::php::file_put_contents(filename, output); return true; } void path2d::update_vertexs() { //vertex.resize(point.size()); vertex.clear(); ALLEGRO_COLOR col = al_color_name("white"); ALLEGRO_VERTEX v; for (int i=0; i<(int)point.size(); i++) { vertex.push_back(v); vertex.back().x = point[i].x; vertex.back().y = point[i].y; vertex.back().z = 0; vertex.back().color = col; vertex.back().u = point[i].x; vertex.back().v = point[i].y; } } /* void path2d::draw_shape(ALLEGRO_BITMAP *image) { static bool warned = false; if (vertex.empty()) { if (!warned) { warned = true; std::cout << std::endl << "[path2d::draw_shape] attempting to draw empty() vertexes, did you remember to update_vertexs()?" << std::endl; } return; } al_draw_prim(&vertex[0], NULL, image, 0, vertex.size(), ALLEGRO_PRIM_TRIANGLE_FAN); } */ void path2d::draw_shape(ALLEGRO_COLOR color) { al_draw_filled_polygon(&point[0].x, point.size(), color); } void path2d::draw_shape(float x, float y, ALLEGRO_COLOR color) { this->move(x, y); draw_shape(color); this->move(-x, -y); } void path2d::draw_outline(const ALLEGRO_COLOR &color, float thickness) { if (point.empty()) return; std::vector<AllegroFlare::vec2d>::iterator previous_it = point.begin(); for (std::vector<AllegroFlare::vec2d>::iterator it=point.begin()+1; it!=point.end(); it++) { al_draw_line(it->x, it->y, previous_it->x, previous_it->y, color, thickness); previous_it = it; } } void path2d::draw_outline(float x, float y, const ALLEGRO_COLOR &color, float thickness) { this->move(x, y); draw_outline(color, thickness); this->move(-x, -y); } path2d *path2d::create_extrapolation(float radian, float theta) { float angle = 0; path2d *result = new path2d(); for (int i=0; i<(int)point.size()-1; i++) { angle = segment[i]->normal.get_angle(); std::cout << std::endl << i << " " << angle; if (angle > radian && angle < radian+theta) { result->add_point(point[i].x, point[i].y, false); //result->add_point(point[i]->x, point[i]->y, false); } } std::cout << std::endl << result->point.size(); //result->refresh_segment_info(); return result; } path2d::path2d(const path2d &source) { source.copy_to(this); } path2d &path2d::roughen(float disp_range_x, float disp_range_y) { disp_range_x *= 0.5; disp_range_y *= 0.5; for (int i=0; i<(int)point.size(); i++) { point[i].x += AllegroFlare::random_float(-disp_range_x, disp_range_x); point[i].y += AllegroFlare::random_float(-disp_range_y, disp_range_y); } refresh_segment_info(); return *this; } bool path2d::within_range(float x) { if (point.empty()) return false; if (point.size() == 1) return false; if (x < point[0].x) return false; if (x > point[point.size()-1].x) return false; return true; } // assumes within_range() is true // this is too slow for practical real-time usage float path2d::get_y(float x) { int lpoint_index = 0; AllegroFlare::vec2d lpoint = point[lpoint_index]; AllegroFlare::vec2d rpoint; for (unsigned i=0; i<point.size(); i++) { if (point[i].x > x) break; lpoint_index = i; } lpoint = point[lpoint_index]; if (lpoint_index >= ((int)point.size()-1)) rpoint = lpoint; else rpoint = point[lpoint_index+1]; float percentage_between = (x - lpoint.x) / (rpoint.x - lpoint.x); AllegroFlare::vec2d point = (rpoint - lpoint) * percentage_between + lpoint; return point.y; } }
22.769752
207
0.571974
MarkOates
f51ed3cfaa07002b291fd653133d8d32e5676374
4,786
cpp
C++
wifiscan/cpp/scenario3_registerforupdates.xaml.cpp
nishkrish/Windows-universal-samples
5c0aa623b4356e96759d901b8b432b3e744204bf
[ "MIT" ]
4
2020-07-13T17:28:32.000Z
2021-11-17T11:24:45.000Z
wifiscan/cpp/scenario3_registerforupdates.xaml.cpp
nishkrish/Windows-universal-samples
5c0aa623b4356e96759d901b8b432b3e744204bf
[ "MIT" ]
null
null
null
wifiscan/cpp/scenario3_registerforupdates.xaml.cpp
nishkrish/Windows-universal-samples
5c0aa623b4356e96759d901b8b432b3e744204bf
[ "MIT" ]
1
2020-11-20T22:15:02.000Z
2020-11-20T22:15:02.000Z
//********************************************************* // // Copyright (c) Microsoft. All rights reserved. // This code is licensed under the MIT License (MIT). // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. // //********************************************************* #include "pch.h" #include "Scenario3_RegisterForUpdates.xaml.h" using namespace SDKTemplate; using namespace SDKTemplate::WiFiScan; using namespace Platform; using namespace Windows::Devices::Enumeration; using namespace Windows::Devices::WiFi; using namespace Windows::Foundation; using namespace Windows::Foundation::Collections; using namespace Windows::Globalization::DateTimeFormatting; using namespace Windows::UI::Core; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Controls; using namespace Windows::UI::Xaml::Controls::Primitives; using namespace Windows::UI::Xaml::Data; using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; using namespace concurrency; Scenario3_RegisterForUpdates::Scenario3_RegisterForUpdates() : _rootPage(MainPage::Current) { InitializeComponent(); } void Scenario3_RegisterForUpdates::Button_Click_Register(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { _registrationToken = _firstAdapter->AvailableNetworksChanged += ref new Windows::Foundation::TypedEventHandler<Windows::Devices::WiFi::WiFiAdapter ^, Platform::Object ^>(this, &WiFiScan::Scenario3_RegisterForUpdates::OnAvailableNetworksChanged); RegisterButton->IsEnabled = false; UnregisterButton->IsEnabled = true; } void Scenario3_RegisterForUpdates::Button_Click_Unregister(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { _firstAdapter->AvailableNetworksChanged -= _registrationToken; UnregisterButton->IsEnabled = false; RegisterButton->IsEnabled = true; } void Scenario3_RegisterForUpdates::OnNavigatedTo(NavigationEventArgs^ e) { // RequestAccessAsync must have been called at least once by the app before using the API // Calling it multiple times is fine but not necessary // RequestAccessAsync must be called from the UI thread auto requestAccessOperation = WiFiAdapter::RequestAccessAsync(); auto requestAccessTask = create_task(requestAccessOperation); requestAccessTask.then([this](WiFiAccessStatus access) { if (access != WiFiAccessStatus::Allowed) { ScenarioOutput->Text = "Access denied"; } else { auto enumerationOperation = DeviceInformation::FindAllAsync(WiFiAdapter::GetDeviceSelector()); auto enumerationTask = create_task(enumerationOperation); enumerationTask.then([this](DeviceInformationCollection^ result) { if (result->Size >= 1) { auto firstAdapterOperation = WiFiAdapter::FromIdAsync(result->GetAt(0)->Id); auto firstAdapterTask = create_task(firstAdapterOperation); firstAdapterTask.then([this](WiFiAdapter^ adapter) { _firstAdapter = adapter; RegisterButton->IsEnabled = true; }); } else { ScenarioOutput->Text = L"No WiFi Adapters detected on this machine"; } }); } }); } void Scenario3_RegisterForUpdates::DisplayNetworkReport(WiFiNetworkReport^ report) { auto timestampString = DateTimeFormatter::LongDate->Format(report->Timestamp); auto message = L"Network Report Timestamp: " + timestampString; for (auto network : report->AvailableNetworks) { message += L"\nNetworkName: " + network->Ssid + L", BSSID: " + network->Bssid + L", RSSI: " + network->NetworkRssiInDecibelMilliwatts + L"dBm, Channel Frequency: " + network->ChannelCenterFrequencyInKilohertz + L"kHz"; } // there is no guarantee of what thread the AvailableNetworksChanged callback is run on _rootPage->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, message] { ScenarioOutput->Text = message; })); } void Scenario3_RegisterForUpdates::OnAvailableNetworksChanged(Windows::Devices::WiFi::WiFiAdapter ^sender, Platform::Object ^args) { DisplayNetworkReport(_firstAdapter->NetworkReport); }
39.553719
190
0.660259
nishkrish
f5208b2a96ecd5c9db18156b49b94df2da0063bd
28,192
cc
C++
tests/inherit_test.cc
akihito-takeuchi/dino-experiment
510ab6b83c41d860d511186c2863834e1b2662cb
[ "MIT" ]
null
null
null
tests/inherit_test.cc
akihito-takeuchi/dino-experiment
510ab6b83c41d860d511186c2863834e1b2662cb
[ "MIT" ]
null
null
null
tests/inherit_test.cc
akihito-takeuchi/dino-experiment
510ab6b83c41d860d511186c2863834e1b2662cb
[ "MIT" ]
null
null
null
// Copyright (c) 2019 Akihito Takeuchi // Distributed under the MIT License : http://opensource.org/licenses/MIT #include "dino/core/dobject.h" #include <gtest/gtest.h> #include <boost/filesystem.hpp> #include "dino/core/session.h" #include "dino/core/dexception.h" namespace dc = dino::core; namespace fs = boost::filesystem; auto& nil = dc::nil; namespace { const std::string kTopName1 = "top1"; const std::string kTopName2 = "top2"; const std::string kTopName3 = "top3"; const std::string kTopName4 = "top4"; const std::string kParentName1 = "parent1"; const std::string kParentName2 = "parent2"; const std::string kChildName1 = "child1"; const std::string kChildName2 = "child2"; const std::string kChildName3 = "child3"; const std::string kChildName4 = "child4"; const std::string kChildName5 = "child5"; } namespace dino { namespace core { std::ostream& operator<<(std::ostream& os, const DObjInfo& info) { os << "DObjInfo(" << info.Name() << "," << info.Type() << "," << info.Path().String() << "," << (info.IsValid() ? "valid" : "invalid") << "," << (info.IsActual() ? "local" : "remote") << ")\n"; return os; } } // namespace core } // namespace dino using StringVector = std::vector<std::string>; class InheritTest : public ::testing::Test { protected: virtual void SetUp() { for (auto dir_name : {kTopName1, kTopName2, kTopName3, kTopName4}) if (fs::exists(dir_name)) fs::remove_all(dir_name); } }; TEST_F(InheritTest, SimpleIneritance) { auto session = dc::Session::Create(); dc::DObjPath path1(boost::join( StringVector{kTopName1, kChildName1}, "/")); dc::DObjPath path2(boost::join( StringVector{kTopName1, kChildName2}, "/")); auto top1 = session->CreateTopLevelObject(kTopName1, "test"); auto child1 = top1->CreateChild(kChildName1, "test"); auto child2 = top1->CreateChild(kChildName2, "test"); child2->Put("test", 100); ASSERT_FALSE(child1->HasKey("test")); ASSERT_EQ(child2->Get("test"), 100); ASSERT_EQ(child1->Bases().size(), 0u); ASSERT_EQ(child2->Bases().size(), 0u); child1->AddBase(child2); ASSERT_TRUE(child1->HasKey("test")); ASSERT_EQ(child1->Get("test"), 100); ASSERT_EQ(child2->Get("test"), 100); ASSERT_EQ(child1->WhereIsKey("test"), path2); ASSERT_FALSE(child1->IsLocalKey("test")); ASSERT_EQ(child1->Bases().size(), 1u); ASSERT_EQ(child1->Bases()[0]->Path(), child2->Path()); ASSERT_NE(child1->Bases()[0]->Path(), child1->Path()); ASSERT_EQ(child2->Bases().size(), 0u); child1->Put("test", 200); ASSERT_TRUE(child1->HasKey("test")); ASSERT_EQ(child1->Get("test"), 200); ASSERT_EQ(child2->Get("test"), 100); ASSERT_EQ(child1->WhereIsKey("test"), path1); ASSERT_TRUE(child1->IsLocalKey("test")); child1->RemoveBase(child2); ASSERT_TRUE(child1->HasKey("test")); ASSERT_EQ(child1->Get("test"), 200); ASSERT_EQ(child2->Get("test"), 100); ASSERT_EQ(child1->WhereIsKey("test"), path1); ASSERT_TRUE(child1->IsLocalKey("test")); ASSERT_EQ(child1->Bases().size(), 0u); ASSERT_EQ(child2->Bases().size(), 0u); child1->RemoveKey("test"); ASSERT_THROW(child1->Get("test"), dc::DException); ASSERT_THROW(child1->WhereIsKey("test"), dc::DException); } TEST_F(InheritTest, LoadSaveInerited) { dc::DObjPath path1(boost::join( StringVector{kTopName2, kChildName1}, "/")); dc::DObjPath path2(boost::join( StringVector{kTopName2, kChildName2}, "/")); { auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName2, "test"); session->InitTopLevelObjectPath(kTopName2, kTopName2); auto child1 = top->CreateChild(kChildName1, "test"); auto child2 = top->CreateChild(kChildName2, "test"); child1->AddBase(child2); child1->Put("test1", 100); child2->Put("test1", 200); child2->Put("test2", 300); ASSERT_TRUE(child1->HasKey("test1")); ASSERT_TRUE(child1->HasKey("test2")); ASSERT_TRUE(child1->IsLocalKey("test1")); ASSERT_FALSE(child1->IsLocalKey("test2")); ASSERT_TRUE(child2->HasKey("test1")); ASSERT_TRUE(child2->HasKey("test2")); ASSERT_TRUE(child1->IsLocalKey("test1")); ASSERT_TRUE(child2->IsLocalKey("test2")); ASSERT_EQ(child1->Get("test1"), 100); ASSERT_EQ(child1->Get("test2"), 300); ASSERT_EQ(child2->Get("test1"), 200); ASSERT_EQ(child2->Get("test2"), 300); child1->Save(); child2->Save(); } { auto session = dc::Session::Create(); auto top = session->OpenTopLevelObject(kTopName2, kTopName2); auto child1 = session->OpenObject(path1); auto child2 = session->OpenObject(path2); ASSERT_EQ(child1->Get("test1"), 100); ASSERT_EQ(child1->Get("test2"), 300); ASSERT_EQ(child2->Get("test1"), 200); ASSERT_EQ(child2->Get("test2"), 300); } } TEST_F(InheritTest, PurgeBase) { dc::DObjPath path1(boost::join( StringVector{kTopName3, kChildName1}, "/")); dc::DObjPath path2(boost::join( StringVector{kTopName3, kChildName2}, "/")); { auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName3, "test"); session->InitTopLevelObjectPath(kTopName3, kTopName3); auto child1 = top->CreateChild(kChildName1, "test"); auto child2 = top->CreateChild(kChildName2, "test"); child1->AddBase(child2); child1->Put("test1", 100); child2->Put("test1", 200); child2->Put("test2", 300); ASSERT_TRUE(child1->HasKey("test1")); ASSERT_TRUE(child1->HasKey("test2")); ASSERT_TRUE(child1->IsLocalKey("test1")); ASSERT_FALSE(child1->IsLocalKey("test2")); ASSERT_TRUE(child2->HasKey("test1")); ASSERT_TRUE(child2->HasKey("test2")); ASSERT_TRUE(child1->IsLocalKey("test1")); ASSERT_TRUE(child2->IsLocalKey("test2")); ASSERT_EQ(child1->Get("test1"), 100); ASSERT_EQ(child1->Get("test2"), 300); ASSERT_EQ(child2->Get("test1"), 200); ASSERT_EQ(child2->Get("test2"), 300); child2->Save(); session->PurgeObject(child2->Path()); ASSERT_TRUE(child1->HasKey("test1")); ASSERT_TRUE(child1->HasKey("test2")); ASSERT_TRUE(child1->IsLocalKey("test1")); ASSERT_FALSE(child1->IsLocalKey("test2")); ASSERT_TRUE(child1->IsLocalKey("test1")); ASSERT_EQ(child1->Get("test1"), 100); ASSERT_EQ(child1->Get("test2"), 300); } } TEST_F(InheritTest, InheritedChildren) { dc::DObjPath path1(boost::join( StringVector{kTopName4, kParentName1}, "/")); dc::DObjPath path2(boost::join( StringVector{kTopName4, kParentName2}, "/")); dc::DObjPath path1_1(boost::join( StringVector{kTopName4, kParentName1, kChildName1}, "/")); dc::DObjPath path1_2(boost::join( StringVector{kTopName4, kParentName1, kChildName2}, "/")); dc::DObjPath path2_2(boost::join( StringVector{kTopName4, kParentName2, kChildName2}, "/")); dc::DObjPath path2_3(boost::join( StringVector{kTopName4, kParentName2, kChildName3}, "/")); auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName4, "test"); auto parent1 = top->CreateChild(kParentName1, "parent"); auto parent2 = top->CreateChild(kParentName2, "parent"); parent1->CreateChild(kChildName1, "child"); parent2->CreateChild(kChildName2, "child"); ASSERT_EQ(parent1->Children().size(), 1u); ASSERT_EQ(parent2->Children().size(), 1u); parent1->AddBase(parent2); ASSERT_EQ(parent1->Children().size(), 2u); ASSERT_EQ(parent2->Children().size(), 1u); ASSERT_TRUE(parent1->HasChild(kChildName1)); ASSERT_TRUE(parent1->HasChild(kChildName2)); ASSERT_TRUE(parent1->IsActualChild(kChildName1)); ASSERT_FALSE(parent1->IsActualChild(kChildName2)); ASSERT_FALSE(parent2->HasChild(kChildName1)); ASSERT_TRUE(parent2->HasChild(kChildName2)); ASSERT_THROW(parent2->IsActualChild(kChildName1), dc::DException); ASSERT_TRUE(parent2->IsActualChild(kChildName2)); ASSERT_THROW(parent1->IsActualChild(kChildName3), dc::DException); parent1->CreateChild(kChildName2, "child"); ASSERT_EQ(parent1->Children().size(), 2u); ASSERT_EQ(parent2->Children().size(), 1u); ASSERT_TRUE(parent1->HasChild(kChildName1)); ASSERT_TRUE(parent1->HasChild(kChildName2)); ASSERT_TRUE(parent1->IsActualChild(kChildName1)); ASSERT_TRUE(parent1->IsActualChild(kChildName2)); ASSERT_FALSE(parent2->HasChild(kChildName1)); ASSERT_TRUE(parent2->HasChild(kChildName2)); ASSERT_THROW(parent2->IsActualChild(kChildName1), dc::DException); ASSERT_TRUE(parent2->IsActualChild(kChildName2)); ASSERT_THROW(parent1->IsActualChild(kChildName3), dc::DException); parent2->CreateChild(kChildName3, "child"); ASSERT_EQ(parent1->Children().size(), 3u); ASSERT_EQ(parent2->Children().size(), 2u); ASSERT_TRUE(parent1->HasChild(kChildName1)); ASSERT_TRUE(parent1->HasChild(kChildName2)); ASSERT_TRUE(parent1->HasChild(kChildName3)); ASSERT_TRUE(parent1->IsActualChild(kChildName1)); ASSERT_TRUE(parent1->IsActualChild(kChildName2)); ASSERT_FALSE(parent1->IsActualChild(kChildName3)); ASSERT_FALSE(parent2->HasChild(kChildName1)); ASSERT_TRUE(parent2->HasChild(kChildName2)); ASSERT_TRUE(parent2->HasChild(kChildName3)); ASSERT_THROW(parent2->IsActualChild(kChildName1), dc::DException); ASSERT_TRUE(parent2->IsActualChild(kChildName2)); ASSERT_TRUE(parent2->IsActualChild(kChildName3)); ASSERT_EQ(parent1->Children()[0].Name(), kChildName1); ASSERT_EQ(parent1->Children()[1].Name(), kChildName2); ASSERT_EQ(parent1->Children()[2].Name(), kChildName3); ASSERT_EQ(parent2->Children()[0].Name(), kChildName2); ASSERT_EQ(parent2->Children()[1].Name(), kChildName3); parent1->RefreshChildren(); ASSERT_EQ(parent1->Children()[0].Name(), kChildName1); ASSERT_EQ(parent1->Children()[1].Name(), kChildName2); ASSERT_EQ(parent1->Children()[2].Name(), kChildName3); ASSERT_TRUE(parent1->HasChild(kChildName1)); ASSERT_TRUE(parent1->HasChild(kChildName2)); ASSERT_TRUE(parent1->HasChild(kChildName3)); ASSERT_TRUE(parent1->IsActualChild(kChildName1)); ASSERT_TRUE(parent1->IsActualChild(kChildName2)); ASSERT_FALSE(parent1->IsActualChild(kChildName3)); } // Command stack version class InheritTestWithCommandStack : public ::testing::Test { protected: virtual void SetUp() { for (auto dir_name : {kTopName1, kTopName2, kTopName3, kTopName4}) if (fs::exists(dir_name)) fs::remove_all(dir_name); } }; TEST_F(InheritTestWithCommandStack, SimpleIneritance) { auto session = dc::Session::Create(); dc::DObjPath path1(boost::join( StringVector{kTopName1, kChildName1}, "/")); dc::DObjPath path2(boost::join( StringVector{kTopName1, kChildName2}, "/")); auto top1 = session->CreateTopLevelObject(kTopName1, "test"); top1->EnableCommandStack(); auto child1 = top1->CreateChild(kChildName1, "test"); auto child2 = top1->CreateChild(kChildName2, "test"); child2->Put("test", 100); ASSERT_FALSE(child1->HasKey("test")); ASSERT_EQ(child2->Get("test"), 100); ASSERT_EQ(child1->Bases().size(), 0u); ASSERT_EQ(child2->Bases().size(), 0u); child1->AddBase(child2); ASSERT_TRUE(child1->HasKey("test")); ASSERT_EQ(child1->Get("test"), 100); ASSERT_EQ(child2->Get("test"), 100); ASSERT_EQ(child1->WhereIsKey("test"), path2); ASSERT_FALSE(child1->IsLocalKey("test")); ASSERT_EQ(child1->Bases().size(), 1u); ASSERT_EQ(child1->Bases()[0]->Path(), child2->Path()); ASSERT_NE(child1->Bases()[0]->Path(), child1->Path()); ASSERT_EQ(child2->Bases().size(), 0u); child1->Put("test", 200); ASSERT_TRUE(child1->HasKey("test")); ASSERT_EQ(child1->Get("test"), 200); ASSERT_EQ(child2->Get("test"), 100); ASSERT_EQ(child1->WhereIsKey("test"), path1); ASSERT_TRUE(child1->IsLocalKey("test")); child1->RemoveBase(child2); ASSERT_TRUE(child1->HasKey("test")); ASSERT_EQ(child1->Get("test"), 200); ASSERT_EQ(child2->Get("test"), 100); ASSERT_EQ(child1->WhereIsKey("test"), path1); ASSERT_TRUE(child1->IsLocalKey("test")); ASSERT_EQ(child1->Bases().size(), 0u); ASSERT_EQ(child2->Bases().size(), 0u); child1->RemoveKey("test"); ASSERT_THROW(child1->Get("test"), dc::DException); ASSERT_THROW(child1->WhereIsKey("test"), dc::DException); } TEST_F(InheritTestWithCommandStack, InheritedChildren) { dc::DObjPath path1(boost::join( StringVector{kTopName4, kParentName1}, "/")); dc::DObjPath path2(boost::join( StringVector{kTopName4, kParentName2}, "/")); dc::DObjPath path1_1(boost::join( StringVector{kTopName4, kParentName1, kChildName1}, "/")); dc::DObjPath path1_2(boost::join( StringVector{kTopName4, kParentName1, kChildName2}, "/")); dc::DObjPath path2_2(boost::join( StringVector{kTopName4, kParentName2, kChildName2}, "/")); dc::DObjPath path2_3(boost::join( StringVector{kTopName4, kParentName2, kChildName3}, "/")); auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName4, "test"); top->EnableCommandStack(); auto parent1 = top->CreateChild(kParentName1, "parent"); auto parent2 = top->CreateChild(kParentName2, "parent"); parent1->CreateChild(kChildName1, "child"); parent2->CreateChild(kChildName2, "child"); ASSERT_EQ(parent1->Children().size(), 1u); ASSERT_EQ(parent2->Children().size(), 1u); parent1->AddBase(parent2); ASSERT_EQ(parent1->Children().size(), 2u); ASSERT_EQ(parent2->Children().size(), 1u); ASSERT_TRUE(parent1->HasChild(kChildName1)); ASSERT_TRUE(parent1->HasChild(kChildName2)); ASSERT_TRUE(parent1->IsActualChild(kChildName1)); ASSERT_FALSE(parent1->IsActualChild(kChildName2)); ASSERT_FALSE(parent2->HasChild(kChildName1)); ASSERT_TRUE(parent2->HasChild(kChildName2)); ASSERT_THROW(parent2->IsActualChild(kChildName1), dc::DException); ASSERT_TRUE(parent2->IsActualChild(kChildName2)); ASSERT_THROW(parent1->IsActualChild(kChildName3), dc::DException); parent1->CreateChild(kChildName2, "child"); ASSERT_EQ(parent1->Children().size(), 2u); ASSERT_EQ(parent2->Children().size(), 1u); ASSERT_TRUE(parent1->HasChild(kChildName1)); ASSERT_TRUE(parent1->HasChild(kChildName2)); ASSERT_TRUE(parent1->IsActualChild(kChildName1)); ASSERT_TRUE(parent1->IsActualChild(kChildName2)); ASSERT_FALSE(parent2->HasChild(kChildName1)); ASSERT_TRUE(parent2->HasChild(kChildName2)); ASSERT_THROW(parent2->IsActualChild(kChildName1), dc::DException); ASSERT_TRUE(parent2->IsActualChild(kChildName2)); ASSERT_THROW(parent1->IsActualChild(kChildName3), dc::DException); parent2->CreateChild(kChildName3, "child"); ASSERT_EQ(parent1->Children().size(), 3u); ASSERT_EQ(parent2->Children().size(), 2u); ASSERT_TRUE(parent1->HasChild(kChildName1)); ASSERT_TRUE(parent1->HasChild(kChildName2)); ASSERT_TRUE(parent1->HasChild(kChildName3)); ASSERT_TRUE(parent1->IsActualChild(kChildName1)); ASSERT_TRUE(parent1->IsActualChild(kChildName2)); ASSERT_FALSE(parent1->IsActualChild(kChildName3)); ASSERT_FALSE(parent2->HasChild(kChildName1)); ASSERT_TRUE(parent2->HasChild(kChildName2)); ASSERT_TRUE(parent2->HasChild(kChildName3)); ASSERT_THROW(parent2->IsActualChild(kChildName1), dc::DException); ASSERT_TRUE(parent2->IsActualChild(kChildName2)); ASSERT_TRUE(parent2->IsActualChild(kChildName3)); ASSERT_EQ(parent1->Children()[0].Name(), kChildName1); ASSERT_EQ(parent1->Children()[1].Name(), kChildName2); ASSERT_EQ(parent1->Children()[2].Name(), kChildName3); ASSERT_EQ(parent2->Children()[0].Name(), kChildName2); ASSERT_EQ(parent2->Children()[1].Name(), kChildName3); parent1->RefreshChildren(); ASSERT_EQ(parent1->Children()[0].Name(), kChildName1); ASSERT_EQ(parent1->Children()[1].Name(), kChildName2); ASSERT_EQ(parent1->Children()[2].Name(), kChildName3); ASSERT_TRUE(parent1->HasChild(kChildName1)); ASSERT_TRUE(parent1->HasChild(kChildName2)); ASSERT_TRUE(parent1->HasChild(kChildName3)); ASSERT_TRUE(parent1->IsActualChild(kChildName1)); ASSERT_TRUE(parent1->IsActualChild(kChildName2)); ASSERT_FALSE(parent1->IsActualChild(kChildName3)); } TEST_F(InheritTest, DeepInheritance) { // base object tree // top1 : { "key1" : "value1", "key2" : 2, "key3" : nil } // +- child1 : { "key1" : "child1" } // | +- child3 : { "key2" : 10.0 } // +- child2 : { "key3" : true } // Create base tree { auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName1, kTopName1); session->InitTopLevelObjectPath(kTopName1, kTopName1); top->Put("key1", std::string("value1")); top->Put("key2", 2); top->Put("key3", nil); auto c1 = top->CreateChild(kChildName1, kChildName1); c1->Put("key1", std::string("child1")); auto c2 = top->CreateChild(kChildName2, kChildName2); c2->Put("key3", true); auto c3 = c1->CreateChild(kChildName3, kChildName3); c3->Put("key2", 10.0); top->Save(); c1->Save(); c2->Save(); c3->Save(); } // Test base tree { auto session = dc::Session::Create(); auto top = session->OpenTopLevelObject(kTopName1, kTopName1); ASSERT_EQ(top->Get("key1"), std::string("value1")); ASSERT_EQ(top->Get("key2"), 2); ASSERT_EQ(top->Get("key3"), nil); ASSERT_EQ(top->ChildCount(), 2u); ASSERT_EQ(top->Children()[0].Name(), kChildName1); ASSERT_EQ(top->Children()[1].Name(), kChildName2); auto c1 = top->OpenChild(kChildName1); ASSERT_EQ(c1->Get("key1"), std::string("child1")); auto c2 = top->OpenChild(kChildName2); ASSERT_EQ(c2->Get("key3"), true); auto c3 = c1->OpenChild(kChildName3); ASSERT_EQ(c3->Get("key2"), 10.0); } // create another tree which inherits base { auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName2, kTopName2); session->InitTopLevelObjectPath(kTopName2, kTopName2); top->AddBase(session->OpenTopLevelObject(kTopName1, kTopName1)); ASSERT_EQ(top->ChildCount(), 2u); auto children = top->Children(); ASSERT_EQ(children[0].Name(), kChildName1); ASSERT_EQ(children[1].Name(), kChildName2); auto c1 = top->OpenChild(kChildName1); ASSERT_FALSE(c1->IsActual()); ASSERT_FALSE(c1->IsDirty()); ASSERT_EQ(c1->Name(), std::string(kChildName1)); ASSERT_EQ(c1->Path(), dc::DObjPath(fmt::format("{}/{}", kTopName2, kChildName1))); ASSERT_EQ(c1->Get("key1"), std::string("child1")); ASSERT_EQ(c1->ChildCount(), 1u); auto c2 = top->OpenChild(kChildName2); ASSERT_EQ(c2->ChildCount(), 0u); ASSERT_EQ(c2->Get("key3"), true); auto c3 = c1->OpenChild(kChildName3); ASSERT_EQ(c3->ChildCount(), 0u); ASSERT_EQ(c3->Get("key2"), 10.0); ASSERT_FALSE(c3->IsDirty()); top->Save(true); } // Check inherited, and put data&save { auto session = dc::Session::Create(); // Need to open base object first session->OpenTopLevelObject(kTopName1, kTopName1); auto top = session->OpenTopLevelObject(kTopName2, kTopName2); ASSERT_EQ(top->EffectiveBases().size(), 1u); auto children = top->Children(); ASSERT_EQ(top->ChildCount(), 2u); ASSERT_EQ(children[0].Name(), kChildName1); ASSERT_EQ(children[1].Name(), kChildName2); ASSERT_FALSE(children[0].IsActual()); ASSERT_FALSE(children[1].IsActual()); auto c1 = top->OpenChild(kChildName1); ASSERT_FALSE(c1->IsActual()); ASSERT_EQ(top->ChildInfo(kChildName1), children[0]); ASSERT_FALSE(top->ChildInfo(kChildName1).IsActual()); ASSERT_EQ(c1->Name(), std::string(kChildName1)); ASSERT_EQ(c1->Path(), dc::DObjPath(fmt::format("{}/{}", kTopName2, kChildName1))); ASSERT_EQ(c1->Get("key1"), std::string("child1")); ASSERT_EQ(c1->ChildCount(), 1u); ASSERT_EQ(c1->Bases().size(), 0u); ASSERT_EQ(c1->EffectiveBases().size(), 1u); auto c2 = top->OpenChild(kChildName2); ASSERT_EQ(c2->ChildCount(), 0u); ASSERT_EQ(c2->Get("key3"), true); auto c3 = c1->OpenChild(kChildName3); ASSERT_EQ(c3->ChildCount(), 0u); ASSERT_EQ(c3->Get("key2"), 10.0); c3->SetEditable(); ASSERT_FALSE(c3->IsActual()); ASSERT_TRUE(c1->ChildInfo(kChildName3).IsValid()); ASSERT_FALSE(top->ChildInfo(kChildName3).IsValid()); ASSERT_FALSE(top->ChildInfo(kChildName3).IsActual()); c3->Put("key1", "test"); c3->Put("key2", 5.0); ASSERT_TRUE(c1->ChildInfo(kChildName3).IsActual()); ASSERT_TRUE(c3->IsActual()); ASSERT_EQ(c3->Get("key1"), std::string("test")); ASSERT_EQ(c3->Get("key2"), 5.0); c3->Save(); } // Check data load of data which already has base and local data { auto session = dc::Session::Create(); // Need to open base object first session->OpenTopLevelObject(kTopName1, kTopName1); auto top = session->OpenTopLevelObject(kTopName2, kTopName2); auto c1 = top->OpenChild(kChildName1); ASSERT_EQ(top->ChildCount(), 2u); auto children = top->Children(); ASSERT_TRUE(children[0].IsActual()); ASSERT_FALSE(children[1].IsActual()); ASSERT_TRUE(c1->IsActual()); ASSERT_EQ(c1->Name(), std::string(kChildName1)); ASSERT_EQ(c1->Path(), dc::DObjPath(fmt::format("{}/{}", kTopName2, kChildName1))); ASSERT_EQ(c1->Get("key1"), std::string("child1")); ASSERT_EQ(c1->ChildCount(), 1u); auto c3 = c1->OpenChild(kChildName3); ASSERT_EQ(c3->ChildCount(), 0u); ASSERT_EQ(c3->Get("key1"),std::string("test")); ASSERT_EQ(c3->Get("key2"), 5.0); auto c2 = top->OpenChild(kChildName2); ASSERT_FALSE(c2->IsActual()); ASSERT_FALSE(top->ChildInfo(kChildName2).IsActual()); c2->SetEditable(); c2->Put("key1", 10); ASSERT_TRUE(c2->IsActual()); ASSERT_TRUE(top->ChildInfo(kChildName2).IsActual()); top->SetEditable(); top->DeleteChild(kChildName2); ASSERT_FALSE(top->ChildInfo(kChildName2).IsActual()); ASSERT_TRUE(top->HasChild(kChildName2)); ASSERT_FALSE(top->HasActualChild(kChildName2)); ASSERT_THROW(c2->Get("key1"), dc::DException); top->Save(); } // Remove base { auto session = dc::Session::Create(); // Need to open base object first session->OpenTopLevelObject(kTopName1, kTopName1); auto top = session->OpenTopLevelObject(kTopName2, kTopName2); auto base = top->Bases()[0]; auto c1 = top->OpenChild(kChildName1); ASSERT_EQ(top->Bases().size(), 1u); ASSERT_EQ(top->EffectiveBases().size(), 1u); ASSERT_EQ(c1->Bases().size(), 0u); ASSERT_EQ(c1->EffectiveBases().size(), 1u); top->SetEditable(); top->RemoveBase(base); ASSERT_EQ(top->Bases().size(), 0u); ASSERT_EQ(top->EffectiveBases().size(), 0u); ASSERT_EQ(c1->Bases().size(), 0u); ASSERT_EQ(c1->EffectiveBases().size(), 0u); top->Save(); } // Check data load after base removal { auto session = dc::Session::Create(); auto top = session->OpenTopLevelObject(kTopName2, kTopName2); auto c1 = top->OpenChild(kChildName1); ASSERT_EQ(top->ChildCount(), 1u); ASSERT_TRUE(c1->IsActual()); ASSERT_EQ(c1->Name(), std::string(kChildName1)); ASSERT_EQ(c1->Path(), dc::DObjPath(fmt::format("{}/{}", kTopName2, kChildName1))); ASSERT_FALSE(c1->HasKey("key1")); ASSERT_EQ(c1->ChildCount(), 1u); auto c3 = c1->OpenChild(kChildName3); ASSERT_EQ(c3->ChildCount(), 0u); ASSERT_EQ(c3->Get("key1"), std::string("test")); ASSERT_EQ(c3->Get("key2"), 5.0); } // Need test to add base after creating some nodes { auto session = dc::Session::Create(); auto top1 = session->OpenTopLevelObject(kTopName1, kTopName1); auto top2 = session->OpenTopLevelObject( kTopName2, kTopName2, dc::OpenMode::kEditable); ASSERT_EQ(top2->ChildCount(), 1u); top2->AddBase(top1); ASSERT_EQ(top2->ChildCount(), 2u); ASSERT_TRUE(top2->ChildInfo(kChildName1).IsActual()); ASSERT_FALSE(top2->ChildInfo(kChildName2).IsActual()); auto c1 = top2->OpenChild(kChildName1); auto c3 = c1->OpenChild(kChildName3); ASSERT_TRUE(c3->IsActual()); ASSERT_EQ(c3->Get("key2"), 5.0); } // create another tree (top3) with actual c1 node, then inherit { auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName3, kTopName3); session->InitTopLevelObjectPath(kTopName3, kTopName3); auto c1 = top->CreateChild(kChildName1, kChildName1); ASSERT_EQ(top->ChildCount(), 1u); ASSERT_TRUE(c1->IsActual()); top->AddBase(session->OpenTopLevelObject(kTopName1, kTopName1)); ASSERT_EQ(top->ChildCount(), 2u); ASSERT_EQ(c1->ChildCount(), 1u); ASSERT_EQ(c1->Get("key1"), std::string("child1")); ASSERT_EQ(c1->Bases().size(), 0u); ASSERT_EQ(c1->EffectiveBases().size(), 1u); top->Save(true); } // Reopen top3, test with child4 and child5 // top1 : { "key1" : "value1", "key2" : 2, "key3" : nil } // +- child1 : { "key1" : "child1" } // | +- child3 : { "key2" : 10.0 } // | +- child4 : { "key4" : "child4" } // | +- child5 : {} // +- child2 : { "key3" : true } { auto session = dc::Session::Create(); // Need to open base object first session->OpenTopLevelObject(kTopName1, kTopName1); auto top = session->OpenTopLevelObject(kTopName3, kTopName3); auto c1 = top->OpenChild(kChildName1); ASSERT_EQ(top->ChildCount(), 2u); ASSERT_EQ(c1->ChildCount(), 1u); ASSERT_EQ(c1->Get("key1"), std::string("child1")); ASSERT_EQ(c1->EffectiveBases().size(), 1u); c1->SetEditable(); auto c4 = c1->CreateChild(kChildName4, "test"); ASSERT_TRUE(c4->IsActual()); ASSERT_EQ(c4->EffectiveBases().size(), 0u); auto base_top = top->Bases()[0]; auto base_c1 = base_top->OpenChild(kChildName1, dc::OpenMode::kEditable); auto base_c4 = base_c1->CreateChild(kChildName4, "test"); base_c4->Put("key4", "child4"); ASSERT_EQ(c1->ChildCount(), 2u); ASSERT_EQ(base_c4->Get("key4"), std::string("child4")); ASSERT_TRUE(c4->HasKey("key4")); ASSERT_EQ(c4->Get("key4"), std::string("child4")); ASSERT_EQ(c4->EffectiveBases().size(), 1u); base_c1->DeleteChild(kChildName4); ASSERT_THROW(base_c4->Get("key4"), dc::DException); auto base_c5 = base_c1->CreateChild(kChildName5, "test"); ASSERT_EQ(c1->ChildCount(), 3u); auto c5 = c1->OpenChild(kChildName5); ASSERT_FALSE(c5->IsActual()); base_c1->DeleteChild(kChildName5); ASSERT_EQ(c1->ChildCount(), 2u); ASSERT_THROW(c5->IsActual(), dc::DException); } } TEST_F(InheritTest, DeepInheritance2) { // base object tree // top1 : { "key1" : "value1", "key2" : 2, "key3" : nil } // +- child1 : { "key1" : "child1" } // | +- child3 : { "key2" : 10.0 } // | +- child4 : {} // | +- child5 : {} // +- child2 : { "key3" : true } // Create base tree { auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName1, kTopName1); session->InitTopLevelObjectPath(kTopName1, kTopName1); top->Put("key1", std::string("value1")); top->Put("key2", 2); top->Put("key3", nil); auto c1 = top->CreateChild(kChildName1, kChildName1); c1->Put("key1", std::string("child1")); auto c2 = top->CreateChild(kChildName2, kChildName2); c2->Put("key3", true); auto c3 = c1->CreateChild(kChildName3, kChildName3); c3->Put("key2", 10.0); auto c4 = c3->CreateChild(kChildName4, kChildName3); auto c5 = c3->CreateChild(kChildName5, kChildName5); top->Save(); c1->Save(); c2->Save(); c3->Save(); } // Inherit and test { auto session = dc::Session::Create(); auto top = session->CreateTopLevelObject(kTopName2, kTopName2); session->InitTopLevelObjectPath(kTopName2, kTopName2); auto base_top = session->OpenTopLevelObject(kTopName1, kTopName1); top->AddBase(base_top); ASSERT_EQ(top->ChildCount(), 2u); auto c1 = top->OpenChild(kChildName1); ASSERT_EQ(c1->ChildCount(), 1u); auto c3 = c1->OpenChild(kChildName3); ASSERT_EQ(c3->ChildCount(), 2u); top->RemoveBase(base_top); ASSERT_EQ(top->ChildCount(), 0u); ASSERT_THROW(c1->ChildCount(), dc::DException); ASSERT_THROW(c3->ChildCount(), dc::DException); } }
37.489362
86
0.670651
akihito-takeuchi
f5250ff83f0bf5928a47c47c948a4b1c4ea13486
963
cpp
C++
llvm/lib/Target/ARM/ARMMachineFunctionInfo.cpp
haohua-li/t-sgx-mirror
49188063f3cb5300cda8a03255cfe800e8266ace
[ "MIT" ]
26
2017-04-18T15:51:16.000Z
2022-03-29T07:03:37.000Z
llvm/lib/Target/ARM/ARMMachineFunctionInfo.cpp
haohua-li/t-sgx-mirror
49188063f3cb5300cda8a03255cfe800e8266ace
[ "MIT" ]
2
2017-10-27T21:29:04.000Z
2019-06-12T01:23:38.000Z
3.7.0/llvm-3.7.0.src/lib/Target/ARM/ARMMachineFunctionInfo.cpp
androm3da/clang_sles
2ba6d0711546ad681883c42dfb8661b842806695
[ "MIT" ]
9
2017-10-02T19:54:36.000Z
2021-11-22T00:48:18.000Z
//===-- ARMMachineFuctionInfo.cpp - ARM machine function info -------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "ARMMachineFunctionInfo.h" using namespace llvm; void ARMFunctionInfo::anchor() { } ARMFunctionInfo::ARMFunctionInfo(MachineFunction &MF) : isThumb(MF.getSubtarget<ARMSubtarget>().isThumb()), hasThumb2(MF.getSubtarget<ARMSubtarget>().hasThumb2()), StByValParamsPadding(0), ArgRegsSaveSize(0), HasStackFrame(false), RestoreSPFromFP(false), LRSpilledForFarJump(false), FramePtrSpillOffset(0), GPRCS1Offset(0), GPRCS2Offset(0), DPRCSOffset(0), GPRCS1Size(0), GPRCS2Size(0), DPRCSSize(0), PICLabelUId(0), VarArgsFrameIndex(0), HasITBlocks(false), GlobalBaseReg(0) {}
38.52
80
0.640706
haohua-li
f525e9fb670749e05e886de9148073599dc94238
2,526
cpp
C++
DPlusPlus/Source/Utils/Cache.cpp
pKiwky/DPlusPlus
0c9ef9567426056c6d65fd175f5e94ad559ee059
[ "MIT" ]
null
null
null
DPlusPlus/Source/Utils/Cache.cpp
pKiwky/DPlusPlus
0c9ef9567426056c6d65fd175f5e94ad559ee059
[ "MIT" ]
null
null
null
DPlusPlus/Source/Utils/Cache.cpp
pKiwky/DPlusPlus
0c9ef9567426056c6d65fd175f5e94ad559ee059
[ "MIT" ]
1
2021-06-05T17:35:27.000Z
2021-06-05T17:35:27.000Z
#include "Utils/Cache.hpp" #include "Entities/Guild/DiscordGuild.h" #include "Entities/Guild/DiscordRole.h" #include "Entities/Channel/DiscordChannel.h" #include "Entities/Message/DiscordMessage.h" #include "Entities/Member/DiscordMember.h" namespace DPlusPlus { template class Cache<DiscordGuild>; template class Cache<DiscordChannel>; template class Cache<DiscordMember>; template class Cache<DiscordRole>; template class CacheRing<DiscordMessage>; template <typename T> Cache<T>::Cache() {} template<typename T> std::unique_ptr<T> Cache<T>::Get(const Snowflake &id) { DPP_LOG_DEBUG("[Cache::Get] {0}", typeid(T).name()); std::lock_guard<std::mutex> lock(m_Mutex); { auto it = m_Objects.find(id); if(it != m_Objects.end()) { return std::make_unique<T>((it->second)); } } return nullptr; } template<typename T> void Cache<T>::Add(const Snowflake &id, T object) { DPP_LOG_DEBUG("[Cache::Add] {0}", typeid(T).name()); std::lock_guard<std::mutex> lock(m_Mutex); { m_Objects.insert(std::make_pair(id, object)); } } template <typename T> void Cache<T>::Delete(const Snowflake &id) { std::lock_guard<std::mutex> lock(m_Mutex); { auto it = m_Objects.find(id); if(it != m_Objects.end()) { DPP_LOG_DEBUG("[Cache::Delete] {0}", typeid(T).name()); m_Objects.erase(it); } } } template<typename T> CacheRing<T>::CacheRing(int size): m_Objects(boost::circular_buffer<T>(size)) {} template<typename T> std::unique_ptr<T> CacheRing<T>::Get(const Snowflake &id) { DPP_LOG_DEBUG("[CacheRing::Get] {0}", typeid(T).name()); std::lock_guard<std::mutex> lock(m_Mutex); { for(size_t i = 0; i < m_Objects.size(); i++) { if(m_Objects.at(i).Id == id) { return std::make_unique<T>(m_Objects.at(i)); } } } return nullptr; } template<typename T> void CacheRing<T>::Add(const Snowflake &id, T object) { DPP_LOG_DEBUG("[CacheRing::Add] {0}", typeid(T).name()); for(size_t i = 0; i < m_Objects.size(); i++) { if(m_Objects.at(i).Id == object.Id) { m_Objects.at(i) = object; return; } } std::lock_guard<std::mutex> lock(m_Mutex); { m_Objects.push_back(object); } } template<typename T> void CacheRing<T>::Delete(const Snowflake &id) { std::lock_guard<std::mutex> lock(m_Mutex); { for(size_t i = 0; i < m_Objects.size(); i++) { if(m_Objects.at(i).Id == id) { DPP_LOG_DEBUG("[CacheRing::Delete] {0}", typeid(T).name()); m_Objects.erase(m_Objects.begin() + i); } } } } }
23.607477
81
0.648852
pKiwky
f5288c488a2b0992a08269cf33d9ef2309db5ebf
261
cpp
C++
test/test.cpp
Fytch/Quiver
572c59bbc7aaef0e61318d6d0feaf5771b38cfdb
[ "MIT" ]
null
null
null
test/test.cpp
Fytch/Quiver
572c59bbc7aaef0e61318d6d0feaf5771b38cfdb
[ "MIT" ]
1
2018-11-28T12:55:50.000Z
2018-11-28T12:55:50.000Z
test/test.cpp
Fytch/Quiver
572c59bbc7aaef0e61318d6d0feaf5771b38cfdb
[ "MIT" ]
1
2018-08-19T16:48:23.000Z
2018-08-19T16:48:23.000Z
/* * Quiver - A graph theory library * Copyright (C) 2018 Josua Rieder (josua.rieder1996@gmail.com) * Distributed under the MIT License. * See the enclosed file LICENSE.txt for further information. */ #define CATCH_CONFIG_MAIN #include <catch2/catch.hpp>
26.1
63
0.747126
Fytch
f5296f58e82a2a306792619071608d8bb3bfe7d5
929
cc
C++
muduo/base/tests/Exception_test.cc
williamxin/muduo
fb5ff05ffde278084b3ea765bc7f51f93140699a
[ "BSD-3-Clause" ]
null
null
null
muduo/base/tests/Exception_test.cc
williamxin/muduo
fb5ff05ffde278084b3ea765bc7f51f93140699a
[ "BSD-3-Clause" ]
null
null
null
muduo/base/tests/Exception_test.cc
williamxin/muduo
fb5ff05ffde278084b3ea765bc7f51f93140699a
[ "BSD-3-Clause" ]
null
null
null
#include "muduo/base/CurrentThread.h" #include "muduo/base/Exception.h" #include <functional> #include <vector> #include <stdio.h> class Bar { public: void test(std::vector<std::string> names = {}) { printf("Stack:\n%s\n", muduo::CurrentThread::stackTrace(true).c_str()); [] { printf("Stack inside lambda:\n%s\n", muduo::CurrentThread::stackTrace(true).c_str()); }(); std::function<void()> func( [] { printf("Stack inside std::function:\n%s\n", muduo::CurrentThread::stackTrace(true).c_str()); }); func(); func = std::bind(&Bar::callback, this); func(); throw muduo::Exception("oops"); } private: void callback() { printf("Stack inside std::bind:\n%s\n", muduo::CurrentThread::stackTrace(true).c_str()); } }; void foo() { Bar b; b.test(); } int main() { try { foo(); } catch (const muduo::Exception& ex) { printf("reason: %s\n", ex.what()); printf("stack trace:\n%s\n", ex.stackTrace()); } }
23.820513
109
0.636168
williamxin
f52b198f4c746a159be2a50b3367d5a60f71d96f
3,802
cpp
C++
src/codegen/lang/if.cpp
aaron-tian/peloton
2406b763b91d9cee2a5d9f4dee01c761b476cef6
[ "Apache-2.0" ]
2
2021-03-29T01:29:18.000Z
2022-02-27T11:22:15.000Z
src/codegen/lang/if.cpp
aaron-tian/peloton
2406b763b91d9cee2a5d9f4dee01c761b476cef6
[ "Apache-2.0" ]
null
null
null
src/codegen/lang/if.cpp
aaron-tian/peloton
2406b763b91d9cee2a5d9f4dee01c761b476cef6
[ "Apache-2.0" ]
3
2018-02-25T23:30:33.000Z
2018-04-08T10:11:42.000Z
//===----------------------------------------------------------------------===// // // Peloton // // if.cpp // // Identification: src/codegen/lang/if.cpp // // Copyright (c) 2015-2017, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// #include "codegen/lang/if.h" #include <llvm/Transforms/Utils/BasicBlockUtils.h> #include "codegen/value.h" #include "codegen/type/boolean_type.h" namespace peloton { namespace codegen { namespace lang { //===----------------------------------------------------------------------===// // Constructor. We create two BB's, one "then" BB that appears right after the // conditional branch //===----------------------------------------------------------------------===// If::If(CodeGen &cg, llvm::Value *if_condition, const std::string &name) : cg_(cg), fn_(cg_->GetInsertBlock()->getParent()), last_bb_in_then_(nullptr), else_bb_(nullptr), last_bb_in_else_(nullptr) { then_bb_ = llvm::BasicBlock::Create(cg_.GetContext(), name, fn_); merge_bb_ = llvm::BasicBlock::Create(cg_.GetContext(), "ifCont"); // This instruction needs to be saved in case we have an else block branch_ = cg_->CreateCondBr(if_condition, then_bb_, merge_bb_); cg_->SetInsertPoint(then_bb_); } If::If(CodeGen &cg, const codegen::Value &if_condition, const std::string &name) : If(cg, type::Boolean::Instance().Reify(cg, if_condition), name) {} void If::EndIf(llvm::BasicBlock *end_bb) { if (end_bb != nullptr) { // Create an unconditional branch to the provided basic block cg_->CreateBr(end_bb); } else { // Create an unconditional branch to the merging block cg_->CreateBr(merge_bb_); } auto *curr_bb = cg_->GetInsertBlock(); if (else_bb_ == nullptr) { // There was no else block, the current block is the last in the "then" last_bb_in_then_ = curr_bb; } else { // There was an else block, the current block is the last in the "else" last_bb_in_else_ = curr_bb; } // Append the merge block to the end, and set it as the new insertion point fn_->getBasicBlockList().push_back(merge_bb_); cg_->SetInsertPoint(merge_bb_); } void If::ElseBlock(const std::string &name) { // Create an unconditional branch from where we are (from the 'then' branch) // to the merging block cg_->CreateBr(merge_bb_); // Create a new else block else_bb_ = llvm::BasicBlock::Create(cg_.GetContext(), name, fn_); last_bb_in_else_ = else_bb_; // Replace the previous branch instruction that normally went to the merging // block on a false predicate to now branch into the new else block auto *new_branch = llvm::BranchInst::Create(then_bb_, else_bb_, branch_->getCondition()); ReplaceInstWithInst(branch_, new_branch); last_bb_in_then_ = cg_->GetInsertBlock(); cg_->SetInsertPoint(else_bb_); } Value If::BuildPHI(const codegen::Value &v1, const codegen::Value &v2) { if (cg_->GetInsertBlock() != merge_bb_) { // The if hasn't been ended, end it now EndIf(); } PELOTON_ASSERT(v1.GetType() == v2.GetType()); std::vector<std::pair<Value, llvm::BasicBlock *>> vals = { {v1, last_bb_in_then_}, {v2, last_bb_in_else_ != nullptr ? last_bb_in_else_ : branch_->getParent()}}; return Value::BuildPHI(cg_, vals); } llvm::Value *If::BuildPHI(llvm::Value *v1, llvm::Value *v2) { PELOTON_ASSERT(v1->getType() == v2->getType()); llvm::PHINode *phi = cg_->CreatePHI(v1->getType(), 2); phi->addIncoming(v1, last_bb_in_then_); phi->addIncoming(v2, last_bb_in_else_ != nullptr ? last_bb_in_else_ : branch_->getParent()); return phi; } } // namespace lang } // namespace codegen } // namespace peloton
33.946429
80
0.620726
aaron-tian
f52b28cacb59640e421fd5c892cf45967f164b47
4,598
hpp
C++
db/silkworm/db/access_layer.hpp
flashbots/silkworm
7770793499d0c665754b17840f7b8edfd53ce8ba
[ "Apache-2.0" ]
1
2021-06-30T22:56:09.000Z
2021-06-30T22:56:09.000Z
db/silkworm/db/access_layer.hpp
flashbots/silkworm
7770793499d0c665754b17840f7b8edfd53ce8ba
[ "Apache-2.0" ]
null
null
null
db/silkworm/db/access_layer.hpp
flashbots/silkworm
7770793499d0c665754b17840f7b8edfd53ce8ba
[ "Apache-2.0" ]
null
null
null
/* Copyright 2020-2021 The Silkworm Authors 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 SILKWORM_DB_ACCESS_LAYER_HPP_ #define SILKWORM_DB_ACCESS_LAYER_HPP_ // Database Access Layer // See Erigon core/rawdb/accessors_chain.go #include <optional> #include <vector> #include <silkworm/chain/config.hpp> #include <silkworm/common/magic_enum.hpp> #include <silkworm/db/chaindb.hpp> #include <silkworm/db/util.hpp> #include <silkworm/types/account.hpp> #include <silkworm/types/block.hpp> namespace silkworm::rlp { class DecodingError : public std::exception { public: explicit DecodingError(DecodingResult err) : err_{magic_enum::enum_integer<DecodingResult>(err)}, message_{"Decoding error : " + std::string(magic_enum::enum_name<DecodingResult>(err))} {}; explicit DecodingError(DecodingResult err, const std::string& message) : err_{magic_enum::enum_integer<DecodingResult>(err)}, message_{message} {}; virtual ~DecodingError() noexcept {}; const char* what() const noexcept override { return message_.c_str(); } int err() const noexcept { return err_; } protected: int err_; std::string message_; }; inline void err_handler(DecodingResult err) { if (err != DecodingResult::kOk) { throw DecodingError(err); } } } // namespace silkworm::rlp namespace silkworm::db { class MissingSenders : public std::runtime_error { public: using std::runtime_error::runtime_error; }; // See Erigon StorageModeReceipts constexpr const char* kStorageModeReceipts{"smReceipts"}; // See Erigon GetStorageModeFromDB bool read_storage_mode_receipts(lmdb::Transaction& txn); std::optional<BlockHeader> read_header(lmdb::Transaction& txn, uint64_t block_number, const uint8_t (&hash)[kHashLength]); std::optional<BlockBody> read_body(lmdb::Transaction& txn, uint64_t block_number, const uint8_t (&hash)[kHashLength], bool read_senders); // See Erigon ReadTd std::optional<intx::uint256> read_total_difficulty(lmdb::Transaction& txn, uint64_t block_number, const uint8_t (&hash)[kHashLength]); // See Erigon ReadBlockByNumber // might throw MissingSenders std::optional<BlockWithHash> read_block(lmdb::Transaction& txn, uint64_t block_number, bool read_senders); // See Erigon ReadSenders std::vector<evmc::address> read_senders(lmdb::Transaction& txn, int64_t block_number, const uint8_t (&hash)[kHashLength]); // Overload std::vector<Transaction> read_transactions(lmdb::Table& txn_table, uint64_t base_id, uint64_t count); std::optional<Bytes> read_code(lmdb::Transaction& txn, const evmc::bytes32& code_hash); // Reads current or historical (if block_number is specified) account. std::optional<Account> read_account(lmdb::Transaction& txn, const evmc::address& address, std::optional<uint64_t> block_number = std::nullopt); // Reads current or historical (if block_number is specified) storage. evmc::bytes32 read_storage(lmdb::Transaction& txn, const evmc::address& address, uint64_t incarnation, const evmc::bytes32& location, std::optional<uint64_t> block_number = std::nullopt); // Reads current or historical (if block_number is specified) previous incarnation. std::optional<uint64_t> read_previous_incarnation(lmdb::Transaction& txn, const evmc::address& address, std::optional<uint64_t> block_number = std::nullopt); AccountChanges read_account_changes(lmdb::Transaction& txn, uint64_t block_number); StorageChanges read_storage_changes(lmdb::Transaction& txn, uint64_t block_number); bool migration_happened(lmdb::Transaction& txn, const char* name); // Retrieves the chain_id for which database is populated // See Erigon chainConfig / chainConfigWithGenesis std::optional<ChainConfig> read_chain_config(lmdb::Transaction& txn); } // namespace silkworm::db #endif // !SILKWORM_DB_ACCESS_LAYER_HPP_
38.316667
117
0.718573
flashbots
f52b481ee48a9fcfdac449a9fb1f18ef74b0ecd0
4,028
cpp
C++
etpServerExample/main.cpp
cgodkin/fesapi
d25c5e30ccec537c471adc3bb036c48f2c51f2c9
[ "Apache-2.0" ]
null
null
null
etpServerExample/main.cpp
cgodkin/fesapi
d25c5e30ccec537c471adc3bb036c48f2c51f2c9
[ "Apache-2.0" ]
null
null
null
etpServerExample/main.cpp
cgodkin/fesapi
d25c5e30ccec537c471adc3bb036c48f2c51f2c9
[ "Apache-2.0" ]
null
null
null
/*----------------------------------------------------------------------- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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. -----------------------------------------------------------------------*/ #ifdef WITH_ETP_SSL #include "etp/ssl/SslServerSession.h" #else #include "etp/PlainServerSession.h" #endif #include "etp/Server.h" #ifdef WITH_ETP_SSL #include "ssl/server_certificate.h" #endif #include "MyServerInitializationParameters.h" #include "common/EpcDocument.h" #include "resqml2/AbstractRepresentation.h" #include "resqml2_0_1/ContinuousProperty.h" void generateProperties(RESQML2_NS::AbstractRepresentation* ijkgrid) { for (unsigned short i = 0; i < (std::numeric_limits<unsigned short>::max)(); ++i) { auto name = "Two faulted sugar cubes timestamp " + std::to_string(i); RESQML2_NS::ContinuousProperty* continuousProp = ijkgrid->getRepository()->createContinuousProperty(ijkgrid, "", name, 1, gsoap_eml2_3::resqml22__IndexableElement__cells, gsoap_resqml2_0_1::resqml20__ResqmlUom__m, gsoap_resqml2_0_1::resqml20__ResqmlPropertyKind__length); double prop1Values[2] = { i, i }; continuousProp->pushBackDoubleHdf5Array3dOfValues(prop1Values, 2, 1, 1, nullptr); std::cout << "A new discrete property has been added" << std::endl; const size_t secondCount = 10; std::cout << "New generated property in " << secondCount << " seconds" << std::endl; std::chrono::seconds dura(secondCount); std::this_thread::sleep_for(dura); } } int main(int argc, char **argv) { if (argc < 4) { std::cerr << "The command must be : etpServerExample ipAddress port epcFileName" << std::endl; std::cerr << "EXAMPLE : ./etpServerExample 127.0.0.1 8080 ../../testingPackageCpp.epc" << std::endl; return 1; } const int threadCount = 2; std::cout << "Start listening on " << argv[1] << ":" << argv[2] << " with " << threadCount << " threads..." << std::endl; COMMON_NS::EpcDocument epcDoc(argv[3]); MyDataObjectRepository repo; std::string resqmlResult = epcDoc.deserializePartiallyInto(repo, COMMON_NS::DataObjectRepository::openingMode::READ_WRITE); // Do not open XML files. Simply rely on the EPC content type and rel files. repo.registerDataFeeder(&epcDoc); // Necessary to resolve partial objects if (!resqmlResult.empty()) { std::cerr << "Error when deserializing " << resqmlResult << std::endl; } if (argc > 4) { std::thread generatePropertiesThread(generateProperties, repo.getDataObjectByUuid<RESQML2_NS::AbstractRepresentation>("df2103a0-fa3d-11e5-b8d4-0002a5d5c51b")); generatePropertiesThread.detach(); // Detach the thread since we don't want it to be a blocking one. } MyServerInitializationParameters serverInitializationParams(&repo); #ifdef WITH_ETP_SSL Server<ETP_NS::SslServerSession> etpServer(postSessionCreationOp.get()); // The SSL context is required, and holds certificates boost::asio::ssl::context ctx{ boost::asio::ssl::context::tlsv12_server }; // This holds the self-signed certificate used by the server load_server_certificate(ctx); etpServer.listen(argv[1], std::stoi(argv[2]), threadCount, ctx); #else ETP_NS::Server<ETP_NS::PlainServerSession> etpServer(&serverInitializationParams); etpServer.listen(argv[1], std::stoi(argv[2]), threadCount); #endif epcDoc.close(); #ifdef _WIN32 _CrtDumpMemoryLeaks(); #endif return 0; }
36.954128
201
0.726167
cgodkin
f5317f3359147732ebcddc63b64c8f7008382101
11,786
hpp
C++
include/RootMotion/FinalIK/Grounding_Pelvis.hpp
marksteward/BeatSaber-Quest-Codegen
a76f063f71cef207a9f048ad7613835f554911a7
[ "Unlicense" ]
null
null
null
include/RootMotion/FinalIK/Grounding_Pelvis.hpp
marksteward/BeatSaber-Quest-Codegen
a76f063f71cef207a9f048ad7613835f554911a7
[ "Unlicense" ]
null
null
null
include/RootMotion/FinalIK/Grounding_Pelvis.hpp
marksteward/BeatSaber-Quest-Codegen
a76f063f71cef207a9f048ad7613835f554911a7
[ "Unlicense" ]
null
null
null
// Autogenerated from CppHeaderCreator // Created by Sc2ad // ========================================================================= #pragma once // Begin includes #include "extern/beatsaber-hook/shared/utils/typedefs.h" #include "extern/beatsaber-hook/shared/utils/byref.hpp" // Including type: RootMotion.FinalIK.Grounding #include "RootMotion/FinalIK/Grounding.hpp" // Including type: UnityEngine.Vector3 #include "UnityEngine/Vector3.hpp" #include "extern/beatsaber-hook/shared/utils/il2cpp-utils-methods.hpp" #include "extern/beatsaber-hook/shared/utils/il2cpp-utils-properties.hpp" #include "extern/beatsaber-hook/shared/utils/il2cpp-utils-fields.hpp" #include "extern/beatsaber-hook/shared/utils/utils.h" // Completed includes // Type namespace: RootMotion.FinalIK namespace RootMotion::FinalIK { // Size: 0x40 #pragma pack(push, 1) // Autogenerated type: RootMotion.FinalIK.Grounding/RootMotion.FinalIK.Pelvis // [TokenAttribute] Offset: FFFFFFFF class Grounding::Pelvis : public ::Il2CppObject { public: // private UnityEngine.Vector3 <IKOffset>k__BackingField // Size: 0xC // Offset: 0x10 UnityEngine::Vector3 IKOffset; // Field size check static_assert(sizeof(UnityEngine::Vector3) == 0xC); // private System.Single <heightOffset>k__BackingField // Size: 0x4 // Offset: 0x1C float heightOffset; // Field size check static_assert(sizeof(float) == 0x4); // private RootMotion.FinalIK.Grounding grounding // Size: 0x8 // Offset: 0x20 RootMotion::FinalIK::Grounding* grounding; // Field size check static_assert(sizeof(RootMotion::FinalIK::Grounding*) == 0x8); // private UnityEngine.Vector3 lastRootPosition // Size: 0xC // Offset: 0x28 UnityEngine::Vector3 lastRootPosition; // Field size check static_assert(sizeof(UnityEngine::Vector3) == 0xC); // private System.Single damperF // Size: 0x4 // Offset: 0x34 float damperF; // Field size check static_assert(sizeof(float) == 0x4); // private System.Boolean initiated // Size: 0x1 // Offset: 0x38 bool initiated; // Field size check static_assert(sizeof(bool) == 0x1); // Padding between fields: initiated and: lastTime char __padding5[0x3] = {}; // private System.Single lastTime // Size: 0x4 // Offset: 0x3C float lastTime; // Field size check static_assert(sizeof(float) == 0x4); // Creating value type constructor for type: Pelvis Pelvis(UnityEngine::Vector3 IKOffset_ = {}, float heightOffset_ = {}, RootMotion::FinalIK::Grounding* grounding_ = {}, UnityEngine::Vector3 lastRootPosition_ = {}, float damperF_ = {}, bool initiated_ = {}, float lastTime_ = {}) noexcept : IKOffset{IKOffset_}, heightOffset{heightOffset_}, grounding{grounding_}, lastRootPosition{lastRootPosition_}, damperF{damperF_}, initiated{initiated_}, lastTime{lastTime_} {} // Get instance field: private UnityEngine.Vector3 <IKOffset>k__BackingField UnityEngine::Vector3 _get_$IKOffset$k__BackingField(); // Set instance field: private UnityEngine.Vector3 <IKOffset>k__BackingField void _set_$IKOffset$k__BackingField(UnityEngine::Vector3 value); // Get instance field: private System.Single <heightOffset>k__BackingField float _get_$heightOffset$k__BackingField(); // Set instance field: private System.Single <heightOffset>k__BackingField void _set_$heightOffset$k__BackingField(float value); // Get instance field: private RootMotion.FinalIK.Grounding grounding RootMotion::FinalIK::Grounding* _get_grounding(); // Set instance field: private RootMotion.FinalIK.Grounding grounding void _set_grounding(RootMotion::FinalIK::Grounding* value); // Get instance field: private UnityEngine.Vector3 lastRootPosition UnityEngine::Vector3 _get_lastRootPosition(); // Set instance field: private UnityEngine.Vector3 lastRootPosition void _set_lastRootPosition(UnityEngine::Vector3 value); // Get instance field: private System.Single damperF float _get_damperF(); // Set instance field: private System.Single damperF void _set_damperF(float value); // Get instance field: private System.Boolean initiated bool _get_initiated(); // Set instance field: private System.Boolean initiated void _set_initiated(bool value); // Get instance field: private System.Single lastTime float _get_lastTime(); // Set instance field: private System.Single lastTime void _set_lastTime(float value); // public UnityEngine.Vector3 get_IKOffset() // Offset: 0x1831790 UnityEngine::Vector3 get_IKOffset(); // private System.Void set_IKOffset(UnityEngine.Vector3 value) // Offset: 0x183179C void set_IKOffset(UnityEngine::Vector3 value); // public System.Single get_heightOffset() // Offset: 0x18317A8 float get_heightOffset(); // private System.Void set_heightOffset(System.Single value) // Offset: 0x18317B0 void set_heightOffset(float value); // public System.Void Initiate(RootMotion.FinalIK.Grounding grounding) // Offset: 0x182F2F4 void Initiate(RootMotion::FinalIK::Grounding* grounding); // public System.Void Reset() // Offset: 0x182FE5C void Reset(); // public System.Void OnEnable() // Offset: 0x18317B8 void OnEnable(); // public System.Void Process(System.Single lowestOffset, System.Single highestOffset, System.Boolean isGrounded) // Offset: 0x182FBF0 void Process(float lowestOffset, float highestOffset, bool isGrounded); // public System.Void .ctor() // Offset: 0x182F208 // Implemented from: System.Object // Base method: System.Void Object::.ctor() template<::il2cpp_utils::CreationType creationType = ::il2cpp_utils::CreationType::Temporary> static Grounding::Pelvis* New_ctor() { static auto ___internal__logger = ::Logger::get().WithContext("RootMotion::FinalIK::Grounding::Pelvis::.ctor"); return THROW_UNLESS((::il2cpp_utils::New<Grounding::Pelvis*, creationType>())); } }; // RootMotion.FinalIK.Grounding/RootMotion.FinalIK.Pelvis #pragma pack(pop) static check_size<sizeof(Grounding::Pelvis), 60 + sizeof(float)> __RootMotion_FinalIK_Grounding_PelvisSizeCheck; static_assert(sizeof(Grounding::Pelvis) == 0x40); } DEFINE_IL2CPP_ARG_TYPE(RootMotion::FinalIK::Grounding::Pelvis*, "RootMotion.FinalIK", "Grounding/Pelvis"); #include "extern/beatsaber-hook/shared/utils/il2cpp-utils-methods.hpp" // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::get_IKOffset // Il2CppName: get_IKOffset template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<UnityEngine::Vector3 (RootMotion::FinalIK::Grounding::Pelvis::*)()>(&RootMotion::FinalIK::Grounding::Pelvis::get_IKOffset)> { static const MethodInfo* get() { return ::il2cpp_utils::FindMethod(classof(RootMotion::FinalIK::Grounding::Pelvis*), "get_IKOffset", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{}); } }; // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::set_IKOffset // Il2CppName: set_IKOffset template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<void (RootMotion::FinalIK::Grounding::Pelvis::*)(UnityEngine::Vector3)>(&RootMotion::FinalIK::Grounding::Pelvis::set_IKOffset)> { static const MethodInfo* get() { static auto* value = &::il2cpp_utils::GetClassFromName("UnityEngine", "Vector3")->byval_arg; return ::il2cpp_utils::FindMethod(classof(RootMotion::FinalIK::Grounding::Pelvis*), "set_IKOffset", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{value}); } }; // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::get_heightOffset // Il2CppName: get_heightOffset template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<float (RootMotion::FinalIK::Grounding::Pelvis::*)()>(&RootMotion::FinalIK::Grounding::Pelvis::get_heightOffset)> { static const MethodInfo* get() { return ::il2cpp_utils::FindMethod(classof(RootMotion::FinalIK::Grounding::Pelvis*), "get_heightOffset", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{}); } }; // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::set_heightOffset // Il2CppName: set_heightOffset template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<void (RootMotion::FinalIK::Grounding::Pelvis::*)(float)>(&RootMotion::FinalIK::Grounding::Pelvis::set_heightOffset)> { static const MethodInfo* get() { static auto* value = &::il2cpp_utils::GetClassFromName("System", "Single")->byval_arg; return ::il2cpp_utils::FindMethod(classof(RootMotion::FinalIK::Grounding::Pelvis*), "set_heightOffset", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{value}); } }; // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::Initiate // Il2CppName: Initiate template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<void (RootMotion::FinalIK::Grounding::Pelvis::*)(RootMotion::FinalIK::Grounding*)>(&RootMotion::FinalIK::Grounding::Pelvis::Initiate)> { static const MethodInfo* get() { static auto* grounding = &::il2cpp_utils::GetClassFromName("RootMotion.FinalIK", "Grounding")->byval_arg; return ::il2cpp_utils::FindMethod(classof(RootMotion::FinalIK::Grounding::Pelvis*), "Initiate", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{grounding}); } }; // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::Reset // Il2CppName: Reset template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<void (RootMotion::FinalIK::Grounding::Pelvis::*)()>(&RootMotion::FinalIK::Grounding::Pelvis::Reset)> { static const MethodInfo* get() { return ::il2cpp_utils::FindMethod(classof(RootMotion::FinalIK::Grounding::Pelvis*), "Reset", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{}); } }; // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::OnEnable // Il2CppName: OnEnable template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<void (RootMotion::FinalIK::Grounding::Pelvis::*)()>(&RootMotion::FinalIK::Grounding::Pelvis::OnEnable)> { static const MethodInfo* get() { return ::il2cpp_utils::FindMethod(classof(RootMotion::FinalIK::Grounding::Pelvis*), "OnEnable", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{}); } }; // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::Process // Il2CppName: Process template<> struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<void (RootMotion::FinalIK::Grounding::Pelvis::*)(float, float, bool)>(&RootMotion::FinalIK::Grounding::Pelvis::Process)> { static const MethodInfo* get() { static auto* lowestOffset = &::il2cpp_utils::GetClassFromName("System", "Single")->byval_arg; static auto* highestOffset = &::il2cpp_utils::GetClassFromName("System", "Single")->byval_arg; static auto* isGrounded = &::il2cpp_utils::GetClassFromName("System", "Boolean")->byval_arg; return ::il2cpp_utils::FindMethod(classof(RootMotion::FinalIK::Grounding::Pelvis*), "Process", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{lowestOffset, highestOffset, isGrounded}); } }; // Writing MetadataGetter for method: RootMotion::FinalIK::Grounding::Pelvis::New_ctor // Il2CppName: .ctor // Cannot get method pointer of value based method overload from template for constructor! // Try using FindMethod instead!
55.333333
419
0.721534
marksteward
f53229fa0939065b3da78394239481622e8d1973
250
cpp
C++
CsWeapon/Source/CsWp/Public/Managers/Weapon/CsGetManagerWeapon.cpp
closedsum/core
c3cae44a177b9684585043a275130f9c7b67fef0
[ "Unlicense" ]
2
2019-03-17T10:43:53.000Z
2021-04-20T21:24:19.000Z
CsWeapon/Source/CsWp/Public/Managers/Weapon/CsGetManagerWeapon.cpp
closedsum/core
c3cae44a177b9684585043a275130f9c7b67fef0
[ "Unlicense" ]
null
null
null
CsWeapon/Source/CsWp/Public/Managers/Weapon/CsGetManagerWeapon.cpp
closedsum/core
c3cae44a177b9684585043a275130f9c7b67fef0
[ "Unlicense" ]
null
null
null
// Copyright 2017-2021 Closed Sum Games, LLC. All Rights Reserved. #include "Managers/Weapon/CsGetManagerWeapon.h" #include "CsWp.h" UCsGetManagerWeapon::UCsGetManagerWeapon(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { }
35.714286
112
0.812
closedsum
f5324ddc27e39726fdcdb67fee51f9af2cbc805e
3,432
hpp
C++
RealtekCardReader/IOPCIeDevice.hpp
MK-986123/RealtekCardReader
0b1a4c66082b63d057cba2a54721b62cbf11c0ac
[ "BSD-3-Clause" ]
106
2021-07-16T03:27:28.000Z
2022-03-31T15:35:50.000Z
RealtekCardReader/IOPCIeDevice.hpp
MK-986123/RealtekCardReader
0b1a4c66082b63d057cba2a54721b62cbf11c0ac
[ "BSD-3-Clause" ]
28
2021-07-16T09:03:10.000Z
2022-03-28T03:36:47.000Z
RealtekCardReader/IOPCIeDevice.hpp
MK-986123/RealtekCardReader
0b1a4c66082b63d057cba2a54721b62cbf11c0ac
[ "BSD-3-Clause" ]
14
2021-07-16T16:15:09.000Z
2022-02-24T22:08:21.000Z
// // IOPCIeDevice.hpp // RealtekCardReader // // Created by FireWolf on 7/7/21. // #ifndef IOPCIeDevice_hpp #define IOPCIeDevice_hpp #include <IOKit/pci/IOPCIDevice.h> #include "Debug.hpp" #define PCI_EXP_LNKCTL 16 /* Link Control */ #define PCI_EXP_LNKCTL_ASPMC 0x0003 /* ASPM Control */ #define PCI_EXP_LNKCTL_ASPM_L0S 0x0001 /* L0s Enable */ #define PCI_EXP_LNKCTL_ASPM_L1 0x0002 /* L1 Enable */ #define PCI_EXP_LNKCTL_RCB 0x0008 /* Read Completion Boundary */ #define PCI_EXP_LNKCTL_LD 0x0010 /* Link Disable */ #define PCI_EXP_LNKCTL_RL 0x0020 /* Retrain Link */ #define PCI_EXP_LNKCTL_CCC 0x0040 /* Common Clock Configuration */ #define PCI_EXP_LNKCTL_ES 0x0080 /* Extended Synch */ #define PCI_EXP_LNKCTL_CLKREQ_EN 0x0100 /* Enable clkreq */ #define PCI_EXP_LNKCTL_HAWD 0x0200 /* Hardware Autonomous Width Disable */ #define PCI_EXP_LNKCTL_LBMIE 0x0400 /* Link Bandwidth Management Interrupt Enable */ #define PCI_EXP_LNKCTL_LABIE 0x0800 /* Link Autonomous Bandwidth Interrupt Enable */ // PCIe Capability (From Linux) #define PCI_EXP_DEVCTL2 40 /* Device Control 2 */ #define PCI_EXP_DEVCTL2_COMP_TIMEOUT 0x000f /* Completion Timeout Value */ #define PCI_EXP_DEVCTL2_COMP_TMOUT_DIS 0x0010 /* Completion Timeout Disable */ #define PCI_EXP_DEVCTL2_ARI 0x0020 /* Alternative Routing-ID */ #define PCI_EXP_DEVCTL2_ATOMIC_REQ 0x0040 /* Set Atomic requests */ #define PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK 0x0080 /* Block atomic egress */ #define PCI_EXP_DEVCTL2_IDO_REQ_EN 0x0100 /* Allow IDO for requests */ #define PCI_EXP_DEVCTL2_IDO_CMP_EN 0x0200 /* Allow IDO for completions */ #define PCI_EXP_DEVCTL2_LTR_EN 0x0400 /* Enable LTR mechanism */ #define PCI_EXP_DEVCTL2_OBFF_MSGA_EN 0x2000 /* Enable OBFF Message type A */ #define PCI_EXP_DEVCTL2_OBFF_MSGB_EN 0x4000 /* Enable OBFF Message type B */ #define PCI_EXP_DEVCTL2_OBFF_WAKE_EN 0x6000 /* OBFF using WAKE# signaling */ static inline UInt16 IOPCIeDeviceConfigRead16(IOPCIDevice* device, IOByteCount offset) { UInt32 base = device->findPCICapability(kIOPCICapabilityIDPCIExpress); passert(base != 0, "The given device is not a PCIe device."); return device->configRead16(base + offset); } static inline void IOPCIeDeviceConfigWrite16(IOPCIDevice* device, IOByteCount offset, UInt16 value) { UInt32 base = device->findPCICapability(kIOPCICapabilityIDPCIExpress); passert(base != 0, "The given device is not a PCIe device."); device->configWrite16(base + offset, value); } static inline void IOPCIeDeviceConfigSet16(IOPCIDevice* device, IOByteCount offset, UInt16 set) { UInt32 base = device->findPCICapability(kIOPCICapabilityIDPCIExpress); passert(base != 0, "The given device is not a PCIe device."); UInt16 value = device->configRead16(base + offset) | set; device->configWrite16(base + offset, value); } static inline void IOPCIeDeviceConfigClear16(IOPCIDevice* device, IOByteCount offset, UInt16 clear) { UInt32 base = device->findPCICapability(kIOPCICapabilityIDPCIExpress); passert(base != 0, "The given device is not a PCIe device."); UInt16 value = device->configRead16(base + offset) & (~clear); device->configWrite16(base + offset, value); } #endif /* IOPCIeDevice_hpp */
41.349398
99
0.722028
MK-986123
f5367c47a2b5f3a6a25d0542272a52f633531fa0
1,485
cpp
C++
src/solverUtils.cpp
ndehio/copra
81ffa423b95d16140c64f19785ac1836af3ef9bf
[ "BSD-2-Clause" ]
9
2019-12-31T07:51:12.000Z
2021-07-31T16:24:51.000Z
src/solverUtils.cpp
vsamy/Copra
2662c567491690f145834aa8b95339cec3a8bb11
[ "BSD-2-Clause" ]
6
2020-02-21T15:06:31.000Z
2021-12-20T07:17:57.000Z
src/solverUtils.cpp
vsamy/Copra
2662c567491690f145834aa8b95339cec3a8bb11
[ "BSD-2-Clause" ]
4
2020-03-09T14:21:56.000Z
2022-03-04T07:35:01.000Z
/* * Copyright 2016-2019 CNRS-UM LIRMM, CNRS-AIST JRL */ #include "solverUtils.h" namespace copra { std::unique_ptr<SolverInterface> solverFactory(SolverFlag flag) { switch (flag) { #ifdef EIGEN_LSSOL_FOUND case SolverFlag::LSSOL: return std::unique_ptr<LSSOLSolver>(new LSSOLSolver()); #endif #ifdef EIGEN_GUROBI_FOUND case SolverFlag::GUROBIDense: return std::unique_ptr<GUROBISolver>(new GUROBISolver()); #endif #ifdef EIGEN_QLD_FOUND case SolverFlag::QLD: return std::unique_ptr<QLDSolver>(new QLDSolver()); #endif #ifdef EIGEN_OSQP_FOUND case SolverFlag::OSQP: return std::unique_ptr<OSQPSolver>(new OSQPSolver()); #endif // case SolverFlag::QuadProgSparse: // return std::make_unique<QuadProgSparseSolver>(); case SolverFlag::QuadProgDense: default: return std::unique_ptr<QuadProgDenseSolver>(new QuadProgDenseSolver()); } } SolverInterface* pythonSolverFactory(SolverFlag flag) { switch (flag) { #ifdef EIGEN_LSSOL_FOUND case SolverFlag::LSSOL: return new LSSOLSolver; #endif #ifdef EIGEN_GUROBI_FOUND case SolverFlag::GUROBIDense: return new GUROBISolver; #endif #ifdef EIGEN_QLD_FOUND case SolverFlag::QLD: return new QLDSolver; #endif #ifdef EIGEN_OSQP_FOUND case SolverFlag::OSQP: return new OSQPSolver(); #endif case SolverFlag::QuadProgDense: default: return new QuadProgDenseSolver; } } } // namespace copra
23.951613
79
0.709091
ndehio
f53ad2eae1132cc06382fe734a2ace66bdba3107
5,334
cc
C++
mars/sdt/src/sdt_core.cc
20150723/mars
916f895d5d6c31a1f4720b189bb0a83e92e0161c
[ "Apache-2.0", "BSD-2-Clause" ]
56
2019-03-20T06:45:40.000Z
2022-01-07T09:30:00.000Z
mars/sdt/src/sdt_core.cc
20150723/mars
916f895d5d6c31a1f4720b189bb0a83e92e0161c
[ "Apache-2.0", "BSD-2-Clause" ]
2
2019-10-22T02:57:02.000Z
2019-10-31T23:30:17.000Z
mars/sdt/src/sdt_core.cc
pengjinning/mars
227aff64a5b819555091a7d6eae6727701e9fff0
[ "Apache-2.0", "BSD-2-Clause" ]
37
2019-03-20T16:20:46.000Z
2021-05-22T00:31:21.000Z
// Tencent is pleased to support the open source community by making Mars available. // Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. // Licensed under the MIT License (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://opensource.org/licenses/MIT // 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. /* * netchecker_service.cc * * Created on: 2014-6-17 * Author: renlibin caoshaokun */ #include <algorithm> #include "boost/bind.hpp" #include "mars/comm/thread/lock.h" #include "mars/comm/xlogger/xlogger.h" #include "mars/comm/singleton.h" #include "mars/comm/messagequeue/message_queue.h" #include "mars/sdt/constants.h" #include "activecheck/dnschecker.h" #include "activecheck/httpchecker.h" #include "activecheck/pingchecker.h" #include "activecheck/tcpchecker.h" #include "sdt_core.h" using namespace mars::sdt; #define RETURN_NETCHECKER_SYNC2ASYNC_FUNC(func) RETURN_SYNC2ASYNC_FUNC(func, async_reg_.Get(), ) SdtCore::SdtCore() : thread_(boost::bind(&SdtCore::__RunOn, this)) , check_list_(std::list<BaseChecker*>()) , cancel_(false) , checking_(false) { xinfo_function(); } SdtCore::~SdtCore() { xinfo_function(); cancel_ = true; if (!thread_.isruning()) { __Reset(); } else { CancelAndWait(); } } void SdtCore::StartCheck(CheckIPPorts& _longlink_items, CheckIPPorts& _shortlink_items, int _mode, int _timeout) { xinfo_function(); ScopedLock lock(checking_mutex_); if (checking_) return; __InitCheckReq(_longlink_items, _shortlink_items, _mode, _timeout); if (thread_.isruning() || thread_.start() != 0) return; } void SdtCore::__InitCheckReq(CheckIPPorts& _longlink_items, CheckIPPorts& _shortlink_items, int _mode, int _timeout) { xverbose_function(); checking_ = true; check_request_.Reset(); check_request_.longlink_items.insert(_longlink_items.begin(), _longlink_items.end()); check_request_.mode = _mode; check_request_.total_timeout = _timeout; if (MODE_BASIC(_mode)) { PingChecker* ping_checker = new PingChecker(); check_list_.push_back(ping_checker); DnsChecker* dns_checker = new DnsChecker(); check_list_.push_back(dns_checker); } if (MODE_SHORT(_mode)) { check_request_.shortlink_items.insert(_shortlink_items.begin(), _shortlink_items.end()); HttpChecker* http_checker = new HttpChecker(); check_list_.push_back(http_checker); } if (MODE_LONG(_mode)) { TcpChecker* tcp_checker = new TcpChecker(); check_list_.push_back(tcp_checker); } } void SdtCore::__Reset() { xinfo_function(); //check_request_.report std::list<BaseChecker*>::iterator iter = check_list_.begin(); for (; iter != check_list_.end();) { if (NULL != (*iter)) { delete(*iter); (*iter) = NULL; } iter = check_list_.erase(iter); } checking_ = false; } void SdtCore::__RunOn() { xinfo_function(); for (std::list<BaseChecker*>::iterator iter = check_list_.begin(); iter != check_list_.end(); ++iter) { if (cancel_ || check_request_.check_status == kCheckFinish) break; (*iter)->StartDoCheck(check_request_); } xinfo2(TSF"all checkers end! cancel_=%_, check_request_.check_status_=%_, check_list__size=%_", cancel_, check_request_.check_status, check_list_.size()); __DumpCheckResult(); __Reset(); } void SdtCore::__DumpCheckResult() { std::vector<CheckResultProfile>::iterator iter = check_request_.checkresult_profiles.begin(); for (; iter != check_request_.checkresult_profiles.end(); ++iter) { switch(iter->netcheck_type) { case kTcpCheck: xinfo2(TSF"tcp check result, error_code:%_, ip:%_, port:%_, network_type:%_, rtt:%_", iter->error_code, iter->ip, iter->port, iter->network_type, iter->rtt); break; case kHttpCheck: xinfo2(TSF"http check result, status_code:%_, url:%_, ip:%_, port:%_, network_type:%_, rtt:%_", iter->status_code, iter->url, iter->ip, iter->port, iter->network_type, iter->rtt); break; case kPingCheck: xinfo2(TSF"ping check result, error_code:%_, ip:%_, network_type:%_, loss_rate:%_, rtt:%_", iter->error_code, iter->ip, iter->network_type, iter->loss_rate, iter->rtt_str); break; case kDnsCheck: xinfo2(TSF"dns check result, error_code:%_, domain_name:%_, network_type:%_, ip1:%_, rtt:%_", iter->error_code, iter->domain_name, iter->network_type, iter->ip1, iter->rtt); break; } } ReportNetCheckResult(check_request_.checkresult_profiles); } void SdtCore::CancelCheck() { xinfo_function(); cancel_ = true; for (std::list<BaseChecker*>::iterator iter = check_list_.begin(); iter != check_list_.end(); ++iter) { (*iter)->CancelDoCheck(); } } void SdtCore::CancelAndWait() { xinfo_function(); CancelCheck(); thread_.join(); }
31.011628
188
0.679415
20150723
f53d0e783431aff2aa125b6b34b2447ed51ddf8b
21,402
cpp
C++
Src/Orbiter/DlgVishelper.cpp
jarmonik/orbiter
527db6209cb0acd4af839682f2d7f05132818fb8
[ "MIT" ]
1,040
2021-07-27T12:12:06.000Z
2021-08-02T14:24:49.000Z
Src/Orbiter/DlgVishelper.cpp
jarmonik/orbiter
527db6209cb0acd4af839682f2d7f05132818fb8
[ "MIT" ]
20
2021-07-27T12:25:22.000Z
2021-08-02T12:22:19.000Z
Src/Orbiter/DlgVishelper.cpp
jarmonik/orbiter
527db6209cb0acd4af839682f2d7f05132818fb8
[ "MIT" ]
71
2021-07-27T14:19:49.000Z
2021-08-02T05:51:52.000Z
// Copyright (c) Martin Schweiger // Licensed under the MIT License // ====================================================================== // Visual helper options dialog // ====================================================================== #define STRICT 1 #define OEMRESOURCE #include <io.h> #include "Orbiter.h" #include "Camera.h" #include "Psys.h" #include "DlgMgr.h" #include "DlgVishelper.h" #include "Resource.h" #include "DlgCtrl.h" #include "Uxtheme.h" #include <Commctrl.h> extern Orbiter *g_pOrbiter; extern PlanetarySystem *g_psys; extern Camera *g_camera; extern HELPCONTEXT DefHelpContext; // ====================================================================== DlgVishelper::DlgVishelper (HINSTANCE hInstance, HWND hParent, void *context) : DialogWin (hInstance, hParent, IDD_VISHELPER, 0, 0, context) { nTab = 0; hcontext = 0; pos = &g_pOrbiter->Cfg()->CfgWindowPos.DlgCamera; } // ====================================================================== DlgVishelper::~DlgVishelper () { Clear (); } // ====================================================================== void DlgVishelper::Update () { for (int i = 0; i < nTab; i++) pTab[i]->Update (); } // ====================================================================== int DlgVishelper::AddTab (HWND hDlg, VhelperTab *tab, const char *label) { char cbuf[256]; strcpy (cbuf, label); TC_ITEM tie; tie.mask = TCIF_TEXT; tie.iImage = -1; tie.pszText = cbuf; SendDlgItemMessage (hDlg, IDC_TAB1, TCM_INSERTITEM, nTab, (LPARAM)&tie); VhelperTab **tmp = new VhelperTab*[nTab+1]; if (nTab) { memcpy (tmp, pTab, nTab*sizeof(VhelperTab*)); delete []pTab; } pTab = tmp; pTab[nTab] = tab; return nTab++; } // ====================================================================== // Display new tab page void DlgVishelper::SwitchTab (HWND hDlg) { int pg, cpg = TabCtrl_GetCurSel (GetDlgItem (hDlg, IDC_TAB1)); for (pg = 0; pg < nTab; pg++) if (pg != cpg) pTab[pg]->Show (false); pTab[cpg]->Show (true); hcontext = pTab[cpg]->HelpContext(); } // ====================================================================== void DlgVishelper::Clear () { if (nTab) { for (int i = 0; i < nTab; i++) delete pTab[i]; delete []pTab; nTab = 0; } } // ====================================================================== BOOL DlgVishelper::OnInitDialog (HWND hDlg, WPARAM wParam, LPARAM lParam) { HWND hTabFrame = hDlg; AddTab (hDlg, new TabPlanetarium (hTabFrame), "Planetarium"); AddTab (hDlg, new TabForces (hTabFrame), "Forces"); AddTab (hDlg, new TabAxes (hTabFrame), "Axes"); SwitchTab (hDlg); return TRUE; } // ====================================================================== BOOL DlgVishelper::OnCommand (HWND hDlg, WORD id, WORD code, HWND hControl) { switch (id) { case IDHELP: DefHelpContext.topic = hcontext; g_pOrbiter->OpenHelp (&DefHelpContext); return TRUE; } return DialogWin::OnCommand (hDlg, id, code, hControl); } // ====================================================================== BOOL DlgVishelper::OnNotify (HWND hDlg, int idCtrl, LPNMHDR pnmh) { if (pnmh->idFrom == IDC_TAB1) { if (pnmh->code == TCN_SELCHANGE) SwitchTab (hDlg); return TRUE; } return MSG_DEFAULT; } // ====================================================================== // ====================================================================== VhelperTab::VhelperTab (HWND hParentTab, int dlgId, DLGPROC dlgProc) { active = false; hParent = hParentTab; hTab = CreateDialogParam (g_pOrbiter->GetInstance(), MAKEINTRESOURCE(dlgId), hParentTab, dlgProc, (LPARAM)this); } // ====================================================================== void VhelperTab::Show (bool show) { ShowWindow (hTab, show ? SW_SHOW : SW_HIDE); active = show; } // ====================================================================== INT_PTR CALLBACK VhelperTab::DlgProcInit (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: EnableThemeDialogTexture (hWnd, ETDT_ENABLETAB); SetWindowLongPtr (hWnd, DWLP_USER, lParam); return TRUE; } return FALSE; } // ====================================================================== // ====================================================================== TabPlanetarium::TabPlanetarium (HWND hParentTab): VhelperTab (hParentTab, IDD_VHELP_PLANETARIUM, DlgProc) { } // ====================================================================== void TabPlanetarium::Update () { Refresh (hTab); } // ====================================================================== void TabPlanetarium::Refresh (HWND hDlg) { int i; bool enable = g_pOrbiter->Cfg()->PlanetariumItem (IDC_PLANETARIUM); SendDlgItemMessage (hDlg, IDC_PLANETARIUM, BM_SETCHECK, enable ? BST_CHECKED:BST_UNCHECKED, 0); for (i = IDC_PLN_CELGRID; i <= IDC_PLN_SHORT; i++) EnableWindow (GetDlgItem (hDlg, i), enable ? TRUE:FALSE); if (enable && !g_pOrbiter->Cfg()->PlanetariumItem (IDC_PLN_CNSTLABEL)) { for (i = IDC_PLN_FULL; i <= IDC_PLN_SHORT; i++) EnableWindow (GetDlgItem (hDlg, i), FALSE); } } // ====================================================================== char *TabPlanetarium::HelpContext () const { static char *context = "/vh_planetarium.htm"; return context; } // ====================================================================== INT_PTR CALLBACK TabPlanetarium::DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { VhelperTab::DlgProcInit (hWnd, uMsg, wParam, lParam); TabPlanetarium *pTab = (TabPlanetarium*)(uMsg == WM_INITDIALOG ? lParam : GetWindowLongPtr(hWnd,DWLP_USER)); switch (uMsg) { case WM_INITDIALOG: { pTab->Refresh (hWnd); for (int i = IDC_PLN_CELGRID; i <= IDC_PLN_SHORT; i++) SendDlgItemMessage (hWnd, i, BM_SETCHECK, g_pOrbiter->Cfg()->PlanetariumItem (i) ? BST_CHECKED:BST_UNCHECKED, 0); } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_PLANETARIUM: case IDC_PLN_CELGRID: case IDC_PLN_ECLGRID: case IDC_PLN_ECLIPTIC: case IDC_PLN_EQUATOR: case IDC_PLN_CONST: case IDC_PLN_CNSTLABEL: case IDC_PLN_CMARKER: case IDC_PLN_VMARKER: case IDC_PLN_BMARKER: case IDC_PLN_RMARKER: case IDC_PLN_LMARKER: case IDC_PLN_CCMARKER: if (HIWORD(wParam) == BN_CLICKED) { bool check = (SendDlgItemMessage (hWnd, LOWORD(wParam), BM_GETCHECK, 0, 0) == TRUE); g_pOrbiter->Cfg()->SetPlanetariumItem (LOWORD(wParam), check); pTab->Refresh (hWnd); if (LOWORD(wParam) == IDC_PLANETARIUM || LOWORD(wParam) == IDC_PLN_LMARKER) g_psys->ActivatePlanetLabels(g_pOrbiter->Cfg()->PlanetariumItem(IDC_PLANETARIUM) && g_pOrbiter->Cfg()->PlanetariumItem(IDC_PLN_LMARKER)); return TRUE; } break; case IDC_PLN_FULL: case IDC_PLN_SHORT: if (HIWORD(wParam) == BN_CLICKED) { bool check = (SendDlgItemMessage (hWnd, LOWORD(wParam), BM_GETCHECK, 0, 0) == TRUE); g_pOrbiter->Cfg()->SetPlanetariumItem (LOWORD(wParam), check); g_pOrbiter->Cfg()->SetPlanetariumItem (LOWORD(wParam) == IDC_PLN_FULL ? IDC_PLN_SHORT : IDC_PLN_FULL, !check); return TRUE; } break; case IDC_PLN_CONFIG: g_pOrbiter->DlgMgr()->EnsureEntry<DlgCustomLabels> (); break; case IDC_PLN_CONFIG2: g_pOrbiter->DlgMgr()->EnsureEntry<DlgCustomCLabels> (); break; } break; } return FALSE; } // ====================================================================== // ====================================================================== TabForces::TabForces (HWND hParentTab): VhelperTab (hParentTab, IDD_VHELP_BODYFORCE, DlgProc) { } // ====================================================================== void TabForces::Update () { Refresh (hTab, true); } // ====================================================================== void TabForces::Refresh (HWND hDlg, bool tick) { int i; DWORD flag = g_pOrbiter->Cfg()->CfgVisHelpPrm.flagBodyforce; bool active = (flag & BF_ENABLE); SendDlgItemMessage (hDlg, IDC_BODYFORCE, BM_SETCHECK, active ? BST_CHECKED:BST_UNCHECKED, 0); if (tick) { SendDlgItemMessage (hDlg, IDC_WEIGHT, BM_SETCHECK, (flag & BF_WEIGHT) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_THRUST, BM_SETCHECK, (flag & BF_THRUST) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_LIFT, BM_SETCHECK, (flag & BF_LIFT) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_DRAG, BM_SETCHECK, (flag & BF_DRAG) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_TOTAL, BM_SETCHECK, (flag & BF_TOTAL) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_TORQUE, BM_SETCHECK, (flag & BF_TORQUE) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_LINSCALE, BM_SETCHECK, (flag & BF_LOGSCALE) ? BST_UNCHECKED:BST_CHECKED, 0); SendDlgItemMessage (hDlg, IDC_LOGSCALE, BM_SETCHECK, (flag & BF_LOGSCALE) ? BST_CHECKED:BST_UNCHECKED, 0); } for (i = IDC_WEIGHT; i <= IDC_LOGSCALE; i++) EnableWindow (GetDlgItem (hDlg, i), active ? TRUE:FALSE); } // ====================================================================== char *TabForces::HelpContext () const { static char *context = "/vh_force.htm"; return context; } // ====================================================================== INT_PTR CALLBACK TabForces::DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { VhelperTab::DlgProcInit (hWnd, uMsg, wParam, lParam); TabForces *pTab = (TabForces*)(uMsg == WM_INITDIALOG ? lParam : GetWindowLongPtr(hWnd,DWLP_USER)); switch (uMsg) { case WM_INITDIALOG: { GAUGEPARAM gp = { 0, 50, GAUGEPARAM::LEFT, GAUGEPARAM::BLACK }; oapiSetGaugeParams (GetDlgItem (hWnd, IDC_SCALE), &gp); int scl = (int)(25.0*(1.0+0.5*log(g_pOrbiter->Cfg()->CfgVisHelpPrm.scaleBodyforce)/log(2.0))); oapiSetGaugePos (GetDlgItem (hWnd, IDC_SCALE), scl); oapiSetGaugeParams (GetDlgItem (hWnd, IDC_OPACITY), &gp); scl = (int)(g_pOrbiter->Cfg()->CfgVisHelpPrm.opacBodyforce * 50.0); oapiSetGaugePos (GetDlgItem (hWnd, IDC_OPACITY), scl); pTab->Refresh (hWnd, true); } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BODYFORCE: case IDC_WEIGHT: case IDC_THRUST: case IDC_LIFT: case IDC_DRAG: case IDC_TOTAL: case IDC_TORQUE: case IDC_LINSCALE: case IDC_LOGSCALE: if (HIWORD(wParam) == BN_CLICKED) { bool check = (SendDlgItemMessage (hWnd, LOWORD(wParam), BM_GETCHECK, 0, 0) == TRUE); g_pOrbiter->Cfg()->SetBodyforceItem (LOWORD(wParam), check); pTab->Refresh (hWnd, false); return TRUE; } break; } break; case WM_HSCROLL: switch (GetDlgCtrlID ((HWND)lParam)) { case IDC_SCALE: switch (LOWORD(wParam)) { case SB_THUMBTRACK: case SB_LINELEFT: case SB_LINERIGHT: g_pOrbiter->Cfg()->CfgVisHelpPrm.scaleBodyforce = (float)pow (2.0, (HIWORD(wParam)-25)*0.08); return 0; } break; case IDC_OPACITY: switch (LOWORD(wParam)) { case SB_THUMBTRACK: case SB_LINELEFT: case SB_LINERIGHT: g_pOrbiter->Cfg()->CfgVisHelpPrm.opacBodyforce = (float)(HIWORD(wParam)*0.02); return 0; } break; } break; } return FALSE; } // ====================================================================== // ====================================================================== TabAxes::TabAxes (HWND hParentTab): VhelperTab (hParentTab, IDD_VHELP_COORDINATES, DlgProc) { } // ====================================================================== void TabAxes::Update () { Refresh (hTab, true); } // ====================================================================== // Coordinate axes tab: Refresh void TabAxes::Refresh (HWND hDlg, bool tick) { DWORD flag = g_pOrbiter->Cfg()->CfgVisHelpPrm.flagCrdAxes; bool active = (flag & CA_ENABLE); SendDlgItemMessage (hDlg, IDC_COORDINATES, BM_SETCHECK, active ? BST_CHECKED:BST_UNCHECKED, 0); if (tick) { SendDlgItemMessage (hDlg, IDC_CRD_VESSEL, BM_SETCHECK, (flag & CA_VESSEL) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_CRD_CBODY, BM_SETCHECK, (flag & CA_CBODY) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_CRD_BASE, BM_SETCHECK, (flag & CA_BASE) ? BST_CHECKED:BST_UNCHECKED, 0); SendDlgItemMessage (hDlg, IDC_CRD_NEGATIVE, BM_SETCHECK, (flag & CA_NEG) ? BST_CHECKED:BST_UNCHECKED, 0); } for (int i = IDC_CRD_VESSEL; i <= IDC_CRD_OPAC; i++) EnableWindow (GetDlgItem (hDlg, i), active ? TRUE:FALSE); } // ====================================================================== char *TabAxes::HelpContext () const { static char *context = "/vh_coord.htm"; return context; } // ====================================================================== INT_PTR CALLBACK TabAxes::DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { VhelperTab::DlgProcInit (hWnd, uMsg, wParam, lParam); TabAxes *pTab = (TabAxes*)(uMsg == WM_INITDIALOG ? lParam : GetWindowLongPtr(hWnd,DWLP_USER)); switch (uMsg) { case WM_INITDIALOG: { GAUGEPARAM gp = {0, 50, GAUGEPARAM::LEFT, GAUGEPARAM::BLACK }; oapiSetGaugeParams (GetDlgItem (hWnd, IDC_CRD_SCALE), &gp); int scl = (int)(25.0*(1.0+0.5*log(g_pOrbiter->Cfg()->CfgVisHelpPrm.scaleCrdAxes)/log(2.0))); oapiSetGaugePos (GetDlgItem (hWnd, IDC_CRD_SCALE), scl); oapiSetGaugeParams (GetDlgItem (hWnd, IDC_CRD_OPAC), &gp); scl = (int)(g_pOrbiter->Cfg()->CfgVisHelpPrm.opacCrdAxes * 50.0); oapiSetGaugePos (GetDlgItem (hWnd, IDC_CRD_OPAC), scl); pTab->Refresh (hWnd, true); } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_COORDINATES: case IDC_CRD_VESSEL: case IDC_CRD_CBODY: case IDC_CRD_BASE: case IDC_CRD_NEGATIVE: if (HIWORD(wParam) == BN_CLICKED) { bool check = (SendDlgItemMessage (hWnd, LOWORD(wParam), BM_GETCHECK, 0, 0) == TRUE); g_pOrbiter->Cfg()->SetCoordinateAxesItem (LOWORD(wParam), check); pTab->Refresh (hWnd, false); return TRUE; } break; } break; case WM_HSCROLL: switch (GetDlgCtrlID ((HWND)lParam)) { case IDC_CRD_SCALE: switch (LOWORD(wParam)) { case SB_THUMBTRACK: case SB_LINELEFT: case SB_LINERIGHT: g_pOrbiter->Cfg()->CfgVisHelpPrm.scaleCrdAxes = (float)pow (2.0, (HIWORD(wParam)-25)*0.08); return 0; } break; case IDC_CRD_OPAC: switch (LOWORD(wParam)) { case SB_THUMBTRACK: case SB_LINELEFT: case SB_LINERIGHT: g_pOrbiter->Cfg()->CfgVisHelpPrm.opacCrdAxes = (float)(HIWORD(wParam)*0.02); return 0; } break; } break; } return FALSE; } // ====================================================================== // ====================================================================== DlgCustomLabels::DlgCustomLabels (HINSTANCE hInstance, HWND hParent, void *context) : DialogWin (hInstance, hParent, IDD_CUSTOMLABELS, 0, 0, context) { } // ====================================================================== void DlgCustomLabels::Refresh (HWND hDlg) { int i, n, nlist; char cbuf[256], cpath[256]; i = SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_GETCURSEL, 0, 0); SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_GETLBTEXT, i, (LPARAM)cbuf); SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_RESETCONTENT, 0, 0); Planet *planet = g_psys->GetPlanet (cbuf, true); if (!planet) return; if (planet->LabelFormat() < 2) { oapi::GraphicsClient::LABELLIST *list = planet->LabelList (&nlist); if (!nlist) return; _finddata_t fdata; long fh = planet->FindFirst (FILETYPE_MARKER, &fdata, cpath, cbuf); if (fh >= 0) { n = 0; do { SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_ADDSTRING, 0, (LPARAM)trim_string(cbuf)); if (n < nlist && list[n].active) SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_SETSEL, TRUE, n); n++; } while (!planet->FindNext (fh, &fdata, cbuf)); _findclose (fh); } } else { int nlabel = planet->NumLabelLegend(); if (nlabel) { const oapi::GraphicsClient::LABELTYPE *lspec = planet->LabelLegend(); for (i = 0; i < nlabel; i++) { SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_ADDSTRING, 0, (LPARAM)lspec[i].name); if (lspec[i].active) SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_SETSEL, TRUE, i); } } } } // ====================================================================== void DlgCustomLabels::Select (HWND hDlg) { int i, sel, nlist; char cbuf[256]; i = SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_GETCURSEL, 0, 0); SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_GETLBTEXT, i, (LPARAM)cbuf); Planet *planet = g_psys->GetPlanet (cbuf, true); if (!planet) return; if (planet->LabelFormat() < 2) { oapi::GraphicsClient::LABELLIST *list = planet->LabelList (&nlist); if (!nlist) return; for (i = 0; i < nlist; i++) { sel = SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_GETSEL, i, 0); list[i].active = (sel ? true : false); } std::ifstream cfg (g_pOrbiter->Cfg()->ConfigPath (planet->Name())); planet->ScanLabelLists (cfg); } else { nlist = planet->NumLabelLegend(); for (i = 0; i < nlist; i++) { sel = SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_GETSEL, i, 0); planet->SetLabelActive(i, sel ? true : false); } } } // ====================================================================== void DlgCustomLabels::SelectAll(HWND hDlg, bool active) { int i, nlist; char cbuf[256]; i = SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_GETCURSEL, 0, 0); SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_GETLBTEXT, i, (LPARAM)cbuf); Planet *planet = g_psys->GetPlanet (cbuf, true); if (!planet) return; if (planet->LabelFormat() < 2) { oapi::GraphicsClient::LABELLIST *list = planet->LabelList (&nlist); if (!nlist) return; for (i = 0; i < nlist; i++) { SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_SETSEL, active ? TRUE:FALSE, i); list[i].active = active; } } else { nlist = planet->NumLabelLegend(); for (i = 0; i < nlist; i++) { SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_SETSEL, active ? TRUE:FALSE, i); planet->SetLabelActive(i, active); } } } // ====================================================================== BOOL DlgCustomLabels::OnInitDialog (HWND hDlg, WPARAM wParam, LPARAM lParam) { int i, j; const Body *sel = 0; for (i = 0; i < g_psys->nPlanet(); i++) { Planet *planet = g_psys->GetPlanet(i); if (planet == g_camera->Target()) sel = planet; if (planet->isMoon()) continue; SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_ADDSTRING, 0, (LPARAM)planet->Name()); for (j = 0; j < planet->nSecondary(); j++) SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_ADDSTRING, 0, (LPARAM)planet->Secondary(j)->Name()); } if (!sel) { Body *tgt = g_camera->Target(); if (tgt->Type() == OBJTP_VESSEL) sel = ((Vessel*)tgt)->GetSurfParam()->ref; } i = (sel ? SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_FINDSTRINGEXACT, -1, (LPARAM)sel->Name()) : 0); SendDlgItemMessage (hDlg, IDC_CLBL_OBJECT, CB_SETCURSEL, i, 0); Refresh (hDlg); return TRUE; } // ====================================================================== BOOL DlgCustomLabels::OnCommand (HWND hDlg, WORD id, WORD code, HWND hControl) { switch (id) { case IDC_CLBL_OBJECT: if (code == CBN_SELCHANGE) Refresh (hDlg); return TRUE; case IDC_CLBL_LIST: if (code == LBN_SELCHANGE) Select (hDlg); return TRUE; case IDC_BUTTON1: SelectAll(hDlg, true); return TRUE; case IDC_BUTTON2: SelectAll(hDlg, false); return TRUE; } return DialogWin::OnCommand (hDlg, id, code, hControl); } // ====================================================================== // ====================================================================== DlgCustomCLabels::DlgCustomCLabels (HINSTANCE hInstance, HWND hParent, void *context) : DialogWin (hInstance, hParent, IDD_CUSTOMCLABELS, 0, 0, context) { } // ====================================================================== void DlgCustomCLabels::Refresh (HWND hDlg) { int n, nlist; char cbuf[256], cpath[256]; SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_RESETCONTENT, 0, 0); oapi::GraphicsClient::LABELLIST *list = g_psys->LabelList (&nlist); if (!nlist) return; _finddata_t fdata; long fh = g_psys->FindFirst (FILETYPE_MARKER, &fdata, cpath, cbuf); if (fh >= 0) { n = 0; do { SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_ADDSTRING, 0, (LPARAM)trim_string(cbuf)); if (n < nlist && list[n].active) SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_SETSEL, TRUE, n); n++; } while (!g_psys->FindNext (fh, &fdata, cbuf)); _findclose (fh); } } // ====================================================================== void DlgCustomCLabels::Select (HWND hDlg) { int i, sel, nlist; oapi::GraphicsClient::LABELLIST *list = g_psys->LabelList (&nlist); if (!nlist) return; for (i = 0; i < nlist; i++) { sel = SendDlgItemMessage (hDlg, IDC_CLBL_LIST, LB_GETSEL, i, 0); list[i].active = (sel ? true:false); } std::ifstream cfg (g_pOrbiter->Cfg()->ConfigPath (g_psys->Name())); g_psys->ScanLabelLists (cfg); } // ====================================================================== BOOL DlgCustomCLabels::OnInitDialog (HWND hDlg, WPARAM wParam, LPARAM lParam) { Refresh (hDlg); return TRUE; } // ====================================================================== BOOL DlgCustomCLabels::OnCommand (HWND hDlg, WORD id, WORD code, HWND hControl) { switch (id) { case IDC_CLBL_LIST: if (code == LBN_SELCHANGE) Select (hDlg); return TRUE; } return DialogWin::OnCommand (hDlg, id, code, hControl); }
30.27157
142
0.584291
jarmonik
f53d98347ea4d2ea28477a160c66693fa1140608
725
cpp
C++
arc078/a.cpp
nel215/atcoder-grand-contest
a13ce146516c03881f50b7ac284be23d16d29ffe
[ "MIT" ]
null
null
null
arc078/a.cpp
nel215/atcoder-grand-contest
a13ce146516c03881f50b7ac284be23d16d29ffe
[ "MIT" ]
null
null
null
arc078/a.cpp
nel215/atcoder-grand-contest
a13ce146516c03881f50b7ac284be23d16d29ffe
[ "MIT" ]
null
null
null
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <deque> #include <complex> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #define REP(i,x) for(int i=0 ; i<(int)(x) ; i++) #define ALL(x) (x).begin(),(x).end() #define LL long long using namespace std; int main(){ int N; cin >> N; vector<LL> A(N); REP(i, N)cin >> A[i]; LL lhs = 0; LL rhs = 0; LL res = 1LL<<62; REP(i, N)rhs += A[i]; REP(i, N-1){ lhs += A[i]; rhs -= A[i]; res = min(res, abs(lhs-rhs)); } cout << res << endl; return 0; }
17.261905
48
0.554483
nel215
f540a2a0d2c19942aff0d1f12fd74db7a08d5769
425
cpp
C++
Recursion-Challanges/move-all-x-end.cpp
RADIUMz-Codes/Learning-DSA
e316d07f8ba92bfe59a520374f3fc0a59bd62ab1
[ "MIT" ]
3
2021-09-26T21:12:40.000Z
2022-02-11T04:29:20.000Z
Recursion-Challanges/move-all-x-end.cpp
theabhikr03/Learning-DSA
e316d07f8ba92bfe59a520374f3fc0a59bd62ab1
[ "MIT" ]
null
null
null
Recursion-Challanges/move-all-x-end.cpp
theabhikr03/Learning-DSA
e316d07f8ba92bfe59a520374f3fc0a59bd62ab1
[ "MIT" ]
null
null
null
#include <bits/stdc++.h> using namespace std; void move(char ch[], int i, int j) { if (i >= j) { return; } if (ch[i] == 'x') { for (int t = i; t < j ; t++) { ch[t] = ch[t + 1]; } ch[j] = 'x'; move(ch, i + 1, j - 1); } else { move(ch, i + 1, j); } } int main() { // string s; // cin >> s; // cout << s; char ch[1005]; cin >> ch; // cout << ch; move(ch, 0, strlen(ch) - 1); cout << ch; }
10.897436
34
0.428235
RADIUMz-Codes
f5414fa7c164a37f8e92a98a8a9a9e657fcbe02a
6,359
cpp
C++
src/matOptimize/main_helper.cpp
abschneider/usher
2ebfe7013d69097427cce59585a3ee2edd98773b
[ "MIT" ]
null
null
null
src/matOptimize/main_helper.cpp
abschneider/usher
2ebfe7013d69097427cce59585a3ee2edd98773b
[ "MIT" ]
1
2022-02-28T19:49:56.000Z
2022-02-28T19:49:56.000Z
src/matOptimize/main_helper.cpp
abschneider/usher
2ebfe7013d69097427cce59585a3ee2edd98773b
[ "MIT" ]
null
null
null
#include "tree_rearrangement_internal.hpp" #include "check_samples.hpp" #include "Fitch_Sankoff.hpp" #include "src/matOptimize/Twice_Bloom_Filter.hpp" #include "src/matOptimize/mutation_annotated_tree.hpp" #include <algorithm> #include <chrono> #include <cstdio> #include <tbb/blocked_range.h> #include <tbb/concurrent_vector.h> #include <tbb/parallel_for.h> #include <tbb/parallel_sort.h> #include <unordered_set> #include <random> #include <utility> #include <vector> namespace MAT=Mutation_Annotated_Tree; //add a root above current root, so nodes can move above the current node void add_root(MAT::Tree *tree) { MAT::Node *old_root = tree->root; MAT::Node *new_root = new MAT::Node(); new_root->identifier = std::to_string(++tree->curr_internal_node); std::string &node_name = new_root->identifier; new_root->children.push_back(old_root); tree->all_nodes.emplace(node_name, new_root); old_root->parent=new_root; tree->root=new_root; } //Usher expect parent of condensed node have no mutation, so before outputing usher compatible protobuf, //add intermediate nodes to carry mutations of condensed nodes void fix_condensed_nodes(MAT::Tree *tree) { std::vector<MAT::Node *> nodes_to_fix; for (auto iter : tree->all_nodes) { if (tree->condensed_nodes.count(iter.first) && (!iter.second->mutations.empty())) { nodes_to_fix.push_back(iter.second); } } for (auto node : nodes_to_fix) { std::string ori_identifier(node->identifier); tree->rename_node(ori_identifier, std::to_string(++tree->curr_internal_node)); tree->create_node(ori_identifier, node); } } static void mark_changed_neighbor_descendent(int radius_left,MAT::Node* root,bool all_node_reachable) { for (auto child : root->children) { child->set_ancestor_changed(); if (radius_left>0 &&(!child->get_self_changed()) /*&&(!(all_node_reachable&&child->get_ancestor_changed()))*/ ) { mark_changed_neighbor_descendent(radius_left-1, child,all_node_reachable); } } } //see whether within radius of root have nodes that have same mutation as root and have changed in previous iteration (or this is the first iteration) static void mark_changed_neighbor_self(int radius, MAT::Node* root,bool all_node_reachable) { root->set_self_changed(); root->set_ancestor_changed(); root->set_descendent_changed(); mark_changed_neighbor_descendent(radius, root,all_node_reachable); for (int radius_left=radius; radius_left>0; radius_left--) { root=root->parent; if (!root) { return; } if (root->get_self_changed()) { return; } /*if (all_node_reachable&&root->get_descendent_changed()) { return; }*/ root->set_descendent_changed(); mark_changed_neighbor_descendent(radius_left, root,all_node_reachable); } } //find src node to search void find_nodes_to_move(const std::vector<MAT::Node *> &bfs_ordered_nodes, std::vector<MAT::Node *> &output, bool search_all_node, bool search_all_dir,int radius_in,MAT::Tree &tree) { auto start=std::chrono::steady_clock::now(); unsigned int radius=abs(radius_in); output.clear(); fprintf(stderr, "find max_level\n"); auto max_level=tree.get_max_level(); fprintf(stderr, "Max level %zu\n",max_level); bool all_node_reachable=(radius>=(2*max_level)); if (!search_all_dir) { //mark surrounding of changed nodes FILE* fh=fopen("changed_nodes","w"); std::vector<MAT::Node*> changed_nodes_ptr; changed_nodes_ptr.reserve(bfs_ordered_nodes.size()); for (const auto node : bfs_ordered_nodes) { if (node->get_self_changed()) { changed_nodes_ptr.push_back(node); fprintf(fh, "%s\n", node->identifier.c_str()); } } fclose(fh); fprintf(stderr, "%zu changed nodes \n",changed_nodes_ptr.size()); tbb::parallel_for(tbb::blocked_range<size_t>(0,changed_nodes_ptr.size()),[radius,&changed_nodes_ptr,all_node_reachable](const tbb::blocked_range<size_t>& r) { for (size_t idx=r.begin(); idx<r.end(); idx++) { mark_changed_neighbor_self(radius, changed_nodes_ptr[idx],all_node_reachable); } }); } int both_count=0; int upward_only_count=0; int downward_only_count=0; for(auto node:bfs_ordered_nodes) { auto upward=node->get_ancestor_changed(); auto downward=node->get_descendent_changed(); if (upward&&downward) { both_count++; } else if (upward) { upward_only_count++; } else if (downward) { downward_only_count++; } } fprintf(stderr, "Upward: %d,downward %d, both %d \n",upward_only_count,downward_only_count,both_count); if (search_all_node) { output=bfs_ordered_nodes; fprintf(stderr, "Search all nodes\n"); } else { if (all_node_reachable) { output=bfs_ordered_nodes; fprintf(stderr, "Search all nodes\n"); } else { output.reserve(bfs_ordered_nodes.size()); for(auto node:bfs_ordered_nodes) { if (node->have_change_in_neighbor()) { output.push_back(node); } } } } fprintf(stderr, "Will search %f of nodes\n",(double)output.size()/(double)bfs_ordered_nodes.size()); std::chrono::duration<double> elapsed_seconds = std::chrono::steady_clock::now()-start; fprintf(stderr, "Took %f s to find nodes to move\n",elapsed_seconds.count()); } void save_final_tree(MAT::Tree &t, const std::string &output_path) { std::vector<MAT::Node *> dfs = t.depth_first_expansion(); tbb::parallel_for(tbb::blocked_range<size_t>(0, dfs.size()), [&dfs](tbb::blocked_range<size_t> r) { for (size_t i = r.begin(); i < r.end(); i++) { dfs[i]->mutations.remove_invalid(); } }); fix_condensed_nodes(&t); fprintf(stderr, "%zu condensed_nodes\n",t.condensed_nodes.size()); Mutation_Annotated_Tree::save_mutation_annotated_tree(t, output_path); }
39.993711
166
0.643969
abschneider
f54210cd77ddc1322b5decefb9163bb01d338269
2,797
cpp
C++
src/crop_layer.cpp
ahmedfawzyelaraby/yolo-v2-gpu-wrapper
be136b46ebdcf71e5c88450ceb11e7d5158655d7
[ "MIT" ]
null
null
null
src/crop_layer.cpp
ahmedfawzyelaraby/yolo-v2-gpu-wrapper
be136b46ebdcf71e5c88450ceb11e7d5158655d7
[ "MIT" ]
null
null
null
src/crop_layer.cpp
ahmedfawzyelaraby/yolo-v2-gpu-wrapper
be136b46ebdcf71e5c88450ceb11e7d5158655d7
[ "MIT" ]
null
null
null
#include "crop_layer.h" #include "cuda.h" #include <stdio.h> image get_crop_image(crop_layer l) { int h = l.out_h; int w = l.out_w; int c = l.out_c; return float_to_image(w,h,c,l.output); } void backward_crop_layer(const crop_layer l, network_state state){} void backward_crop_layer_gpu(const crop_layer l, network_state state){} crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure) { fprintf(stderr, "Crop Layer: %d x %d -> %d x %d x %d image\n", h,w,crop_height,crop_width,c); crop_layer l; l.type = CROP; l.batch = batch; l.h = h; l.w = w; l.c = c; l.scale = (float)crop_height / h; l.flip = flip; l.angle = angle; l.saturation = saturation; l.exposure = exposure; l.out_w = crop_width; l.out_h = crop_height; l.out_c = c; l.inputs = l.w * l.h * l.c; l.outputs = l.out_w * l.out_h * l.out_c; l.output = (float*)calloc(l.outputs*batch, sizeof(float)); l.forward = forward_crop_layer; l.backward = backward_crop_layer; #ifdef GPU l.forward_gpu = forward_crop_layer_gpu; l.backward_gpu = backward_crop_layer_gpu; l.output_gpu = cuda_make_array(l.output, l.outputs*batch); l.rand_gpu = cuda_make_array(0, l.batch*8); #endif return l; } void resize_crop_layer(layer *l, int w, int h) { l->w = w; l->h = h; l->out_w = l->scale*w; l->out_h = l->scale*h; l->inputs = l->w * l->h * l->c; l->outputs = l->out_h * l->out_w * l->out_c; l->output = (float*)realloc(l->output, l->batch*l->outputs*sizeof(float)); #ifdef GPU cuda_free(l->output_gpu); l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch); #endif } void forward_crop_layer(const crop_layer l, network_state state) { int i,j,c,b,row,col; int index; int count = 0; int flip = (l.flip && rand()%2); int dh = rand()%(l.h - l.out_h + 1); int dw = rand()%(l.w - l.out_w + 1); float scale = 2; float trans = -1; if(l.noadjust){ scale = 1; trans = 0; } if(!state.train){ flip = 0; dh = (l.h - l.out_h)/2; dw = (l.w - l.out_w)/2; } for(b = 0; b < l.batch; ++b){ for(c = 0; c < l.c; ++c){ for(i = 0; i < l.out_h; ++i){ for(j = 0; j < l.out_w; ++j){ if(flip){ col = l.w - dw - j - 1; }else{ col = j + dw; } row = i + dh; index = col+l.w*(row+l.h*(c + l.c*b)); l.output[count++] = state.input[index]*scale + trans; } } } } }
26.894231
148
0.531641
ahmedfawzyelaraby
f5423af1fe05acb75f81e54dceee9ba00b604e1a
24,279
cc
C++
Molecule/mc_summarise.cc
rajarshi/Lilly-Medchem-Rules
cb391fd04ba5820a88e31a8957bff68de08959f7
[ "Apache-2.0" ]
47
2015-01-08T17:26:10.000Z
2022-02-04T10:06:20.000Z
Molecule/mc_summarise.cc
rajarshi/Lilly-Medchem-Rules
cb391fd04ba5820a88e31a8957bff68de08959f7
[ "Apache-2.0" ]
17
2015-03-26T16:06:00.000Z
2021-01-16T21:39:15.000Z
Molecule/mc_summarise.cc
rajarshi/Lilly-Medchem-Rules
cb391fd04ba5820a88e31a8957bff68de08959f7
[ "Apache-2.0" ]
19
2016-05-24T17:52:08.000Z
2020-11-27T06:59:44.000Z
/* Examine the output of tp1_pipe.sh and create a formatted report */ #include <stdlib.h> #define RESIZABLE_ARRAY_IMPLEMENTATION #define RESIZABLE_ARRAY_IWQSORT_IMPLEMENTATION #include "cmdline.h" #include "misc.h" #include "iwqsort.h" #include "iwstring_data_source.h" #include "iw_stl_hash_map.h" const char * prog_name = NULL; static int verbose = 0; static IWString bad_file_stem ("bad"); static IWString bad_file_stem_array ("BQTP"); static int molecules_written = 0; static int rejected_molecules = 0; static int demerited_molecules = 0; static int include_reason = 0; static int include_zero_demerit_molecules = 0; static int include_header_record = 0; static IWString prepend_string; static int prepend_d = 1; static IW_STL_Hash_Map_int reason_bad; static IW_STL_Hash_Map_int reason_survivor; static int accumulate_reasons = 0; static extending_resizable_array<int> demerits_per_molecule; static char output_separator = ' '; static int latex_table = 0; static int asciidoc_table = 0; static int gsub_spaces_in_reason_to_underscore = 0; static int bad0_demerit = 200; static int bad12_demerit = 100; static int produce_demerit_scaling_file = 0; static int suppress_normal_output = 0; static int process_rejection_files = 1; static void usage (int rc) { cerr << __FILE__ << " compiled " << __DATE__ << " " << __TIME__ << endl; cerr << "Converts the results of tp1_pipe.sh into a summary\n"; cerr << " -r include the rejection reason with the output\n"; cerr << " -z include zero demerit molecules in the output\n"; cerr << " -h include a header record\n"; cerr << " -D exclude the D prefix\n"; cerr << " -B <stem> bad file stem (default 'bad')\n"; cerr << " -s <string> separator between output fields\n"; cerr << " -u change spaces in reason fields to underscores\n"; cerr << " -t give report of which reasons hit\n"; cerr << " -T <fname> write report on rejection reasons to <fname>\n"; cerr << " -b in the -T file, produce two column format rejections | demerits\n"; cerr << " -X produce table in LaTex format\n"; cerr << " -A produce table in AsciiDoc format\n"; cerr << " -m <n> in the table file, discard any reason with <n> or fewer examples\n"; cerr << " -c produce a demerit based scale factor file\n"; cerr << " -f <n> numeric demerit value for rejections (default 100)\n"; cerr << " -k only process the survivors file (do not process bad0, bad1...)\n"; cerr << " -v verbose output\n"; exit (rc); } static int write_demerit_value(const const_IWSubstring & id, const int demerit, IWString_and_File_Descriptor & output) { molecules_written++; if (demerit >= 100) rejected_molecules++; else if (demerit > 0) demerited_molecules++; if (suppress_normal_output) return 1; output << id << output_separator; if (prepend_string.length()) output << prepend_string; if (prepend_d) output << 'D'; if (produce_demerit_scaling_file) { if (demerit >= 100) output << '0'; else output << static_cast<float>(100 - demerit) * 0.01f; } else output << demerit; output.write_if_buffer_holds_more_than(32768); return output.good (); } static IW_Regular_Expression d_parentheses ("^D\\([0-9]+\\)$"); static int process_from_iwdemerit(const const_IWSubstring & buffer, int must_have_demerit, IWString_and_File_Descriptor & output) { int i = 0; const_IWSubstring token; buffer.nextword (token, i); const_IWSubstring id; buffer.nextword (id, i); //cerr << "Processing '" << id << "'\n"; int previous_was_colon = 0; const_IWSubstring dmrt; while (buffer.nextword (token, i)) { if (':' == token) { previous_was_colon = 1; continue; } if (! previous_was_colon) continue; if (! d_parentheses.matches (token)) { previous_was_colon = 0; continue; } dmrt = token; dmrt.remove_leading_chars (2); dmrt.chop (); break; } //cerr << " Demerit for '" << id << " is '" << dmrt << "'\n"; if (dmrt.length ()) ; else if (must_have_demerit) { cerr << "NO demerit value found for '" << id << "'\n"; return 0; } else { if (include_zero_demerit_molecules) { write_demerit_value (id, 0, output); if (! suppress_normal_output) output << '\n'; } return output.good (); } int d; (void) dmrt.numeric_value (d); if (d > 100) d = 100; write_demerit_value (id, d, output); if (include_reason) { int demerit_reasons_this_molecule = 0; static IWString myreason; while (buffer.nextword (myreason, i, ':')) { myreason.strip_leading_blanks(); if (! suppress_normal_output) output << output_separator << myreason; if (! accumulate_reasons) ; else if (d >= 100) reason_bad[myreason]++; else reason_survivor[myreason]++; demerit_reasons_this_molecule++; } demerits_per_molecule[demerit_reasons_this_molecule]++; } if (! suppress_normal_output) output << '\n'; output.write_if_buffer_holds_more_than(23768); return output.good (); } static int process_from_iwdemerit (iwstring_data_source & input, int must_have_demerit, IWString_and_File_Descriptor & output) { const_IWSubstring buffer; while (input.next_record (buffer)) { if (! process_from_iwdemerit (buffer, must_have_demerit, output)) { cerr << "Invalid from iwdemerit record, line " << input.lines_read () << endl; cerr << buffer << endl; return 0; } } return output.good (); } static IW_Regular_Expression open_paren ("^\\([0-9]+$"); static int process_bad12 (const const_IWSubstring & buffer, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { int i = 0; const_IWSubstring token; buffer.nextword (token, i); const_IWSubstring id; buffer.nextword (id, i); int got_open_paren = 0; while (buffer.nextword (token, i)) { if (! open_paren.matches (token)) continue; got_open_paren = 1; break; } if (! got_open_paren) { cerr << "Never found a '(\\d+' token\n"; return 0; } buffer.nextword (token, i); if ("matches" != token) { cerr << "Expected 'matches' but got '" << token << "'\n"; return 0; } buffer.nextword (token, i); if ("to" != token) { cerr << "Expected 'to' but got '" << token << "'\n"; return 0; } write_demerit_value (id, bad12_demerit, output); if (include_reason) { static IWString myreason; myreason.resize_keep_storage (0); while (buffer.nextword (token, i)) { if (token.starts_with ('\'')) token.remove_leading_chars (1); if (token.ends_with ("')")) token.chop (2); myreason.append_with_spacer (token); } if (! suppress_normal_output) output << output_separator << myreason; if (accumulate_reasons) reason[myreason]++; } if (! suppress_normal_output) output << '\n'; output.write_if_buffer_holds_more_than(32768); return output.good (); } static int process_bad12 (iwstring_data_source & input, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { const_IWSubstring buffer; while (input.next_record (buffer)) { if (! process_bad12 (buffer, reason, output)) { cerr << "Invalid bad12 record '" << buffer << "'\n"; return 0; } } return output.good (); } static int process_bad12 (const IWString & fname, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { iwstring_data_source input (fname); if (! input.good ()) { cerr << "Cannot open '" << fname << "'\n"; return 0; } return process_bad12 (input, reason, output); } static int process_bad1 (const IWString & bad_stem, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { IWString fname; fname = bad_stem; fname << "1.smi"; return process_bad12 (fname, reason, output); } static int process_bad2 (const IWString & bad_stem, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { IWString fname; fname = bad_stem; fname << "2.smi"; return process_bad12 (fname, reason, output); } static int process_from_iwdemerit (const char * fname, int must_have_demerit, IWString_and_File_Descriptor & output) { iwstring_data_source input (fname); if (! input.good ()) { cerr << "Cannot open '" << fname << "'\n"; return 0; } return process_from_iwdemerit (input, must_have_demerit, output); } static int process_from_iwdemerit (const IWString & bad_stem, IWString_and_File_Descriptor & output, int must_have_demerit) { IWString fname; fname = bad_stem; fname << "3.smi"; return process_from_iwdemerit (fname.null_terminated_chars (), must_have_demerit, output); } static int process_bad0 (const const_IWSubstring & buffer, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { int i = 0; const_IWSubstring token; buffer.nextword (token, i); const_IWSubstring id; buffer.nextword (id, i); int got_tp1 = 0; while (buffer.nextword (token, i)) { if ("TP1" != token) continue; got_tp1 = 1; break; } if (! got_tp1) { cerr << "No 'TP1' token\n"; return 0; } write_demerit_value (id, bad0_demerit, output); if (include_reason) { static IWString myreason; myreason.resize_keep_storage (0); while (buffer.nextword (token, i)) { myreason.append_with_spacer (token); } if (gsub_spaces_in_reason_to_underscore) myreason.gsub (' ', '_'); if (! suppress_normal_output) output << output_separator << myreason; if (accumulate_reasons) reason[myreason]++; } if (! suppress_normal_output) output << '\n'; output.write_if_buffer_holds_more_than(32768); return output.good (); } static int process_bad0 (iwstring_data_source & input, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { const_IWSubstring buffer; while (input.next_record (buffer)) { if (! process_bad0 (buffer, reason, output)) { cerr << "Invalid bad0 record '" << buffer << "'\n"; return 0; } } return output.good (); } static int process_bad01 (const IWString & fname, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { iwstring_data_source input (fname); if (! input.good ()) { cerr << "Cannot open '" << fname << "'\n"; return 0; } return process_bad0 (input, reason, output); } static int process_bad0 (const IWString & bad_stem, IW_STL_Hash_Map_int & reason, IWString_and_File_Descriptor & output) { IWString fname; fname = bad_stem; fname << "0.smi"; return process_bad01 (fname, reason, output); } static int all_files_present (const char * okfile, const IWString & bad_stem) { for (int i = 0; i < 3; i++) { IWString fname; fname << bad_stem << i << ".smi"; if (verbose > 1) cerr << "Checking '" << fname << "', result " << dash_f (fname.null_terminated_chars ()) << endl; if (! dash_f (fname.null_terminated_chars ())) { if (verbose) cerr << "File '" << fname << "' not present\n"; return 0; } } return dash_f (okfile); } static int process_single_run (const char * okfile, const IWString & bad_stem, int ndx, IWString_and_File_Descriptor & output) { if (process_rejection_files) { process_bad0 (bad_stem, reason_bad, output); process_bad1 (bad_stem, reason_bad, output); process_bad2 (bad_stem, reason_bad, output); } process_from_iwdemerit (bad_stem, output, 1); process_from_iwdemerit (okfile, 0, output); return output.good (); } class Reason_and_Count { private: const IWString _reason; const int _count; public: Reason_and_Count (const IWString & r, int c) : _reason(r), _count(c) {} const IWString & reason () const { return _reason;} int count () const { return _count;} template <typename T> int latex_table (T &) const; template <typename T> int asciidoc_table (T & os) const; }; template <typename T> T & operator << (T & os, const Reason_and_Count & rc) { os << rc.count() << ' ' << rc.reason(); return os; } template <typename T> int Reason_and_Count::latex_table (T & os) const { os << _count << " & "; if (_reason.contains('_')) { IWString tmp(_reason); tmp.gsub("_", "\\_"); os << tmp; } else os << _reason; os << "\\\\\n"; return 1; } template <typename T> int Reason_and_Count::asciidoc_table (T & os) const { os << '|' << _count << " | " << _reason; return 1; } class Reason_and_Count_Comparator { private: public: int operator () (const Reason_and_Count *, const Reason_and_Count *) const; }; int Reason_and_Count_Comparator::operator () (const Reason_and_Count * rc1, const Reason_and_Count * rc2) const { if (rc1->count() < rc2->count()) return 1; if (rc1->count() > rc2->count()) return -1; return 0; } static int last_item_meeting_support_requirement (const resizable_array_p<Reason_and_Count> & r, const int min_reasons_needed_for_output) { for (int i = r.number_elements() - 1; i >= 0; --i) { if (r[i]->count() >= min_reasons_needed_for_output) return i; } return -1; } static void sorted_list_of_reasons (const IW_STL_Hash_Map_int & reason, resizable_array_p<Reason_and_Count> & r) { int n = reason.size(); r.resize(n); for (IW_STL_Hash_Map_int::const_iterator i = reason.begin(); i != reason.end(); ++i) { Reason_and_Count * t = new Reason_and_Count( (*i).first, (*i).second); r.add(t); } Reason_and_Count_Comparator rcc; r.iwqsort(rcc); return; } template <typename T> void write_rejection_reason (const resizable_array_p<Reason_and_Count> & r, const int ndx, T & output) { if (ndx < r.number_elements()) { if (latex_table) r[ndx]->latex_table(output); else if (asciidoc_table) r[ndx]->asciidoc_table(output); else output << *(r[ndx]); } else { if (latex_table) output << " & &"; else if (asciidoc_table) output << "|.|."; } return; } /* WRite a multi column file containing rejection reasons, and demerit reasons */ template <typename T> int write_reasons (const IW_STL_Hash_Map_int & reason_bad, const IW_STL_Hash_Map_int & reason_survivor, const int min_reasons_needed_for_output, T & output) { resizable_array_p<Reason_and_Count> rej, dem; sorted_list_of_reasons(reason_bad, rej); sorted_list_of_reasons(reason_survivor, dem); int dstop = last_item_meeting_support_requirement(dem, min_reasons_needed_for_output); int rstop = last_item_meeting_support_requirement(rej, min_reasons_needed_for_output); if (dstop < 0 && rstop < 0) return 1; if (asciidoc_table) { output << "[width=\"30%\", options=\"header\"]\n"; output << "|===============\n"; output << "|N |Rejected |N |Demerits\n"; } else if (latex_table) { output << "\\begin{center}\n"; output << "\\begin{tabular}{r c r c}\n"; output << "Molecules & Reason Rej & Molecules & Reason Demerit \\\\\n"; output << "\\hline\n"; } int istop = dstop; if (istop < rstop) istop = rstop; for (int i = 0; i < istop; ++i) { write_rejection_reason(rej, i, output); write_rejection_reason(dem, i, output); output << '\n'; } if (asciidoc_table) output << "|===============\n"; else if (latex_table) { output << "\\hline\n"; output << "\\end{tabular}\n"; output << "\\end{center}\n"; } return 1; } template <typename T> int write_reasons (const IW_STL_Hash_Map_int & reason, const int min_reasons_needed_for_output, T & output) { resizable_array_p<Reason_and_Count> r; sorted_list_of_reasons(reason, r); if (asciidoc_table) { output << "[width=\"30%\"]\n"; output << "|===============\n"; } else if (latex_table) { output << "\\begin{center}\n"; output << "\\begin{tabular}{r l}\n"; output << "Molecules & Reason \\\\\n"; output << "\\hline\n"; } for (int i = 0; i < r.number_elements(); i++) { const Reason_and_Count * ri = r[i]; if (ri->count() < min_reasons_needed_for_output) break; if (latex_table) ri->latex_table(output); else if (asciidoc_table) ri->asciidoc_table(output); else output << (*ri); output << '\n'; } if (asciidoc_table) { output << "|===============\n"; } else if (latex_table) { output << "\\hline\n"; output << "\\end{tabular}\n"; output << "\\end{center}\n"; } return 1; } static int tp1_summarise (int argc, char ** argv) { Command_Line cl (argc, argv, "vB:S:rhzDs:tT:uj:f:XAP:cnkbm:"); if (cl.unrecognised_options_encountered ()) { cerr << "Unrecognised options encountered\n"; usage (1); } verbose = cl.option_count ('v'); if (cl.option_present ('B')) { cl.value ('B', bad_file_stem); if (verbose) cerr << "Bad files have stem '" << bad_file_stem << "'\n"; bad_file_stem_array = bad_file_stem; } if (cl.option_present ('r')) { include_reason = 1; if (verbose) cerr << "The reason for the rejection will be included\n"; if (cl.option_present ('u')) { gsub_spaces_in_reason_to_underscore = 1; if (verbose) cerr << "Spaces in reason converted to underscore\n"; } } if (cl.option_present ('h')) { include_header_record = 1; if (verbose) cerr << "Will write a header record\n"; } if (cl.option_present ('z')) { include_zero_demerit_molecules = 1; if (verbose) cerr << "Will include zero demerit molecules\n"; } if (cl.option_present ('D')) { prepend_d = 0; if (verbose) cerr << "No D prefix\n"; } if (cl.option_present('P')) { cl.value('P', prepend_string); if (verbose) cerr << "Will prepend '" << prepend_string << "' to all output\n"; } if (cl.option_present ('t')) { accumulate_reasons = 1; include_reason = 1; if (verbose) cerr << "Will accumulate reasons for rejections\n"; } const char * fname_for_reason_summary = NULL; if (cl.option_present('T')) { fname_for_reason_summary = cl.option_value('T'); if (verbose) cerr << "Summary of rejection reasons written to '" << fname_for_reason_summary << "'\n"; accumulate_reasons = 1; include_reason = 1; } if (cl.option_present('c')) { produce_demerit_scaling_file = 1; if (verbose) cerr << "Will produce a file where demerit values have been converted to scaling factors\n"; } if (cl.option_present('n')) { suppress_normal_output = 1; if (verbose) cerr << "Will suppress normal output\n"; } if (cl.option_present('k')) { process_rejection_files = 0; if (verbose) cerr << "Will only process survivor files (not bad0, bad1...)\n"; } // Initial implementation used -j, but it should be -f to be compatible with // what is used in iwdemerit const_IWSubstring fj; if (cl.option_present('j')) cl.value('j', fj); else if (cl.option_present('f')) cl.value('f', fj); if (fj.length()) { int j; if (! fj.numeric_value(j) || j < 1) { cerr << "The rejection threshold value (-f) must be a whole +ve number\n"; usage (4); } bad0_demerit = j; bad12_demerit = j; if (verbose) cerr << "Demerit value assigned to hard rejections " << j << endl; } if (cl.option_present ('s')) { IWString s; cl.value ('s', s); if (! char_name_to_char(s)) { cerr << "Unrecognised output separator '" << s << "'\n"; return 1; } output_separator = s[0]; } if (0 == cl.number_elements ()) { cerr << "Insufficient arguments\n"; usage (2); } IWString_and_File_Descriptor output(1); if (include_header_record) { output << "Name" << output_separator; if (produce_demerit_scaling_file) output << "scale\n"; else output << "demerit\n"; } int rc = 0; cerr << "Processing " << cl.number_elements() << " files\n"; if (1 == cl.number_elements ()) process_single_run (cl[0], bad_file_stem, -1, output); else { for (int i = 0; i < cl.number_elements (); i++) { IWString bstem = bad_file_stem_array; bstem << (i + 1) << '_'; if (! all_files_present (cl[i], bstem)) break; if (verbose) cerr << "Processing okfile '" << cl[i] << "', bad stem '" << bstem << "'\n"; if (! process_single_run (cl[i], bstem, i, output)) { cerr << "Fatal error processing files with stem '" << bstem << "'\n"; rc = i + 1; break; } } } output.flush(); if (cl.option_present('X')) { latex_table = 1; } if (cl.option_present('A')) { asciidoc_table = 1; } if (accumulate_reasons) { cerr << "Encountered " << (reason_bad.size() + reason_survivor.size()) << " different reasons\n"; int min_reasons_needed_for_output = 0; if (cl.option_present('m')) { if (! cl.value('m', min_reasons_needed_for_output) || min_reasons_needed_for_output < 0) { cerr << "The minimum reasons for output (-m) option must be a whole +ve number\n"; usage(1); } if (verbose) cerr << "Will not write any rejection/demerit reason to the -T file with fewer than " << min_reasons_needed_for_output << endl; } if (NULL == fname_for_reason_summary) { for (IW_STL_Hash_Map_int::const_iterator i = reason_bad.begin (); i != reason_bad.end (); ++i) { if (i->second > min_reasons_needed_for_output) cerr << (*i).second << " occurrences of '" << (*i).first << "'\n"; } for (IW_STL_Hash_Map_int::const_iterator i = reason_survivor.begin (); i != reason_survivor.end (); ++i) { if (i->second > min_reasons_needed_for_output) cerr << (*i).second << " occurrences of '" << (*i).first << "'\n"; } } else { IWString_and_File_Descriptor tfile; if (! tfile.open(fname_for_reason_summary)) { cerr << "Cannot open reason summary file '" << fname_for_reason_summary<< "'\n"; return 5; } if (cl.option_present('b')) write_reasons(reason_bad, reason_survivor, min_reasons_needed_for_output, tfile); else { if (verbose) cerr << reason_bad.size() << " reasons associated with rejected molecules, " << reason_survivor.size() << " with survivors\n"; write_reasons (reason_bad, min_reasons_needed_for_output, tfile); write_reasons (reason_survivor, min_reasons_needed_for_output, tfile); } } } if (verbose) { cerr << "Wrote " << molecules_written << " molecules, "; cerr << rejected_molecules << " rejected, " << demerited_molecules << " demerited\n"; for (int i = 0; i < demerits_per_molecule.number_elements (); i++) { if (demerits_per_molecule[i]) cerr << demerits_per_molecule[i] << " molecules had " << i << " demerits\n"; } } return rc; } int main (int argc, char ** argv) { prog_name = argv[0]; int rc = tp1_summarise (argc, argv); return rc; } // arch-tag: da1723f4-6a29-4479-8a6e-ba7ee05882a6
21.814016
136
0.606203
rajarshi
f543abd28b92e1764a45a57d902eac7c1d333739
1,357
hpp
C++
src/test/server/mock_task_runner.hpp
nilsthamm/hyrise
75a701f281bb7dc1636832012c43005ec3c66384
[ "MIT" ]
2
2019-01-22T19:44:32.000Z
2019-01-22T19:52:33.000Z
src/test/server/mock_task_runner.hpp
nilsthamm/hyrise
75a701f281bb7dc1636832012c43005ec3c66384
[ "MIT" ]
69
2019-05-24T10:01:32.000Z
2019-12-13T19:09:05.000Z
src/test/server/mock_task_runner.hpp
nilsthamm/hyrise
75a701f281bb7dc1636832012c43005ec3c66384
[ "MIT" ]
null
null
null
#pragma once #include <boost/thread/future.hpp> #include <memory> #include "gmock/gmock.h" #include "storage/prepared_plan.hpp" #include "tasks/server/bind_server_prepared_statement_task.hpp" #include "tasks/server/create_pipeline_task.hpp" #include "tasks/server/execute_server_prepared_statement_task.hpp" #include "tasks/server/execute_server_query_task.hpp" #include "tasks/server/load_server_file_task.hpp" #include "tasks/server/parse_server_prepared_statement_task.hpp" namespace opossum { class MockTaskRunner { public: MOCK_METHOD1(dispatch_server_task, boost::future<std::unique_ptr<PreparedPlan>>(std::shared_ptr<ParseServerPreparedStatementTask>)); MOCK_METHOD1(dispatch_server_task, boost::future<std::shared_ptr<AbstractOperator>>(std::shared_ptr<BindServerPreparedStatementTask>)); MOCK_METHOD1(dispatch_server_task, boost::future<std::unique_ptr<CreatePipelineResult>>(std::shared_ptr<CreatePipelineTask>)); MOCK_METHOD1(dispatch_server_task, boost::future<std::shared_ptr<const Table>>(std::shared_ptr<ExecuteServerPreparedStatementTask>)); MOCK_METHOD1(dispatch_server_task, boost::future<void>(std::shared_ptr<ExecuteServerQueryTask>)); MOCK_METHOD1(dispatch_server_task, boost::future<void>(std::shared_ptr<LoadServerFileTask>)); }; } // namespace opossum
39.911765
115
0.784819
nilsthamm
f543dc902c554863e3c1692ebfb3a7e77c0f86f7
68
cpp
C++
consumer/test_package/example.cpp
memsharded/source_packages
7b73daef46d8bd5a615f0d2ee079ae0d2a159dbd
[ "MIT" ]
null
null
null
consumer/test_package/example.cpp
memsharded/source_packages
7b73daef46d8bd5a615f0d2ee079ae0d2a159dbd
[ "MIT" ]
null
null
null
consumer/test_package/example.cpp
memsharded/source_packages
7b73daef46d8bd5a615f0d2ee079ae0d2a159dbd
[ "MIT" ]
null
null
null
#include <iostream> #include "greet.h" int main() { greet(); }
9.714286
19
0.588235
memsharded
f54982d6ca383e8f8861420942e41d97dd208a4d
5,696
hpp
C++
sferes/exp/images/ea/rank_simple.hpp
Evolving-AI-Lab/innovation-engine
58c7fcc3cbe3d6f8f59f87d95bdb5f2302f425ba
[ "MIT" ]
31
2015-09-20T03:03:29.000Z
2022-01-25T06:50:20.000Z
sferes/exp/images/ea/rank_simple.hpp
Evolving-AI-Lab/innovation-engine
58c7fcc3cbe3d6f8f59f87d95bdb5f2302f425ba
[ "MIT" ]
1
2016-08-11T07:24:50.000Z
2016-08-17T01:19:57.000Z
sferes/exp/images/ea/rank_simple.hpp
Evolving-AI-Lab/innovation-engine
58c7fcc3cbe3d6f8f59f87d95bdb5f2302f425ba
[ "MIT" ]
10
2015-11-15T01:52:25.000Z
2018-06-11T23:42:58.000Z
//| This file is a part of the sferes2 framework. //| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC) //| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr //| //| This software is a computer program whose purpose is to facilitate //| experiments in evolutionary computation and evolutionary robotics. //| //| This software is governed by the CeCILL license under French law //| and abiding by the rules of distribution of free software. You //| can use, modify and/ or redistribute the software under the terms //| of the CeCILL license as circulated by CEA, CNRS and INRIA at the //| following URL "http://www.cecill.info". //| //| As a counterpart to the access to the source code and rights to //| copy, modify and redistribute granted by the license, users are //| provided only with a limited warranty and the software's author, //| the holder of the economic rights, and the successive licensors //| have only limited liability. //| //| In this respect, the user's attention is drawn to the risks //| associated with loading, using, modifying and/or developing or //| reproducing the software by the user in light of its specific //| status of free software, that may mean that it is complicated to //| manipulate, and that also therefore means that it is reserved for //| developers and experienced professionals having in-depth computer //| knowledge. Users are therefore encouraged to load and test the //| software's suitability as regards their requirements in conditions //| enabling the security of their systems and/or data to be ensured //| and, more generally, to use and operate it in the same conditions //| as regards security. //| //| The fact that you are presently reading this means that you have //| had knowledge of the CeCILL license and that you accept its terms. #ifndef RANK_SIMPLE_HPP_ #define RANK_SIMPLE_HPP_ #include <algorithm> #include <boost/foreach.hpp> #include <sferes/stc.hpp> #include "ea_custom.hpp" #include <sferes/fit/fitness.hpp> #include <exp/images/continue_run/continue_run.hpp> namespace sferes { namespace ea { SFERES_EA(RankSimple, EaCustom) { public: typedef boost::shared_ptr<Phen> indiv_t; typedef std::vector<indiv_t> raw_pop_t; typedef std::vector<indiv_t> pop_t; typedef RankSimple<Phen, Eval, Stat, FitModifier, Params, Exact> this_t; SFERES_CONST unsigned nb_keep = (unsigned)(Params::pop::keep_rate * Params::pop::size); void random_pop() { sferes::cont::Continuator<this_t, Params> continuator; // Continuing a run manually from command line or continuing a run automatically if the job was pre-empted bool continue_run = continuator.enabled() || this->_gen_file_path != ""; if(continue_run) { // Load the population file raw_pop_t raw_pop; if (this->_gen_file_path == "") { raw_pop = continuator.getPopulationFromFile(*this); } else { raw_pop = continuator.getPopulationFromFile(*this, this->_gen_file_path); } // Get the number of population to continue with const size_t init_size = raw_pop.size(); // Resize the current population archive this->_pop.resize(init_size); // Add loaded individuals to the new population int i = 0; BOOST_FOREACH(boost::shared_ptr<Phen>&indiv, this->_pop) { indiv = boost::shared_ptr<Phen>(new Phen(*raw_pop[i])); ++i; } } else { // Original Map-Elites code // Intialize a random population this->_pop.resize(Params::pop::size * Params::pop::initial_aleat); BOOST_FOREACH(boost::shared_ptr<Phen>& indiv, this->_pop) { indiv = boost::shared_ptr<Phen>(new Phen()); indiv->random(); } } // Evaluate the initialized population this->_eval.eval(this->_pop, 0, this->_pop.size()); this->apply_modifier(); std::partial_sort(this->_pop.begin(), this->_pop.begin() + Params::pop::size, this->_pop.end(), fit::compare()); this->_pop.resize(Params::pop::size); // Continue a run from a specific generation if(continue_run) { if (this->_gen_file_path == "") { continuator.run_with_current_population(*this); } else { continuator.run_with_current_population(*this, this->_gen_file_path); } } } //ADDED void setGen(size_t gen) { this->_gen = gen; } //ADDED END void epoch() { assert(this->_pop.size()); for (unsigned i = nb_keep; i < this->_pop.size(); i += 2) { unsigned r1 = _random_rank(); unsigned r2 = _random_rank(); boost::shared_ptr<Phen> i1, i2; this->_pop[r1]->cross(this->_pop[r2], i1, i2); i1->mutate(); i2->mutate(); this->_pop[i] = i1; this->_pop[i + 1] = i2; } #ifndef EA_EVAL_ALL this->_eval.eval(this->_pop, nb_keep, Params::pop::size); #else this->_eval.eval(this->_pop, 0, Params::pop::size); #endif this->apply_modifier(); std::partial_sort(this->_pop.begin(), this->_pop.begin() + nb_keep, this->_pop.end(), fit::compare()); dbg::out(dbg::info, "ea")<<"best fitness: " << this->_pop[0]->fit().value() << std::endl; } protected: unsigned _random_rank() { static float kappa = pow(Params::pop::coeff, nb_keep + 1.0f) - 1.0f; static float facteur = nb_keep / ::log(kappa + 1); return (unsigned) (this->_pop.size() - facteur * log(misc::rand<float>(1) * kappa + 1)); } }; } } #endif
33.704142
112
0.642381
Evolving-AI-Lab
f549c155b012e4475edd1b56e1be94ba641bd1cf
1,319
hpp
C++
Source/Physics/TorqueEffect.hpp
JesseMader/PlasmaEngine
ffda8f76b96e83181cfc1f9ec102c4ad0d7fd131
[ "MIT" ]
null
null
null
Source/Physics/TorqueEffect.hpp
JesseMader/PlasmaEngine
ffda8f76b96e83181cfc1f9ec102c4ad0d7fd131
[ "MIT" ]
null
null
null
Source/Physics/TorqueEffect.hpp
JesseMader/PlasmaEngine
ffda8f76b96e83181cfc1f9ec102c4ad0d7fd131
[ "MIT" ]
null
null
null
// MIT Licensed (see LICENSE.md). #pragma once namespace Plasma { DeclareBitField1(TorqueFlags, LocalTorque); /// Applies a torque to the center of mass of a body. class TorqueEffect : public PhysicsEffect { public: LightningDeclareType(TorqueEffect, TypeCopyMode::ReferenceType); TorqueEffect(); // Component Interface void Serialize(Serializer& stream) override; void DebugDraw() override; // Physics Effect Interface void PreCalculate(real dt) override; void ApplyEffect(RigidBody* obj, real dt) override; // Properties /// Determines if the torque is applied in local or world space. bool GetLocalTorque() const; void SetLocalTorque(bool state); /// The strength of the torque being applied. float GetTorqueStrength() const; void SetTorqueStrength(float strength); /// The axis that the torque is being applied about. Vec3 GetTorqueAxis() const; void SetTorqueAxis(Vec3Param axis); /// The axis of the torque in world space (can be used to manually add torque /// to a RigidBody). Vec3 GetWorldTorqueAxis() const; private: // Whether or not the torque is local. BitField<TorqueFlags::Enum> mTorqueStates; // The strength of torque. float mTorqueStrength; // The axis of the torque. Vec3 mTorqueAxis; Vec3 mWorldTorqueAxis; }; } // namespace Plasma
25.365385
79
0.738438
JesseMader
f54ab02e08fb5f9328ba0e3285889ef5f4c2eea5
1,291
cpp
C++
leetcode/binary-tree/Traversals/94.(Morris-Algo)binary-tree-inorder-traversal.cpp
saurabhraj042/dsaPrep
0973a03bc565a2850003c7e48d99b97ff83b1d01
[ "MIT" ]
23
2021-10-30T04:11:52.000Z
2021-11-27T09:16:18.000Z
leetcode/binary-tree/Traversals/94.(Morris-Algo)binary-tree-inorder-traversal.cpp
Pawanupadhyay10/placement-prep
0449fa7cbc56e7933e6b090936ab7c15ca5f290f
[ "MIT" ]
null
null
null
leetcode/binary-tree/Traversals/94.(Morris-Algo)binary-tree-inorder-traversal.cpp
Pawanupadhyay10/placement-prep
0449fa7cbc56e7933e6b090936ab7c15ca5f290f
[ "MIT" ]
4
2021-10-30T03:26:05.000Z
2021-11-14T12:15:04.000Z
// saurabhraj042 // https://leetcode.com/problems/binary-tree-inorder-traversal/description/ /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: // Morris algorithm in O(N) time and O(1) space; vector<int> inorderTraversal(TreeNode* root) { vector<int> nodes; TreeNode* cur = root; while( cur!=NULL ){ if( cur->left==NULL ){ nodes.push_back( cur->val ); cur = cur->right; }else{ TreeNode* prev = cur->left; while( prev->right!=NULL && prev->right!=cur ) prev = prev->right; if( prev->right==NULL ){ prev->right = cur; cur = cur->left; }else{ prev->right = NULL; nodes.push_back( cur->val ); cur = cur->right; } } } return nodes; } };
27.468085
93
0.477149
saurabhraj042
f54c0221ca5105e1309b0d0f6127aac76cde5e27
258
hpp
C++
src/supermarx/qualified.hpp
Supermarx/common
bb1aaaef4486d6c1089193824fde4533de150b4d
[ "MIT" ]
null
null
null
src/supermarx/qualified.hpp
Supermarx/common
bb1aaaef4486d6c1089193824fde4533de150b4d
[ "MIT" ]
null
null
null
src/supermarx/qualified.hpp
Supermarx/common
bb1aaaef4486d6c1089193824fde4533de150b4d
[ "MIT" ]
null
null
null
#pragma once #include <supermarx/reference.hpp> namespace supermarx { template<typename T> struct qualified { reference<T> id; T data; qualified(reference<T> _id, T const& _data) : id(_id) , data(_data) {} operator T() { return data; } }; }
9.923077
44
0.662791
Supermarx
f54ce737d42d103b6f455a9d66c1bfda412a03a6
2,023
cpp
C++
Poj/POJ - 1236 Network of Schools - Tarjan.cpp
bishoy-magdy/Competitive-Programming
689daac9aeb475da3c28aba4a69df394c68a9a34
[ "MIT" ]
null
null
null
Poj/POJ - 1236 Network of Schools - Tarjan.cpp
bishoy-magdy/Competitive-Programming
689daac9aeb475da3c28aba4a69df394c68a9a34
[ "MIT" ]
null
null
null
Poj/POJ - 1236 Network of Schools - Tarjan.cpp
bishoy-magdy/Competitive-Programming
689daac9aeb475da3c28aba4a69df394c68a9a34
[ "MIT" ]
null
null
null
/** * Network of Schools POJ - 1236 * tarjan algorithm */ #include <cstdio> #include <algorithm> #include <cstring> #define endl '\n' using namespace std; typedef long long ll; const int N = 1e4 + 5, M = 1e6 + 5; int n; struct ADJ { int head[N], nxt[M], to[M], ne; void addEdge(int f, int t) { nxt[ne] = head[f]; to[ne] = t; head[f] = ne++; } void init(int n) { memset(head, -1, n * sizeof head[0]); ne = 0; } } adj, Cgraph; int vis[N], vid, stk[N], stkSz, compId[N], ncp,lw[N],dfsTime[N], curTime; void tarjanDFS(int u){ vis[u]=vid; stk[stkSz++]=u; lw[u]=dfsTime[u]=curTime++; compId[u]=-1; for(int e=adj.head[u]; ~e ; e=adj.nxt[e]){ int v=adj.to[e]; if(vis[v]!=vid){ tarjanDFS(v); ///white lw[u]=min(lw[u],lw[v]); } else if(compId[v]==-1){ // Gray lw[u]=min(lw[u],lw[v]); } } if(lw[u]==dfsTime[u]){ do{ compId[stk[--stkSz]]=ncp; }while (stk[stkSz]!=u); ncp++; } } int notSrc[N], notSnk[N]; void T() { ++vid; ncp=0; curTime=0; for (int i = 0; i < n; ++i) if (vis[i] != vid) tarjanDFS(i); Cgraph.init(ncp); for (int u = 0; u < n; ++u) { for (int e = adj.head[u]; ~e; e = adj.nxt[e]) { int v = adj.to[e]; if (compId[u] == compId[v]) continue; //intera comp edge Cgraph.addEdge(compId[u], compId[v]); notSnk[compId[u]] = vid; notSrc[compId[v]] = vid; } } } int m, q; int main() { scanf("%d", &n); adj.init(n); for (int i = 0; i < n; ++i) { int x; while (scanf("%d", &x), x) { --x; adj.addEdge(i, x); } } T(); int cntSrc = 0 , cntSnk = 0; for(int i = 0 ; i< ncp ; ++i) cntSrc+=notSrc[i]!=vid , cntSnk+=notSnk[i]!=vid; printf("%d\n%d\n",cntSrc , ncp == 1 ? 0 : max(cntSrc,cntSnk)); return 0; }
20.029703
73
0.45131
bishoy-magdy
f54f0a6834f214a983ef1e3179e17445be6c4c91
1,818
cpp
C++
src/Scripts/WeaponFactory.cpp
Quivscor/SoulEngine
2951de54cd09c5a017c01d8ea124e375f0b62b9f
[ "MIT" ]
2
2020-06-24T10:18:13.000Z
2020-06-25T19:34:57.000Z
src/Scripts/WeaponFactory.cpp
Quivscor/SoulEngine
2951de54cd09c5a017c01d8ea124e375f0b62b9f
[ "MIT" ]
null
null
null
src/Scripts/WeaponFactory.cpp
Quivscor/SoulEngine
2951de54cd09c5a017c01d8ea124e375f0b62b9f
[ "MIT" ]
null
null
null
#include "WeaponFactory.h" std::vector<WeaponModel> WeaponFactory::weapons; std::shared_ptr<WeaponFactory>WeaponFactory::m_Instance = nullptr; WeaponFactory::WeaponFactory() { } WeaponFactory::~WeaponFactory() { } void WeaponFactory::SetWeapon(Mesh* mesh, WeaponType type) { WeaponModel newWeapon; newWeapon.model = mesh; newWeapon.type = type; weapons.push_back(newWeapon); } std::shared_ptr<WeaponStats> WeaponFactory::GetWeapon() { if (weapons.size() == 0) return nullptr; WeaponStats newWeapon; int weaponModel = rand() % weapons.size(); newWeapon.model = weapons[weaponModel]; // axe if (weaponModel == 0) { newWeapon.bonusDamage = rand() % 20 + 5; newWeapon.bonusSpeed = ((rand() % 25) / 100.0f) + 2.0f; newWeapon.durability = rand() % 15 + 20; } // mace if (weaponModel == 1) { newWeapon.bonusDamage = rand() % 20; newWeapon.bonusSpeed = ((rand() % 50) / 100.0f) + 2.5f; newWeapon.durability = rand() % 15 + 15; } // sword if (weaponModel == 2) { newWeapon.bonusDamage = rand() % 15; newWeapon.bonusSpeed = ((rand() % 50) / 100.0f) + 2.0f; newWeapon.durability = rand() % 25 + 30; } newWeapon.maxDurability = newWeapon.durability; return std::make_shared<WeaponStats>(newWeapon); } std::shared_ptr<WeaponStats> WeaponFactory::GetDefaultWeapon() { if (weapons.size() == 0) return nullptr; WeaponStats newWeapon; for(int i = 0; i < weapons.size(); i++) if (weapons[i].type == Sword) newWeapon.model = weapons[i]; newWeapon.bonusDamage = 0; newWeapon.bonusSpeed = 2.0f; return std::make_shared<WeaponStats>(newWeapon); } /*std::shared_ptr<WeaponFactory> WeaponFactory::GetInstance() { if (WeaponFactory::m_Instance == NULL) { WeaponFactory::m_Instance = std::make_shared<WeaponFactory>(); } return WeaponFactory::m_Instance; }*/
20.426966
66
0.686469
Quivscor
f550a97718855d2d8964e85d6112e9ce2809ee20
250,735
cc
C++
src/quadrature_fem_math/Quadrule_New.cc
pgmaginot/DARK_ARTS
f04b0a30dcac911ef06fe0916921020826f5c42b
[ "MIT" ]
null
null
null
src/quadrature_fem_math/Quadrule_New.cc
pgmaginot/DARK_ARTS
f04b0a30dcac911ef06fe0916921020826f5c42b
[ "MIT" ]
null
null
null
src/quadrature_fem_math/Quadrule_New.cc
pgmaginot/DARK_ARTS
f04b0a30dcac911ef06fe0916921020826f5c42b
[ "MIT" ]
null
null
null
/** @file Quadrule_New.cc * @author The internet / pmaginot * @brief Implement the Quadrule_New class that changes the original quadrule into a vector format */ #include "Quadrule_New.h" // ########################################################## // Public functions // ########################################################## //**************************************************************************** void Quadrule_New::legendre_dr_compute ( const int order, std::vector<double>& xtab, std::vector<double> weight ) const //**************************************************************************** // // Purpose: // // LEGENDRE_DR_COMPUTE: Gauss-Legendre quadrature by Davis-Rabinowitz method. // // Discussion: // // The integral: // // Integral ( -1 <= X <= 1 ) F(X) dX // // The quadrature rule: // // Sum ( 1 <= I <= ORDER ) WEIGHT(I) * F ( XTAB(I) ) // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified/Authored: // // C++ version by John Burkardt- 28 August 2007 // Peter Maginot- 11 June 2014 // // Reference: // // Philip Davis, Philip Rabinowitz, // Methods of Numerical Integration, // Second Edition, // Dover, 2007, // ISBN: 0486453391, // LC: QA299.3.D28. // // Parameters: // // Input, int ORDER, the order. // ORDER must be greater than 0. // // Output, double XTAB[ORDER], the abscissas. // // Output, double WEIGHT[ORDER], the weights. // { throw Dark_Arts_Exception(SUPPORT_OBJECT , "legendre_dr_compute does not work correctly, weights not correct. Don't use!"); double d1=0.; double d2pn=0.; double d3pn=0.; double d4pn=0.; double dp=0.; double dpn=0.; double e1=0.; double fx=0.; double h=0.; int i=0; int iback=0; int k=0; int m=0; int mp1mi=0; int ncopy=0; int nmove=0; double p=0.; const double r8_pi = 3.141592653589793; double pk=0.; double pkm1=0.; double pkp1=0.; double t=0.; double u=0.; double v=0.; double x0=0.; double xtemp=0.; if ( order < 1 ) { std::stringstream err; err << "LEGENDRE_DR_COMPUTE - Fatal error!\n" << " Illegal value of ORDER = " << order << "\n"; throw Dark_Arts_Exception( SUPPORT_OBJECT , err.str() ); } e1 = ( double ) ( order * ( order + 1 ) ); m = ( order + 1 ) / 2; for ( i = 1; i <= m; i++ ) { mp1mi = m + 1 - i; t = ( double ) ( 4 * i - 1 ) * r8_pi / ( double ) ( 4 * order + 2 ); x0 = cos ( t ) * ( 1.0 - ( 1.0 - 1.0 / ( double ) ( order ) ) / ( double ) ( 8 * order * order ) ); pkm1 = 1.0; pk = x0; for ( k = 2; k <= order; k++ ) { pkp1 = 2.0 * x0 * pk - pkm1 - ( x0 * pk - pkm1 ) / ( double ) ( k ); pkm1 = pk; pk = pkp1; } d1 = ( double ) ( order ) * ( pkm1 - x0 * pk ); dpn = d1 / ( 1.0 - x0 * x0 ); d2pn = ( 2.0 * x0 * dpn - e1 * pk ) / ( 1.0 - x0 * x0 ); d3pn = ( 4.0 * x0 * d2pn + ( 2.0 - e1 ) * dpn ) / ( 1.0 - x0 * x0 ); d4pn = ( 6.0 * x0 * d3pn + ( 6.0 - e1 ) * d2pn ) / ( 1.0 - x0 * x0 ); u = pk / dpn; v = d2pn / dpn; // // Initial approximation H: // h = -u * ( 1.0 + 0.5 * u * ( v + u * ( v * v - d3pn / ( 3.0 * dpn ) ) ) ); // // Refine H using one step of Newton's method: // p = pk + h * ( dpn + 0.5 * h * ( d2pn + h / 3.0 * ( d3pn + 0.25 * h * d4pn ) ) ); dp = dpn + h * ( d2pn + 0.5 * h * ( d3pn + h * d4pn / 3.0 ) ); h = h - p / dp; xtemp = x0 + h; xtab[mp1mi-1] = xtemp; fx = d1 - h * e1 * ( pk + 0.5 * h * ( dpn + h / 3.0 * ( d2pn + 0.25 * h * ( d3pn + 0.2 * h * d4pn ) ) ) ); weight[mp1mi-1] = 2.0 * ( 1.0 - xtemp * xtemp ) / ( fx * fx ); } if ( ( order % 2 ) == 1 ) { xtab[0] = 0.0; } // // Shift the data up. // nmove = ( order + 1 ) / 2; ncopy = order - nmove; for ( i = 1; i <= nmove; i++ ) { iback = order + 1 - i; xtab[iback-1] = xtab[iback-ncopy-1]; weight[iback-1] = weight[iback-ncopy-1]; } // // Reflect values for the negative abscissas. // for ( i = 1; i <= order - nmove; i++ ) { xtab[i-1] = - xtab[order-i]; weight[i-1] = weight[order-i]; } return; } //**************************************************************************** void Quadrule_New::legendre_ek_compute ( const int n, std::vector<double>& x, std::vector<double>& w ) const //**************************************************************************** // // Purpose: // // LEGENDRE_EK_COMPUTE: Legendre quadrature rule by the Elhay-Kautsky method. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified/Authored: // // John Burkardt- 19 April 2011 // Peter Maginot- 11 June 2014 // // Reference: // // Sylvan Elhay, Jaroslav Kautsky, // Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of // Interpolatory Quadrature, // ACM Transactions on Mathematical Software, // Volume 13, Number 4, December 1987, pages 399-415. // // Parameters: // // Input, int N, the order. // // Output, double X[N], the abscissas. // // Output, double W[N], the weights. // { std::vector<double> bj; int i=0; // // Define the zero-th moment. // double zemu = 2.0; // // Define the Jacobi matrix. // bj.resize(n,0.); for ( i = 0; i < n; i++ ) { bj[i] = ( double ) ( ( i + 1 ) * ( i + 1 ) ) / ( double ) ( 4 * ( i + 1 ) * ( i + 1 ) - 1 ); bj[i] = sqrt ( bj[i] ); } for ( i = 0; i < n; i++ ) { x[i] = 0.0; } w[0] = sqrt ( zemu ); for ( i = 1; i < n; i++ ) { w[i] = 0.0; } // // Diagonalize the Jacobi matrix. // imtqlx ( n, x, bj, w ); for ( i = 0; i < n; i++ ) { w[i] = w[i] * w[i]; } return; } //**************************************************************************** void Quadrule_New::legendre_set ( const int n, std::vector<double>& x, std::vector<double>& w ) const //**************************************************************************** // // Purpose: // // LEGENDRE_SET sets abscissas and weights for Gauss-Legendre quadrature. // // Discussion: // // The integral: // // Integral ( -1 <= X <= 1 ) F(X) dX // // Quadrature rule: // // Sum ( 1 <= I <= N ) W(I) * F ( X(I) ) // // The quadrature rule is exact for all polynomials through degree 2*N-1. // // The abscissas are the zeroes of the Legendre polynomial P(N)(X). // // Mathematica can compute the abscissas and weights of a Gauss-Legendre // rule of order N for the interval [A,B] with P digits of precision // by the commands: // // Needs["NumericalDifferentialEquationAnalysis`"] // GaussianQuadratureWeights [ n, a, b, p ] // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified/Author: // // John Burkardt- 20 April 2010 // Peter Maginot- 11 June 2014 // // Reference: // // Milton Abramowitz, Irene Stegun, // Handbook of Mathematical Functions, // National Bureau of Standards, 1964, // ISBN: 0-486-61272-4, // LC: QA47.A34. // // Vladimir Krylov, // Approximate Calculation of Integrals, // Dover, 2006, // ISBN: 0486445798. // LC: QA311.K713. // // Arthur Stroud, Don Secrest, // Gaussian Quadrature Formulas, // Prentice Hall, 1966, // LC: QA299.4G3S7. // // Stephen Wolfram, // The Mathematica Book, // Fourth Edition, // Cambridge University Press, 1999, // ISBN: 0-521-64314-7, // LC: QA76.95.W65. // // Daniel Zwillinger, editor, // CRC Standard Mathematical Tables and Formulae, // 30th Edition, // CRC Press, 1996, // ISBN: 0-8493-2479-3, // LC: QA47.M315. // // Parameters: // // Input, int N, the order. // N must be between 1 and 33 or 63/64/65, 127/128/129, // 255/256/257. // // Output, double X[N], the abscissas. // // Output, double W[N], the weights. // { if ( n == 1 ) { x[0] = 0.000000000000000000000000000000; w[0] = 2.000000000000000000000000000000; } else if ( n == 2 ) { x[0] = -0.577350269189625764509148780502; x[1] = 0.577350269189625764509148780502; w[0] = 1.000000000000000000000000000000; w[1] = 1.000000000000000000000000000000; } else if ( n == 3 ) { x[0] = -0.774596669241483377035853079956; x[1] = 0.000000000000000000000000000000; x[2] = 0.774596669241483377035853079956; w[0] = 0.555555555555555555555555555556; w[1] = 0.888888888888888888888888888889; w[2] = 0.555555555555555555555555555556; } else if ( n == 4 ) { x[0] = -0.861136311594052575223946488893; x[1] = -0.339981043584856264802665759103; x[2] = 0.339981043584856264802665759103; x[3] = 0.861136311594052575223946488893; w[0] = 0.347854845137453857373063949222; w[1] = 0.652145154862546142626936050778; w[2] = 0.652145154862546142626936050778; w[3] = 0.347854845137453857373063949222; } else if ( n == 5 ) { x[0] = -0.906179845938663992797626878299; x[1] = -0.538469310105683091036314420700; x[2] = 0.000000000000000000000000000000; x[3] = 0.538469310105683091036314420700; x[4] = 0.906179845938663992797626878299; w[0] = 0.236926885056189087514264040720; w[1] = 0.478628670499366468041291514836; w[2] = 0.568888888888888888888888888889; w[3] = 0.478628670499366468041291514836; w[4] = 0.236926885056189087514264040720; } else if ( n == 6 ) { x[0] = -0.932469514203152027812301554494; x[1] = -0.661209386466264513661399595020; x[2] = -0.238619186083196908630501721681; x[3] = 0.238619186083196908630501721681; x[4] = 0.661209386466264513661399595020; x[5] = 0.932469514203152027812301554494; w[0] = 0.171324492379170345040296142173; w[1] = 0.360761573048138607569833513838; w[2] = 0.467913934572691047389870343990; w[3] = 0.467913934572691047389870343990; w[4] = 0.360761573048138607569833513838; w[5] = 0.171324492379170345040296142173; } else if ( n == 7 ) { x[0] = -0.949107912342758524526189684048; x[1] = -0.741531185599394439863864773281; x[2] = -0.405845151377397166906606412077; x[3] = 0.000000000000000000000000000000; x[4] = 0.405845151377397166906606412077; x[5] = 0.741531185599394439863864773281; x[6] = 0.949107912342758524526189684048; w[0] = 0.129484966168869693270611432679; w[1] = 0.279705391489276667901467771424; w[2] = 0.381830050505118944950369775489; w[3] = 0.417959183673469387755102040816; w[4] = 0.381830050505118944950369775489; w[5] = 0.279705391489276667901467771424; w[6] = 0.129484966168869693270611432679; } else if ( n == 8 ) { x[0] = -0.960289856497536231683560868569; x[1] = -0.796666477413626739591553936476; x[2] = -0.525532409916328985817739049189; x[3] = -0.183434642495649804939476142360; x[4] = 0.183434642495649804939476142360; x[5] = 0.525532409916328985817739049189; x[6] = 0.796666477413626739591553936476; x[7] = 0.960289856497536231683560868569; w[0] = 0.101228536290376259152531354310; w[1] = 0.222381034453374470544355994426; w[2] = 0.313706645877887287337962201987; w[3] = 0.362683783378361982965150449277; w[4] = 0.362683783378361982965150449277; w[5] = 0.313706645877887287337962201987; w[6] = 0.222381034453374470544355994426; w[7] = 0.101228536290376259152531354310; } else if ( n == 9 ) { x[0] = -0.968160239507626089835576203; x[1] = -0.836031107326635794299429788; x[2] = -0.613371432700590397308702039; x[3] = -0.324253423403808929038538015; x[4] = 0.000000000000000000000000000; x[5] = 0.324253423403808929038538015; x[6] = 0.613371432700590397308702039; x[7] = 0.836031107326635794299429788; x[8] = 0.968160239507626089835576203; w[0] = 0.081274388361574411971892158111; w[1] = 0.18064816069485740405847203124; w[2] = 0.26061069640293546231874286942; w[3] = 0.31234707704000284006863040658; w[4] = 0.33023935500125976316452506929; w[5] = 0.31234707704000284006863040658; w[6] = 0.26061069640293546231874286942; w[7] = 0.18064816069485740405847203124; w[8] = 0.081274388361574411971892158111; } else if ( n == 10 ) { x[0] = -0.973906528517171720077964012; x[1] = -0.865063366688984510732096688; x[2] = -0.679409568299024406234327365; x[3] = -0.433395394129247190799265943; x[4] = -0.148874338981631210884826001; x[5] = 0.148874338981631210884826001; x[6] = 0.433395394129247190799265943; x[7] = 0.679409568299024406234327365; x[8] = 0.865063366688984510732096688; x[9] = 0.973906528517171720077964012; w[0] = 0.066671344308688137593568809893; w[1] = 0.14945134915058059314577633966; w[2] = 0.21908636251598204399553493423; w[3] = 0.26926671930999635509122692157; w[4] = 0.29552422471475287017389299465; w[5] = 0.29552422471475287017389299465; w[6] = 0.26926671930999635509122692157; w[7] = 0.21908636251598204399553493423; w[8] = 0.14945134915058059314577633966; w[9] = 0.066671344308688137593568809893; } else if ( n == 11 ) { x[0] = -0.978228658146056992803938001; x[1] = -0.887062599768095299075157769; x[2] = -0.730152005574049324093416252; x[3] = -0.519096129206811815925725669; x[4] = -0.269543155952344972331531985; x[5] = 0.000000000000000000000000000; x[6] = 0.269543155952344972331531985; x[7] = 0.519096129206811815925725669; x[8] = 0.730152005574049324093416252; x[9] = 0.887062599768095299075157769; x[10] = 0.978228658146056992803938001; w[0] = 0.055668567116173666482753720443; w[1] = 0.12558036946490462463469429922; w[2] = 0.18629021092773425142609764143; w[3] = 0.23319376459199047991852370484; w[4] = 0.26280454451024666218068886989; w[5] = 0.27292508677790063071448352834; w[6] = 0.26280454451024666218068886989; w[7] = 0.23319376459199047991852370484; w[8] = 0.18629021092773425142609764143; w[9] = 0.12558036946490462463469429922; w[10] = 0.055668567116173666482753720443; } else if ( n == 12 ) { x[0] = -0.981560634246719250690549090; x[1] = -0.904117256370474856678465866; x[2] = -0.769902674194304687036893833; x[3] = -0.587317954286617447296702419; x[4] = -0.367831498998180193752691537; x[5] = -0.125233408511468915472441369; x[6] = 0.125233408511468915472441369; x[7] = 0.367831498998180193752691537; x[8] = 0.587317954286617447296702419; x[9] = 0.769902674194304687036893833; x[10] = 0.904117256370474856678465866; x[11] = 0.981560634246719250690549090; w[0] = 0.047175336386511827194615961485; w[1] = 0.10693932599531843096025471819; w[2] = 0.16007832854334622633465252954; w[3] = 0.20316742672306592174906445581; w[4] = 0.23349253653835480876084989892; w[5] = 0.24914704581340278500056243604; w[6] = 0.24914704581340278500056243604; w[7] = 0.23349253653835480876084989892; w[8] = 0.20316742672306592174906445581; w[9] = 0.16007832854334622633465252954; w[10] = 0.10693932599531843096025471819; w[11] = 0.047175336386511827194615961485; } else if ( n == 13 ) { x[0] = -0.984183054718588149472829449; x[1] = -0.917598399222977965206547837; x[2] = -0.801578090733309912794206490; x[3] = -0.642349339440340220643984607; x[4] = -0.448492751036446852877912852; x[5] = -0.230458315955134794065528121; x[6] = 0.000000000000000000000000000; x[7] = 0.230458315955134794065528121; x[8] = 0.448492751036446852877912852; x[9] = 0.642349339440340220643984607; x[10] = 0.80157809073330991279420649; x[11] = 0.91759839922297796520654784; x[12] = 0.98418305471858814947282945; w[0] = 0.040484004765315879520021592201; w[1] = 0.092121499837728447914421775954; w[2] = 0.13887351021978723846360177687; w[3] = 0.17814598076194573828004669200; w[4] = 0.20781604753688850231252321931; w[5] = 0.22628318026289723841209018604; w[6] = 0.23255155323087391019458951527; w[7] = 0.22628318026289723841209018604; w[8] = 0.20781604753688850231252321931; w[9] = 0.17814598076194573828004669200; w[10] = 0.13887351021978723846360177687; w[11] = 0.092121499837728447914421775954; w[12] = 0.040484004765315879520021592201; } else if ( n == 14 ) { x[0] = -0.986283808696812338841597267; x[1] = -0.928434883663573517336391139; x[2] = -0.827201315069764993189794743; x[3] = -0.687292904811685470148019803; x[4] = -0.515248636358154091965290719; x[5] = -0.319112368927889760435671824; x[6] = -0.108054948707343662066244650; x[7] = 0.108054948707343662066244650; x[8] = 0.31911236892788976043567182; x[9] = 0.51524863635815409196529072; x[10] = 0.68729290481168547014801980; x[11] = 0.82720131506976499318979474; x[12] = 0.92843488366357351733639114; x[13] = 0.98628380869681233884159727; w[0] = 0.035119460331751863031832876138; w[1] = 0.08015808715976020980563327706; w[2] = 0.12151857068790318468941480907; w[3] = 0.15720316715819353456960193862; w[4] = 0.18553839747793781374171659013; w[5] = 0.20519846372129560396592406566; w[6] = 0.21526385346315779019587644332; w[7] = 0.21526385346315779019587644332; w[8] = 0.20519846372129560396592406566; w[9] = 0.18553839747793781374171659013; w[10] = 0.15720316715819353456960193862; w[11] = 0.12151857068790318468941480907; w[12] = 0.08015808715976020980563327706; w[13] = 0.035119460331751863031832876138; } else if ( n == 15 ) { x[0] = -0.987992518020485428489565719; x[1] = -0.937273392400705904307758948; x[2] = -0.848206583410427216200648321; x[3] = -0.724417731360170047416186055; x[4] = -0.570972172608538847537226737; x[5] = -0.394151347077563369897207371; x[6] = -0.201194093997434522300628303; x[7] = 0.00000000000000000000000000; x[8] = 0.20119409399743452230062830; x[9] = 0.39415134707756336989720737; x[10] = 0.57097217260853884753722674; x[11] = 0.72441773136017004741618605; x[12] = 0.84820658341042721620064832; x[13] = 0.93727339240070590430775895; x[14] = 0.98799251802048542848956572; w[0] = 0.030753241996117268354628393577; w[1] = 0.070366047488108124709267416451; w[2] = 0.107159220467171935011869546686; w[3] = 0.13957067792615431444780479451; w[4] = 0.16626920581699393355320086048; w[5] = 0.18616100001556221102680056187; w[6] = 0.19843148532711157645611832644; w[7] = 0.20257824192556127288062019997; w[8] = 0.19843148532711157645611832644; w[9] = 0.18616100001556221102680056187; w[10] = 0.16626920581699393355320086048; w[11] = 0.13957067792615431444780479451; w[12] = 0.107159220467171935011869546686; w[13] = 0.070366047488108124709267416451; w[14] = 0.030753241996117268354628393577; } else if ( n == 16 ) { x[0] = -0.989400934991649932596154173; x[1] = -0.944575023073232576077988416; x[2] = -0.865631202387831743880467898; x[3] = -0.755404408355003033895101195; x[4] = -0.617876244402643748446671764; x[5] = -0.458016777657227386342419443; x[6] = -0.281603550779258913230460501; x[7] = -0.09501250983763744018531934; x[8] = 0.09501250983763744018531934; x[9] = 0.28160355077925891323046050; x[10] = 0.45801677765722738634241944; x[11] = 0.61787624440264374844667176; x[12] = 0.75540440835500303389510119; x[13] = 0.86563120238783174388046790; x[14] = 0.94457502307323257607798842; x[15] = 0.98940093499164993259615417; w[0] = 0.027152459411754094851780572456; w[1] = 0.062253523938647892862843836994; w[2] = 0.09515851168249278480992510760; w[3] = 0.12462897125553387205247628219; w[4] = 0.14959598881657673208150173055; w[5] = 0.16915651939500253818931207903; w[6] = 0.18260341504492358886676366797; w[7] = 0.18945061045506849628539672321; w[8] = 0.18945061045506849628539672321; w[9] = 0.18260341504492358886676366797; w[10] = 0.16915651939500253818931207903; w[11] = 0.14959598881657673208150173055; w[12] = 0.12462897125553387205247628219; w[13] = 0.09515851168249278480992510760; w[14] = 0.062253523938647892862843836994; w[15] = 0.027152459411754094851780572456; } else if ( n == 17 ) { x[0] = -0.990575475314417335675434020; x[1] = -0.950675521768767761222716958; x[2] = -0.880239153726985902122955694; x[3] = -0.781514003896801406925230056; x[4] = -0.657671159216690765850302217; x[5] = -0.512690537086476967886246569; x[6] = -0.35123176345387631529718552; x[7] = -0.17848418149584785585067749; x[8] = 0.00000000000000000000000000; x[9] = 0.17848418149584785585067749; x[10] = 0.35123176345387631529718552; x[11] = 0.51269053708647696788624657; x[12] = 0.65767115921669076585030222; x[13] = 0.78151400389680140692523006; x[14] = 0.88023915372698590212295569; x[15] = 0.95067552176876776122271696; x[16] = 0.99057547531441733567543402; w[0] = 0.024148302868547931960110026288; w[1] = 0.055459529373987201129440165359; w[2] = 0.085036148317179180883535370191; w[3] = 0.111883847193403971094788385626; w[4] = 0.13513636846852547328631998170; w[5] = 0.15404576107681028808143159480; w[6] = 0.16800410215645004450997066379; w[7] = 0.17656270536699264632527099011; w[8] = 0.17944647035620652545826564426; w[9] = 0.17656270536699264632527099011; w[10] = 0.16800410215645004450997066379; w[11] = 0.15404576107681028808143159480; w[12] = 0.13513636846852547328631998170; w[13] = 0.111883847193403971094788385626; w[14] = 0.085036148317179180883535370191; w[15] = 0.055459529373987201129440165359; w[16] = 0.024148302868547931960110026288; } else if ( n == 18 ) { x[0] = -0.991565168420930946730016005; x[1] = -0.955823949571397755181195893; x[2] = -0.892602466497555739206060591; x[3] = -0.803704958972523115682417455; x[4] = -0.691687043060353207874891081; x[5] = -0.55977083107394753460787155; x[6] = -0.41175116146284264603593179; x[7] = -0.25188622569150550958897285; x[8] = -0.08477501304173530124226185; x[9] = 0.08477501304173530124226185; x[10] = 0.25188622569150550958897285; x[11] = 0.41175116146284264603593179; x[12] = 0.55977083107394753460787155; x[13] = 0.69168704306035320787489108; x[14] = 0.80370495897252311568241746; x[15] = 0.89260246649755573920606059; x[16] = 0.95582394957139775518119589; x[17] = 0.99156516842093094673001600; w[0] = 0.021616013526483310313342710266; w[1] = 0.049714548894969796453334946203; w[2] = 0.07642573025488905652912967762; w[3] = 0.10094204410628716556281398492; w[4] = 0.12255520671147846018451912680; w[5] = 0.14064291467065065120473130375; w[6] = 0.15468467512626524492541800384; w[7] = 0.16427648374583272298605377647; w[8] = 0.16914238296314359184065647013; w[9] = 0.16914238296314359184065647013; w[10] = 0.16427648374583272298605377647; w[11] = 0.15468467512626524492541800384; w[12] = 0.14064291467065065120473130375; w[13] = 0.12255520671147846018451912680; w[14] = 0.10094204410628716556281398492; w[15] = 0.07642573025488905652912967762; w[16] = 0.049714548894969796453334946203; w[17] = 0.021616013526483310313342710266; } else if ( n == 19 ) { x[0] = -0.992406843843584403189017670; x[1] = -0.960208152134830030852778841; x[2] = -0.903155903614817901642660929; x[3] = -0.822714656537142824978922487; x[4] = -0.72096617733522937861709586; x[5] = -0.60054530466168102346963816; x[6] = -0.46457074137596094571726715; x[7] = -0.31656409996362983199011733; x[8] = -0.16035864564022537586809612; x[9] = 0.00000000000000000000000000; x[10] = 0.16035864564022537586809612; x[11] = 0.31656409996362983199011733; x[12] = 0.46457074137596094571726715; x[13] = 0.60054530466168102346963816; x[14] = 0.72096617733522937861709586; x[15] = 0.82271465653714282497892249; x[16] = 0.90315590361481790164266093; x[17] = 0.96020815213483003085277884; x[18] = 0.99240684384358440318901767; w[0] = 0.019461788229726477036312041464; w[1] = 0.044814226765699600332838157402; w[2] = 0.069044542737641226580708258006; w[3] = 0.091490021622449999464462094124; w[4] = 0.111566645547333994716023901682; w[5] = 0.12875396253933622767551578486; w[6] = 0.14260670217360661177574610944; w[7] = 0.15276604206585966677885540090; w[8] = 0.15896884339395434764995643946; w[9] = 0.16105444984878369597916362532; w[10] = 0.15896884339395434764995643946; w[11] = 0.15276604206585966677885540090; w[12] = 0.14260670217360661177574610944; w[13] = 0.12875396253933622767551578486; w[14] = 0.111566645547333994716023901682; w[15] = 0.091490021622449999464462094124; w[16] = 0.069044542737641226580708258006; w[17] = 0.044814226765699600332838157402; w[18] = 0.019461788229726477036312041464; } else if ( n == 20 ) { x[0] = -0.993128599185094924786122388; x[1] = -0.963971927277913791267666131; x[2] = -0.912234428251325905867752441; x[3] = -0.83911697182221882339452906; x[4] = -0.74633190646015079261430507; x[5] = -0.63605368072651502545283670; x[6] = -0.51086700195082709800436405; x[7] = -0.37370608871541956067254818; x[8] = -0.22778585114164507808049620; x[9] = -0.07652652113349733375464041; x[10] = 0.07652652113349733375464041; x[11] = 0.22778585114164507808049620; x[12] = 0.37370608871541956067254818; x[13] = 0.51086700195082709800436405; x[14] = 0.63605368072651502545283670; x[15] = 0.74633190646015079261430507; x[16] = 0.83911697182221882339452906; x[17] = 0.91223442825132590586775244; x[18] = 0.96397192727791379126766613; x[19] = 0.99312859918509492478612239; w[0] = 0.017614007139152118311861962352; w[1] = 0.040601429800386941331039952275; w[2] = 0.062672048334109063569506535187; w[3] = 0.08327674157670474872475814322; w[4] = 0.10193011981724043503675013548; w[5] = 0.11819453196151841731237737771; w[6] = 0.13168863844917662689849449975; w[7] = 0.14209610931838205132929832507; w[8] = 0.14917298647260374678782873700; w[9] = 0.15275338713072585069808433195; w[10] = 0.15275338713072585069808433195; w[11] = 0.14917298647260374678782873700; w[12] = 0.14209610931838205132929832507; w[13] = 0.13168863844917662689849449975; w[14] = 0.11819453196151841731237737771; w[15] = 0.10193011981724043503675013548; w[16] = 0.08327674157670474872475814322; w[17] = 0.062672048334109063569506535187; w[18] = 0.040601429800386941331039952275; w[19] = 0.017614007139152118311861962352; } else if ( n == 21 ) { x[ 0] = -0.99375217062038950026024204; x[ 1] = -0.96722683856630629431662221; x[ 2] = -0.92009933415040082879018713; x[ 3] = -0.85336336458331728364725064; x[ 4] = -0.76843996347567790861587785; x[ 5] = -0.66713880419741231930596667; x[ 6] = -0.55161883588721980705901880; x[ 7] = -0.42434212020743878357366889; x[ 8] = -0.28802131680240109660079252; x[9] = -0.14556185416089509093703098; x[10] = 0.00000000000000000000000000; x[11] = +0.14556185416089509093703098; x[12] = +0.28802131680240109660079252; x[13] = +0.42434212020743878357366889; x[14] = +0.55161883588721980705901880; x[15] = +0.66713880419741231930596667; x[16] = +0.76843996347567790861587785; x[17] = +0.85336336458331728364725064; x[18] = +0.92009933415040082879018713; x[19] = +0.96722683856630629431662221; x[20] = +0.99375217062038950026024204; w[ 0] = 0.016017228257774333324224616858; w[ 1] = 0.036953789770852493799950668299; w[ 2] = 0.057134425426857208283635826472; w[ 3] = 0.076100113628379302017051653300; w[ 4] = 0.093444423456033861553289741114; w[ 5] = 0.108797299167148377663474578070; w[ 6] = 0.12183141605372853419536717713; w[ 7] = 0.13226893863333746178105257450; w[ 8] = 0.13988739479107315472213342387; w[9] = 0.14452440398997005906382716655; w[10] = 0.14608113364969042719198514768; w[11] = 0.14452440398997005906382716655; w[12] = 0.13988739479107315472213342387; w[13] = 0.13226893863333746178105257450; w[14] = 0.12183141605372853419536717713; w[15] = 0.108797299167148377663474578070; w[16] = 0.093444423456033861553289741114; w[17] = 0.076100113628379302017051653300; w[18] = 0.057134425426857208283635826472; w[19] = 0.036953789770852493799950668299; w[20] = 0.016017228257774333324224616858; } else if ( n == 22 ) { x[0] = -0.99429458548239929207303142; x[1] = -0.97006049783542872712395099; x[2] = -0.92695677218717400052069294; x[3] = -0.86581257772030013653642564; x[4] = -0.78781680597920816200427796; x[5] = -0.69448726318668278005068984; x[6] = -0.58764040350691159295887693; x[7] = -0.46935583798675702640633071; x[8] = -0.34193582089208422515814742; x[9] = -0.20786042668822128547884653; x[10] = -0.06973927331972222121384180; x[11] = 0.06973927331972222121384180; x[12] = 0.20786042668822128547884653; x[13] = 0.34193582089208422515814742; x[14] = 0.46935583798675702640633071; x[15] = 0.58764040350691159295887693; x[16] = 0.69448726318668278005068984; x[17] = 0.78781680597920816200427796; x[18] = 0.86581257772030013653642564; x[19] = 0.92695677218717400052069294; x[20] = 0.97006049783542872712395099; x[21] = 0.99429458548239929207303142; w[0] = 0.014627995298272200684991098047; w[1] = 0.033774901584814154793302246866; w[2] = 0.052293335152683285940312051273; w[3] = 0.06979646842452048809496141893; w[4] = 0.08594160621706772741444368137; w[5] = 0.10041414444288096493207883783; w[6] = 0.11293229608053921839340060742; w[7] = 0.12325237681051242428556098615; w[8] = 0.13117350478706237073296499253; w[9] = 0.13654149834601517135257383123; w[10] = 0.13925187285563199337541024834; w[11] = 0.13925187285563199337541024834; w[12] = 0.13654149834601517135257383123; w[13] = 0.13117350478706237073296499253; w[14] = 0.12325237681051242428556098615; w[15] = 0.11293229608053921839340060742; w[16] = 0.10041414444288096493207883783; w[17] = 0.08594160621706772741444368137; w[18] = 0.06979646842452048809496141893; w[19] = 0.052293335152683285940312051273; w[20] = 0.033774901584814154793302246866; w[21] = 0.014627995298272200684991098047; } else if ( n == 23 ) { x[0] = -0.99476933499755212352392572; x[1] = -0.97254247121811523195602408; x[2] = -0.93297108682601610234919699; x[3] = -0.87675235827044166737815689; x[4] = -0.80488840161883989215111841; x[5] = -0.71866136313195019446162448; x[6] = -0.61960987576364615638509731; x[7] = -0.50950147784600754968979305; x[8] = -0.39030103803029083142148887; x[9] = -0.26413568097034493053386954; x[10] = -0.13325682429846611093174268; x[11] = 0.00000000000000000000000000; x[12] = 0.13325682429846611093174268; x[13] = 0.26413568097034493053386954; x[14] = 0.39030103803029083142148887; x[15] = 0.50950147784600754968979305; x[16] = 0.61960987576364615638509731; x[17] = 0.71866136313195019446162448; x[18] = 0.80488840161883989215111841; x[19] = 0.87675235827044166737815689; x[20] = 0.93297108682601610234919699; x[21] = 0.97254247121811523195602408; x[22] = 0.99476933499755212352392572; w[0] = 0.013411859487141772081309493459; w[1] = 0.030988005856979444310694219642; w[2] = 0.048037671731084668571641071632; w[3] = 0.064232421408525852127169615159; w[4] = 0.079281411776718954922892524742; w[5] = 0.092915766060035147477018617370; w[6] = 0.104892091464541410074086185015; w[7] = 0.11499664022241136494164351293; w[8] = 0.12304908430672953046757840067; w[9] = 0.12890572218808214997859533940; w[10] = 0.13246203940469661737164246470; w[11] = 0.13365457218610617535145711055; w[12] = 0.13246203940469661737164246470; w[13] = 0.12890572218808214997859533940; w[14] = 0.12304908430672953046757840067; w[15] = 0.11499664022241136494164351293; w[16] = 0.104892091464541410074086185015; w[17] = 0.092915766060035147477018617370; w[18] = 0.079281411776718954922892524742; w[19] = 0.064232421408525852127169615159; w[20] = 0.048037671731084668571641071632; w[21] = 0.030988005856979444310694219642; w[22] = 0.013411859487141772081309493459; } else if ( n == 24 ) { x[0] = -0.99518721999702136017999741; x[1] = -0.97472855597130949819839199; x[2] = -0.93827455200273275852364900; x[3] = -0.88641552700440103421315434; x[4] = -0.82000198597390292195394987; x[5] = -0.74012419157855436424382810; x[6] = -0.64809365193697556925249579; x[7] = -0.54542147138883953565837562; x[8] = -0.43379350762604513848708423; x[9] = -0.31504267969616337438679329; x[10] = -0.19111886747361630915863982; x[11] = -0.06405689286260562608504308; x[12] = 0.06405689286260562608504308; x[13] = 0.19111886747361630915863982; x[14] = 0.31504267969616337438679329; x[15] = 0.43379350762604513848708423; x[16] = 0.54542147138883953565837562; x[17] = 0.64809365193697556925249579; x[18] = 0.74012419157855436424382810; x[19] = 0.82000198597390292195394987; x[20] = 0.88641552700440103421315434; x[21] = 0.93827455200273275852364900; x[22] = 0.97472855597130949819839199; x[23] = 0.99518721999702136017999741; w[0] = 0.012341229799987199546805667070; w[1] = 0.028531388628933663181307815952; w[2] = 0.044277438817419806168602748211; w[3] = 0.059298584915436780746367758500; w[4] = 0.07334648141108030573403361525; w[5] = 0.08619016153195327591718520298; w[6] = 0.09761865210411388826988066446; w[7] = 0.10744427011596563478257734245; w[8] = 0.11550566805372560135334448391; w[9] = 0.12167047292780339120446315348; w[10] = 0.12583745634682829612137538251; w[11] = 0.12793819534675215697405616522; w[12] = 0.12793819534675215697405616522; w[13] = 0.12583745634682829612137538251; w[14] = 0.12167047292780339120446315348; w[15] = 0.11550566805372560135334448391; w[16] = 0.10744427011596563478257734245; w[17] = 0.09761865210411388826988066446; w[18] = 0.08619016153195327591718520298; w[19] = 0.07334648141108030573403361525; w[20] = 0.059298584915436780746367758500; w[21] = 0.044277438817419806168602748211; w[22] = 0.028531388628933663181307815952; w[23] = 0.012341229799987199546805667070; } else if ( n == 25 ) { x[0] = -0.99555696979049809790878495; x[1] = -0.97666392145951751149831539; x[2] = -0.94297457122897433941401117; x[3] = -0.89499199787827536885104201; x[4] = -0.83344262876083400142102111; x[5] = -0.75925926303735763057728287; x[6] = -0.67356636847346836448512063; x[7] = -0.57766293024122296772368984; x[8] = -0.47300273144571496052218212; x[9] = -0.36117230580938783773582173; x[10] = -0.24386688372098843204519036; x[11] = -0.12286469261071039638735982; x[12] = 0.00000000000000000000000000; x[13] = 0.12286469261071039638735982; x[14] = 0.24386688372098843204519036; x[15] = 0.36117230580938783773582173; x[16] = 0.47300273144571496052218212; x[17] = 0.57766293024122296772368984; x[18] = 0.67356636847346836448512063; x[19] = 0.75925926303735763057728287; x[20] = 0.83344262876083400142102111; x[21] = 0.89499199787827536885104201; x[22] = 0.94297457122897433941401117; x[23] = 0.97666392145951751149831539; x[24] = 0.99555696979049809790878495; w[0] = 0.0113937985010262879479029641132; w[1] = 0.026354986615032137261901815295; w[2] = 0.040939156701306312655623487712; w[3] = 0.054904695975835191925936891541; w[4] = 0.068038333812356917207187185657; w[5] = 0.080140700335001018013234959669; w[6] = 0.091028261982963649811497220703; w[7] = 0.100535949067050644202206890393; w[8] = 0.108519624474263653116093957050; w[9] = 0.11485825914571164833932554587; w[10] = 0.11945576353578477222817812651; w[11] = 0.12224244299031004168895951895; w[12] = 0.12317605372671545120390287308; w[13] = 0.12224244299031004168895951895; w[14] = 0.11945576353578477222817812651; w[15] = 0.11485825914571164833932554587; w[16] = 0.108519624474263653116093957050; w[17] = 0.100535949067050644202206890393; w[18] = 0.091028261982963649811497220703; w[19] = 0.080140700335001018013234959669; w[20] = 0.068038333812356917207187185657; w[21] = 0.054904695975835191925936891541; w[22] = 0.040939156701306312655623487712; w[23] = 0.026354986615032137261901815295; w[24] = 0.0113937985010262879479029641132; } else if ( n == 26 ) { x[0] = -0.99588570114561692900321696; x[1] = -0.97838544595647099110058035; x[2] = -0.94715906666171425013591528; x[3] = -0.90263786198430707421766560; x[4] = -0.84544594278849801879750706; x[5] = -0.77638594882067885619296725; x[6] = -0.69642726041995726486381391; x[7] = -0.60669229301761806323197875; x[8] = -0.50844071482450571769570306; x[9] = -0.40305175512348630648107738; x[10] = -0.29200483948595689514283538; x[11] = -0.17685882035689018396905775; x[12] = -0.05923009342931320709371858; x[13] = 0.05923009342931320709371858; x[14] = 0.17685882035689018396905775; x[15] = 0.29200483948595689514283538; x[16] = 0.40305175512348630648107738; x[17] = 0.50844071482450571769570306; x[18] = 0.60669229301761806323197875; x[19] = 0.69642726041995726486381391; x[20] = 0.77638594882067885619296725; x[21] = 0.84544594278849801879750706; x[22] = 0.90263786198430707421766560; x[23] = 0.94715906666171425013591528; x[24] = 0.97838544595647099110058035; x[25] = 0.99588570114561692900321696; w[0] = 0.010551372617343007155651187685; w[1] = 0.024417851092631908789615827520; w[2] = 0.037962383294362763950303141249; w[3] = 0.050975825297147811998319900724; w[4] = 0.063274046329574835539453689907; w[5] = 0.07468414976565974588707579610; w[6] = 0.08504589431348523921044776508; w[7] = 0.09421380035591414846366488307; w[8] = 0.10205916109442542323841407025; w[9] = 0.10847184052857659065657942673; w[10] = 0.11336181654631966654944071844; w[11] = 0.11666044348529658204466250754; w[12] = 0.11832141527926227651637108570; w[13] = 0.11832141527926227651637108570; w[14] = 0.11666044348529658204466250754; w[15] = 0.11336181654631966654944071844; w[16] = 0.10847184052857659065657942673; w[17] = 0.10205916109442542323841407025; w[18] = 0.09421380035591414846366488307; w[19] = 0.08504589431348523921044776508; w[20] = 0.07468414976565974588707579610; w[21] = 0.063274046329574835539453689907; w[22] = 0.050975825297147811998319900724; w[23] = 0.037962383294362763950303141249; w[24] = 0.024417851092631908789615827520; w[25] = 0.010551372617343007155651187685; } else if ( n == 27 ) { x[0] = -0.99617926288898856693888721; x[1] = -0.97992347596150122285587336; x[2] = -0.95090055781470500685190803; x[3] = -0.90948232067749110430064502; x[4] = -0.85620790801829449030273722; x[5] = -0.79177163907050822714439734; x[6] = -0.71701347373942369929481621; x[7] = -0.63290797194649514092773464; x[8] = -0.54055156457945689490030094; x[9] = -0.44114825175002688058597416; x[10] = -0.33599390363850889973031903; x[11] = -0.22645936543953685885723911; x[12] = -0.11397258560952996693289498; x[13] = 0.00000000000000000000000000; x[14] = 0.11397258560952996693289498; x[15] = 0.22645936543953685885723911; x[16] = 0.33599390363850889973031903; x[17] = 0.44114825175002688058597416; x[18] = 0.54055156457945689490030094; x[19] = 0.63290797194649514092773464; x[20] = 0.71701347373942369929481621; x[21] = 0.79177163907050822714439734; x[22] = 0.85620790801829449030273722; x[23] = 0.90948232067749110430064502; x[24] = 0.95090055781470500685190803; x[25] = 0.97992347596150122285587336; x[26] = 0.99617926288898856693888721; w[0] = 0.0097989960512943602611500550912; w[1] = 0.022686231596180623196034206447; w[2] = 0.035297053757419711022578289305; w[3] = 0.047449412520615062704096710114; w[4] = 0.058983536859833599110300833720; w[5] = 0.069748823766245592984322888357; w[6] = 0.079604867773057771263074959010; w[7] = 0.088423158543756950194322802854; w[8] = 0.096088727370028507565652646558; w[9] = 0.102501637817745798671247711533; w[10] = 0.107578285788533187212162984427; w[11] = 0.111252488356845192672163096043; w[12] = 0.113476346108965148620369948092; w[13] = 0.11422086737895698904504573690; w[14] = 0.113476346108965148620369948092; w[15] = 0.111252488356845192672163096043; w[16] = 0.107578285788533187212162984427; w[17] = 0.102501637817745798671247711533; w[18] = 0.096088727370028507565652646558; w[19] = 0.088423158543756950194322802854; w[20] = 0.079604867773057771263074959010; w[21] = 0.069748823766245592984322888357; w[22] = 0.058983536859833599110300833720; w[23] = 0.047449412520615062704096710114; w[24] = 0.035297053757419711022578289305; w[25] = 0.022686231596180623196034206447; w[26] = 0.0097989960512943602611500550912; } else if ( n == 28 ) { x[0] = -0.99644249757395444995043639; x[1] = -0.98130316537087275369455995; x[2] = -0.95425928062893819725410184; x[3] = -0.91563302639213207386968942; x[4] = -0.86589252257439504894225457; x[5] = -0.80564137091717917144788596; x[6] = -0.73561087801363177202814451; x[7] = -0.65665109403886496121989818; x[8] = -0.56972047181140171930800328; x[9] = -0.47587422495511826103441185; x[10] = -0.37625151608907871022135721; x[11] = -0.27206162763517807767682636; x[12] = -0.16456928213338077128147178; x[13] = -0.05507928988403427042651653; x[14] = 0.05507928988403427042651653; x[15] = 0.16456928213338077128147178; x[16] = 0.27206162763517807767682636; x[17] = 0.37625151608907871022135721; x[18] = 0.47587422495511826103441185; x[19] = 0.56972047181140171930800328; x[20] = 0.65665109403886496121989818; x[21] = 0.73561087801363177202814451; x[22] = 0.80564137091717917144788596; x[23] = 0.86589252257439504894225457; x[24] = 0.91563302639213207386968942; x[25] = 0.95425928062893819725410184; x[26] = 0.98130316537087275369455995; x[27] = 0.99644249757395444995043639; w[0] = 0.009124282593094517738816153923; w[1] = 0.021132112592771259751500380993; w[2] = 0.032901427782304379977630819171; w[3] = 0.044272934759004227839587877653; w[4] = 0.055107345675716745431482918227; w[5] = 0.06527292396699959579339756678; w[6] = 0.07464621423456877902393188717; w[7] = 0.08311341722890121839039649824; w[8] = 0.09057174439303284094218603134; w[9] = 0.09693065799792991585048900610; w[10] = 0.10211296757806076981421663851; w[11] = 0.10605576592284641791041643700; w[12] = 0.10871119225829413525357151930; w[13] = 0.11004701301647519628237626560; w[14] = 0.11004701301647519628237626560; w[15] = 0.10871119225829413525357151930; w[16] = 0.10605576592284641791041643700; w[17] = 0.10211296757806076981421663851; w[18] = 0.09693065799792991585048900610; w[19] = 0.09057174439303284094218603134; w[20] = 0.08311341722890121839039649824; w[21] = 0.07464621423456877902393188717; w[22] = 0.06527292396699959579339756678; w[23] = 0.055107345675716745431482918227; w[24] = 0.044272934759004227839587877653; w[25] = 0.032901427782304379977630819171; w[26] = 0.021132112592771259751500380993; w[27] = 0.009124282593094517738816153923; } else if ( n == 29 ) { x[0] = -0.99667944226059658616319153; x[1] = -0.98254550526141317487092602; x[2] = -0.95728559577808772579820804; x[3] = -0.92118023295305878509375344; x[4] = -0.87463780492010279041779342; x[5] = -0.81818548761525244498957221; x[6] = -0.75246285173447713391261008; x[7] = -0.67821453760268651515618501; x[8] = -0.59628179713822782037958621; x[9] = -0.50759295512422764210262792; x[10] = -0.41315288817400866389070659; x[11] = -0.31403163786763993494819592; x[12] = -0.21135228616600107450637573; x[13] = -0.10627823013267923017098239; x[14] = 0.00000000000000000000000000; x[15] = 0.10627823013267923017098239; x[16] = 0.21135228616600107450637573; x[17] = 0.31403163786763993494819592; x[18] = 0.41315288817400866389070659; x[19] = 0.50759295512422764210262792; x[20] = 0.59628179713822782037958621; x[21] = 0.67821453760268651515618501; x[22] = 0.75246285173447713391261008; x[23] = 0.81818548761525244498957221; x[24] = 0.87463780492010279041779342; x[25] = 0.92118023295305878509375344; x[26] = 0.95728559577808772579820804; x[27] = 0.98254550526141317487092602; x[28] = 0.99667944226059658616319153; w[0] = 0.0085169038787464096542638133022; w[1] = 0.019732085056122705983859801640; w[2] = 0.030740492202093622644408525375; w[3] = 0.041402062518682836104830010114; w[4] = 0.051594826902497923912594381180; w[5] = 0.061203090657079138542109848024; w[6] = 0.070117933255051278569581486949; w[7] = 0.078238327135763783828144888660; w[8] = 0.085472257366172527545344849297; w[9] = 0.091737757139258763347966411077; w[10] = 0.096963834094408606301900074883; w[11] = 0.101091273759914966121820546907; w[12] = 0.104073310077729373913328471285; w[13] = 0.105876155097320941406591327852; w[14] = 0.10647938171831424424651112691; w[15] = 0.105876155097320941406591327852; w[16] = 0.104073310077729373913328471285; w[17] = 0.101091273759914966121820546907; w[18] = 0.096963834094408606301900074883; w[19] = 0.091737757139258763347966411077; w[20] = 0.085472257366172527545344849297; w[21] = 0.078238327135763783828144888660; w[22] = 0.070117933255051278569581486949; w[23] = 0.061203090657079138542109848024; w[24] = 0.051594826902497923912594381180; w[25] = 0.041402062518682836104830010114; w[26] = 0.030740492202093622644408525375; w[27] = 0.019732085056122705983859801640; w[28] = 0.0085169038787464096542638133022; } else if ( n == 30 ) { x[0] = -0.99689348407464954027163005; x[1] = -0.98366812327974720997003258; x[2] = -0.96002186496830751221687103; x[3] = -0.92620004742927432587932428; x[4] = -0.88256053579205268154311646; x[5] = -0.82956576238276839744289812; x[6] = -0.76777743210482619491797734; x[7] = -0.69785049479331579693229239; x[8] = -0.62052618298924286114047756; x[9] = -0.53662414814201989926416979; x[10] = -0.44703376953808917678060990; x[11] = -0.35270472553087811347103721; x[12] = -0.25463692616788984643980513; x[13] = -0.15386991360858354696379467; x[14] = -0.05147184255531769583302521; x[15] = 0.05147184255531769583302521; x[16] = 0.15386991360858354696379467; x[17] = 0.25463692616788984643980513; x[18] = 0.35270472553087811347103721; x[19] = 0.44703376953808917678060990; x[20] = 0.53662414814201989926416979; x[21] = 0.62052618298924286114047756; x[22] = 0.69785049479331579693229239; x[23] = 0.76777743210482619491797734; x[24] = 0.82956576238276839744289812; x[25] = 0.88256053579205268154311646; x[26] = 0.92620004742927432587932428; x[27] = 0.96002186496830751221687103; x[28] = 0.98366812327974720997003258; x[29] = 0.99689348407464954027163005; w[0] = 0.007968192496166605615465883475; w[1] = 0.018466468311090959142302131912; w[2] = 0.028784707883323369349719179611; w[3] = 0.038799192569627049596801936446; w[4] = 0.048402672830594052902938140423; w[5] = 0.057493156217619066481721689402; w[6] = 0.06597422988218049512812851512; w[7] = 0.07375597473770520626824385002; w[8] = 0.08075589522942021535469493846; w[9] = 0.08689978720108297980238753072; w[10] = 0.09212252223778612871763270709; w[11] = 0.09636873717464425963946862635; w[12] = 0.09959342058679526706278028210; w[13] = 0.10176238974840550459642895217; w[14] = 0.10285265289355884034128563671; w[15] = 0.10285265289355884034128563671; w[16] = 0.10176238974840550459642895217; w[17] = 0.09959342058679526706278028210; w[18] = 0.09636873717464425963946862635; w[19] = 0.09212252223778612871763270709; w[20] = 0.08689978720108297980238753072; w[21] = 0.08075589522942021535469493846; w[22] = 0.07375597473770520626824385002; w[23] = 0.06597422988218049512812851512; w[24] = 0.057493156217619066481721689402; w[25] = 0.048402672830594052902938140423; w[26] = 0.038799192569627049596801936446; w[27] = 0.028784707883323369349719179611; w[28] = 0.018466468311090959142302131912; w[29] = 0.007968192496166605615465883475; } else if ( n == 31 ) { x[0] = -0.99708748181947707405562655; x[1] = -0.98468590966515248400246517; x[2] = -0.96250392509294966178905240; x[3] = -0.93075699789664816495694576; x[4] = -0.88976002994827104337419201; x[5] = -0.83992032014626734008690454; x[6] = -0.78173314841662494040636002; x[7] = -0.71577678458685328390597087; x[8] = -0.64270672292426034618441820; x[9] = -0.56324916140714926272094492; x[10] = -0.47819378204490248044059404; x[11] = -0.38838590160823294306135146; x[12] = -0.29471806998170161661790390; x[13] = -0.19812119933557062877241300; x[14] = -0.09955531215234152032517479; x[15] = 0.00000000000000000000000000; x[16] = 0.09955531215234152032517479; x[17] = 0.19812119933557062877241300; x[18] = 0.29471806998170161661790390; x[19] = 0.38838590160823294306135146; x[20] = 0.47819378204490248044059404; x[21] = 0.56324916140714926272094492; x[22] = 0.64270672292426034618441820; x[23] = 0.71577678458685328390597087; x[24] = 0.78173314841662494040636002; x[25] = 0.83992032014626734008690454; x[26] = 0.88976002994827104337419201; x[27] = 0.93075699789664816495694576; x[28] = 0.96250392509294966178905240; x[29] = 0.98468590966515248400246517; x[30] = 0.99708748181947707405562655; w[0] = 0.0074708315792487758586968750322; w[1] = 0.017318620790310582463157996087; w[2] = 0.027009019184979421800608708092; w[3] = 0.036432273912385464024392010468; w[4] = 0.045493707527201102902315857895; w[5] = 0.054103082424916853711666259087; w[6] = 0.062174786561028426910343543687; w[7] = 0.069628583235410366167756126255; w[8] = 0.076390386598776616426357674901; w[9] = 0.082392991761589263903823367432; w[10] = 0.087576740608477876126198069695; w[11] = 0.091890113893641478215362871607; w[12] = 0.095290242912319512807204197488; w[13] = 0.097743335386328725093474010979; w[14] = 0.099225011226672307874875514429; w[15] = 0.09972054479342645142753383373; w[16] = 0.099225011226672307874875514429; w[17] = 0.097743335386328725093474010979; w[18] = 0.095290242912319512807204197488; w[19] = 0.091890113893641478215362871607; w[20] = 0.087576740608477876126198069695; w[21] = 0.082392991761589263903823367432; w[22] = 0.076390386598776616426357674901; w[23] = 0.069628583235410366167756126255; w[24] = 0.062174786561028426910343543687; w[25] = 0.054103082424916853711666259087; w[26] = 0.045493707527201102902315857895; w[27] = 0.036432273912385464024392010468; w[28] = 0.027009019184979421800608708092; w[29] = 0.017318620790310582463157996087; w[30] = 0.0074708315792487758586968750322; } else if ( n == 32 ) { x[0] = -0.99726386184948156354498113; x[1] = -0.98561151154526833540017504; x[2] = -0.96476225558750643077381193; x[3] = -0.93490607593773968917091913; x[4] = -0.89632115576605212396530724; x[5] = -0.84936761373256997013369300; x[6] = -0.79448379596794240696309730; x[7] = -0.73218211874028968038742667; x[8] = -0.66304426693021520097511517; x[9] = -0.58771575724076232904074548; x[10] = -0.50689990893222939002374747; x[11] = -0.42135127613063534536411944; x[12] = -0.33186860228212764977991681; x[13] = -0.23928736225213707454460321; x[14] = -0.14447196158279649348518637; x[15] = -0.04830766568773831623481257; x[16] = 0.04830766568773831623481257; x[17] = 0.14447196158279649348518637; x[18] = 0.23928736225213707454460321; x[19] = 0.33186860228212764977991681; x[20] = 0.42135127613063534536411944; x[21] = 0.50689990893222939002374747; x[22] = 0.58771575724076232904074548; x[23] = 0.66304426693021520097511517; x[24] = 0.73218211874028968038742667; x[25] = 0.79448379596794240696309730; x[26] = 0.84936761373256997013369300; x[27] = 0.89632115576605212396530724; x[28] = 0.93490607593773968917091913; x[29] = 0.96476225558750643077381193; x[30] = 0.98561151154526833540017504; x[31] = 0.99726386184948156354498113; w[0] = 0.007018610009470096600407063739; w[1] = 0.016274394730905670605170562206; w[2] = 0.025392065309262059455752589789; w[3] = 0.034273862913021433102687732252; w[4] = 0.042835898022226680656878646606; w[5] = 0.050998059262376176196163244690; w[6] = 0.058684093478535547145283637300; w[7] = 0.06582222277636184683765006371; w[8] = 0.07234579410884850622539935648; w[9] = 0.07819389578707030647174091883; w[10] = 0.08331192422694675522219907460; w[11] = 0.08765209300440381114277146275; w[12] = 0.09117387869576388471286857711; w[13] = 0.09384439908080456563918023767; w[14] = 0.09563872007927485941908200220; w[15] = 0.09654008851472780056676483006; w[16] = 0.09654008851472780056676483006; w[17] = 0.09563872007927485941908200220; w[18] = 0.09384439908080456563918023767; w[19] = 0.09117387869576388471286857711; w[20] = 0.08765209300440381114277146275; w[21] = 0.08331192422694675522219907460; w[22] = 0.07819389578707030647174091883; w[23] = 0.07234579410884850622539935648; w[24] = 0.06582222277636184683765006371; w[25] = 0.058684093478535547145283637300; w[26] = 0.050998059262376176196163244690; w[27] = 0.042835898022226680656878646606; w[28] = 0.034273862913021433102687732252; w[29] = 0.025392065309262059455752589789; w[30] = 0.016274394730905670605170562206; w[31] = 0.007018610009470096600407063739; } else if ( n == 33 ) { x[0] = -0.99742469424645521726616802; x[1] = -0.98645572623064248811037570; x[2] = -0.96682290968999276892837771; x[3] = -0.93869437261116835035583512; x[4] = -0.90231676774343358304053133; x[5] = -0.85800965267650406464306148; x[6] = -0.80616235627416658979620087; x[7] = -0.74723049644956215785905512; x[8] = -0.68173195996974278626821595; x[9] = -0.61024234583637902730728751; x[10] = -0.53338990478634764354889426; x[11] = -0.45185001727245069572599328; x[12] = -0.36633925774807334107022062; x[13] = -0.27760909715249702940324807; x[14] = -0.18643929882799157233579876; x[15] = -0.09363106585473338567074292; x[16] = 0.00000000000000000000000000; x[17] = 0.09363106585473338567074292; x[18] = 0.18643929882799157233579876; x[19] = 0.27760909715249702940324807; x[20] = 0.36633925774807334107022062; x[21] = 0.45185001727245069572599328; x[22] = 0.53338990478634764354889426; x[23] = 0.61024234583637902730728751; x[24] = 0.68173195996974278626821595; x[25] = 0.74723049644956215785905512; x[26] = 0.80616235627416658979620087; x[27] = 0.85800965267650406464306148; x[28] = 0.90231676774343358304053133; x[29] = 0.93869437261116835035583512; x[30] = 0.96682290968999276892837771; x[31] = 0.98645572623064248811037570; x[32] = 0.99742469424645521726616802; w[0] = 0.0066062278475873780586492352085; w[1] = 0.015321701512934676127945768534; w[2] = 0.023915548101749480350533257529; w[3] = 0.032300358632328953281561447250; w[4] = 0.040401541331669591563409790527; w[5] = 0.048147742818711695670146880138; w[6] = 0.055470846631663561284944495439; w[7] = 0.062306482530317480031627725771; w[8] = 0.068594572818656712805955073015; w[9] = 0.074279854843954149342472175919; w[10] = 0.079312364794886738363908384942; w[11] = 0.083647876067038707613928014518; w[12] = 0.087248287618844337607281670945; w[13] = 0.090081958660638577239743705500; w[14] = 0.092123986643316846213240977717; w[15] = 0.093356426065596116160999126274; w[16] = 0.09376844616020999656730454155; w[17] = 0.093356426065596116160999126274; w[18] = 0.092123986643316846213240977717; w[19] = 0.090081958660638577239743705500; w[20] = 0.087248287618844337607281670945; w[21] = 0.083647876067038707613928014518; w[22] = 0.079312364794886738363908384942; w[23] = 0.074279854843954149342472175919; w[24] = 0.068594572818656712805955073015; w[25] = 0.062306482530317480031627725771; w[26] = 0.055470846631663561284944495439; w[27] = 0.048147742818711695670146880138; w[28] = 0.040401541331669591563409790527; w[29] = 0.032300358632328953281561447250; w[30] = 0.023915548101749480350533257529; w[31] = 0.015321701512934676127945768534; w[32] = 0.0066062278475873780586492352085; } else if ( n == 63 ) { x[0] = -0.99928298402912378037893614; x[1] = -0.99622401277797010860219336; x[2] = -0.99072854689218946681089467; x[3] = -0.98280881059372723486251141; x[4] = -0.97248403469757002280196068; x[5] = -0.95977944975894192707035417; x[6] = -0.94472613404100980296637532; x[7] = -0.92736092062184320544703138; x[8] = -0.90772630277853155803695313; x[9] = -0.88587032850785342629029846; x[10] = -0.86184648236412371953961184; x[11] = -0.83571355431950284347180777; x[12] = -0.80753549577345676005146599; x[13] = -0.7773812629903723355633302; x[14] = -0.7453246483178474178293217; x[15] = -0.7114440995848458078514315; x[16] = -0.6758225281149860901311033; x[17] = -0.6385471058213653850003070; x[18] = -0.5997090518776252357390089; x[19] = -0.5594034094862850132676978; x[20] = -0.5177288132900332481244776; x[21] = -0.4747872479948043999222123; x[22] = -0.4306837987951116006620889; x[23] = -0.3855263942122478924776150; x[24] = -0.3394255419745844024688344; x[25] = -0.2924940585862514400361572; x[26] = -0.2448467932459533627484046; x[27] = -0.1966003467915066845576275; x[28] = -0.1478727863578719685698391; x[29] = -0.0987833564469452795297037; x[30] = -0.0494521871161596272342338; x[31] = 0.0000000000000000000000000; x[32] = 0.0494521871161596272342338; x[33] = 0.0987833564469452795297037; x[34] = 0.1478727863578719685698391; x[35] = 0.1966003467915066845576275; x[36] = 0.2448467932459533627484046; x[37] = 0.2924940585862514400361572; x[38] = 0.3394255419745844024688344; x[39] = 0.3855263942122478924776150; x[40] = 0.4306837987951116006620889; x[41] = 0.4747872479948043999222123; x[42] = 0.5177288132900332481244776; x[43] = 0.5594034094862850132676978; x[44] = 0.5997090518776252357390089; x[45] = 0.6385471058213653850003070; x[46] = 0.6758225281149860901311033; x[47] = 0.7114440995848458078514315; x[48] = 0.7453246483178474178293217; x[49] = 0.7773812629903723355633302; x[50] = 0.8075354957734567600514660; x[51] = 0.8357135543195028434718078; x[52] = 0.8618464823641237195396118; x[53] = 0.8858703285078534262902985; x[54] = 0.9077263027785315580369531; x[55] = 0.9273609206218432054470314; x[56] = 0.9447261340410098029663753; x[57] = 0.9597794497589419270703542; x[58] = 0.9724840346975700228019607; x[59] = 0.9828088105937272348625114; x[60] = 0.9907285468921894668108947; x[61] = 0.9962240127779701086021934; x[62] = 0.9992829840291237803789361; w[0] = 0.0018398745955770841170924455540; w[1] = 0.0042785083468637618660784110826; w[2] = 0.0067102917659601362519069307298; w[3] = 0.0091259686763266563540586454218; w[4] = 0.011519376076880041750750606149; w[5] = 0.013884612616115610824866086368; w[6] = 0.016215878410338338882283672975; w[7] = 0.018507464460161270409260545805; w[8] = 0.020753761258039090775341953421; w[9] = 0.022949271004889933148942319562; w[10] = 0.025088620553344986618630138068; w[11] = 0.027166574359097933225189839439; w[12] = 0.029178047208280526945551502154; w[13] = 0.031118116622219817508215988557; w[14] = 0.032982034883779341765683179672; w[15] = 0.034765240645355877697180504643; w[16] = 0.036463370085457289630452409788; w[17] = 0.038072267584349556763638324928; w[18] = 0.039587995891544093984807928149; w[19] = 0.041006845759666398635110037009; w[20] = 0.042325345020815822982505485403; w[21] = 0.043540267083027590798964315704; w[22] = 0.044648638825941395370332669517; w[23] = 0.045647747876292608685885992609; w[24] = 0.046535149245383696510395418747; w[25] = 0.047308671312268919080604988339; w[26] = 0.047966421137995131411052756195; w[27] = 0.048506789097883847864090099146; w[28] = 0.048928452820511989944709361549; w[29] = 0.049230380423747560785043116988; w[30] = 0.049411833039918178967039646117; w[31] = 0.04947236662393102088866936042; w[32] = 0.049411833039918178967039646117; w[33] = 0.049230380423747560785043116988; w[34] = 0.048928452820511989944709361549; w[35] = 0.048506789097883847864090099146; w[36] = 0.047966421137995131411052756195; w[37] = 0.047308671312268919080604988339; w[38] = 0.046535149245383696510395418747; w[39] = 0.045647747876292608685885992609; w[40] = 0.044648638825941395370332669517; w[41] = 0.043540267083027590798964315704; w[42] = 0.042325345020815822982505485403; w[43] = 0.041006845759666398635110037009; w[44] = 0.039587995891544093984807928149; w[45] = 0.038072267584349556763638324928; w[46] = 0.036463370085457289630452409788; w[47] = 0.034765240645355877697180504643; w[48] = 0.032982034883779341765683179672; w[49] = 0.031118116622219817508215988557; w[50] = 0.029178047208280526945551502154; w[51] = 0.027166574359097933225189839439; w[52] = 0.025088620553344986618630138068; w[53] = 0.022949271004889933148942319562; w[54] = 0.020753761258039090775341953421; w[55] = 0.018507464460161270409260545805; w[56] = 0.016215878410338338882283672975; w[57] = 0.013884612616115610824866086368; w[58] = 0.011519376076880041750750606149; w[59] = 0.0091259686763266563540586454218; w[60] = 0.0067102917659601362519069307298; w[61] = 0.0042785083468637618660784110826; w[62] = 0.0018398745955770841170924455540; } else if ( n == 64 ) { x[0] = -0.99930504173577213945690562; x[1] = -0.99634011677195527934692450; x[2] = -0.99101337147674432073938238; x[3] = -0.98333625388462595693129930; x[4] = -0.97332682778991096374185351; x[5] = -0.96100879965205371891861412; x[6] = -0.94641137485840281606248149; x[7] = -0.92956917213193957582149015; x[8] = -0.91052213707850280575638067; x[9] = -0.88931544599511410585340404; x[10] = -0.86599939815409281976078339; x[11] = -0.8406292962525803627516915; x[12] = -0.8132653151227975597419233; x[13] = -0.7839723589433414076102205; x[14] = -0.7528199072605318966118638; x[15] = -0.7198818501716108268489402; x[16] = -0.6852363130542332425635584; x[17] = -0.6489654712546573398577612; x[18] = -0.6111553551723932502488530; x[19] = -0.5718956462026340342838781; x[20] = -0.5312794640198945456580139; x[21] = -0.4894031457070529574785263; x[22] = -0.4463660172534640879849477; x[23] = -0.4022701579639916036957668; x[24] = -0.3572201583376681159504426; x[25] = -0.3113228719902109561575127; x[26] = -0.2646871622087674163739642; x[27] = -0.2174236437400070841496487; x[28] = -0.1696444204239928180373136; x[29] = -0.1214628192961205544703765; x[30] = -0.0729931217877990394495429; x[31] = -0.0243502926634244325089558; x[32] = 0.0243502926634244325089558; x[33] = 0.0729931217877990394495429; x[34] = 0.1214628192961205544703765; x[35] = 0.1696444204239928180373136; x[36] = 0.2174236437400070841496487; x[37] = 0.2646871622087674163739642; x[38] = 0.3113228719902109561575127; x[39] = 0.3572201583376681159504426; x[40] = 0.4022701579639916036957668; x[41] = 0.4463660172534640879849477; x[42] = 0.4894031457070529574785263; x[43] = 0.5312794640198945456580139; x[44] = 0.5718956462026340342838781; x[45] = 0.6111553551723932502488530; x[46] = 0.6489654712546573398577612; x[47] = 0.6852363130542332425635584; x[48] = 0.7198818501716108268489402; x[49] = 0.7528199072605318966118638; x[50] = 0.7839723589433414076102205; x[51] = 0.8132653151227975597419233; x[52] = 0.8406292962525803627516915; x[53] = 0.8659993981540928197607834; x[54] = 0.8893154459951141058534040; x[55] = 0.9105221370785028057563807; x[56] = 0.9295691721319395758214902; x[57] = 0.9464113748584028160624815; x[58] = 0.9610087996520537189186141; x[59] = 0.9733268277899109637418535; x[60] = 0.9833362538846259569312993; x[61] = 0.9910133714767443207393824; x[62] = 0.9963401167719552793469245; x[63] = 0.9993050417357721394569056; w[0] = 0.0017832807216964329472960791450; w[1] = 0.0041470332605624676352875357286; w[2] = 0.006504457968978362856117360400; w[3] = 0.008846759826363947723030914660; w[4] = 0.011168139460131128818590493019; w[5] = 0.013463047896718642598060766686; w[6] = 0.015726030476024719321965995298; w[7] = 0.017951715775697343085045302001; w[8] = 0.020134823153530209372340316729; w[9] = 0.022270173808383254159298330384; w[10] = 0.024352702568710873338177550409; w[11] = 0.026377469715054658671691792625; w[12] = 0.028339672614259483227511305200; w[13] = 0.030234657072402478867974059820; w[14] = 0.032057928354851553585467504348; w[15] = 0.033805161837141609391565482111; w[16] = 0.035472213256882383810693146715; w[17] = 0.037055128540240046040415101810; w[18] = 0.038550153178615629128962496947; w[19] = 0.039953741132720341386656926128; w[20] = 0.041262563242623528610156297474; w[21] = 0.042473515123653589007339767909; w[22] = 0.043583724529323453376827860974; w[23] = 0.044590558163756563060134710031; w[24] = 0.045491627927418144479770996971; w[25] = 0.046284796581314417295953249232; w[26] = 0.046968182816210017325326285755; w[27] = 0.047540165714830308662282206944; w[28] = 0.04799938859645830772812617987; w[29] = 0.04834476223480295716976952716; w[30] = 0.04857546744150342693479906678; w[31] = 0.04869095700913972038336539073; w[32] = 0.04869095700913972038336539073; w[33] = 0.04857546744150342693479906678; w[34] = 0.04834476223480295716976952716; w[35] = 0.04799938859645830772812617987; w[36] = 0.047540165714830308662282206944; w[37] = 0.046968182816210017325326285755; w[38] = 0.046284796581314417295953249232; w[39] = 0.045491627927418144479770996971; w[40] = 0.044590558163756563060134710031; w[41] = 0.043583724529323453376827860974; w[42] = 0.042473515123653589007339767909; w[43] = 0.041262563242623528610156297474; w[44] = 0.039953741132720341386656926128; w[45] = 0.038550153178615629128962496947; w[46] = 0.037055128540240046040415101810; w[47] = 0.035472213256882383810693146715; w[48] = 0.033805161837141609391565482111; w[49] = 0.032057928354851553585467504348; w[50] = 0.030234657072402478867974059820; w[51] = 0.028339672614259483227511305200; w[52] = 0.026377469715054658671691792625; w[53] = 0.024352702568710873338177550409; w[54] = 0.022270173808383254159298330384; w[55] = 0.020134823153530209372340316729; w[56] = 0.017951715775697343085045302001; w[57] = 0.015726030476024719321965995298; w[58] = 0.013463047896718642598060766686; w[59] = 0.011168139460131128818590493019; w[60] = 0.008846759826363947723030914660; w[61] = 0.006504457968978362856117360400; w[62] = 0.0041470332605624676352875357286; w[63] = 0.0017832807216964329472960791450; } else if ( n == 65 ) { x[0] = -0.99932609707541287726569361; x[1] = -0.99645094806184916305579494; x[2] = -0.99128527617680166872182118; x[3] = -0.98383981218703494137763778; x[4] = -0.97413153983355116907496789; x[5] = -0.96218275471805523771198375; x[6] = -0.94802092816840750637376974; x[7] = -0.93167862822874933796567699; x[8] = -0.91319344054284626173654692; x[9] = -0.89260788050473893142328554; x[10] = -0.8699692949264070361941320; x[11] = -0.8453297528999302839424500; x[12] = -0.8187459259226514534339191; x[13] = -0.7902789574921218430473804; x[14] = -0.7599943224419997868739828; x[15] = -0.7279616763294246790119737; x[16] = -0.6942546952139916335526225; x[17] = -0.6589509061936251330409408; x[18] = -0.6221315090854002415825996; x[19] = -0.5838811896604873133271545; x[20] = -0.5442879248622271385455725; x[21] = -0.5034427804550068823410431; x[22] = -0.4614397015691450576978341; x[23] = -0.4183752966234090092641990; x[24] = -0.3743486151220660120087939; x[25] = -0.3294609198374864076452867; x[26] = -0.2838154539022487306176554; x[27] = -0.2375172033464168065707124; x[28] = -0.1906726556261427697749124; x[29] = -0.1433895546989751711312496; x[30] = -0.0957766532091975056522186; x[31] = -0.0479434623531718575225298; x[32] = 0.0000000000000000000000000; x[33] = 0.0479434623531718575225298; x[34] = 0.0957766532091975056522186; x[35] = 0.1433895546989751711312496; x[36] = 0.1906726556261427697749124; x[37] = 0.2375172033464168065707124; x[38] = 0.2838154539022487306176554; x[39] = 0.3294609198374864076452867; x[40] = 0.3743486151220660120087939; x[41] = 0.4183752966234090092641990; x[42] = 0.4614397015691450576978341; x[43] = 0.5034427804550068823410431; x[44] = 0.5442879248622271385455725; x[45] = 0.5838811896604873133271545; x[46] = 0.6221315090854002415825996; x[47] = 0.6589509061936251330409408; x[48] = 0.6942546952139916335526225; x[49] = 0.7279616763294246790119737; x[50] = 0.7599943224419997868739828; x[51] = 0.7902789574921218430473804; x[52] = 0.8187459259226514534339191; x[53] = 0.8453297528999302839424500; x[54] = 0.8699692949264070361941320; x[55] = 0.8926078805047389314232855; x[56] = 0.9131934405428462617365469; x[57] = 0.9316786282287493379656770; x[58] = 0.9480209281684075063737697; x[59] = 0.9621827547180552377119837; x[60] = 0.9741315398335511690749679; x[61] = 0.9838398121870349413776378; x[62] = 0.9912852761768016687218212; x[63] = 0.9964509480618491630557949; x[64] = 0.9993260970754128772656936; w[0] = 0.0017292582513002508983395851463; w[1] = 0.0040215241720037363470786599528; w[2] = 0.0063079425789717545501888719039; w[3] = 0.0085801482668814598936358121592; w[4] = 0.0108326787895979686215140551272; w[5] = 0.013060311639994846336168342922; w[6] = 0.015257912146448310349265388145; w[7] = 0.017420421997670248495365759969; w[8] = 0.019542865836750062826837429313; w[9] = 0.021620361284934062841654274667; w[10] = 0.023648129691287236698780978994; w[11] = 0.025621506938037758214084978694; w[12] = 0.027535954088450343942499722327; w[13] = 0.029387067789310668062644859210; w[14] = 0.031170590380189142464431845777; w[15] = 0.032882419676368574984049638008; w[16] = 0.034518618398549058625221276859; w[17] = 0.036075423225565273932166270524; w[18] = 0.037549253448257709809772223198; w[19] = 0.038936719204051197616673806364; w[20] = 0.040234629273005533815446337743; w[21] = 0.041439998417240293022686299233; w[22] = 0.042550054246755802719217150803; w[23] = 0.043562243595800486532284821661; w[24] = 0.044474238395082974427323504000; w[25] = 0.045283941026300230657128240574; w[26] = 0.045989489146651696963893390818; w[27] = 0.046589259972233498302255136790; w[28] = 0.047081874010454522246006808290; w[29] = 0.047466198232885503152644458740; w[30] = 0.047741348681240621559038972227; w[31] = 0.047906692500495862031347289176; w[32] = 0.04796184939446661812070762137; w[33] = 0.047906692500495862031347289176; w[34] = 0.047741348681240621559038972227; w[35] = 0.047466198232885503152644458740; w[36] = 0.047081874010454522246006808290; w[37] = 0.046589259972233498302255136790; w[38] = 0.045989489146651696963893390818; w[39] = 0.045283941026300230657128240574; w[40] = 0.044474238395082974427323504000; w[41] = 0.043562243595800486532284821661; w[42] = 0.042550054246755802719217150803; w[43] = 0.041439998417240293022686299233; w[44] = 0.040234629273005533815446337743; w[45] = 0.038936719204051197616673806364; w[46] = 0.037549253448257709809772223198; w[47] = 0.036075423225565273932166270524; w[48] = 0.034518618398549058625221276859; w[49] = 0.032882419676368574984049638008; w[50] = 0.031170590380189142464431845777; w[51] = 0.029387067789310668062644859210; w[52] = 0.027535954088450343942499722327; w[53] = 0.025621506938037758214084978694; w[54] = 0.023648129691287236698780978994; w[55] = 0.021620361284934062841654274667; w[56] = 0.019542865836750062826837429313; w[57] = 0.017420421997670248495365759969; w[58] = 0.015257912146448310349265388145; w[59] = 0.013060311639994846336168342922; w[60] = 0.0108326787895979686215140551272; w[61] = 0.0085801482668814598936358121592; w[62] = 0.0063079425789717545501888719039; w[63] = 0.0040215241720037363470786599528; w[64] = 0.0017292582513002508983395851463; } else if ( n == 127 ) { x[0] = -0.9998221304153061462673512; x[1] = -0.9990629343553118951383159; x[2] = -0.9976975661898046210744170; x[3] = -0.9957265513520272266354334; x[4] = -0.9931510492545171473611308; x[5] = -0.9899726145914841576077867; x[6] = -0.9861931740169316667104383; x[7] = -0.9818150208038141100334631; x[8] = -0.9768408123430703268174439; x[9] = -0.9712735681615291922889469; x[10] = -0.9651166679452921210908251; x[11] = -0.9583738494252387711491029; x[12] = -0.9510492060778803105479076; x[13] = -0.9431471846248148273454496; x[14] = -0.9346725823247379685736349; x[15] = -0.9256305440562338491274647; x[16] = -0.9160265591914658093130886; x[17] = -0.9058664582618213828024613; x[18] = -0.8951564094170837089690438; x[19] = -0.8839029146800265699452579; x[20] = -0.8721128059985607114196375; x[21] = -0.8597932410977408098120313; x[22] = -0.8469516991340975984533393; x[23] = -0.8335959761548995143795572; x[24] = -0.8197341803650786741551191; x[25] = -0.8053747272046802146665608; x[26] = -0.7905263342398137999454500; x[27] = -0.7751980158702023824449628; x[28] = -0.7593990778565366715566637; x[29] = -0.7431391116709545129205669; x[30] = -0.7264279886740726855356929; x[31] = -0.7092758541221045609994446; x[32] = -0.6916931210077006701564414; x[33] = -0.6736904637382504853466825; x[34] = -0.6552788116554826302767651; x[35] = -0.6364693424002972413476082; x[36] = -0.6172734751268582838576392; x[37] = -0.5977028635700652293844120; x[38] = -0.5777693889706125800032517; x[39] = -0.5574851528619322329218619; x[40] = -0.5368624697233975674581664; x[41] = -0.5159138595042493572772773; x[42] = -0.4946520400227821173949402; x[43] = -0.4730899192454052416450999; x[44] = -0.4512405874502662273318986; x[45] = -0.4291173092801933762625441; x[46] = -0.4067335156897825634086729; x[47] = -0.3841027957915169357790778; x[48] = -0.3612388886058697060709248; x[49] = -0.3381556747203985013760003; x[50] = -0.3148671678628949814860148; x[51] = -0.2913875063937056207945188; x[52] = -0.2677309447223886208883435; x[53] = -0.2439118446539178579707132; x[54] = -0.2199446666696875424545234; x[55] = -0.1958439611486108515042816; x[56] = -0.1716243595336421650083449; x[57] = -0.1473005654490856693893293; x[58] = -0.1228873457740829717260337; x[59] = -0.0983995216776989707510918; x[60] = -0.0738519596210485452734404; x[61] = -0.0492595623319266303153793; x[62] = -0.0246372597574209446148971; x[63] = 0.0000000000000000000000000; x[64] = 0.0246372597574209446148971; x[65] = 0.0492595623319266303153793; x[66] = 0.0738519596210485452734404; x[67] = 0.0983995216776989707510918; x[68] = 0.1228873457740829717260337; x[69] = 0.1473005654490856693893293; x[70] = 0.1716243595336421650083449; x[71] = 0.1958439611486108515042816; x[72] = 0.2199446666696875424545234; x[73] = 0.2439118446539178579707132; x[74] = 0.2677309447223886208883435; x[75] = 0.2913875063937056207945188; x[76] = 0.3148671678628949814860148; x[77] = 0.3381556747203985013760003; x[78] = 0.3612388886058697060709248; x[79] = 0.3841027957915169357790778; x[80] = 0.4067335156897825634086729; x[81] = 0.4291173092801933762625441; x[82] = 0.4512405874502662273318986; x[83] = 0.4730899192454052416450999; x[84] = 0.4946520400227821173949402; x[85] = 0.5159138595042493572772773; x[86] = 0.5368624697233975674581664; x[87] = 0.5574851528619322329218619; x[88] = 0.5777693889706125800032517; x[89] = 0.5977028635700652293844120; x[90] = 0.6172734751268582838576392; x[91] = 0.6364693424002972413476082; x[92] = 0.6552788116554826302767651; x[93] = 0.6736904637382504853466825; x[94] = 0.6916931210077006701564414; x[95] = 0.7092758541221045609994446; x[96] = 0.7264279886740726855356929; x[97] = 0.7431391116709545129205669; x[98] = 0.7593990778565366715566637; x[99] = 0.7751980158702023824449628; x[100] = 0.7905263342398137999454500; x[101] = 0.8053747272046802146665608; x[102] = 0.8197341803650786741551191; x[103] = 0.8335959761548995143795572; x[104] = 0.8469516991340975984533393; x[105] = 0.8597932410977408098120313; x[106] = 0.8721128059985607114196375; x[107] = 0.8839029146800265699452579; x[108] = 0.8951564094170837089690438; x[109] = 0.9058664582618213828024613; x[110] = 0.9160265591914658093130886; x[111] = 0.9256305440562338491274647; x[112] = 0.9346725823247379685736349; x[113] = 0.9431471846248148273454496; x[114] = 0.9510492060778803105479076; x[115] = 0.9583738494252387711491029; x[116] = 0.965116667945292121090825; x[117] = 0.971273568161529192288947; x[118] = 0.976840812343070326817444; x[119] = 0.981815020803814110033463; x[120] = 0.986193174016931666710438; x[121] = 0.989972614591484157607787; x[122] = 0.993151049254517147361131; x[123] = 0.995726551352027226635433; x[124] = 0.997697566189804621074417; x[125] = 0.999062934355311895138316; x[126] = 0.999822130415306146267351; w[0] = 0.00045645726109586662791936519265; w[1] = 0.00106227668695384869596523598532; w[2] = 0.0016683488125171936761028862915; w[3] = 0.0022734860707492547802810840776; w[4] = 0.0028772587656289004082883197514; w[5] = 0.0034792893810051465908910894100; w[6] = 0.0040792095178254605327114733457; w[7] = 0.0046766539777779034772638165663; w[8] = 0.0052712596565634400891303815906; w[9] = 0.0058626653903523901033648343751; w[10] = 0.0064505120486899171845442463869; w[11] = 0.0070344427036681608755685893033; w[12] = 0.0076141028256526859356393930849; w[13] = 0.0081891404887415730817235884719; w[14] = 0.0087592065795403145773316804234; w[15] = 0.0093239550065309714787536985834; w[16] = 0.0098830429087554914716648010900; w[17] = 0.0104361308631410052256731719977; w[18] = 0.0109828830900689757887996573761; w[19] = 0.011522967656921087154811609735; w[20] = 0.012056056679400848183529562145; w[21] = 0.012581826520465013101514365424; w[22] = 0.013099957986718627426172681913; w[23] = 0.013610136522139249906034237534; w[24] = 0.014112052399003395774044161634; w[25] = 0.014605400905893418351737288079; w[26] = 0.015089882532666922992635733981; w[27] = 0.015565203152273955098532590263; w[28] = 0.016031074199309941802254151843; w[29] = 0.016487212845194879399346060358; w[30] = 0.016933342169871654545878815295; w[31] = 0.017369191329918731922164721250; w[32] = 0.017794495722974774231027912900; w[33] = 0.018208997148375106468721469154; w[34] = 0.018612443963902310429440419899; w[35] = 0.019004591238555646611148901045; w[36] = 0.019385200901246454628112623489; w[37] = 0.019754041885329183081815217323; w[38] = 0.020110890268880247225644623956; w[39] = 0.020455529410639508279497065713; w[40] = 0.020787750081531811812652137291; w[41] = 0.021107350591688713643523847922; w[42] = 0.021414136912893259295449693234; w[43] = 0.021707922796373466052301324695; w[44] = 0.021988529885872983756478409759; w[45] = 0.022255787825930280235631416460; w[46] = 0.022509534365300608085694429903; w[47] = 0.022749615455457959852242553241; w[48] = 0.022975885344117206754377437839; w[49] = 0.023188206663719640249922582982; w[50] = 0.023386450514828194170722043497; w[51] = 0.023570496544381716050033676844; w[52] = 0.023740233018760777777714726703; w[53] = 0.023895556891620665983864481754; w[54] = 0.024036373866450369675132086026; w[55] = 0.024162598453819584716522917711; w[56] = 0.024274154023278979833195063937; w[57] = 0.024370972849882214952813561907; w[58] = 0.024452996155301467956140198472; w[59] = 0.024520174143511508275183033290; w[60] = 0.024572466031020653286354137335; w[61] = 0.024609840071630254092545634003; w[62] = 0.024632273575707679066033370218; w[63] = 0.02463975292396109441957941748; w[64] = 0.024632273575707679066033370218; w[65] = 0.024609840071630254092545634003; w[66] = 0.024572466031020653286354137335; w[67] = 0.024520174143511508275183033290; w[68] = 0.024452996155301467956140198472; w[69] = 0.024370972849882214952813561907; w[70] = 0.024274154023278979833195063937; w[71] = 0.024162598453819584716522917711; w[72] = 0.024036373866450369675132086026; w[73] = 0.023895556891620665983864481754; w[74] = 0.023740233018760777777714726703; w[75] = 0.023570496544381716050033676844; w[76] = 0.023386450514828194170722043497; w[77] = 0.023188206663719640249922582982; w[78] = 0.022975885344117206754377437839; w[79] = 0.022749615455457959852242553241; w[80] = 0.022509534365300608085694429903; w[81] = 0.022255787825930280235631416460; w[82] = 0.021988529885872983756478409759; w[83] = 0.021707922796373466052301324695; w[84] = 0.021414136912893259295449693234; w[85] = 0.021107350591688713643523847922; w[86] = 0.020787750081531811812652137291; w[87] = 0.020455529410639508279497065713; w[88] = 0.020110890268880247225644623956; w[89] = 0.019754041885329183081815217323; w[90] = 0.019385200901246454628112623489; w[91] = 0.019004591238555646611148901045; w[92] = 0.018612443963902310429440419899; w[93] = 0.018208997148375106468721469154; w[94] = 0.017794495722974774231027912900; w[95] = 0.017369191329918731922164721250; w[96] = 0.016933342169871654545878815295; w[97] = 0.016487212845194879399346060358; w[98] = 0.016031074199309941802254151843; w[99] = 0.015565203152273955098532590263; w[100] = 0.015089882532666922992635733981; w[101] = 0.014605400905893418351737288079; w[102] = 0.014112052399003395774044161634; w[103] = 0.013610136522139249906034237534; w[104] = 0.013099957986718627426172681913; w[105] = 0.012581826520465013101514365424; w[106] = 0.012056056679400848183529562145; w[107] = 0.011522967656921087154811609735; w[108] = 0.0109828830900689757887996573761; w[109] = 0.0104361308631410052256731719977; w[110] = 0.0098830429087554914716648010900; w[111] = 0.0093239550065309714787536985834; w[112] = 0.0087592065795403145773316804234; w[113] = 0.0081891404887415730817235884719; w[114] = 0.0076141028256526859356393930849; w[115] = 0.0070344427036681608755685893033; w[116] = 0.0064505120486899171845442463869; w[117] = 0.0058626653903523901033648343751; w[118] = 0.0052712596565634400891303815906; w[119] = 0.0046766539777779034772638165663; w[120] = 0.0040792095178254605327114733457; w[121] = 0.0034792893810051465908910894100; w[122] = 0.0028772587656289004082883197514; w[123] = 0.0022734860707492547802810840776; w[124] = 0.0016683488125171936761028862915; w[125] = 0.00106227668695384869596523598532; w[126] = 0.00045645726109586662791936519265; } else if ( n == 128 ) { x[0] = -0.9998248879471319144736081; x[1] = -0.9990774599773758950119878; x[2] = -0.9977332486255140198821574; x[3] = -0.9957927585349811868641612; x[4] = -0.9932571129002129353034372; x[5] = -0.9901278184917343833379303; x[6] = -0.9864067427245862088712355; x[7] = -0.9820961084357185360247656; x[8] = -0.9771984914639073871653744; x[9] = -0.9717168187471365809043384; x[10] = -0.9656543664319652686458290; x[11] = -0.9590147578536999280989185; x[12] = -0.9518019613412643862177963; x[13] = -0.9440202878302201821211114; x[14] = -0.9356743882779163757831268; x[15] = -0.9267692508789478433346245; x[16] = -0.9173101980809605370364836; x[17] = -0.9073028834017568139214859; x[18] = -0.8967532880491581843864474; x[19] = -0.8856677173453972174082924; x[20] = -0.8740527969580317986954180; x[21] = -0.8619154689395484605906323; x[22] = -0.8492629875779689691636001; x[23] = -0.8361029150609068471168753; x[24] = -0.8224431169556438424645942; x[25] = -0.8082917575079136601196422; x[26] = -0.7936572947621932902433329; x[27] = -0.7785484755064119668504941; x[28] = -0.7629743300440947227797691; x[29] = -0.7469441667970619811698824; x[30] = -0.7304675667419088064717369; x[31] = -0.7135543776835874133438599; x[32] = -0.6962147083695143323850866; x[33] = -0.6784589224477192593677557; x[34] = -0.6602976322726460521059468; x[35] = -0.6417416925623075571535249; x[36] = -0.6228021939105849107615396; x[37] = -0.6034904561585486242035732; x[38] = -0.5838180216287630895500389; x[39] = -0.5637966482266180839144308; x[40] = -0.5434383024128103634441936; x[41] = -0.5227551520511754784539479; x[42] = -0.5017595591361444642896063; x[43] = -0.4804640724041720258582757; x[44] = -0.4588814198335521954490891; x[45] = -0.4370245010371041629370429; x[46] = -0.4149063795522750154922739; x[47] = -0.3925402750332674427356482; x[48] = -0.3699395553498590266165917; x[49] = -0.3471177285976355084261628; x[50] = -0.3240884350244133751832523; x[51] = -0.3008654388776772026671541; x[52] = -0.2774626201779044028062316; x[53] = -0.2538939664226943208556180; x[54] = -0.2301735642266599864109866; x[55] = -0.2063155909020792171540580; x[56] = -0.1823343059853371824103826; x[57] = -0.1582440427142249339974755; x[58] = -0.1340591994611877851175753; x[59] = -0.1097942311276437466729747; x[60] = -0.0854636405045154986364980; x[61] = -0.0610819696041395681037870; x[62] = -0.0366637909687334933302153; x[63] = -0.0122236989606157641980521; x[64] = 0.0122236989606157641980521; x[65] = 0.0366637909687334933302153; x[66] = 0.0610819696041395681037870; x[67] = 0.0854636405045154986364980; x[68] = 0.1097942311276437466729747; x[69] = 0.1340591994611877851175753; x[70] = 0.1582440427142249339974755; x[71] = 0.1823343059853371824103826; x[72] = 0.2063155909020792171540580; x[73] = 0.2301735642266599864109866; x[74] = 0.2538939664226943208556180; x[75] = 0.2774626201779044028062316; x[76] = 0.3008654388776772026671541; x[77] = 0.3240884350244133751832523; x[78] = 0.3471177285976355084261628; x[79] = 0.3699395553498590266165917; x[80] = 0.3925402750332674427356482; x[81] = 0.4149063795522750154922739; x[82] = 0.4370245010371041629370429; x[83] = 0.4588814198335521954490891; x[84] = 0.4804640724041720258582757; x[85] = 0.5017595591361444642896063; x[86] = 0.5227551520511754784539479; x[87] = 0.5434383024128103634441936; x[88] = 0.5637966482266180839144308; x[89] = 0.5838180216287630895500389; x[90] = 0.6034904561585486242035732; x[91] = 0.6228021939105849107615396; x[92] = 0.6417416925623075571535249; x[93] = 0.6602976322726460521059468; x[94] = 0.6784589224477192593677557; x[95] = 0.6962147083695143323850866; x[96] = 0.7135543776835874133438599; x[97] = 0.7304675667419088064717369; x[98] = 0.7469441667970619811698824; x[99] = 0.7629743300440947227797691; x[100] = 0.7785484755064119668504941; x[101] = 0.7936572947621932902433329; x[102] = 0.8082917575079136601196422; x[103] = 0.8224431169556438424645942; x[104] = 0.8361029150609068471168753; x[105] = 0.8492629875779689691636001; x[106] = 0.8619154689395484605906323; x[107] = 0.8740527969580317986954180; x[108] = 0.8856677173453972174082924; x[109] = 0.8967532880491581843864474; x[110] = 0.9073028834017568139214859; x[111] = 0.9173101980809605370364836; x[112] = 0.926769250878947843334625; x[113] = 0.935674388277916375783127; x[114] = 0.944020287830220182121111; x[115] = 0.951801961341264386217796; x[116] = 0.959014757853699928098919; x[117] = 0.965654366431965268645829; x[118] = 0.971716818747136580904338; x[119] = 0.977198491463907387165374; x[120] = 0.982096108435718536024766; x[121] = 0.986406742724586208871236; x[122] = 0.990127818491734383337930; x[123] = 0.993257112900212935303437; x[124] = 0.995792758534981186864161; x[125] = 0.997733248625514019882157; x[126] = 0.999077459977375895011988; x[127] = 0.999824887947131914473608; w[0] = 0.00044938096029209037639429223999; w[1] = 0.0010458126793403487793128516001; w[2] = 0.0016425030186690295387908755948; w[3] = 0.0022382884309626187436220542727; w[4] = 0.0028327514714579910952857346468; w[5] = 0.0034255260409102157743377846601; w[6] = 0.0040162549837386423131943434863; w[7] = 0.0046045842567029551182905419803; w[8] = 0.0051901618326763302050707671348; w[9] = 0.0057726375428656985893346176261; w[10] = 0.006351663161707188787214327826; w[11] = 0.006926892566898813563426670360; w[12] = 0.007497981925634728687671962688; w[13] = 0.008064589890486057972928598698; w[14] = 0.008626377798616749704978843782; w[15] = 0.009183009871660874334478743688; w[16] = 0.009734153415006805863548266094; w[17] = 0.010279479015832157133215340326; w[18] = 0.010818660739503076247659646277; w[19] = 0.011351376324080416693281668453; w[20] = 0.011877307372740279575891106926; w[21] = 0.012396139543950922968821728197; w[22] = 0.012907562739267347220442834004; w[23] = 0.013411271288616332314488951616; w[24] = 0.013906964132951985244288007396; w[25] = 0.014394345004166846176823892009; w[26] = 0.014873122602147314252385498520; w[27] = 0.015343010768865144085990853741; w[28] = 0.015803728659399346858965631687; w[29] = 0.016255000909785187051657456477; w[30] = 0.016696557801589204589091507954; w[31] = 0.017128135423111376830680987619; w[32] = 0.017549475827117704648706925634; w[33] = 0.017960327185008685940196927525; w[34] = 0.018360443937331343221289290991; w[35] = 0.018749586940544708650919548474; w[36] = 0.019127523609950945486518531668; w[37] = 0.019494028058706602823021918681; w[38] = 0.019848881232830862219944413265; w[39] = 0.020191871042130041180673158406; w[40] = 0.020522792486960069432284967788; w[41] = 0.020841447780751149113583948423; w[42] = 0.021147646468221348537019535180; w[43] = 0.021441205539208460137111853878; w[44] = 0.021721949538052075375260957768; w[45] = 0.021989710668460491434122106599; w[46] = 0.022244328893799765104629133607; w[47] = 0.022485652032744966871824603941; w[48] = 0.022713535850236461309712635923; w[49] = 0.022927844143686846920410987209; w[50] = 0.023128448824387027879297902403; w[51] = 0.023315229994062760122415671273; w[52] = 0.023488076016535913153025273282; w[53] = 0.023646883584447615143651392303; w[54] = 0.023791557781003400638780709885; w[55] = 0.023922012136703455672450408817; w[56] = 0.024038168681024052637587316820; w[57] = 0.024139957989019284997716653890; w[58] = 0.024227319222815248120093308442; w[59] = 0.024300200167971865323442606364; w[60] = 0.024358557264690625853268520246; w[61] = 0.024402355633849582093297989694; w[62] = 0.02443156909785004505484856143; w[63] = 0.02444618019626251821132585261; w[64] = 0.02444618019626251821132585261; w[65] = 0.02443156909785004505484856143; w[66] = 0.024402355633849582093297989694; w[67] = 0.024358557264690625853268520246; w[68] = 0.024300200167971865323442606364; w[69] = 0.024227319222815248120093308442; w[70] = 0.024139957989019284997716653890; w[71] = 0.024038168681024052637587316820; w[72] = 0.023922012136703455672450408817; w[73] = 0.023791557781003400638780709885; w[74] = 0.023646883584447615143651392303; w[75] = 0.023488076016535913153025273282; w[76] = 0.023315229994062760122415671273; w[77] = 0.023128448824387027879297902403; w[78] = 0.022927844143686846920410987209; w[79] = 0.022713535850236461309712635923; w[80] = 0.022485652032744966871824603941; w[81] = 0.022244328893799765104629133607; w[82] = 0.021989710668460491434122106599; w[83] = 0.021721949538052075375260957768; w[84] = 0.021441205539208460137111853878; w[85] = 0.021147646468221348537019535180; w[86] = 0.020841447780751149113583948423; w[87] = 0.020522792486960069432284967788; w[88] = 0.020191871042130041180673158406; w[89] = 0.019848881232830862219944413265; w[90] = 0.019494028058706602823021918681; w[91] = 0.019127523609950945486518531668; w[92] = 0.018749586940544708650919548474; w[93] = 0.018360443937331343221289290991; w[94] = 0.017960327185008685940196927525; w[95] = 0.017549475827117704648706925634; w[96] = 0.017128135423111376830680987619; w[97] = 0.016696557801589204589091507954; w[98] = 0.016255000909785187051657456477; w[99] = 0.015803728659399346858965631687; w[100] = 0.015343010768865144085990853741; w[101] = 0.014873122602147314252385498520; w[102] = 0.014394345004166846176823892009; w[103] = 0.013906964132951985244288007396; w[104] = 0.013411271288616332314488951616; w[105] = 0.012907562739267347220442834004; w[106] = 0.012396139543950922968821728197; w[107] = 0.011877307372740279575891106926; w[108] = 0.011351376324080416693281668453; w[109] = 0.010818660739503076247659646277; w[110] = 0.010279479015832157133215340326; w[111] = 0.009734153415006805863548266094; w[112] = 0.009183009871660874334478743688; w[113] = 0.008626377798616749704978843782; w[114] = 0.008064589890486057972928598698; w[115] = 0.007497981925634728687671962688; w[116] = 0.006926892566898813563426670360; w[117] = 0.006351663161707188787214327826; w[118] = 0.0057726375428656985893346176261; w[119] = 0.0051901618326763302050707671348; w[120] = 0.0046045842567029551182905419803; w[121] = 0.0040162549837386423131943434863; w[122] = 0.0034255260409102157743377846601; w[123] = 0.0028327514714579910952857346468; w[124] = 0.0022382884309626187436220542727; w[125] = 0.0016425030186690295387908755948; w[126] = 0.0010458126793403487793128516001; w[127] = 0.00044938096029209037639429223999; } else if ( n == 129 ) { x[0] = -0.9998275818477487191077441; x[1] = -0.9990916504696409986514389; x[2] = -0.9977681080525852721429460; x[3] = -0.9958574393142831982149111; x[4] = -0.9933607326210712814854011; x[5] = -0.9902794486488178389207689; x[6] = -0.9866153978313475022005761; x[7] = -0.9823707352517413115507418; x[8] = -0.9775479582993672474447814; x[9] = -0.9721499048427034297274163; x[10] = -0.9661797514202097197778763; x[11] = -0.9596410113101918904168119; x[12] = -0.9525375324342090471027732; x[13] = -0.9448734950776734726784764; x[14] = -0.9366534094216514605284616; x[15] = -0.9278821128840036204317296; x[16] = -0.9185647672698286252225115; x[17] = -0.9087068557320696331245539; x[18] = -0.8983141795436338850435985; x[19] = -0.8873928546826803665034968; x[20] = -0.8759493082329433892035217; x[21] = -0.8639902746011257878940216; x[22] = -0.8515227915535356930243826; x[23] = -0.8385541960742664442975407; x[24] = -0.8250921200473358809210133; x[25] = -0.8111444857653120742087717; x[26] = -0.7967195012670592680339606; x[27] = -0.7818256555073413245387500; x[28] = -0.7664717133611208816717785; x[29] = -0.7506667104654910227632368; x[30] = -0.7344199479022727047791516; x[31] = -0.7177409867244055767721220; x[32] = -0.7006396423293521790044710; x[33] = -0.6831259786828258512462248; x[34] = -0.6652103023962409818802202; x[35] = -0.6469031566613704719753373; x[36] = -0.6282153150457794374886895; x[37] = -0.6091577751526861909563306; x[38] = -0.5897417521489813916767844; x[39] = -0.5699786721652138894754096; x[40] = -0.5498801655714271702189358; x[41] = -0.5294580601328034000099406; x[42] = -0.5087243740491428186199463; x[43] = -0.4876913088822746111853066; x[44] = -0.4663712423755613514331869; x[45] = -0.4447767211697226217818454; x[46] = -0.4229204534192644388475065; x[47] = -0.4008153013138596117693121; x[48] = -0.3784742735090801012801265; x[49] = -0.3559105174709357969672656; x[50] = -0.3331373117387248575049982; x[51] = -0.3101680581107488341147318; x[52] = -0.2870162737574911929568755; x[53] = -0.2636955832669005409666949; x[54] = -0.2402197106264598167721148; x[55] = -0.2166024711467599103221439; x[56] = -0.1928577633313305998663880; x[57] = -0.1689995606975133227390302; x[58] = -0.1450419035531891084328306; x[59] = -0.1209988907342009817690539; x[60] = -0.0968846713073332753086909; x[61] = -0.0727134362437305599118207; x[62] = -0.0484994100676562986191764; x[63] = -0.0242568424855058415749954; x[64] = 0.0000000000000000000000000; x[65] = 0.0242568424855058415749954; x[66] = 0.0484994100676562986191764; x[67] = 0.0727134362437305599118207; x[68] = 0.0968846713073332753086909; x[69] = 0.1209988907342009817690539; x[70] = 0.1450419035531891084328306; x[71] = 0.1689995606975133227390302; x[72] = 0.1928577633313305998663880; x[73] = 0.2166024711467599103221439; x[74] = 0.2402197106264598167721148; x[75] = 0.2636955832669005409666949; x[76] = 0.2870162737574911929568755; x[77] = 0.3101680581107488341147318; x[78] = 0.3331373117387248575049982; x[79] = 0.3559105174709357969672656; x[80] = 0.3784742735090801012801265; x[81] = 0.4008153013138596117693121; x[82] = 0.4229204534192644388475065; x[83] = 0.4447767211697226217818454; x[84] = 0.4663712423755613514331869; x[85] = 0.4876913088822746111853066; x[86] = 0.5087243740491428186199463; x[87] = 0.5294580601328034000099406; x[88] = 0.5498801655714271702189358; x[89] = 0.5699786721652138894754096; x[90] = 0.5897417521489813916767844; x[91] = 0.6091577751526861909563306; x[92] = 0.6282153150457794374886895; x[93] = 0.6469031566613704719753373; x[94] = 0.6652103023962409818802202; x[95] = 0.6831259786828258512462248; x[96] = 0.7006396423293521790044710; x[97] = 0.7177409867244055767721220; x[98] = 0.7344199479022727047791516; x[99] = 0.7506667104654910227632368; x[100] = 0.7664717133611208816717785; x[101] = 0.7818256555073413245387500; x[102] = 0.7967195012670592680339606; x[103] = 0.8111444857653120742087717; x[104] = 0.8250921200473358809210133; x[105] = 0.8385541960742664442975407; x[106] = 0.8515227915535356930243826; x[107] = 0.8639902746011257878940216; x[108] = 0.875949308232943389203522; x[109] = 0.887392854682680366503497; x[110] = 0.898314179543633885043599; x[111] = 0.908706855732069633124554; x[112] = 0.918564767269828625222511; x[113] = 0.927882112884003620431730; x[114] = 0.936653409421651460528462; x[115] = 0.944873495077673472678476; x[116] = 0.952537532434209047102773; x[117] = 0.959641011310191890416812; x[118] = 0.966179751420209719777876; x[119] = 0.972149904842703429727416; x[120] = 0.977547958299367247444781; x[121] = 0.982370735251741311550742; x[122] = 0.986615397831347502200576; x[123] = 0.990279448648817838920769; x[124] = 0.993360732621071281485401; x[125] = 0.995857439314283198214911; x[126] = 0.997768108052585272142946; x[127] = 0.999091650469640998651439; x[128] = 0.999827581847748719107744; w[0] = 0.00044246794182939296923668005717; w[1] = 0.00102972844619622394463273519315; w[2] = 0.0016172530556785534682413679271; w[3] = 0.0022039015180966937075786419741; w[4] = 0.0027892681877797554940944677057; w[5] = 0.0033729979506246246117755709288; w[6] = 0.0039547444682113562172392974765; w[7] = 0.0045341644298525434513226874954; w[8] = 0.0051109164669246267289761565766; w[9] = 0.0056846609912469045788016012203; w[10] = 0.0062550602724461408889348709586; w[11] = 0.0068217785893519121070498527769; w[12] = 0.0073844824072454014447165055698; w[13] = 0.0079428405646668029041114107832; w[14] = 0.0084965244635723279730542832506; w[15] = 0.0090452082602137316404219313819; w[16] = 0.0095885690555104190787301294510; w[17] = 0.0101262870842733548093160774580; w[18] = 0.0106580459029055185304204093001; w[19] = 0.0111835325753305049735380697538; w[20] = 0.011702437856964778185746436834; w[21] = 0.012214456376582979416221105914; w[22] = 0.012719286815944623465099036330; w[23] = 0.013216632087061724231482387345; w[24] = 0.013706199506993971244060563234; w[25] = 0.014187700970062900419317230938; w[26] = 0.014660853117380060971041027493; w[27] = 0.015125377503587024690403432771; w[28] = 0.015581000760707523415881287558; w[29] = 0.016027454759014214436403950465; w[30] = 0.016464476764814667467169189640; w[31] = 0.016891809595063204177526208819; w[32] = 0.017309201768707240731293596444; w[33] = 0.017716407654678809269702031810; w[34] = 0.018113187616443980503999783812; w[35] = 0.018499308153024985727791918518; w[36] = 0.018874542036411948181617592169; w[37] = 0.019238668445283284085199492202; w[38] = 0.019591473094956024580283987216; w[39] = 0.019932748363489542089706675388; w[40] = 0.020262293413868438317104423081; w[41] = 0.020579914312192665948185517085; w[42] = 0.020885424141805311409990024684; w[43] = 0.021178643113290860912881038703; w[44] = 0.021459398670279205389981598196; w[45] = 0.021727525590993110687305178710; w[46] = 0.021982866085479386179554968899; w[47] = 0.022225269888466526554736910919; w[48] = 0.022454594347794176432066564511; w[49] = 0.022670704508362374313093970958; w[50] = 0.022873473191551169638592083492; w[51] = 0.023062781070063872924670495006; w[52] = 0.023238516738149892544490435771; w[53] = 0.023400576777165831146714346635; w[54] = 0.023548865816436258377269094263; w[55] = 0.023683296589378342897341543485; w[56] = 0.023803789984857314051325299744; w[57] = 0.023910275093742530302367230296; w[58] = 0.024002689250636756075547029720; w[59] = 0.024080978070754089272959634041; w[60] = 0.024145095481924836783843156014; w[61] = 0.024195003751708503129818111597; w[62] = 0.024230673509598936275508460625; w[63] = 0.024252083764308562906498864071; w[64] = 0.02425922191612154143202867472; w[65] = 0.024252083764308562906498864071; w[66] = 0.024230673509598936275508460625; w[67] = 0.024195003751708503129818111597; w[68] = 0.024145095481924836783843156014; w[69] = 0.024080978070754089272959634041; w[70] = 0.024002689250636756075547029720; w[71] = 0.023910275093742530302367230296; w[72] = 0.023803789984857314051325299744; w[73] = 0.023683296589378342897341543485; w[74] = 0.023548865816436258377269094263; w[75] = 0.023400576777165831146714346635; w[76] = 0.023238516738149892544490435771; w[77] = 0.023062781070063872924670495006; w[78] = 0.022873473191551169638592083492; w[79] = 0.022670704508362374313093970958; w[80] = 0.022454594347794176432066564511; w[81] = 0.022225269888466526554736910919; w[82] = 0.021982866085479386179554968899; w[83] = 0.021727525590993110687305178710; w[84] = 0.021459398670279205389981598196; w[85] = 0.021178643113290860912881038703; w[86] = 0.020885424141805311409990024684; w[87] = 0.020579914312192665948185517085; w[88] = 0.020262293413868438317104423081; w[89] = 0.019932748363489542089706675388; w[90] = 0.019591473094956024580283987216; w[91] = 0.019238668445283284085199492202; w[92] = 0.018874542036411948181617592169; w[93] = 0.018499308153024985727791918518; w[94] = 0.018113187616443980503999783812; w[95] = 0.017716407654678809269702031810; w[96] = 0.017309201768707240731293596444; w[97] = 0.016891809595063204177526208819; w[98] = 0.016464476764814667467169189640; w[99] = 0.016027454759014214436403950465; w[100] = 0.015581000760707523415881287558; w[101] = 0.015125377503587024690403432771; w[102] = 0.014660853117380060971041027493; w[103] = 0.014187700970062900419317230938; w[104] = 0.013706199506993971244060563234; w[105] = 0.013216632087061724231482387345; w[106] = 0.012719286815944623465099036330; w[107] = 0.012214456376582979416221105914; w[108] = 0.011702437856964778185746436834; w[109] = 0.0111835325753305049735380697538; w[110] = 0.0106580459029055185304204093001; w[111] = 0.0101262870842733548093160774580; w[112] = 0.0095885690555104190787301294510; w[113] = 0.0090452082602137316404219313819; w[114] = 0.0084965244635723279730542832506; w[115] = 0.0079428405646668029041114107832; w[116] = 0.0073844824072454014447165055698; w[117] = 0.0068217785893519121070498527769; w[118] = 0.0062550602724461408889348709586; w[119] = 0.0056846609912469045788016012203; w[120] = 0.0051109164669246267289761565766; w[121] = 0.0045341644298525434513226874954; w[122] = 0.0039547444682113562172392974765; w[123] = 0.0033729979506246246117755709288; w[124] = 0.0027892681877797554940944677057; w[125] = 0.0022039015180966937075786419741; w[126] = 0.0016172530556785534682413679271; w[127] = 0.00102972844619622394463273519315; w[128] = 0.00044246794182939296923668005717; } else if ( n == 255 ) { x[0] = -0.999955705317563751730191; x[1] = -0.999766621312000569367063; x[2] = -0.999426474680169959344386; x[3] = -0.998935241284654635142155; x[4] = -0.998292986136967889228248; x[5] = -0.997499804126615814044844; x[6] = -0.996555814435198617028738; x[7] = -0.995461159480026294089975; x[8] = -0.994216004616630164799381; x[9] = -0.992820538021989138984811; x[10] = -0.991274970630385567164523; x[11] = -0.989579536085920123498574; x[12] = -0.987734490699732356281248; x[13] = -0.985740113407419277752900; x[14] = -0.983596705724776358640192; x[15] = -0.981304591701017185126565; x[16] = -0.978864117869068155239121; x[17] = -0.976275653192735980815246; x[18] = -0.973539589010643617645393; x[19] = -0.970656338976880365477697; x[20] = -0.967626338998338798105523; x[21] = -0.964450047168726298761719; x[22] = -0.961127943699247839572910; x[23] = -0.957660530845962076295490; x[24] = -0.954048332833816317950921; x[25] = -0.950291895777368285733522; x[26] = -0.946391787598204251752103; x[27] = -0.942348597939064408301480; x[28] = -0.938162938074687317626793; x[29] = -0.933835440819386124349338; x[30] = -0.929366760431369935739045; x[31] = -0.924757572513824425220425; x[32] = -0.920008573912766315142721; x[33] = -0.915120482611686961035103; x[34] = -0.910094037623000801254172; x[35] = -0.904929998876314959753358; x[36] = -0.899629147103536800144342; x[37] = -0.894192283720836729335637; x[38] = -0.888620230707484040924981; x[39] = -0.882913830481574073645470; x[40] = -0.877073945772665439532627; x[41] = -0.871101459491346550796200; x[42] = -0.864997274595751144137121; x[43] = -0.858762313955042966785823; x[44] = -0.852397520209890250084237; x[45] = -0.845903855629951054143931; x[46] = -0.839282301968391021084600; x[47] = -0.832533860313455524647230; x[48] = -0.825659550937118650611534; x[49] = -0.818660413140831885432406; x[50] = -0.811537505098395829833580; x[51] = -0.804291903695978689734633; x[52] = -0.796924704369305728807154; x[53] = -0.789437020938044295117764; x[54] = -0.781829985437409458675147; x[55] = -0.774104747947015717207115; x[56] = -0.766262476417000644100858; x[57] = -0.758304356491446765092016; x[58] = -0.750231591329128358931528; x[59] = -0.742045401421610281838045; x[60] = -0.733747024408726316001889; x[61] = -0.725337714891464938687812; x[62] = -0.716818744242290800531501; x[63] = -0.708191400412930589382399; x[64] = -0.699456987739652339456557; x[65] = -0.690616826746067624571761; x[66] = -0.681672253943486448787259; x[67] = -0.672624621628855017806731; x[68] = -0.663475297680306939970658; x[69] = -0.654225665350358766508700; x[70] = -0.644877123056781136890077; x[71] = -0.635431084171177146547142; x[72] = -0.625888976805299900901619; x[73] = -0.616252243595141561442344; x[74] = -0.606522341482826526536576; x[75] = -0.596700741496341721653202; x[76] = -0.586788928527137300685706; x[77] = -0.576788401105631382036211; x[78] = -0.566700671174652760010815; x[79] = -0.556527263860855843833077; x[80] = -0.546269717244142383159817; x[81] = -0.535929582125124840335150; x[82] = -0.525508421790666565699453; x[83] = -0.515007811777534223035005; x[84] = -0.504429339634198197635551; x[85] = -0.493774604680816999489812; x[86] = -0.483045217767441948626854; x[87] = -0.472242801030478698742627; x[88] = -0.461368987647442418771401; x[89] = -0.450425421590043710043279; x[90] = -0.439413757375642589040685; x[91] = -0.428335659817108112494341; x[92] = -0.417192803771121462605751; x[93] = -0.405986873884960545511889; x[94] = -0.394719564341804385683361; x[95] = -0.383392578604595822734854; x[96] = -0.372007629158501235092510; x[97] = -0.360566437252006227074021; x[98] = -0.349070732636686422161576; x[99] = -0.337522253305692705554261; x[100] = -0.325922745230990453444769; x[101] = -0.314273962099392474845918; x[102] = -0.302577665047425574167140; x[103] = -0.290835622395070819082047; x[104] = -0.279049609378417768508970; x[105] = -0.267221407881273079721012; x[106] = -0.255352806165764071686080; x[107] = -0.243445598601977973686482; x[108] = -0.231501585396677734059116; x[109] = -0.219522572321135403508985; x[110] = -0.207510370438124240859625; x[111] = -0.195466795828110816293869; x[112] = -0.183393669314688508087976; x[113] = -0.171292816189293903533225; x[114] = -0.159166065935247723154292; x[115] = -0.147015251951161989456661; x[116] = -0.134842211273755257250625; x[117] = -0.122648784300117812092492; x[118] = -0.110436814509468826540991; x[119] = -0.098208148184447540736015; x[120] = -0.085964634131980604256000; x[121] = -0.073708123403767780288977; x[122] = -0.061440469016428270850728; x[123] = -0.049163525671349973093019; x[124] = -0.036879149474284021657652; x[125] = -0.024589197654727010541405; x[126] = -0.012295528285133320036860; x[127] = 0.000000000000000000000000; x[128] = 0.012295528285133320036860; x[129] = 0.024589197654727010541405; x[130] = 0.036879149474284021657652; x[131] = 0.049163525671349973093019; x[132] = 0.061440469016428270850728; x[133] = 0.073708123403767780288977; x[134] = 0.085964634131980604256000; x[135] = 0.098208148184447540736015; x[136] = 0.110436814509468826540991; x[137] = 0.122648784300117812092492; x[138] = 0.134842211273755257250625; x[139] = 0.147015251951161989456661; x[140] = 0.159166065935247723154292; x[141] = 0.171292816189293903533225; x[142] = 0.183393669314688508087976; x[143] = 0.195466795828110816293869; x[144] = 0.207510370438124240859625; x[145] = 0.219522572321135403508985; x[146] = 0.231501585396677734059116; x[147] = 0.243445598601977973686482; x[148] = 0.255352806165764071686080; x[149] = 0.267221407881273079721012; x[150] = 0.279049609378417768508970; x[151] = 0.290835622395070819082047; x[152] = 0.302577665047425574167140; x[153] = 0.314273962099392474845918; x[154] = 0.325922745230990453444769; x[155] = 0.337522253305692705554261; x[156] = 0.349070732636686422161576; x[157] = 0.360566437252006227074021; x[158] = 0.372007629158501235092510; x[159] = 0.383392578604595822734854; x[160] = 0.394719564341804385683361; x[161] = 0.405986873884960545511889; x[162] = 0.417192803771121462605751; x[163] = 0.428335659817108112494341; x[164] = 0.439413757375642589040685; x[165] = 0.450425421590043710043279; x[166] = 0.461368987647442418771401; x[167] = 0.472242801030478698742627; x[168] = 0.483045217767441948626854; x[169] = 0.493774604680816999489812; x[170] = 0.504429339634198197635551; x[171] = 0.515007811777534223035005; x[172] = 0.525508421790666565699453; x[173] = 0.535929582125124840335150; x[174] = 0.546269717244142383159817; x[175] = 0.556527263860855843833077; x[176] = 0.566700671174652760010815; x[177] = 0.576788401105631382036211; x[178] = 0.586788928527137300685706; x[179] = 0.596700741496341721653202; x[180] = 0.606522341482826526536576; x[181] = 0.616252243595141561442344; x[182] = 0.625888976805299900901619; x[183] = 0.635431084171177146547142; x[184] = 0.644877123056781136890077; x[185] = 0.654225665350358766508700; x[186] = 0.663475297680306939970658; x[187] = 0.672624621628855017806731; x[188] = 0.681672253943486448787259; x[189] = 0.690616826746067624571761; x[190] = 0.699456987739652339456557; x[191] = 0.708191400412930589382399; x[192] = 0.716818744242290800531501; x[193] = 0.725337714891464938687812; x[194] = 0.733747024408726316001889; x[195] = 0.742045401421610281838045; x[196] = 0.750231591329128358931528; x[197] = 0.758304356491446765092016; x[198] = 0.766262476417000644100858; x[199] = 0.774104747947015717207115; x[200] = 0.781829985437409458675147; x[201] = 0.789437020938044295117764; x[202] = 0.796924704369305728807154; x[203] = 0.804291903695978689734633; x[204] = 0.811537505098395829833580; x[205] = 0.818660413140831885432406; x[206] = 0.825659550937118650611534; x[207] = 0.832533860313455524647230; x[208] = 0.839282301968391021084600; x[209] = 0.845903855629951054143931; x[210] = 0.852397520209890250084237; x[211] = 0.858762313955042966785823; x[212] = 0.864997274595751144137121; x[213] = 0.871101459491346550796200; x[214] = 0.877073945772665439532627; x[215] = 0.882913830481574073645470; x[216] = 0.888620230707484040924981; x[217] = 0.894192283720836729335637; x[218] = 0.899629147103536800144342; x[219] = 0.904929998876314959753358; x[220] = 0.910094037623000801254172; x[221] = 0.915120482611686961035103; x[222] = 0.920008573912766315142721; x[223] = 0.924757572513824425220425; x[224] = 0.929366760431369935739045; x[225] = 0.933835440819386124349338; x[226] = 0.938162938074687317626793; x[227] = 0.942348597939064408301480; x[228] = 0.946391787598204251752103; x[229] = 0.950291895777368285733522; x[230] = 0.954048332833816317950921; x[231] = 0.957660530845962076295490; x[232] = 0.961127943699247839572910; x[233] = 0.964450047168726298761719; x[234] = 0.967626338998338798105523; x[235] = 0.970656338976880365477697; x[236] = 0.973539589010643617645393; x[237] = 0.976275653192735980815246; x[238] = 0.978864117869068155239121; x[239] = 0.981304591701017185126565; x[240] = 0.983596705724776358640192; x[241] = 0.985740113407419277752900; x[242] = 0.987734490699732356281248; x[243] = 0.989579536085920123498574; x[244] = 0.991274970630385567164523; x[245] = 0.992820538021989138984811; x[246] = 0.994216004616630164799381; x[247] = 0.995461159480026294089975; x[248] = 0.996555814435198617028738; x[249] = 0.997499804126615814044844; x[250] = 0.998292986136967889228248; x[251] = 0.998935241284654635142155; x[252] = 0.999426474680169959344386; x[253] = 0.999766621312000569367063; x[254] = 0.999955705317563751730191; w[0] = 0.00011367361999142272115645954414; w[1] = 0.00026459387119083065532790838855; w[2] = 0.00041569762526823913616284210066; w[3] = 0.00056675794564824918946626058353; w[4] = 0.00071773647800611087798371518325; w[5] = 0.00086860766611945667949717690640; w[6] = 0.00101934797642732530281229369360; w[7] = 0.0011699343729388079886897709773; w[8] = 0.0013203439900221692090523602144; w[9] = 0.0014705540427783843160097204304; w[10] = 0.0016205417990415653896921100325; w[11] = 0.0017702845706603213070421243905; w[12] = 0.0019197597117132050055085980675; w[13] = 0.0020689446195015801533643667413; w[14] = 0.0022178167367540171700373764020; w[15] = 0.0023663535543962867157201855305; w[16] = 0.0025145326145997073931298921370; w[17] = 0.0026623315139717112732749157331; w[18] = 0.0028097279068204407457332299361; w[19] = 0.0029566995084575002760043344138; w[20] = 0.0031032240985191112621977893133; w[21] = 0.0032492795242943133198690930777; w[22] = 0.0033948437040533928255056951665; w[23] = 0.0035398946303722552150296713510; w[24] = 0.0036844103734499176530742235517; w[25] = 0.0038283690844171626400743524999; w[26] = 0.0039717489986349171988699773906; w[27] = 0.0041145284389812475901826468094; w[28] = 0.0042566858191260658425395494472; w[29] = 0.0043981996467927779838546384780; w[30] = 0.0045390485270061921259394035112; w[31] = 0.0046792111653260640506279893190; w[32] = 0.0048186663710656988918572043815; w[33] = 0.0049573930604950563104281084148; w[34] = 0.0050953702600278273039420404117; w[35] = 0.0052325771093919661294970523234; w[36] = 0.0053689928647831724787741258653; w[37] = 0.0055045969020008281904902120813; w[38] = 0.0056393687195659001929970994675; w[39] = 0.0057732879418203275712033691864; w[40] = 0.0059063343220074160130475409466; w[41] = 0.0060384877453327676663371666884; w[42] = 0.0061697282320052788060812561217; w[43] = 0.0063000359402577418025981070425; w[44] = 0.0064293911693465917826140832500; w[45] = 0.0065577743625303421548456356354; w[46] = 0.0066851661100262568757892743568; w[47] = 0.0068115471519448109954345674817; w[48] = 0.0069368983812014946719507501243; w[49] = 0.0070612008464055194979848418291; w[50] = 0.0071844357547249896530757997058; w[51] = 0.0073065844747281040972736443146; w[52] = 0.0074276285391999597581348419714; w[53] = 0.0075475496479345294426435656724; w[54] = 0.0076663296705013920315933272426; w[55] = 0.0077839506489867963897419914623; w[56] = 0.0079003948007086443529587296692; w[57] = 0.0080156445209049821352946484008; w[58] = 0.0081296823853955935356080649925; w[59] = 0.0082424911532162924158504385939; w[60] = 0.0083540537692255160718568405530; w[61] = 0.0084643533666828253227353760036; w[62] = 0.0085733732697989214067758505840; w[63] = 0.0086810969962567940901133439612; w[64] = 0.0087875082597036197689825483144; w[65] = 0.0088925909722130327769834298578; w[66] = 0.0089963292467173975949700110383; w[67] = 0.0090987073994097142025303711406; w[68] = 0.0091997099521147934060534414075; w[69] = 0.0092993216346293436285393234867; w[70] = 0.0093975273870306153500305317074; w[71] = 0.0094943123619532541442165010292; w[72] = 0.0095896619268340180657610209655; w[73] = 0.0096835616661240200035669970076; w[74] = 0.0097759973834681605268499842249; w[75] = 0.0098669551038514217128483481814; w[76] = 0.0099564210757116974565448593910; w[77] = 0.0100443817730188408231888789497; w[78] = 0.0101308238973196141129538950955; w[79] = 0.0102157343797482324629939488415; w[80] = 0.0102991003830021970147153502911; w[81] = 0.0103809093032831189224876935085; w[82] = 0.0104611487722022407735015844669; w[83] = 0.0105398066586503673262517188088; w[84] = 0.0106168710706319228563864391054; w[85] = 0.0106923303570628578226139809571; w[86] = 0.0107661731095321330311788312990; w[87] = 0.0108383881640265149842990798832; w[88] = 0.0109089646026184216450603134401; w[89] = 0.0109778917551165634377595759712; w[90] = 0.0110451592006791299277436662993; w[91] = 0.0111107567693892782875426356195; w[92] = 0.0111746745437926853557086684962; w[93] = 0.0112369028603969308303734810332; w[94] = 0.0112974323111324849102690558722; w[95] = 0.0113562537447750795009464486204; w[96] = 0.011413358268329247942299599697; w[97] = 0.011468737248372824084374355981; w[98] = 0.011522382312362197440930930031; w[99] = 0.011574285349898127083439539046; w[100] = 0.011624438513951922901227922331; w[101] = 0.011672834222051808845465154244; w[102] = 0.011719465157429288794653489478; w[103] = 0.011764324270125341726399410909; w[104] = 0.011807404778056278953532930501; w[105] = 0.011848700168039102281222824051; w[106] = 0.011888204196776208064673282076; w[107] = 0.011925910891799288293359117699; w[108] = 0.011961814552372285996633285380; w[109] = 0.011995909750353268455989686823; w[110] = 0.012028191331015087920350431142; w[111] = 0.012058654413824705751531083631; w[112] = 0.012087294393181062176578184854; w[113] = 0.012114106939111380091025793650; w[114] = 0.012139087997925797641334635250; w[115] = 0.012162233792830230614908682534; w[116] = 0.012183540824497371981177306326; w[117] = 0.012203005871595742256331865516; w[118] = 0.012220625991276710706457005806; w[119] = 0.012236398519619413758040249691; w[120] = 0.012250321072033503350218104906; w[121] = 0.012262391543619664338660618398; w[122] = 0.012272608109487846445745237751; w[123] = 0.012280969225033162644659793962; w[124] = 0.012287473626169412265336919908; w[125] = 0.012292120329520193516690694701; w[126] = 0.012294908632567576531532225710; w[127] = 0.01229583811375831445681490730; w[128] = 0.012294908632567576531532225710; w[129] = 0.012292120329520193516690694701; w[130] = 0.012287473626169412265336919908; w[131] = 0.012280969225033162644659793962; w[132] = 0.012272608109487846445745237751; w[133] = 0.012262391543619664338660618398; w[134] = 0.012250321072033503350218104906; w[135] = 0.012236398519619413758040249691; w[136] = 0.012220625991276710706457005806; w[137] = 0.012203005871595742256331865516; w[138] = 0.012183540824497371981177306326; w[139] = 0.012162233792830230614908682534; w[140] = 0.012139087997925797641334635250; w[141] = 0.012114106939111380091025793650; w[142] = 0.012087294393181062176578184854; w[143] = 0.012058654413824705751531083631; w[144] = 0.012028191331015087920350431142; w[145] = 0.011995909750353268455989686823; w[146] = 0.011961814552372285996633285380; w[147] = 0.011925910891799288293359117699; w[148] = 0.011888204196776208064673282076; w[149] = 0.011848700168039102281222824051; w[150] = 0.011807404778056278953532930501; w[151] = 0.011764324270125341726399410909; w[152] = 0.011719465157429288794653489478; w[153] = 0.011672834222051808845465154244; w[154] = 0.011624438513951922901227922331; w[155] = 0.011574285349898127083439539046; w[156] = 0.011522382312362197440930930031; w[157] = 0.011468737248372824084374355981; w[158] = 0.011413358268329247942299599697; w[159] = 0.0113562537447750795009464486204; w[160] = 0.0112974323111324849102690558722; w[161] = 0.0112369028603969308303734810332; w[162] = 0.0111746745437926853557086684962; w[163] = 0.0111107567693892782875426356195; w[164] = 0.0110451592006791299277436662993; w[165] = 0.0109778917551165634377595759712; w[166] = 0.0109089646026184216450603134401; w[167] = 0.0108383881640265149842990798832; w[168] = 0.0107661731095321330311788312990; w[169] = 0.0106923303570628578226139809571; w[170] = 0.0106168710706319228563864391054; w[171] = 0.0105398066586503673262517188088; w[172] = 0.0104611487722022407735015844669; w[173] = 0.0103809093032831189224876935085; w[174] = 0.0102991003830021970147153502911; w[175] = 0.0102157343797482324629939488415; w[176] = 0.0101308238973196141129538950955; w[177] = 0.0100443817730188408231888789497; w[178] = 0.0099564210757116974565448593910; w[179] = 0.0098669551038514217128483481814; w[180] = 0.0097759973834681605268499842249; w[181] = 0.0096835616661240200035669970076; w[182] = 0.0095896619268340180657610209655; w[183] = 0.0094943123619532541442165010292; w[184] = 0.0093975273870306153500305317074; w[185] = 0.0092993216346293436285393234867; w[186] = 0.0091997099521147934060534414075; w[187] = 0.0090987073994097142025303711406; w[188] = 0.0089963292467173975949700110383; w[189] = 0.0088925909722130327769834298578; w[190] = 0.0087875082597036197689825483144; w[191] = 0.0086810969962567940901133439612; w[192] = 0.0085733732697989214067758505840; w[193] = 0.0084643533666828253227353760036; w[194] = 0.0083540537692255160718568405530; w[195] = 0.0082424911532162924158504385939; w[196] = 0.0081296823853955935356080649925; w[197] = 0.0080156445209049821352946484008; w[198] = 0.0079003948007086443529587296692; w[199] = 0.0077839506489867963897419914623; w[200] = 0.0076663296705013920315933272426; w[201] = 0.0075475496479345294426435656724; w[202] = 0.0074276285391999597581348419714; w[203] = 0.0073065844747281040972736443146; w[204] = 0.0071844357547249896530757997058; w[205] = 0.0070612008464055194979848418291; w[206] = 0.0069368983812014946719507501243; w[207] = 0.0068115471519448109954345674817; w[208] = 0.0066851661100262568757892743568; w[209] = 0.0065577743625303421548456356354; w[210] = 0.0064293911693465917826140832500; w[211] = 0.0063000359402577418025981070425; w[212] = 0.0061697282320052788060812561217; w[213] = 0.0060384877453327676663371666884; w[214] = 0.0059063343220074160130475409466; w[215] = 0.0057732879418203275712033691864; w[216] = 0.0056393687195659001929970994675; w[217] = 0.0055045969020008281904902120813; w[218] = 0.0053689928647831724787741258653; w[219] = 0.0052325771093919661294970523234; w[220] = 0.0050953702600278273039420404117; w[221] = 0.0049573930604950563104281084148; w[222] = 0.0048186663710656988918572043815; w[223] = 0.0046792111653260640506279893190; w[224] = 0.0045390485270061921259394035112; w[225] = 0.0043981996467927779838546384780; w[226] = 0.0042566858191260658425395494472; w[227] = 0.0041145284389812475901826468094; w[228] = 0.0039717489986349171988699773906; w[229] = 0.0038283690844171626400743524999; w[230] = 0.0036844103734499176530742235517; w[231] = 0.0035398946303722552150296713510; w[232] = 0.0033948437040533928255056951665; w[233] = 0.0032492795242943133198690930777; w[234] = 0.0031032240985191112621977893133; w[235] = 0.0029566995084575002760043344138; w[236] = 0.0028097279068204407457332299361; w[237] = 0.0026623315139717112732749157331; w[238] = 0.0025145326145997073931298921370; w[239] = 0.0023663535543962867157201855305; w[240] = 0.0022178167367540171700373764020; w[241] = 0.0020689446195015801533643667413; w[242] = 0.0019197597117132050055085980675; w[243] = 0.0017702845706603213070421243905; w[244] = 0.0016205417990415653896921100325; w[245] = 0.0014705540427783843160097204304; w[246] = 0.0013203439900221692090523602144; w[247] = 0.0011699343729388079886897709773; w[248] = 0.00101934797642732530281229369360; w[249] = 0.00086860766611945667949717690640; w[250] = 0.00071773647800611087798371518325; w[251] = 0.00056675794564824918946626058353; w[252] = 0.00041569762526823913616284210066; w[253] = 0.00026459387119083065532790838855; w[254] = 0.00011367361999142272115645954414; } else if ( n == 256 ) { x[0] = -0.999956050018992230734801; x[1] = -0.999768437409263186104879; x[2] = -0.999430937466261408240854; x[3] = -0.998943525843408856555026; x[4] = -0.998306266473006444055500; x[5] = -0.997519252756720827563409; x[6] = -0.996582602023381540430504; x[7] = -0.995496454481096356592647; x[8] = -0.994260972922409664962878; x[9] = -0.992876342608822117143534; x[10] = -0.991342771207583086922189; x[11] = -0.989660488745065218319244; x[12] = -0.987829747564860608916488; x[13] = -0.985850822286125956479245; x[14] = -0.983724009760315496166686; x[15] = -0.981449629025464405769303; x[16] = -0.979028021257622038824238; x[17] = -0.976459549719234155621011; x[18] = -0.973744599704370405266079; x[19] = -0.970883578480743029320923; x[20] = -0.967876915228489454909004; x[21] = -0.964725060975706430932612; x[22] = -0.961428488530732144006407; x[23] = -0.957987692411178129365790; x[24] = -0.954403188769716241764448; x[25] = -0.950675515316628276363852; x[26] = -0.946805231239127481372052; x[27] = -0.942792917117462443183076; x[28] = -0.938639174837814804981926; x[29] = -0.934344627502003094292477; x[30] = -0.929909919334005641180246; x[31] = -0.925335715583316202872730; x[32] = -0.920622702425146495505047; x[33] = -0.915771586857490384526670; x[34] = -0.910783096595065011890907; x[35] = -0.905657979960144647082682; x[36] = -0.900397005770303544771620; x[37] = -0.895000963223084577441223; x[38] = -0.889470661777610888828677; x[39] = -0.883806931033158284859826; x[40] = -0.878010620604706543986435; x[41] = -0.872082599995488289130046; x[42] = -0.866023758466554519297515; x[43] = -0.859835004903376350696173; x[44] = -0.853517267679502965073036; x[45] = -0.847071494517296207187072; x[46] = -0.840498652345762713895068; x[47] = -0.833799727155504894348444; x[48] = -0.826975723850812514289093; x[49] = -0.820027666098917067403478; x[50] = -0.812956596176431543136410; x[51] = -0.805763574812998623257389; x[52] = -0.798449681032170758782543; x[53] = -0.791016011989545994546707; x[54] = -0.783463682808183820750670; x[55] = -0.775793826411325739132053; x[56] = -0.768007593352445635975891; x[57] = -0.760106151642655454941907; x[58] = -0.752090686575492059587530; x[59] = -0.743962400549111568455683; x[60] = -0.735722512885917834620373; x[61] = -0.727372259649652126586894; x[62] = -0.718912893459971448372640; x[63] = -0.710345683304543313394566; x[64] = -0.701671914348685159406084; x[65] = -0.692892887742576960105342; x[66] = -0.684009920426075953124877; x[67] = -0.675024344931162763855919; x[68] = -0.665937509182048559906408; x[69] = -0.656750776292973221887500; x[70] = -0.647465524363724862617016; x[71] = -0.638083146272911368668689; x[72] = -0.628605049469014975432210; x[73] = -0.619032655759261219430968; x[74] = -0.609367401096333939522311; x[75] = -0.599610735362968321730388; x[76] = -0.589764122154454300785786; x[77] = -0.579829038559082944921832; x[78] = -0.569806974936568759057668; x[79] = -0.559699434694481145136907; x[80] = -0.549507934062718557042427; x[81] = -0.539234001866059181127936; x[82] = -0.528879179294822261951476; x[83] = -0.518445019673674476221662; x[84] = -0.507933088228616036231925; x[85] = -0.497344961852181477119512; x[86] = -0.486682228866890350103621; x[87] = -0.475946488786983306390738; x[88] = -0.465139352078479313645570; x[89] = -0.454262439917589998774455; x[90] = -0.443317383947527357216926; x[91] = -0.432305826033741309953441; x[92] = -0.421229418017623824976812; x[93] = -0.410089821468716550006434; x[94] = -0.398888707435459127713463; x[95] = -0.387627756194515583637985; x[96] = -0.376308656998716390283056; x[97] = -0.364933107823654018533465; x[98] = -0.353502815112969989537790; x[99] = -0.342019493522371636480730; x[100] = -0.330484865662416976229187; x[101] = -0.318900661840106275631683; x[102] = -0.307268619799319076258610; x[103] = -0.295590484460135614563787; x[104] = -0.283868007657081741799766; x[105] = -0.272102947876336609505245; x[106] = -0.260297069991942541978561; x[107] = -0.248452145001056666833243; x[108] = -0.236569949758284018477508; x[109] = -0.224652266709131967147878; x[110] = -0.212700883622625957937040; x[111] = -0.200717593323126670068001; x[112] = -0.188704193421388826461504; x[113] = -0.176662486044901997403722; x[114] = -0.164594277567553849829285; x[115] = -0.152501378338656395374607; x[116] = -0.140385602411375885913025; x[117] = -0.128248767270607094742050; x[118] = -0.116092693560332804940735; x[119] = -0.103919204810509403639197; x[120] = -0.091730127163519552031146; x[121] = -0.079527289100232965903227; x[122] = -0.067312521165716400242290; x[123] = -0.055087655694633984104561; x[124] = -0.042854526536379098381242; x[125] = -0.030614968779979029366279; x[126] = -0.018370818478813665117926; x[127] = -0.006123912375189529501170; x[128] = 0.006123912375189529501170; x[129] = 0.018370818478813665117926; x[130] = 0.030614968779979029366279; x[131] = 0.042854526536379098381242; x[132] = 0.055087655694633984104561; x[133] = 0.067312521165716400242290; x[134] = 0.079527289100232965903227; x[135] = 0.091730127163519552031146; x[136] = 0.103919204810509403639197; x[137] = 0.116092693560332804940735; x[138] = 0.128248767270607094742050; x[139] = 0.140385602411375885913025; x[140] = 0.152501378338656395374607; x[141] = 0.164594277567553849829285; x[142] = 0.176662486044901997403722; x[143] = 0.188704193421388826461504; x[144] = 0.200717593323126670068001; x[145] = 0.212700883622625957937040; x[146] = 0.224652266709131967147878; x[147] = 0.236569949758284018477508; x[148] = 0.248452145001056666833243; x[149] = 0.260297069991942541978561; x[150] = 0.272102947876336609505245; x[151] = 0.283868007657081741799766; x[152] = 0.295590484460135614563787; x[153] = 0.307268619799319076258610; x[154] = 0.318900661840106275631683; x[155] = 0.330484865662416976229187; x[156] = 0.342019493522371636480730; x[157] = 0.353502815112969989537790; x[158] = 0.364933107823654018533465; x[159] = 0.376308656998716390283056; x[160] = 0.387627756194515583637985; x[161] = 0.398888707435459127713463; x[162] = 0.410089821468716550006434; x[163] = 0.421229418017623824976812; x[164] = 0.432305826033741309953441; x[165] = 0.443317383947527357216926; x[166] = 0.454262439917589998774455; x[167] = 0.465139352078479313645570; x[168] = 0.475946488786983306390738; x[169] = 0.486682228866890350103621; x[170] = 0.497344961852181477119512; x[171] = 0.507933088228616036231925; x[172] = 0.518445019673674476221662; x[173] = 0.528879179294822261951476; x[174] = 0.539234001866059181127936; x[175] = 0.549507934062718557042427; x[176] = 0.559699434694481145136907; x[177] = 0.569806974936568759057668; x[178] = 0.579829038559082944921832; x[179] = 0.589764122154454300785786; x[180] = 0.599610735362968321730388; x[181] = 0.609367401096333939522311; x[182] = 0.619032655759261219430968; x[183] = 0.628605049469014975432210; x[184] = 0.638083146272911368668689; x[185] = 0.647465524363724862617016; x[186] = 0.656750776292973221887500; x[187] = 0.665937509182048559906408; x[188] = 0.675024344931162763855919; x[189] = 0.684009920426075953124877; x[190] = 0.692892887742576960105342; x[191] = 0.701671914348685159406084; x[192] = 0.710345683304543313394566; x[193] = 0.718912893459971448372640; x[194] = 0.727372259649652126586894; x[195] = 0.735722512885917834620373; x[196] = 0.743962400549111568455683; x[197] = 0.752090686575492059587530; x[198] = 0.760106151642655454941907; x[199] = 0.768007593352445635975891; x[200] = 0.775793826411325739132053; x[201] = 0.783463682808183820750670; x[202] = 0.791016011989545994546707; x[203] = 0.798449681032170758782543; x[204] = 0.805763574812998623257389; x[205] = 0.812956596176431543136410; x[206] = 0.820027666098917067403478; x[207] = 0.826975723850812514289093; x[208] = 0.833799727155504894348444; x[209] = 0.840498652345762713895068; x[210] = 0.847071494517296207187072; x[211] = 0.853517267679502965073036; x[212] = 0.859835004903376350696173; x[213] = 0.866023758466554519297515; x[214] = 0.872082599995488289130046; x[215] = 0.878010620604706543986435; x[216] = 0.883806931033158284859826; x[217] = 0.889470661777610888828677; x[218] = 0.895000963223084577441223; x[219] = 0.900397005770303544771620; x[220] = 0.905657979960144647082682; x[221] = 0.910783096595065011890907; x[222] = 0.915771586857490384526670; x[223] = 0.920622702425146495505047; x[224] = 0.925335715583316202872730; x[225] = 0.929909919334005641180246; x[226] = 0.934344627502003094292477; x[227] = 0.938639174837814804981926; x[228] = 0.942792917117462443183076; x[229] = 0.946805231239127481372052; x[230] = 0.950675515316628276363852; x[231] = 0.954403188769716241764448; x[232] = 0.957987692411178129365790; x[233] = 0.961428488530732144006407; x[234] = 0.964725060975706430932612; x[235] = 0.967876915228489454909004; x[236] = 0.970883578480743029320923; x[237] = 0.973744599704370405266079; x[238] = 0.976459549719234155621011; x[239] = 0.979028021257622038824238; x[240] = 0.981449629025464405769303; x[241] = 0.983724009760315496166686; x[242] = 0.985850822286125956479245; x[243] = 0.987829747564860608916488; x[244] = 0.989660488745065218319244; x[245] = 0.991342771207583086922189; x[246] = 0.992876342608822117143534; x[247] = 0.994260972922409664962878; x[248] = 0.995496454481096356592647; x[249] = 0.996582602023381540430504; x[250] = 0.997519252756720827563409; x[251] = 0.998306266473006444055500; x[252] = 0.998943525843408856555026; x[253] = 0.999430937466261408240854; x[254] = 0.999768437409263186104879; x[255] = 0.999956050018992230734801; w[0] = 0.00011278901782227217551253887725; w[1] = 0.00026253494429644590628745756250; w[2] = 0.00041246325442617632843218583774; w[3] = 0.00056234895403140980281523674759; w[4] = 0.0007121541634733206669089891511; w[5] = 0.0008618537014200890378140934163; w[6] = 0.0010114243932084404526058128414; w[7] = 0.0011608435575677247239705981135; w[8] = 0.0013100886819025044578316804271; w[9] = 0.0014591373333107332010883864996; w[10] = 0.0016079671307493272424499395690; w[11] = 0.0017565557363307299936069145295; w[12] = 0.0019048808534997184044191411746; w[13] = 0.0020529202279661431745487818492; w[14] = 0.0022006516498399104996848834189; w[15] = 0.0023480529563273120170064609087; w[16] = 0.0024951020347037068508395354372; w[17] = 0.0026417768254274905641208292516; w[18] = 0.0027880553253277068805747610763; w[19] = 0.0029339155908297166460123254142; w[20] = 0.0030793357411993375832053528316; w[21] = 0.0032242939617941981570107134269; w[22] = 0.0033687685073155510120191062489; w[23] = 0.0035127377050563073309710549844; w[24] = 0.0036561799581425021693892413052; w[25] = 0.0037990737487662579981170192082; w[26] = 0.0039413976414088336277290349840; w[27] = 0.0040831302860526684085997759212; w[28] = 0.0042242504213815362723565049060; w[29] = 0.0043647368779680566815684200621; w[30] = 0.0045045685814478970686417923159; w[31] = 0.0046437245556800603139790923525; w[32] = 0.0047821839258926913729317340448; w[33] = 0.0049199259218138656695587765655; w[34] = 0.0050569298807868423875578160762; w[35] = 0.0051931752508692809303287536296; w[36] = 0.0053286415939159303170811114788; w[37] = 0.0054633085886443102775705318566; w[38] = 0.0055971560336829100775514452572; w[39] = 0.005730163850601437177384417555; w[40] = 0.005862312086922653060661598801; w[41] = 0.005993580919115338221127696870; w[42] = 0.006123950655567932542389081187; w[43] = 0.006253401739542401272063645975; w[44] = 0.006381914752107880570375164275; w[45] = 0.006509470415053660267809899951; w[46] = 0.006636049593781065044590038355; w[47] = 0.006761633300173798780927861108; w[48] = 0.006886202695446320346713323775; w[49] = 0.007009739092969822621234436194; w[50] = 0.007132223961075390071672422986; w[51] = 0.007253638925833913783829137214; w[52] = 0.007373965773812346437572440695; w[53] = 0.007493186454805883358599761133; w[54] = 0.007611283084545659461618719618; w[55] = 0.007728237947381555631110194958; w[56] = 0.007844033498939711866810316151; w[57] = 0.007958652368754348353613161227; w[58] = 0.008072077362873499500946974804; w[59] = 0.008184291466438269935619761004; w[60] = 0.008295277846235225425171412553; w[61] = 0.008405019853221535756180301698; w[62] = 0.008513501025022490693838354790; w[63] = 0.008620705088401014305368838410; w[64] = 0.008726615961698807140336632217; w[65] = 0.008831217757248750025318272685; w[66] = 0.008934494783758207548408417085; w[67] = 0.009036431548662873680227775572; w[68] = 0.009137012760450806402000472219; w[69] = 0.009236223330956302687378716714; w[70] = 0.009334048377623269712466014486; w[71] = 0.009430473225737752747352764482; w[72] = 0.009525483410629284811829685754; w[73] = 0.009619064679840727857162164401; w[74] = 0.009711202995266279964249670496; w[75] = 0.009801884535257327825498800250; w[76] = 0.009891095696695828602630683809; w[77] = 0.009978823097034910124733949495; w[78] = 0.010065053576306383309460978930; w[79] = 0.010149774199094865654634066042; w[80] = 0.010232972256478219656954857160; w[81] = 0.010314635267934015068260713997; w[82] = 0.010394750983211728997101725205; w[83] = 0.010473307384170403003569566927; w[84] = 0.010550292686581481517533575536; w[85] = 0.010625695341896561133961681801; w[86] = 0.010699504038979785603048200583; w[87] = 0.010771707705804626636653631927; w[88] = 0.010842295511114795995293477058; w[89] = 0.010911256866049039700796847788; w[90] = 0.010978581425729570637988203448; w[91] = 0.011044259090813901263517571044; w[92] = 0.011108280009009843630460815451; w[93] = 0.011170634576553449462710881938; w[94] = 0.011231313439649668572656802083; w[95] = 0.011290307495875509508367594121; w[96] = 0.011347607895545491941625714297; w[97] = 0.011403206043039185964847059552; w[98] = 0.011457093598090639152334392298; w[99] = 0.011509262477039497958586392439; w[100] = 0.011559704854043635772668656950; w[101] = 0.011608413162253105722084706677; w[102] = 0.011655380094945242121298939730; w[103] = 0.011700598606620740288189823359; w[104] = 0.011744061914060550305376732759; w[105] = 0.011785763497343426181690117627; w[106] = 0.011825697100823977771160737958; w[107] = 0.011863856734071078731904572908; w[108] = 0.011900236672766489754287204237; w[109] = 0.011934831459563562255873201696; w[110] = 0.011967635904905893729007282670; w[111] = 0.011998645087805811934536710071; w[112] = 0.012027854356582571161267533498; w[113] = 0.012055259329560149814347085327; w[114] = 0.012080855895724544655975183976; w[115] = 0.012104640215340463097757829736; w[116] = 0.012126608720527321034718492205; w[117] = 0.012146758115794459815559837664; w[118] = 0.012165085378535502061307291839; w[119] = 0.012181587759481772174047585032; w[120] = 0.012196262783114713518180974196; w[121] = 0.012209108248037240407514094371; w[122] = 0.012220122227303969191708737227; w[123] = 0.012229303068710278904146266083; w[124] = 0.012236649395040158109242574767; w[125] = 0.012242160104272800769728083260; w[126] = 0.012245834369747920142463857550; w[127] = 0.01224767164028975590407032649; w[128] = 0.01224767164028975590407032649; w[129] = 0.012245834369747920142463857550; w[130] = 0.012242160104272800769728083260; w[131] = 0.012236649395040158109242574767; w[132] = 0.012229303068710278904146266083; w[133] = 0.012220122227303969191708737227; w[134] = 0.012209108248037240407514094371; w[135] = 0.012196262783114713518180974196; w[136] = 0.012181587759481772174047585032; w[137] = 0.012165085378535502061307291839; w[138] = 0.012146758115794459815559837664; w[139] = 0.012126608720527321034718492205; w[140] = 0.012104640215340463097757829736; w[141] = 0.012080855895724544655975183976; w[142] = 0.012055259329560149814347085327; w[143] = 0.012027854356582571161267533498; w[144] = 0.011998645087805811934536710071; w[145] = 0.011967635904905893729007282670; w[146] = 0.011934831459563562255873201696; w[147] = 0.011900236672766489754287204237; w[148] = 0.011863856734071078731904572908; w[149] = 0.011825697100823977771160737958; w[150] = 0.011785763497343426181690117627; w[151] = 0.011744061914060550305376732759; w[152] = 0.011700598606620740288189823359; w[153] = 0.011655380094945242121298939730; w[154] = 0.011608413162253105722084706677; w[155] = 0.011559704854043635772668656950; w[156] = 0.011509262477039497958586392439; w[157] = 0.011457093598090639152334392298; w[158] = 0.011403206043039185964847059552; w[159] = 0.011347607895545491941625714297; w[160] = 0.011290307495875509508367594121; w[161] = 0.011231313439649668572656802083; w[162] = 0.011170634576553449462710881938; w[163] = 0.011108280009009843630460815451; w[164] = 0.011044259090813901263517571044; w[165] = 0.010978581425729570637988203448; w[166] = 0.010911256866049039700796847788; w[167] = 0.010842295511114795995293477058; w[168] = 0.010771707705804626636653631927; w[169] = 0.010699504038979785603048200583; w[170] = 0.010625695341896561133961681801; w[171] = 0.010550292686581481517533575536; w[172] = 0.010473307384170403003569566927; w[173] = 0.010394750983211728997101725205; w[174] = 0.010314635267934015068260713997; w[175] = 0.010232972256478219656954857160; w[176] = 0.010149774199094865654634066042; w[177] = 0.010065053576306383309460978930; w[178] = 0.009978823097034910124733949495; w[179] = 0.009891095696695828602630683809; w[180] = 0.009801884535257327825498800250; w[181] = 0.009711202995266279964249670496; w[182] = 0.009619064679840727857162164401; w[183] = 0.009525483410629284811829685754; w[184] = 0.009430473225737752747352764482; w[185] = 0.009334048377623269712466014486; w[186] = 0.009236223330956302687378716714; w[187] = 0.009137012760450806402000472219; w[188] = 0.009036431548662873680227775572; w[189] = 0.008934494783758207548408417085; w[190] = 0.008831217757248750025318272685; w[191] = 0.008726615961698807140336632217; w[192] = 0.008620705088401014305368838410; w[193] = 0.008513501025022490693838354790; w[194] = 0.008405019853221535756180301698; w[195] = 0.008295277846235225425171412553; w[196] = 0.008184291466438269935619761004; w[197] = 0.008072077362873499500946974804; w[198] = 0.007958652368754348353613161227; w[199] = 0.007844033498939711866810316151; w[200] = 0.007728237947381555631110194958; w[201] = 0.007611283084545659461618719618; w[202] = 0.007493186454805883358599761133; w[203] = 0.007373965773812346437572440695; w[204] = 0.007253638925833913783829137214; w[205] = 0.007132223961075390071672422986; w[206] = 0.007009739092969822621234436194; w[207] = 0.006886202695446320346713323775; w[208] = 0.006761633300173798780927861108; w[209] = 0.006636049593781065044590038355; w[210] = 0.006509470415053660267809899951; w[211] = 0.006381914752107880570375164275; w[212] = 0.006253401739542401272063645975; w[213] = 0.006123950655567932542389081187; w[214] = 0.005993580919115338221127696870; w[215] = 0.005862312086922653060661598801; w[216] = 0.005730163850601437177384417555; w[217] = 0.0055971560336829100775514452572; w[218] = 0.0054633085886443102775705318566; w[219] = 0.0053286415939159303170811114788; w[220] = 0.0051931752508692809303287536296; w[221] = 0.0050569298807868423875578160762; w[222] = 0.0049199259218138656695587765655; w[223] = 0.0047821839258926913729317340448; w[224] = 0.0046437245556800603139790923525; w[225] = 0.0045045685814478970686417923159; w[226] = 0.0043647368779680566815684200621; w[227] = 0.0042242504213815362723565049060; w[228] = 0.0040831302860526684085997759212; w[229] = 0.0039413976414088336277290349840; w[230] = 0.0037990737487662579981170192082; w[231] = 0.0036561799581425021693892413052; w[232] = 0.0035127377050563073309710549844; w[233] = 0.0033687685073155510120191062489; w[234] = 0.0032242939617941981570107134269; w[235] = 0.0030793357411993375832053528316; w[236] = 0.0029339155908297166460123254142; w[237] = 0.0027880553253277068805747610763; w[238] = 0.0026417768254274905641208292516; w[239] = 0.0024951020347037068508395354372; w[240] = 0.0023480529563273120170064609087; w[241] = 0.0022006516498399104996848834189; w[242] = 0.0020529202279661431745487818492; w[243] = 0.0019048808534997184044191411746; w[244] = 0.0017565557363307299936069145295; w[245] = 0.0016079671307493272424499395690; w[246] = 0.0014591373333107332010883864996; w[247] = 0.0013100886819025044578316804271; w[248] = 0.0011608435575677247239705981135; w[249] = 0.0010114243932084404526058128414; w[250] = 0.0008618537014200890378140934163; w[251] = 0.0007121541634733206669089891511; w[252] = 0.00056234895403140980281523674759; w[253] = 0.00041246325442617632843218583774; w[254] = 0.00026253494429644590628745756250; w[255] = 0.00011278901782227217551253887725; } else if ( n == 257 ) { x[0] = -0.999956390712330402472857; x[1] = -0.999770232390338019056053; x[2] = -0.999435348366365078441838; x[3] = -0.998951714093223210129834; x[4] = -0.998319392445383847808766; x[5] = -0.997538475365520218731818; x[6] = -0.996609078365487004512326; x[7] = -0.995531339486830143483750; x[8] = -0.994305419008553630362377; x[9] = -0.992931499332908653172844; x[10] = -0.991409784923101705201254; x[11] = -0.989740502257507526030375; x[12] = -0.987923899788618253106809; x[13] = -0.985960247902290665366669; x[14] = -0.983849838875444644048531; x[15] = -0.981592986831381877693095; x[16] = -0.979190027692327124191591; x[17] = -0.976641319128992592610888; x[18] = -0.973947240507062326750976; x[19] = -0.971108192830542793021113; x[20] = -0.968124598681952354372943; x[21] = -0.964996902159337170373447; x[22] = -0.961725568810109767190665; x[23] = -0.958311085561711847074814; x[24] = -0.954753960649106318830855; x[25] = -0.951054723539105826691801; x[26] = -0.947213924851546682950881; x[27] = -0.943232136277318328151464; x[28] = -0.939109950493259404355123; x[29] = -0.934847981073932324370129; x[30] = -0.930446862400288909805510; x[31] = -0.925907249565240289235888; x[32] = -0.921229818276144817520964; x[33] = -0.916415264754228313295468; x[34] = -0.911464305630951423630955; x[35] = -0.906377677841339419411308; x[36] = -0.901156138514290206476301; x[37] = -0.895800464859876809085345; x[38] = -0.890311454053661045810287; x[39] = -0.884689923118035575018750; x[40] = -0.878936708800611938658765; x[41] = -0.873052667449672679799858; x[42] = -0.867038674886706051812473; x[43] = -0.860895626276042275514686; x[44] = -0.854624435991610735314055; x[45] = -0.848226037480837936478636; x[46] = -0.841701383125706473284556; x[47] = -0.835051444100995681967937; x[48] = -0.828277210229725073186687; x[49] = -0.821379689835822056081139; x[50] = -0.814359909594035880004229; x[51] = -0.807218914377120130552073; x[52] = -0.799957767100306523636066; x[53] = -0.792577548563093144962574; x[54] = -0.785079357288370682385816; x[55] = -0.777464309358910595129671; x[56] = -0.769733538251239556788216; x[57] = -0.761888194666924898264210; x[58] = -0.753929446361296162339238; x[59] = -0.745858477969628263337895; x[60] = -0.737676490830812123299244; x[61] = -0.729384702808539030149808; x[62] = -0.720984348110025333531072; x[63] = -0.712476677102304460118510; x[64] = -0.703862956126113592426171; x[65] = -0.695144467307402713168813; x[66] = -0.686322508366494071200553; x[67] = -0.677398392424920474813593; x[68] = -0.668373447809971163711735; x[69] = -0.659249017856974352220492; x[70] = -0.650026460709345873208532; x[71] = -0.640707149116433684724434; x[72] = -0.631292470229188329449219; x[73] = -0.621783825393689760680446; x[74] = -0.612182629942561267650033; x[75] = -0.602490312984301547488097; x[76] = -0.592708317190566281032495; x[77] = -0.582838098581430874902446; x[78] = -0.572881126308666332759406; x[79] = -0.562838882437060514424546; x[80] = -0.552712861723817332466074; x[81] = -0.542504571396066721967792; x[82] = -0.532215530926518500400434; x[83] = -0.521847271807293510797499; x[84] = -0.511401337321965712746629; x[85] = -0.500879282315849152005553; x[86] = -0.490282672964564000798817; x[87] = -0.479613086540916117008992; x[88] = -0.468872111180124821505728; x[89] = -0.458061345643433838720630; x[90] = -0.447182399080140586238810; x[91] = -0.436236890788079234603398; x[92] = -0.425226449972593188682213; x[93] = -0.414152715504032866791986; x[94] = -0.403017335673814873281489; x[95] = -0.391821967949078874408131; x[96] = -0.380568278725978696070941; x[97] = -0.369257943081644365255611; x[98] = -0.357892644524852014873858; x[99] = -0.346474074745438764010632; x[100] = -0.335003933362499872399782; x[101] = -0.323483927671405649204085; x[102] = -0.311915772389675771851948; x[103] = -0.300301189401748840754520; x[104] = -0.288641907502685160168097; x[105] = -0.276939662140840894253032; x[106] = -0.265196195159551900488370; x[107] = -0.253413254537865690008131; x[108] = -0.241592594130360106108882; x[109] = -0.229735973406087448117604; x[110] = -0.217845157186682897983880; x[111] = -0.205921915383676231351599; x[112] = -0.193968022735045913454182; x[113] = -0.181985258541054792946197; x[114] = -0.169975406399406713716337; x[115] = -0.157940253939763465806087; x[116] = -0.145881592557661591770148; x[117] = -0.133801217147868654144405; x[118] = -0.121700925837218653121859; x[119] = -0.109582519716966361063898; x[120] = -0.097447802574700412082119; x[121] = -0.085298580625855050603929; x[122] = -0.073136662244860502573600; x[123] = -0.060963857695971986730406; x[124] = -0.048781978863817431238958; x[125] = -0.036592838983704002816750; x[126] = -0.024398252371723591403953; x[127] = -0.012200034154697423345412; x[128] = 0.000000000000000000000000; x[129] = 0.012200034154697423345412; x[130] = 0.024398252371723591403953; x[131] = 0.036592838983704002816750; x[132] = 0.048781978863817431238958; x[133] = 0.060963857695971986730406; x[134] = 0.073136662244860502573600; x[135] = 0.085298580625855050603929; x[136] = 0.097447802574700412082119; x[137] = 0.109582519716966361063898; x[138] = 0.121700925837218653121859; x[139] = 0.133801217147868654144405; x[140] = 0.145881592557661591770148; x[141] = 0.157940253939763465806087; x[142] = 0.169975406399406713716337; x[143] = 0.181985258541054792946197; x[144] = 0.193968022735045913454182; x[145] = 0.205921915383676231351599; x[146] = 0.217845157186682897983880; x[147] = 0.229735973406087448117604; x[148] = 0.241592594130360106108882; x[149] = 0.253413254537865690008131; x[150] = 0.265196195159551900488370; x[151] = 0.276939662140840894253032; x[152] = 0.288641907502685160168097; x[153] = 0.300301189401748840754520; x[154] = 0.311915772389675771851948; x[155] = 0.323483927671405649204085; x[156] = 0.335003933362499872399782; x[157] = 0.346474074745438764010632; x[158] = 0.357892644524852014873858; x[159] = 0.369257943081644365255611; x[160] = 0.380568278725978696070941; x[161] = 0.391821967949078874408131; x[162] = 0.403017335673814873281489; x[163] = 0.414152715504032866791986; x[164] = 0.425226449972593188682213; x[165] = 0.436236890788079234603398; x[166] = 0.447182399080140586238810; x[167] = 0.458061345643433838720630; x[168] = 0.468872111180124821505728; x[169] = 0.479613086540916117008992; x[170] = 0.490282672964564000798817; x[171] = 0.500879282315849152005553; x[172] = 0.511401337321965712746629; x[173] = 0.521847271807293510797499; x[174] = 0.532215530926518500400434; x[175] = 0.542504571396066721967792; x[176] = 0.552712861723817332466074; x[177] = 0.562838882437060514424546; x[178] = 0.572881126308666332759406; x[179] = 0.582838098581430874902446; x[180] = 0.592708317190566281032495; x[181] = 0.602490312984301547488097; x[182] = 0.612182629942561267650033; x[183] = 0.621783825393689760680446; x[184] = 0.631292470229188329449219; x[185] = 0.640707149116433684724434; x[186] = 0.650026460709345873208532; x[187] = 0.659249017856974352220492; x[188] = 0.668373447809971163711735; x[189] = 0.677398392424920474813593; x[190] = 0.686322508366494071200553; x[191] = 0.695144467307402713168813; x[192] = 0.703862956126113592426171; x[193] = 0.712476677102304460118510; x[194] = 0.720984348110025333531072; x[195] = 0.729384702808539030149808; x[196] = 0.737676490830812123299244; x[197] = 0.745858477969628263337895; x[198] = 0.753929446361296162339238; x[199] = 0.761888194666924898264210; x[200] = 0.769733538251239556788216; x[201] = 0.777464309358910595129671; x[202] = 0.785079357288370682385816; x[203] = 0.792577548563093144962574; x[204] = 0.799957767100306523636066; x[205] = 0.807218914377120130552073; x[206] = 0.814359909594035880004229; x[207] = 0.821379689835822056081139; x[208] = 0.828277210229725073186687; x[209] = 0.835051444100995681967937; x[210] = 0.841701383125706473284556; x[211] = 0.848226037480837936478636; x[212] = 0.854624435991610735314055; x[213] = 0.860895626276042275514686; x[214] = 0.867038674886706051812473; x[215] = 0.873052667449672679799858; x[216] = 0.878936708800611938658765; x[217] = 0.884689923118035575018750; x[218] = 0.890311454053661045810287; x[219] = 0.895800464859876809085345; x[220] = 0.901156138514290206476301; x[221] = 0.906377677841339419411308; x[222] = 0.911464305630951423630955; x[223] = 0.916415264754228313295468; x[224] = 0.921229818276144817520964; x[225] = 0.925907249565240289235888; x[226] = 0.930446862400288909805510; x[227] = 0.934847981073932324370129; x[228] = 0.939109950493259404355123; x[229] = 0.943232136277318328151464; x[230] = 0.947213924851546682950881; x[231] = 0.951054723539105826691801; x[232] = 0.954753960649106318830855; x[233] = 0.958311085561711847074814; x[234] = 0.961725568810109767190665; x[235] = 0.964996902159337170373447; x[236] = 0.968124598681952354372943; x[237] = 0.971108192830542793021113; x[238] = 0.973947240507062326750976; x[239] = 0.976641319128992592610888; x[240] = 0.979190027692327124191591; x[241] = 0.981592986831381877693095; x[242] = 0.983849838875444644048531; x[243] = 0.985960247902290665366669; x[244] = 0.987923899788618253106809; x[245] = 0.989740502257507526030375; x[246] = 0.991409784923101705201254; x[247] = 0.992931499332908653172844; x[248] = 0.994305419008553630362377; x[249] = 0.995531339486830143483750; x[250] = 0.996609078365487004512326; x[251] = 0.997538475365520218731818; x[252] = 0.998319392445383847808766; x[253] = 0.998951714093223210129834; x[254] = 0.999435348366365078441838; x[255] = 0.999770232390338019056053; x[256] = 0.999956390712330402472857; w[0] = 0.00011191470145601756450862287886; w[1] = 0.00026049995580176964436806680831; w[2] = 0.00040926648283531339591138751432; w[3] = 0.00055799120546880640169677292533; w[4] = 0.00070663671051592291949335494247; w[5] = 0.00085517818446696565626595950963; w[6] = 0.00100359280467969441299468763292; w[7] = 0.0011518582377826677880963146741; w[8] = 0.0012999523174235227389668643832; w[9] = 0.0014478529559255120065233994722; w[10] = 0.0015955381166175133369701690235; w[11] = 0.0017429858051468299509941139300; w[12] = 0.0018901740676190104269878470891; w[13] = 0.0020370809914723626741694800322; w[14] = 0.0021836847075455253317921866057; w[15] = 0.0023299633927021828561308282641; w[16] = 0.0024758952727301488651840215879; w[17] = 0.0026214586253808109266552781372; w[18] = 0.0027666317834818283552560256501; w[19] = 0.0029113931380877846359302447381; w[20] = 0.0030557211416493711130936102459; w[21] = 0.0031995943111899437356540290142; w[22] = 0.0033429912314827618499065991316; w[23] = 0.0034858905582247143702551557840; w[24] = 0.0036282710212037760873102463983; w[25] = 0.0037701114274582873548537007645; w[26] = 0.0039113906644266662571543468015; w[27] = 0.0040520877030864825223229951262; w[28] = 0.0041921816010820254766367595011; w[29] = 0.0043316515058396297504806208252; w[30] = 0.0044704766576701092218388764046; w[31] = 0.0046086363928577081326523656522; w[32] = 0.0047461101467350184936945641585; w[33] = 0.0048828774567433411142588306018; w[34] = 0.0050189179654779878773297516544; w[35] = 0.0051542114237180378340642003713; w[36] = 0.0052887376934400710240953933529; w[37] = 0.0054224767508154127788846727083; w[38] = 0.0055554086891904284012033890901; w[39] = 0.0056875137220494140577838938236; w[40] = 0.0058187721859596348346566361185; w[41] = 0.0059491645434980654366600347567; w[42] = 0.0060786713861593931405204596709; w[43] = 0.0062072734372448464599330978665; w[44] = 0.0063349515547314166407936938524; w[45] = 0.0064616867341210426397202932350; w[46] = 0.0065874601112693336961737372300; w[47] = 0.0067122529651934070221351960200; w[48] = 0.0068360467208584215286561508406; w[49] = 0.0069588229519423919043121805236; w[50] = 0.0070805633835788707705149901066; w[51] = 0.0072012498950770900730828552207; w[52] = 0.0073208645226191563361371026044; w[53] = 0.0074393894619338979090297315972; w[54] = 0.0075568070709469658838993300454; w[55] = 0.0076730998724067939537782250476; w[56] = 0.0077882505564860261212726654404; w[57] = 0.0079022419833580248574070864277; w[58] = 0.0080150571857480760504667455353; w[59] = 0.0081266793714589108764118189068; w[60] = 0.0082370919258701685661946145361; w[61] = 0.0083462784144114279413811886655; w[62] = 0.0084542225850084395379670551258; w[63] = 0.0085609083705021941391459209280; w[64] = 0.0086663198910404675908861979240; w[65] = 0.0087704414564414858792445834744; w[66] = 0.0088732575685293586050755892934; w[67] = 0.0089747529234409331997949023068; w[68] = 0.0090749124139037264846862498962; w[69] = 0.0091737211314845944854270065178; w[70] = 0.0092711643688088057725325917169; w[71] = 0.0093672276217491880067391857021; w[72] = 0.0094618965915850218253881576301; w[73] = 0.0095551571871303607110514249099; w[74] = 0.0096469955268314600363329731559; w[75] = 0.0097373979408330030783691793250; w[76] = 0.0098263509730128164423854701706; w[77] = 0.0099138413829847720250916955489; w[78] = 0.0099998561480695773850435626986; w[79] = 0.0100843824652331611676814627839; w[80] = 0.0101674077529923650568895461852; w[81] = 0.0102489196532876585918958554047; w[82] = 0.0103289060333225980974485876288; w[83] = 0.0104073549873697559257355517893; w[84] = 0.0104842548385428511997370260353; w[85] = 0.0105595941405348182788823332058; w[86] = 0.0106333616793215542382761147904; w[87] = 0.0107055464748310917616231511294; w[88] = 0.0107761377825779489945556541150; w[89] = 0.0108451250952624130885928632830; w[90] = 0.0109124981443345193856719616965; w[91] = 0.0109782469015224934483083029166; w[92] = 0.0110423615803254284301924654946; w[93] = 0.0111048326374699756056269264803; w[94] = 0.0111656507743308312328559850485; w[95] = 0.0112248069383148083152535688671; w[96] = 0.0112822923242082872447042603128; w[97] = 0.0113380983754878447625379269120; w[98] = 0.011392216785593866154247619654; w[99] = 0.011444639499166951104119199270; w[100] = 0.011495358713246929174010288914; w[101] = 0.011544366878434306436012137033; w[102] = 0.011591656700013970380783131035; w[103] = 0.011637221139040985841125311445; w[104] = 0.011681053413388320313049670635; w[105] = 0.011723146998756342723302879656; w[106] = 0.011763495629643945382264331878; w[107] = 0.011802093300281144573421477037; w[108] = 0.011838934265523020964443424791; w[109] = 0.011874013041704866779344562066; w[110] = 0.011907324407458412445505183140; w[111] = 0.011938863404489011222535627643; w[112] = 0.011968625338313666131272065445; w[113] = 0.011996605778959789329711050159; w[114] = 0.012022800561624589927558893338; w[115] = 0.012047205787294992091420946532; w[116] = 0.012069817823327991167612855626; w[117] = 0.012090633303991361438266420912; w[118] = 0.012109649130964635027950450318; w[119] = 0.012126862473800277391553601370; w[120] = 0.012142270770344990738801546574; w[121] = 0.012155871727121082685623083829; w[122] = 0.012167663319667843366755737416; w[123] = 0.012177643792842880196606249581; w[124] = 0.012185811661083365425569178819; w[125] = 0.012192165708627157605870499188; w[126] = 0.012196704989693764053654538465; w[127] = 0.012199428828625117371582840212; w[128] = 0.01220033681998614507777289232; w[129] = 0.012199428828625117371582840212; w[130] = 0.012196704989693764053654538465; w[131] = 0.012192165708627157605870499188; w[132] = 0.012185811661083365425569178819; w[133] = 0.012177643792842880196606249581; w[134] = 0.012167663319667843366755737416; w[135] = 0.012155871727121082685623083829; w[136] = 0.012142270770344990738801546574; w[137] = 0.012126862473800277391553601370; w[138] = 0.012109649130964635027950450318; w[139] = 0.012090633303991361438266420912; w[140] = 0.012069817823327991167612855626; w[141] = 0.012047205787294992091420946532; w[142] = 0.012022800561624589927558893338; w[143] = 0.011996605778959789329711050159; w[144] = 0.011968625338313666131272065445; w[145] = 0.011938863404489011222535627643; w[146] = 0.011907324407458412445505183140; w[147] = 0.011874013041704866779344562066; w[148] = 0.011838934265523020964443424791; w[149] = 0.011802093300281144573421477037; w[150] = 0.011763495629643945382264331878; w[151] = 0.011723146998756342723302879656; w[152] = 0.011681053413388320313049670635; w[153] = 0.011637221139040985841125311445; w[154] = 0.011591656700013970380783131035; w[155] = 0.011544366878434306436012137033; w[156] = 0.011495358713246929174010288914; w[157] = 0.011444639499166951104119199270; w[158] = 0.011392216785593866154247619654; w[159] = 0.0113380983754878447625379269120; w[160] = 0.0112822923242082872447042603128; w[161] = 0.0112248069383148083152535688671; w[162] = 0.0111656507743308312328559850485; w[163] = 0.0111048326374699756056269264803; w[164] = 0.0110423615803254284301924654946; w[165] = 0.0109782469015224934483083029166; w[166] = 0.0109124981443345193856719616965; w[167] = 0.0108451250952624130885928632830; w[168] = 0.0107761377825779489945556541150; w[169] = 0.0107055464748310917616231511294; w[170] = 0.0106333616793215542382761147904; w[171] = 0.0105595941405348182788823332058; w[172] = 0.0104842548385428511997370260353; w[173] = 0.0104073549873697559257355517893; w[174] = 0.0103289060333225980974485876288; w[175] = 0.0102489196532876585918958554047; w[176] = 0.0101674077529923650568895461852; w[177] = 0.0100843824652331611676814627839; w[178] = 0.0099998561480695773850435626986; w[179] = 0.0099138413829847720250916955489; w[180] = 0.0098263509730128164423854701706; w[181] = 0.0097373979408330030783691793250; w[182] = 0.0096469955268314600363329731559; w[183] = 0.0095551571871303607110514249099; w[184] = 0.0094618965915850218253881576301; w[185] = 0.0093672276217491880067391857021; w[186] = 0.0092711643688088057725325917169; w[187] = 0.0091737211314845944854270065178; w[188] = 0.0090749124139037264846862498962; w[189] = 0.0089747529234409331997949023068; w[190] = 0.0088732575685293586050755892934; w[191] = 0.0087704414564414858792445834744; w[192] = 0.0086663198910404675908861979240; w[193] = 0.0085609083705021941391459209280; w[194] = 0.0084542225850084395379670551258; w[195] = 0.0083462784144114279413811886655; w[196] = 0.0082370919258701685661946145361; w[197] = 0.0081266793714589108764118189068; w[198] = 0.0080150571857480760504667455353; w[199] = 0.0079022419833580248574070864277; w[200] = 0.0077882505564860261212726654404; w[201] = 0.0076730998724067939537782250476; w[202] = 0.0075568070709469658838993300454; w[203] = 0.0074393894619338979090297315972; w[204] = 0.0073208645226191563361371026044; w[205] = 0.0072012498950770900730828552207; w[206] = 0.0070805633835788707705149901066; w[207] = 0.0069588229519423919043121805236; w[208] = 0.0068360467208584215286561508406; w[209] = 0.0067122529651934070221351960200; w[210] = 0.0065874601112693336961737372300; w[211] = 0.0064616867341210426397202932350; w[212] = 0.0063349515547314166407936938524; w[213] = 0.0062072734372448464599330978665; w[214] = 0.0060786713861593931405204596709; w[215] = 0.0059491645434980654366600347567; w[216] = 0.0058187721859596348346566361185; w[217] = 0.0056875137220494140577838938236; w[218] = 0.0055554086891904284012033890901; w[219] = 0.0054224767508154127788846727083; w[220] = 0.0052887376934400710240953933529; w[221] = 0.0051542114237180378340642003713; w[222] = 0.0050189179654779878773297516544; w[223] = 0.0048828774567433411142588306018; w[224] = 0.0047461101467350184936945641585; w[225] = 0.0046086363928577081326523656522; w[226] = 0.0044704766576701092218388764046; w[227] = 0.0043316515058396297504806208252; w[228] = 0.0041921816010820254766367595011; w[229] = 0.0040520877030864825223229951262; w[230] = 0.0039113906644266662571543468015; w[231] = 0.0037701114274582873548537007645; w[232] = 0.0036282710212037760873102463983; w[233] = 0.0034858905582247143702551557840; w[234] = 0.0033429912314827618499065991316; w[235] = 0.0031995943111899437356540290142; w[236] = 0.0030557211416493711130936102459; w[237] = 0.0029113931380877846359302447381; w[238] = 0.0027666317834818283552560256501; w[239] = 0.0026214586253808109266552781372; w[240] = 0.0024758952727301488651840215879; w[241] = 0.0023299633927021828561308282641; w[242] = 0.0021836847075455253317921866057; w[243] = 0.0020370809914723626741694800322; w[244] = 0.0018901740676190104269878470891; w[245] = 0.0017429858051468299509941139300; w[246] = 0.0015955381166175133369701690235; w[247] = 0.0014478529559255120065233994722; w[248] = 0.0012999523174235227389668643832; w[249] = 0.0011518582377826677880963146741; w[250] = 0.00100359280467969441299468763292; w[251] = 0.00085517818446696565626595950963; w[252] = 0.00070663671051592291949335494247; w[253] = 0.00055799120546880640169677292533; w[254] = 0.00040926648283531339591138751432; w[255] = 0.00026049995580176964436806680831; w[256] = 0.00011191470145601756450862287886; } else { std::stringstream err; err << "LEGENDRE_SET - Fatal error!\n" << " Illegal value of N = " << n << "\n" << " Legal values are 1:33, 63/64/65, 127/128/129, 255/256/257\n"; throw Dark_Arts_Exception( SUPPORT_OBJECT , err.str() ); } return; } //**************************************************************************** void Quadrule_New::lobatto_compute ( const int n, std::vector<double>& x, std::vector<double>& w ) const //**************************************************************************** // // Purpose: // // LOBATTO_COMPUTE computes a Lobatto quadrature rule. // // Discussion: // // The integral: // // Integral ( -1 <= X <= 1 ) F(X) dX // // The quadrature rule: // // Sum ( 1 <= I <= N ) WEIGHT(I) * F ( XTAB(I) ) // // The quadrature rule will integrate exactly all polynomials up to // X^(2*N-3). // // The Lobatto rule is distinguished by the fact that both endpoints // (-1 and 1) are always abscissas. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified/Author: // // John Burkardt- 04 February 2007 // Peter Maginot- 11 June 2014 // // Reference: // // Milton Abramowitz, Irene Stegun, // Handbook of Mathematical Functions, // National Bureau of Standards, 1964, // ISBN: 0-486-61272-4, // LC: QA47.A34. // // Claudio Canuto, Yousuff Hussaini, Alfio Quarteroni, Thomas Zang, // Spectral Methods in Fluid Dynamics, // Springer, 1993, // ISNB13: 978-3540522058, // LC: QA377.S676. // // Arthur Stroud, Don Secrest, // Gaussian Quadrature Formulas, // Prentice Hall, 1966, // LC: QA299.4G3S7. // // Daniel Zwillinger, editor, // CRC Standard Mathematical Tables and Formulae, // 30th Edition, // CRC Press, 1996, // ISBN: 0-8493-2479-3. // // Parameters: // // Input, int N, the order. // // Output, double X[N], the abscissas. // // Output, double W[N], the weights. // { int i=0; int j=0; std::vector<double> p; const double r8_pi = 3.141592653589793; double test=0.; double tolerance=0.; std::vector<double> xold; if ( n == 1 ) { x[0] = -1.0; w[0] = 2.0; return; } tolerance = 100.0 * r8_epsilon ( ); // // Initial estimate for the abscissas is the Chebyshev-Gauss-Lobatto nodes. // for ( i = 0; i < n; i++ ) { x[i] = cos ( r8_pi * ( double ) ( i ) / ( double ) ( n - 1 ) ); } xold.resize(n,0.); p.resize(n*n,0.); do { for ( i = 0; i < n; i++ ) { xold[i] = x[i]; } for ( i = 0; i < n; i++ ) { p[i+0*n] = 1.0; } for ( i = 0; i < n; i++ ) { p[i+1*n] = x[i]; } for ( j = 2; j <= n-1; j++ ) { for ( i = 0; i < n; i++) { p[i+j*n] = ( ( double ) ( 2 * j - 1 ) * x[i] * p[i+(j-1)*n] + ( double ) ( - j + 1 ) * p[i+(j-2)*n] ) / ( double ) ( j ); } } for ( i = 0; i < n; i++ ) { x[i] = xold[i] - ( x[i] * p[i+(n-1)*n] - p[i+(n-2)*n] ) / ( ( double ) ( n ) * p[i+(n-1)*n] ); } test = 0.0; for ( i = 0; i < n; i++ ) { test = r8_max ( test, fabs ( x[i] - xold[i] ) ); } } while ( tolerance < test ); r8vec_reverse ( n, x ); for ( i = 0; i < n; i++ ) { w[i] = 2.0 / ( ( double ) ( ( n - 1 ) * n ) * pow ( p[i+(n-1)*n], 2 ) ); } return; } //**************************************************************************** void Quadrule_New::lobatto_set ( const int order, std::vector<double>& xtab, std::vector<double>& weight ) const //**************************************************************************** // // Purpose: // // LOBATTO_SET sets abscissas and weights for Lobatto quadrature. // // Discussion: // // The integral: // // Integral ( -1 <= X <= 1 ) F(X) dX // // The quadrature rule: // // Sum ( 1 <= I <= ORDER ) WEIGHt[I) * F ( XTAb[I) ) // // The quadrature rule will integrate exactly all polynomials up to // X^(2*ORDER-3). // // The Lobatto rule is distinguished by the fact that both endpoints // (-1 and 1) are always abscissas. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 28 May 2014 // // Author: // // John Burkardt // // Reference: // // Milton Abramowitz, Irene Stegun, // Handbook of Mathematical Functions, // National Bureau of Standards, 1964, // ISBN: 0-486-61272-4, // LC: QA47.A34. // // Arthur Stroud, Don Secrest, // Gaussian Quadrature Formulas, // Prentice Hall, 1966, // LC: QA299.4G3S7. // // Daniel Zwillinger, editor, // CRC Standard Mathematical Tables and Formulae, // 30th Edition, // CRC Press, 1996, // ISBN: 0-8493-2479-3. // // Parameters: // // Input, int ORDER, the order. // ORDER must be between 1 and 20. // // Output, double XTAB[ORDER], the abscissas. // // Output, double WEIGHT[ORDER], the weights. // { if ( order == 1 ) { xtab[0] = -1.0; weight[0] = 2.0; } else if ( order == 2 ) { xtab[0] = - 1.0E+00; xtab[1] = 1.0E+00; weight[0] = 1.0E+00; weight[1] = 1.0E+00; } else if ( order == 3 ) { xtab[0] = - 1.0E+00; xtab[1] = 0.0E+00; xtab[2] = 1.0E+00; weight[0] = 1.0 / 3.0E+00; weight[1] = 4.0 / 3.0E+00; weight[2] = 1.0 / 3.0E+00; } else if ( order == 4 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.447213595499957939281834733746E+00; xtab[2] = 0.447213595499957939281834733746E+00; xtab[3] = 1.0E+00; weight[0] = 1.0E+00 / 6.0E+00; weight[1] = 5.0E+00 / 6.0E+00; weight[2] = 5.0E+00 / 6.0E+00; weight[3] = 1.0E+00 / 6.0E+00; } else if ( order == 5 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.654653670707977143798292456247E+00; xtab[2] = 0.0E+00; xtab[3] = 0.654653670707977143798292456247E+00; xtab[4] = 1.0E+00; weight[0] = 9.0E+00 / 90.0E+00; weight[1] = 49.0E+00 / 90.0E+00; weight[2] = 64.0E+00 / 90.0E+00; weight[3] = 49.0E+00 / 90.0E+00; weight[4] = 9.0E+00 / 90.0E+00; } else if ( order == 6 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.765055323929464692851002973959E+00; xtab[2] = - 0.285231516480645096314150994041E+00; xtab[3] = 0.285231516480645096314150994041E+00; xtab[4] = 0.765055323929464692851002973959E+00; xtab[5] = 1.0E+00; weight[0] = 0.066666666666666666666666666667E+00; weight[1] = 0.378474956297846980316612808212E+00; weight[2] = 0.554858377035486353016720525121E+00; weight[3] = 0.554858377035486353016720525121E+00; weight[4] = 0.378474956297846980316612808212E+00; weight[5] = 0.066666666666666666666666666667E+00; } else if ( order == 7 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.830223896278566929872032213967E+00; xtab[2] = - 0.468848793470714213803771881909E+00; xtab[3] = 0.0E+00; xtab[4] = 0.468848793470714213803771881909E+00; xtab[5] = 0.830223896278566929872032213967E+00; xtab[6] = 1.0E+00; weight[0] = 0.476190476190476190476190476190E-01; weight[1] = 0.276826047361565948010700406290E+00; weight[2] = 0.431745381209862623417871022281E+00; weight[3] = 0.487619047619047619047619047619E+00; weight[4] = 0.431745381209862623417871022281E+00; weight[5] = 0.276826047361565948010700406290E+00; weight[6] = 0.476190476190476190476190476190E-01; } else if ( order == 8 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.871740148509606615337445761221E+00; xtab[2] = - 0.591700181433142302144510731398E+00; xtab[3] = - 0.209299217902478868768657260345E+00; xtab[4] = 0.209299217902478868768657260345E+00; xtab[5] = 0.591700181433142302144510731398E+00; xtab[6] = 0.871740148509606615337445761221E+00; xtab[7] = 1.0E+00; weight[0] = 0.357142857142857142857142857143E-01; weight[1] = 0.210704227143506039382991065776E+00; weight[2] = 0.341122692483504364764240677108E+00; weight[3] = 0.412458794658703881567052971402E+00; weight[4] = 0.412458794658703881567052971402E+00; weight[5] = 0.341122692483504364764240677108E+00; weight[6] = 0.210704227143506039382991065776E+00; weight[7] = 0.357142857142857142857142857143E-01; } else if ( order == 9 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.899757995411460157312345244418E+00; xtab[2] = - 0.677186279510737753445885427091E+00; xtab[3] = - 0.363117463826178158710752068709E+00; xtab[4] = 0.0E+00; xtab[5] = 0.363117463826178158710752068709E+00; xtab[6] = 0.677186279510737753445885427091E+00; xtab[7] = 0.899757995411460157312345244418E+00; xtab[8] = 1.0E+00; weight[0] = 0.277777777777777777777777777778E-01; weight[1] = 0.165495361560805525046339720029E+00; weight[2] = 0.274538712500161735280705618579E+00; weight[3] = 0.346428510973046345115131532140E+00; weight[4] = 0.371519274376417233560090702948E+00; weight[5] = 0.346428510973046345115131532140E+00; weight[6] = 0.274538712500161735280705618579E+00; weight[7] = 0.165495361560805525046339720029E+00; weight[8] = 0.277777777777777777777777777778E-01; } else if ( order == 10 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.919533908166458813828932660822E+00; xtab[2] = - 0.738773865105505075003106174860E+00; xtab[3] = - 0.477924949810444495661175092731E+00; xtab[4] = - 0.165278957666387024626219765958E+00; xtab[5] = 0.165278957666387024626219765958E+00; xtab[6] = 0.477924949810444495661175092731E+00; xtab[7] = 0.738773865105505075003106174860E+00; xtab[8] = 0.919533908166458813828932660822E+00; xtab[9] = 1.0E+00; weight[0] = 0.222222222222222222222222222222E-01; weight[1] = 0.133305990851070111126227170755E+00; weight[2] = 0.224889342063126452119457821731E+00; weight[3] = 0.292042683679683757875582257374E+00; weight[4] = 0.327539761183897456656510527917E+00; weight[5] = 0.327539761183897456656510527917E+00; weight[6] = 0.292042683679683757875582257374E+00; weight[7] = 0.224889342063126452119457821731E+00; weight[8] = 0.133305990851070111126227170755E+00; weight[9] = 0.222222222222222222222222222222E-01; } else if ( order == 11 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.934001430408059134332274136099E+00; xtab[2] = - 0.784483473663144418622417816108E+00; xtab[3] = - 0.565235326996205006470963969478E+00; xtab[4] = - 0.295758135586939391431911515559E+00; xtab[5] = 0.0E+00; xtab[6] = 0.295758135586939391431911515559E+00; xtab[7] = 0.565235326996205006470963969478E+00; xtab[8] = 0.784483473663144418622417816108E+00; xtab[9] = 0.934001430408059134332274136099E+00; xtab[10] = 1.0E+00; weight[0] = 0.181818181818181818181818181818E-01; weight[1] = 0.109612273266994864461403449580E+00; weight[2] = 0.187169881780305204108141521899E+00; weight[3] = 0.248048104264028314040084866422E+00; weight[4] = 0.286879124779008088679222403332E+00; weight[5] = 0.300217595455690693785931881170E+00; weight[6] = 0.286879124779008088679222403332E+00; weight[7] = 0.248048104264028314040084866422E+00; weight[8] = 0.187169881780305204108141521899E+00; weight[9] = 0.109612273266994864461403449580E+00; weight[10] = 0.181818181818181818181818181818E-01; } else if ( order == 12 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.944899272222882223407580138303E+00; xtab[2] = - 0.819279321644006678348641581717E+00; xtab[3] = - 0.632876153031869677662404854444E+00; xtab[4] = - 0.399530940965348932264349791567E+00; xtab[5] = - 0.136552932854927554864061855740E+00; xtab[6] = 0.136552932854927554864061855740E+00; xtab[7] = 0.399530940965348932264349791567E+00; xtab[8] = 0.632876153031869677662404854444E+00; xtab[9] = 0.819279321644006678348641581717E+00; xtab[10] = 0.944899272222882223407580138303E+00; xtab[11] = 1.0E+00; weight[0] = 0.151515151515151515151515151515E-01; weight[1] = 0.916845174131961306683425941341E-01; weight[2] = 0.157974705564370115164671062700E+00; weight[3] = 0.212508417761021145358302077367E+00; weight[4] = 0.251275603199201280293244412148E+00; weight[5] = 0.271405240910696177000288338500E+00; weight[6] = 0.271405240910696177000288338500E+00; weight[7] = 0.251275603199201280293244412148E+00; weight[8] = 0.212508417761021145358302077367E+00; weight[9] = 0.157974705564370115164671062700E+00; weight[10] = 0.916845174131961306683425941341E-01; weight[11] = 0.151515151515151515151515151515E-01; } else if ( order == 13 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.953309846642163911896905464755E+00; xtab[2] = - 0.846347564651872316865925607099E+00; xtab[3] = - 0.686188469081757426072759039566E+00; xtab[4] = - 0.482909821091336201746937233637E+00; xtab[5] = - 0.249286930106239992568673700374E+00; xtab[6] = 0.0E+00; xtab[7] = 0.249286930106239992568673700374E+00; xtab[8] = 0.482909821091336201746937233637E+00; xtab[9] = 0.686188469081757426072759039566E+00; xtab[10] = 0.846347564651872316865925607099E+00; xtab[11] = 0.953309846642163911896905464755E+00; xtab[12] = 1.0E+00; weight[0] = 0.128205128205128205128205128205E-01; weight[1] = 0.778016867468189277935889883331E-01; weight[2] = 0.134981926689608349119914762589E+00; weight[3] = 0.183646865203550092007494258747E+00; weight[4] = 0.220767793566110086085534008379E+00; weight[5] = 0.244015790306676356458578148360E+00; weight[6] = 0.251930849333446736044138641541E+00; weight[7] = 0.244015790306676356458578148360E+00; weight[8] = 0.220767793566110086085534008379E+00; weight[9] = 0.183646865203550092007494258747E+00; weight[10] = 0.134981926689608349119914762589E+00; weight[11] = 0.778016867468189277935889883331E-01; weight[12] = 0.128205128205128205128205128205E-01; } else if ( order == 14 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.959935045267260901355100162015E+00; xtab[2] = - 0.867801053830347251000220202908E+00; xtab[3] = - 0.728868599091326140584672400521E+00; xtab[4] = - 0.550639402928647055316622705859E+00; xtab[5] = - 0.342724013342712845043903403642E+00; xtab[6] = - 0.116331868883703867658776709736E+00; xtab[7] = 0.116331868883703867658776709736E+00; xtab[8] = 0.342724013342712845043903403642E+00; xtab[9] = 0.550639402928647055316622705859E+00; xtab[10] = 0.728868599091326140584672400521E+00; xtab[11] = 0.867801053830347251000220202908E+00; xtab[12] = 0.959935045267260901355100162015E+00; xtab[13] = 1.0E+00; weight[0] = 0.109890109890109890109890109890E-01; weight[1] = 0.668372844976812846340706607461E-01; weight[2] = 0.116586655898711651540996670655E+00; weight[3] = 0.160021851762952142412820997988E+00; weight[4] = 0.194826149373416118640331778376E+00; weight[5] = 0.219126253009770754871162523954E+00; weight[6] = 0.231612794468457058889628357293E+00; weight[7] = 0.231612794468457058889628357293E+00; weight[8] = 0.219126253009770754871162523954E+00; weight[9] = 0.194826149373416118640331778376E+00; weight[10] = 0.160021851762952142412820997988E+00; weight[11] = 0.116586655898711651540996670655E+00; weight[12] = 0.668372844976812846340706607461E-01; weight[13] = 0.109890109890109890109890109890E-01; } else if ( order == 15 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.965245926503838572795851392070E+00; xtab[2] = - 0.885082044222976298825401631482E+00; xtab[3] = - 0.763519689951815200704118475976E+00; xtab[4] = - 0.606253205469845711123529938637E+00; xtab[5] = - 0.420638054713672480921896938739E+00; xtab[6] = - 0.215353955363794238225679446273E+00; xtab[7] = 0.0E+00; xtab[8] = 0.215353955363794238225679446273E+00; xtab[9] = 0.420638054713672480921896938739E+00; xtab[10] = 0.606253205469845711123529938637E+00; xtab[11] = 0.763519689951815200704118475976E+00; xtab[12] = 0.885082044222976298825401631482E+00; xtab[13] = 0.965245926503838572795851392070E+00; xtab[14] = 1.0E+00; weight[0] = 0.952380952380952380952380952381E-02; weight[1] = 0.580298930286012490968805840253E-01; weight[2] = 0.101660070325718067603666170789E+00; weight[3] = 0.140511699802428109460446805644E+00; weight[4] = 0.172789647253600949052077099408E+00; weight[5] = 0.196987235964613356092500346507E+00; weight[6] = 0.211973585926820920127430076977E+00; weight[7] = 0.217048116348815649514950214251E+00; weight[8] = 0.211973585926820920127430076977E+00; weight[9] = 0.196987235964613356092500346507E+00; weight[10] = 0.172789647253600949052077099408E+00; weight[11] = 0.140511699802428109460446805644E+00; weight[12] = 0.101660070325718067603666170789E+00; weight[13] = 0.580298930286012490968805840253E-01; weight[14] = 0.952380952380952380952380952381E-02; } else if ( order == 16 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.969568046270217932952242738367E+00; xtab[2] = - 0.899200533093472092994628261520E+00; xtab[3] = - 0.792008291861815063931088270963E+00; xtab[4] = - 0.652388702882493089467883219641E+00; xtab[5] = - 0.486059421887137611781890785847E+00; xtab[6] = - 0.299830468900763208098353454722E+00; xtab[7] = - 0.101326273521949447843033005046E+00; xtab[8] = 0.101326273521949447843033005046E+00; xtab[9] = 0.299830468900763208098353454722E+00; xtab[10] = 0.486059421887137611781890785847E+00; xtab[11] = 0.652388702882493089467883219641E+00; xtab[12] = 0.792008291861815063931088270963E+00; xtab[13] = 0.899200533093472092994628261520E+00; xtab[14] = 0.969568046270217932952242738367E+00; xtab[15] = 1.0E+00; weight[0] = 0.833333333333333333333333333333E-02; weight[1] = 0.508503610059199054032449195655E-01; weight[2] = 0.893936973259308009910520801661E-01; weight[3] = 0.124255382132514098349536332657E+00; weight[4] = 0.154026980807164280815644940485E+00; weight[5] = 0.177491913391704125301075669528E+00; weight[6] = 0.193690023825203584316913598854E+00; weight[7] = 0.201958308178229871489199125411E+00; weight[8] = 0.201958308178229871489199125411E+00; weight[9] = 0.193690023825203584316913598854E+00; weight[10] = 0.177491913391704125301075669528E+00; weight[11] = 0.154026980807164280815644940485E+00; weight[12] = 0.124255382132514098349536332657E+00; weight[13] = 0.893936973259308009910520801661E-01; weight[14] = 0.508503610059199054032449195655E-01; weight[15] = 0.833333333333333333333333333333E-02; } else if ( order == 17 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.973132176631418314156979501874E+00; xtab[2] = - 0.910879995915573595623802506398E+00; xtab[3] = - 0.815696251221770307106750553238E+00; xtab[4] = - 0.691028980627684705394919357372E+00; xtab[5] = - 0.541385399330101539123733407504E+00; xtab[6] = - 0.372174433565477041907234680735E+00; xtab[7] = - 0.189511973518317388304263014753E+00; xtab[8] = 0.0E+00; xtab[9] = 0.189511973518317388304263014753E+00; xtab[10] = 0.372174433565477041907234680735E+00; xtab[11] = 0.541385399330101539123733407504E+00; xtab[12] = 0.691028980627684705394919357372E+00; xtab[13] = 0.815696251221770307106750553238E+00; xtab[14] = 0.910879995915573595623802506398E+00; xtab[15] = 0.973132176631418314156979501874E+00; xtab[16] = 1.0E+00; weight[0] = 0.735294117647058823529411764706E-02; weight[1] = 0.449219405432542096474009546232E-01; weight[2] = 0.791982705036871191902644299528E-01; weight[3] = 0.110592909007028161375772705220E+00; weight[4] = 0.137987746201926559056201574954E+00; weight[5] = 0.160394661997621539516328365865E+00; weight[6] = 0.177004253515657870436945745363E+00; weight[7] = 0.187216339677619235892088482861E+00; weight[8] = 0.190661874753469433299407247028E+00; weight[9] = 0.187216339677619235892088482861E+00; weight[10] = 0.177004253515657870436945745363E+00; weight[11] = 0.160394661997621539516328365865E+00; weight[12] = 0.137987746201926559056201574954E+00; weight[13] = 0.110592909007028161375772705220E+00; weight[14] = 0.791982705036871191902644299528E-01; weight[15] = 0.449219405432542096474009546232E-01; weight[16] = 0.735294117647058823529411764706E-02; } else if ( order == 18 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.976105557412198542864518924342E+00; xtab[2] = - 0.920649185347533873837854625431E+00; xtab[3] = - 0.835593535218090213713646362328E+00; xtab[4] = - 0.723679329283242681306210365302E+00; xtab[5] = - 0.588504834318661761173535893194E+00; xtab[6] = - 0.434415036912123975342287136741E+00; xtab[7] = - 0.266362652878280984167665332026E+00; xtab[8] = - 0.897490934846521110226450100886E-01; xtab[9] = 0.897490934846521110226450100886E-01; xtab[10] = 0.266362652878280984167665332026E+00; xtab[11] = 0.434415036912123975342287136741E+00; xtab[12] = 0.588504834318661761173535893194E+00; xtab[13] = 0.723679329283242681306210365302E+00; xtab[14] = 0.835593535218090213713646362328E+00; xtab[15] = 0.920649185347533873837854625431E+00; xtab[16] = 0.976105557412198542864518924342E+00; xtab[17] = 1.0E+00; weight[0] = 0.653594771241830065359477124183E-02; weight[1] = 0.399706288109140661375991764101E-01; weight[2] = 0.706371668856336649992229601678E-01; weight[3] = 0.990162717175028023944236053187E-01; weight[4] = 0.124210533132967100263396358897E+00; weight[5] = 0.145411961573802267983003210494E+00; weight[6] = 0.161939517237602489264326706700E+00; weight[7] = 0.173262109489456226010614403827E+00; weight[8] = 0.179015863439703082293818806944E+00; weight[9] = 0.179015863439703082293818806944E+00; weight[10] = 0.173262109489456226010614403827E+00; weight[11] = 0.161939517237602489264326706700E+00; weight[12] = 0.145411961573802267983003210494E+00; weight[13] = 0.124210533132967100263396358897E+00; weight[14] = 0.990162717175028023944236053187E-01; weight[15] = 0.706371668856336649992229601678E-01; weight[16] = 0.399706288109140661375991764101E-01; weight[17] = 0.653594771241830065359477124183E-02; } else if ( order == 19 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.978611766222080095152634063110E+00; xtab[2] = - 0.928901528152586243717940258797E+00; xtab[3] = - 0.852460577796646093085955970041E+00; xtab[4] = - 0.751494202552613014163637489634E+00; xtab[5] = - 0.628908137265220497766832306229E+00; xtab[6] = - 0.488229285680713502777909637625E+00; xtab[7] = - 0.333504847824498610298500103845E+00; xtab[8] = - 0.169186023409281571375154153445E+00; xtab[9] = 0.0E+00; xtab[10] = 0.169186023409281571375154153445E+00; xtab[11] = 0.333504847824498610298500103845E+00; xtab[12] = 0.488229285680713502777909637625E+00; xtab[13] = 0.628908137265220497766832306229E+00; xtab[14] = 0.751494202552613014163637489634E+00; xtab[15] = 0.852460577796646093085955970041E+00; xtab[16] = 0.928901528152586243717940258797E+00; xtab[17] = 0.978611766222080095152634063110E+00; xtab[18] = 1.0E+00; weight[0] = 0.584795321637426900584795321637E-02; weight[1] = 0.357933651861764771154255690351E-01; weight[2] = 0.633818917626297368516956904183E-01; weight[3] = 0.891317570992070844480087905562E-01; weight[4] = 0.112315341477305044070910015464E+00; weight[5] = 0.132267280448750776926046733910E+00; weight[6] = 0.148413942595938885009680643668E+00; weight[7] = 0.160290924044061241979910968184E+00; weight[8] = 0.167556584527142867270137277740E+00; weight[9] = 0.170001919284827234644672715617E+00; weight[10] = 0.167556584527142867270137277740E+00; weight[11] = 0.160290924044061241979910968184E+00; weight[12] = 0.148413942595938885009680643668E+00; weight[13] = 0.132267280448750776926046733910E+00; weight[14] = 0.112315341477305044070910015464E+00; weight[15] = 0.891317570992070844480087905562E-01; weight[16] = 0.633818917626297368516956904183E-01; weight[17] = 0.357933651861764771154255690351E-01; weight[18] = 0.584795321637426900584795321637E-02; } else if ( order == 20 ) { xtab[0] = - 1.0E+00; xtab[1] = - 0.980743704893914171925446438584E+00; xtab[2] = - 0.935934498812665435716181584931E+00; xtab[3] = - 0.866877978089950141309847214616E+00; xtab[4] = - 0.775368260952055870414317527595E+00; xtab[5] = - 0.663776402290311289846403322971E+00; xtab[6] = - 0.534992864031886261648135961829E+00; xtab[7] = - 0.392353183713909299386474703816E+00; xtab[8] = - 0.239551705922986495182401356927E+00; xtab[9] = - 0.805459372388218379759445181596E-01; xtab[10] = 0.805459372388218379759445181596E-01; xtab[11] = 0.239551705922986495182401356927E+00; xtab[12] = 0.392353183713909299386474703816E+00; xtab[13] = 0.534992864031886261648135961829E+00; xtab[14] = 0.663776402290311289846403322971E+00; xtab[15] = 0.775368260952055870414317527595E+00; xtab[16] = 0.866877978089950141309847214616E+00; xtab[17] = 0.935934498812665435716181584931E+00; xtab[18] = 0.980743704893914171925446438584E+00; xtab[19] = 1.0E+00; weight[0] = 0.526315789473684210526315789474E-02; weight[1] = 0.322371231884889414916050281173E-01; weight[2] = 0.571818021275668260047536271732E-01; weight[3] = 0.806317639961196031447768461137E-01; weight[4] = 0.101991499699450815683781205733E+00; weight[5] = 0.120709227628674725099429705002E+00; weight[6] = 0.136300482358724184489780792989E+00; weight[7] = 0.148361554070916825814713013734E+00; weight[8] = 0.156580102647475487158169896794E+00; weight[9] = 0.160743286387845749007726726449E+00; weight[10] = 0.160743286387845749007726726449E+00; weight[11] = 0.156580102647475487158169896794E+00; weight[12] = 0.148361554070916825814713013734E+00; weight[13] = 0.136300482358724184489780792989E+00; weight[14] = 0.120709227628674725099429705002E+00; weight[15] = 0.101991499699450815683781205733E+00; weight[16] = 0.806317639961196031447768461137E-01; weight[17] = 0.571818021275668260047536271732E-01; weight[18] = 0.322371231884889414916050281173E-01; weight[19] = 0.526315789473684210526315789474E-02; } else { std::stringstream err; err << "LOBATTO_SET - Fatal error!\n" << " Illegal value of ORDER = " << order << "\n" << " Legal values are between 1 and 20.\n"; throw Dark_Arts_Exception(SUPPORT_OBJECT, err.str() ); } return; } //**************************************************************************** void Quadrule_New::ncc_compute ( const int n, std::vector<double>& x, std::vector<double>& w ) const //**************************************************************************** // // Purpose: // // NCC_COMPUTE computes a Newton-Cotes closed quadrature rule. // // Discussion: // // For the interval [-1.0,+1.0], the Newton-Cotes closed quadrature rule // estimates // // Integral ( -1 <= X <= +1 ) F(X) dX // // using N abscissas X and weights W: // // sum ( 1 <= I <= N ) W[I] * F ( X[I] ). // // For the CLOSED rule, the abscissas are equally spaced and include // the end points. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // John Burkardt- 16 November 2009 // Peter Maginot- 11 June 2014 // // Parameters: // // Input, int N, the order. // // Output, double X[N], the abscissas. // // Output, double W[N], the weights. // { ncc_compute_points ( n, x ); ncc_compute_weights ( n, w ); return; } //**************************************************************************** void Quadrule_New::ncc_set ( const int order, std::vector<double>& x, std::vector<double>& w ) const //**************************************************************************** // // Purpose: // // NCC_SET sets abscissas and weights for closed Newton-Cotes quadrature. // // Discussion: // // The closed Newton-Cotes rules use equally spaced abscissas, and // hence may be used with tabulated function data. // // The rules are called "closed" because they include the endpoints. // As a favor, we include an order 1 rule, the midpoint rule, even // though this does not satisfy the requirement that the endpoints // be included// // // The higher order rules involve negative weights. These can produce // loss of accuracy due to the subtraction of large, nearly equal quantities. // // ORDER = 1 is the midpoint rule (and is not really an NCC rule//) // ORDER = 2 is the trapezoidal rule. // ORDER = 3 is Simpson's rule. // ORDER = 4 is Simpson's 3/8 rule. // ORDER = 5 is Bode's rule. // // The Kopal reference for ORDER = 12 lists // W(6) = 15494566.0D+00 / 43545600.0D+00 // but this results in a set of coeffients that don't add up to 2. // The correct value is // W(6) = 15493566.0D+00 / 43545600.0. // // The integral: // // Integral ( -1 <= X <= 1 ) F(X) dX // // The quadrature rule: // // Sum ( 1 <= I <= ORDER ) W(I) * F ( X(I) ) // // In Mathematica, the closed Newton-Cotes weights // can be computed by: // // Needs["NumericalDifferentialEquationAnalysis`"] // NewtonCotesWeights [ order, -1, 1, QuadratureType -> Closed ] // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 20 April 2010 // // Author: // // John Burkardt // // Reference: // // Milton Abramowitz, Irene Stegun, // Handbook of Mathematical Functions, // National Bureau of Standards, 1964, // ISBN: 0-486-61272-4, // LC: QA47.A34. // // Johnson, // Quarterly Journal of Mathematics, // Volume 46, Number 52, 1915. // // Zdenek Kopal, // Numerical Analysis, // John Wiley, 1955, // LC: QA297.K6. // // Stephen Wolfram, // The Mathematica Book, // Fourth Edition, // Cambridge University Press, 1999, // ISBN: 0-521-64314-7, // LC: QA76.95.W65. // // Daniel Zwillinger, editor, // CRC Standard Mathematical Tables and Formulae, // 30th Edition, // CRC Press, 1996, // ISBN: 0-8493-2479-3, // LC: QA47.M315. // // Parameters: // // Input, int ORDER, the order. // ORDER must be between 1 and 21. // // Output, double X[ORDER], the abscissas. // // Output, double W[ORDER], the weights. // { if ( order == 1 ) { // // 2 // x[0] = 0.00000000000000000000; w[0] = 2.00000000000000000000; } else if ( order == 2 ) { // // 1 // 1 // x[0] = -1.00000000000000000000; x[1] = 1.00000000000000000000; w[0] = 1.00000000000000000000; w[1] = 1.00000000000000000000; } else if ( order == 3 ) { // // 1 / 3 // 4 / 3 // 1 / 3 // x[0] = -1.00000000000000000000; x[1] = 0.00000000000000000000; x[2] = 1.00000000000000000000; w[0] = 0.33333333333333333333; w[1] = 1.33333333333333333333; w[2] = 0.33333333333333333333; } else if ( order == 4 ) { // // 1 / 4 // 3 / 4 // 3 / 4 // 1 / 4 // x[0] = -1.00000000000000000000; x[1] = -0.33333333333333333333; x[2] = 0.33333333333333333333; x[3] = 1.00000000000000000000; w[0] = 0.25000000000000000000; w[1] = 0.75000000000000000000; w[2] = 0.75000000000000000000; w[3] = 0.25000000000000000000; } else if ( order == 5 ) { // // 7 / 45 // 32 / 45 // 12 / 45 // 32 / 45 // 7 / 45 // x[0] = -1.00000000000000000000; x[1] = -0.50000000000000000000; x[2] = 0.00000000000000000000; x[3] = 0.50000000000000000000; x[4] = 1.00000000000000000000; w[0] = 0.15555555555555555556; w[1] = 0.71111111111111111111; w[2] = 0.26666666666666666667; w[3] = 0.71111111111111111111; w[4] = 0.15555555555555555556; } else if ( order == 6 ) { // // 19 / 144 // 75 / 144 // 50 / 144 // 50 / 144 // 75 / 144 // 19 / 144 // x[0] = -1.00000000000000000000; x[1] = -0.60000000000000000000; x[2] = -0.20000000000000000000; x[3] = 0.20000000000000000000; x[4] = 0.60000000000000000000; x[5] = 1.00000000000000000000; w[0] = 0.13194444444444444444; w[1] = 0.52083333333333333333; w[2] = 0.34722222222222222222; w[3] = 0.34722222222222222222; w[4] = 0.52083333333333333333; w[5] = 0.13194444444444444444; } else if ( order == 7 ) { // // 41 / 420 // 216 / 420 // 27 / 420 // 272 / 420 // 27 / 420 // 216 / 420 // 41 / 420 // x[0] = -1.00000000000000000000; x[1] = -0.66666666666666666667; x[2] = -0.33333333333333333333; x[3] = 0.00000000000000000000; x[4] = 0.33333333333333333333; x[5] = 0.66666666666666666667; x[6] = 1.00000000000000000000; w[0] = 0.097619047619047619048; w[1] = 0.51428571428571428571; w[2] = 0.064285714285714285714; w[3] = 0.64761904761904761905; w[4] = 0.064285714285714285714; w[5] = 0.51428571428571428571; w[6] = 0.097619047619047619048; } else if ( order == 8 ) { // // 751 / 8640 // 3577 / 8640 // 1323 / 8640 // 2989 / 8640 // 2989 / 8640 // 1323 / 8640 // 3577 / 8640 // 751 / 8640 // x[0] = -1.00000000000000000000; x[1] = -0.71428571428571428571; x[2] = -0.42857142857142857143; x[3] = -0.14285714285714285714; x[4] = 0.14285714285714285714; x[5] = 0.42857142857142857143; x[6] = 0.71428571428571428571; x[7] = 1.00000000000000000000; w[0] = 0.086921296296296296296; w[1] = 0.41400462962962962963; w[2] = 0.15312500000000000000; w[3] = 0.34594907407407407407; w[4] = 0.34594907407407407407; w[5] = 0.15312500000000000000; w[6] = 0.41400462962962962963; w[7] = 0.086921296296296296296; } else if ( order == 9 ) { // // 989 / 14175 // 5888 / 14175 // -928 / 14175 // 10496 / 14175 // -4540 / 14175 // 10496 / 14175 // -928 / 14175 // 5888 / 14175 // 989 / 14175 // x[0] = -1.00000000000000000000; x[1] = -0.75000000000000000000; x[2] = -0.50000000000000000000; x[3] = -0.25000000000000000000; x[4] = 0.00000000000000000000; x[5] = 0.25000000000000000000; x[6] = 0.50000000000000000000; x[7] = 0.75000000000000000000; x[8] = 1.00000000000000000000; w[0] = 0.069770723104056437390; w[1] = 0.41537918871252204586; w[2] = -0.065467372134038800705; w[3] = 0.74045855379188712522; w[4] = -0.32028218694885361552; w[5] = 0.74045855379188712522; w[6] = -0.065467372134038800705; w[7] = 0.41537918871252204586; w[8] = 0.069770723104056437390; } else if ( order == 10 ) { // // 2857 / 44800 // 15741 / 44800 // 1080 / 44800 // 19344 / 44800 // 5778 / 44800 // 5778 / 44800 // 19344 / 44800 // 1080 / 44800 // 15741 / 44800 // 2857 / 44800 // x[0] = -1.00000000000000000000; x[1] = -0.77777777777777777778; x[2] = -0.55555555555555555556; x[3] = -0.33333333333333333333; x[4] = -0.11111111111111111111; x[5] = 0.11111111111111111111; x[6] = 0.33333333333333333333; x[7] = 0.55555555555555555556; x[8] = 0.77777777777777777778; x[9] = 1.00000000000000000000; w[0] = 0.063772321428571428571; w[1] = 0.35136160714285714286; w[2] = 0.024107142857142857143; w[3] = 0.43178571428571428571; w[4] = 0.12897321428571428571; w[5] = 0.12897321428571428571; w[6] = 0.43178571428571428571; w[7] = 0.024107142857142857143; w[8] = 0.35136160714285714286; w[9] = 0.063772321428571428571; } else if ( order == 11 ) { // // 16067 / 299376 // 106300 / 299376 // - 48525 / 299376 // 272400 / 299376 // - 260550 / 299376 // 427368 / 299376 // - 260550 / 299376 // 272400 / 299376 // - 48525 / 299376 // 106300 / 299376 // 16067 / 299376 // x[0] = -1.00000000000000000000; x[1] = -0.80000000000000000000; x[2] = -0.60000000000000000000; x[3] = -0.40000000000000000000; x[4] = -0.20000000000000000000; x[5] = 0.00000000000000000000; x[6] = 0.20000000000000000000; x[7] = 0.40000000000000000000; x[8] = 0.60000000000000000000; x[9] = 0.80000000000000000000; x[10] = 1.00000000000000000000; w[0] = 0.053668296723852279408; w[1] = 0.35507188284966062744; w[2] = -0.16208714125380792047; w[3] = 0.90989257655924322591; w[4] = -0.87031024531024531025; w[5] = 1.4275292608625941959; w[6] = -0.87031024531024531025; w[7] = 0.90989257655924322591; w[8] = -0.16208714125380792047; w[9] = 0.35507188284966062744; w[10] = 0.053668296723852279408; } else if ( order == 12 ) { // // 2171465 / 43545600 // 13486539 / 43545600 // - 3237113 / 43545600 // 25226685 / 43545600 // - 9595542 / 43545600 // 15493566 / 43545600 // 15493566 / 43545600 // - 9595542 / 43545600 // 25226685 / 43545600 // - 3237113 / 43545600 // 13486539 / 43545600 // 2171465 / 43545600 // x[0] = -1.00000000000000000000; x[1] = -0.81818181818181818182; x[2] = -0.63636363636363636364; x[3] = -0.45454545454545454545; x[4] = -0.27272727272727272727; x[5] = -0.090909090909090909091; x[6] = 0.090909090909090909091; x[7] = 0.27272727272727272727; x[8] = 0.45454545454545454545; x[9] = 0.63636363636363636364; x[10] = 0.81818181818181818182; x[11] = 1.00000000000000000000; w[0] = 0.049866461823927101705; w[1] = 0.30971071704144620811; w[2] = -0.074338463587595532040; w[3] = 0.57931650958994708995; w[4] = -0.22035617835097001764; w[5] = 0.35580095348324514991; w[6] = 0.35580095348324514991; w[7] = -0.22035617835097001764; w[8] = 0.57931650958994708995; w[9] = -0.074338463587595532040; w[10] = 0.30971071704144620811; w[11] = 0.049866461823927101705; } else if ( order == 13 ) { // // 1364651 / 31531500 // 9903168 / 31531500 // - 7587864 / 31531500 // 35725120 / 31531500 // - 51491295 / 31531500 // 87516288 / 31531500 // - 87797136 / 31531500 // 87516288 / 31531500 // - 51491295 / 31531500 // 35725120 / 31531500 // - 7587864 / 31531500 // 9903168 / 31531500 // 1364651 / 31531500 // x[0] = -1.00000000000000000000; x[1] = -0.83333333333333333333; x[2] = -0.66666666666666666667; x[3] = -0.50000000000000000000; x[4] = -0.33333333333333333333; x[5] = -0.16666666666666666667; x[6] = 0.00000000000000000000; x[7] = 0.16666666666666666667; x[8] = 0.33333333333333333333; x[9] = 0.50000000000000000000; x[10] = 0.66666666666666666667; x[11] = 0.83333333333333333333; x[12] = 1.00000000000000000000; w[0] = 0.043278974993260707546; w[1] = 0.31407221350078492936; w[2] = -0.24064392750107035821; w[3] = 1.1329977958549387121; w[4] = -1.6330112744398458684; w[5] = 2.7755193378050520908; w[6] = -2.7844262404262404262; w[7] = 2.7755193378050520908; w[8] = -1.6330112744398458684; w[9] = 1.1329977958549387121; w[10] = -0.24064392750107035821; w[11] = 0.31407221350078492936; w[12] = 0.043278974993260707546; } else if ( order == 14 ) { // // 6137698213 / 150885504000 // 42194238652 / 150885504000 // - 23361540993 / 150885504000 // 116778274403 / 150885504000 // - 113219777650 / 150885504000 // 154424590209 / 150885504000 // - 32067978834 / 150885504000 // - 32067978834 / 150885504000 // 154424590209 / 150885504000 // - 113219777650 / 150885504000 // 116778274403 / 150885504000 // - 23361540993 / 150885504000 // 42194238652 / 150885504000 // 6137698213 / 150885504000 // x[0] = -1.00000000000000000000; x[1] = -0.84615384615384615385; x[2] = -0.69230769230769230769; x[3] = -0.53846153846153846154; x[4] = -0.38461538461538461538; x[5] = -0.23076923076923076923; x[6] = -0.076923076923076923077; x[7] = 0.076923076923076923077; x[8] = 0.23076923076923076923; x[9] = 0.38461538461538461538; x[10] = 0.53846153846153846154; x[11] = 0.69230769230769230769; x[12] = 0.84615384615384615385; x[13] = 1.00000000000000000000; w[0] = 0.040669438210247155353; w[1] = 0.27975217053157074652; w[2] = -0.15542374057682837445; w[3] = 0.77579230848776566369; w[4] = -0.75384763266423526013; w[5] = 1.0273523591123107492; w[6] = -0.21429490310083068020; w[7] = -0.21429490310083068020; w[8] = 1.0273523591123107492; w[9] = -0.75384763266423526013; w[10] = 0.77579230848776566369; w[11] = -0.15542374057682837445; w[12] = 0.27975217053157074652; w[13] = 0.040669438210247155353; } else if ( order == 15 ) { // // 90241897 / 2501928000 // 710986864 / 2501928000 // - 770720657 / 2501928000 // 3501442784 / 2501928000 // - 6625093363 / 2501928000 // 12630121616 / 2501928000 // - 16802270373 / 2501928000 // 19534438464 / 2501928000 // - 16802270373 / 2501928000 // 12630121616 / 2501928000 // - 6625093363 / 2501928000 // 3501442784 / 2501928000 // - 770720657 / 2501928000 // 710986864 / 2501928000 // 90241897 / 2501928000 // x[0] = -1.00000000000000000000; x[1] = -0.85714285714285714286; x[2] = -0.71428571428571428571; x[3] = -0.57142857142857142857; x[4] = -0.42857142857142857143; x[5] = -0.28571428571428571429; x[6] = -0.14285714285714285714; x[7] = 0.00000000000000000000; x[8] = 0.14285714285714285714; x[9] = 0.28571428571428571429; x[10] = 0.42857142857142857143; x[11] = 0.57142857142857142857; x[12] = 0.71428571428571428571; x[13] = 0.85714285714285714286; x[14] = 1.00000000000000000000; w[0] = 0.036068942431596752584; w[1] = 0.28417558938546592868; w[2] = -0.30805069410470645039; w[3] = 1.3994978208805369299; w[4] = -2.6479952112930507992; w[5] = 5.0481555088715582543; w[6] = -6.7157289790113864188; w[7] = 7.8077540456799716059; w[8] = -6.7157289790113864188; w[9] = 5.0481555088715582543; w[10] = -2.6479952112930507992; w[11] = 1.3994978208805369299; w[12] = -0.30805069410470645039; w[13] = 0.28417558938546592868; w[14] = 0.036068942431596752584; } else if ( order == 16 ) { // // 105930069 / 3099672576 // 796661595 / 3099672576 // - 698808195 / 3099672576 // 3143332755 / 3099672576 // - 4688522055 / 3099672576 // 7385654007 / 3099672576 // - 6000998415 / 3099672576 // 3056422815 / 3099672576 // 3056422815 / 3099672576 // - 6000998415 / 3099672576 // 7385654007 / 3099672576 // - 4688522055 / 3099672576 // 3143332755 / 3099672576 // - 698808195 / 3099672576 // 796661595 / 3099672576 // 105930069 / 3099672576 // x[0] = -1.00000000000000000000; x[1] = -0.86666666666666666667; x[2] = -0.73333333333333333333; x[3] = -0.60000000000000000000; x[4] = -0.46666666666666666667; x[5] = -0.33333333333333333333; x[6] = -0.20000000000000000000; x[7] = -0.066666666666666666667; x[8] = 0.066666666666666666667; x[9] = 0.20000000000000000000; x[10] = 0.33333333333333333333; x[11] = 0.46666666666666666667; x[12] = 0.60000000000000000000; x[13] = 0.73333333333333333333; x[14] = 0.86666666666666666667; x[15] = 1.00000000000000000000; w[0] = 0.034174599543251887002; w[1] = 0.25701475735481036820; w[2] = -0.22544581011901045383; w[3] = 1.0140854164204471124; w[4] = -1.5125862296882804695; w[5] = 2.3827206990135980091; w[6] = -1.9360104229924960952; w[7] = 0.98604699046767964179; w[8] = 0.98604699046767964179; w[9] = -1.9360104229924960952; w[10] = 2.3827206990135980091; w[11] = -1.5125862296882804695; w[12] = 1.0140854164204471124; w[13] = -0.22544581011901045383; w[14] = 0.25701475735481036820; w[15] = 0.034174599543251887002; } else if ( order == 17 ) { // // 15043611773 / 488462349375 // 127626606592 / 488462349375 // - 179731134720 / 488462349375 // 832211855360 / 488462349375 // - 1929498607520 / 488462349375 // 4177588893696 / 488462349375 // - 6806534407936 / 488462349375 // 9368875018240 / 488462349375 // - 10234238972220 / 488462349375 // 9368875018240 / 488462349375 // - 6806534407936 / 488462349375 // 4177588893696 / 488462349375 // - 1929498607520 / 488462349375 // 832211855360 / 488462349375 // - 179731134720 / 488462349375 // 127626606592 / 488462349375 // 15043611773 / 488462349375 // x[0] = -1.00000000000000000000; x[1] = -0.87500000000000000000; x[2] = -0.75000000000000000000; x[3] = -0.62500000000000000000; x[4] = -0.50000000000000000000; x[5] = -0.37500000000000000000; x[6] = -0.25000000000000000000; x[7] = -0.12500000000000000000; x[8] = 0.00000000000000000000; x[9] = 0.12500000000000000000; x[10] = 0.25000000000000000000; x[11] = 0.37500000000000000000; x[12] = 0.50000000000000000000; x[13] = 0.62500000000000000000; x[14] = 0.75000000000000000000; x[15] = 0.87500000000000000000; x[16] = 1.00000000000000000000; w[0] = 0.030797894233299012495; w[1] = 0.26128238288028031086; w[2] = -0.36795289329867605622; w[3] = 1.7037379778090086905; w[4] = -3.9501480717783930427; w[5] = 8.5525299934402953388; w[6] = -13.934614237197880038; w[7] = 19.180342211078732848; w[8] = -20.951950514333334128; w[9] = 19.180342211078732848; w[10] = -13.934614237197880038; w[11] = 8.5525299934402953388; w[12] = -3.9501480717783930427; w[13] = 1.7037379778090086905; w[14] = -0.36795289329867605622; w[15] = 0.26128238288028031086; w[16] = 0.030797894233299012495; } else if ( order == 18 ) { // // 55294720874657 / 1883051089920000 // 450185515446285 / 1883051089920000 // - 542023437008852 / 1883051089920000 // 2428636525764260 / 1883051089920000 // - 4768916800123440 / 1883051089920000 // 8855416648684984 / 1883051089920000 // - 10905371859796660 / 1883051089920000 // 10069615750132836 / 1883051089920000 // - 3759785974054070 / 1883051089920000 // - 3759785974054070 / 1883051089920000 // 10069615750132836 / 1883051089920000 // - 10905371859796660 / 1883051089920000 // 8855416648684984 / 1883051089920000 // - 4768916800123440 / 1883051089920000 // 2428636525764260 / 1883051089920000 // - 542023437008852 / 1883051089920000 // 450185515446285 / 1883051089920000 // 55294720874657 / 1883051089920000 // x[0] = -1.00000000000000000000; x[1] = -0.88235294117647058824; x[2] = -0.76470588235294117647; x[3] = -0.64705882352941176471; x[4] = -0.52941176470588235294; x[5] = -0.41176470588235294118; x[6] = -0.29411764705882352941; x[7] = -0.17647058823529411765; x[8] = -0.058823529411764705882; x[9] = 0.058823529411764705882; x[10] = 0.17647058823529411765; x[11] = 0.29411764705882352941; x[12] = 0.41176470588235294118; x[13] = 0.52941176470588235294; x[14] = 0.64705882352941176471; x[15] = 0.76470588235294117647; x[16] = 0.88235294117647058824; x[17] = 1.00000000000000000000; w[0] = 0.029364429446790078519; w[1] = 0.23907238516051669677; w[2] = -0.28784319231183443641; w[3] = 1.2897348026109258587; w[4] = -2.5325477495812627261; w[5] = 4.7026959045817496499; w[6] = -5.7913308450170443690; w[7] = 5.3475000248456540826; w[8] = -1.9966457597354948350; w[9] = -1.9966457597354948350; w[10] = 5.3475000248456540826; w[11] = -5.7913308450170443690; w[12] = 4.7026959045817496499; w[13] = -2.5325477495812627261; w[14] = 1.2897348026109258587; w[15] = -0.28784319231183443641; w[16] = 0.23907238516051669677; w[17] = 0.029364429446790078519; } else if ( order == 19 ) { // // 203732352169 / 7604556960000 // 1848730221900 / 7604556960000 // - 3212744374395 / 7604556960000 // 15529830312096 / 7604556960000 // - 42368630685840 / 7604556960000 // 103680563465808 / 7604556960000 // - 198648429867720 / 7604556960000 // 319035784479840 / 7604556960000 // - 419127951114198 / 7604556960000 // 461327344340680 / 7604556960000 // - 419127951114198 / 7604556960000 // 319035784479840 / 7604556960000 // - 198648429867720 / 7604556960000 // 103680563465808 / 7604556960000 // - 42368630685840 / 7604556960000 // 15529830312096 / 7604556960000 // - 3212744374395 / 7604556960000 // 1848730221900 / 7604556960000 // 203732352169 / 7604556960000 // x[0] = -1.00000000000000000000; x[1] = -0.88888888888888888889; x[2] = -0.77777777777777777778; x[3] = -0.66666666666666666667; x[4] = -0.55555555555555555556; x[5] = -0.44444444444444444444; x[6] = -0.33333333333333333333; x[7] = -0.22222222222222222222; x[8] = -0.11111111111111111111; x[9] = 0.00000000000000000000; x[10] = 0.11111111111111111111; x[11] = 0.22222222222222222222; x[12] = 0.33333333333333333333; x[13] = 0.44444444444444444444; x[14] = 0.55555555555555555556; x[15] = 0.66666666666666666667; x[16] = 0.77777777777777777778; x[17] = 0.88888888888888888889; x[18] = 1.00000000000000000000; w[0] = 0.026790824664820447344; w[1] = 0.24310820888374278151; w[2] = -0.42247620621346493274; w[3] = 2.0421742376029227612; w[4] = -5.5714791681749728126; w[5] = 13.634004454324976218; w[6] = -26.122288374274995239; w[7] = 41.953237533490708445; w[8] = -55.115367445968607749; w[9] = 60.664591871329740161; w[10] = -55.115367445968607749; w[11] = 41.953237533490708445; w[12] = -26.122288374274995239; w[13] = 13.634004454324976218; w[14] = -5.5714791681749728126; w[15] = 2.0421742376029227612; w[16] = -0.42247620621346493274; w[17] = 0.24310820888374278151; w[18] = 0.026790824664820447344; } else if ( order == 20 ) { // // 69028763155644023 / 2688996956405760000 // 603652082270808125 / 2688996956405760000 // - 926840515700222955 / 2688996956405760000 // 4301581538450500095 / 2688996956405760000 // - 10343692234243192788 / 2688996956405760000 // 22336420328479961316 / 2688996956405760000 // - 35331888421114781580 / 2688996956405760000 // 43920768370565135580 / 2688996956405760000 // - 37088370261379851390 / 2688996956405760000 // 15148337305921759574 / 2688996956405760000 // 15148337305921759574 / 2688996956405760000 // - 37088370261379851390 / 2688996956405760000 // 43920768370565135580 / 2688996956405760000 // - 35331888421114781580 / 2688996956405760000 // 22336420328479961316 / 2688996956405760000 // - 10343692234243192788 / 2688996956405760000 // 4301581538450500095 / 2688996956405760000 // - 926840515700222955 / 2688996956405760000 // 603652082270808125 / 2688996956405760000 // 69028763155644023 / 2688996956405760000 // x[0] = -1.00000000000000000000; x[1] = -0.89473684210526315789; x[2] = -0.78947368421052631579; x[3] = -0.68421052631578947368; x[4] = -0.57894736842105263158; x[5] = -0.47368421052631578947; x[6] = -0.36842105263157894737; x[7] = -0.26315789473684210526; x[8] = -0.15789473684210526316; x[9] = -0.052631578947368421053; x[10] = 0.052631578947368421053; x[11] = 0.15789473684210526316; x[12] = 0.26315789473684210526; x[13] = 0.36842105263157894737; x[14] = 0.47368421052631578947; x[15] = 0.57894736842105263158; x[16] = 0.68421052631578947368; x[17] = 0.78947368421052631579; x[18] = 0.89473684210526315789; x[19] = 1.00000000000000000000; w[0] = 0.025670822345560078100; w[1] = 0.22448968595251886556; w[2] = -0.34467890099030890987; w[3] = 1.5996974366978074270; w[4] = -3.8466730910952978835; w[5] = 8.3065993344729824120; w[6] = -13.139430424771119113; w[7] = 16.333513604742678295; w[8] = -13.792641220001198577; w[9] = 5.6334527526463774045; w[10] = 5.6334527526463774045; w[11] = -13.792641220001198577; w[12] = 16.333513604742678295; w[13] = -13.139430424771119113; w[14] = 8.3065993344729824120; w[15] = -3.8466730910952978835; w[16] = 1.5996974366978074270; w[17] = -0.34467890099030890987; w[18] = 0.22448968595251886556; w[19] = 0.025670822345560078100; } else if ( order == 21 ) { x[0] = -1.00000000000000000000; x[1] = -0.90000000000000000000; x[2] = -0.80000000000000000000; x[3] = -0.70000000000000000000; x[4] = -0.60000000000000000000; x[5] = -0.50000000000000000000; x[6] = -0.40000000000000000000; x[7] = -0.30000000000000000000; x[8] = -0.20000000000000000000; x[9] = -0.10000000000000000000; x[10] = 0.00000000000000000000; x[11] = 0.10000000000000000000; x[12] = 0.20000000000000000000; x[13] = 0.30000000000000000000; x[14] = 0.40000000000000000000; x[15] = 0.50000000000000000000; x[16] = 0.60000000000000000000; x[17] = 0.70000000000000000000; x[18] = 0.80000000000000000000; x[19] = 0.90000000000000000000; x[20] = 1.00000000000000000000; w[0] = 0.023650546498063206389; w[1] = 0.22827543528921394997; w[2] = -0.47295674102285392846; w[3] = 2.4123737869637513288; w[4] = -7.5420634534306609355; w[5] = 20.673596439879602287; w[6] = -45.417631687959024596; w[7] = 83.656114844387109207; w[8] = -128.15055898030800930; w[9] = 165.59456694494570344; w[10] = -180.01073427048578932; w[11] = 165.59456694494570344; w[12] = -128.15055898030800930; w[13] = 83.656114844387109207; w[14] = -45.417631687959024596; w[15] = 20.673596439879602287; w[16] = -7.5420634534306609355; w[17] = 2.4123737869637513288; w[18] = -0.47295674102285392846; w[19] = 0.22827543528921394997; w[20] = 0.023650546498063206389; } else { std::stringstream err ; err << "NCC_SET - Fatal error!\n" << " Illegal value of ORDER = " << order << "Legal values are 1 through 21."; throw Dark_Arts_Exception(SUPPORT_OBJECT , err.str() ); } return; } // ########################################################## // Private Functions // ########################################################## //**************************************************************************** void Quadrule_New::imtqlx( const int n, std::vector<double>& d, std::vector<double>& e, std::vector<double>& z ) const //**************************************************************************** // // Purpose: // // IMTQLX diagonalizes a symmetric tridiagonal matrix. // // Discussion: // // This routine is a slightly modified version of the EISPACK routine to // perform the implicit QL algorithm on a symmetric tridiagonal matrix. // // The authors thank the authors of EISPACK for permission to use this // routine. // // It has been modified to produce the product Q' * Z, where Z is an input // vector and Q is the orthogonal matrix diagonalizing the input matrix. // The changes consist (essentially) of applying the orthogonal transformations // directly to Z as they are generated. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 January 2010 // // Author: // // Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky. // C++ version by John Burkardt. // // Reference: // // Sylvan Elhay, Jaroslav Kautsky, // Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of // Interpolatory Quadrature, // ACM Transactions on Mathematical Software, // Volume 13, Number 4, December 1987, pages 399-415. // // Roger Martin, James Wilkinson, // The Implicit QL Algorithm, // Numerische Mathematik, // Volume 12, Number 5, December 1968, pages 377-383. // // Parameters: // // Input, int N, the order of the matrix. // // Input/output, double D(N), the diagonal entries of the matrix. // On output, the information in D has been overwritten. // // Input/output, double E(N), the subdiagonal entries of the // matrix, in entries E(1) through E(N-1). On output, the information in // E has been overwritten. // // Input/output, double Z(N). On input, a vector. On output, // the value of Q' * Z, where Q is the matrix that diagonalizes the // input symmetric tridiagonal matrix. // { double b = 0.; double c = 0.; double f = 0.; double g = 0.; int i = 0; int ii= 0; /// Set by QUADRULE int itn = 30; int j= 0; int k= 0; int l= 0; int m = 0; int mml= 0; double p = 0.; double prec = 0.; double r = 0.; double s = 0.; prec = r8_epsilon ( ); if ( n == 1 ) { return; } e[n-1] = 0.0; for ( l = 1; l <= n; l++ ) { j = 0; for ( ; ; ) { for ( m = l; m <= n; m++ ) { if ( m == n ) { break; } if ( fabs ( e[m-1] ) <= prec * ( fabs ( d[m-1] ) + fabs ( d[m] ) ) ) { break; } } p = d[l-1]; if ( m == l ) { break; } if ( itn <= j ) { std::stringstream err ; err << "IMTQLX - Fatal error!\n" << " Iteration limit exceeded\n"; throw Dark_Arts_Exception(SUPPORT_OBJECT , err.str() ); } j = j + 1; g = ( d[l] - p ) / ( 2.0 * e[l-1] ); r = sqrt ( g * g + 1.0 ); g = d[m-1] - p + e[l-1] / ( g + fabs ( r ) * r8_sign ( g ) ); s = 1.0; c = 1.0; p = 0.0; mml = m - l; for ( ii = 1; ii <= mml; ii++ ) { i = m - ii; f = s * e[i-1]; b = c * e[i-1]; if ( fabs ( g ) <= fabs ( f ) ) { c = g / f; r = sqrt ( c * c + 1.0 ); e[i] = f * r; s = 1.0 / r; c = c * s; } else { s = f / g; r = sqrt ( s * s + 1.0 ); e[i] = g * r; c = 1.0 / r; s = s * c; } g = d[i] - p; r = ( d[i-1] - g ) * s + 2.0 * c * b; p = s * r; d[i] = g + p; g = c * r - b; f = z[i]; z[i] = s * z[i-1] + c * f; z[i-1] = c * z[i-1] - s * f; } d[l-1] = d[l-1] - p; e[l-1] = g; e[m-1] = 0.0; } } // // Sorting. // for ( ii = 2; ii <= m; ii++ ) { i = ii - 1; k = i; p = d[i-1]; for ( j = ii; j <= n; j++ ) { if ( d[j-1] < p ) { k = j; p = d[j-1]; } } if ( k != i ) { d[k-1] = d[i-1]; d[i-1] = p; p = z[i-1]; z[i-1] = z[k-1]; z[k-1] = p; } } return; } //**************************************************************************** void Quadrule_New::nc_compute ( const int n, const double x_min, const double x_max, const std::vector<double>& x, std::vector<double>& w ) const //**************************************************************************** // // Purpose: // // NC_COMPUTE computes a Newton-Cotes quadrature rule. // // Discussion: // // For the interval [X_MIN,X_MAX], the Newton-Cotes quadrature rule // estimates // // Integral ( X_MIN <= X <= X_MAX ) F(X) dX // // using N abscissas X and weights W: // // Sum ( 1 <= I <= N ) W(I) * F ( X(I) ). // // For the CLOSED rule, the abscissas include the end points. // For the OPEN rule, the abscissas do not include the end points. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified/Author: // // John Burkardt- 17 November 2009 // Peter Maginot- 10 June 2014 // // Parameters: // // Input, int N, the order. // // Input, double X_MIN, X_MAX, the endpoints of the interval. // // Input, double X[N], the abscissas. // // Output, double W[N], the weights. // { std::vector<double> d; int i= 0; int j= 0; int k= 0; double yvala=0.; double yvalb=0.; d.resize(n,0.); for ( i = 1; i <= n; i++ ) { // // Compute the Lagrange basis polynomial which is 1 at XTAB(I), // and zero at the other nodes. // for ( j = 1; j <= n; j++ ) { d[j-1] = 0.0; } d[i-1] = 1.0; for ( j = 2; j <= n; j++ ) { for ( k = j; k <= n; k++ ) { d[n+j-k-1] = ( d[n+j-k-2] - d[n+j-k-1] ) / ( x[n-k] - x[n+j-k-1] ); } } for ( j = 1; j <= n - 1; j++ ) { for ( k = 1; k <= n - j; k++ ) { d[n-k-1] = d[n-k-1] - x[n-k-j] * d[n-k]; } } // // Evaluate the antiderivative of the polynomial at the left and // right endpoints. // yvala = d[n-1] / ( double ) ( n ); for ( j = n - 2; 0 <= j; j-- ) { yvala = yvala * x_min + d[j] / ( double ) ( j + 1 ); } yvala = yvala * x_min; yvalb = d[n-1] / ( double ) ( n ); for ( j = n - 2; 0 <= j; j-- ) { yvalb = yvalb * x_max + d[j] / ( double ) ( j + 1 ); } yvalb = yvalb * x_max; w[i-1] = yvalb - yvala; } return; } //****************************************************************************80 void Quadrule_New::ncc_compute_points ( const int n, std::vector<double>& x ) const //****************************************************************************80 // // Purpose: // // NCC_COMPUTE_POINTS: points of a Newton-Cotes Closed quadrature rule. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified/Author // // John Burkardt- 16 November 2009 // Peter Maginot- 10 June 2014 // // Parameters: // // Input, int N, the order. // // Output, double X[N], the abscissas. // { int i=0; double x_max = 1.0; double x_min = -1.0; if ( n == 1 ) { x[0] = ( x_max + x_min ) / 2.0; } else { for ( i = 0; i < n; i++ ) { x[i] = ( ( double ) ( n - i - 1 ) * x_min + ( double ) ( i ) * x_max ) / ( double ) ( n - 1 ); } } return; } //**************************************************************************** void Quadrule_New::ncc_compute_weights(const int n, std::vector<double>& w) const //**************************************************************************** // // Purpose: // // NCC_COMPUTE_WEIGHTS: weights of a Newton-Cotes Closed quadrature rule. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified/Author: // // John Burkardt- 16 November 2009 // Peter Maginot- 10 June 2014// // // Parameters: // // Input, int N, the order. // // Output, double W[N], the weights. // { int i=0; std::vector<double> x; double x_max = 1.0; double x_min = -1.0; if ( n == 1 ) { w[0] = x_max - x_min; } else { x.resize(n,0.); for ( i = 0; i < n; i++ ) { x[i] = ( double( n - i - 1 ) * x_min + double( i ) * x_max ) / double( n - 1 ); } nc_compute ( n, x_min, x_max, x, w ); } return; } //**************************************************************************** double Quadrule_New::r8_epsilon (void) const //****************************************************************************80 // // Purpose: // // R8_EPSILON returns the R8 roundoff unit. // // Discussion: // // The roundoff unit is a number R which is a power of 2 with the property // that, to the precision of the computer's arithmetic, // 1 < 1 + R // but // 1 = ( 1 + R / 2 ) // // Licensing: // // This code is distributed under the GNU LGPL license. // // Author/Modified: // // John Burkardt- 01 July 2004 // Peter Maginot- 10 June 2014 // // Parameters: // // Output, double R8_EPSILON, the double precision round-off unit. // { double r=1.; while ( 1.0 < (double (1.0 + r) ) ) { r /= 2.; } return ( 2.0 * r ); } //**************************************************************************** double Quadrule_New::r8_max ( const double x, const double y ) const //**************************************************************************** // // Purpose: // // R8_MAX returns the maximum of two R8's. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified/Author: // // John Burkardt- 18 August 2004 // Peter Maginot- 10 June 2014 // // Parameters: // // Input, double X, Y, the quantities to compare. // // Output, double R8_MAX, the maximum of X and Y. // { double value=0.; if ( y < x ) { value = x; } else { value = y; } return value; } //**************************************************************************** double Quadrule_New::r8_sign ( const double x ) const //**************************************************************************** // // Purpose: // // R8_SIGN returns the sign of an R8. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Author/Modified: // // John Burkardt- 18 October 2004 // Peter Maginot- 10 June 2014 // // Parameters: // // Input, double X, the number whose sign is desired. // // Output, double R8_SIGN, the sign of X. // { double value=0.; if ( x < 0.0 ) { value = -1.0; } else { value = 1.0; } return value; } //**************************************************************************** void Quadrule_New::r8vec_reverse ( const int n, std::vector<double>& a ) const //**************************************************************************** // // Purpose: // // R8VEC_REVERSE reverses the elements of an R8VEC. // // Discussion: // // An R8VEC is a vector of double precision values. // // Input: // // N = 5, // A = ( 11.0, 12.0, 13.0, 14.0, 15.0 ) // // Output: // // A = ( 15.0, 14.0, 13.0, 12.0, 11.0 ) // // Licensing: // // This code is distributed under the GNU LGPL license. // // Author/Modified: // // John Burkardt- 30 April 2006 // // Peter Maginot- 10 June 2014 // // Parameters: // // Input, int N, the number of entries in the vector. // // Input/output, double A[N], the vector to be reversed. // { int i=0; double temp=0.; for ( i = 0; i < n/2; i++ ) { temp = a[i]; a[i] = a[n-1-i]; a[n-1-i] = temp; } return; }
38.210149
153
0.661431
pgmaginot
f5524c368f8823d5452abd3fc4f63f49fdf039d1
7,459
cpp
C++
Pelican/src/Pelican/Renderer/Model.cpp
SeppahBaws/PelicanEngine
7bc5f5e55993220d731ad6a5dbff1470ad4c6ee5
[ "MIT" ]
1
2022-03-01T10:36:57.000Z
2022-03-01T10:36:57.000Z
Pelican/src/Pelican/Renderer/Model.cpp
SeppahBaws/PelicanEngine
7bc5f5e55993220d731ad6a5dbff1470ad4c6ee5
[ "MIT" ]
1
2021-09-27T16:47:43.000Z
2021-09-27T16:47:43.000Z
Pelican/src/Pelican/Renderer/Model.cpp
SeppahBaws/PelicanEngine
7bc5f5e55993220d731ad6a5dbff1470ad4c6ee5
[ "MIT" ]
null
null
null
#include "PelicanPCH.h" #include "Model.h" #include "Pelican/Assets/AssetManager.h" #include "Pelican/Renderer/Camera.h" #include "Pelican/Renderer/Mesh.h" #include "Pelican/Renderer/VulkanHelpers.h" #include "Pelican/Renderer/VulkanTexture.h" #include "Pelican/Renderer/VulkanRenderer.h" #include <logtools.h> #pragma warning(push) #pragma warning(disable:4996) #pragma warning(disable:4840) #pragma warning(disable:4201) // #define TINYGLTF_IMPLEMENTATION // #define STB_IMAGE_WRITE_IMPLEMENTATION #define TINYGLTF_NOEXCEPTION #define JSON_NOEXCEPTION #include <glm/vec3.hpp> #include <glm/gtc/type_ptr.hpp> #include "tiny_gltf.h" #pragma warning(pop) #include <assimp/Importer.hpp> #include <assimp/postprocess.h> #include <assimp/scene.h> namespace Pelican { Model::Model(const std::string& file) : m_AssetPath(file) { Initialize(); } Model::~Model() { // Cleanup the material textures for (GltfMaterial& mat : m_Materials) { AssetManager::GetInstance().UnloadTexture(mat.m_pAlbedoTexture); AssetManager::GetInstance().UnloadTexture(mat.m_pMetallicRoughnessTexture); AssetManager::GetInstance().UnloadTexture(mat.m_pNormalTexture); AssetManager::GetInstance().UnloadTexture(mat.m_pAOTexture); AssetManager::GetInstance().UnloadTexture(mat.m_pEmissiveTexture); } vkDestroyDescriptorPool(VulkanRenderer::GetDevice(), m_DescriptorPool, nullptr); for (size_t i = 0; i < m_Meshes.size(); i++) { m_Meshes[i].Cleanup(); } for (size_t i = 0; i < m_pTextures.size(); i++) { delete m_pTextures[i]; m_pTextures[i] = nullptr; } m_pTextures.clear(); delete m_pWhiteTexture; } void Model::UpdateDrawData(const glm::mat4& model, const glm::mat4& view, const glm::mat4& proj) { for (size_t i = 0; i < m_Meshes.size(); i++) { m_Meshes[i].Update(model, view, proj); } } void Model::Draw() { for (size_t i = 0; i < m_Meshes.size(); i++) { m_Meshes[i].Draw(); } } void Model::Initialize() { Assimp::Importer importer; const aiScene* pScene = importer.ReadFile(m_AssetPath, aiProcessPreset_TargetRealtime_Quality | aiProcess_FlipUVs); if (!pScene || pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !pScene->mRootNode) { Logger::LogError("Assimp import error: %s", importer.GetErrorString()); return; } // Materials for (uint32_t i = 0; i < pScene->mNumMaterials; i++) { aiMaterial* pMaterial = pScene->mMaterials[i]; GltfMaterial mat{}; aiString texturePath; aiColor4D textureColor; ai_real textureFloat; if (AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_DIFFUSE, &textureColor)) mat.m_AlbedoColor = glm::vec4(textureColor.r, textureColor.g, textureColor.b, textureColor.a); if (AI_SUCCESS == pMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &texturePath)) mat.m_pAlbedoTexture = AssetManager::GetInstance().LoadTexture(GetAbsolutePath(texturePath.C_Str())); else mat.m_pAlbedoTexture = AssetManager::GetInstance().LoadTexture("res/textures/default-white.png"); if (AI_SUCCESS == aiGetMaterialFloat(pMaterial, AI_MATKEY_METALLIC_FACTOR, &textureFloat)) mat.m_MetallicFactor = textureFloat; if (AI_SUCCESS == aiGetMaterialFloat(pMaterial, AI_MATKEY_ROUGHNESS_FACTOR, &textureFloat)) mat.m_RoughnessFactor = textureFloat; if (AI_SUCCESS == pMaterial->GetTexture(aiTextureType_METALNESS, 0, &texturePath)) mat.m_pMetallicRoughnessTexture = AssetManager::GetInstance().LoadTexture(GetAbsolutePath(texturePath.C_Str())); else mat.m_pMetallicRoughnessTexture = AssetManager::GetInstance().LoadTexture("res/textures/default-white.png"); if (AI_SUCCESS == pMaterial->GetTexture(aiTextureType_NORMALS, 0, &texturePath)) mat.m_pNormalTexture = AssetManager::GetInstance().LoadTexture(GetAbsolutePath(texturePath.C_Str())); else mat.m_pNormalTexture = AssetManager::GetInstance().LoadTexture("res/textures/default-normal.png"); if (AI_SUCCESS == pMaterial->GetTexture(aiTextureType_AMBIENT_OCCLUSION, 0, &texturePath)) mat.m_pAOTexture = AssetManager::GetInstance().LoadTexture(GetAbsolutePath(texturePath.C_Str())); else mat.m_pAOTexture = AssetManager::GetInstance().LoadTexture("res/textures/default-white.png"); if (AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_EMISSIVE_INTENSITY, &textureColor)) mat.m_EmissiveFactor = glm::vec3(textureColor.r, textureColor.g, textureColor.b); if (AI_SUCCESS == pMaterial->GetTexture(aiTextureType_EMISSIVE, 0, &texturePath)) mat.m_pEmissiveTexture = AssetManager::GetInstance().LoadTexture(GetAbsolutePath(texturePath.C_Str())); else mat.m_pEmissiveTexture = AssetManager::GetInstance().LoadTexture("res/textures/default-white.png"); m_Materials.push_back(mat); } ProcessNode(pScene->mRootNode, pScene); CreateDescriptorPool(); } void Model::ProcessNode(aiNode* pNode, const aiScene* pScene) { // Process all the node's meshes (if any) for (unsigned int i = 0; i < pNode->mNumMeshes; i++) { aiMesh* pMesh = pScene->mMeshes[pNode->mMeshes[i]]; m_Meshes.push_back(ProcessMesh(pMesh)); } // Then do the same for each of its children for (unsigned int i = 0; i < pNode->mNumChildren; i++) { ProcessNode(pNode->mChildren[i], pScene); } } Mesh Model::ProcessMesh(aiMesh* pMesh) { std::vector<Vertex> vertices; std::vector<uint32_t> indices; // Vertices for (uint32_t i = 0; i < pMesh->mNumVertices; i++) { Vertex vertex{}; vertex.pos = glm::vec3(0); vertex.normal = glm::vec3(0); vertex.tangent = glm::vec3(0, 0, 1); if (pMesh->mVertices) { vertex.pos = glm::vec3(pMesh->mVertices[i].x, pMesh->mVertices[i].y, pMesh->mVertices[i].z); } if (pMesh->mNormals) { vertex.normal = glm::vec3(pMesh->mNormals[i].x, pMesh->mNormals[i].y, pMesh->mNormals[i].z); } if (pMesh->mTangents) { vertex.tangent = glm::vec3(pMesh->mTangents[i].x, pMesh->mTangents[i].y, pMesh->mTangents[i].z); } if (pMesh->mTextureCoords[0]) { vertex.texCoord = glm::vec2(pMesh->mTextureCoords[0][i].x, pMesh->mTextureCoords[0][i].y); } else { Logger::LogWarning("Mesh: UV coordinates not found! Default to (0, 0)"); vertex.texCoord = glm::vec2(0); } vertices.push_back(vertex); } // Indices for (uint32_t i = 0; i < pMesh->mNumFaces; i++) { aiFace face = pMesh->mFaces[i]; for (uint32_t j = 0; j < face.mNumIndices; j++) { indices.push_back(face.mIndices[j]); } } Mesh mesh{ vertices, indices, pMesh->mMaterialIndex }; mesh.CreateBuffers(); return mesh; } void Model::CreateDescriptorPool() { vk::DescriptorPoolSize poolSize(vk::DescriptorType::eUniformBuffer, static_cast<uint32_t>(m_Meshes.size())); vk::DescriptorPoolCreateInfo createInfo = vk::DescriptorPoolCreateInfo() .setPoolSizes(poolSize) .setMaxSets(static_cast<uint32_t>(m_Meshes.size())); try { m_DescriptorPool = VulkanRenderer::GetDevice().createDescriptorPool(createInfo); } catch (vk::SystemError& e) { throw std::runtime_error("Failed to create descriptor pool: "s + e.what()); } for (size_t i = 0; i < m_Meshes.size(); i++) { m_Meshes[i].CreateDescriptorSet(this, m_DescriptorPool); } } std::string Model::GetAbsolutePath(const std::string& uri) const { std::string absolutePath = m_AssetPath; absolutePath = absolutePath.substr(0, m_AssetPath.find_last_of('/') + 1); absolutePath += uri; return absolutePath; } }
29.955823
117
0.710417
SeppahBaws
f5555d0582a9f0a44c73b58c9422c98e0042e89d
957
cpp
C++
mysql_test/mysql_test.cpp
iassasin/wschatserver
f5b1ae1a37e534bfee93102603f93e85642e230d
[ "MIT" ]
9
2017-01-29T13:27:28.000Z
2020-10-16T19:25:38.000Z
mysql_test/mysql_test.cpp
iassasin/wschatserver
f5b1ae1a37e534bfee93102603f93e85642e230d
[ "MIT" ]
27
2016-11-24T12:42:30.000Z
2022-01-05T20:39:35.000Z
mysql_test/mysql_test.cpp
iassasin/wschatserver
f5b1ae1a37e534bfee93102603f93e85642e230d
[ "MIT" ]
1
2017-01-29T13:25:06.000Z
2017-01-29T13:25:06.000Z
#include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/resultset.h> #include <cppconn/statement.h> #include <iostream> #include "../db.hpp" using namespace std; int main_old(int argc, char **argv){ sql::Connection *con; sql::mysql::MySQL_Driver driver; con = driver.connect("tcp://localhost:3306", "www", ""); if (!con->isClosed()){ cout << "Connect ok" << endl; auto stmt = con->createStatement(); stmt->execute("use www"); auto rs = stmt->executeQuery("SELECT id, login FROM users"); while (rs->next()){ cout << rs->getInt("id") << " -> " << rs->getString("login") << endl; } delete rs; delete stmt; } delete con; return 0; } int main(int argc, char **argv){ Database db; auto stmt = db.statement(); auto rs = stmt->executeQuery("SELECT id, login FROM users ORDER BY id LIMIT 0, 5"); while (rs->next()){ cout << rs->getInt("id") << " -> " << rs->getString("login") << endl; } return 0; }
21.266667
84
0.624869
iassasin
f555ab57f2cde31355783205195880c19add3d99
1,422
cpp
C++
eagleye_util/nmea2fix/src/nmea2fix_node.cpp
takahirokashimoto/eagleye
c80be13b0aba27f9e82d352a80da40300f28d395
[ "BSD-3-Clause" ]
329
2020-03-19T00:41:00.000Z
2022-03-31T05:52:33.000Z
eagleye_util/nmea2fix/src/nmea2fix_node.cpp
takahirokashimoto/eagleye
c80be13b0aba27f9e82d352a80da40300f28d395
[ "BSD-3-Clause" ]
22
2020-03-20T09:14:19.000Z
2022-03-24T23:47:55.000Z
eagleye_util/nmea2fix/src/nmea2fix_node.cpp
takahirokashimoto/eagleye
c80be13b0aba27f9e82d352a80da40300f28d395
[ "BSD-3-Clause" ]
79
2020-03-19T03:08:29.000Z
2022-03-09T00:54:03.000Z
#include "ros/ros.h" #include "nmea2fix/nmea2fix.hpp" static ros::Publisher pub1,pub2; static nmea_msgs::Sentence sentence; static std::string sub_topic_name,pub_fix_topic_name,pub_gga_topic_name; static bool output_gga; void nmea_callback(const nmea_msgs::Sentence::ConstPtr &msg) { nmea_msgs::Gpgga gga; sensor_msgs::NavSatFix fix; sentence.header = msg->header; sentence.sentence = msg->sentence; nmea2fix_converter(sentence, &fix, &gga); if (fix.header.stamp.toSec() != 0) { gga.header.frame_id = fix.header.frame_id = "gps"; pub1.publish(fix); if(output_gga) pub2.publish(gga); } } int main(int argc, char** argv) { ros::init(argc, argv, "nmea2fix_node"); ros::NodeHandle n; n.getParam("sub_topic_name",sub_topic_name); n.getParam("pub_fix_topic_name",pub_fix_topic_name); n.getParam("pub_gga_topic_name",pub_gga_topic_name); n.getParam("output_gga",output_gga); std::cout<< "sub_topic_name "<<sub_topic_name<<std::endl; std::cout<< "pub_fix_topic_name "<<pub_fix_topic_name<<std::endl; std::cout<< "pub_gga_topic_name "<<pub_gga_topic_name<<std::endl; std::cout<< "output_gga "<<output_gga<<std::endl; ros::Subscriber sub = n.subscribe(sub_topic_name, 1000, nmea_callback); pub1 = n.advertise<sensor_msgs::NavSatFix>(pub_fix_topic_name, 1000); if(output_gga) pub2 = n.advertise<nmea_msgs::Gpgga>(pub_gga_topic_name, 1000); ros::spin(); return 0; }
29.020408
80
0.729958
takahirokashimoto
f55a9c94da45dcc98ad6a3668e218f00c1b7fa7c
27,477
cpp
C++
Sea_Chain/scenes/scene_tutorial_main.cpp
Vvaridus/SeaChain
5e48925161e6244245f3af21bd8a1cb7a7acfbd4
[ "MIT" ]
null
null
null
Sea_Chain/scenes/scene_tutorial_main.cpp
Vvaridus/SeaChain
5e48925161e6244245f3af21bd8a1cb7a7acfbd4
[ "MIT" ]
null
null
null
Sea_Chain/scenes/scene_tutorial_main.cpp
Vvaridus/SeaChain
5e48925161e6244245f3af21bd8a1cb7a7acfbd4
[ "MIT" ]
null
null
null
#include "scene_tutorial_main.h" #include "../components/cmp_player_physics.h" #include "../components/cmp_sprite.h" #include "../game.h" #include <LevelSystem.h> #include <iostream> #include <thread> #include "../components/cmp_basic_movement.h" #include <logger.h> #include "../weapon.h" #include "../components/cmp_inventory.h" #include "../gameData.h" #include "../components/cmp_health.h" #include <SFML/Audio/Music.hpp> #include <random> #include "../components/cmp_button.h" #include "../components/cmp_ai_steering.h" #include "../components/cmp_path_follow.h" #include "../helpers/astar.h" #include "../components/cmp_text.h" using namespace std; using namespace sf; static shared_ptr<Entity> player; static shared_ptr<Entity> enemy; static Image playerImage; static Texture playerTexture; static IntRect playerRect = IntRect(64, 0, 64, 64); static Image enemyImage; static Texture enemyTexture; static IntRect enemyRect = IntRect(0, 0, 64, 64); static Image monkeyImage; static Texture monkeyTexture; static IntRect monkeyRect = IntRect(0, 0, 64, 64); static sf::Clock itemInfoTimer; static bool pause = false; std::shared_ptr<ButtonComponent> btnMenu; std::shared_ptr<ButtonComponent> btnQuit; void TutorialMain::Load() { Logger::addEvent(Logger::EventType::Scene, Logger::Action::Loading, "Main Island"); ls::loadLevelFile("resources/map.txt", 64); playerImage.loadFromFile("resources/textures/SeaChainPlayer.png"); playerTexture.loadFromImage(playerImage); enemyImage.loadFromFile("resources/textures/SeaChainEnemy.png"); enemyTexture.loadFromImage(enemyImage); monkeyImage.loadFromFile("resources/textures/SeaChainMonkey.png"); monkeyTexture.loadFromImage(monkeyImage); auto ins = Data::getInstance(); auto debug = ins->getDebug(); pause = false; auto windowSize = Engine::getWindowSize(); auto ho = windowSize.y - (ls::getHeight() * 64.f); ls::setOffset(Vector2f(0, ho)); // Allow us to randomly shuffle a vector std::random_device rd; auto rng = std::default_random_engine{ rd() }; // create basic world textures { vector<IntRect> bounds = { IntRect(0, 0, 64, 64) }; createTexture("resources/textures/SeaChainWorldTilesv.png", bounds, ls::findTiles(ls::GRASS), "grass"); bounds = { IntRect(64, 0, 64, 64) }; createTexture("resources/textures/SeaChainWorldTilesv.png", bounds, ls::findTiles(ls::SAND), "sand"); bounds = { IntRect(128, 0, 64, 64) }; createTexture("resources/textures/SeaChainWorldTilesv.png", bounds, ls::findTiles(ls::DIRT), "dirt"); bounds = { IntRect(192, 0, 64, 64) }; createTexture("resources/textures/SeaChainWorldTilesv.png", bounds, ls::findTiles(ls::STONE), "stone"); bounds = { IntRect(256, 0, 64, 64) }; createTexture("resources/textures/SeaChainWorldTilesv.png", bounds, ls::findTiles(ls::WATER), "water"); } createWaterBlend(); // add extra entities rocks, skeletons, trees { // This will draw a tree over GRASS tiles // Get a list of all grass tiles and then shuffle the vector // get a random numberOfTiles of 0-80% of the vector size // then get a random tile from the list and add that to a vector to be set to a tree. auto tileList = ls::findTiles(ls::GRASS); std::shuffle(std::begin(tileList), std::end(tileList), rng); std::vector<sf::Vector2ul> randomTiles; int numberOfTiles = randomNumber(0, 0.8 * (tileList.size() - 1)); for (int i = 0; i < numberOfTiles; i++) { int rand = randomNumber(0, tileList.size() - 1); randomTiles.push_back(tileList[rand]); } std::vector<sf::IntRect> bounds = { sf::IntRect(192, 64, 64, 64), sf::IntRect(256, 64, 64, 64), sf::IntRect(320, 64, 64, 64) }; createTexture("resources/textures/SeaChainWorldTilesv.png", bounds, randomTiles, "tree"); randomTiles.clear(); tileList.clear(); // This will draw a rock over STONE tiles // Get a list of all stone tiles and then shuffle the vector // get a random numberOfTiles of 0-40% of the vector size // then get a random tile from the list and add that to a vector to be set to a rock. tileList = ls::findTiles(ls::STONE); std::shuffle(std::begin(tileList), std::end(tileList), rng); numberOfTiles = randomNumber(0, 0.4 * (tileList.size() - 1)); for (int i = 0; i < numberOfTiles; i++) { int rand = randomNumber(0, tileList.size() - 1); randomTiles.push_back(tileList[rand]); } bounds = { sf::IntRect(64, 64, 64, 64), sf::IntRect(128, 64, 64, 64) }; createTexture("resources/textures/SeaChainWorldTilesv.png", bounds, randomTiles, "rock"); randomTiles.clear(); tileList.clear(); // This will draw a skeleton on DIRT tiles // Get a list of all dirt tiles and then shuffle the vector // get a random numberOfTiles of 0-5% of the vector size // then get a random tile from the list and add that to a vector to be set to a skeleton. tileList = ls::findTiles(ls::DIRT); std::shuffle(std::begin(tileList), std::end(tileList), rng); numberOfTiles = randomNumber(1, 0.05 * (tileList.size() - 1)); for (int i = 0; i < numberOfTiles; i++) { int rand = randomNumber(0, tileList.size() - 1); randomTiles.push_back(tileList[rand]); } bounds = { sf::IntRect(0, 64, 64, 64) }; createTexture("resources/textures/SeaChainWorldTilesv.png", bounds, randomTiles, "skeleton"); randomTiles.clear(); tileList.clear(); // This will draw a red cross on sandtiles // Get a list of all dirt tiles and then shuffle the vector // get a random numberOfTiles of 0-5% of the vector size // then get a random tile from the list and add that to a vector to be set to a red cross. tileList = ls::findTiles(ls::SAND); std::shuffle(std::begin(tileList), std::end(tileList), rng); numberOfTiles = randomNumber(1, 0.05 * (tileList.size() - 1)); for (int i = 0; i < numberOfTiles; i++) { int rand = randomNumber(0, tileList.size() - 1); randomTiles.push_back(tileList[rand]); } bounds = { sf::IntRect(0, 0, 64, 64) }; createTexture("resources/textures/redx.png", bounds, randomTiles, "xspot"); randomTiles.clear(); tileList.clear(); // This will draw a tree over GRASS tiles // Get a list of all grass tiles and then shuffle the vector // get a random numberOfTiles of 0-80% of the vector size // then get a random tile from the list and add that to a vector to be set to a tree. tileList = ls::findTiles(ls::WATER); std::shuffle(std::begin(tileList), std::end(tileList), rng); numberOfTiles = randomNumber(0, 0.01 * (tileList.size())); for (int i = 0; i < numberOfTiles; i++) { int rand = randomNumber(0, tileList.size() - 1); randomTiles.push_back(tileList[rand]); } bounds = { sf::IntRect(0, 0, 128, 128) }; createTexture("resources/textures/shipWreck.png", bounds, randomTiles, "shipWreck"); randomTiles.clear(); tileList.clear(); } // Add bed to map { auto tileList = ls::findTiles(ls::STONE); std::shuffle(std::begin(tileList), std::end(tileList), rng); std::vector<sf::Vector2ul> randomTiles; Texture bedSheet; bedSheet.loadFromFile("resources/textures/Bed.png", IntRect(0, 0, 64, 64)); shared_ptr<Texture> bedSprite = make_shared<Texture>(bedSheet); auto bed = makeEntity(); bed->addTag("bed"); bed->setPosition(ls::getTilePosition(tileList[randomNumber(0, tileList.size() - 1)])); auto bedSpriteComp = bed->addComponent<SpriteComponent>(); bedSpriteComp->setTexure(bedSprite); } // Create player { auto ins = Data::getInstance(); if (ins->getPlayer() == nullptr) { ins->setPlayer(makeEntity()); player = ins->getPlayer(); player->addTag("player"); player->setPosition(Vector2f((Engine::getWindowSize().x / 2), Engine::getWindowSize().y / 2)); player->addComponent<HealthComponent>(); auto s = player->addComponent<SpriteComponent>(); s->getSprite().setTexture(playerTexture); s->getSprite().setTextureRect(playerRect); s->getSprite().setOrigin(32.f, 32.f); auto b = player->addComponent<BasicMovementComponent>(); b->setSpeed(120.f); player->addComponent<InventoryComponent>(); } else { player = ins->getPlayer(); player->setPosition(Vector2f((Engine::getWindowSize().x / 2), Engine::getWindowSize().y / 2)); // Add the entity back to the list to be rendered, it was removed earlier. tutorialMain.ents.list.push_back(player); } // Ohhh whats this? { if (ins->getBiscuit()) { Texture spritesheet; spritesheet.loadFromFile("resources/textures/ShipBiscuit.png", IntRect(0, 0, 64, 64)); shared_ptr<Texture> spriteBiscuit = make_shared<Texture>(spritesheet); auto p = ins->getPlayer(); auto sprite = p->GetCompatibleComponent<SpriteComponent>()[0]; sprite->setTexure(spriteBiscuit); sprite->getSprite().setTextureRect(IntRect(0, 0, 64, 64)); } else { auto p = ins->getPlayer(); auto sprite = p->GetCompatibleComponent<SpriteComponent>()[0]; sprite->getSprite().setTexture(playerTexture); sprite->getSprite().setTextureRect(playerRect); } } } // Create enemies { enemy = nullptr; enemy = makeEntity(); enemy->addTag("enemy"); enemy->setPosition(Vector2f(384, 376)); //THIS MUST COME BEFORE MOVEMENT! enemy->addComponent<PathfindingComponent>(); enemy->addComponent<BasicAiMovementComponent>(); auto s = enemy->addComponent<SpriteComponent>(); s->getSprite().setTexture(enemyTexture); s->getSprite().setTextureRect(enemyRect); s->getSprite().setOrigin(32.f, 32.f); } random_device dev; default_random_engine engine(dev()); uniform_real_distribution<float> x_dist(0.0f, Engine::GetWindow().getSize().x); uniform_real_distribution<float> y_dist(0.0f, Engine::GetWindow().getSize().y); //Monkey Code for (size_t n = 0; n < 1; n++) { auto enemy = makeEntity(); enemy->setPosition(Vector2f((Engine::getWindowSize().x / 2), Engine::getWindowSize().y / 2 + 32)); enemy->addTag("enemy"); auto s = enemy->addComponent<SpriteComponent>(); s->getSprite().setTexture(monkeyTexture); s->getSprite().setTextureRect(monkeyRect); s->getSprite().setOrigin(32.f, 32.f); enemy->addComponent<SteeringComponent>(player.get()); //enemy->addComponent<BasicAiMovementComponent>(); }; // Draw the UI overlay { // load the sprite Texture mainBanner; mainBanner.loadFromFile("resources/textures/SeaChainMainBanner.png", IntRect(0, 0, 1920, 1080)); shared_ptr<Texture> spriteBanner = make_shared<Texture>(mainBanner); Texture healthBar; healthBar.loadFromFile("resources/textures/SeaChainHealthBar.png", IntRect(0, 0, 224, 33)); shared_ptr<Texture> spriteHealth = make_shared<Texture>(healthBar); // set the position, add a tag, add the sprite component with the texture auto banner = makeEntity(); banner->addTag("mainBanner"); banner->setPosition(Vector2f(windowSize.x / 2, windowSize.y / 2)); auto bannerSprite = banner->addComponent<SpriteComponent>(); bannerSprite->setTexure(spriteBanner); bannerSprite->setOrigin(Vector2f(windowSize.x / 2, windowSize.y / 2)); auto textBox = banner->addComponent<TextComponent>(to_string(ins->getPlayer()->GetCompatibleComponent<InventoryComponent>()[0]->getBiscuits())); textBox->setFillColor(Color(255, 255, 255)); textBox->setOutline(Color(0, 0, 0)); textBox->setOutlineThickness(2.f); textBox->setCharSize(36); textBox->setPosition(Vector2f(728, 50)); textBox->setOrigin(Vector2f(textBox->getBounds().width / 2, textBox->getBounds().height / 2)); auto healthBanner = makeEntity(); healthBanner->addTag("healthUIBar"); healthBanner->setPosition(Vector2f(256, 49)); auto healthSprite = healthBanner->addComponent<SpriteComponent>(); healthSprite->setTexure(spriteHealth); } // text to display item added { auto text = makeEntity(); text->setPosition(Vector2f(windowSize.x / 2, windowSize.y / 2)); text->addTag("itemText"); auto textBox = text->addComponent<TextComponent>("Item added"); textBox->setCharSize(36); textBox->setFillColor(Color(255, 0, 0)); textBox->setPosition(Vector2f(windowSize.x / 2, windowSize.y / 2)); textBox->setOutline(Color(0, 0, 0)); textBox->setOutlineThickness(2.f); textBox->setOrigin(Vector2f(textBox->getBounds().width / 2, textBox->getBounds().height / 2)); text->setVisible(false); } // Draw/create the quit confirmation box with its two buttons { // load the sprite Texture box; box.loadFromFile("resources/textures/QuitMenu.png", IntRect(0, 0, 1920, 1080)); shared_ptr<Texture> spriteBox = make_shared<Texture>(box); // set the position, add a tag, add the sprite component with the texture auto popup = makeEntity(); popup->addTag("quitPopup"); popup->setPosition(Vector2f(windowSize.x / 2, windowSize.y / 2)); auto popupSprite = popup->addComponent<SpriteComponent>(); popupSprite->setTexure(spriteBox); popupSprite->setOrigin(Vector2f(windowSize.x / 2, windowSize.y / 2)); popup->setVisible(false); // draw/create the menu button { auto menuButton = makeEntity(); menuButton->addTag("btnMenu"); menuButton->setPosition(Vector2f(770, 565)); auto buttonShape = menuButton->addComponent<ShapeComponent>(); buttonShape->setShape<RectangleShape>(Vector2f(150, 43)); buttonShape->getShape().setFillColor(Color::Transparent); buttonShape->getShape().setOutlineThickness(2); buttonShape->getShape().setOutlineColor(Color::White); buttonShape->setVisibility(debug); auto bounds = buttonShape->getBounds(); btnMenu = menuButton->addComponent<ButtonComponent>(); Vector2f xy = Vector2f(menuButton->getPosition().x + (bounds->width / 2), (menuButton->getPosition().y + (bounds->height / 2))); btnMenu->setBounds(xy, Vector2f(bounds->width, bounds->height)); btnMenu->setInteraction(false); } // draw/create the quit button { auto exitButton = makeEntity(); exitButton->addTag("btnQuit"); exitButton->setPosition(Vector2f(940, 565)); auto buttonShape = exitButton->addComponent<ShapeComponent>(); buttonShape->setShape<RectangleShape>(Vector2f(150, 43)); buttonShape->getShape().setFillColor(Color::Transparent); buttonShape->getShape().setOutlineThickness(2); buttonShape->getShape().setOutlineColor(Color::White); buttonShape->setVisibility(debug); auto bounds = buttonShape->getBounds(); btnQuit = exitButton->addComponent<ButtonComponent>(); Vector2f xy = Vector2f(exitButton->getPosition().x + (bounds->width / 2), (exitButton->getPosition().y + (bounds->height / 2))); btnQuit->setBounds(xy, Vector2f(bounds->width, bounds->height)); btnQuit->setInteraction(false); } } //Simulate long loading times //std::this_thread::sleep_for(std::chrono::milliseconds(3000)); Logger::addEvent(Logger::EventType::Scene, Logger::Action::Loaded, "Main Island"); setLoaded(true); } void TutorialMain::UnLoad() { Logger::addEvent(Logger::EventType::Scene, Logger::Action::Unloaded, "Main Island"); player.reset(); Nullify(); ls::unload(); Scene::UnLoad(); } void TutorialMain::Update(const double& dt) { bool changingScenes = false; auto ins = Data::getInstance(); auto keybinds = ins->getKeybinds(); auto enemy_Path_Node_One = Vector2i(6, 4); auto enemy_Path_Node_Two = Vector2i(7, 11); // if enemy within range go into combat if (length(player->getPosition() - enemy->getPosition()) < 50 && pause == false) { ins->setPlayer(player); changingScenes = true; enemy->setForDelete(); Engine::ChangeScene(&combat); } // if player is dead go back to main menu if (!ins->getPlayer()->isAlive()) { Engine::ChangeScene(&menu); changingScenes = true; } if (!changingScenes) { if (pause == false) { // Movement annimation { if (ins->getBiscuit() == false) { auto s = player->GetCompatibleComponent<SpriteComponent>()[0]; static sf::Clock clock; float elapsed = clock.getElapsedTime().asSeconds(); //PLAYER ANIMATION FOR UP if (Keyboard::isKeyPressed(keybinds->find("MOVE_UP")->second)) { if (elapsed > 0.2f) { if (playerRect.left == 128) { playerRect.top = 192; playerRect.left = 64; s->getSprite().setTextureRect(playerRect); clock.restart(); } else { playerRect.top = 192; playerRect.left += 64; s->getSprite().setTextureRect(playerRect); clock.restart(); } } } //PLAYER ANIMATION FOR DOWN else if (Keyboard::isKeyPressed(keybinds->find("MOVE_DOWN")->second)) { if (elapsed > 0.2f) { if (playerRect.left == 128) { playerRect.top = 0; playerRect.left = 64; s->getSprite().setTextureRect(playerRect); clock.restart(); } else { playerRect.top = 0; playerRect.left += 64; s->getSprite().setTextureRect(playerRect); clock.restart(); } } } //PLAYER ANIMATION FOR LEFT else if (Keyboard::isKeyPressed(keybinds->find("MOVE_LEFT")->second)) { if (elapsed > 0.15f) { if (playerRect.left == 128) { playerRect.top = 128; playerRect.left = 0; s->getSprite().setTextureRect(playerRect); clock.restart(); } else { playerRect.top = 128; playerRect.left += 64; s->getSprite().setTextureRect(playerRect); clock.restart(); } } } //PLAYER ANIMATION FOR RIGHT else if (Keyboard::isKeyPressed(keybinds->find("MOVE_RIGHT")->second)) { if (elapsed > 0.15f) { if (playerRect.left == 128) { playerRect.top = 64; playerRect.left = 0; s->getSprite().setTextureRect(playerRect); clock.restart(); } else { playerRect.top = 64; playerRect.left += 64; s->getSprite().setTextureRect(playerRect); clock.restart(); } } } s->getSprite().setTextureRect(playerRect); } } auto enemy_current_pos = Vector2i(enemy->getPosition().x / 64, (enemy->getPosition().y - ls::getOffset().y) / 64); static bool test = true; // BOOL TRUE TEST BEFORE REMOVING BOOL Ensure enemy has pathfind component BEFORE move! if (enemy_current_pos == enemy_Path_Node_One) { auto path = pathFind(enemy_current_pos, enemy_Path_Node_Two); auto pathComp = enemy->GetCompatibleComponent<PathfindingComponent>()[0]; pathComp->setPath(path); test = false; } // else if (enemy_current_pos == enemy_Path_Node_Two) { auto path = pathFind(enemy_current_pos, enemy_Path_Node_One); auto pathComp = enemy->GetCompatibleComponent<PathfindingComponent>()[0]; pathComp->setPath(path); test = true; } // update biscuit count { auto text = this->ents.find("mainBanner")[0]->GetCompatibleComponent<TextComponent>()[0]; text->SetText(to_string(ins->getPlayer()->GetCompatibleComponent<InventoryComponent>()[0]->getBiscuits())); text->setOrigin(Vector2f(text->getBounds().width / 2, text->getBounds().height / 2)); } updateHealthBars(dt, changingScenes); Scene::Update(dt); } else { btnMenu->update(dt); btnQuit->update(dt); } { auto textbox = this->ents.find("itemText")[0]; if (itemInfoTimer.getElapsedTime().asSeconds() > 5 && textbox->isVisible() == true) { textbox->setVisible(false); } } checkEventPresses(dt, changingScenes); } } void TutorialMain::checkEventPresses(const double& dt, bool& changingScenes) { static sf::Clock bedCooldown; static float triggertime = 0.0f; triggertime -= dt; auto ins = Data::getInstance(); auto keybinds = ins->getKeybinds(); if (sf::Keyboard::isKeyPressed(keybinds->find("INTERACT")->second) && pause == false) { auto bed = this->ents.find("bed")[0]; auto skeleton = this->ents.find("skeleton"); auto xspot = this->ents.find("xspot"); // check the player is close to the bed if (length(player->getPosition() - bed->getPosition()) < ls::getTileSize()) { // clock counter as a cooldown for using the bed, can only use it once ever 1 minute (its in seconds) if (bedCooldown.getElapsedTime().asSeconds() > 5) { // get player health component and set the health to max health. auto player = ins->getPlayer(); ins->setBiscuit(false); auto health = player->GetCompatibleComponent<HealthComponent>()[0]; health->setHealth(health->getMaxHealth()); // reset the cooldown clock. bedCooldown.restart(); changingScenes = true; Engine::ChangeScene(&tutorialMain); } } // loop through all skeleton entities on the map and check if player is within range if (!changingScenes) { for (auto s : skeleton) { if (length(player->getPosition() - s->getPosition()) < ls::getTileSize()) { // get inventory component, create the weapon and add it to the inventory std::shared_ptr<InventoryComponent> ic = player->GetCompatibleComponent<InventoryComponent>()[0]; auto wep = Weapon("sword", Item::Quality::Iron, 5, 50, 100); ic->addWeapon(wep); ic->setUsing(0); // draw message to say item has been added string message = "Hmm, that skeleton had a sword. \nPerhaps this will come in handy!"; auto text = this->ents.find("itemText")[0]; auto textBox = this->ents.find("itemText")[0]->GetCompatibleComponent<TextComponent>()[0]; textBox->SetText(message); text->setVisible(true); textBox->setOrigin(Vector2f(textBox->getBounds().width / 2, textBox->getBounds().height / 2)); itemInfoTimer.restart(); // delete the skeleton as it's been looted s->setForDelete(); } } for (auto s : xspot) { if (length(player->getPosition() - s->getPosition()) < ls::getTileSize()) { // get inventory component, create the weapon and add it to the inventory std::shared_ptr<InventoryComponent> ic = player->GetCompatibleComponent<InventoryComponent>()[0]; ic->setBiscuits(ic->getBiscuits() + 1); // delete the skeleton as it's been looted s->setForDelete(); } } } } if (sf::Keyboard::isKeyPressed(keybinds->find("GO_BACK")->second) && triggertime < 0) { auto popup = this->ents.find("quitPopup")[0]; // if the popup is already displayed. if (popup->isVisible()) { popup->setVisible(false); btnQuit->setInteraction(false); btnMenu->setInteraction(false); pause = false; } else { popup->setVisible(true); btnQuit->setInteraction(true); btnMenu->setInteraction(true); pause = true; } triggertime = 0.8f; } if (changingScenes == false) { if (btnMenu->isPressed()) { changingScenes = true; Engine::ChangeScene(&menu); } else if (btnQuit->isPressed()) { changingScenes = true; Nullify(); Engine::GetWindow().close(); std::exit(EXIT_SUCCESS); } } } void TutorialMain::updateHealthBars(const double& dt, bool changingScenes) { if (!changingScenes) { auto ins = Data::getInstance(); auto player = ins->getPlayer(); auto playerHealth = player->GetCompatibleComponent<HealthComponent>()[0]; float barWidth; auto uiBar = this->ents.find("healthUIBar")[0]; auto spriteComponent = uiBar->GetCompatibleComponent<SpriteComponent>()[0]; barWidth = max((playerHealth->getHealth() / playerHealth->getMaxHealth()) * spriteComponent->getSprite().getTexture()->getSize().x, 0.f); spriteComponent->getSprite().setTextureRect(IntRect(0, 0, static_cast<int>(barWidth), spriteComponent->getBounds()->height)); } } void TutorialMain::Render() { ls::render(Engine::GetWindow()); Scene::Render(); } void TutorialMain::createTexture(std::string path, std::vector<sf::IntRect> bounds, std::vector<sf::Vector2ul> tiles, std::string tag) { //Tile Texture Texture worldSpriteSheet; worldSpriteSheet.loadFromFile(path); shared_ptr<Texture> worldSheet = make_shared<Texture>(worldSpriteSheet); for (auto t : tiles) { sf::IntRect bound = bounds[randomNumber(0, bounds.size() - 1)]; auto pos = ls::getTilePosition(t); auto e = makeEntity(); e->setPosition(pos); e->addTag(tag); auto t = e->addComponent<SpriteComponent>(); t->setTexure(worldSheet); t->getSprite().setTextureRect(bound); } } void TutorialMain::createWaterBlend() { Texture edgeDown; Texture edgeLeft; Texture edgeRight; Texture edgeUp; edgeDown.loadFromFile("resources/textures/WaterEdgeDOWN.png", IntRect(0, 0, 64, 64)); edgeLeft.loadFromFile("resources/textures/WaterEdgeLEFT.png", IntRect(0, 0, 64, 64)); edgeRight.loadFromFile("resources/textures/WaterEdgeRIGHT.png", IntRect(0, 0, 64, 64)); edgeUp.loadFromFile("resources/textures/WaterEdgeUP.png", IntRect(0, 0, 64, 64)); shared_ptr<Texture> waterDown = make_shared<Texture>(edgeDown); shared_ptr<Texture> waterLeft = make_shared<Texture>(edgeLeft); shared_ptr<Texture> waterRight = make_shared<Texture>(edgeRight); shared_ptr<Texture> waterUp = make_shared<Texture>(edgeUp); auto windowSize = Engine::getWindowSize(); auto waterTiles = ls::findTiles(ls::WATER); // loop through all possible water tiles. for (auto w : waterTiles) { // avoid word 'else' as we have to check multiple directions of some tiles. // check below the tile isn't water // prepare for any index out of range and integer overflow if ((w.y + 1) >= 0 && (w.y + 1) <= ls::getHeight() && ls::getTile(Vector2ul(w.x, w.y + 1)) != ls::WATER) { // if it's not water, make a entity and assign the waterUp texture. auto banner = makeEntity(); banner->addTag("waterUP"); banner->setPosition(ls::getTilePosition(Vector2ul(w.x, w.y + 1))); auto bannerSprite = banner->addComponent<SpriteComponent>(); bannerSprite->setTexure(waterUp); } // check above the tile isn't water // prepare for index out of range and integer overflow if ((w.y - 1) >= 0 && (w.y - 1) <= ls::getHeight() && ls::getTile(Vector2ul(w.x, w.y - 1)) != ls::WATER) { // if it's not water, make a entity and assign the waterDown texture. auto banner = makeEntity(); banner->addTag("waterDOWN"); banner->setPosition(ls::getTilePosition(Vector2ul(w.x, w.y - 1))); auto bannerSprite = banner->addComponent<SpriteComponent>(); bannerSprite->setTexure(waterDown); } // check left of the tile isn't water // prepare for index out of range and integer overflow if ((w.x - 1) >= 0 && (w.x - 1) <= ls::getWidth() && ls::getTile(Vector2ul(w.x - 1, w.y)) != ls::WATER) { // if it's not water, make a entity and assign the waterRight texture. auto banner = makeEntity(); banner->addTag("waterRIGHT"); banner->setPosition(ls::getTilePosition(Vector2ul(w.x - 1, w.y))); auto bannerSprite = banner->addComponent<SpriteComponent>(); bannerSprite->setTexure(waterRight); } // check right of the tile isn't water // prepare for index out of range and integer overflow if ((w.x + 1) >= 0 && (w.x + 1) <= ls::getWidth() && ls::getTile(Vector2ul(w.x + 1, w.y)) != ls::WATER) { // if it's not water, make a entity and assign the WaterLeft texture. auto banner = makeEntity(); banner->addTag("waterLEFT"); banner->setPosition(ls::getTilePosition(Vector2ul(w.x + 1, w.y))); auto bannerSprite = banner->addComponent<SpriteComponent>(); bannerSprite->setTexure(waterLeft); } } } int TutorialMain::randomNumber(int min, int max) { // Seed the random_device with the random engine and get a uniform_real_distribution between the min and max value std::random_device rd; std::default_random_engine engine(rd()); std::uniform_int_distribution<int> damage(min, max); return damage(engine); } void TutorialMain::Nullify() { btnMenu = nullptr; btnQuit = nullptr; }
34.958015
146
0.682607
Vvaridus
f55b73dbe3df91f834f9739c6517cac2cac2214a
25,941
cpp
C++
src/coreclr/src/binder/fusionassemblyname.cpp
abock/runtime
b3346807be96f6089fc1538946b3611f607389e2
[ "MIT" ]
6
2020-01-04T14:02:35.000Z
2020-01-05T15:28:09.000Z
src/coreclr/src/binder/fusionassemblyname.cpp
abock/runtime
b3346807be96f6089fc1538946b3611f607389e2
[ "MIT" ]
null
null
null
src/coreclr/src/binder/fusionassemblyname.cpp
abock/runtime
b3346807be96f6089fc1538946b3611f607389e2
[ "MIT" ]
3
2021-02-10T16:20:05.000Z
2021-03-12T07:55:36.000Z
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. // ============================================================ // // FusionAssemblyName.cpp // // Implements the CAssemblyName class // // ============================================================ #include <windows.h> #include <winerror.h> #include "strongnameinternal.h" #include "fusionhelpers.hpp" #include "fusionassemblyname.hpp" #include <strsafe.h> #include "shlwapi.h" #include "assemblyidentity.hpp" #include "textualidentityparser.hpp" #define DISPLAY_NAME_DELIMITER W(',') #define DISPLAY_NAME_DELIMITER_STRING W(",") #define VERSION_STRING_SEGMENTS 4 #define REMAINING_BUFFER_SIZE ((*pccDisplayName) - (pszBuf - szDisplayName)) // --------------------------------------------------------------------------- // CPropertyArray ctor // --------------------------------------------------------------------------- CPropertyArray::CPropertyArray() { _dwSig = 0x504f5250; /* 'PORP' */ memset(&_rProp, 0, ASM_NAME_MAX_PARAMS * sizeof(FusionProperty)); } // --------------------------------------------------------------------------- // CPropertyArray dtor // --------------------------------------------------------------------------- CPropertyArray::~CPropertyArray() { for (DWORD i = 0; i < ASM_NAME_MAX_PARAMS; i++) { if (_rProp[i].cb > sizeof(DWORD)) { if (_rProp[i].pv != NULL) { FUSION_DELETE_ARRAY((LPBYTE) _rProp[i].pv); _rProp[i].pv = NULL; } } } } // --------------------------------------------------------------------------- // CPropertyArray::Set // --------------------------------------------------------------------------- HRESULT CPropertyArray::Set(DWORD PropertyId, LPCVOID pvProperty, DWORD cbProperty) { HRESULT hr = S_OK; FusionProperty *pItem = NULL; pItem = &(_rProp[PropertyId]); if (!cbProperty && !pvProperty) { if (pItem->cb > sizeof(DWORD)) { if (pItem->pv != NULL) FUSION_DELETE_ARRAY((LPBYTE) pItem->pv); } pItem->pv = NULL; } else if (cbProperty > sizeof(DWORD)) { LPBYTE ptr = NEW(BYTE[cbProperty]); if (!ptr) { hr = E_OUTOFMEMORY; goto exit; } if (pItem->cb > sizeof(DWORD)) FUSION_DELETE_ARRAY((LPBYTE) pItem->pv); memcpy(ptr, pvProperty, cbProperty); pItem->pv = ptr; } else { if (pItem->cb > sizeof(DWORD)) FUSION_DELETE_ARRAY((LPBYTE) pItem->pv); memcpy(&(pItem->pv), pvProperty, cbProperty); #ifdef _DEBUG if (PropertyId == ASM_NAME_ARCHITECTURE) { PEKIND pe = * ((PEKIND *)pvProperty); _ASSERTE(pe != peInvalid); } #endif } pItem->cb = cbProperty; exit: return hr; } // --------------------------------------------------------------------------- // CPropertyArray::Get // --------------------------------------------------------------------------- HRESULT CPropertyArray::Get(DWORD PropertyId, LPVOID pvProperty, LPDWORD pcbProperty) { HRESULT hr = S_OK; FusionProperty *pItem; _ASSERTE(pcbProperty); if (PropertyId >= ASM_NAME_MAX_PARAMS || (!pvProperty && *pcbProperty)) { _ASSERTE(!"Invalid Argument! Passed in NULL buffer with size non-zero!"); hr = E_INVALIDARG; goto exit; } pItem = &(_rProp[PropertyId]); if (pItem->cb > *pcbProperty) hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); else if (pItem->cb) memcpy(pvProperty, (pItem->cb > sizeof(DWORD) ? pItem->pv : (LPBYTE) &(pItem->pv)), pItem->cb); *pcbProperty = pItem->cb; exit: return hr; } // --------------------------------------------------------------------------- // CPropertyArray::operator [] // Wraps DWORD optimization test. // --------------------------------------------------------------------------- FusionProperty CPropertyArray::operator [] (DWORD PropertyId) { FusionProperty prop; prop.pv = _rProp[PropertyId].cb > sizeof(DWORD) ? _rProp[PropertyId].pv : &(_rProp[PropertyId].pv); prop.cb = _rProp[PropertyId].cb; return prop; } // --------------------------------------------------------------------------- // CAssemblyName::AddRef // --------------------------------------------------------------------------- STDMETHODIMP_(ULONG) CAssemblyName::AddRef() { return InterlockedIncrement(&_cRef); } // --------------------------------------------------------------------------- // CAssemblyName::Release // --------------------------------------------------------------------------- STDMETHODIMP_(ULONG) CAssemblyName::Release() { ULONG ulRef = InterlockedDecrement(&_cRef); if (ulRef == 0) { delete this; } return ulRef; } // --------------------------------------------------------------------------- // CAssemblyName::QueryInterface // --------------------------------------------------------------------------- STDMETHODIMP CAssemblyName::QueryInterface(REFIID riid, void** ppv) { HRESULT hr = S_OK; BEGIN_ENTRYPOINT_NOTHROW; if (!ppv) { hr = E_POINTER; goto Exit; } if ( IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IAssemblyName) ) { *ppv = static_cast<IAssemblyName*> (this); AddRef(); hr = S_OK; goto Exit; } else { *ppv = NULL; hr = E_NOINTERFACE; goto Exit; } Exit: END_ENTRYPOINT_NOTHROW; return hr; } // --------------------------------------------------------------------------- // CAssemblyName::SetProperty // --------------------------------------------------------------------------- STDMETHODIMP CAssemblyName::SetProperty(DWORD PropertyId, LPCVOID pvProperty, DWORD cbProperty) { HRESULT hr = S_OK; BEGIN_ENTRYPOINT_NOTHROW; hr = SetPropertyInternal(PropertyId, pvProperty, cbProperty); END_ENTRYPOINT_NOTHROW; return hr; } // --------------------------------------------------------------------------- // CAssemblyName::GetProperty // --------------------------------------------------------------------------- STDMETHODIMP CAssemblyName::GetProperty(DWORD PropertyId, LPVOID pvProperty, LPDWORD pcbProperty) { HRESULT hr = S_OK; BEGIN_ENTRYPOINT_NOTHROW; // Retrieve the property. switch(PropertyId) { case ASM_NAME_NULL_PUBLIC_KEY_TOKEN: case ASM_NAME_NULL_PUBLIC_KEY: { hr = (_fPublicKeyToken && !_rProp[PropertyId].cb) ? S_OK : S_FALSE; break; } case ASM_NAME_NULL_CUSTOM: { hr = (_fCustom && !_rProp[PropertyId].cb) ? S_OK : S_FALSE; break; } default: { hr = _rProp.Get(PropertyId, pvProperty, pcbProperty); break; } } END_ENTRYPOINT_NOTHROW; return hr; } // --------------------------------------------------------------------------- // CAssemblyName::GetName // --------------------------------------------------------------------------- STDMETHODIMP CAssemblyName::GetName( __inout LPDWORD lpcwBuffer, __out_ecount_opt(*lpcwBuffer) LPOLESTR pwzBuffer) { HRESULT hr = S_OK; BEGIN_ENTRYPOINT_NOTHROW; DWORD cbBuffer = *lpcwBuffer * sizeof(TCHAR); hr = GetProperty(ASM_NAME_NAME, pwzBuffer, &cbBuffer); *lpcwBuffer = cbBuffer / sizeof(TCHAR); END_ENTRYPOINT_NOTHROW; return hr; } // --------------------------------------------------------------------------- // CAssemblyName::SetPropertyInternal // --------------------------------------------------------------------------- HRESULT CAssemblyName::SetPropertyInternal(DWORD PropertyId, LPCVOID pvProperty, DWORD cbProperty) { HRESULT hr = S_OK; LPBYTE pbSN = NULL; DWORD cbSN = 0; if (PropertyId >= ASM_NAME_MAX_PARAMS || (!pvProperty && cbProperty)) { _ASSERTE(!"Invalid Argument! Passed in NULL buffer with size non-zero!"); hr = E_INVALIDARG; goto exit; } // <REVISIT_TODO> - make this a switch statement.</REVISIT_TODO> if (PropertyId == ASM_NAME_MAJOR_VERSION || PropertyId == ASM_NAME_MINOR_VERSION || PropertyId == ASM_NAME_BUILD_NUMBER || PropertyId == ASM_NAME_REVISION_NUMBER) { if (cbProperty > sizeof(WORD)) { hr = E_INVALIDARG; goto exit; } } // Check if public key is being set and if so, // set the public key token if not already set. if (PropertyId == ASM_NAME_PUBLIC_KEY) { // If setting true public key, generate hash. if (pvProperty && cbProperty) { // Generate the public key token from the pk. if (FAILED(hr = StrongNameTokenFromPublicKey((LPBYTE) pvProperty, cbProperty, &pbSN, &cbSN))) goto exit; // Set the public key token property. if (FAILED(hr = SetPropertyInternal(ASM_NAME_PUBLIC_KEY_TOKEN, pbSN, cbSN))) goto exit; } // Otherwise expect call to reset property. else if (!cbProperty) { if (FAILED(hr = SetPropertyInternal(ASM_NAME_PUBLIC_KEY_TOKEN, pvProperty, cbProperty))) goto exit; } } // Setting NULL public key clears values in public key, // public key token and sets public key token flag. else if (PropertyId == ASM_NAME_NULL_PUBLIC_KEY) { pvProperty = NULL; cbProperty = 0; hr = SetPropertyInternal(ASM_NAME_NULL_PUBLIC_KEY_TOKEN, pvProperty, cbProperty); goto exit; } // Setting or clearing public key token. else if (PropertyId == ASM_NAME_PUBLIC_KEY_TOKEN) { // Defensive: invalid sized public key tokens should be avoided. if (cbProperty > PUBLIC_KEY_TOKEN_LEN) { hr = SetPropertyInternal(ASM_NAME_NULL_PUBLIC_KEY_TOKEN, NULL, 0); hr = E_INVALIDARG; goto exit; } if (pvProperty && cbProperty) _fPublicKeyToken = TRUE; else if (!cbProperty) _fPublicKeyToken = FALSE; } // Setting NULL public key token clears public key token and // sets public key token flag. else if (PropertyId == ASM_NAME_NULL_PUBLIC_KEY_TOKEN) { _fPublicKeyToken = TRUE; pvProperty = NULL; cbProperty = 0; PropertyId = ASM_NAME_PUBLIC_KEY_TOKEN; } else if (PropertyId == ASM_NAME_CUSTOM) { if (pvProperty && cbProperty) _fCustom = TRUE; else if (!cbProperty) _fCustom = FALSE; } else if (PropertyId == ASM_NAME_NULL_CUSTOM) { _fCustom = TRUE; pvProperty = NULL; cbProperty = 0; PropertyId = ASM_NAME_CUSTOM; } // Setting "neutral" as the culture is the same as "" culture (meaning // culture-invariant). else if (PropertyId == ASM_NAME_CULTURE) { if (pvProperty && !FusionCompareStringI((LPWSTR)pvProperty, W("neutral"))) { pvProperty = (void *)W(""); cbProperty = sizeof(W("")); } } // Set property on array. hr = _rProp.Set(PropertyId, pvProperty, cbProperty); exit: if (SUCCEEDED(hr)) { LPWSTR pwzOld; // Clear cache pwzOld = InterlockedExchangeT(&_pwzTextualIdentity, NULL); SAFEDELETEARRAY(pwzOld); pwzOld = InterlockedExchangeT(&_pwzTextualIdentityILFull, NULL); SAFEDELETEARRAY(pwzOld); } // Free memory allocated by crypto wrapper. if (pbSN) { StrongNameFreeBuffer(pbSN); } return hr; } // --------------------------------------------------------------------------- // CreateAssemblyNameObject // --------------------------------------------------------------------------- // This is not external for CoreCLR STDAPI CreateAssemblyNameObject( LPASSEMBLYNAME *ppAssemblyName, LPCOLESTR szAssemblyName, bool parseDisplayName) { HRESULT hr = S_OK; BEGIN_ENTRYPOINT_NOTHROW; CAssemblyName *pName = NULL; if (!ppAssemblyName) { hr = E_INVALIDARG; goto exit; } pName = NEW(CAssemblyName); if (!pName) { hr = E_OUTOFMEMORY; goto exit; } if (parseDisplayName) { hr = pName->Parse((LPWSTR)szAssemblyName); } else { hr = pName->SetName(szAssemblyName); } if (FAILED(hr)) { SAFERELEASE(pName); goto exit; } *ppAssemblyName = pName; exit: END_ENTRYPOINT_NOTHROW; return hr; } // --------------------------------------------------------------------------- // CAssemblyName constructor // --------------------------------------------------------------------------- CAssemblyName::CAssemblyName() { _dwSig = 0x454d414e; /* 'EMAN' */ _fPublicKeyToken = FALSE; _fCustom = TRUE; _cRef = 1; _pwzPathModifier = NULL; _pwzTextualIdentity = NULL; _pwzTextualIdentityILFull = NULL; } // --------------------------------------------------------------------------- // CAssemblyName destructor // --------------------------------------------------------------------------- CAssemblyName::~CAssemblyName() { SAFEDELETEARRAY(_pwzPathModifier); SAFEDELETEARRAY(_pwzTextualIdentity); SAFEDELETEARRAY(_pwzTextualIdentityILFull); } // --------------------------------------------------------------------------- // CAssemblyName::SetName // --------------------------------------------------------------------------- HRESULT CAssemblyName::SetName(LPCTSTR pszAssemblyName) { if (pszAssemblyName == nullptr) return E_INVALIDARG; return SetProperty(ASM_NAME_NAME, (LPTSTR) pszAssemblyName, (DWORD)((wcslen(pszAssemblyName)+1) * sizeof(TCHAR))); } // --------------------------------------------------------------------------- // CAssemblyName::Parse // --------------------------------------------------------------------------- HRESULT CAssemblyName::Parse(__in_z LPCWSTR szDisplayName) { HRESULT hr = S_OK; if (!(szDisplayName && *szDisplayName)) { hr = E_INVALIDARG; goto exit; } EX_TRY { BINDER_SPACE::AssemblyIdentity assemblyIdentity; SString displayName(szDisplayName); // Parse the textual identity hr = BINDER_SPACE::TextualIdentityParser::Parse(displayName, &assemblyIdentity); if (FAILED(hr)) { goto exit; } // Set name. hr = SetProperty(ASM_NAME_NAME, (LPVOID) assemblyIdentity.m_simpleName.GetUnicode(), (assemblyIdentity.m_simpleName.GetCount() + 1) * sizeof(WCHAR)); if (FAILED(hr)) { goto exit; } // Set version. if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_VERSION)) { WORD wVersionPart = 0; wVersionPart = (WORD) assemblyIdentity.m_version.GetMajor(); hr = SetProperty(ASM_NAME_MAJOR_VERSION, &wVersionPart, sizeof(WORD)); if (FAILED(hr)) { goto exit; } wVersionPart = (WORD) assemblyIdentity.m_version.GetMinor(); hr = SetProperty(ASM_NAME_MINOR_VERSION, &wVersionPart, sizeof(WORD)); if (FAILED(hr)) { goto exit; } wVersionPart = (WORD) assemblyIdentity.m_version.GetBuild(); hr = SetProperty(ASM_NAME_BUILD_NUMBER, &wVersionPart, sizeof(WORD)); if (FAILED(hr)) { goto exit; } wVersionPart = (WORD) assemblyIdentity.m_version.GetRevision(); hr = SetProperty(ASM_NAME_REVISION_NUMBER, &wVersionPart, sizeof(WORD)); if (FAILED(hr)) { goto exit; } } // Set culture. if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CULTURE)) { hr = SetProperty(ASM_NAME_CULTURE, (LPVOID) assemblyIdentity.m_cultureOrLanguage.GetUnicode(), (assemblyIdentity.m_cultureOrLanguage.GetCount()+1) * sizeof(WCHAR)); if (FAILED(hr)) { goto exit; } } // Set public key (token) or NULL flag. if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY)) { SBuffer &publicKeyBuffer = assemblyIdentity.m_publicKeyOrTokenBLOB; const void *pBytes = publicKeyBuffer; // This also computes and sets the public key token. hr = SetProperty(ASM_NAME_PUBLIC_KEY, (void *) pBytes, publicKeyBuffer.GetSize()); if (FAILED(hr)) { goto exit; } } else if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN)) { SBuffer &publicKeyTokenBuffer = assemblyIdentity.m_publicKeyOrTokenBLOB; const void *pBytes = publicKeyTokenBuffer; hr = SetProperty(ASM_NAME_PUBLIC_KEY_TOKEN, (LPVOID) pBytes, publicKeyTokenBuffer.GetSize()); if (FAILED(hr)) { goto exit; } } else if (assemblyIdentity. Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL)) { hr = SetProperty(ASM_NAME_NULL_PUBLIC_KEY_TOKEN, NULL, 0); if (FAILED(hr)) { goto exit; } } // Set architecture. if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PROCESSOR_ARCHITECTURE)) { PEKIND peKind = assemblyIdentity.m_kProcessorArchitecture; hr = SetProperty(ASM_NAME_ARCHITECTURE, (LPVOID) &peKind, sizeof(PEKIND)); if(FAILED(hr)) { goto exit; } } // Set retargetable flag. if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_RETARGETABLE)) { BOOL fRetarget = TRUE; if (FAILED(hr = SetProperty(ASM_NAME_RETARGET, &fRetarget, sizeof(BOOL)))) { goto exit; } } // Set content type. if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CONTENT_TYPE)) { DWORD dwContentType = assemblyIdentity.m_kContentType; hr = SetProperty(ASM_NAME_CONTENT_TYPE, &dwContentType, sizeof(dwContentType)); IfFailGoto(hr, exit); } // Set custom or NULL flag. if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CUSTOM)) { SBuffer &customBuffer = assemblyIdentity.m_customBLOB; const void *pBytes = customBuffer; hr = SetProperty(ASM_NAME_CUSTOM, (void *) pBytes, customBuffer.GetSize()); if (FAILED(hr)) { goto exit; } } else if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CUSTOM_NULL)) { hr = SetProperty(ASM_NAME_NULL_CUSTOM, NULL, 0); if (FAILED(hr)) { goto exit; } } } EX_CATCH_HRESULT(hr); exit: return hr; } namespace fusion { namespace util { namespace priv { inline bool IsNullProperty(DWORD dwProperty) { LIMITED_METHOD_CONTRACT; return dwProperty == ASM_NAME_NULL_PUBLIC_KEY_TOKEN || dwProperty == ASM_NAME_NULL_PUBLIC_KEY || dwProperty == ASM_NAME_NULL_CUSTOM; } HRESULT ConvertToUtf8(PCWSTR wzStr, __deref_out UTF8** pszStr) { HRESULT hr = S_OK; _ASSERTE(wzStr != nullptr && pszStr != nullptr); if (wzStr == nullptr || pszStr == nullptr) { return E_INVALIDARG; } DWORD cbSize = WszWideCharToMultiByte(CP_UTF8, 0, wzStr, -1, NULL, 0, NULL, NULL); if(cbSize == 0) { return SUCCEEDED(hr = HRESULT_FROM_GetLastError()) ? E_UNEXPECTED : hr; } NewArrayHolder<UTF8> szStr = new (nothrow) UTF8[cbSize]; IfNullRet(szStr); cbSize = WszWideCharToMultiByte(CP_UTF8, 0, wzStr, -1, static_cast<LPSTR>(szStr), cbSize, NULL, NULL); if(cbSize == 0) { return SUCCEEDED(hr = HRESULT_FROM_GetLastError()) ? E_UNEXPECTED : hr; } *pszStr = szStr.Extract(); return S_OK; } } // Non-allocating helper. HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, PVOID pBuf, DWORD *pcbBuf) { LIMITED_METHOD_CONTRACT; HRESULT hr = S_OK; _ASSERTE(pName != nullptr && pcbBuf != nullptr); if (pName == nullptr || pcbBuf == nullptr) { return E_INVALIDARG; } hr = pName->GetProperty(dwProperty, pBuf, pcbBuf); IfFailRet(hr); // Zero-length non-null property means there is no value. if (hr == S_OK && *pcbBuf == 0 && !priv::IsNullProperty(dwProperty)) { hr = S_FALSE; } return hr; } // Allocating helper. HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, PBYTE * ppBuf, DWORD *pcbBuf) { LIMITED_METHOD_CONTRACT; HRESULT hr = S_OK; _ASSERTE(ppBuf != nullptr && (*ppBuf == nullptr || pcbBuf != nullptr)); if (ppBuf == nullptr || (*ppBuf != nullptr && pcbBuf == nullptr)) { return E_INVALIDARG; } DWORD cbBuf = 0; if (pcbBuf == nullptr) pcbBuf = &cbBuf; hr = GetProperty(pName, dwProperty, *ppBuf, pcbBuf); // No provided buffer constitutes a request for one to be allocated. if (*ppBuf == nullptr) { // If it's a null property, allocate a single-byte array to provide consistency. if (hr == S_OK && priv::IsNullProperty(dwProperty)) { *ppBuf = new (nothrow) BYTE[1]; IfNullRet(*ppBuf); } // Great, get the value. else if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { NewArrayHolder<BYTE> pBuf = new (nothrow) BYTE[*pcbBuf]; IfNullRet(pBuf); hr = pName->GetProperty(dwProperty, pBuf, pcbBuf); IfFailRet(hr); *ppBuf = pBuf.Extract(); hr = S_OK; } } return hr; } HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, SString & ssVal) { LIMITED_METHOD_CONTRACT; HRESULT hr = S_OK; _ASSERTE(pName != nullptr); if (pName == nullptr) { return E_INVALIDARG; } DWORD cbSize = 0; hr = GetProperty(pName, dwProperty, static_cast<PBYTE>(nullptr), &cbSize); if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { EX_TRY { PWSTR wzNameBuf = ssVal.OpenUnicodeBuffer(cbSize / sizeof(WCHAR) - 1); hr = GetProperty(pName, dwProperty, reinterpret_cast<PBYTE>(wzNameBuf), &cbSize); ssVal.CloseBuffer(); IfFailThrow(hr); ssVal.Normalize(); } EX_CATCH_HRESULT(hr); IfFailRet(hr); } return hr; } HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, __deref_out WCHAR ** pwzVal) { LIMITED_METHOD_CONTRACT; HRESULT hr = S_OK; _ASSERTE(pName != nullptr && pwzVal != nullptr); if (pName == nullptr || pwzVal == nullptr) { return E_INVALIDARG; } DWORD cbSize = 0; hr = pName->GetProperty(dwProperty, NULL, &cbSize); if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { NewArrayHolder<WCHAR> wzVal = reinterpret_cast<PWSTR>(new (nothrow) BYTE[cbSize]); IfNullRet(wzVal); hr = pName->GetProperty(dwProperty, reinterpret_cast<PBYTE>(static_cast<PWSTR>(wzVal)), &cbSize); IfFailRet(hr); *pwzVal = wzVal.Extract(); } return hr; } HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, __deref_out UTF8 **pwzOut) { LIMITED_METHOD_CONTRACT; HRESULT hr = S_OK; if (pwzOut == nullptr) return E_INVALIDARG; SmallStackSString ssStr; hr = GetProperty(pName, dwProperty, ssStr); IfFailRet(hr); hr = priv::ConvertToUtf8(ssStr, pwzOut); IfFailRet(hr); return hr; } } }
30.304907
118
0.50584
abock
f561d11b9dd3a36040d9e52e7353bf2980ca23dc
1,903
hpp
C++
Include/Utils.hpp
grovix/SCLKernelDecoder
c29775d262c30354b7b6787c1d42e205172b1f3c
[ "Apache-2.0" ]
3
2021-07-18T00:53:59.000Z
2021-07-26T10:13:47.000Z
Include/Utils.hpp
grovix/SCLKernelDecoder
c29775d262c30354b7b6787c1d42e205172b1f3c
[ "Apache-2.0" ]
null
null
null
Include/Utils.hpp
grovix/SCLKernelDecoder
c29775d262c30354b7b6787c1d42e205172b1f3c
[ "Apache-2.0" ]
1
2022-02-10T13:47:46.000Z
2022-02-10T13:47:46.000Z
/*------------------------------------------------------------------------ Some functions required for kernel processing Copyright 2020 Grigorii Trofimiuk, Peter Trifonov 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. --------------------------------------------------------------------------*/ #pragma once #include "misc.hpp" #include <cstdint> void setPairEW(LLRType y, LLRType &a0, LLRType &a1); /// compute Q(a, b) = sign(a)*sign(b)*min(a,b) void SoftXOR2Elements(LLRType &pDest, const LLRType &a, const LLRType &b); /// compute Q(a, b) = sign(a)*sign(b)*min(a,b) of an array void SoftXOR(LLRType *pDest, const LLRType *pS, const int &N); /// compute P(a,b,c) = (-1)^u*a+b void SoftCombine2Elements(LLRType &pDest, const LLRType &a, const LLRType &b, const tBit &u); /// compute P(a,b,c) = (-1)^u*a+b of an array void SoftCombine(LLRType *pDest, const LLRType *pS, const tBit *pC, const int &N); /// compute FHT of length 4 vector void hadamardTransform4(const LLRType *in, LLRType *out); /// inplace calculation of xF^{\otimes m}, where F is the Arikan kernel template <class T> void Arikan(unsigned LogLength, T *pData) { unsigned N = 1u << LogLength; // implement Arikan's butterfly unsigned L = 1; while (N > 1) { N >>= 1; for (unsigned k = 0; k < L; k++) { for (unsigned j = 2 * k * N; j < (2 * k + 1) * N; j++) { pData[j] ^= pData[j + N]; }; }; L <<= 1; }; };
33.385965
93
0.629007
grovix
f56343e7961ac2ddaf788c511756ea4aa2b800bb
4,565
hpp
C++
plugin/serializer/include/minko/file/GeometryParser.hpp
aerys/minko
edc3806a4e01570c5cb21f3402223ca695d08d22
[ "BSD-3-Clause" ]
478
2015-01-04T16:59:53.000Z
2022-03-07T20:28:07.000Z
plugin/serializer/include/minko/file/GeometryParser.hpp
aerys/minko
edc3806a4e01570c5cb21f3402223ca695d08d22
[ "BSD-3-Clause" ]
83
2015-01-15T21:45:06.000Z
2021-11-08T11:01:48.000Z
plugin/serializer/include/minko/file/GeometryParser.hpp
aerys/minko
edc3806a4e01570c5cb21f3402223ca695d08d22
[ "BSD-3-Clause" ]
175
2015-01-04T03:30:39.000Z
2020-01-27T17:08:14.000Z
/* Copyright (c) 2014 Aerys 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 "minko/Common.hpp" #include "minko/deserialize/TypeDeserializer.hpp" #include "minko/file/AbstractSerializerParser.hpp" #include "minko/render/IndexBuffer.hpp" namespace minko { namespace file { class GeometryParser: public AbstractSerializerParser { public: typedef std::shared_ptr<GeometryParser> Ptr; typedef std::shared_ptr<render::AbstractContext> AbstractContextPtr; typedef std::shared_ptr<render::IndexBuffer> IndexBufferPtr; typedef std::shared_ptr<render::VertexBuffer> VertexBufferPtr; private: typedef unsigned char uchar; typedef msgpack::type::tuple<std::string, uchar, uchar> SerializeAttribute; typedef msgpack::type::tuple<uchar, std::string, std::string, std::vector<std::string>> SerializedGeometry; private: static std::unordered_map<uint, std::function<IndexBufferPtr(std::string&, AbstractContextPtr)>> indexBufferParserFunctions; static std::unordered_map<uint, std::function<VertexBufferPtr(std::string&, AbstractContextPtr)>> vertexBufferParserFunctions; public: inline static Ptr create() { return std::shared_ptr<GeometryParser>(new GeometryParser()); } void parse(const std::string& filename, const std::string& resolvedFilename, std::shared_ptr<Options> options, const std::vector<unsigned char>& data, std::shared_ptr<AssetLibrary> assetLibrary); inline static void registerIndexBufferParserFunction(std::function<IndexBufferPtr(std::string&, AbstractContextPtr)> f, uint functionId) { indexBufferParserFunctions[functionId] = f; } inline static void registerVertexBufferParserFunction(std::function<VertexBufferPtr(std::string&, AbstractContextPtr)> f, uint functionId) { vertexBufferParserFunctions[functionId] = f; } template <typename T> static IndexBufferPtr deserializeIndexBuffer(std::string& serializedIndexBuffer, AbstractContextPtr context) { auto vector = deserialize::TypeDeserializer::deserializeVector<T>(serializedIndexBuffer); return render::IndexBuffer::create(context, vector); } private: GeometryParser() { initialize(); } void computeMetaData(unsigned short metaData, uint& indexBufferFunctionId, uint& vertexBufferFunctionId); void initialize(); static VertexBufferPtr deserializeVertexBuffer(std::string& serializedVertexBuffer, AbstractContextPtr context); static IndexBufferPtr deserializeIndexBufferChar(std::string& serializedIndexBuffer, AbstractContextPtr context); }; } }
39.017094
140
0.607886
aerys
f5662f9dd4c70058ba585ee94f29d220eddef5fb
1,422
cpp
C++
irohad/multi_sig_transactions/storage/impl/mst_storage.cpp
akshatkarani/iroha
5acef9dd74720c6185360d951e9b11be4ef73260
[ "Apache-2.0" ]
24
2016-09-26T17:11:46.000Z
2020-03-03T13:42:58.000Z
irohad/multi_sig_transactions/storage/impl/mst_storage.cpp
akshatkarani/iroha
5acef9dd74720c6185360d951e9b11be4ef73260
[ "Apache-2.0" ]
11
2016-10-13T10:09:55.000Z
2019-06-13T08:49:11.000Z
irohad/multi_sig_transactions/storage/impl/mst_storage.cpp
akshatkarani/iroha
5acef9dd74720c6185360d951e9b11be4ef73260
[ "Apache-2.0" ]
4
2016-09-27T13:18:28.000Z
2019-08-05T20:47:15.000Z
/** * Copyright Soramitsu Co., Ltd. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ #include <utility> #include "multi_sig_transactions/storage/mst_storage.hpp" namespace iroha { MstStorage::MstStorage(logger::LoggerPtr log) : log_{std::move(log)} {} StateUpdateResult MstStorage::apply( const shared_model::crypto::PublicKey &target_peer_key, const MstState &new_state) { std::lock_guard<std::mutex> lock{this->mutex_}; return applyImpl(target_peer_key, new_state); } StateUpdateResult MstStorage::updateOwnState(const DataType &tx) { std::lock_guard<std::mutex> lock{this->mutex_}; return updateOwnStateImpl(tx); } MstState MstStorage::extractExpiredTransactions( const TimeType &current_time) { std::lock_guard<std::mutex> lock{this->mutex_}; return extractExpiredTransactionsImpl(current_time); } MstState MstStorage::getDiffState( const shared_model::crypto::PublicKey &target_peer_key, const TimeType &current_time) { std::lock_guard<std::mutex> lock{this->mutex_}; return getDiffStateImpl(target_peer_key, current_time); } MstState MstStorage::whatsNew(ConstRefState new_state) const { std::lock_guard<std::mutex> lock{this->mutex_}; return whatsNewImpl(new_state); } bool MstStorage::batchInStorage(const DataType &batch) const { return batchInStorageImpl(batch); } } // namespace iroha
30.255319
73
0.729958
akshatkarani
f5664a55e1ed673dd2b43009f33a7c1faff1e1a2
72
hpp
C++
source/console-draw/rect.hpp
skwirl42/robco-processor
eb92ee0d2402403b36b9b796f80c3d46aaed1442
[ "MIT" ]
null
null
null
source/console-draw/rect.hpp
skwirl42/robco-processor
eb92ee0d2402403b36b9b796f80c3d46aaed1442
[ "MIT" ]
30
2020-12-29T13:25:25.000Z
2021-09-28T12:03:35.000Z
source/console-draw/rect.hpp
skwirl42/robco-processor
eb92ee0d2402403b36b9b796f80c3d46aaed1442
[ "MIT" ]
null
null
null
#pragma once struct rect { int x; int y; int width; int height; };
7.2
12
0.625
skwirl42
f566d8d2fac77bd34cd624683cf43ccbc3d2f6d1
8,204
cpp
C++
Bacchus_Engine/BlockheadInspector.cpp
ForestGin/Bacchus_Engine
4cdc9aa576fa3c91aed75654aa333ed78070b5ce
[ "MIT" ]
null
null
null
Bacchus_Engine/BlockheadInspector.cpp
ForestGin/Bacchus_Engine
4cdc9aa576fa3c91aed75654aa333ed78070b5ce
[ "MIT" ]
null
null
null
Bacchus_Engine/BlockheadInspector.cpp
ForestGin/Bacchus_Engine
4cdc9aa576fa3c91aed75654aa333ed78070b5ce
[ "MIT" ]
null
null
null
#include "Application.h" #include "ModuleSceneManager.h" #include "ModuleRenderer3D.h" #include "BlockheadInspector.h" #include "GameObject.h" #include "ComponentMesh.h" #include "ComponentMaterial.h" #include "ComponentRenderer.h" #include "ComponentTransform.h" #include "ComponentCamera.h" #include "ResourceMesh.h" #include "ResourceMaterial.h" #include "ResourceTexture.h" #include "imgui/imgui.h" #include "mmgr/mmgr.h" BlockheadInspector::BlockheadInspector(char* name) : Blockhead(name) { } BlockheadInspector::~BlockheadInspector() { } bool BlockheadInspector::Draw() { ImGuiWindowFlags settingsFlags = 0; settingsFlags = ImGuiWindowFlags_NoFocusOnAppearing; if (ImGui::Begin(name, &enabled, settingsFlags)) { GameObject* Selected = App->scene_manager->GetSelectedGameObjects(); if (Selected == nullptr) { ImGui::End(); return false; } // --- Game Object --- CreateGameObjectNode(*Selected); // --- Components --- if (Startup) ImGui::SetNextItemOpen(true); // --- Transform --- if (ImGui::TreeNode("Transform")) { CreateTransformNode(*Selected); ImGui::TreePop(); ImGui::Separator(); } // --- Mesh --- if (Selected->GetComponent<ComponentMesh>(Component::ComponentType::Mesh)) { CreateMeshNode(*Selected); ImGui::Separator(); } // --- Renderer --- if (Selected->GetComponent<ComponentRenderer>(Component::ComponentType::Renderer)) { CreateRendererNode(*Selected); ImGui::Separator(); } // --- Material --- if (Selected->GetComponent<ComponentMaterial>(Component::ComponentType::Material)) { CreateMaterialNode(*Selected); ImGui::Separator(); } // --- Camera --- if (Selected->GetComponent<ComponentCamera>(Component::ComponentType::Camera)) { CreateCameraNode(*Selected); ImGui::Separator(); } if (Startup) Startup = false; } ImGui::End(); return true; } inline void BlockheadInspector::CreateGameObjectNode(GameObject& Selected) const { ImGui::BeginChild("child", ImVec2(0, 35), true); ImGui::Checkbox("##GOActive", &Selected.GetActive()); ImGui::SameLine(); // --- Game Object Name Setter --- static char GOName[100] = ""; strcpy_s(GOName, 100, Selected.GetName().data()); if (ImGui::InputText("", GOName, 100, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) Selected.SetName(GOName); ImGui::SameLine(); if (ImGui::Checkbox("Static", &Selected.Static)) App->scene_manager->SetStatic(&Selected); ImGui::EndChild(); } inline void BlockheadInspector::CreateTransformNode(GameObject& Selected) const { ComponentTransform* transform = Selected.GetComponent<ComponentTransform>(Component::ComponentType::Transform); float3 position; float3 rotation; float3 scale; if (transform != NULL) position = transform->GetPosition(); // --- Transform Position --- ImGui::Text("Position "); ImGui::SameLine(); ImGui::Text("X"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##PX", &position.x, 0.005f); ImGui::SameLine(); ImGui::Text("Y"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##PY", &position.y, 0.005f); ImGui::SameLine(); ImGui::Text("Z"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##PZ", &position.z, 0.005f); // --- Transform Rotation --- if (transform != NULL) rotation = transform->GetRotation(); ImGui::Text("Rotation "); ImGui::SameLine(); ImGui::Text("X"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##RX", &rotation.x, 0.005f); ImGui::SameLine(); ImGui::Text("Y"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##RY", &rotation.y, 0.005f); ImGui::SameLine(); ImGui::Text("Z"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##RZ", &rotation.z, 0.005f); // --- Transform Scale --- if (transform != NULL) scale = transform->GetScale(); ImGui::Text("Scale "); ImGui::SameLine(); ImGui::Text("X"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##SX", &scale.x, 0.005f); ImGui::SameLine(); ImGui::Text("Y"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##SY", &scale.y, 0.005f); ImGui::SameLine(); ImGui::Text("Z"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); ImGui::DragFloat("##SZ", &scale.z, 0.005f); // --- Transform Set --- if (!Selected.Static) { if (!transform->GetPosition().Equals(position)) transform->SetPosition(position.x, position.y, position.z); if (!transform->GetScale().Equals(scale)) transform->Scale(scale.x, scale.y, scale.z); if (!transform->GetRotation().Equals(rotation)) transform->SetRotation(rotation); } } inline void BlockheadInspector::CreateMeshNode(GameObject& Selected) const { ComponentMesh* mesh = Selected.GetComponent<ComponentMesh>(Component::ComponentType::Mesh); ImGui::Checkbox("##MeshActive", &mesh->GetActive()); ImGui::SameLine(); if (Startup) ImGui::SetNextItemOpen(true); if (ImGui::TreeNode("Mesh")) { std::string Triangle_count = "Triangles "; Triangle_count.append(std::to_string(mesh->resource_mesh->IndicesSize / 3)); ImGui::Text(Triangle_count.data()); ImGui::Text("Instances:"); ImGui::SameLine(); ImGui::Text(std::to_string(mesh->resource_mesh->instances).data()); ImGui::TreePop(); } } inline void BlockheadInspector::CreateRendererNode(GameObject& Selected) const { ComponentRenderer* renderer = Selected.GetComponent<ComponentRenderer>(Component::ComponentType::Renderer); ImGui::Checkbox("##RenActive", &renderer->GetActive()); ImGui::SameLine(); if (Startup) ImGui::SetNextItemOpen(true); if (ImGui::TreeNode("Mesh Renderer")) { ImGui::Checkbox("Vertex Normals", &renderer->draw_vertexnormals); ImGui::SameLine(); ImGui::Checkbox("Face Normals ", &renderer->draw_facenormals); ImGui::SameLine(); ImGui::Checkbox("Checkers", &renderer->checkers); ImGui::TreePop(); } } inline void BlockheadInspector::CreateMaterialNode(GameObject& Selected) const { ComponentMaterial* material = Selected.GetComponent<ComponentMaterial>(Component::ComponentType::Material); ImGui::Checkbox("##MatActive", &material->GetActive()); ImGui::SameLine(); if (Startup) ImGui::SetNextItemOpen(true); if (ImGui::TreeNode("Material")) { // --- Print Texture Path --- std::string Path = "Path: "; Path.append(material->resource_material->resource_diffuse->Texture_path); ImGui::Text(Path.data()); // --- Texture Preview --- ImGui::Image((void*)(uint)&material->resource_material->resource_diffuse->buffer_id, ImVec2(150, 150)); ImGui::Text("Instances:"); ImGui::SameLine(); ImGui::Text(std::to_string(material->resource_material->resource_diffuse->instances).data()); // --- Print Texture Width and Height --- ImGui::Text(std::to_string(material->resource_material->resource_diffuse->Texture_width).data()); ImGui::SameLine(); ImGui::Text(std::to_string(material->resource_material->resource_diffuse->Texture_height).data()); ImGui::TreePop(); } } inline void BlockheadInspector::CreateCameraNode(GameObject& Selected) const { if (Startup) ImGui::SetNextItemOpen(true); ComponentCamera* camera = Selected.GetComponent<ComponentCamera>(Component::ComponentType::Camera); if (ImGui::TreeNode("Camera")) { if (ImGui::Checkbox("Active Camera", &camera->active_camera)) camera->active_camera ? App->renderer3D->SetActiveCamera(camera) : App->renderer3D->SetActiveCamera(nullptr); if (ImGui::Checkbox("Culling Camera", &camera->culling)) camera->culling ? App->renderer3D->SetCullingCamera(camera) : App->renderer3D->SetCullingCamera(nullptr); ImGui::Text("FOV"); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.15f); float fov = camera->GetFOV(); ImGui::DragFloat("##FOV", &fov, 0.005f); if (fov != camera->GetFOV()) camera->SetFOV(fov); ImGui::TreePop(); } }
24.272189
113
0.695758
ForestGin
f56729fcd5b8fd504ca52f5eadcba9d8580676ac
12,430
cpp
C++
src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp
vmusch/OpenMS
3c4a078ad4687677393c138d4acb91bb444a7c7b
[ "BSL-1.0", "Zlib", "Apache-2.0" ]
348
2015-01-17T16:50:12.000Z
2022-03-30T22:55:39.000Z
src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp
vmusch/OpenMS
3c4a078ad4687677393c138d4acb91bb444a7c7b
[ "BSL-1.0", "Zlib", "Apache-2.0" ]
4,259
2015-01-01T14:07:54.000Z
2022-03-31T16:49:14.000Z
src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp
vmusch/OpenMS
3c4a078ad4687677393c138d4acb91bb444a7c7b
[ "BSL-1.0", "Zlib", "Apache-2.0" ]
266
2015-01-24T14:56:14.000Z
2022-03-30T12:32:35.000Z
// -------------------------------------------------------------------------- // OpenMS -- Open-Source Mass Spectrometry // -------------------------------------------------------------------------- // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, // ETH Zurich, and Freie Universitaet Berlin 2002-2021. // // This software is released under a three-clause BSD license: // * 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 any author or any participating institution // may be used to endorse or promote products derived from this software // without specific prior written permission. // For a full list of authors, refer to the file AUTHORS. // -------------------------------------------------------------------------- // 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 ANY OF THE AUTHORS OR THE CONTRIBUTING // INSTITUTIONS 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. // // -------------------------------------------------------------------------- // $Maintainer: Timo Sachsenberg $ // $Authors: Marc Sturm $ // -------------------------------------------------------------------------- #include <OpenMS/CONCEPT/ClassTest.h> #include <OpenMS/test_config.h> /////////////////////////// #include <OpenMS/METADATA/MetaInfoInterface.h> /////////////////////////// START_TEST(Example, "$Id$") ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// using namespace std; using namespace OpenMS; MetaInfoInterface* test = nullptr; MetaInfoInterface* nullPointer = nullptr; START_SECTION((MetaInfoInterface())) test = new MetaInfoInterface; TEST_NOT_EQUAL(test, nullPointer) END_SECTION START_SECTION((~MetaInfoInterface())) delete test; END_SECTION MetaInfoInterface mi; START_SECTION((static MetaInfoRegistry& metaRegistry())) MetaInfoInterface mi2; mi2.metaRegistry().registerName("testname","testdesc","testunit"); TEST_EQUAL(mi2.metaRegistry().getIndex("testname"),1024); TEST_EQUAL(mi.metaRegistry().getIndex("testname"),1024); END_SECTION START_SECTION((void setMetaValue(const String& name, const DataValue& value))) NOT_TESTABLE //tested in the get method END_SECTION START_SECTION((void setMetaValue(UInt index, const DataValue& value))) NOT_TESTABLE //tested in the get method END_SECTION START_SECTION((const DataValue& getMetaValue(UInt index, const DataValue& default_value = DataValue::EMPTY) const)) { mi.setMetaValue(1024, String("testtesttest")); TEST_STRING_EQUAL(mi.getMetaValue(1024), "testtesttest"); TEST_EQUAL(mi.getMetaValue(1025) == DataValue::EMPTY, true); TEST_EQUAL(mi.getMetaValue(1025, 10) == DataValue(10), true); } END_SECTION START_SECTION((const DataValue& getMetaValue(const String& name, const DataValue& default_value = DataValue::EMPTY) const)) { mi.setMetaValue("testname", String("testtesttest2")); TEST_STRING_EQUAL(mi.getMetaValue("testname"), "testtesttest2"); TEST_EQUAL(mi.getMetaValue("notdefined") == DataValue::EMPTY, true); TEST_EQUAL(mi.getMetaValue("notdefined", 10) == DataValue(10), true); } END_SECTION mi.setMetaValue("cluster_id", 4711.12f); mi.setMetaValue(2, 4712.12f); START_SECTION((bool isMetaEmpty() const)) MetaInfoInterface tmp; TEST_EQUAL(tmp.isMetaEmpty(),true) tmp.setMetaValue(1024,String("testtesttest")); TEST_EQUAL(tmp.isMetaEmpty(),false) END_SECTION TOLERANCE_ABSOLUTE(0.001) // Copy Constructor START_SECTION((MetaInfoInterface(const MetaInfoInterface& rhs))) { //test if copy worked MetaInfoInterface mi3(mi); TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")),double(mi3.getMetaValue("cluster_id"))) //test if a deep copy was done mi3.setMetaValue("cluster_id",11.9); TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")),4712.12) TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")),11.9) } END_SECTION /// Move constructor START_SECTION(( MetaInfoInterface(MetaInfoInterface&&) noexcept )) { // Ensure that MetaInfoInterface has a no-except move constructor (otherwise // std::vector is inefficient and will copy instead of move). TEST_EQUAL(noexcept(MetaInfoInterface(std::declval<MetaInfoInterface&&>())), true) MetaInfoInterface example(mi); MetaInfoInterface mi3(std::move(example)); // test if move worked TEST_EQUAL(mi3.metaValueExists("cluster_id"), true); TEST_EQUAL(example.metaValueExists("cluster_id"), false); TEST_EQUAL(example.isMetaEmpty(), true); TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")), double(mi3.getMetaValue("cluster_id"))) // test if a deep copy was done mi3.setMetaValue("cluster_id", 11.9); TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")), 4712.12) TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")), 11.9) } END_SECTION START_SECTION((MetaInfoInterface& operator = (const MetaInfoInterface& rhs))) { //test if copy worked MetaInfoInterface mi3,mi4; mi3 = mi; TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")),double(mi.getMetaValue("cluster_id"))) //test if a deep copy was done mi3.setMetaValue("cluster_id",11.9); TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")),4712.12) TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")),11.9) //test what happens when left side is not empty mi3 = mi; TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")),double(mi.getMetaValue("cluster_id"))) TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")), 4712.12) //test if a deep copy was done mi3.setMetaValue("cluster_id",11.9); TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")),double(mi.getMetaValue("cluster_id"))) TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")),4712.12) TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")),11.9) //test what happens when source is empty mi3 = mi4; TEST_EQUAL(mi3.isMetaEmpty(),true) } END_SECTION START_SECTION((MetaInfoInterface& operator = (MetaInfoInterface&& rhs))) { // Ensure that MetaInfoInterface has a no-except move assignment operator. TEST_EQUAL(noexcept(declval<MetaInfoInterface&>() = declval<MetaInfoInterface &&>()), true) MetaInfoInterface mi3, mi4; MetaInfoInterface example(mi); mi3 = std::move(example); // test if move worked TEST_EQUAL(mi3.metaValueExists("cluster_id"), true); TEST_EQUAL(example.metaValueExists("cluster_id"), false); TEST_EQUAL(example.isMetaEmpty(), true); TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")), double(mi.getMetaValue("cluster_id"))) TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")), 4712.12) // test if a deep copy was done mi3.setMetaValue("cluster_id", 11.9); TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")), 4712.12) TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")), 11.9) // test what happens when left side is not empty example = mi; mi3 = std::move(example); TEST_EQUAL(mi3.metaValueExists("cluster_id"), true); TEST_EQUAL(example.metaValueExists("cluster_id"), false); TEST_EQUAL(example.isMetaEmpty(), true); TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")), double(mi.getMetaValue("cluster_id"))) // test if a deep copy was done TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")), 4712.12) mi3.setMetaValue("cluster_id", 11.9); TEST_REAL_SIMILAR(double(mi.getMetaValue("cluster_id")), double(mi.getMetaValue("cluster_id"))) TEST_REAL_SIMILAR(double(mi3.getMetaValue("cluster_id")), 11.9) // test what happens when source is empty mi3 = std::move(example); TEST_EQUAL(mi3.isMetaEmpty(), true) TEST_EQUAL(example.isMetaEmpty(), true) } END_SECTION START_SECTION((void getKeys(std::vector<String>& keys) const)) vector<String> tmp,tmp2; tmp.push_back("cluster_id"); tmp.push_back("testname"); mi.getKeys(tmp2); TEST_EQUAL(tmp2.size(),tmp.size()) TEST_EQUAL(tmp2[0],tmp[0]) TEST_EQUAL(tmp2[1],tmp[1]) MetaInfoInterface mi2(mi); mi2.getKeys(tmp2); TEST_EQUAL(tmp2.size(),tmp.size()) TEST_EQUAL(tmp2[0],tmp[0]) TEST_EQUAL(tmp2[1],tmp[1]) mi2.metaRegistry().registerName("a","test"); mi2.metaRegistry().registerName("d","test"); mi2.metaRegistry().registerName("x","test"); mi2.setMetaValue("a",1); mi2.setMetaValue("d",1); mi2.setMetaValue("x",1); mi2.getKeys(tmp2); tmp.clear(); tmp.push_back("cluster_id"); tmp.push_back("testname"); tmp.push_back("a"); tmp.push_back("d"); tmp.push_back("x"); TEST_EQUAL(tmp2.size(),tmp.size()) TEST_EQUAL(tmp2[0],tmp[0]) TEST_EQUAL(tmp2[1],tmp[1]) TEST_EQUAL(tmp2[2],tmp[2]) TEST_EQUAL(tmp2[3],tmp[3]) TEST_EQUAL(tmp2[4],tmp[4]) END_SECTION START_SECTION((void getKeys(std::vector< UInt > &keys) const)) MetaInfoInterface mi; mi.setMetaValue("label",String("tag")); mi.setMetaValue("icon",String("kreis")); vector<UInt> vec; mi.getKeys(vec); TEST_EQUAL(vec.size(),2) TEST_EQUAL(vec[0],3) TEST_EQUAL(vec[1],4) mi.metaRegistry().registerName("a","test"); mi.metaRegistry().registerName("d","test"); mi.metaRegistry().registerName("x","test"); mi.setMetaValue("a",1); mi.setMetaValue("d",1); mi.setMetaValue("x",1); mi.getKeys(vec); TEST_EQUAL(vec.size(),5) TEST_EQUAL(vec[0],3) TEST_EQUAL(vec[1],4) TEST_EQUAL(vec[2],1025) TEST_EQUAL(vec[3],1026) TEST_EQUAL(vec[4],1027) END_SECTION START_SECTION((bool metaValueExists(const String& name) const)) MetaInfoInterface mi4; TEST_EQUAL(mi4.metaValueExists("cluster_id"),false) mi4.setMetaValue("cluster_id",4712.1234); TEST_EQUAL(mi4.metaValueExists("cluster_id"),true) END_SECTION START_SECTION((bool metaValueExists(UInt index) const)) MetaInfoInterface mi4; TEST_EQUAL(mi4.metaValueExists(2),false) mi4.setMetaValue("cluster_id",4712.1234); TEST_EQUAL(mi4.metaValueExists(2),true) END_SECTION START_SECTION(([EXTRA] void getKeys(std::vector<String>& keys) const)) std::vector<String> keys; mi.getKeys(keys); TEST_EQUAL(keys.size(),2) TEST_EQUAL(keys[0],"cluster_id") TEST_EQUAL(keys[1],"testname") END_SECTION START_SECTION((void clearMetaInfo())) MetaInfoInterface i; TEST_EQUAL(i.isMetaEmpty(),true) i.setMetaValue("label",String("test")); TEST_EQUAL(i.isMetaEmpty(),false) i.clearMetaInfo(); TEST_EQUAL(i.isMetaEmpty(),true) END_SECTION START_SECTION((bool operator== (const MetaInfoInterface& rhs) const)) MetaInfoInterface i,i2; TEST_EQUAL(i==i2,true) TEST_EQUAL(i2==i,true) i.setMetaValue("label",String("test")); TEST_EQUAL(i==i2,false) TEST_EQUAL(i2==i,false) i2.setMetaValue("label",String("test")); TEST_EQUAL(i==i2,true) TEST_EQUAL(i2==i,true) END_SECTION START_SECTION((bool operator!= (const MetaInfoInterface& rhs) const)) MetaInfoInterface i,i2; TEST_EQUAL(i!=i2,false) TEST_EQUAL(i2!=i,false) i.setMetaValue("label",String("test")); TEST_EQUAL(i!=i2,true) TEST_EQUAL(i2!=i,true) i2.setMetaValue("label",String("test")); TEST_EQUAL(i!=i2,false) TEST_EQUAL(i2!=i,false) END_SECTION START_SECTION((void removeMetaValue(UInt index))) MetaInfoInterface i,i2; i.setMetaValue(1,String("bla")); TEST_EQUAL(i==i2,false) i.removeMetaValue(1); TEST_EQUAL(i==i2,true) //try if removing a non-existing value works as well i.removeMetaValue(1234); END_SECTION START_SECTION((void removeMetaValue(const String& name))) MetaInfoInterface i,i2; i.setMetaValue("label",String("bla")); TEST_EQUAL(i==i2,false) i.removeMetaValue("label"); TEST_EQUAL(i==i2,true) //try if removing a non-existing value works as well i.removeMetaValue("icon"); END_SECTION ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// END_TEST
34.527778
123
0.713033
vmusch
f568388f82858f3891e51bf19fa53d3dbb9de993
71,015
cpp
C++
framework/common/tcuTextureUtil.cpp
asimiklit/VK-GL-CTS
ededa67cb12aec0c5e92e3eba40d3f3c7b4d697f
[ "Apache-2.0" ]
1
2021-07-15T23:37:39.000Z
2021-07-15T23:37:39.000Z
framework/common/tcuTextureUtil.cpp
asimiklit/VK-GL-CTS
ededa67cb12aec0c5e92e3eba40d3f3c7b4d697f
[ "Apache-2.0" ]
1
2021-03-22T09:53:25.000Z
2021-03-22T09:53:25.000Z
framework/common/tcuTextureUtil.cpp
asimiklit/VK-GL-CTS
ededa67cb12aec0c5e92e3eba40d3f3c7b4d697f
[ "Apache-2.0" ]
null
null
null
/*------------------------------------------------------------------------- * drawElements Quality Program Tester Core * ---------------------------------------- * * Copyright 2014 The Android Open Source Project * * 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. * *//*! * \file * \brief Texture utilities. *//*--------------------------------------------------------------------*/ #include "tcuTextureUtil.hpp" #include "tcuVectorUtil.hpp" #include "deRandom.hpp" #include "deMath.h" #include "deMemory.h" #include <limits> namespace tcu { static inline float sRGBChannelToLinear (float cs) { if (cs <= 0.04045) return cs / 12.92f; else return deFloatPow((cs + 0.055f) / 1.055f, 2.4f); } static const deUint32 s_srgb8Lut[256] = { #include "tcuSRGB8Lut.inl" }; static inline float sRGB8ChannelToLinear (deUint32 cs) { DE_ASSERT(cs < 256); // \note This triggers UB, but in practice it doesn't cause any problems return ((const float*)s_srgb8Lut)[cs]; } static inline float linearChannelToSRGB (float cl) { if (cl <= 0.0f) return 0.0f; else if (cl < 0.0031308f) return 12.92f*cl; else if (cl < 1.0f) return 1.055f*deFloatPow(cl, 0.41666f) - 0.055f; else return 1.0f; } //! Convert sRGB to linear colorspace Vec4 sRGBToLinear (const Vec4& cs) { return Vec4(sRGBChannelToLinear(cs[0]), sRGBChannelToLinear(cs[1]), sRGBChannelToLinear(cs[2]), cs[3]); } Vec4 sRGB8ToLinear (const UVec4& cs) { return Vec4(sRGB8ChannelToLinear(cs[0]), sRGB8ChannelToLinear(cs[1]), sRGB8ChannelToLinear(cs[2]), 1.0f); } Vec4 sRGBA8ToLinear (const UVec4& cs) { return Vec4(sRGB8ChannelToLinear(cs[0]), sRGB8ChannelToLinear(cs[1]), sRGB8ChannelToLinear(cs[2]), (float)cs[3] / 255.0f); } //! Convert from linear to sRGB colorspace Vec4 linearToSRGB (const Vec4& cl) { return Vec4(linearChannelToSRGB(cl[0]), linearChannelToSRGB(cl[1]), linearChannelToSRGB(cl[2]), cl[3]); } bool isSRGB (TextureFormat format) { // make sure to update this if type table is updated DE_STATIC_ASSERT(TextureFormat::CHANNELORDER_LAST == 22); return format.order == TextureFormat::sR || format.order == TextureFormat::sRG || format.order == TextureFormat::sRGB || format.order == TextureFormat::sRGBA || format.order == TextureFormat::sBGR || format.order == TextureFormat::sBGRA; } tcu::Vec4 linearToSRGBIfNeeded (const TextureFormat& format, const tcu::Vec4& color) { return isSRGB(format) ? linearToSRGB(color) : color; } bool isCombinedDepthStencilType (TextureFormat::ChannelType type) { // make sure to update this if type table is updated DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 48); return type == TextureFormat::UNSIGNED_INT_16_8_8 || type == TextureFormat::UNSIGNED_INT_24_8 || type == TextureFormat::UNSIGNED_INT_24_8_REV || type == TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV; } bool hasStencilComponent (TextureFormat::ChannelOrder order) { DE_STATIC_ASSERT(TextureFormat::CHANNELORDER_LAST == 22); switch (order) { case TextureFormat::S: case TextureFormat::DS: return true; default: return false; } } bool hasDepthComponent (TextureFormat::ChannelOrder order) { DE_STATIC_ASSERT(TextureFormat::CHANNELORDER_LAST == 22); switch (order) { case TextureFormat::D: case TextureFormat::DS: return true; default: return false; } } //! Get texture channel class for format - how the values are stored (not how they are sampled) TextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType) { // make sure this table is updated if format table is updated DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 48); switch (channelType) { case TextureFormat::SNORM_INT8: return TEXTURECHANNELCLASS_SIGNED_FIXED_POINT; case TextureFormat::SNORM_INT16: return TEXTURECHANNELCLASS_SIGNED_FIXED_POINT; case TextureFormat::SNORM_INT32: return TEXTURECHANNELCLASS_SIGNED_FIXED_POINT; case TextureFormat::UNORM_INT8: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_INT16: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_INT24: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_INT32: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_BYTE_44: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_SHORT_565: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_SHORT_555: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_SHORT_4444: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_SHORT_5551: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_SHORT_1555: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNSIGNED_BYTE_44: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNSIGNED_SHORT_565: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNSIGNED_SHORT_4444: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNSIGNED_SHORT_5551: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNORM_INT_101010: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::SNORM_INT_1010102_REV: return TEXTURECHANNELCLASS_SIGNED_FIXED_POINT; case TextureFormat::UNORM_INT_1010102_REV: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::SIGNED_INT_1010102_REV: return TEXTURECHANNELCLASS_SIGNED_INTEGER; case TextureFormat::UNSIGNED_INT_1010102_REV: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV: return TEXTURECHANNELCLASS_FLOATING_POINT; case TextureFormat::UNSIGNED_INT_999_E5_REV: return TEXTURECHANNELCLASS_FLOATING_POINT; case TextureFormat::UNSIGNED_INT_16_8_8: return TEXTURECHANNELCLASS_LAST; //!< packed unorm16-x8-uint8 case TextureFormat::UNSIGNED_INT_24_8: return TEXTURECHANNELCLASS_LAST; //!< packed unorm24-uint8 case TextureFormat::UNSIGNED_INT_24_8_REV: return TEXTURECHANNELCLASS_LAST; //!< packed unorm24-uint8 case TextureFormat::SIGNED_INT8: return TEXTURECHANNELCLASS_SIGNED_INTEGER; case TextureFormat::SIGNED_INT16: return TEXTURECHANNELCLASS_SIGNED_INTEGER; case TextureFormat::SIGNED_INT32: return TEXTURECHANNELCLASS_SIGNED_INTEGER; case TextureFormat::SIGNED_INT64: return TEXTURECHANNELCLASS_SIGNED_INTEGER; case TextureFormat::UNSIGNED_INT8: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNSIGNED_INT16: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNSIGNED_INT24: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNSIGNED_INT32: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::UNSIGNED_INT64: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::HALF_FLOAT: return TEXTURECHANNELCLASS_FLOATING_POINT; case TextureFormat::FLOAT: return TEXTURECHANNELCLASS_FLOATING_POINT; case TextureFormat::FLOAT64: return TEXTURECHANNELCLASS_FLOATING_POINT; case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV: return TEXTURECHANNELCLASS_LAST; //!< packed float32-pad24-uint8 case TextureFormat::UNORM_SHORT_10: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::UNORM_SHORT_12: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; case TextureFormat::USCALED_INT8: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::USCALED_INT16: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::SSCALED_INT8: return TEXTURECHANNELCLASS_SIGNED_INTEGER; case TextureFormat::SSCALED_INT16: return TEXTURECHANNELCLASS_SIGNED_INTEGER; case TextureFormat::USCALED_INT_1010102_REV: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; case TextureFormat::SSCALED_INT_1010102_REV: return TEXTURECHANNELCLASS_SIGNED_INTEGER; default: DE_FATAL("Unknown channel type"); return TEXTURECHANNELCLASS_LAST; } } bool isAccessValid (TextureFormat format, TextureAccessType type) { DE_ASSERT(isValid(format)); if (format.order == TextureFormat::DS) { // It is never allowed to access combined depth-stencil format with getPixel(). // Instead either getPixDepth() or getPixStencil(), or effective depth- or stencil- // access must be used. return false; } else if (format.order == TextureFormat::D) return type == TEXTUREACCESSTYPE_FLOAT; else if (format.order == TextureFormat::S) return type == TEXTUREACCESSTYPE_UNSIGNED_INT; else { // A few packed color formats have access type restrictions if (format.type == TextureFormat::UNSIGNED_INT_11F_11F_10F_REV || format.type == TextureFormat::UNSIGNED_INT_999_E5_REV) return type == TEXTUREACCESSTYPE_FLOAT; else return true; } } /*--------------------------------------------------------------------*//*! * \brief Get access to subregion of pixel buffer * \param access Parent access object * \param x X offset * \param y Y offset * \param z Z offset * \param width Width * \param height Height * \param depth Depth * \return Access object that targets given subregion of parent access object *//*--------------------------------------------------------------------*/ ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int z, int width, int height, int depth) { DE_ASSERT(de::inBounds(x, 0, access.getWidth())); DE_ASSERT(de::inRange(x+width, x+1, access.getWidth())); DE_ASSERT(de::inBounds(y, 0, access.getHeight())); DE_ASSERT(de::inRange(y+height, y+1, access.getHeight())); DE_ASSERT(de::inBounds(z, 0, access.getDepth())); DE_ASSERT(de::inRange(z+depth, z+1, access.getDepth())); return ConstPixelBufferAccess(access.getFormat(), tcu::IVec3(width, height, depth), access.getPitch(), (const deUint8*)access.getDataPtr() + access.getPixelPitch()*x + access.getRowPitch()*y + access.getSlicePitch()*z); } /*--------------------------------------------------------------------*//*! * \brief Get access to subregion of pixel buffer * \param access Parent access object * \param x X offset * \param y Y offset * \param z Z offset * \param width Width * \param height Height * \param depth Depth * \return Access object that targets given subregion of parent access object *//*--------------------------------------------------------------------*/ PixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int z, int width, int height, int depth) { DE_ASSERT(de::inBounds(x, 0, access.getWidth())); DE_ASSERT(de::inRange(x+width, x+1, access.getWidth())); DE_ASSERT(de::inBounds(y, 0, access.getHeight())); DE_ASSERT(de::inRange(y+height, y+1, access.getHeight())); DE_ASSERT(de::inBounds(z, 0, access.getDepth())); DE_ASSERT(de::inRange(z+depth, z+1, access.getDepth())); return PixelBufferAccess(access.getFormat(), tcu::IVec3(width, height, depth), access.getPitch(), (deUint8*)access.getDataPtr() + access.getPixelPitch()*x + access.getRowPitch()*y + access.getSlicePitch()*z); } /*--------------------------------------------------------------------*//*! * \brief Get access to subregion of pixel buffer * \param access Parent access object * \param x X offset * \param y Y offset * \param width Width * \param height Height * \return Access object that targets given subregion of parent access object *//*--------------------------------------------------------------------*/ PixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int width, int height) { return getSubregion(access, x, y, 0, width, height, 1); } /*--------------------------------------------------------------------*//*! * \brief Get access to subregion of pixel buffer * \param access Parent access object * \param x X offset * \param y Y offset * \param width Width * \param height Height * \return Access object that targets given subregion of parent access object *//*--------------------------------------------------------------------*/ ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int width, int height) { return getSubregion(access, x, y, 0, width, height, 1); } /*--------------------------------------------------------------------*//*! * \brief Flip rows in Y direction * \param access Access object * \return Modified access object where Y coordinates are reversed *//*--------------------------------------------------------------------*/ PixelBufferAccess flipYAccess (const PixelBufferAccess& access) { const int rowPitch = access.getRowPitch(); const int offsetToLast = rowPitch*(access.getHeight()-1); const tcu::IVec3 pitch (access.getPixelPitch(), -rowPitch, access.getSlicePitch()); return PixelBufferAccess(access.getFormat(), access.getSize(), pitch, (deUint8*)access.getDataPtr() + offsetToLast); } /*--------------------------------------------------------------------*//*! * \brief Flip rows in Y direction * \param access Access object * \return Modified access object where Y coordinates are reversed *//*--------------------------------------------------------------------*/ ConstPixelBufferAccess flipYAccess (const ConstPixelBufferAccess& access) { const int rowPitch = access.getRowPitch(); const int offsetToLast = rowPitch*(access.getHeight()-1); const tcu::IVec3 pitch (access.getPixelPitch(), -rowPitch, access.getSlicePitch()); return ConstPixelBufferAccess(access.getFormat(), access.getSize(), pitch, (deUint8*)access.getDataPtr() + offsetToLast); } static Vec2 getFloatChannelValueRange (TextureFormat::ChannelType channelType) { // make sure this table is updated if format table is updated DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 48); float cMin = 0.0f; float cMax = 0.0f; switch (channelType) { // Signed normalized formats. case TextureFormat::SNORM_INT8: case TextureFormat::SNORM_INT16: case TextureFormat::SNORM_INT32: case TextureFormat::SNORM_INT_1010102_REV: cMin = -1.0f; cMax = 1.0f; break; // Unsigned normalized formats. case TextureFormat::UNORM_INT8: case TextureFormat::UNORM_INT16: case TextureFormat::UNORM_INT24: case TextureFormat::UNORM_INT32: case TextureFormat::UNORM_BYTE_44: case TextureFormat::UNORM_SHORT_565: case TextureFormat::UNORM_SHORT_555: case TextureFormat::UNORM_SHORT_4444: case TextureFormat::UNORM_SHORT_5551: case TextureFormat::UNORM_SHORT_1555: case TextureFormat::UNORM_INT_101010: case TextureFormat::UNORM_INT_1010102_REV: case TextureFormat::UNORM_SHORT_10: case TextureFormat::UNORM_SHORT_12: cMin = 0.0f; cMax = 1.0f; break; // Misc formats. case TextureFormat::SIGNED_INT8: cMin = -128.0f; cMax = 127.0f; break; case TextureFormat::SIGNED_INT16: cMin = -32768.0f; cMax = 32767.0f; break; case TextureFormat::SIGNED_INT32: cMin = -2147483520.0f; cMax = 2147483520.0f; break; // Maximum exactly representable 31-bit integer: (2^24 - 1) * 2^7 case TextureFormat::UNSIGNED_INT8: cMin = 0.0f; cMax = 255.0f; break; case TextureFormat::UNSIGNED_INT16: cMin = 0.0f; cMax = 65535.0f; break; case TextureFormat::UNSIGNED_INT24: cMin = 0.0f; cMax = 16777215.0f; break; case TextureFormat::UNSIGNED_INT32: cMin = 0.0f; cMax = 4294967040.f; break; // Maximum exactly representable 32-bit integer: (2^24 - 1) * 2^8 case TextureFormat::HALF_FLOAT: cMin = -1e3f; cMax = 1e3f; break; case TextureFormat::FLOAT: cMin = -1e5f; cMax = 1e5f; break; case TextureFormat::FLOAT64: cMin = -1e5f; cMax = 1e5f; break; case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV: cMin = 0.0f; cMax = 1e4f; break; case TextureFormat::UNSIGNED_INT_999_E5_REV: cMin = 0.0f; cMax = 0.5e5f; break; case TextureFormat::UNSIGNED_BYTE_44: cMin = 0.0f; cMax = 15.f; break; case TextureFormat::UNSIGNED_SHORT_4444: cMin = 0.0f; cMax = 15.f; break; case TextureFormat::USCALED_INT8: cMin = 0.0f; cMax = 255.0f; break; case TextureFormat::USCALED_INT16: cMin = 0.0f; cMax = 65535.0f; break; case TextureFormat::SSCALED_INT8: cMin = -128.0f; cMax = 127.0f; break; case TextureFormat::SSCALED_INT16: cMin = -32768.0f; cMax = 32767.0f; break; case TextureFormat::USCALED_INT_1010102_REV: cMin = 0.0f; cMax = 1023.0f; break; case TextureFormat::SSCALED_INT_1010102_REV: cMin = -512.0f; cMax = 511.0f; break; default: DE_ASSERT(false); } return Vec2(cMin, cMax); } /*--------------------------------------------------------------------*//*! * \brief Get standard parameters for testing texture format * * Returns TextureFormatInfo that describes good parameters for exercising * given TextureFormat. Parameters include value ranges per channel and * suitable lookup scaling and bias in order to reduce result back to * 0..1 range. *//*--------------------------------------------------------------------*/ TextureFormatInfo getTextureFormatInfo (const TextureFormat& format) { // Special cases. if (format.type == TextureFormat::UNSIGNED_INT_1010102_REV) return TextureFormatInfo(Vec4( 0.0f, 0.0f, 0.0f, 0.0f), Vec4( 1023.0f, 1023.0f, 1023.0f, 3.0f), Vec4(1.0f/1023.f, 1.0f/1023.0f, 1.0f/1023.0f, 1.0f/3.0f), Vec4( 0.0f, 0.0f, 0.0f, 0.0f)); if (format.type == TextureFormat::SIGNED_INT_1010102_REV) return TextureFormatInfo(Vec4( -512.0f, -512.0f, -512.0f, -2.0f), Vec4( 511.0f, 511.0f, 511.0f, 1.0f), Vec4(1.0f/1023.f, 1.0f/1023.0f, 1.0f/1023.0f, 1.0f/3.0f), Vec4( 0.5f, 0.5f, 0.5f, 0.5f)); else if (format.order == TextureFormat::D || format.order == TextureFormat::DS) return TextureFormatInfo(Vec4(0.0f, 0.0f, 0.0f, 0.0f), Vec4(1.0f, 1.0f, 1.0f, 0.0f), Vec4(1.0f, 1.0f, 1.0f, 1.0f), Vec4(0.0f, 0.0f, 0.0f, 0.0f)); // Depth / stencil formats. else if (format == TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_SHORT_5551)) return TextureFormatInfo(Vec4(0.0f, 0.0f, 0.0f, 0.5f), Vec4(1.0f, 1.0f, 1.0f, 1.5f), Vec4(1.0f, 1.0f, 1.0f, 1.0f), Vec4(0.0f, 0.0f, 0.0f, 0.0f)); else if (format.type == TextureFormat::UNSIGNED_SHORT_5551) return TextureFormatInfo(Vec4( 0.0f, 0.0f, 0.0f, 0.0f), Vec4( 31.0f, 31.0f, 31.0f, 1.0f), Vec4(1.0f/31.f, 1.0f/31.0f, 1.0f/31.0f, 1.0f), Vec4( 0.0f, 0.0f, 0.0f, 0.0f)); else if (format.type == TextureFormat::UNSIGNED_SHORT_565) return TextureFormatInfo(Vec4( 0.0f, 0.0f, 0.0f, 0.0f), Vec4( 31.0f, 63.0f, 31.0f, 0.0f), Vec4(1.0f/31.f, 1.0f/63.0f, 1.0f/31.0f, 1.0f), Vec4( 0.0f, 0.0f, 0.0f, 0.0f)); const Vec2 cRange = getFloatChannelValueRange(format.type); const TextureSwizzle::Channel* map = getChannelReadSwizzle(format.order).components; const BVec4 chnMask = BVec4(deInRange32(map[0], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[1], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[2], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[3], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE); const float scale = 1.0f / (cRange[1] - cRange[0]); const float bias = -cRange[0] * scale; return TextureFormatInfo(select(cRange[0], 0.0f, chnMask), select(cRange[1], 0.0f, chnMask), select(scale, 1.0f, chnMask), select(bias, 0.0f, chnMask)); } IVec4 getFormatMinIntValue (const TextureFormat& format) { DE_ASSERT(getTextureChannelClass(format.type) == TEXTURECHANNELCLASS_SIGNED_INTEGER); switch (format.type) { case TextureFormat::SIGNED_INT8: return IVec4(std::numeric_limits<deInt8>::min()); case TextureFormat::SIGNED_INT16: return IVec4(std::numeric_limits<deInt16>::min()); case TextureFormat::SIGNED_INT32: return IVec4(std::numeric_limits<deInt32>::min()); default: DE_FATAL("Invalid channel type"); return IVec4(0); } } IVec4 getFormatMaxIntValue (const TextureFormat& format) { DE_ASSERT(getTextureChannelClass(format.type) == TEXTURECHANNELCLASS_SIGNED_INTEGER); if (format == TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT_1010102_REV) || format == TextureFormat(TextureFormat::BGRA, TextureFormat::SSCALED_INT_1010102_REV) || format == TextureFormat(TextureFormat::RGBA, TextureFormat::SSCALED_INT_1010102_REV) || format == TextureFormat(TextureFormat::BGRA, TextureFormat::SIGNED_INT_1010102_REV)) return IVec4(511, 511, 511, 1); switch (format.type) { case TextureFormat::SIGNED_INT8: return IVec4(std::numeric_limits<deInt8>::max()); case TextureFormat::SIGNED_INT16: return IVec4(std::numeric_limits<deInt16>::max()); case TextureFormat::SIGNED_INT32: return IVec4(std::numeric_limits<deInt32>::max()); case TextureFormat::SSCALED_INT8: return IVec4(std::numeric_limits<deInt8>::max()); case TextureFormat::SSCALED_INT16: return IVec4(std::numeric_limits<deInt16>::max()); default: DE_FATAL("Invalid channel type"); return IVec4(0); } } UVec4 getFormatMaxUintValue (const TextureFormat& format) { DE_ASSERT(getTextureChannelClass(format.type) == TEXTURECHANNELCLASS_UNSIGNED_INTEGER); if (format == TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT_1010102_REV) || format == TextureFormat(TextureFormat::RGBA, TextureFormat::USCALED_INT_1010102_REV) || format == TextureFormat(TextureFormat::BGRA, TextureFormat::USCALED_INT_1010102_REV) || format == TextureFormat(TextureFormat::BGRA, TextureFormat::UNSIGNED_INT_1010102_REV)) return UVec4(1023u, 1023u, 1023u, 3u); switch (format.type) { case TextureFormat::UNSIGNED_INT8: return UVec4(std::numeric_limits<deUint8>::max()); case TextureFormat::UNSIGNED_INT16: return UVec4(std::numeric_limits<deUint16>::max()); case TextureFormat::UNSIGNED_INT24: return UVec4(0xffffffu); case TextureFormat::UNSIGNED_INT32: return UVec4(std::numeric_limits<deUint32>::max()); case TextureFormat::USCALED_INT8: return UVec4(std::numeric_limits<deUint8>::max()); case TextureFormat::USCALED_INT16: return UVec4(std::numeric_limits<deUint16>::max()); default: DE_FATAL("Invalid channel type"); return UVec4(0); } } static IVec4 getChannelBitDepth (TextureFormat::ChannelType channelType) { // make sure this table is updated if format table is updated DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 48); switch (channelType) { case TextureFormat::SNORM_INT8: return IVec4(8); case TextureFormat::SNORM_INT16: return IVec4(16); case TextureFormat::SNORM_INT32: return IVec4(32); case TextureFormat::UNORM_INT8: return IVec4(8); case TextureFormat::UNORM_INT16: return IVec4(16); case TextureFormat::UNORM_INT24: return IVec4(24); case TextureFormat::UNORM_INT32: return IVec4(32); case TextureFormat::UNORM_BYTE_44: return IVec4(4,4,0,0); case TextureFormat::UNORM_SHORT_565: return IVec4(5,6,5,0); case TextureFormat::UNORM_SHORT_4444: return IVec4(4); case TextureFormat::UNORM_SHORT_555: return IVec4(5,5,5,0); case TextureFormat::UNORM_SHORT_5551: return IVec4(5,5,5,1); case TextureFormat::UNORM_SHORT_1555: return IVec4(1,5,5,5); case TextureFormat::UNSIGNED_BYTE_44: return IVec4(4,4,0,0); case TextureFormat::UNSIGNED_SHORT_565: return IVec4(5,6,5,0); case TextureFormat::UNSIGNED_SHORT_4444: return IVec4(4); case TextureFormat::UNSIGNED_SHORT_5551: return IVec4(5,5,5,1); case TextureFormat::UNORM_INT_101010: return IVec4(10,10,10,0); case TextureFormat::SNORM_INT_1010102_REV: return IVec4(10,10,10,2); case TextureFormat::UNORM_INT_1010102_REV: return IVec4(10,10,10,2); case TextureFormat::SIGNED_INT8: return IVec4(8); case TextureFormat::SIGNED_INT16: return IVec4(16); case TextureFormat::SIGNED_INT32: return IVec4(32); case TextureFormat::SIGNED_INT64: return IVec4(64); case TextureFormat::UNSIGNED_INT8: return IVec4(8); case TextureFormat::UNSIGNED_INT16: return IVec4(16); case TextureFormat::UNSIGNED_INT24: return IVec4(24); case TextureFormat::UNSIGNED_INT32: return IVec4(32); case TextureFormat::UNSIGNED_INT64: return IVec4(64); case TextureFormat::SIGNED_INT_1010102_REV: return IVec4(10,10,10,2); case TextureFormat::UNSIGNED_INT_1010102_REV: return IVec4(10,10,10,2); case TextureFormat::UNSIGNED_INT_16_8_8: return IVec4(16,8,0,0); case TextureFormat::UNSIGNED_INT_24_8: return IVec4(24,8,0,0); case TextureFormat::UNSIGNED_INT_24_8_REV: return IVec4(24,8,0,0); case TextureFormat::HALF_FLOAT: return IVec4(16); case TextureFormat::FLOAT: return IVec4(32); case TextureFormat::FLOAT64: return IVec4(64); case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV: return IVec4(11,11,10,0); case TextureFormat::UNSIGNED_INT_999_E5_REV: return IVec4(9,9,9,0); case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV: return IVec4(32,8,0,0); case TextureFormat::UNORM_SHORT_10: return IVec4(10); case TextureFormat::UNORM_SHORT_12: return IVec4(12); case TextureFormat::USCALED_INT8: return IVec4(8); case TextureFormat::USCALED_INT16: return IVec4(16); case TextureFormat::SSCALED_INT8: return IVec4(8); case TextureFormat::SSCALED_INT16: return IVec4(16); case TextureFormat::USCALED_INT_1010102_REV: return IVec4(10,10,10,2); case TextureFormat::SSCALED_INT_1010102_REV: return IVec4(10,10,10,2); default: DE_ASSERT(false); return IVec4(0); } } IVec4 getTextureFormatBitDepth (const TextureFormat& format) { const IVec4 chnBits = getChannelBitDepth(format.type); const TextureSwizzle::Channel* map = getChannelReadSwizzle(format.order).components; const BVec4 chnMask = BVec4(deInRange32(map[0], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[1], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[2], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[3], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE); const IVec4 chnSwz = IVec4((chnMask[0]) ? ((int)map[0]) : (0), (chnMask[1]) ? ((int)map[1]) : (0), (chnMask[2]) ? ((int)map[2]) : (0), (chnMask[3]) ? ((int)map[3]) : (0)); return select(chnBits.swizzle(chnSwz.x(), chnSwz.y(), chnSwz.z(), chnSwz.w()), IVec4(0), chnMask); } static IVec4 getChannelMantissaBitDepth (TextureFormat::ChannelType channelType) { // make sure this table is updated if format table is updated DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 48); switch (channelType) { case TextureFormat::SNORM_INT8: case TextureFormat::SNORM_INT16: case TextureFormat::SNORM_INT32: case TextureFormat::UNORM_INT8: case TextureFormat::UNORM_INT16: case TextureFormat::UNORM_INT24: case TextureFormat::UNORM_INT32: case TextureFormat::UNORM_BYTE_44: case TextureFormat::UNORM_SHORT_565: case TextureFormat::UNORM_SHORT_4444: case TextureFormat::UNORM_SHORT_555: case TextureFormat::UNORM_SHORT_5551: case TextureFormat::UNORM_SHORT_1555: case TextureFormat::UNSIGNED_BYTE_44: case TextureFormat::UNSIGNED_SHORT_565: case TextureFormat::UNSIGNED_SHORT_4444: case TextureFormat::UNSIGNED_SHORT_5551: case TextureFormat::UNORM_INT_101010: case TextureFormat::SNORM_INT_1010102_REV: case TextureFormat::UNORM_INT_1010102_REV: case TextureFormat::SIGNED_INT8: case TextureFormat::SIGNED_INT16: case TextureFormat::SIGNED_INT32: case TextureFormat::UNSIGNED_INT8: case TextureFormat::UNSIGNED_INT16: case TextureFormat::UNSIGNED_INT24: case TextureFormat::UNSIGNED_INT32: case TextureFormat::SIGNED_INT_1010102_REV: case TextureFormat::UNSIGNED_INT_1010102_REV: case TextureFormat::UNSIGNED_INT_16_8_8: case TextureFormat::UNSIGNED_INT_24_8: case TextureFormat::UNSIGNED_INT_24_8_REV: case TextureFormat::UNSIGNED_INT_999_E5_REV: case TextureFormat::UNORM_SHORT_10: case TextureFormat::UNORM_SHORT_12: case TextureFormat::USCALED_INT8: case TextureFormat::USCALED_INT16: case TextureFormat::SSCALED_INT8: case TextureFormat::SSCALED_INT16: case TextureFormat::USCALED_INT_1010102_REV: case TextureFormat::SSCALED_INT_1010102_REV: return getChannelBitDepth(channelType); case TextureFormat::HALF_FLOAT: return IVec4(10); case TextureFormat::FLOAT: return IVec4(23); case TextureFormat::FLOAT64: return IVec4(52); case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV: return IVec4(6,6,5,0); case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV: return IVec4(23,8,0,0); default: DE_ASSERT(false); return IVec4(0); } } IVec4 getTextureFormatMantissaBitDepth (const TextureFormat& format) { const IVec4 chnBits = getChannelMantissaBitDepth(format.type); const TextureSwizzle::Channel* map = getChannelReadSwizzle(format.order).components; const BVec4 chnMask = BVec4(deInRange32(map[0], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[1], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[2], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[3], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE); const IVec4 chnSwz = IVec4((chnMask[0]) ? ((int)map[0]) : (0), (chnMask[1]) ? ((int)map[1]) : (0), (chnMask[2]) ? ((int)map[2]) : (0), (chnMask[3]) ? ((int)map[3]) : (0)); return select(chnBits.swizzle(chnSwz.x(), chnSwz.y(), chnSwz.z(), chnSwz.w()), IVec4(0), chnMask); } BVec4 getTextureFormatChannelMask (const TextureFormat& format) { const TextureSwizzle::Channel* const map = getChannelReadSwizzle(format.order).components; return BVec4(deInRange32(map[0], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[1], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[2], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE, deInRange32(map[3], TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE); } static inline float linearInterpolate (float t, float minVal, float maxVal) { return minVal + (maxVal - minVal) * t; } static inline Vec4 linearInterpolate (float t, const Vec4& a, const Vec4& b) { return a + (b - a) * t; } enum { CLEAR_OPTIMIZE_THRESHOLD = 128, CLEAR_OPTIMIZE_MAX_PIXEL_SIZE = 8 }; inline void fillRow (const PixelBufferAccess& dst, int y, int z, int pixelSize, const deUint8* pixel) { DE_ASSERT(dst.getPixelPitch() == pixelSize); // only tightly packed deUint8* dstPtr = (deUint8*)dst.getPixelPtr(0, y, z); int width = dst.getWidth(); if (pixelSize == 8 && deIsAlignedPtr(dstPtr, pixelSize)) { deUint64 val; memcpy(&val, pixel, sizeof(val)); for (int i = 0; i < width; i++) ((deUint64*)dstPtr)[i] = val; } else if (pixelSize == 4 && deIsAlignedPtr(dstPtr, pixelSize)) { deUint32 val; memcpy(&val, pixel, sizeof(val)); for (int i = 0; i < width; i++) ((deUint32*)dstPtr)[i] = val; } else { for (int i = 0; i < width; i++) for (int j = 0; j < pixelSize; j++) dstPtr[i*pixelSize+j] = pixel[j]; } } void clear (const PixelBufferAccess& access, const Vec4& color) { const int pixelSize = access.getFormat().getPixelSize(); const int pixelPitch = access.getPixelPitch(); const bool rowPixelsTightlyPacked = (pixelSize == pixelPitch); if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD && pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE && rowPixelsTightlyPacked) { // Convert to destination format. union { deUint8 u8[CLEAR_OPTIMIZE_MAX_PIXEL_SIZE]; deUint64 u64; // Forces 64-bit alignment. } pixel; DE_STATIC_ASSERT(sizeof(pixel) == CLEAR_OPTIMIZE_MAX_PIXEL_SIZE); PixelBufferAccess(access.getFormat(), 1, 1, 1, 0, 0, &pixel.u8[0]).setPixel(color, 0, 0); for (int z = 0; z < access.getDepth(); z++) for (int y = 0; y < access.getHeight(); y++) fillRow(access, y, z, pixelSize, &pixel.u8[0]); } else { for (int z = 0; z < access.getDepth(); z++) for (int y = 0; y < access.getHeight(); y++) for (int x = 0; x < access.getWidth(); x++) access.setPixel(color, x, y, z); } } void clear (const PixelBufferAccess& access, const IVec4& color) { const int pixelSize = access.getFormat().getPixelSize(); const int pixelPitch = access.getPixelPitch(); const bool rowPixelsTightlyPacked = (pixelSize == pixelPitch); if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD && pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE && rowPixelsTightlyPacked) { // Convert to destination format. union { deUint8 u8[CLEAR_OPTIMIZE_MAX_PIXEL_SIZE]; deUint64 u64; // Forces 64-bit alignment. } pixel; DE_STATIC_ASSERT(sizeof(pixel) == CLEAR_OPTIMIZE_MAX_PIXEL_SIZE); PixelBufferAccess(access.getFormat(), 1, 1, 1, 0, 0, &pixel.u8[0]).setPixel(color, 0, 0); for (int z = 0; z < access.getDepth(); z++) for (int y = 0; y < access.getHeight(); y++) fillRow(access, y, z, pixelSize, &pixel.u8[0]); } else { for (int z = 0; z < access.getDepth(); z++) for (int y = 0; y < access.getHeight(); y++) for (int x = 0; x < access.getWidth(); x++) access.setPixel(color, x, y, z); } } void clear (const PixelBufferAccess& access, const UVec4& color) { clear(access, color.cast<deInt32>()); } void clearDepth (const PixelBufferAccess& access, float depth) { DE_ASSERT(access.getFormat().order == TextureFormat::DS || access.getFormat().order == TextureFormat::D); clear(getEffectiveDepthStencilAccess(access, Sampler::MODE_DEPTH), tcu::Vec4(depth, 0.0f, 0.0f, 0.0f)); } void clearStencil (const PixelBufferAccess& access, int stencil) { DE_ASSERT(access.getFormat().order == TextureFormat::DS || access.getFormat().order == TextureFormat::S); clear(getEffectiveDepthStencilAccess(access, Sampler::MODE_STENCIL), tcu::UVec4(stencil, 0u, 0u, 0u)); } enum GradientStyle { GRADIENT_STYLE_OLD = 0, GRADIENT_STYLE_NEW = 1, GRADIENT_STYLE_PYRAMID = 2 }; static void fillWithComponentGradients1D (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal, GradientStyle) { DE_ASSERT(access.getHeight() == 1); for (int x = 0; x < access.getWidth(); x++) { float s = ((float)x + 0.5f) / (float)access.getWidth(); float r = linearInterpolate(s, minVal.x(), maxVal.x()); float g = linearInterpolate(s, minVal.y(), maxVal.y()); float b = linearInterpolate(s, minVal.z(), maxVal.z()); float a = linearInterpolate(s, minVal.w(), maxVal.w()); access.setPixel(tcu::Vec4(r, g, b, a), x, 0); } } static void fillWithComponentGradients2D (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal, GradientStyle style) { if (style == GRADIENT_STYLE_PYRAMID) { int xedge = deFloorFloatToInt32(float(access.getWidth()) * 0.6f); int yedge = deFloorFloatToInt32(float(access.getHeight()) * 0.6f); for (int y = 0; y < access.getHeight(); y++) { for (int x = 0; x < access.getWidth(); x++) { float s = ((float)x + 0.5f) / (float)access.getWidth(); float t = ((float)y + 0.5f) / (float)access.getHeight(); float coefR = 0.0f; float coefG = 0.0f; float coefB = 0.0f; float coefA = 0.0f; coefR = (x < xedge) ? s * 0.4f : (1 - s) * 0.6f; coefG = (x < xedge) ? s * 0.4f : (1 - s) * 0.6f; coefB = (x < xedge) ? (1.0f - s) * 0.4f : s * 0.6f - 0.2f; coefA = (x < xedge) ? (1.0f - s) * 0.4f : s * 0.6f - 0.2f; coefR += (y < yedge) ? t * 0.4f : (1 - t) * 0.6f; coefG += (y < yedge) ? (1.0f - t) * 0.4f : t * 0.6f - 0.2f; coefB += (y < yedge) ? t * 0.4f : (1 - t) * 0.6f; coefA += (y < yedge) ? (1.0f - t) * 0.4f : t * 0.6f - 0.2f; float r = linearInterpolate(coefR, minVal.x(), maxVal.x()); float g = linearInterpolate(coefG, minVal.y(), maxVal.y()); float b = linearInterpolate(coefB, minVal.z(), maxVal.z()); float a = linearInterpolate(coefA, minVal.w(), maxVal.w()); access.setPixel(tcu::Vec4(r, g, b, a), x, y); } } } else { for (int y = 0; y < access.getHeight(); y++) { for (int x = 0; x < access.getWidth(); x++) { float s = ((float)x + 0.5f) / (float)access.getWidth(); float t = ((float)y + 0.5f) / (float)access.getHeight(); float r = linearInterpolate((s + t) *0.5f, minVal.x(), maxVal.x()); float g = linearInterpolate((s + (1.0f - t))*0.5f, minVal.y(), maxVal.y()); float b = linearInterpolate(((1.0f - s) + t) *0.5f, minVal.z(), maxVal.z()); float a = linearInterpolate(((1.0f - s) + (1.0f - t))*0.5f, minVal.w(), maxVal.w()); access.setPixel(tcu::Vec4(r, g, b, a), x, y); } } } } static void fillWithComponentGradients3D (const PixelBufferAccess& dst, const Vec4& minVal, const Vec4& maxVal, GradientStyle style) { for (int z = 0; z < dst.getDepth(); z++) { for (int y = 0; y < dst.getHeight(); y++) { for (int x = 0; x < dst.getWidth(); x++) { float s = ((float)x + 0.5f) / (float)dst.getWidth(); float t = ((float)y + 0.5f) / (float)dst.getHeight(); float p = ((float)z + 0.5f) / (float)dst.getDepth(); float r, g, b, a; if (style == GRADIENT_STYLE_NEW) { // R, G, B and A all depend on every coordinate. r = linearInterpolate((s+t+p)/3.0f, minVal.x(), maxVal.x()); g = linearInterpolate((s + (1.0f - (t+p)*0.5f)*2.0f)/3.0f, minVal.y(), maxVal.y()); b = linearInterpolate(((1.0f - (s+t)*0.5f)*2.0f + p)/3.0f, minVal.z(), maxVal.z()); a = linearInterpolate(1.0f - (s+t+p)/3.0f, minVal.w(), maxVal.w()); } else // GRADIENT_STYLE_OLD { // Each of R, G and B only depend on X, Y and Z, respectively. r = linearInterpolate(s, minVal.x(), maxVal.x()); g = linearInterpolate(t, minVal.y(), maxVal.y()); b = linearInterpolate(p, minVal.z(), maxVal.z()); a = linearInterpolate(1.0f - (s+t+p)/3.0f, minVal.w(), maxVal.w()); } dst.setPixel(tcu::Vec4(r, g, b, a), x, y, z); } } } } void fillWithComponentGradientsStyled (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal, GradientStyle style) { if (isCombinedDepthStencilType(access.getFormat().type)) { const bool hasDepth = access.getFormat().order == tcu::TextureFormat::DS || access.getFormat().order == tcu::TextureFormat::D; const bool hasStencil = access.getFormat().order == tcu::TextureFormat::DS || access.getFormat().order == tcu::TextureFormat::S; DE_ASSERT(hasDepth || hasStencil); // For combined formats, treat D and S as separate channels if (hasDepth) fillWithComponentGradientsStyled(getEffectiveDepthStencilAccess(access, tcu::Sampler::MODE_DEPTH), minVal, maxVal, style); if (hasStencil) fillWithComponentGradientsStyled(getEffectiveDepthStencilAccess(access, tcu::Sampler::MODE_STENCIL), minVal.swizzle(3,2,1,0), maxVal.swizzle(3,2,1,0), style); } else { if (access.getHeight() == 1 && access.getDepth() == 1) fillWithComponentGradients1D(access, minVal, maxVal, style); else if (access.getDepth() == 1) fillWithComponentGradients2D(access, minVal, maxVal, style); else fillWithComponentGradients3D(access, minVal, maxVal, style); } } void fillWithComponentGradients (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal) { fillWithComponentGradientsStyled(access, minVal, maxVal, GRADIENT_STYLE_OLD); } void fillWithComponentGradients2 (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal) { fillWithComponentGradientsStyled(access, minVal, maxVal, GRADIENT_STYLE_NEW); } void fillWithComponentGradients3(const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal) { fillWithComponentGradientsStyled(access, minVal, maxVal, GRADIENT_STYLE_PYRAMID); } static void fillWithGrid1D (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB) { for (int x = 0; x < access.getWidth(); x++) { int mx = (x / cellSize) % 2; if (mx) access.setPixel(colorB, x, 0); else access.setPixel(colorA, x, 0); } } static void fillWithGrid2D (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB) { for (int y = 0; y < access.getHeight(); y++) { for (int x = 0; x < access.getWidth(); x++) { int mx = (x / cellSize) % 2; int my = (y / cellSize) % 2; if (mx ^ my) access.setPixel(colorB, x, y); else access.setPixel(colorA, x, y); } } } static void fillWithGrid3D (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB) { for (int z = 0; z < access.getDepth(); z++) { for (int y = 0; y < access.getHeight(); y++) { for (int x = 0; x < access.getWidth(); x++) { int mx = (x / cellSize) % 2; int my = (y / cellSize) % 2; int mz = (z / cellSize) % 2; if (mx ^ my ^ mz) access.setPixel(colorB, x, y, z); else access.setPixel(colorA, x, y, z); } } } } void fillWithGrid (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB) { if (isCombinedDepthStencilType(access.getFormat().type)) { const bool hasDepth = access.getFormat().order == tcu::TextureFormat::DS || access.getFormat().order == tcu::TextureFormat::D; const bool hasStencil = access.getFormat().order == tcu::TextureFormat::DS || access.getFormat().order == tcu::TextureFormat::S; DE_ASSERT(hasDepth || hasStencil); // For combined formats, treat D and S as separate channels if (hasDepth) fillWithGrid(getEffectiveDepthStencilAccess(access, tcu::Sampler::MODE_DEPTH), cellSize, colorA, colorB); if (hasStencil) fillWithGrid(getEffectiveDepthStencilAccess(access, tcu::Sampler::MODE_STENCIL), cellSize, colorA.swizzle(3,2,1,0), colorB.swizzle(3,2,1,0)); } else { if (access.getHeight() == 1 && access.getDepth() == 1) fillWithGrid1D(access, cellSize, colorA, colorB); else if (access.getDepth() == 1) fillWithGrid2D(access, cellSize, colorA, colorB); else fillWithGrid3D(access, cellSize, colorA, colorB); } } void fillWithRepeatableGradient (const PixelBufferAccess& access, const Vec4& colorA, const Vec4& colorB) { for (int y = 0; y < access.getHeight(); y++) { for (int x = 0; x < access.getWidth(); x++) { float s = ((float)x + 0.5f) / (float)access.getWidth(); float t = ((float)y + 0.5f) / (float)access.getHeight(); float a = s > 0.5f ? (2.0f - 2.0f*s) : 2.0f*s; float b = t > 0.5f ? (2.0f - 2.0f*t) : 2.0f*t; float p = deFloatClamp(deFloatSqrt(a*a + b*b), 0.0f, 1.0f); access.setPixel(linearInterpolate(p, colorA, colorB), x, y); } } } void fillWithRGBAQuads (const PixelBufferAccess& dst) { TCU_CHECK_INTERNAL(dst.getDepth() == 1); int width = dst.getWidth(); int height = dst.getHeight(); int left = width/2; int top = height/2; clear(getSubregion(dst, 0, 0, 0, left, top, 1), Vec4(1.0f, 0.0f, 0.0f, 1.0f)); clear(getSubregion(dst, left, 0, 0, width-left, top, 1), Vec4(0.0f, 1.0f, 0.0f, 1.0f)); clear(getSubregion(dst, 0, top, 0, left, height-top, 1), Vec4(0.0f, 0.0f, 1.0f, 0.0f)); clear(getSubregion(dst, left, top, 0, width-left, height-top, 1), Vec4(0.5f, 0.5f, 0.5f, 1.0f)); } // \todo [2012-11-13 pyry] There is much better metaballs code in CL SIR value generators. void fillWithMetaballs (const PixelBufferAccess& dst, int numBalls, deUint32 seed) { TCU_CHECK_INTERNAL(dst.getDepth() == 1); std::vector<Vec2> points(numBalls); de::Random rnd(seed); for (int i = 0; i < numBalls; i++) { float x = rnd.getFloat(); float y = rnd.getFloat(); points[i] = (Vec2(x, y)); } for (int y = 0; y < dst.getHeight(); y++) for (int x = 0; x < dst.getWidth(); x++) { Vec2 p((float)x/(float)dst.getWidth(), (float)y/(float)dst.getHeight()); float sum = 0.0f; for (std::vector<Vec2>::const_iterator i = points.begin(); i != points.end(); i++) { Vec2 d = p - *i; float f = 0.01f / (d.x()*d.x() + d.y()*d.y()); sum += f; } dst.setPixel(Vec4(sum), x, y); } } void copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, const bool clearUnused) { DE_ASSERT(src.getSize() == dst.getSize()); const int width = dst.getWidth(); const int height = dst.getHeight(); const int depth = dst.getDepth(); const int srcPixelSize = src.getFormat().getPixelSize(); const int dstPixelSize = dst.getFormat().getPixelSize(); const int srcPixelPitch = src.getPixelPitch(); const int dstPixelPitch = dst.getPixelPitch(); const bool srcTightlyPacked = (srcPixelSize == srcPixelPitch); const bool dstTightlyPacked = (dstPixelSize == dstPixelPitch); const bool srcHasDepth = (src.getFormat().order == tcu::TextureFormat::DS || src.getFormat().order == tcu::TextureFormat::D); const bool srcHasStencil = (src.getFormat().order == tcu::TextureFormat::DS || src.getFormat().order == tcu::TextureFormat::S); const bool dstHasDepth = (dst.getFormat().order == tcu::TextureFormat::DS || dst.getFormat().order == tcu::TextureFormat::D); const bool dstHasStencil = (dst.getFormat().order == tcu::TextureFormat::DS || dst.getFormat().order == tcu::TextureFormat::S); if (src.getFormat() == dst.getFormat() && srcTightlyPacked && dstTightlyPacked) { // Fast-path for matching formats. for (int z = 0; z < depth; z++) for (int y = 0; y < height; y++) deMemcpy(dst.getPixelPtr(0, y, z), src.getPixelPtr(0, y, z), srcPixelSize*width); } else if (src.getFormat() == dst.getFormat()) { // Bit-exact copy for matching formats. for (int z = 0; z < depth; z++) for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) deMemcpy(dst.getPixelPtr(x, y, z), src.getPixelPtr(x, y, z), srcPixelSize); } else if (srcHasDepth || srcHasStencil || dstHasDepth || dstHasStencil) { DE_ASSERT((srcHasDepth && dstHasDepth) || (srcHasStencil && dstHasStencil)); // must have at least one common channel if (dstHasDepth && srcHasDepth) { for (int z = 0; z < depth; z++) for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) dst.setPixDepth(src.getPixDepth(x, y, z), x, y, z); } else if (dstHasDepth && !srcHasDepth && clearUnused) { // consistency with color copies tcu::clearDepth(dst, 0.0f); } if (dstHasStencil && srcHasStencil) { for (int z = 0; z < depth; z++) for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) dst.setPixStencil(src.getPixStencil(x, y, z), x, y, z); } else if (dstHasStencil && !srcHasStencil && clearUnused) { // consistency with color copies tcu::clearStencil(dst, 0u); } } else { TextureChannelClass srcClass = getTextureChannelClass(src.getFormat().type); TextureChannelClass dstClass = getTextureChannelClass(dst.getFormat().type); bool srcIsInt = srcClass == TEXTURECHANNELCLASS_SIGNED_INTEGER || srcClass == TEXTURECHANNELCLASS_UNSIGNED_INTEGER; bool dstIsInt = dstClass == TEXTURECHANNELCLASS_SIGNED_INTEGER || dstClass == TEXTURECHANNELCLASS_UNSIGNED_INTEGER; if (srcIsInt && dstIsInt) { for (int z = 0; z < depth; z++) for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) dst.setPixel(src.getPixelInt(x, y, z), x, y, z); } else { for (int z = 0; z < depth; z++) for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) dst.setPixel(src.getPixel(x, y, z), x, y, z); } } } void scale (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter) { DE_ASSERT(filter == Sampler::NEAREST || filter == Sampler::LINEAR); Sampler sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, filter, filter, 0.0f, false); float sX = (float)src.getWidth() / (float)dst.getWidth(); float sY = (float)src.getHeight() / (float)dst.getHeight(); float sZ = (float)src.getDepth() / (float)dst.getDepth(); if (dst.getDepth() == 1 && src.getDepth() == 1) { for (int y = 0; y < dst.getHeight(); y++) for (int x = 0; x < dst.getWidth(); x++) dst.setPixel(linearToSRGBIfNeeded(dst.getFormat(), src.sample2D(sampler, filter, ((float)x+0.5f)*sX, ((float)y+0.5f)*sY, 0)), x, y); } else { for (int z = 0; z < dst.getDepth(); z++) for (int y = 0; y < dst.getHeight(); y++) for (int x = 0; x < dst.getWidth(); x++) dst.setPixel(linearToSRGBIfNeeded(dst.getFormat(), src.sample3D(sampler, filter, ((float)x+0.5f)*sX, ((float)y+0.5f)*sY, ((float)z+0.5f)*sZ)), x, y, z); } } void estimatePixelValueRange (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal) { const TextureFormat& format = access.getFormat(); switch (getTextureChannelClass(format.type)) { case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: // Normalized unsigned formats. minVal = Vec4(0.0f); maxVal = Vec4(1.0f); break; case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: // Normalized signed formats. minVal = Vec4(-1.0f); maxVal = Vec4(+1.0f); break; default: // \note Samples every 4/8th pixel. minVal = Vec4(std::numeric_limits<float>::max()); maxVal = Vec4(std::numeric_limits<float>::min()); for (int z = 0; z < access.getDepth(); z += 2) { for (int y = 0; y < access.getHeight(); y += 2) { for (int x = 0; x < access.getWidth(); x += 2) { Vec4 p = access.getPixel(x, y, z); minVal[0] = (deFloatIsNaN(p[0]) ? minVal[0] : de::min(minVal[0], p[0])); minVal[1] = (deFloatIsNaN(p[1]) ? minVal[1] : de::min(minVal[1], p[1])); minVal[2] = (deFloatIsNaN(p[2]) ? minVal[2] : de::min(minVal[2], p[2])); minVal[3] = (deFloatIsNaN(p[3]) ? minVal[3] : de::min(minVal[3], p[3])); maxVal[0] = (deFloatIsNaN(p[0]) ? maxVal[0] : de::max(maxVal[0], p[0])); maxVal[1] = (deFloatIsNaN(p[1]) ? maxVal[1] : de::max(maxVal[1], p[1])); maxVal[2] = (deFloatIsNaN(p[2]) ? maxVal[2] : de::max(maxVal[2], p[2])); maxVal[3] = (deFloatIsNaN(p[3]) ? maxVal[3] : de::max(maxVal[3], p[3])); } } } break; } } void computePixelScaleBias (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias) { Vec4 minVal, maxVal; estimatePixelValueRange(access, minVal, maxVal); const float eps = 0.0001f; for (int c = 0; c < 4; c++) { if (maxVal[c] - minVal[c] < eps) { scale[c] = (maxVal[c] < eps) ? 1.0f : (1.0f / maxVal[c]); bias[c] = (c == 3) ? (1.0f - maxVal[c]*scale[c]) : (0.0f - minVal[c]*scale[c]); } else { scale[c] = 1.0f / (maxVal[c] - minVal[c]); bias[c] = 0.0f - minVal[c]*scale[c]; } } } int getCubeArrayFaceIndex (CubeFace face) { DE_ASSERT((int)face >= 0 && face < CUBEFACE_LAST); switch (face) { case CUBEFACE_POSITIVE_X: return 0; case CUBEFACE_NEGATIVE_X: return 1; case CUBEFACE_POSITIVE_Y: return 2; case CUBEFACE_NEGATIVE_Y: return 3; case CUBEFACE_POSITIVE_Z: return 4; case CUBEFACE_NEGATIVE_Z: return 5; default: return -1; } } deUint32 packRGB999E5 (const tcu::Vec4& color) { const int mBits = 9; const int eBits = 5; const int eBias = 15; const int eMax = (1<<eBits)-1; const float maxVal = (float)(((1<<mBits) - 1) * (1<<(eMax-eBias))) / (float)(1<<mBits); float rc = deFloatClamp(color[0], 0.0f, maxVal); float gc = deFloatClamp(color[1], 0.0f, maxVal); float bc = deFloatClamp(color[2], 0.0f, maxVal); float maxc = de::max(rc, de::max(gc, bc)); int exps = de::max(-eBias - 1, deFloorFloatToInt32(deFloatLog2(maxc))) + 1 + eBias; float e = deFloatPow(2.0f, (float)(exps-eBias-mBits)); int maxs = deFloorFloatToInt32(maxc / e + 0.5f); if (maxs == (1<<mBits)) { exps++; e *= 2.0f; } deUint32 rs = (deUint32)deFloorFloatToInt32(rc / e + 0.5f); deUint32 gs = (deUint32)deFloorFloatToInt32(gc / e + 0.5f); deUint32 bs = (deUint32)deFloorFloatToInt32(bc / e + 0.5f); DE_ASSERT((exps & ~((1<<5)-1)) == 0); DE_ASSERT((rs & ~((1<<9)-1)) == 0); DE_ASSERT((gs & ~((1<<9)-1)) == 0); DE_ASSERT((bs & ~((1<<9)-1)) == 0); return rs | (gs << 9) | (bs << 18) | (exps << 27); } // Sampler utils static const void* addOffset (const void* ptr, int numBytes) { return (const deUint8*)ptr + numBytes; } static void* addOffset (void* ptr, int numBytes) { return (deUint8*)ptr + numBytes; } template <typename AccessType> static AccessType toSamplerAccess (const AccessType& baseAccess, Sampler::DepthStencilMode mode) { // make sure to update this if type table is updated DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 48); if (!isCombinedDepthStencilType(baseAccess.getFormat().type)) return baseAccess; else { #if (DE_ENDIANNESS == DE_LITTLE_ENDIAN) const deUint32 uint32ByteOffsetBits0To8 = 0; //!< least significant byte in the lowest address const deUint32 uint32ByteOffsetBits0To24 = 0; const deUint32 uint32ByteOffsetBits8To32 = 1; const deUint32 uint32ByteOffsetBits16To32 = 2; const deUint32 uint32ByteOffsetBits24To32 = 3; #else const deUint32 uint32ByteOffsetBits0To8 = 3; //!< least significant byte in the highest address const deUint32 uint32ByteOffsetBits0To24 = 1; const deUint32 uint32ByteOffsetBits8To32 = 0; const deUint32 uint32ByteOffsetBits16To32 = 0; const deUint32 uint32ByteOffsetBits24To32 = 0; #endif // Sampled channel must exist DE_ASSERT(baseAccess.getFormat().order == TextureFormat::DS || (mode == Sampler::MODE_DEPTH && baseAccess.getFormat().order == TextureFormat::D) || (mode == Sampler::MODE_STENCIL && baseAccess.getFormat().order == TextureFormat::S)); // combined formats have multiple channel classes, detect on sampler settings switch (baseAccess.getFormat().type) { case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV: { if (mode == Sampler::MODE_DEPTH) { // select the float component return AccessType(TextureFormat(TextureFormat::D, TextureFormat::FLOAT), baseAccess.getSize(), baseAccess.getPitch(), baseAccess.getDataPtr()); } else if (mode == Sampler::MODE_STENCIL) { // select the uint 8 component return AccessType(TextureFormat(TextureFormat::S, TextureFormat::UNSIGNED_INT8), baseAccess.getSize(), baseAccess.getPitch(), addOffset(baseAccess.getDataPtr(), 4 + uint32ByteOffsetBits0To8)); } else { // unknown sampler mode DE_ASSERT(false); return AccessType(); } } case TextureFormat::UNSIGNED_INT_16_8_8: { if (mode == Sampler::MODE_DEPTH) { // select the unorm16 component return AccessType(TextureFormat(TextureFormat::D, TextureFormat::UNORM_INT16), baseAccess.getSize(), baseAccess.getPitch(), addOffset(baseAccess.getDataPtr(), uint32ByteOffsetBits16To32)); } else if (mode == Sampler::MODE_STENCIL) { // select the uint 8 component return AccessType(TextureFormat(TextureFormat::S, TextureFormat::UNSIGNED_INT8), baseAccess.getSize(), baseAccess.getPitch(), addOffset(baseAccess.getDataPtr(), uint32ByteOffsetBits0To8)); } else { // unknown sampler mode DE_ASSERT(false); return AccessType(); } } case TextureFormat::UNSIGNED_INT_24_8: { if (mode == Sampler::MODE_DEPTH) { // select the unorm24 component return AccessType(TextureFormat(TextureFormat::D, TextureFormat::UNORM_INT24), baseAccess.getSize(), baseAccess.getPitch(), addOffset(baseAccess.getDataPtr(), uint32ByteOffsetBits8To32)); } else if (mode == Sampler::MODE_STENCIL) { // select the uint 8 component return AccessType(TextureFormat(TextureFormat::S, TextureFormat::UNSIGNED_INT8), baseAccess.getSize(), baseAccess.getPitch(), addOffset(baseAccess.getDataPtr(), uint32ByteOffsetBits0To8)); } else { // unknown sampler mode DE_ASSERT(false); return AccessType(); } } case TextureFormat::UNSIGNED_INT_24_8_REV: { if (mode == Sampler::MODE_DEPTH) { // select the unorm24 component return AccessType(TextureFormat(TextureFormat::D, TextureFormat::UNORM_INT24), baseAccess.getSize(), baseAccess.getPitch(), addOffset(baseAccess.getDataPtr(), uint32ByteOffsetBits0To24)); } else if (mode == Sampler::MODE_STENCIL) { // select the uint 8 component return AccessType(TextureFormat(TextureFormat::S, TextureFormat::UNSIGNED_INT8), baseAccess.getSize(), baseAccess.getPitch(), addOffset(baseAccess.getDataPtr(), uint32ByteOffsetBits24To32)); } else { // unknown sampler mode DE_ASSERT(false); return AccessType(); } } default: { // unknown combined format DE_ASSERT(false); return AccessType(); } } } } PixelBufferAccess getEffectiveDepthStencilAccess (const PixelBufferAccess& baseAccess, Sampler::DepthStencilMode mode) { return toSamplerAccess<PixelBufferAccess>(baseAccess, mode); } ConstPixelBufferAccess getEffectiveDepthStencilAccess (const ConstPixelBufferAccess& baseAccess, Sampler::DepthStencilMode mode) { return toSamplerAccess<ConstPixelBufferAccess>(baseAccess, mode); } TextureFormat getEffectiveDepthStencilTextureFormat (const TextureFormat& baseFormat, Sampler::DepthStencilMode mode) { return toSamplerAccess(ConstPixelBufferAccess(baseFormat, IVec3(0, 0, 0), DE_NULL), mode).getFormat(); } template <typename ViewType> ViewType getEffectiveTView (const ViewType& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { storage.resize(src.getNumLevels()); ViewType view = ViewType(src.getNumLevels(), &storage[0], src.isES2()); for (int levelNdx = 0; levelNdx < src.getNumLevels(); ++levelNdx) storage[levelNdx] = tcu::getEffectiveDepthStencilAccess(src.getLevel(levelNdx), sampler.depthStencilMode); return view; } tcu::TextureCubeView getEffectiveTView (const tcu::TextureCubeView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { storage.resize(tcu::CUBEFACE_LAST * src.getNumLevels()); const tcu::ConstPixelBufferAccess* storagePtrs[tcu::CUBEFACE_LAST] = { &storage[0 * src.getNumLevels()], &storage[1 * src.getNumLevels()], &storage[2 * src.getNumLevels()], &storage[3 * src.getNumLevels()], &storage[4 * src.getNumLevels()], &storage[5 * src.getNumLevels()], }; tcu::TextureCubeView view = tcu::TextureCubeView(src.getNumLevels(), storagePtrs, false); for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; ++faceNdx) for (int levelNdx = 0; levelNdx < src.getNumLevels(); ++levelNdx) storage[faceNdx * src.getNumLevels() + levelNdx] = tcu::getEffectiveDepthStencilAccess(src.getLevelFace(levelNdx, (tcu::CubeFace)faceNdx), sampler.depthStencilMode); return view; } tcu::Texture1DView getEffectiveTextureView (const tcu::Texture1DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { return getEffectiveTView(src, storage, sampler); } tcu::Texture2DView getEffectiveTextureView (const tcu::Texture2DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { return getEffectiveTView(src, storage, sampler); } tcu::Texture3DView getEffectiveTextureView (const tcu::Texture3DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { return getEffectiveTView(src, storage, sampler); } tcu::Texture1DArrayView getEffectiveTextureView (const tcu::Texture1DArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { return getEffectiveTView(src, storage, sampler); } tcu::Texture2DArrayView getEffectiveTextureView (const tcu::Texture2DArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { return getEffectiveTView(src, storage, sampler); } tcu::TextureCubeView getEffectiveTextureView (const tcu::TextureCubeView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { return getEffectiveTView(src, storage, sampler); } tcu::TextureCubeArrayView getEffectiveTextureView (const tcu::TextureCubeArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler) { return getEffectiveTView(src, storage, sampler); } //! Returns the effective swizzle of a border color. The effective swizzle is the //! equal to first writing an RGBA color with a write swizzle and then reading //! it back using a read swizzle, i.e. BorderSwizzle(c) == readSwizzle(writeSwizzle(C)) static const TextureSwizzle& getBorderColorReadSwizzle (TextureFormat::ChannelOrder order) { // make sure to update these tables when channel orders are updated DE_STATIC_ASSERT(TextureFormat::CHANNELORDER_LAST == 22); static const TextureSwizzle INV = {{ TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; static const TextureSwizzle R = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; static const TextureSwizzle A = {{ TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_3 }}; static const TextureSwizzle I = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0 }}; static const TextureSwizzle L = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ONE }}; static const TextureSwizzle LA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3 }}; static const TextureSwizzle RG = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; static const TextureSwizzle RA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_3 }}; static const TextureSwizzle RGB = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_ONE }}; static const TextureSwizzle RGBA = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_1, TextureSwizzle::CHANNEL_2, TextureSwizzle::CHANNEL_3 }}; static const TextureSwizzle D = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; static const TextureSwizzle S = {{ TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ZERO, TextureSwizzle::CHANNEL_ONE }}; const TextureSwizzle* swizzle; switch (order) { case TextureFormat::R: swizzle = &R; break; case TextureFormat::A: swizzle = &A; break; case TextureFormat::I: swizzle = &I; break; case TextureFormat::L: swizzle = &L; break; case TextureFormat::LA: swizzle = &LA; break; case TextureFormat::RG: swizzle = &RG; break; case TextureFormat::RA: swizzle = &RA; break; case TextureFormat::RGB: swizzle = &RGB; break; case TextureFormat::RGBA: swizzle = &RGBA; break; case TextureFormat::ARGB: swizzle = &RGBA; break; case TextureFormat::ABGR: swizzle = &RGBA; break; case TextureFormat::BGR: swizzle = &RGB; break; case TextureFormat::BGRA: swizzle = &RGBA; break; case TextureFormat::sR: swizzle = &R; break; case TextureFormat::sRG: swizzle = &RG; break; case TextureFormat::sRGB: swizzle = &RGB; break; case TextureFormat::sRGBA: swizzle = &RGBA; break; case TextureFormat::sBGR: swizzle = &RGB; break; case TextureFormat::sBGRA: swizzle = &RGBA; break; case TextureFormat::D: swizzle = &D; break; case TextureFormat::S: swizzle = &S; break; case TextureFormat::DS: DE_ASSERT(false); // combined depth-stencil border color? swizzle = &INV; break; default: DE_ASSERT(false); swizzle = &INV; break; } #ifdef DE_DEBUG { // check that BorderSwizzle(c) == readSwizzle(writeSwizzle(C)) const TextureSwizzle& readSwizzle = getChannelReadSwizzle(order); const TextureSwizzle& writeSwizzle = getChannelWriteSwizzle(order); for (int ndx = 0; ndx < 4; ++ndx) { TextureSwizzle::Channel writeRead = readSwizzle.components[ndx]; if (deInRange32(writeRead, TextureSwizzle::CHANNEL_0, TextureSwizzle::CHANNEL_3) == DE_TRUE) writeRead = writeSwizzle.components[(int)writeRead]; DE_ASSERT(writeRead == swizzle->components[ndx]); } } #endif return *swizzle; } static tcu::UVec4 getNBitUnsignedIntegerVec4MaxValue (const tcu::IVec4& numBits) { return tcu::UVec4((numBits[0] > 0) ? (deUintMaxValue32(numBits[0])) : (0), (numBits[1] > 0) ? (deUintMaxValue32(numBits[1])) : (0), (numBits[2] > 0) ? (deUintMaxValue32(numBits[2])) : (0), (numBits[3] > 0) ? (deUintMaxValue32(numBits[3])) : (0)); } static tcu::IVec4 getNBitSignedIntegerVec4MaxValue (const tcu::IVec4& numBits) { return tcu::IVec4((numBits[0] > 0) ? (deIntMaxValue32(numBits[0])) : (0), (numBits[1] > 0) ? (deIntMaxValue32(numBits[1])) : (0), (numBits[2] > 0) ? (deIntMaxValue32(numBits[2])) : (0), (numBits[3] > 0) ? (deIntMaxValue32(numBits[3])) : (0)); } static tcu::IVec4 getNBitSignedIntegerVec4MinValue (const tcu::IVec4& numBits) { return tcu::IVec4((numBits[0] > 0) ? (deIntMinValue32(numBits[0])) : (0), (numBits[1] > 0) ? (deIntMinValue32(numBits[1])) : (0), (numBits[2] > 0) ? (deIntMinValue32(numBits[2])) : (0), (numBits[3] > 0) ? (deIntMinValue32(numBits[3])) : (0)); } static tcu::Vec4 getTextureBorderColorFloat (const TextureFormat& format, const Sampler& sampler) { const tcu::TextureChannelClass channelClass = getTextureChannelClass(format.type); const TextureSwizzle::Channel* channelMap = getBorderColorReadSwizzle(format.order).components; const bool isFloat = channelClass == tcu::TEXTURECHANNELCLASS_FLOATING_POINT; const bool isSigned = channelClass != tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; const float valueMin = (isSigned) ? (-1.0f) : (0.0f); const float valueMax = 1.0f; Vec4 result; DE_ASSERT(channelClass == tcu::TEXTURECHANNELCLASS_FLOATING_POINT || channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT || channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT); for (int c = 0; c < 4; c++) { const TextureSwizzle::Channel map = channelMap[c]; if (map == TextureSwizzle::CHANNEL_ZERO) result[c] = 0.0f; else if (map == TextureSwizzle::CHANNEL_ONE) result[c] = 1.0f; else if (isFloat) { // floating point values are not clamped result[c] = sampler.borderColor.getAccess<float>()[(int)map]; } else { // fixed point values are clamped to a representable range result[c] = de::clamp(sampler.borderColor.getAccess<float>()[(int)map], valueMin, valueMax); } } return result; } static tcu::IVec4 getTextureBorderColorInt (const TextureFormat& format, const Sampler& sampler) { const tcu::TextureChannelClass channelClass = getTextureChannelClass(format.type); const TextureSwizzle::Channel* channelMap = getBorderColorReadSwizzle(format.order).components; const IVec4 channelBits = getChannelBitDepth(format.type); const IVec4 valueMin = getNBitSignedIntegerVec4MinValue(channelBits); const IVec4 valueMax = getNBitSignedIntegerVec4MaxValue(channelBits); IVec4 result; DE_ASSERT(channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER); DE_UNREF(channelClass); for (int c = 0; c < 4; c++) { const TextureSwizzle::Channel map = channelMap[c]; if (map == TextureSwizzle::CHANNEL_ZERO) result[c] = 0; else if (map == TextureSwizzle::CHANNEL_ONE) result[c] = 1; else { // integer values are clamped to a representable range result[c] = de::clamp(sampler.borderColor.getAccess<deInt32>()[(int)map], valueMin[(int)map], valueMax[(int)map]); } } return result; } static tcu::UVec4 getTextureBorderColorUint (const TextureFormat& format, const Sampler& sampler) { const tcu::TextureChannelClass channelClass = getTextureChannelClass(format.type); const TextureSwizzle::Channel* channelMap = getBorderColorReadSwizzle(format.order).components; const IVec4 channelBits = getChannelBitDepth(format.type); const UVec4 valueMax = getNBitUnsignedIntegerVec4MaxValue(channelBits); UVec4 result; DE_ASSERT(channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER); DE_UNREF(channelClass); for (int c = 0; c < 4; c++) { const TextureSwizzle::Channel map = channelMap[c]; if (map == TextureSwizzle::CHANNEL_ZERO) result[c] = 0; else if (map == TextureSwizzle::CHANNEL_ONE) result[c] = 1; else { // integer values are clamped to a representable range result[c] = de::min(sampler.borderColor.getAccess<deUint32>()[(int)map], valueMax[(int)map]); } } return result; } template <typename ScalarType> tcu::Vector<ScalarType, 4> sampleTextureBorder (const TextureFormat& format, const Sampler& sampler) { const tcu::TextureChannelClass channelClass = getTextureChannelClass(format.type); switch (channelClass) { case tcu::TEXTURECHANNELCLASS_FLOATING_POINT: case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: return getTextureBorderColorFloat(format, sampler).cast<ScalarType>(); case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER: return getTextureBorderColorInt(format, sampler).cast<ScalarType>(); case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER: return getTextureBorderColorUint(format, sampler).cast<ScalarType>(); default: DE_ASSERT(false); return tcu::Vector<ScalarType, 4>(); } } // instantiation template tcu::Vector<float, 4> sampleTextureBorder (const TextureFormat& format, const Sampler& sampler); template tcu::Vector<deInt32, 4> sampleTextureBorder (const TextureFormat& format, const Sampler& sampler); template tcu::Vector<deUint32, 4> sampleTextureBorder (const TextureFormat& format, const Sampler& sampler); } // tcu
38.637106
168
0.689756
asimiklit
f569963a97c8bf5e0a151422d09ad513ccce9f0f
39,535
cpp
C++
tests/test_estimator_pwm.cpp
AlterB/chronovise
5c5fac329b143f3e62ebbc8523d7e205835dd4cb
[ "Apache-2.0" ]
2
2021-02-04T18:22:41.000Z
2021-12-08T10:57:00.000Z
tests/test_estimator_pwm.cpp
AlterB/chronovise
5c5fac329b143f3e62ebbc8523d7e205835dd4cb
[ "Apache-2.0" ]
9
2018-03-20T10:24:22.000Z
2018-08-27T21:53:56.000Z
tests/test_estimator_pwm.cpp
AlterB/chronovise
5c5fac329b143f3e62ebbc8523d7e205835dd4cb
[ "Apache-2.0" ]
4
2018-05-16T14:27:55.000Z
2022-01-28T17:18:24.000Z
#include "gtest/gtest.h" #include "evt/gev_distribution.hpp" #include "evt/gpd_distribution.hpp" #include "evt/evtapproach_bm.hpp" #include "evt/evtapproach_pot.hpp" #include "statistical/estimator_pwm.hpp" #include "utility/oop.hpp" using namespace chronovise; class EstimatorPWM_Test : public ::testing::Test { protected: // You can remove any or all of the following functions if its body // is empty. EstimatorPWM_Test() { // You can do set-up work for each test here. } virtual ~EstimatorPWM_Test() { // You can do clean-up work that doesn't throw exceptions here. } // If the constructor and destructor are not enough for setting up // and cleaning up each test, you can define the following methods: virtual void SetUp() { // Code here will be called immediately after the constructor (right // before each test). } virtual void TearDown() { // Code here will be called immediately after each test (right // before the destructor). } }; TEST_F(EstimatorPWM_Test, GPD_0_1_0) { constexpr int n_elem = 200; double xs[n_elem] = { 1.819034,0.230314,1.167271,0.637650,1.797886,0.507528,1.335710,0.424527,0.372203,0.290150,0.797305,2.479067,1.474134,0.090650,1.881391,0.191382,0.619260,0.003873,2.548799,0.814912,2.238177,0.038847,5.374286,0.255008,0.201745,0.140764,2.471763,0.916834,1.347572,0.223058,0.840687,0.093599,1.704589,1.332553,1.927311,1.994596,0.140076,0.545237,0.598091,1.931333,0.158959,0.474727,1.047105,0.666993,0.911781,2.577460,1.427466,2.092981,1.693321,1.427314,0.874029,3.002668,0.102347,0.056796,0.711588,0.714876,1.085540,0.105301,0.996290,2.196400,0.248138,0.942278,1.420094,0.906558,2.338684,2.025156,0.059696,0.044857,0.553023,2.817092,1.449107,1.040838,0.196996,4.173165,3.146002,1.777916,0.432145,0.312354,0.434257,0.796457,0.603290,1.216313,0.294783,1.666246,0.375748,1.695480,0.998356,0.469014,0.248170,2.511755,0.073231,0.253973,0.719919,0.830437,0.805681,1.183029,0.676273,0.671833,0.201348,0.229625,0.439563,0.971250,0.208772,0.629561,1.047747,0.062938,0.132454,0.597553,0.474052,0.532654,1.571457,1.199827,0.753060,1.467556,0.169237,1.635965,1.487566,1.767801,1.479883,0.830804,1.167634,0.079715,0.843488,1.688393,0.099952,0.020459,0.823552,2.197152,1.354545,0.894725,0.519369,1.338603,0.506098,0.340779,1.506219,2.142018,1.215115,1.143259,0.857629,0.677553,2.459054,1.337572,0.221876,3.532892,0.073804,0.314258,0.716193,0.547273,1.438499,0.779034,0.037610,0.603662,0.651745,1.462768,0.715602,0.471509,0.386935,0.927566,1.001204,0.012091,3.277065,0.121978,0.090705,0.227925,2.315546,1.339903,1.092560,0.386063,1.991041,0.326801,2.237155,0.425019,0.704868,0.249678,0.335421,0.101235,0.115498,1.096126,0.358468,1.620449,3.488687,0.295614,0.693102,0.734131,0.100127,0.494515,0.481807,0.151472,0.216305,0.550396,1.698693,1.427400,0.120461,3.551759,0.713551,1.784225,0.021550,0.338702,0.692204, 0.693211}; MeasuresPool<int, double> mp; for (int i=0; i<n_elem; i++) { mp.push(0, xs[i]); } Estimator_PWM<int, double> mle; mle.set_source_evt_approach(&typeid(EVTApproach_PoT<int, double>)); mle.run(mp); auto res = mle.get_result(); EXPECT_NEAR(std::dynamic_pointer_cast<GPD_Distribution>(res)->get_location(), 0., 5e-1); EXPECT_NEAR(std::dynamic_pointer_cast<GPD_Distribution>(res)->get_scale(), 1, 5e-1); EXPECT_NEAR(std::dynamic_pointer_cast<GPD_Distribution>(res)->get_shape(), 0., 5e-1); } TEST_F(EstimatorPWM_Test, GPD_2_20_1) { constexpr int n_elem = 200; double xs[n_elem] = { 2.972253,12.615112,7.854437,12.186839,14.686876,9.724292,8.931033,17.720373,10.825809,2.873886,4.324948,2.573393,9.363876,13.881676,13.124022,21.863925,15.303356,6.609077,9.077864,13.039553,3.194545,2.428168,12.156383,13.166223,6.046873,19.590124,5.452777,7.074252,10.263555,15.940262,10.298249,10.502486,17.870576,20.857918,17.409326,2.219657,5.872224,21.140228,11.152038,16.706098,11.817679,10.357776,21.088323,4.483723,12.320992,18.115788,2.373304,3.947349,9.443776,14.620806,3.432844,4.029801,20.958898,20.237815,17.227604,15.312286,4.914226,21.698486,16.830726,7.574872,20.229929,4.759897,18.666830,12.968636,16.324473,11.045289,2.571211,19.024144,4.633637,12.231589,10.181876,21.932225,12.288877,7.371050,11.260571,2.269745,11.968961,21.005518,19.790748,12.570655,18.697562,12.889600,9.662577,19.700337,20.348584,21.619802,20.255484,13.717492,13.159500,4.875694,17.189338,5.132981,14.503189,21.619719,7.077687,18.711226,21.600973,10.293159,6.018056,8.367920,16.037691,11.298308,18.505867,11.354837,17.756975,8.312181,14.236784,17.408095,10.497336,19.384572,16.302854,20.472004,14.213144,4.590434,9.765381,14.664925,9.097005,9.658657,15.246266,18.689049,3.100474,11.800784,2.925731,12.601912,3.341977,6.165653,12.114481,21.726561,17.195699,13.242380,4.240435,3.735613,9.526876,12.615748,5.516989,14.747101,8.664883,15.034160,19.524621,12.671436,21.198630,11.065567,2.743819,18.308146,21.159540,13.087160,14.085170,2.596475,8.612978,7.396533,19.806913,12.100668,3.491440,8.557256,13.532752,15.623421,2.164351,6.911866,15.488838,14.436164,10.631625,7.352881,13.800982,9.726953,2.559820,4.876822,14.302165,16.537489,5.310755,12.155094,12.585103,19.095248,19.994198,15.940793,2.330914,20.446230,16.749579,14.743267,9.133148,20.073035,21.506312,15.766427,2.915881,3.894031,7.432066,8.885687,9.675695,17.727717,7.845240,18.250215,4.123982,20.837789,15.539371,4.930078,19.568696,6.999093,12.546647,15.949105,9.953557,17.752163 }; MeasuresPool<int, double> mp; for (int i=0; i<n_elem; i++) { mp.push(0, xs[i]); } Estimator_PWM<int, double> mle; mle.set_source_evt_approach(&typeid(EVTApproach_PoT<int, double>)); mle.run(mp); auto res = mle.get_result(); EXPECT_NEAR(std::dynamic_pointer_cast<GPD_Distribution>(res)->get_location(), 2., 5e-1); EXPECT_NEAR(std::dynamic_pointer_cast<GPD_Distribution>(res)->get_scale(), 20., 5e-1); EXPECT_NEAR(std::dynamic_pointer_cast<GPD_Distribution>(res)->get_shape(), -1., 5e-1); } TEST_F(EstimatorPWM_Test, GEV_M05_1_2) { constexpr int n_elem = 1000; double xs[n_elem] = { 1.583457,2.902126,3.313949,3.222706,2.563704,2.698465,3.403960,2.170689,1.774062,2.644932,1.791515,2.621930,0.509266,3.852967,1.489083,2.587729,1.944164,2.848215,0.218048,0.710363,3.449609,0.880375,1.901028,2.397364,1.633723,2.436886,3.005315,2.387160,3.469053,1.231202,2.128924,1.744411,2.566129,0.360697,0.681095,1.873532,0.954392,1.337900,2.008908,0.408425,2.827720,2.667043,1.355496,0.666429,2.102866,2.245130,1.473219,3.252258,2.565756,0.115841,3.348853,2.220132,0.625471,1.005486,3.920604,3.242392,2.606015,0.197908,1.872483,2.246885,0.958644,2.502820,1.882227,2.214039,2.518850,0.779848,0.618456,1.808389,2.386777,2.481492,1.616172,3.395596,3.124826,2.199220,3.730926,2.519840,1.591161,3.083502,2.215982,1.645075,3.572983,1.209044,2.364970,3.662500,2.683383,2.604768,2.261303,2.518702,3.390513,2.022547,1.570958,2.146201,1.723071,2.199270,2.634734,2.417395,2.047193,3.264325,1.806545,2.085616,2.377269,0.663264,1.580290,1.079068,0.957067,3.318166,0.312439,3.162139,2.352313,1.051070,2.311876,2.569257,0.898035,3.703240,2.694398,2.240374,3.234592,1.688073,3.119932,1.891187,3.508094,1.625010,3.581255,2.360819,2.487818,3.841208,2.980024,1.846869,0.623901,0.466226,3.089850,2.116860,2.043792,2.390116,3.324361,2.100950,2.580793,0.930180,1.911268,1.219991,1.627672,2.029930,1.712512,1.522636,2.649251,3.054486,1.495804,3.338097,2.916636,2.421518,3.650743,2.488529,1.530438,3.216605,3.229284,1.845389,1.885438,3.164925,2.316914,0.560007,2.997992,2.154206,1.743364,1.904206,1.997445,3.041513,0.393254,2.869896,3.261945,1.761776,2.703388,1.582144,2.621756,0.782163,3.632254,2.593806,2.042599,0.264900,3.216016,2.578821,3.187441,2.345966,-0.399783,3.419002,2.113330,2.883801,1.250616,3.096051,3.384378,2.997797,2.945051,2.099073,2.810105,2.489882,2.534948,1.936548,2.815693,1.296522,-1.096290,2.481775,2.445330,2.455548,2.792506,3.451297,3.520808,3.362062,2.580134,3.446269,1.070126,1.924953,0.364536,2.426203,2.895723,1.386168,2.153125,0.952985,1.815242,3.003397,2.422875,2.975166,2.661435,3.327683,0.652183,1.362903,2.127811,2.902027,3.327038,0.176223,1.183141,2.147633,2.963765,2.393227,2.938445,1.336812,2.740769,2.614055,-0.465010,2.903095,3.817804,1.133428,1.980066,1.426987,2.840146,1.371906,3.769883,-0.037124,0.408913,3.066737,3.222660,2.491736,2.937525,2.381532,2.537675,1.425603,2.343150,0.548852,0.605478,1.909033,2.642649,3.323793,2.742350,2.770453,2.795388,3.054793,2.712213,2.382535,1.899129,3.478104,1.633157,2.361730,2.903322,1.659267,3.180911,2.425694,3.386286,1.952752,3.482849,3.452183,2.541867,0.976679,1.997270,1.730274,1.698789,1.562920,-1.149576,3.327213,2.221500,2.520198,1.852199,3.845067,3.745141,3.620022,2.725532,2.868651,1.905735,2.389275,1.722294,2.849769,2.997990,0.829818,1.544825,1.478228,2.626762,2.866332,3.148918,0.015612,1.471043,2.259938,2.028385,1.923799,0.682652,2.955623,2.092481,2.744460,2.456131,0.555000,1.828094,3.624946,3.467137,2.027397,2.611763,2.483023,3.138248,3.584202,0.785316,3.310780,2.482821,1.440259,1.544357,2.819363,2.563006,2.538589,3.642157,2.527960,0.963829,1.322581,0.978832,1.226946,2.738026,2.663562,2.012347,1.305721,2.057998,3.055177,2.085000,2.940038,1.790867,2.663919,3.301329,1.500122,2.287427,1.046712,1.155949,0.684077,0.815946,2.633425,2.114954,2.660607,3.213020,2.961263,3.689333,3.007040,3.483918,2.900452,1.657421,2.851878,2.790065,2.985971,2.920371,1.860376,2.359878,2.985327,2.507095,3.565266,1.344628,3.375969,2.932803,1.762903,2.634490,2.244551,1.140249,2.452155,3.648061,2.193204,2.549482,1.034537,1.462145,1.306136,0.366734,1.720270,1.575875,1.974461,1.166372,3.924996,2.367254,2.053571,1.644680,1.991482,2.083076,3.446624,2.324002,2.591980,-0.620553,2.541933,2.996566,2.704172,2.402423,3.124934,3.608643,1.846675,3.047542,1.759777,-0.102067,0.925675,1.890460,1.822305,-0.008069,1.302683,2.197830,2.969334,2.760940,2.840481,2.237042,3.419734,3.789115,3.471691,2.241338,3.367841,2.049873,2.577593,2.477832,3.181647,1.758616,2.718594,2.575824,2.702481,1.835379,1.898863,1.415226,0.969637,1.764117,1.964193,2.420043,3.808070,0.221529,2.828420,3.368662,3.240876,1.083008,3.572188,2.190099,3.271541,3.238208,1.965091,2.643214,3.236988,0.068778,0.796073,2.023875,1.241370,0.323834,3.008877,1.886192,3.102151,1.353575,2.748780,3.271041,2.945132,1.574053,1.975559,1.987141,1.703177,1.915031,0.874428,2.216691,2.224391,0.237429,2.657129,0.639957,1.334144,2.769059,2.464335,-0.521080,1.768858,2.023598,1.228158,0.777265,2.239415,2.006825,3.121573,2.424233,3.102259,2.238522,-0.130998,-0.605076,1.320894,1.994718,2.849361,1.289878,1.739590,2.675462,1.766114,1.870758,1.271158,2.053086,3.336335,3.309939,2.068797,2.747220,1.652681,3.546982,2.628122,1.489790,1.026507,2.490792,1.725435,0.748692,1.285358,0.532798,2.760059,3.007603,3.074842,1.695376,3.336895,2.589180,-0.118480,1.934057,2.415087,2.635312,2.204690,3.084889,1.219922,3.680671,3.147217,1.922971,2.608425,1.816856,0.890875,2.386313,3.123602,2.962149,3.536184,1.904318,2.058578,1.247277,1.904768,2.462248,2.454293,1.294485,1.070961,2.081750,3.140547,1.402006,2.336778,1.123210,3.237228,2.969019,2.487288,2.058131,2.311132,3.307126,3.368282,2.331019,2.404584,3.384729,2.520613,2.992270,2.714069,2.261320,1.538143,2.576597,1.398913,1.452870,3.229262,1.119541,2.676964,2.181106,2.599950,2.896346,1.815417,0.451870,3.152142,2.003880,2.713939,3.336291,1.724684,3.908267,3.148887,3.032482,2.702832,2.438709,2.050483,3.115167,2.559678,3.007308,3.777271,3.024428,3.202282,2.300184,3.265278,1.905176,1.483494,2.321313,0.275997,3.129928,1.692767,2.752047,3.039078,2.762334,2.689099,1.601455,2.280240,3.487391,1.614604,1.498100,1.719457,2.992353,1.898196,2.577728,1.397894,0.878086,1.832340,1.578543,3.382896,3.489332,0.287420,2.555742,0.462927,2.149708,2.386445,3.165855,2.628933,1.662746,3.367034,2.970677,2.483333,3.341127,2.000543,1.916248,2.614527,0.873948,2.020603,1.411865,3.083330,2.861575,2.745368,3.400183,3.111676,2.450602,-0.081292,0.929374,2.370205,3.558714,3.173645,3.481558,3.671691,2.012592,1.867749,3.011454,1.509921,3.591561,3.462151,1.994147,1.936542,2.788084,2.845475,3.056148,2.555797,0.946319,2.475933,0.453472,2.946325,2.709962,2.569298,1.564571,2.838497,2.864623,1.934589,0.301986,3.175238,2.978286,2.358004,2.822245,3.032038,1.896063,3.399067,2.516188,1.768310,1.701294,3.317846,1.995160,1.245355,3.530249,2.689277,3.732078,1.438161,3.133177,2.319976,2.549050,0.476634,2.487533,2.648815,2.330324,0.641606,2.371170,0.574337,3.175284,2.558135,2.784125,2.680821,2.625223,3.565304,1.367950,2.274149,3.171758,2.327590,2.958313,1.380473,2.785561,3.401803,1.304738,2.157819,0.437069,1.560046,2.725261,3.257794,1.936025,0.203873,3.369102,2.264759,3.387461,1.888315,2.784326,-0.024193,2.364453,1.899351,1.911642,3.562837,2.928537,1.905396,2.647152,2.125793,2.515709,3.593343,2.607513,1.248074,3.159966,2.868669,1.021531,1.298763,1.796377,2.146347,2.402659,1.727882,3.130989,3.036250,1.723558,2.607155,0.975304,2.734247,1.943510,2.733145,1.791149,2.758979,2.069217,2.064069,1.489850,2.864667,3.107143,3.447291,2.368683,1.435377,2.577323,1.455533,2.112524,3.202735,2.160318,3.444123,2.014081,2.801362,2.544026,0.970834,2.117689,3.440439,0.599728,2.043484,1.612991,1.567512,1.970535,3.438102,2.340888,3.063828,1.951542,2.234331,3.552163,1.159204,0.741239,2.820128,3.468055,1.021868,2.691297,1.226033,2.791138,2.630296,0.461711,3.049753,3.764329,2.179664,1.936082,0.524428,1.558072,2.526253,2.573766,1.653708,2.697501,0.646304,3.504673,0.914410,1.905550,2.689780,2.344275,2.408605,2.030337,2.974749,1.751412,2.685614,3.430752,1.896072,3.091189,3.022821,1.112180,1.280409,2.124387,2.775359,2.705395,2.757912,-0.321326,1.135756,2.962098,3.170360,2.919706,3.522194,3.421408,1.550306,2.358292,3.023093,2.388513,2.611114,2.472957,2.880442,0.678399,2.317527,1.575124,1.915282,2.457453,2.911631,2.117459,2.353154,1.137723,1.519773,1.783549,2.212730,1.611744,1.689502,3.322483,2.538225,3.496864,2.612718,1.647620,0.981704,2.445047,2.194469,2.785285,2.950858,2.084026,2.494454,1.484527,3.517803,2.365550,1.731554,1.572306,3.560839,2.780322,2.824430,2.703559,3.000428,2.524984,2.342643,3.280900,2.067049,1.619920,1.748624,3.367312,2.811959,3.202678,2.029159,2.647594,0.281955,3.422609,2.261539,2.382455,2.968175,1.911939,2.631163,1.885200,1.838872,2.678131,2.171972,0.983957,1.597265,3.661634,2.802918,2.709498,1.882870,0.039714,2.501614,0.358585,1.694358,1.425299,2.211073,2.974110,2.635717,1.849526,1.781123,0.807509,1.346257,2.856799,0.892531,3.414295,2.161825,0.819309,2.505524,3.141638,1.943429,3.002797,2.825552,2.549432,2.024625,2.069354,2.158359,2.144929,1.535022,2.327112,0.409937,2.488373,0.528388,3.260694,3.223356,1.917745,3.675576,3.569746,3.786045,1.281950,-0.831868,1.638982,1.940409,1.587313,2.941968,1.560705,2.208941,1.676888,1.939019,3.360993,-0.179036,1.155168,2.054144,3.166659,1.513868,3.482475,3.649771,2.019960,3.752995,1.099633,2.954672,2.522396,2.619895,2.310568,1.540665,1.216470,2.652627,3.061643,2.733493,2.266082,3.521993,2.550689,1.563677,2.767075,1.866995,2.924593,3.913779,1.710615,3.468729,2.796921,0.933306,1.631082,3.480096,2.286035,3.292992,3.001276,-0.000868 }; MeasuresPool<int, double> mp; for (int i=0; i<n_elem; i++) { mp.push(0, xs[i]); } Estimator_PWM<int, double> mle; mle.set_source_evt_approach(&typeid(EVTApproach_BM<int, double>)); mle.run(mp); auto res = mle.get_result(); ASSERT_TRUE(instanceof_ptr<GEV_Distribution>(res)); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_location(), 2, 5e-1); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_scale(), 1., 5e-1); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_shape(), -0.5, 5e-1); EXPECT_LT(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_shape(), 0); } TEST_F(EstimatorPWM_Test, GEV_02_05_1) { constexpr int n_elem = 1000; double xs[n_elem] = { 1.419847,0.982652,6.488776,0.806704,1.463811,1.368834,1.026472,0.687288,0.426141,1.073661,0.750328,1.638849,1.003377,2.052902,1.662038,1.307066,0.739799,3.178870,0.862535,2.659685,0.806151,1.007738,0.592187,1.438005,0.745282,0.493742,1.631862,0.972356,1.481385,1.021833,1.412159,0.410899,2.514269,1.876722,1.695193,1.926053,1.021062,1.392361,1.314943,1.237885,0.875598,0.840049,1.117463,0.811570,1.891638,4.371601,0.445168,1.247063,0.591356,1.882559,4.670775,0.549005,2.852535,0.393930,1.533721,1.815699,1.244558,2.309237,2.412886,1.409359,0.680436,0.797911,0.747493,0.484304,0.628463,1.390739,2.856438,0.981818,1.058914,4.232575,2.950083,1.517113,4.578678,1.759349,0.957928,1.485238,0.834005,0.902895,1.525225,1.234304,1.060265,1.364407,1.708980,1.329294,1.273943,1.329361,1.208652,0.582411,1.622296,6.100088,0.981924,3.569623,0.971025,2.317657,1.121927,1.062837,0.797815,0.660574,0.920780,1.639738,1.812705,1.557323,0.340412,2.061043,2.634319,1.772677,0.486799,1.014049,1.583214,1.649008,0.806849,0.867542,1.508908,1.155747,1.404963,0.823510,0.740192,1.996903,1.759639,2.782886,0.630147,0.747619,0.614242,1.174366,0.763448,2.387873,0.614232,0.491198,1.283295,1.777724,0.924817,0.742904,0.960955,0.787271,1.206021,2.475731,1.415306,0.618717,1.031443,0.519475,1.192134,1.088730,6.824697,1.919928,1.168092,2.376565,0.679921,1.030271,2.692235,2.582535,1.606656,1.394419,0.966774,2.804134,0.659112,1.651949,1.451206,2.012924,1.041712,1.706904,2.022547,0.938866,1.274736,3.909007,1.269752,0.949518,1.396631,0.990175,1.727057,1.063502,1.178322,1.559630,3.624099,0.945946,2.034753,1.675669,3.109876,0.452164,0.985078,1.485833,0.884198,0.815230,1.600374,1.406655,1.342128,1.480996,0.500772,0.974170,1.117028,0.829579,1.610462,2.128452,0.884207,1.653230,0.680267,2.029621,0.681604,1.337754,0.997660,1.900648,1.196026,1.174107,2.252823,0.980044,1.114266,3.329977,0.485727,3.632695,0.757676,1.495678,1.334542,1.513623,0.990697,1.398208,1.918107,0.399432,0.584991,3.706665,1.461471,0.816400,1.048948,0.654511,0.866716,0.852486,0.951181,0.702929,0.973124,0.653903,2.300762,0.605243,2.725130,1.042735,0.500348,0.965545,1.666896,1.854788,1.262371,1.539310,2.370259,0.519920,0.913772,0.496973,0.766623,1.623869,1.628076,2.257734,1.327315,0.557341,2.638908,1.876015,0.890136,1.260298,4.264614,1.612106,2.040337,1.090929,1.145459,1.289154,0.867591,1.704520,1.196193,1.451901,0.919220,0.681800,1.152863,0.992644,1.831066,1.803854,1.498773,0.673423,0.410466,1.287655,0.909981,2.852703,4.006984,0.891036,1.877715,2.389611,1.354867,2.299811,2.919610,1.269499,1.645931,1.317183,0.429118,1.110036,1.450839,1.223590,1.006033,2.819696,1.996404,2.090755,1.006335,1.346849,2.224090,2.769789,1.498666,0.782561,1.466795,0.560329,1.053459,1.495259,2.772774,1.917299,1.166415,1.727790,1.067926,3.588703,4.544995,2.173351,1.028727,1.121996,0.837422,1.818088,2.291636,2.544455,1.284988,1.357360,0.697746,2.418703,1.115648,0.781013,2.418188,1.745885,2.289219,0.888805,1.509348,1.489402,0.655843,1.054284,0.875888,1.614688,0.886714,2.390303,1.983207,1.030301,1.186890,1.559780,2.018570,1.377636,1.313603,0.943655,1.124461,1.607228,2.302524,1.625694,0.396174,1.512860,1.098454,1.097464,0.646069,1.932473,0.942068,0.836800,0.966002,1.010642,1.265126,1.291232,1.038305,1.041502,1.214273,1.474695,3.045419,1.629660,1.044206,2.007033,0.674771,0.533916,0.585739,0.720628,0.941218,0.911192,0.354693,1.254057,0.607307,0.694074,1.419751,2.145797,3.682713,1.306737,6.409460,1.276905,1.214418,0.949864,1.086277,1.177495,0.558115,2.326258,0.543718,1.095117,1.983431,1.036524,1.385004,1.948945,2.315452,2.738668,0.759935,0.853477,2.403631,1.347175,1.196119,1.383725,1.952244,1.240880,0.775957,1.120755,1.083300,3.400986,1.397771,1.561196,1.623865,0.971626,1.216856,1.282270,0.709448,1.291466,1.559775,1.081231,2.027483,1.654156,0.989355,1.121221,1.025296,1.787856,1.662153,1.086670,1.557238,2.943956,1.817424,1.586299,0.632702,1.030169,1.342669,1.128801,0.508335,0.812907,2.017732,0.380057,2.170813,0.573130,1.499955,1.190468,0.798177,1.308102,0.654794,1.504709,1.358697,0.522908,0.523826,0.703339,0.401236,1.093670,2.008639,1.392576,1.221869,2.171727,0.611654,2.490952,0.630373,1.216866,0.688814,1.286848,0.285190,1.758871,2.088813,2.575617,4.447995,1.198139,0.870713,0.617285,1.202396,1.333039,1.746833,0.583158,1.483520,1.216838,0.731265,2.840177,1.341898,1.101513,2.890838,1.471214,1.117910,2.043844,1.242080,1.277491,1.524964,0.999063,0.827385,1.321035,2.189487,1.053528,0.638446,1.106148,0.909134,1.046021,2.013902,1.049140,1.030507,0.989921,0.684232,0.855559,0.590839,1.085416,0.851727,0.905628,1.078964,0.649765,1.182509,1.588398,0.833202,1.820346,0.564726,1.035623,0.265969,0.801887,0.211755,0.757637,0.687756,0.866229,0.736924,0.681680,1.357393,2.429871,2.852259,0.802587,1.163568,1.011077,1.227732,0.861931,0.552181,1.095321,0.735399,0.430134,3.120322,1.087125,3.278408,1.745348,0.318304,1.524902,1.587250,1.448388,1.274818,0.798337,1.777301,0.812003,1.004061,2.349733,2.129515,1.047477,0.932933,1.375742,2.510750,2.500548,1.343931,0.952395,2.111634,1.104056,2.458025,0.456571,1.241758,1.614239,0.743369,0.957705,0.755532,0.938154,1.049457,1.268503,0.504018,1.275533,0.875252,0.830390,0.832621,0.705883,3.157439,2.799060,1.949255,1.645591,0.738273,0.989815,0.757078,0.207571,0.930797,1.571513,1.408006,1.259297,1.099214,0.892113,1.192719,1.742628,1.745328,1.315937,1.700517,1.449235,0.656520,1.196990,0.972119,0.601191,0.696152,0.770442,1.507192,1.088430,1.558810,0.851056,0.340057,1.241524,0.881379,2.961111,2.476436,1.033968,0.424972,1.505317,2.031743,3.578287,0.525295,1.115547,1.327382,1.540286,1.621934,1.458700,1.641930,1.008125,1.325788,0.644497,0.527080,3.942946,0.888636,1.350144,3.293826,0.752749,0.763155,0.964565,2.761806,1.031185,0.873117,0.702488,1.040086,1.009318,0.669546,1.093477,0.599975,1.387225,0.349570,1.310996,1.836829,0.822040,1.112196,1.304145,0.536147,1.184395,1.442543,0.802699,2.031202,3.563076,2.076871,1.199495,0.880688,1.697446,0.824172,3.178001,1.398172,1.359959,0.733561,0.597730,0.849005,2.141613,2.518962,1.571554,1.637250,0.814549,1.315933,1.916005,1.049439,4.593102,0.597057,0.936836,1.208003,0.534250,1.638613,1.282033,1.236760,1.998435,2.142662,1.834324,0.932684,1.118292,1.714087,0.633631,0.633421,0.868653,1.229114,3.620949,1.598535,0.924710,0.897492,2.097362,2.524480,1.436278,0.849151,0.594467,2.036913,1.331430,2.993836,0.535260,1.331291,0.889016,1.988329,0.760224,1.104247,1.034971,1.983185,1.517630,0.783718,0.933047,0.673920,1.505375,1.307005,0.729370,0.695851,1.153624,2.491410,1.274590,0.455739,0.517550,1.894020,1.117078,1.020156,1.836520,0.995122,1.241633,1.601726,2.217385,0.947197,1.458863,3.708109,0.568721,1.335593,1.063482,0.921076,0.860537,1.733991,5.773999,0.753891,1.806760,0.767079,5.121811,1.883210,1.078069,1.647233,1.187587,1.909461,0.984591,0.562909,1.342827,2.510681,0.764189,1.089653,1.704938,0.476265,2.962730,1.749310,1.285905,0.749956,1.186961,1.218219,5.508907,2.121226,3.300126,1.522374,1.048963,2.789690,1.158749,0.817157,1.038952,1.585060,1.285457,1.727428,5.857598,3.300841,1.246082,3.339199,0.643651,0.511274,0.914689,1.323299,1.239372,2.431130,1.255125,1.089100,1.258639,1.603671,0.385877,1.878097,0.687795,1.157226,0.851125,1.001648,1.483889,0.729136,0.880566,0.770516,0.766047,0.944722,2.274612,1.146171,1.049614,0.743267,3.489883,1.054476,2.067382,1.388574,1.011897,2.253691,1.819585,1.137030,1.929581,2.408316,1.085189,0.954750,1.353237,2.437725,1.577558,1.013050,1.664065,3.108401,1.258882,1.254389,0.923709,0.558547,0.747261,0.602796,1.134862,0.336528,2.557463,1.443426,0.216283,0.446617,0.784931,1.122324,0.663238,0.330597,1.642377,0.981360,1.804367,1.095794,1.095648,0.505306,0.506437,0.599182,1.348417,0.829823,2.051968,2.134100,3.332191,1.173045,0.801380,0.809505,1.248911,1.744392,0.972531,1.131529,1.436376,2.580906,0.717135,1.611995,1.318925,1.090984,2.301389,1.034475,0.742894,1.424171,1.405524,0.946196,1.885910,9.833387,4.011335,0.662860,0.817770,0.419758,1.373456,0.635294,1.054481,2.300230,1.267775,1.001528,0.784757,1.101958,3.152641,0.657866,1.145665,2.132361,0.488945,1.552128,3.901512,0.886558,0.673870,1.537093,2.503846,1.380004,2.420926,0.763716,1.720711,0.970772,1.070150,0.708267,1.950462,1.407349,1.674216,1.894211,0.549630,3.043051,1.186385,1.722900,1.685206,2.003644,0.709459,1.125758,1.393958,2.752465,2.021928,2.384188,1.327469,1.327879,2.121628,0.462317,2.309665,1.054860,0.467333,1.696071,0.706907,0.689996,1.370664,0.847952,0.941131,1.046583,1.052965,1.025023,1.377965,0.725098,0.756077,0.605906,0.939837,1.768261,0.820336,1.679354,1.554990,1.972229,1.989424,0.900041,0.921387,1.226524,0.942661,2.006901,1.914669,1.282788,0.859368,1.526120,0.819701,1.124462,1.022792,1.251901,5.013311,1.723127,3.981209,0.821243,1.235459,0.511242,1.728177,1.363172,2.133858,4.576055,2.718195,1.057354,0.150117,1.255669,0.783896,0.799962,0.943340,0.608390,1.700137,1.703013,1.259692,0.959850,2.009154,1.275262,3.182449,2.364129,0.984584,1.264872,0.971339,1.403163,1.861962,1.695273,0.660378,1.964933,0.426205,1.064243,1.654212,1.807545,0.999193 }; MeasuresPool<int, double> mp; for (int i=0; i<n_elem; i++) { mp.push(0, xs[i]); } Estimator_PWM<int, double> mle; mle.set_source_evt_approach(&typeid(EVTApproach_BM<int, double>)); mle.run(mp); auto res = mle.get_result(); ASSERT_TRUE(instanceof_ptr<GEV_Distribution>(res)); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_location(), 1, 5e-1); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_scale(), 0.5, 5e-1); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_shape(), 0.2, 5e-1); EXPECT_GT(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_shape(), 0); } TEST_F(EstimatorPWM_Test, GEV_13_04_M01) { constexpr int n_elem = 1584; double xs[n_elem] = { 14.3157,14.7115,13.5772,13.9443,13.6284,14.2641,13.3719,13.7431,13.6466,12.8505,14.5476,13.7494,14.0811,14.0409,13.3246,13.6003,12.9909,14.9142,13.7036,14.2337,13.6096,13.9346,13.3924,14.5887,14.0099,13.4948,14.5074,14.4202,13.2052,14.2542,13.3772,13.845,14.3238,13.2973,13.6576,13.685,14.1736,13.4478,13.3348,13.4758,13.6007,13.4686,13.4687,13.5404,14.3922,13.8336,13.2415,13.8006,14.1372,14.2832,14.4718,13.9267,15.3801,14.1272,13.3658,14.2372,13.3336,14.0685,14.2734,13.1437,15.3264,13.9656,13.3978,13.5487,13.8487,13.2115,13.1547,14.4971,15.0538,13.0458,13.6831,13.8851,14.0204,14.0465,13.3804,13.6529,14.6315,13.6448,13.6514,13.57,13.4159,14.034,14.5292,14.4334,14.1491,12.9367,14.2723,13.9732,13.9259,13.9903,13.8598,13.4623,13.1696,14.462,13.4225,13.5201,13.6283,14.7928,13.8623,13.8362,14.4486,14.5612,13.8671,13.6059,13.1533,13.8104,13.449,13.9009,13.6191,14.7104,13.5089,14.633,13.9567,12.9809,13.8841,13.9661,14.0404,13.8558,14.1653,14.0805,13.0177,13.9637,13.6223,14.5205,13.4408,13.6498,13.3914,14.1551,14.2212,14.7989,13.6555,13.6339,13.6061,13.7162,13.3709,14.2202,14.0378,14.0442,14.683,14.251,13.8734,14.0366,13.9251,13.8738,14.0178,14.2245,13.3549,14.2154,13.7562,14.2376,14.8534,14.3747,14.0288,13.5162,14.6437,13.745,13.5362,14.7588,13.9807,12.9128,13.8457,12.8447,14.7314,14.4861,14.195,13.1476,13.8094,13.4056,13.4343,14.4087,13.6083,13.6034,14.1282,13.8964,13.8289,13.6677,13.557,13.9601,13.5692,13.5889,13.8516,13.7039,14.8999,13.9257,13.6208,13.9406,13.1793,13.4961,14.5258,13.4843,13.1063,14.3722,14.5931,13.9899,13.8358,13.2483,13.1372,14.0754,13.8069,13.8454,13.7786,13.8941,13.9361,14.2936,13.6835,13.5384,14.2114,14.0617,13.9569,14.196,13.7357,13.4141,13.1462,13.2216,14.3627,13.6071,13.4017,13.9514,13.5451,13.8822,13.9964,14.1814,15.468,14.4441,14.6575,13.8242,14.2711,13.6158,13.5978,13.911,14.6271,13.0794,14.3617,13.3049,14.3512,14.3648,14.2883,13.1848,13.5788,13.3315,14.8267,14.3308,14.29,12.712,13.6657,13.4073,14.362,15.1401,14.5781,14.597,13.5889,13.8422,14.7665,14.0845,13.9551,14.5291,12.9625,13.3967,13.6192,12.9983,13.5836,13.929,14.3005,14.2213,13.0767,14.1888,14.2324,13.4999,13.7087,13.7994,14.5134,13.6571,13.7518,13.8095,13.3509,13.5609,13.958,14.1531,14.2035,13.4069,14.9998,14.1699,13.9222,13.8464,14.0422,13.958,13.9513,14.8436,13.1083,13.4887,13.1455,13.5161,14.9059,13.5896,13.7337,14.7652,14.3892,13.8185,13.2508,13.1592,13.7826,13.7323,13.8738,13.896,14.311,12.8206,13.3333,14.352,14.2931,13.6544,13.0349,14.5895,14.0918,13.1691,13.7828,13.4177,13.4183,13.8215,13.464,13.6953,14.3828,14.043,13.9905,13.5486,13.3233,13.4897,13.4636,13.6151,13.4309,14.0574,13.6877,12.7279,14.234,13.7388,15.3589,14.5107,14.0557,13.5049,15.0352,13.566,14.1583,13.2914,13.3363,13.5459,14.3133,13.6815,13.9855,13.7086,13.7109,13.9274,13.9666,14.396,13.4933,13.982,13.9416,13.5746,13.215,14.3238,14.0938,13.9826,14.7874,14.0576,13.5872,13.5668,13.3682,14.5607,13.4969,13.903,13.8211,13.6657,14.4449,14.3444,13.535,14.5077,13.555,14.194,13.3484,14.9524,12.7418,13.4166,13.906,14.1417,13.2818,13.8657,14.0675,13.1577,14.1686,13.2743,14.1852,14.5814,13.8821,13.532,13.3149,13.8357,14.7683,13.4943,13.37,14.0652,13.7302,13.2845,13.6243,13.5664,13.9211,14.5706,13.2129,15.3158,14.0659,13.3526,14.6379,13.295,13.946,13.6146,13.7857,13.3779,13.4603,13.7441,13.3784,13.6641,12.9784,13.3155,13.0423,13.6495,14.4948,14.0207,14.091,13.6839,14.223,13.6858,13.9402,13.12,13.3385,13.6938,14.1873,13.7522,13.0554,14.3369,13.3941,13.1397,13.9163,13.3249,14.3159,13.4074,14.2647,13.2016,13.4066,13.3865,13.8057,13.4267,13.4663,13.5717,14.0436,13.9637,14.4359,13.749,13.8335,13.3003,13.8557,13.7599,13.3154,13.5563,14.4646,13.8976,14.4705,13.7521,14.7622,13.6014,13.6171,13.2785,13.4428,14.9338,13.1938,13.1624,13.1393,14.3831,12.8322,13.7191,14.1492,13.4058,14.1837,13.2767,14.7346,14.3222,13.6575,13.0345,13.3409,14.1644,14.0205,13.1148,13.5524,14.077,14.5926,13.6738,13.4091,13.9836,14.5245,12.6849,13.8624,14.1938,14.5273,13.2168,13.9984,13.6752,13.6448,13.8659,13.5833,13.6273,14.451,13.5963,13.7923,15.1697,14.1723,14.7294,13.5244,12.7883,13.2425,13.6289,12.872,12.8292,13.9577,14.0179,14.832,13.592,15.4553,14.1054,13.1833,15.3723,13.5469,14.4827,13.8321,13.6637,13.6038,13.5852,14.2048,14.3229,14.9544,13.7483,14.4841,13.1977,13.6217,13.5555,14.0315,13.5009,15.3172,13.2379,14.2366,13.8364,13.6712,13.4931,13.5772,13.034,13.8971,14.405,13.522,14.1126,13.6467,15.1063,13.7825,13.3227,13.695,13.5926,13.3697,13.6599,14.6818,14.9437,14.6489,13.0049,14.0659,13.6604,12.6439,14.4121,13.111,13.7263,14.8189,14.4434,14.1947,14.9262,13.3053,14.3312,15.9225,13.4133,13.324,13.2588,13.887,13.9854,13.5959,13.5929,13.8943,15.1067,13.625,13.7027,13.4583,13.9219,14.2056,13.6884,13.7543,13.5307,14.808,14.5044,14.7326,13.8897,14.1087,14.2403,14.5209,13.9689,14.2035,13.8159,13.5974,14.5029,14.2842,13.257,12.9249,13.5402,13.7383,13.8447,14.8293,14.1519,14.2872,14.582,14.0028,13.599,13.5322,13.8093,13.5829,13.3535,14.8258,13.689,14.023,14.4279,14.8201,14.9182,14.7112,13.5185,12.9703,14.9913,14.3111,14.2621,13.6203,14.2589,13.6575,13.2313,14.2814,13.571,13.5595,13.7228,14.2668,13.1416,14.2689,13.4492,13.4045,13.4919,13.5769,13.4099,13.5707,14.8467,14.1378,13.3216,13.516,14.0954,13.6085,13.8943,14.4021,13.3517,14.3212,13.9256,13.2203,14.1851,13.8628,13.0368,13.7841,13.4195,14.4538,13.8771,14.2648,14.5223,13.9191,14.3911,13.8173,13.8856,14.0242,14.1222,13.9657,13.5278,13.1699,13.6129,13.4555,13.629,13.622,12.9977,12.861,13.677,13.4687,13.8363,14.747,13.7859,13.8493,14.1548,14.2849,13.624,13.5565,13.5446,13.749,14.1305,13.8032,13.7445,14.0226,14.5662,14.0366,14.083,13.0092,12.9895,13.9243,13.0951,13.8235,13.9058,13.0924,14.3393,13.9166,14.6651,13.2707,13.8143,13.5575,14.6344,13.4785,14.0855,14.42,15.4899,13.7381,13.4352,14.3853,13.4613,13.9861,14.0732,14.6546,13.7028,14.3861,13.5205,13.5856,14.1253,14.1415,14.2616,14.3532,14.2202,13.505,13.6827,15.1964,13.5562,13.5056,14.4758,15.0087,13.8971,13.7415,14.1172,13.5673,14.2817,14.3967,14.078,14.2139,14.273,14.1458,13.4381,13.9456,13.5499,13.3854,14.0866,14.0152,13.7332,13.9308,12.9509,15.3324,14.1249,15.5466,14.3124,13.6625,13.96,14.4168,13.7494,13.6817,13.3817,13.9354,13.0138,13.0981,14.1731,14.6692,14.5938,13.9274,13.5414,13.4196,13.6815,14.2019,13.5943,13.9951,13.5885,13.4532,14.1346,13.722,13.6921,13.9862,13.1595,14.6468,13.9645,13.4833,12.9345,13.7729,14.329,13.7288,14.7008,13.9227,14.3935,12.879,15.1143,14.0362,13.407,14.16,13.7726,14.1422,14.0022,14.3164,13.4965,14.4482,14.0619,14.7359,13.7653,13.5587,14.0765,13.1459,13.8405,13.6049,13.8032,15.0225,13.6944,13.4133,14.1084,13.3598,14.5712,14.1552,13.6354,13.2599,13.3855,14.487,13.855,14.1285,13.5616,13.9174,14.0615,13.7046,13.457,13.8504,13.6037,14.5725,13.9408,13.4135,15.1734,12.9988,13.6818,14.0381,14.0851,13.7135,14.5943,13.7361,13.6087,13.3034,14.1593,13.8368,14.3474,13.4673,13.6696,13.1318,13.383,13.5798,13.6156,13.9819,13.4981,13.622,13.4567,13.3682,12.9793,14.4162,13.3658,14.9983,13.8777,13.9811,13.6084,13.7739,13.7535,14.1344,14.1037,13.6434,12.8421,13.5865,14.4827,14.2951,14.0998,14.3157,13.7436,13.5336,14.3319,15.3546,13.4774,13.0706,13.3363,14.3977,13.674,13.6037,14.1228,14.869,13.8437,14.2953,13.4939,14.2929,13.8745,14.0222,13.8611,13.9161,13.7559,13.9295,13.5119,14.557,13.6527,13.4009,14.9064,13.8118,14.1445,13.8114,13.5295,13.725,13.5704,14.3106,14.6912,13.6874,13.3605,13.7109,14.137,13.2399,13.5447,14.1592,13.965,14.0128,14.318,13.729,14.0858,13.5689,14.0576,13.982,13.4003,13.8275,13.4124,13.5964,14.1128,13.7996,14.2113,13.05,13.4978,14.4909,14.025,14.2486,13.4378,13.3642,13.9611,13.5237,13.6764,13.6782,14.6533,13.6354,14.3579,13.5378,13.8632,13.9851,12.9696,14.8896,13.9191,13.3947,14.0149,13.9174,13.3515,13.2867,13.7833,13.6954,13.9648,15.5562,14.5209,13.5066,13.3229,14.9054,14.7933,13.7562,14.0127,13.7221,13.228,13.198,13.0469,13.8318,13.5231,12.8638,13.8104,13.5523,13.7245,13.1692,15.1306,13.6307,15.3912,13.7494,14.2581,12.8219,14.5475,13.9367,13.7205,13.0612,13.0054,13.7154,13.5118,14.246,13.9291,13.8293,13.4568,13.7693,13.6191,14.1093,13.9676,14.2805,12.9627,13.9755,13.3325,13.8889,15.4081,13.8636,13.1314,14.4328,13.5992,13.5541,13.8333,13.8027,13.7756,13.7076,13.3495,13.4471,14.3181,14.4099,13.3468,13.5866,13.9694,13.9728,13.577,13.6471,13.9252,13.8859,14.6978,13.2197,14.3344,13.8703,14.5442,13.7671,14.3136,13.4037,14.4221,13.5272,13.2708,14.0717,14.3489,13.1336,14.2892,13.3174,14.5234,13.1601,14.4434,13.1392,13.2783,13.8058,13.8109,13.6801,12.7109,13.8257,14.229,14.2605,13.4641,13.8071,13.5629,13.8001,12.7669,14.2212,14.3144,13.9831,13.2182,13.5545,13.219,14.0641,14.9314,14.0507,13.1278,13.6548,13.5146,14.5811,13.5677,14.7554,14.6167,13.3704,13.3589,14.0424,12.5763,13.5268,14.3096,14.4003,13.3244,14.0111,13.6556,13.7581,14.3303,14.2147,13.7603,13.251,14.4927,13.6171,13.2343,14.5369,13.92,14.069,13.6393,13.9907,14.8575,13.2961,14.3309,13.4183,13.6764,13.517,13.5941,13.653,13.9013,14.0555,13.6945,13.5633,13.2478,14.2903,13.7799,13.2943,13.5913,13.6957,13.169,13.9977,13.4542,13.3647,14.0236,13.588,14.4979,13.8007,13.4326,13.7567,13.1245,13.8318,13.6296,14.9685,13.5974,14.4142,13.39,13.648,13.681,14.1574,14.0887,13.4521,13.4514,13.7126,13.3279,13.4203,13.0748,14.9464,13.6893,13.7067,13.418,13.9232,13.5133,14.1502,13.292,13.4773,13.3262,14.0924,13.9462,14.3818,14.1013,14.531,13.1054,14.639,14.2482,13.7798,13.9826,14.011,13.3925,13.1065,14.3983,14.5057,15.0773,13.6971,13.8137,13.4512,13.7714,13.8393,13.5913,13.9422,13.8715,13.4067,14.8059,14.0371,14.3982,13.5877,13.2667,14.1116,14.5748,13.0108,14.4685,13.6548,13.4953,13.8498,13.9735,13.471,14.4216,13.5573,13.4373,13.1668,15.0025,13.4347,13.1828,14.4666,14.0074,13.3194,13.6119,13.3139,13.4726,13.41,14.7404,15.0203,14.7711,13.9492,15.0034,13.0799,13.2592,13.8825,13.8467,13.4002,14.3283,14.2989,13.8382,13.542,15.0173,13.1397,13.3728,13.8489,14.0247,13.6582,13.7354,13.6755,13.5324,12.794,13.2446,13.9555,13.8216,13.7131,14.0666,14.1643,13.1426,14.1841,13.7735,14.772,13.4532,14.0007,12.5107,13.06,14.0654,14.2555,13.553,15.1649,14.1389,13.2753,13.8749,13.5881,14.8077,13.3399,14.323,13.5781,15.2453,13.8319,13.5809,14.0298,13.5466,14.5263,13.6578,14.6101,13.2624,13.1094,13.5642,13.7174,13.7122,13.3921,14.4924,14.1344,13.326,14.1332,13.9541,13.4273,13.785,13.0839,14.8006,13.5331,13.76,13.7216,13.9271,14.84,13.711,14.1786,13.3043,14.4644,13.0665,14.818,13.5153,13.5753,13.2709,14.3291,13.9913,13.4887,14.8945,13.7391,13.8247,13.196,14.2107,13.9976,14.0144,13.7903,14.0486,14.0078,13.4011,16.0447,13.9704,12.6737,13.7085,13.4819,13.9126,15.0277,13.8069,13.0747,13.9496,13.9258,14.0004,14.1201,13.1188,13.4269,14.9296,13.4484,13.9402,14.0339,14.0156,13.5252,14.3347,14.1508,14.0084,14.5586,13.6941,13.5716,13.6122,13.0904,13.6632,13.9912,14.2509,13.6757,14.1454,13.5599,13.9692,14.0784,13.5613,13.7422,13.8508,14.0634,14.1733,14.0847,13.6904,13.8766,14.0138,14.2042,13.5535,13.1801,13.633,13.4926,12.9584,13.9702,13.4408,13.5341,13.6868,13.2381,14.3592,14.0203,13.5876,13.7841,13.359,14.0539,13.5739,14.6215,14.5724,15.6163,13.4261,13.4523,14.4351,14.1939,13.7137,15.0969,14.292,12.8352,13.5321,14.0145,14.2182,14.7058,13.6358,13.4256,13.4229,13.8569,13.8871,14.1331,12.7249,13.174,14.6582,14.0244,13.3331,13.8167,14.1329,13.6689,13.2821,14.1214,13.0419,14.177,14.3878,15.7479,14.3181,13.2554,13.6306,13.7276,13.1785,14.6813,13.0461,13.2616,13.6643,13.5301,13.7954,13.8466,13.5966,13.1396,13.3679,13.9939,13.62,13.3586,13.4136,14.4014,13.5922,13.5491,13.6889,13.8358,13.7529,13.426,13.5819,14.1346,13.5354,15.0875,13.7665,13.1906,13.7877,14.8557,14.2105,14.1442,13.672,13.4941,13.5936,14.2073,13.6087,13.6203,13.5467,14.13,13.8742,14.0913,14.2247,13.5101,13.7438,14.4508,13.4727,14.0571,14.5548,13.8612,15.1941,13.8411,14.2165,13.2807,13.403,13.812,13.263,14.0858,12.9789,13.903,14.6642,13.4705,14.2886,13.4281,13.8176,13.6245,15.0777,13.4476,12.9158,13.3409,13.79,13.8096,14.0479,13.4757,13.6152,14.0813,13.3672,13.8858,14.537,13.1083,14.1542,13.2452,13.2998,14.2674,12.8534,13.878,14.4178,14.3333,12.5428,13.7623,14.5852,12.9427,14.5451,14.1954,13.2891,13.739,13.4765,13.6885,14.4447,12.9035,13.962,14.2151,13.8336,13.3474,14.7062,15.4943,13.6771,13.1079,13.8363,13.3572,12.9726,13.7572,13.9429,15.0736,13.5734,14.2321,14.7508,13.7093,13.6325,13.6298,13.8955,14.4985,13.7202,14.4719,13.9388,13.9707,13.9711,13.5474,14.4061,13.104,13.7033,13.4763,13.473,14.1192,13.5378,13.3617,13.9549,14.4216,13.2674,14.6918,13.9059,14.104,13.9729,13.8738,13.3819,13.297,14.153,14.1533,14.1884,13.274,14.5362,13.7533,14.3783,13.7049,14.0152 }; MeasuresPool<int, double> mp; for (int i=0; i<n_elem; i++) { mp.push(0, xs[i]); } Estimator_PWM<int, double> mle; mle.set_source_evt_approach(&typeid(EVTApproach_BM<int, double>)); mle.run(mp); auto res = mle.get_result(); ASSERT_TRUE(instanceof_ptr<GEV_Distribution>(res)); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_location(), 13.641, 1e-3); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_scale(), 0.462, 1e-3); EXPECT_NEAR(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_shape(), -0.116, 1e-3); EXPECT_LT(std::dynamic_pointer_cast<GEV_Distribution>(res)->get_shape(), 0); } TEST_F(EstimatorPWM_Test, Exceptions) { MeasuresPool<int, double> mp; Estimator_PWM<int, double> mle; EXPECT_THROW(mle.get_result(), std::runtime_error); EXPECT_THROW(mle.run(mp), std::runtime_error); mle.set_source_evt_approach(&typeid(int)); EXPECT_THROW(mle.run(mp), std::runtime_error); } TEST_F(EstimatorPWM_Test, String) { Estimator<int, double> *test = new Estimator_PWM<int, double>(); EXPECT_EQ("Probabilistic Weighted Moments (PWM)", test->to_string()); delete test; }
194.753695
12,494
0.753813
AlterB
f5765ea08d58e30f58316a9452fe376ca796ac09
3,821
cpp
C++
libraries/vulkan_renderer/private/VulkanSwapChain.cpp
cledant/particle_system_vulkan
d321eb6bae618138ad445368fa10b25a27a55d02
[ "MIT" ]
4
2021-12-20T19:35:20.000Z
2021-12-27T10:59:35.000Z
libraries/vulkan_renderer/private/VulkanSwapChain.cpp
cledant/particle_system_vulkan
d321eb6bae618138ad445368fa10b25a27a55d02
[ "MIT" ]
null
null
null
libraries/vulkan_renderer/private/VulkanSwapChain.cpp
cledant/particle_system_vulkan
d321eb6bae618138ad445368fa10b25a27a55d02
[ "MIT" ]
3
2021-12-27T06:51:00.000Z
2021-12-31T07:42:45.000Z
#include "VulkanSwapChain.hpp" #include <stdexcept> #include "utils/VulkanImage.hpp" #include "utils/VulkanSwapChainUtils.hpp" #include "utils/VulkanPhysicalDevice.hpp" void VulkanSwapChain::init(VulkanInstance const &vkInstance, uint32_t fb_w, uint32_t fb_h) { _devices = vkInstance.devices; _surface = vkInstance.surface; _create_swap_chain(fb_w, fb_h); _create_image_view(); } void VulkanSwapChain::resize(uint32_t fb_w, uint32_t fb_h) { oldSwapChainNbImg = currentSwapChainNbImg; clean(); _create_swap_chain(fb_w, fb_h); _create_image_view(); } void VulkanSwapChain::clean() { for (auto iv : swapChainImageViews) { iv.clearSwapchainTexture(); } vkDestroySwapchainKHR(_devices.device, swapChain, nullptr); } void VulkanSwapChain::clear() { clean(); _devices = VulkanDevices{}; _surface = nullptr; } void VulkanSwapChain::_create_swap_chain(uint32_t fb_w, uint32_t fb_h) { // Creating swap chain VkExtent2D actual_extent = { fb_w, fb_h }; auto scs = getSwapChainSupport(_devices.physicalDevice, _surface, actual_extent); if (!scs.isValid()) { throw std::runtime_error("VulkanRenderPass: SwapChain error"); } uint32_t nb_img = scs.capabilities.minImageCount + 1; if (scs.capabilities.maxImageCount > 0 && nb_img > scs.capabilities.maxImageCount) { nb_img = scs.capabilities.maxImageCount; } VkSwapchainCreateInfoKHR create_info{}; create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; create_info.surface = _surface; create_info.minImageCount = nb_img; create_info.imageFormat = scs.surface_format.value().format; create_info.imageColorSpace = scs.surface_format.value().colorSpace; create_info.imageExtent = scs.extent; create_info.imageArrayLayers = 1; create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; DeviceRequirement dr{}; getDeviceQueues(_devices.physicalDevice, _surface, dr); uint32_t queue_family_indices[] = { dr.present_family_index.value(), dr.graphic_family_index.value() }; if (dr.present_family_index.value() != dr.graphic_family_index.value()) { create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; create_info.queueFamilyIndexCount = 2; create_info.pQueueFamilyIndices = queue_family_indices; } else { create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; create_info.queueFamilyIndexCount = 0; create_info.pQueueFamilyIndices = nullptr; } create_info.preTransform = scs.capabilities.currentTransform; create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; create_info.presentMode = scs.present_mode.value(); create_info.clipped = VK_TRUE; create_info.oldSwapchain = nullptr; if (vkCreateSwapchainKHR( _devices.device, &create_info, nullptr, &swapChain) != VK_SUCCESS) { throw std::runtime_error( "VulkanRenderPass: Failed to create swap chain"); } // Retrieving img buffer + keeping info uint32_t nb_img_sc; vkGetSwapchainImagesKHR(_devices.device, swapChain, &nb_img_sc, nullptr); swapChainImages.resize(nb_img_sc); currentSwapChainNbImg = nb_img_sc; vkGetSwapchainImagesKHR( _devices.device, swapChain, &nb_img_sc, swapChainImages.data()); swapChainExtent = scs.extent; swapChainImageFormat = scs.surface_format.value().format; } void VulkanSwapChain::_create_image_view() { swapChainImageViews.resize(swapChainImages.size()); for (size_t i = 0; i < swapChainImages.size(); ++i) { swapChainImageViews[i].createSwapchainTexture( _devices, swapChainImages[i], swapChainImageFormat, swapChainExtent); } }
32.381356
79
0.713688
cledant
f5776324973ed49c80b1cd47d665865932adfce6
661
cpp
C++
C++/9.std/3.iterator/9.3.stl_iterator.cpp
Song2017/LabSourceCode
fb0a30f161c99f9c27d2fcdcf5fbb939c94684b8
[ "MIT" ]
2
2018-12-04T01:07:48.000Z
2019-01-02T09:49:25.000Z
C++/9.std/3.iterator/9.3.stl_iterator.cpp
Song2017/LabSourceCode
fb0a30f161c99f9c27d2fcdcf5fbb939c94684b8
[ "MIT" ]
5
2020-05-25T09:15:49.000Z
2021-03-15T02:21:40.000Z
C++/9.std/3.iterator/9.3.stl_iterator.cpp
Song2017/LabSourceCode
fb0a30f161c99f9c27d2fcdcf5fbb939c94684b8
[ "MIT" ]
3
2019-04-09T07:30:21.000Z
2019-07-09T12:48:13.000Z
#include <iostream> #include <list> using namespace std; int main() { // STL iterator // 迭代器是一种smart pointer, 用于访问顺序容器和关联容器中的元素 // 相当于容器和操作容器的算法的之间的中介 cout << " std iterator " << endl; list<int> v; v.push_back(3); v.push_back(4); v.push_front(2); v.push_front(1); list<int>::const_iterator it; // list<int>::iterator it; 可修改值 // !!! 迭代器不支持 >, <, wrong: it > v.end() for (it = v.begin(); it != v.end(); it++) { cout << *it << " "; } list<int>::reverse_iterator it2; for (it2 = v.rbegin(); it2 != v.rend(); it2++) { cout << *it2 << " "; } cout << " end " << endl; }
22.793103
50
0.517398
Song2017
f577a06d74cad2f5af9604df8888fe023bce2c7f
1,783
cpp
C++
c++/RealInterviewQ/maxsum.cpp
praveenpandit/programming
ee07b19d495f363297b5cc80d0b0a51b02cd964d
[ "MIT" ]
null
null
null
c++/RealInterviewQ/maxsum.cpp
praveenpandit/programming
ee07b19d495f363297b5cc80d0b0a51b02cd964d
[ "MIT" ]
null
null
null
c++/RealInterviewQ/maxsum.cpp
praveenpandit/programming
ee07b19d495f363297b5cc80d0b0a51b02cd964d
[ "MIT" ]
null
null
null
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; class solution { int *arr; int length; map<int, vector<int>> mp; int sumDigit(int a) { if (a == 0) return 0; else return (a % 10 + sumDigit(a / 10)); } void createMap(void) { for (int i = 0; i < length; i++) { int index = sumDigit(arr[i]); if (!mp.count(index)) { vector<int> v; v.push_back(arr[i]); mp.insert(pair(index, v)); make_heap(mp.at(index).begin(), mp.at(index).end()); } else { mp.at(index).push_back(arr[i]); push_heap(mp.at(index).begin(), mp.at(index).end()); } } } public: solution(int *data, int size) { arr = data; length = size; createMap(); } void display() { for (auto i : mp) { cout << i.first << "->"; for (auto j : i.second) cout << j << "-"; cout << endl; } } int getMaxSum(void) { auto max = -1; for (auto i : mp) { // cout << i.first << endl; if (i.second.size() > 1) { auto a1 = i.second.front(); pop_heap(i.second.begin(), i.second.end()); auto a2 = i.second.front(); if (max < (a1 + a2)) max = a1 + a2; } } return max; } }; int main() { int arr[3] = {51, 32, 43}; solution s(arr, sizeof(arr) / sizeof(arr[0])); // s.display(); cout << s.getMaxSum(); }
21.743902
68
0.398205
praveenpandit
f57deec6e825181ede2cac20d6f4b76aa8b3942a
1,605
hpp
C++
include/PgfPlotsGroupPlot.hpp
ksmith0/root2tikz
b87f464a988ec8629c8adb9d0fdcb15c990a9b07
[ "MIT" ]
null
null
null
include/PgfPlotsGroupPlot.hpp
ksmith0/root2tikz
b87f464a988ec8629c8adb9d0fdcb15c990a9b07
[ "MIT" ]
null
null
null
include/PgfPlotsGroupPlot.hpp
ksmith0/root2tikz
b87f464a988ec8629c8adb9d0fdcb15c990a9b07
[ "MIT" ]
null
null
null
/** * @author Karl Smith * @date Mar 5, 2018 */ #ifndef PGFPLOTSGROUPPLOT_HPP #define PGFPLOTSGROUPPLOT_HPP #include "PgfPlotsAxis.hpp" #include "PgfPlotsGroupSubPlot.hpp" class PgfPlotsGroupPlot : public PgfPlotsAxis { public: PgfPlotsGroupPlot(unsigned int rows, unsigned int columns, std::string options=""); /// Add a plot item to the axis. void AddPlot(PgfPlotsPlot *plot, unsigned int plotId); void SetGlobalAxisLimits(short axis = -1, bool limitGlobally = true); /// Get the sub plot object for a given id. PgfPlotsGroupSubPlot* GetSubPlot(unsigned int plotId); const std::pair<unsigned short, unsigned short> GetPlotDims(); /// Set the sub plot object for a given id. void SetSubPlot(unsigned int plotId, PgfPlotsGroupSubPlot* subPlot); private: /// The registered sub plots. std::vector< PgfPlotsGroupSubPlot* > subPlots_; std::array<bool, 3> globalAxisLimits_; /// The LaTeX command starting the environment. std::string EnvHeader() {return "\\begin{groupplot}";}; /// The LaTeX command ending the environment. std::string EnvFooter() {return "\\end{groupplot}";}; /// Perform some preprocessing prior to output. virtual void PreprocessOptions(); /// Determine axis label placement. void ProcessAxisLabels(); /// Determine axis label placement. void ProcessTickLabels(); /// Process the axis limits. void ProcessGlobalLimits(); /// Write out the group plot and registered sub plots. void WriteRegisteredItems(std::streambuf *buf); void WriteSubPlotPlaceHolder(std::streambuf *buf); }; #endif // PGFPLOTSGROUPPLOT_HPP
26.75
85
0.730218
ksmith0
f584b7d38c14d64e5d8906a84361732b316a2066
5,343
cpp
C++
ParseTestSuite/src/TestPFManager.cpp
sourada/Parse-Qt-SDK
32bb10a37ddebc71bae4e648438efb3bd9fdd48b
[ "BSD-2-Clause-FreeBSD" ]
null
null
null
ParseTestSuite/src/TestPFManager.cpp
sourada/Parse-Qt-SDK
32bb10a37ddebc71bae4e648438efb3bd9fdd48b
[ "BSD-2-Clause-FreeBSD" ]
null
null
null
ParseTestSuite/src/TestPFManager.cpp
sourada/Parse-Qt-SDK
32bb10a37ddebc71bae4e648438efb3bd9fdd48b
[ "BSD-2-Clause-FreeBSD" ]
null
null
null
// // TestPFManager.cpp // ParseTestSuite // // Created by Christian Noon on 11/14/13. // Copyright (c) 2013 Christian Noon. All rights reserved. // #include "PFManager.h" #include "TestRunner.h" using namespace parse; class TestPFManager : public QObject { Q_OBJECT private slots: // Class init and cleanup methods void initTestCase() { // Store the properties of the PFManager so we can put them back _applicationId = PFManager::sharedManager()->applicationId(); _restApiKey = PFManager::sharedManager()->restApiKey(); _cacheDirectory = PFManager::sharedManager()->cacheDirectory(); } void cleanupTestCase() { // Restore the properties PFManager::sharedManager()->setApplicationIdAndRestApiKey(_applicationId, _restApiKey); PFManager::sharedManager()->setCacheDirectory(_cacheDirectory); } // Function init and cleanup methods (called before/after each test) void init() { // Clear out the app id and rest api key for each test PFManager::sharedManager()->setApplicationIdAndRestApiKey("", ""); } void cleanup() { // No-op } // Creation Methods void test_sharedManager(); // Getter Setter Methods void test_setApplicationIdAndRestApiKey(); void test_applicationId(); void test_restApiKey(); // Caching and Network Methods void test_networkAccessManager(); void test_setCacheDirectory(); void test_cacheDirectory(); void test_clearCache(); private: // Instance members QString _applicationId; QString _restApiKey; QDir _cacheDirectory; }; void TestPFManager::test_sharedManager() { // Test the singleton pointer PFManager* manager1 = PFManager::sharedManager(); PFManager* manager2 = PFManager::sharedManager(); QCOMPARE(manager1, manager2); // Test the cache directory QDir cacheDirectory = PFManager::sharedManager()->cacheDirectory(); QCOMPARE(cacheDirectory.absolutePath().isEmpty(), false); } void TestPFManager::test_setApplicationIdAndRestApiKey() { // Valid Case 1 - Empty Values PFManager::sharedManager()->setApplicationIdAndRestApiKey("", ""); QCOMPARE(PFManager::sharedManager()->applicationId().isEmpty(), true); QCOMPARE(PFManager::sharedManager()->restApiKey().isEmpty(), true); // Valid Case 2 - Proper Values PFManager::sharedManager()->setApplicationIdAndRestApiKey("My Made Up App Id", "My Made Up Rest API Key"); QCOMPARE(PFManager::sharedManager()->applicationId().isEmpty(), false); QCOMPARE(PFManager::sharedManager()->restApiKey().isEmpty(), false); } void TestPFManager::test_applicationId() { // Should be empty now QCOMPARE(PFManager::sharedManager()->applicationId().isEmpty(), true); // Modify and retest PFManager::sharedManager()->setApplicationIdAndRestApiKey("My Made Up App Id", "My Made Up Rest API Key"); QCOMPARE(PFManager::sharedManager()->applicationId().isEmpty(), false); } void TestPFManager::test_restApiKey() { // Should be empty now QCOMPARE(PFManager::sharedManager()->restApiKey().isEmpty(), true); // Modify and retest PFManager::sharedManager()->setApplicationIdAndRestApiKey("My Made Up App Id", "My Made Up Rest API Key"); QCOMPARE(PFManager::sharedManager()->restApiKey().isEmpty(), false); } void TestPFManager::test_networkAccessManager() { QNetworkAccessManager* networkAccessManager = PFManager::sharedManager()->networkAccessManager(); QCOMPARE(networkAccessManager == NULL, false); QCOMPARE(networkAccessManager->networkAccessible(), QNetworkAccessManager::Accessible); } void TestPFManager::test_setCacheDirectory() { QDir tempDirectory = QDir::temp(); PFManager::sharedManager()->setCacheDirectory(tempDirectory); QCOMPARE(PFManager::sharedManager()->cacheDirectory().absolutePath(), tempDirectory.absolutePath()); } void TestPFManager::test_cacheDirectory() { QDir tempDirectory = QDir::temp(); PFManager::sharedManager()->setCacheDirectory(tempDirectory); QCOMPARE(PFManager::sharedManager()->cacheDirectory().absolutePath(), tempDirectory.absolutePath()); } void TestPFManager::test_clearCache() { // Create a new folder in the temp directory and set it as the cache directory QString folder = "TestPFManager-test_clearCache"; QDir tempDirectory = QDir::temp(); tempDirectory.mkdir(folder); QCOMPARE(tempDirectory.cd(folder), true); PFManager::sharedManager()->setCacheDirectory(tempDirectory); QCOMPARE(PFManager::sharedManager()->cacheDirectory().absolutePath(), tempDirectory.absolutePath()); // Add some stuff to that folder int currentCount = PFManager::sharedManager()->cacheDirectory().count(); PFManager::sharedManager()->cacheDirectory().mkdir("Dummy Folder 1"); PFManager::sharedManager()->cacheDirectory().mkdir("Dummy Folder 2"); PFManager::sharedManager()->cacheDirectory().mkdir("Dummy Folder 3"); PFManager::sharedManager()->cacheDirectory().refresh(); QCOMPARE(currentCount + 3, (int) PFManager::sharedManager()->cacheDirectory().count()); // Clear the cache PFManager::sharedManager()->clearCache(); PFManager::sharedManager()->cacheDirectory().refresh(); QCOMPARE(currentCount, (int) PFManager::sharedManager()->cacheDirectory().count()); QCOMPARE(tempDirectory.absolutePath(), PFManager::sharedManager()->cacheDirectory().absolutePath()); // Remove the test cache directory QCOMPARE(PFManager::sharedManager()->cacheDirectory().removeRecursively(), true); } DECLARE_TEST(TestPFManager) #include "TestPFManager.moc"
32.186747
107
0.75613
sourada
f588f904454f214864adda604b2654c69d97734f
1,017
hpp
C++
Server.hpp
mpmartin8080/boop
acd724ebd7c5b950baa6d2bd70e7eb84cce1974c
[ "MIT" ]
null
null
null
Server.hpp
mpmartin8080/boop
acd724ebd7c5b950baa6d2bd70e7eb84cce1974c
[ "MIT" ]
null
null
null
Server.hpp
mpmartin8080/boop
acd724ebd7c5b950baa6d2bd70e7eb84cce1974c
[ "MIT" ]
null
null
null
#ifndef SERVER_HPP #define SERVER_HPP #include "Global.hpp" #include "Demultiplexer.hpp" #include "Multiplexer.hpp" #include "UDPSocket.hpp" #include "ProxyTable.hpp" #include "Controller.hpp" #include <thread> #include <mutex> #include <condition_variable> #include <list> struct ControlCmd; class Controller; // Main server class that owns all other main resources class Server { public: // ctor/dtor Server(int listenport); ~Server(); // methods bool isRunning() { return m_running; } std::mutex* getMutex() { return &m_mutex; } std::condition_variable* getCV() { return &m_cv; } private: void ServerLoop(); // members UDPSocket m_permsocket; ProxyTable m_proxytable; std::shared_ptr<Demultiplexer> p_demux; Multiplexer* ap_muxtable[MAXTABLESIZE]; bool m_running; std::thread m_thread; std::mutex m_mutex; std::condition_variable m_cv; std::shared_ptr<Controller> m_controller; std::list<ControlCmd> m_cmdqueue; }; #endif // SERVER_HPP
19.941176
55
0.709931
mpmartin8080
f58a0dfaded949bf18dc15a8df8bec32b9ea1d5f
3,204
cpp
C++
test/pgfe/pgfe-unit-connection-rows.cpp
thevojacek/pgfe
22e85d4039c347dc4bb61bde8bdb0c4eeea860cf
[ "Zlib" ]
null
null
null
test/pgfe/pgfe-unit-connection-rows.cpp
thevojacek/pgfe
22e85d4039c347dc4bb61bde8bdb0c4eeea860cf
[ "Zlib" ]
null
null
null
test/pgfe/pgfe-unit-connection-rows.cpp
thevojacek/pgfe
22e85d4039c347dc4bb61bde8bdb0c4eeea860cf
[ "Zlib" ]
null
null
null
// -*- C++ -*- // Copyright (C) Dmitry Igrishin // For conditions of distribution and use, see files LICENSE.txt or pgfe.hpp #include "pgfe-unit.hpp" #include "dmitigr/pgfe.hpp" struct Person { int id; std::string name; unsigned int age; }; void print(const Person& p) { std::cout << "{\n"; std::cout << " id: " << p.id << "\n"; std::cout << " name: " << p.name << "\n"; std::cout << " age: " << p.age << "\n"; std::cout << "}\n"; } namespace dmitigr::pgfe { template<> struct Conversions<Person> { static Person to_type(const Row* const r) { ASSERT(r); Person p; p.id = to<int>(r->data("id")); p.name = to<std::string>(r->data("name")); p.age = to<unsigned int>(r->data("age")); return p; } static Person to_type(std::unique_ptr<Composite>&& c) { ASSERT(c); Person p; p.id = to<int>(c->data("id")); p.name = to<std::string>(c->data("name")); p.age = to<unsigned int>(c->data("age")); return p; } }; } // namespace dmitigr::pgfe int main(int, char* argv[]) { namespace pgfe = dmitigr::pgfe; using namespace dmitigr::test; try { // Connecting. const auto conn = pgfe::test::make_connection(); conn->connect(); // Preparing to test -- creating and filling the test table. conn->execute(R"(create temp table person(id serial not null primary key, name text not null, age integer not null))"); conn->execute(R"(insert into person (name, age) values('Alla', 30),('Bella', 33))"); // Test 1a. { std::cout << "From rows created on the server side:\n"; conn->execute("select * from person"); const auto persons = conn->rows<std::vector<Person>>(); ASSERT(persons.size() == 2); print(persons[0]); print(persons[1]); } // Test 1b. { conn->perform("begin"); conn->execute(R"( create or replace function all_persons() returns setof person language sql as $function$ select * from person; $function$; )"); std::cout << "From rows created on the server side by function all_persons:\n"; conn->invoke("all_persons"); auto persons = conn->rows<std::vector<Person>>(); ASSERT(persons.size() == 2); print(persons[0]); print(persons[1]); conn->perform("rollback"); } // Test 1c. { using pgfe::_; conn->perform("begin"); conn->execute(R"( create or replace function persons_by_name(fname text) returns setof person language sql as $function$ select * from person where name ~ fname; $function$; )"); std::cout << "From rows created on the server side by function persons_by_name:\n"; conn->invoke("persons_by_name", _{"fname", "^B"}); auto persons = conn->rows<std::vector<Person>>(); ASSERT(persons.size() == 1); for (const auto& person : persons) print(person); conn->perform("rollback"); } } catch (const std::exception& e) { report_failure(argv[0], e); return 1; } catch (...) { report_failure(argv[0]); return 1; } }
25.228346
89
0.560861
thevojacek
f58c713052d019c6780e12795023f729681c2da7
3,126
cpp
C++
tests/language_unit/ast/node/assgn_test.cpp
alashworth/stan-monorepo
75596bc1f860ededd7b3e9ae9002aea97ee1cd46
[ "BSD-3-Clause" ]
1
2019-09-06T15:53:17.000Z
2019-09-06T15:53:17.000Z
tests/language_unit/ast/node/assgn_test.cpp
alashworth/stan-monorepo
75596bc1f860ededd7b3e9ae9002aea97ee1cd46
[ "BSD-3-Clause" ]
8
2019-01-17T18:51:16.000Z
2019-01-17T18:51:39.000Z
tests/language_unit/ast/node/assgn_test.cpp
alashworth/stan-monorepo
75596bc1f860ededd7b3e9ae9002aea97ee1cd46
[ "BSD-3-Clause" ]
null
null
null
#include <stan/language/ast.hpp> #include <gtest/gtest.h> #include <string> using stan::lang::assgn; using stan::lang::bare_expr_type; using stan::lang::binary_op; using stan::lang::double_literal; using stan::lang::double_type; using stan::lang::expression; using stan::lang::idx; using stan::lang::index_op_sliced; using stan::lang::int_literal; using stan::lang::int_type; using stan::lang::omni_idx; using stan::lang::unary_op; using stan::lang::uni_idx; using stan::lang::variable; using std::vector; TEST(langAst, assgn) { variable v("foo"); double_type tDouble; v.set_type(bare_expr_type(tDouble)); std::vector<idx> is; expression e_int3(int_literal(3)); uni_idx ui(e_int3); idx idx0(ui); is.push_back(idx0); std::string op("="); expression e(int_literal(3)); assgn a(v, is, op, e); // retrieve indexes EXPECT_EQ(1, a.idxs_.size()); // retrieve LHS variable EXPECT_EQ(0, a.lhs_var_.type_.num_dims()); EXPECT_EQ(bare_expr_type(tDouble), a.lhs_var_.type_); // retrieve RHS expression EXPECT_EQ(0, a.rhs_.bare_type().num_dims()); int_type tInt; EXPECT_EQ(bare_expr_type(tInt), a.rhs_.bare_type()); } TEST(langAst, assgnSliced) { variable v("foo"); double_type tDouble; v.set_type(bare_expr_type(tDouble)); std::vector<idx> is; expression e_int3(int_literal(3)); uni_idx ui(e_int3); idx idx0(ui); is.push_back(idx0); stan::lang::expression e(v); stan::lang::multi_idx i(e); idx idx1(i); is.push_back(idx1); std::string op("="); expression e1(double_literal(1.0)); expression e2(double_literal(2.0)); std::vector<stan::lang::expression> elements; elements.push_back(e1); elements.push_back(e1); stan::lang::row_vector_expr rv1(elements); stan::lang::expression e3 = rv1; assgn a(v, is, op, e3); // retrieve indexes EXPECT_EQ(2, a.idxs_.size()); EXPECT_TRUE(a.lhs_var_has_sliced_idx()); // retrieve LHS variable // EXPECT_EQ(0, a.lhs_var_.type_.num_dims()); // EXPECT_EQ(bare_expr_type(tDouble), a.lhs_var_.type_); // retrieve RHS expression // EXPECT_EQ(0, a.rhs_.bare_type().num_dims()); // int_type tInt; // EXPECT_EQ(bare_expr_type(tInt), a.rhs_.bare_type()); } TEST(langAst, lhsVarOccursOnRhs) { variable v("foo"); v.set_type(double_type()); std::vector<idx> is; expression e_int3(int_literal(3)); uni_idx ui(e_int3); idx idx0(ui); is.push_back(idx0); std::string op("="); expression e(int_literal(3)); assgn a(v, is, op, e); EXPECT_FALSE(a.lhs_var_occurs_on_rhs()); std::vector<idx> is2; assgn a2(v, is2, op, v); EXPECT_TRUE(a2.lhs_var_occurs_on_rhs()); unary_op uo('+', v); assgn a3(v, is2, op, uo); EXPECT_TRUE(a3.lhs_var_occurs_on_rhs()); binary_op bo(v, "-", e_int3); assgn a4(v, is2, op, bo); EXPECT_TRUE(a4.lhs_var_occurs_on_rhs()); binary_op bo2(e_int3, "*", e_int3); assgn a5(v, is2, op, bo2); EXPECT_FALSE(a5.lhs_var_occurs_on_rhs()); binary_op bo3(e_int3, "*", bo); assgn a6(v, is2, op, bo3); EXPECT_TRUE(a6.lhs_var_occurs_on_rhs()); index_op_sliced ios(v, is2); assgn a7(v, is2, op, ios); EXPECT_TRUE(a7.lhs_var_occurs_on_rhs()); }
26.948276
59
0.689379
alashworth
f594ab6778155b1ed7e5617943bdaf59c081cb4e
428
hpp
C++
common/imgutils/imgmath.impl.hpp
dustsigns/lecture-demos
50d5abb252e7e467e9648b61310ce93b85c6c5f0
[ "BSD-3-Clause" ]
14
2018-03-26T13:43:58.000Z
2022-03-03T13:04:36.000Z
common/imgutils/imgmath.impl.hpp
dustsigns/lecture-demos
50d5abb252e7e467e9648b61310ce93b85c6c5f0
[ "BSD-3-Clause" ]
null
null
null
common/imgutils/imgmath.impl.hpp
dustsigns/lecture-demos
50d5abb252e7e467e9648b61310ce93b85c6c5f0
[ "BSD-3-Clause" ]
1
2019-08-03T23:12:08.000Z
2019-08-03T23:12:08.000Z
//Helper functions for calculations on images (template implementations) // Andreas Unterweger, 2017-2018 //This code is licensed under the 3-Clause BSD License. See LICENSE file for details. #pragma once //#include "imgmath.hpp" namespace imgutils { constexpr double LevelShift(const double value) { return value - 128; } constexpr double ReverseLevelShift(const double value) { return value + 128; } }
20.380952
85
0.733645
dustsigns
f594c2b996b1d3b9d4fa3d80b9aebb974d828137
2,300
cpp
C++
ext/src/sublstm.cpp
cimacmillan/pytorch-subLSTM
428e259063a016f6ddee0ec69e356bf8c1d87a44
[ "MIT" ]
null
null
null
ext/src/sublstm.cpp
cimacmillan/pytorch-subLSTM
428e259063a016f6ddee0ec69e356bf8c1d87a44
[ "MIT" ]
null
null
null
ext/src/sublstm.cpp
cimacmillan/pytorch-subLSTM
428e259063a016f6ddee0ec69e356bf8c1d87a44
[ "MIT" ]
null
null
null
#include <torch/extension.h> #include <iostream> #include <vector> torch::Tensor d_sigmoid(torch::Tensor z) { auto s = torch::sigmoid(z); return (1 - s) * s; } // tanh'(z) = 1 - tanh^2(z) torch::Tensor d_tanh(torch::Tensor z) { return 1 - z.tanh().pow(2); } // elu'(z) = relu'(z) + { alpha * exp(z) if (alpha * (exp(z) - 1)) < 0, else 0} torch::Tensor d_elu(torch::Tensor z, torch::Scalar alpha = 1.0) { auto e = z.exp(); auto mask = (alpha * (e - 1)) < 0; return (z > 0).type_as(z) + mask.type_as(z) * (alpha * e); } std::vector<at::Tensor> sLSTM_cell_forward( at::Tensor input, at::Tensor W, at::Tensor R, at::Tensor bias, at::Tensor h_tm1, at::Tensor c_tm1) { auto pre_act_gates = at::add((at::mm(input, W.t()) + at::mm(h_tm1, R.t())), bias); auto gates = at::sigmoid(pre_act_gates).chunk(4, /*dim=*/1); auto in_gate = gates[0]; auto f_gate = gates[1]; auto z = gates[2]; auto out_gate = gates[3]; auto new_cell = f_gate * c_tm1 + z - in_gate; auto new_hidden = at::sigmoid(new_cell) - out_gate; return {new_hidden, new_cell, pre_act_gates, f_gate}; } std::vector<at::Tensor> sLSTM_cell_backward( at::Tensor grad_h, at::Tensor grad_cell, at::Tensor cell_t, at::Tensor pre_act_gates, at::Tensor f_gate, at::Tensor W, at::Tensor R, at::Tensor in_t, at::Tensor h_tm1, at::Tensor cell_tm1) { auto d_cell = grad_h * d_sigmoid(cell_t) + grad_cell; // grads w.r.t. in_gate, f_gate, z and out_gate auto grads = torch::cat({-d_cell, d_cell * cell_tm1, d_cell, -grad_h}, /*dim*/1); grads *= d_sigmoid(pre_act_gates); auto t_grads = grads.t(); // Compute the gradients auto grad_W = t_grads.mm(in_t); auto grad_R = t_grads.mm(h_tm1); auto grad_bias = grads.sum(/*dim=*/0, /*keepdim=*/true); // Compute errors auto grad_h_tm1 = grads.mm(R); auto grad_input = grads.mm(W); auto grad_cell_tm1 = grad_cell * f_gate; return {grad_input, grad_h_tm1, grad_cell_tm1, grad_W, grad_R, grad_bias}; } // Binding PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { m.def("forward", &sLSTM_cell_forward, "LLTM forward"); m.def("backward", &sLSTM_cell_backward, "LLTM backward"); }
28.75
86
0.607391
cimacmillan
f597498f712d872f2e84af4a0b7bc9369efb1c4a
7,397
cpp
C++
netsvcs/clients/Tokens/rw_lock/rw_locks.cpp
azerothcore/lib-ace
c1fedd5f2033951eee9ecf898f6f2b75584aaefc
[ "DOC" ]
null
null
null
netsvcs/clients/Tokens/rw_lock/rw_locks.cpp
azerothcore/lib-ace
c1fedd5f2033951eee9ecf898f6f2b75584aaefc
[ "DOC" ]
null
null
null
netsvcs/clients/Tokens/rw_lock/rw_locks.cpp
azerothcore/lib-ace
c1fedd5f2033951eee9ecf898f6f2b75584aaefc
[ "DOC" ]
1
2020-04-26T03:07:12.000Z
2020-04-26T03:07:12.000Z
//============================================================================= /** * @file rw_locks.cpp * * test_rw_locks shows how to use ACE_Local_RLock, ACE_Local_WLock, * ACE_Remote_RLock, and ACE_Remote_WLock. * * @author Tim Harrison */ //============================================================================= #include "ace/Get_Opt.h" #include "ace/Local_Tokens.h" #include "ace/Remote_Tokens.h" #include "ace/Thread_Manager.h" #include "ace/Token_Invariants.h" #if defined (ACE_HAS_THREADS) && defined (ACE_HAS_THREADS_LIBRARY) typedef ACE_Token_Invariant_Manager ACE_TOKEN_INVARIANTS; static ACE_Token_Proxy *global_rlock; static ACE_Token_Proxy *global_wlock; static const char *server_host = ACE_DEFAULT_SERVER_HOST; static int server_port = ACE_DEFAULT_SERVER_PORT; static int ignore_deadlock = 0; static int threads = 2; static int iterations = 50; static int debug = 0; static int remote = 0; static int reads = 4; static int write_sleep = 0; static int renew = 0; static void * run_thread (void *) { for (int x = 0; x < iterations; x++) { int y = 0; for (; y < reads; y++) { if (global_rlock->acquire () == -1) { if (ACE_Log_Msg::instance ()->errnum () == EDEADLK) { ACE_DEBUG ((LM_DEBUG, "rlock deadlock detected\n")); goto READ_DEADLOCK; } else return 0; } if (ACE_TOKEN_INVARIANTS::instance ()->acquired (global_rlock) == 0) ACE_ERROR_RETURN ((LM_ERROR, "reader acquire violated invariant.\n"), 0); ACE_DEBUG ((LM_DEBUG, "(%t) rlock acquired.\n")); } if (renew) { ACE_TOKEN_INVARIANTS::instance ()->releasing (global_rlock); if (global_rlock->renew () == -1) { if (ACE_Log_Msg::instance ()->errnum () == EDEADLK) { ACE_DEBUG ((LM_DEBUG, "rlock deadlock detected during renew\n")); goto READ_DEADLOCK; } else return 0; } ACE_DEBUG ((LM_DEBUG, "(%t) rlock renewed.\n")); if (ACE_TOKEN_INVARIANTS::instance ()->acquired (global_rlock) == 0) ACE_ERROR_RETURN ((LM_ERROR, "reader renew violated invariant.\n"), 0); } READ_DEADLOCK: for (; y > 0; y--) { ACE_TOKEN_INVARIANTS::instance ()->releasing (global_rlock); if (global_rlock->release () == 0) ACE_DEBUG ((LM_DEBUG, "(%t) r-released.\n")); } if (global_wlock->acquire () == -1) ACE_DEBUG ((LM_DEBUG, "wlock deadlock detected\n")); else { if (write_sleep) ACE_OS::sleep (1); ACE_DEBUG ((LM_DEBUG, "\t\t(%t) wlock acquired.\n")); if (ACE_TOKEN_INVARIANTS::instance ()->acquired (global_wlock) == 0) ACE_ERROR_RETURN ((LM_ERROR, "writer acquire violated invariant.\n"), 0); if (renew) { ACE_TOKEN_INVARIANTS::instance ()->releasing (global_wlock); if (global_wlock->renew () == -1) { if (ACE_Log_Msg::instance ()->errnum () == EDEADLK) { ACE_DEBUG ((LM_DEBUG, "wlock deadlock detected during renew\n")); } else return 0; } ACE_DEBUG ((LM_DEBUG, "(%t) rlock renewed.\n")); if (ACE_TOKEN_INVARIANTS::instance ()->acquired (global_wlock) == 0) ACE_ERROR_RETURN ((LM_ERROR, "writer renew violated invariant.\n"), 0); } ACE_TOKEN_INVARIANTS::instance ()->releasing (global_wlock); if (global_wlock->release () == 0) ACE_DEBUG ((LM_DEBUG, "\t\t(%t) w-released.\n")); } } ACE_DEBUG ((LM_DEBUG, "(%t) thread exiting.\n")); return 0; } static int parse_args (int argc, ACE_TCHAR *argv[]) { ACE_LOG_MSG->open (argv[0], ACE_Log_Msg::STDERR); // | ACE_Log_Msg::VERBOSE); ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("t:iun:dr:sp:h:R"), 1); for (int c; (c = get_opt ()) != -1; ) { switch (c) { case 'h': // specify the host machine on which the server is running server_host = get_opt.opt_arg (); remote = 1; break; case 'p': // specify the port on which the server is running server_port = ACE_OS::atoi (get_opt.opt_arg ()); remote = 1; break; case 't': threads = ACE_OS::atoi (get_opt.opt_arg ()); break; case 'R': renew = 1; break; case 'r': reads = ACE_OS::atoi (get_opt.opt_arg ()); break; case 'd': debug = 1; break; case 's': write_sleep = 1; break; case 'n': iterations = ACE_OS::atoi (get_opt.opt_arg ()); break; case 'i': ignore_deadlock = 1; break; case 'u': // usage: fallthrough default: ACE_ERROR_RETURN ((LM_ERROR, "%n:\n" "[-h <remote host>]\n" "[-p <remote port>]\n" "[-i ignore deadlock]\n" "[-n <iterations>]\n" "[-R perform renews]\n" "[-r <reads>]\n" "[-d debug]\n" "[-s sleep during writes]\n" "[-t <threads>\n", 1), -1); } } return 0; } #if defined (ACE_HAS_PTHREADS) #define SUSPEND 0 #else #define SUSPEND THR_SUSPENDED #endif int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { if (parse_args (argc, argv) == -1) return -1; if (remote) { ACE_Remote_Mutex::set_server_address (ACE_INET_Addr (server_port, server_host)); global_rlock = (ACE_Token_Proxy *) new ACE_Remote_RLock ("THE_TOKEN", ignore_deadlock, debug); global_wlock = (ACE_Token_Proxy *) new ACE_Remote_WLock ("THE_TOKEN", ignore_deadlock, debug); } else { global_rlock = (ACE_Token_Proxy *) new ACE_Local_RLock ("THE_TOKEN", ignore_deadlock, debug); global_wlock = (ACE_Token_Proxy *) new ACE_Local_WLock ("THE_TOKEN", ignore_deadlock, debug); } ACE_Thread_Manager mgr; if (mgr.spawn_n (threads, ACE_THR_FUNC (run_thread), (void *) 0, THR_BOUND | SUSPEND) == -1) ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "spawn failed"), -1); #if ! defined (ACE_HAS_PTHREADS) if (mgr.resume_all () == -1) ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "resume failed"), -1); #endif mgr.wait (); return 0; } #else int ACE_TMAIN(int, ACE_TCHAR *[]) { ACE_ERROR_RETURN ((LM_ERROR, "threads not supported on this platform\n"), -1); } #endif /* ACE_HAS_THREADS */
29.588
88
0.493443
azerothcore
60d20eef6a795596af65e072330a15cf8d34af64
1,932
cpp
C++
src/fontgen/main.cpp
mikelange49/pedalevite
a81bd8a6119c5920995ec91b9f70e11e9379580e
[ "WTFPL" ]
69
2017-01-17T13:17:31.000Z
2022-03-01T14:56:32.000Z
src/fontgen/main.cpp
mikelange49/pedalevite
a81bd8a6119c5920995ec91b9f70e11e9379580e
[ "WTFPL" ]
1
2020-11-03T14:52:45.000Z
2020-12-01T20:31:15.000Z
src/fontgen/main.cpp
mikelange49/pedalevite
a81bd8a6119c5920995ec91b9f70e11e9379580e
[ "WTFPL" ]
8
2017-02-08T13:30:42.000Z
2021-12-09T08:43:09.000Z
/***************************************************************************** main.cpp Author: Laurent de Soras, 2019 --- Legal stuff --- This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. *Tab=3***********************************************************************/ #if defined (_MSC_VER) #pragma warning (1 : 4130 4223 4705 4706) #pragma warning (4 : 4355 4786 4800) #endif /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ #include "FontRenderer.h" #include <cassert> #include <cstdio> /*\\\ CLASS DEFINITIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ /*\\\ FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ int main (int /*argc*/, char * /*argv*/ []) { int ret_val = 0; try { // C:\\Windows\\Fonts\\DejaVuSansMono.ttf // 23.0 -> 24 // 31.0 -> 32 // C:\\Windows\\Fonts\\DejaVuSansMono-Bold.ttf // 15.0 -> 16 // 46.0 -> 48 const std::string font_filename ("C:\\Windows\\Fonts\\DejaVuSansMono.ttf"); const std::string expt_filename ("font-24-w125.data"); double size_pix = 23.0; double scale_h = 1.25; FontRenderer rend (font_filename.c_str (), size_pix, scale_h); ret_val = rend.export_to_raw (expt_filename.c_str ()); if (ret_val != 0) { printf ("Something failed (return code %d).\n", ret_val); assert (false); } } catch (std::exception &e) { printf ("*** main(): exception: %s\n", e.what ()); ret_val = -1; } catch (...) { printf ("*** main(): exception (undefined)\n"); ret_val = -1; } return (ret_val); } /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
22.206897
78
0.493789
mikelange49
60d353def9af38b2a10a30ffb4805392003414c1
2,494
cpp
C++
src/map/packets/message_standard.cpp
MarkWaldron/topaz
271665a3cb6c0e0cd9842d32e5b91dd14541c9f3
[ "FTL" ]
2
2020-09-17T12:21:55.000Z
2022-02-06T02:59:57.000Z
src/map/packets/message_standard.cpp
MarkWaldron/topaz
271665a3cb6c0e0cd9842d32e5b91dd14541c9f3
[ "FTL" ]
5
2020-04-10T19:33:53.000Z
2021-06-27T17:50:05.000Z
src/map/packets/message_standard.cpp
MarkWaldron/topaz
271665a3cb6c0e0cd9842d32e5b91dd14541c9f3
[ "FTL" ]
2
2020-04-11T16:56:14.000Z
2021-06-26T12:21:12.000Z
/* =========================================================================== Copyright (c) 2010-2015 Darkstar Dev Teams This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/ =========================================================================== */ #include "../../common/socket.h" #include <string.h> #include "message_standard.h" #include "../entities/charentity.h" CMessageStandardPacket::CMessageStandardPacket(MsgStd MessageID) { this->type = 0x09; this->size = 0x08; ref<uint16>(0x0A) = static_cast<uint16>(MessageID); } CMessageStandardPacket::CMessageStandardPacket(CCharEntity* PChar, uint32 param0, uint32 param1, MsgStd MessageID) { this->type = 0x09; this->size = 0x12; ref<uint16>(0x0A) = static_cast<uint16>(MessageID); if (PChar != nullptr) { ref<uint32>(0x04) = PChar->id; ref<uint16>(0x08) = PChar->targid; if (MessageID == MsgStd::Examine) { this->size = 0x30; ref<uint8>(0x0C) = 0x10; snprintf((char*)data+(0x0D), 24, "string2 %s", PChar->GetName()); } } else { snprintf((char*)data+(0x0D), 24, "Para0 %d Para1 %d", param0, param1); } } CMessageStandardPacket::CMessageStandardPacket(uint32 param0, uint32 param1, uint32 param2, uint32 param3, MsgStd MessageID) { this->type = 0x09; this->size = 0x08; ref<uint16>(0x0A) = static_cast<uint16>(MessageID); snprintf((char*)data+(0x0D), 100, "Para0 %d Para1 %d Para2 %d Para3 %d", param0, param1, param2, param3); this->size += (strlen((char*)data+(0x0D)) >> 1) & 0xFE; } // Only used with MsgStd::DiceRoll (/random) CMessageStandardPacket::CMessageStandardPacket(CCharEntity* PChar, uint32 param0, MsgStd MessageID) { this->type = 0x09; this->size = 0x18; //TPZ_DEBUG_BREAK_IF(MessageID != 0x58); ref<uint16>(0x0A) = static_cast<uint16>(MessageID); snprintf((char*)data+(0x0D), 40, "string2 %s string3 %u", PChar->GetName(), param0); //ref<uint8>(data,(0x2F)) = 0x02; }
27.108696
124
0.661989
MarkWaldron
60d811429af6d48d5adccf0e043a007c9f6af197
7,458
cxx
C++
Modules/Visualization/MonteverdiGui/src/mvdStatusBarWidget.cxx
heralex/OTB
c52b504b64dc89c8fe9cac8af39b8067ca2c3a57
[ "Apache-2.0" ]
317
2015-01-19T08:40:58.000Z
2022-03-17T11:55:48.000Z
Modules/Visualization/MonteverdiGui/src/mvdStatusBarWidget.cxx
guandd/OTB
707ce4c6bb4c7186e3b102b2b00493a5050872cb
[ "Apache-2.0" ]
18
2015-07-29T14:13:45.000Z
2021-03-29T12:36:24.000Z
Modules/Visualization/MonteverdiGui/src/mvdStatusBarWidget.cxx
guandd/OTB
707ce4c6bb4c7186e3b102b2b00493a5050872cb
[ "Apache-2.0" ]
132
2015-02-21T23:57:25.000Z
2022-03-25T16:03:16.000Z
/* * Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES) * * This file is part of Orfeo Toolbox * * https://www.orfeo-toolbox.org/ * * 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 "mvdStatusBarWidget.h" #include "ui_mvdStatusBarWidget.h" /*****************************************************************************/ /* INCLUDE SECTION */ // // Qt includes (sorted by alphabetic order) //// Must be included before system/custom includes. // // System includes (sorted by alphabetic order) // #include <cassert> // // ITK includes (sorted by alphabetic order) // // OTB includes (sorted by alphabetic order) // // Monteverdi includes (sorted by alphabetic order) namespace mvd { /* TRANSLATOR mvd::StatusBarWidget Necessary for lupdate to be aware of C++ namespaces. Context comment for translator. */ /*****************************************************************************/ /* CONSTANTS */ /*****************************************************************************/ /* STATIC IMPLEMENTATION SECTION */ /*****************************************************************************/ /* CLASS IMPLEMENTATION SECTION */ /*****************************************************************************/ StatusBarWidget::StatusBarWidget(QWidget* p, Qt::WindowFlags flags) : QWidget(p, flags), m_UI(new mvd::Ui::StatusBarWidget()) { m_UI->setupUi(this); // mantis-1385 hide scaleLineEdit m_UI->label_4->hide(); m_UI->scaleLineEdit->hide(); } /*****************************************************************************/ StatusBarWidget::~StatusBarWidget() { delete m_UI; m_UI = NULL; } /*****************************************************************************/ QString StatusBarWidget::ZoomLevel(double scale) { if (scale > 1.0) return QString("%1:1").arg(scale); else if (scale < 1.0) return QString("1:%1").arg(1.0 / scale); return "1:1"; } /*****************************************************************************/ void StatusBarWidget::SetGLSLEnabled(bool enabled) { m_UI->renderModelLabel->setText(enabled ? tr("GLSL") : tr("OpenGL")); } /*****************************************************************************/ /* SLOTS */ /*****************************************************************************/ void StatusBarWidget::SetPixelIndex(const IndexType& pixel, bool isInsideRegion) { assert(m_UI != NULL); assert(m_UI->pixelIndexLineEdit != NULL); m_UI->pixelIndexLineEdit->setText(isInsideRegion ? QString("%1, %2").arg(pixel[0]).arg(pixel[1]) : QString()); } /*****************************************************************************/ void StatusBarWidget::SetScale(double sx, double) { // qDebug() << this << "::SetScale(" << sx << "," << sy << ")"; /* if( sx!=sy ) zoomLevel.append( "/" + StatusBarWidget::ZoomLevel( sy ) ); */ m_UI->scaleLineEdit->setText(StatusBarWidget::ZoomLevel(sx)); } /*****************************************************************************/ /* PRIVATE SLOTS */ /*****************************************************************************/ /* void StatusBarWidget ::SetPixelIndexText( const QString& text ) { m_UI->pixelIndexLineEdit->setText( text ); } */ /*****************************************************************************/ void StatusBarWidget::SetText(const QString& text) { assert(m_UI != NULL); assert(m_UI->pixelIndexLineEdit != NULL); m_UI->pixelRadiometryLabel->setText(text); } /*****************************************************************************/ void StatusBarWidget::on_pixelIndexLineEdit_returnPressed() { // // Cancel if pixel-index coordinates text is empty. if (m_UI->pixelIndexLineEdit->text().isEmpty()) return; // // Split coordinates. QStringList coordinates(m_UI->pixelIndexLineEdit->text().split(',')); // // Check split coordinates format. assert(coordinates.size() == 1 || coordinates.size() == 2); if (coordinates.size() != 1 && coordinates.size() != 2) return; // // Construct resulting pixel-index. IndexType index; index.Fill(0); // // Convert first pixel-index coordinate. bool isOk = true; index[0] = coordinates.front().toUInt(&isOk); // assert( isOk ); if (!isOk) return; // // Convert second pixel-index coordinate. if (coordinates.size() > 1) { index[1] = coordinates.back().toUInt(&isOk); // assert( isOk ); if (!isOk) return; } // // If both pixel-index coordinates have correctly been converted, // Q_EMIT pixel-index changed signal. Q_EMIT PixelIndexChanged(index); } /*****************************************************************************/ void StatusBarWidget::on_scaleLineEdit_returnPressed() { ChangeScale(); } void StatusBarWidget::on_scaleLineEdit_editingFinished() { if (m_UI->scaleLineEdit->isModified()) { ChangeScale(); } } void StatusBarWidget::ChangeScale() { // // Cancel if scale text is empty. if (m_UI->scaleLineEdit->text().isEmpty()) return; // // Split scale text. QStringList scale(m_UI->scaleLineEdit->text().split(':')); // // Check scale text format. // assert( scale.size()==1 || scale.size()==2 ); if (scale.size() != 1 && scale.size() != 2) return; /* if( scale.size()!=1 && scale.size()!=2 ) { throw std::invalid_argument( ToStdString( tr( "Invalid argument: '%1' should be scale of the form <numerator>[:<denominator>] with numerator and denominator being real numbers." ) ) ); } */ // // Convert scale numerator. bool isOk = true; double numerator = scale.front().toDouble(&isOk); // assert( isOk ); // assert( numerator!=0.0 ); if (!isOk || numerator == 0.0) return; /* if( !isOk ) { throw std::invalid_argument( ToStdString( tr( "Invalid argument: '%1' should be scale of the form <numerator>[:<denominator>] with numerator and denominator being real numbers." ) ) ); } */ // // Convert scale denominator. double denominator = 1.0; if (scale.size() > 1) { denominator = scale.back().toDouble(&isOk); // assert( isOk ); if (!isOk) return; /* if( !isOk ) { throw std::invalid_argument( ToStdString( tr( "Invalid argument: '%1' should be scale of the form <numerator>[:<denominator>] with numerator and denominator being real numbers." ) ) ); } */ } // // Emit scale changed. Q_EMIT ScaleChanged(numerator / denominator); } } // end namespace 'mvd'
25.367347
147
0.508313
heralex
60d9b5c7bee32d86b125b14357bdceda1e5109b8
2,598
cpp
C++
facebook/2017/round1/3/main.cpp
seirion/code
3b8bf79764107255185061cec33decbc2235d03a
[ "Apache-2.0" ]
13
2015-06-07T09:26:26.000Z
2019-05-01T13:23:38.000Z
facebook/2017/round1/3/main.cpp
seirion/code
3b8bf79764107255185061cec33decbc2235d03a
[ "Apache-2.0" ]
null
null
null
facebook/2017/round1/3/main.cpp
seirion/code
3b8bf79764107255185061cec33decbc2235d03a
[ "Apache-2.0" ]
4
2016-03-05T06:21:05.000Z
2017-02-17T15:34:18.000Z
// https://www.facebook.com/hackercup/problem/300438463685411/ // Facebook Hacker Cup 2016 Round 1 // Manic Moving #include <iostream> #include <cstdio> #include <cstring> #include <set> using namespace std; const int INF = 0x7f7f7f7f; class Line { public: Line(int t, int c) : to(t), cost(c) {} int to, cost; bool operator <(const Line& l) const { return to < l.to; } }; int n, m, k; int dist [5000][5000]; set<Line> line[5000]; int sd[5000][2]; int length_to [5000][5000]; // contains shortest distances class Node { public: Node(int i) : index(i) {} int index; bool operator <(const Node& l) const { return (length_to[index] == length_to[l.index]) ? index < l.index : length_to[index] < length_to[l.index]; } }; void clear() { memset(dist, 0x7F, sizeof(dist)); memset(length_to, 0x7F, sizeof(length_to)); for (int i = 0; i < 5000; i++) line[i].clear(); } void input() { cin >> n >> m >> k; for (int i = 0; i < m; i++) { int a, b, x; cin >> a >> b >> x; a--; b--; // 0-based index if (dist[a][b] <= x) continue; dist[a][b] = dist[b][a] = x; length_to[a][b] = length_to[b][a] = x; line[a].insert(Line(b, x)); line[b].insert(Line(a, x)); } for (int i = 0; i < k; i++) { cin >> sd[i][0] >> sd[i][1]; sd[i][0]--; sd[i][1]--; // 0-based index } } void dijkstra() { for (int i = 0; i < n; i++) { length_to[i][i] = 0; set<Node> Q; for (int j = 0; j < n; j++) { if (i != j && dist[i][j] != INF) { Q.insert(j); } } while (!Q.empty()) { Node node = *Q.begin(); Q.erase(Q.begin()); auto it = line[node.index].begin(); for (; it != line[node.index].end(); it++) { int len = length_to[i][node.index] + dist[node.index][it->to]; if (length_to[i][it->to] > len) { length_to[i][it->to] = len; Q.erase(Node(it->to)); length_to[i][it->to] = len; Q.insert(Node(it->to)); } } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << length_to[i][j] << " "; } cout << endl; } } void solve(int k) { dijkstra(); //printf("Case #%d: %.10f\n", k, expect / (b - a)); } int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { clear(); input(); solve(i); } return 0; }
23.618182
78
0.454965
seirion
60d9f3a3a8331e59a81aa199055116b2ec970e2b
953
cpp
C++
CPPSolutions/Hackerrank/CountingValleys.cpp
Dilbarjot/CP
2395c6c270e53277a7a020e5b467e517353bc229
[ "MIT" ]
null
null
null
CPPSolutions/Hackerrank/CountingValleys.cpp
Dilbarjot/CP
2395c6c270e53277a7a020e5b467e517353bc229
[ "MIT" ]
null
null
null
CPPSolutions/Hackerrank/CountingValleys.cpp
Dilbarjot/CP
2395c6c270e53277a7a020e5b467e517353bc229
[ "MIT" ]
null
null
null
/** ** Created by dilbar on 2021-01-17 ** In progress **/ #include <bits/stdc++.h> using namespace std; /* * Complete the 'countingValleys' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER steps * 2. STRING path */ int countingValleys(int steps, string path) { int l = path.length(); int l1 = 0, l2 = 0; string v1[l / 2], v2[l / 2]; bool d = false; for (int i = 0; i < l; i++) { char c = path.at(i); if (c == 'D') { d = true; v1[l1++] = 'D'; } else { if (d) { v2[l2++] = 'U'; d = false; } } } return l2 - 1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int x; string y; // cin >> x >> y; x = 14; y = "DDDUDUUDDDDUUU"; cout << countingValleys(x, y) << "\n"; return 0; }
19.44898
49
0.481637
Dilbarjot
60db6d7819fddb6ac56c9ae7a247232857fbac0b
2,314
cpp
C++
src/execution/insert_executor.cpp
duynguyen-ori75/bustub-2019
5932f34c602aa8adbb25e7d1b70d82cb0802693f
[ "MIT" ]
10
2020-10-11T15:29:56.000Z
2021-10-09T06:59:14.000Z
src/execution/insert_executor.cpp
duynguyen-ori75/bustub-2019
5932f34c602aa8adbb25e7d1b70d82cb0802693f
[ "MIT" ]
1
2020-10-01T03:36:12.000Z
2020-10-01T03:36:12.000Z
src/execution/insert_executor.cpp
duynguyen-ori75/bustub-2019
5932f34c602aa8adbb25e7d1b70d82cb0802693f
[ "MIT" ]
9
2020-09-01T03:35:19.000Z
2022-02-04T05:00:26.000Z
//===----------------------------------------------------------------------===// // // BusTub // // insert_executor.cpp // // Identification: src/execution/insert_executor.cpp // // Copyright (c) 2015-19, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// #include "execution/executors/insert_executor.h" #include <memory> #include "common/logger.h" namespace bustub { InsertExecutor::InsertExecutor(ExecutorContext *exec_ctx, const InsertPlanNode *plan, std::unique_ptr<AbstractExecutor> &&child_executor) : AbstractExecutor(exec_ctx), plan_(plan), child_exe_(std::move(child_executor)) {} const Schema *InsertExecutor::GetOutputSchema() { const auto &catalog = this->GetExecutorContext()->GetCatalog(); return &catalog->GetTable(this->plan_->TableOid())->schema_; } void InsertExecutor::Init() { const auto &catalog = this->GetExecutorContext()->GetCatalog(); this->table_ = catalog->GetTable(this->plan_->TableOid())->table_.get(); // Initialize all children if (!this->plan_->IsRawInsert()) { this->child_exe_->Init(); } } bool InsertExecutor::Next([[maybe_unused]] Tuple *) { // is raw insert -> get all raw tuples and insert RID rid; Tuple tuple; if (this->plan_->IsRawInsert()) { auto numberOfTups = this->plan_->RawValues().size(); for (size_t idx = 0; idx < numberOfTups; idx++) { tuple = Tuple(this->plan_->RawValuesAt(idx), this->GetOutputSchema()); auto success = this->table_->InsertTuple(tuple, &rid, this->GetExecutorContext()->GetTransaction()); // LOG_DEBUG("Insert tuple successfully: %s", tuple.ToString(this->GetOutputSchema()).c_str()); if (!success) return success; } // LOG_DEBUG("Insert %d tuples into table", int(numberOfTups)); return true; } // get tuples from child executor, and then insert them while (this->child_exe_->Next(&tuple)) { // LOG_DEBUG("Read tuple: %s", tuple.ToString(this->GetOutputSchema()).c_str()); auto success = this->table_->InsertTuple(tuple, &rid, this->GetExecutorContext()->GetTransaction()); if (!success) return success; } return true; } } // namespace bustub
36.730159
107
0.610631
duynguyen-ori75
60dea5a4b2183c353cad8d1b08c062bb22bc471c
5,609
cpp
C++
Splash_CPP/Splash_BackUpThisFolder_ButDontShipItWithYourGame/il2cppOutput/UnityEngine.IMGUIModule1.cpp
seonghwan-dev/Splash-Demonstration
b41a9be7ea3c22fb3e9d461b64bc87df70123c4a
[ "MIT" ]
null
null
null
Splash_CPP/Splash_BackUpThisFolder_ButDontShipItWithYourGame/il2cppOutput/UnityEngine.IMGUIModule1.cpp
seonghwan-dev/Splash-Demonstration
b41a9be7ea3c22fb3e9d461b64bc87df70123c4a
[ "MIT" ]
null
null
null
Splash_CPP/Splash_BackUpThisFolder_ButDontShipItWithYourGame/il2cppOutput/UnityEngine.IMGUIModule1.cpp
seonghwan-dev/Splash-Demonstration
b41a9be7ea3c22fb3e9d461b64bc87df70123c4a
[ "MIT" ]
null
null
null
#include "pch-cpp.hpp" #ifndef _MSC_VER # include <alloca.h> #else # include <malloc.h> #endif #include <limits> #include <stdint.h> // System.Byte[] struct ByteU5BU5D_tA6237BF417AE52AD70CFB4EF24A7A82613DF9031; // System.Char[] struct CharU5BU5D_t799905CF001DD5F13F7DBB310181FC4D8B7D0AAB; // System.String struct String_t; IL2CPP_EXTERN_C_BEGIN IL2CPP_EXTERN_C_END #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winvalid-offsetof" #pragma clang diagnostic ignored "-Wunused-variable" #endif // <PrivateImplementationDetails> struct U3CPrivateImplementationDetailsU3E_tCA0A4120E1B13462A402E739CE2DD9CA72BAC713 : public RuntimeObject { }; struct Il2CppArrayBounds; // System.String struct String_t : public RuntimeObject { // System.Int32 System.String::_stringLength int32_t ____stringLength_4; // System.Char System.String::_firstChar Il2CppChar ____firstChar_5; }; struct String_t_StaticFields { // System.String System.String::Empty String_t* ___Empty_6; }; // System.ValueType struct ValueType_t6D9B272BD21782F0A9A14F2E41F85A50E97A986F : public RuntimeObject { }; // Native definition for P/Invoke marshalling of System.ValueType struct ValueType_t6D9B272BD21782F0A9A14F2E41F85A50E97A986F_marshaled_pinvoke { }; // Native definition for COM marshalling of System.ValueType struct ValueType_t6D9B272BD21782F0A9A14F2E41F85A50E97A986F_marshaled_com { }; // System.Char struct Char_t521A6F19B456D956AF452D926C32709DC03D6B17 { // System.Char System.Char::m_value Il2CppChar ___m_value_0; }; struct Char_t521A6F19B456D956AF452D926C32709DC03D6B17_StaticFields { // System.Byte[] System.Char::s_categoryForLatin1 ByteU5BU5D_tA6237BF417AE52AD70CFB4EF24A7A82613DF9031* ___s_categoryForLatin1_3; }; // System.Enum struct Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2 : public ValueType_t6D9B272BD21782F0A9A14F2E41F85A50E97A986F { }; struct Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2_StaticFields { // System.Char[] System.Enum::enumSeperatorCharArray CharU5BU5D_t799905CF001DD5F13F7DBB310181FC4D8B7D0AAB* ___enumSeperatorCharArray_0; }; // Native definition for P/Invoke marshalling of System.Enum struct Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2_marshaled_pinvoke { }; // Native definition for COM marshalling of System.Enum struct Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2_marshaled_com { }; // System.Int32 struct Int32_t680FF22E76F6EFAD4375103CBBFFA0421349384C { // System.Int32 System.Int32::m_value int32_t ___m_value_0; }; // System.UInt32 struct UInt32_t1833D51FFA667B18A5AA4B8D34DE284F8495D29B { // System.UInt32 System.UInt32::m_value uint32_t ___m_value_0; }; // UnityEngine.TextSelectingUtilities/CharacterType struct CharacterType_tA5537D2CAC701C90819571E9AEBE3D038EB92744 { // System.Int32 UnityEngine.TextSelectingUtilities/CharacterType::value__ int32_t ___value___2; }; // UnityEngine.TextSelectingUtilities/Direction struct Direction_t45077BAAE21B4351F02B52132135851E2610799C { // System.Int32 UnityEngine.TextSelectingUtilities/Direction::value__ int32_t ___value___2; }; #ifdef __clang__ #pragma clang diagnostic pop #endif // System.Char System.String::get_Chars(System.Int32) IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR Il2CppChar String_get_Chars_mC49DF0CD2D3BE7BE97B3AD9C995BE3094F8E36D3 (String_t* __this, int32_t ___index0, const RuntimeMethod* method) ; // System.Int32 System.String::get_Length() IL2CPP_MANAGED_FORCE_INLINE IL2CPP_METHOD_ATTR int32_t String_get_Length_m42625D67623FA5CC7A44D47425CE86FB946542D2_inline (String_t* __this, const RuntimeMethod* method) ; #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winvalid-offsetof" #pragma clang diagnostic ignored "-Wunused-variable" #endif #ifdef __clang__ #pragma clang diagnostic pop #endif #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winvalid-offsetof" #pragma clang diagnostic ignored "-Wunused-variable" #endif #ifdef __clang__ #pragma clang diagnostic pop #endif #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Winvalid-offsetof" #pragma clang diagnostic ignored "-Wunused-variable" #endif // System.UInt32 <PrivateImplementationDetails>::ComputeStringHash(System.String) IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR uint32_t U3CPrivateImplementationDetailsU3E_ComputeStringHash_m782905D005B9F23E65F027133B50E5CCAA150BF1 (String_t* ___s0, const RuntimeMethod* method) { uint32_t V_0 = 0; int32_t V_1 = 0; { String_t* L_0 = ___s0; if (!L_0) { goto IL_002c; } } { V_0 = ((int32_t)-2128831035); V_1 = 0; goto IL_0021; } IL_000d: { String_t* L_1 = ___s0; int32_t L_2 = V_1; NullCheck(L_1); Il2CppChar L_3; L_3 = String_get_Chars_mC49DF0CD2D3BE7BE97B3AD9C995BE3094F8E36D3(L_1, L_2, NULL); uint32_t L_4 = V_0; V_0 = ((int32_t)il2cpp_codegen_multiply(((int32_t)((int32_t)L_3^(int32_t)L_4)), ((int32_t)16777619))); int32_t L_5 = V_1; V_1 = ((int32_t)il2cpp_codegen_add(L_5, 1)); } IL_0021: { int32_t L_6 = V_1; String_t* L_7 = ___s0; NullCheck(L_7); int32_t L_8; L_8 = String_get_Length_m42625D67623FA5CC7A44D47425CE86FB946542D2_inline(L_7, NULL); if ((((int32_t)L_6) >= ((int32_t)L_8))) { goto IL_002c; } } { goto IL_000d; } IL_002c: { uint32_t L_9 = V_0; return L_9; } } #ifdef __clang__ #pragma clang diagnostic pop #endif IL2CPP_MANAGED_FORCE_INLINE IL2CPP_METHOD_ATTR int32_t String_get_Length_m42625D67623FA5CC7A44D47425CE86FB946542D2_inline (String_t* __this, const RuntimeMethod* method) { { int32_t L_0 = __this->____stringLength_4; return L_0; } }
25.495455
186
0.808522
seonghwan-dev
60def206a9486274c6b0ef84f696e5b451efa39f
2,778
hpp
C++
src/mlpack/methods/ann/layer/not_adapted/concat_performance_impl.hpp
shubham1206agra/mlpack
2c656fcba850134f3f5d1dd1a6a1a15743aa7661
[ "BSD-3-Clause-Clear", "BSD-3-Clause" ]
null
null
null
src/mlpack/methods/ann/layer/not_adapted/concat_performance_impl.hpp
shubham1206agra/mlpack
2c656fcba850134f3f5d1dd1a6a1a15743aa7661
[ "BSD-3-Clause-Clear", "BSD-3-Clause" ]
null
null
null
src/mlpack/methods/ann/layer/not_adapted/concat_performance_impl.hpp
shubham1206agra/mlpack
2c656fcba850134f3f5d1dd1a6a1a15743aa7661
[ "BSD-3-Clause-Clear", "BSD-3-Clause" ]
null
null
null
/** * @file methods/ann/layer/concat_performance_impl.hpp * @author Marcus Edel * * Implementation of the ConcatPerformance class. * * mlpack is free software; you may redistribute it and/or modify it under the * terms of the 3-clause BSD license. You should have received a copy of the * 3-clause BSD license along with mlpack. If not, see * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef MLPACK_METHODS_ANN_LAYER_CONCAT_PERFORMANCE_IMPL_HPP #define MLPACK_METHODS_ANN_LAYER_CONCAT_PERFORMANCE_IMPL_HPP // In case it hasn't yet been included. #include "concat_performance.hpp" namespace mlpack { namespace ann /** Artificial Neural Network. */ { template< typename OutputLayerType, typename InputType, typename OutputType > ConcatPerformance< OutputLayerType, InputType, OutputType >::ConcatPerformance(OutputLayerType&& outputLayer) : outputLayer(std::move(outputLayer)) { // Nothing to do here. } template< typename OutputLayerType, typename InputType, typename OutputType > void ConcatPerformance< OutputLayerType, InputType, OutputType >::Forward(const InputType& input, OutputType& target) { const size_t elements = input.n_elem / inputDimensions[0]; double output = 0; for (size_t i = 0; i < input.n_elem; i += elements) { InputType subInput = input.submat(i, 0, i + elements - 1, 0); output += outputLayer.Forward(subInput, target); } // TODO: what to do with output? //return output; return; } template< typename OutputLayerType, typename InputType, typename OutputType > void ConcatPerformance< OutputLayerType, InputType, OutputType >::Backward( const InputType& input, const OutputType& target, OutputType& output) { const size_t elements = input.n_elem / inputDimensions[0]; InputType subInput = input.submat(0, 0, elements - 1, 0); OutputType subOutput; outputLayer.Backward(subInput, target, subOutput); output = arma::zeros(subOutput.n_elem, inputDimensions[0]); output.col(0) = subOutput; for (size_t i = elements, j = 0; i < input.n_elem; i+= elements, ++j) { subInput = input.submat(i, 0, i + elements - 1, 0); outputLayer.Backward(subInput, target, subOutput); output.col(j) = subOutput; } } template< typename OutputLayerType, typename InputType, typename OutputType > template<typename Archive> void ConcatPerformance< OutputLayerType, InputType, OutputType >::serialize(Archive& ar, const uint32_t /* version */) { ar(cereal::base_class<Layer<InputType, OutputType>>(this)); ar(CEREAL_NVP(outputLayer)); } } // namespace ann } // namespace mlpack // Include implementation. #include "concat_performance_impl.hpp" #endif
23.542373
78
0.714543
shubham1206agra
60e0a67cb07d212827575cfd62fa21023b2a36e2
2,579
cpp
C++
samples/Lua2D/proj.win32/main.cpp
pontelua/Lua2D
dde44d78d1600bb9a06e27908cfddf441e1012a6
[ "Zlib", "libtiff", "BSD-2-Clause", "Apache-2.0", "MIT", "Libpng", "curl", "BSD-3-Clause" ]
2
2015-03-22T00:17:30.000Z
2017-09-30T03:23:25.000Z
samples/Lua2D/proj.win32/main.cpp
pontelua/Lua2D
dde44d78d1600bb9a06e27908cfddf441e1012a6
[ "Zlib", "libtiff", "BSD-2-Clause", "Apache-2.0", "MIT", "Libpng", "curl", "BSD-3-Clause" ]
null
null
null
samples/Lua2D/proj.win32/main.cpp
pontelua/Lua2D
dde44d78d1600bb9a06e27908cfddf441e1012a6
[ "Zlib", "libtiff", "BSD-2-Clause", "Apache-2.0", "MIT", "Libpng", "curl", "BSD-3-Clause" ]
null
null
null
#include "main.h" #include "AppDelegate.h" #include "CCEGLView.h" #include "XGetOpt.h" #include <ShellAPI.h> USING_NS_CC; static void parseOptions(AppDelegate* app, int argc, TCHAR* argv[]); #ifdef _CONSOLE int _tmain(int argc, _TCHAR* argv[]) { #else // uncomment below line, open debug console #define USE_WIN32_CONSOLE int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); #endif #ifdef USE_WIN32_CONSOLE AllocConsole(); freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); #endif #ifdef _CONSOLE CCLOG("\nLua2D Parameter : "); for (int index = 0; index < argc; index++) { #ifdef _UNICODE char szBuf[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, argv[index], -1, szBuf, sizeof(szBuf), NULL, NULL); CCLOG("%s ", szBuf); #else CCLOG("%s ", argv[index]); #endif } CCLOG("\n"); #else//_CONSOLE #ifdef _UNICODE char szBuf[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, lpCmdLine, -1, szBuf, sizeof(szBuf), NULL, NULL); CCLOG("\nLua2D Parameter : %s\n", szBuf); #else CCLOG("\nLua2D Parameter : %s\n", lpCmdLine); #endif #endif//_CONSOLE // create the application instance AppDelegate app; #ifdef _CONSOLE parseOptions(&app, argc, argv); #else//_CONSOLE if (lpCmdLine[0] != _T('\0')) { int argc; LPTSTR* argv = CommandLineToArgvW(lpCmdLine, &argc); parseOptions(&app, argc, argv); } #endif//_CONSOLE CCEGLView* eglView = CCEGLView::sharedOpenGLView(); eglView->setFrameSize(1280, 768); int ret = CCApplication::sharedApplication()->run(); #ifdef USE_WIN32_CONSOLE FreeConsole(); #endif return ret; } static void parseOptions(AppDelegate* app, int argc, TCHAR* argv[]) { char szBuf[MAX_PATH]; int opt; while ((opt = getopt(argc, argv, _T("e:"))) != -1) { switch (opt) { case _T('e'): #ifdef _UNICODE WideCharToMultiByte(CP_ACP, 0, optarg, -1, szBuf, sizeof(szBuf), NULL, NULL); app->m_aLuaCmd.push_back(szBuf); #else app->m_aLuaCmd.push_back(optarg); #endif break; } } while (optind < argc) { #ifdef _UNICODE WideCharToMultiByte(CP_ACP, 0, argv[optind++], -1, szBuf, sizeof(szBuf), NULL, NULL); app->m_aLuaScript.push_back(szBuf); #else app->m_aLuaScript.push_back(argv[optind++]); #endif } }
22.823009
88
0.630089
pontelua
60e5e83d6c470fc4136506c0af368163104b0d87
1,327
cpp
C++
CSES/Graph Algorithms/Shortest Routes I.cpp
s166harth/CC
b6c0fe58f03633fe2787a567a16909f1b2966e7b
[ "MIT" ]
406
2020-05-28T13:35:08.000Z
2022-03-31T17:23:26.000Z
CSES/Graph Algorithms/Shortest Routes I.cpp
shakeeb-droids/CC
2f49fcb52d748804aee9fc7f26abb3150bec69e5
[ "MIT" ]
3
2021-01-01T17:50:34.000Z
2021-10-02T10:02:27.000Z
CSES/Graph Algorithms/Shortest Routes I.cpp
shakeeb-droids/CC
2f49fcb52d748804aee9fc7f26abb3150bec69e5
[ "MIT" ]
108
2020-07-21T13:02:33.000Z
2022-03-28T22:46:49.000Z
/** 🍪 the_hyp0cr1t3 🍪 18.05.2021 00:21:28 **/ #ifdef W #include <k_II.h> #else #include <bits/stdc++.h> using namespace std; #endif #define pb emplace_back #define all(x) x.begin(), x.end() #define sz(x) static_cast<int32_t>(x.size()) auto chmax = [](auto& A, auto&& B) { return B > A? A = B, true : false; }; auto chmin = [](auto& A, auto&& B) { return B < A? A = B, true : false; }; const int64_t k_II = 2e18; const int INF = 2e9, MOD = 1e9+7; const int N = 2e5 + 5; int main() { cin.tie(nullptr)->sync_with_stdio(false); int i, n, m; cin >> n >> m; vector<vector<pair<int, int>>> g(n); for(i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; g[--u].pb(--v, w); } struct state { int v; int64_t dist; state(int v, int64_t dist): v(v), dist(dist) {} bool operator<(const state& o) const { return dist > o.dist; } }; vector<int64_t> d(n, k_II); priority_queue<state> pq; pq.emplace(0, d[0] = 0); while(!pq.empty()) { state top = pq.top(); pq.pop(); if(top.dist > d[top.v]) continue; for(auto& [to, w]: g[top.v]) if(chmin(d[to], top.dist + w)) pq.emplace(to, d[to]); } for(i = 0; i < n; i++) cout << d[i] << " \n"[i == n-1]; } // ~W
25.519231
74
0.497362
s166harth
60e6638b0e4872e946e98a709ecc923cb59bdb2d
236
cpp
C++
raygame/MasterTile.cpp
DynashEtvala/CodeDesignAndDataStructures
c516f9e1a6bde3e41f716114bb74da993f8cbfd8
[ "MIT" ]
null
null
null
raygame/MasterTile.cpp
DynashEtvala/CodeDesignAndDataStructures
c516f9e1a6bde3e41f716114bb74da993f8cbfd8
[ "MIT" ]
null
null
null
raygame/MasterTile.cpp
DynashEtvala/CodeDesignAndDataStructures
c516f9e1a6bde3e41f716114bb74da993f8cbfd8
[ "MIT" ]
null
null
null
#include "MasterTile.h" MasterTile::MasterTile() : Tile() { masterTile = true; } MasterTile::~MasterTile() {} void MasterTile::CycleTexture() { currTex++; if (currTex >= 4) { currTex = 0; } Background = textures[currTex]; }
11.238095
33
0.644068
DynashEtvala
60e8562d2d6b0db73ffa640991a9333f25d2df03
10,152
cc
C++
src/Physics/Physics.cc
as1m0n/spheral
4d72822f56aca76d70724c543d389d15ff6ca48e
[ "BSD-Source-Code", "BSD-3-Clause-LBNL", "FSFAP" ]
null
null
null
src/Physics/Physics.cc
as1m0n/spheral
4d72822f56aca76d70724c543d389d15ff6ca48e
[ "BSD-Source-Code", "BSD-3-Clause-LBNL", "FSFAP" ]
null
null
null
src/Physics/Physics.cc
as1m0n/spheral
4d72822f56aca76d70724c543d389d15ff6ca48e
[ "BSD-Source-Code", "BSD-3-Clause-LBNL", "FSFAP" ]
null
null
null
//---------------------------------Spheral++----------------------------------// // Physics -- The topmost abstract base class for all physics packages in // Spheral++. Physics defines the methods generic to all physics classes, // but leaves specialized interfaces for particular types of physics (radiative vs. // hydro, etc.) to a descendent interface class, Physics. //----------------------------------------------------------------------------// #include "Physics.hh" #include "Boundary/Boundary.hh" using std::vector; using std::cout; using std::cerr; using std::endl; using std::min; using std::max; using std::abs; namespace Spheral { //------------------------------------------------------------------------------ // Default constructor //------------------------------------------------------------------------------ template<typename Dimension> Physics<Dimension>:: Physics(): mBoundaryConditions() { } //------------------------------------------------------------------------------ // Destructor //------------------------------------------------------------------------------ template<typename Dimension> Physics<Dimension>:: ~Physics() { } //------------------------------------------------------------------------------ // Add a Boundary condition to the end of the current boundary list. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: appendBoundary(Boundary<Dimension>& boundary) { // if (!haveBoundary(boundary)) { mBoundaryConditions.push_back(&boundary); // } else { // cerr << "Warning: attempt to append Boundary condition " << &boundary // << "to Physics " << this << " which already has it." << endl; // } } //------------------------------------------------------------------------------ // Add a Boundary condition to the beginning of the current boundary list. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: prependBoundary(Boundary<Dimension>& boundary) { // if (!haveBoundary(boundary)) { mBoundaryConditions.insert(mBoundaryConditions.begin(), &boundary); // } else { // cerr << "Warning: attempt to prepend Boundary condition " << &boundary // << "to Physics " << this << " which already has it." << endl; // } } //------------------------------------------------------------------------------ // Clear (erase) the boundary condition list. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: clearBoundaries() { mBoundaryConditions = vector<Boundary<Dimension>*>(); } //------------------------------------------------------------------------------ // Test if the given Boundary condition is listed in the physics package. //------------------------------------------------------------------------------ template<typename Dimension> bool Physics<Dimension>:: haveBoundary(const Boundary<Dimension>& boundary) const { return std::count(mBoundaryConditions.begin(), mBoundaryConditions.end(), &boundary) > 0; } //------------------------------------------------------------------------------ // Provide a default no-op ghost boundary method. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: applyGhostBoundaries(State<Dimension>& /*state*/, StateDerivatives<Dimension>& /*derivs*/) { } //------------------------------------------------------------------------------ // Provide a default no-op enforce boundary method. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: enforceBoundaries(State<Dimension>& /*state*/, StateDerivatives<Dimension>& /*derivs*/) { } //------------------------------------------------------------------------------ // Provide a default no-op problem startup initialization method. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: initializeProblemStartup(DataBase<Dimension>& /*dataBase*/) { } //------------------------------------------------------------------------------ // Provide a default no-op pre-step initialization method. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: preStepInitialize(const DataBase<Dimension>& /*dataBase*/, State<Dimension>& /*state*/, StateDerivatives<Dimension>& /*derivs*/) { } //------------------------------------------------------------------------------ // Provide a default no-op initialization method. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: initialize(const typename Dimension::Scalar /*time*/, const typename Dimension::Scalar /*dt*/, const DataBase<Dimension>& /*dataBase*/, State<Dimension>& /*state*/, StateDerivatives<Dimension>& /*derivs*/) { } //------------------------------------------------------------------------------ // Provide a default no-op finalization method. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: finalize(const typename Dimension::Scalar /*time*/, const typename Dimension::Scalar /*dt*/, DataBase<Dimension>& /*dataBase*/, State<Dimension>& /*state*/, StateDerivatives<Dimension>& /*derivs*/) { } //------------------------------------------------------------------------------ // Provide a default no-op finalizeDerivatives method. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: finalizeDerivatives(const typename Dimension::Scalar /*time*/, const typename Dimension::Scalar /*dt*/, const DataBase<Dimension>& /*dataBase*/, const State<Dimension>& /*state*/, StateDerivatives<Dimension>& /*derivs*/) const { } //------------------------------------------------------------------------------ // Provide a default no-op postStateUpdate method. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: postStateUpdate(const Scalar /*time*/, const Scalar /*dt*/, const DataBase<Dimension>& /*dataBase*/, State<Dimension>& /*state*/, StateDerivatives<Dimension>& /*derivatives*/) { } //------------------------------------------------------------------------------ // By default assume connectivity needs to be constructed. //------------------------------------------------------------------------------ template<typename Dimension> bool Physics<Dimension>:: requireConnectivity() const { return true; } //------------------------------------------------------------------------------ // By default assume ghost connectivity is not needed. //------------------------------------------------------------------------------ template<typename Dimension> bool Physics<Dimension>:: requireGhostConnectivity() const { return false; } //------------------------------------------------------------------------------ // By default assume overlap connectivity is not needed. //------------------------------------------------------------------------------ template<typename Dimension> bool Physics<Dimension>:: requireOverlapConnectivity() const { return false; } //------------------------------------------------------------------------------ // By default assume reproducing kernels are not needed. //------------------------------------------------------------------------------ template<typename Dimension> std::set<RKOrder> Physics<Dimension>:: requireReproducingKernels() const { return std::set<RKOrder>(); } //------------------------------------------------------------------------------ // By default assume reproducing kernels second derivatives are not needed. //------------------------------------------------------------------------------ template<typename Dimension> bool Physics<Dimension>:: requireReproducingKernelHessian() const { return false; } //------------------------------------------------------------------------------ // By default assume reproducing kernel correction in finalize is not needed. //------------------------------------------------------------------------------ template<typename Dimension> bool Physics<Dimension>:: updateReproducingKernelsInFinalize() const { return false; } //------------------------------------------------------------------------------ // Provide a default method for the extraEnergy method, which will return 0.0 // for classes that don't have their own energy. //------------------------------------------------------------------------------ template<typename Dimension> typename Dimension::Scalar Physics<Dimension>:: extraEnergy() const { return 0.0; } //------------------------------------------------------------------------------ // Provide a default method for the extraMomentum method, which will return // the zero vector for classes that don't have their own momentum. //------------------------------------------------------------------------------ template<typename Dimension> typename Dimension::Vector Physics<Dimension>:: extraMomentum() const { return typename Dimension::Vector(); } //------------------------------------------------------------------------------ // Defaul noop for extra viz state. //------------------------------------------------------------------------------ template<typename Dimension> void Physics<Dimension>:: registerAdditionalVisualizationState(DataBase<Dimension>& /*dataBase*/, State<Dimension>& /*state*/) { } }
37.323529
91
0.438042
as1m0n
60ea0654051b3f54427e8dfcd596036a6e480f80
4,508
hpp
C++
libcaf_core/caf/mailbox_element.hpp
dcode/actor-framework
47ebe211f07d31725a3910ed966db1c31192d984
[ "BSL-1.0", "BSD-3-Clause" ]
null
null
null
libcaf_core/caf/mailbox_element.hpp
dcode/actor-framework
47ebe211f07d31725a3910ed966db1c31192d984
[ "BSL-1.0", "BSD-3-Clause" ]
null
null
null
libcaf_core/caf/mailbox_element.hpp
dcode/actor-framework
47ebe211f07d31725a3910ed966db1c31192d984
[ "BSL-1.0", "BSD-3-Clause" ]
3
2020-05-21T20:54:58.000Z
2020-06-17T13:44:13.000Z
/****************************************************************************** * ____ _ _____ * * / ___| / \ | ___| C++ * * | | / _ \ | |_ Actor * * | |___ / ___ \| _| Framework * * \____/_/ \_|_| * * * * Copyright 2011-2018 Dominik Charousset * * * * Distributed under the terms and conditions of the BSD 3-Clause License or * * (at your option) under the terms and conditions of the Boost Software * * License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. * * * * If you did not receive a copy of the license files, see * * http://opensource.org/licenses/BSD-3-Clause and * * http://www.boost.org/LICENSE_1_0.txt. * ******************************************************************************/ #pragma once #include <cstddef> #include <memory> #include "caf/actor_control_block.hpp" #include "caf/detail/core_export.hpp" #include "caf/intrusive/singly_linked.hpp" #include "caf/message.hpp" #include "caf/message_id.hpp" #include "caf/meta/omittable_if_empty.hpp" #include "caf/meta/type_name.hpp" #include "caf/tracing_data.hpp" namespace caf { class CAF_CORE_EXPORT mailbox_element : public intrusive::singly_linked<mailbox_element> { public: using forwarding_stack = std::vector<strong_actor_ptr>; /// Source of this message and receiver of the final response. strong_actor_ptr sender; /// Denotes whether this an asynchronous message or a request. message_id mid; /// `stages.back()` is the next actor in the forwarding chain, /// if this is empty then the original sender receives the response. forwarding_stack stages; #ifdef CAF_ENABLE_ACTOR_PROFILER /// Optional tracing information. This field is unused by default, but an /// @ref actor_profiler can make use of it to inject application-specific /// instrumentation. tracing_data_ptr tracing_id; #endif // CAF_ENABLE_ACTOR_PROFILER /// Stores the payload. message payload; mailbox_element() = default; mailbox_element(strong_actor_ptr sender, message_id mid, forwarding_stack stages, message payload); bool is_high_priority() const { return mid.category() == message_id::urgent_message_category; } mailbox_element(mailbox_element&&) = delete; mailbox_element(const mailbox_element&) = delete; mailbox_element& operator=(mailbox_element&&) = delete; mailbox_element& operator=(const mailbox_element&) = delete; // -- backward compatibility ------------------------------------------------- message& content() noexcept { return payload; } const message& content() const noexcept { return payload; } }; /// @relates mailbox_element template <class Inspector> typename Inspector::result_type inspect(Inspector& f, mailbox_element& x) { return f(meta::type_name("mailbox_element"), x.sender, x.mid, meta::omittable_if_empty(), x.stages, #ifdef CAF_ENABLE_ACTOR_PROFILER x.tracing_id, #endif // CAF_ENABLE_ACTOR_PROFILER x.payload); } /// @relates mailbox_element using mailbox_element_ptr = std::unique_ptr<mailbox_element>; /// @relates mailbox_element CAF_CORE_EXPORT mailbox_element_ptr make_mailbox_element(strong_actor_ptr sender, message_id id, mailbox_element::forwarding_stack stages, message content); /// @relates mailbox_element template <class T, class... Ts> std::enable_if_t<!std::is_same<typename std::decay<T>::type, message>::value || (sizeof...(Ts) > 0), mailbox_element_ptr> make_mailbox_element(strong_actor_ptr sender, message_id id, mailbox_element::forwarding_stack stages, T&& x, Ts&&... xs) { return make_mailbox_element(std::move(sender), id, std::move(stages), make_message(std::forward<T>(x), std::forward<Ts>(xs)...)); } } // namespace caf
38.20339
80
0.564552
dcode
60ef26e094e5ace5b40479a13a644efb75b4fa48
591
cpp
C++
AceptaElReto/370_La13-14.cpp
OscarCaroNavarro/competitive-programming
5ff52544119cbbfd35d4129fbfd14647808a8a44
[ "Apache-2.0" ]
2
2019-09-14T08:56:08.000Z
2019-10-22T07:26:08.000Z
AceptaElReto/370_La13-14.cpp
OscarCaroNavarro/competitive-programming
5ff52544119cbbfd35d4129fbfd14647808a8a44
[ "Apache-2.0" ]
null
null
null
AceptaElReto/370_La13-14.cpp
OscarCaroNavarro/competitive-programming
5ff52544119cbbfd35d4129fbfd14647808a8a44
[ "Apache-2.0" ]
null
null
null
#include <iostream> using namespace std; bool isPrime(int num); void print(bool is); int main() { short int n; unsigned long long int num1, num2; char aux; bool is; cin >> n; for (int i = 0; i < n; i++){ cin >> num1; cin >> aux; cin >> num2; if ((num2 - num1) == 1){ is = isPrime(num1); print (is); } else if ((num1 - num2) == 1 ) { is = isPrime(num2); print (is); } else { print(false); } } return 0; } bool isPrime(int num) { return ((num % 2) == 0); } void print(bool is) { if(is) { cout << "SI" << endl; } else { cout << "NO" << endl; } }
14.775
35
0.529611
OscarCaroNavarro
60f204f575eec2a7233de6d19ff09fb8d0906495
1,409
hpp
C++
components/scream/src/physics/shoc/shoc_pblintd_surf_temp_impl.hpp
ambrad/scream
52da60f65e870b8a3994bdbf4a6022fdcac7cab5
[ "BSD-3-Clause" ]
22
2018-12-12T17:44:55.000Z
2022-03-11T03:47:38.000Z
components/scream/src/physics/shoc/shoc_pblintd_surf_temp_impl.hpp
ambrad/scream
52da60f65e870b8a3994bdbf4a6022fdcac7cab5
[ "BSD-3-Clause" ]
1,440
2018-07-10T16:49:55.000Z
2022-03-31T22:41:25.000Z
components/scream/src/physics/shoc/shoc_pblintd_surf_temp_impl.hpp
ambrad/scream
52da60f65e870b8a3994bdbf4a6022fdcac7cab5
[ "BSD-3-Clause" ]
24
2018-11-12T15:43:53.000Z
2022-03-30T18:10:52.000Z
#ifndef SHOC_PBLINTD_SURF_TEMP_IMPL_HPP #define SHOC_PBLINTD_SURF_TEMP_IMPL_HPP #include "shoc_functions.hpp" // for ETI only but harmless for GPU namespace scream { namespace shoc { /* * Implementation of shoc pblintd_surf_temp. Clients should NOT * #include this file, but include shoc_functions.hpp instead. */ template<typename S, typename D> KOKKOS_FUNCTION void Functions<S,D>::pblintd_surf_temp(const Int& nlev, const Int& nlevi, const Int& npbl, const uview_1d<const Spack>& z, const Scalar& ustar, const Scalar& obklen, const Scalar& kbfs, const uview_1d<const Spack>& thv, Scalar& tlv, Scalar& pblh, bool& check, const uview_1d<Spack>& rino) { // const parameter for Diagnosis of PBL depth const Scalar fak = 8.5; const Scalar betam = 15.0; const Scalar sffrac= 0.1; const Scalar binm = betam*sffrac; // Scalarize views for single entry access const auto s_z = ekat::scalarize(z); const auto s_thv = ekat::scalarize(thv); const auto s_rino = ekat::scalarize(rino); // Estimate an effective surface temperature to account for surface // fluctuations if (check) { pblh = s_z(nlevi-npbl-1); } check = (kbfs > 0); tlv = s_thv(nlev-1); if (check) { s_rino(nlev-1) = 0; const Scalar phiminv = std::cbrt(1-binm*pblh/obklen); tlv += kbfs*fak/(ustar*phiminv); } } } // namespace shoc } // namespace scream #endif
27.096154
90
0.695529
ambrad
60f2fa07608c4b7a18836d990e486c7067a8d3cf
11,584
cpp
C++
src/mongo/db/ops/modifier_set.cpp
krareT/mongo
8776cef330c6de839d80ceec5bd2a63f3c411c6e
[ "Apache-2.0" ]
null
null
null
src/mongo/db/ops/modifier_set.cpp
krareT/mongo
8776cef330c6de839d80ceec5bd2a63f3c411c6e
[ "Apache-2.0" ]
null
null
null
src/mongo/db/ops/modifier_set.cpp
krareT/mongo
8776cef330c6de839d80ceec5bd2a63f3c411c6e
[ "Apache-2.0" ]
5
2020-12-16T13:31:55.000Z
2021-01-17T07:39:30.000Z
/** * Copyright (C) 2013 10gen Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * As a special exception, the copyright holders give permission to link the * code of portions of this program with the OpenSSL library under certain * conditions as described in each individual source file and distribute * linked combinations including the program with the OpenSSL library. You * must comply with the GNU Affero General Public License in all respects for * all of the code used other than as permitted herein. If you modify file(s) * with this exception, you may extend this exception to your version of the * file(s), but you are not obligated to do so. If you do not wish to do so, * delete this exception statement from your version. If you delete this * exception statement from all source files in the program, then also delete * it in the license file. */ #include "mongo/db/ops/modifier_set.h" #include "mongo/base/error_codes.h" #include "mongo/bson/mutable/document.h" #include "mongo/db/update/field_checker.h" #include "mongo/db/update/log_builder.h" #include "mongo/db/update/path_support.h" #include "mongo/util/mongoutils/str.h" namespace mongo { namespace str = mongoutils::str; struct ModifierSet::PreparedState { PreparedState(mutablebson::Document* targetDoc) : doc(*targetDoc), idxFound(0), elemFound(doc.end()), noOp(false), elemIsBlocking(false) {} // Document that is going to be changed. mutablebson::Document& doc; // Index in _fieldRef for which an Element exist in the document. size_t idxFound; // Element corresponding to _fieldRef[0.._idxFound]. mutablebson::Element elemFound; // This $set is a no-op? bool noOp; // The element we find during a replication operation that blocks our update path bool elemIsBlocking; }; ModifierSet::ModifierSet(ModifierSet::ModifierSetMode mode) : _fieldRef(), _posDollar(0), _setMode(mode), _val() {} ModifierSet::~ModifierSet() {} Status ModifierSet::init(const BSONElement& modExpr, const Options& opts, bool* positional) { // // field name analysis // // Break down the field name into its 'dotted' components (aka parts) and check that // the field is fit for updates _fieldRef.parse(modExpr.fieldName()); Status status = fieldchecker::isUpdatable(_fieldRef); if (!status.isOK()) { return status; } // If a $-positional operator was used, get the index in which it occurred // and ensure only one occurrence. size_t foundCount; bool foundDollar = fieldchecker::isPositional(_fieldRef, &_posDollar, &foundCount); if (positional) *positional = foundDollar; if (foundDollar && foundCount > 1) { return Status(ErrorCodes::BadValue, str::stream() << "Too many positional (i.e. '$') elements found in path '" << _fieldRef.dottedField() << "'"); } // // value analysis // if (!modExpr.ok()) return Status(ErrorCodes::BadValue, "cannot $set an empty value"); _val = modExpr; _fromOplogApplication = opts.fromOplogApplication; return Status::OK(); } Status ModifierSet::prepare(mutablebson::Element root, StringData matchedField, ExecInfo* execInfo) { _preparedState.reset(new PreparedState(&root.getDocument())); // If we have a $-positional field, it is time to bind it to an actual field part. if (_posDollar) { if (matchedField.empty()) { return Status(ErrorCodes::BadValue, str::stream() << "The positional operator did not find the match " "needed from the query. Unexpanded update: " << _fieldRef.dottedField()); } _fieldRef.setPart(_posDollar, matchedField); } // Locate the field name in 'root'. Note that we may not have all the parts in the path // in the doc -- which is fine. Our goal now is merely to reason about whether this mod // apply is a noOp or whether is can be in place. The remainin path, if missing, will // be created during the apply. Status status = pathsupport::findLongestPrefix( _fieldRef, root, &_preparedState->idxFound, &_preparedState->elemFound); // FindLongestPrefix may say the path does not exist at all, which is fine here, or // that the path was not viable or otherwise wrong, in which case, the mod cannot // proceed. if (status.code() == ErrorCodes::NonExistentPath) { _preparedState->elemFound = root.getDocument().end(); } else if (_fromOplogApplication && status.code() == ErrorCodes::PathNotViable) { // If we are applying an oplog entry and it is an invalid path, then push on indicating that // we had a blocking element, which we stopped at _preparedState->elemIsBlocking = true; } else if (!status.isOK()) { return status; } if (_setMode == SET_ON_INSERT) { execInfo->context = ModifierInterface::ExecInfo::INSERT_CONTEXT; } // We register interest in the field name. The driver needs this info to sort out if // there is any conflict among mods. execInfo->fieldRef[0] = &_fieldRef; // // in-place and no-op logic // // If the field path is not fully present, then this mod cannot be in place, nor is it a noOp. if (!_preparedState->elemFound.ok() || _preparedState->idxFound < (_fieldRef.numParts() - 1)) { return Status::OK(); } // If the value being $set is the same as the one already in the doc, than this is a noOp. We // use binary equality to compare so that any change to the document is considered, unlike using // a comparison that winds up in woCompare (see SERVER-16801). In the case where elemFound // doesn't have a serialized representation, we just declare the operation to not be a // no-op. This is potentially a missed optimization, but is unlikely to cause much pain since in // the normal update workflow we only admit one modification on any path from a leaf to the // document root. In that domain, hasValue will always be true. We may encounter a // non-serialized elemFound in the case where our base document is the result of calling // populateDocumentWithQueryFields, so this could cause us to do slightly more work than // strictly necessary in the case where an update (w upsert:true) becomes an insert. if (_preparedState->elemFound.ok() && _preparedState->idxFound == (_fieldRef.numParts() - 1) && _preparedState->elemFound.hasValue() && _preparedState->elemFound.getValue().binaryEqualValues(_val)) { execInfo->noOp = _preparedState->noOp = true; } return Status::OK(); } Status ModifierSet::apply() const { dassert(!_preparedState->noOp); const bool destExists = _preparedState->elemFound.ok() && _preparedState->idxFound == (_fieldRef.numParts() - 1); // If there's no need to create any further field part, the $set is simply a value // assignment. if (destExists) { return _preparedState->elemFound.setValueBSONElement(_val); } // // Complete document path logic // // Creates the final element that's going to be $set in 'doc'. mutablebson::Document& doc = _preparedState->doc; StringData lastPart = _fieldRef.getPart(_fieldRef.numParts() - 1); mutablebson::Element elemToSet = doc.makeElementWithNewFieldName(lastPart, _val); if (!elemToSet.ok()) { return Status(ErrorCodes::InternalError, "can't create new element"); } // Now, we can be in two cases here, as far as attaching the element being set goes: // (a) none of the parts in the element's path exist, or (b) some parts of the path // exist but not all. if (!_preparedState->elemFound.ok()) { _preparedState->elemFound = doc.root(); _preparedState->idxFound = 0; } else { _preparedState->idxFound++; } // Remove the blocking element, if we are from replication applier. See comment below. if (_fromOplogApplication && !destExists && _preparedState->elemFound.ok() && _preparedState->elemIsBlocking && (!(_preparedState->elemFound.isType(Array)) || !(_preparedState->elemFound.isType(Object)))) { /** * With replication we want to be able to remove blocking elements for $set (only). * The reason they are blocking elements is that they are not embedded documents * (objects) nor an array (a special type of an embedded doc) and we cannot * add children to them (because the $set path requires adding children past * the blocking element). * * Imagine that we started with this: * {_id:1, a:1} + {$set : {"a.b.c" : 1}} -> {_id:1, a: {b: {c:1}}} * Above we found that element (a:1) is blocking at position 1. We now will replace * it with an empty object so the normal logic below can be * applied from the root (in this example case). * * Here is an array example: * {_id:1, a:[1, 2]} + {$set : {"a.0.c" : 1}} -> {_id:1, a: [ {c:1}, 2]} * The blocking element is "a.0" since it is a number, non-object, and we must * then replace it with an empty object so we can add c:1 to that empty object */ mutablebson::Element blockingElem = _preparedState->elemFound; BSONObj newObj; // Replace blocking non-object with an empty object Status status = blockingElem.setValueObject(newObj); if (!status.isOK()) { return status; } } // createPathAt() will complete the path and attach 'elemToSet' at the end of it. return pathsupport::createPathAt( _fieldRef, _preparedState->idxFound, _preparedState->elemFound, elemToSet) .getStatus(); } Status ModifierSet::log(LogBuilder* logBuilder) const { // We'd like to create an entry such as {$set: {<fieldname>: <value>}} under 'logRoot'. // We start by creating the {$set: ...} Element. mutablebson::Document& doc = logBuilder->getDocument(); // Create the {<fieldname>: <value>} Element. Note that we log the mod with a // dotted field, if it was applied over a dotted field. The rationale is that the // secondary may be in a different state than the primary and thus make different // decisions about creating the intermediate path in _fieldRef or not. mutablebson::Element logElement = doc.makeElementWithNewFieldName(_fieldRef.dottedField(), _val); if (!logElement.ok()) { return Status(ErrorCodes::InternalError, "cannot create details for $set mod"); } return logBuilder->addToSets(logElement); } } // namespace mongo
42.745387
100
0.65884
krareT
60f31026702865a07fed6025c9209fbc465f8f80
4,524
cpp
C++
5/Code/ThirdParty/SDL2/src/thread/stdcpp/SDL_systhread.cpp
Zakhar-V/Prototypes
413a7ce9fdb2a6f3ba97a041f798c71351efc855
[ "MIT" ]
1
2021-01-10T07:29:05.000Z
2021-01-10T07:29:05.000Z
Code/External/SDL2/src/thread/stdcpp/SDL_systhread.cpp
Zakhar-V/NanoEngine
01896caeae2e5505a8a5f303b07e84694c201d6d
[ "MIT" ]
null
null
null
Code/External/SDL2/src/thread/stdcpp/SDL_systhread.cpp
Zakhar-V/NanoEngine
01896caeae2e5505a8a5f303b07e84694c201d6d
[ "MIT" ]
null
null
null
/* Simple DirectMedia Layer Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" /* Thread management routines for SDL */ extern "C" { #include "SDL_thread.h" #include "../SDL_thread_c.h" #include "../SDL_systhread.h" #include "SDL_log.h" } #include <mutex> #include <thread> #include <system_error> #if defined(__WINRT__) || defined(__WIN32__) #include <Windows.h> #endif static void RunThread(void *args) { SDL_RunThread(args); } extern "C" int SDL_SYS_CreateThread(SDL_Thread * thread, void *args) { try { std::thread cpp_thread(RunThread, args); thread->handle = (void *) new std::thread(std::move(cpp_thread)); return 0; } catch (std::system_error & ex) { SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what()); return -1; } catch (std::bad_alloc &) { SDL_OutOfMemory(); return -1; } } extern "C" void SDL_SYS_SetupThread(const char *name) { // Make sure a thread ID gets assigned ASAP, for debugging purposes: SDL_ThreadID(); return; } extern "C" SDL_threadID SDL_ThreadID(void) { #if defined(__WINRT__) || defined(__WIN32__) return GetCurrentThreadId(); #else // HACK: Mimick a thread ID, if one isn't otherwise available. static thread_local SDL_threadID current_thread_id = 0; static SDL_threadID next_thread_id = 1; static std::mutex next_thread_id_mutex; if (current_thread_id == 0) { std::lock_guard<std::mutex> lock(next_thread_id_mutex); current_thread_id = next_thread_id; ++next_thread_id; } return current_thread_id; #endif } extern "C" int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { // Thread priorities do not look to be settable via C++11's thread // interface, at least as of this writing (Nov 2012). std::thread does // provide access to the OS' native handle, however, and some form of // priority-setting could, in theory, be done through this interface. // // WinRT: UPDATE (Aug 20, 2013): thread priorities cannot be changed // on WinRT, at least not for any thread that's already been created. // WinRT threads appear to be based off of the WinRT class, // ThreadPool, more info on which can be found at: // http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool.aspx // // For compatibility sake, 0 will be returned here. return (0); } extern "C" void SDL_SYS_WaitThread(SDL_Thread * thread) { if ( ! thread) { return; } try { std::thread * cpp_thread = (std::thread *) thread->handle; if (cpp_thread->joinable()) { cpp_thread->join(); } } catch (std::system_error &) { // An error occurred when joining the thread. SDL_WaitThread does not, // however, seem to provide a means to report errors to its callers // though! } } extern "C" void SDL_SYS_DetachThread(SDL_Thread * thread) { if ( ! thread) { return; } try { std::thread * cpp_thread = (std::thread *) thread->handle; if (cpp_thread->joinable()) { cpp_thread->detach(); } } catch (std::system_error &) { // An error occurred when detaching the thread. SDL_DetachThread does not, // however, seem to provide a means to report errors to its callers // though! } } extern "C" SDL_TLSData * SDL_SYS_GetTLSData() { return SDL_Generic_GetTLSData(); } extern "C" int SDL_SYS_SetTLSData(SDL_TLSData *data) { return SDL_Generic_SetTLSData(data); } /* vi: set ts=4 sw=4 expandtab: */
26.928571
100
0.673298
Zakhar-V
60f49327fa240593f58cf1574e872c3424d315f0
55,916
cpp
C++
src/catalog_po.cpp
jhertel/poed
679057f8a9e051e482cbfa9caf2bfb37f8a4b0c2
[ "MIT" ]
null
null
null
src/catalog_po.cpp
jhertel/poed
679057f8a9e051e482cbfa9caf2bfb37f8a4b0c2
[ "MIT" ]
null
null
null
src/catalog_po.cpp
jhertel/poed
679057f8a9e051e482cbfa9caf2bfb37f8a4b0c2
[ "MIT" ]
null
null
null
/* * This file is part of Poedit (https://poedit.net) * * Copyright (C) 1999-2020 Vaclav Slavik * * 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. * */ #include "catalog_po.h" #include "configuration.h" #include "errors.h" #include "extractors/extractor.h" #include "gexecute.h" #include "qa_checks.h" #include "str_helpers.h" #include "utility.h" #include "version.h" #include "language.h" #include <stdio.h> #include <wx/utils.h> #include <wx/tokenzr.h> #include <wx/log.h> #include <wx/intl.h> #include <wx/datetime.h> #include <wx/config.h> #include <wx/textfile.h> #include <wx/stdpaths.h> #include <wx/strconv.h> #include <wx/memtext.h> #include <wx/filename.h> #include <set> #include <algorithm> #ifdef __WXOSX__ #import <Foundation/Foundation.h> #endif // TODO: split into different file #if wxUSE_GUI #include <wx/msgdlg.h> #endif // ---------------------------------------------------------------------- // Textfile processing utilities: // ---------------------------------------------------------------------- namespace { // If input begins with pattern, fill output with end of input (without // pattern; strips trailing spaces) and return true. Return false otherwise // and don't touch output. Is permissive about whitespace in the input: // a space (' ') in pattern will match any number of any whitespace characters // on that position in input. bool ReadParam(const wxString& input, const wxString& pattern, wxString& output) { if (input.size() < pattern.size()) return false; unsigned in_pos = 0; unsigned pat_pos = 0; while (pat_pos < pattern.size() && in_pos < input.size()) { const wxChar pat = pattern[pat_pos++]; if (pat == _T(' ')) { if (!wxIsspace(input[in_pos++])) return false; while (wxIsspace(input[in_pos])) { in_pos++; if (in_pos == input.size()) return false; } } else { if (input[in_pos++] != pat) return false; } } if (pat_pos < pattern.size()) // pattern not fully matched return false; output = input.Mid(in_pos); output.Trim(true); // trailing whitespace return true; } // Checks if the file was loaded correctly, i.e. that non-empty lines // ended up non-empty in memory, after doing charset conversion in // wxTextFile. This detects for example files that claim they are in UTF-8 // while in fact they are not. bool VerifyFileCharset(const wxTextFile& f, const wxString& filename, const wxString& charset) { wxTextFile f2; if (!f2.Open(filename, wxConvISO8859_1)) return false; if (f.GetLineCount() != f2.GetLineCount()) { int linesCount = (int)f2.GetLineCount() - (int)f.GetLineCount(); wxLogError(wxPLURAL(L"%i line of file “%s” was not loaded correctly.", L"%i lines of file “%s” were not loaded correctly.", linesCount), linesCount, filename.c_str()); return false; } bool ok = true; size_t cnt = f.GetLineCount(); for (size_t i = 0; i < cnt; i++) { if (f[i].empty() && !f2[i].empty()) // wxMBConv conversion failed { wxLogError( _(L"Line %d of file “%s” is corrupted (not valid %s data)."), int(i), filename.c_str(), charset.c_str()); ok = false; } } return ok; } wxTextFileType GetFileCRLFFormat(wxTextFile& po_file) { wxLogNull null; auto crlf = po_file.GuessType(); // Discard any unsupported setting. In particular, we ignore "Mac" // line endings, because the ancient OS 9 systems aren't used anymore, // OSX uses Unix ending *and* "Mac" endings break gettext tools. So if // we encounter a catalog with "Mac" line endings, we silently convert // it into Unix endings (i.e. the modern Mac). if (crlf == wxTextFileType_Mac) crlf = wxTextFileType_Unix; if (crlf != wxTextFileType_Dos && crlf != wxTextFileType_Unix) crlf = wxTextFileType_None; return crlf; } wxTextFileType GetDesiredCRLFFormat(wxTextFileType existingCRLF) { if (existingCRLF != wxTextFileType_None && wxConfigBase::Get()->ReadBool("keep_crlf", true)) { return existingCRLF; } else { wxString format = wxConfigBase::Get()->Read("crlf_format", "unix"); if (format == "win") return wxTextFileType_Dos; else /* "unix" or obsolete settings */ return wxTextFileType_Unix; } } } // anonymous namespace // ---------------------------------------------------------------------- // Parsers // ---------------------------------------------------------------------- bool POCatalogParser::Parse() { static const wxString prefix_flags(wxS("#, ")); static const wxString prefix_autocomments(wxS("#. ")); static const wxString prefix_autocomments2(wxS("#.")); // account for empty auto comments static const wxString prefix_references(wxS("#: ")); static const wxString prefix_prev_msgid(wxS("#| ")); static const wxString prefix_msgctxt(wxS("msgctxt \"")); static const wxString prefix_msgid(wxS("msgid \"")); static const wxString prefix_msgid_plural(wxS("msgid_plural \"")); static const wxString prefix_msgstr(wxS("msgstr \"")); static const wxString prefix_msgstr_plural(wxS("msgstr[")); static const wxString prefix_deleted(wxS("#~")); static const wxString prefix_deleted_msgid(wxS("#~ msgid")); if (m_textFile->GetLineCount() == 0) return false; wxString line, dummy; wxString mflags, mstr, msgid_plural, mcomment; wxArrayString mrefs, mextractedcomments, mtranslations; wxArrayString msgid_old; bool has_plural = false; bool has_context = false; wxString msgctxt; unsigned mlinenum = 0; line = m_textFile->GetFirstLine(); if (line.empty()) line = ReadTextLine(); while (!line.empty()) { // ignore empty special tags (except for extracted comments which we // DO want to preserve): while (line.length() == 2 && *line.begin() == '#' && (line[1] == ',' || line[1] == ':' || line[1] == '|')) line = ReadTextLine(); // flags: // Can't we have more than one flag, now only the last is kept ... if (ReadParam(line, prefix_flags, dummy)) { static wxString prefix_flags_partial(wxS(", ")); mflags = prefix_flags_partial + dummy; line = ReadTextLine(); } // auto comments: if (ReadParam(line, prefix_autocomments, dummy) || ReadParam(line, prefix_autocomments2, dummy)) { mextractedcomments.Add(dummy); line = ReadTextLine(); } // references: else if (ReadParam(line, prefix_references, dummy)) { // Just store the references unmodified, we don't modify this // data anywhere. mrefs.push_back(dummy); line = ReadTextLine(); } // previous msgid value: else if (ReadParam(line, prefix_prev_msgid, dummy)) { msgid_old.Add(dummy); line = ReadTextLine(); } // msgctxt: else if (ReadParam(line, prefix_msgctxt, dummy)) { has_context = true; msgctxt = UnescapeCString(dummy.RemoveLast()); while (!(line = ReadTextLine()).empty()) { if (line[0u] == _T('\t')) line.Remove(0, 1); if (line[0u] == _T('"') && line.Last() == _T('"')) { msgctxt += UnescapeCString(line.Mid(1, line.Length() - 2)); PossibleWrappedLine(); } else break; } } // msgid: else if (ReadParam(line, prefix_msgid, dummy)) { mstr = UnescapeCString(dummy.RemoveLast()); mlinenum = unsigned(m_textFile->GetCurrentLine() + 1); while (!(line = ReadTextLine()).empty()) { if (line[0u] == wxS('\t')) line.Remove(0, 1); if (line[0u] == wxS('"') && line.Last() == wxS('"')) { mstr += UnescapeCString(line.Mid(1, line.Length() - 2)); PossibleWrappedLine(); } else break; } } // msgid_plural: else if (ReadParam(line, prefix_msgid_plural, dummy)) { msgid_plural = UnescapeCString(dummy.RemoveLast()); has_plural = true; mlinenum = unsigned(m_textFile->GetCurrentLine() + 1); while (!(line = ReadTextLine()).empty()) { if (line[0u] == _T('\t')) line.Remove(0, 1); if (line[0u] == _T('"') && line.Last() == _T('"')) { msgid_plural += UnescapeCString(line.Mid(1, line.Length() - 2)); PossibleWrappedLine(); } else break; } } // msgstr: else if (ReadParam(line, prefix_msgstr, dummy)) { if (has_plural) { wxLogError(_("Broken catalog file: singular form msgstr used together with msgid_plural")); return false; } wxString str = UnescapeCString(dummy.RemoveLast()); while (!(line = ReadTextLine()).empty()) { if (line[0u] == _T('\t')) line.Remove(0, 1); if (line[0u] == _T('"') && line.Last() == _T('"')) { str += UnescapeCString(line.Mid(1, line.Length() - 2)); PossibleWrappedLine(); } else break; } mtranslations.Add(str); bool shouldIgnore = m_ignoreHeader && (mstr.empty() && !has_context); if ( shouldIgnore ) { OnIgnoredEntry(); } else { if (!mstr.empty() && m_ignoreTranslations) mtranslations.clear(); if (!OnEntry(mstr, wxEmptyString, false, has_context, msgctxt, mtranslations, mflags, mrefs, mcomment, mextractedcomments, msgid_old, mlinenum)) { return false; } } mcomment = mstr = msgid_plural = msgctxt = mflags = wxEmptyString; has_plural = has_context = false; mrefs.Clear(); mextractedcomments.Clear(); mtranslations.Clear(); msgid_old.Clear(); } // msgstr[i]: else if (ReadParam(line, prefix_msgstr_plural, dummy)) { if (!has_plural) { wxLogError(_("Broken catalog file: plural form msgstr used without msgid_plural")); return false; } wxString idx = dummy.BeforeFirst(wxS(']')); wxString label_prefix = prefix_msgstr_plural + idx + wxS("] \""); while (ReadParam(line, label_prefix, dummy)) { wxString str = UnescapeCString(dummy.RemoveLast()); while (!(line=ReadTextLine()).empty()) { line.Trim(/*fromRight=*/false); if (line[0u] == wxS('"') && line.Last() == wxS('"')) { str += UnescapeCString(line.Mid(1, line.Length() - 2)); PossibleWrappedLine(); } else { if (ReadParam(line, prefix_msgstr_plural, dummy)) { idx = dummy.BeforeFirst(wxS(']')); label_prefix = prefix_msgstr_plural + idx + wxS("] \""); } break; } } mtranslations.Add(str); } if (!OnEntry(mstr, msgid_plural, true, has_context, msgctxt, mtranslations, mflags, mrefs, mcomment, mextractedcomments, msgid_old, mlinenum)) { return false; } mcomment = mstr = msgid_plural = msgctxt = mflags = wxEmptyString; has_plural = has_context = false; mrefs.Clear(); mextractedcomments.Clear(); mtranslations.Clear(); msgid_old.Clear(); } // deleted lines: else if (ReadParam(line, prefix_deleted, dummy)) { wxArrayString deletedLines; deletedLines.Add(line); mlinenum = unsigned(m_textFile->GetCurrentLine() + 1); while (!(line = ReadTextLine()).empty()) { // if line does not start with "#~" anymore, stop reading if (!ReadParam(line, prefix_deleted, dummy)) break; // if the line starts with "#~ msgid", we skipped an empty line // and it's a new entry, so stop reading too (see bug #329) if (ReadParam(line, prefix_deleted_msgid, dummy)) break; deletedLines.Add(line); } if (!OnDeletedEntry(deletedLines, mflags, mrefs, mcomment, mextractedcomments, mlinenum)) { return false; } mcomment = mstr = msgid_plural = mflags = wxEmptyString; has_plural = false; mrefs.Clear(); mextractedcomments.Clear(); mtranslations.Clear(); msgid_old.Clear(); } // comment: else if (line[0u] == wxS('#')) { bool readNewLine = false; while (!line.empty() && line[0u] == wxS('#') && (line.Length() < 2 || (line[1u] != wxS(',') && line[1u] != wxS(':') && line[1u] != wxS('.') && line[1u] != wxS('~') ))) { mcomment << line << wxS('\n'); readNewLine = true; line = ReadTextLine(); } if (!readNewLine) line = ReadTextLine(); } else { line = ReadTextLine(); } } return true; } wxString POCatalogParser::ReadTextLine() { m_previousLineHardWrapped = m_lastLineHardWrapped; m_lastLineHardWrapped = false; static const wxString msgid_alone(wxS("msgid \"\"")); static const wxString msgstr_alone(wxS("msgstr \"\"")); for (;;) { if (m_textFile->Eof()) return wxString(); // read next line and strip insignificant whitespace from it: const auto& ln = m_textFile->GetNextLine(); if (ln.empty()) continue; // gettext tools don't include (extracted) comments in wrapping, so they can't // be reliably used to detect file's wrapping either; just skip them. if (!ln.StartsWith(wxS("#. ")) && !ln.StartsWith(wxS("# "))) { if (ln.EndsWith(wxS("\\n\""))) { // Similarly, lines ending with \n are always wrapped, so skip that too. m_lastLineHardWrapped = true; } else if (ln == msgid_alone || ln == msgstr_alone) { // The header is always indented like this m_lastLineHardWrapped = true; } else { // Watch out for lines with too long words that couldn't be wrapped. // That "2" is to account for unwrappable comment lines: "#: somethinglong" // See https://github.com/vslavik/poedit/issues/135 auto space = ln.find_last_of(' '); if (space != wxString::npos && space > 2) { m_detectedLineWidth = std::max(m_detectedLineWidth, (int)ln.size()); } } } if (wxIsspace(ln[0]) || wxIsspace(ln.Last())) { auto s = ln.Strip(wxString::both); if (!s.empty()) return s; } else { return ln; } } return wxString(); } int POCatalogParser::GetWrappingWidth() const { if (!m_detectedWrappedLines) return POCatalog::NO_WRAPPING; return m_detectedLineWidth; } class POCharsetInfoFinder : public POCatalogParser { public: POCharsetInfoFinder(wxTextFile *f) : POCatalogParser(f), m_charset("UTF-8") {} wxString GetCharset() const { return m_charset; } protected: wxString m_charset; virtual bool OnEntry(const wxString& msgid, const wxString& /*msgid_plural*/, bool /*has_plural*/, bool has_context, const wxString& /*context*/, const wxArrayString& mtranslations, const wxString& /*flags*/, const wxArrayString& /*references*/, const wxString& /*comment*/, const wxArrayString& /*extractedComments*/, const wxArrayString& /*msgid_old*/, unsigned /*lineNumber*/) { if (msgid.empty() && !has_context) { // gettext header: Catalog::HeaderData hdr; hdr.FromString(mtranslations[0]); m_charset = hdr.Charset; if (m_charset == "CHARSET") m_charset = "ISO-8859-1"; return false; // stop parsing } return true; } }; class POLoadParser : public POCatalogParser { public: POLoadParser(POCatalog& c, wxTextFile *f) : POCatalogParser(f), FileIsValid(false), m_catalog(c), m_nextId(1), m_seenHeaderAlready(false), m_collectMsgidText(true) {} // true if the file is valid, i.e. has at least some data bool FileIsValid; Language GetMsgidLanguage() { auto lang = GetSpecifiedMsgidLanguage(); if (lang.IsValid()) return lang; auto utf8 = m_allMsgidText.utf8_str(); lang = Language::TryDetectFromText(utf8.data(), utf8.length()); if (!lang.IsValid()) lang = Language::English(); // gettext historically assumes English return lang; } protected: Language GetSpecifiedMsgidLanguage() { auto x_srclang = m_catalog.Header().GetHeader("X-Source-Language"); if (x_srclang.empty()) x_srclang = m_catalog.m_header.GetHeader("X-Loco-Source-Locale"); if (!x_srclang.empty()) { auto parsed = Language::TryParse(str::to_utf8(x_srclang)); if (parsed.IsValid()) return parsed; } return Language(); } POCatalog& m_catalog; virtual bool OnEntry(const wxString& msgid, const wxString& msgid_plural, bool has_plural, bool has_context, const wxString& context, const wxArrayString& mtranslations, const wxString& flags, const wxArrayString& references, const wxString& comment, const wxArrayString& extractedComments, const wxArrayString& msgid_old, unsigned lineNumber); virtual bool OnDeletedEntry(const wxArrayString& deletedLines, const wxString& flags, const wxArrayString& references, const wxString& comment, const wxArrayString& extractedComments, unsigned lineNumber); virtual void OnIgnoredEntry() { FileIsValid = true; } private: int m_nextId; bool m_seenHeaderAlready; // collected text of msgids, with newlines, for language detection bool m_collectMsgidText; wxString m_allMsgidText; }; bool POLoadParser::OnEntry(const wxString& msgid, const wxString& msgid_plural, bool has_plural, bool has_context, const wxString& context, const wxArrayString& mtranslations, const wxString& flags, const wxArrayString& references, const wxString& comment, const wxArrayString& extractedComments, const wxArrayString& msgid_old, unsigned lineNumber) { FileIsValid = true; static const wxString MSGCAT_CONFLICT_MARKER("#-#-#-#-#"); if (msgid.empty() && !has_context) { if (!m_seenHeaderAlready) { // gettext header: m_catalog.m_header.FromString(mtranslations[0]); m_catalog.m_header.Comment = comment; m_collectMsgidText = !GetSpecifiedMsgidLanguage().IsValid(); m_seenHeaderAlready = true; } // else: ignore duplicate header in malformed files } else { auto d = std::make_shared<POCatalogItem>(); d->SetId(m_nextId++); if (!flags.empty()) d->SetFlags(flags); d->SetString(msgid); if (has_plural) d->SetPluralString(msgid_plural); if (has_context) d->SetContext(context); d->SetTranslations(mtranslations); d->SetComment(comment); d->SetLineNumber(lineNumber); d->SetRawReferences(references); for (auto i: extractedComments) { // Sometimes, msgcat produces conflicts in extracted comments; see the gory details: // https://groups.google.com/d/topic/poedit/j41KuvXtVUU/discussion // As a workaround, just filter them out. // FIXME: Fix this properly... but not using msgcat in the first place if (i.StartsWith(MSGCAT_CONFLICT_MARKER) && i.EndsWith(MSGCAT_CONFLICT_MARKER)) continue; d->AddExtractedComments(i); } d->SetOldMsgid(msgid_old); m_catalog.AddItem(d); // collect text for language detection: if (m_collectMsgidText) { m_allMsgidText.append(msgid); m_allMsgidText.append('\n'); if (!msgid_plural.empty()) { m_allMsgidText.append(msgid_plural); m_allMsgidText.append('\n'); } } } return true; } bool POLoadParser::OnDeletedEntry(const wxArrayString& deletedLines, const wxString& flags, const wxArrayString& /*references*/, const wxString& comment, const wxArrayString& extractedComments, unsigned lineNumber) { FileIsValid = true; POCatalogDeletedData d; if (!flags.empty()) d.SetFlags(flags); d.SetDeletedLines(deletedLines); d.SetComment(comment); d.SetLineNumber(lineNumber); for (size_t i = 0; i < extractedComments.GetCount(); i++) d.AddExtractedComments(extractedComments[i]); m_catalog.AddDeletedItem(d); return true; } // ---------------------------------------------------------------------- // POCatalogItem class // ---------------------------------------------------------------------- wxArrayString POCatalogItem::GetReferences() const { // A line may contain several references, separated by white-space. // Each reference is in the form "path_name:line_number" // (path_name may contain spaces) wxArrayString refs; for ( wxArrayString::const_iterator i = m_references.begin(); i != m_references.end(); ++i ) { wxString line = *i; line = line.Strip(wxString::both); while (!line.empty()) { size_t idx = 0; while (idx < line.length() && line[idx] != _T(':')) { idx++; } while (idx < line.length() && !wxIsspace(line[idx])) { idx++; } refs.push_back(line.Left(idx)); line = line.Mid(idx).Strip(wxString::both); } } return refs; } // ---------------------------------------------------------------------- // POCatalog class // ---------------------------------------------------------------------- POCatalog::POCatalog(Type type) : Catalog(type) { m_fileCRLF = wxTextFileType_None; m_fileWrappingWidth = DEFAULT_WRAPPING; } POCatalog::POCatalog(const wxString& po_file, int flags) : Catalog(Type::PO) { m_fileCRLF = wxTextFileType_None; m_fileWrappingWidth = DEFAULT_WRAPPING; m_isOk = Load(po_file, flags); } bool POCatalog::HasCapability(Catalog::Cap cap) const { switch (cap) { case Cap::Translations: case Cap::LanguageSetting: case Cap::UserComments: return m_fileType == Type::PO; } return false; // silence VC++ warning } bool POCatalog::CanLoadFile(const wxString& extension) { return extension == "po" || extension == "pot"; } wxString POCatalog::GetPreferredExtension() const { switch (m_fileType) { case Type::PO: return "po"; case Type::POT: return "pot"; case Type::XLIFF: wxFAIL_MSG("not possible here"); } return ""; } static inline wxString GetCurrentTimeString() { return wxDateTime::Now().Format("%Y-%m-%d %H:%M%z"); } bool POCatalog::Load(const wxString& po_file, int flags) { wxTextFile f; Clear(); m_isOk = false; m_fileName = po_file; m_header.BasePath = wxEmptyString; wxString ext; wxFileName::SplitPath(po_file, nullptr, nullptr, &ext); if (ext.CmpNoCase("pot") == 0) m_fileType = Type::POT; else m_fileType = Type::PO; /* Load the .po file: */ if (!f.Open(po_file, wxConvISO8859_1)) return false; { wxLogNull null; // don't report parsing errors from here, report them later POCharsetInfoFinder charsetFinder(&f); charsetFinder.Parse(); m_header.Charset = charsetFinder.GetCharset(); } f.Close(); wxCSConv encConv(m_header.Charset); if (!f.Open(po_file, encConv)) return false; if (!VerifyFileCharset(f, po_file, m_header.Charset)) { wxLogError(_("There were errors when loading the catalog. Some data may be missing or corrupted as the result.")); } POLoadParser parser(*this, &f); parser.IgnoreHeader(flags & CreationFlag_IgnoreHeader); parser.IgnoreTranslations(flags & CreationFlag_IgnoreTranslations); if (!parser.Parse()) { wxLogError( wxString::Format( _(L"Couldn’t load file %s, it is probably corrupted."), po_file.c_str())); return false; } m_sourceLanguage = parser.GetMsgidLanguage(); // now that the catalog is loaded, update its items with the bookmarks for (unsigned i = BOOKMARK_0; i < BOOKMARK_LAST; i++) { if (m_header.Bookmarks[i] == -1) continue; if (m_header.Bookmarks[i] < (int)m_items.size()) { m_items[m_header.Bookmarks[i]]->SetBookmark( static_cast<Bookmark>(i)); } else // invalid bookmark { m_header.Bookmarks[i] = -1; } } m_fileCRLF = GetFileCRLFFormat(f); m_fileWrappingWidth = parser.GetWrappingWidth(); wxLogTrace("poedit", "detect line wrapping: %d", m_fileWrappingWidth); // If we didn't find any entries, the file must be invalid: if (!parser.FileIsValid) return false; m_isOk = true; f.Close(); FixupCommonIssues(); if ( flags & CreationFlag_IgnoreHeader ) CreateNewHeader(); return true; } void POCatalog::FixupCommonIssues() { if (m_header.Project == "PACKAGE VERSION") m_header.Project.clear(); // All the following fixups are specific to POs and should *not* be done in POTs: if (m_fileType == Type::POT) return; if (!m_header.Lang.IsValid()) { if (!m_fileName.empty()) { m_header.Lang = Language::TryGuessFromFilename(m_fileName); wxLogTrace("poedit", "guessed language from filename '%s': %s", m_fileName, m_header.Lang.Code()); } if (!m_header.Lang.IsValid()) { // If all else fails, try to detect the language from content wxString allText; for (auto& i: items()) { for (auto& s: i->GetTranslations()) { if (s.empty()) continue; allText.append(s); allText.append('\n'); } } if (!allText.empty()) { auto utf8 = allText.utf8_str(); m_header.Lang = Language::TryDetectFromText(utf8.data(), utf8.length()); } } } wxLogTrace("poedit", "catalog lang is '%s'", GetLanguage().Code()); if (m_header.GetHeader("Language-Team") == "LANGUAGE <LL@li.org>") { m_header.DeleteHeader("Language-Team"); m_header.LanguageTeam.clear(); } if (m_header.GetHeader("Last-Translator") == "FULL NAME <EMAIL@ADDRESS>") { m_header.DeleteHeader("Last-Translator"); m_header.Translator.clear(); m_header.TranslatorEmail.clear(); } wxString pluralForms = m_header.GetHeader("Plural-Forms"); if (pluralForms == "nplurals=INTEGER; plural=EXPRESSION;") // default invalid value pluralForms = ""; if (!pluralForms.empty()) { if (!pluralForms.EndsWith(";")) { pluralForms += ";"; m_header.SetHeader("Plural-Forms", pluralForms); } } else { // Auto-fill default plural form if it is missing: if (m_header.Lang.IsValid() && HasPluralItems()) { pluralForms = m_header.Lang.DefaultPluralFormsExpr().str(); if (!pluralForms.empty()) m_header.SetHeader("Plural-Forms", pluralForms); } } // TODO: mark catalog as modified if any changes were made } void POCatalog::Clear() { // Catalog base class fields: m_items.clear(); m_isOk = true; for (int i = BOOKMARK_0; i < BOOKMARK_LAST; i++) m_header.Bookmarks[i] = -1; // PO-specific fields: m_deletedItems.clear(); } // misc file-saving helpers namespace { inline bool CanEncodeStringToCharset(const wxString& s, wxMBConv& conv) { if (s.empty()) return true; const wxCharBuffer converted(s.mb_str(conv)); if ( converted.length() == 0 ) return false; return true; } bool CanEncodeToCharset(const wxTextBuffer& f, const wxString& charset) { if (charset.Lower() == "utf-8" || charset.Lower() == "utf8") return true; wxCSConv conv(charset); const size_t lines = f.GetLineCount(); for ( size_t i = 0; i < lines; i++ ) { if ( !CanEncodeStringToCharset(f.GetLine(i), conv) ) return false; } return true; } template<typename Func> inline void SplitIntoLines(const wxString& text, Func&& f) { if (text.empty()) return; wxString::const_iterator last = text.begin(); for (wxString::const_iterator i = text.begin(); i != text.end(); ++i) { if (*i == '\n') { f(wxString(last, i), false); last = i + 1; } } if (last != text.end()) f(wxString(last, text.end()), true); } void SaveMultiLines(wxTextBuffer &f, const wxString& text) { SplitIntoLines(text, [&f](wxString&& s, bool) { f.AddLine(s); }); } /** Adds \n characters as necessary for good-looking output */ wxString FormatStringForFile(const wxString& text) { wxString s; s.reserve(text.length() + 16); static wxString quoted_newline(wxS("\"\n\"")); SplitIntoLines(text, [&s](wxString&& piece, bool last) { if (!s.empty()) s += quoted_newline; if (!last) piece += '\n'; EscapeCStringInplace(piece); s += piece; }); return s; } } // anonymous namespace #ifdef __WXOSX__ @interface CompiledMOFilePresenter : NSObject<NSFilePresenter> @property (atomic, copy) NSURL *presentedItemURL; @property (atomic, copy) NSURL *primaryPresentedItemURL; @end @implementation CompiledMOFilePresenter - (NSOperationQueue *)presentedItemOperationQueue { return [NSOperationQueue mainQueue]; } @end #endif // __WXOSX__ bool POCatalog::Save(const wxString& po_file, bool save_mo, ValidationResults& validation_results, CompilationStatus& mo_compilation_status) { mo_compilation_status = CompilationStatus::NotDone; if ( wxFileExists(po_file) && !wxFile::Access(po_file, wxFile::write) ) { wxLogError(_(L"File “%s” is read-only and cannot be saved.\nPlease save it under different name."), po_file.c_str()); return false; } // Update information about last modification time. But if the header // was empty previously, the author apparently doesn't want this header // set, so don't mess with it. See https://sourceforge.net/tracker/?func=detail&atid=389156&aid=1900298&group_id=27043 // for motivation: auto currentTime = GetCurrentTimeString(); switch (m_fileType) { case Type::PO: if ( !m_header.RevisionDate.empty() ) m_header.RevisionDate = currentTime; break; case Type::POT: if ( m_fileType == Type::POT && !m_header.CreationDate.empty() ) m_header.CreationDate = currentTime; break; case Type::XLIFF: wxFAIL_MSG("not possible here"); break; } TempOutputFileFor po_file_temp_obj(po_file); const wxString po_file_temp = po_file_temp_obj.FileName(); wxTextFileType outputCrlf = GetDesiredCRLFFormat(m_fileCRLF); // Save into Unix line endings first and only if Windows is required, // reformat the file later. This is because msgcat cannot handle DOS // input particularly well. if ( !DoSaveOnly(po_file_temp, wxTextFileType_Unix) ) { wxLogError(_(L"Couldn’t save file %s."), po_file.c_str()); return false; } try { validation_results = DoValidate(po_file_temp); } catch (...) { // DoValidate may fail catastrophically if app bundle is damaged, but // that shouldn't prevent Poedit from trying to save user's file. wxLogError("%s", DescribeCurrentException()); } // Now that the file was written, run msgcat to re-format it according // to the usual format. This is a (barely) passable fix for #25 until // proper preservation of formatting is implemented. int msgcat_ok = false; { int wrapping = DEFAULT_WRAPPING; if (wxConfig::Get()->ReadBool("keep_crlf", true)) wrapping = m_fileWrappingWidth; wxString wrappingFlag; if (wrapping == DEFAULT_WRAPPING) { if (wxConfig::Get()->ReadBool("wrap_po_files", true)) { wrapping = (int)wxConfig::Get()->ReadLong("wrap_po_files_width", 79); } else { wrapping = NO_WRAPPING; } } if (wrapping == NO_WRAPPING) wrappingFlag = " --no-wrap"; else if (wrapping != DEFAULT_WRAPPING) wrappingFlag.Printf(" --width=%d", wrapping); TempOutputFileFor po_file_temp2_obj(po_file_temp); const wxString po_file_temp2 = po_file_temp2_obj.FileName(); auto msgcatCmd = wxString::Format("msgcat --force-po%s -o %s %s", wrappingFlag, QuoteCmdlineArg(po_file_temp2), QuoteCmdlineArg(po_file_temp)); wxLogTrace("poedit", "formatting file with %s", msgcatCmd); // Ignore msgcat errors output (but not exit code), because it // a) complains about things DoValidate() already complained above // b) issues warnings about source-extraction things (e.g. using non-ASCII // msgids) that, while correct, are not something a *translator* can // do anything about. wxLogNull null; msgcat_ok = ExecuteGettext(msgcatCmd) && wxFileExists(po_file_temp2); // msgcat always outputs Unix line endings, so we need to reformat the file if (msgcat_ok && outputCrlf == wxTextFileType_Dos) { wxCSConv conv(m_header.Charset); wxTextFile finalFile(po_file_temp2); if (finalFile.Open(conv)) finalFile.Write(outputCrlf, conv); } if (!TempOutputFileFor::ReplaceFile(po_file_temp2, po_file)) msgcat_ok = false; } if ( msgcat_ok ) { wxRemoveFile(po_file_temp); } else { if ( !po_file_temp_obj.Commit() ) { wxLogError(_(L"Couldn’t save file %s."), po_file.c_str()); } else { // Only shows msgcat's failure warning if we don't also get // validation errors, because if we do, the cause is likely the // same. if ( !validation_results.errors ) { wxLogWarning(_("There was a problem formatting the file nicely (but it was saved all right).")); } } } /* If the user wants it, compile .mo file right now: */ bool compileMO = save_mo; if (!wxConfig::Get()->Read("compile_mo", (long)true)) compileMO = false; if (m_fileType == Type::PO && compileMO) { const wxString mo_file = wxFileName::StripExtension(po_file) + ".mo"; TempOutputFileFor mo_file_temp_obj(mo_file); const wxString mo_file_temp = mo_file_temp_obj.FileName(); { // Ignore msgfmt errors output (but not exit code), because it // complains about things DoValidate() already complained above. wxLogNull null; if ( ExecuteGettext ( wxString::Format("msgfmt -o %s %s", QuoteCmdlineArg(mo_file_temp), QuoteCmdlineArg(CliSafeFileName(po_file))) ) ) { mo_compilation_status = CompilationStatus::Success; } else { // Don't report errors, they were reported as part of validation // step above. Notice that we run msgfmt *without* the -c flag // here to create the MO file in as many cases as possible, even if // it has some errors. // // Still, msgfmt has the ugly habit of sometimes returning non-zero // exit code, reporting "fatal errors" and *still* producing a usable // .mo file. If this happens, don't pretend the file wasn't created. if (wxFileName::FileExists(mo_file_temp)) mo_compilation_status = CompilationStatus::Success; else mo_compilation_status = CompilationStatus::Error; } } // Move the MO from temporary location to the final one, if it was created if (mo_compilation_status == CompilationStatus::Success) { #ifdef __WXOSX__ NSURL *mofileUrl = [NSURL fileURLWithPath:str::to_NS(mo_file)]; NSURL *mofiletempUrl = [NSURL fileURLWithPath:str::to_NS(mo_file_temp)]; bool sandboxed = (getenv("APP_SANDBOX_CONTAINER_ID") != NULL); CompiledMOFilePresenter *presenter = nil; if (sandboxed) { presenter = [CompiledMOFilePresenter new]; presenter.presentedItemURL = mofileUrl; presenter.primaryPresentedItemURL = [NSURL fileURLWithPath:str::to_NS(po_file)]; [NSFileCoordinator addFilePresenter:presenter]; [NSFileCoordinator filePresenters]; } NSFileCoordinator *coo = [[NSFileCoordinator alloc] initWithFilePresenter:presenter]; [coo coordinateWritingItemAtURL:mofileUrl options:NSFileCoordinatorWritingForReplacing error:nil byAccessor:^(NSURL *newURL) { NSURL *resultingUrl; BOOL ok = [[NSFileManager defaultManager] replaceItemAtURL:newURL withItemAtURL:mofiletempUrl backupItemName:nil options:0 resultingItemURL:&resultingUrl error:nil]; if (!ok) { wxLogError(_(L"Couldn’t save file %s."), mo_file.c_str()); mo_compilation_status = CompilationStatus::Error; } }]; if (sandboxed) { [NSFileCoordinator removeFilePresenter:presenter]; } #else // !__WXOSX__ if ( !mo_file_temp_obj.Commit() ) { wxLogError(_(L"Couldn’t save file %s."), mo_file.c_str()); mo_compilation_status = CompilationStatus::Error; } #endif // __WXOSX__/!__WXOSX__ } } m_fileName = po_file; return true; } std::string POCatalog::SaveToBuffer() { class StringSerializer : public wxMemoryText { public: bool OnWrite(wxTextFileType typeNew, const wxMBConv& conv) override { size_t cnt = GetLineCount(); for (size_t n = 0; n < cnt; n++) { auto ln = GetLine(n) + GetEOL(typeNew == wxTextFileType_None ? GetLineType(n) : typeNew); auto buf = ln.mb_str(conv); buffer.append(buf.data(), buf.length()); } return true; } std::string buffer; }; StringSerializer f; if (!DoSaveOnly(f, wxTextFileType_Unix)) return std::string(); return f.buffer; } bool POCatalog::CompileToMO(const wxString& mo_file, ValidationResults& validation_results, CompilationStatus& mo_compilation_status) { mo_compilation_status = CompilationStatus::NotDone; TempDirectory tmpdir; if ( !tmpdir.IsOk() ) return false; wxString po_file_temp = tmpdir.CreateFileName("output.po"); if ( !DoSaveOnly(po_file_temp, wxTextFileType_Unix) ) { wxLogError(_(L"Couldn’t save file %s."), po_file_temp.c_str()); return false; } validation_results = DoValidate(po_file_temp); TempOutputFileFor mo_file_temp_obj(mo_file); const wxString mo_file_temp = mo_file_temp_obj.FileName(); { // Ignore msgfmt errors output (but not exit code), because it // complains about things DoValidate() already complained above. wxLogNull null; ExecuteGettext(wxString::Format("msgfmt -o %s %s", QuoteCmdlineArg(mo_file_temp), QuoteCmdlineArg(po_file_temp))); } // Don't check return code: // msgfmt has the ugly habit of sometimes returning non-zero // exit code, reporting "fatal errors" and *still* producing a usable // .mo file. If this happens, don't pretend the file wasn't created. if (!wxFileName::FileExists(mo_file_temp)) { mo_compilation_status = CompilationStatus::Error; return false; } else { mo_compilation_status = CompilationStatus::Success; } if ( !mo_file_temp_obj.Commit() ) { wxLogError(_(L"Couldn’t save file %s."), mo_file.c_str()); return false; } return true; } bool POCatalog::DoSaveOnly(const wxString& po_file, wxTextFileType crlf) { wxTextFile f; if (!f.Create(po_file)) return false; return DoSaveOnly(f, crlf); } bool POCatalog::DoSaveOnly(wxTextBuffer& f, wxTextFileType crlf) { /* Save .po file: */ if (!m_header.Charset || m_header.Charset == "CHARSET") m_header.Charset = "UTF-8"; SaveMultiLines(f, m_header.Comment); if (m_fileType == Type::POT) f.AddLine(wxS("#, fuzzy")); f.AddLine(wxS("msgid \"\"")); f.AddLine(wxS("msgstr \"\"")); wxString pohdr = wxString(wxS("\"")) + m_header.ToString(wxS("\"\n\"")); pohdr.RemoveLast(); SaveMultiLines(f, pohdr); f.AddLine(wxEmptyString); auto pluralsCount = GetPluralFormsCount(); for (auto& data_: m_items) { auto data = std::static_pointer_cast<POCatalogItem>(data_); data->SetLineNumber(int(f.GetLineCount()+1)); SaveMultiLines(f, data->GetComment()); for (unsigned i = 0; i < data->GetExtractedComments().GetCount(); i++) { if (data->GetExtractedComments()[i].empty()) f.AddLine(wxS("#.")); else f.AddLine(wxS("#. ") + data->GetExtractedComments()[i]); } for (unsigned i = 0; i < data->GetRawReferences().GetCount(); i++) f.AddLine(wxS("#: ") + data->GetRawReferences()[i]); wxString dummy = data->GetFlags(); if (!dummy.empty()) f.AddLine(wxS("#") + dummy); for (unsigned i = 0; i < data->GetOldMsgidRaw().GetCount(); i++) f.AddLine(wxS("#| ") + data->GetOldMsgidRaw()[i]); if ( data->HasContext() ) { SaveMultiLines(f, wxS("msgctxt \"") + FormatStringForFile(data->GetContext()) + wxS("\"")); } dummy = FormatStringForFile(data->GetString()); SaveMultiLines(f, wxS("msgid \"") + dummy + wxS("\"")); if (data->HasPlural()) { dummy = FormatStringForFile(data->GetPluralString()); SaveMultiLines(f, wxS("msgid_plural \"") + dummy + wxS("\"")); for (unsigned i = 0; i < pluralsCount; i++) { dummy = FormatStringForFile(data->GetTranslation(i)); wxString hdr = wxString::Format(wxS("msgstr[%u] \""), i); SaveMultiLines(f, hdr + dummy + wxS("\"")); } } else { dummy = FormatStringForFile(data->GetTranslation()); SaveMultiLines(f, wxS("msgstr \"") + dummy + wxS("\"")); } f.AddLine(wxEmptyString); } // Write back deleted items in the file so that they're not lost for (unsigned itemIdx = 0; itemIdx < m_deletedItems.size(); itemIdx++) { if ( itemIdx != 0 ) f.AddLine(wxEmptyString); POCatalogDeletedData& deletedItem = m_deletedItems[itemIdx]; deletedItem.SetLineNumber(int(f.GetLineCount()+1)); SaveMultiLines(f, deletedItem.GetComment()); for (unsigned i = 0; i < deletedItem.GetExtractedComments().GetCount(); i++) f.AddLine(wxS("#. ") + deletedItem.GetExtractedComments()[i]); for (unsigned i = 0; i < deletedItem.GetRawReferences().GetCount(); i++) f.AddLine(wxS("#: ") + deletedItem.GetRawReferences()[i]); wxString dummy = deletedItem.GetFlags(); if (!dummy.empty()) f.AddLine(wxS("#") + dummy); for (size_t j = 0; j < deletedItem.GetDeletedLines().GetCount(); j++) f.AddLine(deletedItem.GetDeletedLines()[j]); } if (!CanEncodeToCharset(f, m_header.Charset)) { #if wxUSE_GUI wxString msg; msg.Printf(_(L"The catalog couldn’t be saved in “%s” charset as specified in catalog settings.\n\nIt was saved in UTF-8 instead and the setting was modified accordingly."), m_header.Charset.c_str()); wxMessageBox(msg, _("Error saving catalog"), wxOK | wxICON_EXCLAMATION); #endif m_header.Charset = "UTF-8"; // Re-do the save again because we modified a header: f.Clear(); return DoSaveOnly(f, crlf); } // Otherwise everything can be safely saved: return f.Write(crlf, wxCSConv(m_header.Charset)); } bool POCatalog::HasDuplicateItems() const { typedef std::pair<wxString, wxString> MsgId; std::set<MsgId> ids; for (auto& item: m_items) { if (!ids.emplace(std::make_pair(item->GetContext(), item->GetString())).second) return true; } return false; } bool POCatalog::FixDuplicateItems() { auto oldname = m_fileName; TempDirectory tmpdir; if ( !tmpdir.IsOk() ) return false; wxString ext; wxFileName::SplitPath(m_fileName, nullptr, nullptr, &ext); wxString po_file_temp = tmpdir.CreateFileName("catalog." + ext); wxString po_file_fixed = tmpdir.CreateFileName("fixed." + ext); if ( !DoSaveOnly(po_file_temp, wxTextFileType_Unix) ) { wxLogError(_(L"Couldn’t save file %s."), po_file_temp.c_str()); return false; } ExecuteGettext(wxString::Format("msguniq -o %s %s", QuoteCmdlineArg(po_file_fixed), QuoteCmdlineArg(po_file_temp))); if (!wxFileName::FileExists(po_file_fixed)) return false; bool ok = Load(po_file_fixed); m_fileName = oldname; return ok; } Catalog::ValidationResults POCatalog::Validate(bool wasJustLoaded) { if (!HasCapability(Catalog::Cap::Translations)) return ValidationResults(); // no errors in POT files if (wasJustLoaded) { return DoValidate(GetFileName()); } else { TempDirectory tmpdir; if ( !tmpdir.IsOk() ) return ValidationResults(); wxString tmp_po = tmpdir.CreateFileName("validated.po"); if ( !DoSaveOnly(tmp_po, wxTextFileType_Unix) ) return ValidationResults(); return DoValidate(tmp_po); } } Catalog::ValidationResults POCatalog::DoValidate(const wxString& po_file) { ValidationResults res; GettextErrors err; ExecuteGettextAndParseOutput ( wxString::Format("msgfmt -o /dev/null -c %s", QuoteCmdlineArg(CliSafeFileName(po_file))), err ); for (auto& i: m_items) i->ClearIssue(); res.errors = (int)err.size(); if (Config::ShowWarnings()) res.warnings = QAChecker::GetFor(*this)->Check(*this); for ( GettextErrors::const_iterator i = err.begin(); i != err.end(); ++i ) { if ( i->line != -1 ) { auto item = FindItemByLine(i->line); if ( item ) { item->SetIssue(CatalogItem::Issue::Error, i->text); continue; } } // if not matched to an item: wxLogError(i->text); } return res; } bool POCatalog::UpdateFromPOT(const wxString& pot_file, bool replace_header) { POCatalogPtr pot = std::make_shared<POCatalog>(pot_file, CreationFlag_IgnoreTranslations); if (!pot->IsOk()) { wxLogError(_(L"“%s” is not a valid POT file."), pot_file.c_str()); return false; } return UpdateFromPOT(pot, replace_header); } bool POCatalog::UpdateFromPOT(POCatalogPtr pot, bool replace_header) { switch (m_fileType) { case Type::PO: { if (!Merge(pot)) return false; break; } case Type::POT: { m_items = pot->m_items; break; } case Type::XLIFF: wxFAIL_MSG("not possible here"); break; } if (replace_header) CreateNewHeader(pot->Header()); return true; } POCatalogPtr POCatalog::CreateFromPOT(POCatalogPtr pot) { POCatalogPtr c = std::make_shared<POCatalog>(); if (c->UpdateFromPOT(pot, /*replace_header=*/true)) return c; else return nullptr; } bool POCatalog::Merge(const POCatalogPtr& refcat) { wxString oldname = m_fileName; TempDirectory tmpdir; if ( !tmpdir.IsOk() ) return false; wxString tmp1 = tmpdir.CreateFileName("ref.pot"); wxString tmp2 = tmpdir.CreateFileName("input.po"); wxString tmp3 = tmpdir.CreateFileName("output.po"); refcat->DoSaveOnly(tmp1, wxTextFileType_Unix); DoSaveOnly(tmp2, wxTextFileType_Unix); wxString flags("-q --force-po --previous"); if (Config::MergeBehavior() == Merge_None) { flags += " --no-fuzzy-matching"; } bool succ = ExecuteGettext ( wxString::Format ( "msgmerge %s -o %s %s %s", flags, QuoteCmdlineArg(tmp3), QuoteCmdlineArg(tmp2), QuoteCmdlineArg(tmp1) ) ); if (succ) { const wxString charset = m_header.Charset; Load(tmp3); // msgmerge doesn't always preserve the charset, it tends to pick // the most generic one of the charsets used, so if we are merging with // UTF-8 catalog, it will become UTF-8. Some people hate this. m_header.Charset = charset; } m_fileName = oldname; return succ; }
31.431141
180
0.544656
jhertel
60f5d5fe22d3a047ee26954dcb7a20d16707716e
815
hpp
C++
sprout/container/remake.hpp
osyo-manga/Sprout
8885b115f739ef255530f772067475d3bc0dcef7
[ "BSL-1.0" ]
1
2020-02-04T05:16:01.000Z
2020-02-04T05:16:01.000Z
sprout/container/remake.hpp
osyo-manga/Sprout
8885b115f739ef255530f772067475d3bc0dcef7
[ "BSL-1.0" ]
null
null
null
sprout/container/remake.hpp
osyo-manga/Sprout
8885b115f739ef255530f772067475d3bc0dcef7
[ "BSL-1.0" ]
null
null
null
#ifndef SPROUT_CONTAINER_REMAKE_HPP #define SPROUT_CONTAINER_REMAKE_HPP #include <type_traits> #include <sprout/config.hpp> #include <sprout/container/container_traits.hpp> #include <sprout/container/container_construct_traits.hpp> #include <sprout/utility/forward.hpp> namespace sprout { // // remake // template<typename Container, typename Cont, typename... Args> inline SPROUT_CONSTEXPR typename sprout::container_construct_traits<Container>::copied_type remake(Cont&& cont, typename sprout::container_traits<Container>::difference_type size, Args&&... args) { return sprout::container_construct_traits<Container>::remake( sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)... ); } } // namespace sprout #endif // #ifndef SPROUT_CONTAINER_REMAKE_HPP
31.346154
107
0.75092
osyo-manga
60f60afdea4b3f0705fb8b6465dcdf56d4823122
2,302
cpp
C++
src/cpp/rtps/writer/PersistentWriter.cpp
pbleyer/Fast-DDS
1963bd8ccbe0bc6c93267fb1977565d32ef56188
[ "Apache-2.0" ]
null
null
null
src/cpp/rtps/writer/PersistentWriter.cpp
pbleyer/Fast-DDS
1963bd8ccbe0bc6c93267fb1977565d32ef56188
[ "Apache-2.0" ]
null
null
null
src/cpp/rtps/writer/PersistentWriter.cpp
pbleyer/Fast-DDS
1963bd8ccbe0bc6c93267fb1977565d32ef56188
[ "Apache-2.0" ]
null
null
null
// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). // // 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. /* * @file PersistentWriter.cpp * */ #include <fastdds/rtps/writer/PersistentWriter.h> #include <fastdds/rtps/history/WriterHistory.h> #include <rtps/persistence/PersistenceService.h> #include <fastrtps_deprecated/participant/ParticipantImpl.h> namespace eprosima { namespace fastrtps { namespace rtps { PersistentWriter::PersistentWriter( GUID_t& guid, WriterAttributes& att, WriterHistory* hist, IPersistenceService* persistence) : persistence_(persistence) , persistence_guid_() { // When persistence GUID is unknown, create from rtps GUID GUID_t p_guid = att.endpoint.persistence_guid == c_Guid_Unknown ? guid : att.endpoint.persistence_guid; std::ostringstream ss; ss << p_guid; persistence_guid_ = ss.str(); persistence_->load_writer_from_storage(persistence_guid_, guid, hist->m_changes, hist->change_pool_, hist->payload_pool_, hist->m_lastCacheChangeSeqNum); // Update history state after loading from DB hist->m_isHistoryFull = hist->m_att.maximumReservedCaches > 0 && static_cast<int32_t>(hist->m_changes.size()) == hist->m_att.maximumReservedCaches; } PersistentWriter::~PersistentWriter() { delete persistence_; } /* * CHANGE-RELATED METHODS */ void PersistentWriter::add_persistent_change( CacheChange_t* cptr) { persistence_->add_writer_change_to_storage(persistence_guid_, *cptr); } void PersistentWriter::remove_persistent_change( CacheChange_t* change) { persistence_->remove_writer_change_from_storage(persistence_guid_, *change); } } // namespace rtps } // namespace fastrtps } // namespace eprosima
29.896104
107
0.734144
pbleyer
60f6a74a7ec786c8949532911ef0462164404817
10,306
cpp
C++
src/rosecommon/src/crosesocket.cpp
RavenX8/osirosenew
b4ef1aade379e0eb4753b24c30ec43faca77aa37
[ "Apache-2.0" ]
49
2017-02-07T15:10:04.000Z
2021-11-12T06:00:30.000Z
src/rosecommon/src/crosesocket.cpp
RavenX8/osirosenew
b4ef1aade379e0eb4753b24c30ec43faca77aa37
[ "Apache-2.0" ]
104
2016-10-31T01:42:59.000Z
2021-08-28T13:29:09.000Z
src/rosecommon/src/crosesocket.cpp
RavenX8/osirosenew
b4ef1aade379e0eb4753b24c30ec43faca77aa37
[ "Apache-2.0" ]
36
2016-11-01T11:25:34.000Z
2022-03-09T22:38:51.000Z
// Copyright 2016 Chirstopher Torres (Raven), L3nn0x // // 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 <ctime> #include "crosesocket.h" #include "epackettype.h" #include "srv_accept_reply.h" #include "srv_screen_shot_time_reply.h" namespace RoseCommon { CRoseSocket::CRoseSocket() : crypt_() { logger_ = Core::CLog::GetLogger(Core::log_type::NETWORK).lock(); socket_[static_cast<int>(SocketType::Client)] = nullptr; } CRoseSocket::CRoseSocket(std::unique_ptr<Core::INetwork> _sock) : crypt_() { logger_ = Core::CLog::GetLogger(Core::log_type::NETWORK).lock(); socket_[static_cast<int>(SocketType::Client)] = std::move(_sock); socket_[static_cast<int>(SocketType::Client)]->set_socket_id(static_cast<int>(SocketType::Client)); socket_[static_cast<int>(SocketType::Client)]->registerOnReceived(std::bind(&CRoseSocket::onReceived, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); socket_[static_cast<int>(SocketType::Client)]->registerOnSend(std::bind(&CRoseSocket::onSend, this, std::placeholders::_1, std::placeholders::_2)); socket_[static_cast<int>(SocketType::Client)]->registerOnDisconnected(std::bind(&CRoseSocket::onDisconnected, this)); socket_[static_cast<int>(SocketType::Client)]->reset_internal_buffer(); } CRoseSocket::CRoseSocket(std::unique_ptr<Core::INetwork> _sock, bool is_server, int socket_id) : crypt_() { logger_ = Core::CLog::GetLogger(Core::log_type::NETWORK).lock(); socket_[socket_id] = std::move(_sock); socket_[socket_id]->set_socket_id(socket_id); if(true == is_server) { socket_[socket_id]->registerOnReceived(std::bind(&CRoseSocket::onServerReceived, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); socket_[socket_id]->registerOnSend(std::bind(&CRoseSocket::onServerSend, this, std::placeholders::_1, std::placeholders::_2)); socket_[socket_id]->registerOnDisconnected(std::bind(&CRoseSocket::onServerDisconnected, this)); } else { socket_[socket_id]->registerOnReceived(std::bind(&CRoseSocket::onReceived, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); socket_[socket_id]->registerOnSend(std::bind(&CRoseSocket::onSend, this, std::placeholders::_1, std::placeholders::_2)); socket_[socket_id]->registerOnDisconnected(std::bind(&CRoseSocket::onDisconnected, this)); } socket_[socket_id]->reset_internal_buffer(); } CRoseSocket::~CRoseSocket() { for(unsigned int idx = 0; idx < SocketType::MaxSockets; ++idx) { if(socket_[idx]) socket_[idx]->shutdown(true); } logger_.reset(); } bool CRoseSocket::send(const CRosePacket& _buffer, int socket_id) { return CRoseSocket::send(_buffer.getPacked(), socket_id); } bool CRoseSocket::send(std::unique_ptr<uint8_t[]> _buffer, int socket_id) { #ifdef SPDLOG_TRACE_ON logger_->trace("Sending a packet on CRoseSocket: Header[{0}, 0x{1:04x}]", CRosePacket::size(_buffer.get()), static_cast<uint16_t>(CRosePacket::type(_buffer.get()))); #endif return socket_[socket_id]->send_data(std::move(_buffer)); } // Callback functions void CRoseSocket::onDisconnected() {} // TODO The socket ids in this fuction need to be fixed. bool CRoseSocket::onReceived(uint16_t socket_id_, uint16_t& packet_size_, uint8_t* buffer_) { bool rtnVal = true; ///* if (packet_size_ == 6) { #ifndef DISABLE_CRYPT packet_size_ = crypt_[socket_id_].decodeClientHeader(reinterpret_cast<unsigned char*>(buffer_)); #else packet_size_ = reinterpret_cast<uint16_t*>(buffer_)[0]; #endif if (packet_size_ < 6 || packet_size_ > MAX_PACKET_SIZE) { logger_->debug("Client sent incorrect block header"); socket_[socket_id_]->reset_internal_buffer(); return false; } if (packet_size_ > 6) return true; } // decrypt packet now #ifndef DISABLE_CRYPT if (!crypt_[socket_id_].decodeClientBody(reinterpret_cast<unsigned char*>(buffer_))) { // ERROR!!! logger_->debug( "Client sent illegal block" ); socket_[socket_id_]->reset_internal_buffer(); return false; } #endif logger_->trace("Received a packet on CRoseSocket {2}: Header[{0}, 0x{1:04x}]", CRosePacket::size(buffer_), (uint16_t)CRosePacket::type(buffer_), get_id()); #ifdef SPDLOG_TRACE_ON fmt::MemoryWriter out; for(int i = 0; i < CRosePacket::size(buffer_); i++) out.write("0x{0:02x} ", buffer_[i]); logger_->trace("{}", out.c_str()); #endif auto res = std::make_unique<uint8_t[]>( CRosePacket::size(buffer_) ); std::memcpy(res.get(), buffer_, CRosePacket::size(buffer_)); recv_mutex_.lock(); recv_queue_.push(std::move(res)); recv_mutex_.unlock(); socket_[socket_id_]->dispatch([this, socket_id_]() { if (true == socket_[socket_id_]->is_active()) { recv_mutex_.lock(); bool recv_empty = recv_queue_.empty(); if(recv_empty == false) { bool rtnVal = true; std::unique_ptr<uint8_t[]> _buffer = std::move(recv_queue_.front()); recv_queue_.pop(); recv_mutex_.unlock(); rtnVal = handlePacket(_buffer.get()); _buffer.reset(nullptr); if(rtnVal == false) { // Abort connection logger_->debug("handlePacket returned false, disconnecting client."); socket_[socket_id_]->shutdown(); // TODO: if this happens, we should disconnect ALL of the sockets. } } else { recv_mutex_.unlock(); } } }); socket_[socket_id_]->reset_internal_buffer(); //*/ return rtnVal; } bool CRoseSocket::onSend(uint16_t socket_id_, [[maybe_unused]] uint8_t* _buffer) { (void)_buffer; #ifndef DISABLE_CRYPT crypt_[socket_id_].encodeServerPacket(_buffer); #endif return true; } bool CRoseSocket::handlePacket(uint8_t* _buffer) { logger_->trace("CRoseSocket::handlePacket start"); switch (CRosePacket::type(_buffer)) { case ePacketType::PAKCS_ALIVE: { #ifdef STRESS_TEST auto packet = std::unique_ptr<CRosePacket>(new CRosePacket(ePacketType::PAKCS_ALIVE)); send(*packet); #endif //return CNetwork_Asio::handlePacket(_buffer); break; } #ifdef STRESS_TEST case ePacketType::STRESS: { std::unique_ptr<CRosePacket> packet( new CRosePacket(_buffer) ); send(*packet); break; } #endif case ePacketType::PAKCS_ACCEPT_REQ: { // Encryption stuff auto packet = Packet::SrvAcceptReply::create(Packet::SrvAcceptReply::ACCEPTED, std::time(nullptr)); send(packet); break; } case ePacketType::PAKCS_SCREEN_SHOT_TIME_REQ: { auto packet = Packet::SrvScreenShotTimeReply::create(0, 0, 0, 0, 0); send(packet); break; } default: { logger_->warn("Unknown Packet Type: 0x{0:04x}", static_cast<uint16_t>(CRosePacket::type(_buffer))); return false; } } logger_->trace("CRoseSocket::handlePacket end"); return true; } // Server Callback functions void CRoseSocket::onServerDisconnected() {} //TODO The socket ids in this fuction need to be fixed. bool CRoseSocket::onServerReceived(uint16_t socket_id_, uint16_t& packet_size_, uint8_t* buffer_) { logger_->trace("CRoseSocket::onServerReceived start"); bool rtnVal = true; ///* if (packet_size_ == 6) { #ifndef DISABLE_CRYPT packet_size_ = crypt_[socket_id_].decodeServerHeader(reinterpret_cast<unsigned char*>(buffer_)); #else packet_size_ = reinterpret_cast<uint16_t*>(buffer_)[0]; #endif if (packet_size_ < 6 || packet_size_ > MAX_PACKET_SIZE) { logger_->debug("Client sent incorrect block header"); socket_[socket_id_]->reset_internal_buffer(); return false; } if (packet_size_ > 6) return true; } // decrypt packet now #ifndef DISABLE_CRYPT if (!crypt_[socket_id_].decodeServerBody(reinterpret_cast<unsigned char*>(buffer_))) { // ERROR!!! logger_->debug( "Client sent illegal block" ); socket_[socket_id_]->reset_internal_buffer(); return false; } #endif logger_->trace("Received a packet on CRoseSocket {2}: Header[{0}, 0x{1:04x}]", CRosePacket::size(buffer_), (uint16_t)CRosePacket::type(buffer_), get_id()); #ifdef SPDLOG_TRACE_ON fmt::MemoryWriter out; for(int i = 0; i < CRosePacket::size(buffer_); i++) out.write("0x{0:02x} ", buffer_[i]); logger_->trace("{}", out.c_str()); #endif auto res = std::make_unique<uint8_t[]>( CRosePacket::size(buffer_) ); std::memcpy(res.get(), buffer_, CRosePacket::size(buffer_)); recv_mutex_.lock(); recv_queue_.push(std::move(res)); recv_mutex_.unlock(); socket_[socket_id_]->dispatch([this, socket_id_]() { if (true == socket_[socket_id_]->is_active()) { recv_mutex_.lock(); bool recv_empty = recv_queue_.empty(); if(recv_empty == false) { bool rtnVal = true; std::unique_ptr<uint8_t[]> _buffer = std::move(recv_queue_.front()); recv_queue_.pop(); rtnVal = handleServerPacket(_buffer.get()); _buffer.reset(nullptr); if(rtnVal == false) { // Abort connection logger_->debug("handlePacket returned false, disconnecting client."); socket_[socket_id_]->shutdown(); } } recv_mutex_.unlock(); } }); socket_[socket_id_]->reset_internal_buffer(); //*/ return rtnVal; } bool CRoseSocket::onServerSend(uint16_t socket_id_, [[maybe_unused]] uint8_t* _buffer) { #ifndef DISABLE_CRYPT crypt_[socket_id_].encodeClientPacket(_buffer); #endif return true; } bool CRoseSocket::handleServerPacket([[maybe_unused]] uint8_t* _buffer) { logger_->trace("CRoseSocket::handleServerPacket start"); logger_->trace("CRoseSocket::handlePacket end"); return true; } }
33.901316
180
0.682224
RavenX8
60f70a936be826939d317470593a1d5737a5777a
773
cpp
C++
tests/getApp_test.cpp
TheKuko/BP
b3385f52880ef9799c4003e92148488a5463f416
[ "MIT" ]
5
2017-10-25T12:48:52.000Z
2021-06-25T07:46:57.000Z
tests/getApp_test.cpp
jzlka/namon
b3385f52880ef9799c4003e92148488a5463f416
[ "MIT" ]
null
null
null
tests/getApp_test.cpp
jzlka/namon
b3385f52880ef9799c4003e92148488a5463f416
[ "MIT" ]
3
2017-10-25T13:54:10.000Z
2019-08-01T07:03:20.000Z
/** * @file getApp_test.cpp * @brief Brief description * @author Jozef Zuzelka <xzuzel00@stud.fit.vutbr.cz> * @date * - Created: 28.03.2017 17:08 * - Edited: 23.06.2017 12:16 */ #include <iostream> // cout, cerr, endl #include "namon_linux.hpp" // getApp() using namespace std; void printHelp() { cout << "Usage: ./getApp_test <inode_number>" << endl; } int main(int argc, char *argv[]) { if (argc != 2) { printHelp(); return 1; } string appname; unsigned int inode = strtoul(argv[1], NULL, 10); if (getApp(inode, appname)) cerr << "App with inode " << inode << " not found." << endl; else cout << "App with inode " << inode << " is: " << appname << endl; }
20.342105
73
0.547219
TheKuko